aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorShawn Guo <shawn.guo@linaro.org>2011-07-05 04:42:09 -0400
committerShawn Guo <shawn.guo@linaro.org>2011-07-26 21:31:02 -0400
commit4157ef1b8779b34581ee8b9dc8f7f95188008eca (patch)
tree6be8331bc24c59d9fea27a256a681c570c3dfdee /drivers/net
parent6ca1a113791eb09dac8c48b2b264c4d72aab410f (diff)
net: ibm_newemac: convert it to use of_get_phy_mode
The patch extends 'enum phy_interface_t' and of_get_phy_mode a little bit with PHY_INTERFACE_MODE_NA and PHY_INTERFACE_MODE_SMII added, and then converts ibm_newemac net driver to use of_get_phy_mode getting phy mode from device tree. It also resolves the namespace conflict on phy_read/write between common mdiobus interface and ibm_newemac private one. Signed-off-by: Shawn Guo <shawn.guo@linaro.org> Cc: David S. Miller <davem@davemloft.net> Cc: Grant Likely <grant.likely@secretlab.ca> Acked-by: Grant Likely <grant.likely@secretlab.ca> Acked-by: David Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/ibm_newemac/core.c33
-rw-r--r--drivers/net/ibm_newemac/emac.h19
-rw-r--r--drivers/net/ibm_newemac/phy.c7
3 files changed, 19 insertions, 40 deletions
diff --git a/drivers/net/ibm_newemac/core.c b/drivers/net/ibm_newemac/core.c
index 725399ea0690..70cb7d8a3b53 100644
--- a/drivers/net/ibm_newemac/core.c
+++ b/drivers/net/ibm_newemac/core.c
@@ -39,6 +39,7 @@
39#include <linux/bitops.h> 39#include <linux/bitops.h>
40#include <linux/workqueue.h> 40#include <linux/workqueue.h>
41#include <linux/of.h> 41#include <linux/of.h>
42#include <linux/of_net.h>
42#include <linux/slab.h> 43#include <linux/slab.h>
43 44
44#include <asm/processor.h> 45#include <asm/processor.h>
@@ -2506,18 +2507,6 @@ static int __devinit emac_init_config(struct emac_instance *dev)
2506{ 2507{
2507 struct device_node *np = dev->ofdev->dev.of_node; 2508 struct device_node *np = dev->ofdev->dev.of_node;
2508 const void *p; 2509 const void *p;
2509 unsigned int plen;
2510 const char *pm, *phy_modes[] = {
2511 [PHY_MODE_NA] = "",
2512 [PHY_MODE_MII] = "mii",
2513 [PHY_MODE_RMII] = "rmii",
2514 [PHY_MODE_SMII] = "smii",
2515 [PHY_MODE_RGMII] = "rgmii",
2516 [PHY_MODE_TBI] = "tbi",
2517 [PHY_MODE_GMII] = "gmii",
2518 [PHY_MODE_RTBI] = "rtbi",
2519 [PHY_MODE_SGMII] = "sgmii",
2520 };
2521 2510
2522 /* Read config from device-tree */ 2511 /* Read config from device-tree */
2523 if (emac_read_uint_prop(np, "mal-device", &dev->mal_ph, 1)) 2512 if (emac_read_uint_prop(np, "mal-device", &dev->mal_ph, 1))
@@ -2566,23 +2555,9 @@ static int __devinit emac_init_config(struct emac_instance *dev)
2566 dev->mal_burst_size = 256; 2555 dev->mal_burst_size = 256;
2567 2556
2568 /* PHY mode needs some decoding */ 2557 /* PHY mode needs some decoding */
2569 dev->phy_mode = PHY_MODE_NA; 2558 dev->phy_mode = of_get_phy_mode(np);
2570 pm = of_get_property(np, "phy-mode", &plen); 2559 if (dev->phy_mode < 0)
2571 if (pm != NULL) { 2560 dev->phy_mode = PHY_MODE_NA;
2572 int i;
2573 for (i = 0; i < ARRAY_SIZE(phy_modes); i++)
2574 if (!strcasecmp(pm, phy_modes[i])) {
2575 dev->phy_mode = i;
2576 break;
2577 }
2578 }
2579
2580 /* Backward compat with non-final DT */
2581 if (dev->phy_mode == PHY_MODE_NA && pm != NULL && plen == 4) {
2582 u32 nmode = *(const u32 *)pm;
2583 if (nmode > PHY_MODE_NA && nmode <= PHY_MODE_SGMII)
2584 dev->phy_mode = nmode;
2585 }
2586 2561
2587 /* Check EMAC version */ 2562 /* Check EMAC version */
2588 if (of_device_is_compatible(np, "ibm,emac4sync")) { 2563 if (of_device_is_compatible(np, "ibm,emac4sync")) {
diff --git a/drivers/net/ibm_newemac/emac.h b/drivers/net/ibm_newemac/emac.h
index 8a61b597a169..1568278d759a 100644
--- a/drivers/net/ibm_newemac/emac.h
+++ b/drivers/net/ibm_newemac/emac.h
@@ -26,6 +26,7 @@
26#define __IBM_NEWEMAC_H 26#define __IBM_NEWEMAC_H
27 27
28#include <linux/types.h> 28#include <linux/types.h>
29#include <linux/phy.h>
29 30
30/* EMAC registers Write Access rules */ 31/* EMAC registers Write Access rules */
31struct emac_regs { 32struct emac_regs {
@@ -106,15 +107,15 @@ struct emac_regs {
106/* 107/*
107 * PHY mode settings (EMAC <-> ZMII/RGMII bridge <-> PHY) 108 * PHY mode settings (EMAC <-> ZMII/RGMII bridge <-> PHY)
108 */ 109 */
109#define PHY_MODE_NA 0 110#define PHY_MODE_NA PHY_INTERFACE_MODE_NA
110#define PHY_MODE_MII 1 111#define PHY_MODE_MII PHY_INTERFACE_MODE_MII
111#define PHY_MODE_RMII 2 112#define PHY_MODE_RMII PHY_INTERFACE_MODE_RMII
112#define PHY_MODE_SMII 3 113#define PHY_MODE_SMII PHY_INTERFACE_MODE_SMII
113#define PHY_MODE_RGMII 4 114#define PHY_MODE_RGMII PHY_INTERFACE_MODE_RGMII
114#define PHY_MODE_TBI 5 115#define PHY_MODE_TBI PHY_INTERFACE_MODE_TBI
115#define PHY_MODE_GMII 6 116#define PHY_MODE_GMII PHY_INTERFACE_MODE_GMII
116#define PHY_MODE_RTBI 7 117#define PHY_MODE_RTBI PHY_INTERFACE_MODE_RTBI
117#define PHY_MODE_SGMII 8 118#define PHY_MODE_SGMII PHY_INTERFACE_MODE_SGMII
118 119
119/* EMACx_MR0 */ 120/* EMACx_MR0 */
120#define EMAC_MR0_RXI 0x80000000 121#define EMAC_MR0_RXI 0x80000000
diff --git a/drivers/net/ibm_newemac/phy.c b/drivers/net/ibm_newemac/phy.c
index ac9d964e59ec..ab4e5969fe65 100644
--- a/drivers/net/ibm_newemac/phy.c
+++ b/drivers/net/ibm_newemac/phy.c
@@ -28,12 +28,15 @@
28#include "emac.h" 28#include "emac.h"
29#include "phy.h" 29#include "phy.h"
30 30
31static inline int phy_read(struct mii_phy *phy, int reg) 31#define phy_read _phy_read
32#define phy_write _phy_write
33
34static inline int _phy_read(struct mii_phy *phy, int reg)
32{ 35{
33 return phy->mdio_read(phy->dev, phy->address, reg); 36 return phy->mdio_read(phy->dev, phy->address, reg);
34} 37}
35 38
36static inline void phy_write(struct mii_phy *phy, int reg, int val) 39static inline void _phy_write(struct mii_phy *phy, int reg, int val)
37{ 40{
38 phy->mdio_write(phy->dev, phy->address, reg, val); 41 phy->mdio_write(phy->dev, phy->address, reg, val);
39} 42}