From patchwork Mon Sep 24 22:20:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murali Karicheri X-Patchwork-Id: 1500501 Return-Path: X-Original-To: patchwork-davinci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from comal.ext.ti.com (comal.ext.ti.com [198.47.26.152]) by patchwork1.kernel.org (Postfix) with ESMTP id 028D13FC71 for ; Mon, 24 Sep 2012 22:23:14 +0000 (UTC) Received: from dlelxv30.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id q8OMLsEw014364; Mon, 24 Sep 2012 17:21:54 -0500 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv30.itg.ti.com (8.13.8/8.13.8) with ESMTP id q8OMLs4L000528; Mon, 24 Sep 2012 17:21:54 -0500 Received: from dlelxv24.itg.ti.com (172.17.1.199) by dfle73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.1.323.3; Mon, 24 Sep 2012 17:21:54 -0500 Received: from linux.omap.com (dlelxs01.itg.ti.com [157.170.227.31]) by dlelxv24.itg.ti.com (8.13.8/8.13.8) with ESMTP id q8OMLsTI026209; Mon, 24 Sep 2012 17:21:54 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id 86F818062D; Mon, 24 Sep 2012 17:21:54 -0500 (CDT) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dlelxv30.itg.ti.com (dlelxv30.itg.ti.com [172.17.2.17]) by linux.omap.com (Postfix) with ESMTP id ECF838062B for ; Mon, 24 Sep 2012 17:20:16 -0500 (CDT) Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv30.itg.ti.com (8.13.8/8.13.8) with ESMTP id q8OMKGuK029222; Mon, 24 Sep 2012 17:20:16 -0500 Received: from dlelxv22.itg.ti.com (172.17.1.197) by dfle72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.1.323.3; Mon, 24 Sep 2012 17:20:16 -0500 Received: from ares-ubuntu.am.dhcp.ti.com (ares-ubuntu.am.dhcp.ti.com [158.218.103.17]) by dlelxv22.itg.ti.com (8.13.8/8.13.8) with ESMTP id q8OMKGpJ021634; Mon, 24 Sep 2012 17:20:16 -0500 Received: from a0868495 by ares-ubuntu.am.dhcp.ti.com with local (Exim 4.76) (envelope-from ) id 1TGH0i-0004xB-14; Mon, 24 Sep 2012 18:20:16 -0400 From: Murali Karicheri To: , , , , , , , , , , , , , , Subject: [PATCH v1 04/12] clk: davinci - common clk driver initialization Date: Mon, 24 Sep 2012 18:20:05 -0400 Message-ID: <1348525213-18987-5-git-send-email-m-karicheri2@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1348525213-18987-1-git-send-email-m-karicheri2@ti.com> References: <1348525213-18987-1-git-send-email-m-karicheri2@ti.com> MIME-Version: 1.0 X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: Errors-To: davinci-linux-open-source-bounces@linux.davincidsp.com This is the common clk driver initialization function for DaVinci SoCs and other SoCs that uses similar hardware architecture. Different clocks present in the SoC are passed to this function using a clk table and this function initialize the various drivers. Existing driver such as clk-fixed-rate, clk-divider, clk-mux and DaVinci specific clk drivers are initialized by this function. Also adds clock lookup for shared clocks used by various drivers. davinci-clock.h declares the various structures used for defining the DaVinci clocks. Signed-off-by: Murali Karicheri diff --git a/drivers/clk/davinci/davinci-clock.c b/drivers/clk/davinci/davinci-clock.c new file mode 100644 index 0000000..1addec3 --- /dev/null +++ b/drivers/clk/davinci/davinci-clock.c @@ -0,0 +1,220 @@ +/* + * Clock initialization code for DaVinci devices + * + * Copyright (C) 2006-2012 Texas Instruments. + * Copyright (C) 2008-2009 Deep Root Systems, LLC + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static DEFINE_SPINLOCK(_lock); + +struct clk *davinci_lookup_clk(struct davinci_clk_lookup *clocks, + const char *con_id) +{ + struct davinci_clk_lookup *c; + + for (c = clocks; c->_clk; c++) { + if (c->con_id && !strcmp(c->con_id, con_id)) + return c->clk; + } + return NULL; +} + +#ifdef CONFIG_CLK_DAVINCI_PLL +static void register_davinci_pll_clk(struct davinci_clk_lookup *c, + struct clk_davinci_pll_data *pll_data) +{ + + WARN_ON(!pll_data->phy_pllm); + pll_data->pllm = ioremap(pll_data->phy_pllm, 4); + WARN_ON(!pll_data->pllm); + if (pll_data->phy_prediv) { + pll_data->prediv = ioremap(pll_data->phy_prediv, 4); + WARN_ON(!pll_data->prediv); + } + if (pll_data->phy_postdiv) { + pll_data->postdiv = ioremap(pll_data->phy_postdiv, 4); + WARN_ON(!pll_data->postdiv); + } + c->clk = clk_register_davinci_pll(NULL, + c->_clk->name, c->_clk->parent->name, + pll_data); +} +#else +static void register_davinci_pll_clk(struct davinci_clk_lookup *c, + struct clk_davinci_pll_data *pll_data) +{ + return; +} +#endif + +#ifdef CONFIG_CLK_KEYSTONE_PLL +static void register_keystone_pll_clk(struct davinci_clk_lookup *c, + struct clk_keystone_pll_data *pll_data) +{ + WARN_ON(!pll_data->phy_pllm); + pll_data->pllm = ioremap(pll_data->phy_pllm, 4); + WARN_ON(!pll_data->pllm); + WARN_ON(!pll_data->phy_main_pll_ctl0); + pll_data->main_pll_ctl0 = + ioremap(pll_data->phy_main_pll_ctl0, 4); + WARN_ON(!pll_data->main_pll_ctl0); + c->clk = clk_register_keystone_pll(NULL, + c->_clk->name, c->_clk->parent->name, + pll_data); +} +#else +static void register_keystone_pll_clk(struct davinci_clk_lookup *c, + struct clk_keystone_pll_data *pll_data) +{ + return; +} +#endif + +int __init davinci_common_clk_init(struct davinci_clk_lookup *clocks, + struct davinci_dev_lookup *dev_clk_lookups, + u8 num_gpscs, u32 *psc_bases) +{ + void __iomem **base = NULL, *reg; + struct davinci_clk_lookup *c; + struct davinci_clk *_clk; + unsigned long rate; + int i, skip; + + WARN_ON(!num_gpscs); + WARN_ON(psc_bases == NULL); + + base = kzalloc(sizeof(void __iomem *) * num_gpscs, GFP_KERNEL); + WARN_ON(!base); + for (i = 0; i < num_gpscs; i++) { + base[i] = ioremap(psc_bases[i], SZ_4K); + WARN_ON(!base[i]); + } + + for (c = clocks; c->_clk; c++) { + skip = 0; + _clk = c->_clk; + + if (_clk->ref_clk_data) { + /* root node */ + struct clk_fixed_rate_data *ref_clk_dat = _clk->ref_clk_data; + + if (ref_clk_dat->recalc) + rate = ref_clk_dat->recalc(0); + else + rate = ref_clk_dat->rate; + + c->clk = clk_register_fixed_rate(NULL, _clk->name, + NULL, ref_clk_dat->flags, rate); + } else if (_clk->pll_data.main_pll) { + /* This is a PLL clock */ + if (_clk->pll_type == KEYSTONE_MAIN_PLL) + register_keystone_pll_clk(c, + _clk->pll_data.keystone); + else if (_clk->pll_type == DAVINCI_MAIN_PLL) + register_davinci_pll_clk(c, + _clk->pll_data.davinci); + else { + skip = 1; + pr_warn("Unknown PLL clock - %s\n", + _clk->name); + } + } else if (_clk->pll_div_data) { + struct clk_divider_data *pll_div_dat = + _clk->pll_div_data; + + /* This is a PLL derived clock with divider specified by + * div_reg in pll_div_data. + */ + reg = ioremap(pll_div_dat->div_reg, 4); + WARN_ON(!reg); + c->clk = clk_register_divider(NULL, _clk->name, + _clk->parent->name, pll_div_dat->flags, + reg, pll_div_dat->shift, + pll_div_dat->width, + pll_div_dat->divider_flags, &_lock); + } else if (_clk->psc_data) { + /* This is a PSC clock. */ + struct clk_davinci_psc_data *psc_data = _clk->psc_data; + + WARN_ON(!base); + WARN_ON(_clk->psc_data->gpsc >= num_gpscs); + psc_data->base = base[psc_data->gpsc]; + c->clk = clk_register_davinci_psc(NULL, _clk->name, + _clk->parent->name, _clk->psc_data, + &_lock); + } else if (_clk->mux_data) { + struct clk_mux_data *mx_data = _clk->mux_data; + + WARN_ON(!mx_data->phys_base); + reg = ioremap(mx_data->phys_base, 4); + WARN_ON(!reg); + c->clk = clk_register_mux(NULL, _clk->name, + mx_data->parents, mx_data->num_parents, + mx_data->flags, reg, mx_data->shift, + mx_data->width, mx_data->mux_flags, + &_lock); + } else if (_clk->fixed_factor_data) { + struct clk_fixed_factor_data *fixed_factor_data + = _clk->fixed_factor_data; + + WARN_ON(!fixed_factor_data->mult); + WARN_ON(!fixed_factor_data->div); + c->clk = clk_register_fixed_factor(NULL, _clk->name, + _clk->parent->name, + fixed_factor_data->flags, + fixed_factor_data->mult, + fixed_factor_data->div); + } else { + skip = 1; + pr_warn("Unknown clock - %s\n", _clk->name); + } + + if (!skip) { + WARN_ON(!c->clk); + if (clk_register_clkdev(c->clk, + c->con_id, c->dev_id) < 0) { + pr_err("Error in registering clkdev, %s\n", + _clk->name); + } + /* Enable ALWAYS_ENABLED clocks */ + if (_clk->flags & ALWAYS_ENABLED) + clk_prepare_enable(c->clk); + } + } + + if (dev_clk_lookups) { + struct davinci_dev_lookup *c; + struct clk *clk; + + for (c = dev_clk_lookups; c->con_id; c++) { + /* register the clock lookup table */ + clk = davinci_lookup_clk(clocks, c->con_id); + WARN_ON(!clk); + + for (i = 0; i < c->num_devs; i++) { + if (clk_register_clkdev(clk, + c->lookups[i].con_id, + c->lookups[i].dev_id) < 0) { + pr_err("Error in registering clkdev" \ + " for dev_id %s\n", + c->lookups[i].dev_id); + } + } + } + } + return 0; +} diff --git a/include/linux/platform_data/davinci-clock.h b/include/linux/platform_data/davinci-clock.h new file mode 100644 index 0000000..04e5e6d --- /dev/null +++ b/include/linux/platform_data/davinci-clock.h @@ -0,0 +1,137 @@ +/* + * TI DaVinci Clock definitions - Contains Macros and Types used for + * defining various clocks on a DaVinci SoC + * + * Copyright (C) 2012 Texas Instruments + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation version 2. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any + * kind, whether express or implied; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#ifndef __DAVINCI_CLOCK_H +#define __DAVINCI_CLOCK_H + +#include + +struct clk; + +#define CLK(dev, con, ck) \ + { \ + .dev_id = dev, \ + .con_id = con, \ + ._clk = ck, \ + } \ + +/* general flags: */ +#define ALWAYS_ENABLED BIT(0) + +/* configuration data for clk mux */ +struct clk_mux_data { + u32 flags; + u8 mux_flags; + u8 shift; + u8 width; + u8 num_parents; + const char **parents; + u32 phys_base; +}; + +/* configuration data for PLL divider clock */ +struct clk_divider_data { + u32 flags; + u8 divider_flags; + u32 div_reg; + unsigned long maxrate; /* H/W supported max rate */ + /* Width and shift for divider clock register mask */ + u8 shift; + u8 width; +}; + +/* configuration data for fixed factor clocks. Some clocks in DaVinci are just + * duplicate clock pins that can be represented by this using a factor of 1 + * for multiplier and divider + */ +struct clk_fixed_factor_data { + u32 flags; + u32 mult; + u32 div; +}; + +/* configuration data for fixed ref clock */ +struct clk_fixed_rate_data { + u32 flags; + unsigned long rate; + /* where a register has input clock rate settings this function + * is used to read that value from SoC specific code + */ + unsigned long (*recalc)(unsigned long parent_rate); +}; + +/* forward declaration for other clock drivers */ +struct clk_davinci_pll_data; +struct clk_keystone_pll_data; +struct clk_psc_data; + +enum pll_type { + DAVINCI_MAIN_PLL, + KEYSTONE_MAIN_PLL, +}; + +/* struct for defining DaVinci clocks for a SoC. Only one of the data ptr + * to be valid (non NULL). davinci_clk_init() in drivers/clk/davinci/clock.c + * check these ptr values to determine what clock register function to call + * to register a particular clock. + */ +struct davinci_clk { + const char *name; + /* General flag for all drivers */ + u32 flags; + struct davinci_clk *parent; + /* root ref clock data */ + struct clk_fixed_rate_data *ref_clk_data; + enum pll_type pll_type; + /* one of these will be present in each SoC */ + union { + struct clk_davinci_pll_data *davinci; + struct clk_keystone_pll_data *keystone; + void *main_pll; + } pll_data; + struct clk_divider_data *pll_div_data; + struct clk_davinci_psc_data *psc_data; + struct clk_mux_data *mux_data; + struct clk_fixed_factor_data *fixed_factor_data; +}; + +/* struct for the DaVinci clock tables. */ +struct davinci_clk_lookup { + const char *dev_id; + const char *con_id; + struct davinci_clk *_clk; + /* This saves the opaque clk ptr returned by clk_register() and is + * saved to use later to register clkdevs for a specific clk node. + */ + struct clk *clk; +}; + +/* struct for the DaVinci clkdev lookups. When several drivers uses the same + * clock, this structure is used to define a dev look up table that maps + * clkdevs to a clks node. + */ +struct davinci_dev_lookup { + const char *con_id; + unsigned short num_devs; + struct clk_lookup *lookups; +}; + +/* clock init function for a DaVinci SoC (defined in drivers/clk/clock.c). + * This can also be used on other TI SoCs that has similar clock hardware. + */ +extern int davinci_common_clk_init(struct davinci_clk_lookup *clocks, + struct davinci_dev_lookup *dev_lookups, + u8 num_gpscs, u32 *psc_bases); +#endif