Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1 | /* |
| 2 | * drivers/net/phy/mdio_bus.c |
| 3 | * |
| 4 | * MDIO Bus interface |
| 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 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 41 | /* mdio_bus_match |
| 42 | * |
| 43 | * description: Given a PHY device, and a PHY driver, return 1 if |
| 44 | * the driver supports the device. Otherwise, return 0 |
| 45 | */ |
| 46 | static int mdio_bus_match(struct device *dev, struct device_driver *drv) |
| 47 | { |
| 48 | struct phy_device *phydev = to_phy_device(dev); |
| 49 | struct phy_driver *phydrv = to_phy_driver(drv); |
| 50 | |
| 51 | return (phydrv->phy_id == (phydev->phy_id & phydrv->phy_id_mask)); |
| 52 | } |
| 53 | |
| 54 | /* Suspend and resume. Copied from platform_suspend and |
| 55 | * platform_resume |
| 56 | */ |
| 57 | static int mdio_bus_suspend(struct device * dev, u32 state) |
| 58 | { |
| 59 | int ret = 0; |
| 60 | struct device_driver *drv = dev->driver; |
| 61 | |
| 62 | if (drv && drv->suspend) { |
| 63 | ret = drv->suspend(dev, state, SUSPEND_DISABLE); |
| 64 | if (ret == 0) |
| 65 | ret = drv->suspend(dev, state, SUSPEND_SAVE_STATE); |
| 66 | if (ret == 0) |
| 67 | ret = drv->suspend(dev, state, SUSPEND_POWER_DOWN); |
| 68 | } |
| 69 | return ret; |
| 70 | } |
| 71 | |
| 72 | static int mdio_bus_resume(struct device * dev) |
| 73 | { |
| 74 | int ret = 0; |
| 75 | struct device_driver *drv = dev->driver; |
| 76 | |
| 77 | if (drv && drv->resume) { |
| 78 | ret = drv->resume(dev, RESUME_POWER_ON); |
| 79 | if (ret == 0) |
| 80 | ret = drv->resume(dev, RESUME_RESTORE_STATE); |
| 81 | if (ret == 0) |
| 82 | ret = drv->resume(dev, RESUME_ENABLE); |
| 83 | } |
| 84 | return ret; |
| 85 | } |
| 86 | |
| 87 | struct bus_type mdio_bus_type = { |
| 88 | .name = "mdio_bus", |
| 89 | .match = mdio_bus_match, |
| 90 | .suspend = mdio_bus_suspend, |
| 91 | .resume = mdio_bus_resume, |
| 92 | }; |
| 93 | |
Jeff Garzik | 67c4f3f | 2005-08-11 02:07:25 -0400 | [diff] [blame] | 94 | int __init mdio_bus_init(void) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 95 | { |
| 96 | return bus_register(&mdio_bus_type); |
| 97 | } |
| 98 | |
Jeff Garzik | 67c4f3f | 2005-08-11 02:07:25 -0400 | [diff] [blame] | 99 | |