20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24 #include <linux/module.h>
27 #include <linux/list.h>
28 #include <linux/netdevice.h>
29 #include <linux/slab.h>
96 spi_set_drvdata(card->
spi,
NULL);
100 #define MODEL_8385 0x04
101 #define MODEL_8686 0x0b
102 #define MODEL_8688 0x10
105 {
MODEL_8385,
"libertas/gspi8385_helper.bin",
"libertas/gspi8385.bin" },
106 {
MODEL_8385,
"libertas/gspi8385_hlp.bin",
"libertas/gspi8385.bin" },
107 {
MODEL_8686,
"libertas/gspi8686_v9_helper.bin",
"libertas/gspi8686_v9.bin" },
108 {
MODEL_8686,
"libertas/gspi8686_hlp.bin",
"libertas/gspi8686.bin" },
109 {
MODEL_8688,
"libertas/gspi8688_helper.bin",
"libertas/gspi8688.bin" },
145 static void spu_transaction_finish(
struct if_spi_card *card)
162 spi_message_init(&
m);
163 memset(®_trans, 0,
sizeof(reg_trans));
164 memset(&data_trans, 0,
sizeof(data_trans));
170 spu_transaction_init(card);
173 reg_trans.tx_buf = ®_out;
174 reg_trans.len =
sizeof(reg_out);
176 data_trans.tx_buf =
buf;
177 data_trans.len =
len;
179 spi_message_add_tail(®_trans, &
m);
180 spi_message_add_tail(&data_trans, &
m);
183 spu_transaction_finish(card);
192 return spu_write(card, reg, (
u8 *)&buff,
sizeof(
u16));
195 static inline int spu_reg_is_port_reg(
u16 reg)
223 spu_transaction_init(card);
225 spi_message_init(&
m);
226 memset(®_trans, 0,
sizeof(reg_trans));
227 memset(&dummy_trans, 0,
sizeof(dummy_trans));
228 memset(&data_trans, 0,
sizeof(data_trans));
231 reg_trans.tx_buf = ®_out;
232 reg_trans.len =
sizeof(reg_out);
233 spi_message_add_tail(®_trans, &
m);
239 dummy_trans.len = delay / 8;
240 spi_message_add_tail(&dummy_trans, &
m);
243 reg_trans.delay_usecs =
248 data_trans.rx_buf =
buf;
249 data_trans.len =
len;
250 spi_message_add_tail(&data_trans, &
m);
253 spu_transaction_finish(card);
263 ret = spu_read(card, reg, (
u8 *)&buf,
sizeof(buf));
278 err = spu_read(card, reg, (
u8 *)&buf,
sizeof(buf));
300 err = spu_read_u16(card, reg, &val);
304 if ((val & target_mask) == target)
312 pr_err(
"%s: timeout with val=%02x, target_mask=%02x, target=%02x\n",
313 __func__, val, target_mask, target);
326 for (
try = 0;
try < 4; ++
try) {
328 err = spu_read_u32(card, reg, &val);
338 static int spu_set_interrupt_mode(
struct if_spi_card *card,
339 int suppress_host_int,
348 if (suppress_host_int) {
385 static int spu_get_chip_revision(
struct if_spi_card *card,
386 u16 *card_id,
u8 *card_rev)
410 if ((rval & 0xF) != mode) {
411 pr_err(
"Can't read bus mode register\n");
417 static int spu_init(
struct if_spi_card *card,
int use_dummy_writes)
427 err = spu_set_bus_mode(card,
442 if (use_dummy_writes) {
444 err = spu_set_bus_mode(card,
453 "spu_port_delay=0x%04lx, spu_reg_delay=0x%04lx\n",
462 static int if_spi_prog_helper_firmware(
struct if_spi_card *card,
472 err = spu_set_interrupt_mode(card, 1, 0);
476 bytes_remaining = firmware->
size;
480 while (bytes_remaining > 0) {
500 memset(temp, 0,
sizeof(temp));
536 pr_err(
"failed to load helper firmware (err=%d)\n", err);
545 static int if_spi_prog_main_firmware_check_len(
struct if_spi_card *card,
559 pr_err(
"timed out waiting for host_int_status\n");
569 pr_err(
"firmware load device requested a larger transfer than we are prepared to handle (len = %d)\n",
583 static int if_spi_prog_main_firmware(
struct if_spi_card *card,
584 const struct firmware *firmware)
588 int bytes, crc_err = 0, err = 0;
594 err = spu_set_interrupt_mode(card, 1, 0);
600 netdev_err(priv->
dev,
601 "%s: timed out waiting for initial scratch reg = 0\n",
608 bytes = firmware->
size;
610 while ((len = if_spi_prog_main_firmware_check_len(card, &crc_err))) {
620 netdev_err(priv->
dev,
621 "Firmware load wants more bytes than we have to offer.\n");
627 pr_err(
"Too many CRC errors encountered in firmware load.\n");
655 if (bytes > prev_len) {
656 pr_err(
"firmware load wants fewer bytes than we have to offer\n");
663 pr_err(
"failed to confirm the firmware download\n");
669 pr_err(
"failed to load firmware (err=%d)\n", err);
681 static int if_spi_c2h_cmd(
struct if_spi_card *card)
710 netdev_err(priv->
dev,
"%s: error: card has no data for host\n",
715 netdev_err(priv->
dev,
716 "%s: error: response packet too large: %d bytes, but maximum is %d\n",
738 netdev_err(priv->
dev,
"%s: err=%d\n", __func__, err);
744 static int if_spi_c2h_data(
struct if_spi_card *card)
759 netdev_err(priv->
dev,
"%s: error: card has no data for host\n",
764 netdev_err(priv->
dev,
765 "%s: error: card has %d bytes of data, but our maximum skb size is %zu\n",
797 netdev_err(priv->
dev,
"%s: err=%d\n", __func__, err);
820 netdev_err(priv->
dev,
"can't transfer buffer of type %d\n",
827 err = spu_write(card, port_reg, packet->buffer, packet->
blen);
835 netdev_err(priv->
dev,
"%s: error %d\n", __func__, err);
859 netdev_err(priv->
dev,
"%s: error %d\n", __func__, err);
883 netdev_err(priv->
dev,
"I/O error\n");
888 err = if_spi_c2h_cmd(card);
893 err = if_spi_c2h_data(card);
919 cmd_packet_list.next);
927 if (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY) {
933 data_packet_list.next);
946 netdev_err(priv->
dev,
"%s: got error %d\n", __func__, err);
957 static int if_spi_host_to_card(
struct lbs_private *priv,
969 netdev_err(priv->
dev,
"%s: invalid size requested: %d\n",
981 memcpy(packet->buffer, buf, nb);
982 memset(packet->buffer + nb, 0, blen - nb);
999 netdev_err(priv->
dev,
"can't transfer buffer of type %d\n",
1031 static int if_spi_init_card(
struct if_spi_card *card)
1036 const struct firmware *helper =
NULL;
1037 const struct firmware *mainfw =
NULL;
1041 err = spu_init(card, card->
pdata->use_dummy_writes);
1053 "Marvell WLAN 802.11 adapter\n");
1061 netdev_err(priv->
dev,
"Unsupported chip_id: 0x%02x\n",
1068 &fw_table[0], &helper, &mainfw);
1070 netdev_err(priv->
dev,
"failed to find firmware (%d)\n",
1075 lbs_deb_spi(
"Initializing FW for Marvell WLAN 802.11 adapter "
1076 "(chip_id = 0x%04x, chip_rev = 0x%02x) "
1077 "attached to SPI bus_num %d, chip_select %d. "
1078 "spi->max_speed_hz=%d\n",
1080 card->
spi->master->bus_num,
1081 card->
spi->chip_select,
1082 card->
spi->max_speed_hz);
1083 err = if_spi_prog_helper_firmware(card, helper);
1086 err = if_spi_prog_main_firmware(card, mainfw);
1089 lbs_deb_spi(
"loaded FW for Marvell WLAN 802.11 adapter\n");
1092 err = spu_set_interrupt_mode(card, 0, 1);
1105 static void if_spi_resume_worker(
struct work_struct *work)
1112 if (card->
pdata->setup)
1116 if_spi_init_card(card);
1142 err = pdata->
setup(spi);
1153 spi_set_drvdata(spi, card);
1165 err = if_spi_init_card(card);
1195 pr_err(
"can't get host irq line-- request_irq failed\n");
1196 goto terminate_workqueue;
1208 lbs_deb_spi(
"Finished initializing WLAN module.\n");
1215 terminate_workqueue:
1220 free_if_spi_card(card);
1245 if (card->
pdata->teardown)
1246 card->
pdata->teardown(spi);
1247 free_if_spi_card(card);
1252 static int if_spi_suspend(
struct device *
dev)
1262 if (card->
pdata->teardown)
1263 card->
pdata->teardown(spi);
1270 static int if_spi_resume(
struct device *dev)
1281 static const struct dev_pm_ops if_spi_pm_ops = {
1282 .suspend = if_spi_suspend,
1283 .resume = if_spi_resume,
1286 static struct spi_driver libertas_spi_driver = {
1287 .probe = if_spi_probe,
1290 .name =
"libertas_spi",
1292 .pm = &if_spi_pm_ops,
1300 static int __init if_spi_init_module(
void)
1310 static void __exit if_spi_exit_module(
void)
1313 spi_unregister_driver(&libertas_spi_driver);