Re: [PATCHv2 05/11] mxc: Core support for i.MX5 series of processors from Freescale

From: Eric Miao
Date: Wed Feb 03 2010 - 02:03:41 EST


On Tue, Feb 2, 2010 at 9:16 PM, Amit Kucheria
<amit.kucheria@xxxxxxxxxxxxx> wrote:
> From: Amit Kucheria <amit.kucheria@xxxxxxxxxxxxx>
>
> Add basic clock support, cpu identification, I/O mapping and serial port.
>
> Signed-off-by: Amit Kucheria <amit.kucheria@xxxxxxxxxxxxx>
> ---
> Âarch/arm/mach-mx5/clock.c          Â| Â848 ++++++++++++++++++++++++++
> Âarch/arm/mach-mx5/cpu.c           Â|  45 ++
> Âarch/arm/mach-mx5/crm_regs.h         | Â583 ++++++++++++++++++
> Âarch/arm/mach-mx5/devices.c         Â|  96 +++
> Âarch/arm/mach-mx5/devices.h         Â|  Â4 +
> Âarch/arm/mach-mx5/mm.c            |  88 +++
> Âarch/arm/plat-mxc/include/mach/common.h   Â|  Â1 +
> Âarch/arm/plat-mxc/include/mach/debug-macro.S | Â Â4 +-
> Âarch/arm/plat-mxc/include/mach/iomux-mx51.h Â| Â340 +++++++++++
> Âarch/arm/plat-mxc/include/mach/mx51.h    Â| Â454 ++++++++++++++
> Â10 files changed, 2461 insertions(+), 2 deletions(-)
> Âcreate mode 100644 arch/arm/mach-mx5/clock.c
> Âcreate mode 100644 arch/arm/mach-mx5/cpu.c
> Âcreate mode 100644 arch/arm/mach-mx5/crm_regs.h
> Âcreate mode 100644 arch/arm/mach-mx5/devices.c
> Âcreate mode 100644 arch/arm/mach-mx5/devices.h
> Âcreate mode 100644 arch/arm/mach-mx5/mm.c
> Âcreate mode 100644 arch/arm/plat-mxc/include/mach/iomux-mx51.h
> Âcreate mode 100644 arch/arm/plat-mxc/include/mach/mx51.h
>
> diff --git a/arch/arm/mach-mx5/clock.c b/arch/arm/mach-mx5/clock.c
> new file mode 100644
> index 0000000..595f966
> --- /dev/null
> +++ b/arch/arm/mach-mx5/clock.c
> @@ -0,0 +1,848 @@
> +/*
> + * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
> + * Copyright (C) 2009-2010 Amit Kucheria <amit.kucheria@xxxxxxxxxxxxx>
> + *
> + * The code contained herein is licensed under the GNU General Public
> + * License. You may obtain a copy of the GNU General Public License
> + * Version 2 or later at the following locations:
> + *
> + * http://www.opensource.org/licenses/gpl-license.html
> + * http://www.gnu.org/copyleft/gpl.html
> + */
> +
> +#include <linux/mm.h>
> +#include <linux/delay.h>
> +#include <linux/clk.h>
> +#include <linux/io.h>
> +
> +#include <asm/clkdev.h>
> +
> +#include <mach/hardware.h>
> +#include <mach/common.h>
> +#include <mach/clock.h>
> +
> +#include "crm_regs.h"
> +
> +static void __iomem *pll_base[] = {
> + Â Â Â MX51_DPLL1_BASE,
> + Â Â Â MX51_DPLL2_BASE,
> + Â Â Â MX51_DPLL3_BASE,
> +};
> +
> +/* External clock values passed-in by the board code */
> +static unsigned long external_high_reference, external_low_reference;
> +static unsigned long oscillator_reference, ckih2_reference;
> +
> +static struct clk osc_clk;
> +static struct clk pll1_main_clk;
> +static struct clk pll1_sw_clk;
> +static struct clk pll2_sw_clk;
> +static struct clk pll3_sw_clk;
> +static struct clk lp_apm_clk;
> +static struct clk periph_apm_clk;
> +static struct clk ahb_clk;
> +static struct clk ipg_clk;
> +
> +#define MAX_DPLL_WAIT_TRIES Â Â1000 /* 1000 * udelay(1) = 1ms */
> +
> +static int _clk_ccgr_enable(struct clk *clk)
> +{
> + Â Â Â u32 reg;
> +
> + Â Â Â reg = __raw_readl(clk->enable_reg);
> + Â Â Â reg |= MXC_CCM_CCGRx_MOD_ON << clk->enable_shift;
> + Â Â Â __raw_writel(reg, clk->enable_reg);
> +
> + Â Â Â return 0;
> +}
> +
> +static void _clk_ccgr_disable(struct clk *clk)
> +{
> + Â Â Â u32 reg;
> + Â Â Â reg = __raw_readl(clk->enable_reg);
> + Â Â Â reg &= ~(MXC_CCM_CCGRx_MOD_OFF << clk->enable_shift);
> + Â Â Â __raw_writel(reg, clk->enable_reg);
> +
> +}
> +
> +static void _clk_ccgr_disable_inwait(struct clk *clk)
> +{
> + Â Â Â u32 reg;
> +
> + Â Â Â reg = __raw_readl(clk->enable_reg);
> + Â Â Â reg &= ~(MXC_CCM_CCGRx_CG_MASK << clk->enable_shift);
> + Â Â Â reg |= MXC_CCM_CCGRx_MOD_IDLE << clk->enable_shift;
> + Â Â Â __raw_writel(reg, clk->enable_reg);
> +}
> +
> +/*
> + * For the 4-to-1 muxed input clock
> + */
> +static inline u32 _get_mux(struct clk *parent, struct clk *m0,
> + Â Â Â Â Â Â Â Â Â Â Â Â Âstruct clk *m1, struct clk *m2, struct clk *m3)
> +{
> + Â Â Â if (parent == m0)
> + Â Â Â Â Â Â Â return 0;
> + Â Â Â else if (parent == m1)
> + Â Â Â Â Â Â Â return 1;
> + Â Â Â else if (parent == m2)
> + Â Â Â Â Â Â Â return 2;
> + Â Â Â else if (parent == m3)
> + Â Â Â Â Â Â Â return 3;
> + Â Â Â else
> + Â Â Â Â Â Â Â BUG();
> +
> + Â Â Â return -EINVAL;
> +}
> +
> +static inline void __iomem *_get_pll_base(struct clk *pll)
> +{
> + Â Â Â if (pll == &pll1_main_clk)
> + Â Â Â Â Â Â Â return pll_base[0];
> + Â Â Â else if (pll == &pll2_sw_clk)
> + Â Â Â Â Â Â Â return pll_base[1];
> + Â Â Â else if (pll == &pll3_sw_clk)
> + Â Â Â Â Â Â Â return pll_base[2];
> + Â Â Â else
> + Â Â Â Â Â Â Â BUG();
> +
> + Â Â Â return NULL;
> +}
> +
> +static unsigned long clk_pll_get_rate(struct clk *clk)
> +{
> + Â Â Â long mfi, mfn, mfd, pdf, ref_clk, mfn_abs;
> + Â Â Â unsigned long dp_op, dp_mfd, dp_mfn, dp_ctl, pll_hfsm, dbl;
> + Â Â Â void __iomem *pllbase;
> + Â Â Â s64 temp;
> + Â Â Â unsigned long parent_rate;
> +
> + Â Â Â parent_rate = clk_get_rate(clk->parent);
> +
> + Â Â Â pllbase = _get_pll_base(clk);
> +
> + Â Â Â dp_ctl = __raw_readl(pllbase + MXC_PLL_DP_CTL);
> + Â Â Â pll_hfsm = dp_ctl & MXC_PLL_DP_CTL_HFSM;
> + Â Â Â dbl = dp_ctl & MXC_PLL_DP_CTL_DPDCK0_2_EN;
> +
> + Â Â Â if (pll_hfsm == 0) {
> + Â Â Â Â Â Â Â dp_op = __raw_readl(pllbase + MXC_PLL_DP_OP);
> + Â Â Â Â Â Â Â dp_mfd = __raw_readl(pllbase + MXC_PLL_DP_MFD);
> + Â Â Â Â Â Â Â dp_mfn = __raw_readl(pllbase + MXC_PLL_DP_MFN);
> + Â Â Â } else {
> + Â Â Â Â Â Â Â dp_op = __raw_readl(pllbase + MXC_PLL_DP_HFS_OP);
> + Â Â Â Â Â Â Â dp_mfd = __raw_readl(pllbase + MXC_PLL_DP_HFS_MFD);
> + Â Â Â Â Â Â Â dp_mfn = __raw_readl(pllbase + MXC_PLL_DP_HFS_MFN);
> + Â Â Â }
> + Â Â Â pdf = dp_op & MXC_PLL_DP_OP_PDF_MASK;
> + Â Â Â mfi = (dp_op & MXC_PLL_DP_OP_MFI_MASK) >> MXC_PLL_DP_OP_MFI_OFFSET;
> + Â Â Â mfi = (mfi <= 5) ? 5 : mfi;
> + Â Â Â mfd = dp_mfd & MXC_PLL_DP_MFD_MASK;
> + Â Â Â mfn = mfn_abs = dp_mfn & MXC_PLL_DP_MFN_MASK;
> + Â Â Â /* Sign extend to 32-bits */
> + Â Â Â if (mfn >= 0x04000000) {
> + Â Â Â Â Â Â Â mfn |= 0xFC000000;
> + Â Â Â Â Â Â Â mfn_abs = -mfn;
> + Â Â Â }
> +
> + Â Â Â ref_clk = 2 * parent_rate;
> + Â Â Â if (dbl != 0)
> + Â Â Â Â Â Â Â ref_clk *= 2;
> +
> + Â Â Â ref_clk /= (pdf + 1);
> + Â Â Â temp = (u64) ref_clk * mfn_abs;
> + Â Â Â do_div(temp, mfd + 1);
> + Â Â Â if (mfn < 0)
> + Â Â Â Â Â Â Â temp = -temp;
> + Â Â Â temp = (ref_clk * mfi) + temp;
> +
> + Â Â Â return temp;
> +}
> +
> +static int _clk_pll_set_rate(struct clk *clk, unsigned long rate)
> +{
> + Â Â Â u32 reg;
> + Â Â Â void __iomem *pllbase;
> +
> + Â Â Â long mfi, pdf, mfn, mfd = 999999;
> + Â Â Â s64 temp64;
> + Â Â Â unsigned long quad_parent_rate;
> + Â Â Â unsigned long pll_hfsm, dp_ctl;
> + Â Â Â unsigned long parent_rate;
> +
> + Â Â Â parent_rate = clk_get_rate(clk->parent);
> +
> + Â Â Â pllbase = _get_pll_base(clk);
> +
> + Â Â Â quad_parent_rate = 4 * parent_rate;
> + Â Â Â pdf = mfi = -1;
> + Â Â Â while (++pdf < 16 && mfi < 5)
> + Â Â Â Â Â Â Â mfi = rate * (pdf+1) / quad_parent_rate;
> + Â Â Â if (mfi > 15)
> + Â Â Â Â Â Â Â return -1;
> + Â Â Â pdf--;
> +
> + Â Â Â temp64 = rate * (pdf+1) - quad_parent_rate * mfi;
> + Â Â Â do_div(temp64, quad_parent_rate/1000000);
> + Â Â Â mfn = (long)temp64;
> +
> + Â Â Â dp_ctl = __raw_readl(pllbase + MXC_PLL_DP_CTL);
> + Â Â Â /* use dpdck0_2 */
> + Â Â Â __raw_writel(dp_ctl | 0x1000L, pllbase + MXC_PLL_DP_CTL);
> + Â Â Â pll_hfsm = dp_ctl & MXC_PLL_DP_CTL_HFSM;
> + Â Â Â if (pll_hfsm == 0) {
> + Â Â Â Â Â Â Â reg = mfi << 4 | pdf;
> + Â Â Â Â Â Â Â __raw_writel(reg, pllbase + MXC_PLL_DP_OP);
> + Â Â Â Â Â Â Â __raw_writel(mfd, pllbase + MXC_PLL_DP_MFD);
> + Â Â Â Â Â Â Â __raw_writel(mfn, pllbase + MXC_PLL_DP_MFN);
> + Â Â Â } else {
> + Â Â Â Â Â Â Â reg = mfi << 4 | pdf;
> + Â Â Â Â Â Â Â __raw_writel(reg, pllbase + MXC_PLL_DP_HFS_OP);
> + Â Â Â Â Â Â Â __raw_writel(mfd, pllbase + MXC_PLL_DP_HFS_MFD);
> + Â Â Â Â Â Â Â __raw_writel(mfn, pllbase + MXC_PLL_DP_HFS_MFN);
> + Â Â Â }
> +
> + Â Â Â return 0;
> +}
> +
> +static int _clk_pll_enable(struct clk *clk)
> +{
> + Â Â Â u32 reg;
> + Â Â Â void __iomem *pllbase;
> + Â Â Â int i = 0;
> +
> + Â Â Â pllbase = _get_pll_base(clk);
> + Â Â Â reg = __raw_readl(pllbase + MXC_PLL_DP_CTL) | MXC_PLL_DP_CTL_UPEN;
> + Â Â Â __raw_writel(reg, pllbase + MXC_PLL_DP_CTL);
> +
> + Â Â Â /* Wait for lock */
> + Â Â Â while ((!(__raw_readl(pllbase + MXC_PLL_DP_CTL) & MXC_PLL_DP_CTL_LRF))
> + Â Â Â Â Â Â Â && i < MAX_DPLL_WAIT_TRIES) {
> + Â Â Â Â Â Â Â i++;
> + Â Â Â Â Â Â Â udelay(1);
> + Â Â Â }


Mmm... this really hurts my eyes:


do {
v = __raw_readl(pllbase + MXC_PLL_DP_CTL)
if (v & MXC_PLL_DP_CTL_LRF)
break;

udelay(1);
} while (++i < MAX_DPLL_WAIT_TRIES);

> +
> + Â Â Â if (i == MAX_DPLL_WAIT_TRIES) {
> + Â Â Â Â Â Â Â printk(KERN_ERR "MX5: pll locking failed\n");
> + Â Â Â Â Â Â Â return -EINVAL;
> + Â Â Â }
> +
> + Â Â Â return 0;
> +}
> +
> +static void _clk_pll_disable(struct clk *clk)
> +{
> + Â Â Â u32 reg;
> + Â Â Â void __iomem *pllbase;
> +
> + Â Â Â pllbase = _get_pll_base(clk);
> + Â Â Â reg = __raw_readl(pllbase + MXC_PLL_DP_CTL) & ~MXC_PLL_DP_CTL_UPEN;
> + Â Â Â __raw_writel(reg, pllbase + MXC_PLL_DP_CTL);
> +}
> +
> +static int _clk_pll1_sw_set_parent(struct clk *clk, struct clk *parent)
> +{
> + Â Â Â u32 reg;
> +
> + Â Â Â reg = __raw_readl(MXC_CCM_CCSR);
> +
> + Â Â Â /* When switching from pll_main_clk to a bypass clock, first select a
> + Â Â Â Â Âmultiplexed clock in 'step_sel', then shift the glitchless mux
> + Â Â Â Â Â'pll1_sw_clk_sel'.
> + Â Â Â Â ÂWhen switching back, do it in reverse order
> + Â Â Â */

comment style ... not sure if this leaks apw's checkscripts, heh :)

> + Â Â Â if (parent == &pll1_main_clk) {
> + Â Â Â Â Â Â Â /* Switch to pll1_main_clk */
> + Â Â Â Â Â Â Â reg &= ~MXC_CCM_CCSR_PLL1_SW_CLK_SEL;
> + Â Â Â Â Â Â Â __raw_writel(reg, MXC_CCM_CCSR);
> + Â Â Â Â Â Â Â /* step_clk mux switched to lp_apm, to save power. */
> + Â Â Â Â Â Â Â reg = __raw_readl(MXC_CCM_CCSR);
> + Â Â Â Â Â Â Â reg = (reg & ~MXC_CCM_CCSR_STEP_SEL_MASK) |
> + Â Â Â Â Â Â Â Â Â Â Â (MXC_CCM_CCSR_STEP_SEL_LP_APM <<
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MXC_CCM_CCSR_STEP_SEL_OFFSET);
> + Â Â Â } else {
> + Â Â Â Â Â Â Â if (parent == &lp_apm_clk) {
> + Â Â Â Â Â Â Â Â Â Â Â reg = (reg & ~MXC_CCM_CCSR_STEP_SEL_MASK) |
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (MXC_CCM_CCSR_STEP_SEL_LP_APM <<
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MXC_CCM_CCSR_STEP_SEL_OFFSET);
> + Â Â Â Â Â Â Â } else Âif (parent == &pll2_sw_clk) {
> + Â Â Â Â Â Â Â Â Â Â Â reg = (reg & ~MXC_CCM_CCSR_STEP_SEL_MASK) |
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (MXC_CCM_CCSR_STEP_SEL_PLL2_DIVIDED <<
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MXC_CCM_CCSR_STEP_SEL_OFFSET);
> + Â Â Â Â Â Â Â } else Âif (parent == &pll3_sw_clk) {
> + Â Â Â Â Â Â Â Â Â Â Â reg = (reg & ~MXC_CCM_CCSR_STEP_SEL_MASK) |
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (MXC_CCM_CCSR_STEP_SEL_PLL3_DIVIDED <<
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MXC_CCM_CCSR_STEP_SEL_OFFSET);
> + Â Â Â Â Â Â Â } else
> + Â Â Â Â Â Â Â Â Â Â Â return -EINVAL;

Again, hurts my eyes:

if (...)
step = MXC_CCM_CCSR_STEP_SEL_LP_APM;
else if (...)
step = MXC_CCM_CCSR_STEP_SEL_PLL2_DIVIDED;
else if (...)
step = ...

reg &= ~MXC_CCM_CCSR_STEP_SEL_MASK;
reg |= step << MXC_CCM_CCSR_STEP_SEL_OFFSET;
...

> +
> + Â Â Â Â Â Â Â __raw_writel(reg, MXC_CCM_CCSR);
> + Â Â Â Â Â Â Â /* Switch to step_clk */
> + Â Â Â Â Â Â Â reg = __raw_readl(MXC_CCM_CCSR);
> + Â Â Â Â Â Â Â reg |= MXC_CCM_CCSR_PLL1_SW_CLK_SEL;
> + Â Â Â }
> + Â Â Â __raw_writel(reg, MXC_CCM_CCSR);
> + Â Â Â return 0;
> +}
> +
> +static unsigned long clk_pll1_sw_get_rate(struct clk *clk)
> +{
> + Â Â Â u32 reg, div;
> + Â Â Â unsigned long parent_rate;
> +
> + Â Â Â parent_rate = clk_get_rate(clk->parent);
> +
> + Â Â Â div = 1;
> + Â Â Â reg = __raw_readl(MXC_CCM_CCSR);
> +
> + Â Â Â if (clk->parent == &pll2_sw_clk) {
> + Â Â Â Â Â Â Â div = ((reg & MXC_CCM_CCSR_PLL2_PODF_MASK) >>
> + Â Â Â Â Â Â Â Â Â Â ÂMXC_CCM_CCSR_PLL2_PODF_OFFSET) + 1;
> + Â Â Â } else if (clk->parent == &pll3_sw_clk) {
> + Â Â Â Â Â Â Â div = ((reg & MXC_CCM_CCSR_PLL3_PODF_MASK) >>
> + Â Â Â Â Â Â Â Â Â Â ÂMXC_CCM_CCSR_PLL3_PODF_OFFSET) + 1;
> + Â Â Â }
> + Â Â Â return parent_rate / div;
> +}
> +
> +static int _clk_pll2_sw_set_parent(struct clk *clk, struct clk *parent)
> +{
> + Â Â Â u32 reg;
> +
> + Â Â Â reg = __raw_readl(MXC_CCM_CCSR);
> +
> + Â Â Â if (parent == &pll2_sw_clk)
> + Â Â Â Â Â Â Â reg &= ~MXC_CCM_CCSR_PLL2_SW_CLK_SEL;
> + Â Â Â else
> + Â Â Â Â Â Â Â reg |= MXC_CCM_CCSR_PLL2_SW_CLK_SEL;
> +
> + Â Â Â __raw_writel(reg, MXC_CCM_CCSR);
> + Â Â Â return 0;
> +}
> +
> +static int _clk_lp_apm_set_parent(struct clk *clk, struct clk *parent)
> +{
> + Â Â Â u32 reg;
> +
> + Â Â Â if (parent == &osc_clk)
> + Â Â Â Â Â Â Â reg = __raw_readl(MXC_CCM_CCSR) & ~MXC_CCM_CCSR_LP_APM_SEL;
> + Â Â Â else
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â __raw_writel(reg, MXC_CCM_CCSR);
> +
> + Â Â Â return 0;
> +}
> +
> +static unsigned long clk_arm_get_rate(struct clk *clk)
> +{
> + Â Â Â u32 cacrr, div;
> + Â Â Â unsigned long parent_rate;
> +
> + Â Â Â parent_rate = clk_get_rate(clk->parent);
> + Â Â Â cacrr = __raw_readl(MXC_CCM_CACRR);
> + Â Â Â div = (cacrr & MXC_CCM_CACRR_ARM_PODF_MASK) + 1;
> +
> + Â Â Â return parent_rate / div;
> +}
> +
> +static int _clk_periph_apm_set_parent(struct clk *clk, struct clk *parent)
> +{
> + Â Â Â u32 reg, mux;
> + Â Â Â int i = 0;
> +
> + Â Â Â mux = _get_mux(parent, &pll1_sw_clk, &pll3_sw_clk, &lp_apm_clk, NULL);
> +
> + Â Â Â reg = __raw_readl(MXC_CCM_CBCMR) & ~MXC_CCM_CBCMR_PERIPH_CLK_SEL_MASK;
> + Â Â Â reg |= mux << MXC_CCM_CBCMR_PERIPH_CLK_SEL_OFFSET;
> + Â Â Â __raw_writel(reg, MXC_CCM_CBCMR);
> +
> + Â Â Â /* Wait for lock */
> + Â Â Â while ((__raw_readl(MXC_CCM_CDHIPR) & MXC_CCM_CDHIPR_PERIPH_CLK_SEL_BUSY)
> + Â Â Â Â Â Â Â && i < MAX_DPLL_WAIT_TRIES) {
> + Â Â Â Â Â Â Â i++;
> + Â Â Â Â Â Â Â udelay(1);
> + Â Â Â }
> +
> + Â Â Â if (i == MAX_DPLL_WAIT_TRIES) {
> + Â Â Â Â Â Â Â printk(KERN_ERR "MX5: Set parent for periph_apm clock failed\n");
> + Â Â Â Â Â Â Â return -EINVAL;
> + Â Â Â }
> +
> + Â Â Â return 0;
> +}
> +
> +static unsigned long clk_main_bus_get_rate(struct clk *clk)
> +{
> + Â Â Â return clk_get_rate(clk->parent);
> +}
> +
> +static int _clk_main_bus_set_parent(struct clk *clk, struct clk *parent)
> +{
> + Â Â Â u32 reg;
> +
> + Â Â Â reg = __raw_readl(MXC_CCM_CBCDR);
> +
> + Â Â Â if (parent == &pll2_sw_clk)
> + Â Â Â Â Â Â Â reg &= ~MXC_CCM_CBCDR_PERIPH_CLK_SEL;
> + Â Â Â else if (parent == &periph_apm_clk)
> + Â Â Â Â Â Â Â reg |= MXC_CCM_CBCDR_PERIPH_CLK_SEL;
> + Â Â Â else
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â __raw_writel(reg, MXC_CCM_CBCDR);
> +
> + Â Â Â return 0;
> +}
> +
> +static struct clk main_bus_clk = {
> + Â Â Â .parent = &pll2_sw_clk,
> + Â Â Â .set_parent = _clk_main_bus_set_parent,
> + Â Â Â .get_rate = clk_main_bus_get_rate,
> +};
> +
> +static unsigned long clk_ahb_get_rate(struct clk *clk)
> +{
> + Â Â Â u32 reg, div;
> + Â Â Â unsigned long parent_rate;
> +
> + Â Â Â parent_rate = clk_get_rate(clk->parent);
> +
> + Â Â Â reg = __raw_readl(MXC_CCM_CBCDR);
> + Â Â Â div = ((reg & MXC_CCM_CBCDR_AHB_PODF_MASK) >>
> + Â Â Â Â Â Â ÂMXC_CCM_CBCDR_AHB_PODF_OFFSET) + 1;
> + Â Â Â return parent_rate / div;
> +}
> +
> +
> +static int _clk_ahb_set_rate(struct clk *clk, unsigned long rate)
> +{
> + Â Â Â u32 reg, div;
> + Â Â Â unsigned long parent_rate;
> + Â Â Â int i = 0;
> +
> + Â Â Â parent_rate = clk_get_rate(clk->parent);
> +
> + Â Â Â div = parent_rate / rate;
> + Â Â Â if (div > 8 || div < 1 || ((parent_rate / div) != rate))
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â reg = __raw_readl(MXC_CCM_CBCDR);
> + Â Â Â reg &= ~MXC_CCM_CBCDR_AHB_PODF_MASK;
> + Â Â Â reg |= (div - 1) << MXC_CCM_CBCDR_AHB_PODF_OFFSET;
> + Â Â Â __raw_writel(reg, MXC_CCM_CBCDR);
> +
> + Â Â Â /* Wait for lock */
> + Â Â Â while ((__raw_readl(MXC_CCM_CDHIPR) & MXC_CCM_CDHIPR_AHB_PODF_BUSY)
> + Â Â Â Â Â Â Â && i < MAX_DPLL_WAIT_TRIES) {
> + Â Â Â Â Â Â Â i++;
> + Â Â Â Â Â Â Â udelay(1);
> + Â Â Â }

Provided this loop sequence appears so many times here, maybe we can just
invent a static inline function for this, e.g. dpll_wait_flags(register, flags)

> +
> + Â Â Â if (i == MAX_DPLL_WAIT_TRIES) {
> + Â Â Â Â Â Â Â printk(KERN_ERR "MX5: clk_ahb_set_rate failed\n");
> + Â Â Â Â Â Â Â return -EINVAL;
> + Â Â Â }
> +
> + Â Â Â return 0;
> +}
> +
> +static unsigned long _clk_ahb_round_rate(struct clk *clk,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â unsigned long rate)
> +{
> + Â Â Â u32 div;
> + Â Â Â unsigned long parent_rate;
> +
> + Â Â Â parent_rate = clk_get_rate(clk->parent);
> +
> + Â Â Â div = parent_rate / rate;
> + Â Â Â if (div > 8)
> + Â Â Â Â Â Â Â div = 8;
> + Â Â Â else if (div == 0)
> + Â Â Â Â Â Â Â div++;
> + Â Â Â return parent_rate / div;
> +}
> +
> +
> +static int _clk_max_enable(struct clk *clk)
> +{
> + Â Â Â u32 reg;
> +
> + Â Â Â _clk_ccgr_enable(clk);
> +
> + Â Â Â /* Handshake with MAX when LPM is entered. */
> + Â Â Â reg = __raw_readl(MXC_CCM_CLPCR);
> + Â Â Â reg &= ~MXC_CCM_CLPCR_BYPASS_MAX_LPM_HS;
> + Â Â Â __raw_writel(reg, MXC_CCM_CLPCR);
> +
> + Â Â Â return 0;
> +}
> +
> +static void _clk_max_disable(struct clk *clk)
> +{
> + Â Â Â u32 reg;
> +
> + Â Â Â _clk_ccgr_disable_inwait(clk);
> +
> + Â Â Â /* No Handshake with MAX when LPM is entered as its disabled. */
> + Â Â Â reg = __raw_readl(MXC_CCM_CLPCR);
> + Â Â Â reg |= MXC_CCM_CLPCR_BYPASS_MAX_LPM_HS;
> + Â Â Â __raw_writel(reg, MXC_CCM_CLPCR);
> +}
> +
> +static unsigned long clk_ipg_get_rate(struct clk *clk)
> +{
> + Â Â Â u32 reg, div;
> + Â Â Â unsigned long parent_rate;
> +
> + Â Â Â parent_rate = clk_get_rate(clk->parent);
> +
> + Â Â Â reg = __raw_readl(MXC_CCM_CBCDR);
> + Â Â Â div = ((reg & MXC_CCM_CBCDR_IPG_PODF_MASK) >>
> + Â Â Â Â Â Â ÂMXC_CCM_CBCDR_IPG_PODF_OFFSET) + 1;
> +
> + Â Â Â return parent_rate / div;
> +}
> +
> +static unsigned long clk_ipg_per_get_rate(struct clk *clk)
> +{
> + Â Â Â u32 reg, prediv1, prediv2, podf;
> + Â Â Â unsigned long parent_rate;
> +
> + Â Â Â parent_rate = clk_get_rate(clk->parent);
> +
> + Â Â Â if (clk->parent == &main_bus_clk || clk->parent == &lp_apm_clk) {
> + Â Â Â Â Â Â Â /* the main_bus_clk is the one before the DVFS engine */
> + Â Â Â Â Â Â Â reg = __raw_readl(MXC_CCM_CBCDR);
> + Â Â Â Â Â Â Â prediv1 = ((reg & MXC_CCM_CBCDR_PERCLK_PRED1_MASK) >>
> + Â Â Â Â Â Â Â Â Â Â Â Â ÂMXC_CCM_CBCDR_PERCLK_PRED1_OFFSET) + 1;
> + Â Â Â Â Â Â Â prediv2 = ((reg & MXC_CCM_CBCDR_PERCLK_PRED2_MASK) >>
> + Â Â Â Â Â Â Â Â Â Â Â Â ÂMXC_CCM_CBCDR_PERCLK_PRED2_OFFSET) + 1;
> + Â Â Â Â Â Â Â podf = ((reg & MXC_CCM_CBCDR_PERCLK_PODF_MASK) >>
> + Â Â Â Â Â Â Â Â Â Â Â MXC_CCM_CBCDR_PERCLK_PODF_OFFSET) + 1;
> + Â Â Â Â Â Â Â return parent_rate / (prediv1 * prediv2 * podf);
> + Â Â Â } else if (clk->parent == &ipg_clk) {
> + Â Â Â Â Â Â Â return parent_rate;

unnecessary braces

> + Â Â Â } else {
> + Â Â Â Â Â Â Â BUG();

ditto

> + Â Â Â }
> +}
> +
> +static int _clk_ipg_per_set_parent(struct clk *clk, struct clk *parent)
> +{
> + Â Â Â u32 reg;
> +
> + Â Â Â reg = __raw_readl(MXC_CCM_CBCMR);
> +
> + Â Â Â reg &= ~MXC_CCM_CBCMR_PERCLK_LP_APM_CLK_SEL;
> + Â Â Â reg &= ~MXC_CCM_CBCMR_PERCLK_IPG_CLK_SEL;
> +
> + Â Â Â if (parent == &ipg_clk)
> + Â Â Â Â Â Â Â reg |= MXC_CCM_CBCMR_PERCLK_IPG_CLK_SEL;
> + Â Â Â else if (parent == &lp_apm_clk)
> + Â Â Â Â Â Â Â reg |= MXC_CCM_CBCMR_PERCLK_LP_APM_CLK_SEL;
> + Â Â Â else if (parent != &main_bus_clk)
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â __raw_writel(reg, MXC_CCM_CBCMR);
> +
> + Â Â Â return 0;
> +}
> +
> +static unsigned long clk_uart_get_rate(struct clk *clk)
> +{
> + Â Â Â u32 reg, prediv, podf;
> + Â Â Â unsigned long parent_rate;
> +
> + Â Â Â parent_rate = clk_get_rate(clk->parent);
> +
> + Â Â Â reg = __raw_readl(MXC_CCM_CSCDR1);
> + Â Â Â prediv = ((reg & MXC_CCM_CSCDR1_UART_CLK_PRED_MASK) >>
> + Â Â Â Â Â Â Â Â MXC_CCM_CSCDR1_UART_CLK_PRED_OFFSET) + 1;
> + Â Â Â podf = ((reg & MXC_CCM_CSCDR1_UART_CLK_PODF_MASK) >>
> + Â Â Â Â Â Â Â MXC_CCM_CSCDR1_UART_CLK_PODF_OFFSET) + 1;
> +
> + Â Â Â return parent_rate / (prediv * podf);
> +}
> +
> +static int _clk_uart_set_parent(struct clk *clk, struct clk *parent)
> +{
> + Â Â Â u32 reg, mux;
> +
> + Â Â Â mux = _get_mux(parent, &pll1_sw_clk, &pll2_sw_clk, &pll3_sw_clk,
> + Â Â Â Â Â Â Â Â Â Â Â&lp_apm_clk);
> + Â Â Â reg = __raw_readl(MXC_CCM_CSCMR1) & ~MXC_CCM_CSCMR1_UART_CLK_SEL_MASK;
> + Â Â Â reg |= mux << MXC_CCM_CSCMR1_UART_CLK_SEL_OFFSET;
> + Â Â Â __raw_writel(reg, MXC_CCM_CSCMR1);
> +
> + Â Â Â return 0;
> +}
> +
> +static unsigned long get_high_reference_clock_rate(struct clk *clk)
> +{
> + Â Â Â return external_high_reference;
> +}
> +
> +static unsigned long get_low_reference_clock_rate(struct clk *clk)
> +{
> + Â Â Â return external_low_reference;
> +}
> +
> +static unsigned long get_oscillator_reference_clock_rate(struct clk *clk)
> +{
> + Â Â Â return oscillator_reference;
> +}
> +
> +static unsigned long get_ckih2_reference_clock_rate(struct clk *clk)
> +{
> + Â Â Â return ckih2_reference;
> +}
> +
> +/* External high frequency clock */
> +static struct clk ckih_clk = {
> + Â Â Â .get_rate = get_high_reference_clock_rate,
> +};
> +
> +static struct clk ckih2_clk = {
> + Â Â Â .get_rate = get_ckih2_reference_clock_rate,
> +};
> +
> +static struct clk osc_clk = {
> + Â Â Â .get_rate = get_oscillator_reference_clock_rate,
> +};
> +
> +/* External low frequency (32kHz) clock */
> +static struct clk ckil_clk = {
> + Â Â Â .get_rate = get_low_reference_clock_rate,
> +};

