29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/slab.h>
35 #include <linux/netdevice.h>
78 #define MODEL_8385 0x04
79 #define MODEL_8686 0x0b
80 #define MODEL_8688 0x10
83 {
MODEL_8385,
"libertas/sd8385_helper.bin",
"libertas/sd8385.bin" },
84 {
MODEL_8385,
"sd8385_helper.bin",
"sd8385.bin" },
85 {
MODEL_8686,
"libertas/sd8686_v9_helper.bin",
"libertas/sd8686_v9.bin" },
86 {
MODEL_8686,
"libertas/sd8686_v8_helper.bin",
"libertas/sd8686_v8.bin" },
87 {
MODEL_8686,
"sd8686_helper.bin",
"sd8686.bin" },
88 {
MODEL_8688,
"libertas/sd8688_helper.bin",
"libertas/sd8688.bin" },
89 {
MODEL_8688,
"sd8688_helper.bin",
"sd8688.bin" },
184 switch (card->
model) {
187 rx_len = if_sdio_read_scratch(card, &ret);
206 static int if_sdio_handle_cmd(
struct if_sdio_card *card,
231 spin_unlock_irqrestore(&card->
priv->driver_lock, flags);
240 static int if_sdio_handle_data(
struct if_sdio_card *card,
241 u8 *buffer,
unsigned size)
266 memcpy(data, buffer, size);
278 static int if_sdio_handle_event(
struct if_sdio_card *card,
279 u8 *buffer,
unsigned size)
300 event = buffer[3] << 24;
301 event |= buffer[2] << 16;
302 event |= buffer[1] << 8;
303 event |= buffer[0] << 0;
315 static int if_sdio_wait_status(
struct if_sdio_card *card,
const u8 condition)
326 if ((status & condition) == condition)
335 static int if_sdio_card_to_host(
struct if_sdio_card *card)
342 size = if_sdio_read_rx_len(card, &ret);
347 lbs_deb_sdio(
"invalid packet size (%d bytes) from firmware\n",
368 chunk = card->buffer[0] | (card->buffer[1] << 8);
369 type = card->buffer[2] | (card->buffer[3] << 8);
372 (
int)type, (
int)chunk);
376 (
int)chunk, (
int)size);
383 (
int)chunk, (
int)size);
388 ret = if_sdio_handle_cmd(card, card->buffer + 4, chunk - 4);
393 ret = if_sdio_handle_data(card, card->buffer + 4, chunk - 4);
398 ret = if_sdio_handle_event(card, card->buffer + 4, chunk - 4);
411 pr_err(
"problem fetching packet from firmware\n");
434 spin_unlock_irqrestore(&card->
lock, flags);
444 packet->buffer, packet->
nb);
448 pr_err(
"error %d sending packet to firmware\n", ret);
462 #define FW_DL_READY_STATUS (IF_SDIO_IO_RDY | IF_SDIO_DL_RDY)
464 static int if_sdio_prog_helper(
struct if_sdio_card *card,
468 unsigned long timeout;
501 chunk_size =
min(size, (
size_t)60);
504 memcpy(chunk_buffer + 4, firmware, chunk_size);
513 firmware += chunk_size;
518 memset(chunk_buffer, 0, 4);
557 pr_err(
"failed to load helper firmware\n");
567 unsigned long timeout;
571 size_t size, req_size;
611 if (req_size & 0x01) {
621 chunk_size =
min(req_size, (
size_t)512);
623 memcpy(chunk_buffer, firmware, chunk_size);
629 chunk_buffer,
roundup(chunk_size, 32));
633 firmware += chunk_size;
635 req_size -= chunk_size;
648 scratch = if_sdio_read_scratch(card, &ret);
671 pr_err(
"failed to load firmware\n");
677 static void if_sdio_do_prog_firmware(
struct lbs_private *priv,
int ret,
678 const struct firmware *helper,
679 const struct firmware *mainfw)
684 pr_err(
"failed to find firmware (%d)\n", ret);
688 ret = if_sdio_prog_helper(card, helper);
694 ret = if_sdio_prog_real(card, mainfw);
699 if_sdio_finish_power_on(card);
706 static int if_sdio_prog_firmware(
struct if_sdio_card *card)
721 scratch = if_sdio_read_scratch(card, &ret);
743 if_sdio_finish_power_on(card);
747 if_sdio_finish_power_on(card);
752 fw_table, if_sdio_do_prog_firmware);
764 static void if_sdio_finish_power_on(
struct if_sdio_card *card)
779 card->
rx_unit = if_sdio_read_rx_unit(card);
818 netdev_alert(priv->
dev,
"CMD_FUNC_INIT cmd failed\n");
826 if_sdio_power_off(card);
831 pm_runtime_put_noidle(&func->
dev);
887 ret = if_sdio_prog_firmware(card);
921 static int if_sdio_host_to_card(
struct lbs_private *priv,
959 packet->buffer[0] = (nb + 4) & 0xff;
960 packet->buffer[1] = ((nb + 4) >> 8) & 0xff;
961 packet->buffer[2] =
type;
962 packet->buffer[3] = 0;
964 memcpy(packet->buffer + 4, buf, nb);
988 spin_unlock_irqrestore(&card->
lock, flags);
1000 static int if_sdio_enter_deep_sleep(
struct lbs_private *priv)
1011 netdev_err(priv->
dev,
"DEEP_SLEEP cmd failed\n");
1017 static int if_sdio_exit_deep_sleep(
struct lbs_private *priv)
1027 netdev_err(priv->
dev,
"sdio_writeb failed!\n");
1034 static int if_sdio_reset_deep_sleep_wakeup(
struct lbs_private *priv)
1044 netdev_err(priv->
dev,
"sdio_writeb failed!\n");
1052 static struct mmc_host *reset_host;
1054 static void if_sdio_reset_card_worker(
struct work_struct *work)
1070 static DECLARE_WORK(card_reset_work, if_sdio_reset_card_worker);
1072 static void if_sdio_reset_card(
struct lbs_private *priv)
1079 reset_host = card->
func->card->host;
1083 static int if_sdio_power_save(
struct lbs_private *priv)
1090 ret = if_sdio_power_off(card);
1093 pm_runtime_put_sync(&card->
func->dev);
1098 static int if_sdio_power_restore(
struct lbs_private *priv)
1104 pm_runtime_get_sync(&card->
func->dev);
1106 r = if_sdio_power_on(card);
1119 static void if_sdio_interrupt(
struct sdio_func *func)
1143 card->
priv->is_activity_detected = 1;
1149 ret = if_sdio_card_to_host(card);
1160 static int if_sdio_probe(
struct sdio_func *func,
1171 for (i = 0;i < func->
card->num_info;i++) {
1173 "802.11 SDIO ID: %x", &model) == 1)
1176 "ID: %x", &model) == 1)
1178 if (!
strcmp(func->
card->info[i],
"IBIS Wireless SDIO Card")) {
1184 if (i == func->
card->num_info) {
1185 pr_err(
"unable to identify card model\n");
1194 card->
model = model;
1196 switch (card->
model) {
1228 "device = 0x%X, model = 0x%X, ioport = 0x%X\n",
1230 model, (
unsigned)card->
ioport);
1250 ret = if_sdio_power_on(card);
1252 goto err_activate_card;
1275 static void if_sdio_remove(
struct sdio_func *func)
1285 pm_runtime_get_noresume(&func->
dev);
1299 (
unsigned long) &
cmd))
1300 pr_alert(
"CMD_FUNC_SHUTDOWN cmd failed\n");
1321 static int if_sdio_suspend(
struct device *
dev)
1331 if (!lbs_iface_active(card->
priv))
1334 dev_info(dev,
"%s: suspend: PM flags = 0x%x\n",
1341 dev_info(dev,
"Suspend without wake params -- powering down card\n");
1346 dev_err(dev,
"%s: cannot remain alive while host is suspended\n",
1362 static int if_sdio_resume(
struct device *dev)
1375 static const struct dev_pm_ops if_sdio_pm_ops = {
1376 .suspend = if_sdio_suspend,
1377 .resume = if_sdio_resume,
1381 .name =
"libertas_sdio",
1382 .id_table = if_sdio_ids,
1383 .probe = if_sdio_probe,
1384 .remove = if_sdio_remove,
1386 .pm = &if_sdio_pm_ops,
1394 static int __init if_sdio_init_module(
void)
1413 static void __exit if_sdio_exit_module(
void)