b83ae59c014fa4f5b92013f444c2dee38d04a1b9
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk2818 / board-midsdk.c
1 /* linux/arch/arm/mach-rk2818/board-midsdk.c
2  *
3  * Copyright (C) 2010 ROCKCHIP, Inc.
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  */
15
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/input.h>
20 #include <linux/io.h>
21 #include <linux/delay.h>
22 #include <linux/i2c.h>
23 #include <linux/spi/spi.h>
24
25 #include <mach/hardware.h>
26 #include <asm/mach-types.h>
27 #include <asm/mach/arch.h>
28 #include <asm/mach/map.h>
29 #include <asm/mach/flash.h>
30
31 #include <mach/irqs.h>
32 #include <mach/board.h>
33 #include <mach/rk2818_iomap.h>
34 #include <mach/iomux.h>
35 #include <mach/gpio.h>
36
37 #include <linux/mtd/nand.h>
38 #include <linux/mtd/partitions.h>
39
40 #include "devices.h"
41
42
43 /* --------------------------------------------------------------------
44  *  ÉùÃ÷ÁËrk2818_gpioBankÊý×飬²¢¶¨ÒåÁËGPIO¼Ä´æÆ÷×éIDºÍ¼Ä´æÆ÷»ùµØÖ·¡£
45  * -------------------------------------------------------------------- */
46
47 static struct rk2818_gpio_bank rk2818_gpioBank[] = {
48                 {
49                 .id             = RK2818_ID_PIOA,
50                 .offset         = RK2818_GPIO0_BASE,
51                 .clock          = NULL,
52         }, 
53                 {
54                 .id             = RK2818_ID_PIOB,
55                 .offset         = RK2818_GPIO0_BASE,
56                 .clock          = NULL,
57         }, 
58                 {
59                 .id             = RK2818_ID_PIOC,
60                 .offset         = RK2818_GPIO0_BASE,
61                 .clock          = NULL,
62         }, 
63                 {
64                 .id             = RK2818_ID_PIOD,
65                 .offset         = RK2818_GPIO0_BASE,
66                 .clock          = NULL,
67         },
68                 {
69                 .id             = RK2818_ID_PIOE,
70                 .offset         = RK2818_GPIO1_BASE,
71                 .clock          = NULL,
72         },
73                 {
74                 .id             = RK2818_ID_PIOF,
75                 .offset         = RK2818_GPIO1_BASE,
76                 .clock          = NULL,
77         },
78                 {
79                 .id             = RK2818_ID_PIOG,
80                 .offset         = RK2818_GPIO1_BASE,
81                 .clock          = NULL,
82         },
83                 {
84                 .id             = RK2818_ID_PIOH,
85                 .offset         = RK2818_GPIO1_BASE,
86                 .clock          = NULL,
87         }
88 };
89
90 //IOÓ³É䷽ʽÃèÊö £¬Ã¿¸öΪһ¶ÎÏßÐÔÁ¬ÐøÓ³Éä
91 static struct map_desc rk2818_io_desc[] __initdata = {
92
93         {
94                 .virtual        = RK2818_MCDMA_BASE,                                    //ÐéÄâµØÖ·
95                 .pfn            = __phys_to_pfn(RK2818_MCDMA_PHYS),    //ÎïÀíµØÖ·£¬ÐëÓëÒ³±í¶ÔÆë
96                 .length         = RK2818_MCDMA_SIZE,                                                    //³¤¶È
97                 .type           = MT_DEVICE                                                     //Ó³É䷽ʽ
98         },
99         
100         {
101                 .virtual        = RK2818_DWDMA_BASE,                                    
102                 .pfn            = __phys_to_pfn(RK2818_DWDMA_PHYS),    
103                 .length         = RK2818_DWDMA_SIZE,                                            
104                 .type           = MT_DEVICE                                                     
105         },
106         
107         {
108                 .virtual        = RK2818_INTC_BASE,                                     
109                 .pfn            = __phys_to_pfn(RK2818_INTC_PHYS),   
110                 .length         = RK2818_INTC_SIZE,                                     
111                 .type           = MT_DEVICE                                             
112         },
113
114         {
115                 .virtual        = RK2818_NANDC_BASE,                            
116                 .pfn            = __phys_to_pfn(RK2818_NANDC_PHYS),      
117                 .length         = RK2818_NANDC_SIZE,                            
118                 .type           = MT_DEVICE                                     
119         },
120
121         {
122                 .virtual        = RK2818_SDRAMC_BASE,
123                 .pfn            = __phys_to_pfn(RK2818_SDRAMC_PHYS),
124                 .length         = RK2818_SDRAMC_SIZE,
125                 .type           = MT_DEVICE
126         },
127
128         {
129                 .virtual        = RK2818_ARMDARBITER_BASE,                                      
130                 .pfn            = __phys_to_pfn(RK2818_ARMDARBITER_PHYS),    
131                 .length         = RK2818_ARMDARBITER_SIZE,                                              
132                 .type           = MT_DEVICE                                                     
133         },
134         
135         {
136                 .virtual        = RK2818_APB_BASE,
137                 .pfn            = __phys_to_pfn(RK2818_APB_PHYS),
138                 .length         = 0xa0000,                     
139                 .type           = MT_DEVICE
140         },
141         
142         {
143                 .virtual        = RK2818_WDT_BASE,
144                 .pfn            = __phys_to_pfn(RK2818_WDT_PHYS),
145                 .length         = 0xa0000,                      ///apb bus i2s i2c spi no map in this
146                 .type           = MT_DEVICE
147         },
148 };
149
150 /*****************************************************************************************
151  * I2C devices
152  *author: kfx
153  *****************************************************************************************/
154 static struct rk2818_i2c_platform_data default_i2c0_data __initdata = { 
155         .bus_num    = 0,
156         .flags      = 0,
157         .slave_addr = 0xff,
158         .scl_rate  = 400*1000,
159         .clk_id  = "i2c0",
160 };
161 static struct rk2818_i2c_platform_data default_i2c1_data __initdata = { 
162         .bus_num    = 1,
163         .flags      = 0,
164         .slave_addr = 0xff,
165         .scl_rate  = 400*1000,
166         .clk_id  = "i2c1",
167 };
168
169 static struct i2c_board_info __initdata board_i2c0_devices[] = {
170 #if defined (CONFIG_RK1000_CONTROL)
171         {
172                 .type                   = "rk1000_control",
173                 .addr           = 0x40,
174                 .flags                  = 0,
175         },
176 #endif
177
178 #if defined (CONFIG_RK1000_TVOUT)
179         {
180                 .type                   = "rk1000_tvout",
181                 .addr           = 0x42,
182                 .flags                  = 0,
183         },
184 #endif
185 #if defined (CONFIG_SND_SOC_RK1000)
186         {
187                 .type                   = "rk1000_i2c_codec",
188                 .addr           = 0x60,
189                 .flags                  = 0,
190         },
191 #endif
192         {}
193 };
194 static struct i2c_board_info __initdata board_i2c1_devices[] = {
195 #if defined (CONFIG_RTC_HYM8563)
196         {
197                 .type                   = "rtc_hym8563",
198                 .addr           = 0x51,
199                 .flags                  = 0,
200         },
201 #endif
202 #if defined (CONFIG_FM_QN8006)
203         {
204                 .type                   = "fm_qn8006",
205                 .addr           = 0x2b, 
206                 .flags                  = 0,
207         },
208 #endif
209         {}
210 };
211
212 static void rk2818_i2c0_cfg_gpio(struct platform_device *dev)
213 {
214         rk2818_mux_api_set(GPIOE_I2C0_SEL_NAME, IOMUXA_I2C0);
215 }
216
217 static void rk2818_i2c1_cfg_gpio(struct platform_device *dev)
218 {
219         rk2818_mux_api_set(GPIOE_U1IR_I2C1_NAME, IOMUXA_I2C1);
220 }
221
222
223 static void __init rk2818_i2c0_set_platdata(struct rk2818_i2c_platform_data *pd)
224 {
225         struct rk2818_i2c_platform_data *npd;
226
227         if (!pd)
228                 pd = &default_i2c0_data;
229
230         npd = kmemdup(pd, sizeof(struct rk2818_i2c_platform_data), GFP_KERNEL);
231         if (!npd)
232                 printk(KERN_ERR "%s: no memory for platform data\n", __func__);
233         else if (!npd->cfg_gpio)
234                 npd->cfg_gpio = rk2818_i2c0_cfg_gpio;
235
236         rk2818_device_i2c0.dev.platform_data = npd;
237 }
238 static void __init rk2818_i2c1_set_platdata(struct rk2818_i2c_platform_data *pd)
239 {
240         struct rk2818_i2c_platform_data *npd;
241
242         if (!pd)
243                 pd = &default_i2c1_data;
244
245         npd = kmemdup(pd, sizeof(struct rk2818_i2c_platform_data), GFP_KERNEL);
246         if (!npd)
247                 printk(KERN_ERR "%s: no memory for platform data\n", __func__);
248         else if (!npd->cfg_gpio)
249                 npd->cfg_gpio = rk2818_i2c1_cfg_gpio;
250
251         rk2818_device_i2c1.dev.platform_data = npd;
252 }
253
254 static void __init rk2818_i2c_board_init(void)
255 {
256         rk2818_i2c0_set_platdata(NULL);
257         rk2818_i2c1_set_platdata(NULL);
258         i2c_register_board_info(0, board_i2c0_devices,
259                         ARRAY_SIZE(board_i2c0_devices));
260         i2c_register_board_info(1, board_i2c1_devices,
261                         ARRAY_SIZE(board_i2c1_devices));
262 }
263 /*****************************************************************************************
264  * SPI devices
265  *author: lhh
266  *****************************************************************************************/
267 static struct spi_board_info board_spi_devices[] = {
268         {       /* net chip */
269                 .modalias       = "enc28j60",
270                 .chip_select    = 1,
271                 .max_speed_hz   = 12 * 1000 * 1000,
272                 .bus_num        = 0,
273                 .mode   = SPI_MODE_0,
274         },
275
276         {       
277                 .modalias       = "xpt2046_ts",
278                 .chip_select    = 0,
279                 .max_speed_hz   = 1000000,
280                 .bus_num        = 0,
281                 .mode   = SPI_MODE_0,
282         },
283
284 };
285
286 static struct platform_device *devices[] __initdata = {
287         &rk2818_device_uart1,
288         &rk2818_device_dm9k,
289         &rk2818_device_spim,
290 };
291
292 extern struct sys_timer rk2818_timer;
293
294 static void __init machine_rk2818_init_irq(void)
295 {
296         rk2818_init_irq();
297         rk2818_gpio_init(rk2818_gpioBank, 8);
298         rk2818_gpio_irq_setup();
299 }
300
301 static void __init machine_rk2818_board_init(void)
302 {
303         rk2818_i2c_board_init();
304         platform_add_devices(devices, ARRAY_SIZE(devices));
305         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
306         rk2818_mux_api_set(GPIOB4_SPI0CS0_MMC0D4_NAME,IOMUXA_GPIO0_B4); //IOMUXA_SPI0_CSN0);//use for gpio SPI CS0
307         rk2818_mux_api_set(GPIOB0_SPI0CSN1_MMC1PCA_NAME,IOMUXA_GPIO0_B0); //IOMUXA_SPI0_CSN1);//use for gpio SPI CS1
308         rk2818_mux_api_set(GPIOB_SPI0_MMC0_NAME,IOMUXA_SPI0);//use for SPI CLK SDI SDO
309 }
310
311 static void __init machine_rk2818_mapio(void)
312 {
313         iotable_init(rk2818_io_desc, ARRAY_SIZE(rk2818_io_desc));
314         rk2818_clock_init();
315         rk2818_iomux_init();    
316 }
317
318 MACHINE_START(RK2818, "rk2818midsdk")
319
320 /* UART for LL DEBUG */
321         .phys_io        = 0x18002000,
322         .io_pg_offst    = ((0xFF100000) >> 18) & 0xfffc,
323         .boot_params    = RK2818_SDRAM_PHYS + 0x100,
324         .map_io         = machine_rk2818_mapio,
325         .init_irq       = machine_rk2818_init_irq,
326         .init_machine   = machine_rk2818_board_init,
327         .timer          = &rk2818_timer,
328 MACHINE_END