From: Peter Ujfalusi <peter.ujfalusi@ti.com>
To: Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
Samuel Ortiz <sameo@linux.intel.com>,
Lee Jones <lee.jones@linaro.org>
Cc: <alsa-devel@alsa-project.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH 01/11] MFD: twl-core: Simplify IO wrapper functions by moving common code out
Date: Fri, 3 Jan 2014 15:27:46 +0200 [thread overview]
Message-ID: <1388755676-16036-2-git-send-email-peter.ujfalusi@ti.com> (raw)
In-Reply-To: <1388755676-16036-1-git-send-email-peter.ujfalusi@ti.com>
The new twl_get_regmap() function will return a pointer to the regmap needed
for the given module.
Since both read and write function were using the same code to do the lookup
we can reuse this in both places to simplify the code.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
drivers/mfd/twl-core.c | 58 +++++++++++++++++++++++++++-----------------------
1 file changed, 31 insertions(+), 27 deletions(-)
diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
index 29473c2c95ae..c91cb4367b9b 100644
--- a/drivers/mfd/twl-core.c
+++ b/drivers/mfd/twl-core.c
@@ -302,35 +302,50 @@ unsigned int twl_rev(void)
EXPORT_SYMBOL(twl_rev);
/**
- * twl_i2c_write - Writes a n bit register in TWL4030/TWL5030/TWL60X0
+ * twl_get_regmap - Get the regmap associated with the given module
* @mod_no: module number
- * @value: an array of num_bytes+1 containing data to write
- * @reg: register address (just offset will do)
- * @num_bytes: number of bytes to transfer
*
- * Returns the result of operation - 0 is success
+ * Returns the regmap pointer or NULL in case of failure.
*/
-int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
+static struct regmap *twl_get_regmap(u8 mod_no)
{
- int ret;
int sid;
struct twl_client *twl;
if (unlikely(!twl_priv || !twl_priv->ready)) {
pr_err("%s: not initialized\n", DRIVER_NAME);
- return -EPERM;
+ return NULL;
}
if (unlikely(mod_no >= twl_get_last_module())) {
pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
- return -EPERM;
+ return NULL;
}
sid = twl_priv->twl_map[mod_no].sid;
twl = &twl_priv->twl_modules[sid];
- ret = regmap_bulk_write(twl->regmap,
- twl_priv->twl_map[mod_no].base + reg, value,
- num_bytes);
+ return twl->regmap;
+}
+
+/**
+ * twl_i2c_write - Writes a n bit register in TWL4030/TWL5030/TWL60X0
+ * @mod_no: module number
+ * @value: an array of num_bytes+1 containing data to write
+ * @reg: register address (just offset will do)
+ * @num_bytes: number of bytes to transfer
+ *
+ * Returns the result of operation - 0 is success
+ */
+int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
+{
+ struct regmap *regmap = twl_get_regmap(mod_no);
+ int ret;
+
+ if (!regmap)
+ return -EPERM;
+
+ ret = regmap_bulk_write(regmap, twl_priv->twl_map[mod_no].base + reg,
+ value, num_bytes);
if (ret)
pr_err("%s: Write failed (mod %d, reg 0x%02x count %d)\n",
@@ -351,25 +366,14 @@ EXPORT_SYMBOL(twl_i2c_write);
*/
int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
{
+ struct regmap *regmap = twl_get_regmap(mod_no);
int ret;
- int sid;
- struct twl_client *twl;
- if (unlikely(!twl_priv || !twl_priv->ready)) {
- pr_err("%s: not initialized\n", DRIVER_NAME);
- return -EPERM;
- }
- if (unlikely(mod_no >= twl_get_last_module())) {
- pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
+ if (!regmap)
return -EPERM;
- }
-
- sid = twl_priv->twl_map[mod_no].sid;
- twl = &twl_priv->twl_modules[sid];
- ret = regmap_bulk_read(twl->regmap,
- twl_priv->twl_map[mod_no].base + reg, value,
- num_bytes);
+ ret = regmap_bulk_read(regmap, twl_priv->twl_map[mod_no].base + reg,
+ value, num_bytes);
if (ret)
pr_err("%s: Read failed (mod %d, reg 0x%02x count %d)\n",
--
1.8.5.2
next prev parent reply other threads:[~2014-01-03 13:28 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-03 13:27 [PATCH 00/11] ASoC/MFD: twl4030 codec local register cache removal Peter Ujfalusi
2014-01-03 13:27 ` Peter Ujfalusi [this message]
2014-01-03 13:27 ` [PATCH 02/11] MFD: twl-core: API to set the regcache bypass for a given regmap in twl Peter Ujfalusi
2014-01-03 13:27 ` [PATCH 03/11] MFD: twl-core: Enable regcache for audio registers Peter Ujfalusi
2014-01-03 13:27 ` [PATCH 04/11] ASoC: twl4030: Separate write condition checking from I/O function Peter Ujfalusi
2014-01-03 13:27 ` [PATCH 05/11] ASoC: twl4030: Remove check defaults functionality Peter Ujfalusi
2014-01-03 13:27 ` [PATCH 06/11] ASoC: twl4030: Remove reset registers functionality Peter Ujfalusi
2014-01-03 13:27 ` [PATCH 07/11] ASoC: twl4030: Introduce local ctl register cache Peter Ujfalusi
2014-01-03 13:27 ` [PATCH 08/11] ASoC: twl4030: Remove local reg cache Peter Ujfalusi
2014-01-08 8:05 ` Lee Jones
2014-01-08 11:07 ` Peter Ujfalusi
2014-01-08 11:18 ` Lee Jones
2014-01-03 13:27 ` [PATCH 09/11] ASoC: twl4030: Parameter alignment fixes (for code consistency) Peter Ujfalusi
2014-01-03 13:27 ` [PATCH 10/11] ASoC: twl4030: Move the ctl cache update local to twl4030_write() function Peter Ujfalusi
2014-01-03 13:27 ` [PATCH 11/11] ASoC: twl4030: Pass the twl4030_priv directly to twl4030_can_write_to_chip() Peter Ujfalusi
2014-01-06 13:19 ` [PATCH 00/11] ASoC/MFD: twl4030 codec local register cache removal Mark Brown
2014-01-06 16:10 ` Lee Jones
2014-01-06 16:31 ` Mark Brown
2014-01-08 11:42 ` Lee Jones
2014-01-08 12:48 ` Mark Brown
2014-01-08 13:29 ` Lee Jones
2014-01-08 12:49 ` Mark Brown
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=1388755676-16036-2-git-send-email-peter.ujfalusi@ti.com \
--to=peter.ujfalusi@ti.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=lee.jones@linaro.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--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
all inboxes | Powered by JetHome®