Linux 4.14.13
[linux-stable.git] / drivers / net / phy / cortina.c
blob72f4228a63bb0a9fb0f3baa993fa85fc8ad6f823
1 /*
2 * Copyright 2017 NXP
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_config_aneg(struct phy_device *phydev)
35 phydev->supported = SUPPORTED_10000baseT_Full;
36 phydev->advertising = SUPPORTED_10000baseT_Full;
38 return 0;
41 static int cortina_read_status(struct phy_device *phydev)
43 int gpio_int_status, ret = 0;
45 gpio_int_status = cortina_read_reg(phydev, VILLA_GLOBAL_GPIO_1_INTS);
46 if (gpio_int_status < 0) {
47 ret = gpio_int_status;
48 goto err;
51 if (gpio_int_status & 0x8) {
52 /* up when edc_convergedS set */
53 phydev->speed = SPEED_10000;
54 phydev->duplex = DUPLEX_FULL;
55 phydev->link = 1;
56 } else {
57 phydev->link = 0;
60 err:
61 return ret;
64 static int cortina_soft_reset(struct phy_device *phydev)
66 return 0;
69 static int cortina_probe(struct phy_device *phydev)
71 u32 phy_id = 0;
72 int id_lsb = 0, id_msb = 0;
74 /* Read device id from phy registers. */
75 id_lsb = cortina_read_reg(phydev, VILLA_GLOBAL_CHIP_ID_LSB);
76 if (id_lsb < 0)
77 return -ENXIO;
79 phy_id = id_lsb << 16;
81 id_msb = cortina_read_reg(phydev, VILLA_GLOBAL_CHIP_ID_MSB);
82 if (id_msb < 0)
83 return -ENXIO;
85 phy_id |= id_msb;
87 /* Make sure the device tree binding matched the driver with the
88 * right device.
90 if (phy_id != phydev->drv->phy_id) {
91 phydev_err(phydev, "Error matching phy with %s driver\n",
92 phydev->drv->name);
93 return -ENODEV;
96 return 0;
99 static struct phy_driver cortina_driver[] = {
101 .phy_id = PHY_ID_CS4340,
102 .phy_id_mask = 0xffffffff,
103 .name = "Cortina CS4340",
104 .config_aneg = cortina_config_aneg,
105 .read_status = cortina_read_status,
106 .soft_reset = cortina_soft_reset,
107 .probe = cortina_probe,
111 module_phy_driver(cortina_driver);
113 static struct mdio_device_id __maybe_unused cortina_tbl[] = {
114 { PHY_ID_CS4340, 0xffffffff},
118 MODULE_DEVICE_TABLE(mdio, cortina_tbl);