19 #include <linux/module.h>
22 #include <asm/unaligned.h>
24 #define DRIVER_NAME "orion_spi"
26 #define ORION_NUM_CHIPSELECTS 1
27 #define ORION_SPI_WAIT_RDY_MAX_LOOP 2000
29 #define ORION_SPI_IF_CTRL_REG 0x00
30 #define ORION_SPI_IF_CONFIG_REG 0x04
31 #define ORION_SPI_DATA_OUT_REG 0x08
32 #define ORION_SPI_DATA_IN_REG 0x0c
33 #define ORION_SPI_INT_CAUSE_REG 0x10
35 #define ORION_SPI_IF_8_16_BIT_MODE (1 << 5)
36 #define ORION_SPI_CLK_PRESCALE_MASK 0x1F
57 val =
readl(reg_addr);
68 val =
readl(reg_addr);
78 }
else if (size == 8) {
82 pr_debug(
"Bad bits per word value %d (only 8 or 16 are "
90 static int orion_spi_baudrate_set(
struct spi_device *
spi,
unsigned int speed)
96 struct orion_spi *orion_spi;
98 orion_spi = spi_master_get_devdata(spi->
master);
117 prescale = 0x10 + rate/2;
132 struct orion_spi *orion_spi;
137 orion_spi = spi_master_get_devdata(spi->
master);
145 rc = orion_spi_baudrate_set(spi, speed);
149 return orion_spi_set_transfer_size(orion_spi, bits_per_word);
152 static void orion_spi_set_cs(
struct orion_spi *orion_spi,
int enable)
160 static inline int orion_spi_wait_till_ready(
struct orion_spi *orion_spi)
175 orion_spi_write_read_8bit(
struct spi_device *spi,
178 void __iomem *tx_reg, *rx_reg, *int_reg;
179 struct orion_spi *orion_spi;
181 orion_spi = spi_master_get_devdata(spi->
master);
189 if (tx_buf && *tx_buf)
190 writel(*(*tx_buf)++, tx_reg);
194 if (orion_spi_wait_till_ready(orion_spi) < 0) {
199 if (rx_buf && *rx_buf)
200 *(*rx_buf)++ =
readl(rx_reg);
206 orion_spi_write_read_16bit(
struct spi_device *spi,
207 const u16 **tx_buf,
u16 **rx_buf)
209 void __iomem *tx_reg, *rx_reg, *int_reg;
210 struct orion_spi *orion_spi;
212 orion_spi = spi_master_get_devdata(spi->
master);
220 if (tx_buf && *tx_buf)
225 if (orion_spi_wait_till_ready(orion_spi) < 0) {
230 if (rx_buf && *rx_buf)
239 struct orion_spi *orion_spi;
243 orion_spi = spi_master_get_devdata(spi->
master);
252 if (orion_spi_write_read_8bit(spi, &tx, &rx) < 0)
256 }
else if (word_len == 16) {
261 if (orion_spi_write_read_16bit(spi, &tx, &rx) < 0)
275 struct orion_spi *orion_spi = spi_master_get_devdata(master);
278 int par_override = 0;
283 status = orion_spi_setup_transfer(spi,
NULL);
293 "message rejected : "
294 "odd data length %d while in 16 bit mode\n",
302 "message rejected : "
303 "device min speed (%d Hz) exceeds "
304 "required transfer speed (%d Hz)\n",
312 status = orion_spi_setup_transfer(spi, t);
320 orion_spi_set_cs(orion_spi, 1);
331 orion_spi_set_cs(orion_spi, 0);
338 orion_spi_set_cs(orion_spi, 0);
346 static int __init orion_spi_reset(
struct orion_spi *orion_spi)
349 orion_spi_set_cs(orion_spi, 0);
354 static int orion_spi_setup(
struct spi_device *spi)
356 struct orion_spi *orion_spi;
358 orion_spi = spi_master_get_devdata(spi->
master);
365 dev_err(&spi->
dev,
"setup: requested speed too low %d Hz\n",
379 struct orion_spi *
spi;
381 unsigned long tclk_hz;
387 if (master ==
NULL) {
388 dev_dbg(&pdev->
dev,
"master allocation failed\n");
394 if (pdev->
dev.of_node) {
397 if (iprop && size ==
sizeof(*iprop))
404 master->
setup = orion_spi_setup;
410 spi = spi_master_get_devdata(master);
414 if (IS_ERR(spi->
clk)) {
415 status = PTR_ERR(spi->
clk);
432 dev_name(&pdev->
dev))) {
438 if (orion_spi_reset(spi) < 0)
441 master->
dev.of_node = pdev->
dev.of_node;
451 clk_disable_unprepare(spi->
clk);
454 spi_master_put(master);
463 struct orion_spi *
spi;
466 spi = spi_master_get_devdata(master);
468 clk_disable_unprepare(spi->
clk);
482 { .compatible =
"marvell,orion-spi", },
491 .of_match_table =
of_match_ptr(orion_spi_of_match_table),
493 .remove =
__exit_p(orion_spi_remove),
502 static void __exit orion_spi_exit(
void)