mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: "Eric Bénard" <eric@eukrea.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 2/3] i2c: add i2cdev driver
Date: Wed, 19 May 2010 13:01:24 +0200	[thread overview]
Message-ID: <20100519110124.GM31199@pengutronix.de> (raw)
In-Reply-To: <1274174808-9516-2-git-send-email-eric@eukrea.com>

On Tue, May 18, 2010 at 11:26:47AM +0200, Eric Bénard wrote:
> this driver is needed to introduce i2c commands

This approach limits the i2cdev support to exactly one bus which is not
good. What we can do here is:

- collect all available adapters in a list in drivers/i2c/i2c.c
- implement i2c_get_adapter(int busnum) to get an adapter from its
  busnum
- then you can add a -b busnum argument to the i2c_read/i2c_write commands
  and use i2c_get_adapter() there. You don't need this file anymore then.

Sascha

> 
> Signed-off-by: Eric Bénard <eric@eukrea.com>
> ---
>  drivers/i2c/Kconfig  |    3 ++
>  drivers/i2c/Makefile |    1 +
>  drivers/i2c/i2cdev.c |   83 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 87 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/i2c/i2cdev.c
> 
> diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
> index f1b2949..cbd2464 100644
> --- a/drivers/i2c/Kconfig
> +++ b/drivers/i2c/Kconfig
> @@ -16,4 +16,7 @@ config DRIVER_I2C_MC9SDZ60
>  config DRIVER_I2C_LP3972
>  	bool "LP3972 driver"
>  
> +config DRIVER_I2C_I2CDEV
> +	bool "I2CDEV driver"
> +
>  endif
> diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
> index 62d030b..a193f9c 100644
> --- a/drivers/i2c/Makefile
> +++ b/drivers/i2c/Makefile
> @@ -5,3 +5,4 @@ obj-$(CONFIG_DRIVER_I2C_IMX) += i2c-imx.o
>  obj-$(CONFIG_DRIVER_I2C_MC13892) += mc13892.o
>  obj-$(CONFIG_DRIVER_I2C_MC9SDZ60) += mc9sdz60.o
>  obj-$(CONFIG_DRIVER_I2C_LP3972) += lp3972.o
> +obj-$(CONFIG_DRIVER_I2C_I2CDEV) += i2cdev.o
> diff --git a/drivers/i2c/i2cdev.c b/drivers/i2c/i2cdev.c
> new file mode 100644
> index 0000000..194db6c
> --- /dev/null
> +++ b/drivers/i2c/i2cdev.c
> @@ -0,0 +1,83 @@
> +/*
> + * Copyright (C) 2007 Sascha Hauer, Pengutronix
> + *               2009 Marc Kleine-Budde <mkl@pengutronix.de>
> + *               2009 Eric Benard <eric@eukrea.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + *
> + */
> +
> +#include <common.h>
> +#include <init.h>
> +#include <driver.h>
> +#include <xfuncs.h>
> +#include <errno.h>
> +
> +#include <i2c/i2c.h>
> +
> +#include <asm/byteorder.h>
> +
> +#define DRIVERNAME		"i2cdev"
> +
> +struct i2cdev_priv {
> +	struct cdev		cdev;
> +	struct i2c_client	*client;
> +};
> +
> +#define to_i2cdev_priv(a)	container_of(a, struct i2cdev_priv, cdev)
> +
> +static struct i2cdev_priv *i2cdev_dev;
> +
> +struct i2c_client *i2cdev_get_client(void)
> +{
> +	if (!i2cdev_dev)
> +		return NULL;
> +
> +	return i2cdev_dev->client;
> +}
> +
> +static struct file_operations i2cdev_fops = {
> +};
> +
> +static int i2cdev_probe(struct device_d *dev)
> +{
> +	if (i2cdev_dev)
> +		return -EBUSY;
> +
> +	i2cdev_dev = xzalloc(sizeof(struct i2cdev_priv));
> +	i2cdev_dev->cdev.name = DRIVERNAME;
> +	i2cdev_dev->client = to_i2c_client(dev);
> +	i2cdev_dev->cdev.size = 256;
> +	i2cdev_dev->cdev.dev = dev;
> +	i2cdev_dev->cdev.ops = &i2cdev_fops;
> +
> +	devfs_create(&i2cdev_dev->cdev);
> +
> +	return 0;
> +}
> +
> +static struct driver_d i2cdev_driver = {
> +	.name  = DRIVERNAME,
> +	.probe = i2cdev_probe,
> +};
> +
> +static int i2cdev_init(void)
> +{
> +	register_driver(&i2cdev_driver);
> +	return 0;
> +}
> +
> +device_initcall(i2cdev_init);
> -- 
> 1.6.3.3
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2010-05-19 11:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-18  9:26 [PATCH 1/3] i2c-imx: change log level for No ACK Eric Bénard
2010-05-18  9:26 ` [PATCH 2/3] i2c: add i2cdev driver Eric Bénard
2010-05-18  9:26   ` [PATCH 3/3] commands: add i2c commands Eric Bénard
2010-05-18 10:04     ` Eric Bénard
2010-05-19 10:17     ` Sascha Hauer
2010-05-19 11:01   ` Sascha Hauer [this message]
2010-05-19 12:21     ` [PATCH 2/3] i2c: add i2cdev driver Sascha Hauer

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=20100519110124.GM31199@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=eric@eukrea.com \
    /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