From patchwork Fri Jul 2 10:18:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 109849 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o62AIgV6014445 for ; Fri, 2 Jul 2010 10:18:48 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754497Ab0GBKSp (ORCPT ); Fri, 2 Jul 2010 06:18:45 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:38686 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752925Ab0GBKSk (ORCPT ); Fri, 2 Jul 2010 06:18:40 -0400 Received: from dbdp31.itg.ti.com ([172.24.170.98]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id o62AIakS032660 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 2 Jul 2010 05:18:38 -0500 Received: from linfarm488.india.ti.com (localhost [127.0.0.1]) by dbdp31.itg.ti.com (8.13.8/8.13.8) with ESMTP id o62AIX56017724; Fri, 2 Jul 2010 15:48:33 +0530 (IST) Received: from linfarm488.india.ti.com (localhost [127.0.0.1]) by linfarm488.india.ti.com (8.12.11/8.12.11) with ESMTP id o62AIVRZ032240; Fri, 2 Jul 2010 15:48:31 +0530 Received: (from a0393109@localhost) by linfarm488.india.ti.com (8.12.11/8.12.11/Submit) id o62AIVv2032238; Fri, 2 Jul 2010 15:48:31 +0530 From: Thara Gopinath To: linux-omap@vger.kernel.org Cc: khilman@deeprootsystems.com, paul@pwsan.com, b-cousson@ti.com, vishwanath.bs@ti.com, sawant@ti.com, p-basak2@ti.com, Thara Gopinath Subject: [RFC 5/7] OMAP: Introduce set_rate and get_rate API in omap device layer Date: Fri, 2 Jul 2010 15:48:27 +0530 Message-Id: <1278065909-32148-6-git-send-email-thara@ti.com> X-Mailer: git-send-email 1.5.6.6 In-Reply-To: <1278065909-32148-5-git-send-email-thara@ti.com> References: <1278065909-32148-1-git-send-email-thara@ti.com> <1278065909-32148-2-git-send-email-thara@ti.com> <1278065909-32148-3-git-send-email-thara@ti.com> <1278065909-32148-4-git-send-email-thara@ti.com> <1278065909-32148-5-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]); Fri, 02 Jul 2010 10:18:48 +0000 (UTC) diff --git a/arch/arm/plat-omap/include/plat/omap_device.h b/arch/arm/plat-omap/include/plat/omap_device.h index 3694b62..e0d06bb 100644 --- a/arch/arm/plat-omap/include/plat/omap_device.h +++ b/arch/arm/plat-omap/include/plat/omap_device.h @@ -114,6 +114,8 @@ int omap_device_enable_hwmods(struct omap_device *od); int omap_device_disable_clocks(struct omap_device *od); int omap_device_enable_clocks(struct omap_device *od); +int omap_device_set_rate(struct device *dev, unsigned long rate); +unsigned long omap_device_get_rate(struct device *dev); /* * Entries should be kept in latency order ascending diff --git a/arch/arm/plat-omap/omap_device.c b/arch/arm/plat-omap/omap_device.c index 6614cba..900bb5d 100644 --- a/arch/arm/plat-omap/omap_device.c +++ b/arch/arm/plat-omap/omap_device.c @@ -85,6 +85,8 @@ #include #include +#include +#include /* These parameters are passed to _omap_device_{de,}activate() */ #define USE_WAKEUP_LAT 0 @@ -734,3 +736,88 @@ int omap_device_enable_clocks(struct omap_device *od) /* XXX pass along return value here? */ return 0; } + +/** + * omap_device_set_rate - Set a new rate at which the device is to operate + * @dev : the device pointer + * @rate : the rnew rate for the device. + * + * This API gets the device opp table associated with this device and + * tries putting the device to the requested rate and the voltage domain + * associated with the device to the voltage corresponding to the + * requested rate. Since multiple devices can be assocciated with a + * voltage domain this API finds out the possible voltage the + * voltage domain can enter and then decides on the final device + * rate. Return 0 on success else the error value + */ +int omap_device_set_rate(struct device *dev, unsigned long rate) +{ + struct device_opp *dev_opp; + struct omap_opp *opp; + unsigned long volt, freq; + int ret; + + dev_opp = opp_find_dev_opp(dev); + if (IS_ERR(dev_opp)) { + dev_warn(dev, "%s: Unable to find device opp table\n", + __func__); + return -ENODEV; + } + + /* Get the possible rate from the opp layer */ + freq = rate; + opp = opp_find_freq_ceil(dev, &freq); + if (IS_ERR(opp)) { + dev_err(dev, "%s: Unable to find OPP for freq%ld\n", + __func__, rate); + return -ENODEV; + } + if (unlikely(freq != rate)) + dev_warn(dev, "%s: Available freq %ld != dpll freq %ld.\n", + __func__, freq, rate); + + /* Get the voltage corresponding to the requested frequency */ + volt = opp_get_voltage(opp); + + /* + * Call into the voltage layer to get the final voltage possible + * for the voltage domain associated with the device. + */ + + ret = omap_volt_get_final(dev_opp->volt_domain, dev, &volt); + if (ret) { + dev_err(dev, "%s: Unable to get the final volt for scaling\n", + __func__); + return ret; + } + + /* Do the actual scaling */ + return omap_voltage_scale(dev_opp->volt_domain, volt); +} + +/** + * omap_device_get_rate - Gets the current operating rate of the device + * @dev - the device pointer + * + * This API returns the current operating rate of the device on success. + * Else returns the error value. + */ +unsigned long omap_device_get_rate(struct device *dev) +{ + struct device_opp *dev_opp; + + dev_opp = opp_find_dev_opp(dev); + + if (IS_ERR(dev_opp)) { + dev_warn(dev, "%s: Unable to find device opp table\n", + __func__); + return -ENODEV; + } + + if (!dev_opp->get_rate) { + dev_warn(dev, "%s: No get_rate API\n", __func__); + return -EINVAL; + } + + return dev_opp->get_rate(dev); +}