From patchwork Wed Apr 22 14:03:34 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter 'p2' De Schrijver X-Patchwork-Id: 19380 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n3ME5fHO014617 for ; Wed, 22 Apr 2009 14:05:42 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753855AbZDVODn (ORCPT ); Wed, 22 Apr 2009 10:03:43 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753561AbZDVODn (ORCPT ); Wed, 22 Apr 2009 10:03:43 -0400 Received: from smtp.nokia.com ([192.100.122.233]:39558 "EHLO mgw-mx06.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753181AbZDVODm (ORCPT ); Wed, 22 Apr 2009 10:03:42 -0400 Received: from esebh106.NOE.Nokia.com (esebh106.ntc.nokia.com [172.21.138.213]) by mgw-mx06.nokia.com (Switch-3.2.6/Switch-3.2.6) with ESMTP id n3ME3EPi024773 for ; Wed, 22 Apr 2009 17:03:35 +0300 Received: from vaebh104.NOE.Nokia.com ([10.160.244.30]) by esebh106.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 22 Apr 2009 17:03:38 +0300 Received: from mgw-int02.ntc.nokia.com ([172.21.143.97]) by vaebh104.NOE.Nokia.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Wed, 22 Apr 2009 17:03:37 +0300 Received: from localhost.localdomain (esdhcp04238.research.nokia.com [172.21.42.38]) by mgw-int02.ntc.nokia.com (Switch-3.2.5/Switch-3.2.5) with ESMTP id n3ME3Zct005693; Wed, 22 Apr 2009 17:03:36 +0300 From: "Peter 'p2' De Schrijver" To: linux-omap@vger.kernel.org Cc: "Peter 'p2' De Schrijver" Subject: [PATCH] TWL4030: add function to send PB messages Date: Wed, 22 Apr 2009 17:03:34 +0300 Message-Id: <1240409015-2940-1-git-send-email-peter.de-schrijver@nokia.com> X-Mailer: git-send-email 1.5.6.3 In-Reply-To: <1240407833-28060-1-git-send-email-peter.de-schrijver@nokia.com> References: <1240407833-28060-1-git-send-email-peter.de-schrijver@nokia.com> X-OriginalArrivalTime: 22 Apr 2009 14:03:37.0359 (UTC) FILETIME=[21CD89F0:01C9C353] X-Nokia-AV: Clean Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org 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 --- 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 #include #include +#include /* @@ -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); } /*----------------------------------------------------------------------*/