That's why Jerremy is coming up with a clk_fixed, to address exactly such
awkward situations :)

> +
> +static struct clk pll1_main_clk = {
> + Â Â Â .parent = &osc_clk,
> + Â Â Â .get_rate = clk_pll_get_rate,
> + Â Â Â .enable = _clk_pll_enable,
> + Â Â Â .disable = _clk_pll_disable,
> +};
> +
> +/* Clock tree block diagram (WIP):
> + * Â Â CCM: Clock Controller Module
> + *
> + * PLL output -> |
> + * Â Â Â Â Â Â Â | CCM Switcher -> CCM_CLK_ROOT_GEN ->
> + * PLL bypass -> |
> + *
> + */
> +
> +/* PLL1 SW supplies to ARM core */
> +static struct clk pll1_sw_clk = {
> + Â Â Â .parent = &pll1_main_clk,
> + Â Â Â .set_parent = _clk_pll1_sw_set_parent,
> + Â Â Â .get_rate = clk_pll1_sw_get_rate,
> +};
> +
> +/* PLL2 SW supplies to AXI/AHB/IP buses */
> +static struct clk pll2_sw_clk = {
> + Â Â Â .parent = &osc_clk,
> + Â Â Â .get_rate = clk_pll_get_rate,
> + Â Â Â .set_rate = _clk_pll_set_rate,
> + Â Â Â .set_parent = _clk_pll2_sw_set_parent,
> + Â Â Â .enable = _clk_pll_enable,
> + Â Â Â .disable = _clk_pll_disable,
> +};
> +
> +/* PLL3 SW supplies to serial clocks like USB, SSI, etc. */
> +static struct clk pll3_sw_clk = {
> + Â Â Â .parent = &osc_clk,
> + Â Â Â .set_rate = _clk_pll_set_rate,
> + Â Â Â .get_rate = clk_pll_get_rate,
> + Â Â Â .enable = _clk_pll_enable,
> + Â Â Â .disable = _clk_pll_disable,
> +};
> +
> +/* Low-power Audio Playback Mode clock */
> +static struct clk lp_apm_clk = {
> + Â Â Â .parent = &osc_clk,
> + Â Â Â .set_parent = _clk_lp_apm_set_parent,
> +};
> +
> +static struct clk periph_apm_clk = {
> + Â Â Â .parent = &pll1_sw_clk,
> + Â Â Â .set_parent = _clk_periph_apm_set_parent,
> +};
> +
> +static struct clk cpu_clk = {
> + Â Â Â .parent = &pll1_sw_clk,
> + Â Â Â .get_rate = clk_arm_get_rate,
> +};
> +
> +static struct clk ahb_clk = {
> + Â Â Â .parent = &main_bus_clk,
> + Â Â Â .get_rate = clk_ahb_get_rate,
> + Â Â Â .set_rate = _clk_ahb_set_rate,
> + Â Â Â .round_rate = _clk_ahb_round_rate,
> +};
> +
> +/* Main IP interface clock for access to registers */
> +static struct clk ipg_clk = {
> + Â Â Â .parent = &ahb_clk,
> + Â Â Â .get_rate = clk_ipg_get_rate,
> +};
> +
> +static struct clk ipg_perclk = {
> + Â Â Â .parent = &lp_apm_clk,
> + Â Â Â .get_rate = clk_ipg_per_get_rate,
> + Â Â Â .set_parent = _clk_ipg_per_set_parent,
> +};
> +
> +static struct clk uart_root_clk = {
> + Â Â Â .parent = &pll2_sw_clk,
> + Â Â Â .get_rate = clk_uart_get_rate,
> + Â Â Â .set_parent = _clk_uart_set_parent,
> +};
> +
> +static struct clk ahb_max_clk = {
> + Â Â Â .parent = &ahb_clk,
> + Â Â Â .enable_reg = MXC_CCM_CCGR0,
> + Â Â Â .enable_shift = MXC_CCM_CCGRx_CG14_OFFSET,
> + Â Â Â .enable = _clk_max_enable,
> + Â Â Â .disable = _clk_max_disable,
> +};
> +
> +static struct clk aips_tz1_clk = {
> + Â Â Â .parent = &ahb_clk,
> + Â Â Â .secondary = &ahb_max_clk,
> + Â Â Â .enable_reg = MXC_CCM_CCGR0,
> + Â Â Â .enable_shift = MXC_CCM_CCGRx_CG12_OFFSET,
> + Â Â Â .enable = _clk_ccgr_enable,
> + Â Â Â .disable = _clk_ccgr_disable_inwait,
> +};
> +
> +static struct clk aips_tz2_clk = {
> + Â Â Â .parent = &ahb_clk,
> + Â Â Â .secondary = &ahb_max_clk,
> + Â Â Â .enable_reg = MXC_CCM_CCGR0,
> + Â Â Â .enable_shift = MXC_CCM_CCGRx_CG13_OFFSET,
> + Â Â Â .enable = _clk_ccgr_enable,
> + Â Â Â .disable = _clk_ccgr_disable_inwait,
> +};
> +
> +static struct clk gpt_32k_clk = {
> + Â Â Â .id = 0,
> + Â Â Â .parent = &ckil_clk,
> +};
> +
> +#define DEFINE_CLOCK(name, i, er, es, gr, sr, p, s) Â Â\
> + Â Â Â static struct clk name = { Â Â Â Â Â Â Â Â Â Â Â\
> +        .id       = i,          Â\
> +        .enable_reg   = er,          \
> +        .enable_shift  = es,          \
> +        .get_rate    = gr,          \
> +        .set_rate    = sr,          \
> +        .enable     = _clk_ccgr_enable,   \
> +        .disable    Â= _clk_ccgr_disable,  Â\
> +        .parent     = p,          Â\
> +        .secondary   Â= s,          Â\
> + Â Â Â }
> +
> +/* DEFINE_CLOCK(name, id, enable_reg, enable_shift,
> + Â get_rate, set_rate, parent, secondary); */
> +
> +/* Shared peripheral bus arbiter */
> +DEFINE_CLOCK(spba_clk, 0, MXC_CCM_CCGR5, MXC_CCM_CCGRx_CG0_OFFSET,
> + Â Â Â NULL, ÂNULL, &ipg_clk, NULL);
> +
> +/* UART */
> +DEFINE_CLOCK(uart1_clk, 0, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG4_OFFSET,
> + Â Â Â NULL, ÂNULL, &uart_root_clk, NULL);
> +DEFINE_CLOCK(uart2_clk, 1, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG6_OFFSET,
> + Â Â Â NULL, ÂNULL, &uart_root_clk, NULL);
> +DEFINE_CLOCK(uart3_clk, 2, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG8_OFFSET,
> + Â Â Â NULL, ÂNULL, &uart_root_clk, NULL);
> +DEFINE_CLOCK(uart1_ipg_clk, 0, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG3_OFFSET,
> + Â Â Â NULL, ÂNULL, &ipg_clk, &aips_tz1_clk);
> +DEFINE_CLOCK(uart2_ipg_clk, 1, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG5_OFFSET,
> + Â Â Â NULL, ÂNULL, &ipg_clk, &aips_tz1_clk);
> +DEFINE_CLOCK(uart3_ipg_clk, 2, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG7_OFFSET,
> + Â Â Â NULL, ÂNULL, &ipg_clk, &spba_clk);
> +
> +/* GPT */
> +DEFINE_CLOCK(gpt_clk, 0, MXC_CCM_CCGR2, MXC_CCM_CCGRx_CG9_OFFSET,
> + Â Â Â NULL, ÂNULL, &ipg_perclk, NULL);
> +DEFINE_CLOCK(gpt_ipg_clk, 0, MXC_CCM_CCGR2, MXC_CCM_CCGRx_CG10_OFFSET,
> + Â Â Â NULL, ÂNULL, &ipg_clk, NULL);
> +
> +/* FEC */
> +DEFINE_CLOCK(fec_clk, 0, MXC_CCM_CCGR2, MXC_CCM_CCGRx_CG12_OFFSET,
> + Â Â Â NULL, ÂNULL, &ipg_clk, NULL);
> +
> +#define _REGISTER_CLOCK(d, n, c) \
> + Â Â Â { \
> + Â Â Â Â Â Â Â .dev_id = d, \
> + Â Â Â Â Â Â Â .con_id = n, \
> + Â Â Â Â Â Â Â .clk = &c, Â \
> + Â Â Â },
> +
> +static struct clk_lookup lookups[] __initdata = {
> + Â Â Â _REGISTER_CLOCK("imx-uart.0", NULL, uart1_clk)
> + Â Â Â _REGISTER_CLOCK("imx-uart.1", NULL, uart2_clk)
> + Â Â Â _REGISTER_CLOCK("imx-uart.2", NULL, uart3_clk)
> + Â Â Â _REGISTER_CLOCK(NULL, "gpt", gpt_clk)
> + Â Â Â _REGISTER_CLOCK("fec.0", NULL, fec_clk)
> +};
> +
> +static void clk_tree_init(void)
> +{
> + Â Â Â u32 reg;
> +
> + Â Â Â ipg_perclk.set_parent(&ipg_perclk, &lp_apm_clk);
> +
> + Â Â Â /*
> + Â Â Â Â* Initialise the IPG PER CLK dividers to 3. IPG_PER_CLK should be at
> + Â Â Â Â* 8MHz, its derived from lp_apm.
> + Â Â Â Â* FIXME: Verify if true for all boards
> + Â Â Â Â*/
> + Â Â Â reg = __raw_readl(MXC_CCM_CBCDR);
> + Â Â Â reg &= ~MXC_CCM_CBCDR_PERCLK_PRED1_MASK;
> + Â Â Â reg &= ~MXC_CCM_CBCDR_PERCLK_PRED2_MASK;
> + Â Â Â reg &= ~MXC_CCM_CBCDR_PERCLK_PODF_MASK;
> + Â Â Â reg |= (2 << MXC_CCM_CBCDR_PERCLK_PRED1_OFFSET);
> + Â Â Â __raw_writel(reg, MXC_CCM_CBCDR);
> +
> + Â Â Â /* set parent for pll1, pll2 and pll3 */
> + Â Â Â pll1_main_clk.parent = &osc_clk;
> + Â Â Â pll2_sw_clk.parent = &osc_clk;
> + Â Â Â pll3_sw_clk.parent = &osc_clk;
> +
> + Â Â Â /* set ipg_perclk parent */
> + Â Â Â ipg_perclk.parent = &lp_apm_clk;
> + Â Â Â reg = __raw_readl(MXC_CCM_CBCMR);
> + Â Â Â if ((reg & MXC_CCM_CBCMR_PERCLK_IPG_CLK_SEL) != 0) {
> + Â Â Â Â Â Â Â ipg_perclk.parent = &ipg_clk;
> + Â Â Â } else {
> + Â Â Â Â Â Â Â if ((reg & MXC_CCM_CBCMR_PERCLK_LP_APM_CLK_SEL) == 0)
> + Â Â Â Â Â Â Â Â Â Â Â ipg_perclk.parent = &main_bus_clk;
> + Â Â Â }
> +}
> +
> +int __init mx51_clocks_init(unsigned long ckil, unsigned long osc,
> + Â Â Â Â Â Â Â Â Â Â Â unsigned long ckih1, unsigned long ckih2)
> +{
> + Â Â Â int i;
> +
> + Â Â Â external_low_reference = ckil;
> + Â Â Â external_high_reference = ckih1;
> + Â Â Â ckih2_reference = ckih2;
> + Â Â Â oscillator_reference = osc;
> +
> + Â Â Â for (i = 0; i < ARRAY_SIZE(lookups); i++)
> + Â Â Â Â Â Â Â clkdev_add(&lookups[i]);
> +
> + Â Â Â clk_tree_init();
> +
> + Â Â Â clk_enable(&cpu_clk);
> + Â Â Â clk_enable(&main_bus_clk);
> +
> + Â Â Â /* System timer */
> + Â Â Â mxc_timer_init(&gpt_clk, MX51_IO_ADDRESS(MX51_GPT1_BASE_ADDR),
> + Â Â Â Â Â Â Â MX51_MXC_INT_GPT);
> + Â Â Â return 0;
> +}
> diff --git a/arch/arm/mach-mx5/cpu.c b/arch/arm/mach-mx5/cpu.c
> new file mode 100644
> index 0000000..93f1d5a
> --- /dev/null
> +++ b/arch/arm/mach-mx5/cpu.c
> @@ -0,0 +1,45 @@
> +/*
> + * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
> + *
> + * The code contained herein is licensed under the GNU General Public
> + * License. You may obtain a copy of the GNU General Public License
> + * Version 2 or later at the following locations:
> + *
> + * http://www.opensource.org/licenses/gpl-license.html
> + * http://www.gnu.org/copyleft/gpl.html
> + *
> + * This file contains the CPU initialization code.
> + */
> +
> +#include <linux/types.h>
> +#include <linux/kernel.h>
> +#include <linux/init.h>
> +#include <mach/hardware.h>
> +#include <asm/io.h>
> +
> +static int __init post_cpu_init(void)
> +{
> + Â Â Â unsigned int reg;
> + Â Â Â void __iomem *base;
> +
> + Â Â Â if (cpu_is_mx51()) {
> + Â Â Â Â Â Â Â base = MX51_IO_ADDRESS(MX51_AIPS1_BASE_ADDR);
> + Â Â Â Â Â Â Â __raw_writel(0x0, base + 0x40);
> + Â Â Â Â Â Â Â __raw_writel(0x0, base + 0x44);
> + Â Â Â Â Â Â Â __raw_writel(0x0, base + 0x48);
> + Â Â Â Â Â Â Â __raw_writel(0x0, base + 0x4C);
> + Â Â Â Â Â Â Â reg = __raw_readl(base + 0x50) & 0x00FFFFFF;
> + Â Â Â Â Â Â Â __raw_writel(reg, base + 0x50);
> +
> + Â Â Â Â Â Â Â base = MX51_IO_ADDRESS(MX51_AIPS2_BASE_ADDR);
> + Â Â Â Â Â Â Â __raw_writel(0x0, base + 0x40);
> + Â Â Â Â Â Â Â __raw_writel(0x0, base + 0x44);
> + Â Â Â Â Â Â Â __raw_writel(0x0, base + 0x48);
> + Â Â Â Â Â Â Â __raw_writel(0x0, base + 0x4C);
> + Â Â Â Â Â Â Â reg = __raw_readl(base + 0x50) & 0x00FFFFFF;
> + Â Â Â Â Â Â Â __raw_writel(reg, base + 0x50);
> + Â Â Â }
> + Â Â Â return 0;
> +}
> +
> +postcore_initcall(post_cpu_init);
> diff --git a/arch/arm/mach-mx5/crm_regs.h b/arch/arm/mach-mx5/crm_regs.h
> new file mode 100644
> index 0000000..c776b9a
> --- /dev/null
> +++ b/arch/arm/mach-mx5/crm_regs.h
> @@ -0,0 +1,583 @@
> +/*
> + * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
> + *
> + * The code contained herein is licensed under the GNU General Public
> + * License. You may obtain a copy of the GNU General Public License
> + * Version 2 or later at the following locations:
> + *
> + * http://www.opensource.org/licenses/gpl-license.html
> + * http://www.gnu.org/copyleft/gpl.html
> + */
> +#ifndef __ARCH_ARM_MACH_MX51_CRM_REGS_H__
> +#define __ARCH_ARM_MACH_MX51_CRM_REGS_H__
> +
> +#define MX51_CCM_BASE Â Â Â Â ÂMX51_IO_ADDRESS(MX51_CCM_BASE_ADDR)
> +#define MX51_DPLL1_BASE Â Â Â Â Â Â Â ÂMX51_IO_ADDRESS(MX51_PLL1_BASE_ADDR)
> +#define MX51_DPLL2_BASE Â Â Â Â Â Â Â ÂMX51_IO_ADDRESS(MX51_PLL2_BASE_ADDR)

