23 #include <linux/module.h>
32 #include <linux/slab.h>
39 #ifdef CONFIG_P54_SPI_DEFAULT_EEPROM
51 static int p54spi_gpio_power = 97;
55 static int p54spi_gpio_irq = 87;
60 void *
buf,
size_t len)
73 t[0].len =
sizeof(
addr);
74 spi_message_add_tail(&
t[0], &
m);
78 spi_message_add_tail(&
t[1], &
m);
84 static void p54spi_spi_write(
struct p54s_priv *priv,
u8 address,
85 const void *buf,
size_t len)
98 t[0].len =
sizeof(
addr);
99 spi_message_add_tail(&
t[0], &
m);
103 spi_message_add_tail(&
t[1], &
m);
109 t[2].tx_buf = &last_word;
110 t[2].len =
sizeof(last_word);
111 spi_message_add_tail(&
t[2], &
m);
121 p54spi_spi_read(priv, addr, &val,
sizeof(val));
128 p54spi_spi_write(priv, addr, &val,
sizeof(val));
133 p54spi_spi_write(priv, addr, &val,
sizeof(val));
140 for (i = 0; i < 2000; i++) {
142 if ((buffer & bits) == bits)
149 const void *buf,
size_t len)
152 dev_err(&priv->
spi->dev,
"spi_write_dma not allowed "
175 dev_err(&priv->
spi->dev,
"request_firmware() failed: %d", ret);
188 static int p54spi_request_eeprom(
struct ieee80211_hw *dev)
200 #ifdef CONFIG_P54_SPI_DEFAULT_EEPROM
201 dev_info(&priv->
spi->dev,
"loading default eeprom...\n");
203 sizeof(p54spi_eeprom));
205 dev_err(&priv->
spi->dev,
"Failed to request user eeprom\n");
208 dev_info(&priv->
spi->dev,
"loading user eeprom...\n");
216 static int p54spi_upload_firmware(
struct ieee80211_hw *dev)
219 unsigned long fw_len, _fw_len;
247 (fw + offset), _fw_len);
277 static void p54spi_power_off(
struct p54s_priv *priv)
283 static void p54spi_power_on(
struct p54s_priv *priv)
295 static inline void p54spi_int_ack(
struct p54s_priv *priv,
u32 val)
300 static int p54spi_wakeup(
struct p54s_priv *priv)
309 dev_err(&priv->
spi->dev,
"INT_READY timeout\n");
317 static inline void p54spi_sleep(
struct p54s_priv *priv)
323 static void p54spi_int_ready(
struct p54s_priv *priv)
342 static int p54spi_rx(
struct p54s_priv *priv)
347 #define READAHEAD_SZ (sizeof(rx_head)-sizeof(u16))
349 if (p54spi_wakeup(priv) < 0)
361 dev_err(&priv->
spi->dev,
"rx request of zero bytes\n");
369 skb = dev_alloc_skb(len + 4);
372 dev_err(&priv->
spi->dev,
"could not alloc skb");
376 if (len <= READAHEAD_SZ) {
379 memcpy(
skb_put(skb, READAHEAD_SZ), rx_head + 1, READAHEAD_SZ);
381 skb_put(skb, len - READAHEAD_SZ),
411 if (p54spi_wakeup(priv) < 0)
414 ret = p54spi_spi_write_dma(priv, hdr->
req_id, skb->
data, skb->
len);
420 dev_err(&priv->
spi->dev,
"WR_READY timeout\n");
434 static int p54spi_wq_tx(
struct p54s_priv *priv)
450 list_del_init(&entry->
tx_list);
452 spin_unlock_irqrestore(&priv->
tx_lock, flags);
462 ret = p54spi_tx_frame(priv, skb);
471 spin_unlock_irqrestore(&priv->
tx_lock, flags);
487 spin_unlock_irqrestore(&priv->
tx_lock, flags);
506 p54spi_int_ready(priv);
507 p54spi_int_ack(priv, SPI_HOST_INT_READY);
514 p54spi_int_ack(priv, SPI_HOST_INT_UPDATE);
515 ret = p54spi_rx(priv);
520 p54spi_int_ack(priv, SPI_HOST_INT_SW_UPDATE);
521 ret = p54spi_rx(priv);
526 ret = p54spi_wq_tx(priv);
544 p54spi_power_on(priv);
546 ret = p54spi_upload_firmware(dev);
548 p54spi_power_off(priv);
558 dev_err(&priv->
spi->dev,
"firmware boot failed");
559 p54spi_power_off(priv);
566 p54spi_power_off(priv);
587 p54spi_power_off(priv);
590 spin_unlock_irqrestore(&priv->
tx_lock, flags);
606 dev_err(&spi->
dev,
"could not alloc ieee80211_hw");
626 dev_err(&priv->
spi->dev,
"power GPIO request failed: %d", ret);
632 dev_err(&priv->
spi->dev,
"irq GPIO request failed: %d", ret);
633 goto err_free_gpio_power;
643 dev_err(&priv->
spi->dev,
"request_irq() failed");
644 goto err_free_gpio_irq;
652 init_completion(&priv->
fw_comp);
656 SET_IEEE80211_DEV(hw, &spi->
dev);
657 priv->
common.open = p54spi_op_start;
658 priv->
common.stop = p54spi_op_stop;
659 priv->
common.tx = p54spi_op_tx;
661 ret = p54spi_request_firmware(hw);
663 goto err_free_common;
665 ret = p54spi_request_eeprom(hw);
667 goto err_free_common;
671 goto err_free_common;
712 .probe = p54spi_probe,
716 static int __init p54spi_init(
void)
730 static void __exit p54spi_exit(
void)
732 spi_unregister_driver(&p54spi_driver);