21 #include <linux/kernel.h>
25 #include <linux/module.h>
30 #define MODE_BITS (SPI_CPHA | SPI_CPOL | SPI_CS_HIGH)
69 for (count = 0; count < t->
len; count += 1) {
71 ti_ssp_spi_tx(hw, *tx++);
73 *rx++ = ti_ssp_spi_rx(hw);
75 }
else if (hw->
bpw <= 16) {
79 for (count = 0; count < t->
len; count += 2) {
81 ti_ssp_spi_tx(hw, *tx++);
83 *rx++ = ti_ssp_spi_rx(hw);
89 for (count = 0; count < t->
len; count += 4) {
91 ti_ssp_spi_tx(hw, *tx++);
93 *rx++ = ti_ssp_spi_rx(hw);
99 dev_dbg(&msg->
spi->dev,
"xfer %s%s, %d bytes, %d bpw, count %d%s\n",
101 hw->
bpw, count, (count < t->len) ?
" (under)" :
"");
103 return (count < t->len) ? -
EIO : 0;
106 static void ti_ssp_spi_chip_select(
struct ti_ssp_spi *hw,
int cs_active)
108 cs_active = !!cs_active;
115 #define __SHIFT_OUT(bits) (SSP_OPCODE_SHIFT | SSP_OUT_MODE | \
116 cs_en | clk | SSP_COUNT((bits) * 2 - 1))
117 #define __SHIFT_IN(bits) (SSP_OPCODE_SHIFT | SSP_IN_MODE | \
118 cs_en | clk | SSP_COUNT((bits) * 2 - 1))
125 u32 topbits, botbits;
128 if (mode == hw->
mode && bpw == hw->
bpw)
148 topbits = (bpw > 16) ? 16 : bpw;
149 botbits = bpw - topbits;
184 spin_lock(&hw->
lock);
195 list_del_init(&m->
queue);
197 spin_unlock(&hw->
lock);
211 if (ti_ssp_spi_setup_transfer(hw, bpw, spi->
mode) < 0)
214 ti_ssp_spi_chip_select(hw, 1);
216 xfer_status = ti_ssp_spi_txrx(hw, m, t);
218 status = xfer_status;
224 ti_ssp_spi_chip_select(hw, 0);
227 ti_ssp_spi_chip_select(hw, 0);
231 spin_lock(&hw->
lock);
237 spin_unlock(&hw->
lock);
240 static int ti_ssp_spi_setup(
struct spi_device *spi)
257 hw = spi_master_get_devdata(spi->
master);
264 dev_err(&spi->
dev,
"invalid xfer, no buffer\n");
269 dev_err(&spi->
dev,
"invalid xfer, full duplex\n");
280 spin_lock(&hw->
lock);
288 spin_unlock(&hw->
lock);
302 dev_err(dev,
"platform data not found\n");
308 dev_err(dev,
"cannot allocate SPI master\n");
312 hw = spi_master_get_devdata(master);
313 platform_set_drvdata(pdev, hw);
327 dev_err(dev,
"work queue creation failed\n");
333 dev_err(dev,
"io setup failed\n");
341 master->
setup = ti_ssp_spi_setup;
342 master->
transfer = ti_ssp_spi_transfer;
346 dev_err(dev,
"master registration failed\n");
356 spi_master_put(master);
362 struct ti_ssp_spi *hw = platform_get_drvdata(pdev);
380 .probe = ti_ssp_spi_probe,
383 .name =
"ti-ssp-spi",