From patchwork Thu Mar 18 09:15:40 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 86636 X-Patchwork-Delegate: khilman@deeprootsystems.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o2I9GJXS025208 for ; Thu, 18 Mar 2010 09:16:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751424Ab0CRJQL (ORCPT ); Thu, 18 Mar 2010 05:16:11 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:50244 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750835Ab0CRJQI (ORCPT ); Thu, 18 Mar 2010 05:16:08 -0400 Received: from dbdp31.itg.ti.com ([172.24.170.98]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id o2I9G3ZA019579 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 18 Mar 2010 04:16:06 -0500 Received: from linfarm476.india.ti.com (localhost [127.0.0.1]) by dbdp31.itg.ti.com (8.13.8/8.13.8) with ESMTP id o2I9FuC2012460; Thu, 18 Mar 2010 14:45:57 +0530 (IST) Received: from linfarm476.india.ti.com (localhost [127.0.0.1]) by linfarm476.india.ti.com (8.12.11/8.12.11) with ESMTP id o2I9FuOO004275; Thu, 18 Mar 2010 14:45:56 +0530 Received: (from a0393109@localhost) by linfarm476.india.ti.com (8.12.11/8.12.11/Submit) id o2I9Fu6A004273; Thu, 18 Mar 2010 14:45:56 +0530 From: Thara Gopinath To: linux-omap@vger.kernel.org Cc: khilman@deeprootsystems.com, paul@pwsan.com, nm@ti.com, b-cousson@ti.com, vishwanath.bs@ti.com, sawant@ti.com, Thara Gopinath Subject: [PATCHv2 02/17] OMAP3: PM: Create list to keep track of various smartreflex instances. Date: Thu, 18 Mar 2010 14:45:40 +0530 Message-Id: <1268903755-4151-3-git-send-email-thara@ti.com> X-Mailer: git-send-email 1.5.5 In-Reply-To: <1268903755-4151-2-git-send-email-thara@ti.com> References: <1268903755-4151-1-git-send-email-thara@ti.com> <1268903755-4151-2-git-send-email-thara@ti.com> 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.3 (demeter.kernel.org [140.211.167.41]); Thu, 18 Mar 2010 09:16:25 +0000 (UTC) diff --git a/arch/arm/mach-omap2/smartreflex.c b/arch/arm/mach-omap2/smartreflex.c index 1c5ec37..dc8d6e1 100644 --- a/arch/arm/mach-omap2/smartreflex.c +++ b/arch/arm/mach-omap2/smartreflex.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -51,9 +52,12 @@ struct omap_sr { u32 opp5_nvalue; u32 senp_mod, senn_mod; void __iomem *srbase_addr; - void __iomem *vpbase_addr; + struct list_head node; }; +/* sr_list contains all the instances of smartreflex module */ +static LIST_HEAD(sr_list); + #define SR_REGADDR(offs) (sr->srbase_addr + offset) static inline void sr_write_reg(struct omap_sr *sr, unsigned offset, u32 value) @@ -78,6 +82,20 @@ static inline u32 sr_read_reg(struct omap_sr *sr, unsigned offset) return __raw_readl(SR_REGADDR(offset)); } +static struct omap_sr *_sr_lookup(int srid) +{ + struct omap_sr *sr_info, *temp_sr_info; + + sr_info = NULL; + list_for_each_entry(temp_sr_info, &sr_list, node) { + if (srid == temp_sr_info->srid) { + sr_info = temp_sr_info; + break; + } + } + return sr_info; +} + static int sr_clk_enable(struct omap_sr *sr) { if (clk_enable(sr->clk) != 0) { @@ -151,11 +169,17 @@ static u8 get_vdd1_opp(void) { struct omap_opp *opp; unsigned long freq; + struct omap_sr *sr_info = _sr_lookup(SR1); - if (sr1.vdd_opp_clk == NULL || IS_ERR(sr1.vdd_opp_clk)) + if (!sr_info) { + pr_warning("omap_sr struct corresponding to SR1 not found\n"); + return 0; + } + + if (sr_info->vdd_opp_clk == NULL || IS_ERR(sr_info->vdd_opp_clk)) return 0; - freq = sr1.vdd_opp_clk->rate; + freq = sr_info->vdd_opp_clk->rate; opp = opp_find_freq_ceil(OPP_MPU, &freq); if (IS_ERR(opp)) return 0; @@ -163,9 +187,9 @@ static u8 get_vdd1_opp(void) * Use higher freq voltage even if an exact match is not available * we are probably masking a clock framework bug, so warn */ - if (unlikely(freq != sr1.vdd_opp_clk->rate)) + if (unlikely(freq != sr_info->vdd_opp_clk->rate)) pr_warning("%s: Available freq %ld != dpll freq %ld.\n", - __func__, freq, sr1.vdd_opp_clk->rate); + __func__, freq, sr_info->vdd_opp_clk->rate); return opp_get_opp_id(opp); } @@ -174,11 +198,17 @@ static u8 get_vdd2_opp(void) { struct omap_opp *opp; unsigned long freq; + struct omap_sr *sr_info = _sr_lookup(SR2); + + if (!sr_info) { + pr_warning("omap_sr struct corresponding to SR2 not found\n"); + return 0; + } - if (sr2.vdd_opp_clk == NULL || IS_ERR(sr2.vdd_opp_clk)) + if (sr_info->vdd_opp_clk == NULL || IS_ERR(sr_info->vdd_opp_clk)) return 0; - freq = sr2.vdd_opp_clk->rate; + freq = sr_info->vdd_opp_clk->rate; opp = opp_find_freq_ceil(OPP_L3, &freq); if (IS_ERR(opp)) return 0; @@ -187,9 +217,9 @@ static u8 get_vdd2_opp(void) * Use higher freq voltage even if an exact match is not available * we are probably masking a clock framework bug, so warn */ - if (unlikely(freq != sr2.vdd_opp_clk->rate)) + if (unlikely(freq != sr_info->vdd_opp_clk->rate)) pr_warning("%s: Available freq %ld != dpll freq %ld.\n", - __func__, freq, sr2.vdd_opp_clk->rate); + __func__, freq, sr_info->vdd_opp_clk->rate); return opp_get_opp_id(opp); } @@ -694,14 +724,13 @@ static void sr_disable(struct omap_sr *sr) void sr_start_vddautocomap(int srid, u32 target_opp_no) { - struct omap_sr *sr = NULL; + struct omap_sr *sr = _sr_lookup(srid); - if (srid == SR1) - sr = &sr1; - else if (srid == SR2) - sr = &sr2; - else + if (!sr) { + pr_warning("omap_sr struct corresponding to SR%d not found\n", + srid); return; + } if (sr->is_sr_reset == 1) { sr_clk_enable(sr); @@ -719,14 +748,13 @@ EXPORT_SYMBOL(sr_start_vddautocomap); int sr_stop_vddautocomap(int srid) { - struct omap_sr *sr = NULL; + struct omap_sr *sr = _sr_lookup(srid); - if (srid == SR1) - sr = &sr1; - else if (srid == SR2) - sr = &sr2; - else - return -EINVAL; + if (!sr) { + pr_warning("omap_sr struct corresponding to SR%d not found\n", + srid); + return false; + } if (sr->is_autocomp_active == 1) { sr_disable(sr); @@ -744,14 +772,13 @@ EXPORT_SYMBOL(sr_stop_vddautocomap); void enable_smartreflex(int srid) { u32 target_opp_no = 0; - struct omap_sr *sr = NULL; + struct omap_sr *sr = _sr_lookup(srid); - if (srid == SR1) - sr = &sr1; - else if (srid == SR2) - sr = &sr2; - else + if (!sr) { + pr_warning("omap_sr struct corresponding to SR%d not found\n", + srid); return; + } if (sr->is_autocomp_active == 1) { if (sr->is_sr_reset == 1) { @@ -779,15 +806,13 @@ void enable_smartreflex(int srid) void disable_smartreflex(int srid) { u32 i = 0; + struct omap_sr *sr = _sr_lookup(srid); - struct omap_sr *sr = NULL; - - if (srid == SR1) - sr = &sr1; - else if (srid == SR2) - sr = &sr2; - else + if (!sr) { + pr_warning("omap_sr struct corresponding to SR%d not found\n", + srid); return; + } if (sr->is_autocomp_active == 1) { if (sr->is_sr_reset == 0) { @@ -920,7 +945,13 @@ int sr_voltagescale_vcbypass(u32 target_opp, u32 current_opp, static ssize_t omap_sr_vdd1_autocomp_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return sprintf(buf, "%d\n", sr1.is_autocomp_active); + struct omap_sr *sr_info = _sr_lookup(SR1); + + if (!sr_info) { + pr_warning("omap_sr struct corresponding to SR1 not found\n"); + return 0; + } + return sprintf(buf, "%d\n", sr_info->is_autocomp_active); } static ssize_t omap_sr_vdd1_autocomp_store(struct kobject *kobj, @@ -960,7 +991,13 @@ static struct kobj_attribute sr_vdd1_autocomp = { static ssize_t omap_sr_vdd2_autocomp_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return sprintf(buf, "%d\n", sr2.is_autocomp_active); + struct omap_sr *sr_info = _sr_lookup(SR2); + + if (!sr_info) { + pr_warning("omap_sr struct corresponding to SR2 not found\n"); + return 0; + } + return sprintf(buf, "%d\n", sr_info->is_autocomp_active); } static ssize_t omap_sr_vdd2_autocomp_store(struct kobject *kobj, @@ -1010,7 +1047,6 @@ static int __init omap3_sr_init(void) RdReg |= DCDC_GLOBAL_CFG_ENABLE_SRFLX; ret |= twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, RdReg, R_DCDC_GLOBAL_CFG); - if (cpu_is_omap34xx()) { sr1.clk = clk_get(NULL, "sr1_fck"); sr2.clk = clk_get(NULL, "sr2_fck"); @@ -1036,6 +1072,8 @@ static int __init omap3_sr_init(void) ret = sysfs_create_file(power_kobj, &sr_vdd2_autocomp.attr); if (ret) pr_err("sysfs_create_file failed: %d\n", ret); + list_add(&sr1.node, &sr_list); + list_add(&sr2.node, &sr_list); return 0; }