1 /* arch/arm/mach-rk30/board-rk30-sdk-sdmmc.c
3 * Copyright (C) 2012 ROCKCHIP, Inc.
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.
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.
16 #ifdef CONFIG_SDMMC_RK29
18 #if !defined(CONFIG_SDMMC_RK29_OLD)
19 static void rk29_sdmmc_gpio_open(int device_id, int on)
25 #ifdef CONFIG_SDMMC0_RK29
28 gpio_direction_output(RK2928_PIN1_PC0,GPIO_HIGH);//set mmc0-clk to high
29 gpio_direction_output(RK2928_PIN1_PB7,GPIO_HIGH);// set mmc0-cmd to high.
30 gpio_direction_output(RK2928_PIN1_PC2,GPIO_HIGH);//set mmc0-data0 to high.
31 gpio_direction_output(RK2928_PIN1_PC3,GPIO_HIGH);//set mmc0-data1 to high.
32 gpio_direction_output(RK2928_PIN1_PC4,GPIO_HIGH);//set mmc0-data2 to high.
33 gpio_direction_output(RK2928_PIN1_PC5,GPIO_HIGH);//set mmc0-data3 to high.
39 rk30_mux_api_set(GPIO1C0_MMC0_CLKOUT_NAME, GPIO1C_GPIO1C0);
40 gpio_request(RK2928_PIN1_PC0, "mmc0-clk");
41 gpio_direction_output(RK2928_PIN1_PC0,GPIO_LOW);//set mmc0-clk to low.
43 rk30_mux_api_set(GPIO1B7_MMC0_CMD_NAME, GPIO1B_GPIO1B7);
44 gpio_request(RK2928_PIN1_PB7, "mmc0-cmd");
45 gpio_direction_output(RK2928_PIN1_PB7,GPIO_LOW);//set mmc0-cmd to low.
47 rk30_mux_api_set(GPIO1C2_MMC0_D0_NAME, GPIO1C_GPIO1C2);
48 gpio_request(RK2928_PIN1_PC2, "mmc0-data0");
49 gpio_direction_output(RK2928_PIN1_PC2,GPIO_LOW);//set mmc0-data0 to low.
51 rk30_mux_api_set(GPIO1C3_MMC0_D1_NAME, GPIO1C_GPIO1C3);
52 gpio_request(RK2928_PIN1_PC3, "mmc0-data1");
53 gpio_direction_output(RK2928_PIN1_PC3,GPIO_LOW);//set mmc0-data1 to low.
55 rk30_mux_api_set(GPIO1C4_MMC0_D2_NAME, GPIO1C_GPIO1C4);
56 gpio_request(RK2928_PIN1_PC4, "mmc0-data2");
57 gpio_direction_output(RK2928_PIN1_PC4,GPIO_LOW);//set mmc0-data2 to low.
59 rk30_mux_api_set(GPIO1C5_MMC0_D3_NAME, GPIO1C_GPIO1C5);
60 gpio_request(RK2928_PIN1_PC5, "mmc0-data3");
61 gpio_direction_output(RK2928_PIN1_PC5,GPIO_LOW);//set mmc0-data3 to low.
71 #ifdef CONFIG_SDMMC1_RK29
74 gpio_request(RK2928_PIN0_PB1, "mmc1-clk");
75 gpio_direction_output(RK2928_PIN0_PB1,GPIO_HIGH);//set mmc1-clk to high
77 gpio_request(RK2928_PIN0_PB0, "mmc1-cmd");
78 gpio_direction_output(RK2928_PIN0_PB0,GPIO_HIGH);//set mmc1-cmd to high.
80 gpio_request(RK2928_PIN0_PB3, "mmc1-data0");
81 gpio_direction_output(RK2928_PIN0_PB3,GPIO_HIGH);//set mmc1-data0 to high.
83 gpio_request(RK2928_PIN0_PB4, "mmc1-data1");
84 gpio_direction_output(RK2928_PIN0_PB4,GPIO_HIGH);//set mmc1-data1 to high.
86 gpio_request(RK2928_PIN0_PB5, "mmc1-data2");
87 gpio_direction_output(RK2928_PIN0_PB5,GPIO_HIGH);//set mmc1-data2 to high.
89 gpio_request(RK2928_PIN0_PB6, "mmc1-data3");
90 gpio_direction_output(RK2928_PIN0_PB6,GPIO_HIGH);//set mmc1-data3 to high.
95 rk30_mux_api_set(GPIO0B1_MMC1_CLKOUT_NAME, GPIO0B_GPIO0B1);
96 gpio_request(RK2928_PIN0_PB1, "mmc1-clk");
97 gpio_direction_output(RK2928_PIN0_PB1,GPIO_LOW);//set mmc1-clk to low.
99 rk30_mux_api_set(GPIO0B0_MMC1_CMD_NAME, GPIO0B_GPIO0B0);
100 gpio_request(RK2928_PIN0_PB0, "mmc1-cmd");
101 gpio_direction_output(RK2928_PIN0_PB0,GPIO_LOW);//set mmc1-cmd to low.
103 rk30_mux_api_set(GPIO0B3_MMC1_D0_NAME, GPIO0B_GPIO0B3);
104 gpio_request(RK2928_PIN0_PB3, "mmc1-data0");
105 gpio_direction_output(RK2928_PIN0_PB3,GPIO_LOW);//set mmc1-data0 to low.
107 #if defined(CONFIG_SDMMC1_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
108 rk29_mux_api_set(GPIO0B4_MMC1_D1_NAME, GPIO0B_GPIO0B4);
109 gpio_request(RK2928_PIN0_PB4, "mmc1-data1");
110 gpio_direction_output(RK2928_PIN0_PB4,GPIO_LOW);//set mmc1-data1 to low.
112 rk29_mux_api_set(GPIO0B5_MMC1_D2_NAME, GPIO0B_GPIO0B5);
113 gpio_request(RK2928_PIN0_PB5, "mmc1-data2");
114 gpio_direction_output(RK2928_PIN0_PB5,GPIO_LOW);//set mmc1-data2 to low.
116 rk29_mux_api_set(GPIO0B6_MMC1_D3_NAME, GPIO0B_GPIO0B6);
117 gpio_request(RK2928_PIN0_PB6, "mmc1-data3");
118 gpio_direction_output(RK2928_PIN0_PB6,GPIO_LOW);//set mmc1-data3 to low.
120 //rk29_sdmmc_gpio_open(1, 0); //added by xbw at 2011-10-13
137 static void rk29_sdmmc_set_iomux_mmc0(unsigned int bus_width)
142 case 1://SDMMC_CTYPE_4BIT:
144 rk30_mux_api_set(GPIO1C3_MMC0_D1_NAME, GPIO1C_MMC0_D1);
145 rk30_mux_api_set(GPIO1C4_MMC0_D2_NAME, GPIO1C_MMC0_D2);
146 rk30_mux_api_set(GPIO1C5_MMC0_D3_NAME, GPIO1C_MMC0_D3);
150 case 0x10000://SDMMC_CTYPE_8BIT:
152 case 0xFFFF: //gpio_reset
154 rk30_mux_api_set(GPIO1B6_MMC0_PWREN_NAME, GPIO1B_GPIO1B6);
155 gpio_request(RK2928_PIN1_PB6,"sdmmc-power");
156 gpio_direction_output(RK2928_PIN1_PB6,GPIO_HIGH); //power-off
158 rk29_sdmmc_gpio_open(0, 0);
160 gpio_direction_output(RK2928_PIN1_PB6,GPIO_LOW); //power-on
162 rk29_sdmmc_gpio_open(0, 1);
166 default: //case 0://SDMMC_CTYPE_1BIT:
168 rk30_mux_api_set(GPIO1B7_MMC0_CMD_NAME, GPIO1B_MMC0_CMD);
169 rk30_mux_api_set(GPIO1C0_MMC0_CLKOUT_NAME, GPIO1C_MMC0_CLKOUT);
170 rk30_mux_api_set(GPIO1C2_MMC0_D0_NAME, GPIO1C_MMC0_D0);
172 rk30_mux_api_set(GPIO1C3_MMC0_D1_NAME, GPIO1C_GPIO1C3);
173 gpio_request(RK2928_PIN1_PC3, "mmc0-data1");
174 gpio_direction_output(RK2928_PIN1_PC3,GPIO_HIGH);//set mmc0-data1 to high.
176 rk30_mux_api_set(GPIO1C4_MMC0_D2_NAME, GPIO1C_GPIO1C4);
177 gpio_request(RK2928_PIN1_PC4, "mmc0-data2");
178 gpio_direction_output(RK2928_PIN1_PC4,GPIO_HIGH);//set mmc0-data2 to high.
180 rk30_mux_api_set(GPIO1C5_MMC0_D3_NAME, GPIO1C_GPIO1C5);
181 gpio_request(RK2928_PIN1_PC5, "mmc0-data3");
182 gpio_direction_output(RK2928_PIN1_PC5,GPIO_HIGH);//set mmc0-data3 to high.
188 static void rk29_sdmmc_set_iomux_mmc1(unsigned int bus_width)
190 rk30_mux_api_set(GPIO0B0_MMC1_CMD_NAME, GPIO0B_MMC1_CMD);
191 rk30_mux_api_set(GPIO0B1_MMC1_CLKOUT_NAME, GPIO0B_MMC1_CLKOUT);
192 rk30_mux_api_set(GPIO0B3_MMC1_D0_NAME, GPIO0B_MMC1_D0);
193 rk30_mux_api_set(GPIO0B4_MMC1_D1_NAME, GPIO0B_MMC1_D1);
194 rk30_mux_api_set(GPIO0B5_MMC1_D2_NAME, GPIO0B_MMC1_D2);
195 rk30_mux_api_set(GPIO0B6_MMC1_D3_NAME, GPIO0B_MMC1_D3);
198 static void rk29_sdmmc_set_iomux_mmc2(unsigned int bus_width)
203 static void rk29_sdmmc_set_iomux(int device_id, unsigned int bus_width)
208 #ifdef CONFIG_SDMMC0_RK29
209 rk29_sdmmc_set_iomux_mmc0(bus_width);
213 #ifdef CONFIG_SDMMC1_RK29
214 rk29_sdmmc_set_iomux_mmc1(bus_width);
218 rk29_sdmmc_set_iomux_mmc2(bus_width);
229 #ifdef CONFIG_WIFI_CONTROL_FUNC
232 // Define wifi module's power and reset gpio, and gpio sensitive level
235 #if defined(CONFIG_RK903) || defined(CONFIG_RK901)
236 #define RK30SDK_WIFI_GPIO_POWER_N RK2928_PIN0_PD6
237 #define RK30SDK_WIFI_GPIO_POWER_ENABLE_VALUE GPIO_HIGH
238 #define RK30SDK_WIFI_GPIO_RESET_N RK2928_PIN3_PC2
239 #define RK30SDK_WIFI_GPIO_RESET_ENABLE_VALUE GPIO_HIGH
242 #if defined(CONFIG_RTL8192CU) || defined(CONFIG_RTL8188EU)
243 #define RK30SDK_WIFI_GPIO_POWER_N RK2928_PIN0_PD6
244 #define RK30SDK_WIFI_GPIO_POWER_ENABLE_VALUE GPIO_LOW
247 #if defined(CONFIG_BCM4329) || defined(CONFIG_BCM4319)
248 #define RK30SDK_WIFI_GPIO_POWER_N RK2928_PIN0_PD6
249 #define RK30SDK_WIFI_GPIO_POWER_ENABLE_VALUE GPIO_HIGH
250 #define RK30SDK_WIFI_GPIO_RESET_N RK2928_PIN3_PC2
251 #define RK30SDK_WIFI_GPIO_RESET_ENABLE_VALUE GPIO_HIGH
253 #if defined(CONFIG_RDA5990)
254 #define RK30SDK_WIFI_GPIO_POWER_N RK2928_PIN0_PD6
255 #define RK30SDK_WIFI_GPIO_POWER_ENABLE_VALUE GPIO_HIGH
256 #define RK30SDK_WIFI_GPIO_RESET_N RK2928_PIN3_PC2
257 #define RK30SDK_WIFI_GPIO_RESET_ENABLE_VALUE GPIO_HIGH
260 #define PREALLOC_WLAN_SEC_NUM 4
261 #define PREALLOC_WLAN_BUF_NUM 160
262 #define PREALLOC_WLAN_SECTION_HEADER 24
264 #define WLAN_SECTION_SIZE_0 (PREALLOC_WLAN_BUF_NUM * 128)
265 #define WLAN_SECTION_SIZE_1 (PREALLOC_WLAN_BUF_NUM * 128)
266 #define WLAN_SECTION_SIZE_2 (PREALLOC_WLAN_BUF_NUM * 512)
267 #define WLAN_SECTION_SIZE_3 (PREALLOC_WLAN_BUF_NUM * 1024)
269 #define WLAN_SKB_BUF_NUM 16
271 static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM];
273 struct wifi_mem_prealloc {
278 static struct wifi_mem_prealloc wifi_mem_array[PREALLOC_WLAN_SEC_NUM] = {
279 {NULL, (WLAN_SECTION_SIZE_0 + PREALLOC_WLAN_SECTION_HEADER)},
280 {NULL, (WLAN_SECTION_SIZE_1 + PREALLOC_WLAN_SECTION_HEADER)},
281 {NULL, (WLAN_SECTION_SIZE_2 + PREALLOC_WLAN_SECTION_HEADER)},
282 {NULL, (WLAN_SECTION_SIZE_3 + PREALLOC_WLAN_SECTION_HEADER)}
285 static void *rk29sdk_mem_prealloc(int section, unsigned long size)
287 if (section == PREALLOC_WLAN_SEC_NUM)
288 return wlan_static_skb;
290 if ((section < 0) || (section > PREALLOC_WLAN_SEC_NUM))
293 if (wifi_mem_array[section].size < size)
296 return wifi_mem_array[section].mem_ptr;
299 static int __init rk29sdk_init_wifi_mem(void)
304 for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
305 wlan_static_skb[i] = dev_alloc_skb(
306 ((i < (WLAN_SKB_BUF_NUM / 2)) ? 4096 : 8192));
308 if (!wlan_static_skb[i])
312 for (i = 0 ; i < PREALLOC_WLAN_SEC_NUM ; i++) {
313 wifi_mem_array[i].mem_ptr =
314 kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
316 if (!wifi_mem_array[i].mem_ptr)
322 pr_err("Failed to mem_alloc for WLAN\n");
323 for (j = 0 ; j < i ; j++)
324 kfree(wifi_mem_array[j].mem_ptr);
326 i = WLAN_SKB_BUF_NUM;
329 pr_err("Failed to skb_alloc for WLAN\n");
330 for (j = 0 ; j < i ; j++)
331 dev_kfree_skb(wlan_static_skb[j]);
336 static int rk29sdk_wifi_cd = 0; /* wifi virtual 'card detect' status */
337 static void (*wifi_status_cb)(int card_present, void *dev_id);
338 static void *wifi_status_cb_devid;
340 static int rk29sdk_wifi_status(struct device *dev)
342 return rk29sdk_wifi_cd;
345 static int rk29sdk_wifi_status_register(void (*callback)(int card_present, void *dev_id), void *dev_id)
349 wifi_status_cb = callback;
350 wifi_status_cb_devid = dev_id;
354 static int __init rk29sdk_wifi_bt_gpio_control_init(void)
356 rk29sdk_init_wifi_mem();
358 rk29_mux_api_set(GPIO0D6_MMC1_PWREN_NAME, GPIO0D_GPIO0D6);
360 if (gpio_request(RK30SDK_WIFI_GPIO_POWER_N, "wifi_power")) {
361 pr_info("%s: request wifi power gpio failed\n", __func__);
365 #ifdef RK30SDK_WIFI_GPIO_RESET_N
366 if (gpio_request(RK30SDK_WIFI_GPIO_RESET_N, "wifi reset")) {
367 pr_info("%s: request wifi reset gpio failed\n", __func__);
368 gpio_free(RK30SDK_WIFI_GPIO_POWER_N);
373 gpio_direction_output(RK30SDK_WIFI_GPIO_POWER_N, !RK30SDK_WIFI_GPIO_POWER_ENABLE_VALUE);
374 #ifdef RK30SDK_WIFI_GPIO_RESET_N
375 gpio_direction_output(RK30SDK_WIFI_GPIO_RESET_N, !RK30SDK_WIFI_GPIO_RESET_ENABLE_VALUE);
378 #if 0//defined(CONFIG_SDMMC1_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
380 rk29_mux_api_set(GPIO0B4_MMC1_D1_NAME, GPIO0B_GPIO0B4);
381 gpio_request(RK2928_PIN0_PB4, "mmc1-data1");
382 gpio_direction_output(RK2928_PIN0_PB4,GPIO_LOW);//set mmc1-data1 to low.
384 rk29_mux_api_set(GPIO0B5_MMC1_D2_NAME, GPIO0B_GPIO0B5);
385 gpio_request(RK2928_PIN0_PB5, "mmc1-data2");
386 gpio_direction_output(RK2928_PIN0_PB5,GPIO_LOW);//set mmc1-data2 to low.
388 rk29_mux_api_set(GPIO0B6_MMC1_D3_NAME, GPIO0B_GPIO0B6);
389 gpio_request(RK2928_PIN0_PB6, "mmc1-data3");
390 gpio_direction_output(RK2928_PIN0_PB6,GPIO_LOW);//set mmc1-data3 to low.
392 rk29_sdmmc_gpio_open(1, 0); //added by xbw at 2011-10-13
394 pr_info("%s: init finished\n",__func__);
399 #if defined(CONFIG_RTL8192CU) || defined(CONFIG_RTL8188EU)
400 static int usbwifi_power_status = 1;
401 int rk29sdk_wifi_power(int on)
403 pr_info("%s: %d\n", __func__, on);
405 /*if(usbwifi_power_status == 1) {
410 usbwifi_power_status = 1;
411 pr_info("wifi turn on power\n");
414 usbwifi_power_status = 0;
415 pr_info("wifi shut off power\n");
420 int rk29sdk_wifi_power(int on)
422 pr_info("%s: %d\n", __func__, on);
424 //gpio_set_value(RK30SDK_WIFI_GPIO_POWER_N, RK30SDK_WIFI_GPIO_POWER_ENABLE_VALUE);
427 #if defined(CONFIG_SDMMC1_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
428 rk29_sdmmc_gpio_open(1, 1); //added by xbw at 2011-10-13
431 #ifdef RK30SDK_WIFI_GPIO_RESET_N
432 //gpio_set_value(RK30SDK_WIFI_GPIO_RESET_N, RK30SDK_WIFI_GPIO_RESET_ENABLE_VALUE);
435 pr_info("wifi turn on power\n");
437 // if (!rk29sdk_bt_power_state){
438 // gpio_set_value(RK30SDK_WIFI_GPIO_POWER_N, !RK30SDK_WIFI_GPIO_POWER_ENABLE_VALUE);
440 #if defined(CONFIG_SDMMC1_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
441 rk29_sdmmc_gpio_open(1, 0); //added by xbw at 2011-10-13
445 pr_info("wifi shut off power\n");
448 // pr_info("wifi shouldn't shut off power, bt is using it!\n");
450 #ifdef RK30SDK_WIFI_GPIO_RESET_N
451 //gpio_set_value(RK30SDK_WIFI_GPIO_RESET_N, !RK30SDK_WIFI_GPIO_RESET_ENABLE_VALUE);
456 //rk29sdk_wifi_power_state = on;
460 EXPORT_SYMBOL(rk29sdk_wifi_power);
462 static int rk29sdk_wifi_reset_state;
463 static int rk29sdk_wifi_reset(int on)
465 pr_info("%s: %d\n", __func__, on);
467 rk29sdk_wifi_reset_state = on;
471 int rk29sdk_wifi_set_carddetect(int val)
473 pr_info("%s:%d\n", __func__, val);
474 rk29sdk_wifi_cd = val;
476 wifi_status_cb(val, wifi_status_cb_devid);
478 pr_warning("%s, nobody to notify\n", __func__);
482 EXPORT_SYMBOL(rk29sdk_wifi_set_carddetect);
484 #define WIFI_HOST_WAKE RK2928_PIN3_PC0
486 static struct resource resources[] = {
488 .start = WIFI_HOST_WAKE,
489 .flags = IORESOURCE_IRQ,
490 .name = "bcmdhd_wlan_irq",
494 static struct wifi_platform_data rk29sdk_wifi_control = {
495 .set_power = rk29sdk_wifi_power,
496 .set_reset = rk29sdk_wifi_reset,
497 .set_carddetect = rk29sdk_wifi_set_carddetect,
498 .mem_prealloc = rk29sdk_mem_prealloc,
501 static struct platform_device rk29sdk_wifi_device = {
502 .name = "bcmdhd_wlan",
504 .num_resources = ARRAY_SIZE(resources),
505 .resource = resources,
507 .platform_data = &rk29sdk_wifi_control,
513 #endif // endif --#ifdef CONFIG_SDMMC_RK29