Skip to content

Commit

Permalink
phy subsystem: more cleanups
Browse files Browse the repository at this point in the history
- unexport symbols never used outside of home module
- remove dead code
- remove CONFIG_PHYCONTROL, make it unconditionally enabled
  • Loading branch information
jgarzik committed Aug 11, 2005
1 parent 67c4f3f commit 2bf69b5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 414 deletions.
8 changes: 0 additions & 8 deletions drivers/net/phy/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ config PHYLIB
devices. This option provides infrastructure for
managing PHY devices.

config PHYCONTROL
bool "Support for automatically handling PHY state changes"
depends on PHYLIB
help
Adds code to perform all the work for keeping PHY link
state (speed/duplex/etc) up-to-date. Also handles
interrupts.

comment "MII PHY device drivers"
depends on PHYLIB

Expand Down
74 changes: 0 additions & 74 deletions drivers/net/phy/mdio_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,80 +38,6 @@
#include <asm/irq.h>
#include <asm/uaccess.h>

/* mdiobus_register
*
* description: Called by a bus driver to bring up all the PHYs
* on a given bus, and attach them to the bus
*/
int mdiobus_register(struct mii_bus *bus)
{
int i;
int err = 0;

spin_lock_init(&bus->mdio_lock);

if (NULL == bus || NULL == bus->name ||
NULL == bus->read ||
NULL == bus->write)
return -EINVAL;

if (bus->reset)
bus->reset(bus);

for (i = 0; i < PHY_MAX_ADDR; i++) {
struct phy_device *phydev;

phydev = get_phy_device(bus, i);

if (IS_ERR(phydev))
return PTR_ERR(phydev);

/* There's a PHY at this address
* We need to set:
* 1) IRQ
* 2) bus_id
* 3) parent
* 4) bus
* 5) mii_bus
* And, we need to register it */
if (phydev) {
phydev->irq = bus->irq[i];

phydev->dev.parent = bus->dev;
phydev->dev.bus = &mdio_bus_type;
sprintf(phydev->dev.bus_id, "phy%d:%d", bus->id, i);

phydev->bus = bus;

err = device_register(&phydev->dev);

if (err)
printk(KERN_ERR "phy %d failed to register\n",
i);
}

bus->phy_map[i] = phydev;
}

pr_info("%s: probed\n", bus->name);

return err;
}
EXPORT_SYMBOL(mdiobus_register);

void mdiobus_unregister(struct mii_bus *bus)
{
int i;

for (i = 0; i < PHY_MAX_ADDR; i++) {
if (bus->phy_map[i]) {
device_unregister(&bus->phy_map[i]->dev);
kfree(bus->phy_map[i]);
}
}
}
EXPORT_SYMBOL(mdiobus_unregister);

/* mdio_bus_match
*
* description: Given a PHY device, and a PHY driver, return 1 if
Expand Down
197 changes: 11 additions & 186 deletions drivers/net/phy/phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,9 @@
#include <asm/uaccess.h>

static void phy_timer(unsigned long data);

/* Convenience function to print out the current phy status
*/
void phy_print_status(struct phy_device *phydev)
{
pr_info("%s: Link is %s", phydev->dev.bus_id,
phydev->link ? "Up" : "Down");
if (phydev->link)
printk(" - %d/%s", phydev->speed,
DUPLEX_FULL == phydev->duplex ?
"Full" : "Half");

printk("\n");
}
EXPORT_SYMBOL(phy_print_status);
static int phy_disable_interrupts(struct phy_device *phydev);
static void phy_sanitize_settings(struct phy_device *phydev);
static int phy_stop_interrupts(struct phy_device *phydev);


/* Convenience functions for reading/writing a given PHY
Expand Down Expand Up @@ -133,7 +121,7 @@ static inline int phy_aneg_done(struct phy_device *phydev)
* and to PHY_FORCING if auto-negotiation is disabled. Unless
* the PHY is currently HALTED.
*/
int phy_start_aneg(struct phy_device *phydev)
static int phy_start_aneg(struct phy_device *phydev)
{
int err;

Expand Down Expand Up @@ -161,8 +149,6 @@ int phy_start_aneg(struct phy_device *phydev)
spin_unlock(&phydev->lock);
return err;
}
EXPORT_SYMBOL(phy_start_aneg);


/* A structure for mapping a particular speed and duplex
* combination to a particular SUPPORTED and ADVERTISED value */
Expand Down Expand Up @@ -255,7 +241,7 @@ static inline int phy_find_valid(int idx, u32 features)
* duplexes. Drop down by one in this order: 1000/FULL,
* 1000/HALF, 100/FULL, 100/HALF, 10/FULL, 10/HALF
*/
void phy_sanitize_settings(struct phy_device *phydev)
static void phy_sanitize_settings(struct phy_device *phydev)
{
u32 features = phydev->supported;
int idx;
Expand All @@ -270,7 +256,6 @@ void phy_sanitize_settings(struct phy_device *phydev)
phydev->speed = settings[idx].speed;
phydev->duplex = settings[idx].duplex;
}
EXPORT_SYMBOL(phy_sanitize_settings);

