generic: ar8216: add setup_port field to ar8xxx_chip
[openwrt.git] / target / linux / generic / files / drivers / net / phy / micrel.c
1 /*
2  *  Driver for Micrel/Kendin PHYs
3  *
4  *  Copyright (c) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
5  *  Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6  *
7  *  This program is free software; you can redistribute it and/or modify it
8  *  under the terms of the GNU General Public License version 2 as published
9  *  by the Free Software Foundation.
10  *
11  */
12
13 #include <linux/module.h>
14 #include <linux/delay.h>
15 #include <linux/skbuff.h>
16 #include <linux/phy.h>
17
18 #define KSZ_REG_INT_CTRL        0x1b
19
20 #define KSZ_INT_LU_EN   (1 << 8)        /* enable Link Up interrupt */
21 #define KSZ_INT_RF_EN   (1 << 9)        /* enable Remote Fault interrupt */
22 #define KSZ_INT_LD_EN   (1 << 10)       /* enable Link Down interrupt */
23
24 #define KSZ_INT_INIT    (KSZ_INT_LU_EN | KSZ_INT_LD_EN)
25
26 static int ksz8041_ack_interrupt(struct phy_device *phydev)
27 {
28         int err;
29
30         err = phy_read(phydev, KSZ_REG_INT_CTRL);
31
32         return (err < 0) ? err : 0;
33 }
34
35 static int ksz8041_config_intr(struct phy_device *phydev)
36 {
37         int err;
38
39         if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
40                 err = phy_write(phydev, KSZ_REG_INT_CTRL,
41                                 KSZ_INT_INIT);
42         else
43                 err = phy_write(phydev, KSZ_REG_INT_CTRL, 0);
44
45         return err;
46 }
47
48 static struct phy_driver ksz8041_phy_driver = {
49         .phy_id         = 0x00221512,
50         .name           = "Micrel KSZ8041",
51         .phy_id_mask    = 0x001fffff,
52         .features       = PHY_BASIC_FEATURES,
53         .flags          = PHY_HAS_INTERRUPT,
54         .config_aneg    = genphy_config_aneg,
55         .read_status    = genphy_read_status,
56         .ack_interrupt  = ksz8041_ack_interrupt,
57         .config_intr    = ksz8041_config_intr,
58         .driver = {
59                 .owner  = THIS_MODULE,
60         },
61 };
62
63 static int __init micrel_phy_init(void)
64 {
65         return phy_driver_register(&ksz8041_phy_driver);
66 }
67
68 static void __exit micrel_phy_exit(void)
69 {
70         phy_driver_unregister(&ksz8041_phy_driver);
71 }
72
73 #ifdef MODULE
74 module_init(micrel_phy_init);
75 module_exit(micrel_phy_exit);
76 #else
77 subsys_initcall(micrel_phy_init);
78 #endif
79
80 MODULE_DESCRIPTION("Micrel/Kendin PHY driver");
81 MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
82 MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org>");
83 MODULE_LICENSE("GPL v2");