root/drivers/net/phy/mdio-octeon.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. octeon_mdiobus_probe
  2. octeon_mdiobus_remove
  3. octeon_mdiobus_force_mod_depencency

   1 // SPDX-License-Identifier: GPL-2.0
   2 /*
   3  * Copyright (C) 2009-2015 Cavium, Inc.
   4  */
   5 
   6 #include <linux/platform_device.h>
   7 #include <linux/of_address.h>
   8 #include <linux/of_mdio.h>
   9 #include <linux/module.h>
  10 #include <linux/gfp.h>
  11 #include <linux/phy.h>
  12 #include <linux/io.h>
  13 
  14 #include "mdio-cavium.h"
  15 
  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 
  26         mii_bus = devm_mdiobus_alloc_size(&pdev->dev, sizeof(*bus));
  27         if (!mii_bus)
  28                 return -ENOMEM;
  29 
  30         res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  31         if (res_mem == NULL) {
  32                 dev_err(&pdev->dev, "found no memory resource\n");
  33                 return -ENXIO;
  34         }
  35 
  36         bus = mii_bus->priv;
  37         bus->mii_bus = mii_bus;
  38         mdio_phys = res_mem->start;
  39         regsize = resource_size(res_mem);
  40 
  41         if (!devm_request_mem_region(&pdev->dev, mdio_phys, regsize,
  42                                      res_mem->name)) {
  43                 dev_err(&pdev->dev, "request_mem_region failed\n");
  44                 return -ENXIO;
  45         }
  46 
  47         bus->register_base =
  48                 (u64)devm_ioremap(&pdev->dev, mdio_phys, regsize);
  49         if (!bus->register_base) {
  50                 dev_err(&pdev->dev, "dev_ioremap failed\n");
  51                 return -ENOMEM;
  52         }
  53 
  54         smi_en.u64 = 0;
  55         smi_en.s.en = 1;
  56         oct_mdio_writeq(smi_en.u64, bus->register_base + SMI_EN);
  57 
  58         bus->mii_bus->name = KBUILD_MODNAME;
  59         snprintf(bus->mii_bus->id, MII_BUS_ID_SIZE, "%llx", bus->register_base);
  60         bus->mii_bus->parent = &pdev->dev;
  61 
  62         bus->mii_bus->read = cavium_mdiobus_read;
  63         bus->mii_bus->write = cavium_mdiobus_write;
  64 
  65         platform_set_drvdata(pdev, bus);
  66 
  67         err = of_mdiobus_register(bus->mii_bus, pdev->dev.of_node);
  68         if (err)
  69                 goto fail_register;
  70 
  71         dev_info(&pdev->dev, "Probed\n");
  72 
  73         return 0;
  74 fail_register:
  75         mdiobus_free(bus->mii_bus);
  76         smi_en.u64 = 0;
  77         oct_mdio_writeq(smi_en.u64, bus->register_base + SMI_EN);
  78         return err;
  79 }
  80 
  81 static int octeon_mdiobus_remove(struct platform_device *pdev)
  82 {
  83         struct cavium_mdiobus *bus;
  84         union cvmx_smix_en smi_en;
  85 
  86         bus = platform_get_drvdata(pdev);
  87 
  88         mdiobus_unregister(bus->mii_bus);
  89         mdiobus_free(bus->mii_bus);
  90         smi_en.u64 = 0;
  91         oct_mdio_writeq(smi_en.u64, bus->register_base + SMI_EN);
  92         return 0;
  93 }
  94 
  95 static const struct of_device_id octeon_mdiobus_match[] = {
  96         {
  97                 .compatible = "cavium,octeon-3860-mdio",
  98         },
  99         {},
 100 };
 101 MODULE_DEVICE_TABLE(of, octeon_mdiobus_match);
 102 
 103 static struct platform_driver octeon_mdiobus_driver = {
 104         .driver = {
 105                 .name           = KBUILD_MODNAME,
 106                 .of_match_table = octeon_mdiobus_match,
 107         },
 108         .probe          = octeon_mdiobus_probe,
 109         .remove         = octeon_mdiobus_remove,
 110 };
 111 
 112 void octeon_mdiobus_force_mod_depencency(void)
 113 {
 114         /* Let ethernet drivers force us to be loaded.  */
 115 }
 116 EXPORT_SYMBOL(octeon_mdiobus_force_mod_depencency);
 117 
 118 module_platform_driver(octeon_mdiobus_driver);
 119 
 120 MODULE_DESCRIPTION("Cavium OCTEON MDIO bus driver");
 121 MODULE_AUTHOR("David Daney");
 122 MODULE_LICENSE("GPL v2");

/* [<][>][^][v][top][bottom][index][help] */