pxa2xx_spi.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817
  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. if (!(status & mask))
  642. return IRQ_NONE;
  643. if (!drv_data->cur_msg) {
  644. write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
  645. write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg);
  646. if (!pxa25x_ssp_comp(drv_data))
  647. write_SSTO(0, reg);
  648. write_SSSR_CS(drv_data, drv_data->clear_sr);
  649. dev_err(&drv_data->pdev->dev, "bad message state "
  650. "in interrupt handler\n");
  651. /* Never fail */
  652. return IRQ_HANDLED;
  653. }
  654. return drv_data->transfer_handler(drv_data);
  655. }
  656. static int set_dma_burst_and_threshold(struct chip_data *chip,
  657. struct spi_device *spi,
  658. u8 bits_per_word, u32 *burst_code,
  659. u32 *threshold)
  660. {
  661. struct pxa2xx_spi_chip *chip_info =
  662. (struct pxa2xx_spi_chip *)spi->controller_data;
  663. int bytes_per_word;
  664. int burst_bytes;
  665. int thresh_words;
  666. int req_burst_size;
  667. int retval = 0;
  668. /* Set the threshold (in registers) to equal the same amount of data
  669. * as represented by burst size (in bytes). The computation below
  670. * is (burst_size rounded up to nearest 8 byte, word or long word)
  671. * divided by (bytes/register); the tx threshold is the inverse of
  672. * the rx, so that there will always be enough data in the rx fifo
  673. * to satisfy a burst, and there will always be enough space in the
  674. * tx fifo to accept a burst (a tx burst will overwrite the fifo if
  675. * there is not enough space), there must always remain enough empty
  676. * space in the rx fifo for any data loaded to the tx fifo.
  677. * Whenever burst_size (in bytes) equals bits/word, the fifo threshold
  678. * will be 8, or half the fifo;
  679. * The threshold can only be set to 2, 4 or 8, but not 16, because
  680. * to burst 16 to the tx fifo, the fifo would have to be empty;
  681. * however, the minimum fifo trigger level is 1, and the tx will
  682. * request service when the fifo is at this level, with only 15 spaces.
  683. */
  684. /* find bytes/word */
  685. if (bits_per_word <= 8)
  686. bytes_per_word = 1;
  687. else if (bits_per_word <= 16)
  688. bytes_per_word = 2;
  689. else
  690. bytes_per_word = 4;
  691. /* use struct pxa2xx_spi_chip->dma_burst_size if available */
  692. if (chip_info)
  693. req_burst_size = chip_info->dma_burst_size;
  694. else {
  695. switch (chip->dma_burst_size) {
  696. default:
  697. /* if the default burst size is not set,
  698. * do it now */
  699. chip->dma_burst_size = DCMD_BURST8;
  700. case DCMD_BURST8:
  701. req_burst_size = 8;
  702. break;
  703. case DCMD_BURST16:
  704. req_burst_size = 16;
  705. break;
  706. case DCMD_BURST32:
  707. req_burst_size = 32;
  708. break;
  709. }
  710. }
  711. if (req_burst_size <= 8) {
  712. *burst_code = DCMD_BURST8;
  713. burst_bytes = 8;
  714. } else if (req_burst_size <= 16) {
  715. if (bytes_per_word == 1) {
  716. /* don't burst more than 1/2 the fifo */
  717. *burst_code = DCMD_BURST8;
  718. burst_bytes = 8;
  719. retval = 1;
  720. } else {
  721. *burst_code = DCMD_BURST16;
  722. burst_bytes = 16;
  723. }
  724. } else {
  725. if (bytes_per_word == 1) {
  726. /* don't burst more than 1/2 the fifo */
  727. *burst_code = DCMD_BURST8;
  728. burst_bytes = 8;
  729. retval = 1;
  730. } else if (bytes_per_word == 2) {
  731. /* don't burst more than 1/2 the fifo */
  732. *burst_code = DCMD_BURST16;
  733. burst_bytes = 16;
  734. retval = 1;
  735. } else {
  736. *burst_code = DCMD_BURST32;
  737. burst_bytes = 32;
  738. }
  739. }
  740. thresh_words = burst_bytes / bytes_per_word;
  741. /* thresh_words will be between 2 and 8 */
  742. *threshold = (SSCR1_RxTresh(thresh_words) & SSCR1_RFT)
  743. | (SSCR1_TxTresh(16-thresh_words) & SSCR1_TFT);
  744. return retval;
  745. }
  746. static unsigned int ssp_get_clk_div(struct ssp_device *ssp, int rate)
  747. {
  748. unsigned long ssp_clk = clk_get_rate(ssp->clk);
  749. if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP)
  750. return ((ssp_clk / (2 * rate) - 1) & 0xff) << 8;
  751. else
  752. return ((ssp_clk / rate - 1) & 0xfff) << 8;
  753. }
  754. static void pump_transfers(unsigned long data)
  755. {
  756. struct driver_data *drv_data = (struct driver_data *)data;
  757. struct spi_message *message = NULL;
  758. struct spi_transfer *transfer = NULL;
  759. struct spi_transfer *previous = NULL;
  760. struct chip_data *chip = NULL;
  761. struct ssp_device *ssp = drv_data->ssp;
  762. void __iomem *reg = drv_data->ioaddr;
  763. u32 clk_div = 0;
  764. u8 bits = 0;
  765. u32 speed = 0;
  766. u32 cr0;
  767. u32 cr1;
  768. u32 dma_thresh = drv_data->cur_chip->dma_threshold;
  769. u32 dma_burst = drv_data->cur_chip->dma_burst_size;
  770. /* Get current state information */
  771. message = drv_data->cur_msg;
  772. transfer = drv_data->cur_transfer;
  773. chip = drv_data->cur_chip;
  774. /* Handle for abort */
  775. if (message->state == ERROR_STATE) {
  776. message->status = -EIO;
  777. giveback(drv_data);
  778. return;
  779. }
  780. /* Handle end of message */
  781. if (message->state == DONE_STATE) {
  782. message->status = 0;
  783. giveback(drv_data);
  784. return;
  785. }
  786. /* Delay if requested at end of transfer before CS change */
  787. if (message->state == RUNNING_STATE) {
  788. previous = list_entry(transfer->transfer_list.prev,
  789. struct spi_transfer,
  790. transfer_list);
  791. if (previous->delay_usecs)
  792. udelay(previous->delay_usecs);
  793. /* Drop chip select only if cs_change is requested */
  794. if (previous->cs_change)
  795. cs_deassert(drv_data);
  796. }
  797. /* Check for transfers that need multiple DMA segments */
  798. if (transfer->len > MAX_DMA_LEN && chip->enable_dma) {
  799. /* reject already-mapped transfers; PIO won't always work */
  800. if (message->is_dma_mapped
  801. || transfer->rx_dma || transfer->tx_dma) {
  802. dev_err(&drv_data->pdev->dev,
  803. "pump_transfers: mapped transfer length "
  804. "of %u is greater than %d\n",
  805. transfer->len, MAX_DMA_LEN);
  806. message->status = -EINVAL;
  807. giveback(drv_data);
  808. return;
  809. }
  810. /* warn ... we force this to PIO mode */
  811. if (printk_ratelimit())
  812. dev_warn(&message->spi->dev, "pump_transfers: "
  813. "DMA disabled for transfer length %ld "
  814. "greater than %d\n",
  815. (long)drv_data->len, MAX_DMA_LEN);
  816. }
  817. /* Setup the transfer state based on the type of transfer */
  818. if (flush(drv_data) == 0) {
  819. dev_err(&drv_data->pdev->dev, "pump_transfers: flush failed\n");
  820. message->status = -EIO;
  821. giveback(drv_data);
  822. return;
  823. }
  824. drv_data->n_bytes = chip->n_bytes;
  825. drv_data->dma_width = chip->dma_width;
  826. drv_data->tx = (void *)transfer->tx_buf;
  827. drv_data->tx_end = drv_data->tx + transfer->len;
  828. drv_data->rx = transfer->rx_buf;
  829. drv_data->rx_end = drv_data->rx + transfer->len;
  830. drv_data->rx_dma = transfer->rx_dma;
  831. drv_data->tx_dma = transfer->tx_dma;
  832. drv_data->len = transfer->len & DCMD_LENGTH;
  833. drv_data->write = drv_data->tx ? chip->write : null_writer;
  834. drv_data->read = drv_data->rx ? chip->read : null_reader;
  835. /* Change speed and bit per word on a per transfer */
  836. cr0 = chip->cr0;
  837. if (transfer->speed_hz || transfer->bits_per_word) {
  838. bits = chip->bits_per_word;
  839. speed = chip->speed_hz;
  840. if (transfer->speed_hz)
  841. speed = transfer->speed_hz;
  842. if (transfer->bits_per_word)
  843. bits = transfer->bits_per_word;
  844. clk_div = ssp_get_clk_div(ssp, speed);
  845. if (bits <= 8) {
  846. drv_data->n_bytes = 1;
  847. drv_data->dma_width = DCMD_WIDTH1;
  848. drv_data->read = drv_data->read != null_reader ?
  849. u8_reader : null_reader;
  850. drv_data->write = drv_data->write != null_writer ?
  851. u8_writer : null_writer;
  852. } else if (bits <= 16) {
  853. drv_data->n_bytes = 2;
  854. drv_data->dma_width = DCMD_WIDTH2;
  855. drv_data->read = drv_data->read != null_reader ?
  856. u16_reader : null_reader;
  857. drv_data->write = drv_data->write != null_writer ?
  858. u16_writer : null_writer;
  859. } else if (bits <= 32) {
  860. drv_data->n_bytes = 4;
  861. drv_data->dma_width = DCMD_WIDTH4;
  862. drv_data->read = drv_data->read != null_reader ?
  863. u32_reader : null_reader;
  864. drv_data->write = drv_data->write != null_writer ?
  865. u32_writer : null_writer;
  866. }
  867. /* if bits/word is changed in dma mode, then must check the
  868. * thresholds and burst also */
  869. if (chip->enable_dma) {
  870. if (set_dma_burst_and_threshold(chip, message->spi,
  871. bits, &dma_burst,
  872. &dma_thresh))
  873. if (printk_ratelimit())
  874. dev_warn(&message->spi->dev,
  875. "pump_transfers: "
  876. "DMA burst size reduced to "
  877. "match bits_per_word\n");
  878. }
  879. cr0 = clk_div
  880. | SSCR0_Motorola
  881. | SSCR0_DataSize(bits > 16 ? bits - 16 : bits)
  882. | SSCR0_SSE
  883. | (bits > 16 ? SSCR0_EDSS : 0);
  884. }
  885. message->state = RUNNING_STATE;
  886. /* Try to map dma buffer and do a dma transfer if successful, but
  887. * only if the length is non-zero and less than MAX_DMA_LEN.
  888. *
  889. * Zero-length non-descriptor DMA is illegal on PXA2xx; force use
  890. * of PIO instead. Care is needed above because the transfer may
  891. * have have been passed with buffers that are already dma mapped.
  892. * A zero-length transfer in PIO mode will not try to write/read
  893. * to/from the buffers
  894. *
  895. * REVISIT large transfers are exactly where we most want to be
  896. * using DMA. If this happens much, split those transfers into
  897. * multiple DMA segments rather than forcing PIO.
  898. */
  899. drv_data->dma_mapped = 0;
  900. if (drv_data->len > 0 && drv_data->len <= MAX_DMA_LEN)
  901. drv_data->dma_mapped = map_dma_buffers(drv_data);
  902. if (drv_data->dma_mapped) {
  903. /* Ensure we have the correct interrupt handler */
  904. drv_data->transfer_handler = dma_transfer;
  905. /* Setup rx DMA Channel */
  906. DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
  907. DSADR(drv_data->rx_channel) = drv_data->ssdr_physical;
  908. DTADR(drv_data->rx_channel) = drv_data->rx_dma;
  909. if (drv_data->rx == drv_data->null_dma_buf)
  910. /* No target address increment */
  911. DCMD(drv_data->rx_channel) = DCMD_FLOWSRC
  912. | drv_data->dma_width
  913. | dma_burst
  914. | drv_data->len;
  915. else
  916. DCMD(drv_data->rx_channel) = DCMD_INCTRGADDR
  917. | DCMD_FLOWSRC
  918. | drv_data->dma_width
  919. | dma_burst
  920. | drv_data->len;
  921. /* Setup tx DMA Channel */
  922. DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
  923. DSADR(drv_data->tx_channel) = drv_data->tx_dma;
  924. DTADR(drv_data->tx_channel) = drv_data->ssdr_physical;
  925. if (drv_data->tx == drv_data->null_dma_buf)
  926. /* No source address increment */
  927. DCMD(drv_data->tx_channel) = DCMD_FLOWTRG
  928. | drv_data->dma_width
  929. | dma_burst
  930. | drv_data->len;
  931. else
  932. DCMD(drv_data->tx_channel) = DCMD_INCSRCADDR
  933. | DCMD_FLOWTRG
  934. | drv_data->dma_width
  935. | dma_burst
  936. | drv_data->len;
  937. /* Enable dma end irqs on SSP to detect end of transfer */
  938. if (drv_data->ssp_type == PXA25x_SSP)
  939. DCMD(drv_data->tx_channel) |= DCMD_ENDIRQEN;
  940. /* Clear status and start DMA engine */
  941. cr1 = chip->cr1 | dma_thresh | drv_data->dma_cr1;
  942. write_SSSR(drv_data->clear_sr, reg);
  943. DCSR(drv_data->rx_channel) |= DCSR_RUN;
  944. DCSR(drv_data->tx_channel) |= DCSR_RUN;
  945. } else {
  946. /* Ensure we have the correct interrupt handler */
  947. drv_data->transfer_handler = interrupt_transfer;
  948. /* Clear status */
  949. cr1 = chip->cr1 | chip->threshold | drv_data->int_cr1;
  950. write_SSSR_CS(drv_data, drv_data->clear_sr);
  951. }
  952. /* see if we need to reload the config registers */
  953. if ((read_SSCR0(reg) != cr0)
  954. || (read_SSCR1(reg) & SSCR1_CHANGE_MASK) !=
  955. (cr1 & SSCR1_CHANGE_MASK)) {
  956. /* stop the SSP, and update the other bits */
  957. write_SSCR0(cr0 & ~SSCR0_SSE, reg);
  958. if (!pxa25x_ssp_comp(drv_data))
  959. write_SSTO(chip->timeout, reg);
  960. /* first set CR1 without interrupt and service enables */
  961. write_SSCR1(cr1 & SSCR1_CHANGE_MASK, reg);
  962. /* restart the SSP */
  963. write_SSCR0(cr0, reg);
  964. } else {
  965. if (!pxa25x_ssp_comp(drv_data))
  966. write_SSTO(chip->timeout, reg);
  967. }
  968. cs_assert(drv_data);
  969. /* after chip select, release the data by enabling service
  970. * requests and interrupts, without changing any mode bits */
  971. write_SSCR1(cr1, reg);
  972. }
  973. static void pump_messages(struct work_struct *work)
  974. {
  975. struct driver_data *drv_data =
  976. container_of(work, struct driver_data, pump_messages);
  977. unsigned long flags;
  978. /* Lock queue and check for queue work */
  979. spin_lock_irqsave(&drv_data->lock, flags);
  980. if (list_empty(&drv_data->queue) || drv_data->run == QUEUE_STOPPED) {
  981. drv_data->busy = 0;
  982. spin_unlock_irqrestore(&drv_data->lock, flags);
  983. return;
  984. }
  985. /* Make sure we are not already running a message */
  986. if (drv_data->cur_msg) {
  987. spin_unlock_irqrestore(&drv_data->lock, flags);
  988. return;
  989. }
  990. /* Extract head of queue */
  991. drv_data->cur_msg = list_entry(drv_data->queue.next,
  992. struct spi_message, queue);
  993. list_del_init(&drv_data->cur_msg->queue);
  994. /* Initial message state*/
  995. drv_data->cur_msg->state = START_STATE;
  996. drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next,
  997. struct spi_transfer,
  998. transfer_list);
  999. /* prepare to setup the SSP, in pump_transfers, using the per
  1000. * chip configuration */
  1001. drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi);
  1002. /* Mark as busy and launch transfers */
  1003. tasklet_schedule(&drv_data->pump_transfers);
  1004. drv_data->busy = 1;
  1005. spin_unlock_irqrestore(&drv_data->lock, flags);
  1006. }
  1007. static int transfer(struct spi_device *spi, struct spi_message *msg)
  1008. {
  1009. struct driver_data *drv_data = spi_master_get_devdata(spi->master);
  1010. unsigned long flags;
  1011. spin_lock_irqsave(&drv_data->lock, flags);
  1012. if (drv_data->run == QUEUE_STOPPED) {
  1013. spin_unlock_irqrestore(&drv_data->lock, flags);
  1014. return -ESHUTDOWN;
  1015. }
  1016. msg->actual_length = 0;
  1017. msg->status = -EINPROGRESS;
  1018. msg->state = START_STATE;
  1019. list_add_tail(&msg->queue, &drv_data->queue);
  1020. if (drv_data->run == QUEUE_RUNNING && !drv_data->busy)
  1021. queue_work(drv_data->workqueue, &drv_data->pump_messages);
  1022. spin_unlock_irqrestore(&drv_data->lock, flags);
  1023. return 0;
  1024. }
  1025. static int setup_cs(struct spi_device *spi, struct chip_data *chip,
  1026. struct pxa2xx_spi_chip *chip_info)
  1027. {
  1028. int err = 0;
  1029. if (chip == NULL || chip_info == NULL)
  1030. return 0;
  1031. /* NOTE: setup() can be called multiple times, possibly with
  1032. * different chip_info, release previously requested GPIO
  1033. */
  1034. if (gpio_is_valid(chip->gpio_cs))
  1035. gpio_free(chip->gpio_cs);
  1036. /* If (*cs_control) is provided, ignore GPIO chip select */
  1037. if (chip_info->cs_control) {
  1038. chip->cs_control = chip_info->cs_control;
  1039. return 0;
  1040. }
  1041. if (gpio_is_valid(chip_info->gpio_cs)) {
  1042. err = gpio_request(chip_info->gpio_cs, "SPI_CS");
  1043. if (err) {
  1044. dev_err(&spi->dev, "failed to request chip select "
  1045. "GPIO%d\n", chip_info->gpio_cs);
  1046. return err;
  1047. }
  1048. chip->gpio_cs = chip_info->gpio_cs;
  1049. chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
  1050. err = gpio_direction_output(chip->gpio_cs,
  1051. !chip->gpio_cs_inverted);
  1052. }
  1053. return err;
  1054. }
  1055. static int setup(struct spi_device *spi)
  1056. {
  1057. struct pxa2xx_spi_chip *chip_info = NULL;
  1058. struct chip_data *chip;
  1059. struct driver_data *drv_data = spi_master_get_devdata(spi->master);
  1060. struct ssp_device *ssp = drv_data->ssp;
  1061. unsigned int clk_div;
  1062. uint tx_thres = TX_THRESH_DFLT;
  1063. uint rx_thres = RX_THRESH_DFLT;
  1064. if (!pxa25x_ssp_comp(drv_data)
  1065. && (spi->bits_per_word < 4 || spi->bits_per_word > 32)) {
  1066. dev_err(&spi->dev, "failed setup: ssp_type=%d, bits/wrd=%d "
  1067. "b/w not 4-32 for type non-PXA25x_SSP\n",
  1068. drv_data->ssp_type, spi->bits_per_word);
  1069. return -EINVAL;
  1070. } else if (pxa25x_ssp_comp(drv_data)
  1071. && (spi->bits_per_word < 4
  1072. || spi->bits_per_word > 16)) {
  1073. dev_err(&spi->dev, "failed setup: ssp_type=%d, bits/wrd=%d "
  1074. "b/w not 4-16 for type PXA25x_SSP\n",
  1075. drv_data->ssp_type, spi->bits_per_word);
  1076. return -EINVAL;
  1077. }
  1078. /* Only alloc on first setup */
  1079. chip = spi_get_ctldata(spi);
  1080. if (!chip) {
  1081. chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
  1082. if (!chip) {
  1083. dev_err(&spi->dev,
  1084. "failed setup: can't allocate chip data\n");
  1085. return -ENOMEM;
  1086. }
  1087. if (drv_data->ssp_type == CE4100_SSP) {
  1088. if (spi->chip_select > 4) {
  1089. dev_err(&spi->dev, "failed setup: "
  1090. "cs number must not be > 4.\n");
  1091. kfree(chip);
  1092. return -EINVAL;
  1093. }
  1094. chip->frm = spi->chip_select;
  1095. } else
  1096. chip->gpio_cs = -1;
  1097. chip->enable_dma = 0;
  1098. chip->timeout = TIMOUT_DFLT;
  1099. chip->dma_burst_size = drv_data->master_info->enable_dma ?
  1100. DCMD_BURST8 : 0;
  1101. }
  1102. /* protocol drivers may change the chip settings, so...
  1103. * if chip_info exists, use it */
  1104. chip_info = spi->controller_data;
  1105. /* chip_info isn't always needed */
  1106. chip->cr1 = 0;
  1107. if (chip_info) {
  1108. if (chip_info->timeout)
  1109. chip->timeout = chip_info->timeout;
  1110. if (chip_info->tx_threshold)
  1111. tx_thres = chip_info->tx_threshold;
  1112. if (chip_info->rx_threshold)
  1113. rx_thres = chip_info->rx_threshold;
  1114. chip->enable_dma = drv_data->master_info->enable_dma;
  1115. chip->dma_threshold = 0;
  1116. if (chip_info->enable_loopback)
  1117. chip->cr1 = SSCR1_LBM;
  1118. }
  1119. chip->threshold = (SSCR1_RxTresh(rx_thres) & SSCR1_RFT) |
  1120. (SSCR1_TxTresh(tx_thres) & SSCR1_TFT);
  1121. /* set dma burst and threshold outside of chip_info path so that if
  1122. * chip_info goes away after setting chip->enable_dma, the
  1123. * burst and threshold can still respond to changes in bits_per_word */
  1124. if (chip->enable_dma) {
  1125. /* set up legal burst and threshold for dma */
  1126. if (set_dma_burst_and_threshold(chip, spi, spi->bits_per_word,
  1127. &chip->dma_burst_size,
  1128. &chip->dma_threshold)) {
  1129. dev_warn(&spi->dev, "in setup: DMA burst size reduced "
  1130. "to match bits_per_word\n");
  1131. }
  1132. }
  1133. clk_div = ssp_get_clk_div(ssp, spi->max_speed_hz);
  1134. chip->speed_hz = spi->max_speed_hz;
  1135. chip->cr0 = clk_div
  1136. | SSCR0_Motorola
  1137. | SSCR0_DataSize(spi->bits_per_word > 16 ?
  1138. spi->bits_per_word - 16 : spi->bits_per_word)
  1139. | SSCR0_SSE
  1140. | (spi->bits_per_word > 16 ? SSCR0_EDSS : 0);
  1141. chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH);
  1142. chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) ? SSCR1_SPH : 0)
  1143. | (((spi->mode & SPI_CPOL) != 0) ? SSCR1_SPO : 0);
  1144. /* NOTE: PXA25x_SSP _could_ use external clocking ... */
  1145. if (!pxa25x_ssp_comp(drv_data))
  1146. dev_dbg(&spi->dev, "%ld Hz actual, %s\n",
  1147. clk_get_rate(ssp->clk)
  1148. / (1 + ((chip->cr0 & SSCR0_SCR(0xfff)) >> 8)),
  1149. chip->enable_dma ? "DMA" : "PIO");
  1150. else
  1151. dev_dbg(&spi->dev, "%ld Hz actual, %s\n",
  1152. clk_get_rate(ssp->clk) / 2
  1153. / (1 + ((chip->cr0 & SSCR0_SCR(0x0ff)) >> 8)),
  1154. chip->enable_dma ? "DMA" : "PIO");
  1155. if (spi->bits_per_word <= 8) {
  1156. chip->n_bytes = 1;
  1157. chip->dma_width = DCMD_WIDTH1;
  1158. chip->read = u8_reader;
  1159. chip->write = u8_writer;
  1160. } else if (spi->bits_per_word <= 16) {
  1161. chip->n_bytes = 2;
  1162. chip->dma_width = DCMD_WIDTH2;
  1163. chip->read = u16_reader;
  1164. chip->write = u16_writer;
  1165. } else if (spi->bits_per_word <= 32) {
  1166. chip->cr0 |= SSCR0_EDSS;
  1167. chip->n_bytes = 4;
  1168. chip->dma_width = DCMD_WIDTH4;
  1169. chip->read = u32_reader;
  1170. chip->write = u32_writer;
  1171. } else {
  1172. dev_err(&spi->dev, "invalid wordsize\n");
  1173. return -ENODEV;
  1174. }
  1175. chip->bits_per_word = spi->bits_per_word;
  1176. spi_set_ctldata(spi, chip);
  1177. if (drv_data->ssp_type == CE4100_SSP)
  1178. return 0;
  1179. return setup_cs(spi, chip, chip_info);
  1180. }
  1181. static void cleanup(struct spi_device *spi)
  1182. {
  1183. struct chip_data *chip = spi_get_ctldata(spi);
  1184. struct driver_data *drv_data = spi_master_get_devdata(spi->master);
  1185. if (!chip)
  1186. return;
  1187. if (drv_data->ssp_type != CE4100_SSP && gpio_is_valid(chip->gpio_cs))
  1188. gpio_free(chip->gpio_cs);
  1189. kfree(chip);
  1190. }
  1191. static int __devinit init_queue(struct driver_data *drv_data)
  1192. {
  1193. INIT_LIST_HEAD(&drv_data->queue);
  1194. spin_lock_init(&drv_data->lock);
  1195. drv_data->run = QUEUE_STOPPED;
  1196. drv_data->busy = 0;
  1197. tasklet_init(&drv_data->pump_transfers,
  1198. pump_transfers, (unsigned long)drv_data);
  1199. INIT_WORK(&drv_data->pump_messages, pump_messages);
  1200. drv_data->workqueue = create_singlethread_workqueue(
  1201. dev_name(drv_data->master->dev.parent));
  1202. if (drv_data->workqueue == NULL)
  1203. return -EBUSY;
  1204. return 0;
  1205. }
  1206. static int start_queue(struct driver_data *drv_data)
  1207. {
  1208. unsigned long flags;
  1209. spin_lock_irqsave(&drv_data->lock, flags);
  1210. if (drv_data->run == QUEUE_RUNNING || drv_data->busy) {
  1211. spin_unlock_irqrestore(&drv_data->lock, flags);
  1212. return -EBUSY;
  1213. }
  1214. drv_data->run = QUEUE_RUNNING;
  1215. drv_data->cur_msg = NULL;
  1216. drv_data->cur_transfer = NULL;
  1217. drv_data->cur_chip = NULL;
  1218. spin_unlock_irqrestore(&drv_data->lock, flags);
  1219. queue_work(drv_data->workqueue, &drv_data->pump_messages);
  1220. return 0;
  1221. }
  1222. static int stop_queue(struct driver_data *drv_data)
  1223. {
  1224. unsigned long flags;
  1225. unsigned limit = 500;
  1226. int status = 0;
  1227. spin_lock_irqsave(&drv_data->lock, flags);
  1228. /* This is a bit lame, but is optimized for the common execution path.
  1229. * A wait_queue on the drv_data->busy could be used, but then the common
  1230. * execution path (pump_messages) would be required to call wake_up or
  1231. * friends on every SPI message. Do this instead */
  1232. drv_data->run = QUEUE_STOPPED;
  1233. while ((!list_empty(&drv_data->queue) || drv_data->busy) && limit--) {
  1234. spin_unlock_irqrestore(&drv_data->lock, flags);
  1235. msleep(10);
  1236. spin_lock_irqsave(&drv_data->lock, flags);
  1237. }
  1238. if (!list_empty(&drv_data->queue) || drv_data->busy)
  1239. status = -EBUSY;
  1240. spin_unlock_irqrestore(&drv_data->lock, flags);
  1241. return status;
  1242. }
  1243. static int destroy_queue(struct driver_data *drv_data)
  1244. {
  1245. int status;
  1246. status = stop_queue(drv_data);
  1247. /* we are unloading the module or failing to load (only two calls
  1248. * to this routine), and neither call can handle a return value.
  1249. * However, destroy_workqueue calls flush_workqueue, and that will
  1250. * block until all work is done. If the reason that stop_queue
  1251. * timed out is that the work will never finish, then it does no
  1252. * good to call destroy_workqueue, so return anyway. */
  1253. if (status != 0)
  1254. return status;
  1255. destroy_workqueue(drv_data->workqueue);
  1256. return 0;
  1257. }
  1258. static int __devinit pxa2xx_spi_probe(struct platform_device *pdev)
  1259. {
  1260. struct device *dev = &pdev->dev;
  1261. struct pxa2xx_spi_master *platform_info;
  1262. struct spi_master *master;
  1263. struct driver_data *drv_data;
  1264. struct ssp_device *ssp;
  1265. int status;
  1266. platform_info = dev->platform_data;
  1267. ssp = pxa_ssp_request(pdev->id, pdev->name);
  1268. if (ssp == NULL) {
  1269. dev_err(&pdev->dev, "failed to request SSP%d\n", pdev->id);
  1270. return -ENODEV;
  1271. }
  1272. /* Allocate master with space for drv_data and null dma buffer */
  1273. master = spi_alloc_master(dev, sizeof(struct driver_data) + 16);
  1274. if (!master) {
  1275. dev_err(&pdev->dev, "cannot alloc spi_master\n");
  1276. pxa_ssp_free(ssp);
  1277. return -ENOMEM;
  1278. }
  1279. drv_data = spi_master_get_devdata(master);
  1280. drv_data->master = master;
  1281. drv_data->master_info = platform_info;
  1282. drv_data->pdev = pdev;
  1283. drv_data->ssp = ssp;
  1284. master->dev.parent = &pdev->dev;
  1285. master->dev.of_node = pdev->dev.of_node;
  1286. /* the spi->mode bits understood by this driver: */
  1287. master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
  1288. master->bus_num = pdev->id;
  1289. master->num_chipselect = platform_info->num_chipselect;
  1290. master->dma_alignment = DMA_ALIGNMENT;
  1291. master->cleanup = cleanup;
  1292. master->setup = setup;
  1293. master->transfer = transfer;
  1294. drv_data->ssp_type = ssp->type;
  1295. drv_data->null_dma_buf = (u32 *)ALIGN((u32)(drv_data +
  1296. sizeof(struct driver_data)), 8);
  1297. drv_data->ioaddr = ssp->mmio_base;
  1298. drv_data->ssdr_physical = ssp->phys_base + SSDR;
  1299. if (pxa25x_ssp_comp(drv_data)) {
  1300. drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE;
  1301. drv_data->dma_cr1 = 0;
  1302. drv_data->clear_sr = SSSR_ROR;
  1303. drv_data->mask_sr = SSSR_RFS | SSSR_TFS | SSSR_ROR;
  1304. } else {
  1305. drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE;
  1306. drv_data->dma_cr1 = SSCR1_TSRE | SSCR1_RSRE | SSCR1_TINTE;
  1307. drv_data->clear_sr = SSSR_ROR | SSSR_TINT;
  1308. drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS | SSSR_ROR;
  1309. }
  1310. status = request_irq(ssp->irq, ssp_int, IRQF_SHARED, dev_name(dev),
  1311. drv_data);
  1312. if (status < 0) {
  1313. dev_err(&pdev->dev, "cannot get IRQ %d\n", ssp->irq);
  1314. goto out_error_master_alloc;
  1315. }
  1316. /* Setup DMA if requested */
  1317. drv_data->tx_channel = -1;
  1318. drv_data->rx_channel = -1;
  1319. if (platform_info->enable_dma) {
  1320. /* Get two DMA channels (rx and tx) */
  1321. drv_data->rx_channel = pxa_request_dma("pxa2xx_spi_ssp_rx",
  1322. DMA_PRIO_HIGH,
  1323. dma_handler,
  1324. drv_data);
  1325. if (drv_data->rx_channel < 0) {
  1326. dev_err(dev, "problem (%d) requesting rx channel\n",
  1327. drv_data->rx_channel);
  1328. status = -ENODEV;
  1329. goto out_error_irq_alloc;
  1330. }
  1331. drv_data->tx_channel = pxa_request_dma("pxa2xx_spi_ssp_tx",
  1332. DMA_PRIO_MEDIUM,
  1333. dma_handler,
  1334. drv_data);
  1335. if (drv_data->tx_channel < 0) {
  1336. dev_err(dev, "problem (%d) requesting tx channel\n",
  1337. drv_data->tx_channel);
  1338. status = -ENODEV;
  1339. goto out_error_dma_alloc;
  1340. }
  1341. DRCMR(ssp->drcmr_rx) = DRCMR_MAPVLD | drv_data->rx_channel;
  1342. DRCMR(ssp->drcmr_tx) = DRCMR_MAPVLD | drv_data->tx_channel;
  1343. }
  1344. /* Enable SOC clock */
  1345. clk_enable(ssp->clk);
  1346. /* Load default SSP configuration */
  1347. write_SSCR0(0, drv_data->ioaddr);
  1348. write_SSCR1(SSCR1_RxTresh(RX_THRESH_DFLT) |
  1349. SSCR1_TxTresh(TX_THRESH_DFLT),
  1350. drv_data->ioaddr);
  1351. write_SSCR0(SSCR0_SCR(2)
  1352. | SSCR0_Motorola
  1353. | SSCR0_DataSize(8),
  1354. drv_data->ioaddr);
  1355. if (!pxa25x_ssp_comp(drv_data))
  1356. write_SSTO(0, drv_data->ioaddr);
  1357. write_SSPSP(0, drv_data->ioaddr);
  1358. /* Initial and start queue */
  1359. status = init_queue(drv_data);
  1360. if (status != 0) {
  1361. dev_err(&pdev->dev, "problem initializing queue\n");
  1362. goto out_error_clock_enabled;
  1363. }
  1364. status = start_queue(drv_data);
  1365. if (status != 0) {
  1366. dev_err(&pdev->dev, "problem starting queue\n");
  1367. goto out_error_clock_enabled;
  1368. }
  1369. /* Register with the SPI framework */
  1370. platform_set_drvdata(pdev, drv_data);
  1371. status = spi_register_master(master);
  1372. if (status != 0) {
  1373. dev_err(&pdev->dev, "problem registering spi master\n");
  1374. goto out_error_queue_alloc;
  1375. }
  1376. return status;
  1377. out_error_queue_alloc:
  1378. destroy_queue(drv_data);
  1379. out_error_clock_enabled:
  1380. clk_disable(ssp->clk);
  1381. out_error_dma_alloc:
  1382. if (drv_data->tx_channel != -1)
  1383. pxa_free_dma(drv_data->tx_channel);
  1384. if (drv_data->rx_channel != -1)
  1385. pxa_free_dma(drv_data->rx_channel);
  1386. out_error_irq_alloc:
  1387. free_irq(ssp->irq, drv_data);
  1388. out_error_master_alloc:
  1389. spi_master_put(master);
  1390. pxa_ssp_free(ssp);
  1391. return status;
  1392. }
  1393. static int pxa2xx_spi_remove(struct platform_device *pdev)
  1394. {
  1395. struct driver_data *drv_data = platform_get_drvdata(pdev);
  1396. struct ssp_device *ssp;
  1397. int status = 0;
  1398. if (!drv_data)
  1399. return 0;
  1400. ssp = drv_data->ssp;
  1401. /* Remove the queue */
  1402. status = destroy_queue(drv_data);
  1403. if (status != 0)
  1404. /* the kernel does not check the return status of this
  1405. * this routine (mod->exit, within the kernel). Therefore
  1406. * nothing is gained by returning from here, the module is
  1407. * going away regardless, and we should not leave any more
  1408. * resources allocated than necessary. We cannot free the
  1409. * message memory in drv_data->queue, but we can release the
  1410. * resources below. I think the kernel should honor -EBUSY
  1411. * returns but... */
  1412. dev_err(&pdev->dev, "pxa2xx_spi_remove: workqueue will not "
  1413. "complete, message memory not freed\n");
  1414. /* Disable the SSP at the peripheral and SOC level */
  1415. write_SSCR0(0, drv_data->ioaddr);
  1416. clk_disable(ssp->clk);
  1417. /* Release DMA */
  1418. if (drv_data->master_info->enable_dma) {
  1419. DRCMR(ssp->drcmr_rx) = 0;
  1420. DRCMR(ssp->drcmr_tx) = 0;
  1421. pxa_free_dma(drv_data->tx_channel);
  1422. pxa_free_dma(drv_data->rx_channel);
  1423. }
  1424. /* Release IRQ */
  1425. free_irq(ssp->irq, drv_data);
  1426. /* Release SSP */
  1427. pxa_ssp_free(ssp);
  1428. /* Disconnect from the SPI framework */
  1429. spi_unregister_master(drv_data->master);
  1430. /* Prevent double remove */
  1431. platform_set_drvdata(pdev, NULL);
  1432. return 0;
  1433. }
  1434. static void pxa2xx_spi_shutdown(struct platform_device *pdev)
  1435. {
  1436. int status = 0;
  1437. if ((status = pxa2xx_spi_remove(pdev)) != 0)
  1438. dev_err(&pdev->dev, "shutdown failed with %d\n", status);
  1439. }
  1440. #ifdef CONFIG_PM
  1441. static int pxa2xx_spi_suspend(struct device *dev)
  1442. {
  1443. struct driver_data *drv_data = dev_get_drvdata(dev);
  1444. struct ssp_device *ssp = drv_data->ssp;
  1445. int status = 0;
  1446. status = stop_queue(drv_data);
  1447. if (status != 0)
  1448. return status;
  1449. write_SSCR0(0, drv_data->ioaddr);
  1450. clk_disable(ssp->clk);
  1451. return 0;
  1452. }
  1453. static int pxa2xx_spi_resume(struct device *dev)
  1454. {
  1455. struct driver_data *drv_data = dev_get_drvdata(dev);
  1456. struct ssp_device *ssp = drv_data->ssp;
  1457. int status = 0;
  1458. if (drv_data->rx_channel != -1)
  1459. DRCMR(drv_data->ssp->drcmr_rx) =
  1460. DRCMR_MAPVLD | drv_data->rx_channel;
  1461. if (drv_data->tx_channel != -1)
  1462. DRCMR(drv_data->ssp->drcmr_tx) =
  1463. DRCMR_MAPVLD | drv_data->tx_channel;
  1464. /* Enable the SSP clock */
  1465. clk_enable(ssp->clk);
  1466. /* Start the queue running */
  1467. status = start_queue(drv_data);
  1468. if (status != 0) {
  1469. dev_err(dev, "problem starting queue (%d)\n", status);
  1470. return status;
  1471. }
  1472. return 0;
  1473. }
  1474. static const struct dev_pm_ops pxa2xx_spi_pm_ops = {
  1475. .suspend = pxa2xx_spi_suspend,
  1476. .resume = pxa2xx_spi_resume,
  1477. };
  1478. #endif
  1479. static struct platform_driver driver = {
  1480. .driver = {
  1481. .name = "pxa2xx-spi",
  1482. .owner = THIS_MODULE,
  1483. #ifdef CONFIG_PM
  1484. .pm = &pxa2xx_spi_pm_ops,
  1485. #endif
  1486. },
  1487. .probe = pxa2xx_spi_probe,
  1488. .remove = pxa2xx_spi_remove,
  1489. .shutdown = pxa2xx_spi_shutdown,
  1490. };
  1491. static int __init pxa2xx_spi_init(void)
  1492. {
  1493. return platform_driver_register(&driver);
  1494. }
  1495. subsys_initcall(pxa2xx_spi_init);
  1496. static void __exit pxa2xx_spi_exit(void)
  1497. {
  1498. platform_driver_unregister(&driver);
  1499. }
  1500. module_exit(pxa2xx_spi_exit);