mdio-octeon.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2009-2015 Cavium, Inc.
  7. */
  8. #include <linux/platform_device.h>
  9. #include <linux/of_address.h>
  10. #include <linux/of_mdio.h>
  11. #include <linux/module.h>
  12. #include <linux/gfp.h>
  13. #include <linux/phy.h>
  14. #include <linux/io.h>
  15. #include "mdio-cavium.h"
  16. static int octeon_mdiobus_probe(struct platform_device *pdev)
  17. {
  18. struct cavium_mdiobus *bus;
  19. struct mii_bus *mii_bus;
  20. struct resource *res_mem;
  21. resource_size_t mdio_phys;
  22. resource_size_t regsize;
  23. union cvmx_smix_en smi_en;
  24. int err = -ENOENT;
  25. mii_bus = devm_mdiobus_alloc_size(&pdev->dev, sizeof(*bus));
  26. if (!mii_bus)
  27. return -ENOMEM;
  28. res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  29. if (res_mem == NULL) {
  30. dev_err(&pdev->dev, "found no memory resource\n");
  31. return -ENXIO;
  32. }
  33. bus = mii_bus->priv;
  34. bus->mii_bus = mii_bus;
  35. mdio_phys = res_mem->start;
  36. regsize = resource_size(res_mem);
  37. if (!devm_request_mem_region(&pdev->dev, mdio_phys, regsize,
  38. res_mem->name)) {
  39. dev_err(&pdev->dev, "request_mem_region failed\n");
  40. return -ENXIO;
  41. }
  42. bus->register_base =
  43. (u64)devm_ioremap(&pdev->dev, mdio_phys, regsize);
  44. if (!bus->register_base) {
  45. dev_err(&pdev->dev, "dev_ioremap failed\n");
  46. return -ENOMEM;
  47. }
  48. smi_en.u64 = 0;
  49. smi_en.s.en = 1;
  50. oct_mdio_writeq(smi_en.u64, bus->register_base + SMI_EN);
  51. bus->mii_bus->name = KBUILD_MODNAME;
  52. snprintf(bus->mii_bus->id, MII_BUS_ID_SIZE, "%llx", bus->register_base);
  53. bus->mii_bus->parent = &pdev->dev;
  54. bus->mii_bus->read = cavium_mdiobus_read;
  55. bus->mii_bus->write = cavium_mdiobus_write;
  56. platform_set_drvdata(pdev, bus);
  57. err = of_mdiobus_register(bus->mii_bus, pdev->dev.of_node);
  58. if (err)
  59. goto fail_register;
  60. dev_info(&pdev->dev, "Probed\n");
  61. return 0;
  62. fail_register:
  63. mdiobus_free(bus->mii_bus);
  64. smi_en.u64 = 0;
  65. oct_mdio_writeq(smi_en.u64, bus->register_base + SMI_EN);
  66. return err;
  67. }
  68. static int octeon_mdiobus_remove(struct platform_device *pdev)
  69. {
  70. struct cavium_mdiobus *bus;
  71. union cvmx_smix_en smi_en;
  72. bus = platform_get_drvdata(pdev);
  73. mdiobus_unregister(bus->mii_bus);
  74. mdiobus_free(bus->mii_bus);
  75. smi_en.u64 = 0;
  76. oct_mdio_writeq(smi_en.u64, bus->register_base + SMI_EN);
  77. return 0;
  78. }
  79. static const struct of_device_id octeon_mdiobus_match[] = {
  80. {
  81. .compatible = "cavium,octeon-3860-mdio",
  82. },
  83. {},
  84. };
  85. MODULE_DEVICE_TABLE(of, octeon_mdiobus_match);
  86. static struct platform_driver octeon_mdiobus_driver = {
  87. .driver = {
  88. .name = KBUILD_MODNAME,
  89. .of_match_table = octeon_mdiobus_match,
  90. },
  91. .probe = octeon_mdiobus_probe,
  92. .remove = octeon_mdiobus_remove,
  93. };
  94. void octeon_mdiobus_force_mod_depencency(void)
  95. {
  96. /* Let ethernet drivers force us to be loaded. */
  97. }
  98. EXPORT_SYMBOL(octeon_mdiobus_force_mod_depencency);
  99. module_platform_driver(octeon_mdiobus_driver);
  100. MODULE_DESCRIPTION("Cavium OCTEON MDIO bus driver");
  101. MODULE_AUTHOR("David Daney");
  102. MODULE_LICENSE("GPL");