From patchwork Thu May 21 06:37:53 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 25185 X-Patchwork-Delegate: lethal@linux-sh.org 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 n4L6erxV011284 for ; Thu, 21 May 2009 06:40:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751437AbZEUGkv (ORCPT ); Thu, 21 May 2009 02:40:51 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751455AbZEUGkv (ORCPT ); Thu, 21 May 2009 02:40:51 -0400 Received: from wf-out-1314.google.com ([209.85.200.174]:36810 "EHLO wf-out-1314.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751437AbZEUGku (ORCPT ); Thu, 21 May 2009 02:40:50 -0400 Received: by wf-out-1314.google.com with SMTP id 26so303160wfd.4 for ; Wed, 20 May 2009 23:40:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:date:message-id :subject; bh=zH+u/Jq31sh10cDhGaSxG54lH5mkVMJkWCaFT2+v2Wg=; b=YMxYVcD3MD+CysqmqT3FosmuEF9ot/c4Z89iC6CiFnWJNe5c8hd4Got076R4HcxVbr 4quTF3wJ0a5+Xsp8+UdFL61GdX0ImWyXJpH4r2TpYI3SrOeTK4sNi8iT0G+lrPwITfZd +py0GoVPaWhZjmEf0sEOU46WhU9RLehJLD3jU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:date:message-id:subject; b=p1j4+5D87VX6Ep8gFVAgDI7qEbywfpaK5h9NV1blJxAqmmS9SIJFZKjFtvhetnBbRD wjF4iUnAHJ+sx/vgYC/zpjIPx1JaygYdtfvO5lkiOYLplsHskx0k+qB3X0n3lhL6HyFP fWAXnzWFPHAfhQ8nEqmVfYA3fHI7uW3BZUWq4= Received: by 10.143.2.20 with SMTP id e20mr856958wfi.298.1242888051620; Wed, 20 May 2009 23:40:51 -0700 (PDT) Received: from rx1.opensource.se (210.5.32.202.bf.2iij.net [202.32.5.210]) by mx.google.com with ESMTPS id 30sm3577262wfa.15.2009.05.20.23.40.49 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 20 May 2009 23:40:49 -0700 (PDT) From: Magnus Damm To: linux-sh@vger.kernel.org Cc: Magnus Damm , lethal@linux-sh.org Date: Thu, 21 May 2009 15:37:53 +0900 Message-Id: <20090521063753.31513.20597.sendpatchset@rx1.opensource.se> Subject: [PATCH][RFC] sh: struct clk_cpg_div Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org From: Magnus Damm This patch adds CPG divisor helper functions to clock-cpg.c. CPG divisors (and the PLL) usually found in FRQCR can now register multipier and divisor arrays together with callbacks for getting and setting index values. The value read out from the hardware is used as index in the multiplier and divisor arrays to calculate frequency. Invalid settings in the array should be set to zero. Only getting rate is supported for now. Signed-off-by: Magnus Damm --- arch/sh/include/asm/clock.h | 16 ++++++++++++++++ arch/sh/kernel/cpu/clock-cpg.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- 0001/arch/sh/include/asm/clock.h +++ work/arch/sh/include/asm/clock.h 2009-05-21 15:25:07.000000000 +0900 @@ -100,4 +100,20 @@ enum clk_sh_algo_id { IP_N1, }; +struct clk_cpg_div { + struct clk clk; + int id; +}; + +struct clk_cpg_div_group { + int *multipliers; + int *divisors; + int nr_entries; + int (*get_index)(struct clk_cpg_div *div); + void (*set_index)(struct clk_cpg_div *div, int index); +}; + +int clk_cpg_div_register(struct clk_cpg_div *div, + struct clk_cpg_div_group *group); + #endif /* __ASM_SH_CLOCK_H */ --- 0005/arch/sh/kernel/cpu/clock-cpg.c +++ work/arch/sh/kernel/cpu/clock-cpg.c 2009-05-21 15:25:01.000000000 +0900 @@ -2,6 +2,38 @@ #include #include +static unsigned long clk_cpg_div_recalc(struct clk *clk) +{ + struct clk_cpg_div_group *group = clk->priv; + struct clk_cpg_div *div; + unsigned long multiplier, divisor; + int index; + + div = (void *)((char *)clk - offsetof(struct clk_cpg_div, clk)); + index = group->get_index(div); + + BUG_ON(index >= group->nr_entries); + + multiplier = group->multipliers[index]; + divisor = group->divisors[index]; + + BUG_ON(!multiplier || !divisor); + + return clk->parent->rate * multiplier / divisor; +} + +static struct clk_ops clk_cpg_div_ops = { + .recalc = clk_cpg_div_recalc, +}; + +int clk_cpg_div_register(struct clk_cpg_div *div, + struct clk_cpg_div_group *group) +{ + div->clk.ops = &clk_cpg_div_ops; + div->clk.priv = group; + return clk_register(&div->clk); +} + #ifndef CONFIG_SH_CLK_DISABLE_LEGACY static struct clk master_clk = {