davinci_spi.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  1. /*
  2. * Copyright (C) 2009 Texas Instruments.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include <linux/interrupt.h>
  19. #include <linux/io.h>
  20. #include <linux/gpio.h>
  21. #include <linux/module.h>
  22. #include <linux/delay.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/err.h>
  25. #include <linux/clk.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/spi/spi.h>
  28. #include <linux/spi/spi_bitbang.h>
  29. #include <linux/slab.h>
  30. #include <mach/spi.h>
  31. #include <mach/edma.h>
  32. #define SPI_NO_RESOURCE ((resource_size_t)-1)
  33. #define SPI_MAX_CHIPSELECT 2
  34. #define CS_DEFAULT 0xFF
  35. #define SPI_BUFSIZ (SMP_CACHE_BYTES + 1)
  36. #define DAVINCI_DMA_DATA_TYPE_S8 0x01
  37. #define DAVINCI_DMA_DATA_TYPE_S16 0x02
  38. #define DAVINCI_DMA_DATA_TYPE_S32 0x04
  39. #define SPIFMT_PHASE_MASK BIT(16)
  40. #define SPIFMT_POLARITY_MASK BIT(17)
  41. #define SPIFMT_DISTIMER_MASK BIT(18)
  42. #define SPIFMT_SHIFTDIR_MASK BIT(20)
  43. #define SPIFMT_WAITENA_MASK BIT(21)
  44. #define SPIFMT_PARITYENA_MASK BIT(22)
  45. #define SPIFMT_ODD_PARITY_MASK BIT(23)
  46. #define SPIFMT_WDELAY_MASK 0x3f000000u
  47. #define SPIFMT_WDELAY_SHIFT 24
  48. #define SPIFMT_PRESCALE_SHIFT 8
  49. /* SPIPC0 */
  50. #define SPIPC0_DIFUN_MASK BIT(11) /* MISO */
  51. #define SPIPC0_DOFUN_MASK BIT(10) /* MOSI */
  52. #define SPIPC0_CLKFUN_MASK BIT(9) /* CLK */
  53. #define SPIPC0_SPIENA_MASK BIT(8) /* nREADY */
  54. #define SPIINT_MASKALL 0x0101035F
  55. #define SPI_INTLVL_1 0x000001FFu
  56. #define SPI_INTLVL_0 0x00000000u
  57. /* SPIDAT1 (upper 16 bit defines) */
  58. #define SPIDAT1_CSHOLD_MASK BIT(12)
  59. /* SPIGCR1 */
  60. #define SPIGCR1_CLKMOD_MASK BIT(1)
  61. #define SPIGCR1_MASTER_MASK BIT(0)
  62. #define SPIGCR1_LOOPBACK_MASK BIT(16)
  63. #define SPIGCR1_SPIENA_MASK BIT(24)
  64. /* SPIBUF */
  65. #define SPIBUF_TXFULL_MASK BIT(29)
  66. #define SPIBUF_RXEMPTY_MASK BIT(31)
  67. /* SPIDELAY */
  68. #define SPIDELAY_C2TDELAY_SHIFT 24
  69. #define SPIDELAY_C2TDELAY_MASK (0xFF << SPIDELAY_C2TDELAY_SHIFT)
  70. #define SPIDELAY_T2CDELAY_SHIFT 16
  71. #define SPIDELAY_T2CDELAY_MASK (0xFF << SPIDELAY_T2CDELAY_SHIFT)
  72. #define SPIDELAY_T2EDELAY_SHIFT 8
  73. #define SPIDELAY_T2EDELAY_MASK (0xFF << SPIDELAY_T2EDELAY_SHIFT)
  74. #define SPIDELAY_C2EDELAY_SHIFT 0
  75. #define SPIDELAY_C2EDELAY_MASK 0xFF
  76. /* Error Masks */
  77. #define SPIFLG_DLEN_ERR_MASK BIT(0)
  78. #define SPIFLG_TIMEOUT_MASK BIT(1)
  79. #define SPIFLG_PARERR_MASK BIT(2)
  80. #define SPIFLG_DESYNC_MASK BIT(3)
  81. #define SPIFLG_BITERR_MASK BIT(4)
  82. #define SPIFLG_OVRRUN_MASK BIT(6)
  83. #define SPIFLG_RX_INTR_MASK BIT(8)
  84. #define SPIFLG_TX_INTR_MASK BIT(9)
  85. #define SPIFLG_BUF_INIT_ACTIVE_MASK BIT(24)
  86. #define SPIINT_BITERR_INTR BIT(4)
  87. #define SPIINT_OVRRUN_INTR BIT(6)
  88. #define SPIINT_RX_INTR BIT(8)
  89. #define SPIINT_TX_INTR BIT(9)
  90. #define SPIINT_DMA_REQ_EN BIT(16)
  91. /* SPI Controller registers */
  92. #define SPIGCR0 0x00
  93. #define SPIGCR1 0x04
  94. #define SPIINT 0x08
  95. #define SPILVL 0x0c
  96. #define SPIFLG 0x10
  97. #define SPIPC0 0x14
  98. #define SPIDAT1 0x3c
  99. #define SPIBUF 0x40
  100. #define SPIDELAY 0x48
  101. #define SPIDEF 0x4c
  102. #define SPIFMT0 0x50
  103. /* We have 2 DMA channels per CS, one for RX and one for TX */
  104. struct davinci_spi_dma {
  105. int dma_tx_channel;
  106. int dma_rx_channel;
  107. int dma_tx_sync_dev;
  108. int dma_rx_sync_dev;
  109. enum dma_event_q eventq;
  110. struct completion dma_tx_completion;
  111. struct completion dma_rx_completion;
  112. };
  113. /* SPI Controller driver's private data. */
  114. struct davinci_spi {
  115. struct spi_bitbang bitbang;
  116. struct clk *clk;
  117. u8 version;
  118. resource_size_t pbase;
  119. void __iomem *base;
  120. size_t region_size;
  121. u32 irq;
  122. struct completion done;
  123. const void *tx;
  124. void *rx;
  125. u8 *tmp_buf;
  126. int count;
  127. struct davinci_spi_dma *dma_channels;
  128. struct davinci_spi_platform_data *pdata;
  129. void (*get_rx)(u32 rx_data, struct davinci_spi *);
  130. u32 (*get_tx)(struct davinci_spi *);
  131. u8 bytes_per_word[SPI_MAX_CHIPSELECT];
  132. };
  133. static struct davinci_spi_config davinci_spi_default_cfg;
  134. static unsigned use_dma;
  135. static void davinci_spi_rx_buf_u8(u32 data, struct davinci_spi *davinci_spi)
  136. {
  137. u8 *rx = davinci_spi->rx;
  138. *rx++ = (u8)data;
  139. davinci_spi->rx = rx;
  140. }
  141. static void davinci_spi_rx_buf_u16(u32 data, struct davinci_spi *davinci_spi)
  142. {
  143. u16 *rx = davinci_spi->rx;
  144. *rx++ = (u16)data;
  145. davinci_spi->rx = rx;
  146. }
  147. static u32 davinci_spi_tx_buf_u8(struct davinci_spi *davinci_spi)
  148. {
  149. u32 data;
  150. const u8 *tx = davinci_spi->tx;
  151. data = *tx++;
  152. davinci_spi->tx = tx;
  153. return data;
  154. }
  155. static u32 davinci_spi_tx_buf_u16(struct davinci_spi *davinci_spi)
  156. {
  157. u32 data;
  158. const u16 *tx = davinci_spi->tx;
  159. data = *tx++;
  160. davinci_spi->tx = tx;
  161. return data;
  162. }
  163. static inline void set_io_bits(void __iomem *addr, u32 bits)
  164. {
  165. u32 v = ioread32(addr);
  166. v |= bits;
  167. iowrite32(v, addr);
  168. }
  169. static inline void clear_io_bits(void __iomem *addr, u32 bits)
  170. {
  171. u32 v = ioread32(addr);
  172. v &= ~bits;
  173. iowrite32(v, addr);
  174. }
  175. static void davinci_spi_set_dma_req(const struct spi_device *spi, int enable)
  176. {
  177. struct davinci_spi *davinci_spi = spi_master_get_devdata(spi->master);
  178. if (enable)
  179. set_io_bits(davinci_spi->base + SPIINT, SPIINT_DMA_REQ_EN);
  180. else
  181. clear_io_bits(davinci_spi->base + SPIINT, SPIINT_DMA_REQ_EN);
  182. }
  183. /*
  184. * Interface to control the chip select signal
  185. */
  186. static void davinci_spi_chipselect(struct spi_device *spi, int value)
  187. {
  188. struct davinci_spi *davinci_spi;
  189. struct davinci_spi_platform_data *pdata;
  190. u8 chip_sel = spi->chip_select;
  191. u16 spidat1_cfg = CS_DEFAULT;
  192. bool gpio_chipsel = false;
  193. davinci_spi = spi_master_get_devdata(spi->master);
  194. pdata = davinci_spi->pdata;
  195. if (pdata->chip_sel && chip_sel < pdata->num_chipselect &&
  196. pdata->chip_sel[chip_sel] != SPI_INTERN_CS)
  197. gpio_chipsel = true;
  198. /*
  199. * Board specific chip select logic decides the polarity and cs
  200. * line for the controller
  201. */
  202. if (gpio_chipsel) {
  203. if (value == BITBANG_CS_ACTIVE)
  204. gpio_set_value(pdata->chip_sel[chip_sel], 0);
  205. else
  206. gpio_set_value(pdata->chip_sel[chip_sel], 1);
  207. } else {
  208. if (value == BITBANG_CS_ACTIVE) {
  209. spidat1_cfg |= SPIDAT1_CSHOLD_MASK;
  210. spidat1_cfg &= ~(0x1 << chip_sel);
  211. }
  212. iowrite16(spidat1_cfg, davinci_spi->base + SPIDAT1 + 2);
  213. }
  214. }
  215. /**
  216. * davinci_spi_get_prescale - Calculates the correct prescale value
  217. * @maxspeed_hz: the maximum rate the SPI clock can run at
  218. *
  219. * This function calculates the prescale value that generates a clock rate
  220. * less than or equal to the specified maximum.
  221. *
  222. * Returns: calculated prescale - 1 for easy programming into SPI registers
  223. * or negative error number if valid prescalar cannot be updated.
  224. */
  225. static inline int davinci_spi_get_prescale(struct davinci_spi *davinci_spi,
  226. u32 max_speed_hz)
  227. {
  228. int ret;
  229. ret = DIV_ROUND_UP(clk_get_rate(davinci_spi->clk), max_speed_hz);
  230. if (ret < 3 || ret > 256)
  231. return -EINVAL;
  232. return ret - 1;
  233. }
  234. /**
  235. * davinci_spi_setup_transfer - This functions will determine transfer method
  236. * @spi: spi device on which data transfer to be done
  237. * @t: spi transfer in which transfer info is filled
  238. *
  239. * This function determines data transfer method (8/16/32 bit transfer).
  240. * It will also set the SPI Clock Control register according to
  241. * SPI slave device freq.
  242. */
  243. static int davinci_spi_setup_transfer(struct spi_device *spi,
  244. struct spi_transfer *t)
  245. {
  246. struct davinci_spi *davinci_spi;
  247. struct davinci_spi_config *spicfg;
  248. u8 bits_per_word = 0;
  249. u32 hz = 0, spifmt = 0, prescale = 0;
  250. davinci_spi = spi_master_get_devdata(spi->master);
  251. spicfg = (struct davinci_spi_config *)spi->controller_data;
  252. if (!spicfg)
  253. spicfg = &davinci_spi_default_cfg;
  254. if (t) {
  255. bits_per_word = t->bits_per_word;
  256. hz = t->speed_hz;
  257. }
  258. /* if bits_per_word is not set then set it default */
  259. if (!bits_per_word)
  260. bits_per_word = spi->bits_per_word;
  261. /*
  262. * Assign function pointer to appropriate transfer method
  263. * 8bit, 16bit or 32bit transfer
  264. */
  265. if (bits_per_word <= 8 && bits_per_word >= 2) {
  266. davinci_spi->get_rx = davinci_spi_rx_buf_u8;
  267. davinci_spi->get_tx = davinci_spi_tx_buf_u8;
  268. davinci_spi->bytes_per_word[spi->chip_select] = 1;
  269. } else if (bits_per_word <= 16 && bits_per_word >= 2) {
  270. davinci_spi->get_rx = davinci_spi_rx_buf_u16;
  271. davinci_spi->get_tx = davinci_spi_tx_buf_u16;
  272. davinci_spi->bytes_per_word[spi->chip_select] = 2;
  273. } else
  274. return -EINVAL;
  275. if (!hz)
  276. hz = spi->max_speed_hz;
  277. /* Set up SPIFMTn register, unique to this chipselect. */
  278. prescale = davinci_spi_get_prescale(davinci_spi, hz);
  279. if (prescale < 0)
  280. return prescale;
  281. spifmt = (prescale << SPIFMT_PRESCALE_SHIFT) | (bits_per_word & 0x1f);
  282. if (spi->mode & SPI_LSB_FIRST)
  283. spifmt |= SPIFMT_SHIFTDIR_MASK;
  284. if (spi->mode & SPI_CPOL)
  285. spifmt |= SPIFMT_POLARITY_MASK;
  286. if (!(spi->mode & SPI_CPHA))
  287. spifmt |= SPIFMT_PHASE_MASK;
  288. /*
  289. * Version 1 hardware supports two basic SPI modes:
  290. * - Standard SPI mode uses 4 pins, with chipselect
  291. * - 3 pin SPI is a 4 pin variant without CS (SPI_NO_CS)
  292. * (distinct from SPI_3WIRE, with just one data wire;
  293. * or similar variants without MOSI or without MISO)
  294. *
  295. * Version 2 hardware supports an optional handshaking signal,
  296. * so it can support two more modes:
  297. * - 5 pin SPI variant is standard SPI plus SPI_READY
  298. * - 4 pin with enable is (SPI_READY | SPI_NO_CS)
  299. */
  300. if (davinci_spi->version == SPI_VERSION_2) {
  301. u32 delay = 0;
  302. spifmt |= ((spicfg->wdelay << SPIFMT_WDELAY_SHIFT)
  303. & SPIFMT_WDELAY_MASK);
  304. if (spicfg->odd_parity)
  305. spifmt |= SPIFMT_ODD_PARITY_MASK;
  306. if (spicfg->parity_enable)
  307. spifmt |= SPIFMT_PARITYENA_MASK;
  308. if (spicfg->timer_disable) {
  309. spifmt |= SPIFMT_DISTIMER_MASK;
  310. } else {
  311. delay |= (spicfg->c2tdelay << SPIDELAY_C2TDELAY_SHIFT)
  312. & SPIDELAY_C2TDELAY_MASK;
  313. delay |= (spicfg->t2cdelay << SPIDELAY_T2CDELAY_SHIFT)
  314. & SPIDELAY_T2CDELAY_MASK;
  315. }
  316. if (spi->mode & SPI_READY) {
  317. spifmt |= SPIFMT_WAITENA_MASK;
  318. delay |= (spicfg->t2edelay << SPIDELAY_T2EDELAY_SHIFT)
  319. & SPIDELAY_T2EDELAY_MASK;
  320. delay |= (spicfg->c2edelay << SPIDELAY_C2EDELAY_SHIFT)
  321. & SPIDELAY_C2EDELAY_MASK;
  322. }
  323. iowrite32(delay, davinci_spi->base + SPIDELAY);
  324. }
  325. iowrite32(spifmt, davinci_spi->base + SPIFMT0);
  326. return 0;
  327. }
  328. static void davinci_spi_dma_rx_callback(unsigned lch, u16 ch_status, void *data)
  329. {
  330. struct spi_device *spi = (struct spi_device *)data;
  331. struct davinci_spi *davinci_spi;
  332. struct davinci_spi_dma *davinci_spi_dma;
  333. davinci_spi = spi_master_get_devdata(spi->master);
  334. davinci_spi_dma = &(davinci_spi->dma_channels[spi->chip_select]);
  335. if (ch_status == DMA_COMPLETE)
  336. edma_stop(davinci_spi_dma->dma_rx_channel);
  337. else
  338. edma_clean_channel(davinci_spi_dma->dma_rx_channel);
  339. complete(&davinci_spi_dma->dma_rx_completion);
  340. /* We must disable the DMA RX request */
  341. davinci_spi_set_dma_req(spi, 0);
  342. }
  343. static void davinci_spi_dma_tx_callback(unsigned lch, u16 ch_status, void *data)
  344. {
  345. struct spi_device *spi = (struct spi_device *)data;
  346. struct davinci_spi *davinci_spi;
  347. struct davinci_spi_dma *davinci_spi_dma;
  348. davinci_spi = spi_master_get_devdata(spi->master);
  349. davinci_spi_dma = &(davinci_spi->dma_channels[spi->chip_select]);
  350. if (ch_status == DMA_COMPLETE)
  351. edma_stop(davinci_spi_dma->dma_tx_channel);
  352. else
  353. edma_clean_channel(davinci_spi_dma->dma_tx_channel);
  354. complete(&davinci_spi_dma->dma_tx_completion);
  355. /* We must disable the DMA TX request */
  356. davinci_spi_set_dma_req(spi, 0);
  357. }
  358. static int davinci_spi_request_dma(struct spi_device *spi)
  359. {
  360. struct davinci_spi *davinci_spi;
  361. struct davinci_spi_dma *davinci_spi_dma;
  362. struct device *sdev;
  363. int r;
  364. davinci_spi = spi_master_get_devdata(spi->master);
  365. davinci_spi_dma = &davinci_spi->dma_channels[spi->chip_select];
  366. sdev = davinci_spi->bitbang.master->dev.parent;
  367. r = edma_alloc_channel(davinci_spi_dma->dma_rx_sync_dev,
  368. davinci_spi_dma_rx_callback, spi,
  369. davinci_spi_dma->eventq);
  370. if (r < 0) {
  371. dev_dbg(sdev, "Unable to request DMA channel for SPI RX\n");
  372. return -EAGAIN;
  373. }
  374. davinci_spi_dma->dma_rx_channel = r;
  375. r = edma_alloc_channel(davinci_spi_dma->dma_tx_sync_dev,
  376. davinci_spi_dma_tx_callback, spi,
  377. davinci_spi_dma->eventq);
  378. if (r < 0) {
  379. edma_free_channel(davinci_spi_dma->dma_rx_channel);
  380. davinci_spi_dma->dma_rx_channel = -1;
  381. dev_dbg(sdev, "Unable to request DMA channel for SPI TX\n");
  382. return -EAGAIN;
  383. }
  384. davinci_spi_dma->dma_tx_channel = r;
  385. return 0;
  386. }
  387. /**
  388. * davinci_spi_setup - This functions will set default transfer method
  389. * @spi: spi device on which data transfer to be done
  390. *
  391. * This functions sets the default transfer method.
  392. */
  393. static int davinci_spi_setup(struct spi_device *spi)
  394. {
  395. int retval;
  396. struct davinci_spi *davinci_spi;
  397. struct davinci_spi_dma *davinci_spi_dma;
  398. davinci_spi = spi_master_get_devdata(spi->master);
  399. /* if bits per word length is zero then set it default 8 */
  400. if (!spi->bits_per_word)
  401. spi->bits_per_word = 8;
  402. if (use_dma && davinci_spi->dma_channels) {
  403. davinci_spi_dma = &davinci_spi->dma_channels[spi->chip_select];
  404. if ((davinci_spi_dma->dma_rx_channel == -1)
  405. || (davinci_spi_dma->dma_tx_channel == -1)) {
  406. retval = davinci_spi_request_dma(spi);
  407. if (retval < 0)
  408. return retval;
  409. }
  410. }
  411. retval = davinci_spi_setup_transfer(spi, NULL);
  412. return retval;
  413. }
  414. static void davinci_spi_cleanup(struct spi_device *spi)
  415. {
  416. struct davinci_spi *davinci_spi = spi_master_get_devdata(spi->master);
  417. struct davinci_spi_dma *davinci_spi_dma;
  418. davinci_spi_dma = &davinci_spi->dma_channels[spi->chip_select];
  419. if (use_dma && davinci_spi->dma_channels) {
  420. davinci_spi_dma = &davinci_spi->dma_channels[spi->chip_select];
  421. if ((davinci_spi_dma->dma_rx_channel != -1)
  422. && (davinci_spi_dma->dma_tx_channel != -1)) {
  423. edma_free_channel(davinci_spi_dma->dma_tx_channel);
  424. edma_free_channel(davinci_spi_dma->dma_rx_channel);
  425. }
  426. }
  427. }
  428. static int davinci_spi_bufs_prep(struct spi_device *spi,
  429. struct davinci_spi *davinci_spi)
  430. {
  431. struct davinci_spi_platform_data *pdata;
  432. int op_mode = 0;
  433. /*
  434. * REVISIT unless devices disagree about SPI_LOOP or
  435. * SPI_READY (SPI_NO_CS only allows one device!), this
  436. * should not need to be done before each message...
  437. * optimize for both flags staying cleared.
  438. */
  439. op_mode = SPIPC0_DIFUN_MASK
  440. | SPIPC0_DOFUN_MASK
  441. | SPIPC0_CLKFUN_MASK;
  442. if (!(spi->mode & SPI_NO_CS)) {
  443. pdata = davinci_spi->pdata;
  444. if (!pdata->chip_sel ||
  445. pdata->chip_sel[spi->chip_select] == SPI_INTERN_CS)
  446. op_mode |= 1 << spi->chip_select;
  447. }
  448. if (spi->mode & SPI_READY)
  449. op_mode |= SPIPC0_SPIENA_MASK;
  450. iowrite32(op_mode, davinci_spi->base + SPIPC0);
  451. if (spi->mode & SPI_LOOP)
  452. set_io_bits(davinci_spi->base + SPIGCR1,
  453. SPIGCR1_LOOPBACK_MASK);
  454. else
  455. clear_io_bits(davinci_spi->base + SPIGCR1,
  456. SPIGCR1_LOOPBACK_MASK);
  457. return 0;
  458. }
  459. static int davinci_spi_check_error(struct davinci_spi *davinci_spi,
  460. int int_status)
  461. {
  462. struct device *sdev = davinci_spi->bitbang.master->dev.parent;
  463. if (int_status & SPIFLG_TIMEOUT_MASK) {
  464. dev_dbg(sdev, "SPI Time-out Error\n");
  465. return -ETIMEDOUT;
  466. }
  467. if (int_status & SPIFLG_DESYNC_MASK) {
  468. dev_dbg(sdev, "SPI Desynchronization Error\n");
  469. return -EIO;
  470. }
  471. if (int_status & SPIFLG_BITERR_MASK) {
  472. dev_dbg(sdev, "SPI Bit error\n");
  473. return -EIO;
  474. }
  475. if (davinci_spi->version == SPI_VERSION_2) {
  476. if (int_status & SPIFLG_DLEN_ERR_MASK) {
  477. dev_dbg(sdev, "SPI Data Length Error\n");
  478. return -EIO;
  479. }
  480. if (int_status & SPIFLG_PARERR_MASK) {
  481. dev_dbg(sdev, "SPI Parity Error\n");
  482. return -EIO;
  483. }
  484. if (int_status & SPIFLG_OVRRUN_MASK) {
  485. dev_dbg(sdev, "SPI Data Overrun error\n");
  486. return -EIO;
  487. }
  488. if (int_status & SPIFLG_TX_INTR_MASK) {
  489. dev_dbg(sdev, "SPI TX intr bit set\n");
  490. return -EIO;
  491. }
  492. if (int_status & SPIFLG_BUF_INIT_ACTIVE_MASK) {
  493. dev_dbg(sdev, "SPI Buffer Init Active\n");
  494. return -EBUSY;
  495. }
  496. }
  497. return 0;
  498. }
  499. /**
  500. * davinci_spi_bufs - functions which will handle transfer data
  501. * @spi: spi device on which data transfer to be done
  502. * @t: spi transfer in which transfer info is filled
  503. *
  504. * This function will put data to be transferred into data register
  505. * of SPI controller and then wait until the completion will be marked
  506. * by the IRQ Handler.
  507. */
  508. static int davinci_spi_bufs_pio(struct spi_device *spi, struct spi_transfer *t)
  509. {
  510. struct davinci_spi *davinci_spi;
  511. int int_status, count, ret;
  512. u8 conv;
  513. u32 tx_data, data1_reg_val;
  514. u32 buf_val, flg_val;
  515. struct davinci_spi_platform_data *pdata;
  516. davinci_spi = spi_master_get_devdata(spi->master);
  517. pdata = davinci_spi->pdata;
  518. davinci_spi->tx = t->tx_buf;
  519. davinci_spi->rx = t->rx_buf;
  520. /* convert len to words based on bits_per_word */
  521. conv = davinci_spi->bytes_per_word[spi->chip_select];
  522. davinci_spi->count = t->len / conv;
  523. data1_reg_val = ioread32(davinci_spi->base + SPIDAT1);
  524. INIT_COMPLETION(davinci_spi->done);
  525. ret = davinci_spi_bufs_prep(spi, davinci_spi);
  526. if (ret)
  527. return ret;
  528. /* Enable SPI */
  529. set_io_bits(davinci_spi->base + SPIGCR1, SPIGCR1_SPIENA_MASK);
  530. count = davinci_spi->count;
  531. /* Determine the command to execute READ or WRITE */
  532. if (t->tx_buf) {
  533. clear_io_bits(davinci_spi->base + SPIINT, SPIINT_MASKALL);
  534. while (1) {
  535. tx_data = davinci_spi->get_tx(davinci_spi);
  536. data1_reg_val &= ~(0xFFFF);
  537. data1_reg_val |= (0xFFFF & tx_data);
  538. buf_val = ioread32(davinci_spi->base + SPIBUF);
  539. if ((buf_val & SPIBUF_TXFULL_MASK) == 0) {
  540. iowrite32(data1_reg_val,
  541. davinci_spi->base + SPIDAT1);
  542. count--;
  543. }
  544. while (ioread32(davinci_spi->base + SPIBUF)
  545. & SPIBUF_RXEMPTY_MASK)
  546. cpu_relax();
  547. /* getting the returned byte */
  548. if (t->rx_buf) {
  549. buf_val = ioread32(davinci_spi->base + SPIBUF);
  550. davinci_spi->get_rx(buf_val, davinci_spi);
  551. }
  552. if (count <= 0)
  553. break;
  554. }
  555. } else {
  556. if (pdata->poll_mode) {
  557. while (1) {
  558. /* keeps the serial clock going */
  559. if ((ioread32(davinci_spi->base + SPIBUF)
  560. & SPIBUF_TXFULL_MASK) == 0)
  561. iowrite32(data1_reg_val,
  562. davinci_spi->base + SPIDAT1);
  563. while (ioread32(davinci_spi->base + SPIBUF) &
  564. SPIBUF_RXEMPTY_MASK)
  565. cpu_relax();
  566. flg_val = ioread32(davinci_spi->base + SPIFLG);
  567. buf_val = ioread32(davinci_spi->base + SPIBUF);
  568. davinci_spi->get_rx(buf_val, davinci_spi);
  569. count--;
  570. if (count <= 0)
  571. break;
  572. }
  573. } else { /* Receive in Interrupt mode */
  574. int i;
  575. for (i = 0; i < davinci_spi->count; i++) {
  576. set_io_bits(davinci_spi->base + SPIINT,
  577. SPIINT_BITERR_INTR
  578. | SPIINT_OVRRUN_INTR
  579. | SPIINT_RX_INTR);
  580. iowrite32(data1_reg_val,
  581. davinci_spi->base + SPIDAT1);
  582. while (ioread32(davinci_spi->base + SPIINT) &
  583. SPIINT_RX_INTR)
  584. cpu_relax();
  585. }
  586. iowrite32((data1_reg_val & 0x0ffcffff),
  587. davinci_spi->base + SPIDAT1);
  588. }
  589. }
  590. /*
  591. * Check for bit error, desync error,parity error,timeout error and
  592. * receive overflow errors
  593. */
  594. int_status = ioread32(davinci_spi->base + SPIFLG);
  595. ret = davinci_spi_check_error(davinci_spi, int_status);
  596. if (ret != 0)
  597. return ret;
  598. /* SPI Framework maintains the count only in bytes so convert back */
  599. davinci_spi->count *= conv;
  600. return t->len;
  601. }
  602. #define DAVINCI_DMA_DATA_TYPE_S8 0x01
  603. #define DAVINCI_DMA_DATA_TYPE_S16 0x02
  604. #define DAVINCI_DMA_DATA_TYPE_S32 0x04
  605. static int davinci_spi_bufs_dma(struct spi_device *spi, struct spi_transfer *t)
  606. {
  607. struct davinci_spi *davinci_spi;
  608. int int_status = 0;
  609. int count, temp_count;
  610. u8 conv = 1;
  611. u32 data1_reg_val;
  612. struct davinci_spi_dma *davinci_spi_dma;
  613. int word_len, data_type, ret;
  614. unsigned long tx_reg, rx_reg;
  615. struct device *sdev;
  616. davinci_spi = spi_master_get_devdata(spi->master);
  617. sdev = davinci_spi->bitbang.master->dev.parent;
  618. davinci_spi_dma = &davinci_spi->dma_channels[spi->chip_select];
  619. tx_reg = (unsigned long)davinci_spi->pbase + SPIDAT1;
  620. rx_reg = (unsigned long)davinci_spi->pbase + SPIBUF;
  621. davinci_spi->tx = t->tx_buf;
  622. davinci_spi->rx = t->rx_buf;
  623. /* convert len to words based on bits_per_word */
  624. conv = davinci_spi->bytes_per_word[spi->chip_select];
  625. davinci_spi->count = t->len / conv;
  626. data1_reg_val = ioread32(davinci_spi->base + SPIDAT1);
  627. INIT_COMPLETION(davinci_spi->done);
  628. init_completion(&davinci_spi_dma->dma_rx_completion);
  629. init_completion(&davinci_spi_dma->dma_tx_completion);
  630. word_len = conv * 8;
  631. if (word_len <= 8)
  632. data_type = DAVINCI_DMA_DATA_TYPE_S8;
  633. else if (word_len <= 16)
  634. data_type = DAVINCI_DMA_DATA_TYPE_S16;
  635. else if (word_len <= 32)
  636. data_type = DAVINCI_DMA_DATA_TYPE_S32;
  637. else
  638. return -EINVAL;
  639. ret = davinci_spi_bufs_prep(spi, davinci_spi);
  640. if (ret)
  641. return ret;
  642. count = davinci_spi->count; /* the number of elements */
  643. /* disable all interrupts for dma transfers */
  644. clear_io_bits(davinci_spi->base + SPIINT, SPIINT_MASKALL);
  645. /* Disable SPI to write configuration bits in SPIDAT */
  646. clear_io_bits(davinci_spi->base + SPIGCR1, SPIGCR1_SPIENA_MASK);
  647. /* Enable SPI */
  648. set_io_bits(davinci_spi->base + SPIGCR1, SPIGCR1_SPIENA_MASK);
  649. if (t->tx_buf) {
  650. t->tx_dma = dma_map_single(&spi->dev, (void *)t->tx_buf, count,
  651. DMA_TO_DEVICE);
  652. if (dma_mapping_error(&spi->dev, t->tx_dma)) {
  653. dev_dbg(sdev, "Unable to DMA map a %d bytes"
  654. " TX buffer\n", count);
  655. return -ENOMEM;
  656. }
  657. temp_count = count;
  658. } else {
  659. /* We need TX clocking for RX transaction */
  660. t->tx_dma = dma_map_single(&spi->dev,
  661. (void *)davinci_spi->tmp_buf, count + 1,
  662. DMA_TO_DEVICE);
  663. if (dma_mapping_error(&spi->dev, t->tx_dma)) {
  664. dev_dbg(sdev, "Unable to DMA map a %d bytes"
  665. " TX tmp buffer\n", count);
  666. return -ENOMEM;
  667. }
  668. temp_count = count + 1;
  669. }
  670. edma_set_transfer_params(davinci_spi_dma->dma_tx_channel,
  671. data_type, temp_count, 1, 0, ASYNC);
  672. edma_set_dest(davinci_spi_dma->dma_tx_channel, tx_reg, INCR, W8BIT);
  673. edma_set_src(davinci_spi_dma->dma_tx_channel, t->tx_dma, INCR, W8BIT);
  674. edma_set_src_index(davinci_spi_dma->dma_tx_channel, data_type, 0);
  675. edma_set_dest_index(davinci_spi_dma->dma_tx_channel, 0, 0);
  676. if (t->rx_buf) {
  677. /* initiate transaction */
  678. iowrite32(data1_reg_val, davinci_spi->base + SPIDAT1);
  679. t->rx_dma = dma_map_single(&spi->dev, (void *)t->rx_buf, count,
  680. DMA_FROM_DEVICE);
  681. if (dma_mapping_error(&spi->dev, t->rx_dma)) {
  682. dev_dbg(sdev, "Couldn't DMA map a %d bytes RX buffer\n",
  683. count);
  684. if (t->tx_buf != NULL)
  685. dma_unmap_single(NULL, t->tx_dma,
  686. count, DMA_TO_DEVICE);
  687. return -ENOMEM;
  688. }
  689. edma_set_transfer_params(davinci_spi_dma->dma_rx_channel,
  690. data_type, count, 1, 0, ASYNC);
  691. edma_set_src(davinci_spi_dma->dma_rx_channel,
  692. rx_reg, INCR, W8BIT);
  693. edma_set_dest(davinci_spi_dma->dma_rx_channel,
  694. t->rx_dma, INCR, W8BIT);
  695. edma_set_src_index(davinci_spi_dma->dma_rx_channel, 0, 0);
  696. edma_set_dest_index(davinci_spi_dma->dma_rx_channel,
  697. data_type, 0);
  698. }
  699. if ((t->tx_buf) || (t->rx_buf))
  700. edma_start(davinci_spi_dma->dma_tx_channel);
  701. if (t->rx_buf)
  702. edma_start(davinci_spi_dma->dma_rx_channel);
  703. if ((t->rx_buf) || (t->tx_buf))
  704. davinci_spi_set_dma_req(spi, 1);
  705. if (t->tx_buf)
  706. wait_for_completion_interruptible(
  707. &davinci_spi_dma->dma_tx_completion);
  708. if (t->rx_buf)
  709. wait_for_completion_interruptible(
  710. &davinci_spi_dma->dma_rx_completion);
  711. dma_unmap_single(NULL, t->tx_dma, temp_count, DMA_TO_DEVICE);
  712. if (t->rx_buf)
  713. dma_unmap_single(NULL, t->rx_dma, count, DMA_FROM_DEVICE);
  714. /*
  715. * Check for bit error, desync error,parity error,timeout error and
  716. * receive overflow errors
  717. */
  718. int_status = ioread32(davinci_spi->base + SPIFLG);
  719. ret = davinci_spi_check_error(davinci_spi, int_status);
  720. if (ret != 0)
  721. return ret;
  722. /* SPI Framework maintains the count only in bytes so convert back */
  723. davinci_spi->count *= conv;
  724. return t->len;
  725. }
  726. /**
  727. * davinci_spi_irq - IRQ handler for DaVinci SPI
  728. * @irq: IRQ number for this SPI Master
  729. * @context_data: structure for SPI Master controller davinci_spi
  730. */
  731. static irqreturn_t davinci_spi_irq(s32 irq, void *context_data)
  732. {
  733. struct davinci_spi *davinci_spi = context_data;
  734. u32 int_status, rx_data = 0;
  735. irqreturn_t ret = IRQ_NONE;
  736. int_status = ioread32(davinci_spi->base + SPIFLG);
  737. while ((int_status & SPIFLG_RX_INTR_MASK)) {
  738. if (likely(int_status & SPIFLG_RX_INTR_MASK)) {
  739. ret = IRQ_HANDLED;
  740. rx_data = ioread32(davinci_spi->base + SPIBUF);
  741. davinci_spi->get_rx(rx_data, davinci_spi);
  742. /* Disable Receive Interrupt */
  743. iowrite32(~(SPIINT_RX_INTR | SPIINT_TX_INTR),
  744. davinci_spi->base + SPIINT);
  745. } else
  746. (void)davinci_spi_check_error(davinci_spi, int_status);
  747. int_status = ioread32(davinci_spi->base + SPIFLG);
  748. }
  749. return ret;
  750. }
  751. /**
  752. * davinci_spi_probe - probe function for SPI Master Controller
  753. * @pdev: platform_device structure which contains plateform specific data
  754. */
  755. static int davinci_spi_probe(struct platform_device *pdev)
  756. {
  757. struct spi_master *master;
  758. struct davinci_spi *davinci_spi;
  759. struct davinci_spi_platform_data *pdata;
  760. struct resource *r, *mem;
  761. resource_size_t dma_rx_chan = SPI_NO_RESOURCE;
  762. resource_size_t dma_tx_chan = SPI_NO_RESOURCE;
  763. resource_size_t dma_eventq = SPI_NO_RESOURCE;
  764. int i = 0, ret = 0;
  765. pdata = pdev->dev.platform_data;
  766. if (pdata == NULL) {
  767. ret = -ENODEV;
  768. goto err;
  769. }
  770. master = spi_alloc_master(&pdev->dev, sizeof(struct davinci_spi));
  771. if (master == NULL) {
  772. ret = -ENOMEM;
  773. goto err;
  774. }
  775. dev_set_drvdata(&pdev->dev, master);
  776. davinci_spi = spi_master_get_devdata(master);
  777. if (davinci_spi == NULL) {
  778. ret = -ENOENT;
  779. goto free_master;
  780. }
  781. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  782. if (r == NULL) {
  783. ret = -ENOENT;
  784. goto free_master;
  785. }
  786. davinci_spi->pbase = r->start;
  787. davinci_spi->region_size = resource_size(r);
  788. davinci_spi->pdata = pdata;
  789. mem = request_mem_region(r->start, davinci_spi->region_size,
  790. pdev->name);
  791. if (mem == NULL) {
  792. ret = -EBUSY;
  793. goto free_master;
  794. }
  795. davinci_spi->base = ioremap(r->start, davinci_spi->region_size);
  796. if (davinci_spi->base == NULL) {
  797. ret = -ENOMEM;
  798. goto release_region;
  799. }
  800. davinci_spi->irq = platform_get_irq(pdev, 0);
  801. if (davinci_spi->irq <= 0) {
  802. ret = -EINVAL;
  803. goto unmap_io;
  804. }
  805. ret = request_irq(davinci_spi->irq, davinci_spi_irq, IRQF_DISABLED,
  806. dev_name(&pdev->dev), davinci_spi);
  807. if (ret)
  808. goto unmap_io;
  809. /* Allocate tmp_buf for tx_buf */
  810. davinci_spi->tmp_buf = kzalloc(SPI_BUFSIZ, GFP_KERNEL);
  811. if (davinci_spi->tmp_buf == NULL) {
  812. ret = -ENOMEM;
  813. goto irq_free;
  814. }
  815. davinci_spi->bitbang.master = spi_master_get(master);
  816. if (davinci_spi->bitbang.master == NULL) {
  817. ret = -ENODEV;
  818. goto free_tmp_buf;
  819. }
  820. davinci_spi->clk = clk_get(&pdev->dev, NULL);
  821. if (IS_ERR(davinci_spi->clk)) {
  822. ret = -ENODEV;
  823. goto put_master;
  824. }
  825. clk_enable(davinci_spi->clk);
  826. master->bus_num = pdev->id;
  827. master->num_chipselect = pdata->num_chipselect;
  828. master->setup = davinci_spi_setup;
  829. master->cleanup = davinci_spi_cleanup;
  830. davinci_spi->bitbang.chipselect = davinci_spi_chipselect;
  831. davinci_spi->bitbang.setup_transfer = davinci_spi_setup_transfer;
  832. davinci_spi->version = pdata->version;
  833. use_dma = pdata->use_dma;
  834. davinci_spi->bitbang.flags = SPI_NO_CS | SPI_LSB_FIRST | SPI_LOOP;
  835. if (davinci_spi->version == SPI_VERSION_2)
  836. davinci_spi->bitbang.flags |= SPI_READY;
  837. if (use_dma) {
  838. r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  839. if (r)
  840. dma_rx_chan = r->start;
  841. r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
  842. if (r)
  843. dma_tx_chan = r->start;
  844. r = platform_get_resource(pdev, IORESOURCE_DMA, 2);
  845. if (r)
  846. dma_eventq = r->start;
  847. }
  848. if (!use_dma ||
  849. dma_rx_chan == SPI_NO_RESOURCE ||
  850. dma_tx_chan == SPI_NO_RESOURCE ||
  851. dma_eventq == SPI_NO_RESOURCE) {
  852. davinci_spi->bitbang.txrx_bufs = davinci_spi_bufs_pio;
  853. use_dma = 0;
  854. } else {
  855. davinci_spi->bitbang.txrx_bufs = davinci_spi_bufs_dma;
  856. davinci_spi->dma_channels = kzalloc(master->num_chipselect
  857. * sizeof(struct davinci_spi_dma), GFP_KERNEL);
  858. if (davinci_spi->dma_channels == NULL) {
  859. ret = -ENOMEM;
  860. goto free_clk;
  861. }
  862. for (i = 0; i < master->num_chipselect; i++) {
  863. davinci_spi->dma_channels[i].dma_rx_channel = -1;
  864. davinci_spi->dma_channels[i].dma_rx_sync_dev =
  865. dma_rx_chan;
  866. davinci_spi->dma_channels[i].dma_tx_channel = -1;
  867. davinci_spi->dma_channels[i].dma_tx_sync_dev =
  868. dma_tx_chan;
  869. davinci_spi->dma_channels[i].eventq = dma_eventq;
  870. }
  871. dev_info(&pdev->dev, "DaVinci SPI driver in EDMA mode\n"
  872. "Using RX channel = %d , TX channel = %d and "
  873. "event queue = %d", dma_rx_chan, dma_tx_chan,
  874. dma_eventq);
  875. }
  876. davinci_spi->get_rx = davinci_spi_rx_buf_u8;
  877. davinci_spi->get_tx = davinci_spi_tx_buf_u8;
  878. init_completion(&davinci_spi->done);
  879. /* Reset In/OUT SPI module */
  880. iowrite32(0, davinci_spi->base + SPIGCR0);
  881. udelay(100);
  882. iowrite32(1, davinci_spi->base + SPIGCR0);
  883. /* initialize chip selects */
  884. if (pdata->chip_sel) {
  885. for (i = 0; i < pdata->num_chipselect; i++) {
  886. if (pdata->chip_sel[i] != SPI_INTERN_CS)
  887. gpio_direction_output(pdata->chip_sel[i], 1);
  888. }
  889. }
  890. /* Clock internal */
  891. if (davinci_spi->pdata->clk_internal)
  892. set_io_bits(davinci_spi->base + SPIGCR1,
  893. SPIGCR1_CLKMOD_MASK);
  894. else
  895. clear_io_bits(davinci_spi->base + SPIGCR1,
  896. SPIGCR1_CLKMOD_MASK);
  897. iowrite32(CS_DEFAULT, davinci_spi->base + SPIDEF);
  898. /* master mode default */
  899. set_io_bits(davinci_spi->base + SPIGCR1, SPIGCR1_MASTER_MASK);
  900. if (davinci_spi->pdata->intr_level)
  901. iowrite32(SPI_INTLVL_1, davinci_spi->base + SPILVL);
  902. else
  903. iowrite32(SPI_INTLVL_0, davinci_spi->base + SPILVL);
  904. ret = spi_bitbang_start(&davinci_spi->bitbang);
  905. if (ret)
  906. goto free_clk;
  907. dev_info(&pdev->dev, "Controller at 0x%p\n", davinci_spi->base);
  908. if (!pdata->poll_mode)
  909. dev_info(&pdev->dev, "Operating in interrupt mode"
  910. " using IRQ %d\n", davinci_spi->irq);
  911. return ret;
  912. free_clk:
  913. clk_disable(davinci_spi->clk);
  914. clk_put(davinci_spi->clk);
  915. put_master:
  916. spi_master_put(master);
  917. free_tmp_buf:
  918. kfree(davinci_spi->tmp_buf);
  919. irq_free:
  920. free_irq(davinci_spi->irq, davinci_spi);
  921. unmap_io:
  922. iounmap(davinci_spi->base);
  923. release_region:
  924. release_mem_region(davinci_spi->pbase, davinci_spi->region_size);
  925. free_master:
  926. kfree(master);
  927. err:
  928. return ret;
  929. }
  930. /**
  931. * davinci_spi_remove - remove function for SPI Master Controller
  932. * @pdev: platform_device structure which contains plateform specific data
  933. *
  934. * This function will do the reverse action of davinci_spi_probe function
  935. * It will free the IRQ and SPI controller's memory region.
  936. * It will also call spi_bitbang_stop to destroy the work queue which was
  937. * created by spi_bitbang_start.
  938. */
  939. static int __exit davinci_spi_remove(struct platform_device *pdev)
  940. {
  941. struct davinci_spi *davinci_spi;
  942. struct spi_master *master;
  943. master = dev_get_drvdata(&pdev->dev);
  944. davinci_spi = spi_master_get_devdata(master);
  945. spi_bitbang_stop(&davinci_spi->bitbang);
  946. clk_disable(davinci_spi->clk);
  947. clk_put(davinci_spi->clk);
  948. spi_master_put(master);
  949. kfree(davinci_spi->tmp_buf);
  950. free_irq(davinci_spi->irq, davinci_spi);
  951. iounmap(davinci_spi->base);
  952. release_mem_region(davinci_spi->pbase, davinci_spi->region_size);
  953. return 0;
  954. }
  955. static struct platform_driver davinci_spi_driver = {
  956. .driver.name = "spi_davinci",
  957. .remove = __exit_p(davinci_spi_remove),
  958. };
  959. static int __init davinci_spi_init(void)
  960. {
  961. return platform_driver_probe(&davinci_spi_driver, davinci_spi_probe);
  962. }
  963. module_init(davinci_spi_init);
  964. static void __exit davinci_spi_exit(void)
  965. {
  966. platform_driver_unregister(&davinci_spi_driver);
  967. }
  968. module_exit(davinci_spi_exit);
  969. MODULE_DESCRIPTION("TI DaVinci SPI Master Controller Driver");
  970. MODULE_LICENSE("GPL");