Version:  2.0.40 2.2.26 2.4.37 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0

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

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