11 #include <linux/module.h>
17 #include <linux/errno.h>
20 #include <linux/device.h>
24 #include <linux/slab.h>
39 #define ENINT (0x01 << 17)
40 #define ENFLG (0x01 << 16)
41 #define TXNUM (0x03 << 8)
42 #define TXNEG (0x01 << 2)
43 #define RXNEG (0x01 << 1)
44 #define LSB (0x01 << 10)
45 #define SELECTLEV (0x01 << 2)
46 #define SELECTPOL (0x01 << 31)
47 #define SELECTSLAVE 0x01
57 const unsigned char *
tx;
71 return spi_master_get_devdata(sdev->
master);
107 spin_unlock_irqrestore(&hw->
lock, flags);
114 nuc900_slave_select(spi, 0);
118 nuc900_slave_select(spi, 1);
123 static void nuc900_spi_setup_txnum(
struct nuc900_spi *hw,
136 val |= txnum << 0x08;
140 spin_unlock_irqrestore(&hw->
lock, flags);
144 static void nuc900_spi_setup_txbitlen(
struct nuc900_spi *hw,
145 unsigned int txbitlen)
154 val |= (txbitlen << 0x03);
158 spin_unlock_irqrestore(&hw->
lock, flags);
161 static void nuc900_spi_gobusy(
struct nuc900_spi *hw)
174 spin_unlock_irqrestore(&hw->
lock, flags);
177 static int nuc900_spi_setupxfer(
struct spi_device *spi,
183 static int nuc900_spi_setup(
struct spi_device *spi)
204 nuc900_spi_gobusy(hw);
220 if (status &
ENFLG) {
227 if (count < hw->
len) {
229 nuc900_spi_gobusy(hw);
241 static void nuc900_tx_edge(
struct nuc900_spi *hw,
unsigned int edge)
256 spin_unlock_irqrestore(&hw->
lock, flags);
259 static void nuc900_rx_edge(
struct nuc900_spi *hw,
unsigned int edge)
274 spin_unlock_irqrestore(&hw->
lock, flags);
277 static void nuc900_send_first(
struct nuc900_spi *hw,
unsigned int lsb)
292 spin_unlock_irqrestore(&hw->
lock, flags);
295 static void nuc900_set_sleep(
struct nuc900_spi *hw,
unsigned int sleep)
305 val |= (sleep << 12);
307 val &= ~(0x0f << 12);
310 spin_unlock_irqrestore(&hw->
lock, flags);
313 static void nuc900_enable_int(
struct nuc900_spi *hw)
326 spin_unlock_irqrestore(&hw->
lock, flags);
329 static void nuc900_set_divider(
struct nuc900_spi *hw)
334 static void nuc900_init_spi(
struct nuc900_spi *hw)
339 nuc900_tx_edge(hw, hw->
pdata->txneg);
340 nuc900_rx_edge(hw, hw->
pdata->rxneg);
341 nuc900_send_first(hw, hw->
pdata->lsb);
342 nuc900_set_sleep(hw, hw->
pdata->sleep);
343 nuc900_spi_setup_txbitlen(hw, hw->
pdata->txbitlen);
344 nuc900_spi_setup_txnum(hw, hw->
pdata->txnum);
345 nuc900_set_divider(hw);
346 nuc900_enable_int(hw);
356 if (master ==
NULL) {
357 dev_err(&pdev->
dev,
"No memory for spi_master\n");
362 hw = spi_master_get_devdata(master);
363 hw->
master = spi_master_get(master);
364 hw->
pdata = pdev->
dev.platform_data;
368 dev_err(&pdev->
dev,
"No platform data supplied\n");
373 platform_set_drvdata(pdev, hw);
374 init_completion(&hw->
done);
380 hw->
bitbang.setup_transfer = nuc900_spi_setupxfer;
381 hw->
bitbang.chipselect = nuc900_spi_chipsel;
382 hw->
bitbang.txrx_bufs = nuc900_spi_txrx;
383 hw->
bitbang.master->setup = nuc900_spi_setup;
387 dev_err(&pdev->
dev,
"Cannot get IORESOURCE_MEM\n");
393 resource_size(hw->
res), pdev->
name);
396 dev_err(&pdev->
dev,
"Cannot reserve region\n");
422 if (IS_ERR(hw->
clk)) {
424 err = PTR_ERR(hw->
clk);
433 dev_err(&pdev->
dev,
"Failed to register SPI master\n");
450 spi_master_put(hw->
master);
458 struct nuc900_spi *hw = platform_get_drvdata(dev);
462 platform_set_drvdata(dev,
NULL);
474 spi_master_put(hw->
master);
479 .probe = nuc900_spi_probe,
482 .name =
"nuc900-spi",