Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

Shawn Guo 4157ef1b 6ca1a113

+24 -41
+4 -29
drivers/net/ibm_newemac/core.c
··· 39 39 #include <linux/bitops.h> 40 40 #include <linux/workqueue.h> 41 41 #include <linux/of.h> 42 + #include <linux/of_net.h> 42 43 #include <linux/slab.h> 43 44 44 45 #include <asm/processor.h> ··· 2507 2506 { 2508 2507 struct device_node *np = dev->ofdev->dev.of_node; 2509 2508 const void *p; 2510 - unsigned int plen; 2511 - const char *pm, *phy_modes[] = { 2512 - [PHY_MODE_NA] = "", 2513 - [PHY_MODE_MII] = "mii", 2514 - [PHY_MODE_RMII] = "rmii", 2515 - [PHY_MODE_SMII] = "smii", 2516 - [PHY_MODE_RGMII] = "rgmii", 2517 - [PHY_MODE_TBI] = "tbi", 2518 - [PHY_MODE_GMII] = "gmii", 2519 - [PHY_MODE_RTBI] = "rtbi", 2520 - [PHY_MODE_SGMII] = "sgmii", 2521 - }; 2522 2509 2523 2510 /* Read config from device-tree */ 2524 2511 if (emac_read_uint_prop(np, "mal-device", &dev->mal_ph, 1)) ··· 2555 2566 dev->mal_burst_size = 256; 2556 2567 2557 2568 /* PHY mode needs some decoding */ 2558 - dev->phy_mode = PHY_MODE_NA; 2559 - pm = of_get_property(np, "phy-mode", &plen); 2560 - if (pm != NULL) { 2561 - int i; 2562 - for (i = 0; i < ARRAY_SIZE(phy_modes); i++) 2563 - if (!strcasecmp(pm, phy_modes[i])) { 2564 - dev->phy_mode = i; 2565 - break; 2566 - } 2567 - } 2568 - 2569 - /* Backward compat with non-final DT */ 2570 - if (dev->phy_mode == PHY_MODE_NA && pm != NULL && plen == 4) { 2571 - u32 nmode = *(const u32 *)pm; 2572 - if (nmode > PHY_MODE_NA && nmode <= PHY_MODE_SGMII) 2573 - dev->phy_mode = nmode; 2574 - } 2569 + dev->phy_mode = of_get_phy_mode(np); 2570 + if (dev->phy_mode < 0) 2571 + dev->phy_mode = PHY_MODE_NA; 2575 2572 2576 2573 /* Check EMAC version */ 2577 2574 if (of_device_is_compatible(np, "ibm,emac4sync")) {
+10 -9
drivers/net/ibm_newemac/emac.h
··· 26 26 #define __IBM_NEWEMAC_H 27 27 28 28 #include <linux/types.h> 29 + #include <linux/phy.h> 29 30 30 31 /* EMAC registers Write Access rules */ 31 32 struct emac_regs { ··· 107 106 /* 108 107 * PHY mode settings (EMAC <-> ZMII/RGMII bridge <-> PHY) 109 108 */ 110 - #define PHY_MODE_NA 0 111 - #define PHY_MODE_MII 1 112 - #define PHY_MODE_RMII 2 113 - #define PHY_MODE_SMII 3 114 - #define PHY_MODE_RGMII 4 115 - #define PHY_MODE_TBI 5 116 - #define PHY_MODE_GMII 6 117 - #define PHY_MODE_RTBI 7 118 - #define PHY_MODE_SGMII 8 109 + #define PHY_MODE_NA PHY_INTERFACE_MODE_NA 110 + #define PHY_MODE_MII PHY_INTERFACE_MODE_MII 111 + #define PHY_MODE_RMII PHY_INTERFACE_MODE_RMII 112 + #define PHY_MODE_SMII PHY_INTERFACE_MODE_SMII 113 + #define PHY_MODE_RGMII PHY_INTERFACE_MODE_RGMII 114 + #define PHY_MODE_TBI PHY_INTERFACE_MODE_TBI 115 + #define PHY_MODE_GMII PHY_INTERFACE_MODE_GMII 116 + #define PHY_MODE_RTBI PHY_INTERFACE_MODE_RTBI 117 + #define PHY_MODE_SGMII PHY_INTERFACE_MODE_SGMII 119 118 120 119 /* EMACx_MR0 */ 121 120 #define EMAC_MR0_RXI 0x80000000
+5 -2
drivers/net/ibm_newemac/phy.c
··· 28 28 #include "emac.h" 29 29 #include "phy.h" 30 30 31 - static inline int phy_read(struct mii_phy *phy, int reg) 31 + #define phy_read _phy_read 32 + #define phy_write _phy_write 33 + 34 + static inline int _phy_read(struct mii_phy *phy, int reg) 32 35 { 33 36 return phy->mdio_read(phy->dev, phy->address, reg); 34 37 } 35 38 36 - static inline void phy_write(struct mii_phy *phy, int reg, int val) 39 + static inline void _phy_write(struct mii_phy *phy, int reg, int val) 37 40 { 38 41 phy->mdio_write(phy->dev, phy->address, reg, val); 39 42 }
+2
drivers/of/of_net.c
··· 16 16 * device driver can get phy interface from device tree. 17 17 */ 18 18 static const char *phy_modes[] = { 19 + [PHY_INTERFACE_MODE_NA] = "", 19 20 [PHY_INTERFACE_MODE_MII] = "mii", 20 21 [PHY_INTERFACE_MODE_GMII] = "gmii", 21 22 [PHY_INTERFACE_MODE_SGMII] = "sgmii", ··· 27 26 [PHY_INTERFACE_MODE_RGMII_RXID] = "rgmii-rxid", 28 27 [PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid", 29 28 [PHY_INTERFACE_MODE_RTBI] = "rtbi", 29 + [PHY_INTERFACE_MODE_SMII] = "smii", 30 30 }; 31 31 32 32 /**
+3 -1
include/linux/phy.h
··· 53 53 54 54 /* Interface Mode definitions */ 55 55 typedef enum { 56 + PHY_INTERFACE_MODE_NA, 56 57 PHY_INTERFACE_MODE_MII, 57 58 PHY_INTERFACE_MODE_GMII, 58 59 PHY_INTERFACE_MODE_SGMII, ··· 63 62 PHY_INTERFACE_MODE_RGMII_ID, 64 63 PHY_INTERFACE_MODE_RGMII_RXID, 65 64 PHY_INTERFACE_MODE_RGMII_TXID, 66 - PHY_INTERFACE_MODE_RTBI 65 + PHY_INTERFACE_MODE_RTBI, 66 + PHY_INTERFACE_MODE_SMII, 67 67 } phy_interface_t; 68 68 69 69