blob: 5e1eb138916f0c68cea34323ff5f146a60fbeaf8 [file] [log] [blame]
Giuseppe Cavallarof95be1802008-11-28 16:42:41 -08001/*
2 * drivers/net/phy/ste10Xp.c
3 *
4 * Driver for STMicroelectronics STe10Xp PHYs
5 *
6 * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
7 *
8 * Copyright (c) 2008 STMicroelectronics Limited
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
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/sched.h>
20#include <linux/kernel.h>
21#include <linux/moduleparam.h>
22#include <linux/interrupt.h>
23#include <linux/netdevice.h>
24#include <linux/ethtool.h>
25#include <linux/mii.h>
26#include <linux/phy.h>
27
28#define MII_XCIIS 0x11 /* Configuration Info IRQ & Status Reg */
29#define MII_XIE 0x12 /* Interrupt Enable Register */
30#define MII_XIE_DEFAULT_MASK 0x0070 /* ANE complete, Remote Fault, Link Down */
31
32#define STE101P_PHY_ID 0x00061c50
33#define STE100P_PHY_ID 0x1c040011
34
35static int ste10Xp_config_init(struct phy_device *phydev)
36{
37 int value, err;
38
39 /* Software Reset PHY */
40 value = phy_read(phydev, MII_BMCR);
41 if (value < 0)
42 return value;
43
44 value |= BMCR_RESET;
45 err = phy_write(phydev, MII_BMCR, value);
46 if (err < 0)
47 return err;
48
49 do {
50 value = phy_read(phydev, MII_BMCR);
51 } while (value & BMCR_RESET);
52
53 return 0;
54}
55
56static int ste10Xp_config_intr(struct phy_device *phydev)
57{
58 int err, value;
59
60 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
61 /* Enable all STe101P interrupts (PR12) */
62 err = phy_write(phydev, MII_XIE, MII_XIE_DEFAULT_MASK);
63 /* clear any pending interrupts */
64 if (err == 0) {
65 value = phy_read(phydev, MII_XCIIS);
66 if (value < 0)
67 err = value;
68 }
69 } else
70 err = phy_write(phydev, MII_XIE, 0);
71
72 return err;
73}
74
75static int ste10Xp_ack_interrupt(struct phy_device *phydev)
76{
77 int err = phy_read(phydev, MII_XCIIS);
78 if (err < 0)
79 return err;
80
81 return 0;
82}
83
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +000084static struct phy_driver ste10xp_pdriver[] = {
85{
Giuseppe Cavallarof95be1802008-11-28 16:42:41 -080086 .phy_id = STE101P_PHY_ID,
87 .phy_id_mask = 0xfffffff0,
88 .name = "STe101p",
89 .features = PHY_BASIC_FEATURES | SUPPORTED_Pause,
90 .flags = PHY_HAS_INTERRUPT,
91 .config_init = ste10Xp_config_init,
92 .config_aneg = genphy_config_aneg,
93 .read_status = genphy_read_status,
94 .ack_interrupt = ste10Xp_ack_interrupt,
95 .config_intr = ste10Xp_config_intr,
96 .suspend = genphy_suspend,
97 .resume = genphy_resume,
98 .driver = {.owner = THIS_MODULE,}
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +000099}, {
Giuseppe Cavallarof95be1802008-11-28 16:42:41 -0800100 .phy_id = STE100P_PHY_ID,
101 .phy_id_mask = 0xffffffff,
102 .name = "STe100p",
103 .features = PHY_BASIC_FEATURES | SUPPORTED_Pause,
104 .flags = PHY_HAS_INTERRUPT,
105 .config_init = ste10Xp_config_init,
106 .config_aneg = genphy_config_aneg,
107 .read_status = genphy_read_status,
108 .ack_interrupt = ste10Xp_ack_interrupt,
109 .config_intr = ste10Xp_config_intr,
110 .suspend = genphy_suspend,
111 .resume = genphy_resume,
112 .driver = {.owner = THIS_MODULE,}
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000113} };
Giuseppe Cavallarof95be1802008-11-28 16:42:41 -0800114
115static int __init ste10Xp_init(void)
116{
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000117 return phy_drivers_register(ste10xp_pdriver,
118 ARRAY_SIZE(ste10xp_pdriver));
Giuseppe Cavallarof95be1802008-11-28 16:42:41 -0800119}
120
121static void __exit ste10Xp_exit(void)
122{
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000123 phy_drivers_unregister(ste10xp_pdriver,
124 ARRAY_SIZE(ste10xp_pdriver));
Giuseppe Cavallarof95be1802008-11-28 16:42:41 -0800125}
126
127module_init(ste10Xp_init);
128module_exit(ste10Xp_exit);
129
Uwe Kleine-Königcf93c942010-10-03 23:43:32 +0000130static struct mdio_device_id __maybe_unused ste10Xp_tbl[] = {
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000131 { STE101P_PHY_ID, 0xfffffff0 },
132 { STE100P_PHY_ID, 0xffffffff },
133 { }
134};
135
136MODULE_DEVICE_TABLE(mdio, ste10Xp_tbl);
137
Giuseppe Cavallarof95be1802008-11-28 16:42:41 -0800138MODULE_DESCRIPTION("STMicroelectronics STe10Xp PHY driver");
139MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
140MODULE_LICENSE("GPL");