omap2_mcspi.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. /*
  2. * OMAP2 McSPI controller driver
  3. *
  4. * Copyright (C) 2005, 2006 Nokia Corporation
  5. * Author: Samuel Ortiz <samuel.ortiz@nokia.com> and
  6. * Juha Yrjölä <juha.yrjola@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/init.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/module.h>
  27. #include <linux/device.h>
  28. #include <linux/delay.h>
  29. #include <linux/dma-mapping.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/err.h>
  32. #include <linux/clk.h>
  33. #include <linux/io.h>
  34. #include <linux/spi/spi.h>
  35. #include <mach/dma.h>
  36. #include <mach/clock.h>
  37. #define OMAP2_MCSPI_MAX_FREQ 48000000
  38. /* OMAP2 has 3 SPI controllers, while OMAP3 has 4 */
  39. #define OMAP2_MCSPI_MAX_CTRL 4
  40. #define OMAP2_MCSPI_REVISION 0x00
  41. #define OMAP2_MCSPI_SYSCONFIG 0x10
  42. #define OMAP2_MCSPI_SYSSTATUS 0x14
  43. #define OMAP2_MCSPI_IRQSTATUS 0x18
  44. #define OMAP2_MCSPI_IRQENABLE 0x1c
  45. #define OMAP2_MCSPI_WAKEUPENABLE 0x20
  46. #define OMAP2_MCSPI_SYST 0x24
  47. #define OMAP2_MCSPI_MODULCTRL 0x28
  48. /* per-channel banks, 0x14 bytes each, first is: */
  49. #define OMAP2_MCSPI_CHCONF0 0x2c
  50. #define OMAP2_MCSPI_CHSTAT0 0x30
  51. #define OMAP2_MCSPI_CHCTRL0 0x34
  52. #define OMAP2_MCSPI_TX0 0x38
  53. #define OMAP2_MCSPI_RX0 0x3c
  54. /* per-register bitmasks: */
  55. #define OMAP2_MCSPI_SYSCONFIG_SMARTIDLE BIT(4)
  56. #define OMAP2_MCSPI_SYSCONFIG_ENAWAKEUP BIT(2)
  57. #define OMAP2_MCSPI_SYSCONFIG_AUTOIDLE BIT(0)
  58. #define OMAP2_MCSPI_SYSCONFIG_SOFTRESET BIT(1)
  59. #define OMAP2_MCSPI_SYSSTATUS_RESETDONE BIT(0)
  60. #define OMAP2_MCSPI_MODULCTRL_SINGLE BIT(0)
  61. #define OMAP2_MCSPI_MODULCTRL_MS BIT(2)
  62. #define OMAP2_MCSPI_MODULCTRL_STEST BIT(3)
  63. #define OMAP2_MCSPI_CHCONF_PHA BIT(0)
  64. #define OMAP2_MCSPI_CHCONF_POL BIT(1)
  65. #define OMAP2_MCSPI_CHCONF_CLKD_MASK (0x0f << 2)
  66. #define OMAP2_MCSPI_CHCONF_EPOL BIT(6)
  67. #define OMAP2_MCSPI_CHCONF_WL_MASK (0x1f << 7)
  68. #define OMAP2_MCSPI_CHCONF_TRM_RX_ONLY BIT(12)
  69. #define OMAP2_MCSPI_CHCONF_TRM_TX_ONLY BIT(13)
  70. #define OMAP2_MCSPI_CHCONF_TRM_MASK (0x03 << 12)
  71. #define OMAP2_MCSPI_CHCONF_DMAW BIT(14)
  72. #define OMAP2_MCSPI_CHCONF_DMAR BIT(15)
  73. #define OMAP2_MCSPI_CHCONF_DPE0 BIT(16)
  74. #define OMAP2_MCSPI_CHCONF_DPE1 BIT(17)
  75. #define OMAP2_MCSPI_CHCONF_IS BIT(18)
  76. #define OMAP2_MCSPI_CHCONF_TURBO BIT(19)
  77. #define OMAP2_MCSPI_CHCONF_FORCE BIT(20)
  78. #define OMAP2_MCSPI_CHSTAT_RXS BIT(0)
  79. #define OMAP2_MCSPI_CHSTAT_TXS BIT(1)
  80. #define OMAP2_MCSPI_CHSTAT_EOT BIT(2)
  81. #define OMAP2_MCSPI_CHCTRL_EN BIT(0)
  82. #define OMAP2_MCSPI_WAKEUPENABLE_WKEN BIT(0)
  83. /* We have 2 DMA channels per CS, one for RX and one for TX */
  84. struct omap2_mcspi_dma {
  85. int dma_tx_channel;
  86. int dma_rx_channel;
  87. int dma_tx_sync_dev;
  88. int dma_rx_sync_dev;
  89. struct completion dma_tx_completion;
  90. struct completion dma_rx_completion;
  91. };
  92. /* use PIO for small transfers, avoiding DMA setup/teardown overhead and
  93. * cache operations; better heuristics consider wordsize and bitrate.
  94. */
  95. #define DMA_MIN_BYTES 8
  96. struct omap2_mcspi {
  97. struct work_struct work;
  98. /* lock protects queue and registers */
  99. spinlock_t lock;
  100. struct list_head msg_queue;
  101. struct spi_master *master;
  102. struct clk *ick;
  103. struct clk *fck;
  104. /* Virtual base address of the controller */
  105. void __iomem *base;
  106. unsigned long phys;
  107. /* SPI1 has 4 channels, while SPI2 has 2 */
  108. struct omap2_mcspi_dma *dma_channels;
  109. };
  110. struct omap2_mcspi_cs {
  111. void __iomem *base;
  112. unsigned long phys;
  113. int word_len;
  114. /* Context save and restore shadow register */
  115. u32 chconf0;
  116. };
  117. /* used for context save and restore, structure members to be updated whenever
  118. * corresponding registers are modified.
  119. */
  120. struct omap2_mcspi_regs {
  121. u32 sysconfig;
  122. u32 modulctrl;
  123. u32 wakeupenable;
  124. };
  125. static struct omap2_mcspi_regs omap2_mcspi_ctx[OMAP2_MCSPI_MAX_CTRL];
  126. static struct workqueue_struct *omap2_mcspi_wq;
  127. #define MOD_REG_BIT(val, mask, set) do { \
  128. if (set) \
  129. val |= mask; \
  130. else \
  131. val &= ~mask; \
  132. } while (0)
  133. static inline void mcspi_write_reg(struct spi_master *master,
  134. int idx, u32 val)
  135. {
  136. struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
  137. __raw_writel(val, mcspi->base + idx);
  138. }
  139. static inline u32 mcspi_read_reg(struct spi_master *master, int idx)
  140. {
  141. struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
  142. return __raw_readl(mcspi->base + idx);
  143. }
  144. static inline void mcspi_write_cs_reg(const struct spi_device *spi,
  145. int idx, u32 val)
  146. {
  147. struct omap2_mcspi_cs *cs = spi->controller_state;
  148. __raw_writel(val, cs->base + idx);
  149. }
  150. static inline u32 mcspi_read_cs_reg(const struct spi_device *spi, int idx)
  151. {
  152. struct omap2_mcspi_cs *cs = spi->controller_state;
  153. return __raw_readl(cs->base + idx);
  154. }
  155. static inline u32 mcspi_cached_chconf0(const struct spi_device *spi)
  156. {
  157. struct omap2_mcspi_cs *cs = spi->controller_state;
  158. return cs->chconf0;
  159. }
  160. static inline void mcspi_write_chconf0(const struct spi_device *spi, u32 val)
  161. {
  162. struct omap2_mcspi_cs *cs = spi->controller_state;
  163. cs->chconf0 = val;
  164. mcspi_write_cs_reg(spi, OMAP2_MCSPI_CHCONF0, val);
  165. }
  166. static void omap2_mcspi_set_dma_req(const struct spi_device *spi,
  167. int is_read, int enable)
  168. {
  169. u32 l, rw;
  170. l = mcspi_cached_chconf0(spi);
  171. if (is_read) /* 1 is read, 0 write */
  172. rw = OMAP2_MCSPI_CHCONF_DMAR;
  173. else
  174. rw = OMAP2_MCSPI_CHCONF_DMAW;
  175. MOD_REG_BIT(l, rw, enable);
  176. mcspi_write_chconf0(spi, l);
  177. }
  178. static void omap2_mcspi_set_enable(const struct spi_device *spi, int enable)
  179. {
  180. u32 l;
  181. l = enable ? OMAP2_MCSPI_CHCTRL_EN : 0;
  182. mcspi_write_cs_reg(spi, OMAP2_MCSPI_CHCTRL0, l);
  183. }
  184. static void omap2_mcspi_force_cs(struct spi_device *spi, int cs_active)
  185. {
  186. u32 l;
  187. l = mcspi_cached_chconf0(spi);
  188. MOD_REG_BIT(l, OMAP2_MCSPI_CHCONF_FORCE, cs_active);
  189. mcspi_write_chconf0(spi, l);
  190. }
  191. static void omap2_mcspi_set_master_mode(struct spi_master *master)
  192. {
  193. u32 l;
  194. /* setup when switching from (reset default) slave mode
  195. * to single-channel master mode
  196. */
  197. l = mcspi_read_reg(master, OMAP2_MCSPI_MODULCTRL);
  198. MOD_REG_BIT(l, OMAP2_MCSPI_MODULCTRL_STEST, 0);
  199. MOD_REG_BIT(l, OMAP2_MCSPI_MODULCTRL_MS, 0);
  200. MOD_REG_BIT(l, OMAP2_MCSPI_MODULCTRL_SINGLE, 1);
  201. mcspi_write_reg(master, OMAP2_MCSPI_MODULCTRL, l);
  202. omap2_mcspi_ctx[master->bus_num - 1].modulctrl = l;
  203. }
  204. static void omap2_mcspi_restore_ctx(struct omap2_mcspi *mcspi)
  205. {
  206. struct spi_master *spi_cntrl;
  207. spi_cntrl = mcspi->master;
  208. /* McSPI: context restore */
  209. mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_MODULCTRL,
  210. omap2_mcspi_ctx[spi_cntrl->bus_num - 1].modulctrl);
  211. mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_SYSCONFIG,
  212. omap2_mcspi_ctx[spi_cntrl->bus_num - 1].sysconfig);
  213. mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_WAKEUPENABLE,
  214. omap2_mcspi_ctx[spi_cntrl->bus_num - 1].wakeupenable);
  215. }
  216. static void omap2_mcspi_disable_clocks(struct omap2_mcspi *mcspi)
  217. {
  218. clk_disable(mcspi->ick);
  219. clk_disable(mcspi->fck);
  220. }
  221. static int omap2_mcspi_enable_clocks(struct omap2_mcspi *mcspi)
  222. {
  223. if (clk_enable(mcspi->ick))
  224. return -ENODEV;
  225. if (clk_enable(mcspi->fck))
  226. return -ENODEV;
  227. omap2_mcspi_restore_ctx(mcspi);
  228. return 0;
  229. }
  230. static unsigned
  231. omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
  232. {
  233. struct omap2_mcspi *mcspi;
  234. struct omap2_mcspi_cs *cs = spi->controller_state;
  235. struct omap2_mcspi_dma *mcspi_dma;
  236. unsigned int count, c;
  237. unsigned long base, tx_reg, rx_reg;
  238. int word_len, data_type, element_count;
  239. u8 * rx;
  240. const u8 * tx;
  241. mcspi = spi_master_get_devdata(spi->master);
  242. mcspi_dma = &mcspi->dma_channels[spi->chip_select];
  243. count = xfer->len;
  244. c = count;
  245. word_len = cs->word_len;
  246. base = cs->phys;
  247. tx_reg = base + OMAP2_MCSPI_TX0;
  248. rx_reg = base + OMAP2_MCSPI_RX0;
  249. rx = xfer->rx_buf;
  250. tx = xfer->tx_buf;
  251. if (word_len <= 8) {
  252. data_type = OMAP_DMA_DATA_TYPE_S8;
  253. element_count = count;
  254. } else if (word_len <= 16) {
  255. data_type = OMAP_DMA_DATA_TYPE_S16;
  256. element_count = count >> 1;
  257. } else /* word_len <= 32 */ {
  258. data_type = OMAP_DMA_DATA_TYPE_S32;
  259. element_count = count >> 2;
  260. }
  261. if (tx != NULL) {
  262. omap_set_dma_transfer_params(mcspi_dma->dma_tx_channel,
  263. data_type, element_count, 1,
  264. OMAP_DMA_SYNC_ELEMENT,
  265. mcspi_dma->dma_tx_sync_dev, 0);
  266. omap_set_dma_dest_params(mcspi_dma->dma_tx_channel, 0,
  267. OMAP_DMA_AMODE_CONSTANT,
  268. tx_reg, 0, 0);
  269. omap_set_dma_src_params(mcspi_dma->dma_tx_channel, 0,
  270. OMAP_DMA_AMODE_POST_INC,
  271. xfer->tx_dma, 0, 0);
  272. }
  273. if (rx != NULL) {
  274. omap_set_dma_transfer_params(mcspi_dma->dma_rx_channel,
  275. data_type, element_count - 1, 1,
  276. OMAP_DMA_SYNC_ELEMENT,
  277. mcspi_dma->dma_rx_sync_dev, 1);
  278. omap_set_dma_src_params(mcspi_dma->dma_rx_channel, 0,
  279. OMAP_DMA_AMODE_CONSTANT,
  280. rx_reg, 0, 0);
  281. omap_set_dma_dest_params(mcspi_dma->dma_rx_channel, 0,
  282. OMAP_DMA_AMODE_POST_INC,
  283. xfer->rx_dma, 0, 0);
  284. }
  285. if (tx != NULL) {
  286. omap_start_dma(mcspi_dma->dma_tx_channel);
  287. omap2_mcspi_set_dma_req(spi, 0, 1);
  288. }
  289. if (rx != NULL) {
  290. omap_start_dma(mcspi_dma->dma_rx_channel);
  291. omap2_mcspi_set_dma_req(spi, 1, 1);
  292. }
  293. if (tx != NULL) {
  294. wait_for_completion(&mcspi_dma->dma_tx_completion);
  295. dma_unmap_single(NULL, xfer->tx_dma, count, DMA_TO_DEVICE);
  296. }
  297. if (rx != NULL) {
  298. wait_for_completion(&mcspi_dma->dma_rx_completion);
  299. dma_unmap_single(NULL, xfer->rx_dma, count, DMA_FROM_DEVICE);
  300. omap2_mcspi_set_enable(spi, 0);
  301. if (likely(mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHSTAT0)
  302. & OMAP2_MCSPI_CHSTAT_RXS)) {
  303. u32 w;
  304. w = mcspi_read_cs_reg(spi, OMAP2_MCSPI_RX0);
  305. if (word_len <= 8)
  306. ((u8 *)xfer->rx_buf)[element_count - 1] = w;
  307. else if (word_len <= 16)
  308. ((u16 *)xfer->rx_buf)[element_count - 1] = w;
  309. else /* word_len <= 32 */
  310. ((u32 *)xfer->rx_buf)[element_count - 1] = w;
  311. } else {
  312. dev_err(&spi->dev, "DMA RX last word empty");
  313. count -= (word_len <= 8) ? 1 :
  314. (word_len <= 16) ? 2 :
  315. /* word_len <= 32 */ 4;
  316. }
  317. omap2_mcspi_set_enable(spi, 1);
  318. }
  319. return count;
  320. }
  321. static int mcspi_wait_for_reg_bit(void __iomem *reg, unsigned long bit)
  322. {
  323. unsigned long timeout;
  324. timeout = jiffies + msecs_to_jiffies(1000);
  325. while (!(__raw_readl(reg) & bit)) {
  326. if (time_after(jiffies, timeout))
  327. return -1;
  328. cpu_relax();
  329. }
  330. return 0;
  331. }
  332. static unsigned
  333. omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
  334. {
  335. struct omap2_mcspi *mcspi;
  336. struct omap2_mcspi_cs *cs = spi->controller_state;
  337. unsigned int count, c;
  338. u32 l;
  339. void __iomem *base = cs->base;
  340. void __iomem *tx_reg;
  341. void __iomem *rx_reg;
  342. void __iomem *chstat_reg;
  343. int word_len;
  344. mcspi = spi_master_get_devdata(spi->master);
  345. count = xfer->len;
  346. c = count;
  347. word_len = cs->word_len;
  348. l = mcspi_cached_chconf0(spi);
  349. l &= ~OMAP2_MCSPI_CHCONF_TRM_MASK;
  350. /* We store the pre-calculated register addresses on stack to speed
  351. * up the transfer loop. */
  352. tx_reg = base + OMAP2_MCSPI_TX0;
  353. rx_reg = base + OMAP2_MCSPI_RX0;
  354. chstat_reg = base + OMAP2_MCSPI_CHSTAT0;
  355. if (word_len <= 8) {
  356. u8 *rx;
  357. const u8 *tx;
  358. rx = xfer->rx_buf;
  359. tx = xfer->tx_buf;
  360. do {
  361. c -= 1;
  362. if (tx != NULL) {
  363. if (mcspi_wait_for_reg_bit(chstat_reg,
  364. OMAP2_MCSPI_CHSTAT_TXS) < 0) {
  365. dev_err(&spi->dev, "TXS timed out\n");
  366. goto out;
  367. }
  368. #ifdef VERBOSE
  369. dev_dbg(&spi->dev, "write-%d %02x\n",
  370. word_len, *tx);
  371. #endif
  372. __raw_writel(*tx++, tx_reg);
  373. }
  374. if (rx != NULL) {
  375. if (mcspi_wait_for_reg_bit(chstat_reg,
  376. OMAP2_MCSPI_CHSTAT_RXS) < 0) {
  377. dev_err(&spi->dev, "RXS timed out\n");
  378. goto out;
  379. }
  380. /* prevent last RX_ONLY read from triggering
  381. * more word i/o: switch to rx+tx
  382. */
  383. if (c == 0 && tx == NULL)
  384. mcspi_write_chconf0(spi, l);
  385. *rx++ = __raw_readl(rx_reg);
  386. #ifdef VERBOSE
  387. dev_dbg(&spi->dev, "read-%d %02x\n",
  388. word_len, *(rx - 1));
  389. #endif
  390. }
  391. } while (c);
  392. } else if (word_len <= 16) {
  393. u16 *rx;
  394. const u16 *tx;
  395. rx = xfer->rx_buf;
  396. tx = xfer->tx_buf;
  397. do {
  398. c -= 2;
  399. if (tx != NULL) {
  400. if (mcspi_wait_for_reg_bit(chstat_reg,
  401. OMAP2_MCSPI_CHSTAT_TXS) < 0) {
  402. dev_err(&spi->dev, "TXS timed out\n");
  403. goto out;
  404. }
  405. #ifdef VERBOSE
  406. dev_dbg(&spi->dev, "write-%d %04x\n",
  407. word_len, *tx);
  408. #endif
  409. __raw_writel(*tx++, tx_reg);
  410. }
  411. if (rx != NULL) {
  412. if (mcspi_wait_for_reg_bit(chstat_reg,
  413. OMAP2_MCSPI_CHSTAT_RXS) < 0) {
  414. dev_err(&spi->dev, "RXS timed out\n");
  415. goto out;
  416. }
  417. /* prevent last RX_ONLY read from triggering
  418. * more word i/o: switch to rx+tx
  419. */
  420. if (c == 0 && tx == NULL)
  421. mcspi_write_chconf0(spi, l);
  422. *rx++ = __raw_readl(rx_reg);
  423. #ifdef VERBOSE
  424. dev_dbg(&spi->dev, "read-%d %04x\n",
  425. word_len, *(rx - 1));
  426. #endif
  427. }
  428. } while (c);
  429. } else if (word_len <= 32) {
  430. u32 *rx;
  431. const u32 *tx;
  432. rx = xfer->rx_buf;
  433. tx = xfer->tx_buf;
  434. do {
  435. c -= 4;
  436. if (tx != NULL) {
  437. if (mcspi_wait_for_reg_bit(chstat_reg,
  438. OMAP2_MCSPI_CHSTAT_TXS) < 0) {
  439. dev_err(&spi->dev, "TXS timed out\n");
  440. goto out;
  441. }
  442. #ifdef VERBOSE
  443. dev_dbg(&spi->dev, "write-%d %04x\n",
  444. word_len, *tx);
  445. #endif
  446. __raw_writel(*tx++, tx_reg);
  447. }
  448. if (rx != NULL) {
  449. if (mcspi_wait_for_reg_bit(chstat_reg,
  450. OMAP2_MCSPI_CHSTAT_RXS) < 0) {
  451. dev_err(&spi->dev, "RXS timed out\n");
  452. goto out;
  453. }
  454. /* prevent last RX_ONLY read from triggering
  455. * more word i/o: switch to rx+tx
  456. */
  457. if (c == 0 && tx == NULL)
  458. mcspi_write_chconf0(spi, l);
  459. *rx++ = __raw_readl(rx_reg);
  460. #ifdef VERBOSE
  461. dev_dbg(&spi->dev, "read-%d %04x\n",
  462. word_len, *(rx - 1));
  463. #endif
  464. }
  465. } while (c);
  466. }
  467. /* for TX_ONLY mode, be sure all words have shifted out */
  468. if (xfer->rx_buf == NULL) {
  469. if (mcspi_wait_for_reg_bit(chstat_reg,
  470. OMAP2_MCSPI_CHSTAT_TXS) < 0) {
  471. dev_err(&spi->dev, "TXS timed out\n");
  472. } else if (mcspi_wait_for_reg_bit(chstat_reg,
  473. OMAP2_MCSPI_CHSTAT_EOT) < 0)
  474. dev_err(&spi->dev, "EOT timed out\n");
  475. }
  476. out:
  477. return count - c;
  478. }
  479. /* called only when no transfer is active to this device */
  480. static int omap2_mcspi_setup_transfer(struct spi_device *spi,
  481. struct spi_transfer *t)
  482. {
  483. struct omap2_mcspi_cs *cs = spi->controller_state;
  484. struct omap2_mcspi *mcspi;
  485. struct spi_master *spi_cntrl;
  486. u32 l = 0, div = 0;
  487. u8 word_len = spi->bits_per_word;
  488. mcspi = spi_master_get_devdata(spi->master);
  489. spi_cntrl = mcspi->master;
  490. if (t != NULL && t->bits_per_word)
  491. word_len = t->bits_per_word;
  492. cs->word_len = word_len;
  493. if (spi->max_speed_hz) {
  494. while (div <= 15 && (OMAP2_MCSPI_MAX_FREQ / (1 << div))
  495. > spi->max_speed_hz)
  496. div++;
  497. } else
  498. div = 15;
  499. l = mcspi_cached_chconf0(spi);
  500. /* standard 4-wire master mode: SCK, MOSI/out, MISO/in, nCS
  501. * REVISIT: this controller could support SPI_3WIRE mode.
  502. */
  503. l &= ~(OMAP2_MCSPI_CHCONF_IS|OMAP2_MCSPI_CHCONF_DPE1);
  504. l |= OMAP2_MCSPI_CHCONF_DPE0;
  505. /* wordlength */
  506. l &= ~OMAP2_MCSPI_CHCONF_WL_MASK;
  507. l |= (word_len - 1) << 7;
  508. /* set chipselect polarity; manage with FORCE */
  509. if (!(spi->mode & SPI_CS_HIGH))
  510. l |= OMAP2_MCSPI_CHCONF_EPOL; /* active-low; normal */
  511. else
  512. l &= ~OMAP2_MCSPI_CHCONF_EPOL;
  513. /* set clock divisor */
  514. l &= ~OMAP2_MCSPI_CHCONF_CLKD_MASK;
  515. l |= div << 2;
  516. /* set SPI mode 0..3 */
  517. if (spi->mode & SPI_CPOL)
  518. l |= OMAP2_MCSPI_CHCONF_POL;
  519. else
  520. l &= ~OMAP2_MCSPI_CHCONF_POL;
  521. if (spi->mode & SPI_CPHA)
  522. l |= OMAP2_MCSPI_CHCONF_PHA;
  523. else
  524. l &= ~OMAP2_MCSPI_CHCONF_PHA;
  525. mcspi_write_chconf0(spi, l);
  526. dev_dbg(&spi->dev, "setup: speed %d, sample %s edge, clk %s\n",
  527. OMAP2_MCSPI_MAX_FREQ / (1 << div),
  528. (spi->mode & SPI_CPHA) ? "trailing" : "leading",
  529. (spi->mode & SPI_CPOL) ? "inverted" : "normal");
  530. return 0;
  531. }
  532. static void omap2_mcspi_dma_rx_callback(int lch, u16 ch_status, void *data)
  533. {
  534. struct spi_device *spi = data;
  535. struct omap2_mcspi *mcspi;
  536. struct omap2_mcspi_dma *mcspi_dma;
  537. mcspi = spi_master_get_devdata(spi->master);
  538. mcspi_dma = &(mcspi->dma_channels[spi->chip_select]);
  539. complete(&mcspi_dma->dma_rx_completion);
  540. /* We must disable the DMA RX request */
  541. omap2_mcspi_set_dma_req(spi, 1, 0);
  542. }
  543. static void omap2_mcspi_dma_tx_callback(int lch, u16 ch_status, void *data)
  544. {
  545. struct spi_device *spi = data;
  546. struct omap2_mcspi *mcspi;
  547. struct omap2_mcspi_dma *mcspi_dma;
  548. mcspi = spi_master_get_devdata(spi->master);
  549. mcspi_dma = &(mcspi->dma_channels[spi->chip_select]);
  550. complete(&mcspi_dma->dma_tx_completion);
  551. /* We must disable the DMA TX request */
  552. omap2_mcspi_set_dma_req(spi, 0, 0);
  553. }
  554. static int omap2_mcspi_request_dma(struct spi_device *spi)
  555. {
  556. struct spi_master *master = spi->master;
  557. struct omap2_mcspi *mcspi;
  558. struct omap2_mcspi_dma *mcspi_dma;
  559. mcspi = spi_master_get_devdata(master);
  560. mcspi_dma = mcspi->dma_channels + spi->chip_select;
  561. if (omap_request_dma(mcspi_dma->dma_rx_sync_dev, "McSPI RX",
  562. omap2_mcspi_dma_rx_callback, spi,
  563. &mcspi_dma->dma_rx_channel)) {
  564. dev_err(&spi->dev, "no RX DMA channel for McSPI\n");
  565. return -EAGAIN;
  566. }
  567. if (omap_request_dma(mcspi_dma->dma_tx_sync_dev, "McSPI TX",
  568. omap2_mcspi_dma_tx_callback, spi,
  569. &mcspi_dma->dma_tx_channel)) {
  570. omap_free_dma(mcspi_dma->dma_rx_channel);
  571. mcspi_dma->dma_rx_channel = -1;
  572. dev_err(&spi->dev, "no TX DMA channel for McSPI\n");
  573. return -EAGAIN;
  574. }
  575. init_completion(&mcspi_dma->dma_rx_completion);
  576. init_completion(&mcspi_dma->dma_tx_completion);
  577. return 0;
  578. }
  579. static int omap2_mcspi_setup(struct spi_device *spi)
  580. {
  581. int ret;
  582. struct omap2_mcspi *mcspi;
  583. struct omap2_mcspi_dma *mcspi_dma;
  584. struct omap2_mcspi_cs *cs = spi->controller_state;
  585. if (spi->bits_per_word < 4 || spi->bits_per_word > 32) {
  586. dev_dbg(&spi->dev, "setup: unsupported %d bit words\n",
  587. spi->bits_per_word);
  588. return -EINVAL;
  589. }
  590. mcspi = spi_master_get_devdata(spi->master);
  591. mcspi_dma = &mcspi->dma_channels[spi->chip_select];
  592. if (!cs) {
  593. cs = kzalloc(sizeof *cs, GFP_KERNEL);
  594. if (!cs)
  595. return -ENOMEM;
  596. cs->base = mcspi->base + spi->chip_select * 0x14;
  597. cs->phys = mcspi->phys + spi->chip_select * 0x14;
  598. cs->chconf0 = 0;
  599. spi->controller_state = cs;
  600. }
  601. if (mcspi_dma->dma_rx_channel == -1
  602. || mcspi_dma->dma_tx_channel == -1) {
  603. ret = omap2_mcspi_request_dma(spi);
  604. if (ret < 0)
  605. return ret;
  606. }
  607. if (omap2_mcspi_enable_clocks(mcspi))
  608. return -ENODEV;
  609. ret = omap2_mcspi_setup_transfer(spi, NULL);
  610. omap2_mcspi_disable_clocks(mcspi);
  611. return ret;
  612. }
  613. static void omap2_mcspi_cleanup(struct spi_device *spi)
  614. {
  615. struct omap2_mcspi *mcspi;
  616. struct omap2_mcspi_dma *mcspi_dma;
  617. mcspi = spi_master_get_devdata(spi->master);
  618. mcspi_dma = &mcspi->dma_channels[spi->chip_select];
  619. kfree(spi->controller_state);
  620. if (mcspi_dma->dma_rx_channel != -1) {
  621. omap_free_dma(mcspi_dma->dma_rx_channel);
  622. mcspi_dma->dma_rx_channel = -1;
  623. }
  624. if (mcspi_dma->dma_tx_channel != -1) {
  625. omap_free_dma(mcspi_dma->dma_tx_channel);
  626. mcspi_dma->dma_tx_channel = -1;
  627. }
  628. }
  629. static void omap2_mcspi_work(struct work_struct *work)
  630. {
  631. struct omap2_mcspi *mcspi;
  632. mcspi = container_of(work, struct omap2_mcspi, work);
  633. spin_lock_irq(&mcspi->lock);
  634. if (omap2_mcspi_enable_clocks(mcspi))
  635. goto out;
  636. /* We only enable one channel at a time -- the one whose message is
  637. * at the head of the queue -- although this controller would gladly
  638. * arbitrate among multiple channels. This corresponds to "single
  639. * channel" master mode. As a side effect, we need to manage the
  640. * chipselect with the FORCE bit ... CS != channel enable.
  641. */
  642. while (!list_empty(&mcspi->msg_queue)) {
  643. struct spi_message *m;
  644. struct spi_device *spi;
  645. struct spi_transfer *t = NULL;
  646. int cs_active = 0;
  647. struct omap2_mcspi_cs *cs;
  648. int par_override = 0;
  649. int status = 0;
  650. u32 chconf;
  651. m = container_of(mcspi->msg_queue.next, struct spi_message,
  652. queue);
  653. list_del_init(&m->queue);
  654. spin_unlock_irq(&mcspi->lock);
  655. spi = m->spi;
  656. cs = spi->controller_state;
  657. omap2_mcspi_set_enable(spi, 1);
  658. list_for_each_entry(t, &m->transfers, transfer_list) {
  659. if (t->tx_buf == NULL && t->rx_buf == NULL && t->len) {
  660. status = -EINVAL;
  661. break;
  662. }
  663. if (par_override || t->speed_hz || t->bits_per_word) {
  664. par_override = 1;
  665. status = omap2_mcspi_setup_transfer(spi, t);
  666. if (status < 0)
  667. break;
  668. if (!t->speed_hz && !t->bits_per_word)
  669. par_override = 0;
  670. }
  671. if (!cs_active) {
  672. omap2_mcspi_force_cs(spi, 1);
  673. cs_active = 1;
  674. }
  675. chconf = mcspi_cached_chconf0(spi);
  676. chconf &= ~OMAP2_MCSPI_CHCONF_TRM_MASK;
  677. if (t->tx_buf == NULL)
  678. chconf |= OMAP2_MCSPI_CHCONF_TRM_RX_ONLY;
  679. else if (t->rx_buf == NULL)
  680. chconf |= OMAP2_MCSPI_CHCONF_TRM_TX_ONLY;
  681. mcspi_write_chconf0(spi, chconf);
  682. if (t->len) {
  683. unsigned count;
  684. /* RX_ONLY mode needs dummy data in TX reg */
  685. if (t->tx_buf == NULL)
  686. __raw_writel(0, cs->base
  687. + OMAP2_MCSPI_TX0);
  688. if (m->is_dma_mapped || t->len >= DMA_MIN_BYTES)
  689. count = omap2_mcspi_txrx_dma(spi, t);
  690. else
  691. count = omap2_mcspi_txrx_pio(spi, t);
  692. m->actual_length += count;
  693. if (count != t->len) {
  694. status = -EIO;
  695. break;
  696. }
  697. }
  698. if (t->delay_usecs)
  699. udelay(t->delay_usecs);
  700. /* ignore the "leave it on after last xfer" hint */
  701. if (t->cs_change) {
  702. omap2_mcspi_force_cs(spi, 0);
  703. cs_active = 0;
  704. }
  705. }
  706. /* Restore defaults if they were overriden */
  707. if (par_override) {
  708. par_override = 0;
  709. status = omap2_mcspi_setup_transfer(spi, NULL);
  710. }
  711. if (cs_active)
  712. omap2_mcspi_force_cs(spi, 0);
  713. omap2_mcspi_set_enable(spi, 0);
  714. m->status = status;
  715. m->complete(m->context);
  716. spin_lock_irq(&mcspi->lock);
  717. }
  718. omap2_mcspi_disable_clocks(mcspi);
  719. out:
  720. spin_unlock_irq(&mcspi->lock);
  721. }
  722. static int omap2_mcspi_transfer(struct spi_device *spi, struct spi_message *m)
  723. {
  724. struct omap2_mcspi *mcspi;
  725. unsigned long flags;
  726. struct spi_transfer *t;
  727. m->actual_length = 0;
  728. m->status = 0;
  729. /* reject invalid messages and transfers */
  730. if (list_empty(&m->transfers) || !m->complete)
  731. return -EINVAL;
  732. list_for_each_entry(t, &m->transfers, transfer_list) {
  733. const void *tx_buf = t->tx_buf;
  734. void *rx_buf = t->rx_buf;
  735. unsigned len = t->len;
  736. if (t->speed_hz > OMAP2_MCSPI_MAX_FREQ
  737. || (len && !(rx_buf || tx_buf))
  738. || (t->bits_per_word &&
  739. ( t->bits_per_word < 4
  740. || t->bits_per_word > 32))) {
  741. dev_dbg(&spi->dev, "transfer: %d Hz, %d %s%s, %d bpw\n",
  742. t->speed_hz,
  743. len,
  744. tx_buf ? "tx" : "",
  745. rx_buf ? "rx" : "",
  746. t->bits_per_word);
  747. return -EINVAL;
  748. }
  749. if (t->speed_hz && t->speed_hz < OMAP2_MCSPI_MAX_FREQ/(1<<16)) {
  750. dev_dbg(&spi->dev, "%d Hz max exceeds %d\n",
  751. t->speed_hz,
  752. OMAP2_MCSPI_MAX_FREQ/(1<<16));
  753. return -EINVAL;
  754. }
  755. if (m->is_dma_mapped || len < DMA_MIN_BYTES)
  756. continue;
  757. /* Do DMA mapping "early" for better error reporting and
  758. * dcache use. Note that if dma_unmap_single() ever starts
  759. * to do real work on ARM, we'd need to clean up mappings
  760. * for previous transfers on *ALL* exits of this loop...
  761. */
  762. if (tx_buf != NULL) {
  763. t->tx_dma = dma_map_single(&spi->dev, (void *) tx_buf,
  764. len, DMA_TO_DEVICE);
  765. if (dma_mapping_error(&spi->dev, t->tx_dma)) {
  766. dev_dbg(&spi->dev, "dma %cX %d bytes error\n",
  767. 'T', len);
  768. return -EINVAL;
  769. }
  770. }
  771. if (rx_buf != NULL) {
  772. t->rx_dma = dma_map_single(&spi->dev, rx_buf, t->len,
  773. DMA_FROM_DEVICE);
  774. if (dma_mapping_error(&spi->dev, t->rx_dma)) {
  775. dev_dbg(&spi->dev, "dma %cX %d bytes error\n",
  776. 'R', len);
  777. if (tx_buf != NULL)
  778. dma_unmap_single(NULL, t->tx_dma,
  779. len, DMA_TO_DEVICE);
  780. return -EINVAL;
  781. }
  782. }
  783. }
  784. mcspi = spi_master_get_devdata(spi->master);
  785. spin_lock_irqsave(&mcspi->lock, flags);
  786. list_add_tail(&m->queue, &mcspi->msg_queue);
  787. queue_work(omap2_mcspi_wq, &mcspi->work);
  788. spin_unlock_irqrestore(&mcspi->lock, flags);
  789. return 0;
  790. }
  791. static int __init omap2_mcspi_reset(struct omap2_mcspi *mcspi)
  792. {
  793. struct spi_master *master = mcspi->master;
  794. u32 tmp;
  795. if (omap2_mcspi_enable_clocks(mcspi))
  796. return -1;
  797. mcspi_write_reg(master, OMAP2_MCSPI_SYSCONFIG,
  798. OMAP2_MCSPI_SYSCONFIG_SOFTRESET);
  799. do {
  800. tmp = mcspi_read_reg(master, OMAP2_MCSPI_SYSSTATUS);
  801. } while (!(tmp & OMAP2_MCSPI_SYSSTATUS_RESETDONE));
  802. tmp = OMAP2_MCSPI_SYSCONFIG_AUTOIDLE |
  803. OMAP2_MCSPI_SYSCONFIG_ENAWAKEUP |
  804. OMAP2_MCSPI_SYSCONFIG_SMARTIDLE;
  805. mcspi_write_reg(master, OMAP2_MCSPI_SYSCONFIG, tmp);
  806. omap2_mcspi_ctx[master->bus_num - 1].sysconfig = tmp;
  807. tmp = OMAP2_MCSPI_WAKEUPENABLE_WKEN;
  808. mcspi_write_reg(master, OMAP2_MCSPI_WAKEUPENABLE, tmp);
  809. omap2_mcspi_ctx[master->bus_num - 1].wakeupenable = tmp;
  810. omap2_mcspi_set_master_mode(master);
  811. omap2_mcspi_disable_clocks(mcspi);
  812. return 0;
  813. }
  814. static u8 __initdata spi1_rxdma_id [] = {
  815. OMAP24XX_DMA_SPI1_RX0,
  816. OMAP24XX_DMA_SPI1_RX1,
  817. OMAP24XX_DMA_SPI1_RX2,
  818. OMAP24XX_DMA_SPI1_RX3,
  819. };
  820. static u8 __initdata spi1_txdma_id [] = {
  821. OMAP24XX_DMA_SPI1_TX0,
  822. OMAP24XX_DMA_SPI1_TX1,
  823. OMAP24XX_DMA_SPI1_TX2,
  824. OMAP24XX_DMA_SPI1_TX3,
  825. };
  826. static u8 __initdata spi2_rxdma_id[] = {
  827. OMAP24XX_DMA_SPI2_RX0,
  828. OMAP24XX_DMA_SPI2_RX1,
  829. };
  830. static u8 __initdata spi2_txdma_id[] = {
  831. OMAP24XX_DMA_SPI2_TX0,
  832. OMAP24XX_DMA_SPI2_TX1,
  833. };
  834. #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP34XX)
  835. static u8 __initdata spi3_rxdma_id[] = {
  836. OMAP24XX_DMA_SPI3_RX0,
  837. OMAP24XX_DMA_SPI3_RX1,
  838. };
  839. static u8 __initdata spi3_txdma_id[] = {
  840. OMAP24XX_DMA_SPI3_TX0,
  841. OMAP24XX_DMA_SPI3_TX1,
  842. };
  843. #endif
  844. #ifdef CONFIG_ARCH_OMAP3
  845. static u8 __initdata spi4_rxdma_id[] = {
  846. OMAP34XX_DMA_SPI4_RX0,
  847. };
  848. static u8 __initdata spi4_txdma_id[] = {
  849. OMAP34XX_DMA_SPI4_TX0,
  850. };
  851. #endif
  852. static int __init omap2_mcspi_probe(struct platform_device *pdev)
  853. {
  854. struct spi_master *master;
  855. struct omap2_mcspi *mcspi;
  856. struct resource *r;
  857. int status = 0, i;
  858. const u8 *rxdma_id, *txdma_id;
  859. unsigned num_chipselect;
  860. switch (pdev->id) {
  861. case 1:
  862. rxdma_id = spi1_rxdma_id;
  863. txdma_id = spi1_txdma_id;
  864. num_chipselect = 4;
  865. break;
  866. case 2:
  867. rxdma_id = spi2_rxdma_id;
  868. txdma_id = spi2_txdma_id;
  869. num_chipselect = 2;
  870. break;
  871. #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3)
  872. case 3:
  873. rxdma_id = spi3_rxdma_id;
  874. txdma_id = spi3_txdma_id;
  875. num_chipselect = 2;
  876. break;
  877. #endif
  878. #ifdef CONFIG_ARCH_OMAP3
  879. case 4:
  880. rxdma_id = spi4_rxdma_id;
  881. txdma_id = spi4_txdma_id;
  882. num_chipselect = 1;
  883. break;
  884. #endif
  885. default:
  886. return -EINVAL;
  887. }
  888. master = spi_alloc_master(&pdev->dev, sizeof *mcspi);
  889. if (master == NULL) {
  890. dev_dbg(&pdev->dev, "master allocation failed\n");
  891. return -ENOMEM;
  892. }
  893. /* the spi->mode bits understood by this driver: */
  894. master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
  895. if (pdev->id != -1)
  896. master->bus_num = pdev->id;
  897. master->setup = omap2_mcspi_setup;
  898. master->transfer = omap2_mcspi_transfer;
  899. master->cleanup = omap2_mcspi_cleanup;
  900. master->num_chipselect = num_chipselect;
  901. dev_set_drvdata(&pdev->dev, master);
  902. mcspi = spi_master_get_devdata(master);
  903. mcspi->master = master;
  904. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  905. if (r == NULL) {
  906. status = -ENODEV;
  907. goto err1;
  908. }
  909. if (!request_mem_region(r->start, (r->end - r->start) + 1,
  910. dev_name(&pdev->dev))) {
  911. status = -EBUSY;
  912. goto err1;
  913. }
  914. mcspi->phys = r->start;
  915. mcspi->base = ioremap(r->start, r->end - r->start + 1);
  916. if (!mcspi->base) {
  917. dev_dbg(&pdev->dev, "can't ioremap MCSPI\n");
  918. status = -ENOMEM;
  919. goto err1aa;
  920. }
  921. INIT_WORK(&mcspi->work, omap2_mcspi_work);
  922. spin_lock_init(&mcspi->lock);
  923. INIT_LIST_HEAD(&mcspi->msg_queue);
  924. mcspi->ick = clk_get(&pdev->dev, "ick");
  925. if (IS_ERR(mcspi->ick)) {
  926. dev_dbg(&pdev->dev, "can't get mcspi_ick\n");
  927. status = PTR_ERR(mcspi->ick);
  928. goto err1a;
  929. }
  930. mcspi->fck = clk_get(&pdev->dev, "fck");
  931. if (IS_ERR(mcspi->fck)) {
  932. dev_dbg(&pdev->dev, "can't get mcspi_fck\n");
  933. status = PTR_ERR(mcspi->fck);
  934. goto err2;
  935. }
  936. mcspi->dma_channels = kcalloc(master->num_chipselect,
  937. sizeof(struct omap2_mcspi_dma),
  938. GFP_KERNEL);
  939. if (mcspi->dma_channels == NULL)
  940. goto err3;
  941. for (i = 0; i < num_chipselect; i++) {
  942. mcspi->dma_channels[i].dma_rx_channel = -1;
  943. mcspi->dma_channels[i].dma_rx_sync_dev = rxdma_id[i];
  944. mcspi->dma_channels[i].dma_tx_channel = -1;
  945. mcspi->dma_channels[i].dma_tx_sync_dev = txdma_id[i];
  946. }
  947. if (omap2_mcspi_reset(mcspi) < 0)
  948. goto err4;
  949. status = spi_register_master(master);
  950. if (status < 0)
  951. goto err4;
  952. return status;
  953. err4:
  954. kfree(mcspi->dma_channels);
  955. err3:
  956. clk_put(mcspi->fck);
  957. err2:
  958. clk_put(mcspi->ick);
  959. err1a:
  960. iounmap(mcspi->base);
  961. err1aa:
  962. release_mem_region(r->start, (r->end - r->start) + 1);
  963. err1:
  964. spi_master_put(master);
  965. return status;
  966. }
  967. static int __exit omap2_mcspi_remove(struct platform_device *pdev)
  968. {
  969. struct spi_master *master;
  970. struct omap2_mcspi *mcspi;
  971. struct omap2_mcspi_dma *dma_channels;
  972. struct resource *r;
  973. void __iomem *base;
  974. master = dev_get_drvdata(&pdev->dev);
  975. mcspi = spi_master_get_devdata(master);
  976. dma_channels = mcspi->dma_channels;
  977. clk_put(mcspi->fck);
  978. clk_put(mcspi->ick);
  979. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  980. release_mem_region(r->start, (r->end - r->start) + 1);
  981. base = mcspi->base;
  982. spi_unregister_master(master);
  983. iounmap(base);
  984. kfree(dma_channels);
  985. return 0;
  986. }
  987. /* work with hotplug and coldplug */
  988. MODULE_ALIAS("platform:omap2_mcspi");
  989. static struct platform_driver omap2_mcspi_driver = {
  990. .driver = {
  991. .name = "omap2_mcspi",
  992. .owner = THIS_MODULE,
  993. },
  994. .remove = __exit_p(omap2_mcspi_remove),
  995. };
  996. static int __init omap2_mcspi_init(void)
  997. {
  998. omap2_mcspi_wq = create_singlethread_workqueue(
  999. omap2_mcspi_driver.driver.name);
  1000. if (omap2_mcspi_wq == NULL)
  1001. return -1;
  1002. return platform_driver_probe(&omap2_mcspi_driver, omap2_mcspi_probe);
  1003. }
  1004. subsys_initcall(omap2_mcspi_init);
  1005. static void __exit omap2_mcspi_exit(void)
  1006. {
  1007. platform_driver_unregister(&omap2_mcspi_driver);
  1008. destroy_workqueue(omap2_mcspi_wq);
  1009. }
  1010. module_exit(omap2_mcspi_exit);
  1011. MODULE_LICENSE("GPL");