soc: ti: Add module build support to the socinfo
Subsystems (7)
v4 cover soc: ti: Add module build support to the socinfo
In order for the TI K3 SoC info driver to be built as a module, the following changes have been made:
- Converted memory allocations to devm and added the remove callback
- Added necessary code to build the driver as a module
- UDMA: Added deferred probe when soc_device_match() fails because the socinfo driver is built as a module and hasn't probed yet
- MDIO: Same as the UDMA driver, return deferred probe if soc_device_match() returns null
v2->v3:
dropped module conversion part of this series while other driver dependencies on socinfo are worked out.
A dependency issue is introduced by changing subsys_initcall() to module_platform_driver(). Some drivers using the socinfo information probe before the socinfo driver itself and it makes their probe fail.
v3->v4:
reintegrated the module build support and added patches for udma and mdio drivers to allow for deferred probe if socinfo hasn't probed yet.
Nicolas Frayer (4):
soc: ti: Convert allocations to devm
soc: ti: Add module build support
dmaengine: ti: k3-udma: Deferring probe when soc_device_match()
returns NULL
net: ethernet: ti: davinci_mdio: Deferring probe when
soc_device_match() returns NULL
arch/arm64/Kconfig.platforms | 1 - drivers/dma/ti/k3-udma.c | 2 +- drivers/net/ethernet/ti/davinci_mdio.c | 4 +++ drivers/soc/ti/Kconfig | 3 +- drivers/soc/ti/k3-socinfo.c | 47 ++++++++++++++++---------- 5 files changed, 37 insertions(+), 20 deletions(-)
Signature · 1 line
2.25.1
PATCH v4 1/4 soc: ti: Convert allocations to devm
Changed the memory and resource allocations in the probe function to devm. Also added a remove callback.
--- drivers/soc/ti/k3-socinfo.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)
drivers/soc/ti/k3-socinfo.c +19 -17
@@ -96,21 +96,18 @@ static int k3_chipinfo_probe(struct platform_device *pdev) partno_id = (jtag_id &CTRLMMR_WKUP_JTAGID_PARTNO_MASK ) >>CTRLMMR_WKUP_JTAGID_PARTNO_SHIFT ; - soc_dev_attr =kzalloc (sizeof (*soc_dev_attr),GFP_KERNEL ); + soc_dev_attr =devm_kzalloc (&pdev->dev,sizeof (*soc_dev_attr),GFP_KERNEL );if (!soc_dev_attr)return -ENOMEM ; - soc_dev_attr->revision =kasprintf (GFP_KERNEL ,"SR%x.0" , variant); -if (!soc_dev_attr->revision) { - ret = -ENOMEM ; - goto err; - } + soc_dev_attr->revision =devm_kasprintf (&pdev->dev,GFP_KERNEL ,"SR%x.0" , variant); +if (!soc_dev_attr->revision) +return -ENOMEM ; ret =k3_chipinfo_partno_to_names (partno_id, soc_dev_attr);if (ret) {dev_err (dev,"Unknown SoC JTAGID[0x%08X]\n" , jtag_id); - ret = -ENODEV ; - goto err_free_rev; +return -ENODEV ; } node =of_find_node_by_path ("/" );
@@ -118,22 +115,26 @@ static int k3_chipinfo_probe(struct platform_device *pdev)of_node_put (node); soc_dev =soc_device_register (soc_dev_attr); -if (IS_ERR (soc_dev)) { - ret =PTR_ERR (soc_dev); - goto err_free_rev; - } +if (IS_ERR (soc_dev)) +return PTR_ERR (soc_dev); + +platform_set_drvdata (pdev, soc_dev);dev_info (dev,"Family:%s rev:%s JTAGID[0x%08x] Detected\n" , soc_dev_attr->family, soc_dev_attr->revision, jtag_id);return 0 ; +} + +static int k3_chipinfo_remove (struct platform_device *pdev) +{ +struct soc_device *soc_dev =platform_get_drvdata (pdev); -err_free_rev: -kfree (soc_dev_attr->revision); -err: -kfree (soc_dev_attr); -return ret; +if (soc_dev) +soc_device_unregister (soc_dev); + +return 0 ; }static const struct of_device_id k3_chipinfo_of_match[] = {
@@ -147,6 +148,7 @@ static struct platform_driver k3_chipinfo_driver = { .of_match_table = k3_chipinfo_of_match, }, .probe = k3_chipinfo_probe, + .remove = k3_chipinfo_remove, };static int __init k3_chipinfo_init (void )
Signature · 1 line
2.25.1
PATCH v4 2/4 soc: ti: Add module build support
In reply to Nicolas FrayerAdded module build support for the TI K3 SoC info driver.
--- arch/arm64/Kconfig.platforms | 1 - drivers/soc/ti/Kconfig | 3 ++- drivers/soc/ti/k3-socinfo.c | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-)
arch/arm64/Kconfig.platforms +0 -1
@@ -130,7 +130,6 @@ config ARCH_K3 select TI_SCI_PROTOCOL select TI_SCI_INTR_IRQCHIP select TI_SCI_INTA_IRQCHIP - select TI_K3_SOCINFO help This enables support for Texas Instruments' K3 multicore SoC architecture.
drivers/soc/ti/Kconfig +2 -1
@@ -74,7 +74,8 @@ config TI_K3_RINGACC If unsure, say N. config TI_K3_SOCINFO - bool + tristate "TI K3 SoC info driver" + default y depends on ARCH_K3 || COMPILE_TEST select SOC_BUS select MFD_SYSCON
drivers/soc/ti/k3-socinfo.c +11 -0
@@ -13,6 +13,7 @@#include <linux/slab.h> #include <linux/string.h> #include <linux/sys_soc.h> +#include <linux/module.h> #define CTRLMMR_WKUP_JTAGID_REG 0/*
@@ -141,6 +142,7 @@ static const struct of_device_id k3_chipinfo_of_match[] = { { .compatible = "ti,am654-chipid", }, { /* sentinel */ }, }; +MODULE_DEVICE_TABLE (of, k3_chipinfo_of_match);static struct platform_driver k3_chipinfo_driver = { .driver = {
@@ -156,3 +158,12 @@ static int __init k3_chipinfo_init(void)return platform_driver_register (&k3_chipinfo_driver); }subsys_initcall (k3_chipinfo_init); + +static void __exit k3_chipinfo_exit(void) +{ +platform_driver_unregister (&k3_chipinfo_driver); +} +module_exit (k3_chipinfo_exit); + +MODULE_DESCRIPTION ("TI K3 SoC info driver" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
2.25.1
Re: [PATCH v4 2/4] soc: ti: Add module build support
Hi--
Quoted 26 lines · Nicolas Frayer
Added module build support for the TI K3 SoC info driver.
Signed-off-by Nicolas Frayer <[email protected]>--- arch/arm64/Kconfig.platforms | 1 - drivers/soc/ti/Kconfig | 3 ++- drivers/soc/ti/k3-socinfo.c | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-)arch/arm64/Kconfig.platforms +0
-1@@ -130,7 +130,6 @@ config ARCH_K3 select TI_SCI_PROTOCOL select TI_SCI_INTR_IRQCHIP select TI_SCI_INTA_IRQCHIP - select TI_K3_SOCINFO help This enables support for Texas Instruments' K3 multicore SoC architecture.drivers/soc/ti/Kconfig +0
-0
drivers/soc/ti/Kconfig config TI_K3_RINGACC · line 78
Quoted 6 lines
drivers/soc/ti/Kconfig +2
-1@@ -74,7 +74,8 @@ config TI_K3_RINGACC If unsure, say N. config TI_K3_SOCINFO - bool + tristate "TI K3 SoC info driver" + default y
Maybe
default ARCH_K3
?
Quoted 3 lines
drivers/soc/ti/Kconfig +0
-0depends on ARCH_K3 || COMPILE_TEST select SOC_BUS select MFD_SYSCON
Signature · 1 line
~Randy
Re: [PATCH v4 2/4] soc: ti: Add module build support
Hi Randy,
Quoted 32 lines · Randy Dunlap
Hi--
Quoted 28 lines · Nicolas Frayer
Added module build support for the TI K3 SoC info driver.
Signed-off-by Nicolas Frayer <[email protected]>--- arch/arm64/Kconfig.platforms | 1 - drivers/soc/ti/Kconfig | 3 ++- drivers/soc/ti/k3-socinfo.c | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-)arch/arm64/Kconfig.platforms +0
-1@@ -130,7 +130,6 @@ config ARCH_K3 select TI_SCI_PROTOCOL select TI_SCI_INTR_IRQCHIP select TI_SCI_INTA_IRQCHIP - select TI_K3_SOCINFO help This enables support for Texas Instruments' K3 multicore SoC architecture.drivers/soc/ti/Kconfig +0
-0@@ -74,7 +74,8 @@ config TI_K3_RINGACC If unsure, say N.
Quoted 8 lines
drivers/soc/ti/Kconfig config TI_K3_RINGACC · line 78
Quoted 4 lines
drivers/soc/ti/Kconfig +2
-1config TI_K3_SOCINFO - bool + tristate "TI K3 SoC info driver" + default yMaybe
defaultARCH_K3
?
You're correct this should be defaulted to ARCH_K3.
This series will be dropped as it introduces dependency issues with consumer drivers.
Quoted 8 lines
drivers/soc/ti/Kconfig config TI_K3_RINGACC · line 81
Quoted 4 lines
drivers/soc/ti/Kconfig +0
-0depends on ARCH_K3 || COMPILE_TEST select SOC_BUS select MFD_SYSCON--
~Randy
Thanks,
Nicolas
Re: [PATCH v4 2/4] soc: ti: Add module build support
In reply to Nicolas FrayerQuoted 1 line · Nicolas Frayer
Added module build support for the TI K3 SoC info driver.
Subject: "soc: ti: k3-socinfo: ..."
Quoted 25 lines
Signed-off-by Nicolas Frayer <[email protected]>--- arch/arm64/Kconfig.platforms | 1 - drivers/soc/ti/Kconfig | 3 ++- drivers/soc/ti/k3-socinfo.c | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-)arch/arm64/Kconfig.platforms +0
-1@@ -130,7 +130,6 @@ config ARCH_K3 select TI_SCI_PROTOCOL select TI_SCI_INTR_IRQCHIP select TI_SCI_INTA_IRQCHIP - select TI_K3_SOCINFO help This enables support for Texas Instruments' K3 multicore SoC architecture.drivers/soc/ti/Kconfig +0
-0
drivers/soc/ti/Kconfig config TI_K3_RINGACC · line 78
Quoted 6 lines
drivers/soc/ti/Kconfig +2
-1@@ -74,7 +74,8 @@ config TI_K3_RINGACC If unsure, say N. config TI_K3_SOCINFO - bool + tristate "TI K3 SoC info driver" + default y
Why it is a good thing to have this driver as module compared to always built in? It has no dependencies, just things depending on it.
It is small, just couple of lines long
I don't really see the benefit of building it as a module, not even an academic one...
Quoted 24 lines
drivers/soc/ti/Kconfig +0
-0depends on ARCH_K3 || COMPILE_TEST select SOC_BUS select MFD_SYSCONdrivers/soc/ti/k3-socinfo.c +2
-0@@ -13,6 +13,7 @@#include <linux/slab.h> #include <linux/string.h> #include <linux/sys_soc.h> +#include <linux/module.h> #define CTRLMMR_WKUP_JTAGID_REG 0/* @@ -141,6 +142,7 @@ static const struct of_device_id k3_chipinfo_of_match[] = { { .compatible = "ti,am654-chipid", }, { /* sentinel */ }, }; +MODULE_DEVICE_TABLE (of, k3_chipinfo_of_match);static struct platform_driver k3_chipinfo_driver = { .driver = {
drivers/soc/ti/k3-socinfo.c static int __init k3_chipinfo_init(void) · line 160
Quoted 3 lines
drivers/soc/ti/k3-socinfo.c +0
-0@@ -156,3 +158,12 @@ static int __init k3_chipinfo_init(void)return platform_driver_register (&k3_chipinfo_driver); }subsys_initcall (k3_chipinfo_init);
subsys_initcall for a module?
Quoted 9 lines
drivers/soc/ti/k3-socinfo.c +9
-0+ +static void __exit k3_chipinfo_exit(void) +{ +platform_driver_unregister (&k3_chipinfo_driver); +} +module_exit (k3_chipinfo_exit); + +MODULE_DESCRIPTION ("TI K3 SoC info driver" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
Péter
Re: [PATCH v4 2/4] soc: ti: Add module build support
Le jeu. 24 nov. 2022 à 08:53, Péter Ujfalusi
<[email protected]> a écrit :
Hi Peter,
Quoted 45 lines · Nicolas Frayer
Quoted 1 line
Added module build support for the TI K3 SoC info driver.
Subject: "soc: ti: k3-socinfo: ..."
Quoted 25 lines
Signed-off-by Nicolas Frayer <[email protected]>--- arch/arm64/Kconfig.platforms | 1 - drivers/soc/ti/Kconfig | 3 ++- drivers/soc/ti/k3-socinfo.c | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-)arch/arm64/Kconfig.platforms +0
-1@@ -130,7 +130,6 @@ config ARCH_K3 select TI_SCI_PROTOCOL select TI_SCI_INTR_IRQCHIP select TI_SCI_INTA_IRQCHIP - select TI_K3_SOCINFO help This enables support for Texas Instruments' K3 multicore SoC architecture.drivers/soc/ti/Kconfig +0
-0drivers/soc/ti/Kconfig config TI_K3_RINGACC · line 78
Quoted 6 lines
drivers/soc/ti/Kconfig +2
-1@@ -74,7 +74,8 @@ config TI_K3_RINGACC If unsure, say N. config TI_K3_SOCINFO - bool + tristate "TI K3 SoC info driver" + default yWhy it is a good thing to have this driver as module compared to always built in?
It has no dependencies, just things depending on it.
It is small, just couple of lines long
Quoted 3 lines
I don't really see the benefit of building it as a module, not even an academic one...
Just to give an update, this series will be dropped as it introduces dependency issues
with consumer drivers.
The reason why I've enabled the module build support is because it is required to build
vendor drivers as modules for Android GKI feature.
Quoted 22 lines
Quoted 22 lines
drivers/soc/ti/Kconfig +0
-0depends on ARCH_K3 || COMPILE_TEST select SOC_BUS select MFD_SYSCONdrivers/soc/ti/k3-socinfo.c +2
-0@@ -13,6 +13,7 @@#include <linux/slab.h> #include <linux/string.h> #include <linux/sys_soc.h> +#include <linux/module.h> #define CTRLMMR_WKUP_JTAGID_REG 0/* @@ -141,6 +142,7 @@ static const struct of_device_id k3_chipinfo_of_match[] = { { .compatible = "ti,am654-chipid", }, { /* sentinel */ }, }; +MODULE_DEVICE_TABLE (of, k3_chipinfo_of_match);
Quoted 8 lines
drivers/soc/ti/k3-socinfo.c static int __init k3_chipinfo_init(void) · line 160
Quoted 6 lines
drivers/soc/ti/k3-socinfo.c +0
-0static struct platform_driver k3_chipinfo_driver = { .driver = {@@ -156,3 +158,12 @@ static int __init k3_chipinfo_init(void)return platform_driver_register (&k3_chipinfo_driver); }subsys_initcall (k3_chipinfo_init);
subsys_initcallfor a module?
By including module.h, the subsys_initcall() is redefined as module_init() when built
as a module. When built-in, it is redefined as the usual __initcall.
Quoted 13 lines
drivers/soc/ti/k3-socinfo.c static int __init k3_chipinfo_init(void) · line 169
Quoted 10 lines
drivers/soc/ti/k3-socinfo.c +9
-0+ +static void __exit k3_chipinfo_exit(void) +{ +platform_driver_unregister (&k3_chipinfo_driver); +} +module_exit (k3_chipinfo_exit); + +MODULE_DESCRIPTION ("TI K3 SoC info driver" ); +MODULE_LICENSE ("GPL" );--
Péter
PATCH v4 3/4 dmaengine: ti: k3-udma: Deferring probe when soc_device_match() returns NULL
In reply to Nicolas FrayerWhen the k3 socinfo driver is built as a module, there is a possibility that it will probe after the k3 udma driver and the later returns -ENODEV. By deferring the k3 udma probe we allow the k3 socinfo to probe and register the soc_device_attribute structure needed by the k3 udma driver.
--- drivers/dma/ti/k3-udma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/ti/k3-udma.c +1 -1
@@ -5285,7 +5285,7 @@ static int udma_probe(struct platform_device *pdev) soc =soc_device_match (k3_soc_devices);if (!soc) {dev_err (dev,"No compatible SoC found\n" ); -return -ENODEV ; +return -EPROBE_DEFER ; } ud->soc_data = soc->data;
Signature · 1 line
2.25.1
PATCH v4 4/4 net: ethernet: ti: davinci_mdio: Deferring probe when soc_device_match() returns NULL
In reply to Nicolas FrayerWhen the k3 socinfo driver is built as a module, there is a possibility that it will probe after the davinci mdio driver. By deferring the mdio probe we allow the k3 socinfo to probe and register the soc_device_attribute structure needed by the mdio driver.
--- drivers/net/ethernet/ti/davinci_mdio.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/ti/davinci_mdio.c +4 -0
@@ -533,6 +533,10 @@ static int davinci_mdio_probe(struct platform_device *pdev)const struct soc_device_attribute *soc_match_data; soc_match_data =soc_device_match (k3_mdio_socinfo); + +if (!soc_match_data) +return -EPROBE_DEFER ; +if (soc_match_data && soc_match_data->data) {const struct k3_mdio_soc_data *socdata = soc_match_data->data;
Signature · 1 line
2.25.1
Paolo Abeni
maintainerRe: [PATCH v4 4/4] net: ethernet: ti: davinci_mdio: Deferring probe when soc_device_match() returns NULL
Hello,
Quoted 6 lines · Nicolas Frayer
When the k3 socinfo driver is built as a module, there is a possibility that it will probe after the davinci mdio driver. By deferring the mdio probe we allow the k3 socinfo to probe and register the
soc_device_attributestructure needed by the mdio driver.Signed-off-by Nicolas Frayer <[email protected]>
I guess this one will go via the arm tree, right?
I'm dropping it from the netdev PW.
Thanks,
Paolo
Re: [PATCH v4 4/4] net: ethernet: ti: davinci_mdio: Deferring probe when soc_device_match() returns NULL
Quoted 11 lines · Paolo Abeni
Hello,
Quoted 6 lines · Nicolas Frayer
When the k3 socinfo driver is built as a module, there is a possibility that it will probe after the davinci mdio driver. By deferring the mdio probe we allow the k3 socinfo to probe and register the
soc_device_attributestructure needed by the mdio driver.Signed-off-by Nicolas Frayer <[email protected]>
Quoted 8 lines
I guess this one will go via the arm tree, right?
I'm dropping it from the netdev PW.
Thanks,
Paolo
Hello Paolo,
I will resend this series as individual patches, so can you please apply this mdio patch individually as it's independent from the others ?
Thanks,
Nicolas
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Vignesh Raghavendra
maintainerRe: [PATCH v4 4/4] net: ethernet: ti: davinci_mdio: Deferring probe when soc_device_match() returns NULL
In reply to Nicolas FrayerHi Nicolas,
Quoted 15 lines · Nicolas Frayer
When the k3 socinfo driver is built as a module, there is a possibility that it will probe after the davinci mdio driver. By deferring the mdio probe we allow the k3 socinfo to probe and register the
soc_device_attributestructure needed by the mdio driver.Signed-off-by Nicolas Frayer <[email protected]>--- drivers/net/ethernet/ti/davinci_mdio.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/net/ethernet/ti/davinci_mdio.c +0
-0
drivers/net/ethernet/ti/davinci_mdio.c static int davinci_mdio_probe(struct platform_device *pdev) · line 538
Quoted 6 lines
drivers/net/ethernet/ti/davinci_mdio.c +3
-0@@ -533,6 +533,10 @@ static int davinci_mdio_probe(struct platform_device *pdev)const struct soc_device_attribute *soc_match_data; soc_match_data =soc_device_match (k3_mdio_socinfo); + +if (!soc_match_data) +return -EPROBE_DEFER ;
I dont think this is right way to detect if socinfo driver is probed. Per documentation of soc_device_match() , function will return NULL if it does not match any of the entries in k3_mdio_socinfo (ie if we are running on any platforms other that ones in the list)
Note that this driver is used on TI's 32 bit SoCs too that dont even have a k3-socinfo driver equivalent. In such case, this code will end up probe deferring indefinitely.
Quoted 4 lines
drivers/net/ethernet/ti/davinci_mdio.c +1
-0+if (soc_match_data && soc_match_data->data) {const struct k3_mdio_soc_data *socdata = soc_match_data->data;
Re: [PATCH v4 4/4] net: ethernet: ti: davinci_mdio: Deferring probe when soc_device_match() returns NULL
Hi Vignesh,
Quoted 30 lines · Vignesh Raghavendra
Hi Nicolas,
Quoted 15 lines · Nicolas Frayer
When the k3 socinfo driver is built as a module, there is a possibility that it will probe after the davinci mdio driver. By deferring the mdio probe we allow the k3 socinfo to probe and register the
soc_device_attributestructure needed by the mdio driver.Signed-off-by Nicolas Frayer <[email protected]>--- drivers/net/ethernet/ti/davinci_mdio.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/net/ethernet/ti/davinci_mdio.c +0
-0drivers/net/ethernet/ti/davinci_mdio.c static int davinci_mdio_probe(struct platform_device *pdev) · line 538
Quoted 6 lines
drivers/net/ethernet/ti/davinci_mdio.c +3
-0@@ -533,6 +533,10 @@ static int davinci_mdio_probe(struct platform_device *pdev)const struct soc_device_attribute *soc_match_data; soc_match_data =soc_device_match (k3_mdio_socinfo); + +if (!soc_match_data) +return -EPROBE_DEFER ;I dont think this is right way to detect if socinfo driver is probed. Per documentation of
soc_device_match(), function will return NULL if it does not match any of the entries ink3_mdio_socinfo(ie if we are running on any platforms other that ones in the list)
Quoted 3 lines
Note that this driver is used on TI's 32 bit SoCs too that dont even have a k3-socinfo driver equivalent. In such case, this code will end up probe deferring indefinitely.
Yes, you're right. This is not the right solution and this patch should be dropped. We'll need to have a deeper look at socinfo to figure out if/how it could be configured to support a fully modular kernel.
Kevin