spi-pxa2xx.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821
  1. /*
  2. * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <linux/init.h>
  19. #include <linux/module.h>
  20. #include <linux/device.h>
  21. #include <linux/ioport.h>
  22. #include <linux/errno.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/spi/pxa2xx_spi.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/spi/spi.h>
  28. #include <linux/workqueue.h>
  29. #include <linux/delay.h>
  30. #include <linux/gpio.h>
  31. #include <linux/slab.h>
  32. #include <asm/io.h>
  33. #include <asm/irq.h>
  34. #include <asm/delay.h>
  35. MODULE_AUTHOR("Stephen Street");
  36. MODULE_DESCRIPTION("PXA2xx SSP SPI Controller");
  37. MODULE_LICENSE("GPL");
  38. MODULE_ALIAS("platform:pxa2xx-spi");
  39. #define MAX_BUSES 3
  40. #define TIMOUT_DFLT 1000
  41. #define DMA_INT_MASK (DCSR_ENDINTR | DCSR_STARTINTR | DCSR_BUSERR)
  42. #define RESET_DMA_CHANNEL (DCSR_NODESC | DMA_INT_MASK)
  43. #define IS_DMA_ALIGNED(x) ((((u32)(x)) & 0x07) == 0)
  44. #define MAX_DMA_LEN 8191
  45. #define DMA_ALIGNMENT 8
  46. /*
  47. * for testing SSCR1 changes that require SSP restart, basically
  48. * everything except the service and interrupt enables, the pxa270 developer
  49. * manual says only SSCR1_SCFR, SSCR1_SPH, SSCR1_SPO need to be in this
  50. * list, but the PXA255 dev man says all bits without really meaning the
  51. * service and interrupt enables
  52. */
  53. #define SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_SCFR \
  54. | SSCR1_ECRA | SSCR1_ECRB | SSCR1_SCLKDIR \
  55. | SSCR1_SFRMDIR | SSCR1_RWOT | SSCR1_TRAIL \
  56. | SSCR1_IFS | SSCR1_STRF | SSCR1_EFWR \
  57. | SSCR1_RFT | SSCR1_TFT | SSCR1_MWDS \
  58. | SSCR1_SPH | SSCR1_SPO | SSCR1_LBM)
  59. #define DEFINE_SSP_REG(reg, off) \
  60. static inline u32 read_##reg(void const __iomem *p) \
  61. { return __raw_readl(p + (off)); } \
  62. \
  63. static inline void write_##reg(u32 v, void __iomem *p) \
  64. { __raw_writel(v, p + (off)); }
  65. DEFINE_SSP_REG(SSCR0, 0x00)
  66. DEFINE_SSP_REG(SSCR1, 0x04)
  67. DEFINE_SSP_REG(SSSR, 0x08)
  68. DEFINE_SSP_REG(SSITR, 0x0c)
  69. DEFINE_SSP_REG(SSDR, 0x10)
  70. DEFINE_SSP_REG(SSTO, 0x28)
  71. DEFINE_SSP_REG(SSPSP, 0x2c)
  72. #define START_STATE ((void*)0)
  73. #define RUNNING_STATE ((void*)1)
  74. #define DONE_STATE ((void*)2)
  75. #define ERROR_STATE ((void*)-1)
  76. #define QUEUE_RUNNING 0
  77. #define QUEUE_STOPPED 1
  78. struct driver_data {
  79. /* Driver model hookup */
  80. struct platform_device *pdev;
  81. /* SSP Info */
  82. struct ssp_device *ssp;
  83. /* SPI framework hookup */
  84. enum pxa_ssp_type ssp_type;
  85. struct spi_master *master;
  86. /* PXA hookup */
  87. struct pxa2xx_spi_master *master_info;
  88. /* DMA setup stuff */
  89. int rx_channel;
  90. int tx_channel;
  91. u32 *null_dma_buf;
  92. /* SSP register addresses */
  93. void __iomem *ioaddr;
  94. u32 ssdr_physical;
  95. /* SSP masks*/
  96. u32 dma_cr1;
  97. u32 int_cr1;
  98. u32 clear_sr;
  99. u32 mask_sr;
  100. /* Driver message queue */
  101. struct workqueue_struct *workqueue;
  102. struct work_struct pump_messages;
  103. spinlock_t lock;
  104. struct list_head queue;
  105. int busy;
  106. int run;
  107. /* Message Transfer pump */
  108. struct tasklet_struct pump_transfers;
  109. /* Current message transfer state info */
  110. struct spi_message* cur_msg;
  111. struct spi_transfer* cur_transfer;
  112. struct chip_data *cur_chip;
  113. size_t len;
  114. void *tx;
  115. void *tx_end;
  116. void *rx;
  117. void *rx_end;
  118. int dma_mapped;
  119. dma_addr_t rx_dma;
  120. dma_addr_t tx_dma;
  121. size_t rx_map_len;
  122. size_t tx_map_len;
  123. u8 n_bytes;
  124. u32 dma_width;
  125. int (*write)(struct driver_data *drv_data);
  126. int (*read)(struct driver_data *drv_data);
  127. irqreturn_t (*transfer_handler)(struct driver_data *drv_data);
  128. void (*cs_control)(u32 command);
  129. };
  130. struct chip_data {
  131. u32 cr0;
  132. u32 cr1;
  133. u32 psp;
  134. u32 timeout;
  135. u8 n_bytes;
  136. u32 dma_width;
  137. u32 dma_burst_size;
  138. u32 threshold;
  139. u32 dma_threshold;
  140. u8 enable_dma;
  141. u8 bits_per_word;
  142. u32 speed_hz;
  143. union {
  144. int gpio_cs;
  145. unsigned int frm;
  146. };
  147. int gpio_cs_inverted;
  148. int (*write)(struct driver_data *drv_data);
  149. int (*read)(struct driver_data *drv_data);
  150. void (*cs_control)(u32 command);
  151. };
  152. static void pump_messages(struct work_struct *work);
  153. static void cs_assert(struct driver_data *drv_data)
  154. {
  155. struct chip_data *chip = drv_data->cur_chip;
  156. if (drv_data->ssp_type == CE4100_SSP) {
  157. write_SSSR(drv_data->cur_chip->frm, drv_data->ioaddr);
  158. return;
  159. }
  160. if (chip->cs_control) {
  161. chip->cs_control(PXA2XX_CS_ASSERT);
  162. return;
  163. }
  164. if (gpio_is_valid(chip->gpio_cs))
  165. gpio_set_value(chip->gpio_cs, chip->gpio_cs_inverted);
  166. }
  167. static void cs_deassert(struct driver_data *drv_data)
  168. {
  169. struct chip_data *chip = drv_data->cur_chip;
  170. if (drv_data->ssp_type == CE4100_SSP)
  171. return;
  172. if (chip->cs_control) {
  173. chip->cs_control(PXA2XX_CS_DEASSERT);
  174. return;
  175. }
  176. if (gpio_is_valid(chip->gpio_cs))
  177. gpio_set_value(chip->gpio_cs, !chip->gpio_cs_inverted);
  178. }
  179. static void write_SSSR_CS(struct driver_data *drv_data, u32 val)
  180. {
  181. void __iomem *reg = drv_data->ioaddr;
  182. if (drv_data->ssp_type == CE4100_SSP)
  183. val |= read_SSSR(reg) & SSSR_ALT_FRM_MASK;
  184. write_SSSR(val, reg);
  185. }
  186. static int pxa25x_ssp_comp(struct driver_data *drv_data)
  187. {
  188. if (drv_data->ssp_type == PXA25x_SSP)
  189. return 1;
  190. if (drv_data->ssp_type == CE4100_SSP)
  191. return 1;
  192. return 0;
  193. }
  194. static int flush(struct driver_data *drv_data)
  195. {
  196. unsigned long limit = loops_per_jiffy << 1;
  197. void __iomem *reg = drv_data->ioaddr;
  198. do {
  199. while (read_SSSR(reg) & SSSR_RNE) {
  200. read_SSDR(reg);
  201. }
  202. } while ((read_SSSR(reg) & SSSR_BSY) && --limit);
  203. write_SSSR_CS(drv_data, SSSR_ROR);
  204. return limit;
  205. }
  206. static int null_writer(struct driver_data *drv_data)
  207. {
  208. void __iomem *reg = drv_data->ioaddr;
  209. u8 n_bytes = drv_data->n_bytes;
  210. if (((read_SSSR(reg) & SSSR_TFL_MASK) == SSSR_TFL_MASK)
  211. || (drv_data->tx == drv_data->tx_end))
  212. return 0;
  213. write_SSDR(0, reg);
  214. drv_data->tx += n_bytes;
  215. return 1;
  216. }
  217. static int null_reader(struct driver_data *drv_data)
  218. {
  219. void __iomem *reg = drv_data->ioaddr;
  220. u8 n_bytes = drv_data->n_bytes;
  221. while ((read_SSSR(reg) & SSSR_RNE)
  222. && (drv_data->rx < drv_data->rx_end)) {
  223. read_SSDR(reg);
  224. drv_data->rx += n_bytes;
  225. }
  226. return drv_data->rx == drv_data->rx_end;
  227. }
  228. static int u8_writer(struct driver_data *drv_data)
  229. {
  230. void __iomem *reg = drv_data->ioaddr;
  231. if (((read_SSSR(reg) & SSSR_TFL_MASK) == SSSR_TFL_MASK)
  232. || (drv_data->tx == drv_data->tx_end))
  233. return 0;
  234. write_SSDR(*(u8 *)(drv_data->tx), reg);
  235. ++drv_data->tx;
  236. return 1;
  237. }
  238. static int u8_reader(struct driver_data *drv_data)
  239. {
  240. void __iomem *reg = drv_data->ioaddr;
  241. while ((read_SSSR(reg) & SSSR_RNE)
  242. && (drv_data->rx < drv_data->rx_end)) {
  243. *(u8 *)(drv_data->rx) = read_SSDR(reg);
  244. ++drv_data->rx;
  245. }
  246. return drv_data->rx == drv_data->rx_end;
  247. }
  248. static int u16_writer(struct driver_data *drv_data)
  249. {
  250. void __iomem *reg = drv_data->ioaddr;
  251. if (((read_SSSR(reg) & SSSR_TFL_MASK) == SSSR_TFL_MASK)
  252. || (drv_data->tx == drv_data->tx_end))
  253. return 0;
  254. write_SSDR(*(u16 *)(drv_data->tx), reg);
  255. drv_data->tx += 2;
  256. return 1;
  257. }
  258. static int u16_reader(struct driver_data *drv_data)
  259. {
  260. void __iomem *reg = drv_data->ioaddr;
  261. while ((read_SSSR(reg) & SSSR_RNE)
  262. && (drv_data->rx < drv_data->rx_end)) {
  263. *(u16 *)(drv_data->rx) = read_SSDR(reg);
  264. drv_data->rx += 2;
  265. }
  266. return drv_data->rx == drv_data->rx_end;
  267. }
  268. static int u32_writer(struct driver_data *drv_data)
  269. {
  270. void __iomem *reg = drv_data->ioaddr;
  271. if (((read_SSSR(reg) & SSSR_TFL_MASK) == SSSR_TFL_MASK)
  272. || (drv_data->tx == drv_data->tx_end))
  273. return 0;
  274. write_SSDR(*(u32 *)(drv_data->tx), reg);
  275. drv_data->tx += 4;
  276. return 1;
  277. }
  278. static int u32_reader(struct driver_data *drv_data)
  279. {
  280. void __iomem *reg = drv_data->ioaddr;
  281. while ((read_SSSR(reg) & SSSR_RNE)
  282. && (drv_data->rx < drv_data->rx_end)) {
  283. *(u32 *)(drv_data->rx) = read_SSDR(reg);
  284. drv_data->rx += 4;
  285. }
  286. return drv_data->rx == drv_data->rx_end;
  287. }
  288. static void *next_transfer(struct driver_data *drv_data)
  289. {
  290. struct spi_message *msg = drv_data->cur_msg;
  291. struct spi_transfer *trans = drv_data->cur_transfer;
  292. /* Move to next transfer */
  293. if (trans->transfer_list.next != &msg->transfers) {
  294. drv_data->cur_transfer =
  295. list_entry(trans->transfer_list.next,
  296. struct spi_transfer,
  297. transfer_list);
  298. return RUNNING_STATE;
  299. } else
  300. return DONE_STATE;
  301. }
  302. static int map_dma_buffers(struct driver_data *drv_data)
  303. {
  304. struct spi_message *msg = drv_data->cur_msg;
  305. struct device *dev = &msg->spi->dev;
  306. if (!drv_data->cur_chip->enable_dma)
  307. return 0;
  308. if (msg->is_dma_mapped)
  309. return drv_data->rx_dma && drv_data->tx_dma;
  310. if (!IS_DMA_ALIGNED(drv_data->rx) || !IS_DMA_ALIGNED(drv_data->tx))
  311. return 0;
  312. /* Modify setup if rx buffer is null */
  313. if (drv_data->rx == NULL) {
  314. *drv_data->null_dma_buf = 0;
  315. drv_data->rx = drv_data->null_dma_buf;
  316. drv_data->rx_map_len = 4;
  317. } else
  318. drv_data->rx_map_len = drv_data->len;
  319. /* Modify setup if tx buffer is null */
  320. if (drv_data->tx == NULL) {
  321. *drv_data->null_dma_buf = 0;
  322. drv_data->tx = drv_data->null_dma_buf;
  323. drv_data->tx_map_len = 4;
  324. } else
  325. drv_data->tx_map_len = drv_data->len;
  326. /* Stream map the tx buffer. Always do DMA_TO_DEVICE first
  327. * so we flush the cache *before* invalidating it, in case
  328. * the tx and rx buffers overlap.
  329. */
  330. drv_data->tx_dma = dma_map_single(dev, drv_data->tx,
  331. drv_data->tx_map_len, DMA_TO_DEVICE);
  332. if (dma_mapping_error(dev, drv_data->tx_dma))
  333. return 0;
  334. /* Stream map the rx buffer */
  335. drv_data->rx_dma = dma_map_single(dev, drv_data->rx,
  336. drv_data->rx_map_len, DMA_FROM_DEVICE);
  337. if (dma_mapping_error(dev, drv_data->rx_dma)) {
  338. dma_unmap_single(dev, drv_data->tx_dma,
  339. drv_data->tx_map_len, DMA_TO_DEVICE);
  340. return 0;
  341. }
  342. return 1;
  343. }
  344. static void unmap_dma_buffers(struct driver_data *drv_data)
  345. {
  346. struct device *dev;
  347. if (!drv_data->dma_mapped)
  348. return;
  349. if (!drv_data->cur_msg->is_dma_mapped) {
  350. dev = &drv_data->cur_msg->spi->dev;
  351. dma_unmap_single(dev, drv_data->rx_dma,
  352. drv_data->rx_map_len, DMA_FROM_DEVICE);
  353. dma_unmap_single(dev, drv_data->tx_dma,
  354. drv_data->tx_map_len, DMA_TO_DEVICE);
  355. }
  356. drv_data->dma_mapped = 0;
  357. }
  358. /* caller already set message->status; dma and pio irqs are blocked */
  359. static void giveback(struct driver_data *drv_data)
  360. {
  361. struct spi_transfer* last_transfer;
  362. unsigned long flags;
  363. struct spi_message *msg;
  364. spin_lock_irqsave(&drv_data->lock, flags);
  365. msg = drv_data->cur_msg;
  366. drv_data->cur_msg = NULL;
  367. drv_data->cur_transfer = NULL;
  368. queue_work(drv_data->workqueue, &drv_data->pump_messages);
  369. spin_unlock_irqrestore(&drv_data->lock, flags);
  370. last_transfer = list_entry(msg->transfers.prev,
  371. struct spi_transfer,
  372. transfer_list);
  373. /* Delay if requested before any change in chip select */
  374. if (last_transfer->delay_usecs)
  375. udelay(last_transfer->delay_usecs);
  376. /* Drop chip select UNLESS cs_change is true or we are returning
  377. * a message with an error, or next message is for another chip
  378. */
  379. if (!last_transfer->cs_change)
  380. cs_deassert(drv_data);
  381. else {
  382. struct spi_message *next_msg;
  383. /* Holding of cs was hinted, but we need to make sure
  384. * the next message is for the same chip. Don't waste
  385. * time with the following tests unless this was hinted.
  386. *
  387. * We cannot postpone this until pump_messages, because
  388. * after calling msg->complete (below) the driver that
  389. * sent the current message could be unloaded, which
  390. * could invalidate the cs_control() callback...
  391. */
  392. /* get a pointer to the next message, if any */
  393. spin_lock_irqsave(&drv_data->lock, flags);
  394. if (list_empty(&drv_data->queue))
  395. next_msg = NULL;
  396. else
  397. next_msg = list_entry(drv_data->queue.next,
  398. struct spi_message, queue);
  399. spin_unlock_irqrestore(&drv_data->lock, flags);
  400. /* see if the next and current messages point
  401. * to the same chip
  402. */
  403. if (next_msg && next_msg->spi != msg->spi)
  404. next_msg = NULL;
  405. if (!next_msg || msg->state == ERROR_STATE)
  406. cs_deassert(drv_data);
  407. }
  408. msg->state = NULL;
  409. if (msg->complete)
  410. msg->complete(msg->context);
  411. drv_data->cur_chip = NULL;
  412. }
  413. static int wait_ssp_rx_stall(void const __iomem *ioaddr)
  414. {
  415. unsigned long limit = loops_per_jiffy << 1;
  416. while ((read_SSSR(ioaddr) & SSSR_BSY) && --limit)
  417. cpu_relax();
  418. return limit;
  419. }
  420. static int wait_dma_channel_stop(int channel)
  421. {
  422. unsigned long limit = loops_per_jiffy << 1;
  423. while (!(DCSR(channel) & DCSR_STOPSTATE) && --limit)
  424. cpu_relax();
  425. return limit;
  426. }
  427. static void dma_error_stop(struct driver_data *drv_data, const char *msg)
  428. {
  429. void __iomem *reg = drv_data->ioaddr;
  430. /* Stop and reset */
  431. DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
  432. DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
  433. write_SSSR_CS(drv_data, drv_data->clear_sr);
  434. write_SSCR1(read_SSCR1(reg) & ~drv_data->dma_cr1, reg);
  435. if (!pxa25x_ssp_comp(drv_data))
  436. write_SSTO(0, reg);
  437. flush(drv_data);
  438. write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
  439. unmap_dma_buffers(drv_data);
  440. dev_err(&drv_data->pdev->dev, "%s\n", msg);
  441. drv_data->cur_msg->state = ERROR_STATE;
  442. tasklet_schedule(&drv_data->pump_transfers);
  443. }
  444. static void dma_transfer_complete(struct driver_data *drv_data)
  445. {
  446. void __iomem *reg = drv_data->ioaddr;
  447. struct spi_message *msg = drv_data->cur_msg;
  448. /* Clear and disable interrupts on SSP and DMA channels*/
  449. write_SSCR1(read_SSCR1(reg) & ~drv_data->dma_cr1, reg);
  450. write_SSSR_CS(drv_data, drv_data->clear_sr);
  451. DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
  452. DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
  453. if (wait_dma_channel_stop(drv_data->rx_channel) == 0)
  454. dev_err(&drv_data->pdev->dev,
  455. "dma_handler: dma rx channel stop failed\n");
  456. if (wait_ssp_rx_stall(drv_data->ioaddr) == 0)
  457. dev_err(&drv_data->pdev->dev,
  458. "dma_transfer: ssp rx stall failed\n");
  459. unmap_dma_buffers(drv_data);
  460. /* update the buffer pointer for the amount completed in dma */
  461. drv_data->rx += drv_data->len -
  462. (DCMD(drv_data->rx_channel) & DCMD_LENGTH);
  463. /* read trailing data from fifo, it does not matter how many
  464. * bytes are in the fifo just read until buffer is full
  465. * or fifo is empty, which ever occurs first */
  466. drv_data->read(drv_data);
  467. /* return count of what was actually read */
  468. msg->actual_length += drv_data->len -
  469. (drv_data->rx_end - drv_data->rx);
  470. /* Transfer delays and chip select release are
  471. * handled in pump_transfers or giveback
  472. */
  473. /* Move to next transfer */
  474. msg->state = next_transfer(drv_data);
  475. /* Schedule transfer tasklet */
  476. tasklet_schedule(&drv_data->pump_transfers);
  477. }
  478. static void dma_handler(int channel, void *data)
  479. {
  480. struct driver_data *drv_data = data;
  481. u32 irq_status = DCSR(channel) & DMA_INT_MASK;
  482. if (irq_status & DCSR_BUSERR) {
  483. if (channel == drv_data->tx_channel)
  484. dma_error_stop(drv_data,
  485. "dma_handler: "
  486. "bad bus address on tx channel");
  487. else
  488. dma_error_stop(drv_data,
  489. "dma_handler: "
  490. "bad bus address on rx channel");
  491. return;
  492. }
  493. /* PXA255x_SSP has no timeout interrupt, wait for tailing bytes */
  494. if ((channel == drv_data->tx_channel)
  495. && (irq_status & DCSR_ENDINTR)
  496. && (drv_data->ssp_type == PXA25x_SSP)) {
  497. /* Wait for rx to stall */
  498. if (wait_ssp_rx_stall(drv_data->ioaddr) == 0)
  499. dev_err(&drv_data->pdev->dev,
  500. "dma_handler: ssp rx stall failed\n");
  501. /* finish this transfer, start the next */
  502. dma_transfer_complete(drv_data);
  503. }
  504. }
  505. static irqreturn_t dma_transfer(struct driver_data *drv_data)
  506. {
  507. u32 irq_status;
  508. void __iomem *reg = drv_data->ioaddr;
  509. irq_status = read_SSSR(reg) & drv_data->mask_sr;
  510. if (irq_status & SSSR_ROR) {
  511. dma_error_stop(drv_data, "dma_transfer: fifo overrun");
  512. return IRQ_HANDLED;
  513. }
  514. /* Check for false positive timeout */
  515. if ((irq_status & SSSR_TINT)
  516. && (DCSR(drv_data->tx_channel) & DCSR_RUN)) {
  517. write_SSSR(SSSR_TINT, reg);
  518. return IRQ_HANDLED;
  519. }
  520. if (irq_status & SSSR_TINT || drv_data->rx == drv_data->rx_end) {
  521. /* Clear and disable timeout interrupt, do the rest in
  522. * dma_transfer_complete */
  523. if (!pxa25x_ssp_comp(drv_data))
  524. write_SSTO(0, reg);
  525. /* finish this transfer, start the next */
  526. dma_transfer_complete(drv_data);
  527. return IRQ_HANDLED;
  528. }
  529. /* Opps problem detected */
  530. return IRQ_NONE;
  531. }
  532. static void reset_sccr1(struct driver_data *drv_data)
  533. {
  534. void __iomem *reg = drv_data->ioaddr;
  535. struct chip_data *chip = drv_data->cur_chip;
  536. u32 sccr1_reg;
  537. sccr1_reg = read_SSCR1(reg) & ~drv_data->int_cr1;
  538. sccr1_reg &= ~SSCR1_RFT;
  539. sccr1_reg |= chip->threshold;
  540. write_SSCR1(sccr1_reg, reg);
  541. }
  542. static void int_error_stop(struct driver_data *drv_data, const char* msg)
  543. {
  544. void __iomem *reg = drv_data->ioaddr;
  545. /* Stop and reset SSP */
  546. write_SSSR_CS(drv_data, drv_data->clear_sr);
  547. reset_sccr1(drv_data);
  548. if (!pxa25x_ssp_comp(drv_data))
  549. write_SSTO(0, reg);
  550. flush(drv_data);
  551. write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
  552. dev_err(&drv_data->pdev->dev, "%s\n", msg);
  553. drv_data->cur_msg->state = ERROR_STATE;
  554. tasklet_schedule(&drv_data->pump_transfers);
  555. }
  556. static void int_transfer_complete(struct driver_data *drv_data)
  557. {
  558. void __iomem *reg = drv_data->ioaddr;
  559. /* Stop SSP */
  560. write_SSSR_CS(drv_data, drv_data->clear_sr);
  561. reset_sccr1(drv_data);
  562. if (!pxa25x_ssp_comp(drv_data))
  563. write_SSTO(0, reg);
  564. /* Update total byte transferred return count actual bytes read */
  565. drv_data->cur_msg->actual_length += drv_data->len -
  566. (drv_data->rx_end - drv_data->rx);
  567. /* Transfer delays and chip select release are
  568. * handled in pump_transfers or giveback
  569. */
  570. /* Move to next transfer */
  571. drv_data->cur_msg->state = next_transfer(drv_data);
  572. /* Schedule transfer tasklet */
  573. tasklet_schedule(&drv_data->pump_transfers);
  574. }
  575. static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
  576. {
  577. void __iomem *reg = drv_data->ioaddr;
  578. u32 irq_mask = (read_SSCR1(reg) & SSCR1_TIE) ?
  579. drv_data->mask_sr : drv_data->mask_sr & ~SSSR_TFS;
  580. u32 irq_status = read_SSSR(reg) & irq_mask;
  581. if (irq_status & SSSR_ROR) {
  582. int_error_stop(drv_data, "interrupt_transfer: fifo overrun");
  583. return IRQ_HANDLED;
  584. }
  585. if (irq_status & SSSR_TINT) {
  586. write_SSSR(SSSR_TINT, reg);
  587. if (drv_data->read(drv_data)) {
  588. int_transfer_complete(drv_data);
  589. return IRQ_HANDLED;
  590. }
  591. }
  592. /* Drain rx fifo, Fill tx fifo and prevent overruns */
  593. do {
  594. if (drv_data->read(drv_data)) {
  595. int_transfer_complete(drv_data);
  596. return IRQ_HANDLED;
  597. }
  598. } while (drv_data->write(drv_data));
  599. if (drv_data->read(drv_data)) {
  600. int_transfer_complete(drv_data);
  601. return IRQ_HANDLED;
  602. }
  603. if (drv_data->tx == drv_data->tx_end) {
  604. u32 bytes_left;
  605. u32 sccr1_reg;
  606. sccr1_reg = read_SSCR1(reg);
  607. sccr1_reg &= ~SSCR1_TIE;
  608. /*
  609. * PXA25x_SSP has no timeout, set up rx threshould for the
  610. * remaining RX bytes.
  611. */
  612. if (pxa25x_ssp_comp(drv_data)) {
  613. sccr1_reg &= ~SSCR1_RFT;
  614. bytes_left = drv_data->rx_end - drv_data->rx;
  615. switch (drv_data->n_bytes) {
  616. case 4:
  617. bytes_left >>= 1;
  618. case 2:
  619. bytes_left >>= 1;
  620. }
  621. if (bytes_left > RX_THRESH_DFLT)
  622. bytes_left = RX_THRESH_DFLT;
  623. sccr1_reg |= SSCR1_RxTresh(bytes_left);
  624. }
  625. write_SSCR1(sccr1_reg, reg);
  626. }
  627. /* We did something */
  628. return IRQ_HANDLED;
  629. }
  630. static irqreturn_t ssp_int(int irq, void *dev_id)
  631. {
  632. struct driver_data *drv_data = dev_id;
  633. void __iomem *reg = drv_data->ioaddr;
  634. u32 sccr1_reg = read_SSCR1(reg);
  635. u32 mask = drv_data->mask_sr;
  636. u32 status;
  637. status = read_SSSR(reg);
  638. /* Ignore possible writes if we don't need to write */
  639. if (!(sccr1_reg & SSCR1_TIE))
  640. mask &= ~SSSR_TFS;
  641. /* Ignore RX timeout interrupt if it is disabled */
  642. if (!(sccr1_reg & SSCR1_TINTE))
  643. mask &= ~SSSR_TINT;
  644. if (!(status & mask))
  645. return IRQ_NONE;
  646. if (!drv_data->cur_msg) {
  647. write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
  648. write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg);
  649. if (!pxa25x_ssp_comp(drv_data))
  650. write_SSTO(0, reg);
  651. write_SSSR_CS(drv_data, drv_data->clear_sr);
  652. dev_err(&drv_data->pdev->dev, "bad message state "
  653. "in interrupt handler\n");
  654. /* Never fail */
  655. return IRQ_HANDLED;
  656. }
  657. return drv_data->transfer_handler(drv_data);
  658. }
  659. static int set_dma_burst_and_threshold(struct chip_data *chip,
  660. struct spi_device *spi,
  661. u8 bits_per_word, u32 *burst_code,
  662. u32 *threshold)
  663. {
  664. struct pxa2xx_spi_chip *chip_info =
  665. (struct pxa2xx_spi_chip *)spi->controller_data;
  666. int bytes_per_word;
  667. int burst_bytes;
  668. int thresh_words;
  669. int req_burst_size;
  670. int retval = 0;
  671. /* Set the threshold (in registers) to equal the same amount of data
  672. * as represented by burst size (in bytes). The computation below
  673. * is (burst_size rounded up to nearest 8 byte, word or long word)
  674. * divided by (bytes/register); the tx threshold is the inverse of
  675. * the rx, so that there will always be enough data in the rx fifo
  676. * to satisfy a burst, and there will always be enough space in the
  677. * tx fifo to accept a burst (a tx burst will overwrite the fifo if
  678. * there is not enough space), there must always remain enough empty
  679. * space in the rx fifo for any data loaded to the tx fifo.
  680. * Whenever burst_size (in bytes) equals bits/word, the fifo threshold
  681. * will be 8, or half the fifo;
  682. * The threshold can only be set to 2, 4 or 8, but not 16, because
  683. * to burst 16 to the tx fifo, the fifo would have to be empty;
  684. * however, the minimum fifo trigger level is 1, and the tx will
  685. * request service when the fifo is at this level, with only 15 spaces.
  686. */
  687. /* find bytes/word */
  688. if (bits_per_word <= 8)
  689. bytes_per_word = 1;
  690. else if (bits_per_word <= 16)
  691. bytes_per_word = 2;
  692. else
  693. bytes_per_word = 4;
  694. /* use struct pxa2xx_spi_chip->dma_burst_size if available */
  695. if (chip_info)
  696. req_burst_size = chip_info->dma_burst_size;
  697. else {
  698. switch (chip->dma_burst_size) {
  699. default:
  700. /* if the default burst size is not set,
  701. * do it now */
  702. chip->dma_burst_size = DCMD_BURST8;
  703. case DCMD_BURST8:
  704. req_burst_size = 8;
  705. break;
  706. case DCMD_BURST16:
  707. req_burst_size = 16;
  708. break;
  709. case DCMD_BURST32:
  710. req_burst_size = 32;
  711. break;
  712. }
  713. }
  714. if (req_burst_size <= 8) {
  715. *burst_code = DCMD_BURST8;
  716. burst_bytes = 8;
  717. } else if (req_burst_size <= 16) {
  718. if (bytes_per_word == 1) {
  719. /* don't burst more than 1/2 the fifo */
  720. *burst_code = DCMD_BURST8;
  721. burst_bytes = 8;
  722. retval = 1;
  723. } else {
  724. *burst_code = DCMD_BURST16;
  725. burst_bytes = 16;
  726. }
  727. } else {
  728. if (bytes_per_word == 1) {
  729. /* don't burst more than 1/2 the fifo */
  730. *burst_code = DCMD_BURST8;
  731. burst_bytes = 8;
  732. retval = 1;
  733. } else if (bytes_per_word == 2) {
  734. /* don't burst more than 1/2 the fifo */
  735. *burst_code = DCMD_BURST16;
  736. burst_bytes = 16;
  737. retval = 1;
  738. } else {
  739. *burst_code = DCMD_BURST32;
  740. burst_bytes = 32;
  741. }
  742. }
  743. thresh_words = burst_bytes / bytes_per_word;
  744. /* thresh_words will be between 2 and 8 */
  745. *threshold = (SSCR1_RxTresh(thresh_words) & SSCR1_RFT)
  746. | (SSCR1_TxTresh(16-thresh_words) & SSCR1_TFT);
  747. return retval;
  748. }
  749. static unsigned int ssp_get_clk_div(struct ssp_device *ssp, int rate)
  750. {
  751. unsigned long ssp_clk = clk_get_rate(ssp->clk);
  752. if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP)
  753. return ((ssp_clk / (2 * rate) - 1) & 0xff) << 8;
  754. else
  755. return ((ssp_clk / rate - 1) & 0xfff) << 8;
  756. }
  757. static void pump_transfers(unsigned long data)
  758. {
  759. struct driver_data *drv_data = (struct driver_data *)data;
  760. struct spi_message *message = NULL;
  761. struct spi_transfer *transfer = NULL;
  762. struct spi_transfer *previous = NULL;
  763. struct chip_data *chip = NULL;
  764. struct ssp_device *ssp = drv_data->ssp;
  765. void __iomem *reg = drv_data->ioaddr;
  766. u32 clk_div = 0;
  767. u8 bits = 0;
  768. u32 speed = 0;
  769. u32 cr0;
  770. u32 cr1;
  771. u32 dma_thresh = drv_data->cur_chip->dma_threshold;
  772. u32 dma_burst = drv_data->cur_chip->dma_burst_size;
  773. /* Get current state information */
  774. message = drv_data->cur_msg;
  775. transfer = drv_data->cur_transfer;
  776. chip = drv_data->cur_chip;
  777. /* Handle for abort */
  778. if (message->state == ERROR_STATE) {
  779. message->status = -EIO;
  780. giveback(drv_data);
  781. return;
  782. }
  783. /* Handle end of message */
  784. if (message->state == DONE_STATE) {
  785. message->status = 0;
  786. giveback(drv_data);
  787. return;
  788. }
  789. /* Delay if requested at end of transfer before CS change */
  790. if (message->state == RUNNING_STATE) {
  791. previous = list_entry(transfer->transfer_list.prev,
  792. struct spi_transfer,
  793. transfer_list);
  794. if (previous->delay_usecs)
  795. udelay(previous->delay_usecs);
  796. /* Drop chip select only if cs_change is requested */
  797. if (previous->cs_change)
  798. cs_deassert(drv_data);
  799. }
  800. /* Check for transfers that need multiple DMA segments */
  801. if (transfer->len > MAX_DMA_LEN && chip->enable_dma) {
  802. /* reject already-mapped transfers; PIO won't always work */
  803. if (message->is_dma_mapped
  804. || transfer->rx_dma || transfer->tx_dma) {
  805. dev_err(&drv_data->pdev->dev,
  806. "pump_transfers: mapped transfer length "
  807. "of %u is greater than %d\n",
  808. transfer->len, MAX_DMA_LEN);
  809. message->status = -EINVAL;
  810. giveback(drv_data);
  811. return;
  812. }
  813. /* warn ... we force this to PIO mode */
  814. if (printk_ratelimit())
  815. dev_warn(&message->spi->dev, "pump_transfers: "
  816. "DMA disabled for transfer length %ld "
  817. "greater than %d\n",
  818. (long)drv_data->len, MAX_DMA_LEN);
  819. }
  820. /* Setup the transfer state based on the type of transfer */
  821. if (flush(drv_data) == 0) {
  822. dev_err(&drv_data->pdev->dev, "pump_transfers: flush failed\n");
  823. message->status = -EIO;
  824. giveback(drv_data);
  825. return;
  826. }
  827. drv_data->n_bytes = chip->n_bytes;
  828. drv_data->dma_width = chip->dma_width;
  829. drv_data->tx = (void *)transfer->tx_buf;
  830. drv_data->tx_end = drv_data->tx + transfer->len;
  831. drv_data->rx = transfer->rx_buf;
  832. drv_data->rx_end = drv_data->rx + transfer->len;
  833. drv_data->rx_dma = transfer->rx_dma;
  834. drv_data->tx_dma = transfer->tx_dma;
  835. drv_data->len = transfer->len & DCMD_LENGTH;
  836. drv_data->write = drv_data->tx ? chip->write : null_writer;
  837. drv_data->read = drv_data->rx ? chip->read : null_reader;
  838. /* Change speed and bit per word on a per transfer */
  839. cr0 = chip->cr0;
  840. if (transfer->speed_hz || transfer->bits_per_word) {
  841. bits = chip->bits_per_word;
  842. speed = chip->speed_hz;
  843. if (transfer->speed_hz)
  844. speed = transfer->speed_hz;
  845. if (transfer->bits_per_word)
  846. bits = transfer->bits_per_word;
  847. clk_div = ssp_get_clk_div(ssp, speed);
  848. if (bits <= 8) {
  849. drv_data->n_bytes = 1;
  850. drv_data->dma_width = DCMD_WIDTH1;
  851. drv_data->read = drv_data->read != null_reader ?
  852. u8_reader : null_reader;
  853. drv_data->write = drv_data->write != null_writer ?
  854. u8_writer : null_writer;
  855. } else if (bits <= 16) {
  856. drv_data->n_bytes = 2;
  857. drv_data->dma_width = DCMD_WIDTH2;
  858. drv_data->read = drv_data->read != null_reader ?
  859. u16_reader : null_reader;
  860. drv_data->write = drv_data->write != null_writer ?
  861. u16_writer : null_writer;
  862. } else if (bits <= 32) {
  863. drv_data->n_bytes = 4;
  864. drv_data->dma_width = DCMD_WIDTH4;
  865. drv_data->read = drv_data->read != null_reader ?
  866. u32_reader : null_reader;
  867. drv_data->write = drv_data->write != null_writer ?
  868. u32_writer : null_writer;
  869. }
  870. /* if bits/word is changed in dma mode, then must check the
  871. * thresholds and burst also */
  872. if (chip->enable_dma) {
  873. if (set_dma_burst_and_threshold(chip, message->spi,
  874. bits, &dma_burst,
  875. &dma_thresh))
  876. if (printk_ratelimit())
  877. dev_warn(&message->spi->dev,
  878. "pump_transfers: "
  879. "DMA burst size reduced to "
  880. "match bits_per_word\n");
  881. }
  882. cr0 = clk_div
  883. | SSCR0_Motorola
  884. | SSCR0_DataSize(bits > 16 ? bits - 16 : bits)
  885. | SSCR0_SSE
  886. | (bits > 16 ? SSCR0_EDSS : 0);
  887. }
  888. message->state = RUNNING_STATE;
  889. /* Try to map dma buffer and do a dma transfer if successful, but
  890. * only if the length is non-zero and less than MAX_DMA_LEN.
  891. *
  892. * Zero-length non-descriptor DMA is illegal on PXA2xx; force use
  893. * of PIO instead. Care is needed above because the transfer may
  894. * have have been passed with buffers that are already dma mapped.
  895. * A zero-length transfer in PIO mode will not try to write/read
  896. * to/from the buffers
  897. *
  898. * REVISIT large transfers are exactly where we most want to be
  899. * using DMA. If this happens much, split those transfers into
  900. * multiple DMA segments rather than forcing PIO.
  901. */
  902. drv_data->dma_mapped = 0;
  903. if (drv_data->len > 0 && drv_data->len <= MAX_DMA_LEN)
  904. drv_data->dma_mapped = map_dma_buffers(drv_data);
  905. if (drv_data->dma_mapped) {
  906. /* Ensure we have the correct interrupt handler */
  907. drv_data->transfer_handler = dma_transfer;
  908. /* Setup rx DMA Channel */
  909. DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
  910. DSADR(drv_data->rx_channel) = drv_data->ssdr_physical;
  911. DTADR(drv_data->rx_channel) = drv_data->rx_dma;
  912. if (drv_data->rx == drv_data->null_dma_buf)
  913. /* No target address increment */
  914. DCMD(drv_data->rx_channel) = DCMD_FLOWSRC
  915. | drv_data->dma_width
  916. | dma_burst
  917. | drv_data->len;
  918. else
  919. DCMD(drv_data->rx_channel) = DCMD_INCTRGADDR
  920. | DCMD_FLOWSRC
  921. | drv_data->dma_width
  922. | dma_burst
  923. | drv_data->len;
  924. /* Setup tx DMA Channel */
  925. DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
  926. DSADR(drv_data->tx_channel) = drv_data->tx_dma;
  927. DTADR(drv_data->tx_channel) = drv_data->ssdr_physical;
  928. if (drv_data->tx == drv_data->null_dma_buf)
  929. /* No source address increment */
  930. DCMD(drv_data->tx_channel) = DCMD_FLOWTRG
  931. | drv_data->dma_width
  932. | dma_burst
  933. | drv_data->len;
  934. else
  935. DCMD(drv_data->tx_channel) = DCMD_INCSRCADDR
  936. | DCMD_FLOWTRG
  937. | drv_data->dma_width
  938. | dma_burst
  939. | drv_data->len;
  940. /* Enable dma end irqs on SSP to detect end of transfer */
  941. if (drv_data->ssp_type == PXA25x_SSP)
  942. DCMD(drv_data->tx_channel) |= DCMD_ENDIRQEN;
  943. /* Clear status and start DMA engine */
  944. cr1 = chip->cr1 | dma_thresh | drv_data->dma_cr1;
  945. write_SSSR(drv_data->clear_sr, reg);
  946. DCSR(drv_data->rx_channel) |= DCSR_RUN;
  947. DCSR(drv_data->tx_channel) |= DCSR_RUN;
  948. } else {
  949. /* Ensure we have the correct interrupt handler */
  950. drv_data->transfer_handler = interrupt_transfer;
  951. /* Clear status */
  952. cr1 = chip->cr1 | chip->threshold | drv_data->int_cr1;
  953. write_SSSR_CS(drv_data, drv_data->clear_sr);
  954. }
  955. /* see if we need to reload the config registers */
  956. if ((read_SSCR0(reg) != cr0)
  957. || (read_SSCR1(reg) & SSCR1_CHANGE_MASK) !=
  958. (cr1 & SSCR1_CHANGE_MASK)) {
  959. /* stop the SSP, and update the other bits */
  960. write_SSCR0(cr0 & ~SSCR0_SSE, reg);
  961. if (!pxa25x_ssp_comp(drv_data))
  962. write_SSTO(chip->timeout, reg);
  963. /* first set CR1 without interrupt and service enables */
  964. write_SSCR1(cr1 & SSCR1_CHANGE_MASK, reg);
  965. /* restart the SSP */
  966. write_SSCR0(cr0, reg);
  967. } else {
  968. if (!pxa25x_ssp_comp(drv_data))
  969. write_SSTO(chip->timeout, reg);
  970. }
  971. cs_assert(drv_data);
  972. /* after chip select, release the data by enabling service
  973. * requests and interrupts, without changing any mode bits */
  974. write_SSCR1(cr1, reg);
  975. }
  976. static void pump_messages(struct work_struct *work)
  977. {
  978. struct driver_data *drv_data =
  979. container_of(work, struct driver_data, pump_messages);
  980. unsigned long flags;
  981. /* Lock queue and check for queue work */
  982. spin_lock_irqsave(&drv_data->lock, flags);
  983. if (list_empty(&drv_data->queue) || drv_data->run == QUEUE_STOPPED) {
  984. drv_data->busy = 0;
  985. spin_unlock_irqrestore(&drv_data->lock, flags);
  986. return;
  987. }
  988. /* Make sure we are not already running a message */
  989. if (drv_data->cur_msg) {
  990. spin_unlock_irqrestore(&drv_data->lock, flags);
  991. return;
  992. }
  993. /* Extract head of queue */
  994. drv_data->cur_msg = list_entry(drv_data->queue.next,
  995. struct spi_message, queue);
  996. list_del_init(&drv_data->cur_msg->queue);
  997. /* Initial message state*/
  998. drv_data->cur_msg->state = START_STATE;
  999. drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next,
  1000. struct spi_transfer,
  1001. transfer_list);
  1002. /* prepare to setup the SSP, in pump_transfers, using the per
  1003. * chip configuration */
  1004. drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi);
  1005. /* Mark as busy and launch transfers */
  1006. tasklet_schedule(&drv_data->pump_transfers);
  1007. drv_data->busy = 1;
  1008. spin_unlock_irqrestore(&drv_data->lock, flags);
  1009. }
  1010. static int transfer(struct spi_device *spi, struct spi_message *msg)
  1011. {
  1012. struct driver_data *drv_data = spi_master_get_devdata(spi->master);
  1013. unsigned long flags;
  1014. spin_lock_irqsave(&drv_data->lock, flags);
  1015. if (drv_data->run == QUEUE_STOPPED) {
  1016. spin_unlock_irqrestore(&drv_data->lock, flags);
  1017. return -ESHUTDOWN;
  1018. }
  1019. msg->actual_length = 0;
  1020. msg->status = -EINPROGRESS;
  1021. msg->state = START_STATE;
  1022. list_add_tail(&msg->queue, &drv_data->queue);
  1023. if (drv_data->run == QUEUE_RUNNING && !drv_data->busy)
  1024. queue_work(drv_data->workqueue, &drv_data->pump_messages);
  1025. spin_unlock_irqrestore(&drv_data->lock, flags);
  1026. return 0;
  1027. }
  1028. static int setup_cs(struct spi_device *spi, struct chip_data *chip,
  1029. struct pxa2xx_spi_chip *chip_info)
  1030. {
  1031. int err = 0;
  1032. if (chip == NULL || chip_info == NULL)
  1033. return 0;
  1034. /* NOTE: setup() can be called multiple times, possibly with
  1035. * different chip_info, release previously requested GPIO
  1036. */
  1037. if (gpio_is_valid(chip->gpio_cs))
  1038. gpio_free(chip->gpio_cs);
  1039. /* If (*cs_control) is provided, ignore GPIO chip select */
  1040. if (chip_info->cs_control) {
  1041. chip->cs_control = chip_info->cs_control;
  1042. return 0;
  1043. }
  1044. if (gpio_is_valid(chip_info->gpio_cs)) {
  1045. err = gpio_request(chip_info->gpio_cs, "SPI_CS");
  1046. if (err) {
  1047. dev_err(&spi->dev, "failed to request chip select "
  1048. "GPIO%d\n", chip_info->gpio_cs);
  1049. return err;
  1050. }
  1051. chip->gpio_cs = chip_info->gpio_cs;
  1052. chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
  1053. err = gpio_direction_output(chip->gpio_cs,
  1054. !chip->gpio_cs_inverted);
  1055. }
  1056. return err;
  1057. }
  1058. static int setup(struct spi_device *spi)
  1059. {
  1060. struct pxa2xx_spi_chip *chip_info = NULL;
  1061. struct chip_data *chip;
  1062. struct driver_data *drv_data = spi_master_get_devdata(spi->master);
  1063. struct ssp_device *ssp = drv_data->ssp;
  1064. unsigned int clk_div;
  1065. uint tx_thres = TX_THRESH_DFLT;
  1066. uint rx_thres = RX_THRESH_DFLT;
  1067. if (!pxa25x_ssp_comp(drv_data)
  1068. && (spi->bits_per_word < 4 || spi->bits_per_word > 32)) {
  1069. dev_err(&spi->dev, "failed setup: ssp_type=%d, bits/wrd=%d "
  1070. "b/w not 4-32 for type non-PXA25x_SSP\n",
  1071. drv_data->ssp_type, spi->bits_per_word);
  1072. return -EINVAL;
  1073. } else if (pxa25x_ssp_comp(drv_data)
  1074. && (spi->bits_per_word < 4
  1075. || spi->bits_per_word > 16)) {
  1076. dev_err(&spi->dev, "failed setup: ssp_type=%d, bits/wrd=%d "
  1077. "b/w not 4-16 for type PXA25x_SSP\n",
  1078. drv_data->ssp_type, spi->bits_per_word);
  1079. return -EINVAL;
  1080. }
  1081. /* Only alloc on first setup */
  1082. chip = spi_get_ctldata(spi);
  1083. if (!chip) {
  1084. chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
  1085. if (!chip) {
  1086. dev_err(&spi->dev,
  1087. "failed setup: can't allocate chip data\n");
  1088. return -ENOMEM;
  1089. }
  1090. if (drv_data->ssp_type == CE4100_SSP) {
  1091. if (spi->chip_select > 4) {
  1092. dev_err(&spi->dev, "failed setup: "
  1093. "cs number must not be > 4.\n");
  1094. kfree(chip);
  1095. return -EINVAL;
  1096. }
  1097. chip->frm = spi->chip_select;
  1098. } else
  1099. chip->gpio_cs = -1;
  1100. chip->enable_dma = 0;
  1101. chip->timeout = TIMOUT_DFLT;
  1102. chip->dma_burst_size = drv_data->master_info->enable_dma ?
  1103. DCMD_BURST8 : 0;
  1104. }
  1105. /* protocol drivers may change the chip settings, so...
  1106. * if chip_info exists, use it */
  1107. chip_info = spi->controller_data;
  1108. /* chip_info isn't always needed */
  1109. chip->cr1 = 0;
  1110. if (chip_info) {
  1111. if (chip_info->timeout)
  1112. chip->timeout = chip_info->timeout;
  1113. if (chip_info->tx_threshold)
  1114. tx_thres = chip_info->tx_threshold;
  1115. if (chip_info->rx_threshold)
  1116. rx_thres = chip_info->rx_threshold;
  1117. chip->enable_dma = drv_data->master_info->enable_dma;
  1118. chip->dma_threshold = 0;
  1119. if (chip_info->enable_loopback)
  1120. chip->cr1 = SSCR1_LBM;
  1121. }
  1122. chip->threshold = (SSCR1_RxTresh(rx_thres) & SSCR1_RFT) |
  1123. (SSCR1_TxTresh(tx_thres) & SSCR1_TFT);
  1124. /* set dma burst and threshold outside of chip_info path so that if
  1125. * chip_info goes away after setting chip->enable_dma, the
  1126. * burst and threshold can still respond to changes in bits_per_word */
  1127. if (chip->enable_dma) {
  1128. /* set up legal burst and threshold for dma */
  1129. if (set_dma_burst_and_threshold(chip, spi, spi->bits_per_word,
  1130. &chip->dma_burst_size,
  1131. &chip->dma_threshold)) {
  1132. dev_warn(&spi->dev, "in setup: DMA burst size reduced "
  1133. "to match bits_per_word\n");
  1134. }
  1135. }
  1136. clk_div = ssp_get_clk_div(ssp, spi->max_speed_hz);
  1137. chip->speed_hz = spi->max_speed_hz;
  1138. chip->cr0 = clk_div
  1139. | SSCR0_Motorola
  1140. | SSCR0_DataSize(spi->bits_per_word > 16 ?
  1141. spi->bits_per_word - 16 : spi->bits_per_word)
  1142. | SSCR0_SSE
  1143. | (spi->bits_per_word > 16 ? SSCR0_EDSS : 0);
  1144. chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH);
  1145. chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) ? SSCR1_SPH : 0)
  1146. | (((spi->mode & SPI_CPOL) != 0) ? SSCR1_SPO : 0);
  1147. /* NOTE: PXA25x_SSP _could_ use external clocking ... */
  1148. if (!pxa25x_ssp_comp(drv_data))
  1149. dev_dbg(&spi->dev, "%ld Hz actual, %s\n",
  1150. clk_get_rate(ssp->clk)
  1151. / (1 + ((chip->cr0 & SSCR0_SCR(0xfff)) >> 8)),
  1152. chip->enable_dma ? "DMA" : "PIO");
  1153. else
  1154. dev_dbg(&spi->dev, "%ld Hz actual, %s\n",
  1155. clk_get_rate(ssp->clk) / 2
  1156. / (1 + ((chip->cr0 & SSCR0_SCR(0x0ff)) >> 8)),
  1157. chip->enable_dma ? "DMA" : "PIO");
  1158. if (spi->bits_per_word <= 8) {
  1159. chip->n_bytes = 1;
  1160. chip->dma_width = DCMD_WIDTH1;
  1161. chip->read = u8_reader;
  1162. chip->write = u8_writer;
  1163. } else if (spi->bits_per_word <= 16) {
  1164. chip->n_bytes = 2;
  1165. chip->dma_width = DCMD_WIDTH2;
  1166. chip->read = u16_reader;
  1167. chip->write = u16_writer;
  1168. } else if (spi->bits_per_word <= 32) {
  1169. chip->cr0 |= SSCR0_EDSS;
  1170. chip->n_bytes = 4;
  1171. chip->dma_width = DCMD_WIDTH4;
  1172. chip->read = u32_reader;
  1173. chip->write = u32_writer;
  1174. } else {
  1175. dev_err(&spi->dev, "invalid wordsize\n");
  1176. return -ENODEV;
  1177. }
  1178. chip->bits_per_word = spi->bits_per_word;
  1179. spi_set_ctldata(spi, chip);
  1180. if (drv_data->ssp_type == CE4100_SSP)
  1181. return 0;
  1182. return setup_cs(spi, chip, chip_info);
  1183. }
  1184. static void cleanup(struct spi_device *spi)
  1185. {
  1186. struct chip_data *chip = spi_get_ctldata(spi);
  1187. struct driver_data *drv_data = spi_master_get_devdata(spi->master);
  1188. if (!chip)
  1189. return;
  1190. if (drv_data->ssp_type != CE4100_SSP && gpio_is_valid(chip->gpio_cs))
  1191. gpio_free(chip->gpio_cs);
  1192. kfree(chip);
  1193. }
  1194. static int __devinit init_queue(struct driver_data *drv_data)
  1195. {
  1196. INIT_LIST_HEAD(&drv_data->queue);
  1197. spin_lock_init(&drv_data->lock);
  1198. drv_data->run = QUEUE_STOPPED;
  1199. drv_data->busy = 0;
  1200. tasklet_init(&drv_data->pump_transfers,
  1201. pump_transfers, (unsigned long)drv_data);
  1202. INIT_WORK(&drv_data->pump_messages, pump_messages);
  1203. drv_data->workqueue = create_singlethread_workqueue(
  1204. dev_name(drv_data->master->dev.parent));
  1205. if (drv_data->workqueue == NULL)
  1206. return -EBUSY;
  1207. return 0;
  1208. }
  1209. static int start_queue(struct driver_data *drv_data)
  1210. {
  1211. unsigned long flags;
  1212. spin_lock_irqsave(&drv_data->lock, flags);
  1213. if (drv_data->run == QUEUE_RUNNING || drv_data->busy) {
  1214. spin_unlock_irqrestore(&drv_data->lock, flags);
  1215. return -EBUSY;
  1216. }
  1217. drv_data->run = QUEUE_RUNNING;
  1218. drv_data->cur_msg = NULL;
  1219. drv_data->cur_transfer = NULL;
  1220. drv_data->cur_chip = NULL;
  1221. spin_unlock_irqrestore(&drv_data->lock, flags);
  1222. queue_work(drv_data->workqueue, &drv_data->pump_messages);
  1223. return 0;
  1224. }
  1225. static int stop_queue(struct driver_data *drv_data)
  1226. {
  1227. unsigned long flags;
  1228. unsigned limit = 500;
  1229. int status = 0;
  1230. spin_lock_irqsave(&drv_data->lock, flags);
  1231. /* This is a bit lame, but is optimized for the common execution path.
  1232. * A wait_queue on the drv_data->busy could be used, but then the common
  1233. * execution path (pump_messages) would be required to call wake_up or
  1234. * friends on every SPI message. Do this instead */
  1235. drv_data->run = QUEUE_STOPPED;
  1236. while ((!list_empty(&drv_data->queue) || drv_data->busy) && limit--) {
  1237. spin_unlock_irqrestore(&drv_data->lock, flags);
  1238. msleep(10);
  1239. spin_lock_irqsave(&drv_data->lock, flags);
  1240. }
  1241. if (!list_empty(&drv_data->queue) || drv_data->busy)
  1242. status = -EBUSY;
  1243. spin_unlock_irqrestore(&drv_data->lock, flags);
  1244. return status;
  1245. }
  1246. static int destroy_queue(struct driver_data *drv_data)
  1247. {
  1248. int status;
  1249. status = stop_queue(drv_data);
  1250. /* we are unloading the module or failing to load (only two calls
  1251. * to this routine), and neither call can handle a return value.
  1252. * However, destroy_workqueue calls flush_workqueue, and that will
  1253. * block until all work is done. If the reason that stop_queue
  1254. * timed out is that the work will never finish, then it does no
  1255. * good to call destroy_workqueue, so return anyway. */
  1256. if (status != 0)
  1257. return status;
  1258. destroy_workqueue(drv_data->workqueue);
  1259. return 0;
  1260. }
  1261. static int __devinit pxa2xx_spi_probe(struct platform_device *pdev)
  1262. {
  1263. struct device *dev = &pdev->dev;
  1264. struct pxa2xx_spi_master *platform_info;
  1265. struct spi_master *master;
  1266. struct driver_data *drv_data;
  1267. struct ssp_device *ssp;
  1268. int status;
  1269. platform_info = dev->platform_data;
  1270. ssp = pxa_ssp_request(pdev->id, pdev->name);
  1271. if (ssp == NULL) {
  1272. dev_err(&pdev->dev, "failed to request SSP%d\n", pdev->id);
  1273. return -ENODEV;
  1274. }
  1275. /* Allocate master with space for drv_data and null dma buffer */
  1276. master = spi_alloc_master(dev, sizeof(struct driver_data) + 16);
  1277. if (!master) {
  1278. dev_err(&pdev->dev, "cannot alloc spi_master\n");
  1279. pxa_ssp_free(ssp);
  1280. return -ENOMEM;
  1281. }
  1282. drv_data = spi_master_get_devdata(master);
  1283. drv_data->master = master;
  1284. drv_data->master_info = platform_info;
  1285. drv_data->pdev = pdev;
  1286. drv_data->ssp = ssp;
  1287. master->dev.parent = &pdev->dev;
  1288. master->dev.of_node = pdev->dev.of_node;
  1289. /* the spi->mode bits understood by this driver: */
  1290. master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
  1291. master->bus_num = pdev->id;
  1292. master->num_chipselect = platform_info->num_chipselect;
  1293. master->dma_alignment = DMA_ALIGNMENT;
  1294. master->cleanup = cleanup;
  1295. master->setup = setup;
  1296. master->transfer = transfer;
  1297. drv_data->ssp_type = ssp->type;
  1298. drv_data->null_dma_buf = (u32 *)ALIGN((u32)(drv_data +
  1299. sizeof(struct driver_data)), 8);
  1300. drv_data->ioaddr = ssp->mmio_base;
  1301. drv_data->ssdr_physical = ssp->phys_base + SSDR;
  1302. if (pxa25x_ssp_comp(drv_data)) {
  1303. drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE;
  1304. drv_data->dma_cr1 = 0;
  1305. drv_data->clear_sr = SSSR_ROR;
  1306. drv_data->mask_sr = SSSR_RFS | SSSR_TFS | SSSR_ROR;
  1307. } else {
  1308. drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE;
  1309. drv_data->dma_cr1 = SSCR1_TSRE | SSCR1_RSRE | SSCR1_TINTE;
  1310. drv_data->clear_sr = SSSR_ROR | SSSR_TINT;
  1311. drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS | SSSR_ROR;
  1312. }
  1313. status = request_irq(ssp->irq, ssp_int, IRQF_SHARED, dev_name(dev),
  1314. drv_data);
  1315. if (status < 0) {
  1316. dev_err(&pdev->dev, "cannot get IRQ %d\n", ssp->irq);
  1317. goto out_error_master_alloc;
  1318. }
  1319. /* Setup DMA if requested */
  1320. drv_data->tx_channel = -1;
  1321. drv_data->rx_channel = -1;
  1322. if (platform_info->enable_dma) {
  1323. /* Get two DMA channels (rx and tx) */
  1324. drv_data->rx_channel = pxa_request_dma("pxa2xx_spi_ssp_rx",
  1325. DMA_PRIO_HIGH,
  1326. dma_handler,
  1327. drv_data);
  1328. if (drv_data->rx_channel < 0) {
  1329. dev_err(dev, "problem (%d) requesting rx channel\n",
  1330. drv_data->rx_channel);
  1331. status = -ENODEV;
  1332. goto out_error_irq_alloc;
  1333. }
  1334. drv_data->tx_channel = pxa_request_dma("pxa2xx_spi_ssp_tx",
  1335. DMA_PRIO_MEDIUM,
  1336. dma_handler,
  1337. drv_data);
  1338. if (drv_data->tx_channel < 0) {
  1339. dev_err(dev, "problem (%d) requesting tx channel\n",
  1340. drv_data->tx_channel);
  1341. status = -ENODEV;
  1342. goto out_error_dma_alloc;
  1343. }
  1344. DRCMR(ssp->drcmr_rx) = DRCMR_MAPVLD | drv_data->rx_channel;
  1345. DRCMR(ssp->drcmr_tx) = DRCMR_MAPVLD | drv_data->tx_channel;
  1346. }
  1347. /* Enable SOC clock */
  1348. clk_enable(ssp->clk);
  1349. /* Load default SSP configuration */
  1350. write_SSCR0(0, drv_data->ioaddr);
  1351. write_SSCR1(SSCR1_RxTresh(RX_THRESH_DFLT) |
  1352. SSCR1_TxTresh(TX_THRESH_DFLT),
  1353. drv_data->ioaddr);
  1354. write_SSCR0(SSCR0_SCR(2)
  1355. | SSCR0_Motorola
  1356. | SSCR0_DataSize(8),
  1357. drv_data->ioaddr);
  1358. if (!pxa25x_ssp_comp(drv_data))
  1359. write_SSTO(0, drv_data->ioaddr);
  1360. write_SSPSP(0, drv_data->ioaddr);
  1361. /* Initial and start queue */
  1362. status = init_queue(drv_data);
  1363. if (status != 0) {
  1364. dev_err(&pdev->dev, "problem initializing queue\n");
  1365. goto out_error_clock_enabled;
  1366. }
  1367. status = start_queue(drv_data);
  1368. if (status != 0) {
  1369. dev_err(&pdev->dev, "problem starting queue\n");
  1370. goto out_error_clock_enabled;
  1371. }
  1372. /* Register with the SPI framework */
  1373. platform_set_drvdata(pdev, drv_data);
  1374. status = spi_register_master(master);
  1375. if (status != 0) {
  1376. dev_err(&pdev->dev, "problem registering spi master\n");
  1377. goto out_error_queue_alloc;
  1378. }
  1379. return status;
  1380. out_error_queue_alloc:
  1381. destroy_queue(drv_data);
  1382. out_error_clock_enabled:
  1383. clk_disable(ssp->clk);
  1384. out_error_dma_alloc:
  1385. if (drv_data->tx_channel != -1)
  1386. pxa_free_dma(drv_data->tx_channel);
  1387. if (drv_data->rx_channel != -1)
  1388. pxa_free_dma(drv_data->rx_channel);
  1389. out_error_irq_alloc:
  1390. free_irq(ssp->irq, drv_data);
  1391. out_error_master_alloc:
  1392. spi_master_put(master);
  1393. pxa_ssp_free(ssp);
  1394. return status;
  1395. }
  1396. static int pxa2xx_spi_remove(struct platform_device *pdev)
  1397. {
  1398. struct driver_data *drv_data = platform_get_drvdata(pdev);
  1399. struct ssp_device *ssp;
  1400. int status = 0;
  1401. if (!drv_data)
  1402. return 0;
  1403. ssp = drv_data->ssp;
  1404. /* Remove the queue */
  1405. status = destroy_queue(drv_data);
  1406. if (status != 0)
  1407. /* the kernel does not check the return status of this
  1408. * this routine (mod->exit, within the kernel). Therefore
  1409. * nothing is gained by returning from here, the module is
  1410. * going away regardless, and we should not leave any more
  1411. * resources allocated than necessary. We cannot free the
  1412. * message memory in drv_data->queue, but we can release the
  1413. * resources below. I think the kernel should honor -EBUSY
  1414. * returns but... */
  1415. dev_err(&pdev->dev, "pxa2xx_spi_remove: workqueue will not "
  1416. "complete, message memory not freed\n");
  1417. /* Disable the SSP at the peripheral and SOC level */
  1418. write_SSCR0(0, drv_data->ioaddr);
  1419. clk_disable(ssp->clk);
  1420. /* Release DMA */
  1421. if (drv_data->master_info->enable_dma) {
  1422. DRCMR(ssp->drcmr_rx) = 0;
  1423. DRCMR(ssp->drcmr_tx) = 0;
  1424. pxa_free_dma(drv_data->tx_channel);
  1425. pxa_free_dma(drv_data->rx_channel);
  1426. }
  1427. /* Release IRQ */
  1428. free_irq(ssp->irq, drv_data);
  1429. /* Release SSP */
  1430. pxa_ssp_free(ssp);
  1431. /* Disconnect from the SPI framework */
  1432. spi_unregister_master(drv_data->master);
  1433. /* Prevent double remove */
  1434. platform_set_drvdata(pdev, NULL);
  1435. return 0;
  1436. }
  1437. static void pxa2xx_spi_shutdown(struct platform_device *pdev)
  1438. {
  1439. int status = 0;
  1440. if ((status = pxa2xx_spi_remove(pdev)) != 0)
  1441. dev_err(&pdev->dev, "shutdown failed with %d\n", status);
  1442. }
  1443. #ifdef CONFIG_PM
  1444. static int pxa2xx_spi_suspend(struct device *dev)
  1445. {
  1446. struct driver_data *drv_data = dev_get_drvdata(dev);
  1447. struct ssp_device *ssp = drv_data->ssp;
  1448. int status = 0;
  1449. status = stop_queue(drv_data);
  1450. if (status != 0)
  1451. return status;
  1452. write_SSCR0(0, drv_data->ioaddr);
  1453. clk_disable(ssp->clk);
  1454. return 0;
  1455. }
  1456. static int pxa2xx_spi_resume(struct device *dev)
  1457. {
  1458. struct driver_data *drv_data = dev_get_drvdata(dev);
  1459. struct ssp_device *ssp = drv_data->ssp;
  1460. int status = 0;
  1461. if (drv_data->rx_channel != -1)
  1462. DRCMR(drv_data->ssp->drcmr_rx) =
  1463. DRCMR_MAPVLD | drv_data->rx_channel;
  1464. if (drv_data->tx_channel != -1)
  1465. DRCMR(drv_data->ssp->drcmr_tx) =
  1466. DRCMR_MAPVLD | drv_data->tx_channel;
  1467. /* Enable the SSP clock */
  1468. clk_enable(ssp->clk);
  1469. /* Start the queue running */
  1470. status = start_queue(drv_data);
  1471. if (status != 0) {
  1472. dev_err(dev, "problem starting queue (%d)\n", status);
  1473. return status;
  1474. }
  1475. return 0;
  1476. }
  1477. static const struct dev_pm_ops pxa2xx_spi_pm_ops = {
  1478. .suspend = pxa2xx_spi_suspend,
  1479. .resume = pxa2xx_spi_resume,
  1480. };
  1481. #endif
  1482. static struct platform_driver driver = {
  1483. .driver = {
  1484. .name = "pxa2xx-spi",
  1485. .owner = THIS_MODULE,
  1486. #ifdef CONFIG_PM
  1487. .pm = &pxa2xx_spi_pm_ops,
  1488. #endif
  1489. },
  1490. .probe = pxa2xx_spi_probe,
  1491. .remove = pxa2xx_spi_remove,
  1492. .shutdown = pxa2xx_spi_shutdown,
  1493. };
  1494. static int __init pxa2xx_spi_init(void)
  1495. {
  1496. return platform_driver_register(&driver);
  1497. }
  1498. subsys_initcall(pxa2xx_spi_init);
  1499. static void __exit pxa2xx_spi_exit(void)
  1500. {
  1501. platform_driver_unregister(&driver);
  1502. }
  1503. module_exit(pxa2xx_spi_exit);