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
207 #define RK30SDK_BT_GPIO_RESET_N RK30_PIN3_PD1
210 #define PREALLOC_WLAN_SEC_NUM 4
211 #define PREALLOC_WLAN_BUF_NUM 160
212 #define PREALLOC_WLAN_SECTION_HEADER 24
214 #define WLAN_SECTION_SIZE_0 (PREALLOC_WLAN_BUF_NUM * 128)
215 #define WLAN_SECTION_SIZE_1 (PREALLOC_WLAN_BUF_NUM * 128)
216 #define WLAN_SECTION_SIZE_2 (PREALLOC_WLAN_BUF_NUM * 512)
217 #define WLAN_SECTION_SIZE_3 (PREALLOC_WLAN_BUF_NUM * 1024)
219 #define WLAN_SKB_BUF_NUM 16
221 static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM];
223 struct wifi_mem_prealloc {
228 static struct wifi_mem_prealloc wifi_mem_array[PREALLOC_WLAN_SEC_NUM] = {
229 {NULL, (WLAN_SECTION_SIZE_0 + PREALLOC_WLAN_SECTION_HEADER)},
230 {NULL, (WLAN_SECTION_SIZE_1 + PREALLOC_WLAN_SECTION_HEADER)},
231 {NULL, (WLAN_SECTION_SIZE_2 + PREALLOC_WLAN_SECTION_HEADER)},
232 {NULL, (WLAN_SECTION_SIZE_3 + PREALLOC_WLAN_SECTION_HEADER)}
235 static void *rk29sdk_mem_prealloc(int section, unsigned long size)
237 if (section == PREALLOC_WLAN_SEC_NUM)
238 return wlan_static_skb;
240 if ((section < 0) || (section > PREALLOC_WLAN_SEC_NUM))
243 if (wifi_mem_array[section].size < size)
246 return wifi_mem_array[section].mem_ptr;
249 static int __init rk29sdk_init_wifi_mem(void)
254 for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
255 wlan_static_skb[i] = dev_alloc_skb(
256 ((i < (WLAN_SKB_BUF_NUM / 2)) ? 4096 : 8192));
258 if (!wlan_static_skb[i])
262 for (i = 0 ; i < PREALLOC_WLAN_SEC_NUM ; i++) {
263 wifi_mem_array[i].mem_ptr =
264 kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
266 if (!wifi_mem_array[i].mem_ptr)
272 pr_err("Failed to mem_alloc for WLAN\n");
273 for (j = 0 ; j < i ; j++)
274 kfree(wifi_mem_array[j].mem_ptr);
276 i = WLAN_SKB_BUF_NUM;
279 pr_err("Failed to skb_alloc for WLAN\n");
280 for (j = 0 ; j < i ; j++)
281 dev_kfree_skb(wlan_static_skb[j]);
286 static int rk29sdk_wifi_cd = 0; /* wifi virtual 'card detect' status */
287 static void (*wifi_status_cb)(int card_present, void *dev_id);
288 static void *wifi_status_cb_devid;
290 static int rk29sdk_wifi_status(struct device *dev)
292 return rk29sdk_wifi_cd;
295 static int rk29sdk_wifi_status_register(void (*callback)(int card_present, void *dev_id), void *dev_id)
299 wifi_status_cb = callback;
300 wifi_status_cb_devid = dev_id;
304 static int __init rk29sdk_wifi_bt_gpio_control_init(void)
306 rk29sdk_init_wifi_mem();
308 rk29_mux_api_set(GPIO4D5_SMCDATA13_TRACEDATA13_NAME, GPIO4D_GPIO4D5);
310 rk29_mux_api_set(GPIO3D0_SDMMC1PWREN_NAME, GPIO3D_GPIO3D0);
312 if (gpio_request(RK30SDK_WIFI_BT_GPIO_POWER_N, "wifi_power")) {
313 pr_info("%s: request wifi power gpio failed\n", __func__);
317 if (gpio_request(RK30SDK_WIFI_GPIO_RESET_N, "wifi reset")) {
318 pr_info("%s: request wifi reset gpio failed\n", __func__);
319 gpio_free(RK30SDK_WIFI_GPIO_RESET_N);
323 if (gpio_request(RK30SDK_BT_GPIO_RESET_N, "bt reset")) {
324 pr_info("%s: request bt reset gpio failed\n", __func__);
325 gpio_free(RK30SDK_WIFI_GPIO_RESET_N);
329 gpio_direction_output(RK30SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
330 gpio_direction_output(RK30SDK_WIFI_GPIO_RESET_N, GPIO_LOW);
331 gpio_direction_output(RK30SDK_BT_GPIO_RESET_N, GPIO_LOW);
333 #if defined(CONFIG_SDMMC1_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
335 rk29_mux_api_set(GPIO3C2_SDMMC1DATA1_NAME, GPIO3C_GPIO3C2);
336 gpio_request(RK30_PIN3_PC2, "mmc1-data1");
337 gpio_direction_output(RK30_PIN3_PC2,GPIO_LOW);//set mmc1-data1 to low.
339 rk29_mux_api_set(GPIO3C3_SDMMC1DATA2_NAME, GPIO3C_GPIO3C3);
340 gpio_request(RK30_PIN3_PC3, "mmc1-data2");
341 gpio_direction_output(RK30_PIN3_PC3,GPIO_LOW);//set mmc1-data2 to low.
343 rk29_mux_api_set(GPIO3C4_SDMMC1DATA3_NAME, GPIO3C_GPIO3C4);
344 gpio_request(RK30_PIN3_PC4, "mmc1-data3");
345 gpio_direction_output(RK30_PIN3_PC4,GPIO_LOW);//set mmc1-data3 to low.
347 rk29_sdmmc_gpio_open(1, 0); //added by xbw at 2011-10-13
349 pr_info("%s: init finished\n",__func__);
354 static int rk29sdk_wifi_power(int on)
356 pr_info("%s: %d\n", __func__, on);
358 gpio_set_value(RK30SDK_WIFI_BT_GPIO_POWER_N, GPIO_HIGH);
360 #if defined(CONFIG_SDMMC1_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
361 rk29_sdmmc_gpio_open(1, 1); //added by xbw at 2011-10-13
364 gpio_set_value(RK30SDK_WIFI_GPIO_RESET_N, GPIO_HIGH);
366 pr_info("wifi turn on power\n");
368 if (!rk29sdk_bt_power_state){
369 gpio_set_value(RK30SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
371 #if defined(CONFIG_SDMMC1_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
372 rk29_sdmmc_gpio_open(1, 0); //added by xbw at 2011-10-13
376 pr_info("wifi shut off power\n");
379 pr_info("wifi shouldn't shut off power, bt is using it!\n");
381 gpio_set_value(RK30SDK_WIFI_GPIO_RESET_N, GPIO_LOW);
385 rk29sdk_wifi_power_state = on;
389 static int rk29sdk_wifi_reset_state;
390 static int rk29sdk_wifi_reset(int on)
392 pr_info("%s: %d\n", __func__, on);
393 gpio_set_value(RK30SDK_WIFI_GPIO_RESET_N, on);
395 rk29sdk_wifi_reset_state = on;
399 int rk29sdk_wifi_set_carddetect(int val)
401 pr_info("%s:%d\n", __func__, val);
402 rk29sdk_wifi_cd = val;
404 wifi_status_cb(val, wifi_status_cb_devid);
406 pr_warning("%s, nobody to notify\n", __func__);
410 EXPORT_SYMBOL(rk29sdk_wifi_set_carddetect);
412 static struct wifi_platform_data rk29sdk_wifi_control = {
413 .set_power = rk29sdk_wifi_power,
414 .set_reset = rk29sdk_wifi_reset,
415 .set_carddetect = rk29sdk_wifi_set_carddetect,
416 .mem_prealloc = rk29sdk_mem_prealloc,
419 static struct platform_device rk29sdk_wifi_device = {
420 .name = "bcm4329_wlan",
423 .platform_data = &rk29sdk_wifi_control,
429 #endif // endif --#ifdef CONFIG_SDMMC_RK29