WIP FPC-III support
[linux/fpc-iii.git] / drivers / net / phy / ste10Xp.c
blob431fe5e0ce313ee284180fa2cf238a2e372e88b2
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * drivers/net/phy/ste10Xp.c
5 * Driver for STMicroelectronics STe10Xp PHYs
7 * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
9 * Copyright (c) 2008 STMicroelectronics Limited
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/sched.h>
15 #include <linux/kernel.h>
16 #include <linux/moduleparam.h>
17 #include <linux/interrupt.h>
18 #include <linux/netdevice.h>
19 #include <linux/ethtool.h>
20 #include <linux/mii.h>
21 #include <linux/phy.h>
23 #define MII_XCIIS 0x11 /* Configuration Info IRQ & Status Reg */
24 #define MII_XIE 0x12 /* Interrupt Enable Register */
25 #define MII_XIE_DEFAULT_MASK 0x0070 /* ANE complete, Remote Fault, Link Down */
27 #define STE101P_PHY_ID 0x00061c50
28 #define STE100P_PHY_ID 0x1c040011
30 static int ste10Xp_config_init(struct phy_device *phydev)
32 int value, err;
34 /* Software Reset PHY */
35 value = phy_read(phydev, MII_BMCR);
36 if (value < 0)
37 return value;
39 value |= BMCR_RESET;
40 err = phy_write(phydev, MII_BMCR, value);
41 if (err < 0)
42 return err;
44 do {
45 value = phy_read(phydev, MII_BMCR);
46 } while (value & BMCR_RESET);
48 return 0;
51 static int ste10Xp_ack_interrupt(struct phy_device *phydev)
53 int err = phy_read(phydev, MII_XCIIS);
55 if (err < 0)
56 return err;
58 return 0;
61 static int ste10Xp_config_intr(struct phy_device *phydev)
63 int err;
65 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
66 /* clear any pending interrupts */
67 err = ste10Xp_ack_interrupt(phydev);
68 if (err)
69 return err;
71 /* Enable all STe101P interrupts (PR12) */
72 err = phy_write(phydev, MII_XIE, MII_XIE_DEFAULT_MASK);
73 } else {
74 err = phy_write(phydev, MII_XIE, 0);
75 if (err)
76 return err;
78 err = ste10Xp_ack_interrupt(phydev);
81 return err;
84 static irqreturn_t ste10Xp_handle_interrupt(struct phy_device *phydev)
86 int irq_status;
88 irq_status = phy_read(phydev, MII_XCIIS);
89 if (irq_status < 0) {
90 phy_error(phydev);
91 return IRQ_NONE;
94 if (!(irq_status & MII_XIE_DEFAULT_MASK))
95 return IRQ_NONE;
97 phy_trigger_machine(phydev);
99 return IRQ_HANDLED;
102 static struct phy_driver ste10xp_pdriver[] = {
104 .phy_id = STE101P_PHY_ID,
105 .phy_id_mask = 0xfffffff0,
106 .name = "STe101p",
107 /* PHY_BASIC_FEATURES */
108 .config_init = ste10Xp_config_init,
109 .config_intr = ste10Xp_config_intr,
110 .handle_interrupt = ste10Xp_handle_interrupt,
111 .suspend = genphy_suspend,
112 .resume = genphy_resume,
113 }, {
114 .phy_id = STE100P_PHY_ID,
115 .phy_id_mask = 0xffffffff,
116 .name = "STe100p",
117 /* PHY_BASIC_FEATURES */
118 .config_init = ste10Xp_config_init,
119 .config_intr = ste10Xp_config_intr,
120 .handle_interrupt = ste10Xp_handle_interrupt,
121 .suspend = genphy_suspend,
122 .resume = genphy_resume,
123 } };
125 module_phy_driver(ste10xp_pdriver);
127 static struct mdio_device_id __maybe_unused ste10Xp_tbl[] = {
128 { STE101P_PHY_ID, 0xfffffff0 },
129 { STE100P_PHY_ID, 0xffffffff },
133 MODULE_DEVICE_TABLE(mdio, ste10Xp_tbl);
135 MODULE_DESCRIPTION("STMicroelectronics STe10Xp PHY driver");
136 MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
137 MODULE_LICENSE("GPL");