[PATCH 2/3] i2c: add i2cdev driver
Eric Bénard
eric at eukrea.com
Tue May 18 05:26:47 EDT 2010
this driver is needed to introduce i2c commands
Signed-off-by: Eric Bénard <eric at 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 at pengutronix.de>
+ * 2009 Eric Benard <eric at 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
More information about the barebox
mailing list