Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1 | /* |
| 2 | * drivers/net/phy/lxt.c |
| 3 | * |
| 4 | * Driver for Intel LXT 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 | */ |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 16 | #include <linux/kernel.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 17 | #include <linux/string.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/unistd.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/delay.h> |
| 23 | #include <linux/netdevice.h> |
| 24 | #include <linux/etherdevice.h> |
| 25 | #include <linux/skbuff.h> |
| 26 | #include <linux/spinlock.h> |
| 27 | #include <linux/mm.h> |
| 28 | #include <linux/module.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 29 | #include <linux/mii.h> |
| 30 | #include <linux/ethtool.h> |
| 31 | #include <linux/phy.h> |
| 32 | |
| 33 | #include <asm/io.h> |
| 34 | #include <asm/irq.h> |
| 35 | #include <asm/uaccess.h> |
| 36 | |
| 37 | /* The Level one LXT970 is used by many boards */ |
| 38 | |
| 39 | #define MII_LXT970_IER 17 /* Interrupt Enable Register */ |
| 40 | |
| 41 | #define MII_LXT970_IER_IEN 0x0002 |
| 42 | |
| 43 | #define MII_LXT970_ISR 18 /* Interrupt Status Register */ |
| 44 | |
| 45 | #define MII_LXT970_CONFIG 19 /* Configuration Register */ |
| 46 | |
| 47 | /* ------------------------------------------------------------------------- */ |
| 48 | /* The Level one LXT971 is used on some of my custom boards */ |
| 49 | |
| 50 | /* register definitions for the 971 */ |
| 51 | #define MII_LXT971_IER 18 /* Interrupt Enable Register */ |
| 52 | #define MII_LXT971_IER_IEN 0x00f2 |
| 53 | |
| 54 | #define MII_LXT971_ISR 19 /* Interrupt Status Register */ |
| 55 | |
| 56 | |
| 57 | MODULE_DESCRIPTION("Intel LXT PHY driver"); |
| 58 | MODULE_AUTHOR("Andy Fleming"); |
| 59 | MODULE_LICENSE("GPL"); |
| 60 | |
| 61 | static int lxt970_ack_interrupt(struct phy_device *phydev) |
| 62 | { |
| 63 | int err; |
| 64 | |
| 65 | err = phy_read(phydev, MII_BMSR); |
| 66 | |
| 67 | if (err < 0) |
| 68 | return err; |
| 69 | |
| 70 | err = phy_read(phydev, MII_LXT970_ISR); |
| 71 | |
| 72 | if (err < 0) |
| 73 | return err; |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static int lxt970_config_intr(struct phy_device *phydev) |
| 79 | { |
| 80 | int err; |
| 81 | |
| 82 | if(phydev->interrupts == PHY_INTERRUPT_ENABLED) |
| 83 | err = phy_write(phydev, MII_LXT970_IER, MII_LXT970_IER_IEN); |
| 84 | else |
| 85 | err = phy_write(phydev, MII_LXT970_IER, 0); |
| 86 | |
| 87 | return err; |
| 88 | } |
| 89 | |
| 90 | static int lxt970_config_init(struct phy_device *phydev) |
| 91 | { |
| 92 | int err; |
| 93 | |
| 94 | err = phy_write(phydev, MII_LXT970_CONFIG, 0); |
| 95 | |
| 96 | return err; |
| 97 | } |
| 98 | |
| 99 | |
| 100 | static int lxt971_ack_interrupt(struct phy_device *phydev) |
| 101 | { |
| 102 | int err = phy_read(phydev, MII_LXT971_ISR); |
| 103 | |
| 104 | if (err < 0) |
| 105 | return err; |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | static int lxt971_config_intr(struct phy_device *phydev) |
| 111 | { |
| 112 | int err; |
| 113 | |
| 114 | if(phydev->interrupts == PHY_INTERRUPT_ENABLED) |
| 115 | err = phy_write(phydev, MII_LXT971_IER, MII_LXT971_IER_IEN); |
| 116 | else |
| 117 | err = phy_write(phydev, MII_LXT971_IER, 0); |
| 118 | |
| 119 | return err; |
| 120 | } |
| 121 | |
| 122 | static struct phy_driver lxt970_driver = { |
Uwe Zeisberger | 600991b | 2006-06-25 01:44:37 -0700 | [diff] [blame] | 123 | .phy_id = 0x78100000, |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 124 | .name = "LXT970", |
Uwe Zeisberger | 600991b | 2006-06-25 01:44:37 -0700 | [diff] [blame] | 125 | .phy_id_mask = 0xfffffff0, |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 126 | .features = PHY_BASIC_FEATURES, |
| 127 | .flags = PHY_HAS_INTERRUPT, |
| 128 | .config_init = lxt970_config_init, |
| 129 | .config_aneg = genphy_config_aneg, |
| 130 | .read_status = genphy_read_status, |
| 131 | .ack_interrupt = lxt970_ack_interrupt, |
| 132 | .config_intr = lxt970_config_intr, |
| 133 | .driver = { .owner = THIS_MODULE,}, |
| 134 | }; |
| 135 | |
| 136 | static struct phy_driver lxt971_driver = { |
Uwe Zeisberger | 600991b | 2006-06-25 01:44:37 -0700 | [diff] [blame] | 137 | .phy_id = 0x001378e0, |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 138 | .name = "LXT971", |
Uwe Zeisberger | 600991b | 2006-06-25 01:44:37 -0700 | [diff] [blame] | 139 | .phy_id_mask = 0xfffffff0, |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 140 | .features = PHY_BASIC_FEATURES, |
| 141 | .flags = PHY_HAS_INTERRUPT, |
| 142 | .config_aneg = genphy_config_aneg, |
| 143 | .read_status = genphy_read_status, |
| 144 | .ack_interrupt = lxt971_ack_interrupt, |
| 145 | .config_intr = lxt971_config_intr, |
| 146 | .driver = { .owner = THIS_MODULE,}, |
| 147 | }; |
| 148 | |
| 149 | static int __init lxt_init(void) |
| 150 | { |
| 151 | int ret; |
| 152 | |
| 153 | ret = phy_driver_register(&lxt970_driver); |
| 154 | if (ret) |
| 155 | goto err1; |
| 156 | |
| 157 | ret = phy_driver_register(&lxt971_driver); |
| 158 | if (ret) |
| 159 | goto err2; |
| 160 | return 0; |
| 161 | |
| 162 | err2: |
| 163 | phy_driver_unregister(&lxt970_driver); |
| 164 | err1: |
| 165 | return ret; |
| 166 | } |
| 167 | |
| 168 | static void __exit lxt_exit(void) |
| 169 | { |
| 170 | phy_driver_unregister(&lxt970_driver); |
| 171 | phy_driver_unregister(&lxt971_driver); |
| 172 | } |
| 173 | |
| 174 | module_init(lxt_init); |
| 175 | module_exit(lxt_exit); |
David Woodhouse | 4e4f10f | 2010-04-02 01:05:56 +0000 | [diff] [blame] | 176 | |
| 177 | static struct mdio_device_id lxt_tbl[] = { |
| 178 | { 0x78100000, 0xfffffff0 }, |
| 179 | { 0x001378e0, 0xfffffff0 }, |
| 180 | { } |
| 181 | }; |
| 182 | |
| 183 | MODULE_DEVICE_TABLE(mdio, lxt_tbl); |