aboutsummaryrefslogtreecommitdiffstats
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
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>
-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
-rw-r--r--drivers/of/of_net.c2
-rw-r--r--include/linux/phy.h4
5 files changed, 24 insertions, 41 deletions
diff --git a/drivers/net/ibm_newemac/core.c b/drivers/net/ibm_newemac/core.c
index 725399ea069..70cb7d8a3b5 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 8a61b597a16..1568278d759 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 ac9d964e59e..ab4e5969fe6 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}
diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index cc117db0589..bb184717588 100644
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -16,6 +16,7 @@
16 * device driver can get phy interface from device tree. 16 * device driver can get phy interface from device tree.
17 */ 17 */
18static const char *phy_modes[] = { 18static const char *phy_modes[] = {
19 [PHY_INTERFACE_MODE_NA] = "",
19 [PHY_INTERFACE_MODE_MII] = "mii", 20 [PHY_INTERFACE_MODE_MII] = "mii",
20 [PHY_INTERFACE_MODE_GMII] = "gmii", 21 [PHY_INTERFACE_MODE_GMII] = "gmii",
21 [PHY_INTERFACE_MODE_SGMII] = "sgmii", 22 [PHY_INTERFACE_MODE_SGMII] = "sgmii",
@@ -26,6 +27,7 @@ static const char *phy_modes[] = {
26 [PHY_INTERFACE_MODE_RGMII_RXID] = "rgmii-rxid", 27 [PHY_INTERFACE_MODE_RGMII_RXID] = "rgmii-rxid",
27 [PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid", 28 [PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid",
28 [PHY_INTERFACE_MODE_RTBI] = "rtbi", 29 [PHY_INTERFACE_MODE_RTBI] = "rtbi",
30 [PHY_INTERFACE_MODE_SMII] = "smii",
29}; 31};
30 32
31/** 33/**
diff --git a/include/linux/phy.h b/include/linux/phy.h
index ad5186354d9..54fc4138955 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -53,6 +53,7 @@
53 53
54/* Interface Mode definitions */ 54/* Interface Mode definitions */
55typedef enum { 55typedef enum {
56 PHY_INTERFACE_MODE_NA,
56 PHY_INTERFACE_MODE_MII, 57 PHY_INTERFACE_MODE_MII,
57 PHY_INTERFACE_MODE_GMII, 58 PHY_INTERFACE_MODE_GMII,
58 PHY_INTERFACE_MODE_SGMII, 59 PHY_INTERFACE_MODE_SGMII,
@@ -62,7 +63,8 @@ typedef enum {
62 PHY_INTERFACE_MODE_RGMII_ID, 63 PHY_INTERFACE_MODE_RGMII_ID,
63 PHY_INTERFACE_MODE_RGMII_RXID, 64 PHY_INTERFACE_MODE_RGMII_RXID,
64 PHY_INTERFACE_MODE_RGMII_TXID, 65 PHY_INTERFACE_MODE_RGMII_TXID,
65 PHY_INTERFACE_MODE_RTBI 66 PHY_INTERFACE_MODE_RTBI,
67 PHY_INTERFACE_MODE_SMII,
66} phy_interface_t; 68} phy_interface_t;
67 69
68 70