12 #include <linux/module.h>
21 #define OCTEON_SPI_CFG 0
22 #define OCTEON_SPI_STS 0x08
23 #define OCTEON_SPI_TX 0x10
24 #define OCTEON_SPI_DAT0 0x80
26 #define OCTEON_SPI_MAX_BYTES 9
28 #define OCTEON_SPI_MAX_CLOCK_HZ 16000000
44 static void octeon_spi_wait_ready(
struct octeon_spi *
p)
47 unsigned int loops = 0;
53 }
while (mpi_sts.
s.busy);
56 static int octeon_spi_do_transfer(
struct octeon_spi *p,
64 unsigned int speed_hz;
76 mode = msg_setup->
mode;
93 mpi_cfg.s.clkdiv = clkdiv;
96 mpi_cfg.s.wireor = (mode &
SPI_3WIRE) ? 1 : 0;
97 mpi_cfg.s.idlelo = cpha != cpol;
98 mpi_cfg.s.cslate = cpha ? 1 : 0;
123 mpi_tx.s.leavecs = 1;
124 mpi_tx.s.txnum = tx_buf ? OCTEON_SPI_MAX_BYTES : 0;
128 octeon_spi_wait_ready(p);
137 for (i = 0; i < len; i++) {
152 mpi_tx.s.txnum = tx_buf ? len : 0;
153 mpi_tx.s.totnum = len;
156 octeon_spi_wait_ready(p);
158 for (i = 0; i < len; i++) {
175 dev_err(&spi->
dev,
"Error: %d bits per word not supported\n",
182 static int octeon_spi_transfer_one_message(
struct spi_master *master,
185 struct octeon_spi *p = spi_master_get_devdata(master);
194 if (spi_get_ctldata(msg->
spi) ==
NULL) {
201 status = octeon_spi_validate_bpw(msg->
spi,
210 int r = octeon_spi_do_transfer(p, msg, xfer, last_xfer);
247 new_setup = octeon_spi_new_setup(spi);
251 spi_set_ctldata(spi, new_setup);
257 static void octeon_spi_cleanup(
struct spi_device *spi)
260 spi_set_ctldata(spi,
NULL);
264 static int octeon_spi_nop_transfer_hardware(
struct spi_master *master)
280 p = spi_master_get_devdata(master);
281 platform_set_drvdata(pdev, p);
286 if (res_mem ==
NULL) {
287 dev_err(&pdev->
dev,
"found no memory resource\n");
292 resource_size(res_mem), res_mem->
name)) {
293 dev_err(&pdev->
dev,
"request_mem_region failed\n");
297 resource_size(res_mem));
309 master->
cleanup = octeon_spi_cleanup;
314 master->
dev.of_node = pdev->
dev.of_node;
317 dev_err(&pdev->
dev,
"register master failed: %d\n", err);
325 spi_master_put(master);
331 struct octeon_spi *p = platform_get_drvdata(pdev);
343 { .compatible =
"cavium,octeon-3010-spi", },
350 .name =
"spi-octeon",
352 .of_match_table = octeon_spi_match,
354 .probe = octeon_spi_probe,