10cefeebaSMichael Barkowski /* 20cefeebaSMichael Barkowski * Driver for ICPlus PHYs 30cefeebaSMichael Barkowski * 40cefeebaSMichael Barkowski * Copyright (c) 2007 Freescale Semiconductor, Inc. 50cefeebaSMichael Barkowski * 60cefeebaSMichael Barkowski * This program is free software; you can redistribute it and/or modify it 70cefeebaSMichael Barkowski * under the terms of the GNU General Public License as published by the 80cefeebaSMichael Barkowski * Free Software Foundation; either version 2 of the License, or (at your 90cefeebaSMichael Barkowski * option) any later version. 100cefeebaSMichael Barkowski * 110cefeebaSMichael Barkowski */ 120cefeebaSMichael Barkowski #include <linux/kernel.h> 130cefeebaSMichael Barkowski #include <linux/string.h> 140cefeebaSMichael Barkowski #include <linux/errno.h> 150cefeebaSMichael Barkowski #include <linux/unistd.h> 160cefeebaSMichael Barkowski #include <linux/interrupt.h> 170cefeebaSMichael Barkowski #include <linux/init.h> 180cefeebaSMichael Barkowski #include <linux/delay.h> 190cefeebaSMichael Barkowski #include <linux/netdevice.h> 200cefeebaSMichael Barkowski #include <linux/etherdevice.h> 210cefeebaSMichael Barkowski #include <linux/skbuff.h> 220cefeebaSMichael Barkowski #include <linux/spinlock.h> 230cefeebaSMichael Barkowski #include <linux/mm.h> 240cefeebaSMichael Barkowski #include <linux/module.h> 250cefeebaSMichael Barkowski #include <linux/mii.h> 260cefeebaSMichael Barkowski #include <linux/ethtool.h> 270cefeebaSMichael Barkowski #include <linux/phy.h> 280cefeebaSMichael Barkowski 290cefeebaSMichael Barkowski #include <asm/io.h> 300cefeebaSMichael Barkowski #include <asm/irq.h> 310cefeebaSMichael Barkowski #include <asm/uaccess.h> 320cefeebaSMichael Barkowski 33*377ecca9SGiuseppe CAVALLARO MODULE_DESCRIPTION("ICPlus IP175C/IC1001 PHY drivers"); 340cefeebaSMichael Barkowski MODULE_AUTHOR("Michael Barkowski"); 350cefeebaSMichael Barkowski MODULE_LICENSE("GPL"); 360cefeebaSMichael Barkowski 370cefeebaSMichael Barkowski static int ip175c_config_init(struct phy_device *phydev) 380cefeebaSMichael Barkowski { 390cefeebaSMichael Barkowski int err, i; 400cefeebaSMichael Barkowski static int full_reset_performed = 0; 410cefeebaSMichael Barkowski 420cefeebaSMichael Barkowski if (full_reset_performed == 0) { 430cefeebaSMichael Barkowski 440cefeebaSMichael Barkowski /* master reset */ 450cefeebaSMichael Barkowski err = phydev->bus->write(phydev->bus, 30, 0, 0x175c); 460cefeebaSMichael Barkowski if (err < 0) 470cefeebaSMichael Barkowski return err; 480cefeebaSMichael Barkowski 490cefeebaSMichael Barkowski /* ensure no bus delays overlap reset period */ 500cefeebaSMichael Barkowski err = phydev->bus->read(phydev->bus, 30, 0); 510cefeebaSMichael Barkowski 520cefeebaSMichael Barkowski /* data sheet specifies reset period is 2 msec */ 530cefeebaSMichael Barkowski mdelay(2); 540cefeebaSMichael Barkowski 550cefeebaSMichael Barkowski /* enable IP175C mode */ 560cefeebaSMichael Barkowski err = phydev->bus->write(phydev->bus, 29, 31, 0x175c); 570cefeebaSMichael Barkowski if (err < 0) 580cefeebaSMichael Barkowski return err; 590cefeebaSMichael Barkowski 600cefeebaSMichael Barkowski /* Set MII0 speed and duplex (in PHY mode) */ 610cefeebaSMichael Barkowski err = phydev->bus->write(phydev->bus, 29, 22, 0x420); 620cefeebaSMichael Barkowski if (err < 0) 630cefeebaSMichael Barkowski return err; 640cefeebaSMichael Barkowski 650cefeebaSMichael Barkowski /* reset switch ports */ 660cefeebaSMichael Barkowski for (i = 0; i < 5; i++) { 670cefeebaSMichael Barkowski err = phydev->bus->write(phydev->bus, i, 680cefeebaSMichael Barkowski MII_BMCR, BMCR_RESET); 690cefeebaSMichael Barkowski if (err < 0) 700cefeebaSMichael Barkowski return err; 710cefeebaSMichael Barkowski } 720cefeebaSMichael Barkowski 730cefeebaSMichael Barkowski for (i = 0; i < 5; i++) 740cefeebaSMichael Barkowski err = phydev->bus->read(phydev->bus, i, MII_BMCR); 750cefeebaSMichael Barkowski 760cefeebaSMichael Barkowski mdelay(2); 770cefeebaSMichael Barkowski 780cefeebaSMichael Barkowski full_reset_performed = 1; 790cefeebaSMichael Barkowski } 800cefeebaSMichael Barkowski 810cefeebaSMichael Barkowski if (phydev->addr != 4) { 820cefeebaSMichael Barkowski phydev->state = PHY_RUNNING; 830cefeebaSMichael Barkowski phydev->speed = SPEED_100; 840cefeebaSMichael Barkowski phydev->duplex = DUPLEX_FULL; 850cefeebaSMichael Barkowski phydev->link = 1; 860cefeebaSMichael Barkowski netif_carrier_on(phydev->attached_dev); 870cefeebaSMichael Barkowski } 880cefeebaSMichael Barkowski 890cefeebaSMichael Barkowski return 0; 900cefeebaSMichael Barkowski } 910cefeebaSMichael Barkowski 92*377ecca9SGiuseppe CAVALLARO static int ip1001_config_init(struct phy_device *phydev) 93*377ecca9SGiuseppe CAVALLARO { 94*377ecca9SGiuseppe CAVALLARO int err, value; 95*377ecca9SGiuseppe CAVALLARO 96*377ecca9SGiuseppe CAVALLARO /* Software Reset PHY */ 97*377ecca9SGiuseppe CAVALLARO value = phy_read(phydev, MII_BMCR); 98*377ecca9SGiuseppe CAVALLARO value |= BMCR_RESET; 99*377ecca9SGiuseppe CAVALLARO err = phy_write(phydev, MII_BMCR, value); 100*377ecca9SGiuseppe CAVALLARO if (err < 0) 101*377ecca9SGiuseppe CAVALLARO return err; 102*377ecca9SGiuseppe CAVALLARO 103*377ecca9SGiuseppe CAVALLARO do { 104*377ecca9SGiuseppe CAVALLARO value = phy_read(phydev, MII_BMCR); 105*377ecca9SGiuseppe CAVALLARO } while (value & BMCR_RESET); 106*377ecca9SGiuseppe CAVALLARO 107*377ecca9SGiuseppe CAVALLARO /* Additional delay (2ns) used to adjust RX clock phase 108*377ecca9SGiuseppe CAVALLARO * at GMII/ RGMII interface */ 109*377ecca9SGiuseppe CAVALLARO value = phy_read(phydev, 16); 110*377ecca9SGiuseppe CAVALLARO value |= 0x3; 111*377ecca9SGiuseppe CAVALLARO 112*377ecca9SGiuseppe CAVALLARO err = phy_write(phydev, 16, value); 113*377ecca9SGiuseppe CAVALLARO if (err < 0) 114*377ecca9SGiuseppe CAVALLARO return err; 115*377ecca9SGiuseppe CAVALLARO 116*377ecca9SGiuseppe CAVALLARO return err; 117*377ecca9SGiuseppe CAVALLARO } 118*377ecca9SGiuseppe CAVALLARO 1190cefeebaSMichael Barkowski static int ip175c_read_status(struct phy_device *phydev) 1200cefeebaSMichael Barkowski { 1210cefeebaSMichael Barkowski if (phydev->addr == 4) /* WAN port */ 1220cefeebaSMichael Barkowski genphy_read_status(phydev); 1230cefeebaSMichael Barkowski else 1240cefeebaSMichael Barkowski /* Don't need to read status for switch ports */ 1250cefeebaSMichael Barkowski phydev->irq = PHY_IGNORE_INTERRUPT; 1260cefeebaSMichael Barkowski 1270cefeebaSMichael Barkowski return 0; 1280cefeebaSMichael Barkowski } 1290cefeebaSMichael Barkowski 1300cefeebaSMichael Barkowski static int ip175c_config_aneg(struct phy_device *phydev) 1310cefeebaSMichael Barkowski { 1320cefeebaSMichael Barkowski if (phydev->addr == 4) /* WAN port */ 1330cefeebaSMichael Barkowski genphy_config_aneg(phydev); 1340cefeebaSMichael Barkowski 1350cefeebaSMichael Barkowski return 0; 1360cefeebaSMichael Barkowski } 1370cefeebaSMichael Barkowski 1380cefeebaSMichael Barkowski static struct phy_driver ip175c_driver = { 1390cefeebaSMichael Barkowski .phy_id = 0x02430d80, 1400cefeebaSMichael Barkowski .name = "ICPlus IP175C", 1410cefeebaSMichael Barkowski .phy_id_mask = 0x0ffffff0, 1420cefeebaSMichael Barkowski .features = PHY_BASIC_FEATURES, 1430cefeebaSMichael Barkowski .config_init = &ip175c_config_init, 1440cefeebaSMichael Barkowski .config_aneg = &ip175c_config_aneg, 1450cefeebaSMichael Barkowski .read_status = &ip175c_read_status, 146dab10863SGiuseppe Cavallaro .suspend = genphy_suspend, 147dab10863SGiuseppe Cavallaro .resume = genphy_resume, 1480cefeebaSMichael Barkowski .driver = { .owner = THIS_MODULE,}, 1490cefeebaSMichael Barkowski }; 1500cefeebaSMichael Barkowski 151*377ecca9SGiuseppe CAVALLARO static struct phy_driver ip1001_driver = { 152*377ecca9SGiuseppe CAVALLARO .phy_id = 0x02430d90, 153*377ecca9SGiuseppe CAVALLARO .name = "ICPlus IP1001", 154*377ecca9SGiuseppe CAVALLARO .phy_id_mask = 0x0ffffff0, 155*377ecca9SGiuseppe CAVALLARO .features = PHY_GBIT_FEATURES | SUPPORTED_Pause | 156*377ecca9SGiuseppe CAVALLARO SUPPORTED_Asym_Pause, 157*377ecca9SGiuseppe CAVALLARO .config_init = &ip1001_config_init, 158*377ecca9SGiuseppe CAVALLARO .config_aneg = &genphy_config_aneg, 159*377ecca9SGiuseppe CAVALLARO .read_status = &genphy_read_status, 160*377ecca9SGiuseppe CAVALLARO .suspend = genphy_suspend, 161*377ecca9SGiuseppe CAVALLARO .resume = genphy_resume, 162*377ecca9SGiuseppe CAVALLARO .driver = { .owner = THIS_MODULE,}, 163*377ecca9SGiuseppe CAVALLARO }; 164*377ecca9SGiuseppe CAVALLARO 165*377ecca9SGiuseppe CAVALLARO static int __init icplus_init(void) 1660cefeebaSMichael Barkowski { 167*377ecca9SGiuseppe CAVALLARO int ret = 0; 168*377ecca9SGiuseppe CAVALLARO 169*377ecca9SGiuseppe CAVALLARO ret = phy_driver_register(&ip1001_driver); 170*377ecca9SGiuseppe CAVALLARO if (ret < 0) 171*377ecca9SGiuseppe CAVALLARO return -ENODEV; 172*377ecca9SGiuseppe CAVALLARO 1730cefeebaSMichael Barkowski return phy_driver_register(&ip175c_driver); 1740cefeebaSMichael Barkowski } 1750cefeebaSMichael Barkowski 176*377ecca9SGiuseppe CAVALLARO static void __exit icplus_exit(void) 1770cefeebaSMichael Barkowski { 178*377ecca9SGiuseppe CAVALLARO phy_driver_unregister(&ip1001_driver); 1790cefeebaSMichael Barkowski phy_driver_unregister(&ip175c_driver); 1800cefeebaSMichael Barkowski } 1810cefeebaSMichael Barkowski 182*377ecca9SGiuseppe CAVALLARO module_init(icplus_init); 183*377ecca9SGiuseppe CAVALLARO module_exit(icplus_exit); 1844e4f10f6SDavid Woodhouse 185cf93c945SUwe Kleine-König static struct mdio_device_id __maybe_unused icplus_tbl[] = { 1864e4f10f6SDavid Woodhouse { 0x02430d80, 0x0ffffff0 }, 187*377ecca9SGiuseppe CAVALLARO { 0x02430d90, 0x0ffffff0 }, 1884e4f10f6SDavid Woodhouse { } 1894e4f10f6SDavid Woodhouse }; 1904e4f10f6SDavid Woodhouse 1914e4f10f6SDavid Woodhouse MODULE_DEVICE_TABLE(mdio, icplus_tbl); 192