ARM: da8xx: use platform data for CFGCHIP syscon regmap
authorDavid Lechner <david@lechnology.com>
Sun, 18 Feb 2018 03:22:24 +0000 (21:22 -0600)
committerSekhar Nori <nsekhar@ti.com>
Mon, 19 Feb 2018 10:49:25 +0000 (16:19 +0530)
This converts from using a platform device for the CFGCHIP syscon
regmap to using platform data to pass the regmap to consumers.

A lazy getter function is used so that the regmap will only be
created if it is actually used. This function will also be used
in the clock init when we convert to the common clock framework.

The USB PHY driver is currently the only consumer. This driver is
updated to use platform data to get the CFGCHIP regmap instead of
syscon_regmap_lookup_by_pdevname().

Signed-off-by: David Lechner <david@lechnology.com>
Acked-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
arch/arm/mach-davinci/board-da830-evm.c
arch/arm/mach-davinci/board-da850-evm.c
arch/arm/mach-davinci/board-mityomapl138.c
arch/arm/mach-davinci/board-omapl138-hawk.c
arch/arm/mach-davinci/devices-da8xx.c
arch/arm/mach-davinci/include/mach/da8xx.h
arch/arm/mach-davinci/usb-da8xx.c
drivers/phy/ti/phy-da8xx-usb.c
include/linux/platform_data/phy-da8xx-usb.h [new file with mode: 0644]

index f673cd7a67665896f849cab26a394ce012e44e19..f960cbef6538119784f496c4b5c17998c0936ca8 100644 (file)
@@ -551,10 +551,6 @@ static __init void da830_evm_init(void)
        struct davinci_soc_info *soc_info = &davinci_soc_info;
        int ret;
 
-       ret = da8xx_register_cfgchip();
-       if (ret)
-               pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
-
        ret = da830_register_gpio();
        if (ret)
                pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
