[From nobody Tue Jul 26 02:28:06 2011
Received: from az33smr02.freescale.net (10.64.34.200) by
	039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP
	Server id 14.1.270.2; Thu, 14 Apr 2011 05:28:18 -0500
Received: from x-VirtualBox.ap.freescale.net (x-VirtualBox.ap.freescale.net
	[10.192.242.110])	by az33smr02.freescale.net (8.13.1/8.13.0) with ESMTP
	id p3EASD5j015799;	Thu, 14 Apr 2011 05:28:14 -0500 (CDT)
From: Zhu Richard-R65037 &lt;r65037@freescale.com&gt;
To: &quot;linux-arm-kernel@lists.infradead.org&quot;
	&lt;linux-arm-kernel@lists.infradead.org&gt;
CC: &quot;jgarzik@pobox.com&quot; &lt;jgarzik@pobox.com&gt;, &quot;kernel@pengutronix.de&quot;
	&lt;kernel@pengutronix.de&gt;, &quot;linux-ide@vger.kernel.org&quot;
	&lt;linux-ide@vger.kernel.org&gt;, &quot;avorontsov@ru.mvista.com&quot;
	&lt;avorontsov@ru.mvista.com&gt;, &quot;eric@eukrea.com&quot; &lt;eric@eukrea.com&gt;,
	&quot;eric.miao@linaro.org&quot; &lt;eric.miao@linaro.org&gt;, Zhu Richard-R65037
	&lt;r65037@freescale.com&gt;
Subject: [PATCH V5 1/2] AHCI Add the AHCI SATA feature on MX53 platforms
Thread-Topic: [PATCH V5 1/2] AHCI Add the AHCI SATA feature on MX53 platforms
Thread-Index: AQHL+o6ssB/V0MpwfEekw+E1KiVjfQ==
Date: Thu, 14 Apr 2011 10:28:11 +0000
Message-ID: &lt;1302776892-17243-1-git-send-email-Hong-Xing.Zhu@freescale.com&gt;
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 10
X-MS-Exchange-Organization-AuthSource: 039-SN1MMR1-001.039d.mgd.msft.net
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Content-Type: text/plain; charset=&quot;iso-8859-1&quot;
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

Signed-off-by: Richard Zhu &lt;Hong-Xing.Zhu@freescale.com&gt;
---
 arch/arm/mach-mx5/clock-mx51-mx53.c             |   11 +++++
 arch/arm/mach-mx5/devices-imx53.h               |    4 ++
 arch/arm/plat-mxc/Makefile                      |    1 +
 arch/arm/plat-mxc/ahci_sata.c                   |   43 ++++++++++++++++++
 arch/arm/plat-mxc/devices/Kconfig               |    4 ++
 arch/arm/plat-mxc/devices/Makefile              |    1 +
 arch/arm/plat-mxc/devices/platform-ahci-imx.c   |   55 +++++++++++++++++++=
++++
 arch/arm/plat-mxc/include/mach/ahci_sata.h      |   54 +++++++++++++++++++=
+++
 arch/arm/plat-mxc/include/mach/devices-common.h |   10 ++++
 9 files changed, 183 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/plat-mxc/ahci_sata.c
 create mode 100644 arch/arm/plat-mxc/devices/platform-ahci-imx.c
 create mode 100644 arch/arm/plat-mxc/include/mach/ahci_sata.h

diff --git a/arch/arm/mach-mx5/clock-mx51-mx53.c b/arch/arm/mach-mx5/clock-=
mx51-mx53.c
index 6b89c1b..5d7d861 100644
--- a/arch/arm/mach-mx5/clock-mx51-mx53.c
+++ b/arch/arm/mach-mx5/clock-mx51-mx53.c
@@ -1387,6 +1387,14 @@ static struct clk esdhc4_mx53_clk =3D {
        .secondary =3D &amp;esdhc4_ipg_clk,
 };

+static struct clk sata_clk =3D {
+       .parent =3D &amp;ipg_clk,
+       .enable =3D _clk_max_enable,
+       .enable_reg =3D MXC_CCM_CCGR4,
+       .enable_shift =3D MXC_CCM_CCGRx_CG1_OFFSET,
+       .disable =3D _clk_max_disable,
+};
+
 DEFINE_CLOCK(mipi_esc_clk, 0, MXC_CCM_CCGR4, MXC_CCM_CCGRx_CG5_OFFSET, NUL=
L, NULL, NULL, &amp;pll2_sw_clk);
 DEFINE_CLOCK(mipi_hsc2_clk, 0, MXC_CCM_CCGR4, MXC_CCM_CCGRx_CG4_OFFSET, NU=
LL, NULL, &amp;mipi_esc_clk, &amp;pll2_sw_clk);
 DEFINE_CLOCK(mipi_hsc1_clk, 0, MXC_CCM_CCGR4, MXC_CCM_CCGRx_CG3_OFFSET, NU=
LL, NULL, &amp;mipi_hsc2_clk, &amp;pll2_sw_clk);
@@ -1476,6 +1484,9 @@ static struct clk_lookup mx53_lookups[] =3D {
        _REGISTER_CLOCK(&quot;imx53-cspi.0&quot;, NULL, cspi_clk)
        _REGISTER_CLOCK(&quot;imx2-wdt.0&quot;, NULL, dummy_clk)
        _REGISTER_CLOCK(&quot;imx2-wdt.1&quot;, NULL, dummy_clk)
+       _REGISTER_CLOCK(&quot;ahci.0&quot;, NULL, sata_clk)
+       _REGISTER_CLOCK(NULL, &quot;usb_phy1&quot;, usb_phy1_clk)
+       _REGISTER_CLOCK(NULL, &quot;ahb&quot;, ahb_clk)
 };

 static void clk_tree_init(void)
diff --git a/arch/arm/mach-mx5/devices-imx53.h b/arch/arm/mach-mx5/devices-=
imx53.h
index 48f4c8c..62d23a1 100644
--- a/arch/arm/mach-mx5/devices-imx53.h
+++ b/arch/arm/mach-mx5/devices-imx53.h
@@ -32,3 +32,7 @@ extern const struct imx_spi_imx_data imx53_ecspi_data[];
 extern const struct imx_imx2_wdt_data imx53_imx2_wdt_data[];
 #define imx53_add_imx2_wdt(id, pdata)  \
        imx_add_imx2_wdt(&amp;imx53_imx2_wdt_data[id])
+
+extern const struct imx_ahci_data imx53_ahci_data __initconst;
+#define imx53_add_ahci(id, pdata)   \
+       imx_add_ahci(&amp;imx53_ahci_data, pdata)
diff --git a/arch/arm/plat-mxc/Makefile b/arch/arm/plat-mxc/Makefile
index a138787..a9386bc 100644
--- a/arch/arm/plat-mxc/Makefile
+++ b/arch/arm/plat-mxc/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_ARCH_MXC_AUDMUX_V1) +=3D audmux-v1.o
 obj-$(CONFIG_ARCH_MXC_AUDMUX_V2) +=3D audmux-v2.o
 obj-$(CONFIG_MXC_DEBUG_BOARD) +=3D 3ds_debugboard.o
 obj-$(CONFIG_CPU_FREQ_IMX)    +=3D cpufreq.o
