cortina.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2017 NXP
  4. *
  5. * CORTINA is a registered trademark of Cortina Systems, Inc.
  6. *
  7. */
  8. #include <linux/module.h>
  9. #include <linux/phy.h>
  10. #define PHY_ID_CS4340 0x13e51002
  11. #define VILLA_GLOBAL_CHIP_ID_LSB 0x0
  12. #define VILLA_GLOBAL_CHIP_ID_MSB 0x1
  13. #define VILLA_GLOBAL_GPIO_1_INTS 0x017
  14. static int cortina_read_reg(struct phy_device *phydev, u16 regnum)
  15. {
  16. return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr,
  17. MII_ADDR_C45 | regnum);
  18. }
  19. static int cortina_read_status(struct phy_device *phydev)
  20. {
  21. int gpio_int_status, ret = 0;
  22. gpio_int_status = cortina_read_reg(phydev, VILLA_GLOBAL_GPIO_1_INTS);
  23. if (gpio_int_status < 0) {
  24. ret = gpio_int_status;
  25. goto err;
  26. }
  27. if (gpio_int_status & 0x8) {
  28. /* up when edc_convergedS set */
  29. phydev->speed = SPEED_10000;
  30. phydev->duplex = DUPLEX_FULL;
  31. phydev->link = 1;
  32. } else {
  33. phydev->link = 0;
  34. }
  35. err:
  36. return ret;
  37. }
  38. static int cortina_probe(struct phy_device *phydev)
  39. {
  40. u32 phy_id = 0;
  41. int id_lsb = 0, id_msb = 0;
  42. /* Read device id from phy registers. */
  43. id_lsb = cortina_read_reg(phydev, VILLA_GLOBAL_CHIP_ID_LSB);
  44. if (id_lsb < 0)
  45. return -ENXIO;
  46. phy_id = id_lsb << 16;
  47. id_msb = cortina_read_reg(phydev, VILLA_GLOBAL_CHIP_ID_MSB);
  48. if (id_msb < 0)
  49. return -ENXIO;
  50. phy_id |= id_msb;
  51. /* Make sure the device tree binding matched the driver with the
  52. * right device.
  53. */
  54. if (phy_id != phydev->drv->phy_id) {
  55. phydev_err(phydev, "Error matching phy with %s driver\n",
  56. phydev->drv->name);
  57. return -ENODEV;
  58. }
  59. return 0;
  60. }
  61. static struct phy_driver cortina_driver[] = {
  62. {
  63. .phy_id = PHY_ID_CS4340,
  64. .phy_id_mask = 0xffffffff,
  65. .name = "Cortina CS4340",
  66. .features = PHY_10GBIT_FEATURES,
  67. .config_aneg = gen10g_config_aneg,
  68. .read_status = cortina_read_status,
  69. .soft_reset = genphy_no_soft_reset,
  70. .probe = cortina_probe,
  71. },
  72. };
  73. module_phy_driver(cortina_driver);
  74. static struct mdio_device_id __maybe_unused cortina_tbl[] = {
  75. { PHY_ID_CS4340, 0xffffffff},
  76. {},
  77. };
  78. MODULE_DEVICE_TABLE(mdio, cortina_tbl);
  79. MODULE_DESCRIPTION("Cortina EDC CDR 10G Ethernet PHY driver");
  80. MODULE_AUTHOR("NXP");
  81. MODULE_LICENSE("GPL");