cortina.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright 2017 NXP
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * CORTINA is a registered trademark of Cortina Systems, Inc.
  15. *
  16. */
  17. #include <linux/module.h>
  18. #include <linux/phy.h>
  19. #define PHY_ID_CS4340 0x13e51002
  20. #define VILLA_GLOBAL_CHIP_ID_LSB 0x0
  21. #define VILLA_GLOBAL_CHIP_ID_MSB 0x1
  22. #define VILLA_GLOBAL_GPIO_1_INTS 0x017
  23. static int cortina_read_reg(struct phy_device *phydev, u16 regnum)
  24. {
  25. return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr,
  26. MII_ADDR_C45 | regnum);
  27. }
  28. static int cortina_read_status(struct phy_device *phydev)
  29. {
  30. int gpio_int_status, ret = 0;
  31. gpio_int_status = cortina_read_reg(phydev, VILLA_GLOBAL_GPIO_1_INTS);
  32. if (gpio_int_status < 0) {
  33. ret = gpio_int_status;
  34. goto err;
  35. }
  36. if (gpio_int_status & 0x8) {
  37. /* up when edc_convergedS set */
  38. phydev->speed = SPEED_10000;
  39. phydev->duplex = DUPLEX_FULL;
  40. phydev->link = 1;
  41. } else {
  42. phydev->link = 0;
  43. }
  44. err:
  45. return ret;
  46. }
  47. static int cortina_probe(struct phy_device *phydev)
  48. {
  49. u32 phy_id = 0;
  50. int id_lsb = 0, id_msb = 0;
  51. /* Read device id from phy registers. */
  52. id_lsb = cortina_read_reg(phydev, VILLA_GLOBAL_CHIP_ID_LSB);
  53. if (id_lsb < 0)
  54. return -ENXIO;
  55. phy_id = id_lsb << 16;
  56. id_msb = cortina_read_reg(phydev, VILLA_GLOBAL_CHIP_ID_MSB);
  57. if (id_msb < 0)
  58. return -ENXIO;
  59. phy_id |= id_msb;
  60. /* Make sure the device tree binding matched the driver with the
  61. * right device.
  62. */
  63. if (phy_id != phydev->drv->phy_id) {
  64. phydev_err(phydev, "Error matching phy with %s driver\n",
  65. phydev->drv->name);
  66. return -ENODEV;
  67. }
  68. return 0;
  69. }
  70. static struct phy_driver cortina_driver[] = {
  71. {
  72. .phy_id = PHY_ID_CS4340,
  73. .phy_id_mask = 0xffffffff,
  74. .name = "Cortina CS4340",
  75. .config_init = gen10g_config_init,
  76. .config_aneg = gen10g_config_aneg,
  77. .read_status = cortina_read_status,
  78. .soft_reset = gen10g_no_soft_reset,
  79. .probe = cortina_probe,
  80. },
  81. };
  82. module_phy_driver(cortina_driver);
  83. static struct mdio_device_id __maybe_unused cortina_tbl[] = {
  84. { PHY_ID_CS4340, 0xffffffff},
  85. {},
  86. };
  87. MODULE_DEVICE_TABLE(mdio, cortina_tbl);
  88. MODULE_DESCRIPTION("Cortina EDC CDR 10G Ethernet PHY driver");
  89. MODULE_AUTHOR("NXP");
  90. MODULE_LICENSE("GPL");