.... skipping register definitions ....

> +#define MXC_SRPGC_EMI_PUPSCR Â (MXC_SRPGC_EMI_BASE + 0x4)
> +#define MXC_SRPGC_EMI_PDNSCR Â (MXC_SRPGC_EMI_BASE + 0x8)
> +
> +#endif             /* __ARCH_ARM_MACH_MX51_CRM_REGS_H__ */
> diff --git a/arch/arm/mach-mx5/devices.c b/arch/arm/mach-mx5/devices.c
> new file mode 100644
> index 0000000..55eb089
> --- /dev/null
> +++ b/arch/arm/mach-mx5/devices.c
> @@ -0,0 +1,96 @@
> +/*
> + * Copyright 2009 Amit Kucheria <amit.kucheria@xxxxxxxxxxxxx>
> + *
> + * The code contained herein is licensed under the GNU General Public
> + * License. You may obtain a copy of the GNU General Public License
> + * Version 2 or later at the following locations:
> + *
> + * http://www.opensource.org/licenses/gpl-license.html
> + * http://www.gnu.org/copyleft/gpl.html
> + */
> +
> +#include <linux/platform_device.h>
> +#include <mach/hardware.h>
> +#include <mach/imx-uart.h>
> +
> +static struct resource uart0[] = {
> + Â Â Â {
> + Â Â Â Â Â Â Â .start = MX51_UART1_BASE_ADDR,
> + Â Â Â Â Â Â Â .end = MX51_UART1_BASE_ADDR + 0x0B5,
> + Â Â Â Â Â Â Â .flags = IORESOURCE_MEM,
> + Â Â Â }, {
> + Â Â Â Â Â Â Â .start = MX51_MXC_INT_UART1,
> + Â Â Â Â Â Â Â .end = MX51_MXC_INT_UART1,
> + Â Â Â Â Â Â Â .flags = IORESOURCE_IRQ,
> + Â Â Â },
> +};
> +
> +struct platform_device mxc_uart_device0 = {
> + Â Â Â .name = "imx-uart",
> + Â Â Â .id = 0,
> + Â Â Â .resource = uart0,
> + Â Â Â .num_resources = ARRAY_SIZE(uart0),
> +};
> +
> +static struct resource uart1[] = {
> + Â Â Â {
> + Â Â Â Â Â Â Â .start = MX51_UART2_BASE_ADDR,
> + Â Â Â Â Â Â Â .end = MX51_UART2_BASE_ADDR + 0x0B5,
> + Â Â Â Â Â Â Â .flags = IORESOURCE_MEM,
> + Â Â Â }, {
> + Â Â Â Â Â Â Â .start = MX51_MXC_INT_UART2,
> + Â Â Â Â Â Â Â .end = MX51_MXC_INT_UART2,
> + Â Â Â Â Â Â Â .flags = IORESOURCE_IRQ,
> + Â Â Â },
> +};
> +
> +struct platform_device mxc_uart_device1 = {
> + Â Â Â .name = "imx-uart",
> + Â Â Â .id = 1,
> + Â Â Â .resource = uart1,
> + Â Â Â .num_resources = ARRAY_SIZE(uart1),
> +};
> +
> +static struct resource uart2[] = {
> + Â Â Â {
> + Â Â Â Â Â Â Â .start = MX51_UART3_BASE_ADDR,
> + Â Â Â Â Â Â Â .end = MX51_UART3_BASE_ADDR + 0x0B5,
> + Â Â Â Â Â Â Â .flags = IORESOURCE_MEM,
> + Â Â Â }, {
> + Â Â Â Â Â Â Â .start = MX51_MXC_INT_UART3,
> + Â Â Â Â Â Â Â .end = MX51_MXC_INT_UART3,
> + Â Â Â Â Â Â Â .flags = IORESOURCE_IRQ,
> + Â Â Â },
> +};
> +
> +struct platform_device mxc_uart_device2 = {
> + Â Â Â .name = "imx-uart",
> + Â Â Â .id = 2,
> + Â Â Â .resource = uart2,
> + Â Â Â .num_resources = ARRAY_SIZE(uart2),
> +};
> +
> +static struct resource mxc_fec_resources[] = {
> + Â Â Â {
> + Â Â Â Â Â Â Â .start Â= MX51_MXC_FEC_BASE_ADDR,
> +        .end  Â= MX51_MXC_FEC_BASE_ADDR + 0xfff,
> + Â Â Â Â Â Â Â .flags Â= IORESOURCE_MEM,
> + Â Â Â }, {
> + Â Â Â Â Â Â Â .start Â= MX51_MXC_INT_FEC,
> +        .end  Â= MX51_MXC_INT_FEC,
> + Â Â Â Â Â Â Â .flags Â= IORESOURCE_IRQ,
> + Â Â Â },
> +};
> +
> +struct platform_device mxc_fec_device = {
> + Â Â Â .name = "fec",
> + Â Â Â .id = 0,
> + Â Â Â .num_resources = ARRAY_SIZE(mxc_fec_resources),
> + Â Â Â .resource = mxc_fec_resources,
> +};
> +
> +/* Dummy definition to allow compiling in AVIC and TZIC simultaneously */
> +int __init mxc_register_gpios(void)
> +{
> + Â Â Â return 0;
> +}
> diff --git a/arch/arm/mach-mx5/devices.h b/arch/arm/mach-mx5/devices.h
> new file mode 100644
> index 0000000..f339ab8
> --- /dev/null
> +++ b/arch/arm/mach-mx5/devices.h
> @@ -0,0 +1,4 @@
> +extern struct platform_device mxc_uart_device0;
> +extern struct platform_device mxc_uart_device1;
> +extern struct platform_device mxc_uart_device2;
> +extern struct platform_device mxc_fec_device;
> diff --git a/arch/arm/mach-mx5/mm.c b/arch/arm/mach-mx5/mm.c
> new file mode 100644
> index 0000000..d66c31a
> --- /dev/null
> +++ b/arch/arm/mach-mx5/mm.c
> @@ -0,0 +1,88 @@
> +/*
> + * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
> + *
> + * The code contained herein is licensed under the GNU General Public
> + * License. ÂYou may obtain a copy of the GNU General Public License
> + * Version 2 or later at the following locations:
> + *
> + * http://www.opensource.org/licenses/gpl-license.html
> + * http://www.gnu.org/copyleft/gpl.html
> + *
> + * Create static mapping between physical to virtual memory.
> + */
> +
> +#include <linux/mm.h>
> +#include <linux/init.h>
> +
> +#include <asm/mach/map.h>
> +
> +#include <mach/hardware.h>
> +#include <mach/common.h>
> +#include <mach/iomux-v3.h>
> +
> +/*
> + * Define the MX51 memory map.
> + */
> +static struct map_desc mxc_io_desc[] __initdata = {
> + Â Â Â {
> + Â Â Â Â.virtual = MX51_IRAM_BASE_ADDR_VIRT,
> + Â Â Â Â.pfn = __phys_to_pfn(MX51_IRAM_BASE_ADDR),
> + Â Â Â Â.length = MX51_IRAM_SIZE,
> + Â Â Â Â.type = MT_DEVICE},
> + Â Â Â {
> + Â Â Â Â.virtual = MX51_DEBUG_BASE_ADDR_VIRT,
> + Â Â Â Â.pfn = __phys_to_pfn(MX51_DEBUG_BASE_ADDR),
> + Â Â Â Â.length = MX51_DEBUG_SIZE,
> + Â Â Â Â.type = MT_DEVICE},
> + Â Â Â {
> + Â Â Â Â.virtual = MX51_TZIC_BASE_ADDR_VIRT,
> + Â Â Â Â.pfn = __phys_to_pfn(MX51_TZIC_BASE_ADDR),
> + Â Â Â Â.length = MX51_TZIC_SIZE,
> + Â Â Â Â.type = MT_DEVICE},
> + Â Â Â {
> + Â Â Â Â.virtual = MX51_AIPS1_BASE_ADDR_VIRT,
> + Â Â Â Â.pfn = __phys_to_pfn(MX51_AIPS1_BASE_ADDR),
> + Â Â Â Â.length = MX51_AIPS1_SIZE,
> + Â Â Â Â.type = MT_DEVICE},
> + Â Â Â {
> + Â Â Â Â.virtual = MX51_SPBA0_BASE_ADDR_VIRT,
> + Â Â Â Â.pfn = __phys_to_pfn(MX51_SPBA0_BASE_ADDR),
> + Â Â Â Â.length = MX51_SPBA0_SIZE,
> + Â Â Â Â.type = MT_DEVICE},
> + Â Â Â {
> + Â Â Â Â.virtual = MX51_AIPS2_BASE_ADDR_VIRT,
> + Â Â Â Â.pfn = __phys_to_pfn(MX51_AIPS2_BASE_ADDR),
> + Â Â Â Â.length = MX51_AIPS2_SIZE,
> + Â Â Â Â.type = MT_DEVICE},
> + Â Â Â {
> + Â Â Â Â.virtual = MX51_NFC_AXI_BASE_ADDR_VIRT,
> + Â Â Â Â.pfn = __phys_to_pfn(MX51_NFC_AXI_BASE_ADDR),
> + Â Â Â Â.length = MX51_NFC_AXI_SIZE,
> + Â Â Â Â.type = MT_DEVICE},

Weird alignment, guess due to leading white spaces?


.... skipping the rest ....
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/