spi-s3c64xx.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664
  1. /*
  2. * Copyright (C) 2009 Samsung Electronics Ltd.
  3. * Jaswinder Singh <jassi.brar@samsung.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <linux/init.h>
  20. #include <linux/module.h>
  21. #include <linux/workqueue.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/delay.h>
  24. #include <linux/clk.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/dmaengine.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/pm_runtime.h>
  29. #include <linux/spi/spi.h>
  30. #include <linux/gpio.h>
  31. #include <linux/of.h>
  32. #include <linux/of_gpio.h>
  33. #include <linux/platform_data/spi-s3c64xx.h>
  34. #ifdef CONFIG_S3C_DMA
  35. #include <mach/dma.h>
  36. #endif
  37. #define MAX_SPI_PORTS 3
  38. #define S3C64XX_SPI_QUIRK_POLL (1 << 0)
  39. /* Registers and bit-fields */
  40. #define S3C64XX_SPI_CH_CFG 0x00
  41. #define S3C64XX_SPI_CLK_CFG 0x04
  42. #define S3C64XX_SPI_MODE_CFG 0x08
  43. #define S3C64XX_SPI_SLAVE_SEL 0x0C
  44. #define S3C64XX_SPI_INT_EN 0x10
  45. #define S3C64XX_SPI_STATUS 0x14
  46. #define S3C64XX_SPI_TX_DATA 0x18
  47. #define S3C64XX_SPI_RX_DATA 0x1C
  48. #define S3C64XX_SPI_PACKET_CNT 0x20
  49. #define S3C64XX_SPI_PENDING_CLR 0x24
  50. #define S3C64XX_SPI_SWAP_CFG 0x28
  51. #define S3C64XX_SPI_FB_CLK 0x2C
  52. #define S3C64XX_SPI_CH_HS_EN (1<<6) /* High Speed Enable */
  53. #define S3C64XX_SPI_CH_SW_RST (1<<5)
  54. #define S3C64XX_SPI_CH_SLAVE (1<<4)
  55. #define S3C64XX_SPI_CPOL_L (1<<3)
  56. #define S3C64XX_SPI_CPHA_B (1<<2)
  57. #define S3C64XX_SPI_CH_RXCH_ON (1<<1)
  58. #define S3C64XX_SPI_CH_TXCH_ON (1<<0)
  59. #define S3C64XX_SPI_CLKSEL_SRCMSK (3<<9)
  60. #define S3C64XX_SPI_CLKSEL_SRCSHFT 9
  61. #define S3C64XX_SPI_ENCLK_ENABLE (1<<8)
  62. #define S3C64XX_SPI_PSR_MASK 0xff
  63. #define S3C64XX_SPI_MODE_CH_TSZ_BYTE (0<<29)
  64. #define S3C64XX_SPI_MODE_CH_TSZ_HALFWORD (1<<29)
  65. #define S3C64XX_SPI_MODE_CH_TSZ_WORD (2<<29)
  66. #define S3C64XX_SPI_MODE_CH_TSZ_MASK (3<<29)
  67. #define S3C64XX_SPI_MODE_BUS_TSZ_BYTE (0<<17)
  68. #define S3C64XX_SPI_MODE_BUS_TSZ_HALFWORD (1<<17)
  69. #define S3C64XX_SPI_MODE_BUS_TSZ_WORD (2<<17)
  70. #define S3C64XX_SPI_MODE_BUS_TSZ_MASK (3<<17)
  71. #define S3C64XX_SPI_MODE_RXDMA_ON (1<<2)
  72. #define S3C64XX_SPI_MODE_TXDMA_ON (1<<1)
  73. #define S3C64XX_SPI_MODE_4BURST (1<<0)
  74. #define S3C64XX_SPI_SLAVE_AUTO (1<<1)
  75. #define S3C64XX_SPI_SLAVE_SIG_INACT (1<<0)
  76. #define S3C64XX_SPI_INT_TRAILING_EN (1<<6)
  77. #define S3C64XX_SPI_INT_RX_OVERRUN_EN (1<<5)
  78. #define S3C64XX_SPI_INT_RX_UNDERRUN_EN (1<<4)
  79. #define S3C64XX_SPI_INT_TX_OVERRUN_EN (1<<3)
  80. #define S3C64XX_SPI_INT_TX_UNDERRUN_EN (1<<2)
  81. #define S3C64XX_SPI_INT_RX_FIFORDY_EN (1<<1)
  82. #define S3C64XX_SPI_INT_TX_FIFORDY_EN (1<<0)
  83. #define S3C64XX_SPI_ST_RX_OVERRUN_ERR (1<<5)
  84. #define S3C64XX_SPI_ST_RX_UNDERRUN_ERR (1<<4)
  85. #define S3C64XX_SPI_ST_TX_OVERRUN_ERR (1<<3)
  86. #define S3C64XX_SPI_ST_TX_UNDERRUN_ERR (1<<2)
  87. #define S3C64XX_SPI_ST_RX_FIFORDY (1<<1)
  88. #define S3C64XX_SPI_ST_TX_FIFORDY (1<<0)
  89. #define S3C64XX_SPI_PACKET_CNT_EN (1<<16)
  90. #define S3C64XX_SPI_PND_TX_UNDERRUN_CLR (1<<4)
  91. #define S3C64XX_SPI_PND_TX_OVERRUN_CLR (1<<3)
  92. #define S3C64XX_SPI_PND_RX_UNDERRUN_CLR (1<<2)
  93. #define S3C64XX_SPI_PND_RX_OVERRUN_CLR (1<<1)
  94. #define S3C64XX_SPI_PND_TRAILING_CLR (1<<0)
  95. #define S3C64XX_SPI_SWAP_RX_HALF_WORD (1<<7)
  96. #define S3C64XX_SPI_SWAP_RX_BYTE (1<<6)
  97. #define S3C64XX_SPI_SWAP_RX_BIT (1<<5)
  98. #define S3C64XX_SPI_SWAP_RX_EN (1<<4)
  99. #define S3C64XX_SPI_SWAP_TX_HALF_WORD (1<<3)
  100. #define S3C64XX_SPI_SWAP_TX_BYTE (1<<2)
  101. #define S3C64XX_SPI_SWAP_TX_BIT (1<<1)
  102. #define S3C64XX_SPI_SWAP_TX_EN (1<<0)
  103. #define S3C64XX_SPI_FBCLK_MSK (3<<0)
  104. #define FIFO_LVL_MASK(i) ((i)->port_conf->fifo_lvl_mask[i->port_id])
  105. #define S3C64XX_SPI_ST_TX_DONE(v, i) (((v) & \
  106. (1 << (i)->port_conf->tx_st_done)) ? 1 : 0)
  107. #define TX_FIFO_LVL(v, i) (((v) >> 6) & FIFO_LVL_MASK(i))
  108. #define RX_FIFO_LVL(v, i) (((v) >> (i)->port_conf->rx_lvl_offset) & \
  109. FIFO_LVL_MASK(i))
  110. #define S3C64XX_SPI_MAX_TRAILCNT 0x3ff
  111. #define S3C64XX_SPI_TRAILCNT_OFF 19
  112. #define S3C64XX_SPI_TRAILCNT S3C64XX_SPI_MAX_TRAILCNT
  113. #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
  114. #define is_polling(x) (x->port_conf->quirks & S3C64XX_SPI_QUIRK_POLL)
  115. #define RXBUSY (1<<2)
  116. #define TXBUSY (1<<3)
  117. struct s3c64xx_spi_dma_data {
  118. struct dma_chan *ch;
  119. enum dma_transfer_direction direction;
  120. unsigned int dmach;
  121. };
  122. /**
  123. * struct s3c64xx_spi_info - SPI Controller hardware info
  124. * @fifo_lvl_mask: Bit-mask for {TX|RX}_FIFO_LVL bits in SPI_STATUS register.
  125. * @rx_lvl_offset: Bit offset of RX_FIFO_LVL bits in SPI_STATUS regiter.
  126. * @tx_st_done: Bit offset of TX_DONE bit in SPI_STATUS regiter.
  127. * @high_speed: True, if the controller supports HIGH_SPEED_EN bit.
  128. * @clk_from_cmu: True, if the controller does not include a clock mux and
  129. * prescaler unit.
  130. *
  131. * The Samsung s3c64xx SPI controller are used on various Samsung SoC's but
  132. * differ in some aspects such as the size of the fifo and spi bus clock
  133. * setup. Such differences are specified to the driver using this structure
  134. * which is provided as driver data to the driver.
  135. */
  136. struct s3c64xx_spi_port_config {
  137. int fifo_lvl_mask[MAX_SPI_PORTS];
  138. int rx_lvl_offset;
  139. int tx_st_done;
  140. int quirks;
  141. bool high_speed;
  142. bool clk_from_cmu;
  143. };
  144. /**
  145. * struct s3c64xx_spi_driver_data - Runtime info holder for SPI driver.
  146. * @clk: Pointer to the spi clock.
  147. * @src_clk: Pointer to the clock used to generate SPI signals.
  148. * @master: Pointer to the SPI Protocol master.
  149. * @cntrlr_info: Platform specific data for the controller this driver manages.
  150. * @tgl_spi: Pointer to the last CS left untoggled by the cs_change hint.
  151. * @lock: Controller specific lock.
  152. * @state: Set of FLAGS to indicate status.
  153. * @rx_dmach: Controller's DMA channel for Rx.
  154. * @tx_dmach: Controller's DMA channel for Tx.
  155. * @sfr_start: BUS address of SPI controller regs.
  156. * @regs: Pointer to ioremap'ed controller registers.
  157. * @irq: interrupt
  158. * @xfer_completion: To indicate completion of xfer task.
  159. * @cur_mode: Stores the active configuration of the controller.
  160. * @cur_bpw: Stores the active bits per word settings.
  161. * @cur_speed: Stores the active xfer clock speed.
  162. */
  163. struct s3c64xx_spi_driver_data {
  164. void __iomem *regs;
  165. struct clk *clk;
  166. struct clk *src_clk;
  167. struct platform_device *pdev;
  168. struct spi_master *master;
  169. struct s3c64xx_spi_info *cntrlr_info;
  170. struct spi_device *tgl_spi;
  171. spinlock_t lock;
  172. unsigned long sfr_start;
  173. struct completion xfer_completion;
  174. unsigned state;
  175. unsigned cur_mode, cur_bpw;
  176. unsigned cur_speed;
  177. struct s3c64xx_spi_dma_data rx_dma;
  178. struct s3c64xx_spi_dma_data tx_dma;
  179. #ifdef CONFIG_S3C_DMA
  180. struct samsung_dma_ops *ops;
  181. #endif
  182. struct s3c64xx_spi_port_config *port_conf;
  183. unsigned int port_id;
  184. unsigned long gpios[4];
  185. bool cs_gpio;
  186. };
  187. static void flush_fifo(struct s3c64xx_spi_driver_data *sdd)
  188. {
  189. void __iomem *regs = sdd->regs;
  190. unsigned long loops;
  191. u32 val;
  192. writel(0, regs + S3C64XX_SPI_PACKET_CNT);
  193. val = readl(regs + S3C64XX_SPI_CH_CFG);
  194. val &= ~(S3C64XX_SPI_CH_RXCH_ON | S3C64XX_SPI_CH_TXCH_ON);
  195. writel(val, regs + S3C64XX_SPI_CH_CFG);
  196. val = readl(regs + S3C64XX_SPI_CH_CFG);
  197. val |= S3C64XX_SPI_CH_SW_RST;
  198. val &= ~S3C64XX_SPI_CH_HS_EN;
  199. writel(val, regs + S3C64XX_SPI_CH_CFG);
  200. /* Flush TxFIFO*/
  201. loops = msecs_to_loops(1);
  202. do {
  203. val = readl(regs + S3C64XX_SPI_STATUS);
  204. } while (TX_FIFO_LVL(val, sdd) && loops--);
  205. if (loops == 0)
  206. dev_warn(&sdd->pdev->dev, "Timed out flushing TX FIFO\n");
  207. /* Flush RxFIFO*/
  208. loops = msecs_to_loops(1);
  209. do {
  210. val = readl(regs + S3C64XX_SPI_STATUS);
  211. if (RX_FIFO_LVL(val, sdd))
  212. readl(regs + S3C64XX_SPI_RX_DATA);
  213. else
  214. break;
  215. } while (loops--);
  216. if (loops == 0)
  217. dev_warn(&sdd->pdev->dev, "Timed out flushing RX FIFO\n");
  218. val = readl(regs + S3C64XX_SPI_CH_CFG);
  219. val &= ~S3C64XX_SPI_CH_SW_RST;
  220. writel(val, regs + S3C64XX_SPI_CH_CFG);
  221. val = readl(regs + S3C64XX_SPI_MODE_CFG);
  222. val &= ~(S3C64XX_SPI_MODE_TXDMA_ON | S3C64XX_SPI_MODE_RXDMA_ON);
  223. writel(val, regs + S3C64XX_SPI_MODE_CFG);
  224. }
  225. static void s3c64xx_spi_dmacb(void *data)
  226. {
  227. struct s3c64xx_spi_driver_data *sdd;
  228. struct s3c64xx_spi_dma_data *dma = data;
  229. unsigned long flags;
  230. if (dma->direction == DMA_DEV_TO_MEM)
  231. sdd = container_of(data,
  232. struct s3c64xx_spi_driver_data, rx_dma);
  233. else
  234. sdd = container_of(data,
  235. struct s3c64xx_spi_driver_data, tx_dma);
  236. spin_lock_irqsave(&sdd->lock, flags);
  237. if (dma->direction == DMA_DEV_TO_MEM) {
  238. sdd->state &= ~RXBUSY;
  239. if (!(sdd->state & TXBUSY))
  240. complete(&sdd->xfer_completion);
  241. } else {
  242. sdd->state &= ~TXBUSY;
  243. if (!(sdd->state & RXBUSY))
  244. complete(&sdd->xfer_completion);
  245. }
  246. spin_unlock_irqrestore(&sdd->lock, flags);
  247. }
  248. #ifdef CONFIG_S3C_DMA
  249. /* FIXME: remove this section once arch/arm/mach-s3c64xx uses dmaengine */
  250. static struct s3c2410_dma_client s3c64xx_spi_dma_client = {
  251. .name = "samsung-spi-dma",
  252. };
  253. static void prepare_dma(struct s3c64xx_spi_dma_data *dma,
  254. unsigned len, dma_addr_t buf)
  255. {
  256. struct s3c64xx_spi_driver_data *sdd;
  257. struct samsung_dma_prep info;
  258. struct samsung_dma_config config;
  259. if (dma->direction == DMA_DEV_TO_MEM) {
  260. sdd = container_of((void *)dma,
  261. struct s3c64xx_spi_driver_data, rx_dma);
  262. config.direction = sdd->rx_dma.direction;
  263. config.fifo = sdd->sfr_start + S3C64XX_SPI_RX_DATA;
  264. config.width = sdd->cur_bpw / 8;
  265. sdd->ops->config((enum dma_ch)sdd->rx_dma.ch, &config);
  266. } else {
  267. sdd = container_of((void *)dma,
  268. struct s3c64xx_spi_driver_data, tx_dma);
  269. config.direction = sdd->tx_dma.direction;
  270. config.fifo = sdd->sfr_start + S3C64XX_SPI_TX_DATA;
  271. config.width = sdd->cur_bpw / 8;
  272. sdd->ops->config((enum dma_ch)sdd->tx_dma.ch, &config);
  273. }
  274. info.cap = DMA_SLAVE;
  275. info.len = len;
  276. info.fp = s3c64xx_spi_dmacb;
  277. info.fp_param = dma;
  278. info.direction = dma->direction;
  279. info.buf = buf;
  280. sdd->ops->prepare((enum dma_ch)dma->ch, &info);
  281. sdd->ops->trigger((enum dma_ch)dma->ch);
  282. }
  283. static int acquire_dma(struct s3c64xx_spi_driver_data *sdd)
  284. {
  285. struct samsung_dma_req req;
  286. struct device *dev = &sdd->pdev->dev;
  287. sdd->ops = samsung_dma_get_ops();
  288. req.cap = DMA_SLAVE;
  289. req.client = &s3c64xx_spi_dma_client;
  290. sdd->rx_dma.ch = (struct dma_chan *)(unsigned long)sdd->ops->request(
  291. sdd->rx_dma.dmach, &req, dev, "rx");
  292. sdd->tx_dma.ch = (struct dma_chan *)(unsigned long)sdd->ops->request(
  293. sdd->tx_dma.dmach, &req, dev, "tx");
  294. return 1;
  295. }
  296. static int s3c64xx_spi_prepare_transfer(struct spi_master *spi)
  297. {
  298. struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(spi);
  299. /*
  300. * If DMA resource was not available during
  301. * probe, no need to continue with dma requests
  302. * else Acquire DMA channels
  303. */
  304. while (!is_polling(sdd) && !acquire_dma(sdd))
  305. usleep_range(10000, 11000);
  306. pm_runtime_get_sync(&sdd->pdev->dev);
  307. return 0;
  308. }
  309. static int s3c64xx_spi_unprepare_transfer(struct spi_master *spi)
  310. {
  311. struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(spi);
  312. /* Free DMA channels */
  313. if (!is_polling(sdd)) {
  314. sdd->ops->release((enum dma_ch)sdd->rx_dma.ch,
  315. &s3c64xx_spi_dma_client);
  316. sdd->ops->release((enum dma_ch)sdd->tx_dma.ch,
  317. &s3c64xx_spi_dma_client);
  318. }
  319. pm_runtime_put(&sdd->pdev->dev);
  320. return 0;
  321. }
  322. static void s3c64xx_spi_dma_stop(struct s3c64xx_spi_driver_data *sdd,
  323. struct s3c64xx_spi_dma_data *dma)
  324. {
  325. sdd->ops->stop((enum dma_ch)dma->ch);
  326. }
  327. #else
  328. static void prepare_dma(struct s3c64xx_spi_dma_data *dma,
  329. unsigned len, dma_addr_t buf)
  330. {
  331. struct s3c64xx_spi_driver_data *sdd;
  332. struct dma_slave_config config;
  333. struct scatterlist sg;
  334. struct dma_async_tx_descriptor *desc;
  335. memset(&config, 0, sizeof(config));
  336. if (dma->direction == DMA_DEV_TO_MEM) {
  337. sdd = container_of((void *)dma,
  338. struct s3c64xx_spi_driver_data, rx_dma);
  339. config.direction = dma->direction;
  340. config.src_addr = sdd->sfr_start + S3C64XX_SPI_RX_DATA;
  341. config.src_addr_width = sdd->cur_bpw / 8;
  342. config.src_maxburst = 1;
  343. dmaengine_slave_config(dma->ch, &config);
  344. } else {
  345. sdd = container_of((void *)dma,
  346. struct s3c64xx_spi_driver_data, tx_dma);
  347. config.direction = dma->direction;
  348. config.dst_addr = sdd->sfr_start + S3C64XX_SPI_TX_DATA;
  349. config.dst_addr_width = sdd->cur_bpw / 8;
  350. config.dst_maxburst = 1;
  351. dmaengine_slave_config(dma->ch, &config);
  352. }
  353. sg_init_table(&sg, 1);
  354. sg_dma_len(&sg) = len;
  355. sg_set_page(&sg, pfn_to_page(PFN_DOWN(buf)),
  356. len, offset_in_page(buf));
  357. sg_dma_address(&sg) = buf;
  358. desc = dmaengine_prep_slave_sg(dma->ch,
  359. &sg, 1, dma->direction, DMA_PREP_INTERRUPT);
  360. desc->callback = s3c64xx_spi_dmacb;
  361. desc->callback_param = dma;
  362. dmaengine_submit(desc);
  363. dma_async_issue_pending(dma->ch);
  364. }
  365. static int s3c64xx_spi_prepare_transfer(struct spi_master *spi)
  366. {
  367. struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(spi);
  368. dma_filter_fn filter = sdd->cntrlr_info->filter;
  369. struct device *dev = &sdd->pdev->dev;
  370. dma_cap_mask_t mask;
  371. int ret;
  372. if (is_polling(sdd))
  373. return 0;
  374. dma_cap_zero(mask);
  375. dma_cap_set(DMA_SLAVE, mask);
  376. /* Acquire DMA channels */
  377. sdd->rx_dma.ch = dma_request_slave_channel_compat(mask, filter,
  378. (void *)sdd->rx_dma.dmach, dev, "rx");
  379. if (!sdd->rx_dma.ch) {
  380. dev_err(dev, "Failed to get RX DMA channel\n");
  381. ret = -EBUSY;
  382. goto out;
  383. }
  384. sdd->tx_dma.ch = dma_request_slave_channel_compat(mask, filter,
  385. (void *)sdd->tx_dma.dmach, dev, "tx");
  386. if (!sdd->tx_dma.ch) {
  387. dev_err(dev, "Failed to get TX DMA channel\n");
  388. ret = -EBUSY;
  389. goto out_rx;
  390. }
  391. ret = pm_runtime_get_sync(&sdd->pdev->dev);
  392. if (ret < 0) {
  393. dev_err(dev, "Failed to enable device: %d\n", ret);
  394. goto out_tx;
  395. }
  396. return 0;
  397. out_tx:
  398. dma_release_channel(sdd->tx_dma.ch);
  399. out_rx:
  400. dma_release_channel(sdd->rx_dma.ch);
  401. out:
  402. return ret;
  403. }
  404. static int s3c64xx_spi_unprepare_transfer(struct spi_master *spi)
  405. {
  406. struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(spi);
  407. /* Free DMA channels */
  408. if (!is_polling(sdd)) {
  409. dma_release_channel(sdd->rx_dma.ch);
  410. dma_release_channel(sdd->tx_dma.ch);
  411. }
  412. pm_runtime_put(&sdd->pdev->dev);
  413. return 0;
  414. }
  415. static void s3c64xx_spi_dma_stop(struct s3c64xx_spi_driver_data *sdd,
  416. struct s3c64xx_spi_dma_data *dma)
  417. {
  418. dmaengine_terminate_all(dma->ch);
  419. }
  420. #endif
  421. static void enable_datapath(struct s3c64xx_spi_driver_data *sdd,
  422. struct spi_device *spi,
  423. struct spi_transfer *xfer, int dma_mode)
  424. {
  425. void __iomem *regs = sdd->regs;
  426. u32 modecfg, chcfg;
  427. modecfg = readl(regs + S3C64XX_SPI_MODE_CFG);
  428. modecfg &= ~(S3C64XX_SPI_MODE_TXDMA_ON | S3C64XX_SPI_MODE_RXDMA_ON);
  429. chcfg = readl(regs + S3C64XX_SPI_CH_CFG);
  430. chcfg &= ~S3C64XX_SPI_CH_TXCH_ON;
  431. if (dma_mode) {
  432. chcfg &= ~S3C64XX_SPI_CH_RXCH_ON;
  433. } else {
  434. /* Always shift in data in FIFO, even if xfer is Tx only,
  435. * this helps setting PCKT_CNT value for generating clocks
  436. * as exactly needed.
  437. */
  438. chcfg |= S3C64XX_SPI_CH_RXCH_ON;
  439. writel(((xfer->len * 8 / sdd->cur_bpw) & 0xffff)
  440. | S3C64XX_SPI_PACKET_CNT_EN,
  441. regs + S3C64XX_SPI_PACKET_CNT);
  442. }
  443. if (xfer->tx_buf != NULL) {
  444. sdd->state |= TXBUSY;
  445. chcfg |= S3C64XX_SPI_CH_TXCH_ON;
  446. if (dma_mode) {
  447. modecfg |= S3C64XX_SPI_MODE_TXDMA_ON;
  448. prepare_dma(&sdd->tx_dma, xfer->len, xfer->tx_dma);
  449. } else {
  450. switch (sdd->cur_bpw) {
  451. case 32:
  452. iowrite32_rep(regs + S3C64XX_SPI_TX_DATA,
  453. xfer->tx_buf, xfer->len / 4);
  454. break;
  455. case 16:
  456. iowrite16_rep(regs + S3C64XX_SPI_TX_DATA,
  457. xfer->tx_buf, xfer->len / 2);
  458. break;
  459. default:
  460. iowrite8_rep(regs + S3C64XX_SPI_TX_DATA,
  461. xfer->tx_buf, xfer->len);
  462. break;
  463. }
  464. }
  465. }
  466. if (xfer->rx_buf != NULL) {
  467. sdd->state |= RXBUSY;
  468. if (sdd->port_conf->high_speed && sdd->cur_speed >= 30000000UL
  469. && !(sdd->cur_mode & SPI_CPHA))
  470. chcfg |= S3C64XX_SPI_CH_HS_EN;
  471. if (dma_mode) {
  472. modecfg |= S3C64XX_SPI_MODE_RXDMA_ON;
  473. chcfg |= S3C64XX_SPI_CH_RXCH_ON;
  474. writel(((xfer->len * 8 / sdd->cur_bpw) & 0xffff)
  475. | S3C64XX_SPI_PACKET_CNT_EN,
  476. regs + S3C64XX_SPI_PACKET_CNT);
  477. prepare_dma(&sdd->rx_dma, xfer->len, xfer->rx_dma);
  478. }
  479. }
  480. writel(modecfg, regs + S3C64XX_SPI_MODE_CFG);
  481. writel(chcfg, regs + S3C64XX_SPI_CH_CFG);
  482. }
  483. static inline void enable_cs(struct s3c64xx_spi_driver_data *sdd,
  484. struct spi_device *spi)
  485. {
  486. struct s3c64xx_spi_csinfo *cs;
  487. if (sdd->tgl_spi != NULL) { /* If last device toggled after mssg */
  488. if (sdd->tgl_spi != spi) { /* if last mssg on diff device */
  489. /* Deselect the last toggled device */
  490. cs = sdd->tgl_spi->controller_data;
  491. if (sdd->cs_gpio)
  492. gpio_set_value(cs->line,
  493. spi->mode & SPI_CS_HIGH ? 0 : 1);
  494. }
  495. sdd->tgl_spi = NULL;
  496. }
  497. cs = spi->controller_data;
  498. if (sdd->cs_gpio)
  499. gpio_set_value(cs->line, spi->mode & SPI_CS_HIGH ? 1 : 0);
  500. /* Start the signals */
  501. writel(0, sdd->regs + S3C64XX_SPI_SLAVE_SEL);
  502. }
  503. static u32 s3c64xx_spi_wait_for_timeout(struct s3c64xx_spi_driver_data *sdd,
  504. int timeout_ms)
  505. {
  506. void __iomem *regs = sdd->regs;
  507. unsigned long val = 1;
  508. u32 status;
  509. /* max fifo depth available */
  510. u32 max_fifo = (FIFO_LVL_MASK(sdd) >> 1) + 1;
  511. if (timeout_ms)
  512. val = msecs_to_loops(timeout_ms);
  513. do {
  514. status = readl(regs + S3C64XX_SPI_STATUS);
  515. } while (RX_FIFO_LVL(status, sdd) < max_fifo && --val);
  516. /* return the actual received data length */
  517. return RX_FIFO_LVL(status, sdd);
  518. }
  519. static int wait_for_xfer(struct s3c64xx_spi_driver_data *sdd,
  520. struct spi_transfer *xfer, int dma_mode)
  521. {
  522. void __iomem *regs = sdd->regs;
  523. unsigned long val;
  524. int ms;
  525. /* millisecs to xfer 'len' bytes @ 'cur_speed' */
  526. ms = xfer->len * 8 * 1000 / sdd->cur_speed;
  527. ms += 10; /* some tolerance */
  528. if (dma_mode) {
  529. val = msecs_to_jiffies(ms) + 10;
  530. val = wait_for_completion_timeout(&sdd->xfer_completion, val);
  531. } else {
  532. u32 status;
  533. val = msecs_to_loops(ms);
  534. do {
  535. status = readl(regs + S3C64XX_SPI_STATUS);
  536. } while (RX_FIFO_LVL(status, sdd) < xfer->len && --val);
  537. }
  538. if (dma_mode) {
  539. u32 status;
  540. /*
  541. * If the previous xfer was completed within timeout, then
  542. * proceed further else return -EIO.
  543. * DmaTx returns after simply writing data in the FIFO,
  544. * w/o waiting for real transmission on the bus to finish.
  545. * DmaRx returns only after Dma read data from FIFO which
  546. * needs bus transmission to finish, so we don't worry if
  547. * Xfer involved Rx(with or without Tx).
  548. */
  549. if (val && !xfer->rx_buf) {
  550. val = msecs_to_loops(10);
  551. status = readl(regs + S3C64XX_SPI_STATUS);
  552. while ((TX_FIFO_LVL(status, sdd)
  553. || !S3C64XX_SPI_ST_TX_DONE(status, sdd))
  554. && --val) {
  555. cpu_relax();
  556. status = readl(regs + S3C64XX_SPI_STATUS);
  557. }
  558. }
  559. /* If timed out while checking rx/tx status return error */
  560. if (!val)
  561. return -EIO;
  562. } else {
  563. int loops;
  564. u32 cpy_len;
  565. u8 *buf;
  566. /* If it was only Tx */
  567. if (!xfer->rx_buf) {
  568. sdd->state &= ~TXBUSY;
  569. return 0;
  570. }
  571. /*
  572. * If the receive length is bigger than the controller fifo
  573. * size, calculate the loops and read the fifo as many times.
  574. * loops = length / max fifo size (calculated by using the
  575. * fifo mask).
  576. * For any size less than the fifo size the below code is
  577. * executed atleast once.
  578. */
  579. loops = xfer->len / ((FIFO_LVL_MASK(sdd) >> 1) + 1);
  580. buf = xfer->rx_buf;
  581. do {
  582. /* wait for data to be received in the fifo */
  583. cpy_len = s3c64xx_spi_wait_for_timeout(sdd,
  584. (loops ? ms : 0));
  585. switch (sdd->cur_bpw) {
  586. case 32:
  587. ioread32_rep(regs + S3C64XX_SPI_RX_DATA,
  588. buf, cpy_len / 4);
  589. break;
  590. case 16:
  591. ioread16_rep(regs + S3C64XX_SPI_RX_DATA,
  592. buf, cpy_len / 2);
  593. break;
  594. default:
  595. ioread8_rep(regs + S3C64XX_SPI_RX_DATA,
  596. buf, cpy_len);
  597. break;
  598. }
  599. buf = buf + cpy_len;
  600. } while (loops--);
  601. sdd->state &= ~RXBUSY;
  602. }
  603. return 0;
  604. }
  605. static inline void disable_cs(struct s3c64xx_spi_driver_data *sdd,
  606. struct spi_device *spi)
  607. {
  608. struct s3c64xx_spi_csinfo *cs = spi->controller_data;
  609. if (sdd->tgl_spi == spi)
  610. sdd->tgl_spi = NULL;
  611. if (sdd->cs_gpio)
  612. gpio_set_value(cs->line, spi->mode & SPI_CS_HIGH ? 0 : 1);
  613. /* Quiese the signals */
  614. writel(S3C64XX_SPI_SLAVE_SIG_INACT, sdd->regs + S3C64XX_SPI_SLAVE_SEL);
  615. }
  616. static void s3c64xx_spi_config(struct s3c64xx_spi_driver_data *sdd)
  617. {
  618. void __iomem *regs = sdd->regs;
  619. u32 val;
  620. /* Disable Clock */
  621. if (sdd->port_conf->clk_from_cmu) {
  622. clk_disable_unprepare(sdd->src_clk);
  623. } else {
  624. val = readl(regs + S3C64XX_SPI_CLK_CFG);
  625. val &= ~S3C64XX_SPI_ENCLK_ENABLE;
  626. writel(val, regs + S3C64XX_SPI_CLK_CFG);
  627. }
  628. /* Set Polarity and Phase */
  629. val = readl(regs + S3C64XX_SPI_CH_CFG);
  630. val &= ~(S3C64XX_SPI_CH_SLAVE |
  631. S3C64XX_SPI_CPOL_L |
  632. S3C64XX_SPI_CPHA_B);
  633. if (sdd->cur_mode & SPI_CPOL)
  634. val |= S3C64XX_SPI_CPOL_L;
  635. if (sdd->cur_mode & SPI_CPHA)
  636. val |= S3C64XX_SPI_CPHA_B;
  637. writel(val, regs + S3C64XX_SPI_CH_CFG);
  638. /* Set Channel & DMA Mode */
  639. val = readl(regs + S3C64XX_SPI_MODE_CFG);
  640. val &= ~(S3C64XX_SPI_MODE_BUS_TSZ_MASK
  641. | S3C64XX_SPI_MODE_CH_TSZ_MASK);
  642. switch (sdd->cur_bpw) {
  643. case 32:
  644. val |= S3C64XX_SPI_MODE_BUS_TSZ_WORD;
  645. val |= S3C64XX_SPI_MODE_CH_TSZ_WORD;
  646. break;
  647. case 16:
  648. val |= S3C64XX_SPI_MODE_BUS_TSZ_HALFWORD;
  649. val |= S3C64XX_SPI_MODE_CH_TSZ_HALFWORD;
  650. break;
  651. default:
  652. val |= S3C64XX_SPI_MODE_BUS_TSZ_BYTE;
  653. val |= S3C64XX_SPI_MODE_CH_TSZ_BYTE;
  654. break;
  655. }
  656. writel(val, regs + S3C64XX_SPI_MODE_CFG);
  657. if (sdd->port_conf->clk_from_cmu) {
  658. /* Configure Clock */
  659. /* There is half-multiplier before the SPI */
  660. clk_set_rate(sdd->src_clk, sdd->cur_speed * 2);
  661. /* Enable Clock */
  662. clk_prepare_enable(sdd->src_clk);
  663. } else {
  664. /* Configure Clock */
  665. val = readl(regs + S3C64XX_SPI_CLK_CFG);
  666. val &= ~S3C64XX_SPI_PSR_MASK;
  667. val |= ((clk_get_rate(sdd->src_clk) / sdd->cur_speed / 2 - 1)
  668. & S3C64XX_SPI_PSR_MASK);
  669. writel(val, regs + S3C64XX_SPI_CLK_CFG);
  670. /* Enable Clock */
  671. val = readl(regs + S3C64XX_SPI_CLK_CFG);
  672. val |= S3C64XX_SPI_ENCLK_ENABLE;
  673. writel(val, regs + S3C64XX_SPI_CLK_CFG);
  674. }
  675. }
  676. #define XFER_DMAADDR_INVALID DMA_BIT_MASK(32)
  677. static int s3c64xx_spi_map_mssg(struct s3c64xx_spi_driver_data *sdd,
  678. struct spi_message *msg)
  679. {
  680. struct device *dev = &sdd->pdev->dev;
  681. struct spi_transfer *xfer;
  682. if (is_polling(sdd) || msg->is_dma_mapped)
  683. return 0;
  684. /* First mark all xfer unmapped */
  685. list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  686. xfer->rx_dma = XFER_DMAADDR_INVALID;
  687. xfer->tx_dma = XFER_DMAADDR_INVALID;
  688. }
  689. /* Map until end or first fail */
  690. list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  691. if (xfer->len <= ((FIFO_LVL_MASK(sdd) >> 1) + 1))
  692. continue;
  693. if (xfer->tx_buf != NULL) {
  694. xfer->tx_dma = dma_map_single(dev,
  695. (void *)xfer->tx_buf, xfer->len,
  696. DMA_TO_DEVICE);
  697. if (dma_mapping_error(dev, xfer->tx_dma)) {
  698. dev_err(dev, "dma_map_single Tx failed\n");
  699. xfer->tx_dma = XFER_DMAADDR_INVALID;
  700. return -ENOMEM;
  701. }
  702. }
  703. if (xfer->rx_buf != NULL) {
  704. xfer->rx_dma = dma_map_single(dev, xfer->rx_buf,
  705. xfer->len, DMA_FROM_DEVICE);
  706. if (dma_mapping_error(dev, xfer->rx_dma)) {
  707. dev_err(dev, "dma_map_single Rx failed\n");
  708. dma_unmap_single(dev, xfer->tx_dma,
  709. xfer->len, DMA_TO_DEVICE);
  710. xfer->tx_dma = XFER_DMAADDR_INVALID;
  711. xfer->rx_dma = XFER_DMAADDR_INVALID;
  712. return -ENOMEM;
  713. }
  714. }
  715. }
  716. return 0;
  717. }
  718. static void s3c64xx_spi_unmap_mssg(struct s3c64xx_spi_driver_data *sdd,
  719. struct spi_message *msg)
  720. {
  721. struct device *dev = &sdd->pdev->dev;
  722. struct spi_transfer *xfer;
  723. if (is_polling(sdd) || msg->is_dma_mapped)
  724. return;
  725. list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  726. if (xfer->len <= ((FIFO_LVL_MASK(sdd) >> 1) + 1))
  727. continue;
  728. if (xfer->rx_buf != NULL
  729. && xfer->rx_dma != XFER_DMAADDR_INVALID)
  730. dma_unmap_single(dev, xfer->rx_dma,
  731. xfer->len, DMA_FROM_DEVICE);
  732. if (xfer->tx_buf != NULL
  733. && xfer->tx_dma != XFER_DMAADDR_INVALID)
  734. dma_unmap_single(dev, xfer->tx_dma,
  735. xfer->len, DMA_TO_DEVICE);
  736. }
  737. }
  738. static int s3c64xx_spi_transfer_one_message(struct spi_master *master,
  739. struct spi_message *msg)
  740. {
  741. struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
  742. struct spi_device *spi = msg->spi;
  743. struct s3c64xx_spi_csinfo *cs = spi->controller_data;
  744. struct spi_transfer *xfer;
  745. int status = 0, cs_toggle = 0;
  746. u32 speed;
  747. u8 bpw;
  748. /* If Master's(controller) state differs from that needed by Slave */
  749. if (sdd->cur_speed != spi->max_speed_hz
  750. || sdd->cur_mode != spi->mode
  751. || sdd->cur_bpw != spi->bits_per_word) {
  752. sdd->cur_bpw = spi->bits_per_word;
  753. sdd->cur_speed = spi->max_speed_hz;
  754. sdd->cur_mode = spi->mode;
  755. s3c64xx_spi_config(sdd);
  756. }
  757. /* Map all the transfers if needed */
  758. if (s3c64xx_spi_map_mssg(sdd, msg)) {
  759. dev_err(&spi->dev,
  760. "Xfer: Unable to map message buffers!\n");
  761. status = -ENOMEM;
  762. goto out;
  763. }
  764. /* Configure feedback delay */
  765. writel(cs->fb_delay & 0x3, sdd->regs + S3C64XX_SPI_FB_CLK);
  766. list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  767. unsigned long flags;
  768. int use_dma;
  769. INIT_COMPLETION(sdd->xfer_completion);
  770. /* Only BPW and Speed may change across transfers */
  771. bpw = xfer->bits_per_word;
  772. speed = xfer->speed_hz ? : spi->max_speed_hz;
  773. if (xfer->len % (bpw / 8)) {
  774. dev_err(&spi->dev,
  775. "Xfer length(%u) not a multiple of word size(%u)\n",
  776. xfer->len, bpw / 8);
  777. status = -EIO;
  778. goto out;
  779. }
  780. if (bpw != sdd->cur_bpw || speed != sdd->cur_speed) {
  781. sdd->cur_bpw = bpw;
  782. sdd->cur_speed = speed;
  783. s3c64xx_spi_config(sdd);
  784. }
  785. /* Polling method for xfers not bigger than FIFO capacity */
  786. use_dma = 0;
  787. if (!is_polling(sdd) &&
  788. (sdd->rx_dma.ch && sdd->tx_dma.ch &&
  789. (xfer->len > ((FIFO_LVL_MASK(sdd) >> 1) + 1))))
  790. use_dma = 1;
  791. spin_lock_irqsave(&sdd->lock, flags);
  792. /* Pending only which is to be done */
  793. sdd->state &= ~RXBUSY;
  794. sdd->state &= ~TXBUSY;
  795. enable_datapath(sdd, spi, xfer, use_dma);
  796. /* Slave Select */
  797. enable_cs(sdd, spi);
  798. spin_unlock_irqrestore(&sdd->lock, flags);
  799. status = wait_for_xfer(sdd, xfer, use_dma);
  800. if (status) {
  801. dev_err(&spi->dev, "I/O Error: rx-%d tx-%d res:rx-%c tx-%c len-%d\n",
  802. xfer->rx_buf ? 1 : 0, xfer->tx_buf ? 1 : 0,
  803. (sdd->state & RXBUSY) ? 'f' : 'p',
  804. (sdd->state & TXBUSY) ? 'f' : 'p',
  805. xfer->len);
  806. if (use_dma) {
  807. if (xfer->tx_buf != NULL
  808. && (sdd->state & TXBUSY))
  809. s3c64xx_spi_dma_stop(sdd, &sdd->tx_dma);
  810. if (xfer->rx_buf != NULL
  811. && (sdd->state & RXBUSY))
  812. s3c64xx_spi_dma_stop(sdd, &sdd->rx_dma);
  813. }
  814. goto out;
  815. }
  816. if (xfer->delay_usecs)
  817. udelay(xfer->delay_usecs);
  818. if (xfer->cs_change) {
  819. /* Hint that the next mssg is gonna be
  820. for the same device */
  821. if (list_is_last(&xfer->transfer_list,
  822. &msg->transfers))
  823. cs_toggle = 1;
  824. }
  825. msg->actual_length += xfer->len;
  826. flush_fifo(sdd);
  827. }
  828. out:
  829. if (!cs_toggle || status)
  830. disable_cs(sdd, spi);
  831. else
  832. sdd->tgl_spi = spi;
  833. s3c64xx_spi_unmap_mssg(sdd, msg);
  834. msg->status = status;
  835. spi_finalize_current_message(master);
  836. return 0;
  837. }
  838. static struct s3c64xx_spi_csinfo *s3c64xx_get_slave_ctrldata(
  839. struct spi_device *spi)
  840. {
  841. struct s3c64xx_spi_csinfo *cs;
  842. struct device_node *slave_np, *data_np = NULL;
  843. struct s3c64xx_spi_driver_data *sdd;
  844. u32 fb_delay = 0;
  845. sdd = spi_master_get_devdata(spi->master);
  846. slave_np = spi->dev.of_node;
  847. if (!slave_np) {
  848. dev_err(&spi->dev, "device node not found\n");
  849. return ERR_PTR(-EINVAL);
  850. }
  851. data_np = of_get_child_by_name(slave_np, "controller-data");
  852. if (!data_np) {
  853. dev_err(&spi->dev, "child node 'controller-data' not found\n");
  854. return ERR_PTR(-EINVAL);
  855. }
  856. cs = kzalloc(sizeof(*cs), GFP_KERNEL);
  857. if (!cs) {
  858. dev_err(&spi->dev, "could not allocate memory for controller data\n");
  859. of_node_put(data_np);
  860. return ERR_PTR(-ENOMEM);
  861. }
  862. /* The CS line is asserted/deasserted by the gpio pin */
  863. if (sdd->cs_gpio)
  864. cs->line = of_get_named_gpio(data_np, "cs-gpio", 0);
  865. if (!gpio_is_valid(cs->line)) {
  866. dev_err(&spi->dev, "chip select gpio is not specified or invalid\n");
  867. kfree(cs);
  868. of_node_put(data_np);
  869. return ERR_PTR(-EINVAL);
  870. }
  871. of_property_read_u32(data_np, "samsung,spi-feedback-delay", &fb_delay);
  872. cs->fb_delay = fb_delay;
  873. of_node_put(data_np);
  874. return cs;
  875. }
  876. /*
  877. * Here we only check the validity of requested configuration
  878. * and save the configuration in a local data-structure.
  879. * The controller is actually configured only just before we
  880. * get a message to transfer.
  881. */
  882. static int s3c64xx_spi_setup(struct spi_device *spi)
  883. {
  884. struct s3c64xx_spi_csinfo *cs = spi->controller_data;
  885. struct s3c64xx_spi_driver_data *sdd;
  886. struct s3c64xx_spi_info *sci;
  887. int err;
  888. sdd = spi_master_get_devdata(spi->master);
  889. if (!cs && spi->dev.of_node) {
  890. cs = s3c64xx_get_slave_ctrldata(spi);
  891. spi->controller_data = cs;
  892. }
  893. if (IS_ERR_OR_NULL(cs)) {
  894. dev_err(&spi->dev, "No CS for SPI(%d)\n", spi->chip_select);
  895. return -ENODEV;
  896. }
  897. /* Request gpio only if cs line is asserted by gpio pins */
  898. if (sdd->cs_gpio) {
  899. err = gpio_request_one(cs->line, GPIOF_OUT_INIT_HIGH,
  900. dev_name(&spi->dev));
  901. if (err) {
  902. dev_err(&spi->dev,
  903. "Failed to get /CS gpio [%d]: %d\n",
  904. cs->line, err);
  905. goto err_gpio_req;
  906. }
  907. }
  908. if (!spi_get_ctldata(spi))
  909. spi_set_ctldata(spi, cs);
  910. sci = sdd->cntrlr_info;
  911. pm_runtime_get_sync(&sdd->pdev->dev);
  912. /* Check if we can provide the requested rate */
  913. if (!sdd->port_conf->clk_from_cmu) {
  914. u32 psr, speed;
  915. /* Max possible */
  916. speed = clk_get_rate(sdd->src_clk) / 2 / (0 + 1);
  917. if (spi->max_speed_hz > speed)
  918. spi->max_speed_hz = speed;
  919. psr = clk_get_rate(sdd->src_clk) / 2 / spi->max_speed_hz - 1;
  920. psr &= S3C64XX_SPI_PSR_MASK;
  921. if (psr == S3C64XX_SPI_PSR_MASK)
  922. psr--;
  923. speed = clk_get_rate(sdd->src_clk) / 2 / (psr + 1);
  924. if (spi->max_speed_hz < speed) {
  925. if (psr+1 < S3C64XX_SPI_PSR_MASK) {
  926. psr++;
  927. } else {
  928. err = -EINVAL;
  929. goto setup_exit;
  930. }
  931. }
  932. speed = clk_get_rate(sdd->src_clk) / 2 / (psr + 1);
  933. if (spi->max_speed_hz >= speed) {
  934. spi->max_speed_hz = speed;
  935. } else {
  936. dev_err(&spi->dev, "Can't set %dHz transfer speed\n",
  937. spi->max_speed_hz);
  938. err = -EINVAL;
  939. goto setup_exit;
  940. }
  941. }
  942. pm_runtime_put(&sdd->pdev->dev);
  943. disable_cs(sdd, spi);
  944. return 0;
  945. setup_exit:
  946. /* setup() returns with device de-selected */
  947. disable_cs(sdd, spi);
  948. gpio_free(cs->line);
  949. spi_set_ctldata(spi, NULL);
  950. err_gpio_req:
  951. if (spi->dev.of_node)
  952. kfree(cs);
  953. return err;
  954. }
  955. static void s3c64xx_spi_cleanup(struct spi_device *spi)
  956. {
  957. struct s3c64xx_spi_csinfo *cs = spi_get_ctldata(spi);
  958. struct s3c64xx_spi_driver_data *sdd;
  959. sdd = spi_master_get_devdata(spi->master);
  960. if (cs && sdd->cs_gpio) {
  961. gpio_free(cs->line);
  962. if (spi->dev.of_node)
  963. kfree(cs);
  964. }
  965. spi_set_ctldata(spi, NULL);
  966. }
  967. static irqreturn_t s3c64xx_spi_irq(int irq, void *data)
  968. {
  969. struct s3c64xx_spi_driver_data *sdd = data;
  970. struct spi_master *spi = sdd->master;
  971. unsigned int val, clr = 0;
  972. val = readl(sdd->regs + S3C64XX_SPI_STATUS);
  973. if (val & S3C64XX_SPI_ST_RX_OVERRUN_ERR) {
  974. clr = S3C64XX_SPI_PND_RX_OVERRUN_CLR;
  975. dev_err(&spi->dev, "RX overrun\n");
  976. }
  977. if (val & S3C64XX_SPI_ST_RX_UNDERRUN_ERR) {
  978. clr |= S3C64XX_SPI_PND_RX_UNDERRUN_CLR;
  979. dev_err(&spi->dev, "RX underrun\n");
  980. }
  981. if (val & S3C64XX_SPI_ST_TX_OVERRUN_ERR) {
  982. clr |= S3C64XX_SPI_PND_TX_OVERRUN_CLR;
  983. dev_err(&spi->dev, "TX overrun\n");
  984. }
  985. if (val & S3C64XX_SPI_ST_TX_UNDERRUN_ERR) {
  986. clr |= S3C64XX_SPI_PND_TX_UNDERRUN_CLR;
  987. dev_err(&spi->dev, "TX underrun\n");
  988. }
  989. /* Clear the pending irq by setting and then clearing it */
  990. writel(clr, sdd->regs + S3C64XX_SPI_PENDING_CLR);
  991. writel(0, sdd->regs + S3C64XX_SPI_PENDING_CLR);
  992. return IRQ_HANDLED;
  993. }
  994. static void s3c64xx_spi_hwinit(struct s3c64xx_spi_driver_data *sdd, int channel)
  995. {
  996. struct s3c64xx_spi_info *sci = sdd->cntrlr_info;
  997. void __iomem *regs = sdd->regs;
  998. unsigned int val;
  999. sdd->cur_speed = 0;
  1000. writel(S3C64XX_SPI_SLAVE_SIG_INACT, sdd->regs + S3C64XX_SPI_SLAVE_SEL);
  1001. /* Disable Interrupts - we use Polling if not DMA mode */
  1002. writel(0, regs + S3C64XX_SPI_INT_EN);
  1003. if (!sdd->port_conf->clk_from_cmu)
  1004. writel(sci->src_clk_nr << S3C64XX_SPI_CLKSEL_SRCSHFT,
  1005. regs + S3C64XX_SPI_CLK_CFG);
  1006. writel(0, regs + S3C64XX_SPI_MODE_CFG);
  1007. writel(0, regs + S3C64XX_SPI_PACKET_CNT);
  1008. /* Clear any irq pending bits, should set and clear the bits */
  1009. val = S3C64XX_SPI_PND_RX_OVERRUN_CLR |
  1010. S3C64XX_SPI_PND_RX_UNDERRUN_CLR |
  1011. S3C64XX_SPI_PND_TX_OVERRUN_CLR |
  1012. S3C64XX_SPI_PND_TX_UNDERRUN_CLR;
  1013. writel(val, regs + S3C64XX_SPI_PENDING_CLR);
  1014. writel(0, regs + S3C64XX_SPI_PENDING_CLR);
  1015. writel(0, regs + S3C64XX_SPI_SWAP_CFG);
  1016. val = readl(regs + S3C64XX_SPI_MODE_CFG);
  1017. val &= ~S3C64XX_SPI_MODE_4BURST;
  1018. val &= ~(S3C64XX_SPI_MAX_TRAILCNT << S3C64XX_SPI_TRAILCNT_OFF);
  1019. val |= (S3C64XX_SPI_TRAILCNT << S3C64XX_SPI_TRAILCNT_OFF);
  1020. writel(val, regs + S3C64XX_SPI_MODE_CFG);
  1021. flush_fifo(sdd);
  1022. }
  1023. #ifdef CONFIG_OF
  1024. static struct s3c64xx_spi_info *s3c64xx_spi_parse_dt(struct device *dev)
  1025. {
  1026. struct s3c64xx_spi_info *sci;
  1027. u32 temp;
  1028. sci = devm_kzalloc(dev, sizeof(*sci), GFP_KERNEL);
  1029. if (!sci) {
  1030. dev_err(dev, "memory allocation for spi_info failed\n");
  1031. return ERR_PTR(-ENOMEM);
  1032. }
  1033. if (of_property_read_u32(dev->of_node, "samsung,spi-src-clk", &temp)) {
  1034. dev_warn(dev, "spi bus clock parent not specified, using clock at index 0 as parent\n");
  1035. sci->src_clk_nr = 0;
  1036. } else {
  1037. sci->src_clk_nr = temp;
  1038. }
  1039. if (of_property_read_u32(dev->of_node, "num-cs", &temp)) {
  1040. dev_warn(dev, "number of chip select lines not specified, assuming 1 chip select line\n");
  1041. sci->num_cs = 1;
  1042. } else {
  1043. sci->num_cs = temp;
  1044. }
  1045. return sci;
  1046. }
  1047. #else
  1048. static struct s3c64xx_spi_info *s3c64xx_spi_parse_dt(struct device *dev)
  1049. {
  1050. return dev->platform_data;
  1051. }
  1052. #endif
  1053. static const struct of_device_id s3c64xx_spi_dt_match[];
  1054. static inline struct s3c64xx_spi_port_config *s3c64xx_spi_get_port_config(
  1055. struct platform_device *pdev)
  1056. {
  1057. #ifdef CONFIG_OF
  1058. if (pdev->dev.of_node) {
  1059. const struct of_device_id *match;
  1060. match = of_match_node(s3c64xx_spi_dt_match, pdev->dev.of_node);
  1061. return (struct s3c64xx_spi_port_config *)match->data;
  1062. }
  1063. #endif
  1064. return (struct s3c64xx_spi_port_config *)
  1065. platform_get_device_id(pdev)->driver_data;
  1066. }
  1067. static int s3c64xx_spi_probe(struct platform_device *pdev)
  1068. {
  1069. struct resource *mem_res;
  1070. struct resource *res;
  1071. struct s3c64xx_spi_driver_data *sdd;
  1072. struct s3c64xx_spi_info *sci = pdev->dev.platform_data;
  1073. struct spi_master *master;
  1074. int ret, irq;
  1075. char clk_name[16];
  1076. if (!sci && pdev->dev.of_node) {
  1077. sci = s3c64xx_spi_parse_dt(&pdev->dev);
  1078. if (IS_ERR(sci))
  1079. return PTR_ERR(sci);
  1080. }
  1081. if (!sci) {
  1082. dev_err(&pdev->dev, "platform_data missing!\n");
  1083. return -ENODEV;
  1084. }
  1085. mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1086. if (mem_res == NULL) {
  1087. dev_err(&pdev->dev, "Unable to get SPI MEM resource\n");
  1088. return -ENXIO;
  1089. }
  1090. irq = platform_get_irq(pdev, 0);
  1091. if (irq < 0) {
  1092. dev_warn(&pdev->dev, "Failed to get IRQ: %d\n", irq);
  1093. return irq;
  1094. }
  1095. master = spi_alloc_master(&pdev->dev,
  1096. sizeof(struct s3c64xx_spi_driver_data));
  1097. if (master == NULL) {
  1098. dev_err(&pdev->dev, "Unable to allocate SPI Master\n");
  1099. return -ENOMEM;
  1100. }
  1101. platform_set_drvdata(pdev, master);
  1102. sdd = spi_master_get_devdata(master);
  1103. sdd->port_conf = s3c64xx_spi_get_port_config(pdev);
  1104. sdd->master = master;
  1105. sdd->cntrlr_info = sci;
  1106. sdd->pdev = pdev;
  1107. sdd->sfr_start = mem_res->start;
  1108. sdd->cs_gpio = true;
  1109. if (pdev->dev.of_node) {
  1110. if (!of_find_property(pdev->dev.of_node, "cs-gpio", NULL))
  1111. sdd->cs_gpio = false;
  1112. ret = of_alias_get_id(pdev->dev.of_node, "spi");
  1113. if (ret < 0) {
  1114. dev_err(&pdev->dev, "failed to get alias id, errno %d\n",
  1115. ret);
  1116. goto err0;
  1117. }
  1118. sdd->port_id = ret;
  1119. } else {
  1120. sdd->port_id = pdev->id;
  1121. }
  1122. sdd->cur_bpw = 8;
  1123. if (!sdd->pdev->dev.of_node) {
  1124. res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  1125. if (!res) {
  1126. dev_warn(&pdev->dev, "Unable to get SPI tx dma resource. Switching to poll mode\n");
  1127. sdd->port_conf->quirks = S3C64XX_SPI_QUIRK_POLL;
  1128. } else
  1129. sdd->tx_dma.dmach = res->start;
  1130. res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
  1131. if (!res) {
  1132. dev_warn(&pdev->dev, "Unable to get SPI rx dma resource. Switching to poll mode\n");
  1133. sdd->port_conf->quirks = S3C64XX_SPI_QUIRK_POLL;
  1134. } else
  1135. sdd->rx_dma.dmach = res->start;
  1136. }
  1137. sdd->tx_dma.direction = DMA_MEM_TO_DEV;
  1138. sdd->rx_dma.direction = DMA_DEV_TO_MEM;
  1139. master->dev.of_node = pdev->dev.of_node;
  1140. master->bus_num = sdd->port_id;
  1141. master->setup = s3c64xx_spi_setup;
  1142. master->cleanup = s3c64xx_spi_cleanup;
  1143. master->prepare_transfer_hardware = s3c64xx_spi_prepare_transfer;
  1144. master->transfer_one_message = s3c64xx_spi_transfer_one_message;
  1145. master->unprepare_transfer_hardware = s3c64xx_spi_unprepare_transfer;
  1146. master->num_chipselect = sci->num_cs;
  1147. master->dma_alignment = 8;
  1148. master->bits_per_word_mask = SPI_BPW_MASK(32) | SPI_BPW_MASK(16) |
  1149. SPI_BPW_MASK(8);
  1150. /* the spi->mode bits understood by this driver: */
  1151. master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
  1152. sdd->regs = devm_ioremap_resource(&pdev->dev, mem_res);
  1153. if (IS_ERR(sdd->regs)) {
  1154. ret = PTR_ERR(sdd->regs);
  1155. goto err0;
  1156. }
  1157. if (sci->cfg_gpio && sci->cfg_gpio()) {
  1158. dev_err(&pdev->dev, "Unable to config gpio\n");
  1159. ret = -EBUSY;
  1160. goto err0;
  1161. }
  1162. /* Setup clocks */
  1163. sdd->clk = devm_clk_get(&pdev->dev, "spi");
  1164. if (IS_ERR(sdd->clk)) {
  1165. dev_err(&pdev->dev, "Unable to acquire clock 'spi'\n");
  1166. ret = PTR_ERR(sdd->clk);
  1167. goto err0;
  1168. }
  1169. if (clk_prepare_enable(sdd->clk)) {
  1170. dev_err(&pdev->dev, "Couldn't enable clock 'spi'\n");
  1171. ret = -EBUSY;
  1172. goto err0;
  1173. }
  1174. sprintf(clk_name, "spi_busclk%d", sci->src_clk_nr);
  1175. sdd->src_clk = devm_clk_get(&pdev->dev, clk_name);
  1176. if (IS_ERR(sdd->src_clk)) {
  1177. dev_err(&pdev->dev,
  1178. "Unable to acquire clock '%s'\n", clk_name);
  1179. ret = PTR_ERR(sdd->src_clk);
  1180. goto err2;
  1181. }
  1182. if (clk_prepare_enable(sdd->src_clk)) {
  1183. dev_err(&pdev->dev, "Couldn't enable clock '%s'\n", clk_name);
  1184. ret = -EBUSY;
  1185. goto err2;
  1186. }
  1187. /* Setup Deufult Mode */
  1188. s3c64xx_spi_hwinit(sdd, sdd->port_id);
  1189. spin_lock_init(&sdd->lock);
  1190. init_completion(&sdd->xfer_completion);
  1191. ret = devm_request_irq(&pdev->dev, irq, s3c64xx_spi_irq, 0,
  1192. "spi-s3c64xx", sdd);
  1193. if (ret != 0) {
  1194. dev_err(&pdev->dev, "Failed to request IRQ %d: %d\n",
  1195. irq, ret);
  1196. goto err3;
  1197. }
  1198. writel(S3C64XX_SPI_INT_RX_OVERRUN_EN | S3C64XX_SPI_INT_RX_UNDERRUN_EN |
  1199. S3C64XX_SPI_INT_TX_OVERRUN_EN | S3C64XX_SPI_INT_TX_UNDERRUN_EN,
  1200. sdd->regs + S3C64XX_SPI_INT_EN);
  1201. if (spi_register_master(master)) {
  1202. dev_err(&pdev->dev, "cannot register SPI master\n");
  1203. ret = -EBUSY;
  1204. goto err3;
  1205. }
  1206. dev_dbg(&pdev->dev, "Samsung SoC SPI Driver loaded for Bus SPI-%d with %d Slaves attached\n",
  1207. sdd->port_id, master->num_chipselect);
  1208. dev_dbg(&pdev->dev, "\tIOmem=[%pR]\tDMA=[Rx-%d, Tx-%d]\n",
  1209. mem_res,
  1210. sdd->rx_dma.dmach, sdd->tx_dma.dmach);
  1211. pm_runtime_enable(&pdev->dev);
  1212. return 0;
  1213. err3:
  1214. clk_disable_unprepare(sdd->src_clk);
  1215. err2:
  1216. clk_disable_unprepare(sdd->clk);
  1217. err0:
  1218. spi_master_put(master);
  1219. return ret;
  1220. }
  1221. static int s3c64xx_spi_remove(struct platform_device *pdev)
  1222. {
  1223. struct spi_master *master = spi_master_get(platform_get_drvdata(pdev));
  1224. struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
  1225. pm_runtime_disable(&pdev->dev);
  1226. spi_unregister_master(master);
  1227. writel(0, sdd->regs + S3C64XX_SPI_INT_EN);
  1228. clk_disable_unprepare(sdd->src_clk);
  1229. clk_disable_unprepare(sdd->clk);
  1230. spi_master_put(master);
  1231. return 0;
  1232. }
  1233. #ifdef CONFIG_PM_SLEEP
  1234. static int s3c64xx_spi_suspend(struct device *dev)
  1235. {
  1236. struct spi_master *master = dev_get_drvdata(dev);
  1237. struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
  1238. spi_master_suspend(master);
  1239. /* Disable the clock */
  1240. clk_disable_unprepare(sdd->src_clk);
  1241. clk_disable_unprepare(sdd->clk);
  1242. sdd->cur_speed = 0; /* Output Clock is stopped */
  1243. return 0;
  1244. }
  1245. static int s3c64xx_spi_resume(struct device *dev)
  1246. {
  1247. struct spi_master *master = dev_get_drvdata(dev);
  1248. struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
  1249. struct s3c64xx_spi_info *sci = sdd->cntrlr_info;
  1250. if (sci->cfg_gpio)
  1251. sci->cfg_gpio();
  1252. /* Enable the clock */
  1253. clk_prepare_enable(sdd->src_clk);
  1254. clk_prepare_enable(sdd->clk);
  1255. s3c64xx_spi_hwinit(sdd, sdd->port_id);
  1256. spi_master_resume(master);
  1257. return 0;
  1258. }
  1259. #endif /* CONFIG_PM_SLEEP */
  1260. #ifdef CONFIG_PM_RUNTIME
  1261. static int s3c64xx_spi_runtime_suspend(struct device *dev)
  1262. {
  1263. struct spi_master *master = dev_get_drvdata(dev);
  1264. struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
  1265. clk_disable_unprepare(sdd->clk);
  1266. clk_disable_unprepare(sdd->src_clk);
  1267. return 0;
  1268. }
  1269. static int s3c64xx_spi_runtime_resume(struct device *dev)
  1270. {
  1271. struct spi_master *master = dev_get_drvdata(dev);
  1272. struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
  1273. clk_prepare_enable(sdd->src_clk);
  1274. clk_prepare_enable(sdd->clk);
  1275. return 0;
  1276. }
  1277. #endif /* CONFIG_PM_RUNTIME */
  1278. static const struct dev_pm_ops s3c64xx_spi_pm = {
  1279. SET_SYSTEM_SLEEP_PM_OPS(s3c64xx_spi_suspend, s3c64xx_spi_resume)
  1280. SET_RUNTIME_PM_OPS(s3c64xx_spi_runtime_suspend,
  1281. s3c64xx_spi_runtime_resume, NULL)
  1282. };
  1283. static struct s3c64xx_spi_port_config s3c2443_spi_port_config = {
  1284. .fifo_lvl_mask = { 0x7f },
  1285. .rx_lvl_offset = 13,
  1286. .tx_st_done = 21,
  1287. .high_speed = true,
  1288. };
  1289. static struct s3c64xx_spi_port_config s3c6410_spi_port_config = {
  1290. .fifo_lvl_mask = { 0x7f, 0x7F },
  1291. .rx_lvl_offset = 13,
  1292. .tx_st_done = 21,
  1293. };
  1294. static struct s3c64xx_spi_port_config s5p64x0_spi_port_config = {
  1295. .fifo_lvl_mask = { 0x1ff, 0x7F },
  1296. .rx_lvl_offset = 15,
  1297. .tx_st_done = 25,
  1298. };
  1299. static struct s3c64xx_spi_port_config s5pc100_spi_port_config = {
  1300. .fifo_lvl_mask = { 0x7f, 0x7F },
  1301. .rx_lvl_offset = 13,
  1302. .tx_st_done = 21,
  1303. .high_speed = true,
  1304. };
  1305. static struct s3c64xx_spi_port_config s5pv210_spi_port_config = {
  1306. .fifo_lvl_mask = { 0x1ff, 0x7F },
  1307. .rx_lvl_offset = 15,
  1308. .tx_st_done = 25,
  1309. .high_speed = true,
  1310. };
  1311. static struct s3c64xx_spi_port_config exynos4_spi_port_config = {
  1312. .fifo_lvl_mask = { 0x1ff, 0x7F, 0x7F },
  1313. .rx_lvl_offset = 15,
  1314. .tx_st_done = 25,
  1315. .high_speed = true,
  1316. .clk_from_cmu = true,
  1317. };
  1318. static struct s3c64xx_spi_port_config exynos5440_spi_port_config = {
  1319. .fifo_lvl_mask = { 0x1ff },
  1320. .rx_lvl_offset = 15,
  1321. .tx_st_done = 25,
  1322. .high_speed = true,
  1323. .clk_from_cmu = true,
  1324. .quirks = S3C64XX_SPI_QUIRK_POLL,
  1325. };
  1326. static struct platform_device_id s3c64xx_spi_driver_ids[] = {
  1327. {
  1328. .name = "s3c2443-spi",
  1329. .driver_data = (kernel_ulong_t)&s3c2443_spi_port_config,
  1330. }, {
  1331. .name = "s3c6410-spi",
  1332. .driver_data = (kernel_ulong_t)&s3c6410_spi_port_config,
  1333. }, {
  1334. .name = "s5p64x0-spi",
  1335. .driver_data = (kernel_ulong_t)&s5p64x0_spi_port_config,
  1336. }, {
  1337. .name = "s5pc100-spi",
  1338. .driver_data = (kernel_ulong_t)&s5pc100_spi_port_config,
  1339. }, {
  1340. .name = "s5pv210-spi",
  1341. .driver_data = (kernel_ulong_t)&s5pv210_spi_port_config,
  1342. }, {
  1343. .name = "exynos4210-spi",
  1344. .driver_data = (kernel_ulong_t)&exynos4_spi_port_config,
  1345. },
  1346. { },
  1347. };
  1348. static const struct of_device_id s3c64xx_spi_dt_match[] = {
  1349. { .compatible = "samsung,exynos4210-spi",
  1350. .data = (void *)&exynos4_spi_port_config,
  1351. },
  1352. { .compatible = "samsung,exynos5440-spi",
  1353. .data = (void *)&exynos5440_spi_port_config,
  1354. },
  1355. { },
  1356. };
  1357. MODULE_DEVICE_TABLE(of, s3c64xx_spi_dt_match);
  1358. static struct platform_driver s3c64xx_spi_driver = {
  1359. .driver = {
  1360. .name = "s3c64xx-spi",
  1361. .owner = THIS_MODULE,
  1362. .pm = &s3c64xx_spi_pm,
  1363. .of_match_table = of_match_ptr(s3c64xx_spi_dt_match),
  1364. },
  1365. .remove = s3c64xx_spi_remove,
  1366. .id_table = s3c64xx_spi_driver_ids,
  1367. };
  1368. MODULE_ALIAS("platform:s3c64xx-spi");
  1369. static int __init s3c64xx_spi_init(void)
  1370. {
  1371. return platform_driver_probe(&s3c64xx_spi_driver, s3c64xx_spi_probe);
  1372. }
  1373. subsys_initcall(s3c64xx_spi_init);
  1374. static void __exit s3c64xx_spi_exit(void)
  1375. {
  1376. platform_driver_unregister(&s3c64xx_spi_driver);
  1377. }
  1378. module_exit(s3c64xx_spi_exit);
  1379. MODULE_AUTHOR("Jaswinder Singh <jassi.brar@samsung.com>");
  1380. MODULE_DESCRIPTION("S3C64XX SPI Controller Driver");
  1381. MODULE_LICENSE("GPL");