/* phy_force_reduction
*
Expand Down Expand Up @@ -477,48 +462,22 @@ void phy_error(struct phy_device *phydev)
spin_unlock(&phydev->lock);
}

#ifdef CONFIG_PHYCONTROL

static void phy_change(void *data);

/* phy_interrupt
*
* description: When a PHY interrupt occurs, the handler disables
* interrupts, and schedules a work task to clear the interrupt.
*/
static irqreturn_t phy_interrupt(int irq, void *phy_dat, struct pt_regs *regs)
{
struct phy_device *phydev = phy_dat;

/* The MDIO bus is not allowed to be written in interrupt
* context, so we need to disable the irq here. A work
* queue will write the PHY to disable and clear the
* interrupt, and then reenable the irq line. */
disable_irq_nosync(irq);

schedule_work(&phydev->phy_queue);

return IRQ_HANDLED;
}

/* Enable the interrupts from the PHY side */
int phy_enable_interrupts(struct phy_device *phydev)
static int phy_stop_interrupts(struct phy_device *phydev)
{
int err;

err = phy_clear_interrupt(phydev);
err = phy_disable_interrupts(phydev);

if (err < 0)
return err;
if (err)
phy_error(phydev);

err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED);
free_irq(phydev->irq, phydev);

return err;
}
EXPORT_SYMBOL(phy_enable_interrupts);

/* Disable the PHY interrupts from the PHY side */
int phy_disable_interrupts(struct phy_device *phydev)
static int phy_disable_interrupts(struct phy_device *phydev)
{
int err;

Expand All @@ -541,140 +500,6 @@ int phy_disable_interrupts(struct phy_device *phydev)

return err;
}
EXPORT_SYMBOL(phy_disable_interrupts);

/* phy_start_interrupts
*
* description: Request the interrupt for the given PHY. If
* this fails, then we set irq to PHY_POLL.
* Otherwise, we enable the interrupts in the PHY.
* Returns 0 on success.
* This should only be called with a valid IRQ number.
*/
int phy_start_interrupts(struct phy_device *phydev)
{
int err = 0;

INIT_WORK(&phydev->phy_queue, phy_change, phydev);

if (request_irq(phydev->irq, phy_interrupt,
SA_SHIRQ,
"phy_interrupt",
phydev) < 0) {
printk(KERN_WARNING "%s: Can't get IRQ %d (PHY)\n",
phydev->bus->name,
phydev->irq);
phydev->irq = PHY_POLL;
return 0;
}

err = phy_enable_interrupts(phydev);

return err;
}
EXPORT_SYMBOL(phy_start_interrupts);

int phy_stop_interrupts(struct phy_device *phydev)
{
int err;

err = phy_disable_interrupts(phydev);

if (err)
phy_error(phydev);

free_irq(phydev->irq, phydev);

return err;
}
EXPORT_SYMBOL(phy_stop_interrupts);


/* Scheduled by the phy_interrupt/timer to handle PHY changes */
static void phy_change(void *data)
{
int err;
struct phy_device *phydev = data;

err = phy_disable_interrupts(phydev);

if (err)
goto phy_err;

spin_lock(&phydev->lock);
if ((PHY_RUNNING == phydev->state) || (PHY_NOLINK == phydev->state))
phydev->state = PHY_CHANGELINK;
spin_unlock(&phydev->lock);

enable_irq(phydev->irq);

/* Reenable interrupts */
err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED);

if (err)
goto irq_enable_err;

return;

irq_enable_err:
disable_irq(phydev->irq);
phy_err:
phy_error(phydev);
}

/* Bring down the PHY link, and stop checking the status. */
void phy_stop(struct phy_device *phydev)
{
spin_lock(&phydev->lock);

if (PHY_HALTED == phydev->state)
goto out_unlock;

if (phydev->irq != PHY_POLL) {
/* Clear any pending interrupts */
phy_clear_interrupt(phydev);

/* Disable PHY Interrupts */
phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED);
}

phydev->state = PHY_HALTED;

out_unlock:
spin_unlock(&phydev->lock);
}


/* phy_start
*
* description: Indicates the attached device's readiness to
* handle PHY-related work. Used during startup to start the
* PHY, and after a call to phy_stop() to resume operation.
* Also used to indicate the MDIO bus has cleared an error
* condition.
*/
void phy_start(struct phy_device *phydev)
{
spin_lock(&phydev->lock);

switch (phydev->state) {
case PHY_STARTING:
phydev->state = PHY_PENDING;
break;
case PHY_READY:
phydev->state = PHY_UP;
break;
case PHY_HALTED:
phydev->state = PHY_RESUMING;
default:
break;
}
spin_unlock(&phydev->lock);
}
EXPORT_SYMBOL(phy_stop);
EXPORT_SYMBOL(phy_start);

#endif /* CONFIG_PHYCONTROL */

/* PHY timer which handles the state machine */
static void phy_timer(unsigned long data)
Expand Down
Loading

0 comments on commit 2bf69b5

Please sign in to comment.