linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Corey Minyard <cminyard-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org>
To: minyard-HInyCGIudOg@public.gmane.org,
	Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] i2c: Add parameters to sysfs-added i2c devices
Date: Mon, 24 Nov 2014 07:43:23 -0600	[thread overview]
Message-ID: <547335FB.4020002@mvista.com> (raw)
In-Reply-To: <1415976117-27755-1-git-send-email-minyard-HInyCGIudOg@public.gmane.org>

Ping, I haven't heard anything on this.

-corey

On 11/14/2014 08:41 AM, minyard-HInyCGIudOg@public.gmane.org wrote:
> From: Corey Minyard <cminyard-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org>
>
> Some devices might need parameters to control their operation,
> add the ability to pass these parameters to the client.
>
> This also makes the parsing of sysfs-added I2C devices a little
> more flexible, allowing tabs and arbitrary numbers of spaces.
>
> Signed-off-by: Corey Minyard <cminyard-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org>
> ---
>  drivers/i2c/i2c-core.c | 46 ++++++++++++++++++++++++++++++++++------------
>  include/linux/i2c.h    |  3 +++
>  2 files changed, 37 insertions(+), 12 deletions(-)
>
> I'm adding an SMBus IPMI driver, and it needs to be able to have
> the IPMI bus address specified in case it's not the default.
>
> Also, this seems like it would be useful for other devices that
> need some sort of configuration.
>
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index f43b4e1..9a2ab13 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -781,7 +781,10 @@ static int i2c_device_pm_restore(struct device *dev)
>  
>  static void i2c_client_dev_release(struct device *dev)
>  {
> -	kfree(to_i2c_client(dev));
> +	struct i2c_client *client = to_i2c_client(dev);
> +
> +	kfree(client->parms);
> +	kfree(client);
>  }
>  
>  static ssize_t
> @@ -1059,6 +1062,13 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
>  	client->flags = info->flags;
>  	client->addr = info->addr;
>  	client->irq = info->irq;
> +	if (info->parms) {
> +		client->parms = kstrdup(info->parms, GFP_KERNEL);
> +		if (!client->parms) {
> +			dev_err(&adap->dev, "Out of memory allocating parms\n");
> +			goto out_err_silent;
> +		}
> +	}
>  
>  	strlcpy(client->name, info->type, sizeof(client->name));
>  
> @@ -1207,31 +1217,43 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
>  	struct i2c_adapter *adap = to_i2c_adapter(dev);
>  	struct i2c_board_info info;
>  	struct i2c_client *client;
> -	char *blank, end;
> +	char *pos, end;
>  	int res;
>  
>  	memset(&info, 0, sizeof(struct i2c_board_info));
>  
> -	blank = strchr(buf, ' ');
> -	if (!blank) {
> +	pos = strpbrk(buf, " \t");
> +	if (!pos) {
>  		dev_err(dev, "%s: Missing parameters\n", "new_device");
>  		return -EINVAL;
>  	}
> -	if (blank - buf > I2C_NAME_SIZE - 1) {
> +	if (pos - buf > I2C_NAME_SIZE - 1) {
>  		dev_err(dev, "%s: Invalid device name\n", "new_device");
>  		return -EINVAL;
>  	}
> -	memcpy(info.type, buf, blank - buf);
> +	memcpy(info.type, buf, pos - buf);
>  
> -	/* Parse remaining parameters, reject extra parameters */
> -	res = sscanf(++blank, "%hi%c", &info.addr, &end);
> -	if (res < 1) {
> +	while (isspace(*pos))
> +		pos++;
> +
> +	/* Parse address, saving remaining parameters. */
> +	res = sscanf(pos, "%hi%c", &info.addr, &end);
> +	if (res < 1 || !isspace(end)) {
>  		dev_err(dev, "%s: Can't parse I2C address\n", "new_device");
>  		return -EINVAL;
>  	}
> -	if (res > 1  && end != '\n') {
> -		dev_err(dev, "%s: Extra parameters\n", "new_device");
> -		return -EINVAL;
> +	if (res > 1 && end != '\n') {
> +		if (isspace(end)) {
> +			/* Extra parms, skip the address and space. */
> +			while (!isspace(*pos))
> +				pos++;
> +			while (isspace(*pos))
> +				pos++;
> +			info.parms = pos;
> +		} else {
> +			dev_err(dev, "%s: Extra parameters\n", "new_device");
> +			return -EINVAL;
> +		}
>  	}
>  
>  	client = i2c_new_device(adap, &info);
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index b556e0a..e40fc56 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -222,6 +222,7 @@ struct i2c_client {
>  	char name[I2C_NAME_SIZE];
>  	struct i2c_adapter *adapter;	/* the adapter we sit on	*/
>  	struct device dev;		/* the device structure		*/
> +	char *parms;			/* sysfs extra parms		*/
>  	int irq;			/* irq issued by device		*/
>  	struct list_head detected;
>  };
> @@ -255,6 +256,7 @@ static inline void i2c_set_clientdata(struct i2c_client *dev, void *data)
>   * @archdata: copied into i2c_client.dev.archdata
>   * @of_node: pointer to OpenFirmware device node
>   * @acpi_node: ACPI device node
> + * @parms: Parameters supplied on the sysfs command line
>   * @irq: stored in i2c_client.irq
>   *
>   * I2C doesn't actually support hardware probing, although controllers and
> @@ -276,6 +278,7 @@ struct i2c_board_info {
>  	struct dev_archdata	*archdata;
>  	struct device_node *of_node;
>  	struct acpi_dev_node acpi_node;
> +	char            *parms;
>  	int		irq;
>  };
>  

  parent reply	other threads:[~2014-11-24 13:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-14 14:41 [PATCH] i2c: Add parameters to sysfs-added i2c devices minyard-HInyCGIudOg
     [not found] ` <1415976117-27755-1-git-send-email-minyard-HInyCGIudOg@public.gmane.org>
2014-11-24 13:43   ` Corey Minyard [this message]
2014-12-01 17:38     ` Wolfram Sang
2014-12-02 13:06       ` Corey Minyard

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=547335FB.4020002@mvista.com \
    --to=cminyard-igf4poytycdqt0dzr+alfa@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=minyard-HInyCGIudOg@public.gmane.org \
    --cc=wsa-z923LK4zBo2bacvFa/9K2g@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).