From: Mark Brown <broonie@opensource.wolfsonmicro.com>
To: linux-kernel@vger.kernel.org
Cc: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>,
Liam Girdwood <lrg@ti.com>, Samuel Oritz <sameo@linux.intel.com>,
Lars-Peter Clausen <lars@metafoo.de>,
Graeme Gregory <gg@slimlogic.co.uk>,
Mark Brown <broonie@opensource.wolfsonmicro.com>
Subject: [PATCH 2/8] regmap: Add I2C bus support
Date: Wed, 29 Jun 2011 23:00:30 -0700 [thread overview]
Message-ID: <1309413636-1169-2-git-send-email-broonie@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1309413636-1169-1-git-send-email-broonie@opensource.wolfsonmicro.com>
We initialise at postcore_initcall() so that we are available before users
- some users such as PMICs initialise very early. We won't actually try to
use any of the bus until a device initialises a register map.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
drivers/regmap/Makefile | 2 +-
drivers/regmap/regmap-i2c.c | 113 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 114 insertions(+), 1 deletions(-)
create mode 100644 drivers/regmap/regmap-i2c.c
diff --git a/drivers/regmap/Makefile b/drivers/regmap/Makefile
index 1e5037e..641c20a 100644
--- a/drivers/regmap/Makefile
+++ b/drivers/regmap/Makefile
@@ -1,2 +1,2 @@
obj-$(CONFIG_REGMAP) += regmap.o
-
+obj-$(CONFIG_I2C) += regmap-i2c.o
diff --git a/drivers/regmap/regmap-i2c.c b/drivers/regmap/regmap-i2c.c
new file mode 100644
index 0000000..19d0739
--- /dev/null
+++ b/drivers/regmap/regmap-i2c.c
@@ -0,0 +1,113 @@
+/*
+ * Register map access API - I2C support
+ *
+ * Copyright 2011 Wolfson Microelectronics plc
+ *
+ * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/regmap.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+
+static int regmap_i2c_write(struct device *dev, const void *data, size_t count)
+{
+ struct i2c_client *i2c = to_i2c_client(dev);
+ int ret;
+
+ ret = i2c_master_send(i2c, data, count);
+ if (ret == count)
+ return 0;
+ else if (ret < 0)
+ return ret;
+ else
+ return -EIO;
+}
+
+static int regmap_i2c_gather_write(struct device *dev,
+ const void *reg, size_t reg_size,
+ const void *val, size_t val_size)
+{
+ struct i2c_client *i2c = to_i2c_client(dev);
+ struct i2c_msg xfer[2];
+ int ret;
+
+ /* If the I2C controller can't do a gather tell the core, it
+ * will substitute in a linear write for us.
+ */
+ if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_PROTOCOL_MANGLING))
+ return -ENOTSUPP;
+
+ xfer[0].addr = i2c->addr;
+ xfer[0].flags = 0;
+ xfer[0].len = reg_size;
+ xfer[0].buf = (void *)reg;
+
+ xfer[1].addr = i2c->addr;
+ xfer[1].flags = I2C_M_NOSTART;
+ xfer[1].len = val_size;
+ xfer[1].buf = (void *)val;
+
+ ret = i2c_transfer(i2c->adapter, xfer, 2);
+ if (ret == 2)
+ return 0;
+ if (ret < 0)
+ return ret;
+ else
+ return -EIO;
+}
+
+static int regmap_i2c_read(struct device *dev,
+ const void *reg, size_t reg_size,
+ void *val, size_t val_size)
+{
+ struct i2c_client *i2c = to_i2c_client(dev);
+ struct i2c_msg xfer[2];
+ int ret;
+
+ if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_PROTOCOL_MANGLING))
+ return -ENOTSUPP;
+
+ xfer[0].addr = i2c->addr;
+ xfer[0].flags = 0;
+ xfer[0].len = reg_size;
+ xfer[0].buf = (void *)reg;
+
+ xfer[1].addr = i2c->addr;
+ xfer[1].flags = I2C_M_RD;
+ xfer[1].len = val_size;
+ xfer[1].buf = val;
+
+ ret = i2c_transfer(i2c->adapter, xfer, 2);
+ if (ret == 2)
+ return 0;
+ else if (ret < 0)
+ return ret;
+ else
+ return -EIO;
+}
+
+static struct regmap_bus regmap_i2c = {
+ .type = &i2c_bus_type,
+ .write = regmap_i2c_write,
+ .gather_write = regmap_i2c_gather_write,
+ .read = regmap_i2c_read,
+ .owner = THIS_MODULE,
+};
+
+static int __init regmap_i2c_init(void)
+{
+ regmap_add_bus(®map_i2c);
+ return 0;
+}
+postcore_initcall(regmap_i2c_init);
+
+static void __exit regmap_i2c_exit(void)
+{
+ regmap_del_bus(®map_i2c);
+}
+module_exit(regmap_i2c_exit);
--
1.7.5.4
next prev parent reply other threads:[~2011-06-30 6:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-30 5:58 [PATCH 0/8] regmap: Generic I2C and SPI register map library Mark Brown
2011-06-30 6:00 ` [PATCH 1/8] regmap: Add generic non-memory mapped register access API Mark Brown
2011-06-30 6:00 ` Mark Brown [this message]
2011-06-30 6:00 ` [PATCH 3/8] regmap: Add SPI bus support Mark Brown
2011-06-30 6:00 ` [PATCH 4/8] ASoC: Use new register map API for ASoC generic physical I/O Mark Brown
2011-06-30 6:00 ` [PATCH 5/8] mfd: Convert WM831x to use regmap API Mark Brown
2011-06-30 6:00 ` [PATCH 6/8] mfd: Convert WM8994 to use new register map API Mark Brown
2011-06-30 6:00 ` [PATCH 7/8] mfd: Convert pcf50633 " Mark Brown
2011-06-30 6:00 ` [PATCH 8/8] regulator: Convert tps65023 to use regmap API Mark Brown
2011-06-30 17:07 ` [PATCH 0/8] regmap: Generic I2C and SPI register map library Liam Girdwood
2011-06-30 17:14 ` Liam Girdwood
-- strict thread matches above, loose matches on Subject: below --
2011-06-22 18:44 [PATCH 0/8] " Mark Brown
2011-06-22 18:45 ` [PATCH 1/8] regmap: Add generic non-memory mapped register access API Mark Brown
2011-06-22 18:45 ` [PATCH 2/8] regmap: Add I2C bus support Mark Brown
2011-06-20 12:46 [PATCH 0/8] Generic I2C and SPI register map library Mark Brown
2011-06-20 12:54 ` [PATCH 1/8] regmap: Add generic non-memory mapped register access API Mark Brown
2011-06-20 12:54 ` [PATCH 2/8] regmap: Add I2C bus support Mark Brown
2011-06-20 23:22 ` Lars-Peter Clausen
2011-06-20 23:41 ` Mark Brown
2011-06-21 0:01 ` Lars-Peter Clausen
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=1309413636-1169-2-git-send-email-broonie@opensource.wolfsonmicro.com \
--to=broonie@opensource.wolfsonmicro.com \
--cc=dp@opensource.wolfsonmicro.com \
--cc=gg@slimlogic.co.uk \
--cc=lars@metafoo.de \
--cc=linux-kernel@vger.kernel.org \
--cc=lrg@ti.com \
--cc=sameo@linux.intel.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
Powered by JetHome