1 /* 2 * drivers/net/phy/marvell.c 3 * 4 * Driver for Marvell PHYs 5 * 6 * Author: Andy Fleming 7 * 8 * Copyright (c) 2004 Freescale Semiconductor, Inc. 9 * 10 * This program is free software; you can redistribute it and/or modify it 11 * under the terms of the GNU General Public License as published by the 12 * Free Software Foundation; either version 2 of the License, or (at your 13 * option) any later version. 14 * 15 */ 16 #include <linux/config.h> 17 #include <linux/kernel.h> 18 #include <linux/sched.h> 19 #include <linux/string.h> 20 #include <linux/errno.h> 21 #include <linux/unistd.h> 22 #include <linux/slab.h> 23 #include <linux/interrupt.h> 24 #include <linux/init.h> 25 #include <linux/delay.h> 26 #include <linux/netdevice.h> 27 #include <linux/etherdevice.h> 28 #include <linux/skbuff.h> 29 #include <linux/spinlock.h> 30 #include <linux/mm.h> 31 #include <linux/module.h> 32 #include <linux/version.h> 33 #include <linux/mii.h> 34 #include <linux/ethtool.h> 35 #include <linux/phy.h> 36 37 #include <asm/io.h> 38 #include <asm/irq.h> 39 #include <asm/uaccess.h> 40 41 #define MII_M1011_IEVENT 0x13 42 #define MII_M1011_IEVENT_CLEAR 0x0000 43 44 #define MII_M1011_IMASK 0x12 45 #define MII_M1011_IMASK_INIT 0x6400 46 #define MII_M1011_IMASK_CLEAR 0x0000 47 48 MODULE_DESCRIPTION("Marvell PHY driver"); 49 MODULE_AUTHOR("Andy Fleming"); 50 MODULE_LICENSE("GPL"); 51 52 static int marvell_ack_interrupt(struct phy_device *phydev) 53 { 54 int err; 55 56 /* Clear the interrupts by reading the reg */ 57 err = phy_read(phydev, MII_M1011_IEVENT); 58 59 if (err < 0) 60 return err; 61 62 return 0; 63 } 64 65 static int marvell_config_intr(struct phy_device *phydev) 66 { 67 int err; 68 69 if(phydev->interrupts == PHY_INTERRUPT_ENABLED) 70 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_INIT); 71 else 72 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR); 73 74 return err; 75 } 76 77 static int marvell_config_aneg(struct phy_device *phydev) 78 { 79 int err; 80 81 /* The Marvell PHY has an errata which requires 82 * that certain registers get written in order 83 * to restart autonegotiation */ 84 err = phy_write(phydev, MII_BMCR, BMCR_RESET); 85 86 if (err < 0) 87 return err; 88 89 err = phy_write(phydev, 0x1d, 0x1f); 90 if (err < 0) 91 return err; 92 93 err = phy_write(phydev, 0x1e, 0x200c); 94 if (err < 0) 95 return err; 96 97 err = phy_write(phydev, 0x1d, 0x5); 98 if (err < 0) 99 return err; 100 101 err = phy_write(phydev, 0x1e, 0); 102 if (err < 0) 103 return err; 104 105 err = phy_write(phydev, 0x1e, 0x100); 106 if (err < 0) 107 return err; 108 109 110 err = genphy_config_aneg(phydev); 111 112 return err; 113 } 114 115 116 static struct phy_driver m88e1101_driver = { 117 .phy_id = 0x01410c00, 118 .phy_id_mask = 0xffffff00, 119 .name = "Marvell 88E1101", 120 .features = PHY_GBIT_FEATURES, 121 .flags = PHY_HAS_INTERRUPT, 122 .config_aneg = &marvell_config_aneg, 123 .read_status = &genphy_read_status, 124 .ack_interrupt = &marvell_ack_interrupt, 125 .config_intr = &marvell_config_intr, 126 .driver = { .owner = THIS_MODULE,}, 127 }; 128 129 static int __init marvell_init(void) 130 { 131 return phy_driver_register(&m88e1101_driver); 132 } 133 134 static void __exit marvell_exit(void) 135 { 136 phy_driver_unregister(&m88e1101_driver); 137 } 138 139 module_init(marvell_init); 140 module_exit(marvell_exit); 141