2 * SDIO access interface for drivers - linux specific (pci only)
4 * $Copyright Open Broadcom Corporation$
6 * $Id: bcmsdh_linux.c 461444 2014-03-12 02:55:28Z $
10 * @file bcmsdh_linux.c
13 #define __UNDEF_NO_VERSION__
17 #include <linux/pci.h>
18 #include <linux/completion.h>
24 #include <linux/irq.h>
25 extern void dhdsdio_isr(void * args);
27 #include <dngl_stats.h>
29 #if defined(CONFIG_ARCH_ODIN)
30 #include <linux/platform_data/gpio-odin.h>
31 #endif /* defined(CONFIG_ARCH_ODIN) */
32 #include <dhd_linux.h>
34 /* driver info, initialized when bcmsdh_register is called */
35 static bcmsdh_driver_t drvinfo = {NULL, NULL, NULL, NULL};
44 /* the BCMSDH module comprises the generic part (bcmsdh.c) and OS specific layer (e.g.
45 * bcmsdh_linux.c). Put all OS specific variables (e.g. irq number and flags) here rather
46 * than in the common structure bcmsdh_info. bcmsdh_info only keeps a handle (os_ctx) to this
49 typedef struct bcmsdh_os_info {
50 DHD_HOST_INTR_TYPE intr_type;
51 int oob_irq_num; /* valid when hardware or software oob in use */
52 unsigned long oob_irq_flags; /* valid when hardware or software oob in use */
53 bool oob_irq_registered;
55 bool oob_irq_wake_enabled;
56 spinlock_t oob_irq_spinlock;
57 bcmsdh_cb_fn_t oob_irq_handler;
58 void *oob_irq_handler_context;
59 void *context; /* context returned from upper layer */
60 void *sdioh; /* handle to lower layer (sdioh) */
61 void *dev; /* handle to the underlying device */
62 bool dev_wake_enabled;
65 /* debugging macros */
66 #define SDLX_MSG(x) printf x
69 * Checks to see if vendor and device IDs match a supported SDIO Host Controller.
72 bcmsdh_chipmatch(uint16 vendor, uint16 device)
74 /* Add other vendors and devices as required */
77 /* Check for Arasan host controller */
78 if (vendor == VENDOR_SI_IMAGE) {
81 /* Check for BRCM 27XX Standard host controller */
82 if (device == BCM27XX_SDIOH_ID && vendor == VENDOR_BROADCOM) {
85 /* Check for BRCM Standard host controller */
86 if (device == SDIOH_FPGA_ID && vendor == VENDOR_BROADCOM) {
89 /* Check for TI PCIxx21 Standard host controller */
90 if (device == PCIXX21_SDIOH_ID && vendor == VENDOR_TI) {
93 if (device == PCIXX21_SDIOH0_ID && vendor == VENDOR_TI) {
96 /* Ricoh R5C822 Standard SDIO Host */
97 if (device == R5C822_SDIOH_ID && vendor == VENDOR_RICOH) {
100 /* JMicron Standard SDIO Host */
101 if (device == JMICRON_SDIOH_ID && vendor == VENDOR_JMICRON) {
105 #endif /* BCMSDIOH_STD */
107 /* This is the PciSpiHost. */
108 if (device == SPIH_FPGA_ID && vendor == VENDOR_BROADCOM) {
109 printf("Found PCI SPI Host Controller\n");
113 #endif /* BCMSDIOH_SPI */
118 void* bcmsdh_probe(osl_t *osh, void *dev, void *sdioh, void *adapter_info, uint bus_type,
119 uint bus_num, uint slot_num)
122 bcmsdh_info_t *bcmsdh;
124 bcmsdh_os_info_t *bcmsdh_osinfo = NULL;
126 bcmsdh = bcmsdh_attach(osh, sdioh, ®s);
127 if (bcmsdh == NULL) {
128 SDLX_MSG(("%s: bcmsdh_attach failed\n", __FUNCTION__));
131 bcmsdh_osinfo = MALLOC(osh, sizeof(bcmsdh_os_info_t));
132 if (bcmsdh_osinfo == NULL) {
133 SDLX_MSG(("%s: failed to allocate bcmsdh_os_info_t\n", __FUNCTION__));
136 bzero((char *)bcmsdh_osinfo, sizeof(bcmsdh_os_info_t));
137 bcmsdh->os_cxt = bcmsdh_osinfo;
138 bcmsdh_osinfo->sdioh = sdioh;
139 bcmsdh_osinfo->dev = dev;
140 osl_set_bus_handle(osh, bcmsdh);
142 #if !defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
143 if (dev && device_init_wakeup(dev, true) == 0)
144 bcmsdh_osinfo->dev_wake_enabled = TRUE;
145 #endif /* !defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36)) */
147 #if defined(OOB_INTR_ONLY)
148 spin_lock_init(&bcmsdh_osinfo->oob_irq_spinlock);
149 /* Get customer specific OOB IRQ parametres: IRQ number as IRQ type */
150 bcmsdh_osinfo->oob_irq_num = wifi_platform_get_irq_number(adapter_info,
151 &bcmsdh_osinfo->oob_irq_flags);
152 if (bcmsdh_osinfo->oob_irq_num < 0) {
153 SDLX_MSG(("%s: Host OOB irq is not defined\n", __FUNCTION__));
156 #endif /* defined(BCMLXSDMMC) */
158 /* Read the vendor/device ID from the CIS */
159 vendevid = bcmsdh_query_device(bcmsdh);
160 /* try to attach to the target device */
161 bcmsdh_osinfo->context = drvinfo.probe((vendevid >> 16), (vendevid & 0xFFFF), bus_num,
162 slot_num, 0, bus_type, (void *)regs, osh, bcmsdh);
163 if (bcmsdh_osinfo->context == NULL) {
164 SDLX_MSG(("%s: device attach failed\n", __FUNCTION__));
173 bcmsdh_detach(osh, bcmsdh);
174 if (bcmsdh_osinfo != NULL)
175 MFREE(osh, bcmsdh_osinfo, sizeof(bcmsdh_os_info_t));
179 int bcmsdh_remove(bcmsdh_info_t *bcmsdh)
181 bcmsdh_os_info_t *bcmsdh_osinfo = bcmsdh->os_cxt;
183 #if !defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
184 if (bcmsdh_osinfo->dev)
185 device_init_wakeup(bcmsdh_osinfo->dev, false);
186 bcmsdh_osinfo->dev_wake_enabled = FALSE;
187 #endif /* !defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36)) */
189 drvinfo.remove(bcmsdh_osinfo->context);
190 MFREE(bcmsdh->osh, bcmsdh->os_cxt, sizeof(bcmsdh_os_info_t));
191 bcmsdh_detach(bcmsdh->osh, bcmsdh);
196 int bcmsdh_suspend(bcmsdh_info_t *bcmsdh)
198 bcmsdh_os_info_t *bcmsdh_osinfo = bcmsdh->os_cxt;
200 if (drvinfo.suspend && drvinfo.suspend(bcmsdh_osinfo->context))
205 int bcmsdh_resume(bcmsdh_info_t *bcmsdh)
207 bcmsdh_os_info_t *bcmsdh_osinfo = bcmsdh->os_cxt;
210 return drvinfo.resume(bcmsdh_osinfo->context);
214 extern int bcmsdh_register_client_driver(void);
215 extern void bcmsdh_unregister_client_driver(void);
216 extern int sdio_func_reg_notify(void* semaphore);
217 extern void sdio_func_unreg_notify(void);
219 #if defined(BCMLXSDMMC)
220 int bcmsdh_reg_sdio_notify(void* semaphore)
222 return sdio_func_reg_notify(semaphore);
225 void bcmsdh_unreg_sdio_notify(void)
227 sdio_func_unreg_notify();
229 #endif /* defined(BCMLXSDMMC) */
232 bcmsdh_register(bcmsdh_driver_t *driver)
237 SDLX_MSG(("%s: register client driver\n", __FUNCTION__));
238 error = bcmsdh_register_client_driver();
240 SDLX_MSG(("%s: failed %d\n", __FUNCTION__, error));
246 bcmsdh_unregister(void)
248 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
249 if (bcmsdh_pci_driver.node.next == NULL)
253 bcmsdh_unregister_client_driver();
256 void bcmsdh_dev_pm_stay_awake(bcmsdh_info_t *bcmsdh)
258 #if !defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
259 bcmsdh_os_info_t *bcmsdh_osinfo = bcmsdh->os_cxt;
260 pm_stay_awake(bcmsdh_osinfo->dev);
261 #endif /* !defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36)) */
264 void bcmsdh_dev_relax(bcmsdh_info_t *bcmsdh)
266 #if !defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
267 bcmsdh_os_info_t *bcmsdh_osinfo = bcmsdh->os_cxt;
268 pm_relax(bcmsdh_osinfo->dev);
269 #endif /* !defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36)) */
272 bool bcmsdh_dev_pm_enabled(bcmsdh_info_t *bcmsdh)
274 bcmsdh_os_info_t *bcmsdh_osinfo = bcmsdh->os_cxt;
276 return bcmsdh_osinfo->dev_wake_enabled;
279 #if defined(OOB_INTR_ONLY)
280 void bcmsdh_oob_intr_set(bcmsdh_info_t *bcmsdh, bool enable)
283 bcmsdh_os_info_t *bcmsdh_osinfo;
288 bcmsdh_osinfo = bcmsdh->os_cxt;
289 spin_lock_irqsave(&bcmsdh_osinfo->oob_irq_spinlock, flags);
290 if (bcmsdh_osinfo->oob_irq_enabled != enable) {
292 enable_irq(bcmsdh_osinfo->oob_irq_num);
294 disable_irq_nosync(bcmsdh_osinfo->oob_irq_num);
295 bcmsdh_osinfo->oob_irq_enabled = enable;
297 spin_unlock_irqrestore(&bcmsdh_osinfo->oob_irq_spinlock, flags);
300 static irqreturn_t wlan_oob_irq(int irq, void *dev_id)
302 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)dev_id;
303 bcmsdh_os_info_t *bcmsdh_osinfo = bcmsdh->os_cxt;
305 bcmsdh_oob_intr_set(bcmsdh, FALSE);
306 bcmsdh_osinfo->oob_irq_handler(bcmsdh_osinfo->oob_irq_handler_context);
311 int bcmsdh_oob_intr_register(bcmsdh_info_t *bcmsdh, bcmsdh_cb_fn_t oob_irq_handler,
312 void* oob_irq_handler_context)
315 bcmsdh_os_info_t *bcmsdh_osinfo = bcmsdh->os_cxt;
317 SDLX_MSG(("%s: Enter\n", __FUNCTION__));
318 if (bcmsdh_osinfo->oob_irq_registered) {
319 SDLX_MSG(("%s: irq is already registered\n", __FUNCTION__));
322 SDLX_MSG(("%s OOB irq=%d flags=%X\n", __FUNCTION__,
323 (int)bcmsdh_osinfo->oob_irq_num, (int)bcmsdh_osinfo->oob_irq_flags));
324 bcmsdh_osinfo->oob_irq_handler = oob_irq_handler;
325 bcmsdh_osinfo->oob_irq_handler_context = oob_irq_handler_context;
326 #if defined(CONFIG_ARCH_ODIN)
327 err = odin_gpio_sms_request_irq(bcmsdh_osinfo->oob_irq_num, wlan_oob_irq,
328 bcmsdh_osinfo->oob_irq_flags, "bcmsdh_sdmmc", bcmsdh);
330 err = request_irq(bcmsdh_osinfo->oob_irq_num, wlan_oob_irq,
331 bcmsdh_osinfo->oob_irq_flags, "bcmsdh_sdmmc", bcmsdh);
332 #endif /* defined(CONFIG_ARCH_ODIN) */
334 SDLX_MSG(("%s: request_irq failed with %d\n", __FUNCTION__, err));
338 #if defined(DISABLE_WOWLAN)
339 SDLX_MSG(("%s: disable_irq_wake\n", __FUNCTION__));
340 err = disable_irq_wake(bcmsdh_osinfo->oob_irq_num);
342 SDLX_MSG(("%s: disable_irq_wake failed with %d\n", __FUNCTION__, err));
344 bcmsdh_osinfo->oob_irq_wake_enabled = FALSE;
346 SDLX_MSG(("%s: enable_irq_wake\n", __FUNCTION__));
347 err = enable_irq_wake(bcmsdh_osinfo->oob_irq_num);
349 SDLX_MSG(("%s: enable_irq_wake failed with %d\n", __FUNCTION__, err));
351 bcmsdh_osinfo->oob_irq_wake_enabled = TRUE;
353 bcmsdh_osinfo->oob_irq_enabled = TRUE;
354 bcmsdh_osinfo->oob_irq_registered = TRUE;
358 void bcmsdh_oob_intr_unregister(bcmsdh_info_t *bcmsdh)
361 bcmsdh_os_info_t *bcmsdh_osinfo = bcmsdh->os_cxt;
363 SDLX_MSG(("%s: Enter\n", __FUNCTION__));
364 if (!bcmsdh_osinfo->oob_irq_registered) {
365 SDLX_MSG(("%s: irq is not registered\n", __FUNCTION__));
368 if (bcmsdh_osinfo->oob_irq_wake_enabled) {
369 err = disable_irq_wake(bcmsdh_osinfo->oob_irq_num);
371 bcmsdh_osinfo->oob_irq_wake_enabled = FALSE;
373 if (bcmsdh_osinfo->oob_irq_enabled) {
374 disable_irq(bcmsdh_osinfo->oob_irq_num);
375 bcmsdh_osinfo->oob_irq_enabled = FALSE;
377 free_irq(bcmsdh_osinfo->oob_irq_num, bcmsdh);
378 bcmsdh_osinfo->oob_irq_registered = FALSE;
382 /* Module parameters specific to each host-controller driver */
384 extern uint sd_msglevel; /* Debug message level */
385 module_param(sd_msglevel, uint, 0);
387 extern uint sd_power; /* 0 = SD Power OFF, 1 = SD Power ON. */
388 module_param(sd_power, uint, 0);
390 extern uint sd_clock; /* SD Clock Control, 0 = SD Clock OFF, 1 = SD Clock ON */
391 module_param(sd_clock, uint, 0);
393 extern uint sd_divisor; /* Divisor (-1 means external clock) */
394 module_param(sd_divisor, uint, 0);
396 extern uint sd_sdmode; /* Default is SD4, 0=SPI, 1=SD1, 2=SD4 */
397 module_param(sd_sdmode, uint, 0);
399 extern uint sd_hiok; /* Ok to use hi-speed mode */
400 module_param(sd_hiok, uint, 0);
402 extern uint sd_f2_blocksize;
403 module_param(sd_f2_blocksize, int, 0);
406 extern int sd_uhsimode;
407 module_param(sd_uhsimode, int, 0);
408 extern uint sd_tuning_period;
409 module_param(sd_tuning_period, uint, 0);
410 extern int sd_delay_value;
411 module_param(sd_delay_value, uint, 0);
413 /* SDIO Drive Strength for UHSI mode specific to SDIO3.0 */
414 extern char dhd_sdiod_uhsi_ds_override[2];
415 module_param_string(dhd_sdiod_uhsi_ds_override, dhd_sdiod_uhsi_ds_override, 2, 0);
420 EXPORT_SYMBOL(bcmsdh_attach);
421 EXPORT_SYMBOL(bcmsdh_detach);
422 EXPORT_SYMBOL(bcmsdh_intr_query);
423 EXPORT_SYMBOL(bcmsdh_intr_enable);
424 EXPORT_SYMBOL(bcmsdh_intr_disable);
425 EXPORT_SYMBOL(bcmsdh_intr_reg);
426 EXPORT_SYMBOL(bcmsdh_intr_dereg);
428 #if defined(DHD_DEBUG)
429 EXPORT_SYMBOL(bcmsdh_intr_pending);
432 EXPORT_SYMBOL(bcmsdh_devremove_reg);
433 EXPORT_SYMBOL(bcmsdh_cfg_read);
434 EXPORT_SYMBOL(bcmsdh_cfg_write);
435 EXPORT_SYMBOL(bcmsdh_cis_read);
436 EXPORT_SYMBOL(bcmsdh_reg_read);
437 EXPORT_SYMBOL(bcmsdh_reg_write);
438 EXPORT_SYMBOL(bcmsdh_regfail);
439 EXPORT_SYMBOL(bcmsdh_send_buf);
440 EXPORT_SYMBOL(bcmsdh_recv_buf);
442 EXPORT_SYMBOL(bcmsdh_rwdata);
443 EXPORT_SYMBOL(bcmsdh_abort);
444 EXPORT_SYMBOL(bcmsdh_query_device);
445 EXPORT_SYMBOL(bcmsdh_query_iofnum);
446 EXPORT_SYMBOL(bcmsdh_iovar_op);
447 EXPORT_SYMBOL(bcmsdh_register);
448 EXPORT_SYMBOL(bcmsdh_unregister);
449 EXPORT_SYMBOL(bcmsdh_chipmatch);
450 EXPORT_SYMBOL(bcmsdh_reset);
451 EXPORT_SYMBOL(bcmsdh_waitlockfree);
453 EXPORT_SYMBOL(bcmsdh_get_dstatus);
454 EXPORT_SYMBOL(bcmsdh_cfg_read_word);
455 EXPORT_SYMBOL(bcmsdh_cfg_write_word);
456 EXPORT_SYMBOL(bcmsdh_cur_sbwad);
457 EXPORT_SYMBOL(bcmsdh_chipinfo);
459 #endif /* BCMSDH_MODULE */