diff options
author | Sekhar Nori <nsekhar@ti.com> | 2011-07-06 02:01:23 -0400 |
---|---|---|
committer | Sekhar Nori <nsekhar@ti.com> | 2011-07-08 01:43:08 -0400 |
commit | cbb2c9617ae80c99a7b290dbe5cf48ebf9a36ad9 (patch) | |
tree | ce7c6593adeac4044b5875a04d0ccae648791a6b | |
parent | aad70de20fc69970a3080e7e8f02b54a4a3fe3e6 (diff) |
davinci: da850: add support for SATA interface
Add support for SATA controller on the
DA850/OMAP-L138/AM18x devices.
The patch adds the necessary clocks, platform
resources and a routine to initialize the SATA
controller.
The PHY configuration in this patch is
courtesy the work done by Zegeye Alemu,
Swaminathan and Mansoor Ahamed from TI.
While testing this patch, enable port multiplier
support iff you are actually using one. The
reasons of this behaviour are discussed
here: http://patchwork.ozlabs.org/patch/78163/
ChangeLog:
v3:
Removed fields which were being initialized
to zero in PHY configuration. Moved SATA base
address definition to the top of the file to
make it inline with what is done for the rest
of the modules.
v2:
Addressed comments from Sergei. Removed unnecessary
braces and removed unnecessary else after goto.
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
-rw-r--r-- | arch/arm/mach-davinci/da850.c | 9 | ||||
-rw-r--r-- | arch/arm/mach-davinci/devices-da8xx.c | 126 | ||||
-rw-r--r-- | arch/arm/mach-davinci/include/mach/da8xx.h | 2 |
3 files changed, 137 insertions, 0 deletions
diff --git a/arch/arm/mach-davinci/da850.c b/arch/arm/mach-davinci/da850.c index 4e22b8da3493..935dbed5c541 100644 --- a/arch/arm/mach-davinci/da850.c +++ b/arch/arm/mach-davinci/da850.c | |||
@@ -374,6 +374,14 @@ static struct clk spi1_clk = { | |||
374 | .flags = DA850_CLK_ASYNC3, | 374 | .flags = DA850_CLK_ASYNC3, |
375 | }; | 375 | }; |
376 | 376 | ||
377 | static struct clk sata_clk = { | ||
378 | .name = "sata", | ||
379 | .parent = &pll0_sysclk2, | ||
380 | .lpsc = DA850_LPSC1_SATA, | ||
381 | .gpsc = 1, | ||
382 | .flags = PSC_FORCE, | ||
383 | }; | ||
384 | |||
377 | static struct clk_lookup da850_clks[] = { | 385 | static struct clk_lookup da850_clks[] = { |
378 | CLK(NULL, "ref", &ref_clk), | 386 | CLK(NULL, "ref", &ref_clk), |
379 | CLK(NULL, "pll0", &pll0_clk), | 387 | CLK(NULL, "pll0", &pll0_clk), |
@@ -420,6 +428,7 @@ static struct clk_lookup da850_clks[] = { | |||
420 | CLK(NULL, "usb20", &usb20_clk), | 428 | CLK(NULL, "usb20", &usb20_clk), |
421 | CLK("spi_davinci.0", NULL, &spi0_clk), | 429 | CLK("spi_davinci.0", NULL, &spi0_clk), |
422 | CLK("spi_davinci.1", NULL, &spi1_clk), | 430 | CLK("spi_davinci.1", NULL, &spi1_clk), |
431 | CLK("ahci", NULL, &sata_clk), | ||
423 | CLK(NULL, NULL, NULL), | 432 | CLK(NULL, NULL, NULL), |
424 | }; | 433 | }; |
425 | 434 | ||
diff --git a/arch/arm/mach-davinci/devices-da8xx.c b/arch/arm/mach-davinci/devices-da8xx.c index fc4e98ea7543..2f7e719636f1 100644 --- a/arch/arm/mach-davinci/devices-da8xx.c +++ b/arch/arm/mach-davinci/devices-da8xx.c | |||
@@ -14,6 +14,8 @@ | |||
14 | #include <linux/platform_device.h> | 14 | #include <linux/platform_device.h> |
15 | #include <linux/dma-mapping.h> | 15 | #include <linux/dma-mapping.h> |
16 | #include <linux/serial_8250.h> | 16 | #include <linux/serial_8250.h> |
17 | #include <linux/ahci_platform.h> | ||
18 | #include <linux/clk.h> | ||
17 | 19 | ||
18 | #include <mach/cputype.h> | 20 | #include <mach/cputype.h> |
19 | #include <mach/common.h> | 21 | #include <mach/common.h> |
@@ -33,6 +35,7 @@ | |||
33 | #define DA8XX_SPI0_BASE 0x01c41000 | 35 | #define DA8XX_SPI0_BASE 0x01c41000 |
34 | #define DA830_SPI1_BASE 0x01e12000 | 36 | #define DA830_SPI1_BASE 0x01e12000 |
35 | #define DA8XX_LCD_CNTRL_BASE 0x01e13000 | 37 | #define DA8XX_LCD_CNTRL_BASE 0x01e13000 |
38 | #define DA850_SATA_BASE 0x01e18000 | ||
36 | #define DA850_MMCSD1_BASE 0x01e1b000 | 39 | #define DA850_MMCSD1_BASE 0x01e1b000 |
37 | #define DA8XX_EMAC_CPPI_PORT_BASE 0x01e20000 | 40 | #define DA8XX_EMAC_CPPI_PORT_BASE 0x01e20000 |
38 | #define DA8XX_EMAC_CPGMACSS_BASE 0x01e22000 | 41 | #define DA8XX_EMAC_CPGMACSS_BASE 0x01e22000 |
@@ -842,3 +845,126 @@ int __init da8xx_register_spi(int instance, struct spi_board_info *info, | |||
842 | 845 | ||
843 | return platform_device_register(&da8xx_spi_device[instance]); | 846 | return platform_device_register(&da8xx_spi_device[instance]); |
844 | } | 847 | } |
848 | |||
849 | #ifdef CONFIG_ARCH_DAVINCI_DA850 | ||
850 | |||
851 | static struct resource da850_sata_resources[] = { | ||
852 | { | ||
853 | .start = DA850_SATA_BASE, | ||
854 | .end = DA850_SATA_BASE + 0x1fff, | ||
855 | .flags = IORESOURCE_MEM, | ||
856 | }, | ||
857 | { | ||
858 | .start = IRQ_DA850_SATAINT, | ||
859 | .flags = IORESOURCE_IRQ, | ||
860 | }, | ||
861 | }; | ||
862 | |||
863 | /* SATA PHY Control Register offset from AHCI base */ | ||
864 | #define SATA_P0PHYCR_REG 0x178 | ||
865 | |||
866 | #define SATA_PHY_MPY(x) ((x) << 0) | ||
867 | #define SATA_PHY_LOS(x) ((x) << 6) | ||
868 | #define SATA_PHY_RXCDR(x) ((x) << 10) | ||
869 | #define SATA_PHY_RXEQ(x) ((x) << 13) | ||
870 | #define SATA_PHY_TXSWING(x) ((x) << 19) | ||
871 | #define SATA_PHY_ENPLL(x) ((x) << 31) | ||
872 | |||
873 | static struct clk *da850_sata_clk; | ||
874 | static unsigned long da850_sata_refclkpn; | ||
875 | |||
876 | /* Supported DA850 SATA crystal frequencies */ | ||
877 | #define KHZ_TO_HZ(freq) ((freq) * 1000) | ||
878 | static unsigned long da850_sata_xtal[] = { | ||
879 | KHZ_TO_HZ(300000), | ||
880 | KHZ_TO_HZ(250000), | ||
881 | 0, /* Reserved */ | ||
882 | KHZ_TO_HZ(187500), | ||
883 | KHZ_TO_HZ(150000), | ||
884 | KHZ_TO_HZ(125000), | ||
885 | KHZ_TO_HZ(120000), | ||
886 | KHZ_TO_HZ(100000), | ||
887 | KHZ_TO_HZ(75000), | ||
888 | KHZ_TO_HZ(60000), | ||
889 | }; | ||
890 | |||
891 | static int da850_sata_init(struct device *dev, void __iomem *addr) | ||
892 | { | ||
893 | int i, ret; | ||
894 | unsigned int val; | ||
895 | |||
896 | da850_sata_clk = clk_get(dev, NULL); | ||
897 | if (IS_ERR(da850_sata_clk)) | ||
898 | return PTR_ERR(da850_sata_clk); | ||
899 | |||
900 | ret = clk_enable(da850_sata_clk); | ||
901 | if (ret) | ||
902 | goto err0; | ||
903 | |||
904 | /* Enable SATA clock receiver */ | ||
905 | val = __raw_readl(DA8XX_SYSCFG1_VIRT(DA8XX_PWRDN_REG)); | ||
906 | val &= ~BIT(0); | ||
907 | __raw_writel(val, DA8XX_SYSCFG1_VIRT(DA8XX_PWRDN_REG)); | ||
908 | |||
909 | /* Get the multiplier needed for 1.5GHz PLL output */ | ||
910 | for (i = 0; i < ARRAY_SIZE(da850_sata_xtal); i++) | ||
911 | if (da850_sata_xtal[i] == da850_sata_refclkpn) | ||
912 | break; | ||
913 | |||
914 | if (i == ARRAY_SIZE(da850_sata_xtal)) { | ||
915 | ret = -EINVAL; | ||
916 | goto err1; | ||
917 | } | ||
918 | |||
919 | val = SATA_PHY_MPY(i + 1) | | ||
920 | SATA_PHY_LOS(1) | | ||
921 | SATA_PHY_RXCDR(4) | | ||
922 | SATA_PHY_RXEQ(1) | | ||
923 | SATA_PHY_TXSWING(3) | | ||
924 | SATA_PHY_ENPLL(1); | ||
925 | |||
926 | __raw_writel(val, addr + SATA_P0PHYCR_REG); | ||
927 | |||
928 | return 0; | ||
929 | |||
930 | err1: | ||
931 | clk_disable(da850_sata_clk); | ||
932 | err0: | ||
933 | clk_put(da850_sata_clk); | ||
934 | return ret; | ||
935 | } | ||
936 | |||
937 | static void da850_sata_exit(struct device *dev) | ||
938 | { | ||
939 | clk_disable(da850_sata_clk); | ||
940 | clk_put(da850_sata_clk); | ||
941 | } | ||
942 | |||
943 | static struct ahci_platform_data da850_sata_pdata = { | ||
944 | .init = da850_sata_init, | ||
945 | .exit = da850_sata_exit, | ||
946 | }; | ||
947 | |||
948 | static u64 da850_sata_dmamask = DMA_BIT_MASK(32); | ||
949 | |||
950 | static struct platform_device da850_sata_device = { | ||
951 | .name = "ahci", | ||
952 | .id = -1, | ||
953 | .dev = { | ||
954 | .platform_data = &da850_sata_pdata, | ||
955 | .dma_mask = &da850_sata_dmamask, | ||
956 | .coherent_dma_mask = DMA_BIT_MASK(32), | ||
957 | }, | ||
958 | .num_resources = ARRAY_SIZE(da850_sata_resources), | ||
959 | .resource = da850_sata_resources, | ||
960 | }; | ||
961 | |||
962 | int __init da850_register_sata(unsigned long refclkpn) | ||
963 | { | ||
964 | da850_sata_refclkpn = refclkpn; | ||
965 | if (!da850_sata_refclkpn) | ||
966 | return -EINVAL; | ||
967 | |||
968 | return platform_device_register(&da850_sata_device); | ||
969 | } | ||
970 | #endif | ||
diff --git a/arch/arm/mach-davinci/include/mach/da8xx.h b/arch/arm/mach-davinci/include/mach/da8xx.h index ad64da713fc8..eaca7d8b9d68 100644 --- a/arch/arm/mach-davinci/include/mach/da8xx.h +++ b/arch/arm/mach-davinci/include/mach/da8xx.h | |||
@@ -57,6 +57,7 @@ extern unsigned int da850_max_speed; | |||
57 | #define DA8XX_SYSCFG1_BASE (IO_PHYS + 0x22C000) | 57 | #define DA8XX_SYSCFG1_BASE (IO_PHYS + 0x22C000) |
58 | #define DA8XX_SYSCFG1_VIRT(x) (da8xx_syscfg1_base + (x)) | 58 | #define DA8XX_SYSCFG1_VIRT(x) (da8xx_syscfg1_base + (x)) |
59 | #define DA8XX_DEEPSLEEP_REG 0x8 | 59 | #define DA8XX_DEEPSLEEP_REG 0x8 |
60 | #define DA8XX_PWRDN_REG 0x18 | ||
60 | 61 | ||
61 | #define DA8XX_PSC0_BASE 0x01c10000 | 62 | #define DA8XX_PSC0_BASE 0x01c10000 |
62 | #define DA8XX_PLL0_BASE 0x01c11000 | 63 | #define DA8XX_PLL0_BASE 0x01c11000 |
@@ -89,6 +90,7 @@ int da850_register_cpufreq(char *async_clk); | |||
89 | int da8xx_register_cpuidle(void); | 90 | int da8xx_register_cpuidle(void); |
90 | void __iomem * __init da8xx_get_mem_ctlr(void); | 91 | void __iomem * __init da8xx_get_mem_ctlr(void); |
91 | int da850_register_pm(struct platform_device *pdev); | 92 | int da850_register_pm(struct platform_device *pdev); |
93 | int __init da850_register_sata(unsigned long refclkpn); | ||
92 | 94 | ||
93 | extern struct platform_device da8xx_serial_device; | 95 | extern struct platform_device da8xx_serial_device; |
94 | extern struct emac_platform_data da8xx_emac_pdata; | 96 | extern struct emac_platform_data da8xx_emac_pdata; |