2024-04-25 00:27:29

by Florian Fainelli

[permalink] [raw]
Subject: [PATCH v2 1/4] i2c: designware: Create shared header hosting driver name

We have a number of drivers that reference the string "i2c_designware"
towards two goals:

- ensure their device gets bound to the i2c_designware platform_driver
- create a clock lookup reference that matches the i2c_designware
instance number for the i2c-designware-platdrv.c driver to be able to
lookup the input reference clock

Since this string is copied in a bunch of different places and since it
is possible to get this named wrong (see [1] and [2]) with unintended
consequences, create a header file that hosts that define for other
drivers to use and all agree on the correct name to use.

[1]:
https://lore.kernel.org/all/[email protected]/
[2]:
https://lore.kernel.org/all/[email protected]/

Signed-off-by: Florian Fainelli <[email protected]>
---
MAINTAINERS | 1 +
drivers/i2c/busses/i2c-designware-pcidrv.c | 3 ++-
drivers/i2c/busses/i2c-designware-platdrv.c | 5 +++--
include/linux/platform_data/i2c-designware.h | 11 +++++++++++
4 files changed, 17 insertions(+), 3 deletions(-)
create mode 100644 include/linux/platform_data/i2c-designware.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 2d5acd6d98c4..da1b39df2b94 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -21438,6 +21438,7 @@ R: Jan Dabros <[email protected]>
L: [email protected]
S: Supported
F: drivers/i2c/busses/i2c-designware-*
+F: include/linux/platform_data/i2c-designware.h

SYNOPSYS DESIGNWARE MMC/SD/SDIO DRIVER
M: Jaehoon Chung <[email protected]>
diff --git a/drivers/i2c/busses/i2c-designware-pcidrv.c b/drivers/i2c/busses/i2c-designware-pcidrv.c
index 9be9a2658e1f..32d6f338a1ea 100644
--- a/drivers/i2c/busses/i2c-designware-pcidrv.c
+++ b/drivers/i2c/busses/i2c-designware-pcidrv.c
@@ -19,6 +19,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pci.h>
+#include <linux/platform_data/i2c-designware.h>
#include <linux/pm_runtime.h>
#include <linux/power_supply.h>
#include <linux/sched.h>
@@ -425,7 +426,7 @@ static struct pci_driver dw_i2c_driver = {
module_pci_driver(dw_i2c_driver);

/* Work with hotplug and coldplug */
-MODULE_ALIAS("i2c_designware-pci");
+MODULE_ALIAS(I2C_DESIGNWARE_NAME "-pci");
MODULE_AUTHOR("Baruch Siach <[email protected]>");
MODULE_DESCRIPTION("Synopsys DesignWare PCI I2C bus adapter");
MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index 4ab41ba39d55..8aa2bf274d78 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -22,6 +22,7 @@
#include <linux/mfd/syscon.h>
#include <linux/module.h>
#include <linux/of.h>
+#include <linux/platform_data/i2c-designware.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
#include <linux/pm_runtime.h>
@@ -480,13 +481,13 @@ static const struct dev_pm_ops dw_i2c_dev_pm_ops = {
};

/* Work with hotplug and coldplug */
-MODULE_ALIAS("platform:i2c_designware");
+MODULE_ALIAS("platform:" I2C_DESIGNWARE_NAME);

static struct platform_driver dw_i2c_driver = {
.probe = dw_i2c_plat_probe,
.remove_new = dw_i2c_plat_remove,
.driver = {
- .name = "i2c_designware",
+ .name = I2C_DESIGNWARE_NAME,
.of_match_table = of_match_ptr(dw_i2c_of_match),
.acpi_match_table = ACPI_PTR(dw_i2c_acpi_match),
.pm = pm_ptr(&dw_i2c_dev_pm_ops),
diff --git a/include/linux/platform_data/i2c-designware.h b/include/linux/platform_data/i2c-designware.h
new file mode 100644
index 000000000000..e385b6d70a04
--- /dev/null
+++ b/include/linux/platform_data/i2c-designware.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef __I2C_DESIGNWARE_PDATA_H__
+#define __I2C_DESIGNWARE_PDATA_H__
+
+/* This is the i2c-designware-platdrv.c platform driver name. This name is used
+ * to bind the device to the driver, as well as by the driver itself to request
+ * the input reference clock
+ */
+#define I2C_DESIGNWARE_NAME "i2c_designware"
+
+#endif /* __I2C_DESIGNWARE_PDATA_H__ */
--
2.34.1



2024-04-25 09:57:13

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 1/4] i2c: designware: Create shared header hosting driver name

On Wed, Apr 24, 2024 at 05:26:39PM -0700, Florian Fainelli wrote:
> We have a number of drivers that reference the string "i2c_designware"
> towards two goals:
>
> - ensure their device gets bound to the i2c_designware platform_driver
> - create a clock lookup reference that matches the i2c_designware
> instance number for the i2c-designware-platdrv.c driver to be able to
> lookup the input reference clock
>
> Since this string is copied in a bunch of different places and since it
> is possible to get this named wrong (see [1] and [2]) with unintended
> consequences, create a header file that hosts that define for other
> drivers to use and all agree on the correct name to use.

> [1]:
> https://lore.kernel.org/all/[email protected]/
> [2]:
> https://lore.kernel.org/all/[email protected]/

Make them tags.

Link: URL#1 [1]
Link: URL#2 [2]

> Signed-off-by: Florian Fainelli <[email protected]>

> +++ b/drivers/i2c/busses/i2c-designware-pcidrv.c
> @@ -19,6 +19,7 @@
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/pci.h>

> +#include <linux/platform_data/i2c-designware.h>

Please, make it a separate group after linux/* and before "xxx" below.

> #include <linux/pm_runtime.h>
> #include <linux/power_supply.h>
> #include <linux/sched.h>

..

> module_pci_driver(dw_i2c_driver);
>
> /* Work with hotplug and coldplug */
> -MODULE_ALIAS("i2c_designware-pci");
> +MODULE_ALIAS(I2C_DESIGNWARE_NAME "-pci");

As Jarkko said, please get rid of this.
You may take my patch from here:
https://lore.kernel.org/linux-i2c/[email protected]/
and incorporate in this series.

..

> #include <linux/mfd/syscon.h>
> #include <linux/module.h>
> #include <linux/of.h>
> +#include <linux/platform_data/i2c-designware.h>

As per above.

> #include <linux/platform_device.h>
> #include <linux/pm.h>
> #include <linux/pm_runtime.h>

..

> /* Work with hotplug and coldplug */
> -MODULE_ALIAS("platform:i2c_designware");
> +MODULE_ALIAS("platform:" I2C_DESIGNWARE_NAME);

See above.

..

> +/* This is the i2c-designware-platdrv.c platform driver name. This name is used
> + * to bind the device to the driver, as well as by the driver itself to request
> + * the input reference clock
> + */

/*
* Use correct multi-line comment style. This
* is not the net subsystem, we use traditional style.
*/

--
With Best Regards,
Andy Shevchenko