aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-davinci/da850.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-davinci/da850.c')
-rw-r--r--arch/arm/mach-davinci/da850.c298
1 files changed, 276 insertions, 22 deletions
diff --git a/arch/arm/mach-davinci/da850.c b/arch/arm/mach-davinci/da850.c
index 192d719a47df..717806c6cef9 100644
--- a/arch/arm/mach-davinci/da850.c
+++ b/arch/arm/mach-davinci/da850.c
@@ -11,31 +11,41 @@
11 * is licensed "as is" without any warranty of any kind, whether express 11 * is licensed "as is" without any warranty of any kind, whether express
12 * or implied. 12 * or implied.
13 */ 13 */
14#include <linux/kernel.h>
15#include <linux/init.h> 14#include <linux/init.h>
16#include <linux/clk.h> 15#include <linux/clk.h>
17#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/cpufreq.h>
18#include <linux/regulator/consumer.h>
18 19
19#include <asm/mach/map.h> 20#include <asm/mach/map.h>
20 21
21#include <mach/clock.h>
22#include <mach/psc.h> 22#include <mach/psc.h>
23#include <mach/mux.h>
24#include <mach/irqs.h> 23#include <mach/irqs.h>
25#include <mach/cputype.h> 24#include <mach/cputype.h>
26#include <mach/common.h> 25#include <mach/common.h>
27#include <mach/time.h> 26#include <mach/time.h>
28#include <mach/da8xx.h> 27#include <mach/da8xx.h>
28#include <mach/cpufreq.h>
29 29
30#include "clock.h" 30#include "clock.h"
31#include "mux.h" 31#include "mux.h"
32 32
33/* SoC specific clock flags */
34#define DA850_CLK_ASYNC3 BIT(16)
35
33#define DA850_PLL1_BASE 0x01e1a000 36#define DA850_PLL1_BASE 0x01e1a000
34#define DA850_TIMER64P2_BASE 0x01f0c000 37#define DA850_TIMER64P2_BASE 0x01f0c000
35#define DA850_TIMER64P3_BASE 0x01f0d000 38#define DA850_TIMER64P3_BASE 0x01f0d000
36 39
37#define DA850_REF_FREQ 24000000 40#define DA850_REF_FREQ 24000000
38 41
42#define CFGCHIP3_ASYNC3_CLKSRC BIT(4)
43#define CFGCHIP0_PLL_MASTER_LOCK BIT(4)
44
45static int da850_set_armrate(struct clk *clk, unsigned long rate);
46static int da850_round_armrate(struct clk *clk, unsigned long rate);
47static int da850_set_pll0rate(struct clk *clk, unsigned long armrate);
48
39static struct pll_data pll0_data = { 49static struct pll_data pll0_data = {
40 .num = 1, 50 .num = 1,
41 .phys_base = DA8XX_PLL0_BASE, 51 .phys_base = DA8XX_PLL0_BASE,
@@ -52,6 +62,7 @@ static struct clk pll0_clk = {
52 .parent = &ref_clk, 62 .parent = &ref_clk,
53 .pll_data = &pll0_data, 63 .pll_data = &pll0_data,
54 .flags = CLK_PLL, 64 .flags = CLK_PLL,
65 .set_rate = da850_set_pll0rate,
55}; 66};
56 67
57static struct clk pll0_aux_clk = { 68static struct clk pll0_aux_clk = {
@@ -210,16 +221,16 @@ static struct clk tpcc1_clk = {
210 .name = "tpcc1", 221 .name = "tpcc1",
211 .parent = &pll0_sysclk2, 222 .parent = &pll0_sysclk2,
212 .lpsc = DA850_LPSC1_TPCC1, 223 .lpsc = DA850_LPSC1_TPCC1,
224 .gpsc = 1,
213 .flags = CLK_PSC | ALWAYS_ENABLED, 225 .flags = CLK_PSC | ALWAYS_ENABLED,
214 .psc_ctlr = 1,
215}; 226};
216 227
217static struct clk tptc2_clk = { 228static struct clk tptc2_clk = {
218 .name = "tptc2", 229 .name = "tptc2",
219 .parent = &pll0_sysclk2, 230 .parent = &pll0_sysclk2,
220 .lpsc = DA850_LPSC1_TPTC2, 231 .lpsc = DA850_LPSC1_TPTC2,
232 .gpsc = 1,
221 .flags = ALWAYS_ENABLED, 233 .flags = ALWAYS_ENABLED,
222 .psc_ctlr = 1,
223}; 234};
224 235
225static struct clk uart0_clk = { 236static struct clk uart0_clk = {
@@ -232,14 +243,16 @@ static struct clk uart1_clk = {
232 .name = "uart1", 243 .name = "uart1",
233 .parent = &pll0_sysclk2, 244 .parent = &pll0_sysclk2,
234 .lpsc = DA8XX_LPSC1_UART1, 245 .lpsc = DA8XX_LPSC1_UART1,
235 .psc_ctlr = 1, 246 .gpsc = 1,
247 .flags = DA850_CLK_ASYNC3,
236}; 248};
237 249
238static struct clk uart2_clk = { 250static struct clk uart2_clk = {
239 .name = "uart2", 251 .name = "uart2",
240 .parent = &pll0_sysclk2, 252 .parent = &pll0_sysclk2,
241 .lpsc = DA8XX_LPSC1_UART2, 253 .lpsc = DA8XX_LPSC1_UART2,
242 .psc_ctlr = 1, 254 .gpsc = 1,
255 .flags = DA850_CLK_ASYNC3,
243}; 256};
244 257
245static struct clk aintc_clk = { 258static struct clk aintc_clk = {
@@ -253,22 +266,22 @@ static struct clk gpio_clk = {
253 .name = "gpio", 266 .name = "gpio",
254 .parent = &pll0_sysclk4, 267 .parent = &pll0_sysclk4,
255 .lpsc = DA8XX_LPSC1_GPIO, 268 .lpsc = DA8XX_LPSC1_GPIO,
256 .psc_ctlr = 1, 269 .gpsc = 1,
257}; 270};
258 271
259static struct clk i2c1_clk = { 272static struct clk i2c1_clk = {
260 .name = "i2c1", 273 .name = "i2c1",
261 .parent = &pll0_sysclk4, 274 .parent = &pll0_sysclk4,
262 .lpsc = DA8XX_LPSC1_I2C, 275 .lpsc = DA8XX_LPSC1_I2C,
263 .psc_ctlr = 1, 276 .gpsc = 1,
264}; 277};
265 278
266static struct clk emif3_clk = { 279static struct clk emif3_clk = {
267 .name = "emif3", 280 .name = "emif3",
268 .parent = &pll0_sysclk5, 281 .parent = &pll0_sysclk5,
269 .lpsc = DA8XX_LPSC1_EMIF3C, 282 .lpsc = DA8XX_LPSC1_EMIF3C,
283 .gpsc = 1,
270 .flags = ALWAYS_ENABLED, 284 .flags = ALWAYS_ENABLED,
271 .psc_ctlr = 1,
272}; 285};
273 286
274static struct clk arm_clk = { 287static struct clk arm_clk = {
@@ -276,6 +289,8 @@ static struct clk arm_clk = {
276 .parent = &pll0_sysclk6, 289 .parent = &pll0_sysclk6,
277 .lpsc = DA8XX_LPSC0_ARM, 290 .lpsc = DA8XX_LPSC0_ARM,
278 .flags = ALWAYS_ENABLED, 291 .flags = ALWAYS_ENABLED,
292 .set_rate = da850_set_armrate,
293 .round_rate = da850_round_armrate,
279}; 294};
280 295
281static struct clk rmii_clk = { 296static struct clk rmii_clk = {
@@ -287,21 +302,22 @@ static struct clk emac_clk = {
287 .name = "emac", 302 .name = "emac",
288 .parent = &pll0_sysclk4, 303 .parent = &pll0_sysclk4,
289 .lpsc = DA8XX_LPSC1_CPGMAC, 304 .lpsc = DA8XX_LPSC1_CPGMAC,
290 .psc_ctlr = 1, 305 .gpsc = 1,
291}; 306};
292 307
293static struct clk mcasp_clk = { 308static struct clk mcasp_clk = {
294 .name = "mcasp", 309 .name = "mcasp",
295 .parent = &pll0_sysclk2, 310 .parent = &pll0_sysclk2,
296 .lpsc = DA8XX_LPSC1_McASP0, 311 .lpsc = DA8XX_LPSC1_McASP0,
297 .psc_ctlr = 1, 312 .gpsc = 1,
313 .flags = DA850_CLK_ASYNC3,
298}; 314};
299 315
300static struct clk lcdc_clk = { 316static struct clk lcdc_clk = {
301 .name = "lcdc", 317 .name = "lcdc",
302 .parent = &pll0_sysclk2, 318 .parent = &pll0_sysclk2,
303 .lpsc = DA8XX_LPSC1_LCDC, 319 .lpsc = DA8XX_LPSC1_LCDC,
304 .psc_ctlr = 1, 320 .gpsc = 1,
305}; 321};
306 322
307static struct clk mmcsd_clk = { 323static struct clk mmcsd_clk = {
@@ -404,6 +420,14 @@ static const struct mux_config da850_pins[] = {
404 MUX_CFG(DA850, MII_RXD_0, 3, 28, 15, 8, false) 420 MUX_CFG(DA850, MII_RXD_0, 3, 28, 15, 8, false)
405 MUX_CFG(DA850, MDIO_CLK, 4, 0, 15, 8, false) 421 MUX_CFG(DA850, MDIO_CLK, 4, 0, 15, 8, false)
406 MUX_CFG(DA850, MDIO_D, 4, 4, 15, 8, false) 422 MUX_CFG(DA850, MDIO_D, 4, 4, 15, 8, false)
423 MUX_CFG(DA850, RMII_TXD_0, 14, 12, 15, 8, false)
424 MUX_CFG(DA850, RMII_TXD_1, 14, 8, 15, 8, false)
425 MUX_CFG(DA850, RMII_TXEN, 14, 16, 15, 8, false)
426 MUX_CFG(DA850, RMII_CRS_DV, 15, 4, 15, 8, false)
427 MUX_CFG(DA850, RMII_RXD_0, 14, 24, 15, 8, false)
428 MUX_CFG(DA850, RMII_RXD_1, 14, 20, 15, 8, false)
429 MUX_CFG(DA850, RMII_RXER, 14, 28, 15, 8, false)
430 MUX_CFG(DA850, RMII_MHZ_50_CLK, 15, 0, 15, 0, false)
407 /* McASP function */ 431 /* McASP function */
408 MUX_CFG(DA850, ACLKR, 0, 0, 15, 1, false) 432 MUX_CFG(DA850, ACLKR, 0, 0, 15, 1, false)
409 MUX_CFG(DA850, ACLKX, 0, 4, 15, 1, false) 433 MUX_CFG(DA850, ACLKX, 0, 4, 15, 1, false)
@@ -506,8 +530,9 @@ static const struct mux_config da850_pins[] = {
506 MUX_CFG(DA850, EMA_WAIT_1, 6, 24, 15, 1, false) 530 MUX_CFG(DA850, EMA_WAIT_1, 6, 24, 15, 1, false)
507 MUX_CFG(DA850, NEMA_CS_2, 7, 0, 15, 1, false) 531 MUX_CFG(DA850, NEMA_CS_2, 7, 0, 15, 1, false)
508 /* GPIO function */ 532 /* GPIO function */
533 MUX_CFG(DA850, GPIO2_6, 6, 4, 15, 8, false)
534 MUX_CFG(DA850, GPIO2_8, 5, 28, 15, 8, false)
509 MUX_CFG(DA850, GPIO2_15, 5, 0, 15, 8, false) 535 MUX_CFG(DA850, GPIO2_15, 5, 0, 15, 8, false)
510 MUX_CFG(DA850, GPIO8_10, 18, 28, 15, 8, false)
511 MUX_CFG(DA850, GPIO4_0, 10, 28, 15, 8, false) 536 MUX_CFG(DA850, GPIO4_0, 10, 28, 15, 8, false)
512 MUX_CFG(DA850, GPIO4_1, 10, 24, 15, 8, false) 537 MUX_CFG(DA850, GPIO4_1, 10, 24, 15, 8, false)
513#endif 538#endif
@@ -547,6 +572,14 @@ const short da850_cpgmac_pins[] __initdata = {
547 -1 572 -1
548}; 573};
549 574
575const short da850_rmii_pins[] __initdata = {
576 DA850_RMII_TXD_0, DA850_RMII_TXD_1, DA850_RMII_TXEN,
577 DA850_RMII_CRS_DV, DA850_RMII_RXD_0, DA850_RMII_RXD_1,
578 DA850_RMII_RXER, DA850_RMII_MHZ_50_CLK, DA850_MDIO_CLK,
579 DA850_MDIO_D,
580 -1
581};
582
550const short da850_mcasp_pins[] __initdata = { 583const short da850_mcasp_pins[] __initdata = {
551 DA850_AHCLKX, DA850_ACLKX, DA850_AFSX, 584 DA850_AHCLKX, DA850_ACLKX, DA850_AFSX,
552 DA850_AHCLKR, DA850_ACLKR, DA850_AFSR, DA850_AMUTE, 585 DA850_AHCLKR, DA850_ACLKR, DA850_AFSR, DA850_AMUTE,
@@ -555,12 +588,11 @@ const short da850_mcasp_pins[] __initdata = {
555}; 588};
556 589
557const short da850_lcdcntl_pins[] __initdata = { 590const short da850_lcdcntl_pins[] __initdata = {
558 DA850_LCD_D_1, DA850_LCD_D_2, DA850_LCD_D_3, DA850_LCD_D_4, 591 DA850_LCD_D_0, DA850_LCD_D_1, DA850_LCD_D_2, DA850_LCD_D_3,
559 DA850_LCD_D_5, DA850_LCD_D_6, DA850_LCD_D_7, DA850_LCD_D_8, 592 DA850_LCD_D_4, DA850_LCD_D_5, DA850_LCD_D_6, DA850_LCD_D_7,
560 DA850_LCD_D_9, DA850_LCD_D_10, DA850_LCD_D_11, DA850_LCD_D_12, 593 DA850_LCD_D_8, DA850_LCD_D_9, DA850_LCD_D_10, DA850_LCD_D_11,
561 DA850_LCD_D_13, DA850_LCD_D_14, DA850_LCD_D_15, DA850_LCD_PCLK, 594 DA850_LCD_D_12, DA850_LCD_D_13, DA850_LCD_D_14, DA850_LCD_D_15,
562 DA850_LCD_HSYNC, DA850_LCD_VSYNC, DA850_NLCD_AC_ENB_CS, DA850_GPIO2_15, 595 DA850_LCD_PCLK, DA850_LCD_HSYNC, DA850_LCD_VSYNC, DA850_NLCD_AC_ENB_CS,
563 DA850_GPIO8_10,
564 -1 596 -1
565}; 597};
566 598
@@ -790,16 +822,221 @@ static struct davinci_timer_info da850_timer_info = {
790 .clocksource_id = T0_TOP, 822 .clocksource_id = T0_TOP,
791}; 823};
792 824
825static void da850_set_async3_src(int pllnum)
826{
827 struct clk *clk, *newparent = pllnum ? &pll1_sysclk2 : &pll0_sysclk2;
828 struct davinci_clk *c;
829 unsigned int v;
830 int ret;
831
832 for (c = da850_clks; c->lk.clk; c++) {
833 clk = c->lk.clk;
834 if (clk->flags & DA850_CLK_ASYNC3) {
835 ret = clk_set_parent(clk, newparent);
836 WARN(ret, "DA850: unable to re-parent clock %s",
837 clk->name);
838 }
839 }
840
841 v = __raw_readl(DA8XX_SYSCFG_VIRT(DA8XX_CFGCHIP3_REG));
842 if (pllnum)
843 v |= CFGCHIP3_ASYNC3_CLKSRC;
844 else
845 v &= ~CFGCHIP3_ASYNC3_CLKSRC;
846 __raw_writel(v, DA8XX_SYSCFG_VIRT(DA8XX_CFGCHIP3_REG));
847}
848
849#ifdef CONFIG_CPU_FREQ
850/*
851 * Notes:
852 * According to the TRM, minimum PLLM results in maximum power savings.
853 * The OPP definitions below should keep the PLLM as low as possible.
854 *
855 * The output of the PLLM must be between 400 to 600 MHz.
856 * This rules out prediv of anything but divide-by-one for 24Mhz OSC input.
857 */
858struct da850_opp {
859 unsigned int freq; /* in KHz */
860 unsigned int prediv;
861 unsigned int mult;
862 unsigned int postdiv;
863 unsigned int cvdd_min; /* in uV */
864 unsigned int cvdd_max; /* in uV */
865};
866
867static const struct da850_opp da850_opp_300 = {
868 .freq = 300000,
869 .prediv = 1,
870 .mult = 25,
871 .postdiv = 2,
872 .cvdd_min = 1140000,
873 .cvdd_max = 1320000,
874};
875
876static const struct da850_opp da850_opp_200 = {
877 .freq = 200000,
878 .prediv = 1,
879 .mult = 25,
880 .postdiv = 3,
881 .cvdd_min = 1050000,
882 .cvdd_max = 1160000,
883};
884
885static const struct da850_opp da850_opp_96 = {
886 .freq = 96000,
887 .prediv = 1,
888 .mult = 20,
889 .postdiv = 5,
890 .cvdd_min = 950000,
891 .cvdd_max = 1050000,
892};
893
894#define OPP(freq) \
895 { \
896 .index = (unsigned int) &da850_opp_##freq, \
897 .frequency = freq * 1000, \
898 }
899
900static struct cpufreq_frequency_table da850_freq_table[] = {
901 OPP(300),
902 OPP(200),
903 OPP(96),
904 {
905 .index = 0,
906 .frequency = CPUFREQ_TABLE_END,
907 },
908};
909
910#ifdef CONFIG_REGULATOR
911static struct regulator *cvdd;
912
913static int da850_set_voltage(unsigned int index)
914{
915 struct da850_opp *opp;
916
917 if (!cvdd)
918 return -ENODEV;
919
920 opp = (struct da850_opp *) da850_freq_table[index].index;
921
922 return regulator_set_voltage(cvdd, opp->cvdd_min, opp->cvdd_max);
923}
924
925static int da850_regulator_init(void)
926{
927 cvdd = regulator_get(NULL, "cvdd");
928 if (WARN(IS_ERR(cvdd), "Unable to obtain voltage regulator for CVDD;"
929 " voltage scaling unsupported\n")) {
930 return PTR_ERR(cvdd);
931 }
932
933 return 0;
934}
935#endif
936
937static struct davinci_cpufreq_config cpufreq_info = {
938 .freq_table = &da850_freq_table[0],
939#ifdef CONFIG_REGULATOR
940 .init = da850_regulator_init,
941 .set_voltage = da850_set_voltage,
942#endif
943};
944
945static struct platform_device da850_cpufreq_device = {
946 .name = "cpufreq-davinci",
947 .dev = {
948 .platform_data = &cpufreq_info,
949 },
950};
951
952int __init da850_register_cpufreq(void)
953{
954 return platform_device_register(&da850_cpufreq_device);
955}
956
957static int da850_round_armrate(struct clk *clk, unsigned long rate)
958{
959 int i, ret = 0, diff;
960 unsigned int best = (unsigned int) -1;
961
962 rate /= 1000; /* convert to kHz */
963
964 for (i = 0; da850_freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
965 diff = da850_freq_table[i].frequency - rate;
966 if (diff < 0)
967 diff = -diff;
968
969 if (diff < best) {
970 best = diff;
971 ret = da850_freq_table[i].frequency;
972 }
973 }
974
975 return ret * 1000;
976}
977
978static int da850_set_armrate(struct clk *clk, unsigned long index)
979{
980 struct clk *pllclk = &pll0_clk;
981
982 return clk_set_rate(pllclk, index);
983}
984
985static int da850_set_pll0rate(struct clk *clk, unsigned long index)
986{
987 unsigned int prediv, mult, postdiv;
988 struct da850_opp *opp;
989 struct pll_data *pll = clk->pll_data;
990 unsigned int v;
991 int ret;
992
993 opp = (struct da850_opp *) da850_freq_table[index].index;
994 prediv = opp->prediv;
995 mult = opp->mult;
996 postdiv = opp->postdiv;
997
998 /* Unlock writing to PLL registers */
999 v = __raw_readl(DA8XX_SYSCFG_VIRT(DA8XX_CFGCHIP0_REG));
1000 v &= ~CFGCHIP0_PLL_MASTER_LOCK;
1001 __raw_writel(v, DA8XX_SYSCFG_VIRT(DA8XX_CFGCHIP0_REG));
1002
1003 ret = davinci_set_pllrate(pll, prediv, mult, postdiv);
1004 if (WARN_ON(ret))
1005 return ret;
1006
1007 return 0;
1008}
1009#else
1010int __init da850_register_cpufreq(void)
1011{
1012 return 0;
1013}
1014
1015static int da850_set_armrate(struct clk *clk, unsigned long rate)
1016{
1017 return -EINVAL;
1018}
1019
1020static int da850_set_pll0rate(struct clk *clk, unsigned long armrate)
1021{
1022 return -EINVAL;
1023}
1024
1025static int da850_round_armrate(struct clk *clk, unsigned long rate)
1026{
1027 return clk->rate;
1028}
1029#endif
1030
1031
793static struct davinci_soc_info davinci_soc_info_da850 = { 1032static struct davinci_soc_info davinci_soc_info_da850 = {
794 .io_desc = da850_io_desc, 1033 .io_desc = da850_io_desc,
795 .io_desc_num = ARRAY_SIZE(da850_io_desc), 1034 .io_desc_num = ARRAY_SIZE(da850_io_desc),
796 .jtag_id_base = IO_ADDRESS(DA8XX_JTAG_ID_REG),
797 .ids = da850_ids, 1035 .ids = da850_ids,
798 .ids_num = ARRAY_SIZE(da850_ids), 1036 .ids_num = ARRAY_SIZE(da850_ids),
799 .cpu_clks = da850_clks, 1037 .cpu_clks = da850_clks,
800 .psc_bases = da850_psc_bases, 1038 .psc_bases = da850_psc_bases,
801 .psc_bases_num = ARRAY_SIZE(da850_psc_bases), 1039 .psc_bases_num = ARRAY_SIZE(da850_psc_bases),
802 .pinmux_base = IO_ADDRESS(DA8XX_BOOT_CFG_BASE + 0x120),
803 .pinmux_pins = da850_pins, 1040 .pinmux_pins = da850_pins,
804 .pinmux_pins_num = ARRAY_SIZE(da850_pins), 1041 .pinmux_pins_num = ARRAY_SIZE(da850_pins),
805 .intc_base = (void __iomem *)DA8XX_CP_INTC_VIRT, 1042 .intc_base = (void __iomem *)DA8XX_CP_INTC_VIRT,
@@ -816,5 +1053,22 @@ static struct davinci_soc_info davinci_soc_info_da850 = {
816 1053
817void __init da850_init(void) 1054void __init da850_init(void)
818{ 1055{
1056 da8xx_syscfg_base = ioremap(DA8XX_SYSCFG_BASE, SZ_4K);
1057 if (WARN(!da8xx_syscfg_base, "Unable to map syscfg module"))
1058 return;
1059
1060 davinci_soc_info_da850.jtag_id_base =
1061 DA8XX_SYSCFG_VIRT(DA8XX_JTAG_ID_REG);
1062 davinci_soc_info_da850.pinmux_base = DA8XX_SYSCFG_VIRT(0x120);
1063
819 davinci_common_init(&davinci_soc_info_da850); 1064 davinci_common_init(&davinci_soc_info_da850);
1065
1066 /*
1067 * Move the clock source of Async3 domain to PLL1 SYSCLK2.
1068 * This helps keeping the peripherals on this domain insulated
1069 * from CPU frequency changes caused by DVFS. The firmware sets
1070 * both PLL0 and PLL1 to the same frequency so, there should not
1071 * be any noticible change even in non-DVFS use cases.
1072 */
1073 da850_set_async3_src(1);
820} 1074}