From patchwork Thu Apr 14 12:27:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lesly A M X-Patchwork-Id: 707021 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3ECRw4m020416 for ; Thu, 14 Apr 2011 12:28:02 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757806Ab1DNM2A (ORCPT ); Thu, 14 Apr 2011 08:28:00 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:34841 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757545Ab1DNM16 (ORCPT ); Thu, 14 Apr 2011 08:27:58 -0400 Received: from dbdp20.itg.ti.com ([172.24.170.38]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id p3ECRtHb015429 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 14 Apr 2011 07:27:57 -0500 Received: from dbde71.ent.ti.com (localhost [127.0.0.1]) by dbdp20.itg.ti.com (8.13.8/8.13.8) with ESMTP id p3ECRp1K025777; Thu, 14 Apr 2011 17:57:51 +0530 (IST) Received: from dbdp31.itg.ti.com (172.24.170.98) by DBDE71.ent.ti.com (172.24.170.149) with Microsoft SMTP Server id 8.3.106.1; Thu, 14 Apr 2011 17:57:37 +0530 Received: from ucmsshproxy.india.ext.ti.com (dbdp20.itg.ti.com [172.24.170.38]) by dbdp31.itg.ti.com (8.13.8/8.13.8) with SMTP id p3ECRoSm018351; Thu, 14 Apr 2011 17:57:50 +0530 (IST) Received: from localhost (unknown [10.24.244.98]) by ucmsshproxy.india.ext.ti.com (Postfix) with ESMTP id CD061158002; Thu, 14 Apr 2011 17:57:50 +0530 (IST) From: Lesly A M To: CC: Lesly A M , Nishanth Menon , David Derrick , Samuel Ortiz Subject: [PATCH v9 9/9] OMAP3: PM: TWL4030 optimizing resource configuration Date: Thu, 14 Apr 2011 17:57:57 +0530 Message-ID: <1302784077-16697-10-git-send-email-leslyam@ti.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1302784077-16697-1-git-send-email-leslyam@ti.com> References: <1302784077-16697-1-git-send-email-leslyam@ti.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 14 Apr 2011 12:28:03 +0000 (UTC) Skip the i2c register writes in twl4030_configure_resource() if the new value is same as the old value, for devgrp/type/remap regs. Suggested by David Derrick Signed-off-by: Lesly A M Cc: Nishanth Menon Cc: David Derrick Cc: Samuel Ortiz --- drivers/mfd/twl4030-power.c | 126 ++++++++++++++++++++++++------------------ 1 files changed, 72 insertions(+), 54 deletions(-) diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c index 8d1db78..95ef257 100644 --- a/drivers/mfd/twl4030-power.c +++ b/drivers/mfd/twl4030-power.c @@ -335,9 +335,9 @@ static int __init twl4030_configure_resource(struct twl4030_resconfig *rconfig) { int rconfig_addr; int err; - u8 type; - u8 grp; - u8 remap; + u8 type, type_value; + u8 grp, grp_value; + u8 remap, remap_value; if (rconfig->resource > TOTAL_RESOURCES) { pr_err("TWL4030 Resource %d does not exist\n", @@ -348,76 +348,94 @@ static int __init twl4030_configure_resource(struct twl4030_resconfig *rconfig) rconfig_addr = res_config_addrs[rconfig->resource]; /* Set resource group */ - err = twl_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &grp, + if (rconfig->devgroup != TWL4030_RESCONFIG_UNDEF) { + err = twl_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &grp, rconfig_addr + DEV_GRP_OFFSET); - if (err) { - pr_err("TWL4030 Resource %d group could not be read\n", - rconfig->resource); - return err; - } + if (err) { + pr_err("TWL4030 Resource %d group could not be read\n", + rconfig->resource); + return err; + } - if (rconfig->devgroup != TWL4030_RESCONFIG_UNDEF) { - grp &= ~DEV_GRP_MASK; - grp |= rconfig->devgroup << DEV_GRP_SHIFT; - err = twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, + grp_value = (grp & DEV_GRP_MASK) >> DEV_GRP_SHIFT; + + if (rconfig->devgroup != grp_value) { + grp &= ~DEV_GRP_MASK; + grp |= rconfig->devgroup << DEV_GRP_SHIFT; + err = twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, grp, rconfig_addr + DEV_GRP_OFFSET); - if (err < 0) { - pr_err("TWL4030 failed to program devgroup\n"); - return err; + if (err < 0) { + pr_err("TWL4030 failed to program devgroup\n"); + return err; + } } } /* Set resource types */ - err = twl_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &type, + if ((rconfig->type != TWL4030_RESCONFIG_UNDEF) || + (rconfig->type2 != TWL4030_RESCONFIG_UNDEF)) { + + err = twl_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &type, rconfig_addr + TYPE_OFFSET); - if (err < 0) { - pr_err("TWL4030 Resource %d type could not be read\n", - rconfig->resource); - return err; - } + if (err < 0) { + pr_err("TWL4030 Resource %d type could not be read\n", + rconfig->resource); + return err; + } - if (rconfig->type != TWL4030_RESCONFIG_UNDEF) { - type &= ~TYPE_MASK; - type |= rconfig->type << TYPE_SHIFT; - } + type_value = type; - if (rconfig->type2 != TWL4030_RESCONFIG_UNDEF) { - type &= ~TYPE2_MASK; - type |= rconfig->type2 << TYPE2_SHIFT; - } + if (rconfig->type != TWL4030_RESCONFIG_UNDEF) { + type &= ~TYPE_MASK; + type |= rconfig->type << TYPE_SHIFT; + } - err = twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, + if (rconfig->type2 != TWL4030_RESCONFIG_UNDEF) { + type &= ~TYPE2_MASK; + type |= rconfig->type2 << TYPE2_SHIFT; + } + + if (type != type_value) { + err = twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, type, rconfig_addr + TYPE_OFFSET); - if (err < 0) { - pr_err("TWL4030 failed to program resource type\n"); - return err; + if (err < 0) { + pr_err("TWL4030 failed to program resource type\n"); + return err; + } + } } /* Set remap states */ - err = twl_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &remap, + if ((rconfig->remap_off != TWL4030_RESCONFIG_UNDEF) || + (rconfig->remap_sleep != TWL4030_RESCONFIG_UNDEF)) { + err = twl_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &remap, rconfig_addr + REMAP_OFFSET); - if (err < 0) { - pr_err("TWL4030 Resource %d remap could not be read\n", - rconfig->resource); - return err; - } + if (err < 0) { + pr_err("TWL4030 Resource %d remap could not be read\n", + rconfig->resource); + return err; + } - if (rconfig->remap_off != TWL4030_RESCONFIG_UNDEF) { - remap &= ~OFF_STATE_MASK; - remap |= rconfig->remap_off << OFF_STATE_SHIFT; - } + remap_value = remap; - if (rconfig->remap_sleep != TWL4030_RESCONFIG_UNDEF) { - remap &= ~SLEEP_STATE_MASK; - remap |= rconfig->remap_sleep << SLEEP_STATE_SHIFT; - } + if (rconfig->remap_off != TWL4030_RESCONFIG_UNDEF) { + remap &= ~OFF_STATE_MASK; + remap |= rconfig->remap_off << OFF_STATE_SHIFT; + } - err = twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, - remap, - rconfig_addr + REMAP_OFFSET); - if (err < 0) { - pr_err("TWL4030 failed to program remap\n"); - return err; + if (rconfig->remap_sleep != TWL4030_RESCONFIG_UNDEF) { + remap &= ~SLEEP_STATE_MASK; + remap |= rconfig->remap_sleep << SLEEP_STATE_SHIFT; + } + + if (remap != remap_value) { + err = twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, + remap, rconfig_addr + REMAP_OFFSET); + if (err < 0) { + pr_err("TWL4030 failed to program remap\n"); + return err; + } + } } return 0;