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.
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.
14 * CORTINA is a registered trademark of Cortina Systems, Inc.
17 #include <linux/module.h>
18 #include <linux/phy.h>
20 #define PHY_ID_CS4340 0x13e51002
22 #define VILLA_GLOBAL_CHIP_ID_LSB 0x0
23 #define VILLA_GLOBAL_CHIP_ID_MSB 0x1
25 #define VILLA_GLOBAL_GPIO_1_INTS 0x017
27 static int cortina_read_reg(struct phy_device *phydev, u16 regnum)
29 return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr,
30 MII_ADDR_C45 | regnum);
33 static int cortina_read_status(struct phy_device *phydev)
35 int gpio_int_status, ret = 0;
37 gpio_int_status = cortina_read_reg(phydev, VILLA_GLOBAL_GPIO_1_INTS);
38 if (gpio_int_status < 0) {
39 ret = gpio_int_status;
43 if (gpio_int_status & 0x8) {
44 /* up when edc_convergedS set */
45 phydev->speed = SPEED_10000;
46 phydev->duplex = DUPLEX_FULL;
56 static int cortina_probe(struct phy_device *phydev)
59 int id_lsb = 0, id_msb = 0;
61 /* Read device id from phy registers. */
62 id_lsb = cortina_read_reg(phydev, VILLA_GLOBAL_CHIP_ID_LSB);
66 phy_id = id_lsb << 16;
68 id_msb = cortina_read_reg(phydev, VILLA_GLOBAL_CHIP_ID_MSB);
74 /* Make sure the device tree binding matched the driver with the
77 if (phy_id != phydev->drv->phy_id) {
78 phydev_err(phydev, "Error matching phy with %s driver\n",
86 static struct phy_driver cortina_driver[] = {
88 .phy_id = PHY_ID_CS4340,
89 .phy_id_mask = 0xffffffff,
90 .name = "Cortina CS4340",
91 .config_init = gen10g_config_init,
92 .config_aneg = gen10g_config_aneg,
93 .read_status = cortina_read_status,
94 .soft_reset = gen10g_no_soft_reset,
95 .probe = cortina_probe,
99 module_phy_driver(cortina_driver);
101 static struct mdio_device_id __maybe_unused cortina_tbl[] = {
102 { PHY_ID_CS4340, 0xffffffff},
106 MODULE_DEVICE_TABLE(mdio, cortina_tbl);
108 MODULE_DESCRIPTION("Cortina EDC CDR 10G Ethernet PHY driver");
109 MODULE_AUTHOR("NXP");
110 MODULE_LICENSE("GPL");