18 #include <linux/module.h>
71 #define CMD53_ARG_READ 0
72 #define CMD53_ARG_WRITE 1
73 #define CMD53_ARG_BLOCK_BASIS 1
74 #define CMD53_ARG_FIXED_ADDRESS 0
75 #define CMD53_ARG_INCR_ADDRESS 1
88 static inline bool buf_needs_bounce(
u8 *
buf)
93 static void ath6kl_sdio_set_mbox_info(
struct ath6kl *
ar)
110 *arg = (((rw & 1) << 31) |
111 ((func & 0x7) << 28) |
113 ((opcode & 1) << 26) |
114 ((addr & 0x1FFFF) << 9) |
124 *arg = ((write & 1) << 31) |
125 ((func & 0x7) << 28) |
128 ((address & 0x1FFFF) << 9) |
133 static int ath6kl_sdio_func0_cmd52_wr_byte(
struct mmc_card *
card,
134 unsigned int address,
140 ath6kl_sdio_set_cmd52_arg(&
io_cmd.arg, 1, 0, address, byte);
178 request & HIF_WRITE ?
"wr" :
"rd", addr,
189 spin_lock_bh(&ar_sdio->
lock);
192 spin_unlock_bh(&ar_sdio->
lock);
200 spin_unlock_bh(&ar_sdio->
lock);
207 static void ath6kl_sdio_free_bus_req(
struct ath6kl_sdio *ar_sdio,
213 spin_lock_bh(&ar_sdio->
lock);
215 spin_unlock_bh(&ar_sdio->
lock);
228 "hif-scatter: (%s) addr: 0x%X, (block len: %d, block count: %d) , (tot:%d,sg:%d)\n",
229 (scat_req->
req & HIF_WRITE) ?
"WR" :
"RD", scat_req->
addr,
246 sg_set_buf(sg, scat_req->
scat_list[i].buf,
255 static int ath6kl_sdio_scat_rw(
struct ath6kl_sdio *ar_sdio,
272 status = ath6kl_sdio_io(ar_sdio->
func, scat_req->
req,
282 ath6kl_sdio_setup_scat_data(scat_req, &data);
290 if (scat_req->
req & HIF_WRITE) {
299 ath6kl_sdio_set_cmd53_arg(&
cmd.arg, rw, ar_sdio->
func->num,
307 mmc_req.data = &
data;
323 ath6kl_err(
"Scatter write request failed:%d\n",
327 scat_req->
complete(ar_sdio->
ar->htc_target, scat_req);
332 static int ath6kl_sdio_alloc_prep_scat_req(
struct ath6kl_sdio *ar_sdio,
333 int n_scat_entry,
int n_scat_req,
338 int i, scat_req_sz, scat_list_sz, sg_sz, buf_sz;
342 scat_req_sz =
sizeof(*s_req) + scat_list_sz;
350 for (i = 0; i < n_scat_req; i++) {
376 bus_req = ath6kl_sdio_alloc_busreq(ar_sdio);
391 hif_scatter_req_add(ar_sdio->
ar, s_req);
397 static int ath6kl_sdio_read_write_sync(
struct ath6kl *
ar,
u32 addr,
u8 *buf,
400 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
403 bool bounced =
false;
408 if (buf_needs_bounce(buf)) {
414 if (request & HIF_WRITE)
421 ret = ath6kl_sdio_io(ar_sdio->
func, request, addr, tbuf, len);
422 if ((request &
HIF_READ) && bounced)
431 static void __ath6kl_sdio_write_async(
struct ath6kl_sdio *ar_sdio,
435 ath6kl_sdio_scat_rw(ar_sdio, req);
440 status = ath6kl_sdio_read_write_sync(ar_sdio->
ar, req->
address,
444 ath6kl_sdio_free_bus_req(ar_sdio, req);
460 __ath6kl_sdio_write_async(ar_sdio, req);
466 static void ath6kl_sdio_irq_handler(
struct sdio_func *func)
490 static int ath6kl_sdio_power_on(
struct ath6kl *ar)
492 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
505 ath6kl_err(
"Unable to enable sdio func: %d)\n", ret);
523 static int ath6kl_sdio_power_off(
struct ath6kl *ar)
525 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
550 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
553 bus_req = ath6kl_sdio_alloc_busreq(ar_sdio);
572 static void ath6kl_sdio_irq_enable(
struct ath6kl *ar)
574 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
582 ath6kl_err(
"Failed to claim sdio irq: %d\n", ret);
587 static bool ath6kl_sdio_is_on_irq(
struct ath6kl *ar)
589 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
594 static void ath6kl_sdio_irq_disable(
struct ath6kl *ar)
596 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
605 ath6kl_sdio_is_on_irq(ar));
614 ath6kl_err(
"Failed to release sdio irq: %d\n", ret);
621 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
626 if (!list_empty(&ar_sdio->
scat_req)) {
639 static void ath6kl_sdio_scatter_req_add(
struct ath6kl *ar,
642 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
653 static int ath6kl_sdio_async_rw_scatter(
struct ath6kl *ar,
656 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
657 u32 request = scat_req->
req;
664 "hif-scatter: total len: %d scatter entries: %d\n",
668 status = ath6kl_sdio_scat_rw(ar_sdio, scat_req->
busrequest);
680 static void ath6kl_sdio_cleanup_scatter(
struct ath6kl *ar)
682 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
697 ath6kl_sdio_free_bus_req(ar_sdio, s_req->
busrequest);
708 static int ath6kl_sdio_enable_scatter(
struct ath6kl *ar)
710 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
713 bool virt_scat =
false;
722 ath6kl_err(
"host only supports scatter of :%d entries, need: %d\n",
723 ar_sdio->
func->card->host->max_segs,
729 ret = ath6kl_sdio_alloc_prep_scat_req(ar_sdio,
735 "hif-scatter enabled requests %d entries %d\n",
743 ath6kl_sdio_cleanup_scatter(ar);
744 ath6kl_warn(
"hif scatter resource setup failed, trying virtual scatter method\n");
748 if (virt_scat || ret) {
749 ret = ath6kl_sdio_alloc_prep_scat_req(ar_sdio,
754 ath6kl_err(
"failed to alloc virtual scatter resources !\n");
755 ath6kl_sdio_cleanup_scatter(ar);
760 "virtual scatter enabled requests %d entries %d\n",
771 static int ath6kl_sdio_config(
struct ath6kl *ar)
773 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
782 ret = ath6kl_sdio_func0_cmd52_wr_byte(func->
card,
786 ath6kl_err(
"Failed to enable 4-bit async irq mode %d\n",
799 ath6kl_err(
"Set sdio block size %d failed: %d)\n",
810 static int ath6kl_set_sdio_pm_caps(
struct ath6kl *ar)
812 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
827 ath6kl_err(
"set sdio keep pwr flag failed: %d\n", ret);
834 ath6kl_err(
"set sdio wake irq flag failed: %d\n", ret);
841 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
844 bool try_deepsleep =
false;
850 ret = ath6kl_set_sdio_pm_caps(ar);
866 ret = ath6kl_set_sdio_pm_caps(ar);
877 try_deepsleep =
true;
889 if (!(flags & MMC_PM_KEEP_POWER))
902 if ((flags & MMC_PM_WAKE_SDIO_IRQ)) {
904 MMC_PM_WAKE_SDIO_IRQ);
919 func->
card->host->pm_flags &= ~MMC_PM_KEEP_POWER;
924 static int ath6kl_sdio_resume(
struct ath6kl *ar)
930 "sdio resume configuring sdio\n");
933 ath6kl_sdio_config(ar);
972 for (i = 1; i <= 3; i++) {
977 memset(addr_val, ((
u8 *)&addr)[i], 4);
984 status = ath6kl_sdio_read_write_sync(ar, reg_addr + i, addr_val,
991 ath6kl_err(
"%s: failed to write initial bytes of 0x%x to window reg: 0x%X\n",
992 __func__, addr, reg_addr);
1002 status = ath6kl_sdio_read_write_sync(ar, reg_addr, (
u8 *)(&addr),
1006 ath6kl_err(
"%s: failed to write 0x%x to window reg: 0x%X\n",
1007 __func__, addr, reg_addr);
1014 static int ath6kl_sdio_diag_read32(
struct ath6kl *ar,
u32 address,
u32 *data)
1029 ath6kl_err(
"%s: failed to read from window data addr\n",
1037 static int ath6kl_sdio_diag_write32(
struct ath6kl *ar,
u32 address,
1047 ath6kl_err(
"%s: failed to write 0x%x to window data addr\n",
1057 static int ath6kl_sdio_bmi_credits(
struct ath6kl *ar)
1063 ar->
bmi.cmd_credits = 0;
1077 ret = ath6kl_sdio_read_write_sync(ar, addr,
1078 (
u8 *)&ar->
bmi.cmd_credits, 4,
1081 ath6kl_err(
"Unable to decrement the command credit count register: %d\n",
1089 ar->
bmi.cmd_credits &= 0xFF;
1092 if (!ar->
bmi.cmd_credits) {
1100 static int ath6kl_bmi_get_rx_lkahd(
struct ath6kl *ar)
1102 unsigned long timeout;
1107 while ((
time_before(jiffies, timeout)) && !rx_word) {
1108 ret = ath6kl_sdio_read_write_sync(ar,
1110 (
u8 *)&rx_word,
sizeof(rx_word),
1113 ath6kl_err(
"unable to read RX_LOOKAHEAD_VALID\n");
1129 static int ath6kl_sdio_bmi_write(
struct ath6kl *ar,
u8 *buf,
u32 len)
1134 ret = ath6kl_sdio_bmi_credits(ar);
1140 ret = ath6kl_sdio_read_write_sync(ar, addr, buf, len,
1143 ath6kl_err(
"unable to send the bmi data to the device\n");
1148 static int ath6kl_sdio_bmi_read(
struct ath6kl *ar,
u8 *buf,
u32 len)
1200 ret = ath6kl_bmi_get_rx_lkahd(ar);
1206 ret = ath6kl_sdio_read_write_sync(ar, addr, buf, len,
1209 ath6kl_err(
"Unable to read the bmi data from the device: %d\n",
1217 static void ath6kl_sdio_stop(
struct ath6kl *ar)
1219 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
1235 req->
scat_req->complete(ar_sdio->
ar->htc_target,
1239 ath6kl_sdio_free_bus_req(ar_sdio, req);
1250 .read_write_sync = ath6kl_sdio_read_write_sync,
1251 .write_async = ath6kl_sdio_write_async,
1252 .irq_enable = ath6kl_sdio_irq_enable,
1253 .irq_disable = ath6kl_sdio_irq_disable,
1254 .scatter_req_get = ath6kl_sdio_scatter_req_get,
1255 .scatter_req_add = ath6kl_sdio_scatter_req_add,
1256 .enable_scatter = ath6kl_sdio_enable_scatter,
1257 .scat_req_rw = ath6kl_sdio_async_rw_scatter,
1258 .cleanup_scatter = ath6kl_sdio_cleanup_scatter,
1259 .suspend = ath6kl_sdio_suspend,
1260 .resume = ath6kl_sdio_resume,
1261 .diag_read32 = ath6kl_sdio_diag_read32,
1262 .diag_write32 = ath6kl_sdio_diag_write32,
1263 .bmi_read = ath6kl_sdio_bmi_read,
1264 .bmi_write = ath6kl_sdio_bmi_write,
1265 .power_on = ath6kl_sdio_power_on,
1266 .power_off = ath6kl_sdio_power_off,
1267 .stop = ath6kl_sdio_stop,
1270 #ifdef CONFIG_PM_SLEEP
1276 static int ath6kl_sdio_pm_suspend(
struct device *
device)
1283 static int ath6kl_sdio_pm_resume(
struct device *
device)
1291 ath6kl_sdio_pm_resume);
1293 #define ATH6KL_SDIO_PM_OPS (&ath6kl_sdio_pm_ops)
1297 #define ATH6KL_SDIO_PM_OPS NULL
1301 static int ath6kl_sdio_probe(
struct sdio_func *func,
1310 "sdio new func %d vendor 0x%x device 0x%x block 0x%x/0x%x\n",
1335 INIT_LIST_HEAD(&ar_sdio->
scat_req);
1344 ath6kl_sdio_free_bus_req(ar_sdio, &ar_sdio->
bus_req[count]);
1356 ar->
hif_ops = &ath6kl_sdio_ops;
1357 ar->
bmi.max_data_size = 256;
1359 ath6kl_sdio_set_mbox_info(ar);
1361 ret = ath6kl_sdio_config(ar);
1363 ath6kl_err(
"Failed to config sdio: %d\n", ret);
1364 goto err_core_alloc;
1370 goto err_core_alloc;
1385 static void ath6kl_sdio_remove(
struct sdio_func *func)
1390 "sdio removed func %d vendor 0x%x device 0x%x\n",
1416 .name =
"ath6kl_sdio",
1417 .id_table = ath6kl_sdio_devices,
1418 .probe = ath6kl_sdio_probe,
1419 .remove = ath6kl_sdio_remove,
1423 static int __init ath6kl_sdio_init(
void)
1429 ath6kl_err(
"sdio driver registration failed: %d\n", ret);
1434 static void __exit ath6kl_sdio_exit(
void)