3 * Copyright (c) 2011, 2012, Qualcomm Atheros Communications Inc.
4 * Copyright (c) 2014, I2SE GmbH
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose with or without fee is hereby granted, provided
8 * that the above copyright notice and this permission notice appear
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
12 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
14 * THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
15 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
17 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 /* This module implements the Qualcomm Atheros SPI protocol for
23 * kernel-based SPI device.
26 #include <linux/init.h>
27 #include <linux/module.h>
28 #include <linux/moduleparam.h>
29 #include <linux/spi/spi.h>
30 #include <linux/version.h>
35 qcaspi_spi_error(struct qcaspi
*qca
)
37 if (qca
->sync
!= QCASPI_SYNC_READY
)
40 netdev_err(qca
->net_dev
, "spi error\n");
41 qca
->sync
= QCASPI_SYNC_UNKNOWN
;
46 qcaspi_read_register(struct qcaspi
*qca
, u16 reg
, u16
*result
)
50 struct spi_transfer
*transfer
;
51 struct spi_message
*msg
;
54 tx_data
= cpu_to_be16(QCA7K_SPI_READ
| QCA7K_SPI_INTERNAL
| reg
);
56 if (qca
->legacy_mode
) {
58 transfer
= &qca
->spi_xfer1
;
59 transfer
->tx_buf
= &tx_data
;
60 transfer
->rx_buf
= NULL
;
61 transfer
->len
= QCASPI_CMD_LEN
;
62 spi_sync(qca
->spi_dev
, msg
);
65 transfer
= &qca
->spi_xfer2
[0];
66 transfer
->tx_buf
= &tx_data
;
67 transfer
->rx_buf
= NULL
;
68 transfer
->len
= QCASPI_CMD_LEN
;
69 transfer
= &qca
->spi_xfer2
[1];
71 transfer
->tx_buf
= NULL
;
72 transfer
->rx_buf
= &rx_data
;
73 transfer
->len
= QCASPI_CMD_LEN
;
74 ret
= spi_sync(qca
->spi_dev
, msg
);
80 qcaspi_spi_error(qca
);
82 *result
= be16_to_cpu(rx_data
);
88 qcaspi_write_register(struct qcaspi
*qca
, u16 reg
, u16 value
)
91 struct spi_transfer
*transfer
;
92 struct spi_message
*msg
;
95 tx_data
[0] = cpu_to_be16(QCA7K_SPI_WRITE
| QCA7K_SPI_INTERNAL
| reg
);
96 tx_data
[1] = cpu_to_be16(value
);
98 if (qca
->legacy_mode
) {
100 transfer
= &qca
->spi_xfer1
;
101 transfer
->tx_buf
= &tx_data
[0];
102 transfer
->rx_buf
= NULL
;
103 transfer
->len
= QCASPI_CMD_LEN
;
104 spi_sync(qca
->spi_dev
, msg
);
106 msg
= &qca
->spi_msg2
;
107 transfer
= &qca
->spi_xfer2
[0];
108 transfer
->tx_buf
= &tx_data
[0];
109 transfer
->rx_buf
= NULL
;
110 transfer
->len
= QCASPI_CMD_LEN
;
111 transfer
= &qca
->spi_xfer2
[1];
113 transfer
->tx_buf
= &tx_data
[1];
114 transfer
->rx_buf
= NULL
;
115 transfer
->len
= QCASPI_CMD_LEN
;
116 ret
= spi_sync(qca
->spi_dev
, msg
);
122 qcaspi_spi_error(qca
);
128 qcaspi_tx_cmd(struct qcaspi
*qca
, u16 cmd
)
131 struct spi_message
*msg
= &qca
->spi_msg1
;
132 struct spi_transfer
*transfer
= &qca
->spi_xfer1
;
135 tx_data
= cpu_to_be16(cmd
);
136 transfer
->len
= sizeof(tx_data
);
137 transfer
->tx_buf
= &tx_data
;
138 transfer
->rx_buf
= NULL
;
140 ret
= spi_sync(qca
->spi_dev
, msg
);
146 qcaspi_spi_error(qca
);