stmmac_platform.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*******************************************************************************
  2. This contains the functions to handle the platform driver.
  3. Copyright (C) 2007-2011 STMicroelectronics Ltd
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. The full GNU General Public License is included in this distribution in
  12. the file called "COPYING".
  13. Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
  14. *******************************************************************************/
  15. #include <linux/platform_device.h>
  16. #include <linux/module.h>
  17. #include <linux/io.h>
  18. #include <linux/of.h>
  19. #include <linux/of_net.h>
  20. #include <linux/of_device.h>
  21. #include <linux/of_mdio.h>
  22. #include "stmmac.h"
  23. #include "stmmac_platform.h"
  24. #ifdef CONFIG_OF
  25. /**
  26. * dwmac1000_validate_mcast_bins - validates the number of Multicast filter bins
  27. * @mcast_bins: Multicast filtering bins
  28. * Description:
  29. * this function validates the number of Multicast filtering bins specified
  30. * by the configuration through the device tree. The Synopsys GMAC supports
  31. * 64 bins, 128 bins, or 256 bins. "bins" refer to the division of CRC
  32. * number space. 64 bins correspond to 6 bits of the CRC, 128 corresponds
  33. * to 7 bits, and 256 refers to 8 bits of the CRC. Any other setting is
  34. * invalid and will cause the filtering algorithm to use Multicast
  35. * promiscuous mode.
  36. */
  37. static int dwmac1000_validate_mcast_bins(int mcast_bins)
  38. {
  39. int x = mcast_bins;
  40. switch (x) {
  41. case HASH_TABLE_SIZE:
  42. case 128:
  43. case 256:
  44. break;
  45. default:
  46. x = 0;
  47. pr_info("Hash table entries set to unexpected value %d",
  48. mcast_bins);
  49. break;
  50. }
  51. return x;
  52. }
  53. /**
  54. * dwmac1000_validate_ucast_entries - validate the Unicast address entries
  55. * @ucast_entries: number of Unicast address entries
  56. * Description:
  57. * This function validates the number of Unicast address entries supported
  58. * by a particular Synopsys 10/100/1000 controller. The Synopsys controller
  59. * supports 1, 32, 64, or 128 Unicast filter entries for it's Unicast filter
  60. * logic. This function validates a valid, supported configuration is
  61. * selected, and defaults to 1 Unicast address if an unsupported
  62. * configuration is selected.
  63. */
  64. static int dwmac1000_validate_ucast_entries(int ucast_entries)
  65. {
  66. int x = ucast_entries;
  67. switch (x) {
  68. case 1:
  69. case 32:
  70. case 64:
  71. case 128:
  72. break;
  73. default:
  74. x = 1;
  75. pr_info("Unicast table entries set to unexpected value %d\n",
  76. ucast_entries);
  77. break;
  78. }
  79. return x;
  80. }
  81. /**
  82. * stmmac_axi_setup - parse DT parameters for programming the AXI register
  83. * @pdev: platform device
  84. * @priv: driver private struct.
  85. * Description:
  86. * if required, from device-tree the AXI internal register can be tuned
  87. * by using platform parameters.
  88. */
  89. static struct stmmac_axi *stmmac_axi_setup(struct platform_device *pdev)
  90. {
  91. struct device_node *np;
  92. struct stmmac_axi *axi;
  93. np = of_parse_phandle(pdev->dev.of_node, "snps,axi-config", 0);
  94. if (!np)
  95. return NULL;
  96. axi = devm_kzalloc(&pdev->dev, sizeof(*axi), GFP_KERNEL);
  97. if (!axi) {
  98. of_node_put(np);
  99. return ERR_PTR(-ENOMEM);
  100. }
  101. axi->axi_lpi_en = of_property_read_bool(np, "snps,lpi_en");
  102. axi->axi_xit_frm = of_property_read_bool(np, "snps,xit_frm");
  103. axi->axi_kbbe = of_property_read_bool(np, "snps,axi_kbbe");
  104. axi->axi_fb = of_property_read_bool(np, "snps,axi_fb");
  105. axi->axi_mb = of_property_read_bool(np, "snps,axi_mb");
  106. axi->axi_rb = of_property_read_bool(np, "snps,axi_rb");
  107. if (of_property_read_u32(np, "snps,wr_osr_lmt", &axi->axi_wr_osr_lmt))
  108. axi->axi_wr_osr_lmt = 1;
  109. if (of_property_read_u32(np, "snps,rd_osr_lmt", &axi->axi_rd_osr_lmt))
  110. axi->axi_rd_osr_lmt = 1;
  111. of_property_read_u32_array(np, "snps,blen", axi->axi_blen, AXI_BLEN);
  112. of_node_put(np);
  113. return axi;
  114. }
  115. /**
  116. * stmmac_mtl_setup - parse DT parameters for multiple queues configuration
  117. * @pdev: platform device
  118. */
  119. static void stmmac_mtl_setup(struct platform_device *pdev,
  120. struct plat_stmmacenet_data *plat)
  121. {
  122. struct device_node *q_node;
  123. struct device_node *rx_node;
  124. struct device_node *tx_node;
  125. u8 queue = 0;
  126. /* For backwards-compatibility with device trees that don't have any
  127. * snps,mtl-rx-config or snps,mtl-tx-config properties, we fall back
  128. * to one RX and TX queues each.
  129. */
  130. plat->rx_queues_to_use = 1;
  131. plat->tx_queues_to_use = 1;
  132. rx_node = of_parse_phandle(pdev->dev.of_node, "snps,mtl-rx-config", 0);
  133. if (!rx_node)
  134. return;
  135. tx_node = of_parse_phandle(pdev->dev.of_node, "snps,mtl-tx-config", 0);
  136. if (!tx_node) {
  137. of_node_put(rx_node);
  138. return;
  139. }
  140. /* Processing RX queues common config */
  141. if (of_property_read_u8(rx_node, "snps,rx-queues-to-use",
  142. &plat->rx_queues_to_use))
  143. plat->rx_queues_to_use = 1;
  144. if (of_property_read_bool(rx_node, "snps,rx-sched-sp"))
  145. plat->rx_sched_algorithm = MTL_RX_ALGORITHM_SP;
  146. else if (of_property_read_bool(rx_node, "snps,rx-sched-wsp"))
  147. plat->rx_sched_algorithm = MTL_RX_ALGORITHM_WSP;
  148. else
  149. plat->rx_sched_algorithm = MTL_RX_ALGORITHM_SP;
  150. /* Processing individual RX queue config */
  151. for_each_child_of_node(rx_node, q_node) {
  152. if (queue >= plat->rx_queues_to_use)
  153. break;
  154. if (of_property_read_bool(q_node, "snps,dcb-algorithm"))
  155. plat->rx_queues_cfg[queue].mode_to_use = MTL_QUEUE_DCB;
  156. else if (of_property_read_bool(q_node, "snps,avb-algorithm"))
  157. plat->rx_queues_cfg[queue].mode_to_use = MTL_QUEUE_AVB;
  158. else
  159. plat->rx_queues_cfg[queue].mode_to_use = MTL_QUEUE_DCB;
  160. if (of_property_read_u8(q_node, "snps,map-to-dma-channel",
  161. &plat->rx_queues_cfg[queue].chan))
  162. plat->rx_queues_cfg[queue].chan = queue;
  163. /* TODO: Dynamic mapping to be included in the future */
  164. if (of_property_read_u32(q_node, "snps,priority",
  165. &plat->rx_queues_cfg[queue].prio)) {
  166. plat->rx_queues_cfg[queue].prio = 0;
  167. plat->rx_queues_cfg[queue].use_prio = false;
  168. } else {
  169. plat->rx_queues_cfg[queue].use_prio = true;
  170. }
  171. /* RX queue specific packet type routing */
  172. if (of_property_read_bool(q_node, "snps,route-avcp"))
  173. plat->rx_queues_cfg[queue].pkt_route = PACKET_AVCPQ;
  174. else if (of_property_read_bool(q_node, "snps,route-ptp"))
  175. plat->rx_queues_cfg[queue].pkt_route = PACKET_PTPQ;
  176. else if (of_property_read_bool(q_node, "snps,route-dcbcp"))
  177. plat->rx_queues_cfg[queue].pkt_route = PACKET_DCBCPQ;
  178. else if (of_property_read_bool(q_node, "snps,route-up"))
  179. plat->rx_queues_cfg[queue].pkt_route = PACKET_UPQ;
  180. else if (of_property_read_bool(q_node, "snps,route-multi-broad"))
  181. plat->rx_queues_cfg[queue].pkt_route = PACKET_MCBCQ;
  182. else
  183. plat->rx_queues_cfg[queue].pkt_route = 0x0;
  184. queue++;
  185. }
  186. /* Processing TX queues common config */
  187. if (of_property_read_u8(tx_node, "snps,tx-queues-to-use",
  188. &plat->tx_queues_to_use))
  189. plat->tx_queues_to_use = 1;
  190. if (of_property_read_bool(tx_node, "snps,tx-sched-wrr"))
  191. plat->tx_sched_algorithm = MTL_TX_ALGORITHM_WRR;
  192. else if (of_property_read_bool(tx_node, "snps,tx-sched-wfq"))
  193. plat->tx_sched_algorithm = MTL_TX_ALGORITHM_WFQ;
  194. else if (of_property_read_bool(tx_node, "snps,tx-sched-dwrr"))
  195. plat->tx_sched_algorithm = MTL_TX_ALGORITHM_DWRR;
  196. else if (of_property_read_bool(tx_node, "snps,tx-sched-sp"))
  197. plat->tx_sched_algorithm = MTL_TX_ALGORITHM_SP;
  198. else
  199. plat->tx_sched_algorithm = MTL_TX_ALGORITHM_SP;
  200. queue = 0;
  201. /* Processing individual TX queue config */
  202. for_each_child_of_node(tx_node, q_node) {
  203. if (queue >= plat->tx_queues_to_use)
  204. break;
  205. if (of_property_read_u8(q_node, "snps,weight",
  206. &plat->tx_queues_cfg[queue].weight))
  207. plat->tx_queues_cfg[queue].weight = 0x10 + queue;
  208. if (of_property_read_bool(q_node, "snps,dcb-algorithm")) {
  209. plat->tx_queues_cfg[queue].mode_to_use = MTL_QUEUE_DCB;
  210. } else if (of_property_read_bool(q_node,
  211. "snps,avb-algorithm")) {
  212. plat->tx_queues_cfg[queue].mode_to_use = MTL_QUEUE_AVB;
  213. /* Credit Base Shaper parameters used by AVB */
  214. if (of_property_read_u32(q_node, "snps,send_slope",
  215. &plat->tx_queues_cfg[queue].send_slope))
  216. plat->tx_queues_cfg[queue].send_slope = 0x0;
  217. if (of_property_read_u32(q_node, "snps,idle_slope",
  218. &plat->tx_queues_cfg[queue].idle_slope))
  219. plat->tx_queues_cfg[queue].idle_slope = 0x0;
  220. if (of_property_read_u32(q_node, "snps,high_credit",
  221. &plat->tx_queues_cfg[queue].high_credit))
  222. plat->tx_queues_cfg[queue].high_credit = 0x0;
  223. if (of_property_read_u32(q_node, "snps,low_credit",
  224. &plat->tx_queues_cfg[queue].low_credit))
  225. plat->tx_queues_cfg[queue].low_credit = 0x0;
  226. } else {
  227. plat->tx_queues_cfg[queue].mode_to_use = MTL_QUEUE_DCB;
  228. }
  229. if (of_property_read_u32(q_node, "snps,priority",
  230. &plat->tx_queues_cfg[queue].prio)) {
  231. plat->tx_queues_cfg[queue].prio = 0;
  232. plat->tx_queues_cfg[queue].use_prio = false;
  233. } else {
  234. plat->tx_queues_cfg[queue].use_prio = true;
  235. }
  236. queue++;
  237. }
  238. of_node_put(rx_node);
  239. of_node_put(tx_node);
  240. of_node_put(q_node);
  241. }
  242. /**
  243. * stmmac_dt_phy - parse device-tree driver parameters to allocate PHY resources
  244. * @plat: driver data platform structure
  245. * @np: device tree node
  246. * @dev: device pointer
  247. * Description:
  248. * The mdio bus will be allocated in case of a phy transceiver is on board;
  249. * it will be NULL if the fixed-link is configured.
  250. * If there is the "snps,dwmac-mdio" sub-node the mdio will be allocated
  251. * in any case (for DSA, mdio must be registered even if fixed-link).
  252. * The table below sums the supported configurations:
  253. * -------------------------------
  254. * snps,phy-addr | Y
  255. * -------------------------------
  256. * phy-handle | Y
  257. * -------------------------------
  258. * fixed-link | N
  259. * -------------------------------
  260. * snps,dwmac-mdio |
  261. * even if | Y
  262. * fixed-link |
  263. * -------------------------------
  264. *
  265. * It returns 0 in case of success otherwise -ENODEV.
  266. */
  267. static int stmmac_dt_phy(struct plat_stmmacenet_data *plat,
  268. struct device_node *np, struct device *dev)
  269. {
  270. bool mdio = true;
  271. /* If phy-handle property is passed from DT, use it as the PHY */
  272. plat->phy_node = of_parse_phandle(np, "phy-handle", 0);
  273. if (plat->phy_node)
  274. dev_dbg(dev, "Found phy-handle subnode\n");
  275. /* If phy-handle is not specified, check if we have a fixed-phy */
  276. if (!plat->phy_node && of_phy_is_fixed_link(np)) {
  277. if ((of_phy_register_fixed_link(np) < 0))
  278. return -ENODEV;
  279. dev_dbg(dev, "Found fixed-link subnode\n");
  280. plat->phy_node = of_node_get(np);
  281. mdio = false;
  282. }
  283. /* exception for dwmac-dwc-qos-eth glue logic */
  284. if (of_device_is_compatible(np, "snps,dwc-qos-ethernet-4.10")) {
  285. plat->mdio_node = of_get_child_by_name(np, "mdio");
  286. } else {
  287. /**
  288. * If snps,dwmac-mdio is passed from DT, always register
  289. * the MDIO
  290. */
  291. for_each_child_of_node(np, plat->mdio_node) {
  292. if (of_device_is_compatible(plat->mdio_node,
  293. "snps,dwmac-mdio"))
  294. break;
  295. }
  296. }
  297. if (plat->mdio_node) {
  298. dev_dbg(dev, "Found MDIO subnode\n");
  299. mdio = true;
  300. }
  301. if (mdio)
  302. plat->mdio_bus_data =
  303. devm_kzalloc(dev, sizeof(struct stmmac_mdio_bus_data),
  304. GFP_KERNEL);
  305. return 0;
  306. }
  307. /**
  308. * stmmac_probe_config_dt - parse device-tree driver parameters
  309. * @pdev: platform_device structure
  310. * @mac: MAC address to use
  311. * Description:
  312. * this function is to read the driver parameters from device-tree and
  313. * set some private fields that will be used by the main at runtime.
  314. */
  315. struct plat_stmmacenet_data *
  316. stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
  317. {
  318. struct device_node *np = pdev->dev.of_node;
  319. struct plat_stmmacenet_data *plat;
  320. struct stmmac_dma_cfg *dma_cfg;
  321. plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
  322. if (!plat)
  323. return ERR_PTR(-ENOMEM);
  324. *mac = of_get_mac_address(np);
  325. plat->interface = of_get_phy_mode(np);
  326. /* Get max speed of operation from device tree */
  327. if (of_property_read_u32(np, "max-speed", &plat->max_speed))
  328. plat->max_speed = -1;
  329. plat->bus_id = of_alias_get_id(np, "ethernet");
  330. if (plat->bus_id < 0)
  331. plat->bus_id = 0;
  332. /* Default to phy auto-detection */
  333. plat->phy_addr = -1;
  334. /* "snps,phy-addr" is not a standard property. Mark it as deprecated
  335. * and warn of its use. Remove this when phy node support is added.
  336. */
  337. if (of_property_read_u32(np, "snps,phy-addr", &plat->phy_addr) == 0)
  338. dev_warn(&pdev->dev, "snps,phy-addr property is deprecated\n");
  339. /* To Configure PHY by using all device-tree supported properties */
  340. if (stmmac_dt_phy(plat, np, &pdev->dev))
  341. return ERR_PTR(-ENODEV);
  342. of_property_read_u32(np, "tx-fifo-depth", &plat->tx_fifo_size);
  343. of_property_read_u32(np, "rx-fifo-depth", &plat->rx_fifo_size);
  344. plat->force_sf_dma_mode =
  345. of_property_read_bool(np, "snps,force_sf_dma_mode");
  346. plat->en_tx_lpi_clockgating =
  347. of_property_read_bool(np, "snps,en-tx-lpi-clockgating");
  348. /* Set the maxmtu to a default of JUMBO_LEN in case the
  349. * parameter is not present in the device tree.
  350. */
  351. plat->maxmtu = JUMBO_LEN;
  352. /* Set default value for multicast hash bins */
  353. plat->multicast_filter_bins = HASH_TABLE_SIZE;
  354. /* Set default value for unicast filter entries */
  355. plat->unicast_filter_entries = 1;
  356. /*
  357. * Currently only the properties needed on SPEAr600
  358. * are provided. All other properties should be added
  359. * once needed on other platforms.
  360. */
  361. if (of_device_is_compatible(np, "st,spear600-gmac") ||
  362. of_device_is_compatible(np, "snps,dwmac-3.50a") ||
  363. of_device_is_compatible(np, "snps,dwmac-3.70a") ||
  364. of_device_is_compatible(np, "snps,dwmac")) {
  365. /* Note that the max-frame-size parameter as defined in the
  366. * ePAPR v1.1 spec is defined as max-frame-size, it's
  367. * actually used as the IEEE definition of MAC Client
  368. * data, or MTU. The ePAPR specification is confusing as
  369. * the definition is max-frame-size, but usage examples
  370. * are clearly MTUs
  371. */
  372. of_property_read_u32(np, "max-frame-size", &plat->maxmtu);
  373. of_property_read_u32(np, "snps,multicast-filter-bins",
  374. &plat->multicast_filter_bins);
  375. of_property_read_u32(np, "snps,perfect-filter-entries",
  376. &plat->unicast_filter_entries);
  377. plat->unicast_filter_entries = dwmac1000_validate_ucast_entries(
  378. plat->unicast_filter_entries);
  379. plat->multicast_filter_bins = dwmac1000_validate_mcast_bins(
  380. plat->multicast_filter_bins);
  381. plat->has_gmac = 1;
  382. plat->pmt = 1;
  383. }
  384. if (of_device_is_compatible(np, "snps,dwmac-4.00") ||
  385. of_device_is_compatible(np, "snps,dwmac-4.10a")) {
  386. plat->has_gmac4 = 1;
  387. plat->has_gmac = 0;
  388. plat->pmt = 1;
  389. plat->tso_en = of_property_read_bool(np, "snps,tso");
  390. }
  391. if (of_device_is_compatible(np, "snps,dwmac-3.610") ||
  392. of_device_is_compatible(np, "snps,dwmac-3.710")) {
  393. plat->enh_desc = 1;
  394. plat->bugged_jumbo = 1;
  395. plat->force_sf_dma_mode = 1;
  396. }
  397. dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*dma_cfg),
  398. GFP_KERNEL);
  399. if (!dma_cfg) {
  400. stmmac_remove_config_dt(pdev, plat);
  401. return ERR_PTR(-ENOMEM);
  402. }
  403. plat->dma_cfg = dma_cfg;
  404. of_property_read_u32(np, "snps,pbl", &dma_cfg->pbl);
  405. if (!dma_cfg->pbl)
  406. dma_cfg->pbl = DEFAULT_DMA_PBL;
  407. of_property_read_u32(np, "snps,txpbl", &dma_cfg->txpbl);
  408. of_property_read_u32(np, "snps,rxpbl", &dma_cfg->rxpbl);
  409. dma_cfg->pblx8 = !of_property_read_bool(np, "snps,no-pbl-x8");
  410. dma_cfg->aal = of_property_read_bool(np, "snps,aal");
  411. dma_cfg->fixed_burst = of_property_read_bool(np, "snps,fixed-burst");
  412. dma_cfg->mixed_burst = of_property_read_bool(np, "snps,mixed-burst");
  413. plat->force_thresh_dma_mode = of_property_read_bool(np, "snps,force_thresh_dma_mode");
  414. if (plat->force_thresh_dma_mode) {
  415. plat->force_sf_dma_mode = 0;
  416. pr_warn("force_sf_dma_mode is ignored if force_thresh_dma_mode is set.");
  417. }
  418. of_property_read_u32(np, "snps,ps-speed", &plat->mac_port_sel_speed);
  419. plat->axi = stmmac_axi_setup(pdev);
  420. stmmac_mtl_setup(pdev, plat);
  421. /* clock setup */
  422. plat->stmmac_clk = devm_clk_get(&pdev->dev,
  423. STMMAC_RESOURCE_NAME);
  424. if (IS_ERR(plat->stmmac_clk)) {
  425. dev_warn(&pdev->dev, "Cannot get CSR clock\n");
  426. plat->stmmac_clk = NULL;
  427. }
  428. clk_prepare_enable(plat->stmmac_clk);
  429. plat->pclk = devm_clk_get(&pdev->dev, "pclk");
  430. if (IS_ERR(plat->pclk)) {
  431. if (PTR_ERR(plat->pclk) == -EPROBE_DEFER)
  432. goto error_pclk_get;
  433. plat->pclk = NULL;
  434. }
  435. clk_prepare_enable(plat->pclk);
  436. /* Fall-back to main clock in case of no PTP ref is passed */
  437. plat->clk_ptp_ref = devm_clk_get(&pdev->dev, "ptp_ref");
  438. if (IS_ERR(plat->clk_ptp_ref)) {
  439. plat->clk_ptp_rate = clk_get_rate(plat->stmmac_clk);
  440. plat->clk_ptp_ref = NULL;
  441. dev_warn(&pdev->dev, "PTP uses main clock\n");
  442. } else {
  443. plat->clk_ptp_rate = clk_get_rate(plat->clk_ptp_ref);
  444. dev_dbg(&pdev->dev, "PTP rate %d\n", plat->clk_ptp_rate);
  445. }
  446. plat->stmmac_rst = devm_reset_control_get(&pdev->dev,
  447. STMMAC_RESOURCE_NAME);
  448. if (IS_ERR(plat->stmmac_rst)) {
  449. if (PTR_ERR(plat->stmmac_rst) == -EPROBE_DEFER)
  450. goto error_hw_init;
  451. dev_info(&pdev->dev, "no reset control found\n");
  452. plat->stmmac_rst = NULL;
  453. }
  454. return plat;
  455. error_hw_init:
  456. clk_disable_unprepare(plat->pclk);
  457. error_pclk_get:
  458. clk_disable_unprepare(plat->stmmac_clk);
  459. return ERR_PTR(-EPROBE_DEFER);
  460. }
  461. /**
  462. * stmmac_remove_config_dt - undo the effects of stmmac_probe_config_dt()
  463. * @pdev: platform_device structure
  464. * @plat: driver data platform structure
  465. *
  466. * Release resources claimed by stmmac_probe_config_dt().
  467. */
  468. void stmmac_remove_config_dt(struct platform_device *pdev,
  469. struct plat_stmmacenet_data *plat)
  470. {
  471. struct device_node *np = pdev->dev.of_node;
  472. if (of_phy_is_fixed_link(np))
  473. of_phy_deregister_fixed_link(np);
  474. of_node_put(plat->phy_node);
  475. of_node_put(plat->mdio_node);
  476. }
  477. #else
  478. struct plat_stmmacenet_data *
  479. stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
  480. {
  481. return ERR_PTR(-EINVAL);
  482. }
  483. void stmmac_remove_config_dt(struct platform_device *pdev,
  484. struct plat_stmmacenet_data *plat)
  485. {
  486. }
  487. #endif /* CONFIG_OF */
  488. EXPORT_SYMBOL_GPL(stmmac_probe_config_dt);
  489. EXPORT_SYMBOL_GPL(stmmac_remove_config_dt);
  490. int stmmac_get_platform_resources(struct platform_device *pdev,
  491. struct stmmac_resources *stmmac_res)
  492. {
  493. struct resource *res;
  494. memset(stmmac_res, 0, sizeof(*stmmac_res));
  495. /* Get IRQ information early to have an ability to ask for deferred
  496. * probe if needed before we went too far with resource allocation.
  497. */
  498. stmmac_res->irq = platform_get_irq_byname(pdev, "macirq");
  499. if (stmmac_res->irq < 0) {
  500. if (stmmac_res->irq != -EPROBE_DEFER) {
  501. dev_err(&pdev->dev,
  502. "MAC IRQ configuration information not found\n");
  503. }
  504. return stmmac_res->irq;
  505. }
  506. /* On some platforms e.g. SPEAr the wake up irq differs from the mac irq
  507. * The external wake up irq can be passed through the platform code
  508. * named as "eth_wake_irq"
  509. *
  510. * In case the wake up interrupt is not passed from the platform
  511. * so the driver will continue to use the mac irq (ndev->irq)
  512. */
  513. stmmac_res->wol_irq = platform_get_irq_byname(pdev, "eth_wake_irq");
  514. if (stmmac_res->wol_irq < 0) {
  515. if (stmmac_res->wol_irq == -EPROBE_DEFER)
  516. return -EPROBE_DEFER;
  517. stmmac_res->wol_irq = stmmac_res->irq;
  518. }
  519. stmmac_res->lpi_irq = platform_get_irq_byname(pdev, "eth_lpi");
  520. if (stmmac_res->lpi_irq == -EPROBE_DEFER)
  521. return -EPROBE_DEFER;
  522. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  523. stmmac_res->addr = devm_ioremap_resource(&pdev->dev, res);
  524. return PTR_ERR_OR_ZERO(stmmac_res->addr);
  525. }
  526. EXPORT_SYMBOL_GPL(stmmac_get_platform_resources);
  527. /**
  528. * stmmac_pltfr_remove
  529. * @pdev: platform device pointer
  530. * Description: this function calls the main to free the net resources
  531. * and calls the platforms hook and release the resources (e.g. mem).
  532. */
  533. int stmmac_pltfr_remove(struct platform_device *pdev)
  534. {
  535. struct net_device *ndev = platform_get_drvdata(pdev);
  536. struct stmmac_priv *priv = netdev_priv(ndev);
  537. struct plat_stmmacenet_data *plat = priv->plat;
  538. int ret = stmmac_dvr_remove(&pdev->dev);
  539. if (plat->exit)
  540. plat->exit(pdev, plat->bsp_priv);
  541. stmmac_remove_config_dt(pdev, plat);
  542. return ret;
  543. }
  544. EXPORT_SYMBOL_GPL(stmmac_pltfr_remove);
  545. #ifdef CONFIG_PM_SLEEP
  546. /**
  547. * stmmac_pltfr_suspend
  548. * @dev: device pointer
  549. * Description: this function is invoked when suspend the driver and it direcly
  550. * call the main suspend function and then, if required, on some platform, it
  551. * can call an exit helper.
  552. */
  553. static int stmmac_pltfr_suspend(struct device *dev)
  554. {
  555. int ret;
  556. struct net_device *ndev = dev_get_drvdata(dev);
  557. struct stmmac_priv *priv = netdev_priv(ndev);
  558. struct platform_device *pdev = to_platform_device(dev);
  559. ret = stmmac_suspend(dev);
  560. if (priv->plat->exit)
  561. priv->plat->exit(pdev, priv->plat->bsp_priv);
  562. return ret;
  563. }
  564. /**
  565. * stmmac_pltfr_resume
  566. * @dev: device pointer
  567. * Description: this function is invoked when resume the driver before calling
  568. * the main resume function, on some platforms, it can call own init helper
  569. * if required.
  570. */
  571. static int stmmac_pltfr_resume(struct device *dev)
  572. {
  573. struct net_device *ndev = dev_get_drvdata(dev);
  574. struct stmmac_priv *priv = netdev_priv(ndev);
  575. struct platform_device *pdev = to_platform_device(dev);
  576. if (priv->plat->init)
  577. priv->plat->init(pdev, priv->plat->bsp_priv);
  578. return stmmac_resume(dev);
  579. }
  580. #endif /* CONFIG_PM_SLEEP */
  581. SIMPLE_DEV_PM_OPS(stmmac_pltfr_pm_ops, stmmac_pltfr_suspend,
  582. stmmac_pltfr_resume);
  583. EXPORT_SYMBOL_GPL(stmmac_pltfr_pm_ops);
  584. MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet platform support");
  585. MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
  586. MODULE_LICENSE("GPL");