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
;
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
;
51 if (gpio_int_status
& 0x8) {
52 /* up when edc_convergedS set */
53 phydev
->speed
= SPEED_10000
;
54 phydev
->duplex
= DUPLEX_FULL
;
64 static int cortina_soft_reset(struct phy_device
*phydev
)
69 static int cortina_probe(struct phy_device
*phydev
)
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
);
79 phy_id
= id_lsb
<< 16;
81 id_msb
= cortina_read_reg(phydev
, VILLA_GLOBAL_CHIP_ID_MSB
);
87 /* Make sure the device tree binding matched the driver with the
90 if (phy_id
!= phydev
->drv
->phy_id
) {
91 phydev_err(phydev
, "Error matching phy with %s driver\n",
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
);