dwmac-dwc-qos-eth.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Synopsys DWC Ethernet Quality-of-Service v4.10a linux driver
  3. *
  4. * Copyright (C) 2016 Joao Pinto <jpinto@synopsys.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * You should have received a copy of the GNU General Public License
  11. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/clk-provider.h>
  15. #include <linux/device.h>
  16. #include <linux/ethtool.h>
  17. #include <linux/io.h>
  18. #include <linux/ioport.h>
  19. #include <linux/module.h>
  20. #include <linux/of_net.h>
  21. #include <linux/mfd/syscon.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/stmmac.h>
  24. #include "stmmac_platform.h"
  25. static int dwc_eth_dwmac_config_dt(struct platform_device *pdev,
  26. struct plat_stmmacenet_data *plat_dat)
  27. {
  28. struct device_node *np = pdev->dev.of_node;
  29. u32 burst_map = 0;
  30. u32 bit_index = 0;
  31. u32 a_index = 0;
  32. if (!plat_dat->axi) {
  33. plat_dat->axi = kzalloc(sizeof(struct stmmac_axi), GFP_KERNEL);
  34. if (!plat_dat->axi)
  35. return -ENOMEM;
  36. }
  37. plat_dat->axi->axi_lpi_en = of_property_read_bool(np, "snps,en-lpi");
  38. if (of_property_read_u32(np, "snps,write-requests",
  39. &plat_dat->axi->axi_wr_osr_lmt)) {
  40. /**
  41. * Since the register has a reset value of 1, if property
  42. * is missing, default to 1.
  43. */
  44. plat_dat->axi->axi_wr_osr_lmt = 1;
  45. } else {
  46. /**
  47. * If property exists, to keep the behavior from dwc_eth_qos,
  48. * subtract one after parsing.
  49. */
  50. plat_dat->axi->axi_wr_osr_lmt--;
  51. }
  52. if (of_property_read_u32(np, "read,read-requests",
  53. &plat_dat->axi->axi_rd_osr_lmt)) {
  54. /**
  55. * Since the register has a reset value of 1, if property
  56. * is missing, default to 1.
  57. */
  58. plat_dat->axi->axi_rd_osr_lmt = 1;
  59. } else {
  60. /**
  61. * If property exists, to keep the behavior from dwc_eth_qos,
  62. * subtract one after parsing.
  63. */
  64. plat_dat->axi->axi_rd_osr_lmt--;
  65. }
  66. of_property_read_u32(np, "snps,burst-map", &burst_map);
  67. /* converts burst-map bitmask to burst array */
  68. for (bit_index = 0; bit_index < 7; bit_index++) {
  69. if (burst_map & (1 << bit_index)) {
  70. switch (bit_index) {
  71. case 0:
  72. plat_dat->axi->axi_blen[a_index] = 4; break;
  73. case 1:
  74. plat_dat->axi->axi_blen[a_index] = 8; break;
  75. case 2:
  76. plat_dat->axi->axi_blen[a_index] = 16; break;
  77. case 3:
  78. plat_dat->axi->axi_blen[a_index] = 32; break;
  79. case 4:
  80. plat_dat->axi->axi_blen[a_index] = 64; break;
  81. case 5:
  82. plat_dat->axi->axi_blen[a_index] = 128; break;
  83. case 6:
  84. plat_dat->axi->axi_blen[a_index] = 256; break;
  85. default:
  86. break;
  87. }
  88. a_index++;
  89. }
  90. }
  91. /* dwc-qos needs GMAC4, AAL, TSO and PMT */
  92. plat_dat->has_gmac4 = 1;
  93. plat_dat->dma_cfg->aal = 1;
  94. plat_dat->tso_en = 1;
  95. plat_dat->pmt = 1;
  96. return 0;
  97. }
  98. static int dwc_eth_dwmac_probe(struct platform_device *pdev)
  99. {
  100. struct plat_stmmacenet_data *plat_dat;
  101. struct stmmac_resources stmmac_res;
  102. struct resource *res;
  103. int ret;
  104. memset(&stmmac_res, 0, sizeof(struct stmmac_resources));
  105. /**
  106. * Since stmmac_platform supports name IRQ only, basic platform
  107. * resource initialization is done in the glue logic.
  108. */
  109. stmmac_res.irq = platform_get_irq(pdev, 0);
  110. if (stmmac_res.irq < 0) {
  111. if (stmmac_res.irq != -EPROBE_DEFER)
  112. dev_err(&pdev->dev,
  113. "IRQ configuration information not found\n");
  114. return stmmac_res.irq;
  115. }
  116. stmmac_res.wol_irq = stmmac_res.irq;
  117. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  118. stmmac_res.addr = devm_ioremap_resource(&pdev->dev, res);
  119. if (IS_ERR(stmmac_res.addr))
  120. return PTR_ERR(stmmac_res.addr);
  121. plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  122. if (IS_ERR(plat_dat))
  123. return PTR_ERR(plat_dat);
  124. plat_dat->stmmac_clk = devm_clk_get(&pdev->dev, "apb_pclk");
  125. if (IS_ERR(plat_dat->stmmac_clk)) {
  126. dev_err(&pdev->dev, "apb_pclk clock not found.\n");
  127. ret = PTR_ERR(plat_dat->stmmac_clk);
  128. plat_dat->stmmac_clk = NULL;
  129. goto err_remove_config_dt;
  130. }
  131. clk_prepare_enable(plat_dat->stmmac_clk);
  132. plat_dat->pclk = devm_clk_get(&pdev->dev, "phy_ref_clk");
  133. if (IS_ERR(plat_dat->pclk)) {
  134. dev_err(&pdev->dev, "phy_ref_clk clock not found.\n");
  135. ret = PTR_ERR(plat_dat->pclk);
  136. plat_dat->pclk = NULL;
  137. goto err_out_clk_dis_phy;
  138. }
  139. clk_prepare_enable(plat_dat->pclk);
  140. ret = dwc_eth_dwmac_config_dt(pdev, plat_dat);
  141. if (ret)
  142. goto err_out_clk_dis_aper;
  143. ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  144. if (ret)
  145. goto err_out_clk_dis_aper;
  146. return 0;
  147. err_out_clk_dis_aper:
  148. clk_disable_unprepare(plat_dat->pclk);
  149. err_out_clk_dis_phy:
  150. clk_disable_unprepare(plat_dat->stmmac_clk);
  151. err_remove_config_dt:
  152. stmmac_remove_config_dt(pdev, plat_dat);
  153. return ret;
  154. }
  155. static int dwc_eth_dwmac_remove(struct platform_device *pdev)
  156. {
  157. return stmmac_pltfr_remove(pdev);
  158. }
  159. static const struct of_device_id dwc_eth_dwmac_match[] = {
  160. { .compatible = "snps,dwc-qos-ethernet-4.10", },
  161. { }
  162. };
  163. MODULE_DEVICE_TABLE(of, dwc_eth_dwmac_match);
  164. static struct platform_driver dwc_eth_dwmac_driver = {
  165. .probe = dwc_eth_dwmac_probe,
  166. .remove = dwc_eth_dwmac_remove,
  167. .driver = {
  168. .name = "dwc-eth-dwmac",
  169. .of_match_table = dwc_eth_dwmac_match,
  170. },
  171. };
  172. module_platform_driver(dwc_eth_dwmac_driver);
  173. MODULE_AUTHOR("Joao Pinto <jpinto@synopsys.com>");
  174. MODULE_DESCRIPTION("Synopsys DWC Ethernet Quality-of-Service v4.10a driver");
  175. MODULE_LICENSE("GPL v2");