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