spi-atmel.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786
  1. /*
  2. * Driver for Atmel AT32 and AT91 SPI Controllers
  3. *
  4. * Copyright (C) 2006 Atmel Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/clk.h>
  12. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/delay.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/dmaengine.h>
  17. #include <linux/err.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/spi/spi.h>
  20. #include <linux/slab.h>
  21. #include <linux/platform_data/dma-atmel.h>
  22. #include <linux/of.h>
  23. #include <linux/io.h>
  24. #include <linux/gpio.h>
  25. #include <linux/of_gpio.h>
  26. #include <linux/pinctrl/consumer.h>
  27. #include <linux/pm_runtime.h>
  28. /* SPI register offsets */
  29. #define SPI_CR 0x0000
  30. #define SPI_MR 0x0004
  31. #define SPI_RDR 0x0008
  32. #define SPI_TDR 0x000c
  33. #define SPI_SR 0x0010
  34. #define SPI_IER 0x0014
  35. #define SPI_IDR 0x0018
  36. #define SPI_IMR 0x001c
  37. #define SPI_CSR0 0x0030
  38. #define SPI_CSR1 0x0034
  39. #define SPI_CSR2 0x0038
  40. #define SPI_CSR3 0x003c
  41. #define SPI_FMR 0x0040
  42. #define SPI_FLR 0x0044
  43. #define SPI_VERSION 0x00fc
  44. #define SPI_RPR 0x0100
  45. #define SPI_RCR 0x0104
  46. #define SPI_TPR 0x0108
  47. #define SPI_TCR 0x010c
  48. #define SPI_RNPR 0x0110
  49. #define SPI_RNCR 0x0114
  50. #define SPI_TNPR 0x0118
  51. #define SPI_TNCR 0x011c
  52. #define SPI_PTCR 0x0120
  53. #define SPI_PTSR 0x0124
  54. /* Bitfields in CR */
  55. #define SPI_SPIEN_OFFSET 0
  56. #define SPI_SPIEN_SIZE 1
  57. #define SPI_SPIDIS_OFFSET 1
  58. #define SPI_SPIDIS_SIZE 1
  59. #define SPI_SWRST_OFFSET 7
  60. #define SPI_SWRST_SIZE 1
  61. #define SPI_LASTXFER_OFFSET 24
  62. #define SPI_LASTXFER_SIZE 1
  63. #define SPI_TXFCLR_OFFSET 16
  64. #define SPI_TXFCLR_SIZE 1
  65. #define SPI_RXFCLR_OFFSET 17
  66. #define SPI_RXFCLR_SIZE 1
  67. #define SPI_FIFOEN_OFFSET 30
  68. #define SPI_FIFOEN_SIZE 1
  69. #define SPI_FIFODIS_OFFSET 31
  70. #define SPI_FIFODIS_SIZE 1
  71. /* Bitfields in MR */
  72. #define SPI_MSTR_OFFSET 0
  73. #define SPI_MSTR_SIZE 1
  74. #define SPI_PS_OFFSET 1
  75. #define SPI_PS_SIZE 1
  76. #define SPI_PCSDEC_OFFSET 2
  77. #define SPI_PCSDEC_SIZE 1
  78. #define SPI_FDIV_OFFSET 3
  79. #define SPI_FDIV_SIZE 1
  80. #define SPI_MODFDIS_OFFSET 4
  81. #define SPI_MODFDIS_SIZE 1
  82. #define SPI_WDRBT_OFFSET 5
  83. #define SPI_WDRBT_SIZE 1
  84. #define SPI_LLB_OFFSET 7
  85. #define SPI_LLB_SIZE 1
  86. #define SPI_PCS_OFFSET 16
  87. #define SPI_PCS_SIZE 4
  88. #define SPI_DLYBCS_OFFSET 24
  89. #define SPI_DLYBCS_SIZE 8
  90. /* Bitfields in RDR */
  91. #define SPI_RD_OFFSET 0
  92. #define SPI_RD_SIZE 16
  93. /* Bitfields in TDR */
  94. #define SPI_TD_OFFSET 0
  95. #define SPI_TD_SIZE 16
  96. /* Bitfields in SR */
  97. #define SPI_RDRF_OFFSET 0
  98. #define SPI_RDRF_SIZE 1
  99. #define SPI_TDRE_OFFSET 1
  100. #define SPI_TDRE_SIZE 1
  101. #define SPI_MODF_OFFSET 2
  102. #define SPI_MODF_SIZE 1
  103. #define SPI_OVRES_OFFSET 3
  104. #define SPI_OVRES_SIZE 1
  105. #define SPI_ENDRX_OFFSET 4
  106. #define SPI_ENDRX_SIZE 1
  107. #define SPI_ENDTX_OFFSET 5
  108. #define SPI_ENDTX_SIZE 1
  109. #define SPI_RXBUFF_OFFSET 6
  110. #define SPI_RXBUFF_SIZE 1
  111. #define SPI_TXBUFE_OFFSET 7
  112. #define SPI_TXBUFE_SIZE 1
  113. #define SPI_NSSR_OFFSET 8
  114. #define SPI_NSSR_SIZE 1
  115. #define SPI_TXEMPTY_OFFSET 9
  116. #define SPI_TXEMPTY_SIZE 1
  117. #define SPI_SPIENS_OFFSET 16
  118. #define SPI_SPIENS_SIZE 1
  119. #define SPI_TXFEF_OFFSET 24
  120. #define SPI_TXFEF_SIZE 1
  121. #define SPI_TXFFF_OFFSET 25
  122. #define SPI_TXFFF_SIZE 1
  123. #define SPI_TXFTHF_OFFSET 26
  124. #define SPI_TXFTHF_SIZE 1
  125. #define SPI_RXFEF_OFFSET 27
  126. #define SPI_RXFEF_SIZE 1
  127. #define SPI_RXFFF_OFFSET 28
  128. #define SPI_RXFFF_SIZE 1
  129. #define SPI_RXFTHF_OFFSET 29
  130. #define SPI_RXFTHF_SIZE 1
  131. #define SPI_TXFPTEF_OFFSET 30
  132. #define SPI_TXFPTEF_SIZE 1
  133. #define SPI_RXFPTEF_OFFSET 31
  134. #define SPI_RXFPTEF_SIZE 1
  135. /* Bitfields in CSR0 */
  136. #define SPI_CPOL_OFFSET 0
  137. #define SPI_CPOL_SIZE 1
  138. #define SPI_NCPHA_OFFSET 1
  139. #define SPI_NCPHA_SIZE 1
  140. #define SPI_CSAAT_OFFSET 3
  141. #define SPI_CSAAT_SIZE 1
  142. #define SPI_BITS_OFFSET 4
  143. #define SPI_BITS_SIZE 4
  144. #define SPI_SCBR_OFFSET 8
  145. #define SPI_SCBR_SIZE 8
  146. #define SPI_DLYBS_OFFSET 16
  147. #define SPI_DLYBS_SIZE 8
  148. #define SPI_DLYBCT_OFFSET 24
  149. #define SPI_DLYBCT_SIZE 8
  150. /* Bitfields in RCR */
  151. #define SPI_RXCTR_OFFSET 0
  152. #define SPI_RXCTR_SIZE 16
  153. /* Bitfields in TCR */
  154. #define SPI_TXCTR_OFFSET 0
  155. #define SPI_TXCTR_SIZE 16
  156. /* Bitfields in RNCR */
  157. #define SPI_RXNCR_OFFSET 0
  158. #define SPI_RXNCR_SIZE 16
  159. /* Bitfields in TNCR */
  160. #define SPI_TXNCR_OFFSET 0
  161. #define SPI_TXNCR_SIZE 16
  162. /* Bitfields in PTCR */
  163. #define SPI_RXTEN_OFFSET 0
  164. #define SPI_RXTEN_SIZE 1
  165. #define SPI_RXTDIS_OFFSET 1
  166. #define SPI_RXTDIS_SIZE 1
  167. #define SPI_TXTEN_OFFSET 8
  168. #define SPI_TXTEN_SIZE 1
  169. #define SPI_TXTDIS_OFFSET 9
  170. #define SPI_TXTDIS_SIZE 1
  171. /* Bitfields in FMR */
  172. #define SPI_TXRDYM_OFFSET 0
  173. #define SPI_TXRDYM_SIZE 2
  174. #define SPI_RXRDYM_OFFSET 4
  175. #define SPI_RXRDYM_SIZE 2
  176. #define SPI_TXFTHRES_OFFSET 16
  177. #define SPI_TXFTHRES_SIZE 6
  178. #define SPI_RXFTHRES_OFFSET 24
  179. #define SPI_RXFTHRES_SIZE 6
  180. /* Bitfields in FLR */
  181. #define SPI_TXFL_OFFSET 0
  182. #define SPI_TXFL_SIZE 6
  183. #define SPI_RXFL_OFFSET 16
  184. #define SPI_RXFL_SIZE 6
  185. /* Constants for BITS */
  186. #define SPI_BITS_8_BPT 0
  187. #define SPI_BITS_9_BPT 1
  188. #define SPI_BITS_10_BPT 2
  189. #define SPI_BITS_11_BPT 3
  190. #define SPI_BITS_12_BPT 4
  191. #define SPI_BITS_13_BPT 5
  192. #define SPI_BITS_14_BPT 6
  193. #define SPI_BITS_15_BPT 7
  194. #define SPI_BITS_16_BPT 8
  195. #define SPI_ONE_DATA 0
  196. #define SPI_TWO_DATA 1
  197. #define SPI_FOUR_DATA 2
  198. /* Bit manipulation macros */
  199. #define SPI_BIT(name) \
  200. (1 << SPI_##name##_OFFSET)
  201. #define SPI_BF(name, value) \
  202. (((value) & ((1 << SPI_##name##_SIZE) - 1)) << SPI_##name##_OFFSET)
  203. #define SPI_BFEXT(name, value) \
  204. (((value) >> SPI_##name##_OFFSET) & ((1 << SPI_##name##_SIZE) - 1))
  205. #define SPI_BFINS(name, value, old) \
  206. (((old) & ~(((1 << SPI_##name##_SIZE) - 1) << SPI_##name##_OFFSET)) \
  207. | SPI_BF(name, value))
  208. /* Register access macros */
  209. #ifdef CONFIG_AVR32
  210. #define spi_readl(port, reg) \
  211. __raw_readl((port)->regs + SPI_##reg)
  212. #define spi_writel(port, reg, value) \
  213. __raw_writel((value), (port)->regs + SPI_##reg)
  214. #define spi_readw(port, reg) \
  215. __raw_readw((port)->regs + SPI_##reg)
  216. #define spi_writew(port, reg, value) \
  217. __raw_writew((value), (port)->regs + SPI_##reg)
  218. #define spi_readb(port, reg) \
  219. __raw_readb((port)->regs + SPI_##reg)
  220. #define spi_writeb(port, reg, value) \
  221. __raw_writeb((value), (port)->regs + SPI_##reg)
  222. #else
  223. #define spi_readl(port, reg) \
  224. readl_relaxed((port)->regs + SPI_##reg)
  225. #define spi_writel(port, reg, value) \
  226. writel_relaxed((value), (port)->regs + SPI_##reg)
  227. #define spi_readw(port, reg) \
  228. readw_relaxed((port)->regs + SPI_##reg)
  229. #define spi_writew(port, reg, value) \
  230. writew_relaxed((value), (port)->regs + SPI_##reg)
  231. #define spi_readb(port, reg) \
  232. readb_relaxed((port)->regs + SPI_##reg)
  233. #define spi_writeb(port, reg, value) \
  234. writeb_relaxed((value), (port)->regs + SPI_##reg)
  235. #endif
  236. /* use PIO for small transfers, avoiding DMA setup/teardown overhead and
  237. * cache operations; better heuristics consider wordsize and bitrate.
  238. */
  239. #define DMA_MIN_BYTES 16
  240. #define SPI_DMA_TIMEOUT (msecs_to_jiffies(1000))
  241. #define AUTOSUSPEND_TIMEOUT 2000
  242. struct atmel_spi_caps {
  243. bool is_spi2;
  244. bool has_wdrbt;
  245. bool has_dma_support;
  246. bool has_pdc_support;
  247. };
  248. /*
  249. * The core SPI transfer engine just talks to a register bank to set up
  250. * DMA transfers; transfer queue progress is driven by IRQs. The clock
  251. * framework provides the base clock, subdivided for each spi_device.
  252. */
  253. struct atmel_spi {
  254. spinlock_t lock;
  255. unsigned long flags;
  256. phys_addr_t phybase;
  257. void __iomem *regs;
  258. int irq;
  259. struct clk *clk;
  260. struct platform_device *pdev;
  261. unsigned long spi_clk;
  262. struct spi_transfer *current_transfer;
  263. int current_remaining_bytes;
  264. int done_status;
  265. struct completion xfer_completion;
  266. struct atmel_spi_caps caps;
  267. bool use_dma;
  268. bool use_pdc;
  269. bool use_cs_gpios;
  270. bool keep_cs;
  271. bool cs_active;
  272. u32 fifo_size;
  273. };
  274. /* Controller-specific per-slave state */
  275. struct atmel_spi_device {
  276. unsigned int npcs_pin;
  277. u32 csr;
  278. };
  279. #define SPI_MAX_DMA_XFER 65535 /* true for both PDC and DMA */
  280. #define INVALID_DMA_ADDRESS 0xffffffff
  281. /*
  282. * Version 2 of the SPI controller has
  283. * - CR.LASTXFER
  284. * - SPI_MR.DIV32 may become FDIV or must-be-zero (here: always zero)
  285. * - SPI_SR.TXEMPTY, SPI_SR.NSSR (and corresponding irqs)
  286. * - SPI_CSRx.CSAAT
  287. * - SPI_CSRx.SBCR allows faster clocking
  288. */
  289. static bool atmel_spi_is_v2(struct atmel_spi *as)
  290. {
  291. return as->caps.is_spi2;
  292. }
  293. /*
  294. * Earlier SPI controllers (e.g. on at91rm9200) have a design bug whereby
  295. * they assume that spi slave device state will not change on deselect, so
  296. * that automagic deselection is OK. ("NPCSx rises if no data is to be
  297. * transmitted") Not so! Workaround uses nCSx pins as GPIOs; or newer
  298. * controllers have CSAAT and friends.
  299. *
  300. * Since the CSAAT functionality is a bit weird on newer controllers as
  301. * well, we use GPIO to control nCSx pins on all controllers, updating
  302. * MR.PCS to avoid confusing the controller. Using GPIOs also lets us
  303. * support active-high chipselects despite the controller's belief that
  304. * only active-low devices/systems exists.
  305. *
  306. * However, at91rm9200 has a second erratum whereby nCS0 doesn't work
  307. * right when driven with GPIO. ("Mode Fault does not allow more than one
  308. * Master on Chip Select 0.") No workaround exists for that ... so for
  309. * nCS0 on that chip, we (a) don't use the GPIO, (b) can't support CS_HIGH,
  310. * and (c) will trigger that first erratum in some cases.
  311. */
  312. static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
  313. {
  314. struct atmel_spi_device *asd = spi->controller_state;
  315. unsigned active = spi->mode & SPI_CS_HIGH;
  316. u32 mr;
  317. if (atmel_spi_is_v2(as)) {
  318. spi_writel(as, CSR0 + 4 * spi->chip_select, asd->csr);
  319. /* For the low SPI version, there is a issue that PDC transfer
  320. * on CS1,2,3 needs SPI_CSR0.BITS config as SPI_CSR1,2,3.BITS
  321. */
  322. spi_writel(as, CSR0, asd->csr);
  323. if (as->caps.has_wdrbt) {
  324. spi_writel(as, MR,
  325. SPI_BF(PCS, ~(0x01 << spi->chip_select))
  326. | SPI_BIT(WDRBT)
  327. | SPI_BIT(MODFDIS)
  328. | SPI_BIT(MSTR));
  329. } else {
  330. spi_writel(as, MR,
  331. SPI_BF(PCS, ~(0x01 << spi->chip_select))
  332. | SPI_BIT(MODFDIS)
  333. | SPI_BIT(MSTR));
  334. }
  335. mr = spi_readl(as, MR);
  336. if (as->use_cs_gpios)
  337. gpio_set_value(asd->npcs_pin, active);
  338. } else {
  339. u32 cpol = (spi->mode & SPI_CPOL) ? SPI_BIT(CPOL) : 0;
  340. int i;
  341. u32 csr;
  342. /* Make sure clock polarity is correct */
  343. for (i = 0; i < spi->master->num_chipselect; i++) {
  344. csr = spi_readl(as, CSR0 + 4 * i);
  345. if ((csr ^ cpol) & SPI_BIT(CPOL))
  346. spi_writel(as, CSR0 + 4 * i,
  347. csr ^ SPI_BIT(CPOL));
  348. }
  349. mr = spi_readl(as, MR);
  350. mr = SPI_BFINS(PCS, ~(1 << spi->chip_select), mr);
  351. if (as->use_cs_gpios && spi->chip_select != 0)
  352. gpio_set_value(asd->npcs_pin, active);
  353. spi_writel(as, MR, mr);
  354. }
  355. dev_dbg(&spi->dev, "activate %u%s, mr %08x\n",
  356. asd->npcs_pin, active ? " (high)" : "",
  357. mr);
  358. }
  359. static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi)
  360. {
  361. struct atmel_spi_device *asd = spi->controller_state;
  362. unsigned active = spi->mode & SPI_CS_HIGH;
  363. u32 mr;
  364. /* only deactivate *this* device; sometimes transfers to
  365. * another device may be active when this routine is called.
  366. */
  367. mr = spi_readl(as, MR);
  368. if (~SPI_BFEXT(PCS, mr) & (1 << spi->chip_select)) {
  369. mr = SPI_BFINS(PCS, 0xf, mr);
  370. spi_writel(as, MR, mr);
  371. }
  372. dev_dbg(&spi->dev, "DEactivate %u%s, mr %08x\n",
  373. asd->npcs_pin, active ? " (low)" : "",
  374. mr);
  375. if (!as->use_cs_gpios)
  376. spi_writel(as, CR, SPI_BIT(LASTXFER));
  377. else if (atmel_spi_is_v2(as) || spi->chip_select != 0)
  378. gpio_set_value(asd->npcs_pin, !active);
  379. }
  380. static void atmel_spi_lock(struct atmel_spi *as) __acquires(&as->lock)
  381. {
  382. spin_lock_irqsave(&as->lock, as->flags);
  383. }
  384. static void atmel_spi_unlock(struct atmel_spi *as) __releases(&as->lock)
  385. {
  386. spin_unlock_irqrestore(&as->lock, as->flags);
  387. }
  388. static inline bool atmel_spi_use_dma(struct atmel_spi *as,
  389. struct spi_transfer *xfer)
  390. {
  391. return as->use_dma && xfer->len >= DMA_MIN_BYTES;
  392. }
  393. static bool atmel_spi_can_dma(struct spi_master *master,
  394. struct spi_device *spi,
  395. struct spi_transfer *xfer)
  396. {
  397. struct atmel_spi *as = spi_master_get_devdata(master);
  398. return atmel_spi_use_dma(as, xfer);
  399. }
  400. static int atmel_spi_dma_slave_config(struct atmel_spi *as,
  401. struct dma_slave_config *slave_config,
  402. u8 bits_per_word)
  403. {
  404. struct spi_master *master = platform_get_drvdata(as->pdev);
  405. int err = 0;
  406. if (bits_per_word > 8) {
  407. slave_config->dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
  408. slave_config->src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
  409. } else {
  410. slave_config->dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
  411. slave_config->src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
  412. }
  413. slave_config->dst_addr = (dma_addr_t)as->phybase + SPI_TDR;
  414. slave_config->src_addr = (dma_addr_t)as->phybase + SPI_RDR;
  415. slave_config->src_maxburst = 1;
  416. slave_config->dst_maxburst = 1;
  417. slave_config->device_fc = false;
  418. /*
  419. * This driver uses fixed peripheral select mode (PS bit set to '0' in
  420. * the Mode Register).
  421. * So according to the datasheet, when FIFOs are available (and
  422. * enabled), the Transmit FIFO operates in Multiple Data Mode.
  423. * In this mode, up to 2 data, not 4, can be written into the Transmit
  424. * Data Register in a single access.
  425. * However, the first data has to be written into the lowest 16 bits and
  426. * the second data into the highest 16 bits of the Transmit
  427. * Data Register. For 8bit data (the most frequent case), it would
  428. * require to rework tx_buf so each data would actualy fit 16 bits.
  429. * So we'd rather write only one data at the time. Hence the transmit
  430. * path works the same whether FIFOs are available (and enabled) or not.
  431. */
  432. slave_config->direction = DMA_MEM_TO_DEV;
  433. if (dmaengine_slave_config(master->dma_tx, slave_config)) {
  434. dev_err(&as->pdev->dev,
  435. "failed to configure tx dma channel\n");
  436. err = -EINVAL;
  437. }
  438. /*
  439. * This driver configures the spi controller for master mode (MSTR bit
  440. * set to '1' in the Mode Register).
  441. * So according to the datasheet, when FIFOs are available (and
  442. * enabled), the Receive FIFO operates in Single Data Mode.
  443. * So the receive path works the same whether FIFOs are available (and
  444. * enabled) or not.
  445. */
  446. slave_config->direction = DMA_DEV_TO_MEM;
  447. if (dmaengine_slave_config(master->dma_rx, slave_config)) {
  448. dev_err(&as->pdev->dev,
  449. "failed to configure rx dma channel\n");
  450. err = -EINVAL;
  451. }
  452. return err;
  453. }
  454. static int atmel_spi_configure_dma(struct spi_master *master,
  455. struct atmel_spi *as)
  456. {
  457. struct dma_slave_config slave_config;
  458. struct device *dev = &as->pdev->dev;
  459. int err;
  460. dma_cap_mask_t mask;
  461. dma_cap_zero(mask);
  462. dma_cap_set(DMA_SLAVE, mask);
  463. master->dma_tx = dma_request_slave_channel_reason(dev, "tx");
  464. if (IS_ERR(master->dma_tx)) {
  465. err = PTR_ERR(master->dma_tx);
  466. if (err == -EPROBE_DEFER) {
  467. dev_warn(dev, "no DMA channel available at the moment\n");
  468. goto error_clear;
  469. }
  470. dev_err(dev,
  471. "DMA TX channel not available, SPI unable to use DMA\n");
  472. err = -EBUSY;
  473. goto error_clear;
  474. }
  475. /*
  476. * No reason to check EPROBE_DEFER here since we have already requested
  477. * tx channel. If it fails here, it's for another reason.
  478. */
  479. master->dma_rx = dma_request_slave_channel(dev, "rx");
  480. if (!master->dma_rx) {
  481. dev_err(dev,
  482. "DMA RX channel not available, SPI unable to use DMA\n");
  483. err = -EBUSY;
  484. goto error;
  485. }
  486. err = atmel_spi_dma_slave_config(as, &slave_config, 8);
  487. if (err)
  488. goto error;
  489. dev_info(&as->pdev->dev,
  490. "Using %s (tx) and %s (rx) for DMA transfers\n",
  491. dma_chan_name(master->dma_tx),
  492. dma_chan_name(master->dma_rx));
  493. return 0;
  494. error:
  495. if (master->dma_rx)
  496. dma_release_channel(master->dma_rx);
  497. if (!IS_ERR(master->dma_tx))
  498. dma_release_channel(master->dma_tx);
  499. error_clear:
  500. master->dma_tx = master->dma_rx = NULL;
  501. return err;
  502. }
  503. static void atmel_spi_stop_dma(struct spi_master *master)
  504. {
  505. if (master->dma_rx)
  506. dmaengine_terminate_all(master->dma_rx);
  507. if (master->dma_tx)
  508. dmaengine_terminate_all(master->dma_tx);
  509. }
  510. static void atmel_spi_release_dma(struct spi_master *master)
  511. {
  512. if (master->dma_rx) {
  513. dma_release_channel(master->dma_rx);
  514. master->dma_rx = NULL;
  515. }
  516. if (master->dma_tx) {
  517. dma_release_channel(master->dma_tx);
  518. master->dma_tx = NULL;
  519. }
  520. }
  521. /* This function is called by the DMA driver from tasklet context */
  522. static void dma_callback(void *data)
  523. {
  524. struct spi_master *master = data;
  525. struct atmel_spi *as = spi_master_get_devdata(master);
  526. complete(&as->xfer_completion);
  527. }
  528. /*
  529. * Next transfer using PIO without FIFO.
  530. */
  531. static void atmel_spi_next_xfer_single(struct spi_master *master,
  532. struct spi_transfer *xfer)
  533. {
  534. struct atmel_spi *as = spi_master_get_devdata(master);
  535. unsigned long xfer_pos = xfer->len - as->current_remaining_bytes;
  536. dev_vdbg(master->dev.parent, "atmel_spi_next_xfer_pio\n");
  537. /* Make sure data is not remaining in RDR */
  538. spi_readl(as, RDR);
  539. while (spi_readl(as, SR) & SPI_BIT(RDRF)) {
  540. spi_readl(as, RDR);
  541. cpu_relax();
  542. }
  543. if (xfer->bits_per_word > 8)
  544. spi_writel(as, TDR, *(u16 *)(xfer->tx_buf + xfer_pos));
  545. else
  546. spi_writel(as, TDR, *(u8 *)(xfer->tx_buf + xfer_pos));
  547. dev_dbg(master->dev.parent,
  548. " start pio xfer %p: len %u tx %p rx %p bitpw %d\n",
  549. xfer, xfer->len, xfer->tx_buf, xfer->rx_buf,
  550. xfer->bits_per_word);
  551. /* Enable relevant interrupts */
  552. spi_writel(as, IER, SPI_BIT(RDRF) | SPI_BIT(OVRES));
  553. }
  554. /*
  555. * Next transfer using PIO with FIFO.
  556. */
  557. static void atmel_spi_next_xfer_fifo(struct spi_master *master,
  558. struct spi_transfer *xfer)
  559. {
  560. struct atmel_spi *as = spi_master_get_devdata(master);
  561. u32 current_remaining_data, num_data;
  562. u32 offset = xfer->len - as->current_remaining_bytes;
  563. const u16 *words = (const u16 *)((u8 *)xfer->tx_buf + offset);
  564. const u8 *bytes = (const u8 *)((u8 *)xfer->tx_buf + offset);
  565. u16 td0, td1;
  566. u32 fifomr;
  567. dev_vdbg(master->dev.parent, "atmel_spi_next_xfer_fifo\n");
  568. /* Compute the number of data to transfer in the current iteration */
  569. current_remaining_data = ((xfer->bits_per_word > 8) ?
  570. ((u32)as->current_remaining_bytes >> 1) :
  571. (u32)as->current_remaining_bytes);
  572. num_data = min(current_remaining_data, as->fifo_size);
  573. /* Flush RX and TX FIFOs */
  574. spi_writel(as, CR, SPI_BIT(RXFCLR) | SPI_BIT(TXFCLR));
  575. while (spi_readl(as, FLR))
  576. cpu_relax();
  577. /* Set RX FIFO Threshold to the number of data to transfer */
  578. fifomr = spi_readl(as, FMR);
  579. spi_writel(as, FMR, SPI_BFINS(RXFTHRES, num_data, fifomr));
  580. /* Clear FIFO flags in the Status Register, especially RXFTHF */
  581. (void)spi_readl(as, SR);
  582. /* Fill TX FIFO */
  583. while (num_data >= 2) {
  584. if (xfer->bits_per_word > 8) {
  585. td0 = *words++;
  586. td1 = *words++;
  587. } else {
  588. td0 = *bytes++;
  589. td1 = *bytes++;
  590. }
  591. spi_writel(as, TDR, (td1 << 16) | td0);
  592. num_data -= 2;
  593. }
  594. if (num_data) {
  595. if (xfer->bits_per_word > 8)
  596. td0 = *words++;
  597. else
  598. td0 = *bytes++;
  599. spi_writew(as, TDR, td0);
  600. num_data--;
  601. }
  602. dev_dbg(master->dev.parent,
  603. " start fifo xfer %p: len %u tx %p rx %p bitpw %d\n",
  604. xfer, xfer->len, xfer->tx_buf, xfer->rx_buf,
  605. xfer->bits_per_word);
  606. /*
  607. * Enable RX FIFO Threshold Flag interrupt to be notified about
  608. * transfer completion.
  609. */
  610. spi_writel(as, IER, SPI_BIT(RXFTHF) | SPI_BIT(OVRES));
  611. }
  612. /*
  613. * Next transfer using PIO.
  614. */
  615. static void atmel_spi_next_xfer_pio(struct spi_master *master,
  616. struct spi_transfer *xfer)
  617. {
  618. struct atmel_spi *as = spi_master_get_devdata(master);
  619. if (as->fifo_size)
  620. atmel_spi_next_xfer_fifo(master, xfer);
  621. else
  622. atmel_spi_next_xfer_single(master, xfer);
  623. }
  624. /*
  625. * Submit next transfer for DMA.
  626. */
  627. static int atmel_spi_next_xfer_dma_submit(struct spi_master *master,
  628. struct spi_transfer *xfer,
  629. u32 *plen)
  630. {
  631. struct atmel_spi *as = spi_master_get_devdata(master);
  632. struct dma_chan *rxchan = master->dma_rx;
  633. struct dma_chan *txchan = master->dma_tx;
  634. struct dma_async_tx_descriptor *rxdesc;
  635. struct dma_async_tx_descriptor *txdesc;
  636. struct dma_slave_config slave_config;
  637. dma_cookie_t cookie;
  638. dev_vdbg(master->dev.parent, "atmel_spi_next_xfer_dma_submit\n");
  639. /* Check that the channels are available */
  640. if (!rxchan || !txchan)
  641. return -ENODEV;
  642. /* release lock for DMA operations */
  643. atmel_spi_unlock(as);
  644. *plen = xfer->len;
  645. if (atmel_spi_dma_slave_config(as, &slave_config,
  646. xfer->bits_per_word))
  647. goto err_exit;
  648. /* Send both scatterlists */
  649. rxdesc = dmaengine_prep_slave_sg(rxchan,
  650. xfer->rx_sg.sgl, xfer->rx_sg.nents,
  651. DMA_FROM_DEVICE,
  652. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  653. if (!rxdesc)
  654. goto err_dma;
  655. txdesc = dmaengine_prep_slave_sg(txchan,
  656. xfer->tx_sg.sgl, xfer->tx_sg.nents,
  657. DMA_TO_DEVICE,
  658. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  659. if (!txdesc)
  660. goto err_dma;
  661. dev_dbg(master->dev.parent,
  662. " start dma xfer %p: len %u tx %p/%08llx rx %p/%08llx\n",
  663. xfer, xfer->len, xfer->tx_buf, (unsigned long long)xfer->tx_dma,
  664. xfer->rx_buf, (unsigned long long)xfer->rx_dma);
  665. /* Enable relevant interrupts */
  666. spi_writel(as, IER, SPI_BIT(OVRES));
  667. /* Put the callback on the RX transfer only, that should finish last */
  668. rxdesc->callback = dma_callback;
  669. rxdesc->callback_param = master;
  670. /* Submit and fire RX and TX with TX last so we're ready to read! */
  671. cookie = rxdesc->tx_submit(rxdesc);
  672. if (dma_submit_error(cookie))
  673. goto err_dma;
  674. cookie = txdesc->tx_submit(txdesc);
  675. if (dma_submit_error(cookie))
  676. goto err_dma;
  677. rxchan->device->device_issue_pending(rxchan);
  678. txchan->device->device_issue_pending(txchan);
  679. /* take back lock */
  680. atmel_spi_lock(as);
  681. return 0;
  682. err_dma:
  683. spi_writel(as, IDR, SPI_BIT(OVRES));
  684. atmel_spi_stop_dma(master);
  685. err_exit:
  686. atmel_spi_lock(as);
  687. return -ENOMEM;
  688. }
  689. static void atmel_spi_next_xfer_data(struct spi_master *master,
  690. struct spi_transfer *xfer,
  691. dma_addr_t *tx_dma,
  692. dma_addr_t *rx_dma,
  693. u32 *plen)
  694. {
  695. *rx_dma = xfer->rx_dma + xfer->len - *plen;
  696. *tx_dma = xfer->tx_dma + xfer->len - *plen;
  697. if (*plen > master->max_dma_len)
  698. *plen = master->max_dma_len;
  699. }
  700. static int atmel_spi_set_xfer_speed(struct atmel_spi *as,
  701. struct spi_device *spi,
  702. struct spi_transfer *xfer)
  703. {
  704. u32 scbr, csr;
  705. unsigned long bus_hz;
  706. /* v1 chips start out at half the peripheral bus speed. */
  707. bus_hz = as->spi_clk;
  708. if (!atmel_spi_is_v2(as))
  709. bus_hz /= 2;
  710. /*
  711. * Calculate the lowest divider that satisfies the
  712. * constraint, assuming div32/fdiv/mbz == 0.
  713. */
  714. scbr = DIV_ROUND_UP(bus_hz, xfer->speed_hz);
  715. /*
  716. * If the resulting divider doesn't fit into the
  717. * register bitfield, we can't satisfy the constraint.
  718. */
  719. if (scbr >= (1 << SPI_SCBR_SIZE)) {
  720. dev_err(&spi->dev,
  721. "setup: %d Hz too slow, scbr %u; min %ld Hz\n",
  722. xfer->speed_hz, scbr, bus_hz/255);
  723. return -EINVAL;
  724. }
  725. if (scbr == 0) {
  726. dev_err(&spi->dev,
  727. "setup: %d Hz too high, scbr %u; max %ld Hz\n",
  728. xfer->speed_hz, scbr, bus_hz);
  729. return -EINVAL;
  730. }
  731. csr = spi_readl(as, CSR0 + 4 * spi->chip_select);
  732. csr = SPI_BFINS(SCBR, scbr, csr);
  733. spi_writel(as, CSR0 + 4 * spi->chip_select, csr);
  734. return 0;
  735. }
  736. /*
  737. * Submit next transfer for PDC.
  738. * lock is held, spi irq is blocked
  739. */
  740. static void atmel_spi_pdc_next_xfer(struct spi_master *master,
  741. struct spi_message *msg,
  742. struct spi_transfer *xfer)
  743. {
  744. struct atmel_spi *as = spi_master_get_devdata(master);
  745. u32 len;
  746. dma_addr_t tx_dma, rx_dma;
  747. spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
  748. len = as->current_remaining_bytes;
  749. atmel_spi_next_xfer_data(master, xfer, &tx_dma, &rx_dma, &len);
  750. as->current_remaining_bytes -= len;
  751. spi_writel(as, RPR, rx_dma);
  752. spi_writel(as, TPR, tx_dma);
  753. if (msg->spi->bits_per_word > 8)
  754. len >>= 1;
  755. spi_writel(as, RCR, len);
  756. spi_writel(as, TCR, len);
  757. dev_dbg(&msg->spi->dev,
  758. " start xfer %p: len %u tx %p/%08llx rx %p/%08llx\n",
  759. xfer, xfer->len, xfer->tx_buf,
  760. (unsigned long long)xfer->tx_dma, xfer->rx_buf,
  761. (unsigned long long)xfer->rx_dma);
  762. if (as->current_remaining_bytes) {
  763. len = as->current_remaining_bytes;
  764. atmel_spi_next_xfer_data(master, xfer, &tx_dma, &rx_dma, &len);
  765. as->current_remaining_bytes -= len;
  766. spi_writel(as, RNPR, rx_dma);
  767. spi_writel(as, TNPR, tx_dma);
  768. if (msg->spi->bits_per_word > 8)
  769. len >>= 1;
  770. spi_writel(as, RNCR, len);
  771. spi_writel(as, TNCR, len);
  772. dev_dbg(&msg->spi->dev,
  773. " next xfer %p: len %u tx %p/%08llx rx %p/%08llx\n",
  774. xfer, xfer->len, xfer->tx_buf,
  775. (unsigned long long)xfer->tx_dma, xfer->rx_buf,
  776. (unsigned long long)xfer->rx_dma);
  777. }
  778. /* REVISIT: We're waiting for RXBUFF before we start the next
  779. * transfer because we need to handle some difficult timing
  780. * issues otherwise. If we wait for TXBUFE in one transfer and
  781. * then starts waiting for RXBUFF in the next, it's difficult
  782. * to tell the difference between the RXBUFF interrupt we're
  783. * actually waiting for and the RXBUFF interrupt of the
  784. * previous transfer.
  785. *
  786. * It should be doable, though. Just not now...
  787. */
  788. spi_writel(as, IER, SPI_BIT(RXBUFF) | SPI_BIT(OVRES));
  789. spi_writel(as, PTCR, SPI_BIT(TXTEN) | SPI_BIT(RXTEN));
  790. }
  791. /*
  792. * For DMA, tx_buf/tx_dma have the same relationship as rx_buf/rx_dma:
  793. * - The buffer is either valid for CPU access, else NULL
  794. * - If the buffer is valid, so is its DMA address
  795. *
  796. * This driver manages the dma address unless message->is_dma_mapped.
  797. */
  798. static int
  799. atmel_spi_dma_map_xfer(struct atmel_spi *as, struct spi_transfer *xfer)
  800. {
  801. struct device *dev = &as->pdev->dev;
  802. xfer->tx_dma = xfer->rx_dma = INVALID_DMA_ADDRESS;
  803. if (xfer->tx_buf) {
  804. /* tx_buf is a const void* where we need a void * for the dma
  805. * mapping */
  806. void *nonconst_tx = (void *)xfer->tx_buf;
  807. xfer->tx_dma = dma_map_single(dev,
  808. nonconst_tx, xfer->len,
  809. DMA_TO_DEVICE);
  810. if (dma_mapping_error(dev, xfer->tx_dma))
  811. return -ENOMEM;
  812. }
  813. if (xfer->rx_buf) {
  814. xfer->rx_dma = dma_map_single(dev,
  815. xfer->rx_buf, xfer->len,
  816. DMA_FROM_DEVICE);
  817. if (dma_mapping_error(dev, xfer->rx_dma)) {
  818. if (xfer->tx_buf)
  819. dma_unmap_single(dev,
  820. xfer->tx_dma, xfer->len,
  821. DMA_TO_DEVICE);
  822. return -ENOMEM;
  823. }
  824. }
  825. return 0;
  826. }
  827. static void atmel_spi_dma_unmap_xfer(struct spi_master *master,
  828. struct spi_transfer *xfer)
  829. {
  830. if (xfer->tx_dma != INVALID_DMA_ADDRESS)
  831. dma_unmap_single(master->dev.parent, xfer->tx_dma,
  832. xfer->len, DMA_TO_DEVICE);
  833. if (xfer->rx_dma != INVALID_DMA_ADDRESS)
  834. dma_unmap_single(master->dev.parent, xfer->rx_dma,
  835. xfer->len, DMA_FROM_DEVICE);
  836. }
  837. static void atmel_spi_disable_pdc_transfer(struct atmel_spi *as)
  838. {
  839. spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
  840. }
  841. static void
  842. atmel_spi_pump_single_data(struct atmel_spi *as, struct spi_transfer *xfer)
  843. {
  844. u8 *rxp;
  845. u16 *rxp16;
  846. unsigned long xfer_pos = xfer->len - as->current_remaining_bytes;
  847. if (xfer->bits_per_word > 8) {
  848. rxp16 = (u16 *)(((u8 *)xfer->rx_buf) + xfer_pos);
  849. *rxp16 = spi_readl(as, RDR);
  850. } else {
  851. rxp = ((u8 *)xfer->rx_buf) + xfer_pos;
  852. *rxp = spi_readl(as, RDR);
  853. }
  854. if (xfer->bits_per_word > 8) {
  855. if (as->current_remaining_bytes > 2)
  856. as->current_remaining_bytes -= 2;
  857. else
  858. as->current_remaining_bytes = 0;
  859. } else {
  860. as->current_remaining_bytes--;
  861. }
  862. }
  863. static void
  864. atmel_spi_pump_fifo_data(struct atmel_spi *as, struct spi_transfer *xfer)
  865. {
  866. u32 fifolr = spi_readl(as, FLR);
  867. u32 num_bytes, num_data = SPI_BFEXT(RXFL, fifolr);
  868. u32 offset = xfer->len - as->current_remaining_bytes;
  869. u16 *words = (u16 *)((u8 *)xfer->rx_buf + offset);
  870. u8 *bytes = (u8 *)((u8 *)xfer->rx_buf + offset);
  871. u16 rd; /* RD field is the lowest 16 bits of RDR */
  872. /* Update the number of remaining bytes to transfer */
  873. num_bytes = ((xfer->bits_per_word > 8) ?
  874. (num_data << 1) :
  875. num_data);
  876. if (as->current_remaining_bytes > num_bytes)
  877. as->current_remaining_bytes -= num_bytes;
  878. else
  879. as->current_remaining_bytes = 0;
  880. /* Handle odd number of bytes when data are more than 8bit width */
  881. if (xfer->bits_per_word > 8)
  882. as->current_remaining_bytes &= ~0x1;
  883. /* Read data */
  884. while (num_data) {
  885. rd = spi_readl(as, RDR);
  886. if (xfer->bits_per_word > 8)
  887. *words++ = rd;
  888. else
  889. *bytes++ = rd;
  890. num_data--;
  891. }
  892. }
  893. /* Called from IRQ
  894. *
  895. * Must update "current_remaining_bytes" to keep track of data
  896. * to transfer.
  897. */
  898. static void
  899. atmel_spi_pump_pio_data(struct atmel_spi *as, struct spi_transfer *xfer)
  900. {
  901. if (as->fifo_size)
  902. atmel_spi_pump_fifo_data(as, xfer);
  903. else
  904. atmel_spi_pump_single_data(as, xfer);
  905. }
  906. /* Interrupt
  907. *
  908. * No need for locking in this Interrupt handler: done_status is the
  909. * only information modified.
  910. */
  911. static irqreturn_t
  912. atmel_spi_pio_interrupt(int irq, void *dev_id)
  913. {
  914. struct spi_master *master = dev_id;
  915. struct atmel_spi *as = spi_master_get_devdata(master);
  916. u32 status, pending, imr;
  917. struct spi_transfer *xfer;
  918. int ret = IRQ_NONE;
  919. imr = spi_readl(as, IMR);
  920. status = spi_readl(as, SR);
  921. pending = status & imr;
  922. if (pending & SPI_BIT(OVRES)) {
  923. ret = IRQ_HANDLED;
  924. spi_writel(as, IDR, SPI_BIT(OVRES));
  925. dev_warn(master->dev.parent, "overrun\n");
  926. /*
  927. * When we get an overrun, we disregard the current
  928. * transfer. Data will not be copied back from any
  929. * bounce buffer and msg->actual_len will not be
  930. * updated with the last xfer.
  931. *
  932. * We will also not process any remaning transfers in
  933. * the message.
  934. */
  935. as->done_status = -EIO;
  936. smp_wmb();
  937. /* Clear any overrun happening while cleaning up */
  938. spi_readl(as, SR);
  939. complete(&as->xfer_completion);
  940. } else if (pending & (SPI_BIT(RDRF) | SPI_BIT(RXFTHF))) {
  941. atmel_spi_lock(as);
  942. if (as->current_remaining_bytes) {
  943. ret = IRQ_HANDLED;
  944. xfer = as->current_transfer;
  945. atmel_spi_pump_pio_data(as, xfer);
  946. if (!as->current_remaining_bytes)
  947. spi_writel(as, IDR, pending);
  948. complete(&as->xfer_completion);
  949. }
  950. atmel_spi_unlock(as);
  951. } else {
  952. WARN_ONCE(pending, "IRQ not handled, pending = %x\n", pending);
  953. ret = IRQ_HANDLED;
  954. spi_writel(as, IDR, pending);
  955. }
  956. return ret;
  957. }
  958. static irqreturn_t
  959. atmel_spi_pdc_interrupt(int irq, void *dev_id)
  960. {
  961. struct spi_master *master = dev_id;
  962. struct atmel_spi *as = spi_master_get_devdata(master);
  963. u32 status, pending, imr;
  964. int ret = IRQ_NONE;
  965. imr = spi_readl(as, IMR);
  966. status = spi_readl(as, SR);
  967. pending = status & imr;
  968. if (pending & SPI_BIT(OVRES)) {
  969. ret = IRQ_HANDLED;
  970. spi_writel(as, IDR, (SPI_BIT(RXBUFF) | SPI_BIT(ENDRX)
  971. | SPI_BIT(OVRES)));
  972. /* Clear any overrun happening while cleaning up */
  973. spi_readl(as, SR);
  974. as->done_status = -EIO;
  975. complete(&as->xfer_completion);
  976. } else if (pending & (SPI_BIT(RXBUFF) | SPI_BIT(ENDRX))) {
  977. ret = IRQ_HANDLED;
  978. spi_writel(as, IDR, pending);
  979. complete(&as->xfer_completion);
  980. }
  981. return ret;
  982. }
  983. static int atmel_spi_setup(struct spi_device *spi)
  984. {
  985. struct atmel_spi *as;
  986. struct atmel_spi_device *asd;
  987. u32 csr;
  988. unsigned int bits = spi->bits_per_word;
  989. unsigned int npcs_pin;
  990. as = spi_master_get_devdata(spi->master);
  991. /* see notes above re chipselect */
  992. if (!atmel_spi_is_v2(as)
  993. && spi->chip_select == 0
  994. && (spi->mode & SPI_CS_HIGH)) {
  995. dev_dbg(&spi->dev, "setup: can't be active-high\n");
  996. return -EINVAL;
  997. }
  998. csr = SPI_BF(BITS, bits - 8);
  999. if (spi->mode & SPI_CPOL)
  1000. csr |= SPI_BIT(CPOL);
  1001. if (!(spi->mode & SPI_CPHA))
  1002. csr |= SPI_BIT(NCPHA);
  1003. if (!as->use_cs_gpios)
  1004. csr |= SPI_BIT(CSAAT);
  1005. /* DLYBS is mostly irrelevant since we manage chipselect using GPIOs.
  1006. *
  1007. * DLYBCT would add delays between words, slowing down transfers.
  1008. * It could potentially be useful to cope with DMA bottlenecks, but
  1009. * in those cases it's probably best to just use a lower bitrate.
  1010. */
  1011. csr |= SPI_BF(DLYBS, 0);
  1012. csr |= SPI_BF(DLYBCT, 0);
  1013. /* chipselect must have been muxed as GPIO (e.g. in board setup) */
  1014. npcs_pin = (unsigned long)spi->controller_data;
  1015. if (!as->use_cs_gpios)
  1016. npcs_pin = spi->chip_select;
  1017. else if (gpio_is_valid(spi->cs_gpio))
  1018. npcs_pin = spi->cs_gpio;
  1019. asd = spi->controller_state;
  1020. if (!asd) {
  1021. asd = kzalloc(sizeof(struct atmel_spi_device), GFP_KERNEL);
  1022. if (!asd)
  1023. return -ENOMEM;
  1024. if (as->use_cs_gpios)
  1025. gpio_direction_output(npcs_pin,
  1026. !(spi->mode & SPI_CS_HIGH));
  1027. asd->npcs_pin = npcs_pin;
  1028. spi->controller_state = asd;
  1029. }
  1030. asd->csr = csr;
  1031. dev_dbg(&spi->dev,
  1032. "setup: bpw %u mode 0x%x -> csr%d %08x\n",
  1033. bits, spi->mode, spi->chip_select, csr);
  1034. if (!atmel_spi_is_v2(as))
  1035. spi_writel(as, CSR0 + 4 * spi->chip_select, csr);
  1036. return 0;
  1037. }
  1038. static int atmel_spi_one_transfer(struct spi_master *master,
  1039. struct spi_message *msg,
  1040. struct spi_transfer *xfer)
  1041. {
  1042. struct atmel_spi *as;
  1043. struct spi_device *spi = msg->spi;
  1044. u8 bits;
  1045. u32 len;
  1046. struct atmel_spi_device *asd;
  1047. int timeout;
  1048. int ret;
  1049. unsigned long dma_timeout;
  1050. as = spi_master_get_devdata(master);
  1051. if (!(xfer->tx_buf || xfer->rx_buf) && xfer->len) {
  1052. dev_dbg(&spi->dev, "missing rx or tx buf\n");
  1053. return -EINVAL;
  1054. }
  1055. asd = spi->controller_state;
  1056. bits = (asd->csr >> 4) & 0xf;
  1057. if (bits != xfer->bits_per_word - 8) {
  1058. dev_dbg(&spi->dev,
  1059. "you can't yet change bits_per_word in transfers\n");
  1060. return -ENOPROTOOPT;
  1061. }
  1062. /*
  1063. * DMA map early, for performance (empties dcache ASAP) and
  1064. * better fault reporting.
  1065. */
  1066. if ((!msg->is_dma_mapped)
  1067. && as->use_pdc) {
  1068. if (atmel_spi_dma_map_xfer(as, xfer) < 0)
  1069. return -ENOMEM;
  1070. }
  1071. atmel_spi_set_xfer_speed(as, msg->spi, xfer);
  1072. as->done_status = 0;
  1073. as->current_transfer = xfer;
  1074. as->current_remaining_bytes = xfer->len;
  1075. while (as->current_remaining_bytes) {
  1076. reinit_completion(&as->xfer_completion);
  1077. if (as->use_pdc) {
  1078. atmel_spi_pdc_next_xfer(master, msg, xfer);
  1079. } else if (atmel_spi_use_dma(as, xfer)) {
  1080. len = as->current_remaining_bytes;
  1081. ret = atmel_spi_next_xfer_dma_submit(master,
  1082. xfer, &len);
  1083. if (ret) {
  1084. dev_err(&spi->dev,
  1085. "unable to use DMA, fallback to PIO\n");
  1086. atmel_spi_next_xfer_pio(master, xfer);
  1087. } else {
  1088. as->current_remaining_bytes -= len;
  1089. if (as->current_remaining_bytes < 0)
  1090. as->current_remaining_bytes = 0;
  1091. }
  1092. } else {
  1093. atmel_spi_next_xfer_pio(master, xfer);
  1094. }
  1095. /* interrupts are disabled, so free the lock for schedule */
  1096. atmel_spi_unlock(as);
  1097. dma_timeout = wait_for_completion_timeout(&as->xfer_completion,
  1098. SPI_DMA_TIMEOUT);
  1099. atmel_spi_lock(as);
  1100. if (WARN_ON(dma_timeout == 0)) {
  1101. dev_err(&spi->dev, "spi transfer timeout\n");
  1102. as->done_status = -EIO;
  1103. }
  1104. if (as->done_status)
  1105. break;
  1106. }
  1107. if (as->done_status) {
  1108. if (as->use_pdc) {
  1109. dev_warn(master->dev.parent,
  1110. "overrun (%u/%u remaining)\n",
  1111. spi_readl(as, TCR), spi_readl(as, RCR));
  1112. /*
  1113. * Clean up DMA registers and make sure the data
  1114. * registers are empty.
  1115. */
  1116. spi_writel(as, RNCR, 0);
  1117. spi_writel(as, TNCR, 0);
  1118. spi_writel(as, RCR, 0);
  1119. spi_writel(as, TCR, 0);
  1120. for (timeout = 1000; timeout; timeout--)
  1121. if (spi_readl(as, SR) & SPI_BIT(TXEMPTY))
  1122. break;
  1123. if (!timeout)
  1124. dev_warn(master->dev.parent,
  1125. "timeout waiting for TXEMPTY");
  1126. while (spi_readl(as, SR) & SPI_BIT(RDRF))
  1127. spi_readl(as, RDR);
  1128. /* Clear any overrun happening while cleaning up */
  1129. spi_readl(as, SR);
  1130. } else if (atmel_spi_use_dma(as, xfer)) {
  1131. atmel_spi_stop_dma(master);
  1132. }
  1133. if (!msg->is_dma_mapped
  1134. && as->use_pdc)
  1135. atmel_spi_dma_unmap_xfer(master, xfer);
  1136. return 0;
  1137. } else {
  1138. /* only update length if no error */
  1139. msg->actual_length += xfer->len;
  1140. }
  1141. if (!msg->is_dma_mapped
  1142. && as->use_pdc)
  1143. atmel_spi_dma_unmap_xfer(master, xfer);
  1144. if (xfer->delay_usecs)
  1145. udelay(xfer->delay_usecs);
  1146. if (xfer->cs_change) {
  1147. if (list_is_last(&xfer->transfer_list,
  1148. &msg->transfers)) {
  1149. as->keep_cs = true;
  1150. } else {
  1151. as->cs_active = !as->cs_active;
  1152. if (as->cs_active)
  1153. cs_activate(as, msg->spi);
  1154. else
  1155. cs_deactivate(as, msg->spi);
  1156. }
  1157. }
  1158. return 0;
  1159. }
  1160. static int atmel_spi_transfer_one_message(struct spi_master *master,
  1161. struct spi_message *msg)
  1162. {
  1163. struct atmel_spi *as;
  1164. struct spi_transfer *xfer;
  1165. struct spi_device *spi = msg->spi;
  1166. int ret = 0;
  1167. as = spi_master_get_devdata(master);
  1168. dev_dbg(&spi->dev, "new message %p submitted for %s\n",
  1169. msg, dev_name(&spi->dev));
  1170. atmel_spi_lock(as);
  1171. cs_activate(as, spi);
  1172. as->cs_active = true;
  1173. as->keep_cs = false;
  1174. msg->status = 0;
  1175. msg->actual_length = 0;
  1176. list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  1177. ret = atmel_spi_one_transfer(master, msg, xfer);
  1178. if (ret)
  1179. goto msg_done;
  1180. }
  1181. if (as->use_pdc)
  1182. atmel_spi_disable_pdc_transfer(as);
  1183. list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  1184. dev_dbg(&spi->dev,
  1185. " xfer %p: len %u tx %p/%pad rx %p/%pad\n",
  1186. xfer, xfer->len,
  1187. xfer->tx_buf, &xfer->tx_dma,
  1188. xfer->rx_buf, &xfer->rx_dma);
  1189. }
  1190. msg_done:
  1191. if (!as->keep_cs)
  1192. cs_deactivate(as, msg->spi);
  1193. atmel_spi_unlock(as);
  1194. msg->status = as->done_status;
  1195. spi_finalize_current_message(spi->master);
  1196. return ret;
  1197. }
  1198. static void atmel_spi_cleanup(struct spi_device *spi)
  1199. {
  1200. struct atmel_spi_device *asd = spi->controller_state;
  1201. if (!asd)
  1202. return;
  1203. spi->controller_state = NULL;
  1204. kfree(asd);
  1205. }
  1206. static inline unsigned int atmel_get_version(struct atmel_spi *as)
  1207. {
  1208. return spi_readl(as, VERSION) & 0x00000fff;
  1209. }
  1210. static void atmel_get_caps(struct atmel_spi *as)
  1211. {
  1212. unsigned int version;
  1213. version = atmel_get_version(as);
  1214. as->caps.is_spi2 = version > 0x121;
  1215. as->caps.has_wdrbt = version >= 0x210;
  1216. #ifdef CONFIG_SOC_SAM_V4_V5
  1217. /*
  1218. * Atmel SoCs based on ARM9 (SAM9x) cores should not use spi_map_buf()
  1219. * since this later function tries to map buffers with dma_map_sg()
  1220. * even if they have not been allocated inside DMA-safe areas.
  1221. * On SoCs based on Cortex A5 (SAMA5Dx), it works anyway because for
  1222. * those ARM cores, the data cache follows the PIPT model.
  1223. * Also the L2 cache controller of SAMA5D2 uses the PIPT model too.
  1224. * In case of PIPT caches, there cannot be cache aliases.
  1225. * However on ARM9 cores, the data cache follows the VIVT model, hence
  1226. * the cache aliases issue can occur when buffers are allocated from
  1227. * DMA-unsafe areas, by vmalloc() for instance, where cache coherency is
  1228. * not taken into account or at least not handled completely (cache
  1229. * lines of aliases are not invalidated).
  1230. * This is not a theorical issue: it was reproduced when trying to mount
  1231. * a UBI file-system on a at91sam9g35ek board.
  1232. */
  1233. as->caps.has_dma_support = false;
  1234. #else
  1235. as->caps.has_dma_support = version >= 0x212;
  1236. #endif
  1237. as->caps.has_pdc_support = version < 0x212;
  1238. }
  1239. /*-------------------------------------------------------------------------*/
  1240. static int atmel_spi_gpio_cs(struct platform_device *pdev)
  1241. {
  1242. struct spi_master *master = platform_get_drvdata(pdev);
  1243. struct atmel_spi *as = spi_master_get_devdata(master);
  1244. struct device_node *np = master->dev.of_node;
  1245. int i;
  1246. int ret = 0;
  1247. int nb = 0;
  1248. if (!as->use_cs_gpios)
  1249. return 0;
  1250. if (!np)
  1251. return 0;
  1252. nb = of_gpio_named_count(np, "cs-gpios");
  1253. for (i = 0; i < nb; i++) {
  1254. int cs_gpio = of_get_named_gpio(pdev->dev.of_node,
  1255. "cs-gpios", i);
  1256. if (cs_gpio == -EPROBE_DEFER)
  1257. return cs_gpio;
  1258. if (gpio_is_valid(cs_gpio)) {
  1259. ret = devm_gpio_request(&pdev->dev, cs_gpio,
  1260. dev_name(&pdev->dev));
  1261. if (ret)
  1262. return ret;
  1263. }
  1264. }
  1265. return 0;
  1266. }
  1267. static void atmel_spi_init(struct atmel_spi *as)
  1268. {
  1269. spi_writel(as, CR, SPI_BIT(SWRST));
  1270. spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
  1271. if (as->caps.has_wdrbt) {
  1272. spi_writel(as, MR, SPI_BIT(WDRBT) | SPI_BIT(MODFDIS)
  1273. | SPI_BIT(MSTR));
  1274. } else {
  1275. spi_writel(as, MR, SPI_BIT(MSTR) | SPI_BIT(MODFDIS));
  1276. }
  1277. if (as->use_pdc)
  1278. spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
  1279. spi_writel(as, CR, SPI_BIT(SPIEN));
  1280. if (as->fifo_size)
  1281. spi_writel(as, CR, SPI_BIT(FIFOEN));
  1282. }
  1283. static int atmel_spi_probe(struct platform_device *pdev)
  1284. {
  1285. struct resource *regs;
  1286. int irq;
  1287. struct clk *clk;
  1288. int ret;
  1289. struct spi_master *master;
  1290. struct atmel_spi *as;
  1291. /* Select default pin state */
  1292. pinctrl_pm_select_default_state(&pdev->dev);
  1293. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1294. if (!regs)
  1295. return -ENXIO;
  1296. irq = platform_get_irq(pdev, 0);
  1297. if (irq < 0)
  1298. return irq;
  1299. clk = devm_clk_get(&pdev->dev, "spi_clk");
  1300. if (IS_ERR(clk))
  1301. return PTR_ERR(clk);
  1302. /* setup spi core then atmel-specific driver state */
  1303. ret = -ENOMEM;
  1304. master = spi_alloc_master(&pdev->dev, sizeof(*as));
  1305. if (!master)
  1306. goto out_free;
  1307. /* the spi->mode bits understood by this driver: */
  1308. master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
  1309. master->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 16);
  1310. master->dev.of_node = pdev->dev.of_node;
  1311. master->bus_num = pdev->id;
  1312. master->num_chipselect = master->dev.of_node ? 0 : 4;
  1313. master->setup = atmel_spi_setup;
  1314. master->flags = (SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX);
  1315. master->transfer_one_message = atmel_spi_transfer_one_message;
  1316. master->cleanup = atmel_spi_cleanup;
  1317. master->auto_runtime_pm = true;
  1318. master->max_dma_len = SPI_MAX_DMA_XFER;
  1319. master->can_dma = atmel_spi_can_dma;
  1320. platform_set_drvdata(pdev, master);
  1321. as = spi_master_get_devdata(master);
  1322. spin_lock_init(&as->lock);
  1323. as->pdev = pdev;
  1324. as->regs = devm_ioremap_resource(&pdev->dev, regs);
  1325. if (IS_ERR(as->regs)) {
  1326. ret = PTR_ERR(as->regs);
  1327. goto out_unmap_regs;
  1328. }
  1329. as->phybase = regs->start;
  1330. as->irq = irq;
  1331. as->clk = clk;
  1332. init_completion(&as->xfer_completion);
  1333. atmel_get_caps(as);
  1334. as->use_cs_gpios = true;
  1335. if (atmel_spi_is_v2(as) &&
  1336. pdev->dev.of_node &&
  1337. !of_get_property(pdev->dev.of_node, "cs-gpios", NULL)) {
  1338. as->use_cs_gpios = false;
  1339. master->num_chipselect = 4;
  1340. }
  1341. ret = atmel_spi_gpio_cs(pdev);
  1342. if (ret)
  1343. goto out_unmap_regs;
  1344. as->use_dma = false;
  1345. as->use_pdc = false;
  1346. if (as->caps.has_dma_support) {
  1347. ret = atmel_spi_configure_dma(master, as);
  1348. if (ret == 0) {
  1349. as->use_dma = true;
  1350. } else if (ret == -EPROBE_DEFER) {
  1351. return ret;
  1352. }
  1353. } else if (as->caps.has_pdc_support) {
  1354. as->use_pdc = true;
  1355. }
  1356. if (as->caps.has_dma_support && !as->use_dma)
  1357. dev_info(&pdev->dev, "Atmel SPI Controller using PIO only\n");
  1358. if (as->use_pdc) {
  1359. ret = devm_request_irq(&pdev->dev, irq, atmel_spi_pdc_interrupt,
  1360. 0, dev_name(&pdev->dev), master);
  1361. } else {
  1362. ret = devm_request_irq(&pdev->dev, irq, atmel_spi_pio_interrupt,
  1363. 0, dev_name(&pdev->dev), master);
  1364. }
  1365. if (ret)
  1366. goto out_unmap_regs;
  1367. /* Initialize the hardware */
  1368. ret = clk_prepare_enable(clk);
  1369. if (ret)
  1370. goto out_free_irq;
  1371. as->spi_clk = clk_get_rate(clk);
  1372. as->fifo_size = 0;
  1373. if (!of_property_read_u32(pdev->dev.of_node, "atmel,fifo-size",
  1374. &as->fifo_size)) {
  1375. dev_info(&pdev->dev, "Using FIFO (%u data)\n", as->fifo_size);
  1376. }
  1377. atmel_spi_init(as);
  1378. pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT);
  1379. pm_runtime_use_autosuspend(&pdev->dev);
  1380. pm_runtime_set_active(&pdev->dev);
  1381. pm_runtime_enable(&pdev->dev);
  1382. ret = devm_spi_register_master(&pdev->dev, master);
  1383. if (ret)
  1384. goto out_free_dma;
  1385. /* go! */
  1386. dev_info(&pdev->dev, "Atmel SPI Controller version 0x%x at 0x%08lx (irq %d)\n",
  1387. atmel_get_version(as), (unsigned long)regs->start,
  1388. irq);
  1389. return 0;
  1390. out_free_dma:
  1391. pm_runtime_disable(&pdev->dev);
  1392. pm_runtime_set_suspended(&pdev->dev);
  1393. if (as->use_dma)
  1394. atmel_spi_release_dma(master);
  1395. spi_writel(as, CR, SPI_BIT(SWRST));
  1396. spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
  1397. clk_disable_unprepare(clk);
  1398. out_free_irq:
  1399. out_unmap_regs:
  1400. out_free:
  1401. spi_master_put(master);
  1402. return ret;
  1403. }
  1404. static int atmel_spi_remove(struct platform_device *pdev)
  1405. {
  1406. struct spi_master *master = platform_get_drvdata(pdev);
  1407. struct atmel_spi *as = spi_master_get_devdata(master);
  1408. pm_runtime_get_sync(&pdev->dev);
  1409. /* reset the hardware and block queue progress */
  1410. spin_lock_irq(&as->lock);
  1411. if (as->use_dma) {
  1412. atmel_spi_stop_dma(master);
  1413. atmel_spi_release_dma(master);
  1414. }
  1415. spi_writel(as, CR, SPI_BIT(SWRST));
  1416. spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
  1417. spi_readl(as, SR);
  1418. spin_unlock_irq(&as->lock);
  1419. clk_disable_unprepare(as->clk);
  1420. pm_runtime_put_noidle(&pdev->dev);
  1421. pm_runtime_disable(&pdev->dev);
  1422. return 0;
  1423. }
  1424. #ifdef CONFIG_PM
  1425. static int atmel_spi_runtime_suspend(struct device *dev)
  1426. {
  1427. struct spi_master *master = dev_get_drvdata(dev);
  1428. struct atmel_spi *as = spi_master_get_devdata(master);
  1429. clk_disable_unprepare(as->clk);
  1430. pinctrl_pm_select_sleep_state(dev);
  1431. return 0;
  1432. }
  1433. static int atmel_spi_runtime_resume(struct device *dev)
  1434. {
  1435. struct spi_master *master = dev_get_drvdata(dev);
  1436. struct atmel_spi *as = spi_master_get_devdata(master);
  1437. pinctrl_pm_select_default_state(dev);
  1438. return clk_prepare_enable(as->clk);
  1439. }
  1440. #ifdef CONFIG_PM_SLEEP
  1441. static int atmel_spi_suspend(struct device *dev)
  1442. {
  1443. struct spi_master *master = dev_get_drvdata(dev);
  1444. int ret;
  1445. /* Stop the queue running */
  1446. ret = spi_master_suspend(master);
  1447. if (ret) {
  1448. dev_warn(dev, "cannot suspend master\n");
  1449. return ret;
  1450. }
  1451. if (!pm_runtime_suspended(dev))
  1452. atmel_spi_runtime_suspend(dev);
  1453. return 0;
  1454. }
  1455. static int atmel_spi_resume(struct device *dev)
  1456. {
  1457. struct spi_master *master = dev_get_drvdata(dev);
  1458. struct atmel_spi *as = spi_master_get_devdata(master);
  1459. int ret;
  1460. ret = clk_prepare_enable(as->clk);
  1461. if (ret)
  1462. return ret;
  1463. atmel_spi_init(as);
  1464. clk_disable_unprepare(as->clk);
  1465. if (!pm_runtime_suspended(dev)) {
  1466. ret = atmel_spi_runtime_resume(dev);
  1467. if (ret)
  1468. return ret;
  1469. }
  1470. /* Start the queue running */
  1471. ret = spi_master_resume(master);
  1472. if (ret)
  1473. dev_err(dev, "problem starting queue (%d)\n", ret);
  1474. return ret;
  1475. }
  1476. #endif
  1477. static const struct dev_pm_ops atmel_spi_pm_ops = {
  1478. SET_SYSTEM_SLEEP_PM_OPS(atmel_spi_suspend, atmel_spi_resume)
  1479. SET_RUNTIME_PM_OPS(atmel_spi_runtime_suspend,
  1480. atmel_spi_runtime_resume, NULL)
  1481. };
  1482. #define ATMEL_SPI_PM_OPS (&atmel_spi_pm_ops)
  1483. #else
  1484. #define ATMEL_SPI_PM_OPS NULL
  1485. #endif
  1486. #if defined(CONFIG_OF)
  1487. static const struct of_device_id atmel_spi_dt_ids[] = {
  1488. { .compatible = "atmel,at91rm9200-spi" },
  1489. { /* sentinel */ }
  1490. };
  1491. MODULE_DEVICE_TABLE(of, atmel_spi_dt_ids);
  1492. #endif
  1493. static struct platform_driver atmel_spi_driver = {
  1494. .driver = {
  1495. .name = "atmel_spi",
  1496. .pm = ATMEL_SPI_PM_OPS,
  1497. .of_match_table = of_match_ptr(atmel_spi_dt_ids),
  1498. },
  1499. .probe = atmel_spi_probe,
  1500. .remove = atmel_spi_remove,
  1501. };
  1502. module_platform_driver(atmel_spi_driver);
  1503. MODULE_DESCRIPTION("Atmel AT32/AT91 SPI Controller driver");
  1504. MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
  1505. MODULE_LICENSE("GPL");
  1506. MODULE_ALIAS("platform:atmel_spi");