Version:  2.0.40 2.2.26 2.4.37 2.6.39 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15

Linux/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c

  1 /*
  2  * Copyright (c) 2010 Broadcom Corporation
  3  *
  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.
  7  *
  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.
 15  */
 16 /* ****************** SDIO CARD Interface Functions **************************/
 17 
 18 #include <linux/types.h>
 19 #include <linux/netdevice.h>
 20 #include <linux/pci.h>
 21 #include <linux/pci_ids.h>
 22 #include <linux/sched.h>
 23 #include <linux/completion.h>
 24 #include <linux/scatterlist.h>
 25 #include <linux/mmc/sdio.h>
 26 #include <linux/mmc/core.h>
 27 #include <linux/mmc/sdio_func.h>
 28 #include <linux/mmc/sdio_ids.h>
 29 #include <linux/mmc/card.h>
 30 #include <linux/mmc/host.h>
 31 #include <linux/platform_device.h>
 32 #include <linux/platform_data/brcmfmac-sdio.h>
 33 #include <linux/suspend.h>
 34 #include <linux/errno.h>
 35 #include <linux/module.h>
 36 #include <net/cfg80211.h>
 37 
 38 #include <defs.h>
 39 #include <brcm_hw_ids.h>
 40 #include <brcmu_utils.h>
 41 #include <brcmu_wifi.h>
 42 #include <soc.h>
 43 #include "dhd_bus.h"
 44 #include "dhd_dbg.h"
 45 #include "sdio_host.h"
 46 
 47 #define SDIOH_API_ACCESS_RETRY_LIMIT    2
 48 
 49 #define DMA_ALIGN_MASK  0x03
 50 
 51 #define SDIO_FUNC1_BLOCKSIZE            64
 52 #define SDIO_FUNC2_BLOCKSIZE            512
 53 /* Maximum milliseconds to wait for F2 to come up */
 54 #define SDIO_WAIT_F2RDY 3000
 55 
 56 #define BRCMF_DEFAULT_TXGLOM_SIZE       32  /* max tx frames in glom chain */
 57 #define BRCMF_DEFAULT_RXGLOM_SIZE       32  /* max rx frames in glom chain */
 58 
 59 static int brcmf_sdiod_txglomsz = BRCMF_DEFAULT_TXGLOM_SIZE;
 60 module_param_named(txglomsz, brcmf_sdiod_txglomsz, int, 0);
 61 MODULE_PARM_DESC(txglomsz, "maximum tx packet chain size [SDIO]");
 62 
 63 static irqreturn_t brcmf_sdiod_oob_irqhandler(int irq, void *dev_id)
 64 {
 65         struct brcmf_bus *bus_if = dev_get_drvdata(dev_id);
 66         struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
 67 
 68         brcmf_dbg(INTR, "OOB intr triggered\n");
 69 
 70         /* out-of-band interrupt is level-triggered which won't
 71          * be cleared until dpc
 72          */
 73         if (sdiodev->irq_en) {
 74                 disable_irq_nosync(irq);
 75                 sdiodev->irq_en = false;
 76         }
 77 
 78         brcmf_sdio_isr(sdiodev->bus);
 79 
 80         return IRQ_HANDLED;
 81 }
 82 
 83 static void brcmf_sdiod_ib_irqhandler(struct sdio_func *func)
 84 {
 85         struct brcmf_bus *bus_if = dev_get_drvdata(&func->dev);
 86         struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
 87 
 88         brcmf_dbg(INTR, "IB intr triggered\n");
 89 
 90         brcmf_sdio_isr(sdiodev->bus);
 91 }
 92 
 93 /* dummy handler for SDIO function 2 interrupt */
 94 static void brcmf_sdiod_dummy_irqhandler(struct sdio_func *func)
 95 {
 96 }
 97 
 98 static bool brcmf_sdiod_pm_resume_error(struct brcmf_sdio_dev *sdiodev)
 99 {
100         bool is_err = false;
101 #ifdef CONFIG_PM_SLEEP
102         is_err = atomic_read(&sdiodev->suspend);
103 #endif
104         return is_err;
105 }
106 
107 static void brcmf_sdiod_pm_resume_wait(struct brcmf_sdio_dev *sdiodev,
108                                        wait_queue_head_t *wq)
109 {
110 #ifdef CONFIG_PM_SLEEP
111         int retry = 0;
112         while (atomic_read(&sdiodev->suspend) && retry++ != 30)
113                 wait_event_timeout(*wq, false, HZ/100);
114 #endif
115 }
116 
117 int brcmf_sdiod_intr_register(struct brcmf_sdio_dev *sdiodev)
118 {
119         int ret = 0;
120         u8 data;
121         unsigned long flags;
122 
123         if ((sdiodev->pdata) && (sdiodev->pdata->oob_irq_supported)) {
124                 brcmf_dbg(SDIO, "Enter, register OOB IRQ %d\n",
125                           sdiodev->pdata->oob_irq_nr);
126                 ret = request_irq(sdiodev->pdata->oob_irq_nr,
127                                   brcmf_sdiod_oob_irqhandler,
128                                   sdiodev->pdata->oob_irq_flags,
129                                   "brcmf_oob_intr",
130                                   &sdiodev->func[1]->dev);
131                 if (ret != 0) {
132                         brcmf_err("request_irq failed %d\n", ret);
133                         return ret;
134                 }
135                 sdiodev->oob_irq_requested = true;
136                 spin_lock_init(&sdiodev->irq_en_lock);
137                 spin_lock_irqsave(&sdiodev->irq_en_lock, flags);
138                 sdiodev->irq_en = true;
139                 spin_unlock_irqrestore(&sdiodev->irq_en_lock, flags);
140 
141                 ret = enable_irq_wake(sdiodev->pdata->oob_irq_nr);
142                 if (ret != 0) {
143                         brcmf_err("enable_irq_wake failed %d\n", ret);
144                         return ret;
145                 }
146                 sdiodev->irq_wake = true;
147 
148                 sdio_claim_host(sdiodev->func[1]);
149 
150                 /* must configure SDIO_CCCR_IENx to enable irq */
151                 data = brcmf_sdiod_regrb(sdiodev, SDIO_CCCR_IENx, &ret);
152                 data |= 1 << SDIO_FUNC_1 | 1 << SDIO_FUNC_2 | 1;
153                 brcmf_sdiod_regwb(sdiodev, SDIO_CCCR_IENx, data, &ret);
154 
155                 /* redirect, configure and enable io for interrupt signal */
156                 data = SDIO_SEPINT_MASK | SDIO_SEPINT_OE;
157                 if (sdiodev->pdata->oob_irq_flags & IRQF_TRIGGER_HIGH)
158                         data |= SDIO_SEPINT_ACT_HI;
159                 brcmf_sdiod_regwb(sdiodev, SDIO_CCCR_BRCM_SEPINT, data, &ret);
160 
161                 sdio_release_host(sdiodev->func[1]);
162         } else {
163                 brcmf_dbg(SDIO, "Entering\n");
164                 sdio_claim_host(sdiodev->func[1]);
165                 sdio_claim_irq(sdiodev->func[1], brcmf_sdiod_ib_irqhandler);
166                 sdio_claim_irq(sdiodev->func[2], brcmf_sdiod_dummy_irqhandler);
167                 sdio_release_host(sdiodev->func[1]);
168         }
169 
170         return 0;
171 }
172 
173 int brcmf_sdiod_intr_unregister(struct brcmf_sdio_dev *sdiodev)
174 {
175         brcmf_dbg(SDIO, "Entering\n");
176 
177         if ((sdiodev->pdata) && (sdiodev->pdata->oob_irq_supported)) {
178                 sdio_claim_host(sdiodev->func[1]);
179                 brcmf_sdiod_regwb(sdiodev, SDIO_CCCR_BRCM_SEPINT, 0, NULL);
180                 brcmf_sdiod_regwb(sdiodev, SDIO_CCCR_IENx, 0, NULL);
181                 sdio_release_host(sdiodev->func[1]);
182 
183                 if (sdiodev->oob_irq_requested) {
184                         sdiodev->oob_irq_requested = false;
185                         if (sdiodev->irq_wake) {
186                                 disable_irq_wake(sdiodev->pdata->oob_irq_nr);
187                                 sdiodev->irq_wake = false;
188                         }
189                         free_irq(sdiodev->pdata->oob_irq_nr,
190                                  &sdiodev->func[1]->dev);
191                         sdiodev->irq_en = false;
192                 }
193         } else {
194                 sdio_claim_host(sdiodev->func[1]);
195                 sdio_release_irq(sdiodev->func[2]);
196                 sdio_release_irq(sdiodev->func[1]);
197                 sdio_release_host(sdiodev->func[1]);
198         }
199 
200         return 0;
201 }
202 
203 static inline int brcmf_sdiod_f0_writeb(struct sdio_func *func,
204                                         uint regaddr, u8 byte)
205 {
206         int err_ret;
207 
208         /*
209          * Can only directly write to some F0 registers.
210          * Handle CCCR_IENx and CCCR_ABORT command
211          * as a special case.
212          */
213         if ((regaddr == SDIO_CCCR_ABORT) ||
214             (regaddr == SDIO_CCCR_IENx))
215                 sdio_writeb(func, byte, regaddr, &err_ret);
216         else
217                 sdio_f0_writeb(func, byte, regaddr, &err_ret);
218 
219         return err_ret;
220 }
221 
222 static int brcmf_sdiod_request_data(struct brcmf_sdio_dev *sdiodev, u8 fn,
223                                     u32 addr, u8 regsz, void *data, bool write)
224 {
225         struct sdio_func *func;
226         int ret;
227 
228         brcmf_dbg(SDIO, "rw=%d, func=%d, addr=0x%05x, nbytes=%d\n",
229                   write, fn, addr, regsz);
230 
231         brcmf_sdiod_pm_resume_wait(sdiodev, &sdiodev->request_word_wait);
232         if (brcmf_sdiod_pm_resume_error(sdiodev))
233                 return -EIO;
234 
235         /* only allow byte access on F0 */
236         if (WARN_ON(regsz > 1 && !fn))
237                 return -EINVAL;
238         func = sdiodev->func[fn];
239 
240         switch (regsz) {
241         case sizeof(u8):
242                 if (write) {
243                         if (fn)
244                                 sdio_writeb(func, *(u8 *)data, addr, &ret);
245                         else
246                                 ret = brcmf_sdiod_f0_writeb(func, addr,
247                                                             *(u8 *)data);
248                 } else {
249                         if (fn)
250                                 *(u8 *)data = sdio_readb(func, addr, &ret);
251                         else
252                                 *(u8 *)data = sdio_f0_readb(func, addr, &ret);
253                 }
254                 break;
255         case sizeof(u16):
256                 if (write)
257                         sdio_writew(func, *(u16 *)data, addr, &ret);
258                 else
259                         *(u16 *)data = sdio_readw(func, addr, &ret);
260                 break;
261         case sizeof(u32):
262                 if (write)
263                         sdio_writel(func, *(u32 *)data, addr, &ret);
264                 else
265                         *(u32 *)data = sdio_readl(func, addr, &ret);
266                 break;
267         default:
268                 brcmf_err("invalid size: %d\n", regsz);
269                 break;
270         }
271 
272         if (ret)
273                 brcmf_dbg(SDIO, "failed to %s data F%d@0x%05x, err: %d\n",
274                           write ? "write" : "read", fn, addr, ret);
275 
276         return ret;
277 }
278 
279 static int brcmf_sdiod_regrw_helper(struct brcmf_sdio_dev *sdiodev, u32 addr,
280                                    u8 regsz, void *data, bool write)
281 {
282         u8 func;
283         s32 retry = 0;
284         int ret;
285 
286         if (sdiodev->bus_if->state == BRCMF_BUS_NOMEDIUM)
287                 return -ENOMEDIUM;
288 
289         /*
290          * figure out how to read the register based on address range
291          * 0x00 ~ 0x7FF: function 0 CCCR and FBR
292          * 0x10000 ~ 0x1FFFF: function 1 miscellaneous registers
293          * The rest: function 1 silicon backplane core registers
294          */
295         if ((addr & ~REG_F0_REG_MASK) == 0)
296                 func = SDIO_FUNC_0;
297         else
298                 func = SDIO_FUNC_1;
299 
300         do {
301                 if (!write)
302                         memset(data, 0, regsz);
303                 /* for retry wait for 1 ms till bus get settled down */
304                 if (retry)
305                         usleep_range(1000, 2000);
306                 ret = brcmf_sdiod_request_data(sdiodev, func, addr, regsz,
307                                                data, write);
308         } while (ret != 0 && ret != -ENOMEDIUM &&
309                  retry++ < SDIOH_API_ACCESS_RETRY_LIMIT);
310 
311         if (ret == -ENOMEDIUM)
312                 brcmf_bus_change_state(sdiodev->bus_if, BRCMF_BUS_NOMEDIUM);
313         else if (ret != 0) {
314                 /*
315                  * SleepCSR register access can fail when
316                  * waking up the device so reduce this noise
317                  * in the logs.
318                  */
319                 if (addr != SBSDIO_FUNC1_SLEEPCSR)
320                         brcmf_err("failed to %s data F%d@0x%05x, err: %d\n",
321                                   write ? "write" : "read", func, addr, ret);
322                 else
323                         brcmf_dbg(SDIO, "failed to %s data F%d@0x%05x, err: %d\n",
324                                   write ? "write" : "read", func, addr, ret);
325         }
326         return ret;
327 }
328 
329 static int
330 brcmf_sdiod_set_sbaddr_window(struct brcmf_sdio_dev *sdiodev, u32 address)
331 {
332         int err = 0, i;
333         u8 addr[3];
334 
335         if (sdiodev->bus_if->state == BRCMF_BUS_NOMEDIUM)
336                 return -ENOMEDIUM;
337 
338         addr[0] = (address >> 8) & SBSDIO_SBADDRLOW_MASK;
339         addr[1] = (address >> 16) & SBSDIO_SBADDRMID_MASK;
340         addr[2] = (address >> 24) & SBSDIO_SBADDRHIGH_MASK;
341 
342         for (i = 0; i < 3; i++) {
343                 err = brcmf_sdiod_regrw_helper(sdiodev,
344                                                SBSDIO_FUNC1_SBADDRLOW + i,
345                                                sizeof(u8), &addr[i], true);
346                 if (err) {
347                         brcmf_err("failed at addr: 0x%0x\n",
348                                   SBSDIO_FUNC1_SBADDRLOW + i);
349                         break;
350                 }
351         }
352 
353         return err;
354 }
355 
356 static int
357 brcmf_sdiod_addrprep(struct brcmf_sdio_dev *sdiodev, uint width, u32 *addr)
358 {
359         uint bar0 = *addr & ~SBSDIO_SB_OFT_ADDR_MASK;
360         int err = 0;
361 
362         if (bar0 != sdiodev->sbwad) {
363                 err = brcmf_sdiod_set_sbaddr_window(sdiodev, bar0);
364                 if (err)
365                         return err;
366 
367                 sdiodev->sbwad = bar0;
368         }
369 
370         *addr &= SBSDIO_SB_OFT_ADDR_MASK;
371 
372         if (width == 4)
373                 *addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
374 
375         return 0;
376 }
377 
378 u8 brcmf_sdiod_regrb(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
379 {
380         u8 data;
381         int retval;
382 
383         brcmf_dbg(SDIO, "addr:0x%08x\n", addr);
384         retval = brcmf_sdiod_regrw_helper(sdiodev, addr, sizeof(data), &data,
385                                           false);
386         brcmf_dbg(SDIO, "data:0x%02x\n", data);
387 
388         if (ret)
389                 *ret = retval;
390 
391         return data;
392 }
393 
394 u32 brcmf_sdiod_regrl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
395 {
396         u32 data;
397         int retval;
398 
399         brcmf_dbg(SDIO, "addr:0x%08x\n", addr);
400         retval = brcmf_sdiod_addrprep(sdiodev, sizeof(data), &addr);
401         if (retval)
402                 goto done;
403         retval = brcmf_sdiod_regrw_helper(sdiodev, addr, sizeof(data), &data,
404                                           false);
405         brcmf_dbg(SDIO, "data:0x%08x\n", data);
406 
407 done:
408         if (ret)
409                 *ret = retval;
410 
411         return data;
412 }
413 
414 void brcmf_sdiod_regwb(struct brcmf_sdio_dev *sdiodev, u32 addr,
415                       u8 data, int *ret)
416 {
417         int retval;
418 
419         brcmf_dbg(SDIO, "addr:0x%08x, data:0x%02x\n", addr, data);
420         retval = brcmf_sdiod_regrw_helper(sdiodev, addr, sizeof(data), &data,
421                                           true);
422         if (ret)
423                 *ret = retval;
424 }
425 
426 void brcmf_sdiod_regwl(struct brcmf_sdio_dev *sdiodev, u32 addr,
427                       u32 data, int *ret)
428 {
429         int retval;
430 
431         brcmf_dbg(SDIO, "addr:0x%08x, data:0x%08x\n", addr, data);
432         retval = brcmf_sdiod_addrprep(sdiodev, sizeof(data), &addr);
433         if (retval)
434                 goto done;
435         retval = brcmf_sdiod_regrw_helper(sdiodev, addr, sizeof(data), &data,
436                                           true);
437 
438 done:
439         if (ret)
440                 *ret = retval;
441 }
442 
443 static int brcmf_sdiod_buffrw(struct brcmf_sdio_dev *sdiodev, uint fn,
444                              bool write, u32 addr, struct sk_buff *pkt)
445 {
446         unsigned int req_sz;
447         int err;
448 
449         brcmf_sdiod_pm_resume_wait(sdiodev, &sdiodev->request_buffer_wait);
450         if (brcmf_sdiod_pm_resume_error(sdiodev))
451                 return -EIO;
452 
453         /* Single skb use the standard mmc interface */
454         req_sz = pkt->len + 3;
455         req_sz &= (uint)~3;
456 
457         if (write)
458                 err = sdio_memcpy_toio(sdiodev->func[fn], addr,
459                                        ((u8 *)(pkt->data)), req_sz);
460         else if (fn == 1)
461                 err = sdio_memcpy_fromio(sdiodev->func[fn], ((u8 *)(pkt->data)),
462                                          addr, req_sz);
463         else
464                 /* function 2 read is FIFO operation */
465                 err = sdio_readsb(sdiodev->func[fn], ((u8 *)(pkt->data)), addr,
466                                   req_sz);
467         if (err == -ENOMEDIUM)
468                 brcmf_bus_change_state(sdiodev->bus_if, BRCMF_BUS_NOMEDIUM);
469         return err;
470 }
471 
472 /**
473  * brcmf_sdiod_sglist_rw - SDIO interface function for block data access
474  * @sdiodev: brcmfmac sdio device
475  * @fn: SDIO function number
476  * @write: direction flag
477  * @addr: dongle memory address as source/destination
478  * @pkt: skb pointer
479  *
480  * This function takes the respbonsibility as the interface function to MMC
481  * stack for block data access. It assumes that the skb passed down by the
482  * caller has already been padded and aligned.
483  */
484 static int brcmf_sdiod_sglist_rw(struct brcmf_sdio_dev *sdiodev, uint fn,
485                                  bool write, u32 addr,
486                                  struct sk_buff_head *pktlist)
487 {
488         unsigned int req_sz, func_blk_sz, sg_cnt, sg_data_sz, pkt_offset;
489         unsigned int max_req_sz, orig_offset, dst_offset;
490         unsigned short max_seg_cnt, seg_sz;
491         unsigned char *pkt_data, *orig_data, *dst_data;
492         struct sk_buff *pkt_next = NULL, *local_pkt_next;
493         struct sk_buff_head local_list, *target_list;
494         struct mmc_request mmc_req;
495         struct mmc_command mmc_cmd;
496         struct mmc_data mmc_dat;
497         struct scatterlist *sgl;
498         int ret = 0;
499 
500         if (!pktlist->qlen)
501                 return -EINVAL;
502 
503         brcmf_sdiod_pm_resume_wait(sdiodev, &sdiodev->request_buffer_wait);
504         if (brcmf_sdiod_pm_resume_error(sdiodev))
505                 return -EIO;
506 
507         target_list = pktlist;
508         /* for host with broken sg support, prepare a page aligned list */
509         __skb_queue_head_init(&local_list);
510         if (sdiodev->pdata && sdiodev->pdata->broken_sg_support && !write) {
511                 req_sz = 0;
512                 skb_queue_walk(pktlist, pkt_next)
513                         req_sz += pkt_next->len;
514                 req_sz = ALIGN(req_sz, sdiodev->func[fn]->cur_blksize);
515                 while (req_sz > PAGE_SIZE) {
516                         pkt_next = brcmu_pkt_buf_get_skb(PAGE_SIZE);
517                         if (pkt_next == NULL) {
518                                 ret = -ENOMEM;
519                                 goto exit;
520                         }
521                         __skb_queue_tail(&local_list, pkt_next);
522                         req_sz -= PAGE_SIZE;
523                 }
524                 pkt_next = brcmu_pkt_buf_get_skb(req_sz);
525                 if (pkt_next == NULL) {
526                         ret = -ENOMEM;
527                         goto exit;
528                 }
529                 __skb_queue_tail(&local_list, pkt_next);
530                 target_list = &local_list;
531         }
532 
533         func_blk_sz = sdiodev->func[fn]->cur_blksize;
534         max_req_sz = sdiodev->max_request_size;
535         max_seg_cnt = min_t(unsigned short, sdiodev->max_segment_count,
536                             target_list->qlen);
537         seg_sz = target_list->qlen;
538         pkt_offset = 0;
539         pkt_next = target_list->next;
540 
541         memset(&mmc_req, 0, sizeof(struct mmc_request));
542         memset(&mmc_cmd, 0, sizeof(struct mmc_command));
543         memset(&mmc_dat, 0, sizeof(struct mmc_data));
544 
545         mmc_dat.sg = sdiodev->sgtable.sgl;
546         mmc_dat.blksz = func_blk_sz;
547         mmc_dat.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
548         mmc_cmd.opcode = SD_IO_RW_EXTENDED;
549         mmc_cmd.arg = write ? 1<<31 : 0;        /* write flag  */
550         mmc_cmd.arg |= (fn & 0x7) << 28;        /* SDIO func num */
551         mmc_cmd.arg |= 1<<27;                   /* block mode */
552         /* for function 1 the addr will be incremented */
553         mmc_cmd.arg |= (fn == 1) ? 1<<26 : 0;
554         mmc_cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC;
555         mmc_req.cmd = &mmc_cmd;
556         mmc_req.data = &mmc_dat;
557 
558         while (seg_sz) {
559                 req_sz = 0;
560                 sg_cnt = 0;
561                 sgl = sdiodev->sgtable.sgl;
562                 /* prep sg table */
563                 while (pkt_next != (struct sk_buff *)target_list) {
564                         pkt_data = pkt_next->data + pkt_offset;
565                         sg_data_sz = pkt_next->len - pkt_offset;
566                         if (sg_data_sz > sdiodev->max_segment_size)
567                                 sg_data_sz = sdiodev->max_segment_size;
568                         if (sg_data_sz > max_req_sz - req_sz)
569                                 sg_data_sz = max_req_sz - req_sz;
570 
571                         sg_set_buf(sgl, pkt_data, sg_data_sz);
572 
573                         sg_cnt++;
574                         sgl = sg_next(sgl);
575                         req_sz += sg_data_sz;
576                         pkt_offset += sg_data_sz;
577                         if (pkt_offset == pkt_next->len) {
578                                 pkt_offset = 0;
579                                 pkt_next = pkt_next->next;
580                         }
581 
582                         if (req_sz >= max_req_sz || sg_cnt >= max_seg_cnt)
583                                 break;
584                 }
585                 seg_sz -= sg_cnt;
586 
587                 if (req_sz % func_blk_sz != 0) {
588                         brcmf_err("sg request length %u is not %u aligned\n",
589                                   req_sz, func_blk_sz);
590                         ret = -ENOTBLK;
591                         goto exit;
592                 }
593 
594                 mmc_dat.sg_len = sg_cnt;
595                 mmc_dat.blocks = req_sz / func_blk_sz;
596                 mmc_cmd.arg |= (addr & 0x1FFFF) << 9;   /* address */
597                 mmc_cmd.arg |= mmc_dat.blocks & 0x1FF;  /* block count */
598                 /* incrementing addr for function 1 */
599                 if (fn == 1)
600                         addr += req_sz;
601 
602                 mmc_set_data_timeout(&mmc_dat, sdiodev->func[fn]->card);
603                 mmc_wait_for_req(sdiodev->func[fn]->card->host, &mmc_req);
604 
605                 ret = mmc_cmd.error ? mmc_cmd.error : mmc_dat.error;
606                 if (ret == -ENOMEDIUM) {
607                         brcmf_bus_change_state(sdiodev->bus_if,
608                                                BRCMF_BUS_NOMEDIUM);
609                         break;
610                 } else if (ret != 0) {
611                         brcmf_err("CMD53 sg block %s failed %d\n",
612                                   write ? "write" : "read", ret);
613                         ret = -EIO;
614                         break;
615                 }
616         }
617 
618         if (sdiodev->pdata && sdiodev->pdata->broken_sg_support && !write) {
619                 local_pkt_next = local_list.next;
620                 orig_offset = 0;
621                 skb_queue_walk(pktlist, pkt_next) {
622                         dst_offset = 0;
623                         do {
624                                 req_sz = local_pkt_next->len - orig_offset;
625                                 req_sz = min_t(uint, pkt_next->len - dst_offset,
626                                                req_sz);
627                                 orig_data = local_pkt_next->data + orig_offset;
628                                 dst_data = pkt_next->data + dst_offset;
629                                 memcpy(dst_data, orig_data, req_sz);
630                                 orig_offset += req_sz;
631                                 dst_offset += req_sz;
632                                 if (orig_offset == local_pkt_next->len) {
633                                         orig_offset = 0;
634                                         local_pkt_next = local_pkt_next->next;
635                                 }
636                                 if (dst_offset == pkt_next->len)
637                                         break;
638                         } while (!skb_queue_empty(&local_list));
639                 }
640         }
641 
642 exit:
643         sg_init_table(sdiodev->sgtable.sgl, sdiodev->sgtable.orig_nents);
644         while ((pkt_next = __skb_dequeue(&local_list)) != NULL)
645                 brcmu_pkt_buf_free_skb(pkt_next);
646 
647         return ret;
648 }
649 
650 int brcmf_sdiod_recv_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)
651 {
652         struct sk_buff *mypkt;
653         int err;
654 
655         mypkt = brcmu_pkt_buf_get_skb(nbytes);
656         if (!mypkt) {
657                 brcmf_err("brcmu_pkt_buf_get_skb failed: len %d\n",
658                           nbytes);
659                 return -EIO;
660         }
661 
662         err = brcmf_sdiod_recv_pkt(sdiodev, mypkt);
663         if (!err)
664                 memcpy(buf, mypkt->data, nbytes);
665 
666         brcmu_pkt_buf_free_skb(mypkt);
667         return err;
668 }
669 
670 int brcmf_sdiod_recv_pkt(struct brcmf_sdio_dev *sdiodev, struct sk_buff *pkt)
671 {
672         u32 addr = sdiodev->sbwad;
673         int err = 0;
674 
675         brcmf_dbg(SDIO, "addr = 0x%x, size = %d\n", addr, pkt->len);
676 
677         err = brcmf_sdiod_addrprep(sdiodev, 4, &addr);
678         if (err)
679                 goto done;
680 
681         err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_2, false, addr, pkt);
682 
683 done:
684         return err;
685 }
686 
687 int brcmf_sdiod_recv_chain(struct brcmf_sdio_dev *sdiodev,
688                            struct sk_buff_head *pktq, uint totlen)
689 {
690         struct sk_buff *glom_skb;
691         struct sk_buff *skb;
692         u32 addr = sdiodev->sbwad;
693         int err = 0;
694 
695         brcmf_dbg(SDIO, "addr = 0x%x, size = %d\n",
696                   addr, pktq->qlen);
697 
698         err = brcmf_sdiod_addrprep(sdiodev, 4, &addr);
699         if (err)
700                 goto done;
701 
702         if (pktq->qlen == 1)
703                 err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_2, false, addr,
704                                          pktq->next);
705         else if (!sdiodev->sg_support) {
706                 glom_skb = brcmu_pkt_buf_get_skb(totlen);
707                 if (!glom_skb)
708                         return -ENOMEM;
709                 err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_2, false, addr,
710                                          glom_skb);
711                 if (err)
712                         goto done;
713 
714                 skb_queue_walk(pktq, skb) {
715                         memcpy(skb->data, glom_skb->data, skb->len);
716                         skb_pull(glom_skb, skb->len);
717                 }
718         } else
719                 err = brcmf_sdiod_sglist_rw(sdiodev, SDIO_FUNC_2, false, addr,
720                                             pktq);
721 
722 done:
723         return err;
724 }
725 
726 int brcmf_sdiod_send_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)
727 {
728         struct sk_buff *mypkt;
729         u32 addr = sdiodev->sbwad;
730         int err;
731 
732         mypkt = brcmu_pkt_buf_get_skb(nbytes);
733         if (!mypkt) {
734                 brcmf_err("brcmu_pkt_buf_get_skb failed: len %d\n",
735                           nbytes);
736                 return -EIO;
737         }
738 
739         memcpy(mypkt->data, buf, nbytes);
740 
741         err = brcmf_sdiod_addrprep(sdiodev, 4, &addr);
742 
743         if (!err)
744                 err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_2, true, addr,
745                                          mypkt);
746 
747         brcmu_pkt_buf_free_skb(mypkt);
748         return err;
749 
750 }
751 
752 int brcmf_sdiod_send_pkt(struct brcmf_sdio_dev *sdiodev,
753                          struct sk_buff_head *pktq)
754 {
755         struct sk_buff *skb;
756         u32 addr = sdiodev->sbwad;
757         int err;
758 
759         brcmf_dbg(SDIO, "addr = 0x%x, size = %d\n", addr, pktq->qlen);
760 
761         err = brcmf_sdiod_addrprep(sdiodev, 4, &addr);
762         if (err)
763                 return err;
764 
765         if (pktq->qlen == 1 || !sdiodev->sg_support)
766                 skb_queue_walk(pktq, skb) {
767                         err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_2, true,
768                                                  addr, skb);
769                         if (err)
770                                 break;
771                 }
772         else
773                 err = brcmf_sdiod_sglist_rw(sdiodev, SDIO_FUNC_2, true, addr,
774                                             pktq);
775 
776         return err;
777 }
778 
779 int
780 brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,
781                   u8 *data, uint size)
782 {
783         int bcmerror = 0;
784         struct sk_buff *pkt;
785         u32 sdaddr;
786         uint dsize;
787 
788         dsize = min_t(uint, SBSDIO_SB_OFT_ADDR_LIMIT, size);
789         pkt = dev_alloc_skb(dsize);
790         if (!pkt) {
791                 brcmf_err("dev_alloc_skb failed: len %d\n", dsize);
792                 return -EIO;
793         }
794         pkt->priority = 0;
795 
796         /* Determine initial transfer parameters */
797         sdaddr = address & SBSDIO_SB_OFT_ADDR_MASK;
798         if ((sdaddr + size) & SBSDIO_SBWINDOW_MASK)
799                 dsize = (SBSDIO_SB_OFT_ADDR_LIMIT - sdaddr);
800         else
801                 dsize = size;
802 
803         sdio_claim_host(sdiodev->func[1]);
804 
805         /* Do the transfer(s) */
806         while (size) {
807                 /* Set the backplane window to include the start address */
808                 bcmerror = brcmf_sdiod_set_sbaddr_window(sdiodev, address);
809                 if (bcmerror)
810                         break;
811 
812                 brcmf_dbg(SDIO, "%s %d bytes at offset 0x%08x in window 0x%08x\n",
813                           write ? "write" : "read", dsize,
814                           sdaddr, address & SBSDIO_SBWINDOW_MASK);
815 
816                 sdaddr &= SBSDIO_SB_OFT_ADDR_MASK;
817                 sdaddr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
818 
819                 skb_put(pkt, dsize);
820                 if (write)
821                         memcpy(pkt->data, data, dsize);
822                 bcmerror = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_1, write,
823                                               sdaddr, pkt);
824                 if (bcmerror) {
825                         brcmf_err("membytes transfer failed\n");
826                         break;
827                 }
828                 if (!write)
829                         memcpy(data, pkt->data, dsize);
830                 skb_trim(pkt, 0);
831 
832                 /* Adjust for next transfer (if any) */
833                 size -= dsize;
834                 if (size) {
835                         data += dsize;
836                         address += dsize;
837                         sdaddr = 0;
838                         dsize = min_t(uint, SBSDIO_SB_OFT_ADDR_LIMIT, size);
839                 }
840         }
841 
842         dev_kfree_skb(pkt);
843 
844         /* Return the window to backplane enumeration space for core access */
845         if (brcmf_sdiod_set_sbaddr_window(sdiodev, sdiodev->sbwad))
846                 brcmf_err("FAILED to set window back to 0x%x\n",
847                           sdiodev->sbwad);
848 
849         sdio_release_host(sdiodev->func[1]);
850 
851         return bcmerror;
852 }
853 
854 int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, uint fn)
855 {
856         char t_func = (char)fn;
857         brcmf_dbg(SDIO, "Enter\n");
858 
859         /* issue abort cmd52 command through F0 */
860         brcmf_sdiod_request_data(sdiodev, SDIO_FUNC_0, SDIO_CCCR_ABORT,
861                                  sizeof(t_func), &t_func, true);
862 
863         brcmf_dbg(SDIO, "Exit\n");
864         return 0;
865 }
866 
867 static void brcmf_sdiod_sgtable_alloc(struct brcmf_sdio_dev *sdiodev)
868 {
869         uint nents;
870         int err;
871 
872         if (!sdiodev->sg_support)
873                 return;
874 
875         nents = max_t(uint, BRCMF_DEFAULT_RXGLOM_SIZE, brcmf_sdiod_txglomsz);
876         nents += (nents >> 4) + 1;
877 
878         WARN_ON(nents > sdiodev->max_segment_count);
879 
880         brcmf_dbg(TRACE, "nents=%d\n", nents);
881         err = sg_alloc_table(&sdiodev->sgtable, nents, GFP_KERNEL);
882         if (err < 0) {
883                 brcmf_err("allocation failed: disable scatter-gather");
884                 sdiodev->sg_support = false;
885         }
886 
887         sdiodev->txglomsz = brcmf_sdiod_txglomsz;
888 }
889 
890 static int brcmf_sdiod_remove(struct brcmf_sdio_dev *sdiodev)
891 {
892         if (sdiodev->bus) {
893                 brcmf_sdio_remove(sdiodev->bus);
894                 sdiodev->bus = NULL;
895         }
896 
897         /* Disable Function 2 */
898         sdio_claim_host(sdiodev->func[2]);
899         sdio_disable_func(sdiodev->func[2]);
900         sdio_release_host(sdiodev->func[2]);
901 
902         /* Disable Function 1 */
903         sdio_claim_host(sdiodev->func[1]);
904         sdio_disable_func(sdiodev->func[1]);
905         sdio_release_host(sdiodev->func[1]);
906 
907         sg_free_table(&sdiodev->sgtable);
908         sdiodev->sbwad = 0;
909 
910         return 0;
911 }
912 
913 static int brcmf_sdiod_probe(struct brcmf_sdio_dev *sdiodev)
914 {
915         struct sdio_func *func;
916         struct mmc_host *host;
917         uint max_blocks;
918         int ret = 0;
919 
920         sdiodev->num_funcs = 2;
921 
922         sdio_claim_host(sdiodev->func[1]);
923 
924         ret = sdio_set_block_size(sdiodev->func[1], SDIO_FUNC1_BLOCKSIZE);
925         if (ret) {
926                 brcmf_err("Failed to set F1 blocksize\n");
927                 sdio_release_host(sdiodev->func[1]);
928                 goto out;
929         }
930         ret = sdio_set_block_size(sdiodev->func[2], SDIO_FUNC2_BLOCKSIZE);
931         if (ret) {
932                 brcmf_err("Failed to set F2 blocksize\n");
933                 sdio_release_host(sdiodev->func[1]);
934                 goto out;
935         }
936 
937         /* increase F2 timeout */
938         sdiodev->func[2]->enable_timeout = SDIO_WAIT_F2RDY;
939 
940         /* Enable Function 1 */
941         ret = sdio_enable_func(sdiodev->func[1]);
942         sdio_release_host(sdiodev->func[1]);
943         if (ret) {
944                 brcmf_err("Failed to enable F1: err=%d\n", ret);
945                 goto out;
946         }
947 
948         /*
949          * determine host related variables after brcmf_sdiod_probe()
950          * as func->cur_blksize is properly set and F2 init has been
951          * completed successfully.
952          */
953         func = sdiodev->func[2];
954         host = func->card->host;
955         sdiodev->sg_support = host->max_segs > 1;
956         max_blocks = min_t(uint, host->max_blk_count, 511u);
957         sdiodev->max_request_size = min_t(uint, host->max_req_size,
958                                           max_blocks * func->cur_blksize);
959         sdiodev->max_segment_count = min_t(uint, host->max_segs,
960                                            SG_MAX_SINGLE_ALLOC);
961         sdiodev->max_segment_size = host->max_seg_size;
962 
963         /* allocate scatter-gather table. sg support
964          * will be disabled upon allocation failure.
965          */
966         brcmf_sdiod_sgtable_alloc(sdiodev);
967 
968         /* try to attach to the target device */
969         sdiodev->bus = brcmf_sdio_probe(sdiodev);
970         if (!sdiodev->bus) {
971                 ret = -ENODEV;
972                 goto out;
973         }
974 
975 out:
976         if (ret)
977                 brcmf_sdiod_remove(sdiodev);
978 
979         return ret;
980 }
981 
982 /* devices we support, null terminated */
983 static const struct sdio_device_id brcmf_sdmmc_ids[] = {
984         {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_43143)},
985         {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_43241)},
986         {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4329)},
987         {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4330)},
988         {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4334)},
989         {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_43362)},
990         {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM,
991                      SDIO_DEVICE_ID_BROADCOM_4335_4339)},
992         {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4354)},
993         { /* end: all zeroes */ },
994 };
995 MODULE_DEVICE_TABLE(sdio, brcmf_sdmmc_ids);
996 
997 static struct brcmfmac_sdio_platform_data *brcmfmac_sdio_pdata;
998 
999 
1000 static int brcmf_ops_sdio_probe(struct sdio_func *func,
1001                                 const struct sdio_device_id *id)
1002 {
1003         int err;
1004         struct brcmf_sdio_dev *sdiodev;
1005         struct brcmf_bus *bus_if;
1006 
1007         brcmf_dbg(SDIO, "Enter\n");
1008         brcmf_dbg(SDIO, "Class=%x\n", func->class);
1009         brcmf_dbg(SDIO, "sdio vendor ID: 0x%04x\n", func->vendor);
1010         brcmf_dbg(SDIO, "sdio device ID: 0x%04x\n", func->device);
1011         brcmf_dbg(SDIO, "Function#: %d\n", func->num);
1012 
1013         /* Consume func num 1 but dont do anything with it. */
1014         if (func->num == 1)
1015                 return 0;
1016 
1017         /* Ignore anything but func 2 */
1018         if (func->num != 2)
1019                 return -ENODEV;
1020 
1021         bus_if = kzalloc(sizeof(struct brcmf_bus), GFP_KERNEL);
1022         if (!bus_if)
1023                 return -ENOMEM;
1024         sdiodev = kzalloc(sizeof(struct brcmf_sdio_dev), GFP_KERNEL);
1025         if (!sdiodev) {
1026                 kfree(bus_if);
1027                 return -ENOMEM;
1028         }
1029 
1030         /* store refs to functions used. mmc_card does
1031          * not hold the F0 function pointer.
1032          */
1033         sdiodev->func[0] = kmemdup(func, sizeof(*func), GFP_KERNEL);
1034         sdiodev->func[0]->num = 0;
1035         sdiodev->func[1] = func->card->sdio_func[0];
1036         sdiodev->func[2] = func;
1037 
1038         sdiodev->bus_if = bus_if;
1039         bus_if->bus_priv.sdio = sdiodev;
1040         bus_if->proto_type = BRCMF_PROTO_BCDC;
1041         dev_set_drvdata(&func->dev, bus_if);
1042         dev_set_drvdata(&sdiodev->func[1]->dev, bus_if);
1043         sdiodev->dev = &sdiodev->func[1]->dev;
1044         sdiodev->pdata = brcmfmac_sdio_pdata;
1045 
1046         atomic_set(&sdiodev->suspend, false);
1047         init_waitqueue_head(&sdiodev->request_word_wait);
1048         init_waitqueue_head(&sdiodev->request_buffer_wait);
1049 
1050         brcmf_dbg(SDIO, "F2 found, calling brcmf_sdiod_probe...\n");
1051         err = brcmf_sdiod_probe(sdiodev);
1052         if (err) {
1053                 brcmf_err("F2 error, probe failed %d...\n", err);
1054                 goto fail;
1055         }
1056 
1057         brcmf_dbg(SDIO, "F2 init completed...\n");
1058         return 0;
1059 
1060 fail:
1061         dev_set_drvdata(&func->dev, NULL);
1062         dev_set_drvdata(&sdiodev->func[1]->dev, NULL);
1063         kfree(sdiodev->func[0]);
1064         kfree(sdiodev);
1065         kfree(bus_if);
1066         return err;
1067 }
1068 
1069 static void brcmf_ops_sdio_remove(struct sdio_func *func)
1070 {
1071         struct brcmf_bus *bus_if;
1072         struct brcmf_sdio_dev *sdiodev;
1073 
1074         brcmf_dbg(SDIO, "Enter\n");
1075         brcmf_dbg(SDIO, "sdio vendor ID: 0x%04x\n", func->vendor);
1076         brcmf_dbg(SDIO, "sdio device ID: 0x%04x\n", func->device);
1077         brcmf_dbg(SDIO, "Function: %d\n", func->num);
1078 
1079         if (func->num != 1 && func->num != 2)
1080                 return;
1081 
1082         bus_if = dev_get_drvdata(&func->dev);
1083         if (bus_if) {
1084                 sdiodev = bus_if->bus_priv.sdio;
1085                 brcmf_sdiod_remove(sdiodev);
1086 
1087                 dev_set_drvdata(&sdiodev->func[1]->dev, NULL);
1088                 dev_set_drvdata(&sdiodev->func[2]->dev, NULL);
1089 
1090                 kfree(bus_if);
1091                 kfree(sdiodev->func[0]);
1092                 kfree(sdiodev);
1093         }
1094 
1095         brcmf_dbg(SDIO, "Exit\n");
1096 }
1097 
1098 #ifdef CONFIG_PM_SLEEP
1099 static int brcmf_ops_sdio_suspend(struct device *dev)
1100 {
1101         mmc_pm_flag_t sdio_flags;
1102         struct brcmf_bus *bus_if = dev_get_drvdata(dev);
1103         struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
1104         int ret = 0;
1105 
1106         brcmf_dbg(SDIO, "Enter\n");
1107 
1108         sdio_flags = sdio_get_host_pm_caps(sdiodev->func[1]);
1109         if (!(sdio_flags & MMC_PM_KEEP_POWER)) {
1110                 brcmf_err("Host can't keep power while suspended\n");
1111                 return -EINVAL;
1112         }
1113 
1114         atomic_set(&sdiodev->suspend, true);
1115 
1116         ret = sdio_set_host_pm_flags(sdiodev->func[1], MMC_PM_KEEP_POWER);
1117         if (ret) {
1118                 brcmf_err("Failed to set pm_flags\n");
1119                 atomic_set(&sdiodev->suspend, false);
1120                 return ret;
1121         }
1122 
1123         brcmf_sdio_wd_timer(sdiodev->bus, 0);
1124 
1125         return ret;
1126 }
1127 
1128 static int brcmf_ops_sdio_resume(struct device *dev)
1129 {
1130         struct brcmf_bus *bus_if = dev_get_drvdata(dev);
1131         struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
1132 
1133         brcmf_dbg(SDIO, "Enter\n");
1134         brcmf_sdio_wd_timer(sdiodev->bus, BRCMF_WD_POLL_MS);
1135         atomic_set(&sdiodev->suspend, false);
1136         return 0;
1137 }
1138 
1139 static const struct dev_pm_ops brcmf_sdio_pm_ops = {
1140         .suspend        = brcmf_ops_sdio_suspend,
1141         .resume         = brcmf_ops_sdio_resume,
1142 };
1143 #endif  /* CONFIG_PM_SLEEP */
1144 
1145 static struct sdio_driver brcmf_sdmmc_driver = {
1146         .probe = brcmf_ops_sdio_probe,
1147         .remove = brcmf_ops_sdio_remove,
1148         .name = BRCMFMAC_SDIO_PDATA_NAME,
1149         .id_table = brcmf_sdmmc_ids,
1150         .drv = {
1151                 .owner = THIS_MODULE,
1152 #ifdef CONFIG_PM_SLEEP
1153                 .pm = &brcmf_sdio_pm_ops,
1154 #endif  /* CONFIG_PM_SLEEP */
1155         },
1156 };
1157 
1158 static int __init brcmf_sdio_pd_probe(struct platform_device *pdev)
1159 {
1160         brcmf_dbg(SDIO, "Enter\n");
1161 
1162         brcmfmac_sdio_pdata = dev_get_platdata(&pdev->dev);
1163 
1164         if (brcmfmac_sdio_pdata->power_on)
1165                 brcmfmac_sdio_pdata->power_on();
1166 
1167         return 0;
1168 }
1169 
1170 static int brcmf_sdio_pd_remove(struct platform_device *pdev)
1171 {
1172         brcmf_dbg(SDIO, "Enter\n");
1173 
1174         if (brcmfmac_sdio_pdata->power_off)
1175                 brcmfmac_sdio_pdata->power_off();
1176 
1177         sdio_unregister_driver(&brcmf_sdmmc_driver);
1178 
1179         return 0;
1180 }
1181 
1182 static struct platform_driver brcmf_sdio_pd = {
1183         .remove         = brcmf_sdio_pd_remove,
1184         .driver         = {
1185                 .name   = BRCMFMAC_SDIO_PDATA_NAME,
1186                 .owner  = THIS_MODULE,
1187         }
1188 };
1189 
1190 void brcmf_sdio_register(void)
1191 {
1192         int ret;
1193 
1194         ret = sdio_register_driver(&brcmf_sdmmc_driver);
1195         if (ret)
1196                 brcmf_err("sdio_register_driver failed: %d\n", ret);
1197 }
1198 
1199 void brcmf_sdio_exit(void)
1200 {
1201         brcmf_dbg(SDIO, "Enter\n");
1202 
1203         if (brcmfmac_sdio_pdata)
1204                 platform_driver_unregister(&brcmf_sdio_pd);
1205         else
1206                 sdio_unregister_driver(&brcmf_sdmmc_driver);
1207 }
1208 
1209 void __init brcmf_sdio_init(void)
1210 {
1211         int ret;
1212 
1213         brcmf_dbg(SDIO, "Enter\n");
1214 
1215         ret = platform_driver_probe(&brcmf_sdio_pd, brcmf_sdio_pd_probe);
1216         if (ret == -ENODEV)
1217                 brcmf_dbg(SDIO, "No platform data available.\n");
1218 }
1219 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us