blob: f08c85acf761d3893b54f3d2f70e2fddcb6c5904 [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 */
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_G_APS_ON 2 /* IP101A/G APS Mode bit */
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +000043
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 */
David Daney76231e02011-09-30 12:17:48 +000052 err = mdiobus_write(phydev->bus, 30, 0, 0x175c);
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050053 if (err < 0)
54 return err;
55
56 /* ensure no bus delays overlap reset period */
David Daney76231e02011-09-30 12:17:48 +000057 err = mdiobus_read(phydev->bus, 30, 0);
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050058
59 /* data sheet specifies reset period is 2 msec */
60 mdelay(2);
61
62 /* enable IP175C mode */
David Daney76231e02011-09-30 12:17:48 +000063 err = mdiobus_write(phydev->bus, 29, 31, 0x175c);
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050064 if (err < 0)
65 return err;
66
67 /* Set MII0 speed and duplex (in PHY mode) */
David Daney76231e02011-09-30 12:17:48 +000068 err = mdiobus_write(phydev->bus, 29, 22, 0x420);
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050069 if (err < 0)
70 return err;
71
72 /* reset switch ports */
73 for (i = 0; i < 5; i++) {
David Daney76231e02011-09-30 12:17:48 +000074 err = mdiobus_write(phydev->bus, i,
75 MII_BMCR, BMCR_RESET);
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050076 if (err < 0)
77 return err;
78 }
79
80 for (i = 0; i < 5; i++)
David Daney76231e02011-09-30 12:17:48 +000081 err = mdiobus_read(phydev->bus, i, MII_BMCR);
Michael Barkowski0cefeeb2007-05-11 18:24:51 -050082
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{
David McKayb8e39952012-02-21 21:24:57 +0000101 int 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);
David McKayb8e39952012-02-21 21:24:57 +0000105 if (bmcr < 0)
106 return bmcr;
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000107 bmcr |= BMCR_RESET;
David McKayb8e39952012-02-21 21:24:57 +0000108 bmcr = phy_write(phydev, MII_BMCR, bmcr);
109 if (bmcr < 0)
110 return bmcr;
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000111
112 do {
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000113 bmcr = phy_read(phydev, MII_BMCR);
David McKayb8e39952012-02-21 21:24:57 +0000114 if (bmcr < 0)
115 return bmcr;
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000116 } while (bmcr & BMCR_RESET);
117
David McKayb8e39952012-02-21 21:24:57 +0000118 return 0;
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000119}
120
121static int ip1001_config_init(struct phy_device *phydev)
122{
123 int c;
124
125 c = ip1xx_reset(phydev);
126 if (c < 0)
127 return c;
128
129 /* Enable Auto Power Saving mode */
130 c = phy_read(phydev, IP1001_SPEC_CTRL_STATUS_2);
David McKayb8e39952012-02-21 21:24:57 +0000131 if (c < 0)
132 return c;
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000133 c |= IP1001_APS_ON;
David McKayb8e39952012-02-21 21:24:57 +0000134 c = phy_write(phydev, IP1001_SPEC_CTRL_STATUS_2, c);
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000135 if (c < 0)
136 return c;
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000137
Giuseppe CAVALLAROa4886d52011-10-10 21:37:56 +0000138 if (phydev->interface == PHY_INTERFACE_MODE_RGMII) {
139 /* Additional delay (2ns) used to adjust RX clock phase
140 * at RGMII interface */
141 c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS);
David McKayb8e39952012-02-21 21:24:57 +0000142 if (c < 0)
143 return c;
144
Giuseppe CAVALLAROa4886d52011-10-10 21:37:56 +0000145 c |= IP1001_PHASE_SEL_MASK;
146 c = phy_write(phydev, IP10XX_SPEC_CTRL_STATUS, c);
David McKayb8e39952012-02-21 21:24:57 +0000147 if (c < 0)
148 return c;
Giuseppe CAVALLAROa4886d52011-10-10 21:37:56 +0000149 }
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000150
David McKayb8e39952012-02-21 21:24:57 +0000151 return 0;
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000152}
153
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +0000154static int ip101a_g_config_init(struct phy_device *phydev)
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000155{
156 int c;
157
158 c = ip1xx_reset(phydev);
159 if (c < 0)
160 return c;
161
162 /* Enable Auto Power Saving mode */
163 c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS);
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +0000164 c |= IP101A_G_APS_ON;
Srinivas Kandagatlab3300142012-04-02 00:02:09 +0000165
166 return phy_write(phydev, IP10XX_SPEC_CTRL_STATUS, c);
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000167}
168
Michael Barkowski0cefeeb2007-05-11 18:24:51 -0500169static int ip175c_read_status(struct phy_device *phydev)
170{
171 if (phydev->addr == 4) /* WAN port */
172 genphy_read_status(phydev);
173 else
174 /* Don't need to read status for switch ports */
175 phydev->irq = PHY_IGNORE_INTERRUPT;
176
177 return 0;
178}
179
180static int ip175c_config_aneg(struct phy_device *phydev)
181{
182 if (phydev->addr == 4) /* WAN port */
183 genphy_config_aneg(phydev);
184
185 return 0;
186}
187
188static struct phy_driver ip175c_driver = {
189 .phy_id = 0x02430d80,
190 .name = "ICPlus IP175C",
191 .phy_id_mask = 0x0ffffff0,
192 .features = PHY_BASIC_FEATURES,
193 .config_init = &ip175c_config_init,
194 .config_aneg = &ip175c_config_aneg,
195 .read_status = &ip175c_read_status,
Giuseppe Cavallarodab10862010-07-20 13:24:25 -0700196 .suspend = genphy_suspend,
197 .resume = genphy_resume,
Michael Barkowski0cefeeb2007-05-11 18:24:51 -0500198 .driver = { .owner = THIS_MODULE,},
199};
200
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000201static struct phy_driver ip1001_driver = {
202 .phy_id = 0x02430d90,
203 .name = "ICPlus IP1001",
204 .phy_id_mask = 0x0ffffff0,
205 .features = PHY_GBIT_FEATURES | SUPPORTED_Pause |
206 SUPPORTED_Asym_Pause,
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +0000207 .flags = PHY_HAS_INTERRUPT,
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000208 .config_init = &ip1001_config_init,
209 .config_aneg = &genphy_config_aneg,
210 .read_status = &genphy_read_status,
211 .suspend = genphy_suspend,
212 .resume = genphy_resume,
213 .driver = { .owner = THIS_MODULE,},
214};
215
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +0000216static struct phy_driver ip101a_g_driver = {
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000217 .phy_id = 0x02430c54,
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +0000218 .name = "ICPlus IP101A/G",
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000219 .phy_id_mask = 0x0ffffff0,
220 .features = PHY_BASIC_FEATURES | SUPPORTED_Pause |
221 SUPPORTED_Asym_Pause,
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +0000222 .flags = PHY_HAS_INTERRUPT,
223 .config_init = &ip101a_g_config_init,
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000224 .config_aneg = &genphy_config_aneg,
225 .read_status = &genphy_read_status,
226 .suspend = genphy_suspend,
227 .resume = genphy_resume,
228 .driver = { .owner = THIS_MODULE,},
229};
230
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000231static int __init icplus_init(void)
Michael Barkowski0cefeeb2007-05-11 18:24:51 -0500232{
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000233 int ret = 0;
234
235 ret = phy_driver_register(&ip1001_driver);
236 if (ret < 0)
237 return -ENODEV;
238
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +0000239 ret = phy_driver_register(&ip101a_g_driver);
Giuseppe CAVALLARO9c9b1f22011-09-06 20:14:50 +0000240 if (ret < 0)
241 return -ENODEV;
242
Michael Barkowski0cefeeb2007-05-11 18:24:51 -0500243 return phy_driver_register(&ip175c_driver);
244}
245
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000246static void __exit icplus_exit(void)
Michael Barkowski0cefeeb2007-05-11 18:24:51 -0500247{
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000248 phy_driver_unregister(&ip1001_driver);
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +0000249 phy_driver_unregister(&ip101a_g_driver);
Michael Barkowski0cefeeb2007-05-11 18:24:51 -0500250 phy_driver_unregister(&ip175c_driver);
251}
252
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000253module_init(icplus_init);
254module_exit(icplus_exit);
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000255
Uwe Kleine-Königcf93c942010-10-03 23:43:32 +0000256static struct mdio_device_id __maybe_unused icplus_tbl[] = {
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000257 { 0x02430d80, 0x0ffffff0 },
Giuseppe CAVALLARO377ecca2010-12-08 23:05:13 +0000258 { 0x02430d90, 0x0ffffff0 },
Giuseppe CAVALLAROe3e09f22012-02-21 21:26:28 +0000259 { 0x02430c54, 0x0ffffff0 },
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000260 { }
261};
262
263MODULE_DEVICE_TABLE(mdio, icplus_tbl);