tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / platform / sprd / iomap.c
1 /*
2  * Copyright (C) 2014 Spreadtrum Communications Inc.
3  * This software is licensed under the terms of the GNU General Public
4  * License version 2, as published by the Free Software Foundation, and
5  * may be copied, distributed, and modified under those terms.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  */
12
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/vmalloc.h>
18 #include <linux/of.h>
19 #include <linux/of_address.h>
20 #include <asm/io.h>
21 #include <soc/sprd/sci_glb_regs.h>
22
23 struct iotable_sprd io_addr_sprd;
24 EXPORT_SYMBOL_GPL(io_addr_sprd);
25
26 #define ADD_SPRD_DEVICE_BY_COMPAT(compat, id)           \
27 do {                                                    \
28         np = of_find_compatible_node(NULL, NULL, compat);\
29         if (of_can_translate_address(np)) {             \
30                 of_address_to_resource(np, 0, &res);    \
31                 io_addr_sprd.id.paddr = res.start;      \
32                 io_addr_sprd.id.length =                \
33                         resource_size(&res);            \
34                 io_addr_sprd.id.vaddr = base + res.start;\
35                 pr_debug("sprd io map: phys=%16lx virt=%16lx size=%16lx\n", \
36         io_addr_sprd.id.paddr, io_addr_sprd.id.vaddr, io_addr_sprd.id.length);\
37         }                                               \
38 } while (0)
39
40 #define ADD_SPRD_DEVICE_BY_NAME(name, id)               \
41 do {                                                    \
42         np = of_find_node_by_name(NULL, name);          \
43         if (of_can_translate_address(np)) {             \
44                 of_address_to_resource(np, 0, &res);    \
45                 io_addr_sprd.id.paddr = res.start;      \
46                 io_addr_sprd.id.length =                \
47                         resource_size(&res);            \
48                 io_addr_sprd.id.vaddr = base + res.start;\
49                 pr_debug("sprd io map: phys=%16lx virt=%16lx size=%16lx\n", \
50         io_addr_sprd.id.paddr, io_addr_sprd.id.vaddr, io_addr_sprd.id.length);\
51         }                                               \
52 } while (0)
53
54 static int sprd_create_iomap(void)
55 {
56         struct device_node *np;
57         struct resource res;
58         unsigned long base;
59
60         base = (unsigned long) ioremap_nocache(0, SZ_2G);
61         if (!base)
62                 panic("%s: unable to alloc such memory!", __func__);
63         io_addr_sprd.base = base;
64         pr_debug("sprd io map base address: %016x\n", base);
65
66         ADD_SPRD_DEVICE_BY_COMPAT("sprd,ahb", AHB);
67         ADD_SPRD_DEVICE_BY_COMPAT("sprd,apbckg", APBCKG);
68         //ADD_SPRD_DEVICE_BY_COMPAT("sprd,hwlock0", HWLOCK0);
69         ADD_SPRD_DEVICE_BY_COMPAT("sprd,pub_apb", PUB);
70         ADD_SPRD_DEVICE_BY_COMPAT("sprd,aon_apb", AONAPB);
71         ADD_SPRD_DEVICE_BY_COMPAT("sprd,pmu_apb", PMU);
72         ADD_SPRD_DEVICE_BY_COMPAT("sprd,mm_ahb", MMAHB);
73         ADD_SPRD_DEVICE_BY_COMPAT("sprd,mm_clk", MMCKG);
74         ADD_SPRD_DEVICE_BY_COMPAT("sprd,ap_apb", APBREG);
75         ADD_SPRD_DEVICE_BY_COMPAT("sprd,dma0", DMA0);
76         ADD_SPRD_DEVICE_BY_COMPAT("sprd,gpu_apb", GPUAPB);
77         ADD_SPRD_DEVICE_BY_COMPAT("sprd,ap_ckg", APCKG);
78         ADD_SPRD_DEVICE_BY_COMPAT("sprd,aon_dma", AONDMA);
79         ADD_SPRD_DEVICE_BY_COMPAT("sprd,pwm", PWM);
80         ADD_SPRD_DEVICE_BY_NAME("hwspinlock0", HWSPINLOCK0);
81         ADD_SPRD_DEVICE_BY_NAME("hwspinlock1", HWSPINLOCK1);
82         ADD_SPRD_DEVICE_BY_COMPAT("sprd,intc2", INTC2);
83         ADD_SPRD_DEVICE_BY_COMPAT("sprd,aonckg", AONCKG);
84         ADD_SPRD_DEVICE_BY_COMPAT("sprd,core", CORE);
85         ADD_SPRD_DEVICE_BY_COMPAT("sprd,gpuckg", GPUCKG);
86         ADD_SPRD_DEVICE_BY_COMPAT("sprd,int", INT);
87         ADD_SPRD_DEVICE_BY_COMPAT("sprd,intc0", INTC0);
88         ADD_SPRD_DEVICE_BY_COMPAT("sprd,intc1", INTC1);
89         ADD_SPRD_DEVICE_BY_COMPAT("sprd,intc3", INTC3);
90         ADD_SPRD_DEVICE_BY_COMPAT("sprd,uidefuse", UIDEFUSE);
91         ADD_SPRD_DEVICE_BY_COMPAT("sprd,isp", ISP);
92         ADD_SPRD_DEVICE_BY_COMPAT("sprd,csi2", CSI2);
93         ADD_SPRD_DEVICE_BY_COMPAT("sprd,d-eic-gpio", EIC);
94         ADD_SPRD_DEVICE_BY_COMPAT("sprd,ipi", IPI);
95         ADD_SPRD_DEVICE_BY_COMPAT("sprd,dcam", DCAM);
96         ADD_SPRD_DEVICE_BY_COMPAT("sprd,syscnt", SYSCNT);
97         ADD_SPRD_DEVICE_BY_COMPAT("sprd,pin", PIN);
98         ADD_SPRD_DEVICE_BY_COMPAT("sprd,d-gpio-gpio", GPIO);
99 #if defined(CONFIG_ARCH_SCX35LT8)
100         ADD_SPRD_DEVICE_BY_COMPAT("sprd,codecahb", CODECAHB);
101 #endif
102         ADD_SPRD_DEVICE_BY_COMPAT("sprd,lpddr2", LPDDR2);
103         ADD_SPRD_DEVICE_BY_COMPAT("sprd,uart0", UART0);
104         ADD_SPRD_DEVICE_BY_COMPAT("sprd,uart1", UART1);
105         ADD_SPRD_DEVICE_BY_COMPAT("sprd,uart2", UART2);
106         ADD_SPRD_DEVICE_BY_COMPAT("sprd,uart3", UART3);
107         ADD_SPRD_DEVICE_BY_COMPAT("sprd,uart4", UART4);
108         return 0;
109 }
110
111 early_initcall(sprd_create_iomap);