index d898a94f6eaed8766e38103f3c3b113ae1eed3f0..26bdb10a8927b98ff526f04ded4be4a0fced050d 100644 (file)
@@ -1334,10 +1334,6 @@ static __init void da850_evm_init(void)
 {
        int ret;
 
-       ret = da8xx_register_cfgchip();
-       if (ret)
-               pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
-
        ret = da850_register_gpio();
        if (ret)
                pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
index b73ce7bae81f6399ec0fd64113e53ec93f935124..9e7388ba413ca0cd96d0069bcfe842733dee49c2 100644 (file)
@@ -502,10 +502,6 @@ static void __init mityomapl138_init(void)
 {
        int ret;
 
-       ret = da8xx_register_cfgchip();
-       if (ret)
-               pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
-
        /* for now, no special EDMA channels are reserved */
        ret = da850_register_edma(NULL);
        if (ret)
index a3e78074be701a3a6abec03ff7e5586f79acfcbe..baab7eb616321fc7232778c5e77e835546229316 100644 (file)
@@ -281,10 +281,6 @@ static __init void omapl138_hawk_init(void)
 {
        int ret;
 
-       ret = da8xx_register_cfgchip();
-       if (ret)
-               pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
-
        ret = da850_register_gpio();
        if (ret)
                pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
index e1c40e73d30abca32e53f7cf92650b322a936141..166bf29b1296198ce45292261dd7381cae4f8a8d 100644 (file)
@@ -11,7 +11,6 @@
  * (at your option) any later version.
  */
 #include <linux/init.h>
-#include <linux/platform_data/syscon.h>
 #include <linux/platform_device.h>
 #include <linux/dma-contiguous.h>
 #include <linux/serial_8250.h>
@@ -1118,29 +1117,33 @@ int __init da850_register_sata(unsigned long refclkpn)
 }
 #endif
 
-static struct syscon_platform_data da8xx_cfgchip_platform_data = {
-       .label  = "cfgchip",
-};
+static struct regmap *da8xx_cfgchip;
 
-static struct resource da8xx_cfgchip_resources[] = {
-       {
-               .start  = DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP0_REG,
-               .end    = DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP4_REG + 3,
-               .flags  = IORESOURCE_MEM,
-       },
-};
+/* regmap doesn't make a copy of this, so we need to keep the pointer around */
+static const char da8xx_cfgchip_name[] = "cfgchip";
 
-static struct platform_device da8xx_cfgchip_device = {
-       .name   = "syscon",
-       .id     = -1,
-       .dev    = {
-               .platform_data  = &da8xx_cfgchip_platform_data,
-       },
-       .num_resources  = ARRAY_SIZE(da8xx_cfgchip_resources),
-       .resource       = da8xx_cfgchip_resources,
+static const struct regmap_config da8xx_cfgchip_config __initconst = {
+       .name           = da8xx_cfgchip_name,
+       .reg_bits       = 32,
+       .val_bits       = 32,
+       .reg_stride     = 4,
+       .max_register   = DA8XX_CFGCHIP4_REG - DA8XX_CFGCHIP0_REG,
 };
 
-int __init da8xx_register_cfgchip(void)
+/**
+ * da8xx_get_cfgchip - Lazy gets CFGCHIP as regmap
+ *
+ * This is for use on non-DT boards only. For DT boards, use
+ * syscon_regmap_lookup_by_compatible("ti,da830-cfgchip")
+ *
+ * Returns: Pointer to the CFGCHIP regmap or negative error code.
+ */
+struct regmap * __init da8xx_get_cfgchip(void)
 {
-       return platform_device_register(&da8xx_cfgchip_device);
+       if (IS_ERR_OR_NULL(da8xx_cfgchip))
+               da8xx_cfgchip = regmap_init_mmio(NULL,
+                                       DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP0_REG),
+                                       &da8xx_cfgchip_config);
+
+       return da8xx_cfgchip;
 }
index 93ff1569cee5113a4743ade94c0d1adb0a9df45b..03f37ef4297f0cf960285c12a7e1cbbf2a0aded8 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/spi/spi.h>
 #include <linux/platform_data/davinci_asp.h>
 #include <linux/reboot.h>
+#include <linux/regmap.h>
 #include <linux/videodev2.h>
 
 #include <mach/serial.h>
@@ -123,7 +124,7 @@ void da8xx_rproc_reserve_cma(void);
 int da8xx_register_rproc(void);
 int da850_register_gpio(void);
 int da830_register_gpio(void);
-int da8xx_register_cfgchip(void);
+struct regmap *da8xx_get_cfgchip(void);
 
 extern struct platform_device da8xx_serial_device[];
 extern struct emac_platform_data da8xx_emac_pdata;
index fb31f6eeba963b9f55c29a18c140990fb9c0c5f9..4d89d86ce7e580eb79f4b15ce462f44bc49efa4f 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/init.h>
 #include <linux/mfd/da8xx-cfgchip.h>
 #include <linux/phy/phy.h>
+#include <linux/platform_data/phy-da8xx-usb.h>
 #include <linux/platform_data/usb-davinci.h>
 #include <linux/platform_device.h>
 #include <linux/usb/musb.h>
@@ -40,6 +41,11 @@ static struct platform_device da8xx_usb_phy = {
 
 int __init da8xx_register_usb_phy(void)
 {
+       struct da8xx_usb_phy_platform_data pdata;
+
+       pdata.cfgchip = da8xx_get_cfgchip();
+       da8xx_usb_phy.dev.platform_data = &pdata;
+
        return platform_device_register(&da8xx_usb_phy);
 }
 
index 5bd33d06df9596572f9fe37fe3c3201a5a0b1571..befb886ff1212abe6796f4b67d43816987f5f70b 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/mfd/syscon.h>
 #include <linux/module.h>
 #include <linux/phy/phy.h>
+#include <linux/platform_data/phy-da8xx-usb.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 
@@ -145,6 +146,7 @@ static struct phy *da8xx_usb_phy_of_xlate(struct device *dev,
 static int da8xx_usb_phy_probe(struct platform_device *pdev)
 {
        struct device           *dev = &pdev->dev;
+       struct da8xx_usb_phy_platform_data *pdata = dev->platform_data;
        struct device_node      *node = dev->of_node;
        struct da8xx_usb_phy    *d_phy;
 
@@ -152,11 +154,11 @@ static int da8xx_usb_phy_probe(struct platform_device *pdev)
        if (!d_phy)
                return -ENOMEM;
 
-       if (node)
+       if (pdata)
+               d_phy->regmap = pdata->cfgchip;
+       else
                d_phy->regmap = syscon_regmap_lookup_by_compatible(
                                                        "ti,da830-cfgchip");
-       else
-               d_phy->regmap = syscon_regmap_lookup_by_pdevname("syscon");
        if (IS_ERR(d_phy->regmap)) {
                dev_err(dev, "Failed to get syscon\n");
                return PTR_ERR(d_phy->regmap);
diff --git a/include/linux/platform_data/phy-da8xx-usb.h b/include/linux/platform_data/phy-da8xx-usb.h
new file mode 100644 (file)
index 0000000..85c2b99
--- /dev/null
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * phy-da8xx-usb - TI DaVinci DA8xx USB PHY driver
+ *
+ * Copyright (C) 2018 David Lechner <david@lechnology.com>
+ */
+
+#ifndef __LINUX_PLATFORM_DATA_PHY_DA8XX_USB_H__
+#define __LINUX_PLATFORM_DATA_PHY_DA8XX_USB_H__
+
+#include <linux/regmap.h>
+
+/**
+ * da8xx_usb_phy_platform_data
+ * @cfgchip: CFGCHIP syscon regmap
+ */
+struct da8xx_usb_phy_platform_data {
+       struct regmap *cfgchip;
+};
+
+#endif /* __LINUX_PLATFORM_DATA_PHY_DA8XX_USB_H__ */