linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Holler <holler-SXC+2es9fhnfWeYVQQPykw@public.gmane.org>
To: "till-RcHadlBFbzVAfugRpC6u6w@public.gmane.org"
	<till-RcHadlBFbzVAfugRpC6u6w@public.gmane.org>
Cc: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 1/2] i2c: Add possibility for user-defined (i2c-)devices for bus-drivers.
Date: Mon, 19 Nov 2012 14:38:04 +0100	[thread overview]
Message-ID: <20121119133802.GA5030@krabat.ahsoftware> (raw)
In-Reply-To: <1352920954.19432.2.camel@Nokia-N900>

Hello,

after the needed break in the discussion (to calm down), I've decided to make a last try. I don't want to make a thesis about USB RTCs, nor do I want to write a whole new driver (and afterwards trying to get such into the kernel, not to speak about the then necessary explicit device/vendor ID).

On Wed, Nov 14, 2012 at 08:22:34PM +0100, till-RcHadlBFbzVAfugRpC6u6w@public.gmane.org wrote:

> i have seen i2c chips going nuts because some probing actually affected the chips state. So i fully agree with Jean here.

I've now changed the device registration from using i2c_new_probed_device() to i2c_new_device(),
even if that would register non-existent RTCs.

> I2C just isn't meant to be used for hot plugging. And so isn't the i2c-tiny-usb. It's more a hacking and testing device and is e.g. very convenient to test i2c client drivers or to test some new i2c hardware. But i have never had a need for this before user land was available. And once it is you can really do any magic you want using e.g. udev and sysfs.

As you've written yourself, i2c-tiny-usb is more a hacking and testing device, so there's hopefully no real argument left against including the few lines to enable devices through module options or the kernel command line. Someone could like to test such too with the "hacking and testing device".

Regards,

Alexander


>From 1aa6bbd0a87ce39f9889f835d12127226ffa9403 Mon Sep 17 00:00:00 2001
From: Alexander Holler <holler-SXC+2es9fhnfWeYVQQPykw@public.gmane.org>
Date: Tue, 13 Nov 2012 16:28:07 +0100
Subject: [PATCH] i2c: i2c-tiny-usb: Add parameter for optional i2c-devices.

Make it possible to define i2c-devices at the kernel command line
or as a module parameter.

Format is devname1@addr1,devname2@addr2,...

Example for the kernel command line:

   i2c-tiny-usb.devices=ds1307@0x68,pcf8563@0x51

The definition of up to 8 devices is allowed.

Cc: Till Harbaum <till-RcHadlBFbzVAfugRpC6u6w@public.gmane.org>
Signed-off-by: Alexander Holler <holler-SXC+2es9fhnfWeYVQQPykw@public.gmane.org>
---
 drivers/i2c/busses/i2c-tiny-usb.c |   44 +++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c
index 0510636..a3fc711 100644
--- a/drivers/i2c/busses/i2c-tiny-usb.c
+++ b/drivers/i2c/busses/i2c-tiny-usb.c
@@ -40,6 +40,11 @@ module_param(delay, ushort, 0);
 MODULE_PARM_DESC(delay, "bit delay in microseconds "
 		 "(default is 10us for 100kHz max)");
 
+#define MAX_OPTIONAL_I2C_DEVICES 8
+static char *opt_devices[MAX_OPTIONAL_I2C_DEVICES];
+module_param_array_named(devices, opt_devices, charp, NULL, 0);
+MODULE_PARM_DESC(devices, "devname1@adr1,devname2@adr2,... (e.g. ds1307@0x68)");
+
 static int usb_read(struct i2c_adapter *adapter, int cmd,
 		    int value, int index, void *data, int len);
 
@@ -184,6 +189,42 @@ static void i2c_tiny_usb_free(struct i2c_tiny_usb *dev)
 	kfree(dev);
 }
 
