All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Eric Bénard" <eric@eukrea.com>
To: barebox@lists.infradead.org
Subject: [PATCH 2/3] i2c: add i2cdev driver
Date: Tue, 18 May 2010 11:26:47 +0200	[thread overview]
Message-ID: <1274174808-9516-2-git-send-email-eric@eukrea.com> (raw)
In-Reply-To: <1274174808-9516-1-git-send-email-eric@eukrea.com>

this driver is needed to introduce i2c commands

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

  reply	other threads:[~2010-05-18  9:26 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 ` Eric Bénard [this message]
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   ` [PATCH 2/3] i2c: add i2cdev driver Sascha Hauer
2010-05-19 12:21     ` 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=1274174808-9516-2-git-send-email-eric@eukrea.com \
    --to=eric@eukrea.com \
    --cc=barebox@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.