2 * Copyright (C) 2014 Spreadtrum Communications Inc.
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/platform_device.h>
17 #include <linux/delay.h>
18 #include <linux/export.h>
19 #include <linux/irqchip/arm-gic.h>
20 #include <linux/input.h>
23 #include <asm/setup.h>
24 #include <asm/mach/time.h>
25 #include <asm/mach/arch.h>
26 #include <asm/mach/map.h>
27 #include <asm/mach-types.h>
28 #include <asm/hardware/cache-l2x0.h>
29 #include <asm/localtimer.h>
30 #include <linux/of_platform.h>
32 #include <linux/of_address.h>
33 #include <linux/clocksource.h>
34 #include <linux/clk-provider.h>
35 #include <soc/sprd/hardware.h>
36 #include <linux/i2c.h>
37 #if (defined(CONFIG_INPUT_LIS3DH_I2C) || defined(CONFIG_INPUT_LIS3DH_I2C_MODULE))
38 #include <linux/i2c/lis3dh.h>
40 #if (defined(CONFIG_INPUT_LTR558_I2C) || defined(CONFIG_INPUT_LTR558_I2C_MODULE))
41 #include <linux/i2c/ltr_558als.h>
43 #if (defined(CONFIG_TOUCHSCREEN_MSG2138) || defined(CONFIG_TOUCHSCREEN_MSG2138_MODULE))
44 #include <linux/i2c/msg2138.h>
46 #include <linux/spi/spi.h>
47 #include <linux/gpio.h>
48 #include <soc/sprd/board.h>
49 #include <soc/sprd/serial_sprd.h>
50 #include <soc/sprd/adi.h>
51 #include <soc/sprd/adc.h>
52 #include <soc/sprd/pinmap.h>
53 #include <linux/irq.h>
54 #include <linux/input/matrix_keypad.h>
56 #include <soc/sprd/sci.h>
57 #include <soc/sprd/kpd.h>
58 #include <soc/sprd/sci_glb_regs.h>
60 #if (defined(CONFIG_INV_MPU_IIO) || defined(CONFIG_INV_MPU_IIO_MODULE))
61 #include <linux/mpu.h>
63 #if (defined(CONFIG_SENSORS_AK8975) || defined(CONFIG_SENSORS_AK8975_MODULE))
64 #include <linux/akm8975.h>
68 /* IRQ's for the multi sensor board */
69 #define MPUIRQ_GPIO 212
70 #include <linux/regulator/consumer.h>
71 #include <soc/sprd/regulator.h>
72 #if (defined(CONFIG_TOUCHSCREEN_FOCALTECH) || defined(CONFIG_TOUCHSCREEN_FOCALTECH_MODULE))
73 #include <linux/i2c/focaltech.h>
76 #if (defined(CONFIG_KEYBOARD_SC) || defined (CONFIG_KEYBOARD_SC_MODULE))
77 #include <linux/input/matrix_keypad.h>
78 #include <soc/sprd/kpd.h>
80 #if (defined(CONFIG_KEYBOARD_GPIO) || defined (CONFIG_KEYBOARD_GPIO_MODULE))
81 #include <linux/gpio_keys.h>
83 #if (defined(CONFIG_KEYBOARD_SPRD_EIC) || defined(CONFIG_KEYBOARD_SPRD_EIC_MODULE))
84 #include <linux/sprd_eic_keys.h>
86 #if (defined(CONFIG_BACKLIGHT_SPRD_PWM) || defined(CONFIG_BACKLIGHT_SPRD_PWM_MODULE))
87 #include <linux/sprd_pwm_bl.h>
89 #if (defined(CONFIG_INPUT_HEADSET_SPRD_SC2723) || defined(CONFIG_INPUT_HEADSET_SPRD_SC2723_MODULE))
90 #include <linux/headset_sprd_sc2723.h>
92 extern void bluesleep_setup_uart_port(struct platform_device *uart_dev);
93 extern void __init sci_reserve(void);
94 extern void __init sci_map_io(void);
95 extern void __init sci_init_irq(void);
96 extern void __init sci_timer_init(void);
97 extern int __init sci_clock_init(void);
98 extern int __init sci_regulator_init(void);
100 int __init __clock_init_early(void)
102 #if !defined(CONFIG_ARCH_SCX15)
103 pr_info("ahb ctl0 %08x, ctl2 %0x8 glb aon apb0 %08x aon apb1 %08x clk_en %08x\n",
104 sci_glb_raw_read(REG_AP_AHB_AHB_EB),
105 sci_glb_raw_read(REG_AP_AHB_AHB_RST),
106 sci_glb_raw_read(REG_AON_APB_APB_EB0),
107 sci_glb_raw_read(REG_AON_APB_APB_EB1),
108 sci_glb_raw_read(REG_AON_CLK_PUB_AHB_CFG));
111 sci_glb_clr(REG_AP_AHB_AHB_EB,
116 #if !defined(CONFIG_ARCH_SCX35L)
127 #if !defined(CONFIG_ARCH_SCX35L)
132 sci_glb_clr(REG_AP_APB_APB_EB,
146 sci_glb_clr(REG_AON_APB_APB_RTC_EB,
152 sci_glb_clr(REG_AON_APB_APB_EB0,
158 sci_glb_clr(REG_AON_APB_APB_EB1,
162 printk("sc clock module early init ok\n");
166 static inline int __sci_get_chip_id(void)
168 return __raw_readl(CHIP_ID_LOW_REG);
171 const struct of_device_id of_sprd_default_bus_match_table[] = {
172 { .compatible = "simple-bus", },
173 { .compatible = "sprd,adi-bus", },
177 static struct of_dev_auxdata of_sprd_default_bus_lookup[] = {
178 { .compatible = "sprd,sdhci-shark", .name = "sdio_sd", },
179 { .compatible = "sprd,sdhci-shark", .name = "sdio_wifi", },
180 { .compatible = "sprd,sdhci-shark", .name = "sprd-sdhci.2", },
181 { .compatible = "sprd,sdhci-shark", .name = "sdio_emmc", },
182 { .compatible = "sprd,sprd_backlight", .name = "sprd_backlight" },
183 #if (defined(CONFIG_BACKLIGHT_SPRD_PWM) || defined(CONFIG_BACKLIGHT_SPRD_PWM_MODULE))
184 { .compatible = "sprd,sprd_pwm_bl", .name = "sprd_pwm_bl" },
186 #if (defined(CONFIG_KEYBOARD_SC) || defined(CONFIG_KEYBOARD_SC_MODULE))
187 {.compatible = "sprd,sci-keypad", .name = "sci-keypad" },
189 #if (defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE))
190 {.compatible = "gpio-keys", .name = "gpio-keys" },
192 #if (defined(CONFIG_KEYBOARD_SPRD_EIC) || defined(CONFIG_KEYBOARD_SPRD_EIC_MODULE))
193 {.compatible = "sprd,sprd-eic-keys", .name = "sprd-eic-keys" },
195 #if (defined(CONFIG_INPUT_HEADSET_SPRD_SC2723) || defined(CONFIG_INPUT_HEADSET_SPRD_SC2723_MODULE))
196 { .compatible = "sprd,headset_sprd_sc2723", .name = "headset_sprd_sc2723" },
201 struct iotable_sprd io_addr_sprd;
202 EXPORT_SYMBOL(io_addr_sprd);
206 struct device_node *np;
209 #define ADD_SPRD_DEVICE(compat, id) \
211 np = of_find_compatible_node(NULL, NULL, compat);\
212 if (of_can_translate_address(np)) { \
213 of_address_to_resource(np, 0, &res); \
214 io_addr_sprd.id.paddr = res.start; \
215 io_addr_sprd.id.length = \
216 resource_size(&res); \
217 io_addr_sprd.id.vaddr = \
218 ioremap_nocache(res.start, io_addr_sprd.id.length);\
219 pr_debug("sprd io map: phys=%08x virt=%08x size=%08x\n", \
220 io_addr_sprd.id.paddr, io_addr_sprd.id.vaddr, io_addr_sprd.id.length);\
223 #define ADD_SPRD_DEVICE_BY_NAME(name, id) \
225 np = of_find_node_by_name(NULL, name); \
226 if (of_can_translate_address(np)) { \
227 of_address_to_resource(np, 0, &res); \
228 io_addr_sprd.id.paddr = res.start; \
229 io_addr_sprd.id.length = \
230 resource_size(&res); \
231 io_addr_sprd.id.vaddr = \
232 ioremap_nocache(res.start, io_addr_sprd.id.length);\
233 pr_debug("sprd io map: phys=%16lx virt=%16lx size=%16lx\n", \
234 io_addr_sprd.id.paddr, io_addr_sprd.id.vaddr, io_addr_sprd.id.length);\
237 ADD_SPRD_DEVICE("sprd,ahb", AHB);
238 ADD_SPRD_DEVICE("sprd,aonapb", AONAPB);
239 ADD_SPRD_DEVICE("sprd,aonckg", AONCKG);
240 ADD_SPRD_DEVICE("sprd,apbreg", APBREG);
241 ADD_SPRD_DEVICE("sprd,core", CORE);
242 ADD_SPRD_DEVICE("sprd,mmahb", MMAHB);
243 ADD_SPRD_DEVICE("sprd,pmu", PMU);
244 ADD_SPRD_DEVICE("sprd,mmckg", MMCKG);
245 ADD_SPRD_DEVICE("sprd,gpuapb", GPUAPB);
246 ADD_SPRD_DEVICE("sprd,apbckg", APBCKG);
247 ADD_SPRD_DEVICE("sprd,gpuckg", GPUCKG);
248 ADD_SPRD_DEVICE("sprd,int", INT);
249 ADD_SPRD_DEVICE("sprd,intc0", INTC0);
250 ADD_SPRD_DEVICE("sprd,intc1", INTC1);
251 ADD_SPRD_DEVICE("sprd,intc2", INTC2);
252 ADD_SPRD_DEVICE("sprd,intc3", INTC3);
253 ADD_SPRD_DEVICE("sprd,uidefuse", UIDEFUSE);
254 ADD_SPRD_DEVICE("sprd,isp", ISP);
255 ADD_SPRD_DEVICE("sprd,csi2", CSI2);
256 ADD_SPRD_DEVICE("sprd,d-eic-gpio", EIC);
257 ADD_SPRD_DEVICE("sprd,ipi", IPI);
258 ADD_SPRD_DEVICE("sprd,dcam", DCAM);
259 ADD_SPRD_DEVICE("sprd,syscnt", SYSCNT);
260 ADD_SPRD_DEVICE("sprd,dma0", DMA0);
261 ADD_SPRD_DEVICE("sprd,pub", PUB);
262 ADD_SPRD_DEVICE("sprd,pin", PIN);
263 ADD_SPRD_DEVICE("sprd,d-gpio-gpio", GPIO);
264 ADD_SPRD_DEVICE_BY_NAME("hwspinlock0", HWSPINLOCK0);
265 ADD_SPRD_DEVICE_BY_NAME("hwspinlock1", HWSPINLOCK1);
270 static void __init sc8830_init_machine(void)
272 printk("sci get chip id = 0x%x\n", __sci_get_chip_id());
275 #ifndef CONFIG_SC_FPGA
276 sci_regulator_init();
278 of_sprd_default_bus_lookup[0].phys_addr = 0x20300000;
279 of_sprd_default_bus_lookup[1].phys_addr = 0x20400000;
280 of_sprd_default_bus_lookup[2].phys_addr = 0x20500000;
281 of_sprd_default_bus_lookup[3].phys_addr = 0x20600000;
282 of_platform_populate(NULL, of_sprd_default_bus_match_table, of_sprd_default_bus_lookup, NULL);
286 const struct of_device_id of_sprd_late_bus_match_table[] = {
287 { .compatible = "sprd,sound", },
292 static void __init sc8830_init_late(void)
294 of_platform_populate(of_find_node_by_path("/sprd-audio-devices"),
295 of_sprd_late_bus_match_table, NULL, NULL);
299 extern void __init sci_enable_timer_early(void);
300 extern void __init sc_init_chip_id(void);
302 void __init sprd_init_before_irq(void)
306 /* earlier init request than irq and timer */
307 __clock_init_early();
308 /*ipi reg init for sipc*/
309 sci_glb_set(REG_AON_APB_APB_EB0, BIT_IPI_EB);
312 static void __init sc8830_pmu_init(void)
314 __raw_writel(__raw_readl(REG_PMU_APB_PD_MM_TOP_CFG)
315 & ~(BIT_PD_MM_TOP_FORCE_SHUTDOWN),
316 REG_PMU_APB_PD_MM_TOP_CFG);
317 #ifndef CONFIG_SC_FPGA
318 while (__raw_readl(REG_PMU_APB_PWR_STATUS0_DBG) & 0xf0000000) {};
320 __raw_writel(__raw_readl(REG_PMU_APB_PD_GPU_TOP_CFG)
321 & ~(BIT_PD_GPU_TOP_FORCE_SHUTDOWN),
322 REG_PMU_APB_PD_GPU_TOP_CFG);
323 #ifndef CONFIG_SC_FPGA
324 while (__raw_readl(REG_PMU_APB_PWR_STATUS0_DBG) & 0x0f000000) {};
326 __raw_writel(__raw_readl(REG_AON_APB_APB_EB0) | BIT_MM_EB |
327 BIT_GPU_EB, REG_AON_APB_APB_EB0);
328 #ifndef CONFIG_SC_FPGA
329 __raw_writel(__raw_readl(REG_MM_AHB_AHB_EB) | BIT_MM_CKG_EB,
331 __raw_writel(__raw_readl(REG_MM_AHB_GEN_CKG_CFG)
332 | BIT_MM_MTX_AXI_CKG_EN | BIT_MM_AXI_CKG_EN,
333 REG_MM_AHB_GEN_CKG_CFG);
334 __raw_writel(__raw_readl(REG_MM_CLK_MM_AHB_CFG) | 0x3,
335 REG_MM_CLK_MM_AHB_CFG);
339 static void sprd_init_time(void)
341 if (of_have_populated_dt()) {
343 #ifndef CONFIG_SC_FPGA
346 clocksource_of_init();
349 sci_enable_timer_early();
353 static const char *sprd_boards_compat[] __initdata = {
357 extern struct smp_operations sprd_smp_ops;
359 MACHINE_START(SCPHONE, "sc8830")
360 .smp = smp_ops(sprd_smp_ops),
361 .reserve = sci_reserve,
362 .map_io = sci_map_io,
363 .init_irq = sci_init_irq,
364 .init_time = sprd_init_time,
365 .init_machine = sc8830_init_machine,
366 .init_late = sc8830_init_late,
367 .dt_compat = sprd_boards_compat,