+obj-$(CONFIG_IMX_HAVE_PLATFORM_AHCI)   +=3D ahci_sata.o
 ifdef CONFIG_SND_IMX_SOC
 obj-y +=3D ssi-fiq.o
 obj-y +=3D ssi-fiq-ksym.o
diff --git a/arch/arm/plat-mxc/ahci_sata.c b/arch/arm/plat-mxc/ahci_sata.c
new file mode 100644
index 0000000..1455eaf
--- /dev/null
+++ b/arch/arm/plat-mxc/ahci_sata.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * 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.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include &lt;linux/io.h&gt;
+#include &lt;linux/clk.h&gt;
+#include &lt;mach/ahci_sata.h&gt;
+
+/* AHCI module Initialization, if return 0, initialization is successful. =
*/
+int sata_init(void __iomem *addr, unsigned long timer1ms)
+{
+       u32 tmpdata;
+
+       tmpdata =3D readl(addr + HOST_CAP);
+       if (!(tmpdata &amp; HOST_CAP_SSS)) {
+               tmpdata |=3D HOST_CAP_SSS;
+               writel(tmpdata, addr + HOST_CAP);
+       }
+
+       if (!(readl(addr + HOST_PORTS_IMPL) &amp; 0x1))
+               writel((readl(addr + HOST_PORTS_IMPL) | 0x1),
+                       addr + HOST_PORTS_IMPL);
+
+       writel(timer1ms, addr + HOST_TIMER1MS);
+
+       return 0;
+}
diff --git a/arch/arm/plat-mxc/devices/Kconfig b/arch/arm/plat-mxc/devices/=
Kconfig
index bd294ad..f63887b 100644
--- a/arch/arm/plat-mxc/devices/Kconfig
+++ b/arch/arm/plat-mxc/devices/Kconfig
@@ -76,3 +76,7 @@ config IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX

 config IMX_HAVE_PLATFORM_SPI_IMX
        bool
+
+config IMX_HAVE_PLATFORM_AHCI
+       bool
+       default y if ARCH_MX53
diff --git a/arch/arm/plat-mxc/devices/Makefile b/arch/arm/plat-mxc/devices=
/Makefile
index ad2922a..4d2a1f1 100644
--- a/arch/arm/plat-mxc/devices/Makefile
+++ b/arch/arm/plat-mxc/devices/Makefile
@@ -24,3 +24,4 @@ obj-$(CONFIG_IMX_HAVE_PLATFORM_MXC_RTC) +=3D platform-mxc=
_rtc.o
 obj-$(CONFIG_IMX_HAVE_PLATFORM_MXC_W1) +=3D platform-mxc_w1.o
 obj-$(CONFIG_IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX) +=3D platform-sdhci-esdhc-=
imx.o
 obj-$(CONFIG_IMX_HAVE_PLATFORM_SPI_IMX) +=3D  platform-spi_imx.o
