bcmsdh.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  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. #include <linux/types.h>
  18. #include <linux/netdevice.h>
  19. #include <linux/pci.h>
  20. #include <linux/pci_ids.h>
  21. #include <linux/sched.h>
  22. #include <linux/completion.h>
  23. #include <linux/interrupt.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/pm_runtime.h>
  31. #include <linux/suspend.h>
  32. #include <linux/errno.h>
  33. #include <linux/module.h>
  34. #include <linux/acpi.h>
  35. #include <net/cfg80211.h>
  36. #include <defs.h>
  37. #include <brcm_hw_ids.h>
  38. #include <brcmu_utils.h>
  39. #include <brcmu_wifi.h>
  40. #include <chipcommon.h>
  41. #include <soc.h>
  42. #include "chip.h"
  43. #include "bus.h"
  44. #include "debug.h"
  45. #include "sdio.h"
  46. #include "core.h"
  47. #include "common.h"
  48. #define SDIOH_API_ACCESS_RETRY_LIMIT 2
  49. #define DMA_ALIGN_MASK 0x03
  50. #define SDIO_FUNC1_BLOCKSIZE 64
  51. #define SDIO_FUNC2_BLOCKSIZE 512
  52. /* Maximum milliseconds to wait for F2 to come up */
  53. #define SDIO_WAIT_F2RDY 3000
  54. #define BRCMF_DEFAULT_RXGLOM_SIZE 32 /* max rx frames in glom chain */
  55. struct brcmf_sdiod_freezer {
  56. atomic_t freezing;
  57. atomic_t thread_count;
  58. u32 frozen_count;
  59. wait_queue_head_t thread_freeze;
  60. struct completion resumed;
  61. };
  62. static irqreturn_t brcmf_sdiod_oob_irqhandler(int irq, void *dev_id)
  63. {
  64. struct brcmf_bus *bus_if = dev_get_drvdata(dev_id);
  65. struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
  66. brcmf_dbg(INTR, "OOB intr triggered\n");
  67. /* out-of-band interrupt is level-triggered which won't
  68. * be cleared until dpc
  69. */
  70. if (sdiodev->irq_en) {
  71. disable_irq_nosync(irq);
  72. sdiodev->irq_en = false;
  73. }
  74. brcmf_sdio_isr(sdiodev->bus);
  75. return IRQ_HANDLED;
  76. }
  77. static void brcmf_sdiod_ib_irqhandler(struct sdio_func *func)
  78. {
  79. struct brcmf_bus *bus_if = dev_get_drvdata(&func->dev);
  80. struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
  81. brcmf_dbg(INTR, "IB intr triggered\n");
  82. brcmf_sdio_isr(sdiodev->bus);
  83. }
  84. /* dummy handler for SDIO function 2 interrupt */
  85. static void brcmf_sdiod_dummy_irqhandler(struct sdio_func *func)
  86. {
  87. }
  88. int brcmf_sdiod_intr_register(struct brcmf_sdio_dev *sdiodev)
  89. {
  90. struct brcmfmac_sdio_pd *pdata;
  91. int ret = 0;
  92. u8 data;
  93. u32 addr, gpiocontrol;
  94. pdata = &sdiodev->settings->bus.sdio;
  95. if (pdata->oob_irq_supported) {
  96. brcmf_dbg(SDIO, "Enter, register OOB IRQ %d\n",
  97. pdata->oob_irq_nr);
  98. spin_lock_init(&sdiodev->irq_en_lock);
  99. sdiodev->irq_en = true;
  100. ret = request_irq(pdata->oob_irq_nr, brcmf_sdiod_oob_irqhandler,
  101. pdata->oob_irq_flags, "brcmf_oob_intr",
  102. &sdiodev->func1->dev);
  103. if (ret != 0) {
  104. brcmf_err("request_irq failed %d\n", ret);
  105. return ret;
  106. }
  107. sdiodev->oob_irq_requested = true;
  108. ret = enable_irq_wake(pdata->oob_irq_nr);
  109. if (ret != 0) {
  110. brcmf_err("enable_irq_wake failed %d\n", ret);
  111. return ret;
  112. }
  113. sdiodev->irq_wake = true;
  114. sdio_claim_host(sdiodev->func1);
  115. if (sdiodev->bus_if->chip == BRCM_CC_43362_CHIP_ID) {
  116. /* assign GPIO to SDIO core */
  117. addr = CORE_CC_REG(SI_ENUM_BASE, gpiocontrol);
  118. gpiocontrol = brcmf_sdiod_readl(sdiodev, addr, &ret);
  119. gpiocontrol |= 0x2;
  120. brcmf_sdiod_writel(sdiodev, addr, gpiocontrol, &ret);
  121. brcmf_sdiod_writeb(sdiodev, SBSDIO_GPIO_SELECT,
  122. 0xf, &ret);
  123. brcmf_sdiod_writeb(sdiodev, SBSDIO_GPIO_OUT, 0, &ret);
  124. brcmf_sdiod_writeb(sdiodev, SBSDIO_GPIO_EN, 0x2, &ret);
  125. }
  126. /* must configure SDIO_CCCR_IENx to enable irq */
  127. data = brcmf_sdiod_func0_rb(sdiodev, SDIO_CCCR_IENx, &ret);
  128. data |= SDIO_CCCR_IEN_FUNC1 | SDIO_CCCR_IEN_FUNC2 |
  129. SDIO_CCCR_IEN_FUNC0;
  130. brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_IENx, data, &ret);
  131. /* redirect, configure and enable io for interrupt signal */
  132. data = SDIO_CCCR_BRCM_SEPINT_MASK | SDIO_CCCR_BRCM_SEPINT_OE;
  133. if (pdata->oob_irq_flags & IRQF_TRIGGER_HIGH)
  134. data |= SDIO_CCCR_BRCM_SEPINT_ACT_HI;
  135. brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_BRCM_SEPINT,
  136. data, &ret);
  137. sdio_release_host(sdiodev->func1);
  138. } else {
  139. brcmf_dbg(SDIO, "Entering\n");
  140. sdio_claim_host(sdiodev->func1);
  141. sdio_claim_irq(sdiodev->func1, brcmf_sdiod_ib_irqhandler);
  142. sdio_claim_irq(sdiodev->func2, brcmf_sdiod_dummy_irqhandler);
  143. sdio_release_host(sdiodev->func1);
  144. sdiodev->sd_irq_requested = true;
  145. }
  146. return 0;
  147. }
  148. void brcmf_sdiod_intr_unregister(struct brcmf_sdio_dev *sdiodev)
  149. {
  150. brcmf_dbg(SDIO, "Entering oob=%d sd=%d\n",
  151. sdiodev->oob_irq_requested,
  152. sdiodev->sd_irq_requested);
  153. if (sdiodev->oob_irq_requested) {
  154. struct brcmfmac_sdio_pd *pdata;
  155. pdata = &sdiodev->settings->bus.sdio;
  156. sdio_claim_host(sdiodev->func1);
  157. brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_BRCM_SEPINT, 0, NULL);
  158. brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_IENx, 0, NULL);
  159. sdio_release_host(sdiodev->func1);
  160. sdiodev->oob_irq_requested = false;
  161. if (sdiodev->irq_wake) {
  162. disable_irq_wake(pdata->oob_irq_nr);
  163. sdiodev->irq_wake = false;
  164. }
  165. free_irq(pdata->oob_irq_nr, &sdiodev->func1->dev);
  166. sdiodev->irq_en = false;
  167. sdiodev->oob_irq_requested = false;
  168. }
  169. if (sdiodev->sd_irq_requested) {
  170. sdio_claim_host(sdiodev->func1);
  171. sdio_release_irq(sdiodev->func2);
  172. sdio_release_irq(sdiodev->func1);
  173. sdio_release_host(sdiodev->func1);
  174. sdiodev->sd_irq_requested = false;
  175. }
  176. }
  177. void brcmf_sdiod_change_state(struct brcmf_sdio_dev *sdiodev,
  178. enum brcmf_sdiod_state state)
  179. {
  180. if (sdiodev->state == BRCMF_SDIOD_NOMEDIUM ||
  181. state == sdiodev->state)
  182. return;
  183. brcmf_dbg(TRACE, "%d -> %d\n", sdiodev->state, state);
  184. switch (sdiodev->state) {
  185. case BRCMF_SDIOD_DATA:
  186. /* any other state means bus interface is down */
  187. brcmf_bus_change_state(sdiodev->bus_if, BRCMF_BUS_DOWN);
  188. break;
  189. case BRCMF_SDIOD_DOWN:
  190. /* transition from DOWN to DATA means bus interface is up */
  191. if (state == BRCMF_SDIOD_DATA)
  192. brcmf_bus_change_state(sdiodev->bus_if, BRCMF_BUS_UP);
  193. break;
  194. default:
  195. break;
  196. }
  197. sdiodev->state = state;
  198. }
  199. static int brcmf_sdiod_set_backplane_window(struct brcmf_sdio_dev *sdiodev,
  200. u32 addr)
  201. {
  202. u32 v, bar0 = addr & SBSDIO_SBWINDOW_MASK;
  203. int err = 0, i;
  204. if (bar0 == sdiodev->sbwad)
  205. return 0;
  206. v = bar0 >> 8;
  207. for (i = 0 ; i < 3 && !err ; i++, v >>= 8)
  208. brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_SBADDRLOW + i,
  209. v & 0xff, &err);
  210. if (!err)
  211. sdiodev->sbwad = bar0;
  212. return err;
  213. }
  214. u32 brcmf_sdiod_readl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret)
  215. {
  216. u32 data = 0;
  217. int retval;
  218. retval = brcmf_sdiod_set_backplane_window(sdiodev, addr);
  219. if (retval)
  220. goto out;
  221. addr &= SBSDIO_SB_OFT_ADDR_MASK;
  222. addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
  223. data = sdio_readl(sdiodev->func1, addr, &retval);
  224. out:
  225. if (ret)
  226. *ret = retval;
  227. return data;
  228. }
  229. void brcmf_sdiod_writel(struct brcmf_sdio_dev *sdiodev, u32 addr,
  230. u32 data, int *ret)
  231. {
  232. int retval;
  233. retval = brcmf_sdiod_set_backplane_window(sdiodev, addr);
  234. if (retval)
  235. goto out;
  236. addr &= SBSDIO_SB_OFT_ADDR_MASK;
  237. addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
  238. sdio_writel(sdiodev->func1, data, addr, &retval);
  239. out:
  240. if (ret)
  241. *ret = retval;
  242. }
  243. static int brcmf_sdiod_skbuff_read(struct brcmf_sdio_dev *sdiodev,
  244. struct sdio_func *func, u32 addr,
  245. struct sk_buff *skb)
  246. {
  247. unsigned int req_sz;
  248. int err;
  249. /* Single skb use the standard mmc interface */
  250. req_sz = skb->len + 3;
  251. req_sz &= (uint)~3;
  252. switch (func->num) {
  253. case 1:
  254. err = sdio_memcpy_fromio(func, ((u8 *)(skb->data)), addr,
  255. req_sz);
  256. break;
  257. case 2:
  258. err = sdio_readsb(func, ((u8 *)(skb->data)), addr, req_sz);
  259. break;
  260. default:
  261. /* bail out as things are really fishy here */
  262. WARN(1, "invalid sdio function number: %d\n", func->num);
  263. err = -ENOMEDIUM;
  264. };
  265. if (err == -ENOMEDIUM)
  266. brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
  267. return err;
  268. }
  269. static int brcmf_sdiod_skbuff_write(struct brcmf_sdio_dev *sdiodev,
  270. struct sdio_func *func, u32 addr,
  271. struct sk_buff *skb)
  272. {
  273. unsigned int req_sz;
  274. int err;
  275. /* Single skb use the standard mmc interface */
  276. req_sz = skb->len + 3;
  277. req_sz &= (uint)~3;
  278. err = sdio_memcpy_toio(func, addr, ((u8 *)(skb->data)), req_sz);
  279. if (err == -ENOMEDIUM)
  280. brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
  281. return err;
  282. }
  283. /**
  284. * brcmf_sdiod_sglist_rw - SDIO interface function for block data access
  285. * @sdiodev: brcmfmac sdio device
  286. * @func: SDIO function
  287. * @write: direction flag
  288. * @addr: dongle memory address as source/destination
  289. * @pkt: skb pointer
  290. *
  291. * This function takes the respbonsibility as the interface function to MMC
  292. * stack for block data access. It assumes that the skb passed down by the
  293. * caller has already been padded and aligned.
  294. */
  295. static int brcmf_sdiod_sglist_rw(struct brcmf_sdio_dev *sdiodev,
  296. struct sdio_func *func,
  297. bool write, u32 addr,
  298. struct sk_buff_head *pktlist)
  299. {
  300. unsigned int req_sz, func_blk_sz, sg_cnt, sg_data_sz, pkt_offset;
  301. unsigned int max_req_sz, orig_offset, dst_offset;
  302. unsigned short max_seg_cnt, seg_sz;
  303. unsigned char *pkt_data, *orig_data, *dst_data;
  304. struct sk_buff *pkt_next = NULL, *local_pkt_next;
  305. struct sk_buff_head local_list, *target_list;
  306. struct mmc_request mmc_req;
  307. struct mmc_command mmc_cmd;
  308. struct mmc_data mmc_dat;
  309. struct scatterlist *sgl;
  310. int ret = 0;
  311. if (!pktlist->qlen)
  312. return -EINVAL;
  313. target_list = pktlist;
  314. /* for host with broken sg support, prepare a page aligned list */
  315. __skb_queue_head_init(&local_list);
  316. if (!write && sdiodev->settings->bus.sdio.broken_sg_support) {
  317. req_sz = 0;
  318. skb_queue_walk(pktlist, pkt_next)
  319. req_sz += pkt_next->len;
  320. req_sz = ALIGN(req_sz, func->cur_blksize);
  321. while (req_sz > PAGE_SIZE) {
  322. pkt_next = brcmu_pkt_buf_get_skb(PAGE_SIZE);
  323. if (pkt_next == NULL) {
  324. ret = -ENOMEM;
  325. goto exit;
  326. }
  327. __skb_queue_tail(&local_list, pkt_next);
  328. req_sz -= PAGE_SIZE;
  329. }
  330. pkt_next = brcmu_pkt_buf_get_skb(req_sz);
  331. if (pkt_next == NULL) {
  332. ret = -ENOMEM;
  333. goto exit;
  334. }
  335. __skb_queue_tail(&local_list, pkt_next);
  336. target_list = &local_list;
  337. }
  338. func_blk_sz = func->cur_blksize;
  339. max_req_sz = sdiodev->max_request_size;
  340. max_seg_cnt = min_t(unsigned short, sdiodev->max_segment_count,
  341. target_list->qlen);
  342. seg_sz = target_list->qlen;
  343. pkt_offset = 0;
  344. pkt_next = target_list->next;
  345. memset(&mmc_req, 0, sizeof(struct mmc_request));
  346. memset(&mmc_cmd, 0, sizeof(struct mmc_command));
  347. memset(&mmc_dat, 0, sizeof(struct mmc_data));
  348. mmc_dat.sg = sdiodev->sgtable.sgl;
  349. mmc_dat.blksz = func_blk_sz;
  350. mmc_dat.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
  351. mmc_cmd.opcode = SD_IO_RW_EXTENDED;
  352. mmc_cmd.arg = write ? 1<<31 : 0; /* write flag */
  353. mmc_cmd.arg |= (func->num & 0x7) << 28; /* SDIO func num */
  354. mmc_cmd.arg |= 1 << 27; /* block mode */
  355. /* for function 1 the addr will be incremented */
  356. mmc_cmd.arg |= (func->num == 1) ? 1 << 26 : 0;
  357. mmc_cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC;
  358. mmc_req.cmd = &mmc_cmd;
  359. mmc_req.data = &mmc_dat;
  360. while (seg_sz) {
  361. req_sz = 0;
  362. sg_cnt = 0;
  363. sgl = sdiodev->sgtable.sgl;
  364. /* prep sg table */
  365. while (pkt_next != (struct sk_buff *)target_list) {
  366. pkt_data = pkt_next->data + pkt_offset;
  367. sg_data_sz = pkt_next->len - pkt_offset;
  368. if (sg_data_sz > sdiodev->max_segment_size)
  369. sg_data_sz = sdiodev->max_segment_size;
  370. if (sg_data_sz > max_req_sz - req_sz)
  371. sg_data_sz = max_req_sz - req_sz;
  372. sg_set_buf(sgl, pkt_data, sg_data_sz);
  373. sg_cnt++;
  374. sgl = sg_next(sgl);
  375. req_sz += sg_data_sz;
  376. pkt_offset += sg_data_sz;
  377. if (pkt_offset == pkt_next->len) {
  378. pkt_offset = 0;
  379. pkt_next = pkt_next->next;
  380. }
  381. if (req_sz >= max_req_sz || sg_cnt >= max_seg_cnt)
  382. break;
  383. }
  384. seg_sz -= sg_cnt;
  385. if (req_sz % func_blk_sz != 0) {
  386. brcmf_err("sg request length %u is not %u aligned\n",
  387. req_sz, func_blk_sz);
  388. ret = -ENOTBLK;
  389. goto exit;
  390. }
  391. mmc_dat.sg_len = sg_cnt;
  392. mmc_dat.blocks = req_sz / func_blk_sz;
  393. mmc_cmd.arg |= (addr & 0x1FFFF) << 9; /* address */
  394. mmc_cmd.arg |= mmc_dat.blocks & 0x1FF; /* block count */
  395. /* incrementing addr for function 1 */
  396. if (func->num == 1)
  397. addr += req_sz;
  398. mmc_set_data_timeout(&mmc_dat, func->card);
  399. mmc_wait_for_req(func->card->host, &mmc_req);
  400. ret = mmc_cmd.error ? mmc_cmd.error : mmc_dat.error;
  401. if (ret == -ENOMEDIUM) {
  402. brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
  403. break;
  404. } else if (ret != 0) {
  405. brcmf_err("CMD53 sg block %s failed %d\n",
  406. write ? "write" : "read", ret);
  407. ret = -EIO;
  408. break;
  409. }
  410. }
  411. if (!write && sdiodev->settings->bus.sdio.broken_sg_support) {
  412. local_pkt_next = local_list.next;
  413. orig_offset = 0;
  414. skb_queue_walk(pktlist, pkt_next) {
  415. dst_offset = 0;
  416. do {
  417. req_sz = local_pkt_next->len - orig_offset;
  418. req_sz = min_t(uint, pkt_next->len - dst_offset,
  419. req_sz);
  420. orig_data = local_pkt_next->data + orig_offset;
  421. dst_data = pkt_next->data + dst_offset;
  422. memcpy(dst_data, orig_data, req_sz);
  423. orig_offset += req_sz;
  424. dst_offset += req_sz;
  425. if (orig_offset == local_pkt_next->len) {
  426. orig_offset = 0;
  427. local_pkt_next = local_pkt_next->next;
  428. }
  429. if (dst_offset == pkt_next->len)
  430. break;
  431. } while (!skb_queue_empty(&local_list));
  432. }
  433. }
  434. exit:
  435. sg_init_table(sdiodev->sgtable.sgl, sdiodev->sgtable.orig_nents);
  436. while ((pkt_next = __skb_dequeue(&local_list)) != NULL)
  437. brcmu_pkt_buf_free_skb(pkt_next);
  438. return ret;
  439. }
  440. int brcmf_sdiod_recv_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)
  441. {
  442. struct sk_buff *mypkt;
  443. int err;
  444. mypkt = brcmu_pkt_buf_get_skb(nbytes);
  445. if (!mypkt) {
  446. brcmf_err("brcmu_pkt_buf_get_skb failed: len %d\n",
  447. nbytes);
  448. return -EIO;
  449. }
  450. err = brcmf_sdiod_recv_pkt(sdiodev, mypkt);
  451. if (!err)
  452. memcpy(buf, mypkt->data, nbytes);
  453. brcmu_pkt_buf_free_skb(mypkt);
  454. return err;
  455. }
  456. int brcmf_sdiod_recv_pkt(struct brcmf_sdio_dev *sdiodev, struct sk_buff *pkt)
  457. {
  458. u32 addr = sdiodev->cc_core->base;
  459. int err = 0;
  460. brcmf_dbg(SDIO, "addr = 0x%x, size = %d\n", addr, pkt->len);
  461. err = brcmf_sdiod_set_backplane_window(sdiodev, addr);
  462. if (err)
  463. goto done;
  464. addr &= SBSDIO_SB_OFT_ADDR_MASK;
  465. addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
  466. err = brcmf_sdiod_skbuff_read(sdiodev, sdiodev->func2, addr, pkt);
  467. done:
  468. return err;
  469. }
  470. int brcmf_sdiod_recv_chain(struct brcmf_sdio_dev *sdiodev,
  471. struct sk_buff_head *pktq, uint totlen)
  472. {
  473. struct sk_buff *glom_skb = NULL;
  474. struct sk_buff *skb;
  475. u32 addr = sdiodev->cc_core->base;
  476. int err = 0;
  477. brcmf_dbg(SDIO, "addr = 0x%x, size = %d\n",
  478. addr, pktq->qlen);
  479. err = brcmf_sdiod_set_backplane_window(sdiodev, addr);
  480. if (err)
  481. goto done;
  482. addr &= SBSDIO_SB_OFT_ADDR_MASK;
  483. addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
  484. if (pktq->qlen == 1)
  485. err = brcmf_sdiod_skbuff_read(sdiodev, sdiodev->func2, addr,
  486. pktq->next);
  487. else if (!sdiodev->sg_support) {
  488. glom_skb = brcmu_pkt_buf_get_skb(totlen);
  489. if (!glom_skb)
  490. return -ENOMEM;
  491. err = brcmf_sdiod_skbuff_read(sdiodev, sdiodev->func2, addr,
  492. glom_skb);
  493. if (err)
  494. goto done;
  495. skb_queue_walk(pktq, skb) {
  496. memcpy(skb->data, glom_skb->data, skb->len);
  497. skb_pull(glom_skb, skb->len);
  498. }
  499. } else
  500. err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func2, false,
  501. addr, pktq);
  502. done:
  503. brcmu_pkt_buf_free_skb(glom_skb);
  504. return err;
  505. }
  506. int brcmf_sdiod_send_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)
  507. {
  508. struct sk_buff *mypkt;
  509. u32 addr = sdiodev->cc_core->base;
  510. int err;
  511. mypkt = brcmu_pkt_buf_get_skb(nbytes);
  512. if (!mypkt) {
  513. brcmf_err("brcmu_pkt_buf_get_skb failed: len %d\n",
  514. nbytes);
  515. return -EIO;
  516. }
  517. memcpy(mypkt->data, buf, nbytes);
  518. err = brcmf_sdiod_set_backplane_window(sdiodev, addr);
  519. if (err)
  520. goto out;
  521. addr &= SBSDIO_SB_OFT_ADDR_MASK;
  522. addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
  523. err = brcmf_sdiod_skbuff_write(sdiodev, sdiodev->func2, addr, mypkt);
  524. out:
  525. brcmu_pkt_buf_free_skb(mypkt);
  526. return err;
  527. }
  528. int brcmf_sdiod_send_pkt(struct brcmf_sdio_dev *sdiodev,
  529. struct sk_buff_head *pktq)
  530. {
  531. struct sk_buff *skb;
  532. u32 addr = sdiodev->cc_core->base;
  533. int err;
  534. brcmf_dbg(SDIO, "addr = 0x%x, size = %d\n", addr, pktq->qlen);
  535. err = brcmf_sdiod_set_backplane_window(sdiodev, addr);
  536. if (err)
  537. return err;
  538. addr &= SBSDIO_SB_OFT_ADDR_MASK;
  539. addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
  540. if (pktq->qlen == 1 || !sdiodev->sg_support) {
  541. skb_queue_walk(pktq, skb) {
  542. err = brcmf_sdiod_skbuff_write(sdiodev, sdiodev->func2,
  543. addr, skb);
  544. if (err)
  545. break;
  546. }
  547. } else {
  548. err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func2, true,
  549. addr, pktq);
  550. }
  551. return err;
  552. }
  553. int
  554. brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,
  555. u8 *data, uint size)
  556. {
  557. int err = 0;
  558. struct sk_buff *pkt;
  559. u32 sdaddr;
  560. uint dsize;
  561. dsize = min_t(uint, SBSDIO_SB_OFT_ADDR_LIMIT, size);
  562. pkt = dev_alloc_skb(dsize);
  563. if (!pkt) {
  564. brcmf_err("dev_alloc_skb failed: len %d\n", dsize);
  565. return -EIO;
  566. }
  567. pkt->priority = 0;
  568. /* Determine initial transfer parameters */
  569. sdaddr = address & SBSDIO_SB_OFT_ADDR_MASK;
  570. if ((sdaddr + size) & SBSDIO_SBWINDOW_MASK)
  571. dsize = (SBSDIO_SB_OFT_ADDR_LIMIT - sdaddr);
  572. else
  573. dsize = size;
  574. sdio_claim_host(sdiodev->func1);
  575. /* Do the transfer(s) */
  576. while (size) {
  577. /* Set the backplane window to include the start address */
  578. err = brcmf_sdiod_set_backplane_window(sdiodev, address);
  579. if (err)
  580. break;
  581. brcmf_dbg(SDIO, "%s %d bytes at offset 0x%08x in window 0x%08x\n",
  582. write ? "write" : "read", dsize,
  583. sdaddr, address & SBSDIO_SBWINDOW_MASK);
  584. sdaddr &= SBSDIO_SB_OFT_ADDR_MASK;
  585. sdaddr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
  586. skb_put(pkt, dsize);
  587. if (write) {
  588. memcpy(pkt->data, data, dsize);
  589. err = brcmf_sdiod_skbuff_write(sdiodev, sdiodev->func1,
  590. sdaddr, pkt);
  591. } else {
  592. err = brcmf_sdiod_skbuff_read(sdiodev, sdiodev->func1,
  593. sdaddr, pkt);
  594. }
  595. if (err) {
  596. brcmf_err("membytes transfer failed\n");
  597. break;
  598. }
  599. if (!write)
  600. memcpy(data, pkt->data, dsize);
  601. skb_trim(pkt, 0);
  602. /* Adjust for next transfer (if any) */
  603. size -= dsize;
  604. if (size) {
  605. data += dsize;
  606. address += dsize;
  607. sdaddr = 0;
  608. dsize = min_t(uint, SBSDIO_SB_OFT_ADDR_LIMIT, size);
  609. }
  610. }
  611. dev_kfree_skb(pkt);
  612. sdio_release_host(sdiodev->func1);
  613. return err;
  614. }
  615. int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, struct sdio_func *func)
  616. {
  617. brcmf_dbg(SDIO, "Enter\n");
  618. /* Issue abort cmd52 command through F0 */
  619. brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_ABORT, func->num, NULL);
  620. brcmf_dbg(SDIO, "Exit\n");
  621. return 0;
  622. }
  623. void brcmf_sdiod_sgtable_alloc(struct brcmf_sdio_dev *sdiodev)
  624. {
  625. struct sdio_func *func;
  626. struct mmc_host *host;
  627. uint max_blocks;
  628. uint nents;
  629. int err;
  630. func = sdiodev->func2;
  631. host = func->card->host;
  632. sdiodev->sg_support = host->max_segs > 1;
  633. max_blocks = min_t(uint, host->max_blk_count, 511u);
  634. sdiodev->max_request_size = min_t(uint, host->max_req_size,
  635. max_blocks * func->cur_blksize);
  636. sdiodev->max_segment_count = min_t(uint, host->max_segs,
  637. SG_MAX_SINGLE_ALLOC);
  638. sdiodev->max_segment_size = host->max_seg_size;
  639. if (!sdiodev->sg_support)
  640. return;
  641. nents = max_t(uint, BRCMF_DEFAULT_RXGLOM_SIZE,
  642. sdiodev->settings->bus.sdio.txglomsz);
  643. nents += (nents >> 4) + 1;
  644. WARN_ON(nents > sdiodev->max_segment_count);
  645. brcmf_dbg(TRACE, "nents=%d\n", nents);
  646. err = sg_alloc_table(&sdiodev->sgtable, nents, GFP_KERNEL);
  647. if (err < 0) {
  648. brcmf_err("allocation failed: disable scatter-gather");
  649. sdiodev->sg_support = false;
  650. }
  651. sdiodev->txglomsz = sdiodev->settings->bus.sdio.txglomsz;
  652. }
  653. #ifdef CONFIG_PM_SLEEP
  654. static int brcmf_sdiod_freezer_attach(struct brcmf_sdio_dev *sdiodev)
  655. {
  656. sdiodev->freezer = kzalloc(sizeof(*sdiodev->freezer), GFP_KERNEL);
  657. if (!sdiodev->freezer)
  658. return -ENOMEM;
  659. atomic_set(&sdiodev->freezer->thread_count, 0);
  660. atomic_set(&sdiodev->freezer->freezing, 0);
  661. init_waitqueue_head(&sdiodev->freezer->thread_freeze);
  662. init_completion(&sdiodev->freezer->resumed);
  663. return 0;
  664. }
  665. static void brcmf_sdiod_freezer_detach(struct brcmf_sdio_dev *sdiodev)
  666. {
  667. if (sdiodev->freezer) {
  668. WARN_ON(atomic_read(&sdiodev->freezer->freezing));
  669. kfree(sdiodev->freezer);
  670. }
  671. }
  672. static int brcmf_sdiod_freezer_on(struct brcmf_sdio_dev *sdiodev)
  673. {
  674. atomic_t *expect = &sdiodev->freezer->thread_count;
  675. int res = 0;
  676. sdiodev->freezer->frozen_count = 0;
  677. reinit_completion(&sdiodev->freezer->resumed);
  678. atomic_set(&sdiodev->freezer->freezing, 1);
  679. brcmf_sdio_trigger_dpc(sdiodev->bus);
  680. wait_event(sdiodev->freezer->thread_freeze,
  681. atomic_read(expect) == sdiodev->freezer->frozen_count);
  682. sdio_claim_host(sdiodev->func1);
  683. res = brcmf_sdio_sleep(sdiodev->bus, true);
  684. sdio_release_host(sdiodev->func1);
  685. return res;
  686. }
  687. static void brcmf_sdiod_freezer_off(struct brcmf_sdio_dev *sdiodev)
  688. {
  689. sdio_claim_host(sdiodev->func1);
  690. brcmf_sdio_sleep(sdiodev->bus, false);
  691. sdio_release_host(sdiodev->func1);
  692. atomic_set(&sdiodev->freezer->freezing, 0);
  693. complete_all(&sdiodev->freezer->resumed);
  694. }
  695. bool brcmf_sdiod_freezing(struct brcmf_sdio_dev *sdiodev)
  696. {
  697. return atomic_read(&sdiodev->freezer->freezing);
  698. }
  699. void brcmf_sdiod_try_freeze(struct brcmf_sdio_dev *sdiodev)
  700. {
  701. if (!brcmf_sdiod_freezing(sdiodev))
  702. return;
  703. sdiodev->freezer->frozen_count++;
  704. wake_up(&sdiodev->freezer->thread_freeze);
  705. wait_for_completion(&sdiodev->freezer->resumed);
  706. }
  707. void brcmf_sdiod_freezer_count(struct brcmf_sdio_dev *sdiodev)
  708. {
  709. atomic_inc(&sdiodev->freezer->thread_count);
  710. }
  711. void brcmf_sdiod_freezer_uncount(struct brcmf_sdio_dev *sdiodev)
  712. {
  713. atomic_dec(&sdiodev->freezer->thread_count);
  714. }
  715. #else
  716. static int brcmf_sdiod_freezer_attach(struct brcmf_sdio_dev *sdiodev)
  717. {
  718. return 0;
  719. }
  720. static void brcmf_sdiod_freezer_detach(struct brcmf_sdio_dev *sdiodev)
  721. {
  722. }
  723. #endif /* CONFIG_PM_SLEEP */
  724. static int brcmf_sdiod_remove(struct brcmf_sdio_dev *sdiodev)
  725. {
  726. sdiodev->state = BRCMF_SDIOD_DOWN;
  727. if (sdiodev->bus) {
  728. brcmf_sdio_remove(sdiodev->bus);
  729. sdiodev->bus = NULL;
  730. }
  731. brcmf_sdiod_freezer_detach(sdiodev);
  732. /* Disable Function 2 */
  733. sdio_claim_host(sdiodev->func2);
  734. sdio_disable_func(sdiodev->func2);
  735. sdio_release_host(sdiodev->func2);
  736. /* Disable Function 1 */
  737. sdio_claim_host(sdiodev->func1);
  738. sdio_disable_func(sdiodev->func1);
  739. sdio_release_host(sdiodev->func1);
  740. sg_free_table(&sdiodev->sgtable);
  741. sdiodev->sbwad = 0;
  742. pm_runtime_allow(sdiodev->func1->card->host->parent);
  743. return 0;
  744. }
  745. static void brcmf_sdiod_host_fixup(struct mmc_host *host)
  746. {
  747. /* runtime-pm powers off the device */
  748. pm_runtime_forbid(host->parent);
  749. /* avoid removal detection upon resume */
  750. host->caps |= MMC_CAP_NONREMOVABLE;
  751. }
  752. static int brcmf_sdiod_probe(struct brcmf_sdio_dev *sdiodev)
  753. {
  754. int ret = 0;
  755. sdio_claim_host(sdiodev->func1);
  756. ret = sdio_set_block_size(sdiodev->func1, SDIO_FUNC1_BLOCKSIZE);
  757. if (ret) {
  758. brcmf_err("Failed to set F1 blocksize\n");
  759. sdio_release_host(sdiodev->func1);
  760. goto out;
  761. }
  762. ret = sdio_set_block_size(sdiodev->func2, SDIO_FUNC2_BLOCKSIZE);
  763. if (ret) {
  764. brcmf_err("Failed to set F2 blocksize\n");
  765. sdio_release_host(sdiodev->func1);
  766. goto out;
  767. }
  768. /* increase F2 timeout */
  769. sdiodev->func2->enable_timeout = SDIO_WAIT_F2RDY;
  770. /* Enable Function 1 */
  771. ret = sdio_enable_func(sdiodev->func1);
  772. sdio_release_host(sdiodev->func1);
  773. if (ret) {
  774. brcmf_err("Failed to enable F1: err=%d\n", ret);
  775. goto out;
  776. }
  777. ret = brcmf_sdiod_freezer_attach(sdiodev);
  778. if (ret)
  779. goto out;
  780. /* try to attach to the target device */
  781. sdiodev->bus = brcmf_sdio_probe(sdiodev);
  782. if (!sdiodev->bus) {
  783. ret = -ENODEV;
  784. goto out;
  785. }
  786. brcmf_sdiod_host_fixup(sdiodev->func2->card->host);
  787. out:
  788. if (ret)
  789. brcmf_sdiod_remove(sdiodev);
  790. return ret;
  791. }
  792. #define BRCMF_SDIO_DEVICE(dev_id) \
  793. {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, dev_id)}
  794. /* devices we support, null terminated */
  795. static const struct sdio_device_id brcmf_sdmmc_ids[] = {
  796. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_43143),
  797. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_43241),
  798. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_4329),
  799. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_4330),
  800. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_4334),
  801. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_43340),
  802. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_43341),
  803. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_43362),
  804. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_43364),
  805. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_4335_4339),
  806. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_4339),
  807. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_43430),
  808. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_4345),
  809. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_43455),
  810. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_4354),
  811. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_BROADCOM_4356),
  812. BRCMF_SDIO_DEVICE(SDIO_DEVICE_ID_CYPRESS_4373),
  813. { /* end: all zeroes */ }
  814. };
  815. MODULE_DEVICE_TABLE(sdio, brcmf_sdmmc_ids);
  816. static void brcmf_sdiod_acpi_set_power_manageable(struct device *dev,
  817. int val)
  818. {
  819. #if IS_ENABLED(CONFIG_ACPI)
  820. struct acpi_device *adev;
  821. adev = ACPI_COMPANION(dev);
  822. if (adev)
  823. adev->flags.power_manageable = 0;
  824. #endif
  825. }
  826. static int brcmf_ops_sdio_probe(struct sdio_func *func,
  827. const struct sdio_device_id *id)
  828. {
  829. int err;
  830. struct brcmf_sdio_dev *sdiodev;
  831. struct brcmf_bus *bus_if;
  832. struct device *dev;
  833. brcmf_dbg(SDIO, "Enter\n");
  834. brcmf_dbg(SDIO, "Class=%x\n", func->class);
  835. brcmf_dbg(SDIO, "sdio vendor ID: 0x%04x\n", func->vendor);
  836. brcmf_dbg(SDIO, "sdio device ID: 0x%04x\n", func->device);
  837. brcmf_dbg(SDIO, "Function#: %d\n", func->num);
  838. dev = &func->dev;
  839. /* Set MMC_QUIRK_LENIENT_FN0 for this card */
  840. func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
  841. /* prohibit ACPI power management for this device */
  842. brcmf_sdiod_acpi_set_power_manageable(dev, 0);
  843. /* Consume func num 1 but dont do anything with it. */
  844. if (func->num == 1)
  845. return 0;
  846. /* Ignore anything but func 2 */
  847. if (func->num != 2)
  848. return -ENODEV;
  849. bus_if = kzalloc(sizeof(struct brcmf_bus), GFP_KERNEL);
  850. if (!bus_if)
  851. return -ENOMEM;
  852. sdiodev = kzalloc(sizeof(struct brcmf_sdio_dev), GFP_KERNEL);
  853. if (!sdiodev) {
  854. kfree(bus_if);
  855. return -ENOMEM;
  856. }
  857. /* store refs to functions used. mmc_card does
  858. * not hold the F0 function pointer.
  859. */
  860. sdiodev->func1 = func->card->sdio_func[0];
  861. sdiodev->func2 = func;
  862. sdiodev->bus_if = bus_if;
  863. bus_if->bus_priv.sdio = sdiodev;
  864. bus_if->proto_type = BRCMF_PROTO_BCDC;
  865. dev_set_drvdata(&func->dev, bus_if);
  866. dev_set_drvdata(&sdiodev->func1->dev, bus_if);
  867. sdiodev->dev = &sdiodev->func1->dev;
  868. brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_DOWN);
  869. brcmf_dbg(SDIO, "F2 found, calling brcmf_sdiod_probe...\n");
  870. err = brcmf_sdiod_probe(sdiodev);
  871. if (err) {
  872. brcmf_err("F2 error, probe failed %d...\n", err);
  873. goto fail;
  874. }
  875. brcmf_dbg(SDIO, "F2 init completed...\n");
  876. return 0;
  877. fail:
  878. dev_set_drvdata(&func->dev, NULL);
  879. dev_set_drvdata(&sdiodev->func1->dev, NULL);
  880. kfree(sdiodev);
  881. kfree(bus_if);
  882. return err;
  883. }
  884. static void brcmf_ops_sdio_remove(struct sdio_func *func)
  885. {
  886. struct brcmf_bus *bus_if;
  887. struct brcmf_sdio_dev *sdiodev;
  888. brcmf_dbg(SDIO, "Enter\n");
  889. brcmf_dbg(SDIO, "sdio vendor ID: 0x%04x\n", func->vendor);
  890. brcmf_dbg(SDIO, "sdio device ID: 0x%04x\n", func->device);
  891. brcmf_dbg(SDIO, "Function: %d\n", func->num);
  892. bus_if = dev_get_drvdata(&func->dev);
  893. if (bus_if) {
  894. sdiodev = bus_if->bus_priv.sdio;
  895. /* start by unregistering irqs */
  896. brcmf_sdiod_intr_unregister(sdiodev);
  897. if (func->num != 1)
  898. return;
  899. /* only proceed with rest of cleanup if func 1 */
  900. brcmf_sdiod_remove(sdiodev);
  901. dev_set_drvdata(&sdiodev->func1->dev, NULL);
  902. dev_set_drvdata(&sdiodev->func2->dev, NULL);
  903. kfree(bus_if);
  904. kfree(sdiodev);
  905. }
  906. brcmf_dbg(SDIO, "Exit\n");
  907. }
  908. void brcmf_sdio_wowl_config(struct device *dev, bool enabled)
  909. {
  910. struct brcmf_bus *bus_if = dev_get_drvdata(dev);
  911. struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
  912. brcmf_dbg(SDIO, "Configuring WOWL, enabled=%d\n", enabled);
  913. sdiodev->wowl_enabled = enabled;
  914. }
  915. #ifdef CONFIG_PM_SLEEP
  916. static int brcmf_ops_sdio_suspend(struct device *dev)
  917. {
  918. struct sdio_func *func;
  919. struct brcmf_bus *bus_if;
  920. struct brcmf_sdio_dev *sdiodev;
  921. mmc_pm_flag_t sdio_flags;
  922. func = container_of(dev, struct sdio_func, dev);
  923. brcmf_dbg(SDIO, "Enter: F%d\n", func->num);
  924. if (func->num != 1)
  925. return 0;
  926. bus_if = dev_get_drvdata(dev);
  927. sdiodev = bus_if->bus_priv.sdio;
  928. brcmf_sdiod_freezer_on(sdiodev);
  929. brcmf_sdio_wd_timer(sdiodev->bus, 0);
  930. sdio_flags = MMC_PM_KEEP_POWER;
  931. if (sdiodev->wowl_enabled) {
  932. if (sdiodev->settings->bus.sdio.oob_irq_supported)
  933. enable_irq_wake(sdiodev->settings->bus.sdio.oob_irq_nr);
  934. else
  935. sdio_flags |= MMC_PM_WAKE_SDIO_IRQ;
  936. }
  937. if (sdio_set_host_pm_flags(sdiodev->func1, sdio_flags))
  938. brcmf_err("Failed to set pm_flags %x\n", sdio_flags);
  939. return 0;
  940. }
  941. static int brcmf_ops_sdio_resume(struct device *dev)
  942. {
  943. struct brcmf_bus *bus_if = dev_get_drvdata(dev);
  944. struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
  945. struct sdio_func *func = container_of(dev, struct sdio_func, dev);
  946. brcmf_dbg(SDIO, "Enter: F%d\n", func->num);
  947. if (func->num != 2)
  948. return 0;
  949. brcmf_sdiod_freezer_off(sdiodev);
  950. return 0;
  951. }
  952. static const struct dev_pm_ops brcmf_sdio_pm_ops = {
  953. .suspend = brcmf_ops_sdio_suspend,
  954. .resume = brcmf_ops_sdio_resume,
  955. };
  956. #endif /* CONFIG_PM_SLEEP */
  957. static struct sdio_driver brcmf_sdmmc_driver = {
  958. .probe = brcmf_ops_sdio_probe,
  959. .remove = brcmf_ops_sdio_remove,
  960. .name = KBUILD_MODNAME,
  961. .id_table = brcmf_sdmmc_ids,
  962. .drv = {
  963. .owner = THIS_MODULE,
  964. #ifdef CONFIG_PM_SLEEP
  965. .pm = &brcmf_sdio_pm_ops,
  966. #endif /* CONFIG_PM_SLEEP */
  967. .coredump = brcmf_dev_coredump,
  968. },
  969. };
  970. void brcmf_sdio_register(void)
  971. {
  972. int ret;
  973. ret = sdio_register_driver(&brcmf_sdmmc_driver);
  974. if (ret)
  975. brcmf_err("sdio_register_driver failed: %d\n", ret);
  976. }
  977. void brcmf_sdio_exit(void)
  978. {
  979. brcmf_dbg(SDIO, "Enter\n");
  980. sdio_unregister_driver(&brcmf_sdmmc_driver);
  981. }