modify dm9000
[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 #include <linux/mmc/host.h>
25
26 #include <mach/hardware.h>
27 #include <asm/mach-types.h>
28 #include <asm/mach/arch.h>
29 #include <asm/mach/map.h>
30 #include <asm/mach/flash.h>
31
32 #include <mach/irqs.h>
33 #include <mach/board.h>
34 #include <mach/rk2818_iomap.h>
35 #include <mach/iomux.h>
36 #include <mach/gpio.h>
37
38 #include <linux/mtd/nand.h>
39 #include <linux/mtd/partitions.h>
40
41 #include "devices.h"
42
43
44 /* --------------------------------------------------------------------
45  *  ÉùÃ÷ÁËrk2818_gpioBankÊý×飬²¢¶¨ÒåÁËGPIO¼Ä´æÆ÷×éIDºÍ¼Ä´æÆ÷»ùµØÖ·¡£
46  * -------------------------------------------------------------------- */
47
48 static struct rk2818_gpio_bank rk2818_gpioBank[] = {
49                 {
50                 .id             = RK2818_ID_PIOA,
51                 .offset         = RK2818_GPIO0_BASE,
52                 .clock          = NULL,
53         }, 
54                 {
55                 .id             = RK2818_ID_PIOB,
56                 .offset         = RK2818_GPIO0_BASE,
57                 .clock          = NULL,
58         }, 
59                 {
60                 .id             = RK2818_ID_PIOC,
61                 .offset         = RK2818_GPIO0_BASE,
62                 .clock          = NULL,
63         }, 
64                 {
65                 .id             = RK2818_ID_PIOD,
66                 .offset         = RK2818_GPIO0_BASE,
67                 .clock          = NULL,
68         },
69                 {
70                 .id             = RK2818_ID_PIOE,
71                 .offset         = RK2818_GPIO1_BASE,
72                 .clock          = NULL,
73         },
74                 {
75                 .id             = RK2818_ID_PIOF,
76                 .offset         = RK2818_GPIO1_BASE,
77                 .clock          = NULL,
78         },
79                 {
80                 .id             = RK2818_ID_PIOG,
81                 .offset         = RK2818_GPIO1_BASE,
82                 .clock          = NULL,
83         },
84                 {
85                 .id             = RK2818_ID_PIOH,
86                 .offset         = RK2818_GPIO1_BASE,
87                 .clock          = NULL,
88         }
89 };
90
91 //IOÓ³É䷽ʽÃèÊö £¬Ã¿¸öΪһ¶ÎÏßÐÔÁ¬ÐøÓ³Éä
92 static struct map_desc rk2818_io_desc[] __initdata = {
93
94         {
95                 .virtual        = RK2818_MCDMA_BASE,                                    //ÐéÄâµØÖ·
96                 .pfn            = __phys_to_pfn(RK2818_MCDMA_PHYS),    //ÎïÀíµØÖ·£¬ÐëÓëÒ³±í¶ÔÆë
97                 .length         = RK2818_MCDMA_SIZE,                                                    //³¤¶È
98                 .type           = MT_DEVICE                                                     //Ó³É䷽ʽ
99         },
100         
101         {
102                 .virtual        = RK2818_DWDMA_BASE,                                    
103                 .pfn            = __phys_to_pfn(RK2818_DWDMA_PHYS),    
104                 .length         = RK2818_DWDMA_SIZE,                                            
105                 .type           = MT_DEVICE                                                     
106         },
107         
108         {
109                 .virtual        = RK2818_INTC_BASE,                                     
110                 .pfn            = __phys_to_pfn(RK2818_INTC_PHYS),   
111                 .length         = RK2818_INTC_SIZE,                                     
112                 .type           = MT_DEVICE                                             
113         },
114
115         {
116                 .virtual        = RK2818_NANDC_BASE,                            
117                 .pfn            = __phys_to_pfn(RK2818_NANDC_PHYS),      
118                 .length         = RK2818_NANDC_SIZE,                            
119                 .type           = MT_DEVICE                                     
120         },
121
122         {
123                 .virtual        = RK2818_SDRAMC_BASE,
124                 .pfn            = __phys_to_pfn(RK2818_SDRAMC_PHYS),
125                 .length         = RK2818_SDRAMC_SIZE,
126                 .type           = MT_DEVICE
127         },
128
129         {
130                 .virtual        = RK2818_ARMDARBITER_BASE,                                      
131                 .pfn            = __phys_to_pfn(RK2818_ARMDARBITER_PHYS),    
132                 .length         = RK2818_ARMDARBITER_SIZE,                                              
133                 .type           = MT_DEVICE                                                     
134         },
135         
136         {
137                 .virtual        = RK2818_APB_BASE,
138                 .pfn            = __phys_to_pfn(RK2818_APB_PHYS),
139                 .length         = 0xa0000,                     
140                 .type           = MT_DEVICE
141         },
142         
143         {
144                 .virtual        = RK2818_WDT_BASE,
145                 .pfn            = __phys_to_pfn(RK2818_WDT_PHYS),
146                 .length         = 0xa0000,                      ///apb bus i2s i2c spi no map in this
147                 .type           = MT_DEVICE
148         },
149 };
150 /*****************************************************************************************
151  * SDMMC devices
152  *author: kfx
153 *****************************************************************************************/
154  void rk2818_sdmmc0_cfg_gpio(struct platform_device *dev)
155 {
156         rk2818_mux_api_set(GPIOF3_APWM1_MMC0DETN_NAME, IOMUXA_SDMMC1_DETECT_N);
157         rk2818_mux_api_set(GPIOH_MMC0D_SEL_NAME, IOMUXA_SDMMC0_DATA123);
158         rk2818_mux_api_set(GPIOH_MMC0_SEL_NAME, IOMUXA_SDMMC0_CMD_DATA0_CLKOUT);
159 }
160
161 void rk2818_sdmmc1_cfg_gpio(struct platform_device *dev)
162 {
163         rk2818_mux_api_set(GPIOG_MMC1_SEL_NAME, IOMUXA_SDMMC1_CMD_DATA0_CLKOUT);
164         rk2818_mux_api_set(GPIOG_MMC1D_SEL_NAME, IOMUXA_SDMMC1_DATA123);
165 #if 1
166         /* wifi power up (gpio control) */
167         rk2818_mux_api_set(GPIOH7_HSADCCLK_SEL_NAME,IOMUXB_GPIO1_D7);
168         rk2818_mux_api_set(GPIOF5_APWM3_DPWM3_NAME,IOMUXB_GPIO1_B5);
169         gpio_request(RK2818_PIN_PH7, "sdio");
170         gpio_direction_output(RK2818_PIN_PH7,GPIO_HIGH);
171 #endif
172
173 }
174 #define CONFIG_SDMMC0_USE_DMA
175 #define CONFIG_SDMMC1_USE_DMA
176 struct rk2818_sdmmc_platform_data default_sdmmc0_data = {
177         .host_ocr_avail = (MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
178                                            MMC_VDD_30_31|MMC_VDD_31_32|MMC_VDD_32_33| 
179                                            MMC_VDD_33_34|MMC_VDD_34_35| MMC_VDD_35_36),
180         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
181         .cfg_gpio = rk2818_sdmmc0_cfg_gpio,
182         .no_detect = 0,
183         .dma_name = "sd_mmc",
184 #ifdef CONFIG_SDMMC0_USE_DMA
185         .use_dma  = 1,
186 #else
187         .use_dma = 0,
188 #endif
189 };
190 struct rk2818_sdmmc_platform_data default_sdmmc1_data = {
191         .host_ocr_avail = (MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|
192                                            MMC_VDD_29_30|MMC_VDD_30_31|MMC_VDD_31_32|
193                                            MMC_VDD_32_33|MMC_VDD_33_34),
194         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_SDIO_IRQ|
195                                    MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
196         .cfg_gpio = rk2818_sdmmc1_cfg_gpio,
197         .no_detect = 1,
198         .dma_name = "sdio",
199 #ifdef CONFIG_SDMMC1_USE_DMA
200         .use_dma  = 1,
201 #else
202         .use_dma = 0,
203 #endif
204 };
205
206 /*****************************************************************************************
207  * extern gpio devices
208  *author: xxx
209  *****************************************************************************************/
210 #if defined (CONFIG_GPIO_PCA9554)
211 struct rk2818_gpio_expander_info  extern_gpio_settinginfo[] = {
212         {
213                 .gpio_num               =RK2818_PIN_PI0,
214                 .pin_type           = GPIO_IN,
215                 //.pin_value                    =GPIO_HIGH,
216          },
217
218         {
219                 .gpio_num               =RK2818_PIN_PI4,// tp3
220                 .pin_type           = GPIO_IN,
221                 //.pin_value                    =GPIO_HIGH,
222          },
223          
224          {
225                 .gpio_num               =RK2818_PIN_PI5,//tp4
226                 .pin_type           = GPIO_IN,
227                 //.pin_value                    =GPIO_HIGH,
228          },
229          {
230                 .gpio_num               =RK2818_PIN_PI6,//tp2
231                 .pin_type           = GPIO_OUT,
232                 //.pin_value                    =GPIO_HIGH,
233          },
234          {
235                 .gpio_num               =RK2818_PIN_PI7,//tp1
236                 .pin_type           = GPIO_OUT,
237                 .pin_value                      =GPIO_HIGH,
238          },
239
240
241                 
242 };
243
244 struct pca9554_platform_data rk2818_pca9554_data={
245         .gpio_base=GPIOS_EXPANDER_BASE,
246         .gpio_pin_num=CONFIG_EXPANDED_GPIO_NUM,
247         .gpio_irq_start=NR_AIC_IRQS + 2*NUM_GROUP,
248         .irq_pin_num=CONFIG_EXPANDED_GPIO_IRQ_NUM,
249         .pca9954_irq_pin=RK2818_PIN_PE2,
250         .settinginfo=extern_gpio_settinginfo,
251         .settinginfolen=ARRAY_SIZE(extern_gpio_settinginfo),
252         .names="pca9554",
253 };
254 #endif
255
256 /*****************************************************************************************
257  * I2C devices
258  *author: kfx
259 *****************************************************************************************/
260  void rk2818_i2c0_cfg_gpio(struct platform_device *dev)
261 {
262         rk2818_mux_api_set(GPIOE_I2C0_SEL_NAME, IOMUXA_I2C0);
263 }
264
265 void rk2818_i2c1_cfg_gpio(struct platform_device *dev)
266 {
267         rk2818_mux_api_set(GPIOE_U1IR_I2C1_NAME, IOMUXA_I2C1);
268 }
269 struct rk2818_i2c_platform_data default_i2c0_data = { 
270         .bus_num    = 0,
271         .flags      = 0,
272         .slave_addr = 0xff,
273         .scl_rate  = 400*1000,
274         .cfg_gpio = rk2818_i2c0_cfg_gpio,
275 };
276 struct rk2818_i2c_platform_data default_i2c1_data = { 
277 #ifdef CONFIG_I2C0_RK2818
278         .bus_num    = 1,
279 #else
280         .bus_num        = 0,
281 #endif
282         .flags      = 0,
283         .slave_addr = 0xff,
284         .scl_rate  = 400*1000,
285         .cfg_gpio = rk2818_i2c1_cfg_gpio,
286 };
287
288 static struct i2c_board_info __initdata board_i2c0_devices[] = {
289 #if defined (CONFIG_RK1000_CONTROL)
290         {
291                 .type                   = "rk1000_control",
292                 .addr           = 0x40,
293                 .flags                  = 0,
294         },
295 #endif
296
297 #if defined (CONFIG_RK1000_TVOUT)
298         {
299                 .type                   = "rk1000_tvout",
300                 .addr           = 0x42,
301                 .flags                  = 0,
302         },
303 #endif
304 #if defined (CONFIG_SND_SOC_RK1000)
305         {
306                 .type                   = "rk1000_i2c_codec",
307                 .addr           = 0x60,
308                 .flags                  = 0,
309         },
310 #endif
311 #if defined (CONFIG_SND_SOC_WM8988)
312         {
313                 .type                   = "wm8988",
314                 .addr           = 0x1a,
315                 .flags                  = 0,
316         }
317 #endif  
318 };
319 static struct i2c_board_info __initdata board_i2c1_devices[] = {
320 #if defined (CONFIG_RTC_HYM8563)
321         {
322                 .type                   = "rtc_hym8563",
323                 .addr           = 0x51,
324                 .flags                  = 0,
325         },
326 #endif
327 #if defined (CONFIG_FM_QN8006)
328         {
329                 .type                   = "fm_qn8006",
330                 .addr           = 0x2b, 
331                 .flags                  = 0,
332         },
333 #endif
334 #if defined (CONFIG_GPIO_PCA9554)
335         {
336                 .type                   = "extend_gpio_pca9554",
337                 .addr           = 0x3c, 
338                 .flags                  = 0,
339                 .platform_data=&rk2818_pca9554_data.gpio_base,
340         },
341 #endif
342         {}
343 };
344
345
346 /*****************************************************************************************
347  * SPI devices
348  *author: lhh
349  *****************************************************************************************/
350 static struct spi_board_info board_spi_devices[] = {
351 #if defined(CONFIG_ENC28J60)    
352         {       /* net chip */
353                 .modalias       = "enc28j60",
354                 .chip_select    = 1,
355                 .max_speed_hz   = 12 * 1000 * 1000,
356                 .bus_num        = 0,
357                 .mode   = SPI_MODE_0,
358         },
359 #endif  
360 #if defined(CONFIG_TOUCHSCREEN_XPT2046_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
361         {
362                 .modalias       = "xpt2046_ts",
363                 .chip_select    = 0,
364                 .max_speed_hz   = 1000000,/* (max sample rate @ 3V) * (cmd + data + overhead) */
365                 .bus_num        = 0,
366                 .irq            = RK2818_PIN_PE3,
367         },
368 #endif
369 }; 
370
371 /*rk2818_fb gpio information*/
372 static struct rk2818_fb_gpio rk2818_fb_gpio_info = {
373     .lcd_cs     = 0,
374     .display_on = (GPIO_LOW<<16)|RK2818_PIN_PA2,
375     .lcd_standby = 0,
376     .mcu_fmk_pin = 0,
377 };
378
379 /*rk2818_fb iomux information*/
380 static struct rk2818_fb_iomux rk2818_fb_iomux_info = {
381     .data16     = GPIOC_LCDC16BIT_SEL_NAME,
382     .data18     = GPIOC_LCDC18BIT_SEL_NAME,
383     .data24     = GPIOC_LCDC24BIT_SEL_NAME,
384     .den        = CXGPIO_LCDDEN_SEL_NAME,
385     .vsync      = CXGPIO_LCDVSYNC_SEL_NAME,
386     .mcu_fmk    = 0,
387 };
388 /*rk2818_fb*/
389 struct rk2818_fb_mach_info rk2818_fb_mach_info = {
390     .gpio = &rk2818_fb_gpio_info,
391     .iomux = &rk2818_fb_iomux_info,
392 };
393
394 struct rk2818bl_info rk2818_bl_info = {
395         .pwm_id   = 0,
396         .pw_pin   = GPIO_HIGH | (RK2818_PIN_PA3<< 8) ,
397         .bl_ref   = 0,
398         .pw_iomux = GPIOA23_UART2_SEL_NAME,
399 };
400
401 static struct platform_device *devices[] __initdata = {
402         &rk2818_device_uart1,
403 #ifdef CONFIG_DM9000
404         &rk2818_device_dm9k,
405 #endif
406 #ifdef CONFIG_I2C0_RK2818
407         &rk2818_device_i2c0,
408 #endif
409 #ifdef CONFIG_I2C1_RK2818
410         &rk2818_device_i2c1,
411 #endif
412 #ifdef CONFIG_SDMMC0_RK2818     
413         &rk2818_device_sdmmc0,
414 #endif
415 #ifdef CONFIG_SDMMC1_RK2818
416         &rk2818_device_sdmmc1,
417 #endif
418         &rk2818_device_spim,
419         &rk2818_device_i2s,
420 #if defined(CONFIG_ANDROID_PMEM)
421         &rk2818_device_pmem,
422         &rk2818_device_pmem_dsp,
423 #endif
424         &rk2818_device_adc,
425         &rk2818_device_adckey,
426         &rk2818_device_battery,
427     &rk2818_device_fb,    
428     &rk2818_device_backlight,
429         &rk2818_device_dsp,
430 #ifdef CONFIG_MTD_NAND_RK2818
431         &rk2818_nand_device,
432 #endif
433 };
434
435 extern struct sys_timer rk2818_timer;
436 #define POWER_PIN       RK2818_PIN_PA3
437 static void rk2818_power_on(void)
438 {
439         int ret;
440         ret = gpio_request(POWER_PIN, NULL);
441         if (ret) {
442                 printk("failed to request power_off gpio\n");
443                 goto err_free_gpio;
444         }
445
446         gpio_pull_updown(POWER_PIN, GPIOPullUp);
447         ret = gpio_direction_output(POWER_PIN, GPIO_HIGH);
448         if (ret) {
449                 printk("failed to set power_off gpio output\n");
450                 goto err_free_gpio;
451         }
452
453         gpio_set_value(POWER_PIN, 1);/*power on*/
454         
455 err_free_gpio:
456         gpio_free(POWER_PIN);
457 }
458
459 static void rk2818_power_off(void)
460 {
461         printk("shut down system now ...\n");
462         gpio_set_value(POWER_PIN, 0);/*power down*/
463 }
464
465 static void __init machine_rk2818_init_irq(void)
466 {
467         rk2818_init_irq();
468         rk2818_gpio_init(rk2818_gpioBank, 8);
469         rk2818_gpio_irq_setup();
470 }
471
472 static void __init machine_rk2818_board_init(void)
473 {       
474         rk2818_power_on();
475         pm_power_off = rk2818_power_off;
476 #ifdef CONFIG_I2C0_RK2818
477         i2c_register_board_info(default_i2c0_data.bus_num, board_i2c0_devices,
478                         ARRAY_SIZE(board_i2c0_devices));
479 #endif
480 #ifdef CONFIG_I2C1_RK2818
481         i2c_register_board_info(default_i2c1_data.bus_num, board_i2c1_devices,
482                         ARRAY_SIZE(board_i2c1_devices));
483 #endif
484         platform_add_devices(devices, ARRAY_SIZE(devices));     
485         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
486         rk2818_mux_api_set(GPIOB4_SPI0CS0_MMC0D4_NAME,IOMUXA_GPIO0_B4); //IOMUXA_SPI0_CSN0);//use for gpio SPI CS0
487         rk2818_mux_api_set(GPIOB0_SPI0CSN1_MMC1PCA_NAME,IOMUXA_GPIO0_B0); //IOMUXA_SPI0_CSN1);//use for gpio SPI CS1
488         rk2818_mux_api_set(GPIOB_SPI0_MMC0_NAME,IOMUXA_SPI0);//use for SPI CLK SDI SDO
489 }
490
491 static void __init machine_rk2818_mapio(void)
492 {
493         iotable_init(rk2818_io_desc, ARRAY_SIZE(rk2818_io_desc));
494         rk2818_clock_init();
495         rk2818_iomux_init();    
496 }
497
498 MACHINE_START(RK2818, "RK28board")
499
500 /* UART for LL DEBUG */
501         .phys_io        = 0x18002000,
502         .io_pg_offst    = ((0xFF100000) >> 18) & 0xfffc,
503         .boot_params    = RK2818_SDRAM_PHYS + 0xf8000,
504         .map_io         = machine_rk2818_mapio,
505         .init_irq       = machine_rk2818_init_irq,
506         .init_machine   = machine_rk2818_board_init,
507         .timer          = &rk2818_timer,
508 MACHINE_END