spi-topcliff-pch.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740
  1. /*
  2. * SPI bus driver for the Topcliff PCH used by Intel SoCs
  3. *
  4. * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  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. #include <linux/delay.h>
  16. #include <linux/pci.h>
  17. #include <linux/wait.h>
  18. #include <linux/spi/spi.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/sched.h>
  21. #include <linux/spi/spidev.h>
  22. #include <linux/module.h>
  23. #include <linux/device.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/dmaengine.h>
  26. #include <linux/pch_dma.h>
  27. /* Register offsets */
  28. #define PCH_SPCR 0x00 /* SPI control register */
  29. #define PCH_SPBRR 0x04 /* SPI baud rate register */
  30. #define PCH_SPSR 0x08 /* SPI status register */
  31. #define PCH_SPDWR 0x0C /* SPI write data register */
  32. #define PCH_SPDRR 0x10 /* SPI read data register */
  33. #define PCH_SSNXCR 0x18 /* SSN Expand Control Register */
  34. #define PCH_SRST 0x1C /* SPI reset register */
  35. #define PCH_ADDRESS_SIZE 0x20
  36. #define PCH_SPSR_TFD 0x000007C0
  37. #define PCH_SPSR_RFD 0x0000F800
  38. #define PCH_READABLE(x) (((x) & PCH_SPSR_RFD)>>11)
  39. #define PCH_WRITABLE(x) (((x) & PCH_SPSR_TFD)>>6)
  40. #define PCH_RX_THOLD 7
  41. #define PCH_RX_THOLD_MAX 15
  42. #define PCH_TX_THOLD 2
  43. #define PCH_MAX_BAUDRATE 5000000
  44. #define PCH_MAX_FIFO_DEPTH 16
  45. #define STATUS_RUNNING 1
  46. #define STATUS_EXITING 2
  47. #define PCH_SLEEP_TIME 10
  48. #define SSN_LOW 0x02U
  49. #define SSN_HIGH 0x03U
  50. #define SSN_NO_CONTROL 0x00U
  51. #define PCH_MAX_CS 0xFF
  52. #define PCI_DEVICE_ID_GE_SPI 0x8816
  53. #define SPCR_SPE_BIT (1 << 0)
  54. #define SPCR_MSTR_BIT (1 << 1)
  55. #define SPCR_LSBF_BIT (1 << 4)
  56. #define SPCR_CPHA_BIT (1 << 5)
  57. #define SPCR_CPOL_BIT (1 << 6)
  58. #define SPCR_TFIE_BIT (1 << 8)
  59. #define SPCR_RFIE_BIT (1 << 9)
  60. #define SPCR_FIE_BIT (1 << 10)
  61. #define SPCR_ORIE_BIT (1 << 11)
  62. #define SPCR_MDFIE_BIT (1 << 12)
  63. #define SPCR_FICLR_BIT (1 << 24)
  64. #define SPSR_TFI_BIT (1 << 0)
  65. #define SPSR_RFI_BIT (1 << 1)
  66. #define SPSR_FI_BIT (1 << 2)
  67. #define SPSR_ORF_BIT (1 << 3)
  68. #define SPBRR_SIZE_BIT (1 << 10)
  69. #define PCH_ALL (SPCR_TFIE_BIT|SPCR_RFIE_BIT|SPCR_FIE_BIT|\
  70. SPCR_ORIE_BIT|SPCR_MDFIE_BIT)
  71. #define SPCR_RFIC_FIELD 20
  72. #define SPCR_TFIC_FIELD 16
  73. #define MASK_SPBRR_SPBR_BITS ((1 << 10) - 1)
  74. #define MASK_RFIC_SPCR_BITS (0xf << SPCR_RFIC_FIELD)
  75. #define MASK_TFIC_SPCR_BITS (0xf << SPCR_TFIC_FIELD)
  76. #define PCH_CLOCK_HZ 50000000
  77. #define PCH_MAX_SPBR 1023
  78. /* Definition for ML7213/ML7223/ML7831 by LAPIS Semiconductor */
  79. #define PCI_VENDOR_ID_ROHM 0x10DB
  80. #define PCI_DEVICE_ID_ML7213_SPI 0x802c
  81. #define PCI_DEVICE_ID_ML7223_SPI 0x800F
  82. #define PCI_DEVICE_ID_ML7831_SPI 0x8816
  83. /*
  84. * Set the number of SPI instance max
  85. * Intel EG20T PCH : 1ch
  86. * LAPIS Semiconductor ML7213 IOH : 2ch
  87. * LAPIS Semiconductor ML7223 IOH : 1ch
  88. * LAPIS Semiconductor ML7831 IOH : 1ch
  89. */
  90. #define PCH_SPI_MAX_DEV 2
  91. #define PCH_BUF_SIZE 4096
  92. #define PCH_DMA_TRANS_SIZE 12
  93. static int use_dma = 1;
  94. struct pch_spi_dma_ctrl {
  95. struct dma_async_tx_descriptor *desc_tx;
  96. struct dma_async_tx_descriptor *desc_rx;
  97. struct pch_dma_slave param_tx;
  98. struct pch_dma_slave param_rx;
  99. struct dma_chan *chan_tx;
  100. struct dma_chan *chan_rx;
  101. struct scatterlist *sg_tx_p;
  102. struct scatterlist *sg_rx_p;
  103. struct scatterlist sg_tx;
  104. struct scatterlist sg_rx;
  105. int nent;
  106. void *tx_buf_virt;
  107. void *rx_buf_virt;
  108. dma_addr_t tx_buf_dma;
  109. dma_addr_t rx_buf_dma;
  110. };
  111. /**
  112. * struct pch_spi_data - Holds the SPI channel specific details
  113. * @io_remap_addr: The remapped PCI base address
  114. * @master: Pointer to the SPI master structure
  115. * @work: Reference to work queue handler
  116. * @wait: Wait queue for waking up upon receiving an
  117. * interrupt.
  118. * @transfer_complete: Status of SPI Transfer
  119. * @bcurrent_msg_processing: Status flag for message processing
  120. * @lock: Lock for protecting this structure
  121. * @queue: SPI Message queue
  122. * @status: Status of the SPI driver
  123. * @bpw_len: Length of data to be transferred in bits per
  124. * word
  125. * @transfer_active: Flag showing active transfer
  126. * @tx_index: Transmit data count; for bookkeeping during
  127. * transfer
  128. * @rx_index: Receive data count; for bookkeeping during
  129. * transfer
  130. * @tx_buff: Buffer for data to be transmitted
  131. * @rx_index: Buffer for Received data
  132. * @n_curnt_chip: The chip number that this SPI driver currently
  133. * operates on
  134. * @current_chip: Reference to the current chip that this SPI
  135. * driver currently operates on
  136. * @current_msg: The current message that this SPI driver is
  137. * handling
  138. * @cur_trans: The current transfer that this SPI driver is
  139. * handling
  140. * @board_dat: Reference to the SPI device data structure
  141. * @plat_dev: platform_device structure
  142. * @ch: SPI channel number
  143. * @irq_reg_sts: Status of IRQ registration
  144. */
  145. struct pch_spi_data {
  146. void __iomem *io_remap_addr;
  147. unsigned long io_base_addr;
  148. struct spi_master *master;
  149. struct work_struct work;
  150. wait_queue_head_t wait;
  151. u8 transfer_complete;
  152. u8 bcurrent_msg_processing;
  153. spinlock_t lock;
  154. struct list_head queue;
  155. u8 status;
  156. u32 bpw_len;
  157. u8 transfer_active;
  158. u32 tx_index;
  159. u32 rx_index;
  160. u16 *pkt_tx_buff;
  161. u16 *pkt_rx_buff;
  162. u8 n_curnt_chip;
  163. struct spi_device *current_chip;
  164. struct spi_message *current_msg;
  165. struct spi_transfer *cur_trans;
  166. struct pch_spi_board_data *board_dat;
  167. struct platform_device *plat_dev;
  168. int ch;
  169. struct pch_spi_dma_ctrl dma;
  170. int use_dma;
  171. u8 irq_reg_sts;
  172. int save_total_len;
  173. };
  174. /**
  175. * struct pch_spi_board_data - Holds the SPI device specific details
  176. * @pdev: Pointer to the PCI device
  177. * @suspend_sts: Status of suspend
  178. * @num: The number of SPI device instance
  179. */
  180. struct pch_spi_board_data {
  181. struct pci_dev *pdev;
  182. u8 suspend_sts;
  183. int num;
  184. };
  185. struct pch_pd_dev_save {
  186. int num;
  187. struct platform_device *pd_save[PCH_SPI_MAX_DEV];
  188. struct pch_spi_board_data *board_dat;
  189. };
  190. static const struct pci_device_id pch_spi_pcidev_id[] = {
  191. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_GE_SPI), 1, },
  192. { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7213_SPI), 2, },
  193. { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7223_SPI), 1, },
  194. { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7831_SPI), 1, },
  195. { }
  196. };
  197. /**
  198. * pch_spi_writereg() - Performs register writes
  199. * @master: Pointer to struct spi_master.
  200. * @idx: Register offset.
  201. * @val: Value to be written to register.
  202. */
  203. static inline void pch_spi_writereg(struct spi_master *master, int idx, u32 val)
  204. {
  205. struct pch_spi_data *data = spi_master_get_devdata(master);
  206. iowrite32(val, (data->io_remap_addr + idx));
  207. }
  208. /**
  209. * pch_spi_readreg() - Performs register reads
  210. * @master: Pointer to struct spi_master.
  211. * @idx: Register offset.
  212. */
  213. static inline u32 pch_spi_readreg(struct spi_master *master, int idx)
  214. {
  215. struct pch_spi_data *data = spi_master_get_devdata(master);
  216. return ioread32(data->io_remap_addr + idx);
  217. }
  218. static inline void pch_spi_setclr_reg(struct spi_master *master, int idx,
  219. u32 set, u32 clr)
  220. {
  221. u32 tmp = pch_spi_readreg(master, idx);
  222. tmp = (tmp & ~clr) | set;
  223. pch_spi_writereg(master, idx, tmp);
  224. }
  225. static void pch_spi_set_master_mode(struct spi_master *master)
  226. {
  227. pch_spi_setclr_reg(master, PCH_SPCR, SPCR_MSTR_BIT, 0);
  228. }
  229. /**
  230. * pch_spi_clear_fifo() - Clears the Transmit and Receive FIFOs
  231. * @master: Pointer to struct spi_master.
  232. */
  233. static void pch_spi_clear_fifo(struct spi_master *master)
  234. {
  235. pch_spi_setclr_reg(master, PCH_SPCR, SPCR_FICLR_BIT, 0);
  236. pch_spi_setclr_reg(master, PCH_SPCR, 0, SPCR_FICLR_BIT);
  237. }
  238. static void pch_spi_handler_sub(struct pch_spi_data *data, u32 reg_spsr_val,
  239. void __iomem *io_remap_addr)
  240. {
  241. u32 n_read, tx_index, rx_index, bpw_len;
  242. u16 *pkt_rx_buffer, *pkt_tx_buff;
  243. int read_cnt;
  244. u32 reg_spcr_val;
  245. void __iomem *spsr;
  246. void __iomem *spdrr;
  247. void __iomem *spdwr;
  248. spsr = io_remap_addr + PCH_SPSR;
  249. iowrite32(reg_spsr_val, spsr);
  250. if (data->transfer_active) {
  251. rx_index = data->rx_index;
  252. tx_index = data->tx_index;
  253. bpw_len = data->bpw_len;
  254. pkt_rx_buffer = data->pkt_rx_buff;
  255. pkt_tx_buff = data->pkt_tx_buff;
  256. spdrr = io_remap_addr + PCH_SPDRR;
  257. spdwr = io_remap_addr + PCH_SPDWR;
  258. n_read = PCH_READABLE(reg_spsr_val);
  259. for (read_cnt = 0; (read_cnt < n_read); read_cnt++) {
  260. pkt_rx_buffer[rx_index++] = ioread32(spdrr);
  261. if (tx_index < bpw_len)
  262. iowrite32(pkt_tx_buff[tx_index++], spdwr);
  263. }
  264. /* disable RFI if not needed */
  265. if ((bpw_len - rx_index) <= PCH_MAX_FIFO_DEPTH) {
  266. reg_spcr_val = ioread32(io_remap_addr + PCH_SPCR);
  267. reg_spcr_val &= ~SPCR_RFIE_BIT; /* disable RFI */
  268. /* reset rx threshold */
  269. reg_spcr_val &= ~MASK_RFIC_SPCR_BITS;
  270. reg_spcr_val |= (PCH_RX_THOLD_MAX << SPCR_RFIC_FIELD);
  271. iowrite32(reg_spcr_val, (io_remap_addr + PCH_SPCR));
  272. }
  273. /* update counts */
  274. data->tx_index = tx_index;
  275. data->rx_index = rx_index;
  276. /* if transfer complete interrupt */
  277. if (reg_spsr_val & SPSR_FI_BIT) {
  278. if ((tx_index == bpw_len) && (rx_index == tx_index)) {
  279. /* disable interrupts */
  280. pch_spi_setclr_reg(data->master, PCH_SPCR, 0,
  281. PCH_ALL);
  282. /* transfer is completed;
  283. inform pch_spi_process_messages */
  284. data->transfer_complete = true;
  285. data->transfer_active = false;
  286. wake_up(&data->wait);
  287. } else {
  288. dev_vdbg(&data->master->dev,
  289. "%s : Transfer is not completed",
  290. __func__);
  291. }
  292. }
  293. }
  294. }
  295. /**
  296. * pch_spi_handler() - Interrupt handler
  297. * @irq: The interrupt number.
  298. * @dev_id: Pointer to struct pch_spi_board_data.
  299. */
  300. static irqreturn_t pch_spi_handler(int irq, void *dev_id)
  301. {
  302. u32 reg_spsr_val;
  303. void __iomem *spsr;
  304. void __iomem *io_remap_addr;
  305. irqreturn_t ret = IRQ_NONE;
  306. struct pch_spi_data *data = dev_id;
  307. struct pch_spi_board_data *board_dat = data->board_dat;
  308. if (board_dat->suspend_sts) {
  309. dev_dbg(&board_dat->pdev->dev,
  310. "%s returning due to suspend\n", __func__);
  311. return IRQ_NONE;
  312. }
  313. io_remap_addr = data->io_remap_addr;
  314. spsr = io_remap_addr + PCH_SPSR;
  315. reg_spsr_val = ioread32(spsr);
  316. if (reg_spsr_val & SPSR_ORF_BIT) {
  317. dev_err(&board_dat->pdev->dev, "%s Over run error\n", __func__);
  318. if (data->current_msg->complete) {
  319. data->transfer_complete = true;
  320. data->current_msg->status = -EIO;
  321. data->current_msg->complete(data->current_msg->context);
  322. data->bcurrent_msg_processing = false;
  323. data->current_msg = NULL;
  324. data->cur_trans = NULL;
  325. }
  326. }
  327. if (data->use_dma)
  328. return IRQ_NONE;
  329. /* Check if the interrupt is for SPI device */
  330. if (reg_spsr_val & (SPSR_FI_BIT | SPSR_RFI_BIT)) {
  331. pch_spi_handler_sub(data, reg_spsr_val, io_remap_addr);
  332. ret = IRQ_HANDLED;
  333. }
  334. dev_dbg(&board_dat->pdev->dev, "%s EXIT return value=%d\n",
  335. __func__, ret);
  336. return ret;
  337. }
  338. /**
  339. * pch_spi_set_baud_rate() - Sets SPBR field in SPBRR
  340. * @master: Pointer to struct spi_master.
  341. * @speed_hz: Baud rate.
  342. */
  343. static void pch_spi_set_baud_rate(struct spi_master *master, u32 speed_hz)
  344. {
  345. u32 n_spbr = PCH_CLOCK_HZ / (speed_hz * 2);
  346. /* if baud rate is less than we can support limit it */
  347. if (n_spbr > PCH_MAX_SPBR)
  348. n_spbr = PCH_MAX_SPBR;
  349. pch_spi_setclr_reg(master, PCH_SPBRR, n_spbr, MASK_SPBRR_SPBR_BITS);
  350. }
  351. /**
  352. * pch_spi_set_bits_per_word() - Sets SIZE field in SPBRR
  353. * @master: Pointer to struct spi_master.
  354. * @bits_per_word: Bits per word for SPI transfer.
  355. */
  356. static void pch_spi_set_bits_per_word(struct spi_master *master,
  357. u8 bits_per_word)
  358. {
  359. if (bits_per_word == 8)
  360. pch_spi_setclr_reg(master, PCH_SPBRR, 0, SPBRR_SIZE_BIT);
  361. else
  362. pch_spi_setclr_reg(master, PCH_SPBRR, SPBRR_SIZE_BIT, 0);
  363. }
  364. /**
  365. * pch_spi_setup_transfer() - Configures the PCH SPI hardware for transfer
  366. * @spi: Pointer to struct spi_device.
  367. */
  368. static void pch_spi_setup_transfer(struct spi_device *spi)
  369. {
  370. u32 flags = 0;
  371. dev_dbg(&spi->dev, "%s SPBRR content =%x setting baud rate=%d\n",
  372. __func__, pch_spi_readreg(spi->master, PCH_SPBRR),
  373. spi->max_speed_hz);
  374. pch_spi_set_baud_rate(spi->master, spi->max_speed_hz);
  375. /* set bits per word */
  376. pch_spi_set_bits_per_word(spi->master, spi->bits_per_word);
  377. if (!(spi->mode & SPI_LSB_FIRST))
  378. flags |= SPCR_LSBF_BIT;
  379. if (spi->mode & SPI_CPOL)
  380. flags |= SPCR_CPOL_BIT;
  381. if (spi->mode & SPI_CPHA)
  382. flags |= SPCR_CPHA_BIT;
  383. pch_spi_setclr_reg(spi->master, PCH_SPCR, flags,
  384. (SPCR_LSBF_BIT | SPCR_CPOL_BIT | SPCR_CPHA_BIT));
  385. /* Clear the FIFO by toggling FICLR to 1 and back to 0 */
  386. pch_spi_clear_fifo(spi->master);
  387. }
  388. /**
  389. * pch_spi_reset() - Clears SPI registers
  390. * @master: Pointer to struct spi_master.
  391. */
  392. static void pch_spi_reset(struct spi_master *master)
  393. {
  394. /* write 1 to reset SPI */
  395. pch_spi_writereg(master, PCH_SRST, 0x1);
  396. /* clear reset */
  397. pch_spi_writereg(master, PCH_SRST, 0x0);
  398. }
  399. static int pch_spi_transfer(struct spi_device *pspi, struct spi_message *pmsg)
  400. {
  401. struct spi_transfer *transfer;
  402. struct pch_spi_data *data = spi_master_get_devdata(pspi->master);
  403. int retval;
  404. unsigned long flags;
  405. spin_lock_irqsave(&data->lock, flags);
  406. /* validate Tx/Rx buffers and Transfer length */
  407. list_for_each_entry(transfer, &pmsg->transfers, transfer_list) {
  408. if (!transfer->tx_buf && !transfer->rx_buf) {
  409. dev_err(&pspi->dev,
  410. "%s Tx and Rx buffer NULL\n", __func__);
  411. retval = -EINVAL;
  412. goto err_return_spinlock;
  413. }
  414. if (!transfer->len) {
  415. dev_err(&pspi->dev, "%s Transfer length invalid\n",
  416. __func__);
  417. retval = -EINVAL;
  418. goto err_return_spinlock;
  419. }
  420. dev_dbg(&pspi->dev,
  421. "%s Tx/Rx buffer valid. Transfer length valid\n",
  422. __func__);
  423. }
  424. spin_unlock_irqrestore(&data->lock, flags);
  425. /* We won't process any messages if we have been asked to terminate */
  426. if (data->status == STATUS_EXITING) {
  427. dev_err(&pspi->dev, "%s status = STATUS_EXITING.\n", __func__);
  428. retval = -ESHUTDOWN;
  429. goto err_out;
  430. }
  431. /* If suspended ,return -EINVAL */
  432. if (data->board_dat->suspend_sts) {
  433. dev_err(&pspi->dev, "%s suspend; returning EINVAL\n", __func__);
  434. retval = -EINVAL;
  435. goto err_out;
  436. }
  437. /* set status of message */
  438. pmsg->actual_length = 0;
  439. dev_dbg(&pspi->dev, "%s - pmsg->status =%d\n", __func__, pmsg->status);
  440. pmsg->status = -EINPROGRESS;
  441. spin_lock_irqsave(&data->lock, flags);
  442. /* add message to queue */
  443. list_add_tail(&pmsg->queue, &data->queue);
  444. spin_unlock_irqrestore(&data->lock, flags);
  445. dev_dbg(&pspi->dev, "%s - Invoked list_add_tail\n", __func__);
  446. schedule_work(&data->work);
  447. dev_dbg(&pspi->dev, "%s - Invoked queue work\n", __func__);
  448. retval = 0;
  449. err_out:
  450. dev_dbg(&pspi->dev, "%s RETURN=%d\n", __func__, retval);
  451. return retval;
  452. err_return_spinlock:
  453. dev_dbg(&pspi->dev, "%s RETURN=%d\n", __func__, retval);
  454. spin_unlock_irqrestore(&data->lock, flags);
  455. return retval;
  456. }
  457. static inline void pch_spi_select_chip(struct pch_spi_data *data,
  458. struct spi_device *pspi)
  459. {
  460. if (data->current_chip != NULL) {
  461. if (pspi->chip_select != data->n_curnt_chip) {
  462. dev_dbg(&pspi->dev, "%s : different slave\n", __func__);
  463. data->current_chip = NULL;
  464. }
  465. }
  466. data->current_chip = pspi;
  467. data->n_curnt_chip = data->current_chip->chip_select;
  468. dev_dbg(&pspi->dev, "%s :Invoking pch_spi_setup_transfer\n", __func__);
  469. pch_spi_setup_transfer(pspi);
  470. }
  471. static void pch_spi_set_tx(struct pch_spi_data *data, int *bpw)
  472. {
  473. int size;
  474. u32 n_writes;
  475. int j;
  476. struct spi_message *pmsg, *tmp;
  477. const u8 *tx_buf;
  478. const u16 *tx_sbuf;
  479. /* set baud rate if needed */
  480. if (data->cur_trans->speed_hz) {
  481. dev_dbg(&data->master->dev, "%s:setting baud rate\n", __func__);
  482. pch_spi_set_baud_rate(data->master, data->cur_trans->speed_hz);
  483. }
  484. /* set bits per word if needed */
  485. if (data->cur_trans->bits_per_word &&
  486. (data->current_msg->spi->bits_per_word != data->cur_trans->bits_per_word)) {
  487. dev_dbg(&data->master->dev, "%s:set bits per word\n", __func__);
  488. pch_spi_set_bits_per_word(data->master,
  489. data->cur_trans->bits_per_word);
  490. *bpw = data->cur_trans->bits_per_word;
  491. } else {
  492. *bpw = data->current_msg->spi->bits_per_word;
  493. }
  494. /* reset Tx/Rx index */
  495. data->tx_index = 0;
  496. data->rx_index = 0;
  497. data->bpw_len = data->cur_trans->len / (*bpw / 8);
  498. /* find alloc size */
  499. size = data->cur_trans->len * sizeof(*data->pkt_tx_buff);
  500. /* allocate memory for pkt_tx_buff & pkt_rx_buffer */
  501. data->pkt_tx_buff = kzalloc(size, GFP_KERNEL);
  502. if (data->pkt_tx_buff != NULL) {
  503. data->pkt_rx_buff = kzalloc(size, GFP_KERNEL);
  504. if (!data->pkt_rx_buff)
  505. kfree(data->pkt_tx_buff);
  506. }
  507. if (!data->pkt_rx_buff) {
  508. /* flush queue and set status of all transfers to -ENOMEM */
  509. list_for_each_entry_safe(pmsg, tmp, data->queue.next, queue) {
  510. pmsg->status = -ENOMEM;
  511. if (pmsg->complete)
  512. pmsg->complete(pmsg->context);
  513. /* delete from queue */
  514. list_del_init(&pmsg->queue);
  515. }
  516. return;
  517. }
  518. /* copy Tx Data */
  519. if (data->cur_trans->tx_buf != NULL) {
  520. if (*bpw == 8) {
  521. tx_buf = data->cur_trans->tx_buf;
  522. for (j = 0; j < data->bpw_len; j++)
  523. data->pkt_tx_buff[j] = *tx_buf++;
  524. } else {
  525. tx_sbuf = data->cur_trans->tx_buf;
  526. for (j = 0; j < data->bpw_len; j++)
  527. data->pkt_tx_buff[j] = *tx_sbuf++;
  528. }
  529. }
  530. /* if len greater than PCH_MAX_FIFO_DEPTH, write 16,else len bytes */
  531. n_writes = data->bpw_len;
  532. if (n_writes > PCH_MAX_FIFO_DEPTH)
  533. n_writes = PCH_MAX_FIFO_DEPTH;
  534. dev_dbg(&data->master->dev,
  535. "\n%s:Pulling down SSN low - writing 0x2 to SSNXCR\n",
  536. __func__);
  537. pch_spi_writereg(data->master, PCH_SSNXCR, SSN_LOW);
  538. for (j = 0; j < n_writes; j++)
  539. pch_spi_writereg(data->master, PCH_SPDWR, data->pkt_tx_buff[j]);
  540. /* update tx_index */
  541. data->tx_index = j;
  542. /* reset transfer complete flag */
  543. data->transfer_complete = false;
  544. data->transfer_active = true;
  545. }
  546. static void pch_spi_nomore_transfer(struct pch_spi_data *data)
  547. {
  548. struct spi_message *pmsg, *tmp;
  549. dev_dbg(&data->master->dev, "%s called\n", __func__);
  550. /* Invoke complete callback
  551. * [To the spi core..indicating end of transfer] */
  552. data->current_msg->status = 0;
  553. if (data->current_msg->complete) {
  554. dev_dbg(&data->master->dev,
  555. "%s:Invoking callback of SPI core\n", __func__);
  556. data->current_msg->complete(data->current_msg->context);
  557. }
  558. /* update status in global variable */
  559. data->bcurrent_msg_processing = false;
  560. dev_dbg(&data->master->dev,
  561. "%s:data->bcurrent_msg_processing = false\n", __func__);
  562. data->current_msg = NULL;
  563. data->cur_trans = NULL;
  564. /* check if we have items in list and not suspending
  565. * return 1 if list empty */
  566. if ((list_empty(&data->queue) == 0) &&
  567. (!data->board_dat->suspend_sts) &&
  568. (data->status != STATUS_EXITING)) {
  569. /* We have some more work to do (either there is more tranint
  570. * bpw;sfer requests in the current message or there are
  571. *more messages)
  572. */
  573. dev_dbg(&data->master->dev, "%s:Invoke queue_work\n", __func__);
  574. schedule_work(&data->work);
  575. } else if (data->board_dat->suspend_sts ||
  576. data->status == STATUS_EXITING) {
  577. dev_dbg(&data->master->dev,
  578. "%s suspend/remove initiated, flushing queue\n",
  579. __func__);
  580. list_for_each_entry_safe(pmsg, tmp, data->queue.next, queue) {
  581. pmsg->status = -EIO;
  582. if (pmsg->complete)
  583. pmsg->complete(pmsg->context);
  584. /* delete from queue */
  585. list_del_init(&pmsg->queue);
  586. }
  587. }
  588. }
  589. static void pch_spi_set_ir(struct pch_spi_data *data)
  590. {
  591. /* enable interrupts, set threshold, enable SPI */
  592. if ((data->bpw_len) > PCH_MAX_FIFO_DEPTH)
  593. /* set receive threshold to PCH_RX_THOLD */
  594. pch_spi_setclr_reg(data->master, PCH_SPCR,
  595. PCH_RX_THOLD << SPCR_RFIC_FIELD |
  596. SPCR_FIE_BIT | SPCR_RFIE_BIT |
  597. SPCR_ORIE_BIT | SPCR_SPE_BIT,
  598. MASK_RFIC_SPCR_BITS | PCH_ALL);
  599. else
  600. /* set receive threshold to maximum */
  601. pch_spi_setclr_reg(data->master, PCH_SPCR,
  602. PCH_RX_THOLD_MAX << SPCR_RFIC_FIELD |
  603. SPCR_FIE_BIT | SPCR_ORIE_BIT |
  604. SPCR_SPE_BIT,
  605. MASK_RFIC_SPCR_BITS | PCH_ALL);
  606. /* Wait until the transfer completes; go to sleep after
  607. initiating the transfer. */
  608. dev_dbg(&data->master->dev,
  609. "%s:waiting for transfer to get over\n", __func__);
  610. wait_event_interruptible(data->wait, data->transfer_complete);
  611. /* clear all interrupts */
  612. pch_spi_writereg(data->master, PCH_SPSR,
  613. pch_spi_readreg(data->master, PCH_SPSR));
  614. /* Disable interrupts and SPI transfer */
  615. pch_spi_setclr_reg(data->master, PCH_SPCR, 0, PCH_ALL | SPCR_SPE_BIT);
  616. /* clear FIFO */
  617. pch_spi_clear_fifo(data->master);
  618. }
  619. static void pch_spi_copy_rx_data(struct pch_spi_data *data, int bpw)
  620. {
  621. int j;
  622. u8 *rx_buf;
  623. u16 *rx_sbuf;
  624. /* copy Rx Data */
  625. if (!data->cur_trans->rx_buf)
  626. return;
  627. if (bpw == 8) {
  628. rx_buf = data->cur_trans->rx_buf;
  629. for (j = 0; j < data->bpw_len; j++)
  630. *rx_buf++ = data->pkt_rx_buff[j] & 0xFF;
  631. } else {
  632. rx_sbuf = data->cur_trans->rx_buf;
  633. for (j = 0; j < data->bpw_len; j++)
  634. *rx_sbuf++ = data->pkt_rx_buff[j];
  635. }
  636. }
  637. static void pch_spi_copy_rx_data_for_dma(struct pch_spi_data *data, int bpw)
  638. {
  639. int j;
  640. u8 *rx_buf;
  641. u16 *rx_sbuf;
  642. const u8 *rx_dma_buf;
  643. const u16 *rx_dma_sbuf;
  644. /* copy Rx Data */
  645. if (!data->cur_trans->rx_buf)
  646. return;
  647. if (bpw == 8) {
  648. rx_buf = data->cur_trans->rx_buf;
  649. rx_dma_buf = data->dma.rx_buf_virt;
  650. for (j = 0; j < data->bpw_len; j++)
  651. *rx_buf++ = *rx_dma_buf++ & 0xFF;
  652. data->cur_trans->rx_buf = rx_buf;
  653. } else {
  654. rx_sbuf = data->cur_trans->rx_buf;
  655. rx_dma_sbuf = data->dma.rx_buf_virt;
  656. for (j = 0; j < data->bpw_len; j++)
  657. *rx_sbuf++ = *rx_dma_sbuf++;
  658. data->cur_trans->rx_buf = rx_sbuf;
  659. }
  660. }
  661. static int pch_spi_start_transfer(struct pch_spi_data *data)
  662. {
  663. struct pch_spi_dma_ctrl *dma;
  664. unsigned long flags;
  665. int rtn;
  666. dma = &data->dma;
  667. spin_lock_irqsave(&data->lock, flags);
  668. /* disable interrupts, SPI set enable */
  669. pch_spi_setclr_reg(data->master, PCH_SPCR, SPCR_SPE_BIT, PCH_ALL);
  670. spin_unlock_irqrestore(&data->lock, flags);
  671. /* Wait until the transfer completes; go to sleep after
  672. initiating the transfer. */
  673. dev_dbg(&data->master->dev,
  674. "%s:waiting for transfer to get over\n", __func__);
  675. rtn = wait_event_interruptible_timeout(data->wait,
  676. data->transfer_complete,
  677. msecs_to_jiffies(2 * HZ));
  678. if (!rtn)
  679. dev_err(&data->master->dev,
  680. "%s wait-event timeout\n", __func__);
  681. dma_sync_sg_for_cpu(&data->master->dev, dma->sg_rx_p, dma->nent,
  682. DMA_FROM_DEVICE);
  683. dma_sync_sg_for_cpu(&data->master->dev, dma->sg_tx_p, dma->nent,
  684. DMA_FROM_DEVICE);
  685. memset(data->dma.tx_buf_virt, 0, PAGE_SIZE);
  686. async_tx_ack(dma->desc_rx);
  687. async_tx_ack(dma->desc_tx);
  688. kfree(dma->sg_tx_p);
  689. kfree(dma->sg_rx_p);
  690. spin_lock_irqsave(&data->lock, flags);
  691. /* clear fifo threshold, disable interrupts, disable SPI transfer */
  692. pch_spi_setclr_reg(data->master, PCH_SPCR, 0,
  693. MASK_RFIC_SPCR_BITS | MASK_TFIC_SPCR_BITS | PCH_ALL |
  694. SPCR_SPE_BIT);
  695. /* clear all interrupts */
  696. pch_spi_writereg(data->master, PCH_SPSR,
  697. pch_spi_readreg(data->master, PCH_SPSR));
  698. /* clear FIFO */
  699. pch_spi_clear_fifo(data->master);
  700. spin_unlock_irqrestore(&data->lock, flags);
  701. return rtn;
  702. }
  703. static void pch_dma_rx_complete(void *arg)
  704. {
  705. struct pch_spi_data *data = arg;
  706. /* transfer is completed;inform pch_spi_process_messages_dma */
  707. data->transfer_complete = true;
  708. wake_up_interruptible(&data->wait);
  709. }
  710. static bool pch_spi_filter(struct dma_chan *chan, void *slave)
  711. {
  712. struct pch_dma_slave *param = slave;
  713. if ((chan->chan_id == param->chan_id) &&
  714. (param->dma_dev == chan->device->dev)) {
  715. chan->private = param;
  716. return true;
  717. } else {
  718. return false;
  719. }
  720. }
  721. static void pch_spi_request_dma(struct pch_spi_data *data, int bpw)
  722. {
  723. dma_cap_mask_t mask;
  724. struct dma_chan *chan;
  725. struct pci_dev *dma_dev;
  726. struct pch_dma_slave *param;
  727. struct pch_spi_dma_ctrl *dma;
  728. unsigned int width;
  729. if (bpw == 8)
  730. width = PCH_DMA_WIDTH_1_BYTE;
  731. else
  732. width = PCH_DMA_WIDTH_2_BYTES;
  733. dma = &data->dma;
  734. dma_cap_zero(mask);
  735. dma_cap_set(DMA_SLAVE, mask);
  736. /* Get DMA's dev information */
  737. dma_dev = pci_get_slot(data->board_dat->pdev->bus,
  738. PCI_DEVFN(PCI_SLOT(data->board_dat->pdev->devfn), 0));
  739. /* Set Tx DMA */
  740. param = &dma->param_tx;
  741. param->dma_dev = &dma_dev->dev;
  742. param->chan_id = data->ch * 2; /* Tx = 0, 2 */;
  743. param->tx_reg = data->io_base_addr + PCH_SPDWR;
  744. param->width = width;
  745. chan = dma_request_channel(mask, pch_spi_filter, param);
  746. if (!chan) {
  747. dev_err(&data->master->dev,
  748. "ERROR: dma_request_channel FAILS(Tx)\n");
  749. data->use_dma = 0;
  750. return;
  751. }
  752. dma->chan_tx = chan;
  753. /* Set Rx DMA */
  754. param = &dma->param_rx;
  755. param->dma_dev = &dma_dev->dev;
  756. param->chan_id = data->ch * 2 + 1; /* Rx = Tx + 1 */;
  757. param->rx_reg = data->io_base_addr + PCH_SPDRR;
  758. param->width = width;
  759. chan = dma_request_channel(mask, pch_spi_filter, param);
  760. if (!chan) {
  761. dev_err(&data->master->dev,
  762. "ERROR: dma_request_channel FAILS(Rx)\n");
  763. dma_release_channel(dma->chan_tx);
  764. dma->chan_tx = NULL;
  765. data->use_dma = 0;
  766. return;
  767. }
  768. dma->chan_rx = chan;
  769. }
  770. static void pch_spi_release_dma(struct pch_spi_data *data)
  771. {
  772. struct pch_spi_dma_ctrl *dma;
  773. dma = &data->dma;
  774. if (dma->chan_tx) {
  775. dma_release_channel(dma->chan_tx);
  776. dma->chan_tx = NULL;
  777. }
  778. if (dma->chan_rx) {
  779. dma_release_channel(dma->chan_rx);
  780. dma->chan_rx = NULL;
  781. }
  782. }
  783. static void pch_spi_handle_dma(struct pch_spi_data *data, int *bpw)
  784. {
  785. const u8 *tx_buf;
  786. const u16 *tx_sbuf;
  787. u8 *tx_dma_buf;
  788. u16 *tx_dma_sbuf;
  789. struct scatterlist *sg;
  790. struct dma_async_tx_descriptor *desc_tx;
  791. struct dma_async_tx_descriptor *desc_rx;
  792. int num;
  793. int i;
  794. int size;
  795. int rem;
  796. int head;
  797. unsigned long flags;
  798. struct pch_spi_dma_ctrl *dma;
  799. dma = &data->dma;
  800. /* set baud rate if needed */
  801. if (data->cur_trans->speed_hz) {
  802. dev_dbg(&data->master->dev, "%s:setting baud rate\n", __func__);
  803. spin_lock_irqsave(&data->lock, flags);
  804. pch_spi_set_baud_rate(data->master, data->cur_trans->speed_hz);
  805. spin_unlock_irqrestore(&data->lock, flags);
  806. }
  807. /* set bits per word if needed */
  808. if (data->cur_trans->bits_per_word &&
  809. (data->current_msg->spi->bits_per_word !=
  810. data->cur_trans->bits_per_word)) {
  811. dev_dbg(&data->master->dev, "%s:set bits per word\n", __func__);
  812. spin_lock_irqsave(&data->lock, flags);
  813. pch_spi_set_bits_per_word(data->master,
  814. data->cur_trans->bits_per_word);
  815. spin_unlock_irqrestore(&data->lock, flags);
  816. *bpw = data->cur_trans->bits_per_word;
  817. } else {
  818. *bpw = data->current_msg->spi->bits_per_word;
  819. }
  820. data->bpw_len = data->cur_trans->len / (*bpw / 8);
  821. if (data->bpw_len > PCH_BUF_SIZE) {
  822. data->bpw_len = PCH_BUF_SIZE;
  823. data->cur_trans->len -= PCH_BUF_SIZE;
  824. }
  825. /* copy Tx Data */
  826. if (data->cur_trans->tx_buf != NULL) {
  827. if (*bpw == 8) {
  828. tx_buf = data->cur_trans->tx_buf;
  829. tx_dma_buf = dma->tx_buf_virt;
  830. for (i = 0; i < data->bpw_len; i++)
  831. *tx_dma_buf++ = *tx_buf++;
  832. } else {
  833. tx_sbuf = data->cur_trans->tx_buf;
  834. tx_dma_sbuf = dma->tx_buf_virt;
  835. for (i = 0; i < data->bpw_len; i++)
  836. *tx_dma_sbuf++ = *tx_sbuf++;
  837. }
  838. }
  839. /* Calculate Rx parameter for DMA transmitting */
  840. if (data->bpw_len > PCH_DMA_TRANS_SIZE) {
  841. if (data->bpw_len % PCH_DMA_TRANS_SIZE) {
  842. num = data->bpw_len / PCH_DMA_TRANS_SIZE + 1;
  843. rem = data->bpw_len % PCH_DMA_TRANS_SIZE;
  844. } else {
  845. num = data->bpw_len / PCH_DMA_TRANS_SIZE;
  846. rem = PCH_DMA_TRANS_SIZE;
  847. }
  848. size = PCH_DMA_TRANS_SIZE;
  849. } else {
  850. num = 1;
  851. size = data->bpw_len;
  852. rem = data->bpw_len;
  853. }
  854. dev_dbg(&data->master->dev, "%s num=%d size=%d rem=%d\n",
  855. __func__, num, size, rem);
  856. spin_lock_irqsave(&data->lock, flags);
  857. /* set receive fifo threshold and transmit fifo threshold */
  858. pch_spi_setclr_reg(data->master, PCH_SPCR,
  859. ((size - 1) << SPCR_RFIC_FIELD) |
  860. (PCH_TX_THOLD << SPCR_TFIC_FIELD),
  861. MASK_RFIC_SPCR_BITS | MASK_TFIC_SPCR_BITS);
  862. spin_unlock_irqrestore(&data->lock, flags);
  863. /* RX */
  864. dma->sg_rx_p = kcalloc(num, sizeof(*dma->sg_rx_p), GFP_ATOMIC);
  865. if (!dma->sg_rx_p)
  866. return;
  867. sg_init_table(dma->sg_rx_p, num); /* Initialize SG table */
  868. /* offset, length setting */
  869. sg = dma->sg_rx_p;
  870. for (i = 0; i < num; i++, sg++) {
  871. if (i == (num - 2)) {
  872. sg->offset = size * i;
  873. sg->offset = sg->offset * (*bpw / 8);
  874. sg_set_page(sg, virt_to_page(dma->rx_buf_virt), rem,
  875. sg->offset);
  876. sg_dma_len(sg) = rem;
  877. } else if (i == (num - 1)) {
  878. sg->offset = size * (i - 1) + rem;
  879. sg->offset = sg->offset * (*bpw / 8);
  880. sg_set_page(sg, virt_to_page(dma->rx_buf_virt), size,
  881. sg->offset);
  882. sg_dma_len(sg) = size;
  883. } else {
  884. sg->offset = size * i;
  885. sg->offset = sg->offset * (*bpw / 8);
  886. sg_set_page(sg, virt_to_page(dma->rx_buf_virt), size,
  887. sg->offset);
  888. sg_dma_len(sg) = size;
  889. }
  890. sg_dma_address(sg) = dma->rx_buf_dma + sg->offset;
  891. }
  892. sg = dma->sg_rx_p;
  893. desc_rx = dmaengine_prep_slave_sg(dma->chan_rx, sg,
  894. num, DMA_DEV_TO_MEM,
  895. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  896. if (!desc_rx) {
  897. dev_err(&data->master->dev,
  898. "%s:dmaengine_prep_slave_sg Failed\n", __func__);
  899. return;
  900. }
  901. dma_sync_sg_for_device(&data->master->dev, sg, num, DMA_FROM_DEVICE);
  902. desc_rx->callback = pch_dma_rx_complete;
  903. desc_rx->callback_param = data;
  904. dma->nent = num;
  905. dma->desc_rx = desc_rx;
  906. /* Calculate Tx parameter for DMA transmitting */
  907. if (data->bpw_len > PCH_MAX_FIFO_DEPTH) {
  908. head = PCH_MAX_FIFO_DEPTH - PCH_DMA_TRANS_SIZE;
  909. if (data->bpw_len % PCH_DMA_TRANS_SIZE > 4) {
  910. num = data->bpw_len / PCH_DMA_TRANS_SIZE + 1;
  911. rem = data->bpw_len % PCH_DMA_TRANS_SIZE - head;
  912. } else {
  913. num = data->bpw_len / PCH_DMA_TRANS_SIZE;
  914. rem = data->bpw_len % PCH_DMA_TRANS_SIZE +
  915. PCH_DMA_TRANS_SIZE - head;
  916. }
  917. size = PCH_DMA_TRANS_SIZE;
  918. } else {
  919. num = 1;
  920. size = data->bpw_len;
  921. rem = data->bpw_len;
  922. head = 0;
  923. }
  924. dma->sg_tx_p = kcalloc(num, sizeof(*dma->sg_tx_p), GFP_ATOMIC);
  925. if (!dma->sg_tx_p)
  926. return;
  927. sg_init_table(dma->sg_tx_p, num); /* Initialize SG table */
  928. /* offset, length setting */
  929. sg = dma->sg_tx_p;
  930. for (i = 0; i < num; i++, sg++) {
  931. if (i == 0) {
  932. sg->offset = 0;
  933. sg_set_page(sg, virt_to_page(dma->tx_buf_virt), size + head,
  934. sg->offset);
  935. sg_dma_len(sg) = size + head;
  936. } else if (i == (num - 1)) {
  937. sg->offset = head + size * i;
  938. sg->offset = sg->offset * (*bpw / 8);
  939. sg_set_page(sg, virt_to_page(dma->tx_buf_virt), rem,
  940. sg->offset);
  941. sg_dma_len(sg) = rem;
  942. } else {
  943. sg->offset = head + size * i;
  944. sg->offset = sg->offset * (*bpw / 8);
  945. sg_set_page(sg, virt_to_page(dma->tx_buf_virt), size,
  946. sg->offset);
  947. sg_dma_len(sg) = size;
  948. }
  949. sg_dma_address(sg) = dma->tx_buf_dma + sg->offset;
  950. }
  951. sg = dma->sg_tx_p;
  952. desc_tx = dmaengine_prep_slave_sg(dma->chan_tx,
  953. sg, num, DMA_MEM_TO_DEV,
  954. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  955. if (!desc_tx) {
  956. dev_err(&data->master->dev,
  957. "%s:dmaengine_prep_slave_sg Failed\n", __func__);
  958. return;
  959. }
  960. dma_sync_sg_for_device(&data->master->dev, sg, num, DMA_TO_DEVICE);
  961. desc_tx->callback = NULL;
  962. desc_tx->callback_param = data;
  963. dma->nent = num;
  964. dma->desc_tx = desc_tx;
  965. dev_dbg(&data->master->dev, "%s:Pulling down SSN low - writing 0x2 to SSNXCR\n", __func__);
  966. spin_lock_irqsave(&data->lock, flags);
  967. pch_spi_writereg(data->master, PCH_SSNXCR, SSN_LOW);
  968. desc_rx->tx_submit(desc_rx);
  969. desc_tx->tx_submit(desc_tx);
  970. spin_unlock_irqrestore(&data->lock, flags);
  971. /* reset transfer complete flag */
  972. data->transfer_complete = false;
  973. }
  974. static void pch_spi_process_messages(struct work_struct *pwork)
  975. {
  976. struct spi_message *pmsg, *tmp;
  977. struct pch_spi_data *data;
  978. int bpw;
  979. data = container_of(pwork, struct pch_spi_data, work);
  980. dev_dbg(&data->master->dev, "%s data initialized\n", __func__);
  981. spin_lock(&data->lock);
  982. /* check if suspend has been initiated;if yes flush queue */
  983. if (data->board_dat->suspend_sts || (data->status == STATUS_EXITING)) {
  984. dev_dbg(&data->master->dev,
  985. "%s suspend/remove initiated, flushing queue\n", __func__);
  986. list_for_each_entry_safe(pmsg, tmp, data->queue.next, queue) {
  987. pmsg->status = -EIO;
  988. if (pmsg->complete) {
  989. spin_unlock(&data->lock);
  990. pmsg->complete(pmsg->context);
  991. spin_lock(&data->lock);
  992. }
  993. /* delete from queue */
  994. list_del_init(&pmsg->queue);
  995. }
  996. spin_unlock(&data->lock);
  997. return;
  998. }
  999. data->bcurrent_msg_processing = true;
  1000. dev_dbg(&data->master->dev,
  1001. "%s Set data->bcurrent_msg_processing= true\n", __func__);
  1002. /* Get the message from the queue and delete it from there. */
  1003. data->current_msg = list_entry(data->queue.next, struct spi_message,
  1004. queue);
  1005. list_del_init(&data->current_msg->queue);
  1006. data->current_msg->status = 0;
  1007. pch_spi_select_chip(data, data->current_msg->spi);
  1008. spin_unlock(&data->lock);
  1009. if (data->use_dma)
  1010. pch_spi_request_dma(data,
  1011. data->current_msg->spi->bits_per_word);
  1012. pch_spi_writereg(data->master, PCH_SSNXCR, SSN_NO_CONTROL);
  1013. do {
  1014. int cnt;
  1015. /* If we are already processing a message get the next
  1016. transfer structure from the message otherwise retrieve
  1017. the 1st transfer request from the message. */
  1018. spin_lock(&data->lock);
  1019. if (data->cur_trans == NULL) {
  1020. data->cur_trans =
  1021. list_entry(data->current_msg->transfers.next,
  1022. struct spi_transfer, transfer_list);
  1023. dev_dbg(&data->master->dev,
  1024. "%s :Getting 1st transfer message\n",
  1025. __func__);
  1026. } else {
  1027. data->cur_trans =
  1028. list_entry(data->cur_trans->transfer_list.next,
  1029. struct spi_transfer, transfer_list);
  1030. dev_dbg(&data->master->dev,
  1031. "%s :Getting next transfer message\n",
  1032. __func__);
  1033. }
  1034. spin_unlock(&data->lock);
  1035. if (!data->cur_trans->len)
  1036. goto out;
  1037. cnt = (data->cur_trans->len - 1) / PCH_BUF_SIZE + 1;
  1038. data->save_total_len = data->cur_trans->len;
  1039. if (data->use_dma) {
  1040. int i;
  1041. char *save_rx_buf = data->cur_trans->rx_buf;
  1042. for (i = 0; i < cnt; i ++) {
  1043. pch_spi_handle_dma(data, &bpw);
  1044. if (!pch_spi_start_transfer(data)) {
  1045. data->transfer_complete = true;
  1046. data->current_msg->status = -EIO;
  1047. data->current_msg->complete
  1048. (data->current_msg->context);
  1049. data->bcurrent_msg_processing = false;
  1050. data->current_msg = NULL;
  1051. data->cur_trans = NULL;
  1052. goto out;
  1053. }
  1054. pch_spi_copy_rx_data_for_dma(data, bpw);
  1055. }
  1056. data->cur_trans->rx_buf = save_rx_buf;
  1057. } else {
  1058. pch_spi_set_tx(data, &bpw);
  1059. pch_spi_set_ir(data);
  1060. pch_spi_copy_rx_data(data, bpw);
  1061. kfree(data->pkt_rx_buff);
  1062. data->pkt_rx_buff = NULL;
  1063. kfree(data->pkt_tx_buff);
  1064. data->pkt_tx_buff = NULL;
  1065. }
  1066. /* increment message count */
  1067. data->cur_trans->len = data->save_total_len;
  1068. data->current_msg->actual_length += data->cur_trans->len;
  1069. dev_dbg(&data->master->dev,
  1070. "%s:data->current_msg->actual_length=%d\n",
  1071. __func__, data->current_msg->actual_length);
  1072. /* check for delay */
  1073. if (data->cur_trans->delay_usecs) {
  1074. dev_dbg(&data->master->dev, "%s:delay in usec=%d\n",
  1075. __func__, data->cur_trans->delay_usecs);
  1076. udelay(data->cur_trans->delay_usecs);
  1077. }
  1078. spin_lock(&data->lock);
  1079. /* No more transfer in this message. */
  1080. if ((data->cur_trans->transfer_list.next) ==
  1081. &(data->current_msg->transfers)) {
  1082. pch_spi_nomore_transfer(data);
  1083. }
  1084. spin_unlock(&data->lock);
  1085. } while (data->cur_trans != NULL);
  1086. out:
  1087. pch_spi_writereg(data->master, PCH_SSNXCR, SSN_HIGH);
  1088. if (data->use_dma)
  1089. pch_spi_release_dma(data);
  1090. }
  1091. static void pch_spi_free_resources(struct pch_spi_board_data *board_dat,
  1092. struct pch_spi_data *data)
  1093. {
  1094. dev_dbg(&board_dat->pdev->dev, "%s ENTRY\n", __func__);
  1095. flush_work(&data->work);
  1096. }
  1097. static int pch_spi_get_resources(struct pch_spi_board_data *board_dat,
  1098. struct pch_spi_data *data)
  1099. {
  1100. dev_dbg(&board_dat->pdev->dev, "%s ENTRY\n", __func__);
  1101. /* reset PCH SPI h/w */
  1102. pch_spi_reset(data->master);
  1103. dev_dbg(&board_dat->pdev->dev,
  1104. "%s pch_spi_reset invoked successfully\n", __func__);
  1105. dev_dbg(&board_dat->pdev->dev, "%s data->irq_reg_sts=true\n", __func__);
  1106. return 0;
  1107. }
  1108. static void pch_free_dma_buf(struct pch_spi_board_data *board_dat,
  1109. struct pch_spi_data *data)
  1110. {
  1111. struct pch_spi_dma_ctrl *dma;
  1112. dma = &data->dma;
  1113. if (dma->tx_buf_dma)
  1114. dma_free_coherent(&board_dat->pdev->dev, PCH_BUF_SIZE,
  1115. dma->tx_buf_virt, dma->tx_buf_dma);
  1116. if (dma->rx_buf_dma)
  1117. dma_free_coherent(&board_dat->pdev->dev, PCH_BUF_SIZE,
  1118. dma->rx_buf_virt, dma->rx_buf_dma);
  1119. }
  1120. static int pch_alloc_dma_buf(struct pch_spi_board_data *board_dat,
  1121. struct pch_spi_data *data)
  1122. {
  1123. struct pch_spi_dma_ctrl *dma;
  1124. int ret;
  1125. dma = &data->dma;
  1126. ret = 0;
  1127. /* Get Consistent memory for Tx DMA */
  1128. dma->tx_buf_virt = dma_alloc_coherent(&board_dat->pdev->dev,
  1129. PCH_BUF_SIZE, &dma->tx_buf_dma, GFP_KERNEL);
  1130. if (!dma->tx_buf_virt)
  1131. ret = -ENOMEM;
  1132. /* Get Consistent memory for Rx DMA */
  1133. dma->rx_buf_virt = dma_alloc_coherent(&board_dat->pdev->dev,
  1134. PCH_BUF_SIZE, &dma->rx_buf_dma, GFP_KERNEL);
  1135. if (!dma->rx_buf_virt)
  1136. ret = -ENOMEM;
  1137. return ret;
  1138. }
  1139. static int pch_spi_pd_probe(struct platform_device *plat_dev)
  1140. {
  1141. int ret;
  1142. struct spi_master *master;
  1143. struct pch_spi_board_data *board_dat = dev_get_platdata(&plat_dev->dev);
  1144. struct pch_spi_data *data;
  1145. dev_dbg(&plat_dev->dev, "%s:debug\n", __func__);
  1146. master = spi_alloc_master(&board_dat->pdev->dev,
  1147. sizeof(struct pch_spi_data));
  1148. if (!master) {
  1149. dev_err(&plat_dev->dev, "spi_alloc_master[%d] failed.\n",
  1150. plat_dev->id);
  1151. return -ENOMEM;
  1152. }
  1153. data = spi_master_get_devdata(master);
  1154. data->master = master;
  1155. platform_set_drvdata(plat_dev, data);
  1156. /* baseaddress + address offset) */
  1157. data->io_base_addr = pci_resource_start(board_dat->pdev, 1) +
  1158. PCH_ADDRESS_SIZE * plat_dev->id;
  1159. data->io_remap_addr = pci_iomap(board_dat->pdev, 1, 0);
  1160. if (!data->io_remap_addr) {
  1161. dev_err(&plat_dev->dev, "%s pci_iomap failed\n", __func__);
  1162. ret = -ENOMEM;
  1163. goto err_pci_iomap;
  1164. }
  1165. data->io_remap_addr += PCH_ADDRESS_SIZE * plat_dev->id;
  1166. dev_dbg(&plat_dev->dev, "[ch%d] remap_addr=%p\n",
  1167. plat_dev->id, data->io_remap_addr);
  1168. /* initialize members of SPI master */
  1169. master->num_chipselect = PCH_MAX_CS;
  1170. master->transfer = pch_spi_transfer;
  1171. master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
  1172. master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
  1173. master->max_speed_hz = PCH_MAX_BAUDRATE;
  1174. data->board_dat = board_dat;
  1175. data->plat_dev = plat_dev;
  1176. data->n_curnt_chip = 255;
  1177. data->status = STATUS_RUNNING;
  1178. data->ch = plat_dev->id;
  1179. data->use_dma = use_dma;
  1180. INIT_LIST_HEAD(&data->queue);
  1181. spin_lock_init(&data->lock);
  1182. INIT_WORK(&data->work, pch_spi_process_messages);
  1183. init_waitqueue_head(&data->wait);
  1184. ret = pch_spi_get_resources(board_dat, data);
  1185. if (ret) {
  1186. dev_err(&plat_dev->dev, "%s fail(retval=%d)\n", __func__, ret);
  1187. goto err_spi_get_resources;
  1188. }
  1189. ret = request_irq(board_dat->pdev->irq, pch_spi_handler,
  1190. IRQF_SHARED, KBUILD_MODNAME, data);
  1191. if (ret) {
  1192. dev_err(&plat_dev->dev,
  1193. "%s request_irq failed\n", __func__);
  1194. goto err_request_irq;
  1195. }
  1196. data->irq_reg_sts = true;
  1197. pch_spi_set_master_mode(master);
  1198. if (use_dma) {
  1199. dev_info(&plat_dev->dev, "Use DMA for data transfers\n");
  1200. ret = pch_alloc_dma_buf(board_dat, data);
  1201. if (ret)
  1202. goto err_spi_register_master;
  1203. }
  1204. ret = spi_register_master(master);
  1205. if (ret != 0) {
  1206. dev_err(&plat_dev->dev,
  1207. "%s spi_register_master FAILED\n", __func__);
  1208. goto err_spi_register_master;
  1209. }
  1210. return 0;
  1211. err_spi_register_master:
  1212. pch_free_dma_buf(board_dat, data);
  1213. free_irq(board_dat->pdev->irq, data);
  1214. err_request_irq:
  1215. pch_spi_free_resources(board_dat, data);
  1216. err_spi_get_resources:
  1217. pci_iounmap(board_dat->pdev, data->io_remap_addr);
  1218. err_pci_iomap:
  1219. spi_master_put(master);
  1220. return ret;
  1221. }
  1222. static int pch_spi_pd_remove(struct platform_device *plat_dev)
  1223. {
  1224. struct pch_spi_board_data *board_dat = dev_get_platdata(&plat_dev->dev);
  1225. struct pch_spi_data *data = platform_get_drvdata(plat_dev);
  1226. int count;
  1227. unsigned long flags;
  1228. dev_dbg(&plat_dev->dev, "%s:[ch%d] irq=%d\n",
  1229. __func__, plat_dev->id, board_dat->pdev->irq);
  1230. if (use_dma)
  1231. pch_free_dma_buf(board_dat, data);
  1232. /* check for any pending messages; no action is taken if the queue
  1233. * is still full; but at least we tried. Unload anyway */
  1234. count = 500;
  1235. spin_lock_irqsave(&data->lock, flags);
  1236. data->status = STATUS_EXITING;
  1237. while ((list_empty(&data->queue) == 0) && --count) {
  1238. dev_dbg(&board_dat->pdev->dev, "%s :queue not empty\n",
  1239. __func__);
  1240. spin_unlock_irqrestore(&data->lock, flags);
  1241. msleep(PCH_SLEEP_TIME);
  1242. spin_lock_irqsave(&data->lock, flags);
  1243. }
  1244. spin_unlock_irqrestore(&data->lock, flags);
  1245. pch_spi_free_resources(board_dat, data);
  1246. /* disable interrupts & free IRQ */
  1247. if (data->irq_reg_sts) {
  1248. /* disable interrupts */
  1249. pch_spi_setclr_reg(data->master, PCH_SPCR, 0, PCH_ALL);
  1250. data->irq_reg_sts = false;
  1251. free_irq(board_dat->pdev->irq, data);
  1252. }
  1253. pci_iounmap(board_dat->pdev, data->io_remap_addr);
  1254. spi_unregister_master(data->master);
  1255. return 0;
  1256. }
  1257. #ifdef CONFIG_PM
  1258. static int pch_spi_pd_suspend(struct platform_device *pd_dev,
  1259. pm_message_t state)
  1260. {
  1261. u8 count;
  1262. struct pch_spi_board_data *board_dat = dev_get_platdata(&pd_dev->dev);
  1263. struct pch_spi_data *data = platform_get_drvdata(pd_dev);
  1264. dev_dbg(&pd_dev->dev, "%s ENTRY\n", __func__);
  1265. if (!board_dat) {
  1266. dev_err(&pd_dev->dev,
  1267. "%s pci_get_drvdata returned NULL\n", __func__);
  1268. return -EFAULT;
  1269. }
  1270. /* check if the current message is processed:
  1271. Only after thats done the transfer will be suspended */
  1272. count = 255;
  1273. while ((--count) > 0) {
  1274. if (!(data->bcurrent_msg_processing))
  1275. break;
  1276. msleep(PCH_SLEEP_TIME);
  1277. }
  1278. /* Free IRQ */
  1279. if (data->irq_reg_sts) {
  1280. /* disable all interrupts */
  1281. pch_spi_setclr_reg(data->master, PCH_SPCR, 0, PCH_ALL);
  1282. pch_spi_reset(data->master);
  1283. free_irq(board_dat->pdev->irq, data);
  1284. data->irq_reg_sts = false;
  1285. dev_dbg(&pd_dev->dev,
  1286. "%s free_irq invoked successfully.\n", __func__);
  1287. }
  1288. return 0;
  1289. }
  1290. static int pch_spi_pd_resume(struct platform_device *pd_dev)
  1291. {
  1292. struct pch_spi_board_data *board_dat = dev_get_platdata(&pd_dev->dev);
  1293. struct pch_spi_data *data = platform_get_drvdata(pd_dev);
  1294. int retval;
  1295. if (!board_dat) {
  1296. dev_err(&pd_dev->dev,
  1297. "%s pci_get_drvdata returned NULL\n", __func__);
  1298. return -EFAULT;
  1299. }
  1300. if (!data->irq_reg_sts) {
  1301. /* register IRQ */
  1302. retval = request_irq(board_dat->pdev->irq, pch_spi_handler,
  1303. IRQF_SHARED, KBUILD_MODNAME, data);
  1304. if (retval < 0) {
  1305. dev_err(&pd_dev->dev,
  1306. "%s request_irq failed\n", __func__);
  1307. return retval;
  1308. }
  1309. /* reset PCH SPI h/w */
  1310. pch_spi_reset(data->master);
  1311. pch_spi_set_master_mode(data->master);
  1312. data->irq_reg_sts = true;
  1313. }
  1314. return 0;
  1315. }
  1316. #else
  1317. #define pch_spi_pd_suspend NULL
  1318. #define pch_spi_pd_resume NULL
  1319. #endif
  1320. static struct platform_driver pch_spi_pd_driver = {
  1321. .driver = {
  1322. .name = "pch-spi",
  1323. },
  1324. .probe = pch_spi_pd_probe,
  1325. .remove = pch_spi_pd_remove,
  1326. .suspend = pch_spi_pd_suspend,
  1327. .resume = pch_spi_pd_resume
  1328. };
  1329. static int pch_spi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  1330. {
  1331. struct pch_spi_board_data *board_dat;
  1332. struct platform_device *pd_dev = NULL;
  1333. int retval;
  1334. int i;
  1335. struct pch_pd_dev_save *pd_dev_save;
  1336. pd_dev_save = kzalloc(sizeof(*pd_dev_save), GFP_KERNEL);
  1337. if (!pd_dev_save)
  1338. return -ENOMEM;
  1339. board_dat = kzalloc(sizeof(*board_dat), GFP_KERNEL);
  1340. if (!board_dat) {
  1341. retval = -ENOMEM;
  1342. goto err_no_mem;
  1343. }
  1344. retval = pci_request_regions(pdev, KBUILD_MODNAME);
  1345. if (retval) {
  1346. dev_err(&pdev->dev, "%s request_region failed\n", __func__);
  1347. goto pci_request_regions;
  1348. }
  1349. board_dat->pdev = pdev;
  1350. board_dat->num = id->driver_data;
  1351. pd_dev_save->num = id->driver_data;
  1352. pd_dev_save->board_dat = board_dat;
  1353. retval = pci_enable_device(pdev);
  1354. if (retval) {
  1355. dev_err(&pdev->dev, "%s pci_enable_device failed\n", __func__);
  1356. goto pci_enable_device;
  1357. }
  1358. for (i = 0; i < board_dat->num; i++) {
  1359. pd_dev = platform_device_alloc("pch-spi", i);
  1360. if (!pd_dev) {
  1361. dev_err(&pdev->dev, "platform_device_alloc failed\n");
  1362. retval = -ENOMEM;
  1363. goto err_platform_device;
  1364. }
  1365. pd_dev_save->pd_save[i] = pd_dev;
  1366. pd_dev->dev.parent = &pdev->dev;
  1367. retval = platform_device_add_data(pd_dev, board_dat,
  1368. sizeof(*board_dat));
  1369. if (retval) {
  1370. dev_err(&pdev->dev,
  1371. "platform_device_add_data failed\n");
  1372. platform_device_put(pd_dev);
  1373. goto err_platform_device;
  1374. }
  1375. retval = platform_device_add(pd_dev);
  1376. if (retval) {
  1377. dev_err(&pdev->dev, "platform_device_add failed\n");
  1378. platform_device_put(pd_dev);
  1379. goto err_platform_device;
  1380. }
  1381. }
  1382. pci_set_drvdata(pdev, pd_dev_save);
  1383. return 0;
  1384. err_platform_device:
  1385. while (--i >= 0)
  1386. platform_device_unregister(pd_dev_save->pd_save[i]);
  1387. pci_disable_device(pdev);
  1388. pci_enable_device:
  1389. pci_release_regions(pdev);
  1390. pci_request_regions:
  1391. kfree(board_dat);
  1392. err_no_mem:
  1393. kfree(pd_dev_save);
  1394. return retval;
  1395. }
  1396. static void pch_spi_remove(struct pci_dev *pdev)
  1397. {
  1398. int i;
  1399. struct pch_pd_dev_save *pd_dev_save = pci_get_drvdata(pdev);
  1400. dev_dbg(&pdev->dev, "%s ENTRY:pdev=%p\n", __func__, pdev);
  1401. for (i = 0; i < pd_dev_save->num; i++)
  1402. platform_device_unregister(pd_dev_save->pd_save[i]);
  1403. pci_disable_device(pdev);
  1404. pci_release_regions(pdev);
  1405. kfree(pd_dev_save->board_dat);
  1406. kfree(pd_dev_save);
  1407. }
  1408. #ifdef CONFIG_PM
  1409. static int pch_spi_suspend(struct pci_dev *pdev, pm_message_t state)
  1410. {
  1411. int retval;
  1412. struct pch_pd_dev_save *pd_dev_save = pci_get_drvdata(pdev);
  1413. dev_dbg(&pdev->dev, "%s ENTRY\n", __func__);
  1414. pd_dev_save->board_dat->suspend_sts = true;
  1415. /* save config space */
  1416. retval = pci_save_state(pdev);
  1417. if (retval == 0) {
  1418. pci_enable_wake(pdev, PCI_D3hot, 0);
  1419. pci_disable_device(pdev);
  1420. pci_set_power_state(pdev, PCI_D3hot);
  1421. } else {
  1422. dev_err(&pdev->dev, "%s pci_save_state failed\n", __func__);
  1423. }
  1424. return retval;
  1425. }
  1426. static int pch_spi_resume(struct pci_dev *pdev)
  1427. {
  1428. int retval;
  1429. struct pch_pd_dev_save *pd_dev_save = pci_get_drvdata(pdev);
  1430. dev_dbg(&pdev->dev, "%s ENTRY\n", __func__);
  1431. pci_set_power_state(pdev, PCI_D0);
  1432. pci_restore_state(pdev);
  1433. retval = pci_enable_device(pdev);
  1434. if (retval < 0) {
  1435. dev_err(&pdev->dev,
  1436. "%s pci_enable_device failed\n", __func__);
  1437. } else {
  1438. pci_enable_wake(pdev, PCI_D3hot, 0);
  1439. /* set suspend status to false */
  1440. pd_dev_save->board_dat->suspend_sts = false;
  1441. }
  1442. return retval;
  1443. }
  1444. #else
  1445. #define pch_spi_suspend NULL
  1446. #define pch_spi_resume NULL
  1447. #endif
  1448. static struct pci_driver pch_spi_pcidev_driver = {
  1449. .name = "pch_spi",
  1450. .id_table = pch_spi_pcidev_id,
  1451. .probe = pch_spi_probe,
  1452. .remove = pch_spi_remove,
  1453. .suspend = pch_spi_suspend,
  1454. .resume = pch_spi_resume,
  1455. };
  1456. static int __init pch_spi_init(void)
  1457. {
  1458. int ret;
  1459. ret = platform_driver_register(&pch_spi_pd_driver);
  1460. if (ret)
  1461. return ret;
  1462. ret = pci_register_driver(&pch_spi_pcidev_driver);
  1463. if (ret) {
  1464. platform_driver_unregister(&pch_spi_pd_driver);
  1465. return ret;
  1466. }
  1467. return 0;
  1468. }
  1469. module_init(pch_spi_init);
  1470. static void __exit pch_spi_exit(void)
  1471. {
  1472. pci_unregister_driver(&pch_spi_pcidev_driver);
  1473. platform_driver_unregister(&pch_spi_pd_driver);
  1474. }
  1475. module_exit(pch_spi_exit);
  1476. module_param(use_dma, int, 0644);
  1477. MODULE_PARM_DESC(use_dma,
  1478. "to use DMA for data transfers pass 1 else 0; default 1");
  1479. MODULE_LICENSE("GPL");
  1480. MODULE_DESCRIPTION("Intel EG20T PCH/LAPIS Semiconductor ML7xxx IOH SPI Driver");
  1481. MODULE_DEVICE_TABLE(pci, pch_spi_pcidev_id);