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(GPIO3B_GPIO3B0,GPIO_HIGH);//set mmc0-clk to high
29 gpio_direction_output(GPIO3B_GPIO3B1,GPIO_HIGH);// set mmc0-cmd to high.
30 gpio_direction_output(GPIO3B_GPIO3B2,GPIO_HIGH);//set mmc0-data0 to high.
31 gpio_direction_output(GPIO3B_GPIO3B3,GPIO_HIGH);//set mmc0-data1 to high.
32 gpio_direction_output(GPIO3B_GPIO3B4,GPIO_HIGH);//set mmc0-data2 to high.
33 gpio_direction_output(GPIO3B_GPIO3B5,GPIO_HIGH);//set mmc0-data3 to high.
39 rk30_mux_api_set(GPIO3B0_SDMMC0CLKOUT_NAME, GPIO3B_GPIO3B0);
40 gpio_request(RK30_PIN3_PB0, "mmc0-clk");
41 gpio_direction_output(RK30_PIN3_PB0,GPIO_LOW);//set mmc0-clk to low.
43 rk30_mux_api_set(GPIO3B1_SDMMC0CMD_NAME, GPIO3B_GPIO3B1);
44 gpio_request(RK30_PIN3_PB1, "mmc0-cmd");
45 gpio_direction_output(RK30_PIN3_PB1,GPIO_LOW);//set mmc0-cmd to low.
47 rk30_mux_api_set(GPIO3B2_SDMMC0DATA0_NAME, GPIO3B_GPIO3B2);
48 gpio_request(RK30_PIN3_PB2, "mmc0-data0");
49 gpio_direction_output(RK30_PIN3_PB2,GPIO_LOW);//set mmc0-data0 to low.
51 rk30_mux_api_set(GPIO3B3_SDMMC0DATA1_NAME, GPIO3B_GPIO3B3);
52 gpio_request(RK30_PIN3_PB3, "mmc0-data1");
53 gpio_direction_output(RK30_PIN3_PB3,GPIO_LOW);//set mmc0-data1 to low.
55 rk30_mux_api_set(GPIO3B4_SDMMC0DATA2_NAME, GPIO3B_GPIO3B4);
56 gpio_request(RK30_PIN3_PB4, "mmc0-data2");
57 gpio_direction_output(RK30_PIN3_PB4,GPIO_LOW);//set mmc0-data2 to low.
59 rk30_mux_api_set(GPIO3B5_SDMMC0DATA3_NAME, GPIO3B_GPIO3B5);
60 gpio_request(RK30_PIN3_PB5, "mmc0-data3");
61 gpio_direction_output(RK30_PIN3_PB5,GPIO_LOW);//set mmc0-data3 to low.
71 #ifdef CONFIG_SDMMC1_RK29
74 gpio_direction_output(RK30_PIN3_PC5,GPIO_HIGH);//set mmc1-clk to high
75 gpio_direction_output(RK30_PIN3_PC0,GPIO_HIGH);//set mmc1-cmd to high.
76 gpio_direction_output(RK30_PIN3_PC1,GPIO_HIGH);//set mmc1-data0 to high.
77 gpio_direction_output(RK30_PIN3_PC2,GPIO_HIGH);//set mmc1-data1 to high.
78 gpio_direction_output(RK30_PIN3_PC3,GPIO_HIGH);//set mmc1-data2 to high.
79 gpio_direction_output(RK30_PIN3_PC5,GPIO_HIGH);//set mmc1-data3 to high.
84 rk30_mux_api_set(GPIO3C5_SDMMC1CLKOUT_NAME, GPIO3C_GPIO3C5);
85 gpio_request(RK30_PIN3_PC5, "mmc1-clk");
86 gpio_direction_output(RK30_PIN3_PC5,GPIO_LOW);//set mmc1-clk to low.
88 rk30_mux_api_set(GPIO3C0_SMMC1CMD_NAME, GPIO3C_GPIO3C0);
89 gpio_request(RK30_PIN3_PC0, "mmc1-cmd");
90 gpio_direction_output(RK30_PIN3_PC0,GPIO_LOW);//set mmc1-cmd to low.
92 rk30_mux_api_set(GPIO3C1_SDMMC1DATA0_NAME, GPIO3C_GPIO3C1);
93 gpio_request(RK30_PIN3_PC1, "mmc1-data0");
94 gpio_direction_output(RK30_PIN3_PC1,GPIO_LOW);//set mmc1-data0 to low.
110 static void rk29_sdmmc_set_iomux_mmc0(unsigned int bus_width)
115 case 1://SDMMC_CTYPE_4BIT:
117 rk30_mux_api_set(GPIO3B3_SDMMC0DATA1_NAME, GPIO3B_SDMMC0_DATA1);
118 rk30_mux_api_set(GPIO3B4_SDMMC0DATA2_NAME, GPIO3B_SDMMC0_DATA2);
119 rk30_mux_api_set(GPIO3B5_SDMMC0DATA3_NAME, GPIO3B_SDMMC0_DATA3);
123 case 0x10000://SDMMC_CTYPE_8BIT:
125 case 0xFFFF: //gpio_reset
127 rk30_mux_api_set(GPIO3A7_SDMMC0PWREN_NAME, GPIO3A_GPIO3A7);
128 gpio_request(RK30_PIN3_PA7,"sdmmc-power");
129 gpio_direction_output(RK30_PIN3_PA7,GPIO_HIGH); //power-off
131 rk29_sdmmc_gpio_open(0, 0);
133 gpio_direction_output(RK30_PIN3_PA7,GPIO_LOW); //power-on
135 rk29_sdmmc_gpio_open(0, 1);
139 default: //case 0://SDMMC_CTYPE_1BIT:
141 rk30_mux_api_set(GPIO3B1_SDMMC0CMD_NAME, GPIO3B_SDMMC0_CMD);
142 rk30_mux_api_set(GPIO3B0_SDMMC0CLKOUT_NAME, GPIO3B_SDMMC0_CLKOUT);
143 rk30_mux_api_set(GPIO3B2_SDMMC0DATA0_NAME, GPIO3B_SDMMC0_DATA0);
145 rk30_mux_api_set(GPIO3B3_SDMMC0DATA1_NAME, GPIO3B_GPIO3B3);
146 gpio_request(RK30_PIN3_PB3, "mmc0-data1");
147 gpio_direction_output(RK30_PIN3_PB3,GPIO_HIGH);//set mmc0-data1 to high.
149 rk30_mux_api_set(GPIO3B4_SDMMC0DATA2_NAME, GPIO3B_GPIO3B4);
150 gpio_request(RK30_PIN3_PB4, "mmc0-data2");
151 gpio_direction_output(RK30_PIN3_PB4,GPIO_HIGH);//set mmc0-data2 to high.
153 rk30_mux_api_set(GPIO3B5_SDMMC0DATA3_NAME, GPIO3B_GPIO3B5);
154 gpio_request(RK30_PIN3_PB5, "mmc0-data3");
155 gpio_direction_output(RK30_PIN3_PB5,GPIO_HIGH);//set mmc0-data3 to high.
161 static void rk29_sdmmc_set_iomux_mmc1(unsigned int bus_width)
163 rk30_mux_api_set(GPIO3C0_SMMC1CMD_NAME, GPIO3C_SMMC1_CMD);
164 rk30_mux_api_set(GPIO3C5_SDMMC1CLKOUT_NAME, GPIO3C_SDMMC1_CLKOUT);
165 rk30_mux_api_set(GPIO3C1_SDMMC1DATA0_NAME, GPIO3C_SDMMC1_DATA0);
166 rk30_mux_api_set(GPIO3C2_SDMMC1DATA1_NAME, GPIO3C_SDMMC1_DATA1);
167 rk30_mux_api_set(GPIO3C3_SDMMC1DATA2_NAME, GPIO3C_SDMMC1_DATA2);
168 rk30_mux_api_set(GPIO3C4_SDMMC1DATA3_NAME, GPIO3C_SDMMC1_DATA3);
171 static void rk29_sdmmc_set_iomux_mmc2(unsigned int bus_width)
176 static void rk29_sdmmc_set_iomux(int device_id, unsigned int bus_width)
181 #ifdef CONFIG_SDMMC0_RK29
182 rk29_sdmmc_set_iomux_mmc0(bus_width);
186 #ifdef CONFIG_SDMMC1_RK29
187 rk29_sdmmc_set_iomux_mmc1(bus_width);
191 rk29_sdmmc_set_iomux_mmc2(bus_width);
201 int rk29sdk_wifi_power_state = 0;
202 int rk29sdk_bt_power_state = 0;
204 #ifdef CONFIG_WIFI_CONTROL_FUNC
205 #define RK30SDK_WIFI_BT_GPIO_POWER_N RK30_PIN4_PD5
206 #define RK30SDK_WIFI_GPIO_RESET_N RK30_PIN3_PD0
209 #define PREALLOC_WLAN_SEC_NUM 4
210 #define PREALLOC_WLAN_BUF_NUM 160
211 #define PREALLOC_WLAN_SECTION_HEADER 24
213 #define WLAN_SECTION_SIZE_0 (PREALLOC_WLAN_BUF_NUM * 128)
214 #define WLAN_SECTION_SIZE_1 (PREALLOC_WLAN_BUF_NUM * 128)
215 #define WLAN_SECTION_SIZE_2 (PREALLOC_WLAN_BUF_NUM * 512)
216 #define WLAN_SECTION_SIZE_3 (PREALLOC_WLAN_BUF_NUM * 1024)
218 #define WLAN_SKB_BUF_NUM 16
220 static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM];
222 struct wifi_mem_prealloc {
227 static struct wifi_mem_prealloc wifi_mem_array[PREALLOC_WLAN_SEC_NUM] = {
228 {NULL, (WLAN_SECTION_SIZE_0 + PREALLOC_WLAN_SECTION_HEADER)},
229 {NULL, (WLAN_SECTION_SIZE_1 + PREALLOC_WLAN_SECTION_HEADER)},
230 {NULL, (WLAN_SECTION_SIZE_2 + PREALLOC_WLAN_SECTION_HEADER)},
231 {NULL, (WLAN_SECTION_SIZE_3 + PREALLOC_WLAN_SECTION_HEADER)}
234 static void *rk29sdk_mem_prealloc(int section, unsigned long size)
236 if (section == PREALLOC_WLAN_SEC_NUM)
237 return wlan_static_skb;
239 if ((section < 0) || (section > PREALLOC_WLAN_SEC_NUM))
242 if (wifi_mem_array[section].size < size)
245 return wifi_mem_array[section].mem_ptr;
248 static int __init rk29sdk_init_wifi_mem(void)
253 for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
254 wlan_static_skb[i] = dev_alloc_skb(
255 ((i < (WLAN_SKB_BUF_NUM / 2)) ? 4096 : 8192));
257 if (!wlan_static_skb[i])
261 for (i = 0 ; i < PREALLOC_WLAN_SEC_NUM ; i++) {
262 wifi_mem_array[i].mem_ptr =
263 kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
265 if (!wifi_mem_array[i].mem_ptr)
271 pr_err("Failed to mem_alloc for WLAN\n");
272 for (j = 0 ; j < i ; j++)
273 kfree(wifi_mem_array[j].mem_ptr);
275 i = WLAN_SKB_BUF_NUM;
278 pr_err("Failed to skb_alloc for WLAN\n");
279 for (j = 0 ; j < i ; j++)
280 dev_kfree_skb(wlan_static_skb[j]);
285 static int rk29sdk_wifi_cd = 0; /* wifi virtual 'card detect' status */
286 static void (*wifi_status_cb)(int card_present, void *dev_id);
287 static void *wifi_status_cb_devid;
289 static int rk29sdk_wifi_status(struct device *dev)
291 return rk29sdk_wifi_cd;
294 static int rk29sdk_wifi_status_register(void (*callback)(int card_present, void *dev_id), void *dev_id)
298 wifi_status_cb = callback;
299 wifi_status_cb_devid = dev_id;
303 static int __init rk29sdk_wifi_bt_gpio_control_init(void)
305 rk29sdk_init_wifi_mem();
307 rk29_mux_api_set(GPIO4D5_SMCDATA13_TRACEDATA13_NAME, GPIO4D_GPIO4D5);
309 rk29_mux_api_set(GPIO3D0_SDMMC1PWREN_NAME, GPIO3D_GPIO3D0);
311 if (gpio_request(RK30SDK_WIFI_BT_GPIO_POWER_N, "wifi_power")) {
312 pr_info("%s: request wifi power gpio failed\n", __func__);
316 if (gpio_request(RK30SDK_WIFI_GPIO_RESET_N, "wifi reset")) {
317 pr_info("%s: request wifi reset gpio failed\n", __func__);
318 gpio_free(RK30SDK_WIFI_GPIO_RESET_N);
323 gpio_direction_output(RK30SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
324 gpio_direction_output(RK30SDK_WIFI_GPIO_RESET_N, GPIO_LOW);
326 #if defined(CONFIG_SDMMC1_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
328 rk29_mux_api_set(GPIO3C2_SDMMC1DATA1_NAME, GPIO3C_GPIO3C2);
329 gpio_request(RK30_PIN3_PC2, "mmc1-data1");
330 gpio_direction_output(RK30_PIN3_PC2,GPIO_LOW);//set mmc1-data1 to low.
332 rk29_mux_api_set(GPIO3C3_SDMMC1DATA2_NAME, GPIO3C_GPIO3C3);
333 gpio_request(RK30_PIN3_PC3, "mmc1-data2");
334 gpio_direction_output(RK30_PIN3_PC3,GPIO_LOW);//set mmc1-data2 to low.
336 rk29_mux_api_set(GPIO3C4_SDMMC1DATA3_NAME, GPIO3C_GPIO3C4);
337 gpio_request(RK30_PIN3_PC4, "mmc1-data3");
338 gpio_direction_output(RK30_PIN3_PC4,GPIO_LOW);//set mmc1-data3 to low.
340 rk29_sdmmc_gpio_open(1, 0); //added by xbw at 2011-10-13
342 pr_info("%s: init finished\n",__func__);
347 static int rk29sdk_wifi_power(int on)
349 pr_info("%s: %d\n", __func__, on);
351 gpio_set_value(RK30SDK_WIFI_BT_GPIO_POWER_N, GPIO_HIGH);
353 #if defined(CONFIG_SDMMC1_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
354 rk29_sdmmc_gpio_open(1, 1); //added by xbw at 2011-10-13
357 gpio_set_value(RK30SDK_WIFI_GPIO_RESET_N, GPIO_HIGH);
359 pr_info("wifi turn on power\n");
361 if (!rk29sdk_bt_power_state){
362 gpio_set_value(RK30SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
364 #if defined(CONFIG_SDMMC1_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
365 rk29_sdmmc_gpio_open(1, 0); //added by xbw at 2011-10-13
369 pr_info("wifi shut off power\n");
372 pr_info("wifi shouldn't shut off power, bt is using it!\n");
374 gpio_set_value(RK30SDK_WIFI_GPIO_RESET_N, GPIO_LOW);
378 rk29sdk_wifi_power_state = on;
382 static int rk29sdk_wifi_reset_state;
383 static int rk29sdk_wifi_reset(int on)
385 pr_info("%s: %d\n", __func__, on);
386 gpio_set_value(RK30SDK_WIFI_GPIO_RESET_N, on);
388 rk29sdk_wifi_reset_state = on;
392 int rk29sdk_wifi_set_carddetect(int val)
394 pr_info("%s:%d\n", __func__, val);
395 rk29sdk_wifi_cd = val;
397 wifi_status_cb(val, wifi_status_cb_devid);
399 pr_warning("%s, nobody to notify\n", __func__);
403 EXPORT_SYMBOL(rk29sdk_wifi_set_carddetect);
405 static struct wifi_platform_data rk29sdk_wifi_control = {
406 .set_power = rk29sdk_wifi_power,
407 .set_reset = rk29sdk_wifi_reset,
408 .set_carddetect = rk29sdk_wifi_set_carddetect,
409 .mem_prealloc = rk29sdk_mem_prealloc,
412 static struct platform_device rk29sdk_wifi_device = {
413 .name = "bcm4329_wlan",
416 .platform_data = &rk29sdk_wifi_control,
422 #endif // endif --#ifdef CONFIG_SDMMC_RK29