38 #include <linux/kernel.h>
39 #include <linux/errno.h>
41 #include <linux/slab.h>
42 #include <linux/module.h>
52 #include <linux/ctype.h>
62 #define FIRMWARE_BLOCK_BOUNDARY 1024
133 #define INTERRUPT_REGISTER_ACCESSES 15
150 #define PIGGYBACK_REGISTER_ACCESSES 14
185 #define RESPONSE_INTERRUPT 0x01
186 #define RESPONSE_ERROR 0x02
187 #define RESPONSE_STATUS 0x03
188 #define RESPONSE_IRQ_DISABLED 0x05
189 #define RESPONSE_IRQ_ENABLED 0x06
190 #define RESPONSE_PIGGYBACKED 0x07
191 #define RESPONSE_NO_INTERRUPT 0x08
192 #define RESPONSE_PIG_DISABLED 0x09
193 #define RESPONSE_PIG_ENABLED 0x0A
194 #define SD_ERROR_1BIT_TIMEOUT 0x01
195 #define SD_ERROR_4BIT_TIMEOUT 0x02
196 #define SD_ERROR_1BIT_CRC_WRONG 0x03
197 #define SD_ERROR_4BIT_CRC_WRONG 0x04
198 #define SD_ERROR_1BIT_CRC_ERROR 0x05
199 #define SD_ERROR_4BIT_CRC_ERROR 0x06
200 #define SD_ERROR_NO_CMD_ENDBIT 0x07
201 #define SD_ERROR_NO_1BIT_DATEND 0x08
202 #define SD_ERROR_NO_4BIT_DATEND 0x09
203 #define SD_ERROR_1BIT_UNEXPECTED_TIMEOUT 0x0A
204 #define SD_ERROR_4BIT_UNEXPECTED_TIMEOUT 0x0B
205 #define SD_ERROR_ILLEGAL_COMMAND 0x0C
206 #define SD_ERROR_NO_DEVICE 0x0D
207 #define SD_ERROR_TRANSFER_LENGTH 0x0E
208 #define SD_ERROR_1BIT_DATA_TIMEOUT 0x0F
209 #define SD_ERROR_4BIT_DATA_TIMEOUT 0x10
210 #define SD_ERROR_ILLEGAL_STATE 0x11
211 #define SD_ERROR_UNKNOWN_ERROR 0x12
212 #define SD_ERROR_RESERVED_ERROR 0x13
213 #define SD_ERROR_INVALID_FUNCTION 0x14
214 #define SD_ERROR_OUT_OF_RANGE 0x15
215 #define SD_ERROR_STAT_CMD 0x16
216 #define SD_ERROR_STAT_DATA 0x17
217 #define SD_ERROR_STAT_CMD_TIMEOUT 0x18
218 #define SD_ERROR_SDCRDY_STUCK 0x19
219 #define SD_ERROR_UNHANDLED 0x1A
220 #define SD_ERROR_OVERRUN 0x1B
221 #define SD_ERROR_PIO_TIMEOUT 0x1C
223 #define FUN(c) (0x000007 & (c->arg>>28))
224 #define REG(c) (0x01FFFF & (c->arg>>9))
226 static bool limit_speed_to_24_MHz;
228 MODULE_PARM_DESC(limit_speed_to_24_MHz,
"Limit Max SDIO Clock Speed to 24 MHz");
230 static bool pad_input_to_usb_pkt;
233 "Pad USB data input transfers to whole USB Packet");
235 static bool disable_offload_processing;
239 static bool force_1_bit_data_xfers;
242 "Force SDIO Data Transfers to 1-bit Mode");
244 static bool force_polling_for_irqs;
246 MODULE_PARM_DESC(force_polling_for_irqs,
"Force Polling for SDIO interrupts");
248 static int firmware_irqpoll_timeout = 1024;
250 MODULE_PARM_DESC(firmware_irqpoll_timeout,
"VUB300 firmware irqpoll timeout");
252 static int force_max_req_size = 128;
256 #ifdef SMSC_DEVELOPMENT_BOARD
257 static int firmware_rom_wait_states = 0x04;
259 static int firmware_rom_wait_states = 0x1C;
264 "ROM wait states byte=RRRIIEEE (Reserved Internal External)");
266 #define ELAN_VENDOR_ID 0x2201
267 #define VUB300_VENDOR_ID 0x0424
268 #define VUB300_PRODUCT_ID 0x012C
284 if (!interface->cur_altsetting)
286 return interface->cur_altsetting->desc.bInterfaceNumber;
329 #define MAXREGS (1<<MAXREGBITS)
330 #define MAXREGMASK (MAXREGS-1)
358 #define kref_to_vub300_mmc_host(d) container_of(d, struct vub300_mmc_host, kref)
359 #define SET_TRANSFER_PSEUDOCODE 21
360 #define SET_INTERRUPT_PSEUDOCODE 20
361 #define SET_FAILURE_MODE 18
362 #define SET_ROM_WAIT_STATES 16
363 #define SET_IRQ_ENABLE 13
364 #define SET_CLOCK_SPEED 11
365 #define SET_FUNCTION_BLOCK_SIZE 9
366 #define SET_SD_DATA_MODE 6
367 #define SET_SD_POWER 4
368 #define ENTER_DFU_MODE 3
369 #define GET_HC_INF0 1
370 #define GET_SYSTEM_PORT_STATUS 0
372 static void vub300_delete(
struct kref *
kref)
390 kref_get(&vub300->
kref);
404 kref_put(&vub300->
kref, vub300_delete);
410 kref_get(&vub300->
kref);
424 kref_put(&vub300->
kref, vub300_delete);
430 kref_get(&vub300->
kref);
444 kref_put(&vub300->
kref, vub300_delete);
448 static void irqpoll_res_completed(
struct urb *
urb)
456 static void irqpoll_out_completed(
struct urb *urb)
468 &vub300->
resp,
sizeof(vub300->
resp),
469 irqpoll_res_completed, vub300);
484 int timeout = 0xFFFF & (0x0001FFFF - firmware_irqpoll_timeout);
489 vub300->
cmnd.
poll.poll_timeout_lsb = 0xFF & (unsigned)timeout;
490 vub300->
cmnd.
poll.poll_timeout_msb = 0xFF & (unsigned)(timeout >> 8);
493 , &vub300->
cmnd,
sizeof(vub300->
cmnd)
494 , irqpoll_out_completed, vub300);
498 vub300_queue_poll_work(vub300, 1);
509 int new_card_present =
513 if (new_card_present && !old_card_present) {
517 if (disable_offload_processing)
523 }
else if (!new_card_present && old_card_present) {
532 static void __add_offloaded_reg_to_fifo(
struct vub300_mmc_host *vub300,
534 *register_access,
u8 func)
536 u8 r = vub300->
fn[
func].offload_point + vub300->
fn[
func].offload_count;
539 vub300->
fn[
func].offload_count += 1;
552 while (0 < regs-- && 1 == vub300->
sdio_register[i].activate) {
567 __add_offloaded_reg_to_fifo(vub300, register_access, func);
584 new_system_port_status(vub300);
597 mmc_signal_sdio_irq(vub300->
mmc);
605 check_vub300_port_status(vub300);
609 new_system_port_status(vub300);
611 vub300_queue_poll_work(vub300,
HZ / 5);
615 int offloaded_data_length = vub300->
resp.
common.header_size - 3;
616 int register_count = offloaded_data_length >> 3;
618 while (register_count--) {
619 add_offloaded_reg(vub300, &vub300->
resp.
irq.reg[ri]);
624 mmc_signal_sdio_irq(vub300->
mmc);
633 int offloaded_data_length = vub300->
resp.
common.header_size - 3;
634 int register_count = offloaded_data_length >> 3;
636 while (register_count--) {
637 add_offloaded_reg(vub300, &vub300->
resp.
irq.reg[ri]);
642 mmc_signal_sdio_irq(vub300->
mmc);
652 vub300_queue_poll_work(vub300, 1);
665 send_irqpoll(vub300);
670 }
else if (commretval == 0) {
674 }
else if (commretval < 0) {
675 vub300_queue_poll_work(vub300, 1);
677 __vub300_irqpoll_response(vub300);
689 kref_put(&vub300->
kref, vub300_delete);
694 vub300_queue_poll_work(vub300, 1);
703 mmc_signal_sdio_irq(vub300->
mmc);
712 kref_put(&vub300->
kref, vub300_delete);
715 static void vub300_deadwork_thread(
struct work_struct *work)
720 kref_put(&vub300->
kref, vub300_delete);
732 check_vub300_port_status(vub300);
733 }
else if (vub300->
mmc && vub300->
mmc->card &&
742 check_vub300_port_status(vub300);
746 kref_put(&vub300->
kref, vub300_delete);
749 static void vub300_inactivity_timer_expired(
unsigned long data)
753 kref_put(&vub300->
kref, vub300_delete);
754 }
else if (vub300->
cmd) {
757 vub300_queue_dead_work(vub300);
764 switch (error_code) {
798 static void command_res_completed(
struct urb *urb)
808 }
else if (!vub300->
data) {
810 }
else if (vub300->
resp.
common.header_type != 0x02) {
815 }
else if (vub300->
urb) {
817 vub300_response_error(vub300->
resp.
error.error_code);
821 vub300_response_error(vub300->
resp.
error.error_code);
827 static void command_out_completed(
struct urb *urb)
837 &vub300->
resp,
sizeof(vub300->
resp),
838 command_res_completed, vub300);
859 static void snoop_block_size_and_bus_width(
struct vub300_mmc_host *vub300,
862 if ((0xFBFFFE00 & cmd_arg) == 0x80022200)
863 vub300->
fbs[1] = (cmd_arg << 8) | (0x00FF & vub300->
fbs[1]);
864 else if ((0xFBFFFE00 & cmd_arg) == 0x80022000)
865 vub300->
fbs[1] = (0xFF & cmd_arg) | (0xFF00 & vub300->
fbs[1]);
866 else if ((0xFBFFFE00 & cmd_arg) == 0x80042200)
867 vub300->
fbs[2] = (cmd_arg << 8) | (0x00FF & vub300->
fbs[2]);
868 else if ((0xFBFFFE00 & cmd_arg) == 0x80042000)
869 vub300->
fbs[2] = (0xFF & cmd_arg) | (0xFF00 & vub300->
fbs[2]);
870 else if ((0xFBFFFE00 & cmd_arg) == 0x80062200)
871 vub300->
fbs[3] = (cmd_arg << 8) | (0x00FF & vub300->
fbs[3]);
872 else if ((0xFBFFFE00 & cmd_arg) == 0x80062000)
873 vub300->
fbs[3] = (0xFF & cmd_arg) | (0xFF00 & vub300->
fbs[3]);
874 else if ((0xFBFFFE00 & cmd_arg) == 0x80082200)
875 vub300->
fbs[4] = (cmd_arg << 8) | (0x00FF & vub300->
fbs[4]);
876 else if ((0xFBFFFE00 & cmd_arg) == 0x80082000)
877 vub300->
fbs[4] = (0xFF & cmd_arg) | (0xFF00 & vub300->
fbs[4]);
878 else if ((0xFBFFFE00 & cmd_arg) == 0x800A2200)
879 vub300->
fbs[5] = (cmd_arg << 8) | (0x00FF & vub300->
fbs[5]);
880 else if ((0xFBFFFE00 & cmd_arg) == 0x800A2000)
881 vub300->
fbs[5] = (0xFF & cmd_arg) | (0xFF00 & vub300->
fbs[5]);
882 else if ((0xFBFFFE00 & cmd_arg) == 0x800C2200)
883 vub300->
fbs[6] = (cmd_arg << 8) | (0x00FF & vub300->
fbs[6]);
884 else if ((0xFBFFFE00 & cmd_arg) == 0x800C2000)
885 vub300->
fbs[6] = (0xFF & cmd_arg) | (0xFF00 & vub300->
fbs[6]);
886 else if ((0xFBFFFE00 & cmd_arg) == 0x800E2200)
887 vub300->
fbs[7] = (cmd_arg << 8) | (0x00FF & vub300->
fbs[7]);
888 else if ((0xFBFFFE00 & cmd_arg) == 0x800E2000)
889 vub300->
fbs[7] = (0xFF & cmd_arg) | (0xFF00 & vub300->
fbs[7]);
890 else if ((0xFBFFFE03 & cmd_arg) == 0x80000E00)
892 else if ((0xFBFFFE03 & cmd_arg) == 0x80000E02)
909 if (0x00000000 == (0x00000003 & cmd->
arg))
911 else if (0x00000002 == (0x00000003 & cmd->
arg))
915 "unexpected ACMD6 bus_width=%d\n",
916 0x00000003 & cmd->
arg);
1013 vub300->
fbs[i] = 0xFFFF & cmd->
arg;
1047 snoop_block_size_and_bus_width(vub300, cmd->
arg);
1073 vub300->
cmnd.
head.header_size = 20;
1074 vub300->
cmnd.
head.header_type = 0x00;
1076 vub300->
cmnd.
head.command_type = 0x00;
1077 vub300->
cmnd.
head.response_type = response_type;
1084 int fn = 0x7 & (cmd->
arg >> 28);
1085 vub300->
cmnd.
head.block_count[0] = 0;
1086 vub300->
cmnd.
head.block_count[1] = 0;
1087 vub300->
cmnd.
head.block_size[0] = (vub300->
fbs[
fn] >> 8) & 0xFF;
1088 vub300->
cmnd.
head.block_size[1] = (vub300->
fbs[
fn] >> 0) & 0xFF;
1089 vub300->
cmnd.
head.command_type = 0x00;
1090 vub300->
cmnd.
head.transfer_size[0] = 0;
1091 vub300->
cmnd.
head.transfer_size[1] = 0;
1092 vub300->
cmnd.
head.transfer_size[2] = 0;
1093 vub300->
cmnd.
head.transfer_size[3] = 0;
1095 vub300->
cmnd.
head.block_count[0] = 0;
1096 vub300->
cmnd.
head.block_count[1] = 0;
1097 vub300->
cmnd.
head.block_size[0] = (vub300->
fbs[0] >> 8) & 0xFF;
1098 vub300->
cmnd.
head.block_size[1] = (vub300->
fbs[0] >> 0) & 0xFF;
1099 vub300->
cmnd.
head.command_type = 0x00;
1100 vub300->
cmnd.
head.transfer_size[0] = 0;
1101 vub300->
cmnd.
head.transfer_size[1] = 0;
1102 vub300->
cmnd.
head.transfer_size[2] = 0;
1103 vub300->
cmnd.
head.transfer_size[3] = 0;
1104 }
else if (cmd->
opcode == 53) {
1105 int fn = 0x7 & (cmd->
arg >> 28);
1106 if (0x08 & vub300->
cmnd.
head.arguments[0]) {
1108 (data->
blocks >> 8) & 0xFF;
1110 (data->
blocks >> 0) & 0xFF;
1112 (data->
blksz >> 8) & 0xFF;
1114 (data->
blksz >> 0) & 0xFF;
1116 vub300->
cmnd.
head.block_count[0] = 0;
1117 vub300->
cmnd.
head.block_count[1] = 0;
1125 vub300->
cmnd.
head.transfer_size[0] =
1127 vub300->
cmnd.
head.transfer_size[1] =
1129 vub300->
cmnd.
head.transfer_size[2] =
1131 vub300->
cmnd.
head.transfer_size[3] =
1134 vub300->
cmnd.
head.block_count[0] = 0;
1135 vub300->
cmnd.
head.block_count[1] = 0;
1140 vub300->
cmnd.
head.block_size[0] = (data->
blksz >> 8) & 0xFF;
1141 vub300->
cmnd.
head.block_size[1] = (data->
blksz >> 0) & 0xFF;
1144 vub300->
cmnd.
head.transfer_size[0] =
1146 vub300->
cmnd.
head.transfer_size[1] =
1148 vub300->
cmnd.
head.transfer_size[2] =
1150 vub300->
cmnd.
head.transfer_size[3] =
1153 vub300->
cmnd.
head.block_count[0] = 0;
1154 vub300->
cmnd.
head.block_count[1] = 0;
1159 (vub300->
cmnd.
head.block_size[0] << 8);
1162 vub300->
cmnd.
head.block_boundary[0] =
1163 (block_boundary >> 8) & 0xFF;
1164 vub300->
cmnd.
head.block_boundary[1] =
1165 (block_boundary >> 0) & 0xFF;
1167 vub300->
cmnd.
head.block_boundary[0] = 0;
1168 vub300->
cmnd.
head.block_boundary[1] = 0;
1172 &vub300->
cmnd,
sizeof(vub300->
cmnd),
1173 command_out_completed, vub300);
1188 static void vub300_sg_timed_out(
unsigned long data)
1197 static u16 roundup_to_multiple_of_64(
u16 number)
1199 return 0xFFC0 & (0x3F + number);
1205 static void __download_offload_pseudocode(
struct vub300_mmc_host *vub300,
1208 u8 register_count = 0;
1210 u16 interrupt_size = 0;
1211 const u8 *data = fw->
data;
1214 dev_info(&vub300->
udev->dev,
"using %s for SDIO offload processing\n",
1218 }
while (size-- && c);
1223 "corrupt offload pseudocode in firmware %s\n",
1229 interrupt_size += *data++;
1231 interrupt_size <<= 8;
1232 interrupt_size += *data++;
1234 if (interrupt_size < size) {
1235 u16 xfer_length = roundup_to_multiple_of_64(interrupt_size);
1239 memcpy(xfer_buffer, data, interrupt_size);
1240 memset(xfer_buffer + interrupt_size, 0,
1241 xfer_length - interrupt_size);
1242 size -= interrupt_size;
1243 data += interrupt_size;
1246 usb_sndctrlpipe(vub300->
udev, 0),
1250 xfer_buffer, xfer_length,
HZ);
1254 "SDIO pseudocode download failed",
1260 "not enough memory for xfer buffer to send"
1261 " INTERRUPT_PSEUDOCODE for %s %s\n", fw->
data,
1264 "SDIO interrupt pseudocode download failed",
1270 "corrupt interrupt pseudocode in firmware %s %s\n",
1282 u16 xfer_length = roundup_to_multiple_of_64(ts);
1286 memcpy(xfer_buffer, data, ts);
1287 memset(xfer_buffer + ts, 0,
1293 usb_sndctrlpipe(vub300->
udev, 0),
1297 xfer_buffer, xfer_length,
HZ);
1301 "SDIO pseudocode download failed",
1307 "not enough memory for xfer buffer to send"
1308 " TRANSFER_PSEUDOCODE for %s %s\n", fw->
data,
1311 "SDIO transfer pseudocode download failed",
1317 "corrupt transfer pseudocode in firmware %s %s\n",
1323 register_count += *data++;
1325 if (register_count * 4 == size) {
1329 unsigned int func_num = 0;
1332 func_num += *data++;
1335 func_num += *data++;
1338 func_num += *data++;
1346 "initialized %d dynamic pseudocode registers\n",
1351 "corrupt dynamic registers in firmware %s\n",
1363 static void download_offload_pseudocode(
struct vub300_mmc_host *vub300)
1369 "vub_%04X%04X", card->
cis.vendor, card->
cis.device);
1372 for (n = 0; n < sdio_funcs; n++) {
1375 sizeof(vub300->
vub_name) - l,
"_%04X%04X",
1379 dev_info(&vub300->
udev->dev,
"requesting offload firmware %s\n",
1388 "no SDIO offload firmware found",
1391 __download_offload_pseudocode(vub300, fw);
1395 __download_offload_pseudocode(vub300, fw);
1400 static void vub300_usb_bulk_msg_completion(
struct urb *urb)
1406 unsigned int pipe,
void *data,
int len,
1407 int *actual_length,
int timeout_msecs)
1410 struct usb_device *usb_dev = vub300->
udev;
1416 usb_fill_bulk_urb(vub300->
urb, usb_dev, pipe, data, len,
1417 vub300_usb_bulk_msg_completion,
NULL);
1418 init_completion(&
done);
1420 vub300->
urb->actual_length = 0;
1429 retval = vub300->
urb->status;
1432 *actual_length = vub300->
urb->actual_length;
1442 int linear_length = vub300->
datasize;
1444 ((511 + linear_length) >> 9) << 9 :
1445 ((63 + linear_length) >> 6) << 6;
1446 if ((padded_length == linear_length) || !pad_input_to_usb_pkt) {
1462 (linear_length / 16384));
1472 return linear_length;
1479 unsigned pipe = usb_rcvbulkpipe(vub300->
udev,
1481 int actual_length = 0;
1482 result = vub300_usb_bulk_msg(vub300, pipe, buf,
1483 padded_length, &actual_length,
1484 2000 + (padded_length / 16384));
1490 }
else if (actual_length < linear_length) {
1500 return linear_length;
1515 int linear_length = vub300->
datasize;
1516 int modulo_64_length = linear_length & 0x003F;
1517 int modulo_512_length = linear_length & 0x01FF;
1518 if (linear_length < 64) {
1526 result = vub300_usb_bulk_msg(vub300, pipe, vub300->
padded_buffer,
1528 &actual_length, 2000 +
1540 int padded_length = ((63 + linear_length) >> 6) << 6;
1547 memset(buf + linear_length, 0,
1548 padded_length - linear_length);
1550 vub300_usb_bulk_msg(vub300, pipe, buf,
1551 padded_length, &actual_length,
1552 2000 + padded_length / 16384);
1566 unsigned char buf[64 * 4];
1579 linear_length / 16384);
1595 return linear_length;
1604 int msec_timeout = 1000 + data_length / 4;
1608 if (respretval == 0) {
1619 usb_unlock_device(vub300->
udev);
1621 }
else if (respretval < 0) {
1625 cmd->
error = respretval;
1626 }
else if (cmd->
error) {
1639 }
else if (vub300->
resp.
common.header_type == 0x00) {
1646 vub300_response_error(vub300->
resp.
error.error_code);
1650 int offloaded_data_length =
1653 int register_count = offloaded_data_length >> 3;
1655 while (register_count--) {
1656 add_offloaded_reg(vub300, &vub300->
resp.
pig.reg[ri]);
1664 int offloaded_data_length =
1667 int register_count = offloaded_data_length >> 3;
1669 while (register_count--) {
1670 add_offloaded_reg(vub300, &vub300->
resp.
pig.reg[ri]);
1678 vub300_queue_poll_work(vub300, 0);
1689 int offloaded_data_length =
1692 int register_count = offloaded_data_length >> 3;
1694 while (register_count--) {
1695 add_offloaded_reg(vub300, &vub300->
resp.
pig.reg[ri]);
1703 vub300_queue_poll_work(vub300, 0);
1718 static void construct_request_response(
struct vub300_mmc_host *vub300,
1722 int less_cmd = (17 ==
resp_len) ? resp_len : resp_len - 1;
1723 int bytes = 3 & less_cmd;
1724 int words = less_cmd >> 2;
1727 cmd->
resp[words] = (r[1 + (words << 2)] << 24)
1728 | (r[2 + (words << 2)] << 16)
1729 | (r[3 + (words << 2)] << 8);
1730 }
else if (bytes == 2) {
1731 cmd->
resp[words] = (r[1 + (words << 2)] << 24)
1732 | (r[2 + (words << 2)] << 16);
1733 }
else if (bytes == 1) {
1734 cmd->
resp[words] = (r[1 + (words << 2)] << 24);
1736 while (words-- > 0) {
1737 cmd->
resp[words] = (r[1 + (words << 2)] << 24)
1738 | (r[2 + (words << 2)] << 16)
1739 | (r[3 + (words << 2)] << 8)
1740 | (r[4 + (words << 2)] << 0);
1742 if ((cmd->
opcode == 53) && (0x000000FF & cmd->
resp[0]))
1743 cmd->
resp[0] &= 0xFFFFFF00;
1747 static void vub300_cmndwork_thread(
struct work_struct *work)
1752 kref_put(&vub300->
kref, vub300_delete);
1768 }
else if (0 == vub300->
mmc->card->sdio_funcs) {
1772 download_offload_pseudocode(vub300);
1774 send_command(vub300);
1778 data_length = __command_read_data(vub300, cmd, data);
1780 data_length = __command_write_data(vub300, cmd, data);
1781 __vub300_command_response(vub300, cmd, data, data_length);
1787 check_vub300_port_status(vub300);
1790 kref_put(&vub300->
kref, vub300_delete);
1793 construct_request_response(vub300, cmd);
1796 kref_put(&vub300->
kref, vub300_delete);
1807 u8 cmd0 = 0xFF & (cmd->
arg >> 24);
1808 u8 cmd1 = 0xFF & (cmd->
arg >> 16);
1809 u8 cmd2 = 0xFF & (cmd->
arg >> 8);
1810 u8 cmd3 = 0xFF & (cmd->
arg >> 0);
1818 cmd->
resp[1] = checksum << 24;
1823 vub300->
fn[Function].offload_point += 1;
1824 vub300->
fn[Function].offload_count -= 1;
1829 u8 register_count = vub300->
fn[Function].offload_count - 1;
1830 u32 register_point = vub300->
fn[Function].offload_point + 1;
1831 while (0 < register_count) {
1834 &vub300->
fn[Function].reg[
point];
1840 cmd->
resp[1] = checksum << 24;
1845 vub300->
fn[Function].offload_point +=
delta;
1846 vub300->
fn[Function].offload_count -=
delta;
1850 register_point += 1;
1851 register_count -= 1;
1860 static int satisfy_request_from_offloaded_data(
struct vub300_mmc_host *vub300,
1868 while (0 < regs--) {
1873 }
else if ((0x80000000 & cmd->
arg) == 0x80000000) {
1887 cmd->
resp[1] = checksum << 24;
1888 cmd->
resp[0] = (rsp0 << 24)
1901 else if (vub300->
fn[func].offload_count == 0)
1904 return examine_cyclic_buffer(vub300, cmd, func);
1937 kref_get(&vub300->
kref);
1945 satisfy_request_from_offloaded_data(vub300, cmd)) {
1948 kref_put(&vub300->
kref, vub300_delete);
1959 vub300_queue_cmnd_work(vub300);
1961 kref_put(&vub300->
kref, vub300_delete);
1976 int buf_array_size = 8;
1979 if (ios->
clock >= 48000000)
1981 else if (ios->
clock >= 24000000)
1983 else if (ios->
clock >= 20000000)
1985 else if (ios->
clock >= 15000000)
1987 else if (ios->
clock >= 200000)
1994 for (i = 0; i < buf_array_size; i++) {
2003 0x00, 0x00, buf, buf_array_size,
HZ);
2006 " %dkHz failed with retval=%d\n", kHzClock, retval);
2009 " %dkHz\n", kHzClock);
2013 static void vub300_mmc_set_ios(
struct mmc_host *mmc,
struct mmc_ios *ios)
2018 kref_get(&vub300->
kref);
2025 0x0000, 0x0000,
NULL, 0,
HZ);
2032 0x0001, 0x0000,
NULL, 0,
HZ);
2038 __set_clock_speed(vub300, buf, ios);
2045 kref_put(&vub300->
kref, vub300_delete);
2048 static int vub300_mmc_get_ro(
struct mmc_host *mmc)
2054 static void vub300_enable_sdio_irq(
struct mmc_host *mmc,
int enable)
2059 kref_get(&vub300->
kref);
2064 mmc_signal_sdio_irq(vub300->
mmc);
2068 vub300_queue_poll_work(vub300, 0);
2073 vub300_queue_poll_work(vub300, 0);
2079 kref_put(&vub300->
kref, vub300_delete);
2085 dev_info(&vub300->
udev->dev,
"NO host QUIRKS for this card\n");
2089 .request = vub300_mmc_request,
2090 .set_ios = vub300_mmc_set_ios,
2091 .get_ro = vub300_mmc_get_ro,
2092 .enable_sdio_irq = vub300_enable_sdio_irq,
2100 struct usb_host_interface *iface_desc;
2101 struct usb_device *
udev =
usb_get_dev(interface_to_usbdev(interface));
2104 struct urb *command_out_urb;
2105 struct urb *command_res_urb;
2110 usb_string(udev, udev->descriptor.iManufacturer, manufacturer,
2111 sizeof(manufacturer));
2112 usb_string(udev, udev->descriptor.iProduct, product,
sizeof(product));
2113 usb_string(udev, udev->descriptor.iSerialNumber, serial_number,
2114 sizeof(serial_number));
2115 dev_info(&udev->dev,
"probing VID:PID(%04X:%04X) %s %s %s\n",
2116 udev->descriptor.idVendor, udev->descriptor.idProduct,
2117 manufacturer, product, serial_number);
2119 if (!command_out_urb) {
2121 dev_err(&udev->dev,
"not enough memory for command_out_urb\n");
2125 if (!command_res_urb) {
2127 dev_err(&udev->dev,
"not enough memory for command_res_urb\n");
2134 dev_err(&udev->dev,
"not enough memory for the mmc_host\n");
2139 if (!force_1_bit_data_xfers)
2141 if (!force_polling_for_irqs)
2149 if (limit_speed_to_24_MHz) {
2152 mmc->
f_max = 24000000;
2153 dev_info(&udev->dev,
"limiting SDIO speed to 24_MHz\n");
2157 mmc->
f_max = 48000000;
2159 mmc->
f_min = 200000;
2163 if (force_max_req_size)
2186 mmc->
ops = &vub300_mmc_ops;
2187 vub300 = mmc_priv(mmc);
2191 vub300->
cmnd.
head.block_size[0] = 0x00;
2192 vub300->
cmnd.
head.block_size[1] = 0x00;
2202 vub300->
fn[
i].offload_point = 0;
2203 vub300->
fn[
i].offload_count = 0;
2214 vub300->
udev = udev;
2222 vub300->
fbs[i] = 512;
2234 iface_desc = interface->cur_altsetting;
2235 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++
i) {
2237 &iface_desc->endpoint[
i].desc;
2239 "vub300 testing %s EndPoint(%d) %02X\n",
2240 usb_endpoint_is_bulk_in(endpoint) ?
"BULK IN" :
2241 usb_endpoint_is_bulk_out(endpoint) ?
"BULK OUT" :
2245 if (usb_endpoint_is_bulk_in(endpoint)) {
2255 " unexpected bulk_in endpoint");
2257 }
else if (usb_endpoint_is_bulk_out(endpoint)) {
2267 " unexpected bulk_out endpoint");
2271 "vub300 ignoring EndPoint(%d) %02X", i,
2279 " using EndPoints %02X %02X %02X %02X\n",
2286 "Could not find two sets of bulk-in/out endpoint pairs\n");
2294 0x0000, 0x0000, &vub300->
hc_info,
2302 firmware_rom_wait_states, 0x0000,
NULL, 0,
HZ);
2306 "operating_mode = %s %s %d MHz %s %d byte USB packets\n",
2309 mmc->
f_max / 1000000,
2310 pad_input_to_usb_pkt ?
"padding input data to" :
"with",
2328 usb_set_intfdata(interface, vub300);
2332 kref_init(&vub300->
kref);
2336 kref_get(&vub300->
kref);
2344 "USB vub300 remote SDIO host controller[%d]"
2345 "connected with SD/SDIO card inserted\n",
2346 interface_to_InterfaceNumber(interface));
2349 "USB vub300 remote SDIO host controller[%d]"
2350 "connected with no SD/SDIO card inserted\n",
2351 interface_to_InterfaceNumber(interface));
2368 static void vub300_disconnect(
struct usb_interface *interface)
2371 if (!vub300 || !vub300->
mmc) {
2378 int ifnum = interface_to_InterfaceNumber(interface);
2379 usb_set_intfdata(interface,
NULL);
2382 kref_put(&vub300->
kref, vub300_delete);
2384 pr_info(
"USB vub300 remote SDIO host controller[%d]"
2385 " now disconnected", ifnum);
2395 if (!vub300 || !vub300->
mmc) {
2407 if (!vub300 || !vub300->
mmc) {
2416 #define vub300_suspend NULL
2417 #define vub300_resume NULL
2435 static struct usb_driver vub300_driver = {
2437 .probe = vub300_probe,
2438 .disconnect = vub300_disconnect,
2441 .pre_reset = vub300_pre_reset,
2442 .post_reset = vub300_post_reset,
2443 .id_table = vub300_table,
2444 .supports_autosuspend = 1,
2447 static int __init vub300_init(
void)
2451 pr_info(
"VUB300 Driver rom wait states = %02X irqpoll timeout = %04X",
2452 firmware_rom_wait_states, 0x0FFFF & firmware_irqpoll_timeout);
2454 if (!cmndworkqueue) {
2455 pr_err(
"not enough memory for the REQUEST workqueue");
2460 if (!pollworkqueue) {
2461 pr_err(
"not enough memory for the IRQPOLL workqueue");
2466 if (!deadworkqueue) {
2467 pr_err(
"not enough memory for the EXPIRED workqueue");
2471 result = usb_register(&vub300_driver);
2473 pr_err(
"usb_register failed. Error number %d", result);
2487 static void __exit vub300_exit(
void)