summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2009-11-23 10:40:30 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2009-12-03 10:45:23 +0100
commit635dd44d47f445648f77e04ea5f01a45bec8665e (patch)
treef23464166f024d81959a3874625df84dabb9089e
parenteff9f8718501cc140022c1644dff661757f00a86 (diff)
downloadbarebox-635dd44d47f445648f77e04ea5f01a45bec8665e.tar.gz
barebox-635dd44d47f445648f77e04ea5f01a45bec8665e.tar.xz
mc13892: driver added
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r--drivers/i2c/Kconfig3
-rw-r--r--drivers/i2c/Makefile2
-rw-r--r--drivers/i2c/mc13892.c111
-rw-r--r--include/i2c/mc13892.h7
4 files changed, 123 insertions, 0 deletions
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index aeae450848..e02824e24e 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -7,4 +7,7 @@ config DRIVER_I2C_IMX
bool "i.MX I2C Master driver"
depends on ARCH_IMX
+config DRIVER_I2C_MC13892
+ bool "MC13892 a.k.a. PMIC driver"
+
endif
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index bf16153baa..2fa50fad14 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -1,3 +1,5 @@
obj-$(CONFIG_I2C) += i2c.o
obj-$(CONFIG_DRIVER_I2C_IMX) += i2c-imx.o
+
+obj-$(CONFIG_DRIVER_I2C_MC13892) += mc13892.o
diff --git a/drivers/i2c/mc13892.c b/drivers/i2c/mc13892.c
new file mode 100644
index 0000000000..54661d4f5e
--- /dev/null
+++ b/drivers/i2c/mc13892.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2007 Sascha Hauer, Pengutronix
+ * 2009 Marc Kleine-Budde <mkl@pengutronix.de>
+ *
+ * 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 "mc13892"
+
+struct mc_priv {
+ struct cdev cdev;
+ struct i2c_client *client;
+};
+
+#define to_mc_priv(a) container_of(a, struct mc_priv, cdev)
+
+static struct mc_priv *mc_dev;
+
+struct i2c_client *mc13892_get_client(void)
+{
+ if (!mc_dev)
+ return NULL;
+
+ return mc_dev->client;
+}
+
+static u32 mc_read_reg(struct mc_priv *mc, int reg)
+{
+ u32 buf;
+
+ i2c_read_reg(mc->client, reg, (u8 *)&buf, sizeof(buf));
+
+ return buf;
+}
+
+static ssize_t mc_read(struct cdev *cdev, void *_buf, size_t count, ulong offset, ulong flags)
+{
+ struct mc_priv *priv = to_mc_priv(cdev);
+ int i = count >> 2;
+ u32 *buf = _buf;
+
+ offset >>= 2;
+
+ while (i) {
+ *buf = mc_read_reg(priv, offset);
+ buf++;
+ i--;
+ offset++;
+ }
+
+ return count;
+}
+
+static struct file_operations mc_fops = {
+ .lseek = dev_lseek_default,
+ .read = mc_read,
+};
+
+static int mc_probe(struct device_d *dev)
+{
+ if (mc_dev)
+ return -EBUSY;
+
+ mc_dev = xzalloc(sizeof(struct mc_priv));
+ mc_dev->cdev.name = DRIVERNAME;
+ mc_dev->client = to_i2c_client(dev);
+ mc_dev->cdev.size = 256;
+ mc_dev->cdev.dev = dev;
+ mc_dev->cdev.ops = &mc_fops;
+
+ devfs_create(&mc_dev->cdev);
+
+ return 0;
+}
+
+static struct driver_d mc_driver = {
+ .name = DRIVERNAME,
+ .probe = mc_probe,
+};
+
+static int mc_init(void)
+{
+ register_driver(&mc_driver);
+ return 0;
+}
+
+device_initcall(mc_init);
diff --git a/include/i2c/mc13892.h b/include/i2c/mc13892.h
new file mode 100644
index 0000000000..2f44f6c853
--- /dev/null
+++ b/include/i2c/mc13892.h
@@ -0,0 +1,7 @@
+#ifndef __ASM_ARCH_MC13892_H
+#define __ASM_ARCH_MC13892_H
+
+extern struct i2c_client *mc13892_get_client(void);
+
+#endif /* __ASM_ARCH_MC13892_H */
+