aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorTimur Tabi <timur@freescale.com>2012-08-29 04:07:59 -0400
committerDavid S. Miller <davem@davemloft.net>2012-08-30 13:29:31 -0400
commit69cfb41941638d3070c284f3e8849dc5b356fc3f (patch)
tree224367e64313b0363c5cde7c28df75ed51fc32cd /drivers/net
parent1aa06d42d98ef96e92857802c31f662fa971247b (diff)
net/fsl_pq_mdio: merge some functions together
A few small functions were called only by other functions in the same file, so merge them together. One function, for example, was calculating the device address even though the caller was doing the same thing. Signed-off-by: Timur Tabi <timur@freescale.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/ethernet/freescale/fsl_pq_mdio.c92
1 files changed, 26 insertions, 66 deletions
diff --git a/drivers/net/ethernet/freescale/fsl_pq_mdio.c b/drivers/net/ethernet/freescale/fsl_pq_mdio.c
index edaa25ea55a9..d5b7590b7533 100644
--- a/drivers/net/ethernet/freescale/fsl_pq_mdio.c
+++ b/drivers/net/ethernet/freescale/fsl_pq_mdio.c
@@ -68,17 +68,19 @@ struct fsl_pq_mdio_priv {
68}; 68};
69 69
70/* 70/*
71 * Write value to the PHY at mii_id at register regnum, 71 * Write value to the PHY at mii_id at register regnum, on the bus attached
72 * on the bus attached to the local interface, which may be different from the 72 * to the local interface, which may be different from the generic mdio bus
73 * generic mdio bus (tied to a single interface), waiting until the write is 73 * (tied to a single interface), waiting until the write is done before
74 * done before returning. This is helpful in programming interfaces like 74 * returning. This is helpful in programming interfaces like the TBI which
75 * the TBI which control interfaces like onchip SERDES and are always tied to 75 * control interfaces like onchip SERDES and are always tied to the local
76 * the local mdio pins, which may not be the same as system mdio bus, used for 76 * mdio pins, which may not be the same as system mdio bus, used for
77 * controlling the external PHYs, for example. 77 * controlling the external PHYs, for example.
78 */ 78 */
79static int fsl_pq_local_mdio_write(struct fsl_pq_mdio __iomem *regs, int mii_id, 79static int fsl_pq_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
80 int regnum, u16 value) 80 u16 value)
81{ 81{
82 struct fsl_pq_mdio_priv *priv = bus->priv;
83 struct fsl_pq_mdio __iomem *regs = priv->regs;
82 u32 status; 84 u32 status;
83 85
84 /* Set the PHY address and the register address we want to write */ 86 /* Set the PHY address and the register address we want to write */
@@ -95,20 +97,21 @@ static int fsl_pq_local_mdio_write(struct fsl_pq_mdio __iomem *regs, int mii_id,
95} 97}
96 98
97/* 99/*
98 * Read the bus for PHY at addr mii_id, register regnum, and 100 * Read the bus for PHY at addr mii_id, register regnum, and return the value.
99 * return the value. Clears miimcom first. All PHY operation 101 * Clears miimcom first.
100 * done on the bus attached to the local interface, 102 *
101 * which may be different from the generic mdio bus 103 * All PHY operation done on the bus attached to the local interface, which
102 * This is helpful in programming interfaces like 104 * may be different from the generic mdio bus. This is helpful in programming
103 * the TBI which, in turn, control interfaces like onchip SERDES 105 * interfaces like the TBI which, in turn, control interfaces like on-chip
104 * and are always tied to the local mdio pins, which may not be the 106 * SERDES and are always tied to the local mdio pins, which may not be the
105 * same as system mdio bus, used for controlling the external PHYs, for eg. 107 * same as system mdio bus, used for controlling the external PHYs, for eg.
106 */ 108 */
107static int fsl_pq_local_mdio_read(struct fsl_pq_mdio __iomem *regs, 109static int fsl_pq_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
108 int mii_id, int regnum)
109{ 110{
110 u16 value; 111 struct fsl_pq_mdio_priv *priv = bus->priv;
112 struct fsl_pq_mdio __iomem *regs = priv->regs;
111 u32 status; 113 u32 status;
114 u16 value;
112 115
113 /* Set the PHY address and the register address we want to read */ 116 /* Set the PHY address and the register address we want to read */
114 out_be32(&regs->miimadd, (mii_id << 8) | regnum); 117 out_be32(&regs->miimadd, (mii_id << 8) | regnum);
@@ -130,42 +133,11 @@ static int fsl_pq_local_mdio_read(struct fsl_pq_mdio __iomem *regs,
130 return value; 133 return value;
131} 134}
132 135
133static struct fsl_pq_mdio __iomem *fsl_pq_mdio_get_regs(struct mii_bus *bus)
134{
135 struct fsl_pq_mdio_priv *priv = bus->priv;
136
137 return priv->regs;
138}
139
140/*
141 * Write value to the PHY at mii_id at register regnum,
142 * on the bus, waiting until the write is done before returning.
143 */
144static int fsl_pq_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
145 u16 value)
146{
147 struct fsl_pq_mdio __iomem *regs = fsl_pq_mdio_get_regs(bus);
148
149 /* Write to the local MII regs */
150 return fsl_pq_local_mdio_write(regs, mii_id, regnum, value);
151}
152
153/*
154 * Read the bus for PHY at addr mii_id, register regnum, and
155 * return the value. Clears miimcom first.
156 */
157static int fsl_pq_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
158{
159 struct fsl_pq_mdio __iomem *regs = fsl_pq_mdio_get_regs(bus);
160
161 /* Read the local MII regs */
162 return fsl_pq_local_mdio_read(regs, mii_id, regnum);
163}
164
165/* Reset the MIIM registers, and wait for the bus to free */ 136/* Reset the MIIM registers, and wait for the bus to free */
166static int fsl_pq_mdio_reset(struct mii_bus *bus) 137static int fsl_pq_mdio_reset(struct mii_bus *bus)
167{ 138{
168 struct fsl_pq_mdio __iomem *regs = fsl_pq_mdio_get_regs(bus); 139 struct fsl_pq_mdio_priv *priv = bus->priv;
140 struct fsl_pq_mdio __iomem *regs = priv->regs;
169 u32 status; 141 u32 status;
170 142
171 mutex_lock(&bus->mdio_lock); 143 mutex_lock(&bus->mdio_lock);
@@ -191,20 +163,6 @@ static int fsl_pq_mdio_reset(struct mii_bus *bus)
191 return 0; 163 return 0;
192} 164}
193 165
194static void fsl_pq_mdio_bus_name(char *name, struct device_node *np)
195{
196 const u32 *addr;
197 u64 taddr = OF_BAD_ADDR;
198
199 addr = of_get_address(np, 0, NULL, NULL);
200 if (addr)
201 taddr = of_translate_address(np, addr);
202
203 snprintf(name, MII_BUS_ID_SIZE, "%s@%llx", np->name,
204 (unsigned long long)taddr);
205}
206
207
208static u32 __iomem *get_gfar_tbipa(struct fsl_pq_mdio __iomem *regs, struct device_node *np) 166static u32 __iomem *get_gfar_tbipa(struct fsl_pq_mdio __iomem *regs, struct device_node *np)
209{ 167{
210#if defined(CONFIG_GIANFAR) || defined(CONFIG_GIANFAR_MODULE) 168#if defined(CONFIG_GIANFAR) || defined(CONFIG_GIANFAR_MODULE)
@@ -298,7 +256,6 @@ static int fsl_pq_mdio_probe(struct platform_device *ofdev)
298 new_bus->write = &fsl_pq_mdio_write, 256 new_bus->write = &fsl_pq_mdio_write,
299 new_bus->reset = &fsl_pq_mdio_reset, 257 new_bus->reset = &fsl_pq_mdio_reset,
300 new_bus->priv = priv; 258 new_bus->priv = priv;
301 fsl_pq_mdio_bus_name(new_bus->id, np);
302 259
303 addrp = of_get_address(np, 0, &size, NULL); 260 addrp = of_get_address(np, 0, &size, NULL);
304 if (!addrp) { 261 if (!addrp) {
@@ -313,6 +270,9 @@ static int fsl_pq_mdio_probe(struct platform_device *ofdev)
313 goto err_free_bus; 270 goto err_free_bus;
314 } 271 }
315 272
273 snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s@%llx", np->name,
274 (unsigned long long)addr);
275
316 map = ioremap(addr, size); 276 map = ioremap(addr, size);
317 if (!map) { 277 if (!map) {
318 err = -ENOMEM; 278 err = -ENOMEM;