spi-atmel.c 45 KB

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