| .. | .. |
|---|
| 49 | 49 | struct mdio_fsl_priv { |
|---|
| 50 | 50 | struct tgec_mdio_controller __iomem *mdio_base; |
|---|
| 51 | 51 | bool is_little_endian; |
|---|
| 52 | + bool has_a009885; |
|---|
| 52 | 53 | bool has_a011043; |
|---|
| 53 | 54 | }; |
|---|
| 54 | 55 | |
|---|
| .. | .. |
|---|
| 184 | 185 | { |
|---|
| 185 | 186 | struct mdio_fsl_priv *priv = (struct mdio_fsl_priv *)bus->priv; |
|---|
| 186 | 187 | struct tgec_mdio_controller __iomem *regs = priv->mdio_base; |
|---|
| 188 | + unsigned long flags; |
|---|
| 187 | 189 | uint16_t dev_addr; |
|---|
| 188 | 190 | uint32_t mdio_stat; |
|---|
| 189 | 191 | uint32_t mdio_ctl; |
|---|
| 190 | | - uint16_t value; |
|---|
| 191 | 192 | int ret; |
|---|
| 192 | 193 | bool endian = priv->is_little_endian; |
|---|
| 193 | 194 | |
|---|
| .. | .. |
|---|
| 219 | 220 | return ret; |
|---|
| 220 | 221 | } |
|---|
| 221 | 222 | |
|---|
| 223 | + if (priv->has_a009885) |
|---|
| 224 | + /* Once the operation completes, i.e. MDIO_STAT_BSY clears, we |
|---|
| 225 | + * must read back the data register within 16 MDC cycles. |
|---|
| 226 | + */ |
|---|
| 227 | + local_irq_save(flags); |
|---|
| 228 | + |
|---|
| 222 | 229 | /* Initiate the read */ |
|---|
| 223 | 230 | xgmac_write32(mdio_ctl | MDIO_CTL_READ, ®s->mdio_ctl, endian); |
|---|
| 224 | 231 | |
|---|
| 225 | 232 | ret = xgmac_wait_until_done(&bus->dev, regs, endian); |
|---|
| 226 | 233 | if (ret) |
|---|
| 227 | | - return ret; |
|---|
| 234 | + goto irq_restore; |
|---|
| 228 | 235 | |
|---|
| 229 | 236 | /* Return all Fs if nothing was there */ |
|---|
| 230 | 237 | if ((xgmac_read32(®s->mdio_stat, endian) & MDIO_STAT_RD_ER) && |
|---|
| 231 | 238 | !priv->has_a011043) { |
|---|
| 232 | | - dev_err(&bus->dev, |
|---|
| 239 | + dev_dbg(&bus->dev, |
|---|
| 233 | 240 | "Error while reading PHY%d reg at %d.%hhu\n", |
|---|
| 234 | 241 | phy_id, dev_addr, regnum); |
|---|
| 235 | | - return 0xffff; |
|---|
| 242 | + ret = 0xffff; |
|---|
| 243 | + } else { |
|---|
| 244 | + ret = xgmac_read32(®s->mdio_data, endian) & 0xffff; |
|---|
| 245 | + dev_dbg(&bus->dev, "read %04x\n", ret); |
|---|
| 236 | 246 | } |
|---|
| 237 | 247 | |
|---|
| 238 | | - value = xgmac_read32(®s->mdio_data, endian) & 0xffff; |
|---|
| 239 | | - dev_dbg(&bus->dev, "read %04x\n", value); |
|---|
| 248 | +irq_restore: |
|---|
| 249 | + if (priv->has_a009885) |
|---|
| 250 | + local_irq_restore(flags); |
|---|
| 240 | 251 | |
|---|
| 241 | | - return value; |
|---|
| 252 | + return ret; |
|---|
| 242 | 253 | } |
|---|
| 243 | 254 | |
|---|
| 244 | 255 | static int xgmac_mdio_probe(struct platform_device *pdev) |
|---|
| 245 | 256 | { |
|---|
| 246 | 257 | struct device_node *np = pdev->dev.of_node; |
|---|
| 247 | 258 | struct mii_bus *bus; |
|---|
| 248 | | - struct resource res; |
|---|
| 259 | + struct resource *res; |
|---|
| 249 | 260 | struct mdio_fsl_priv *priv; |
|---|
| 250 | 261 | int ret; |
|---|
| 251 | 262 | |
|---|
| 252 | | - ret = of_address_to_resource(np, 0, &res); |
|---|
| 253 | | - if (ret) { |
|---|
| 263 | + /* In DPAA-1, MDIO is one of the many FMan sub-devices. The FMan |
|---|
| 264 | + * defines a register space that spans a large area, covering all the |
|---|
| 265 | + * subdevice areas. Therefore, MDIO cannot claim exclusive access to |
|---|
| 266 | + * this register area. |
|---|
| 267 | + */ |
|---|
| 268 | + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 269 | + if (!res) { |
|---|
| 254 | 270 | dev_err(&pdev->dev, "could not obtain address\n"); |
|---|
| 255 | | - return ret; |
|---|
| 271 | + return -EINVAL; |
|---|
| 256 | 272 | } |
|---|
| 257 | 273 | |
|---|
| 258 | 274 | bus = mdiobus_alloc_size(sizeof(struct mdio_fsl_priv)); |
|---|
| .. | .. |
|---|
| 263 | 279 | bus->read = xgmac_mdio_read; |
|---|
| 264 | 280 | bus->write = xgmac_mdio_write; |
|---|
| 265 | 281 | bus->parent = &pdev->dev; |
|---|
| 266 | | - snprintf(bus->id, MII_BUS_ID_SIZE, "%llx", (unsigned long long)res.start); |
|---|
| 282 | + bus->probe_capabilities = MDIOBUS_C22_C45; |
|---|
| 283 | + snprintf(bus->id, MII_BUS_ID_SIZE, "%pa", &res->start); |
|---|
| 267 | 284 | |
|---|
| 268 | 285 | /* Set the PHY base address */ |
|---|
| 269 | 286 | priv = bus->priv; |
|---|
| 270 | | - priv->mdio_base = of_iomap(np, 0); |
|---|
| 287 | + priv->mdio_base = ioremap(res->start, resource_size(res)); |
|---|
| 271 | 288 | if (!priv->mdio_base) { |
|---|
| 272 | 289 | ret = -ENOMEM; |
|---|
| 273 | 290 | goto err_ioremap; |
|---|
| 274 | 291 | } |
|---|
| 275 | 292 | |
|---|
| 276 | | - priv->is_little_endian = of_property_read_bool(pdev->dev.of_node, |
|---|
| 277 | | - "little-endian"); |
|---|
| 293 | + priv->is_little_endian = device_property_read_bool(&pdev->dev, |
|---|
| 294 | + "little-endian"); |
|---|
| 278 | 295 | |
|---|
| 279 | | - priv->has_a011043 = of_property_read_bool(pdev->dev.of_node, |
|---|
| 280 | | - "fsl,erratum-a011043"); |
|---|
| 296 | + priv->has_a009885 = device_property_read_bool(&pdev->dev, |
|---|
| 297 | + "fsl,erratum-a009885"); |
|---|
| 298 | + priv->has_a011043 = device_property_read_bool(&pdev->dev, |
|---|
| 299 | + "fsl,erratum-a011043"); |
|---|
| 281 | 300 | |
|---|
| 282 | 301 | ret = of_mdiobus_register(bus, np); |
|---|
| 283 | 302 | if (ret) { |
|---|
| .. | .. |
|---|
| 321 | 340 | }; |
|---|
| 322 | 341 | MODULE_DEVICE_TABLE(of, xgmac_mdio_match); |
|---|
| 323 | 342 | |
|---|
| 343 | +static const struct acpi_device_id xgmac_acpi_match[] = { |
|---|
| 344 | + { "NXP0006" }, |
|---|
| 345 | + { } |
|---|
| 346 | +}; |
|---|
| 347 | +MODULE_DEVICE_TABLE(acpi, xgmac_acpi_match); |
|---|
| 348 | + |
|---|
| 324 | 349 | static struct platform_driver xgmac_mdio_driver = { |
|---|
| 325 | 350 | .driver = { |
|---|
| 326 | 351 | .name = "fsl-fman_xmdio", |
|---|
| 327 | 352 | .of_match_table = xgmac_mdio_match, |
|---|
| 353 | + .acpi_match_table = xgmac_acpi_match, |
|---|
| 328 | 354 | }, |
|---|
| 329 | 355 | .probe = xgmac_mdio_probe, |
|---|
| 330 | 356 | .remove = xgmac_mdio_remove, |
|---|