Andrew Lunn | a2443fd | 2019-01-21 19:05:50 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Giuseppe Cavallaro | f95be180 | 2008-11-28 16:42:41 -0800 | [diff] [blame] | 2 | /* |
| 3 | * drivers/net/phy/ste10Xp.c |
| 4 | * |
| 5 | * Driver for STMicroelectronics STe10Xp PHYs |
| 6 | * |
| 7 | * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com> |
| 8 | * |
| 9 | * Copyright (c) 2008 STMicroelectronics Limited |
Giuseppe Cavallaro | f95be180 | 2008-11-28 16:42:41 -0800 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/sched.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/moduleparam.h> |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/netdevice.h> |
| 19 | #include <linux/ethtool.h> |
| 20 | #include <linux/mii.h> |
| 21 | #include <linux/phy.h> |
| 22 | |
| 23 | #define MII_XCIIS 0x11 /* Configuration Info IRQ & Status Reg */ |
| 24 | #define MII_XIE 0x12 /* Interrupt Enable Register */ |
| 25 | #define MII_XIE_DEFAULT_MASK 0x0070 /* ANE complete, Remote Fault, Link Down */ |
| 26 | |
| 27 | #define STE101P_PHY_ID 0x00061c50 |
| 28 | #define STE100P_PHY_ID 0x1c040011 |
| 29 | |
| 30 | static int ste10Xp_config_init(struct phy_device *phydev) |
| 31 | { |
| 32 | int value, err; |
| 33 | |
| 34 | /* Software Reset PHY */ |
| 35 | value = phy_read(phydev, MII_BMCR); |
| 36 | if (value < 0) |
| 37 | return value; |
| 38 | |
| 39 | value |= BMCR_RESET; |
| 40 | err = phy_write(phydev, MII_BMCR, value); |
| 41 | if (err < 0) |
| 42 | return err; |
| 43 | |
| 44 | do { |
| 45 | value = phy_read(phydev, MII_BMCR); |
| 46 | } while (value & BMCR_RESET); |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static int ste10Xp_config_intr(struct phy_device *phydev) |
| 52 | { |
| 53 | int err, value; |
| 54 | |
| 55 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { |
| 56 | /* Enable all STe101P interrupts (PR12) */ |
| 57 | err = phy_write(phydev, MII_XIE, MII_XIE_DEFAULT_MASK); |
| 58 | /* clear any pending interrupts */ |
| 59 | if (err == 0) { |
| 60 | value = phy_read(phydev, MII_XCIIS); |
| 61 | if (value < 0) |
| 62 | err = value; |
| 63 | } |
| 64 | } else |
| 65 | err = phy_write(phydev, MII_XIE, 0); |
| 66 | |
| 67 | return err; |
| 68 | } |
| 69 | |
| 70 | static int ste10Xp_ack_interrupt(struct phy_device *phydev) |
| 71 | { |
| 72 | int err = phy_read(phydev, MII_XCIIS); |
| 73 | if (err < 0) |
| 74 | return err; |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
Christian Hohnstaedt | d5bf907 | 2012-07-04 05:44:34 +0000 | [diff] [blame] | 79 | static struct phy_driver ste10xp_pdriver[] = { |
| 80 | { |
Giuseppe Cavallaro | f95be180 | 2008-11-28 16:42:41 -0800 | [diff] [blame] | 81 | .phy_id = STE101P_PHY_ID, |
| 82 | .phy_id_mask = 0xfffffff0, |
| 83 | .name = "STe101p", |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 84 | /* PHY_BASIC_FEATURES */ |
Giuseppe Cavallaro | f95be180 | 2008-11-28 16:42:41 -0800 | [diff] [blame] | 85 | .config_init = ste10Xp_config_init, |
Giuseppe Cavallaro | f95be180 | 2008-11-28 16:42:41 -0800 | [diff] [blame] | 86 | .ack_interrupt = ste10Xp_ack_interrupt, |
| 87 | .config_intr = ste10Xp_config_intr, |
| 88 | .suspend = genphy_suspend, |
| 89 | .resume = genphy_resume, |
Christian Hohnstaedt | d5bf907 | 2012-07-04 05:44:34 +0000 | [diff] [blame] | 90 | }, { |
Giuseppe Cavallaro | f95be180 | 2008-11-28 16:42:41 -0800 | [diff] [blame] | 91 | .phy_id = STE100P_PHY_ID, |
| 92 | .phy_id_mask = 0xffffffff, |
| 93 | .name = "STe100p", |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 94 | /* PHY_BASIC_FEATURES */ |
Giuseppe Cavallaro | f95be180 | 2008-11-28 16:42:41 -0800 | [diff] [blame] | 95 | .config_init = ste10Xp_config_init, |
Giuseppe Cavallaro | f95be180 | 2008-11-28 16:42:41 -0800 | [diff] [blame] | 96 | .ack_interrupt = ste10Xp_ack_interrupt, |
| 97 | .config_intr = ste10Xp_config_intr, |
| 98 | .suspend = genphy_suspend, |
| 99 | .resume = genphy_resume, |
Christian Hohnstaedt | d5bf907 | 2012-07-04 05:44:34 +0000 | [diff] [blame] | 100 | } }; |
Giuseppe Cavallaro | f95be180 | 2008-11-28 16:42:41 -0800 | [diff] [blame] | 101 | |
Johan Hovold | 50fd715 | 2014-11-11 19:45:59 +0100 | [diff] [blame] | 102 | module_phy_driver(ste10xp_pdriver); |
Giuseppe Cavallaro | f95be180 | 2008-11-28 16:42:41 -0800 | [diff] [blame] | 103 | |
Uwe Kleine-König | cf93c94 | 2010-10-03 23:43:32 +0000 | [diff] [blame] | 104 | static struct mdio_device_id __maybe_unused ste10Xp_tbl[] = { |
David Woodhouse | 4e4f10f | 2010-04-02 01:05:56 +0000 | [diff] [blame] | 105 | { STE101P_PHY_ID, 0xfffffff0 }, |
| 106 | { STE100P_PHY_ID, 0xffffffff }, |
| 107 | { } |
| 108 | }; |
| 109 | |
| 110 | MODULE_DEVICE_TABLE(mdio, ste10Xp_tbl); |
| 111 | |
Giuseppe Cavallaro | f95be180 | 2008-11-28 16:42:41 -0800 | [diff] [blame] | 112 | MODULE_DESCRIPTION("STMicroelectronics STe10Xp PHY driver"); |
| 113 | MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>"); |
| 114 | MODULE_LICENSE("GPL"); |