cortina.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_c45_read(phydev->mdio.bus, phydev->mdio.addr, 0, regnum);
  17. }
  18. static int cortina_read_status(struct phy_device *phydev)
  19. {
  20. int gpio_int_status, ret = 0;
  21. gpio_int_status = cortina_read_reg(phydev, VILLA_GLOBAL_GPIO_1_INTS);
  22. if (gpio_int_status < 0) {
  23. ret = gpio_int_status;
  24. goto err;
  25. }
  26. if (gpio_int_status & 0x8) {
  27. /* up when edc_convergedS set */
  28. phydev->speed = SPEED_10000;
  29. phydev->duplex = DUPLEX_FULL;
  30. phydev->link = 1;
  31. } else {
  32. phydev->link = 0;
  33. }
  34. err:
  35. return ret;
  36. }
  37. static int cortina_probe(struct phy_device *phydev)
  38. {
  39. u32 phy_id = 0;
  40. int id_lsb = 0, id_msb = 0;
  41. /* Read device id from phy registers. */
  42. id_lsb = cortina_read_reg(phydev, VILLA_GLOBAL_CHIP_ID_LSB);
  43. if (id_lsb < 0)
  44. return -ENXIO;
  45. phy_id = id_lsb << 16;
  46. id_msb = cortina_read_reg(phydev, VILLA_GLOBAL_CHIP_ID_MSB);
  47. if (id_msb < 0)
  48. return -ENXIO;
  49. phy_id |= id_msb;
  50. /* Make sure the device tree binding matched the driver with the
  51. * right device.
  52. */
  53. if (phy_id != phydev->drv->phy_id) {
  54. phydev_err(phydev, "Error matching phy with %s driver\n",
  55. phydev->drv->name);
  56. return -ENODEV;
  57. }
  58. return 0;
  59. }
  60. static struct phy_driver cortina_driver[] = {
  61. {
  62. .phy_id = PHY_ID_CS4340,
  63. .phy_id_mask = 0xffffffff,
  64. .name = "Cortina CS4340",
  65. .features = PHY_10GBIT_FEATURES,
  66. .config_aneg = gen10g_config_aneg,
  67. .read_status = cortina_read_status,
  68. .probe = cortina_probe,
  69. },
  70. };
  71. module_phy_driver(cortina_driver);
  72. static const struct mdio_device_id __maybe_unused cortina_tbl[] = {
  73. { PHY_ID_CS4340, 0xffffffff},
  74. {},
  75. };
  76. MODULE_DEVICE_TABLE(mdio, cortina_tbl);
  77. MODULE_DESCRIPTION("Cortina EDC CDR 10G Ethernet PHY driver");
  78. MODULE_AUTHOR("NXP");
  79. MODULE_LICENSE("GPL");