spi-s3c64xx.c 44 KB

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