+static void i2c_add_optional_devices(struct i2c_adapter *adapter)
+{
+	int i;
+	struct i2c_board_info i2c_info;
+	uint addr;
+	const char *at;
+
+	for (i = 0; opt_devices[i]; ++i) {
+		at = strchr(opt_devices[i], '@');
+		if (at++ == NULL) {
+			dev_warn(&adapter->dev,
+				"address needed in device definition '%s'\n",
+				opt_devices[i]);
+			continue;
+		}
+		if (kstrtouint(at, 0, &addr) || addr >= I2C_CLIENT_END) {
+			dev_warn(&adapter->dev,
+				"wrong address in device definition '%s'\n",
+				opt_devices[i]);
+			continue;
+		}
+		memset(&i2c_info, 0, sizeof(struct i2c_board_info));
+		strlcpy(i2c_info.type, opt_devices[i],
+			min(I2C_NAME_SIZE, (int)(at-opt_devices[i])));
+		i2c_info.addr = addr;
+		if (i2c_new_device(adapter, &i2c_info) != NULL)
+			dev_info(&adapter->dev,
+				"device %s at address 0x%02x registered\n",
+				i2c_info.type, addr);
+		else
+			dev_warn(&adapter->dev,
+				"device %s at address 0x%02x not found\n",
+				i2c_info.type, addr);
+	}
+}
+
 static int i2c_tiny_usb_probe(struct usb_interface *interface,
 			      const struct usb_device_id *id)
 {
@@ -236,6 +277,9 @@ static int i2c_tiny_usb_probe(struct usb_interface *interface,
 	/* inform user about successful attachment to i2c layer */
 	dev_info(&dev->adapter.dev, "connected i2c-tiny-usb device\n");
 
+	/* add optional devices */
+	i2c_add_optional_devices(&dev->adapter);
+
 	return 0;
 
  error:
-- 
1.7.8.6

  parent reply	other threads:[~2012-11-19 13:38 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-13 18:06 [PATCH 1/2] i2c: Add possibility for user-defined (i2c-)devices for bus-drivers Alexander Holler
2012-11-13 18:06 ` [PATCH 2/2] i2c: i2c-tiny-usb: Add parameter for optional user-defined devices Alexander Holler
     [not found] ` <1352829968-4908-1-git-send-email-holler-SXC+2es9fhnfWeYVQQPykw@public.gmane.org>
2012-11-13 18:55   ` [PATCH 1/2] i2c: Add possibility for user-defined (i2c-)devices for bus-drivers Jean Delvare
     [not found]     ` <20121113195533.6db71716-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-11-13 20:23       ` Alexander Holler
2012-11-13 20:52         ` [PATCH] i2c: i2c-tiny-usb: Add parameter for optional i2c-devices Alexander Holler
     [not found]           ` <1352839940-7559-1-git-send-email-holler-SXC+2es9fhnfWeYVQQPykw@public.gmane.org>
2012-11-13 22:42             ` Alan Cox
     [not found]               ` <20121113224251.20b52f34-38n7/U1jhRXW96NNrWNlrekiAK3p4hvP@public.gmane.org>
2012-11-13 23:41                 ` Alexander Holler
     [not found]         ` <50A2AC28.7050304-SXC+2es9fhnfWeYVQQPykw@public.gmane.org>
2012-11-13 21:08           ` [PATCH 1/2] i2c: Add possibility for user-defined (i2c-)devices for bus-drivers Jean Delvare
     [not found]             ` <20121113220835.111a178a-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-11-13 21:24               ` Alexander Holler
     [not found]                 ` <50A2BAA2.6090009-SXC+2es9fhnfWeYVQQPykw@public.gmane.org>
2012-11-13 21:42                   ` Jean Delvare
2012-11-13 23:38                     ` Alexander Holler
     [not found]                       ` <50A2DA0C.3090507-SXC+2es9fhnfWeYVQQPykw@public.gmane.org>
2012-11-14  9:40                         ` Jean Delvare
     [not found]                           ` <20121114104050.79df8cd9-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-11-14 12:38                             ` Alexander Holler
     [not found]                               ` <50A390CC.9000208-SXC+2es9fhnfWeYVQQPykw@public.gmane.org>
2012-11-14 19:22                                 ` till-RcHadlBFbzVAfugRpC6u6w
2012-11-14 23:34                                   ` Alexander Holler
     [not found]                                     ` <1639554.ZUOmHr6Yka@lxtiha>
2012-11-15 11:44                                       ` Alexander Holler
2012-11-19 13:38                                   ` Alexander Holler [this message]
2012-11-23 14:35                             ` Alexander Holler
2012-11-14  2:47                     ` Alexander Holler
     [not found]                       ` <50A30652.1020208-SXC+2es9fhnfWeYVQQPykw@public.gmane.org>
2012-11-14  9:08                         ` Alexander Holler

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=20121119133802.GA5030@krabat.ahsoftware \
    --to=holler-sxc+2es9fhnfweyvqqpykw@public.gmane.org \
    --cc=khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=till-RcHadlBFbzVAfugRpC6u6w@public.gmane.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).