From patchwork Thu Apr 8 23:16:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: omar ramirez X-Patchwork-Id: 91536 X-Patchwork-Delegate: omar.ramirez@ti.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 o38Mxo5R010162 for ; Thu, 8 Apr 2010 22:59:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933823Ab0DHW7n (ORCPT ); Thu, 8 Apr 2010 18:59:43 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:59843 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933768Ab0DHW7g (ORCPT ); Thu, 8 Apr 2010 18:59:36 -0400 Received: from dlep36.itg.ti.com ([157.170.170.91]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id o38MxPkO026704 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 8 Apr 2010 17:59:25 -0500 Received: from legion.dal.design.ti.com (localhost [127.0.0.1]) by dlep36.itg.ti.com (8.13.8/8.13.8) with ESMTP id o38MxO5q029536; Thu, 8 Apr 2010 17:59:25 -0500 (CDT) Received: from Matrix (matrix.am.dhcp.ti.com [128.247.75.166]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id o38MxNZ16522; Thu, 8 Apr 2010 17:59:24 -0500 (CDT) Received: by Matrix (Postfix, from userid 1003) id 828F041017C; Thu, 8 Apr 2010 18:16:09 -0500 (CDT) From: Omar Ramirez Luna To: linux-omap@vger.kernel.org Cc: Paul Walmsley , Hiroshi DOYU , Felipe Contreras , Ameya Palande , Guzman Lugo Fernando , Nishanth Menon , Omar Ramirez Luna Subject: [PATCH 17/19] DSPBRIDGE: Balance the number of enable/disable Date: Thu, 8 Apr 2010 18:16:06 -0500 Message-Id: <1270768568-10712-18-git-send-email-omar.ramirez@ti.com> X-Mailer: git-send-email 1.5.4.3 In-Reply-To: <1270768568-10712-17-git-send-email-omar.ramirez@ti.com> References: <1270768568-10712-1-git-send-email-omar.ramirez@ti.com> <1270768568-10712-2-git-send-email-omar.ramirez@ti.com> <1270768568-10712-3-git-send-email-omar.ramirez@ti.com> <1270768568-10712-4-git-send-email-omar.ramirez@ti.com> <1270768568-10712-5-git-send-email-omar.ramirez@ti.com> <1270768568-10712-6-git-send-email-omar.ramirez@ti.com> <1270768568-10712-7-git-send-email-omar.ramirez@ti.com> <1270768568-10712-8-git-send-email-omar.ramirez@ti.com> <1270768568-10712-9-git-send-email-omar.ramirez@ti.com> <1270768568-10712-10-git-send-email-omar.ramirez@ti.com> <1270768568-10712-11-git-send-email-omar.ramirez@ti.com> <1270768568-10712-12-git-send-email-omar.ramirez@ti.com> <1270768568-10712-13-git-send-email-omar.ramirez@ti.com> <1270768568-10712-14-git-send-email-omar.ramirez@ti.com> <1270768568-10712-15-git-send-email-omar.ramirez@ti.com> <1270768568-10712-16-git-send-email-omar.ramirez@ti.com> <1270768568-10712-17-git-send-email-omar.ramirez@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, 08 Apr 2010 22:59:54 +0000 (UTC) diff --git a/drivers/dsp/bridge/services/clk.c b/drivers/dsp/bridge/services/clk.c index 711bae4..8f539fd 100644 --- a/drivers/dsp/bridge/services/clk.c +++ b/drivers/dsp/bridge/services/clk.c @@ -69,6 +69,23 @@ struct dsp_ssi { static struct dsp_ssi ssi; +static u32 dsp_clocks; + +static inline u32 is_dsp_clk_active(u32 clk, u8 id) +{ + return clk & (1 << id); +} + +static inline void set_dsp_clk_active(u32 *clk, u8 id) +{ + *clk |= (1 << id); +} + +static inline void set_dsp_clk_inactive(u32 *clk, u8 id) +{ + *clk &= ~(1 << id); +} + static s8 get_clk_type(u8 id) { s8 type; @@ -182,6 +199,11 @@ dsp_status dsp_clk_enable(IN enum dsp_clk_id clk_id) { dsp_status status = DSP_SOK; + if (is_dsp_clk_active(dsp_clocks, clk_id)) { + dev_err(bridge, "WARN: clock id %d already enabled\n", clk_id); + goto out; + } + switch (get_clk_type(clk_id)) { case GPT_CLK: timer[clk_id] = omap_dm_timer_request_specific(DMT_ID(clk_id)); @@ -210,8 +232,13 @@ dsp_status dsp_clk_enable(IN enum dsp_clk_id clk_id) break; default: dev_err(bridge, "Invalid clock id for enable\n"); + status = DSP_EFAIL; } + if (DSP_SUCCEEDED(status)) + set_dsp_clk_active(&dsp_clocks, clk_id); + +out: return status; } @@ -227,6 +254,11 @@ dsp_status dsp_clk_disable(IN enum dsp_clk_id clk_id) DBC_REQUIRE(clk_id < DSP_CLK_NOT_DEFINED); + if (!is_dsp_clk_active(dsp_clocks, clk_id)) { + dev_err(bridge, "ERR: clock id %d already disabled\n", clk_id); + goto out; + } + switch (get_clk_type(clk_id)) { case GPT_CLK: omap_dm_timer_free(timer[clk_id]); @@ -246,7 +278,12 @@ dsp_status dsp_clk_disable(IN enum dsp_clk_id clk_id) break; default: dev_err(bridge, "Invalid clock id for disable\n"); + status = DSP_EFAIL; } + if (DSP_SUCCEEDED(status)) + set_dsp_clk_inactive(&dsp_clocks, clk_id); + +out: return status; }