2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 * @file bcmsdh_linux.c
21 #define __UNDEF_NO_VERSION__
23 #include <linux/netdevice.h>
24 #include <linux/pci.h>
25 #include <linux/completion.h>
26 #include <linux/sched.h>
29 #include <brcm_hw_ids.h>
30 #include <brcmu_utils.h>
31 #include <brcmu_wifi.h>
32 #include "sdio_host.h"
34 extern void brcmf_sdbrcm_isr(void *args);
36 #include "dngl_stats.h"
40 * SDIO Host Controller info
43 struct bcmsdh_hc *next;
44 struct device *dev; /* platform device handle */
45 void *regs; /* SDIO Host Controller address */
46 struct brcmf_sdio *sdh; /* SDIO Host Controller handle */
49 unsigned long oob_flags; /* OOB Host specifiction
51 bool oob_irq_registered;
53 static struct bcmsdh_hc *sdhcinfo;
55 /* driver info, initialized when brcmf_sdio_register is called */
56 static struct brcmf_sdioh_driver drvinfo = { NULL, NULL };
58 /* debugging macros */
62 * Checks to see if vendor and device IDs match a supported SDIO Host Controller.
64 bool brcmf_sdio_chipmatch(u16 vendor, u16 device)
66 /* Add other vendors and devices as required */
69 /* Check for Arasan host controller */
70 if (vendor == VENDOR_SI_IMAGE)
73 /* Check for BRCM 27XX Standard host controller */
74 if (device == BCM27XX_SDIOH_ID && vendor == PCI_VENDOR_ID_BROADCOM)
77 /* Check for BRCM Standard host controller */
78 if (device == SDIOH_FPGA_ID && vendor == PCI_VENDOR_ID_BROADCOM)
81 /* Check for TI PCIxx21 Standard host controller */
82 if (device == PCIXX21_SDIOH_ID && vendor == VENDOR_TI)
85 if (device == PCIXX21_SDIOH0_ID && vendor == VENDOR_TI)
88 /* Ricoh R5C822 Standard SDIO Host */
89 if (device == R5C822_SDIOH_ID && vendor == VENDOR_RICOH)
92 /* JMicron Standard SDIO Host */
93 if (device == JMICRON_SDIOH_ID && vendor == VENDOR_JMICRON)
95 #endif /* BCMSDIOH_STD */
97 /* This is the PciSpiHost. */
98 if (device == SPIH_FPGA_ID && vendor == PCI_VENDOR_ID_BROADCOM) {
101 #endif /* BCMSDIOH_SPI */
106 /* forward declarations */
107 int brcmf_sdio_probe(struct device *dev);
108 EXPORT_SYMBOL(brcmf_sdio_probe);
110 int brcmf_sdio_remove(struct device *dev);
111 EXPORT_SYMBOL(brcmf_sdio_remove);
113 int brcmf_sdio_probe(struct device *dev)
115 struct bcmsdh_hc *sdhc = NULL;
116 unsigned long regs = 0;
117 struct brcmf_sdio *sdh = NULL;
120 unsigned long irq_flags = 0;
122 /* allocate SDIO Host Controller state info */
123 sdhc = kzalloc(sizeof(struct bcmsdh_hc), GFP_ATOMIC);
125 SDLX_MSG(("%s: out of memory\n", __func__));
128 sdhc->dev = (void *)dev;
130 sdh = brcmf_sdcard_attach((void *)0, (void **)®s, irq);
132 SDLX_MSG(("%s: bcmsdh_attach failed\n", __func__));
138 sdhc->oob_flags = irq_flags;
139 sdhc->oob_irq_registered = false; /* to make sure.. */
141 /* chain SDIO Host Controller info together */
142 sdhc->next = sdhcinfo;
144 /* Read the vendor/device ID from the CIS */
145 vendevid = brcmf_sdcard_query_device(sdh);
147 /* try to attach to the target device */
148 sdhc->ch = drvinfo.attach((vendevid >> 16), (vendevid & 0xFFFF),
149 0, 0, 0, 0, (void *)regs, sdh);
151 SDLX_MSG(("%s: device attach failed\n", __func__));
161 brcmf_sdcard_detach(sdhc->sdh);
168 int brcmf_sdio_remove(struct device *dev)
170 struct bcmsdh_hc *sdhc, *prev;
173 drvinfo.detach(sdhc->ch);
174 brcmf_sdcard_detach(sdhc->sdh);
175 /* find the SDIO Host Controller state for this pdev
176 and take it out from the list */
177 for (sdhc = sdhcinfo, prev = NULL; sdhc; sdhc = sdhc->next) {
178 if (sdhc->dev == (void *)dev) {
180 prev->next = sdhc->next;
188 SDLX_MSG(("%s: failed\n", __func__));
192 /* release SDIO Host Controller info */
197 extern int brcmf_sdio_function_init(void);
199 int brcmf_sdio_register(struct brcmf_sdioh_driver *driver)
203 SDLX_MSG(("Linux Kernel SDIO/MMC Driver\n"));
204 return brcmf_sdio_function_init();
207 extern void brcmf_sdio_function_cleanup(void);
209 void brcmf_sdio_unregister(void)
211 brcmf_sdio_function_cleanup();
214 /* Module parameters specific to each host-controller driver */
216 extern uint sd_msglevel; /* Debug message level */
217 module_param(sd_msglevel, uint, 0);
219 extern uint sd_f2_blocksize;
220 module_param(sd_f2_blocksize, int, 0);