dwmac-rk.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  1. /**
  2. * dwmac-rk.c - Rockchip RK3288 DWMAC specific glue layer
  3. *
  4. * Copyright (C) 2014 Chen-Zhi (Roger Chen)
  5. *
  6. * Chen-Zhi (Roger Chen) <roger.chen@rock-chips.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/stmmac.h>
  19. #include <linux/bitops.h>
  20. #include <linux/clk.h>
  21. #include <linux/phy.h>
  22. #include <linux/of_net.h>
  23. #include <linux/gpio.h>
  24. #include <linux/module.h>
  25. #include <linux/of_gpio.h>
  26. #include <linux/of_device.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/regulator/consumer.h>
  29. #include <linux/delay.h>
  30. #include <linux/mfd/syscon.h>
  31. #include <linux/regmap.h>
  32. #include <linux/pm_runtime.h>
  33. #include "stmmac_platform.h"
  34. struct rk_priv_data;
  35. struct rk_gmac_ops {
  36. void (*set_to_rgmii)(struct rk_priv_data *bsp_priv,
  37. int tx_delay, int rx_delay);
  38. void (*set_to_rmii)(struct rk_priv_data *bsp_priv);
  39. void (*set_rgmii_speed)(struct rk_priv_data *bsp_priv, int speed);
  40. void (*set_rmii_speed)(struct rk_priv_data *bsp_priv, int speed);
  41. };
  42. struct rk_priv_data {
  43. struct platform_device *pdev;
  44. int phy_iface;
  45. struct regulator *regulator;
  46. bool suspended;
  47. const struct rk_gmac_ops *ops;
  48. bool clk_enabled;
  49. bool clock_input;
  50. struct clk *clk_mac;
  51. struct clk *gmac_clkin;
  52. struct clk *mac_clk_rx;
  53. struct clk *mac_clk_tx;
  54. struct clk *clk_mac_ref;
  55. struct clk *clk_mac_refout;
  56. struct clk *aclk_mac;
  57. struct clk *pclk_mac;
  58. int tx_delay;
  59. int rx_delay;
  60. struct regmap *grf;
  61. };
  62. #define HIWORD_UPDATE(val, mask, shift) \
  63. ((val) << (shift) | (mask) << ((shift) + 16))
  64. #define GRF_BIT(nr) (BIT(nr) | BIT(nr+16))
  65. #define GRF_CLR_BIT(nr) (BIT(nr+16))
  66. #define RK3228_GRF_MAC_CON0 0x0900
  67. #define RK3228_GRF_MAC_CON1 0x0904
  68. /* RK3228_GRF_MAC_CON0 */
  69. #define RK3228_GMAC_CLK_RX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 7)
  70. #define RK3228_GMAC_CLK_TX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 0)
  71. /* RK3228_GRF_MAC_CON1 */
  72. #define RK3228_GMAC_PHY_INTF_SEL_RGMII \
  73. (GRF_BIT(4) | GRF_CLR_BIT(5) | GRF_CLR_BIT(6))
  74. #define RK3228_GMAC_PHY_INTF_SEL_RMII \
  75. (GRF_CLR_BIT(4) | GRF_CLR_BIT(5) | GRF_BIT(6))
  76. #define RK3228_GMAC_FLOW_CTRL GRF_BIT(3)
  77. #define RK3228_GMAC_FLOW_CTRL_CLR GRF_CLR_BIT(3)
  78. #define RK3228_GMAC_SPEED_10M GRF_CLR_BIT(2)
  79. #define RK3228_GMAC_SPEED_100M GRF_BIT(2)
  80. #define RK3228_GMAC_RMII_CLK_25M GRF_BIT(7)
  81. #define RK3228_GMAC_RMII_CLK_2_5M GRF_CLR_BIT(7)
  82. #define RK3228_GMAC_CLK_125M (GRF_CLR_BIT(8) | GRF_CLR_BIT(9))
  83. #define RK3228_GMAC_CLK_25M (GRF_BIT(8) | GRF_BIT(9))
  84. #define RK3228_GMAC_CLK_2_5M (GRF_CLR_BIT(8) | GRF_BIT(9))
  85. #define RK3228_GMAC_RMII_MODE GRF_BIT(10)
  86. #define RK3228_GMAC_RMII_MODE_CLR GRF_CLR_BIT(10)
  87. #define RK3228_GMAC_TXCLK_DLY_ENABLE GRF_BIT(0)
  88. #define RK3228_GMAC_TXCLK_DLY_DISABLE GRF_CLR_BIT(0)
  89. #define RK3228_GMAC_RXCLK_DLY_ENABLE GRF_BIT(1)
  90. #define RK3228_GMAC_RXCLK_DLY_DISABLE GRF_CLR_BIT(1)
  91. static void rk3228_set_to_rgmii(struct rk_priv_data *bsp_priv,
  92. int tx_delay, int rx_delay)
  93. {
  94. struct device *dev = &bsp_priv->pdev->dev;
  95. if (IS_ERR(bsp_priv->grf)) {
  96. dev_err(dev, "Missing rockchip,grf property\n");
  97. return;
  98. }
  99. regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON1,
  100. RK3228_GMAC_PHY_INTF_SEL_RGMII |
  101. RK3228_GMAC_RMII_MODE_CLR |
  102. RK3228_GMAC_RXCLK_DLY_ENABLE |
  103. RK3228_GMAC_TXCLK_DLY_ENABLE);
  104. regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON0,
  105. RK3228_GMAC_CLK_RX_DL_CFG(rx_delay) |
  106. RK3228_GMAC_CLK_TX_DL_CFG(tx_delay));
  107. }
  108. static void rk3228_set_to_rmii(struct rk_priv_data *bsp_priv)
  109. {
  110. struct device *dev = &bsp_priv->pdev->dev;
  111. if (IS_ERR(bsp_priv->grf)) {
  112. dev_err(dev, "Missing rockchip,grf property\n");
  113. return;
  114. }
  115. regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON1,
  116. RK3228_GMAC_PHY_INTF_SEL_RMII |
  117. RK3228_GMAC_RMII_MODE);
  118. /* set MAC to RMII mode */
  119. regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON1, GRF_BIT(11));
  120. }
  121. static void rk3228_set_rgmii_speed(struct rk_priv_data *bsp_priv, int speed)
  122. {
  123. struct device *dev = &bsp_priv->pdev->dev;
  124. if (IS_ERR(bsp_priv->grf)) {
  125. dev_err(dev, "Missing rockchip,grf property\n");
  126. return;
  127. }
  128. if (speed == 10)
  129. regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON1,
  130. RK3228_GMAC_CLK_2_5M);
  131. else if (speed == 100)
  132. regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON1,
  133. RK3228_GMAC_CLK_25M);
  134. else if (speed == 1000)
  135. regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON1,
  136. RK3228_GMAC_CLK_125M);
  137. else
  138. dev_err(dev, "unknown speed value for RGMII! speed=%d", speed);
  139. }
  140. static void rk3228_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed)
  141. {
  142. struct device *dev = &bsp_priv->pdev->dev;
  143. if (IS_ERR(bsp_priv->grf)) {
  144. dev_err(dev, "Missing rockchip,grf property\n");
  145. return;
  146. }
  147. if (speed == 10)
  148. regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON1,
  149. RK3228_GMAC_RMII_CLK_2_5M |
  150. RK3228_GMAC_SPEED_10M);
  151. else if (speed == 100)
  152. regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON1,
  153. RK3228_GMAC_RMII_CLK_25M |
  154. RK3228_GMAC_SPEED_100M);
  155. else
  156. dev_err(dev, "unknown speed value for RMII! speed=%d", speed);
  157. }
  158. static const struct rk_gmac_ops rk3228_ops = {
  159. .set_to_rgmii = rk3228_set_to_rgmii,
  160. .set_to_rmii = rk3228_set_to_rmii,
  161. .set_rgmii_speed = rk3228_set_rgmii_speed,
  162. .set_rmii_speed = rk3228_set_rmii_speed,
  163. };
  164. #define RK3288_GRF_SOC_CON1 0x0248
  165. #define RK3288_GRF_SOC_CON3 0x0250
  166. /*RK3288_GRF_SOC_CON1*/
  167. #define RK3288_GMAC_PHY_INTF_SEL_RGMII (GRF_BIT(6) | GRF_CLR_BIT(7) | \
  168. GRF_CLR_BIT(8))
  169. #define RK3288_GMAC_PHY_INTF_SEL_RMII (GRF_CLR_BIT(6) | GRF_CLR_BIT(7) | \
  170. GRF_BIT(8))
  171. #define RK3288_GMAC_FLOW_CTRL GRF_BIT(9)
  172. #define RK3288_GMAC_FLOW_CTRL_CLR GRF_CLR_BIT(9)
  173. #define RK3288_GMAC_SPEED_10M GRF_CLR_BIT(10)
  174. #define RK3288_GMAC_SPEED_100M GRF_BIT(10)
  175. #define RK3288_GMAC_RMII_CLK_25M GRF_BIT(11)
  176. #define RK3288_GMAC_RMII_CLK_2_5M GRF_CLR_BIT(11)
  177. #define RK3288_GMAC_CLK_125M (GRF_CLR_BIT(12) | GRF_CLR_BIT(13))
  178. #define RK3288_GMAC_CLK_25M (GRF_BIT(12) | GRF_BIT(13))
  179. #define RK3288_GMAC_CLK_2_5M (GRF_CLR_BIT(12) | GRF_BIT(13))
  180. #define RK3288_GMAC_RMII_MODE GRF_BIT(14)
  181. #define RK3288_GMAC_RMII_MODE_CLR GRF_CLR_BIT(14)
  182. /*RK3288_GRF_SOC_CON3*/
  183. #define RK3288_GMAC_TXCLK_DLY_ENABLE GRF_BIT(14)
  184. #define RK3288_GMAC_TXCLK_DLY_DISABLE GRF_CLR_BIT(14)
  185. #define RK3288_GMAC_RXCLK_DLY_ENABLE GRF_BIT(15)
  186. #define RK3288_GMAC_RXCLK_DLY_DISABLE GRF_CLR_BIT(15)
  187. #define RK3288_GMAC_CLK_RX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 7)
  188. #define RK3288_GMAC_CLK_TX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 0)
  189. static void rk3288_set_to_rgmii(struct rk_priv_data *bsp_priv,
  190. int tx_delay, int rx_delay)
  191. {
  192. struct device *dev = &bsp_priv->pdev->dev;
  193. if (IS_ERR(bsp_priv->grf)) {
  194. dev_err(dev, "Missing rockchip,grf property\n");
  195. return;
  196. }
  197. regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1,
  198. RK3288_GMAC_PHY_INTF_SEL_RGMII |
  199. RK3288_GMAC_RMII_MODE_CLR);
  200. regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON3,
  201. RK3288_GMAC_RXCLK_DLY_ENABLE |
  202. RK3288_GMAC_TXCLK_DLY_ENABLE |
  203. RK3288_GMAC_CLK_RX_DL_CFG(rx_delay) |
  204. RK3288_GMAC_CLK_TX_DL_CFG(tx_delay));
  205. }
  206. static void rk3288_set_to_rmii(struct rk_priv_data *bsp_priv)
  207. {
  208. struct device *dev = &bsp_priv->pdev->dev;
  209. if (IS_ERR(bsp_priv->grf)) {
  210. dev_err(dev, "Missing rockchip,grf property\n");
  211. return;
  212. }
  213. regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1,
  214. RK3288_GMAC_PHY_INTF_SEL_RMII | RK3288_GMAC_RMII_MODE);
  215. }
  216. static void rk3288_set_rgmii_speed(struct rk_priv_data *bsp_priv, int speed)
  217. {
  218. struct device *dev = &bsp_priv->pdev->dev;
  219. if (IS_ERR(bsp_priv->grf)) {
  220. dev_err(dev, "Missing rockchip,grf property\n");
  221. return;
  222. }
  223. if (speed == 10)
  224. regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1,
  225. RK3288_GMAC_CLK_2_5M);
  226. else if (speed == 100)
  227. regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1,
  228. RK3288_GMAC_CLK_25M);
  229. else if (speed == 1000)
  230. regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1,
  231. RK3288_GMAC_CLK_125M);
  232. else
  233. dev_err(dev, "unknown speed value for RGMII! speed=%d", speed);
  234. }
  235. static void rk3288_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed)
  236. {
  237. struct device *dev = &bsp_priv->pdev->dev;
  238. if (IS_ERR(bsp_priv->grf)) {
  239. dev_err(dev, "Missing rockchip,grf property\n");
  240. return;
  241. }
  242. if (speed == 10) {
  243. regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1,
  244. RK3288_GMAC_RMII_CLK_2_5M |
  245. RK3288_GMAC_SPEED_10M);
  246. } else if (speed == 100) {
  247. regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1,
  248. RK3288_GMAC_RMII_CLK_25M |
  249. RK3288_GMAC_SPEED_100M);
  250. } else {
  251. dev_err(dev, "unknown speed value for RMII! speed=%d", speed);
  252. }
  253. }
  254. static const struct rk_gmac_ops rk3288_ops = {
  255. .set_to_rgmii = rk3288_set_to_rgmii,
  256. .set_to_rmii = rk3288_set_to_rmii,
  257. .set_rgmii_speed = rk3288_set_rgmii_speed,
  258. .set_rmii_speed = rk3288_set_rmii_speed,
  259. };
  260. #define RK3366_GRF_SOC_CON6 0x0418
  261. #define RK3366_GRF_SOC_CON7 0x041c
  262. /* RK3366_GRF_SOC_CON6 */
  263. #define RK3366_GMAC_PHY_INTF_SEL_RGMII (GRF_BIT(9) | GRF_CLR_BIT(10) | \
  264. GRF_CLR_BIT(11))
  265. #define RK3366_GMAC_PHY_INTF_SEL_RMII (GRF_CLR_BIT(9) | GRF_CLR_BIT(10) | \
  266. GRF_BIT(11))
  267. #define RK3366_GMAC_FLOW_CTRL GRF_BIT(8)
  268. #define RK3366_GMAC_FLOW_CTRL_CLR GRF_CLR_BIT(8)
  269. #define RK3366_GMAC_SPEED_10M GRF_CLR_BIT(7)
  270. #define RK3366_GMAC_SPEED_100M GRF_BIT(7)
  271. #define RK3366_GMAC_RMII_CLK_25M GRF_BIT(3)
  272. #define RK3366_GMAC_RMII_CLK_2_5M GRF_CLR_BIT(3)
  273. #define RK3366_GMAC_CLK_125M (GRF_CLR_BIT(4) | GRF_CLR_BIT(5))
  274. #define RK3366_GMAC_CLK_25M (GRF_BIT(4) | GRF_BIT(5))
  275. #define RK3366_GMAC_CLK_2_5M (GRF_CLR_BIT(4) | GRF_BIT(5))
  276. #define RK3366_GMAC_RMII_MODE GRF_BIT(6)
  277. #define RK3366_GMAC_RMII_MODE_CLR GRF_CLR_BIT(6)
  278. /* RK3366_GRF_SOC_CON7 */
  279. #define RK3366_GMAC_TXCLK_DLY_ENABLE GRF_BIT(7)
  280. #define RK3366_GMAC_TXCLK_DLY_DISABLE GRF_CLR_BIT(7)
  281. #define RK3366_GMAC_RXCLK_DLY_ENABLE GRF_BIT(15)
  282. #define RK3366_GMAC_RXCLK_DLY_DISABLE GRF_CLR_BIT(15)
  283. #define RK3366_GMAC_CLK_RX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 8)
  284. #define RK3366_GMAC_CLK_TX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 0)
  285. static void rk3366_set_to_rgmii(struct rk_priv_data *bsp_priv,
  286. int tx_delay, int rx_delay)
  287. {
  288. struct device *dev = &bsp_priv->pdev->dev;
  289. if (IS_ERR(bsp_priv->grf)) {
  290. dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
  291. return;
  292. }
  293. regmap_write(bsp_priv->grf, RK3366_GRF_SOC_CON6,
  294. RK3366_GMAC_PHY_INTF_SEL_RGMII |
  295. RK3366_GMAC_RMII_MODE_CLR);
  296. regmap_write(bsp_priv->grf, RK3366_GRF_SOC_CON7,
  297. RK3366_GMAC_RXCLK_DLY_ENABLE |
  298. RK3366_GMAC_TXCLK_DLY_ENABLE |
  299. RK3366_GMAC_CLK_RX_DL_CFG(rx_delay) |
  300. RK3366_GMAC_CLK_TX_DL_CFG(tx_delay));
  301. }
  302. static void rk3366_set_to_rmii(struct rk_priv_data *bsp_priv)
  303. {
  304. struct device *dev = &bsp_priv->pdev->dev;
  305. if (IS_ERR(bsp_priv->grf)) {
  306. dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
  307. return;
  308. }
  309. regmap_write(bsp_priv->grf, RK3366_GRF_SOC_CON6,
  310. RK3366_GMAC_PHY_INTF_SEL_RMII | RK3366_GMAC_RMII_MODE);
  311. }
  312. static void rk3366_set_rgmii_speed(struct rk_priv_data *bsp_priv, int speed)
  313. {
  314. struct device *dev = &bsp_priv->pdev->dev;
  315. if (IS_ERR(bsp_priv->grf)) {
  316. dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
  317. return;
  318. }
  319. if (speed == 10)
  320. regmap_write(bsp_priv->grf, RK3366_GRF_SOC_CON6,
  321. RK3366_GMAC_CLK_2_5M);
  322. else if (speed == 100)
  323. regmap_write(bsp_priv->grf, RK3366_GRF_SOC_CON6,
  324. RK3366_GMAC_CLK_25M);
  325. else if (speed == 1000)
  326. regmap_write(bsp_priv->grf, RK3366_GRF_SOC_CON6,
  327. RK3366_GMAC_CLK_125M);
  328. else
  329. dev_err(dev, "unknown speed value for RGMII! speed=%d", speed);
  330. }
  331. static void rk3366_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed)
  332. {
  333. struct device *dev = &bsp_priv->pdev->dev;
  334. if (IS_ERR(bsp_priv->grf)) {
  335. dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
  336. return;
  337. }
  338. if (speed == 10) {
  339. regmap_write(bsp_priv->grf, RK3366_GRF_SOC_CON6,
  340. RK3366_GMAC_RMII_CLK_2_5M |
  341. RK3366_GMAC_SPEED_10M);
  342. } else if (speed == 100) {
  343. regmap_write(bsp_priv->grf, RK3366_GRF_SOC_CON6,
  344. RK3366_GMAC_RMII_CLK_25M |
  345. RK3366_GMAC_SPEED_100M);
  346. } else {
  347. dev_err(dev, "unknown speed value for RMII! speed=%d", speed);
  348. }
  349. }
  350. static const struct rk_gmac_ops rk3366_ops = {
  351. .set_to_rgmii = rk3366_set_to_rgmii,
  352. .set_to_rmii = rk3366_set_to_rmii,
  353. .set_rgmii_speed = rk3366_set_rgmii_speed,
  354. .set_rmii_speed = rk3366_set_rmii_speed,
  355. };
  356. #define RK3368_GRF_SOC_CON15 0x043c
  357. #define RK3368_GRF_SOC_CON16 0x0440
  358. /* RK3368_GRF_SOC_CON15 */
  359. #define RK3368_GMAC_PHY_INTF_SEL_RGMII (GRF_BIT(9) | GRF_CLR_BIT(10) | \
  360. GRF_CLR_BIT(11))
  361. #define RK3368_GMAC_PHY_INTF_SEL_RMII (GRF_CLR_BIT(9) | GRF_CLR_BIT(10) | \
  362. GRF_BIT(11))
  363. #define RK3368_GMAC_FLOW_CTRL GRF_BIT(8)
  364. #define RK3368_GMAC_FLOW_CTRL_CLR GRF_CLR_BIT(8)
  365. #define RK3368_GMAC_SPEED_10M GRF_CLR_BIT(7)
  366. #define RK3368_GMAC_SPEED_100M GRF_BIT(7)
  367. #define RK3368_GMAC_RMII_CLK_25M GRF_BIT(3)
  368. #define RK3368_GMAC_RMII_CLK_2_5M GRF_CLR_BIT(3)
  369. #define RK3368_GMAC_CLK_125M (GRF_CLR_BIT(4) | GRF_CLR_BIT(5))
  370. #define RK3368_GMAC_CLK_25M (GRF_BIT(4) | GRF_BIT(5))
  371. #define RK3368_GMAC_CLK_2_5M (GRF_CLR_BIT(4) | GRF_BIT(5))
  372. #define RK3368_GMAC_RMII_MODE GRF_BIT(6)
  373. #define RK3368_GMAC_RMII_MODE_CLR GRF_CLR_BIT(6)
  374. /* RK3368_GRF_SOC_CON16 */
  375. #define RK3368_GMAC_TXCLK_DLY_ENABLE GRF_BIT(7)
  376. #define RK3368_GMAC_TXCLK_DLY_DISABLE GRF_CLR_BIT(7)
  377. #define RK3368_GMAC_RXCLK_DLY_ENABLE GRF_BIT(15)
  378. #define RK3368_GMAC_RXCLK_DLY_DISABLE GRF_CLR_BIT(15)
  379. #define RK3368_GMAC_CLK_RX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 8)
  380. #define RK3368_GMAC_CLK_TX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 0)
  381. static void rk3368_set_to_rgmii(struct rk_priv_data *bsp_priv,
  382. int tx_delay, int rx_delay)
  383. {
  384. struct device *dev = &bsp_priv->pdev->dev;
  385. if (IS_ERR(bsp_priv->grf)) {
  386. dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
  387. return;
  388. }
  389. regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15,
  390. RK3368_GMAC_PHY_INTF_SEL_RGMII |
  391. RK3368_GMAC_RMII_MODE_CLR);
  392. regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON16,
  393. RK3368_GMAC_RXCLK_DLY_ENABLE |
  394. RK3368_GMAC_TXCLK_DLY_ENABLE |
  395. RK3368_GMAC_CLK_RX_DL_CFG(rx_delay) |
  396. RK3368_GMAC_CLK_TX_DL_CFG(tx_delay));
  397. }
  398. static void rk3368_set_to_rmii(struct rk_priv_data *bsp_priv)
  399. {
  400. struct device *dev = &bsp_priv->pdev->dev;
  401. if (IS_ERR(bsp_priv->grf)) {
  402. dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
  403. return;
  404. }
  405. regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15,
  406. RK3368_GMAC_PHY_INTF_SEL_RMII | RK3368_GMAC_RMII_MODE);
  407. }
  408. static void rk3368_set_rgmii_speed(struct rk_priv_data *bsp_priv, int speed)
  409. {
  410. struct device *dev = &bsp_priv->pdev->dev;
  411. if (IS_ERR(bsp_priv->grf)) {
  412. dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
  413. return;
  414. }
  415. if (speed == 10)
  416. regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15,
  417. RK3368_GMAC_CLK_2_5M);
  418. else if (speed == 100)
  419. regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15,
  420. RK3368_GMAC_CLK_25M);
  421. else if (speed == 1000)
  422. regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15,
  423. RK3368_GMAC_CLK_125M);
  424. else
  425. dev_err(dev, "unknown speed value for RGMII! speed=%d", speed);
  426. }
  427. static void rk3368_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed)
  428. {
  429. struct device *dev = &bsp_priv->pdev->dev;
  430. if (IS_ERR(bsp_priv->grf)) {
  431. dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
  432. return;
  433. }
  434. if (speed == 10) {
  435. regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15,
  436. RK3368_GMAC_RMII_CLK_2_5M |
  437. RK3368_GMAC_SPEED_10M);
  438. } else if (speed == 100) {
  439. regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15,
  440. RK3368_GMAC_RMII_CLK_25M |
  441. RK3368_GMAC_SPEED_100M);
  442. } else {
  443. dev_err(dev, "unknown speed value for RMII! speed=%d", speed);
  444. }
  445. }
  446. static const struct rk_gmac_ops rk3368_ops = {
  447. .set_to_rgmii = rk3368_set_to_rgmii,
  448. .set_to_rmii = rk3368_set_to_rmii,
  449. .set_rgmii_speed = rk3368_set_rgmii_speed,
  450. .set_rmii_speed = rk3368_set_rmii_speed,
  451. };
  452. #define RK3399_GRF_SOC_CON5 0xc214
  453. #define RK3399_GRF_SOC_CON6 0xc218
  454. /* RK3399_GRF_SOC_CON5 */
  455. #define RK3399_GMAC_PHY_INTF_SEL_RGMII (GRF_BIT(9) | GRF_CLR_BIT(10) | \
  456. GRF_CLR_BIT(11))
  457. #define RK3399_GMAC_PHY_INTF_SEL_RMII (GRF_CLR_BIT(9) | GRF_CLR_BIT(10) | \
  458. GRF_BIT(11))
  459. #define RK3399_GMAC_FLOW_CTRL GRF_BIT(8)
  460. #define RK3399_GMAC_FLOW_CTRL_CLR GRF_CLR_BIT(8)
  461. #define RK3399_GMAC_SPEED_10M GRF_CLR_BIT(7)
  462. #define RK3399_GMAC_SPEED_100M GRF_BIT(7)
  463. #define RK3399_GMAC_RMII_CLK_25M GRF_BIT(3)
  464. #define RK3399_GMAC_RMII_CLK_2_5M GRF_CLR_BIT(3)
  465. #define RK3399_GMAC_CLK_125M (GRF_CLR_BIT(4) | GRF_CLR_BIT(5))
  466. #define RK3399_GMAC_CLK_25M (GRF_BIT(4) | GRF_BIT(5))
  467. #define RK3399_GMAC_CLK_2_5M (GRF_CLR_BIT(4) | GRF_BIT(5))
  468. #define RK3399_GMAC_RMII_MODE GRF_BIT(6)
  469. #define RK3399_GMAC_RMII_MODE_CLR GRF_CLR_BIT(6)
  470. /* RK3399_GRF_SOC_CON6 */
  471. #define RK3399_GMAC_TXCLK_DLY_ENABLE GRF_BIT(7)
  472. #define RK3399_GMAC_TXCLK_DLY_DISABLE GRF_CLR_BIT(7)
  473. #define RK3399_GMAC_RXCLK_DLY_ENABLE GRF_BIT(15)
  474. #define RK3399_GMAC_RXCLK_DLY_DISABLE GRF_CLR_BIT(15)
  475. #define RK3399_GMAC_CLK_RX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 8)
  476. #define RK3399_GMAC_CLK_TX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 0)
  477. static void rk3399_set_to_rgmii(struct rk_priv_data *bsp_priv,
  478. int tx_delay, int rx_delay)
  479. {
  480. struct device *dev = &bsp_priv->pdev->dev;
  481. if (IS_ERR(bsp_priv->grf)) {
  482. dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
  483. return;
  484. }
  485. regmap_write(bsp_priv->grf, RK3399_GRF_SOC_CON5,
  486. RK3399_GMAC_PHY_INTF_SEL_RGMII |
  487. RK3399_GMAC_RMII_MODE_CLR);
  488. regmap_write(bsp_priv->grf, RK3399_GRF_SOC_CON6,
  489. RK3399_GMAC_RXCLK_DLY_ENABLE |
  490. RK3399_GMAC_TXCLK_DLY_ENABLE |
  491. RK3399_GMAC_CLK_RX_DL_CFG(rx_delay) |
  492. RK3399_GMAC_CLK_TX_DL_CFG(tx_delay));
  493. }
  494. static void rk3399_set_to_rmii(struct rk_priv_data *bsp_priv)
  495. {
  496. struct device *dev = &bsp_priv->pdev->dev;
  497. if (IS_ERR(bsp_priv->grf)) {
  498. dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
  499. return;
  500. }
  501. regmap_write(bsp_priv->grf, RK3399_GRF_SOC_CON5,
  502. RK3399_GMAC_PHY_INTF_SEL_RMII | RK3399_GMAC_RMII_MODE);
  503. }
  504. static void rk3399_set_rgmii_speed(struct rk_priv_data *bsp_priv, int speed)
  505. {
  506. struct device *dev = &bsp_priv->pdev->dev;
  507. if (IS_ERR(bsp_priv->grf)) {
  508. dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
  509. return;
  510. }
  511. if (speed == 10)
  512. regmap_write(bsp_priv->grf, RK3399_GRF_SOC_CON5,
  513. RK3399_GMAC_CLK_2_5M);
  514. else if (speed == 100)
  515. regmap_write(bsp_priv->grf, RK3399_GRF_SOC_CON5,
  516. RK3399_GMAC_CLK_25M);
  517. else if (speed == 1000)
  518. regmap_write(bsp_priv->grf, RK3399_GRF_SOC_CON5,
  519. RK3399_GMAC_CLK_125M);
  520. else
  521. dev_err(dev, "unknown speed value for RGMII! speed=%d", speed);
  522. }
  523. static void rk3399_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed)
  524. {
  525. struct device *dev = &bsp_priv->pdev->dev;
  526. if (IS_ERR(bsp_priv->grf)) {
  527. dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
  528. return;
  529. }
  530. if (speed == 10) {
  531. regmap_write(bsp_priv->grf, RK3399_GRF_SOC_CON5,
  532. RK3399_GMAC_RMII_CLK_2_5M |
  533. RK3399_GMAC_SPEED_10M);
  534. } else if (speed == 100) {
  535. regmap_write(bsp_priv->grf, RK3399_GRF_SOC_CON5,
  536. RK3399_GMAC_RMII_CLK_25M |
  537. RK3399_GMAC_SPEED_100M);
  538. } else {
  539. dev_err(dev, "unknown speed value for RMII! speed=%d", speed);
  540. }
  541. }
  542. static const struct rk_gmac_ops rk3399_ops = {
  543. .set_to_rgmii = rk3399_set_to_rgmii,
  544. .set_to_rmii = rk3399_set_to_rmii,
  545. .set_rgmii_speed = rk3399_set_rgmii_speed,
  546. .set_rmii_speed = rk3399_set_rmii_speed,
  547. };
  548. static int gmac_clk_init(struct rk_priv_data *bsp_priv)
  549. {
  550. struct device *dev = &bsp_priv->pdev->dev;
  551. bsp_priv->clk_enabled = false;
  552. bsp_priv->mac_clk_rx = devm_clk_get(dev, "mac_clk_rx");
  553. if (IS_ERR(bsp_priv->mac_clk_rx))
  554. dev_err(dev, "cannot get clock %s\n",
  555. "mac_clk_rx");
  556. bsp_priv->mac_clk_tx = devm_clk_get(dev, "mac_clk_tx");
  557. if (IS_ERR(bsp_priv->mac_clk_tx))
  558. dev_err(dev, "cannot get clock %s\n",
  559. "mac_clk_tx");
  560. bsp_priv->aclk_mac = devm_clk_get(dev, "aclk_mac");
  561. if (IS_ERR(bsp_priv->aclk_mac))
  562. dev_err(dev, "cannot get clock %s\n",
  563. "aclk_mac");
  564. bsp_priv->pclk_mac = devm_clk_get(dev, "pclk_mac");
  565. if (IS_ERR(bsp_priv->pclk_mac))
  566. dev_err(dev, "cannot get clock %s\n",
  567. "pclk_mac");
  568. bsp_priv->clk_mac = devm_clk_get(dev, "stmmaceth");
  569. if (IS_ERR(bsp_priv->clk_mac))
  570. dev_err(dev, "cannot get clock %s\n",
  571. "stmmaceth");
  572. if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) {
  573. bsp_priv->clk_mac_ref = devm_clk_get(dev, "clk_mac_ref");
  574. if (IS_ERR(bsp_priv->clk_mac_ref))
  575. dev_err(dev, "cannot get clock %s\n",
  576. "clk_mac_ref");
  577. if (!bsp_priv->clock_input) {
  578. bsp_priv->clk_mac_refout =
  579. devm_clk_get(dev, "clk_mac_refout");
  580. if (IS_ERR(bsp_priv->clk_mac_refout))
  581. dev_err(dev, "cannot get clock %s\n",
  582. "clk_mac_refout");
  583. }
  584. }
  585. if (bsp_priv->clock_input) {
  586. dev_info(dev, "clock input from PHY\n");
  587. } else {
  588. if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII)
  589. clk_set_rate(bsp_priv->clk_mac, 50000000);
  590. }
  591. return 0;
  592. }
  593. static int gmac_clk_enable(struct rk_priv_data *bsp_priv, bool enable)
  594. {
  595. int phy_iface = bsp_priv->phy_iface;
  596. if (enable) {
  597. if (!bsp_priv->clk_enabled) {
  598. if (phy_iface == PHY_INTERFACE_MODE_RMII) {
  599. if (!IS_ERR(bsp_priv->mac_clk_rx))
  600. clk_prepare_enable(
  601. bsp_priv->mac_clk_rx);
  602. if (!IS_ERR(bsp_priv->clk_mac_ref))
  603. clk_prepare_enable(
  604. bsp_priv->clk_mac_ref);
  605. if (!IS_ERR(bsp_priv->clk_mac_refout))
  606. clk_prepare_enable(
  607. bsp_priv->clk_mac_refout);
  608. }
  609. if (!IS_ERR(bsp_priv->aclk_mac))
  610. clk_prepare_enable(bsp_priv->aclk_mac);
  611. if (!IS_ERR(bsp_priv->pclk_mac))
  612. clk_prepare_enable(bsp_priv->pclk_mac);
  613. if (!IS_ERR(bsp_priv->mac_clk_tx))
  614. clk_prepare_enable(bsp_priv->mac_clk_tx);
  615. /**
  616. * if (!IS_ERR(bsp_priv->clk_mac))
  617. * clk_prepare_enable(bsp_priv->clk_mac);
  618. */
  619. mdelay(5);
  620. bsp_priv->clk_enabled = true;
  621. }
  622. } else {
  623. if (bsp_priv->clk_enabled) {
  624. if (phy_iface == PHY_INTERFACE_MODE_RMII) {
  625. if (!IS_ERR(bsp_priv->mac_clk_rx))
  626. clk_disable_unprepare(
  627. bsp_priv->mac_clk_rx);
  628. if (!IS_ERR(bsp_priv->clk_mac_ref))
  629. clk_disable_unprepare(
  630. bsp_priv->clk_mac_ref);
  631. if (!IS_ERR(bsp_priv->clk_mac_refout))
  632. clk_disable_unprepare(
  633. bsp_priv->clk_mac_refout);
  634. }
  635. if (!IS_ERR(bsp_priv->aclk_mac))
  636. clk_disable_unprepare(bsp_priv->aclk_mac);
  637. if (!IS_ERR(bsp_priv->pclk_mac))
  638. clk_disable_unprepare(bsp_priv->pclk_mac);
  639. if (!IS_ERR(bsp_priv->mac_clk_tx))
  640. clk_disable_unprepare(bsp_priv->mac_clk_tx);
  641. /**
  642. * if (!IS_ERR(bsp_priv->clk_mac))
  643. * clk_disable_unprepare(bsp_priv->clk_mac);
  644. */
  645. bsp_priv->clk_enabled = false;
  646. }
  647. }
  648. return 0;
  649. }
  650. static int phy_power_on(struct rk_priv_data *bsp_priv, bool enable)
  651. {
  652. struct regulator *ldo = bsp_priv->regulator;
  653. int ret;
  654. struct device *dev = &bsp_priv->pdev->dev;
  655. if (!ldo) {
  656. dev_err(dev, "no regulator found\n");
  657. return -1;
  658. }
  659. if (enable) {
  660. ret = regulator_enable(ldo);
  661. if (ret)
  662. dev_err(dev, "fail to enable phy-supply\n");
  663. } else {
  664. ret = regulator_disable(ldo);
  665. if (ret)
  666. dev_err(dev, "fail to disable phy-supply\n");
  667. }
  668. return 0;
  669. }
  670. static struct rk_priv_data *rk_gmac_setup(struct platform_device *pdev,
  671. const struct rk_gmac_ops *ops)
  672. {
  673. struct rk_priv_data *bsp_priv;
  674. struct device *dev = &pdev->dev;
  675. int ret;
  676. const char *strings = NULL;
  677. int value;
  678. bsp_priv = devm_kzalloc(dev, sizeof(*bsp_priv), GFP_KERNEL);
  679. if (!bsp_priv)
  680. return ERR_PTR(-ENOMEM);
  681. bsp_priv->phy_iface = of_get_phy_mode(dev->of_node);
  682. bsp_priv->ops = ops;
  683. bsp_priv->regulator = devm_regulator_get_optional(dev, "phy");
  684. if (IS_ERR(bsp_priv->regulator)) {
  685. if (PTR_ERR(bsp_priv->regulator) == -EPROBE_DEFER) {
  686. dev_err(dev, "phy regulator is not available yet, deferred probing\n");
  687. return ERR_PTR(-EPROBE_DEFER);
  688. }
  689. dev_err(dev, "no regulator found\n");
  690. bsp_priv->regulator = NULL;
  691. }
  692. ret = of_property_read_string(dev->of_node, "clock_in_out", &strings);
  693. if (ret) {
  694. dev_err(dev, "Can not read property: clock_in_out.\n");
  695. bsp_priv->clock_input = true;
  696. } else {
  697. dev_info(dev, "clock input or output? (%s).\n",
  698. strings);
  699. if (!strcmp(strings, "input"))
  700. bsp_priv->clock_input = true;
  701. else
  702. bsp_priv->clock_input = false;
  703. }
  704. ret = of_property_read_u32(dev->of_node, "tx_delay", &value);
  705. if (ret) {
  706. bsp_priv->tx_delay = 0x30;
  707. dev_err(dev, "Can not read property: tx_delay.");
  708. dev_err(dev, "set tx_delay to 0x%x\n",
  709. bsp_priv->tx_delay);
  710. } else {
  711. dev_info(dev, "TX delay(0x%x).\n", value);
  712. bsp_priv->tx_delay = value;
  713. }
  714. ret = of_property_read_u32(dev->of_node, "rx_delay", &value);
  715. if (ret) {
  716. bsp_priv->rx_delay = 0x10;
  717. dev_err(dev, "Can not read property: rx_delay.");
  718. dev_err(dev, "set rx_delay to 0x%x\n",
  719. bsp_priv->rx_delay);
  720. } else {
  721. dev_info(dev, "RX delay(0x%x).\n", value);
  722. bsp_priv->rx_delay = value;
  723. }
  724. bsp_priv->grf = syscon_regmap_lookup_by_phandle(dev->of_node,
  725. "rockchip,grf");
  726. bsp_priv->pdev = pdev;
  727. gmac_clk_init(bsp_priv);
  728. return bsp_priv;
  729. }
  730. static int rk_gmac_powerup(struct rk_priv_data *bsp_priv)
  731. {
  732. int ret;
  733. struct device *dev = &bsp_priv->pdev->dev;
  734. /*rmii or rgmii*/
  735. if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RGMII) {
  736. dev_info(dev, "init for RGMII\n");
  737. bsp_priv->ops->set_to_rgmii(bsp_priv, bsp_priv->tx_delay,
  738. bsp_priv->rx_delay);
  739. } else if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) {
  740. dev_info(dev, "init for RMII\n");
  741. bsp_priv->ops->set_to_rmii(bsp_priv);
  742. } else {
  743. dev_err(dev, "NO interface defined!\n");
  744. }
  745. ret = phy_power_on(bsp_priv, true);
  746. if (ret)
  747. return ret;
  748. ret = gmac_clk_enable(bsp_priv, true);
  749. if (ret)
  750. return ret;
  751. pm_runtime_enable(dev);
  752. pm_runtime_get_sync(dev);
  753. return 0;
  754. }
  755. static void rk_gmac_powerdown(struct rk_priv_data *gmac)
  756. {
  757. struct device *dev = &gmac->pdev->dev;
  758. pm_runtime_put_sync(dev);
  759. pm_runtime_disable(dev);
  760. phy_power_on(gmac, false);
  761. gmac_clk_enable(gmac, false);
  762. }
  763. static int rk_gmac_init(struct platform_device *pdev, void *priv)
  764. {
  765. struct rk_priv_data *bsp_priv = priv;
  766. return rk_gmac_powerup(bsp_priv);
  767. }
  768. static void rk_gmac_exit(struct platform_device *pdev, void *priv)
  769. {
  770. struct rk_priv_data *bsp_priv = priv;
  771. rk_gmac_powerdown(bsp_priv);
  772. }
  773. static void rk_gmac_suspend(struct platform_device *pdev, void *priv)
  774. {
  775. struct rk_priv_data *bsp_priv = priv;
  776. /* Keep the PHY up if we use Wake-on-Lan. */
  777. if (device_may_wakeup(&pdev->dev))
  778. return;
  779. rk_gmac_powerdown(bsp_priv);
  780. bsp_priv->suspended = true;
  781. }
  782. static void rk_gmac_resume(struct platform_device *pdev, void *priv)
  783. {
  784. struct rk_priv_data *bsp_priv = priv;
  785. /* The PHY was up for Wake-on-Lan. */
  786. if (!bsp_priv->suspended)
  787. return;
  788. rk_gmac_powerup(bsp_priv);
  789. bsp_priv->suspended = false;
  790. }
  791. static void rk_fix_speed(void *priv, unsigned int speed)
  792. {
  793. struct rk_priv_data *bsp_priv = priv;
  794. struct device *dev = &bsp_priv->pdev->dev;
  795. if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RGMII)
  796. bsp_priv->ops->set_rgmii_speed(bsp_priv, speed);
  797. else if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII)
  798. bsp_priv->ops->set_rmii_speed(bsp_priv, speed);
  799. else
  800. dev_err(dev, "unsupported interface %d", bsp_priv->phy_iface);
  801. }
  802. static int rk_gmac_probe(struct platform_device *pdev)
  803. {
  804. struct plat_stmmacenet_data *plat_dat;
  805. struct stmmac_resources stmmac_res;
  806. const struct rk_gmac_ops *data;
  807. int ret;
  808. data = of_device_get_match_data(&pdev->dev);
  809. if (!data) {
  810. dev_err(&pdev->dev, "no of match data provided\n");
  811. return -EINVAL;
  812. }
  813. ret = stmmac_get_platform_resources(pdev, &stmmac_res);
  814. if (ret)
  815. return ret;
  816. plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  817. if (IS_ERR(plat_dat))
  818. return PTR_ERR(plat_dat);
  819. plat_dat->has_gmac = true;
  820. plat_dat->init = rk_gmac_init;
  821. plat_dat->exit = rk_gmac_exit;
  822. plat_dat->fix_mac_speed = rk_fix_speed;
  823. plat_dat->suspend = rk_gmac_suspend;
  824. plat_dat->resume = rk_gmac_resume;
  825. plat_dat->bsp_priv = rk_gmac_setup(pdev, data);
  826. if (IS_ERR(plat_dat->bsp_priv)) {
  827. ret = PTR_ERR(plat_dat->bsp_priv);
  828. goto err_remove_config_dt;
  829. }
  830. ret = rk_gmac_init(pdev, plat_dat->bsp_priv);
  831. if (ret)
  832. goto err_remove_config_dt;
  833. ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  834. if (ret)
  835. goto err_gmac_exit;
  836. return 0;
  837. err_gmac_exit:
  838. rk_gmac_exit(pdev, plat_dat->bsp_priv);
  839. err_remove_config_dt:
  840. stmmac_remove_config_dt(pdev, plat_dat);
  841. return ret;
  842. }
  843. static const struct of_device_id rk_gmac_dwmac_match[] = {
  844. { .compatible = "rockchip,rk3228-gmac", .data = &rk3228_ops },
  845. { .compatible = "rockchip,rk3288-gmac", .data = &rk3288_ops },
  846. { .compatible = "rockchip,rk3366-gmac", .data = &rk3366_ops },
  847. { .compatible = "rockchip,rk3368-gmac", .data = &rk3368_ops },
  848. { .compatible = "rockchip,rk3399-gmac", .data = &rk3399_ops },
  849. { }
  850. };
  851. MODULE_DEVICE_TABLE(of, rk_gmac_dwmac_match);
  852. static struct platform_driver rk_gmac_dwmac_driver = {
  853. .probe = rk_gmac_probe,
  854. .remove = stmmac_pltfr_remove,
  855. .driver = {
  856. .name = "rk_gmac-dwmac",
  857. .pm = &stmmac_pltfr_pm_ops,
  858. .of_match_table = rk_gmac_dwmac_match,
  859. },
  860. };
  861. module_platform_driver(rk_gmac_dwmac_driver);
  862. MODULE_AUTHOR("Chen-Zhi (Roger Chen) <roger.chen@rock-chips.com>");
  863. MODULE_DESCRIPTION("Rockchip RK3288 DWMAC specific glue layer");
  864. MODULE_LICENSE("GPL");