2a92d488be74fd3e6a119717ee3db289c73784f0
[profile/mobile/platform/kernel/u-boot-tm1.git] / board / spreadtrum / tizen_tm1 / openphone.c
1 #include <common.h>
2 #include <asm/io.h>
3 #include <asm/arch/ldo.h>
4 #include <asm/arch/sprd_reg_ahb.h>
5 #include <asm/arch/regs_ahb.h>
6 #include <asm/arch/common.h>
7 #include <asm/arch/adi_hal_internal.h>
8 #include <asm/u-boot.h>
9 #include <part.h>
10 #include <sdhci.h>
11 #include <asm/arch/mfp.h>
12 #include <linux/gpio.h>
13 #include <asm/arch/gpio.h>
14 #include <asm/arch/pinmap.h>
15 DECLARE_GLOBAL_DATA_PTR;
16
17 extern void sprd_gpio_init(void);
18 extern void ADI_init (void);
19 extern int LDO_Init(void);
20 extern void ADC_Init(void);
21 extern int sound_init(void);
22 extern void misc_init(void);
23 extern int pin_init(void);
24 extern void sprd_eic_init(void);
25 extern void init_ldo_sleep_gr(void);
26 extern int sprd_gpio_request(struct gpio_chip *chip, unsigned offset);
27 extern int sprd_gpio_direction_input(struct gpio_chip *chip, unsigned offset);
28 extern int sprd_gpio_get(struct gpio_chip *chip, unsigned offset);
29 extern void sprd_gpio_free(struct gpio_chip *chip, unsigned offset);
30
31 #ifdef CONFIG_GENERIC_MMC
32 int mv_sdh_init(u32 regbase, u32 max_clk, u32 min_clk, u32 quirks);
33 int mmc_sdcard_init(void);
34
35 int board_mmc_init(bd_t *bd)
36 {
37 #if 0
38         mmc_sdcard_init();
39
40         mv_sdh_init(CONFIG_SYS_SD_BASE, SDIO_BASE_CLK_192M,
41                         SDIO_CLK_250K, 0);
42 #endif
43         return 0;
44 }
45 #endif
46
47 extern struct eic_gpio_resource sprd_gpio_resource[];
48
49 /*enable aon timer2 for udelay functions*/
50 void aon_26M_timer2_enable(void)
51 {
52         REG32(REG_AON_APB_APB_EB0) |= BIT_AON_TMR_EB;
53 }
54
55 unsigned int hw_revision = 0;
56 #define GPIO_HW_REV_COUNT 3
57 unsigned hw_rev_gpio[GPIO_HW_REV_COUNT] = {166, 169, 170};
58
59 int get_hw_rev(void)
60 {
61         int i;
62
63         hw_revision = 0;
64
65         for (i = 0 ; i < GPIO_HW_REV_COUNT ; i++) {
66                 sprd_gpio_request(NULL, hw_rev_gpio[i]);
67                 sprd_gpio_direction_input(NULL, hw_rev_gpio[i]);
68                 hw_revision = (hw_revision << 1) | sprd_gpio_get(NULL, hw_rev_gpio[i]);
69                 sprd_gpio_free(NULL, hw_rev_gpio[i]);
70         }
71
72         return hw_revision;
73 }
74
75 void check_smpl(void)
76 {
77 #ifdef CONFIG_SMPL_MODE
78         if(is_real_battery() == 0){
79                 sci_adi_write_fast(ANA_REG_GLB_SMPL_CTRL0,0x0,1);
80         }
81 #endif
82 }
83
84 int board_init(void)
85 {
86         gd->bd->bi_arch_number = 0x7df;
87         gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x02000100;
88         ADI_init();
89         sprd_gpio_init();
90         misc_init();
91
92         pin_init();
93         sprd_eic_init();
94
95         init_ldo_sleep_gr();
96
97         LDO_Init();
98         ADC_Init();
99 //      sound_init();
100         //TDPllRefConfig(1);
101 //      aon_26M_timer2_enable();
102         check_smpl();
103         get_hw_rev();
104
105         return 0;
106 }
107
108 int dram_init(void)
109 {
110         gd->ram_size = get_ram_size((volatile void *)PHYS_SDRAM_1,
111                         PHYS_SDRAM_1_SIZE);
112         return 0;
113 }
114
115 void fdt_fixup_chosen_bootargs_board(char *buf, const char *boot_mode, int calibration_mode)
116 {
117         char *p = buf;
118         /**
119          * Because of in u-boot, we can't find FDT chosen remove function
120          * and samsung only uses uart to do calibration,
121          * so in samsung board .dts, we remove the "console=ttyS1,115200n8" in chosen node by default.
122          * so in normal mode, we need to append console
123          */
124         if (!calibration_mode) {
125                 p += sprintf(p, "console=ttyS1,115200n8 no_console_suspend");
126         } else {
127                 p += sprintf(p, "console=null");
128         }
129 }