blob: 6e344e59caf7e9457b8f973b57aba05b33cc06d5 [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 CAVALLARO9c9b1f22011-09-06 20:14:50 +000033MODULE_DESCRIPTION("ICPlus IP175C/IP101A/IC1001 PHY drivers");
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050034MODULE_AUTHOR("Michael Barkowski");
35MODULE_LICENSE("GPL");
36
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +000037/* IP101A/IP1001 */
38#define IP10XX_SPEC_CTRL_STATUS 16 /* Spec. Control Register */
39#define IP1001_SPEC_CTRL_STATUS_2 20 /* IP1001 Spec. Control Reg 2 */
40#define IP1001_PHASE_SEL_MASK 3 /* IP1001 RX/TXPHASE_SEL */
41#define IP1001_APS_ON 11 /* IP1001 APS Mode bit */
42#define IP101A_APS_ON 2 /* IP101A APS Mode bit */
43
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050044static int ip175c_config_init(struct phy_device *phydev)
45{
46 int err, i;
47 static int full_reset_performed = 0;
48
49 if (full_reset_performed == 0) {
50
51 /* master reset */
52 err = phydev->bus->write(phydev->bus, 30, 0, 0x175c);
53 if (err < 0)
54 return err;
55
56 /* ensure no bus delays overlap reset period */
57 err = phydev->bus->read(phydev->bus, 30, 0);
58
59 /* data sheet specifies reset period is 2 msec */
60 mdelay(2);
61
62 /* enable IP175C mode */
63 err = phydev->bus->write(phydev->bus, 29, 31, 0x175c);
64 if (err < 0)
65 return err;
66
67 /* Set MII0 speed and duplex (in PHY mode) */
68 err = phydev->bus->write(phydev->bus, 29, 22, 0x420);
69 if (err < 0)
70 return err;
71
72 /* reset switch ports */
73 for (i = 0; i < 5; i++) {
74 err = phydev->bus->write(phydev->bus, i,
75 MII_BMCR, BMCR_RESET);
76 if (err < 0)
77 return err;
78 }
79
80 for (i = 0; i < 5; i++)
81 err = phydev->bus->read(phydev->bus, i, MII_BMCR);
82
83 mdelay(2);
84
85 full_reset_performed = 1;
86 }
87
88 if (phydev->addr != 4) {
89 phydev->state = PHY_RUNNING;
90 phydev->speed = SPEED_100;
91 phydev->duplex = DUPLEX_FULL;
92 phydev->link = 1;
93 netif_carrier_on(phydev->attached_dev);
94 }
95
96 return 0;
97}
98
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +000099static int ip1xx_reset(struct phy_device *phydev)
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000100{
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000101 int err, bmcr;
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000102
103 /* Software Reset PHY */
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000104 bmcr = phy_read(phydev, MII_BMCR);
105 bmcr |= BMCR_RESET;
106 err = phy_write(phydev, MII_BMCR, bmcr);
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000107 if (err < 0)
108 return err;
109
110 do {
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000111 bmcr = phy_read(phydev, MII_BMCR);
112 } while (bmcr & BMCR_RESET);
113
114 return err;
115}
116
117static int ip1001_config_init(struct phy_device *phydev)
118{
119 int c;
120
121 c = ip1xx_reset(phydev);
122 if (c < 0)
123 return c;
124
125 /* Enable Auto Power Saving mode */
126 c = phy_read(phydev, IP1001_SPEC_CTRL_STATUS_2);
127 c |= IP1001_APS_ON;
128 if (c < 0)
129 return c;
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000130
131 /* Additional delay (2ns) used to adjust RX clock phase
132 * at GMII/ RGMII interface */
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000133 c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS);
134 c |= IP1001_PHASE_SEL_MASK;
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000135
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000136 return phy_write(phydev, IP10XX_SPEC_CTRL_STATUS, c);
137}
138
139static int ip101a_config_init(struct phy_device *phydev)
140{
141 int c;
142
143 c = ip1xx_reset(phydev);
144 if (c < 0)
145 return c;
146
147 /* Enable Auto Power Saving mode */
148 c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS);
149 c |= IP101A_APS_ON;
150 return c;
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000151}
152
Michael Barkowski0cefeeb2007-05-11 18:24:51 -0500153static int ip175c_read_status(struct phy_device *phydev)
154{
155 if (phydev->addr == 4) /* WAN port */
156 genphy_read_status(phydev);
157 else
158 /* Don't need to read status for switch ports */
159 phydev->irq = PHY_IGNORE_INTERRUPT;
160
161 return 0;
162}
163
164static int ip175c_config_aneg(struct phy_device *phydev)
165{
166 if (phydev->addr == 4) /* WAN port */
167 genphy_config_aneg(phydev);
168
169 return 0;
170}
171
172static struct phy_driver ip175c_driver = {
173 .phy_id = 0x02430d80,
174 .name = "ICPlus IP175C",
175 .phy_id_mask = 0x0ffffff0,
176 .features = PHY_BASIC_FEATURES,
177 .config_init = &ip175c_config_init,
178 .config_aneg = &ip175c_config_aneg,
179 .read_status = &ip175c_read_status,
Giuseppe Cavallarodab10862010-07-20 13:24:25 -0700180 .suspend = genphy_suspend,
181 .resume = genphy_resume,
Michael Barkowski0cefeeb2007-05-11 18:24:51 -0500182 .driver = { .owner = THIS_MODULE,},
183};
184
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000185static struct phy_driver ip1001_driver = {
186 .phy_id = 0x02430d90,
187 .name = "ICPlus IP1001",
188 .phy_id_mask = 0x0ffffff0,
189 .features = PHY_GBIT_FEATURES | SUPPORTED_Pause |
190 SUPPORTED_Asym_Pause,
191 .config_init = &ip1001_config_init,
192 .config_aneg = &genphy_config_aneg,
193 .read_status = &genphy_read_status,
194 .suspend = genphy_suspend,
195 .resume = genphy_resume,
196 .driver = { .owner = THIS_MODULE,},
197};
198
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000199static struct phy_driver ip101a_driver = {
200 .phy_id = 0x02430c54,
201 .name = "ICPlus IP101A",
202 .phy_id_mask = 0x0ffffff0,
203 .features = PHY_BASIC_FEATURES | SUPPORTED_Pause |
204 SUPPORTED_Asym_Pause,
205 .config_init = &ip101a_config_init,
206 .config_aneg = &genphy_config_aneg,
207 .read_status = &genphy_read_status,
208 .suspend = genphy_suspend,
209 .resume = genphy_resume,
210 .driver = { .owner = THIS_MODULE,},
211};
212
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000213static int __init icplus_init(void)
Michael Barkowski0cefeeb2007-05-11 18:24:51 -0500214{
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000215 int ret = 0;
216
217 ret = phy_driver_register(&ip1001_driver);
218 if (ret < 0)
219 return -ENODEV;
220
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000221 ret = phy_driver_register(&ip101a_driver);
222 if (ret < 0)
223 return -ENODEV;
224
Michael Barkowski0cefeeb2007-05-11 18:24:51 -0500225 return phy_driver_register(&ip175c_driver);
226}
227
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000228static void __exit icplus_exit(void)
Michael Barkowski0cefeeb2007-05-11 18:24:51 -0500229{
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000230 phy_driver_unregister(&ip1001_driver);
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000231 phy_driver_unregister(&ip101a_driver);
Michael Barkowski0cefeeb2007-05-11 18:24:51 -0500232 phy_driver_unregister(&ip175c_driver);
233}
234
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000235module_init(icplus_init);
236module_exit(icplus_exit);
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000237
Uwe Kleine-Königcf93c942010-10-03 23:43:32 +0000238static struct mdio_device_id __maybe_unused icplus_tbl[] = {
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000239 { 0x02430d80, 0x0ffffff0 },
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000240 { 0x02430d90, 0x0ffffff0 },
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000241 { }
242};
243
244MODULE_DEVICE_TABLE(mdio, icplus_tbl);