linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
To: Wolfram Sang <wsa@the-dreams.de>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	Michal Marek <michal.lkml@markovi.net>,
	linux-kbuild@vger.kernel.org,
	linux-kernel@vger.kernel.org (open list)
Cc: linux-renesas-soc@vger.kernel.org,
	Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>,
	Lee Jones <lee.jones@linaro.org>,
	Javier Martinez Canillas <javierm@redhat.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Mark Brown <broonie@kernel.org>
Subject: [PATCH RFC] modpost: Support I2C Aliases from OF tables
Date: Wed, 10 Jul 2019 20:39:06 +0100	[thread overview]
Message-ID: <20190710193918.31135-1-kieran.bingham+renesas@ideasonboard.com> (raw)

I2C drivers match against an I2C ID table, an OF table, and an ACPI
table. It is now also possible to match against an OF table entry
without the vendor prefix to support backwards compatibility, and allow
simplification of the i2c probe functions.

As part of this matching, the probe function is being converted to
remove the need to specify the i2c_device_id table, but to support
module aliasing, we still require to have the MODULE_DEVICE_TABLE entry.

Facilitate generating the I2C aliases directly from the of_device_id
tables, by stripping the vendor prefix prefix from the compatible string
and using that as an alias just as the i2c-core supports.

Drivers which remove the i2c_device_id table can then register against
the of_device_id table by adding an extra MODULE_DEVICE_TABLE
registration as shown by the following example:

 /* si4713_i2c_driver - i2c driver interface */
-static const struct i2c_device_id si4713_id[] = {
-       { "si4713" , 0 },
-       { },
-};
-MODULE_DEVICE_TABLE(i2c, si4713_id);

 static const struct of_device_id si4713_of_match[] = {
        { .compatible = "silabs,si4713" },
        { },
 };
 MODULE_DEVICE_TABLE(of, si4713_of_match);
+MODULE_DEVICE_TABLE(i2c_of, si4713_of_match);

Several drivers have had their i2c_device_id tables removed entirely
which will lead to their module aliases being limited, during the
following patches:

0f21700ac40c ("rtc: pcf85063: switch to probe_new")
3a4f4f2963f4 ("ASoC: rt5677: Convert I2C driver to ->probe_new()")
511cb17448d9 ("mfd: tps65217: Introduce dependency on CONFIG_OF")
8597c0920d6f ("NFC: fdp: Convert I2C driver to ->probe_new()")
b8a1a4cd5a98 ("i2c: Provide a temporary .probe_new() call-back type")

The following patches might require I2C aliases to be generated from
their ACPI tables:

e19c92059a70 ("media: staging: atomisp: Switch i2c drivers to use ->probe_new()")
f758eb2363ec ("media: dw9714: Remove ACPI match tables, convert to use probe_new")

Cc: Lee Jones <lee.jones@linaro.org>
Cc: Wolfram Sang <wsa@the-dreams.de>
Cc: Javier Martinez Canillas <javierm@redhat.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Mark Brown <broonie@kernel.org>

Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
---
 scripts/mod/file2alias.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index e17a29ae2e97..16776f624d3a 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -379,6 +379,35 @@ static void do_of_table(void *symval, unsigned long size,
 		do_of_entry_multi(symval + i, mod);
 }
 
+static int do_i2c_of_entry(void *symval, struct module *mod)
+{
+	const char *alias;
+	DEF_FIELD_ADDR(symval, of_device_id, compatible);
+
+	alias = strrchr(*compatible, ',');
+
+	buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"%s%s\");\n",
+		   I2C_MODULE_PREFIX, alias ? alias + 1 : *compatible);
+
+	return 1;
+}
+
+/* Reuse OF tables to generate I2C aliases */
+static void do_i2c_of_table(void *symval, unsigned long size,
+			    struct module *mod)
+{
+	unsigned int i;
+	const unsigned long id_size = SIZE_of_device_id;
+
+	device_id_check(mod->name, "i2c_of", size, id_size, symval);
+
+	/* Leave last one: it's the terminator. */
+	size -= id_size;
+
+	for (i = 0; i < size; i += id_size)
+		do_i2c_of_entry(symval + i, mod);
+}
+
 /* Looks like: hid:bNvNpN */
 static int do_hid_entry(const char *filename,
 			     void *symval, char *alias)
@@ -1452,6 +1481,8 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
 		do_usb_table(symval, sym->st_size, mod);
 	if (sym_is(name, namelen, "of"))
 		do_of_table(symval, sym->st_size, mod);
+	else if (sym_is(name, namelen, "i2c_of"))
+		do_i2c_of_table(symval, sym->st_size, mod);
 	else if (sym_is(name, namelen, "pnp"))
 		do_pnp_device_entry(symval, sym->st_size, mod);
 	else if (sym_is(name, namelen, "pnp_card"))
-- 
2.20.1


             reply	other threads:[~2019-07-10 19:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-10 19:39 Kieran Bingham [this message]
2019-07-22 13:03 ` Javier Martinez Canillas
2019-07-31 19:44   ` Wolfram Sang
2019-08-01  2:17     ` Masahiro Yamada
2019-08-05 22:48       ` Javier Martinez Canillas
2019-08-06  7:30         ` Geert Uytterhoeven
2019-08-06 17:39           ` Javier Martinez Canillas
2019-08-05 22:25     ` Javier Martinez Canillas
2019-08-06  7:22       ` Geert Uytterhoeven
2019-08-06 17:12         ` Javier Martinez Canillas
2019-08-08 13:12           ` Enrico Weigelt, metux IT consult
2019-08-08 13:24             ` Andy Shevchenko
2019-08-08 14:00               ` Enrico Weigelt, metux IT consult

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190710193918.31135-1-kieran.bingham+renesas@ideasonboard.com \
    --to=kieran.bingham+renesas@ideasonboard.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=broonie@kernel.org \
    --cc=javierm@redhat.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=michal.lkml@markovi.net \
    --cc=wsa@the-dreams.de \
    --cc=yamada.masahiro@socionext.com \
    --subject='Re: [PATCH RFC] modpost: Support I2C Aliases from OF tables' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).