am35xx-emac.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (C) 2011 Ilya Yanok, Emcraft Systems
  3. *
  4. * Based on mach-omap2/board-am3517evm.c
  5. * Copyright (C) 2009 Texas Instruments Incorporated
  6. * Author: Ranjith Lohithakshan <ranjithl@ti.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 version 2
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
  13. * whether express or implied; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. #include <linux/err.h>
  18. #include <linux/davinci_emac.h>
  19. #include <asm/system.h>
  20. #include <plat/omap_device.h>
  21. #include <mach/am35xx.h>
  22. #include "control.h"
  23. #include "am35xx-emac.h"
  24. static void am35xx_enable_emac_int(void)
  25. {
  26. u32 v;
  27. v = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  28. v |= (AM35XX_CPGMAC_C0_RX_PULSE_CLR | AM35XX_CPGMAC_C0_TX_PULSE_CLR |
  29. AM35XX_CPGMAC_C0_MISC_PULSE_CLR | AM35XX_CPGMAC_C0_RX_THRESH_CLR);
  30. omap_ctrl_writel(v, AM35XX_CONTROL_LVL_INTR_CLEAR);
  31. omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR); /* OCP barrier */
  32. }
  33. static void am35xx_disable_emac_int(void)
  34. {
  35. u32 v;
  36. v = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  37. v |= (AM35XX_CPGMAC_C0_RX_PULSE_CLR | AM35XX_CPGMAC_C0_TX_PULSE_CLR);
  38. omap_ctrl_writel(v, AM35XX_CONTROL_LVL_INTR_CLEAR);
  39. omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR); /* OCP barrier */
  40. }
  41. static struct emac_platform_data am35xx_emac_pdata = {
  42. .ctrl_reg_offset = AM35XX_EMAC_CNTRL_OFFSET,
  43. .ctrl_mod_reg_offset = AM35XX_EMAC_CNTRL_MOD_OFFSET,
  44. .ctrl_ram_offset = AM35XX_EMAC_CNTRL_RAM_OFFSET,
  45. .ctrl_ram_size = AM35XX_EMAC_CNTRL_RAM_SIZE,
  46. .hw_ram_addr = AM35XX_EMAC_HW_RAM_ADDR,
  47. .version = EMAC_VERSION_2,
  48. .interrupt_enable = am35xx_enable_emac_int,
  49. .interrupt_disable = am35xx_disable_emac_int,
  50. };
  51. static struct mdio_platform_data am35xx_mdio_pdata;
  52. static int __init omap_davinci_emac_dev_init(struct omap_hwmod *oh,
  53. void *pdata, int pdata_len)
  54. {
  55. struct platform_device *pdev;
  56. pdev = omap_device_build(oh->class->name, 0, oh, pdata, pdata_len,
  57. NULL, 0, false);
  58. if (IS_ERR(pdev)) {
  59. WARN(1, "Can't build omap_device for %s:%s.\n",
  60. oh->class->name, oh->name);
  61. return PTR_ERR(pdev);
  62. }
  63. return 0;
  64. }
  65. void __init am35xx_emac_init(unsigned long mdio_bus_freq, u8 rmii_en)
  66. {
  67. struct omap_hwmod *oh;
  68. u32 v;
  69. int ret;
  70. oh = omap_hwmod_lookup("davinci_mdio");
  71. if (!oh) {
  72. pr_err("Could not find davinci_mdio hwmod\n");
  73. return;
  74. }
  75. am35xx_mdio_pdata.bus_freq = mdio_bus_freq;
  76. ret = omap_davinci_emac_dev_init(oh, &am35xx_mdio_pdata,
  77. sizeof(am35xx_mdio_pdata));
  78. if (ret) {
  79. pr_err("Could not build davinci_mdio hwmod device\n");
  80. return;
  81. }
  82. oh = omap_hwmod_lookup("davinci_emac");
  83. if (!oh) {
  84. pr_err("Could not find davinci_emac hwmod\n");
  85. return;
  86. }
  87. am35xx_emac_pdata.rmii_en = rmii_en;
  88. ret = omap_davinci_emac_dev_init(oh, &am35xx_emac_pdata,
  89. sizeof(am35xx_emac_pdata));
  90. if (ret) {
  91. pr_err("Could not build davinci_emac hwmod device\n");
  92. return;
  93. }
  94. v = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
  95. v &= ~AM35XX_CPGMACSS_SW_RST;
  96. omap_ctrl_writel(v, AM35XX_CONTROL_IP_SW_RESET);
  97. omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET); /* OCP barrier */
  98. }