From: "Peter 'p2' De Schrijver" <peter.de-schrijver@nokia.com>
To: linux-kernel@vger.kernel.org
Cc: "Peter 'p2' De Schrijver" <peter.de-schrijver@nokia.com>
Subject: [PATCH] TWL4030: add function to send PB messages
Date: Thu, 23 Apr 2009 16:08:08 +0300 [thread overview]
Message-ID: <1240492089-14410-1-git-send-email-peter.de-schrijver@nokia.com> (raw)
And now with fix to make it compile.
This patch moves sending of powerbus messages to a separate function. It also
makes sure I2C access to the powerbus is enabled.
Signed-off-by: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>
---
drivers/regulator/twl4030-regulator.c | 72 +++++++++++++++++++++++++++++---
1 files changed, 65 insertions(+), 7 deletions(-)
diff --git a/drivers/regulator/twl4030-regulator.c b/drivers/regulator/twl4030-regulator.c
index 472c35a..df9a94b 100644
--- a/drivers/regulator/twl4030-regulator.c
+++ b/drivers/regulator/twl4030-regulator.c
@@ -16,6 +16,7 @@
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
#include <linux/i2c/twl4030.h>
+#include <linux/delay.h>
/*
@@ -81,6 +82,69 @@ twl4030reg_write(struct twlreg_info *info, unsigned offset, u8 value)
value, info->base + offset);
}
+static int twl4030_wait_pb_ready(void)
+{
+
+ u8 pb_status;
+ int status, timeout = 10;
+
+ do {
+ status = twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER,
+ &pb_status, 0x14);
+ if (status < 0)
+ return status;
+
+ if (!(pb_status & 1))
+ return 0;
+
+ mdelay(1);
+ timeout--;
+
+ } while (timeout);
+
+ return -ETIMEDOUT;
+}
+
+static int twl4030_send_pb_msg(unsigned msg)
+{
+
+ u8 pb_state;
+ int status;
+
+ /* save powerbus configuration */
+ status = twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER,
+ &pb_state, 0x14);
+ if (status < 0)
+ return status;
+
+ /* Enable I2C access to powerbus */
+ status = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER,
+ pb_state | (1<<1), 0x14);
+ if (status < 0)
+ return status;
+
+ status = twl4030_wait_pb_ready();
+ if (status < 0)
+ return status;
+
+ status = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, msg >> 8,
+ 0x15 /* PB_WORD_MSB */);
+ if (status < 0)
+ return status;
+
+ status = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, msg & 0xff,
+ 0x16 /* PB_WORD_LSB */);
+ if (status < 0)
+ return status;
+
+ status = twl4030_wait_pb_ready();
+ if (status < 0)
+ return status;
+
+ /* Restore powerbus configuration */
+ return twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, pb_state, 0x14);
+}
+
/*----------------------------------------------------------------------*/
/* generic power resource operations, which work on all regulators */
@@ -177,13 +241,7 @@ static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
if (!(status & (P3_GRP | P2_GRP | P1_GRP)))
return -EACCES;
- status = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER,
- message >> 8, 0x15 /* PB_WORD_MSB */ );
- if (status >= 0)
- return status;
-
- return twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER,
- message, 0x16 /* PB_WORD_LSB */ );
+ return twl4030_send_pb_msg(message);
}
/*----------------------------------------------------------------------*/
--
1.5.6.3
next reply other threads:[~2009-04-23 13:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-23 13:08 Peter 'p2' De Schrijver [this message]
2009-04-23 13:08 ` [PATCH] TWL4030: Make sure the regulator is active after calling twl4030reg_enable Peter 'p2' De Schrijver
2009-04-23 14:56 ` Mark Brown
2009-04-23 14:52 ` [PATCH] TWL4030: add function to send PB messages Mark Brown
[not found] <1240407833-28060-1-git-send-email-peter.de-schrijver@nokia.com>
2009-04-23 22:03 ` David Brownell
2009-04-24 9:25 ` Peter 'p2' De Schrijver
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=1240492089-14410-1-git-send-email-peter.de-schrijver@nokia.com \
--to=peter.de-schrijver@nokia.com \
--cc=linux-kernel@vger.kernel.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 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®