diff options
author | Tomasz Figa <t.figa@samsung.com> | 2014-07-03 11:49:14 -0400 |
---|---|---|
committer | Kukjin Kim <kgene.kim@samsung.com> | 2014-07-18 15:32:15 -0400 |
commit | 6d4ed0f46af6c27ca2de4a7d586955aef38ef556 (patch) | |
tree | b9fca1fa7ed228973ef775d154f44675405052b5 /drivers/cpufreq | |
parent | 7d6764b38999e32188cbc82b5cd670682d11e837 (diff) |
cpufreq: s5pv210: Make the driver multiplatform aware
Signed-off-by: Tomasz Figa <t.figa@samsung.com>
Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
Diffstat (limited to 'drivers/cpufreq')
-rw-r--r-- | drivers/cpufreq/s5pv210-cpufreq.c | 131 |
1 files changed, 122 insertions, 9 deletions
diff --git a/drivers/cpufreq/s5pv210-cpufreq.c b/drivers/cpufreq/s5pv210-cpufreq.c index 19a10b89fef7..9a68225a757e 100644 --- a/drivers/cpufreq/s5pv210-cpufreq.c +++ b/drivers/cpufreq/s5pv210-cpufreq.c | |||
@@ -16,11 +16,70 @@ | |||
16 | #include <linux/clk.h> | 16 | #include <linux/clk.h> |
17 | #include <linux/io.h> | 17 | #include <linux/io.h> |
18 | #include <linux/cpufreq.h> | 18 | #include <linux/cpufreq.h> |
19 | #include <linux/of.h> | ||
20 | #include <linux/of_address.h> | ||
21 | #include <linux/platform_device.h> | ||
19 | #include <linux/reboot.h> | 22 | #include <linux/reboot.h> |
20 | #include <linux/regulator/consumer.h> | 23 | #include <linux/regulator/consumer.h> |
21 | 24 | ||
22 | #include <mach/map.h> | 25 | static void __iomem *clk_base; |
23 | #include <mach/regs-clock.h> | 26 | static void __iomem *dmc_base[2]; |
27 | |||
28 | #define S5P_CLKREG(x) (clk_base + (x)) | ||
29 | |||
30 | #define S5P_APLL_LOCK S5P_CLKREG(0x00) | ||
31 | #define S5P_APLL_CON S5P_CLKREG(0x100) | ||
32 | #define S5P_CLK_SRC0 S5P_CLKREG(0x200) | ||
33 | #define S5P_CLK_SRC2 S5P_CLKREG(0x208) | ||
34 | #define S5P_CLK_DIV0 S5P_CLKREG(0x300) | ||
35 | #define S5P_CLK_DIV2 S5P_CLKREG(0x308) | ||
36 | #define S5P_CLK_DIV6 S5P_CLKREG(0x318) | ||
37 | #define S5P_CLKDIV_STAT0 S5P_CLKREG(0x1000) | ||
38 | #define S5P_CLKDIV_STAT1 S5P_CLKREG(0x1004) | ||
39 | #define S5P_CLKMUX_STAT0 S5P_CLKREG(0x1100) | ||
40 | #define S5P_CLKMUX_STAT1 S5P_CLKREG(0x1104) | ||
41 | |||
42 | #define S5P_ARM_MCS_CON S5P_CLKREG(0x6100) | ||
43 | |||
44 | /* CLKSRC0 */ | ||
45 | #define S5P_CLKSRC0_MUX200_SHIFT (16) | ||
46 | #define S5P_CLKSRC0_MUX200_MASK (0x1 << S5P_CLKSRC0_MUX200_SHIFT) | ||
47 | #define S5P_CLKSRC0_MUX166_MASK (0x1<<20) | ||
48 | #define S5P_CLKSRC0_MUX133_MASK (0x1<<24) | ||
49 | |||
50 | /* CLKSRC2 */ | ||
51 | #define S5P_CLKSRC2_G3D_SHIFT (0) | ||
52 | #define S5P_CLKSRC2_G3D_MASK (0x3 << S5P_CLKSRC2_G3D_SHIFT) | ||
53 | #define S5P_CLKSRC2_MFC_SHIFT (4) | ||
54 | #define S5P_CLKSRC2_MFC_MASK (0x3 << S5P_CLKSRC2_MFC_SHIFT) | ||
55 | |||
56 | /* CLKDIV0 */ | ||
57 | #define S5P_CLKDIV0_APLL_SHIFT (0) | ||
58 | #define S5P_CLKDIV0_APLL_MASK (0x7 << S5P_CLKDIV0_APLL_SHIFT) | ||
59 | #define S5P_CLKDIV0_A2M_SHIFT (4) | ||
60 | #define S5P_CLKDIV0_A2M_MASK (0x7 << S5P_CLKDIV0_A2M_SHIFT) | ||
61 | #define S5P_CLKDIV0_HCLK200_SHIFT (8) | ||
62 | #define S5P_CLKDIV0_HCLK200_MASK (0x7 << S5P_CLKDIV0_HCLK200_SHIFT) | ||
63 | #define S5P_CLKDIV0_PCLK100_SHIFT (12) | ||
64 | #define S5P_CLKDIV0_PCLK100_MASK (0x7 << S5P_CLKDIV0_PCLK100_SHIFT) | ||
65 | #define S5P_CLKDIV0_HCLK166_SHIFT (16) | ||
66 | #define S5P_CLKDIV0_HCLK166_MASK (0xF << S5P_CLKDIV0_HCLK166_SHIFT) | ||
67 | #define S5P_CLKDIV0_PCLK83_SHIFT (20) | ||
68 | #define S5P_CLKDIV0_PCLK83_MASK (0x7 << S5P_CLKDIV0_PCLK83_SHIFT) | ||
69 | #define S5P_CLKDIV0_HCLK133_SHIFT (24) | ||
70 | #define S5P_CLKDIV0_HCLK133_MASK (0xF << S5P_CLKDIV0_HCLK133_SHIFT) | ||
71 | #define S5P_CLKDIV0_PCLK66_SHIFT (28) | ||
72 | #define S5P_CLKDIV0_PCLK66_MASK (0x7 << S5P_CLKDIV0_PCLK66_SHIFT) | ||
73 | |||
74 | /* CLKDIV2 */ | ||
75 | #define S5P_CLKDIV2_G3D_SHIFT (0) | ||
76 | #define S5P_CLKDIV2_G3D_MASK (0xF << S5P_CLKDIV2_G3D_SHIFT) | ||
77 | #define S5P_CLKDIV2_MFC_SHIFT (4) | ||
78 | #define S5P_CLKDIV2_MFC_MASK (0xF << S5P_CLKDIV2_MFC_SHIFT) | ||
79 | |||
80 | /* CLKDIV6 */ | ||
81 | #define S5P_CLKDIV6_ONEDRAM_SHIFT (28) | ||
82 | #define S5P_CLKDIV6_ONEDRAM_MASK (0xF << S5P_CLKDIV6_ONEDRAM_SHIFT) | ||
24 | 83 | ||
25 | static struct clk *dmc0_clk; | 84 | static struct clk *dmc0_clk; |
26 | static struct clk *dmc1_clk; | 85 | static struct clk *dmc1_clk; |
@@ -142,9 +201,9 @@ static void s5pv210_set_refresh(enum s5pv210_dmc_port ch, unsigned long freq) | |||
142 | void __iomem *reg = NULL; | 201 | void __iomem *reg = NULL; |
143 | 202 | ||
144 | if (ch == DMC0) { | 203 | if (ch == DMC0) { |
145 | reg = (S5P_VA_DMC0 + 0x30); | 204 | reg = (dmc_base[0] + 0x30); |
146 | } else if (ch == DMC1) { | 205 | } else if (ch == DMC1) { |
147 | reg = (S5P_VA_DMC1 + 0x30); | 206 | reg = (dmc_base[1] + 0x30); |
148 | } else { | 207 | } else { |
149 | printk(KERN_ERR "Cannot find DMC port\n"); | 208 | printk(KERN_ERR "Cannot find DMC port\n"); |
150 | return; | 209 | return; |
@@ -472,7 +531,7 @@ static int __init s5pv210_cpu_init(struct cpufreq_policy *policy) | |||
472 | * check_mem_type : This driver only support LPDDR & LPDDR2. | 531 | * check_mem_type : This driver only support LPDDR & LPDDR2. |
473 | * other memory type is not supported. | 532 | * other memory type is not supported. |
474 | */ | 533 | */ |
475 | mem_type = check_mem_type(S5P_VA_DMC0); | 534 | mem_type = check_mem_type(dmc_base[0]); |
476 | 535 | ||
477 | if ((mem_type != LPDDR) && (mem_type != LPDDR2)) { | 536 | if ((mem_type != LPDDR) && (mem_type != LPDDR2)) { |
478 | printk(KERN_ERR "CPUFreq doesn't support this memory type\n"); | 537 | printk(KERN_ERR "CPUFreq doesn't support this memory type\n"); |
@@ -481,10 +540,10 @@ static int __init s5pv210_cpu_init(struct cpufreq_policy *policy) | |||
481 | } | 540 | } |
482 | 541 | ||
483 | /* Find current refresh counter and frequency each DMC */ | 542 | /* Find current refresh counter and frequency each DMC */ |
484 | s5pv210_dram_conf[0].refresh = (__raw_readl(S5P_VA_DMC0 + 0x30) * 1000); | 543 | s5pv210_dram_conf[0].refresh = (__raw_readl(dmc_base[0] + 0x30) * 1000); |
485 | s5pv210_dram_conf[0].freq = clk_get_rate(dmc0_clk); | 544 | s5pv210_dram_conf[0].freq = clk_get_rate(dmc0_clk); |
486 | 545 | ||
487 | s5pv210_dram_conf[1].refresh = (__raw_readl(S5P_VA_DMC1 + 0x30) * 1000); | 546 | s5pv210_dram_conf[1].refresh = (__raw_readl(dmc_base[1] + 0x30) * 1000); |
488 | s5pv210_dram_conf[1].freq = clk_get_rate(dmc1_clk); | 547 | s5pv210_dram_conf[1].freq = clk_get_rate(dmc1_clk); |
489 | 548 | ||
490 | policy->suspend_freq = SLEEP_FREQ; | 549 | policy->suspend_freq = SLEEP_FREQ; |
@@ -527,8 +586,55 @@ static struct notifier_block s5pv210_cpufreq_reboot_notifier = { | |||
527 | .notifier_call = s5pv210_cpufreq_reboot_notifier_event, | 586 | .notifier_call = s5pv210_cpufreq_reboot_notifier_event, |
528 | }; | 587 | }; |
529 | 588 | ||
530 | static int __init s5pv210_cpufreq_init(void) | 589 | static int s5pv210_cpufreq_probe(struct platform_device *pdev) |
531 | { | 590 | { |
591 | struct device_node *np; | ||
592 | int id; | ||
593 | |||
594 | /* | ||
595 | * HACK: This is a temporary workaround to get access to clock | ||
596 | * and DMC controller registers directly and remove static mappings | ||
597 | * and dependencies on platform headers. It is necessary to enable | ||
598 | * S5PV210 multi-platform support and will be removed together with | ||
599 | * this whole driver as soon as S5PV210 gets migrated to use | ||
600 | * cpufreq-cpu0 driver. | ||
601 | */ | ||
602 | np = of_find_compatible_node(NULL, NULL, "samsung,s5pv210-clock"); | ||
603 | if (!np) { | ||
604 | pr_err("%s: failed to find clock controller DT node\n", | ||
605 | __func__); | ||
606 | return -ENODEV; | ||
607 | } | ||
608 | |||
609 | clk_base = of_iomap(np, 0); | ||
610 | if (!clk_base) { | ||
611 | pr_err("%s: failed to map clock registers\n", __func__); | ||
612 | return -EFAULT; | ||
613 | } | ||
614 | |||
615 | for_each_compatible_node(np, NULL, "samsung,s5pv210-dmc") { | ||
616 | id = of_alias_get_id(np, "dmc"); | ||
617 | if (id < 0 || id >= ARRAY_SIZE(dmc_base)) { | ||
618 | pr_err("%s: failed to get alias of dmc node '%s'\n", | ||
619 | __func__, np->name); | ||
620 | return id; | ||
621 | } | ||
622 | |||
623 | dmc_base[id] = of_iomap(np, 0); | ||
624 | if (!dmc_base[id]) { | ||
625 | pr_err("%s: failed to map dmc%d registers\n", | ||
626 | __func__, id); | ||
627 | return -EFAULT; | ||
628 | } | ||
629 | } | ||
630 | |||
631 | for (id = 0; id < ARRAY_SIZE(dmc_base); ++id) { | ||
632 | if (!dmc_base[id]) { | ||
633 | pr_err("%s: failed to find dmc%d node\n", __func__, id); | ||
634 | return -ENODEV; | ||
635 | } | ||
636 | } | ||
637 | |||
532 | arm_regulator = regulator_get(NULL, "vddarm"); | 638 | arm_regulator = regulator_get(NULL, "vddarm"); |
533 | if (IS_ERR(arm_regulator)) { | 639 | if (IS_ERR(arm_regulator)) { |
534 | pr_err("failed to get regulator vddarm"); | 640 | pr_err("failed to get regulator vddarm"); |
@@ -547,4 +653,11 @@ static int __init s5pv210_cpufreq_init(void) | |||
547 | return cpufreq_register_driver(&s5pv210_driver); | 653 | return cpufreq_register_driver(&s5pv210_driver); |
548 | } | 654 | } |
549 | 655 | ||
550 | late_initcall(s5pv210_cpufreq_init); | 656 | static struct platform_driver s5pv210_cpufreq_platdrv = { |
657 | .driver = { | ||
658 | .name = "s5pv210-cpufreq", | ||
659 | .owner = THIS_MODULE, | ||
660 | }, | ||
661 | .probe = s5pv210_cpufreq_probe, | ||
662 | }; | ||
663 | module_platform_driver(s5pv210_cpufreq_platdrv); | ||