+obj-$(CONFIG_IMX_HAVE_PLATFORM_AHCI) +=3D  platform-ahci-imx.o
diff --git a/arch/arm/plat-mxc/devices/platform-ahci-imx.c b/arch/arm/plat-=
mxc/devices/platform-ahci-imx.c
new file mode 100644
index 0000000..65a76ce
--- /dev/null
+++ b/arch/arm/plat-mxc/devices/platform-ahci-imx.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * 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.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include &lt;asm/sizes.h&gt;
+#include &lt;mach/hardware.h&gt;
+#include &lt;mach/devices-common.h&gt;
+
+#define imx_ahci_data_entry_single(soc)                                   =
     \
+       {                                                               \
+               .iobase =3D soc ## _SATA_BASE_ADDR,                       \
+               .irq =3D soc ## _INT_SATA,                                \
+       }
+
+#ifdef CONFIG_SOC_IMX53
+const struct imx_ahci_data imx53_ahci_data __initconst =3D
+       imx_ahci_data_entry_single(MX53);
+#endif
+
+struct platform_device *__init imx_add_ahci(
+               const struct imx_ahci_data *data,
+               const struct ahci_platform_data *pdata)
+{
+       struct resource res[] =3D {
+               {
+                       .start =3D data-&gt;iobase,
+                       .end =3D data-&gt;iobase + SZ_4K - 1,
+                       .flags =3D IORESOURCE_MEM,
+               }, {
+                       .start =3D data-&gt;irq,
+                       .end =3D data-&gt;irq,
+                       .flags =3D IORESOURCE_IRQ,
+               },
+       };
+
+       return imx_add_platform_device_dmamask(&quot;ahci&quot;, 0,
+                       res, ARRAY_SIZE(res),
+                       pdata, sizeof(*pdata),  DMA_BIT_MASK(32));
+}
diff --git a/arch/arm/plat-mxc/include/mach/ahci_sata.h b/arch/arm/plat-mxc=
/include/mach/ahci_sata.h
new file mode 100644
index 0000000..dbaaf74
--- /dev/null
+++ b/arch/arm/plat-mxc/include/mach/ahci_sata.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * 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.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __PLAT_MXC_AHCI_SATA_H__
+#define __PLAT_MXC_AHCI_SATA_H__
+
+enum {
+       HOST_CAP =3D 0x00,
+       HOST_CAP_SSS =3D (1 &lt;&lt; 27), /* Staggered Spin-up */
+       HOST_PORTS_IMPL =3D 0x0c,
+       HOST_TIMER1MS =3D 0xe0, /* Timer 1-ms */
+       /* Offest used to control the MPLL input clk */
+       PHY_CR_CLOCK_FREQ_OVRD =3D 0x12,
+       /* Port0 SATA Status */
+       PORT_SATA_SR =3D 0x128,
+       /* Port0 PHY Control */
+       PORT_PHY_CTL =3D 0x178,
+       /* PORT_PHY_CTL bits */
+       PORT_PHY_CTL_CAP_ADR_LOC =3D 0x10000,
+       PORT_PHY_CTL_CAP_DAT_LOC =3D 0x20000,
+       PORT_PHY_CTL_WRITE_LOC =3D 0x40000,
+       PORT_PHY_CTL_READ_LOC =3D 0x80000,
+       /* Port0 PHY Status */
+       PORT_PHY_SR =3D 0x17c,
+       /* PORT_PHY_SR */
+       PORT_PHY_STAT_DATA_LOC =3D 0,
+       PORT_PHY_STAT_ACK_LOC =3D 18,
+       /* SATA PHY Register */
+       SATA_PHY_CR_CLOCK_CRCMP_LT_LIMIT =3D 0x0001,
+       SATA_PHY_CR_CLOCK_DAC_CTL =3D 0x0008,
+       SATA_PHY_CR_CLOCK_RTUNE_CTL =3D 0x0009,
+       SATA_PHY_CR_CLOCK_ADC_OUT =3D 0x000A,
+       SATA_PHY_CR_CLOCK_MPLL_TST =3D 0x0017,
+};
+
+extern int sata_init(void __iomem *addr, unsigned long timer1ms);
+#endif /* __PLAT_MXC_AHCI_SATA_H__ */
diff --git a/arch/arm/plat-mxc/include/mach/devices-common.h b/arch/arm/pla=
t-mxc/include/mach/devices-common.h
index fa84773..ada88d7 100644
--- a/arch/arm/plat-mxc/include/mach/devices-common.h
+++ b/arch/arm/plat-mxc/include/mach/devices-common.h
@@ -291,3 +291,13 @@ struct imx_spi_imx_data {
 struct platform_device *__init imx_add_spi_imx(
                const struct imx_spi_imx_data *data,
                const struct spi_imx_master *pdata);
+
+#include &lt;linux/ahci_platform.h&gt;
+struct imx_ahci_data {
+       int id;
+       resource_size_t iobase;
+       resource_size_t irq;
+};
+struct platform_device *__init imx_add_ahci(
+               const struct imx_ahci_data *data,
+               const struct ahci_platform_data *pdata);
--
1.7.1

]