AHCI Add the AHCI SATA feature on MX53 platforms
Subsystems (4)
PATCH v2 1/2 AHCI Add the AHCI SATA feature on MX53 platforms
--- arch/arm/mach-mx5/clock-mx51-mx53.c | 11 +++++ arch/arm/mach-mx5/devices-imx53.h | 4 ++ 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 | 51 +++++++++++++++++++++ arch/arm/plat-mxc/include/mach/devices-common.h | 10 ++++ 7 files changed, 136 insertions(+), 0 deletions(-) create mode 100644 arch/arm/plat-mxc/devices/platform-ahci-imx.c create mode 100644 arch/arm/plat-mxc/include/mach/ahci_sata.h
arch/arm/mach-mx5/clock-mx51-mx53.c +11 -0
@@ -1380,6 +1380,14 @@ static struct clk esdhc4_mx53_clk = { .secondary = &esdhc4_ipg_clk, }; +static struct clk sata_clk = { + .parent = &ipg_clk, + .enable = _clk_max_enable, + .enable_reg =MXC_CCM_CCGR4 , + .enable_shift = MXC_CCM_CCGRx_CG1_OFFSET, + .disable = _clk_max_disable, +}; +DEFINE_CLOCK (mipi_esc_clk,0 ,MXC_CCM_CCGR4 , MXC_CCM_CCGRx_CG5_OFFSET,NULL ,NULL ,NULL , &pll2_sw_clk);DEFINE_CLOCK (mipi_hsc2_clk,0 ,MXC_CCM_CCGR4 , MXC_CCM_CCGRx_CG4_OFFSET,NULL ,NULL , &mipi_esc_clk, &pll2_sw_clk);DEFINE_CLOCK (mipi_hsc1_clk,0 ,MXC_CCM_CCGR4 , MXC_CCM_CCGRx_CG3_OFFSET,NULL ,NULL , &mipi_hsc2_clk, &pll2_sw_clk);
@@ -1468,6 +1476,9 @@ static struct clk_lookup mx53_lookups[] = { _REGISTER_CLOCK("imx53-cspi.0", NULL, cspi_clk) _REGISTER_CLOCK("imx2-wdt.0", NULL, dummy_clk) _REGISTER_CLOCK("imx2-wdt.1", NULL, dummy_clk) + _REGISTER_CLOCK("ahci.0", NULL, sata_clk) + _REGISTER_CLOCK(NULL, "usb_phy1", usb_phy1_clk) + _REGISTER_CLOCK(NULL, "ahb", ahb_clk) };static void clk_tree_init (void )
arch/arm/mach-mx5/devices-imx53.h +4 -0
@@ -33,3 +33,7 @@ extern const struct imx_spi_imx_data imx53_ecspi_data[] __initconst;extern const struct imx_imx2_wdt_data imx53_imx2_wdt_data[]__initconst ;#define imx53_add_imx2_wdt (id, pdata) \ imx_add_imx2_wdt(&imx53_imx2_wdt_data[id]) + +extern const struct imx_ahci_imx_data imx53_ahci_imx_data[]__initconst ; +#define imx53_add_ahci_imx (id, pdata) \ + imx_add_ahci_imx(&imx53_ahci_imx_data[id], pdata)
arch/arm/plat-mxc/devices/Kconfig +4 -0
@@ -71,3 +71,7 @@ config IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX config IMX_HAVE_PLATFORM_SPI_IMX bool + +config IMX_HAVE_PLATFORM_SATA_AHCI + bool + default y if SOC_IMX53
arch/arm/plat-mxc/devices/Makefile +1 -0
@@ -22,3 +22,4 @@ obj-$(CONFIG_IMX_HAVE_PLATFORM_MXC_RNGA) += platform-mxc_rnga.o obj-$(CONFIG_IMX_HAVE_PLATFORM_MXC_W1) += platform-mxc_w1.o obj-$(CONFIG_IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX) += platform-sdhci-esdhc-imx.o obj-$(CONFIG_IMX_HAVE_PLATFORM_SPI_IMX) += platform-spi_imx.o +obj-$(CONFIG_IMX_HAVE_PLATFORM_SATA_AHCI) += platform-ahci-imx.o
arch/arm/plat-mxc/devices/platform-ahci-imx.c new file +55 -0
55 lines not on this page · raw message
arch/arm/plat-mxc/include/mach/ahci_sata.h new file +51 -0
51 lines not on this page · raw message
arch/arm/plat-mxc/include/mach/devices-common.h +10 -0
@@ -264,3 +264,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 <linux/ahci_platform.h> +struct imx_ahci_imx_data { +int id; +resource_size_t iobase; +resource_size_t irq; +}; +struct platform_device *__init imx_add_ahci_imx ( +const struct imx_ahci_imx_data *data, +const struct ahci_platform_data *pdata);
Signature · 1 line
1.7.1
PATCH v2 2/2 MX53 Enable the AHCI SATA on MX53 LOCO
--- arch/arm/mach-mx5/board-mx53_loco.c | 88 +++++++++++++++++++++++++++++++++++ 1 files changed, 88 insertions(+), 0 deletions(-)
arch/arm/mach-mx5/board-mx53_loco.c +88 -0
@@ -23,11 +23,13 @@#include <linux/fec.h> #include <linux/delay.h> #include <linux/gpio.h> +#include <linux/ahci_platform.h> #include <mach/common.h> #include <mach/hardware.h> #include <mach/imx-uart.h> #include <mach/iomux-mx53.h> +#include <mach/ahci_sata.h> #include <asm/mach-types.h> #include <asm/mach/arch.h>
@@ -38,6 +40,8 @@#define LOCO_FEC_PHY_RST IMX_GPIO_NR(7, 6) +static struct clk *sata_clk, *sata_ref_clk; +static iomux_v3_cfg_t mx53_loco_pads[] = {/* FEC */ MX53_PAD_FEC_MDC__FEC_MDC ,
@@ -203,6 +207,89 @@ static const struct imxi2c_platform_data mx53_loco_i2c_data __initconst = { .bitrate = 100000, }; +/* HW Initialization, if return 0, initialization is successful. */ +static int sata_init (struct device *dev,void __iomem *addr) +{ +int ret =0 ; +u32 tmpdata; +struct clk *clk; + + sata_clk =clk_get (dev,NULL ); +if (IS_ERR (sata_clk)) { +dev_err (dev,"no sata clock.\n" ); +return PTR_ERR (sata_clk); + } + ret =clk_enable (sata_clk); +if (ret) { +dev_err (dev,"can't enable sata clock.\n" ); +clk_put (sata_clk); +return ret; + } + +/* FSL IMX AHCI SATA uses the internal usb phy1 clk on loco */ + sata_ref_clk =clk_get (NULL ,"usb_phy1" ); +if (IS_ERR (sata_ref_clk)) { +dev_err (dev,"no sata ref clock.\n" ); + ret =PTR_ERR (sata_ref_clk); + goto release_sata_clk; + } + ret =clk_enable (sata_ref_clk); +if (ret) { +dev_err (dev,"can't enable sata ref clock.\n" ); +clk_put (sata_ref_clk); + goto release_sata_clk; + } + +/* Get the AHB clock rate, and configure the TIMER1MS reg later */ + clk =clk_get (NULL ,"ahb" ); +if (IS_ERR (clk)) { +dev_err (dev,"no ahb clock.\n" ); + ret =PTR_ERR (clk); + goto release_sata_ref_clk; + } + + tmpdata =readl (addr +HOST_CAP ); +if (!(tmpdata &HOST_CAP_SSS )) { + tmpdata |=HOST_CAP_SSS ; +writel (tmpdata, addr +HOST_CAP ); + } + +if (!(readl (addr +HOST_PORTS_IMPL ) &0x1 )) +writel ((readl (addr +HOST_PORTS_IMPL ) |0x1 ), + addr +HOST_PORTS_IMPL ); + + tmpdata =clk_get_rate (clk) /1000 ; +clk_put (clk); +writel (tmpdata, addr +HOST_TIMER1MS ); + + clk =NULL ; +return ret; + +release_sata_ref_clk: +clk_disable (sata_ref_clk); +clk_put (sata_ref_clk); + +release_sata_clk: +clk_disable (sata_clk); +clk_put (sata_clk); + + clk =NULL ; +return ret; +} + +static void sata_exit (struct device *dev) +{ +clk_disable (sata_ref_clk); +clk_put (sata_ref_clk); + +clk_disable (sata_clk); +clk_put (sata_clk); +} + +static struct ahci_platform_data sata_data = { + .init = sata_init, + .exit = sata_exit, }; +static void __init mx53_loco_board_init (void ) { mxc_iomux_v3_setup_multiple_pads(mx53_loco_pads,
@@ -215,6 +302,7 @@ static void __init mx53_loco_board_init(void)imx53_add_imx_i2c (1 , &mx53_loco_i2c_data);imx53_add_sdhci_esdhc_imx (0 ,NULL );imx53_add_sdhci_esdhc_imx (2 ,NULL ); +imx53_add_ahci_imx (0 , &sata_data); }static void __init mx53_loco_timer_init (void )
Signature · 1 line
1.7.1
Sascha Hauer
maintainerPATCH v2 2/2 MX53 Enable the AHCI SATA on MX53 LOCO
Quoted 66 lines · Richard Zhu
Signed-off-by Richard Zhu <[email protected]>--- arch/arm/mach-mx5/board-mx53_loco.c | 88 +++++++++++++++++++++++++++++++++++ 1 files changed, 88 insertions(+), 0 deletions(-)arch/arm/mach-mx5/board-mx53_loco.c +34
-0@@ -23,11 +23,13 @@#include <linux/fec.h> #include <linux/delay.h> #include <linux/gpio.h> +#include <linux/ahci_platform.h> #include <mach/common.h> #include <mach/hardware.h> #include <mach/imx-uart.h> #include <mach/iomux-mx53.h> +#include <mach/ahci_sata.h> #include <asm/mach-types.h> #include <asm/mach/arch.h> @@ -38,6 +40,8 @@#define LOCO_FEC_PHY_RST IMX_GPIO_NR(7, 6) +static struct clk *sata_clk, *sata_ref_clk; +static iomux_v3_cfg_t mx53_loco_pads[] = {/* FEC */ MX53_PAD_FEC_MDC__FEC_MDC ,@@ -203,6 +207,89 @@ static const struct imxi2c_platform_data mx53_loco_i2c_data __initconst = { .bitrate = 100000, }; +/* HW Initialization, if return 0, initialization is successful. */ +static int sata_init (struct device *dev,void __iomem *addr) +{ +int ret =0 ; +u32 tmpdata; +struct clk *clk; + + sata_clk =clk_get (dev,NULL ); +if (IS_ERR (sata_clk)) { +dev_err (dev,"no sata clock.\n" ); +return PTR_ERR (sata_clk); + } + ret =clk_enable (sata_clk); +if (ret) { +dev_err (dev,"can't enable sata clock.\n" ); +clk_put (sata_clk); +return ret; + } + +/* FSL IMX AHCI SATA uses the internal usb phy1 clk on loco */ + sata_ref_clk =clk_get (NULL ,"usb_phy1" ); +if (IS_ERR (sata_ref_clk)) { +dev_err (dev,"no sata ref clock.\n" ); + ret =PTR_ERR (sata_ref_clk); + goto release_sata_clk; + } + ret =clk_enable (sata_ref_clk); +if (ret) { +dev_err (dev,"can't enable sata ref clock.\n" ); +clk_put (sata_ref_clk);
arch/arm/mach-mx5/board-mx53_loco.c static const struct imxi2c_platform_data mx53_loco_i2c_data __initconst = { · line 249
Quoted 10 lines
arch/arm/mach-mx5/board-mx53_loco.c +10
-0+ goto release_sata_clk; + } + +/* Get the AHB clock rate, and configure the TIMER1MS reg later */ + clk =clk_get (NULL ,"ahb" ); +if (IS_ERR (clk)) { +dev_err (dev,"no ahb clock.\n" ); + ret =PTR_ERR (clk); + goto release_sata_ref_clk; + }
When I read code like this I think that a devm_clk_get is overdue.
Also, the ahci driver should handle the regular
arch/arm/mach-mx5/board-mx53_loco.c static const struct imxi2c_platform_data mx53_loco_i2c_data __initconst = { · line 255
Quoted 6 lines
arch/arm/mach-mx5/board-mx53_loco.c +6
-0+ + tmpdata =readl (addr +HOST_CAP ); +if (!(tmpdata &HOST_CAP_SSS )) { + tmpdata |=HOST_CAP_SSS ; +writel (tmpdata, addr +HOST_CAP ); + }
According to the AHCI spec this bit is read only.
arch/arm/mach-mx5/board-mx53_loco.c static const struct imxi2c_platform_data mx53_loco_i2c_data __initconst = { · line 259
Quoted 4 lines
arch/arm/mach-mx5/board-mx53_loco.c +4
-0+ +if (!(readl (addr +HOST_PORTS_IMPL ) &0x1 )) +writel ((readl (addr +HOST_PORTS_IMPL ) |0x1 ), + addr +HOST_PORTS_IMPL );
This is also readonly.
arch/arm/mach-mx5/board-mx53_loco.c static const struct imxi2c_platform_data mx53_loco_i2c_data __initconst = { · line 263
Quoted 4 lines
arch/arm/mach-mx5/board-mx53_loco.c +4
-0+ + tmpdata =clk_get_rate (clk) /1000 ; +clk_put (clk); +writel (tmpdata, addr +HOST_TIMER1MS );
This should be in a more generic place as it needs to be done for every board. We can put this into some i.MX53 startup function.
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH v2 2/2 MX53 Enable the AHCI SATA on MX53 LOCO
Hi Sascha:
Thanks a lot for your comments.
please see my comments marked by [Richard]
Best Regards
Richard Zhu
Quoted 91 lines
-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Friday, April 08, 2011 3:36 PM
To: Zhu Richard-R65037
Cc: linux-arm-kernel at lists.infradead.org; jgarzik at pobox.com; kernel at pengutronix.de; linux-ide at vger.kernel.org; avorontsov at ru.mvista.com; eric at eukrea.com; eric.miao at linaro.org
Subject: Re: [PATCH V2 2/2] MX53 Enable the AHCI SATA on MX53 LOCOQuoted 3 lines · Richard Zhu
Signed-off-by Richard Zhu <[email protected]>--- arch/arm/mach-mx5/board-mx53_loco.c | 88+++++++++++++++++++++++++++++++++++
arch/arm/mach-mx5/board-mx53_loco.c static const struct imxi2c_platform_data
Quoted 31 lines
1 files changed, 88 insertions(+), 0 deletions(-)arch/arm/mach-mx5/board-mx53_loco.c +4
-0@@ -23,11 +23,13 @@#include <linux/fec.h> #include <linux/delay.h> #include <linux/gpio.h> +#include <linux/ahci_platform.h> #include <mach/common.h> #include <mach/hardware.h> #include <mach/imx-uart.h> #include <mach/iomux-mx53.h> +#include <mach/ahci_sata.h> #include <asm/mach-types.h> #include <asm/mach/arch.h> @@ -38,6 +40,8 @@#define LOCO_FEC_PHY_RST IMX_GPIO_NR(7, 6) +static struct clk *sata_clk, *sata_ref_clk; +static iomux_v3_cfg_t mx53_loco_pads[] = {/* FEC */ MX53_PAD_FEC_MDC__FEC_MDC ,@@ -203,6 +207,89 @@ static const struct imxi2c_platform_data
mx53_loco_i2c_data__initconst= {Quoted 32 lines
arch/arm/mach-mx5/board-mx53_loco.c +29
-0.bitrate = 100000, }; +/* HW Initialization, if return 0, initialization is successful. */ +static int sata_init (struct device *dev,void __iomem *addr) { +int ret =0 ; +u32 tmpdata; +struct clk *clk; + + sata_clk =clk_get (dev,NULL ); +if (IS_ERR (sata_clk)) { +dev_err (dev,"no sata clock.\n" ); +return PTR_ERR (sata_clk); + } + ret =clk_enable (sata_clk); +if (ret) { +dev_err (dev,"can't enable sata clock.\n" ); +clk_put (sata_clk); +return ret; + } + +/* FSL IMX AHCI SATA uses the internal usb phy1 clk on loco */ + sata_ref_clk =clk_get (NULL ,"usb_phy1" ); +if (IS_ERR (sata_ref_clk)) { +dev_err (dev,"no sata ref clock.\n" ); + ret =PTR_ERR (sata_ref_clk); + goto release_sata_clk; + } + ret =clk_enable (sata_ref_clk); +if (ret) { +dev_err (dev,"can't enable sata ref clock.\n" ); +clk_put (sata_ref_clk);arch/arm/mach-mx5/board-mx53_loco.c static const struct imxi2c_platform_data mx53_loco_i2c_data __initconst = { · line 249
Quoted 10 lines
arch/arm/mach-mx5/board-mx53_loco.c +10
-0+ goto release_sata_clk; + } + +/* Get the AHB clock rate, and configure the TIMER1MS reg later */ + clk =clk_get (NULL ,"ahb" ); +if (IS_ERR (clk)) { +dev_err (dev,"no ahb clock.\n" ); + ret =PTR_ERR (clk); + goto release_sata_ref_clk; + }When I read code like this I think that a
devm_clk_getis overdue.
Quoted 1 line
Also, the ahci driver should handle the regular
[Richard]Sorry, I can't catch what's the exact means of this comment.
Quoted 8 lines
arch/arm/mach-mx5/board-mx53_loco.c static const struct imxi2c_platform_data mx53_loco_i2c_data __initconst = { · line 255
Quoted 7 lines
arch/arm/mach-mx5/board-mx53_loco.c +6
-0+ + tmpdata =readl (addr +HOST_CAP ); +if (!(tmpdata &HOST_CAP_SSS )) { + tmpdata |=HOST_CAP_SSS ; +writel (tmpdata, addr +HOST_CAP ); + }
Quoted 9 lines
According to the AHCI spec this bit is read only.
arch/arm/mach-mx5/board-mx53_loco.c static const struct imxi2c_platform_data mx53_loco_i2c_data __initconst = { · line 259
Quoted 4 lines
arch/arm/mach-mx5/board-mx53_loco.c +4
-0+ +if (!(readl (addr +HOST_PORTS_IMPL ) &0x1 )) +writel ((readl (addr +HOST_PORTS_IMPL ) |0x1 ), + addr +HOST_PORTS_IMPL );This is also readonly.
[Richard]:About the RO marked bits defined in the SPEC, there are used
as R/W bits in MX53 AHCI implementation actually.
Here are the hack debug log:
----------Log--------------------HOST_CAP: 0x6726ff80HOST_CAP: 0x6f26ff80 <------------ After set the SSS bit.HOST_PT_IMPL: 0x0HOST_PT_IMPL: 0x1 <------------ After set the IMPL bit
ahci: SSS flag set, parallel bus scan disabled
ahci ahci.0: AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl platform mode ahci ahci.0: flags: ncq sntf stag pm led clo only pmp pio slum part ccc scsi0 : ahci
ata1: SATA max UDMA/133 irq_stat 0x00000040, connection status changed irq 28 MXC MTD nand Driver 3.0
----------End--------------------
Quoted 8 lines
arch/arm/mach-mx5/board-mx53_loco.c static const struct imxi2c_platform_data mx53_loco_i2c_data __initconst = { · line 263
Quoted 4 lines
arch/arm/mach-mx5/board-mx53_loco.c +4
-0+ + tmpdata =clk_get_rate (clk) /1000 ; +clk_put (clk); +writel (tmpdata, addr +HOST_TIMER1MS );This should be in a more generic place as it needs to be done for every board. We can put this into some i.MX53 startup function.
[Richard]How about put these codes into one standalone file in .../arch/arm/plat-mxc/ folder,
and export the sata_init and sata_exit out for kinds of MX53 boards?
Quoted 10 lines
--
Pengutronix e.K. |
|
Industrial Linux Solutions | http://www.pengutronix.de/
|
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555
|
Sascha Hauer
maintainerPATCH v2 2/2 MX53 Enable the AHCI SATA on MX53 LOCO
Quoted 5 lines · On Fri, Apr 08, 2011 at 08:49:28AM +0000, Zhu Richard-R65037 wrote:
Quoted 4 lines
When I read code like this I think that a
devm_clk_getis overdue.Also, the ahci driver should handle the regular
[Richard]Sorry, I can't catch what's the exact means of this comment.
devm_* are a set of functions which track the resources a driver allocates and frees them automatically when the driver exits. See for example the ahci driver. It uses devm_kzalloc and devm_ioremap. devm_clk_get would be nice to have also.
Quoted 18 lines
Quoted 9 lines
arch/arm/mach-mx5/board-mx53_loco.c static const struct imxi2c_platform_data mx53_loco_i2c_data __initconst = { · line 255
Quoted 8 lines
arch/arm/mach-mx5/board-mx53_loco.c +6
-0+ + tmpdata =readl (addr +HOST_CAP ); +if (!(tmpdata &HOST_CAP_SSS )) { + tmpdata |=HOST_CAP_SSS ; +writel (tmpdata, addr +HOST_CAP ); + }Quoted 9 lines
According to the AHCI spec this bit is read only.
arch/arm/mach-mx5/board-mx53_loco.c static const struct imxi2c_platform_data mx53_loco_i2c_data __initconst = { · line 259
Quoted 4 lines
arch/arm/mach-mx5/board-mx53_loco.c +4
-0+ +if (!(readl (addr +HOST_PORTS_IMPL ) &0x1 )) +writel ((readl (addr +HOST_PORTS_IMPL ) |0x1 ), + addr +HOST_PORTS_IMPL );This is also readonly.
Quoted 15 lines
[Richard]:About the RO marked bits defined in the SPEC, there are used
as R/W bits in MX53 AHCI implementation actually.
Here are the hack debug log:
----------Log--------------------HOST_CAP:0x6726ff80HOST_CAP:0x6f26ff80<------------ After set the SSS bit.HOST_PT_IMPL:0x0HOST_PT_IMPL:0x1<------------ After set the IMPL bit
ahci: SSS flag set, parallel bus scan disabled
ahci ahci.0: AHCI 0001.0100 32 slots 1 ports 3 Gbps0x1impl platform mode ahci ahci.0: flags: ncq sntf stag pm led clo only pmp pio slum part ccc scsi0 : ahci
ata1: SATA max UDMA/133irq_stat0x00000040, connection status changed irq 28 MXC MTD nand Driver 3.0
----------End--------------------
Sigh. At least they tried to implement a standard...
Quoted 10 lines
Quoted 8 lines
arch/arm/mach-mx5/board-mx53_loco.c static const struct imxi2c_platform_data mx53_loco_i2c_data __initconst = { · line 263
Quoted 4 lines
arch/arm/mach-mx5/board-mx53_loco.c +4
-0+ + tmpdata =clk_get_rate (clk) /1000 ; +clk_put (clk); +writel (tmpdata, addr +HOST_TIMER1MS );This should be in a more generic place as it needs to be done for every board. We can put this into some i.MX53 startup function.
[Richard]How about put these codes into one standalone file in .../arch/arm/plat-mxc/ folder,
and export thesata_initandsata_exitout for kinds of MX53 boards?
Yes, probably except the special clock usage on the loco board.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |