blob: e5f251b915788e87e369027ab0251bb6a9397964 [file] [log] [blame]
Michael Barkowski0cefeeb2007-05-11 18:24:51 -05001/*
2 * Driver for ICPlus PHYs
3 *
4 * Copyright (c) 2007 Freescale Semiconductor, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 */
12#include <linux/kernel.h>
13#include <linux/string.h>
14#include <linux/errno.h>
15#include <linux/unistd.h>
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050016#include <linux/interrupt.h>
17#include <linux/init.h>
18#include <linux/delay.h>
19#include <linux/netdevice.h>
20#include <linux/etherdevice.h>
21#include <linux/skbuff.h>
22#include <linux/spinlock.h>
23#include <linux/mm.h>
24#include <linux/module.h>
25#include <linux/mii.h>
26#include <linux/ethtool.h>
27#include <linux/phy.h>
28
29#include <asm/io.h>
30#include <asm/irq.h>
31#include <asm/uaccess.h>
32
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +000033MODULE_DESCRIPTION("ICPlus IP175C/IP101A/IP101G/IC1001 PHY drivers");
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050034MODULE_AUTHOR("Michael Barkowski");
35MODULE_LICENSE("GPL");
36
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +000037/* IP101A/G - IP1001 */
38#define IP10XX_SPEC_CTRL_STATUS 16 /* Spec. Control Register */
Stuart Menefyb4a49632013-01-23 00:22:36 +000039#define IP1001_RXPHASE_SEL (1<<0) /* Add delay on RX_CLK */
40#define IP1001_TXPHASE_SEL (1<<1) /* Add delay on TX_CLK */
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +000041#define IP1001_SPEC_CTRL_STATUS_2 20 /* IP1001 Spec. Control Reg 2 */
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +000042#define IP1001_APS_ON 11 /* IP1001 APS Mode bit */
43#define IP101A_G_APS_ON 2 /* IP101A/G APS Mode bit */
Giuseppe CAVALLARO996f7392012-04-17 21:16:40 +000044#define IP101A_G_IRQ_CONF_STATUS 0x11 /* Conf Info IRQ & Status Reg */
Giuseppe CAVALLARO9ec0db72012-06-04 05:51:18 +000045#define IP101A_G_IRQ_PIN_USED (1<<15) /* INTR pin used */
46#define IP101A_G_IRQ_DEFAULT IP101A_G_IRQ_PIN_USED
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +000047
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050048static int ip175c_config_init(struct phy_device *phydev)
49{
50 int err, i;
Florian Fainelli9ed66cb2013-12-17 21:38:08 -080051 static int full_reset_performed;
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050052
53 if (full_reset_performed == 0) {
54
55 /* master reset */
Andrew Lunne5a03bf2016-01-06 20:11:16 +010056 err = mdiobus_write(phydev->mdio.bus, 30, 0, 0x175c);
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050057 if (err < 0)
58 return err;
59
60 /* ensure no bus delays overlap reset period */
Andrew Lunne5a03bf2016-01-06 20:11:16 +010061 err = mdiobus_read(phydev->mdio.bus, 30, 0);
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050062
63 /* data sheet specifies reset period is 2 msec */
64 mdelay(2);
65
66 /* enable IP175C mode */
Andrew Lunne5a03bf2016-01-06 20:11:16 +010067 err = mdiobus_write(phydev->mdio.bus, 29, 31, 0x175c);
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050068 if (err < 0)
69 return err;
70
71 /* Set MII0 speed and duplex (in PHY mode) */
Andrew Lunne5a03bf2016-01-06 20:11:16 +010072 err = mdiobus_write(phydev->mdio.bus, 29, 22, 0x420);
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050073 if (err < 0)
74 return err;
75
76 /* reset switch ports */
77 for (i = 0; i < 5; i++) {
Andrew Lunne5a03bf2016-01-06 20:11:16 +010078 err = mdiobus_write(phydev->mdio.bus, i,
David Daney76231e02011-09-30 12:17:48 +000079 MII_BMCR, BMCR_RESET);
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050080 if (err < 0)
81 return err;
82 }
83
84 for (i = 0; i < 5; i++)
Andrew Lunne5a03bf2016-01-06 20:11:16 +010085 err = mdiobus_read(phydev->mdio.bus, i, MII_BMCR);
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050086
87 mdelay(2);
88
89 full_reset_performed = 1;
90 }
91
Andrew Lunne5a03bf2016-01-06 20:11:16 +010092 if (phydev->mdio.addr != 4) {
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050093 phydev->state = PHY_RUNNING;
94 phydev->speed = SPEED_100;
95 phydev->duplex = DUPLEX_FULL;
96 phydev->link = 1;
97 netif_carrier_on(phydev->attached_dev);
98 }
99
100 return 0;
101}
102
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000103static int ip1xx_reset(struct phy_device *phydev)
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000104{
David McKayb8e39952012-02-21 21:24:57 +0000105 int bmcr;
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000106
107 /* Software Reset PHY */
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000108 bmcr = phy_read(phydev, MII_BMCR);
David McKayb8e39952012-02-21 21:24:57 +0000109 if (bmcr < 0)
110 return bmcr;
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000111 bmcr |= BMCR_RESET;
David McKayb8e39952012-02-21 21:24:57 +0000112 bmcr = phy_write(phydev, MII_BMCR, bmcr);
113 if (bmcr < 0)
114 return bmcr;
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000115
116 do {
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000117 bmcr = phy_read(phydev, MII_BMCR);
David McKayb8e39952012-02-21 21:24:57 +0000118 if (bmcr < 0)
119 return bmcr;
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000120 } while (bmcr & BMCR_RESET);
121
David McKayb8e39952012-02-21 21:24:57 +0000122 return 0;
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000123}
124
125static int ip1001_config_init(struct phy_device *phydev)
126{
127 int c;
128
129 c = ip1xx_reset(phydev);
130 if (c < 0)
131 return c;
132
133 /* Enable Auto Power Saving mode */
134 c = phy_read(phydev, IP1001_SPEC_CTRL_STATUS_2);
David McKayb8e39952012-02-21 21:24:57 +0000135 if (c < 0)
136 return c;
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000137 c |= IP1001_APS_ON;
David McKayb8e39952012-02-21 21:24:57 +0000138 c = phy_write(phydev, IP1001_SPEC_CTRL_STATUS_2, c);
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000139 if (c < 0)
140 return c;
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000141
Florian Fainelli32a64162015-05-26 12:19:59 -0700142 if (phy_interface_is_rgmii(phydev)) {
Stuart Menefyb4a49632013-01-23 00:22:36 +0000143
Giuseppe CAVALLAROa4886d52011-10-10 21:37:56 +0000144 c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS);
David McKayb8e39952012-02-21 21:24:57 +0000145 if (c < 0)
146 return c;
147
Stuart Menefyb4a49632013-01-23 00:22:36 +0000148 c &= ~(IP1001_RXPHASE_SEL | IP1001_TXPHASE_SEL);
149
150 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
151 c |= (IP1001_RXPHASE_SEL | IP1001_TXPHASE_SEL);
152 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
153 c |= IP1001_RXPHASE_SEL;
154 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
155 c |= IP1001_TXPHASE_SEL;
156
Giuseppe CAVALLAROa4886d52011-10-10 21:37:56 +0000157 c = phy_write(phydev, IP10XX_SPEC_CTRL_STATUS, c);
David McKayb8e39952012-02-21 21:24:57 +0000158 if (c < 0)
159 return c;
Giuseppe CAVALLAROa4886d52011-10-10 21:37:56 +0000160 }
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000161
David McKayb8e39952012-02-21 21:24:57 +0000162 return 0;
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000163}
164
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +0000165static int ip101a_g_config_init(struct phy_device *phydev)
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000166{
167 int c;
168
169 c = ip1xx_reset(phydev);
170 if (c < 0)
171 return c;
172
Giuseppe CAVALLARO014f2ff2013-01-23 00:22:37 +0000173 /* INTR pin used: speed/link/duplex will cause an interrupt */
174 c = phy_write(phydev, IP101A_G_IRQ_CONF_STATUS, IP101A_G_IRQ_DEFAULT);
175 if (c < 0)
176 return c;
177
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000178 /* Enable Auto Power Saving mode */
179 c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS);
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +0000180 c |= IP101A_G_APS_ON;
Srinivas Kandagatlab3300142012-04-02 00:02:09 +0000181
182 return phy_write(phydev, IP10XX_SPEC_CTRL_STATUS, c);
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000183}
184
Michael Barkowski0cefeeb2007-05-11 18:24:51 -0500185static int ip175c_read_status(struct phy_device *phydev)
186{
Andrew Lunne5a03bf2016-01-06 20:11:16 +0100187 if (phydev->mdio.addr == 4) /* WAN port */
Michael Barkowski0cefeeb2007-05-11 18:24:51 -0500188 genphy_read_status(phydev);
189 else
190 /* Don't need to read status for switch ports */
191 phydev->irq = PHY_IGNORE_INTERRUPT;
192
193 return 0;
194}
195
196static int ip175c_config_aneg(struct phy_device *phydev)
197{
Andrew Lunne5a03bf2016-01-06 20:11:16 +0100198 if (phydev->mdio.addr == 4) /* WAN port */
Michael Barkowski0cefeeb2007-05-11 18:24:51 -0500199 genphy_config_aneg(phydev);
200
201 return 0;
202}
203
Giuseppe CAVALLARO996f7392012-04-17 21:16:40 +0000204static int ip101a_g_ack_interrupt(struct phy_device *phydev)
205{
206 int err = phy_read(phydev, IP101A_G_IRQ_CONF_STATUS);
207 if (err < 0)
208 return err;
209
210 return 0;
211}
212
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000213static struct phy_driver icplus_driver[] = {
214{
Michael Barkowski0cefeeb2007-05-11 18:24:51 -0500215 .phy_id = 0x02430d80,
216 .name = "ICPlus IP175C",
217 .phy_id_mask = 0x0ffffff0,
218 .features = PHY_BASIC_FEATURES,
219 .config_init = &ip175c_config_init,
220 .config_aneg = &ip175c_config_aneg,
221 .read_status = &ip175c_read_status,
Giuseppe Cavallarodab10862010-07-20 13:24:25 -0700222 .suspend = genphy_suspend,
223 .resume = genphy_resume,
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000224}, {
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000225 .phy_id = 0x02430d90,
226 .name = "ICPlus IP1001",
227 .phy_id_mask = 0x0ffffff0,
228 .features = PHY_GBIT_FEATURES | SUPPORTED_Pause |
229 SUPPORTED_Asym_Pause,
230 .config_init = &ip1001_config_init,
231 .config_aneg = &genphy_config_aneg,
232 .read_status = &genphy_read_status,
233 .suspend = genphy_suspend,
234 .resume = genphy_resume,
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000235}, {
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000236 .phy_id = 0x02430c54,
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +0000237 .name = "ICPlus IP101A/G",
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000238 .phy_id_mask = 0x0ffffff0,
239 .features = PHY_BASIC_FEATURES | SUPPORTED_Pause |
240 SUPPORTED_Asym_Pause,
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +0000241 .flags = PHY_HAS_INTERRUPT,
Giuseppe CAVALLARO996f7392012-04-17 21:16:40 +0000242 .ack_interrupt = ip101a_g_ack_interrupt,
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +0000243 .config_init = &ip101a_g_config_init,
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000244 .config_aneg = &genphy_config_aneg,
245 .read_status = &genphy_read_status,
246 .suspend = genphy_suspend,
247 .resume = genphy_resume,
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000248} };
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000249
Johan Hovold50fd7152014-11-11 19:45:59 +0100250module_phy_driver(icplus_driver);
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000251
Uwe Kleine-Königcf93c942010-10-03 23:43:32 +0000252static struct mdio_device_id __maybe_unused icplus_tbl[] = {
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000253 { 0x02430d80, 0x0ffffff0 },
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000254 { 0x02430d90, 0x0ffffff0 },
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +0000255 { 0x02430c54, 0x0ffffff0 },
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000256 { }
257};
258
259MODULE_DEVICE_TABLE(mdio, icplus_tbl);