Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Freescale PowerQUICC Ethernet Driver -- MIIM bus implementation |
| 3 | * Provides Bus interface for MIIM regs |
| 4 | * |
| 5 | * Author: Andy Fleming <afleming@freescale.com> |
Sandeep Gopalpet | 1d2397d | 2009-11-02 07:03:22 +0000 | [diff] [blame] | 6 | * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com> |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 7 | * |
Sandeep Gopalpet | 1d2397d | 2009-11-02 07:03:22 +0000 | [diff] [blame] | 8 | * Copyright 2002-2004, 2008-2009 Freescale Semiconductor, Inc. |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 9 | * |
| 10 | * Based on gianfar_mii.c and ucc_geth_mii.c (Li Yang, Kim Phillips) |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License as published by the |
| 14 | * Free Software Foundation; either version 2 of the License, or (at your |
| 15 | * option) any later version. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/string.h> |
| 21 | #include <linux/errno.h> |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 22 | #include <linux/slab.h> |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 23 | #include <linux/init.h> |
| 24 | #include <linux/delay.h> |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 25 | #include <linux/module.h> |
| 26 | #include <linux/platform_device.h> |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 27 | #include <linux/mii.h> |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 28 | #include <linux/of_address.h> |
Grant Likely | 324931b | 2009-04-25 12:53:07 +0000 | [diff] [blame] | 29 | #include <linux/of_mdio.h> |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 30 | #include <linux/of_platform.h> |
| 31 | |
| 32 | #include <asm/io.h> |
Timur Tabi | 1aa06d4 | 2012-08-29 08:07:58 +0000 | [diff] [blame] | 33 | #include <asm/ucc.h> /* for ucc_set_qe_mux_mii_mng() */ |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 34 | |
| 35 | #include "gianfar.h" |
Timur Tabi | 19bcd6c | 2012-08-29 08:07:57 +0000 | [diff] [blame] | 36 | |
| 37 | #define MIIMIND_BUSY 0x00000001 |
| 38 | #define MIIMIND_NOTVALID 0x00000004 |
| 39 | #define MIIMCFG_INIT_VALUE 0x00000007 |
| 40 | #define MIIMCFG_RESET 0x80000000 |
| 41 | |
| 42 | #define MII_READ_COMMAND 0x00000001 |
| 43 | |
| 44 | struct fsl_pq_mdio { |
| 45 | u8 res1[16]; |
| 46 | u32 ieventm; /* MDIO Interrupt event register (for etsec2)*/ |
| 47 | u32 imaskm; /* MDIO Interrupt mask register (for etsec2)*/ |
| 48 | u8 res2[4]; |
| 49 | u32 emapm; /* MDIO Event mapping register (for etsec2)*/ |
| 50 | u8 res3[1280]; |
| 51 | u32 miimcfg; /* MII management configuration reg */ |
| 52 | u32 miimcom; /* MII management command reg */ |
| 53 | u32 miimadd; /* MII management address reg */ |
| 54 | u32 miimcon; /* MII management control reg */ |
| 55 | u32 miimstat; /* MII management status reg */ |
| 56 | u32 miimind; /* MII management indication reg */ |
| 57 | u8 res4[28]; |
| 58 | u32 utbipar; /* TBI phy address reg (only on UCC) */ |
| 59 | u8 res5[2728]; |
| 60 | } __packed; |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 61 | |
Timur Tabi | 59399c5 | 2012-07-09 16:57:36 -0500 | [diff] [blame] | 62 | /* Number of microseconds to wait for an MII register to respond */ |
| 63 | #define MII_TIMEOUT 1000 |
| 64 | |
Anton Vorontsov | b3319b1 | 2009-12-30 08:23:34 +0000 | [diff] [blame] | 65 | struct fsl_pq_mdio_priv { |
| 66 | void __iomem *map; |
| 67 | struct fsl_pq_mdio __iomem *regs; |
| 68 | }; |
| 69 | |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 70 | /* |
Timur Tabi | 69cfb41 | 2012-08-29 08:07:59 +0000 | [diff] [blame] | 71 | * Write value to the PHY at mii_id at register regnum, on the bus attached |
| 72 | * to the local interface, which may be different from the generic mdio bus |
| 73 | * (tied to a single interface), waiting until the write is done before |
| 74 | * returning. This is helpful in programming interfaces like the TBI which |
| 75 | * control interfaces like onchip SERDES and are always tied to the local |
| 76 | * mdio pins, which may not be the same as system mdio bus, used for |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 77 | * controlling the external PHYs, for example. |
| 78 | */ |
Timur Tabi | 69cfb41 | 2012-08-29 08:07:59 +0000 | [diff] [blame] | 79 | static int fsl_pq_mdio_write(struct mii_bus *bus, int mii_id, int regnum, |
| 80 | u16 value) |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 81 | { |
Timur Tabi | 69cfb41 | 2012-08-29 08:07:59 +0000 | [diff] [blame] | 82 | struct fsl_pq_mdio_priv *priv = bus->priv; |
| 83 | struct fsl_pq_mdio __iomem *regs = priv->regs; |
Timur Tabi | 59399c5 | 2012-07-09 16:57:36 -0500 | [diff] [blame] | 84 | u32 status; |
| 85 | |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 86 | /* Set the PHY address and the register address we want to write */ |
| 87 | out_be32(®s->miimadd, (mii_id << 8) | regnum); |
| 88 | |
| 89 | /* Write out the value we want */ |
| 90 | out_be32(®s->miimcon, value); |
| 91 | |
| 92 | /* Wait for the transaction to finish */ |
Timur Tabi | 59399c5 | 2012-07-09 16:57:36 -0500 | [diff] [blame] | 93 | status = spin_event_timeout(!(in_be32(®s->miimind) & MIIMIND_BUSY), |
| 94 | MII_TIMEOUT, 0); |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 95 | |
Timur Tabi | 59399c5 | 2012-07-09 16:57:36 -0500 | [diff] [blame] | 96 | return status ? 0 : -ETIMEDOUT; |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /* |
Timur Tabi | 69cfb41 | 2012-08-29 08:07:59 +0000 | [diff] [blame] | 100 | * Read the bus for PHY at addr mii_id, register regnum, and return the value. |
| 101 | * Clears miimcom first. |
| 102 | * |
| 103 | * All PHY operation done on the bus attached to the local interface, which |
| 104 | * may be different from the generic mdio bus. This is helpful in programming |
| 105 | * interfaces like the TBI which, in turn, control interfaces like on-chip |
| 106 | * SERDES and are always tied to the local mdio pins, which may not be the |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 107 | * same as system mdio bus, used for controlling the external PHYs, for eg. |
| 108 | */ |
Timur Tabi | 69cfb41 | 2012-08-29 08:07:59 +0000 | [diff] [blame] | 109 | static int fsl_pq_mdio_read(struct mii_bus *bus, int mii_id, int regnum) |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 110 | { |
Timur Tabi | 69cfb41 | 2012-08-29 08:07:59 +0000 | [diff] [blame] | 111 | struct fsl_pq_mdio_priv *priv = bus->priv; |
| 112 | struct fsl_pq_mdio __iomem *regs = priv->regs; |
Timur Tabi | 59399c5 | 2012-07-09 16:57:36 -0500 | [diff] [blame] | 113 | u32 status; |
Timur Tabi | 69cfb41 | 2012-08-29 08:07:59 +0000 | [diff] [blame] | 114 | u16 value; |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 115 | |
| 116 | /* Set the PHY address and the register address we want to read */ |
| 117 | out_be32(®s->miimadd, (mii_id << 8) | regnum); |
| 118 | |
| 119 | /* Clear miimcom, and then initiate a read */ |
| 120 | out_be32(®s->miimcom, 0); |
| 121 | out_be32(®s->miimcom, MII_READ_COMMAND); |
| 122 | |
Timur Tabi | 59399c5 | 2012-07-09 16:57:36 -0500 | [diff] [blame] | 123 | /* Wait for the transaction to finish, normally less than 100us */ |
| 124 | status = spin_event_timeout(!(in_be32(®s->miimind) & |
| 125 | (MIIMIND_NOTVALID | MIIMIND_BUSY)), |
| 126 | MII_TIMEOUT, 0); |
| 127 | if (!status) |
| 128 | return -ETIMEDOUT; |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 129 | |
| 130 | /* Grab the value of the register from miimstat */ |
| 131 | value = in_be32(®s->miimstat); |
| 132 | |
| 133 | return value; |
| 134 | } |
| 135 | |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 136 | /* Reset the MIIM registers, and wait for the bus to free */ |
| 137 | static int fsl_pq_mdio_reset(struct mii_bus *bus) |
| 138 | { |
Timur Tabi | 69cfb41 | 2012-08-29 08:07:59 +0000 | [diff] [blame] | 139 | struct fsl_pq_mdio_priv *priv = bus->priv; |
| 140 | struct fsl_pq_mdio __iomem *regs = priv->regs; |
Timur Tabi | 59399c5 | 2012-07-09 16:57:36 -0500 | [diff] [blame] | 141 | u32 status; |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 142 | |
| 143 | mutex_lock(&bus->mdio_lock); |
| 144 | |
| 145 | /* Reset the management interface */ |
| 146 | out_be32(®s->miimcfg, MIIMCFG_RESET); |
| 147 | |
| 148 | /* Setup the MII Mgmt clock speed */ |
| 149 | out_be32(®s->miimcfg, MIIMCFG_INIT_VALUE); |
| 150 | |
| 151 | /* Wait until the bus is free */ |
Timur Tabi | 59399c5 | 2012-07-09 16:57:36 -0500 | [diff] [blame] | 152 | status = spin_event_timeout(!(in_be32(®s->miimind) & MIIMIND_BUSY), |
| 153 | MII_TIMEOUT, 0); |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 154 | |
| 155 | mutex_unlock(&bus->mdio_lock); |
| 156 | |
Timur Tabi | 59399c5 | 2012-07-09 16:57:36 -0500 | [diff] [blame] | 157 | if (!status) { |
Timur Tabi | 5078ac7 | 2012-08-29 08:08:00 +0000 | [diff] [blame^] | 158 | dev_err(&bus->dev, "timeout waiting for MII bus\n"); |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 159 | return -EBUSY; |
| 160 | } |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
Sandeep Gopalpet | 1d2397d | 2009-11-02 07:03:22 +0000 | [diff] [blame] | 165 | static u32 __iomem *get_gfar_tbipa(struct fsl_pq_mdio __iomem *regs, struct device_node *np) |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 166 | { |
Andy Fleming | 952c5ca | 2011-11-11 05:10:39 +0000 | [diff] [blame] | 167 | #if defined(CONFIG_GIANFAR) || defined(CONFIG_GIANFAR_MODULE) |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 168 | struct gfar __iomem *enet_regs; |
| 169 | |
| 170 | /* |
| 171 | * This is mildly evil, but so is our hardware for doing this. |
| 172 | * Also, we have to cast back to struct gfar because of |
| 173 | * definition weirdness done in gianfar.h. |
| 174 | */ |
Timur Tabi | 5078ac7 | 2012-08-29 08:08:00 +0000 | [diff] [blame^] | 175 | if (of_device_is_compatible(np, "fsl,gianfar-mdio") || |
Sandeep Gopalpet | 1d2397d | 2009-11-02 07:03:22 +0000 | [diff] [blame] | 176 | of_device_is_compatible(np, "fsl,gianfar-tbi") || |
| 177 | of_device_is_compatible(np, "gianfar")) { |
| 178 | enet_regs = (struct gfar __iomem *)regs; |
| 179 | return &enet_regs->tbipa; |
| 180 | } else if (of_device_is_compatible(np, "fsl,etsec2-mdio") || |
| 181 | of_device_is_compatible(np, "fsl,etsec2-tbi")) { |
Anton Vorontsov | 3b1fd3e | 2010-04-23 07:12:35 +0000 | [diff] [blame] | 182 | return of_iomap(np, 1); |
Andy Fleming | 952c5ca | 2011-11-11 05:10:39 +0000 | [diff] [blame] | 183 | } |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 184 | #endif |
Andy Fleming | 952c5ca | 2011-11-11 05:10:39 +0000 | [diff] [blame] | 185 | return NULL; |
| 186 | } |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 187 | |
| 188 | |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 189 | static int get_ucc_id_for_range(u64 start, u64 end, u32 *ucc_id) |
| 190 | { |
Andy Fleming | 952c5ca | 2011-11-11 05:10:39 +0000 | [diff] [blame] | 191 | #if defined(CONFIG_UCC_GETH) || defined(CONFIG_UCC_GETH_MODULE) |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 192 | struct device_node *np = NULL; |
| 193 | int err = 0; |
| 194 | |
| 195 | for_each_compatible_node(np, NULL, "ucc_geth") { |
| 196 | struct resource tempres; |
| 197 | |
| 198 | err = of_address_to_resource(np, 0, &tempres); |
| 199 | if (err) |
| 200 | continue; |
| 201 | |
| 202 | /* if our mdio regs fall within this UCC regs range */ |
| 203 | if ((start >= tempres.start) && (end <= tempres.end)) { |
| 204 | /* Find the id of the UCC */ |
| 205 | const u32 *id; |
| 206 | |
| 207 | id = of_get_property(np, "cell-index", NULL); |
| 208 | if (!id) { |
| 209 | id = of_get_property(np, "device-id", NULL); |
| 210 | if (!id) |
| 211 | continue; |
| 212 | } |
| 213 | |
| 214 | *ucc_id = *id; |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | if (err) |
| 221 | return err; |
| 222 | else |
| 223 | return -EINVAL; |
Andy Fleming | 952c5ca | 2011-11-11 05:10:39 +0000 | [diff] [blame] | 224 | #else |
| 225 | return -ENODEV; |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 226 | #endif |
Andy Fleming | 952c5ca | 2011-11-11 05:10:39 +0000 | [diff] [blame] | 227 | } |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 228 | |
Timur Tabi | 5078ac7 | 2012-08-29 08:08:00 +0000 | [diff] [blame^] | 229 | static int fsl_pq_mdio_probe(struct platform_device *pdev) |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 230 | { |
Timur Tabi | 5078ac7 | 2012-08-29 08:08:00 +0000 | [diff] [blame^] | 231 | struct device_node *np = pdev->dev.of_node; |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 232 | struct device_node *tbi; |
Anton Vorontsov | b3319b1 | 2009-12-30 08:23:34 +0000 | [diff] [blame] | 233 | struct fsl_pq_mdio_priv *priv; |
Sandeep Gopalpet | 1d2397d | 2009-11-02 07:03:22 +0000 | [diff] [blame] | 234 | struct fsl_pq_mdio __iomem *regs = NULL; |
Anton Vorontsov | 2951d64 | 2009-11-04 12:52:56 +0000 | [diff] [blame] | 235 | void __iomem *map; |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 236 | u32 __iomem *tbipa; |
| 237 | struct mii_bus *new_bus; |
| 238 | int tbiaddr = -1; |
Anton Vorontsov | 3b1fd3e | 2010-04-23 07:12:35 +0000 | [diff] [blame] | 239 | const u32 *addrp; |
Anton Vorontsov | 2951d64 | 2009-11-04 12:52:56 +0000 | [diff] [blame] | 240 | u64 addr = 0, size = 0; |
Anton Vorontsov | 08d18f3 | 2010-05-14 04:27:30 +0000 | [diff] [blame] | 241 | int err; |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 242 | |
Anton Vorontsov | b3319b1 | 2009-12-30 08:23:34 +0000 | [diff] [blame] | 243 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 244 | if (!priv) |
| 245 | return -ENOMEM; |
| 246 | |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 247 | new_bus = mdiobus_alloc(); |
Anton Vorontsov | 08d18f3 | 2010-05-14 04:27:30 +0000 | [diff] [blame] | 248 | if (!new_bus) { |
| 249 | err = -ENOMEM; |
Anton Vorontsov | b3319b1 | 2009-12-30 08:23:34 +0000 | [diff] [blame] | 250 | goto err_free_priv; |
Anton Vorontsov | 08d18f3 | 2010-05-14 04:27:30 +0000 | [diff] [blame] | 251 | } |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 252 | |
| 253 | new_bus->name = "Freescale PowerQUICC MII Bus", |
Timur Tabi | 5078ac7 | 2012-08-29 08:08:00 +0000 | [diff] [blame^] | 254 | new_bus->read = &fsl_pq_mdio_read; |
| 255 | new_bus->write = &fsl_pq_mdio_write; |
| 256 | new_bus->reset = &fsl_pq_mdio_reset; |
Anton Vorontsov | b3319b1 | 2009-12-30 08:23:34 +0000 | [diff] [blame] | 257 | new_bus->priv = priv; |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 258 | |
Anton Vorontsov | 3b1fd3e | 2010-04-23 07:12:35 +0000 | [diff] [blame] | 259 | addrp = of_get_address(np, 0, &size, NULL); |
| 260 | if (!addrp) { |
| 261 | err = -EINVAL; |
| 262 | goto err_free_bus; |
| 263 | } |
| 264 | |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 265 | /* Set the PHY base address */ |
Anton Vorontsov | 3b1fd3e | 2010-04-23 07:12:35 +0000 | [diff] [blame] | 266 | addr = of_translate_address(np, addrp); |
| 267 | if (addr == OF_BAD_ADDR) { |
| 268 | err = -EINVAL; |
| 269 | goto err_free_bus; |
| 270 | } |
| 271 | |
Timur Tabi | 69cfb41 | 2012-08-29 08:07:59 +0000 | [diff] [blame] | 272 | snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s@%llx", np->name, |
| 273 | (unsigned long long)addr); |
| 274 | |
Anton Vorontsov | 2951d64 | 2009-11-04 12:52:56 +0000 | [diff] [blame] | 275 | map = ioremap(addr, size); |
| 276 | if (!map) { |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 277 | err = -ENOMEM; |
| 278 | goto err_free_bus; |
| 279 | } |
Anton Vorontsov | b3319b1 | 2009-12-30 08:23:34 +0000 | [diff] [blame] | 280 | priv->map = map; |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 281 | |
Anton Vorontsov | 2951d64 | 2009-11-04 12:52:56 +0000 | [diff] [blame] | 282 | if (of_device_is_compatible(np, "fsl,gianfar-mdio") || |
| 283 | of_device_is_compatible(np, "fsl,gianfar-tbi") || |
| 284 | of_device_is_compatible(np, "fsl,ucc-mdio") || |
| 285 | of_device_is_compatible(np, "ucc_geth_phy")) |
| 286 | map -= offsetof(struct fsl_pq_mdio, miimcfg); |
| 287 | regs = map; |
Anton Vorontsov | b3319b1 | 2009-12-30 08:23:34 +0000 | [diff] [blame] | 288 | priv->regs = regs; |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 289 | |
Grant Likely | 324931b | 2009-04-25 12:53:07 +0000 | [diff] [blame] | 290 | new_bus->irq = kcalloc(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL); |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 291 | |
| 292 | if (NULL == new_bus->irq) { |
| 293 | err = -ENOMEM; |
| 294 | goto err_unmap_regs; |
| 295 | } |
| 296 | |
Timur Tabi | 5078ac7 | 2012-08-29 08:08:00 +0000 | [diff] [blame^] | 297 | new_bus->parent = &pdev->dev; |
| 298 | dev_set_drvdata(&pdev->dev, new_bus); |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 299 | |
| 300 | if (of_device_is_compatible(np, "fsl,gianfar-mdio") || |
Anton Vorontsov | 3019684 | 2009-03-21 13:30:05 -0700 | [diff] [blame] | 301 | of_device_is_compatible(np, "fsl,gianfar-tbi") || |
Sandeep Gopalpet | 1d2397d | 2009-11-02 07:03:22 +0000 | [diff] [blame] | 302 | of_device_is_compatible(np, "fsl,etsec2-mdio") || |
| 303 | of_device_is_compatible(np, "fsl,etsec2-tbi") || |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 304 | of_device_is_compatible(np, "gianfar")) { |
Sandeep Gopalpet | 1d2397d | 2009-11-02 07:03:22 +0000 | [diff] [blame] | 305 | tbipa = get_gfar_tbipa(regs, np); |
| 306 | if (!tbipa) { |
| 307 | err = -EINVAL; |
| 308 | goto err_free_irqs; |
| 309 | } |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 310 | } else if (of_device_is_compatible(np, "fsl,ucc-mdio") || |
| 311 | of_device_is_compatible(np, "ucc_geth_phy")) { |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 312 | u32 id; |
Haiying Wang | fbcc0e2 | 2009-06-02 04:04:14 +0000 | [diff] [blame] | 313 | static u32 mii_mng_master; |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 314 | |
| 315 | tbipa = ®s->utbipar; |
| 316 | |
| 317 | if ((err = get_ucc_id_for_range(addr, addr + size, &id))) |
| 318 | goto err_free_irqs; |
| 319 | |
Haiying Wang | fbcc0e2 | 2009-06-02 04:04:14 +0000 | [diff] [blame] | 320 | if (!mii_mng_master) { |
| 321 | mii_mng_master = id; |
| 322 | ucc_set_qe_mux_mii_mng(id - 1); |
| 323 | } |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 324 | } else { |
| 325 | err = -ENODEV; |
| 326 | goto err_free_irqs; |
| 327 | } |
| 328 | |
| 329 | for_each_child_of_node(np, tbi) { |
| 330 | if (!strncmp(tbi->type, "tbi-phy", 8)) |
| 331 | break; |
| 332 | } |
| 333 | |
| 334 | if (tbi) { |
| 335 | const u32 *prop = of_get_property(tbi, "reg", NULL); |
| 336 | |
| 337 | if (prop) |
| 338 | tbiaddr = *prop; |
Baruch Siach | c3e072f | 2011-11-14 08:21:30 +0200 | [diff] [blame] | 339 | |
Kenth Eriksson | 464b57d | 2012-03-27 22:05:54 +0000 | [diff] [blame] | 340 | if (tbiaddr == -1) { |
| 341 | err = -EBUSY; |
| 342 | goto err_free_irqs; |
| 343 | } else { |
| 344 | out_be32(tbipa, tbiaddr); |
| 345 | } |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 346 | } |
| 347 | |
Grant Likely | 324931b | 2009-04-25 12:53:07 +0000 | [diff] [blame] | 348 | err = of_mdiobus_register(new_bus, np); |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 349 | if (err) { |
Timur Tabi | 5078ac7 | 2012-08-29 08:08:00 +0000 | [diff] [blame^] | 350 | dev_err(&pdev->dev, "cannot register %s as MDIO bus\n", |
| 351 | new_bus->name); |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 352 | goto err_free_irqs; |
| 353 | } |
| 354 | |
| 355 | return 0; |
| 356 | |
| 357 | err_free_irqs: |
| 358 | kfree(new_bus->irq); |
| 359 | err_unmap_regs: |
Anton Vorontsov | b3319b1 | 2009-12-30 08:23:34 +0000 | [diff] [blame] | 360 | iounmap(priv->map); |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 361 | err_free_bus: |
| 362 | kfree(new_bus); |
Anton Vorontsov | b3319b1 | 2009-12-30 08:23:34 +0000 | [diff] [blame] | 363 | err_free_priv: |
| 364 | kfree(priv); |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 365 | return err; |
| 366 | } |
| 367 | |
| 368 | |
Timur Tabi | 5078ac7 | 2012-08-29 08:08:00 +0000 | [diff] [blame^] | 369 | static int fsl_pq_mdio_remove(struct platform_device *pdev) |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 370 | { |
Timur Tabi | 5078ac7 | 2012-08-29 08:08:00 +0000 | [diff] [blame^] | 371 | struct device *device = &pdev->dev; |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 372 | struct mii_bus *bus = dev_get_drvdata(device); |
Anton Vorontsov | b3319b1 | 2009-12-30 08:23:34 +0000 | [diff] [blame] | 373 | struct fsl_pq_mdio_priv *priv = bus->priv; |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 374 | |
| 375 | mdiobus_unregister(bus); |
| 376 | |
| 377 | dev_set_drvdata(device, NULL); |
| 378 | |
Anton Vorontsov | b3319b1 | 2009-12-30 08:23:34 +0000 | [diff] [blame] | 379 | iounmap(priv->map); |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 380 | bus->priv = NULL; |
| 381 | mdiobus_free(bus); |
Anton Vorontsov | b3319b1 | 2009-12-30 08:23:34 +0000 | [diff] [blame] | 382 | kfree(priv); |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | static struct of_device_id fsl_pq_mdio_match[] = { |
| 388 | { |
| 389 | .type = "mdio", |
| 390 | .compatible = "ucc_geth_phy", |
| 391 | }, |
| 392 | { |
| 393 | .type = "mdio", |
| 394 | .compatible = "gianfar", |
| 395 | }, |
| 396 | { |
| 397 | .compatible = "fsl,ucc-mdio", |
| 398 | }, |
| 399 | { |
| 400 | .compatible = "fsl,gianfar-tbi", |
| 401 | }, |
| 402 | { |
| 403 | .compatible = "fsl,gianfar-mdio", |
| 404 | }, |
Sandeep Gopalpet | 1d2397d | 2009-11-02 07:03:22 +0000 | [diff] [blame] | 405 | { |
| 406 | .compatible = "fsl,etsec2-tbi", |
| 407 | }, |
| 408 | { |
| 409 | .compatible = "fsl,etsec2-mdio", |
| 410 | }, |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 411 | {}, |
| 412 | }; |
Anton Vorontsov | e72701a | 2009-10-14 14:54:52 -0700 | [diff] [blame] | 413 | MODULE_DEVICE_TABLE(of, fsl_pq_mdio_match); |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 414 | |
Grant Likely | 7488876 | 2011-02-22 21:05:51 -0700 | [diff] [blame] | 415 | static struct platform_driver fsl_pq_mdio_driver = { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 416 | .driver = { |
| 417 | .name = "fsl-pq_mdio", |
| 418 | .owner = THIS_MODULE, |
| 419 | .of_match_table = fsl_pq_mdio_match, |
| 420 | }, |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 421 | .probe = fsl_pq_mdio_probe, |
| 422 | .remove = fsl_pq_mdio_remove, |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 423 | }; |
| 424 | |
Axel Lin | db62f68 | 2011-11-27 16:44:17 +0000 | [diff] [blame] | 425 | module_platform_driver(fsl_pq_mdio_driver); |
Andy Fleming | 1577ece | 2009-02-04 16:42:12 -0800 | [diff] [blame] | 426 | |
Sebastian Siewior | 2606289 | 2009-11-06 08:50:28 +0000 | [diff] [blame] | 427 | MODULE_LICENSE("GPL"); |