Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARM: da8xx: use platform data for CFGCHIP syscon regmap

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>

authored by

David Lechner and committed by
Sekhar Nori
bdec5a6b e98bbbf3

+60 -43
-4
arch/arm/mach-davinci/board-da830-evm.c
··· 551 551 struct davinci_soc_info *soc_info = &davinci_soc_info; 552 552 int ret; 553 553 554 - ret = da8xx_register_cfgchip(); 555 - if (ret) 556 - pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret); 557 - 558 554 ret = da830_register_gpio(); 559 555 if (ret) 560 556 pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
-4
arch/arm/mach-davinci/board-da850-evm.c
··· 1334 1334 { 1335 1335 int ret; 1336 1336 1337 - ret = da8xx_register_cfgchip(); 1338 - if (ret) 1339 - pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret); 1340 - 1341 1337 ret = da850_register_gpio(); 1342 1338 if (ret) 1343 1339 pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
-4
arch/arm/mach-davinci/board-mityomapl138.c
··· 502 502 { 503 503 int ret; 504 504 505 - ret = da8xx_register_cfgchip(); 506 - if (ret) 507 - pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret); 508 - 509 505 /* for now, no special EDMA channels are reserved */ 510 506 ret = da850_register_edma(NULL); 511 507 if (ret)
-4
arch/arm/mach-davinci/board-omapl138-hawk.c
··· 281 281 { 282 282 int ret; 283 283 284 - ret = da8xx_register_cfgchip(); 285 - if (ret) 286 - pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret); 287 - 288 284 ret = da850_register_gpio(); 289 285 if (ret) 290 286 pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
+26 -23
arch/arm/mach-davinci/devices-da8xx.c
··· 11 11 * (at your option) any later version. 12 12 */ 13 13 #include <linux/init.h> 14 - #include <linux/platform_data/syscon.h> 15 14 #include <linux/platform_device.h> 16 15 #include <linux/dma-contiguous.h> 17 16 #include <linux/serial_8250.h> ··· 1117 1118 } 1118 1119 #endif 1119 1120 1120 - static struct syscon_platform_data da8xx_cfgchip_platform_data = { 1121 - .label = "cfgchip", 1121 + static struct regmap *da8xx_cfgchip; 1122 + 1123 + /* regmap doesn't make a copy of this, so we need to keep the pointer around */ 1124 + static const char da8xx_cfgchip_name[] = "cfgchip"; 1125 + 1126 + static const struct regmap_config da8xx_cfgchip_config __initconst = { 1127 + .name = da8xx_cfgchip_name, 1128 + .reg_bits = 32, 1129 + .val_bits = 32, 1130 + .reg_stride = 4, 1131 + .max_register = DA8XX_CFGCHIP4_REG - DA8XX_CFGCHIP0_REG, 1122 1132 }; 1123 1133 1124 - static struct resource da8xx_cfgchip_resources[] = { 1125 - { 1126 - .start = DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP0_REG, 1127 - .end = DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP4_REG + 3, 1128 - .flags = IORESOURCE_MEM, 1129 - }, 1130 - }; 1131 - 1132 - static struct platform_device da8xx_cfgchip_device = { 1133 - .name = "syscon", 1134 - .id = -1, 1135 - .dev = { 1136 - .platform_data = &da8xx_cfgchip_platform_data, 1137 - }, 1138 - .num_resources = ARRAY_SIZE(da8xx_cfgchip_resources), 1139 - .resource = da8xx_cfgchip_resources, 1140 - }; 1141 - 1142 - int __init da8xx_register_cfgchip(void) 1134 + /** 1135 + * da8xx_get_cfgchip - Lazy gets CFGCHIP as regmap 1136 + * 1137 + * This is for use on non-DT boards only. For DT boards, use 1138 + * syscon_regmap_lookup_by_compatible("ti,da830-cfgchip") 1139 + * 1140 + * Returns: Pointer to the CFGCHIP regmap or negative error code. 1141 + */ 1142 + struct regmap * __init da8xx_get_cfgchip(void) 1143 1143 { 1144 - return platform_device_register(&da8xx_cfgchip_device); 1144 + if (IS_ERR_OR_NULL(da8xx_cfgchip)) 1145 + da8xx_cfgchip = regmap_init_mmio(NULL, 1146 + DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP0_REG), 1147 + &da8xx_cfgchip_config); 1148 + 1149 + return da8xx_cfgchip; 1145 1150 }
+2 -1
arch/arm/mach-davinci/include/mach/da8xx.h
··· 18 18 #include <linux/spi/spi.h> 19 19 #include <linux/platform_data/davinci_asp.h> 20 20 #include <linux/reboot.h> 21 + #include <linux/regmap.h> 21 22 #include <linux/videodev2.h> 22 23 23 24 #include <mach/serial.h> ··· 124 123 int da8xx_register_rproc(void); 125 124 int da850_register_gpio(void); 126 125 int da830_register_gpio(void); 127 - int da8xx_register_cfgchip(void); 126 + struct regmap *da8xx_get_cfgchip(void); 128 127 129 128 extern struct platform_device da8xx_serial_device[]; 130 129 extern struct emac_platform_data da8xx_emac_pdata;
+6
arch/arm/mach-davinci/usb-da8xx.c
··· 8 8 #include <linux/init.h> 9 9 #include <linux/mfd/da8xx-cfgchip.h> 10 10 #include <linux/phy/phy.h> 11 + #include <linux/platform_data/phy-da8xx-usb.h> 11 12 #include <linux/platform_data/usb-davinci.h> 12 13 #include <linux/platform_device.h> 13 14 #include <linux/usb/musb.h> ··· 41 40 42 41 int __init da8xx_register_usb_phy(void) 43 42 { 43 + struct da8xx_usb_phy_platform_data pdata; 44 + 45 + pdata.cfgchip = da8xx_get_cfgchip(); 46 + da8xx_usb_phy.dev.platform_data = &pdata; 47 + 44 48 return platform_device_register(&da8xx_usb_phy); 45 49 } 46 50
+5 -3
drivers/phy/ti/phy-da8xx-usb.c
··· 20 20 #include <linux/mfd/syscon.h> 21 21 #include <linux/module.h> 22 22 #include <linux/phy/phy.h> 23 + #include <linux/platform_data/phy-da8xx-usb.h> 23 24 #include <linux/platform_device.h> 24 25 #include <linux/regmap.h> 25 26 ··· 146 145 static int da8xx_usb_phy_probe(struct platform_device *pdev) 147 146 { 148 147 struct device *dev = &pdev->dev; 148 + struct da8xx_usb_phy_platform_data *pdata = dev->platform_data; 149 149 struct device_node *node = dev->of_node; 150 150 struct da8xx_usb_phy *d_phy; 151 151 ··· 154 152 if (!d_phy) 155 153 return -ENOMEM; 156 154 157 - if (node) 155 + if (pdata) 156 + d_phy->regmap = pdata->cfgchip; 157 + else 158 158 d_phy->regmap = syscon_regmap_lookup_by_compatible( 159 159 "ti,da830-cfgchip"); 160 - else 161 - d_phy->regmap = syscon_regmap_lookup_by_pdevname("syscon"); 162 160 if (IS_ERR(d_phy->regmap)) { 163 161 dev_err(dev, "Failed to get syscon\n"); 164 162 return PTR_ERR(d_phy->regmap);
+21
include/linux/platform_data/phy-da8xx-usb.h
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * phy-da8xx-usb - TI DaVinci DA8xx USB PHY driver 4 + * 5 + * Copyright (C) 2018 David Lechner <david@lechnology.com> 6 + */ 7 + 8 + #ifndef __LINUX_PLATFORM_DATA_PHY_DA8XX_USB_H__ 9 + #define __LINUX_PLATFORM_DATA_PHY_DA8XX_USB_H__ 10 + 11 + #include <linux/regmap.h> 12 + 13 + /** 14 + * da8xx_usb_phy_platform_data 15 + * @cfgchip: CFGCHIP syscon regmap 16 + */ 17 + struct da8xx_usb_phy_platform_data { 18 + struct regmap *cfgchip; 19 + }; 20 + 21 + #endif /* __LINUX_PLATFORM_DATA_PHY_DA8XX_USB_H__ */