spi-topcliff-pch.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735
  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. dev_err(&data->master->dev, "%s :kzalloc failed\n", __func__);
  510. list_for_each_entry_safe(pmsg, tmp, data->queue.next, queue) {
  511. pmsg->status = -ENOMEM;
  512. if (pmsg->complete)
  513. pmsg->complete(pmsg->context);
  514. /* delete from queue */
  515. list_del_init(&pmsg->queue);
  516. }
  517. return;
  518. }
  519. /* copy Tx Data */
  520. if (data->cur_trans->tx_buf != NULL) {
  521. if (*bpw == 8) {
  522. tx_buf = data->cur_trans->tx_buf;
  523. for (j = 0; j < data->bpw_len; j++)
  524. data->pkt_tx_buff[j] = *tx_buf++;
  525. } else {
  526. tx_sbuf = data->cur_trans->tx_buf;
  527. for (j = 0; j < data->bpw_len; j++)
  528. data->pkt_tx_buff[j] = *tx_sbuf++;
  529. }
  530. }
  531. /* if len greater than PCH_MAX_FIFO_DEPTH, write 16,else len bytes */
  532. n_writes = data->bpw_len;
  533. if (n_writes > PCH_MAX_FIFO_DEPTH)
  534. n_writes = PCH_MAX_FIFO_DEPTH;
  535. dev_dbg(&data->master->dev, "\n%s:Pulling down SSN low - writing "
  536. "0x2 to SSNXCR\n", __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. return;
  783. }
  784. static void pch_spi_handle_dma(struct pch_spi_data *data, int *bpw)
  785. {
  786. const u8 *tx_buf;
  787. const u16 *tx_sbuf;
  788. u8 *tx_dma_buf;
  789. u16 *tx_dma_sbuf;
  790. struct scatterlist *sg;
  791. struct dma_async_tx_descriptor *desc_tx;
  792. struct dma_async_tx_descriptor *desc_rx;
  793. int num;
  794. int i;
  795. int size;
  796. int rem;
  797. int head;
  798. unsigned long flags;
  799. struct pch_spi_dma_ctrl *dma;
  800. dma = &data->dma;
  801. /* set baud rate if needed */
  802. if (data->cur_trans->speed_hz) {
  803. dev_dbg(&data->master->dev, "%s:setting baud rate\n", __func__);
  804. spin_lock_irqsave(&data->lock, flags);
  805. pch_spi_set_baud_rate(data->master, data->cur_trans->speed_hz);
  806. spin_unlock_irqrestore(&data->lock, flags);
  807. }
  808. /* set bits per word if needed */
  809. if (data->cur_trans->bits_per_word &&
  810. (data->current_msg->spi->bits_per_word !=
  811. data->cur_trans->bits_per_word)) {
  812. dev_dbg(&data->master->dev, "%s:set bits per word\n", __func__);
  813. spin_lock_irqsave(&data->lock, flags);
  814. pch_spi_set_bits_per_word(data->master,
  815. data->cur_trans->bits_per_word);
  816. spin_unlock_irqrestore(&data->lock, flags);
  817. *bpw = data->cur_trans->bits_per_word;
  818. } else {
  819. *bpw = data->current_msg->spi->bits_per_word;
  820. }
  821. data->bpw_len = data->cur_trans->len / (*bpw / 8);
  822. if (data->bpw_len > PCH_BUF_SIZE) {
  823. data->bpw_len = PCH_BUF_SIZE;
  824. data->cur_trans->len -= PCH_BUF_SIZE;
  825. }
  826. /* copy Tx Data */
  827. if (data->cur_trans->tx_buf != NULL) {
  828. if (*bpw == 8) {
  829. tx_buf = data->cur_trans->tx_buf;
  830. tx_dma_buf = dma->tx_buf_virt;
  831. for (i = 0; i < data->bpw_len; i++)
  832. *tx_dma_buf++ = *tx_buf++;
  833. } else {
  834. tx_sbuf = data->cur_trans->tx_buf;
  835. tx_dma_sbuf = dma->tx_buf_virt;
  836. for (i = 0; i < data->bpw_len; i++)
  837. *tx_dma_sbuf++ = *tx_sbuf++;
  838. }
  839. }
  840. /* Calculate Rx parameter for DMA transmitting */
  841. if (data->bpw_len > PCH_DMA_TRANS_SIZE) {
  842. if (data->bpw_len % PCH_DMA_TRANS_SIZE) {
  843. num = data->bpw_len / PCH_DMA_TRANS_SIZE + 1;
  844. rem = data->bpw_len % PCH_DMA_TRANS_SIZE;
  845. } else {
  846. num = data->bpw_len / PCH_DMA_TRANS_SIZE;
  847. rem = PCH_DMA_TRANS_SIZE;
  848. }
  849. size = PCH_DMA_TRANS_SIZE;
  850. } else {
  851. num = 1;
  852. size = data->bpw_len;
  853. rem = data->bpw_len;
  854. }
  855. dev_dbg(&data->master->dev, "%s num=%d size=%d rem=%d\n",
  856. __func__, num, size, rem);
  857. spin_lock_irqsave(&data->lock, flags);
  858. /* set receive fifo threshold and transmit fifo threshold */
  859. pch_spi_setclr_reg(data->master, PCH_SPCR,
  860. ((size - 1) << SPCR_RFIC_FIELD) |
  861. (PCH_TX_THOLD << SPCR_TFIC_FIELD),
  862. MASK_RFIC_SPCR_BITS | MASK_TFIC_SPCR_BITS);
  863. spin_unlock_irqrestore(&data->lock, flags);
  864. /* RX */
  865. dma->sg_rx_p = kzalloc(sizeof(struct scatterlist)*num, GFP_ATOMIC);
  866. sg_init_table(dma->sg_rx_p, num); /* Initialize SG table */
  867. /* offset, length setting */
  868. sg = dma->sg_rx_p;
  869. for (i = 0; i < num; i++, sg++) {
  870. if (i == (num - 2)) {
  871. sg->offset = size * i;
  872. sg->offset = sg->offset * (*bpw / 8);
  873. sg_set_page(sg, virt_to_page(dma->rx_buf_virt), rem,
  874. sg->offset);
  875. sg_dma_len(sg) = rem;
  876. } else if (i == (num - 1)) {
  877. sg->offset = size * (i - 1) + rem;
  878. sg->offset = sg->offset * (*bpw / 8);
  879. sg_set_page(sg, virt_to_page(dma->rx_buf_virt), size,
  880. sg->offset);
  881. sg_dma_len(sg) = size;
  882. } else {
  883. sg->offset = size * i;
  884. sg->offset = sg->offset * (*bpw / 8);
  885. sg_set_page(sg, virt_to_page(dma->rx_buf_virt), size,
  886. sg->offset);
  887. sg_dma_len(sg) = size;
  888. }
  889. sg_dma_address(sg) = dma->rx_buf_dma + sg->offset;
  890. }
  891. sg = dma->sg_rx_p;
  892. desc_rx = dmaengine_prep_slave_sg(dma->chan_rx, sg,
  893. num, DMA_DEV_TO_MEM,
  894. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  895. if (!desc_rx) {
  896. dev_err(&data->master->dev,
  897. "%s:dmaengine_prep_slave_sg Failed\n", __func__);
  898. return;
  899. }
  900. dma_sync_sg_for_device(&data->master->dev, sg, num, DMA_FROM_DEVICE);
  901. desc_rx->callback = pch_dma_rx_complete;
  902. desc_rx->callback_param = data;
  903. dma->nent = num;
  904. dma->desc_rx = desc_rx;
  905. /* Calculate Tx parameter for DMA transmitting */
  906. if (data->bpw_len > PCH_MAX_FIFO_DEPTH) {
  907. head = PCH_MAX_FIFO_DEPTH - PCH_DMA_TRANS_SIZE;
  908. if (data->bpw_len % PCH_DMA_TRANS_SIZE > 4) {
  909. num = data->bpw_len / PCH_DMA_TRANS_SIZE + 1;
  910. rem = data->bpw_len % PCH_DMA_TRANS_SIZE - head;
  911. } else {
  912. num = data->bpw_len / PCH_DMA_TRANS_SIZE;
  913. rem = data->bpw_len % PCH_DMA_TRANS_SIZE +
  914. PCH_DMA_TRANS_SIZE - head;
  915. }
  916. size = PCH_DMA_TRANS_SIZE;
  917. } else {
  918. num = 1;
  919. size = data->bpw_len;
  920. rem = data->bpw_len;
  921. head = 0;
  922. }
  923. dma->sg_tx_p = kzalloc(sizeof(struct scatterlist)*num, GFP_ATOMIC);
  924. sg_init_table(dma->sg_tx_p, num); /* Initialize SG table */
  925. /* offset, length setting */
  926. sg = dma->sg_tx_p;
  927. for (i = 0; i < num; i++, sg++) {
  928. if (i == 0) {
  929. sg->offset = 0;
  930. sg_set_page(sg, virt_to_page(dma->tx_buf_virt), size + head,
  931. sg->offset);
  932. sg_dma_len(sg) = size + head;
  933. } else if (i == (num - 1)) {
  934. sg->offset = head + size * i;
  935. sg->offset = sg->offset * (*bpw / 8);
  936. sg_set_page(sg, virt_to_page(dma->tx_buf_virt), rem,
  937. sg->offset);
  938. sg_dma_len(sg) = rem;
  939. } else {
  940. sg->offset = head + size * i;
  941. sg->offset = sg->offset * (*bpw / 8);
  942. sg_set_page(sg, virt_to_page(dma->tx_buf_virt), size,
  943. sg->offset);
  944. sg_dma_len(sg) = size;
  945. }
  946. sg_dma_address(sg) = dma->tx_buf_dma + sg->offset;
  947. }
  948. sg = dma->sg_tx_p;
  949. desc_tx = dmaengine_prep_slave_sg(dma->chan_tx,
  950. sg, num, DMA_MEM_TO_DEV,
  951. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  952. if (!desc_tx) {
  953. dev_err(&data->master->dev,
  954. "%s:dmaengine_prep_slave_sg Failed\n", __func__);
  955. return;
  956. }
  957. dma_sync_sg_for_device(&data->master->dev, sg, num, DMA_TO_DEVICE);
  958. desc_tx->callback = NULL;
  959. desc_tx->callback_param = data;
  960. dma->nent = num;
  961. dma->desc_tx = desc_tx;
  962. dev_dbg(&data->master->dev, "%s:Pulling down SSN low - writing 0x2 to SSNXCR\n", __func__);
  963. spin_lock_irqsave(&data->lock, flags);
  964. pch_spi_writereg(data->master, PCH_SSNXCR, SSN_LOW);
  965. desc_rx->tx_submit(desc_rx);
  966. desc_tx->tx_submit(desc_tx);
  967. spin_unlock_irqrestore(&data->lock, flags);
  968. /* reset transfer complete flag */
  969. data->transfer_complete = false;
  970. }
  971. static void pch_spi_process_messages(struct work_struct *pwork)
  972. {
  973. struct spi_message *pmsg, *tmp;
  974. struct pch_spi_data *data;
  975. int bpw;
  976. data = container_of(pwork, struct pch_spi_data, work);
  977. dev_dbg(&data->master->dev, "%s data initialized\n", __func__);
  978. spin_lock(&data->lock);
  979. /* check if suspend has been initiated;if yes flush queue */
  980. if (data->board_dat->suspend_sts || (data->status == STATUS_EXITING)) {
  981. dev_dbg(&data->master->dev,
  982. "%s suspend/remove initiated, flushing queue\n", __func__);
  983. list_for_each_entry_safe(pmsg, tmp, data->queue.next, queue) {
  984. pmsg->status = -EIO;
  985. if (pmsg->complete) {
  986. spin_unlock(&data->lock);
  987. pmsg->complete(pmsg->context);
  988. spin_lock(&data->lock);
  989. }
  990. /* delete from queue */
  991. list_del_init(&pmsg->queue);
  992. }
  993. spin_unlock(&data->lock);
  994. return;
  995. }
  996. data->bcurrent_msg_processing = true;
  997. dev_dbg(&data->master->dev,
  998. "%s Set data->bcurrent_msg_processing= true\n", __func__);
  999. /* Get the message from the queue and delete it from there. */
  1000. data->current_msg = list_entry(data->queue.next, struct spi_message,
  1001. queue);
  1002. list_del_init(&data->current_msg->queue);
  1003. data->current_msg->status = 0;
  1004. pch_spi_select_chip(data, data->current_msg->spi);
  1005. spin_unlock(&data->lock);
  1006. if (data->use_dma)
  1007. pch_spi_request_dma(data,
  1008. data->current_msg->spi->bits_per_word);
  1009. pch_spi_writereg(data->master, PCH_SSNXCR, SSN_NO_CONTROL);
  1010. do {
  1011. int cnt;
  1012. /* If we are already processing a message get the next
  1013. transfer structure from the message otherwise retrieve
  1014. the 1st transfer request from the message. */
  1015. spin_lock(&data->lock);
  1016. if (data->cur_trans == NULL) {
  1017. data->cur_trans =
  1018. list_entry(data->current_msg->transfers.next,
  1019. struct spi_transfer, transfer_list);
  1020. dev_dbg(&data->master->dev, "%s "
  1021. ":Getting 1st transfer message\n", __func__);
  1022. } else {
  1023. data->cur_trans =
  1024. list_entry(data->cur_trans->transfer_list.next,
  1025. struct spi_transfer, transfer_list);
  1026. dev_dbg(&data->master->dev, "%s "
  1027. ":Getting next transfer message\n", __func__);
  1028. }
  1029. spin_unlock(&data->lock);
  1030. if (!data->cur_trans->len)
  1031. goto out;
  1032. cnt = (data->cur_trans->len - 1) / PCH_BUF_SIZE + 1;
  1033. data->save_total_len = data->cur_trans->len;
  1034. if (data->use_dma) {
  1035. int i;
  1036. char *save_rx_buf = data->cur_trans->rx_buf;
  1037. for (i = 0; i < cnt; i ++) {
  1038. pch_spi_handle_dma(data, &bpw);
  1039. if (!pch_spi_start_transfer(data)) {
  1040. data->transfer_complete = true;
  1041. data->current_msg->status = -EIO;
  1042. data->current_msg->complete
  1043. (data->current_msg->context);
  1044. data->bcurrent_msg_processing = false;
  1045. data->current_msg = NULL;
  1046. data->cur_trans = NULL;
  1047. goto out;
  1048. }
  1049. pch_spi_copy_rx_data_for_dma(data, bpw);
  1050. }
  1051. data->cur_trans->rx_buf = save_rx_buf;
  1052. } else {
  1053. pch_spi_set_tx(data, &bpw);
  1054. pch_spi_set_ir(data);
  1055. pch_spi_copy_rx_data(data, bpw);
  1056. kfree(data->pkt_rx_buff);
  1057. data->pkt_rx_buff = NULL;
  1058. kfree(data->pkt_tx_buff);
  1059. data->pkt_tx_buff = NULL;
  1060. }
  1061. /* increment message count */
  1062. data->cur_trans->len = data->save_total_len;
  1063. data->current_msg->actual_length += data->cur_trans->len;
  1064. dev_dbg(&data->master->dev,
  1065. "%s:data->current_msg->actual_length=%d\n",
  1066. __func__, data->current_msg->actual_length);
  1067. /* check for delay */
  1068. if (data->cur_trans->delay_usecs) {
  1069. dev_dbg(&data->master->dev, "%s:"
  1070. "delay in usec=%d\n", __func__,
  1071. data->cur_trans->delay_usecs);
  1072. udelay(data->cur_trans->delay_usecs);
  1073. }
  1074. spin_lock(&data->lock);
  1075. /* No more transfer in this message. */
  1076. if ((data->cur_trans->transfer_list.next) ==
  1077. &(data->current_msg->transfers)) {
  1078. pch_spi_nomore_transfer(data);
  1079. }
  1080. spin_unlock(&data->lock);
  1081. } while (data->cur_trans != NULL);
  1082. out:
  1083. pch_spi_writereg(data->master, PCH_SSNXCR, SSN_HIGH);
  1084. if (data->use_dma)
  1085. pch_spi_release_dma(data);
  1086. }
  1087. static void pch_spi_free_resources(struct pch_spi_board_data *board_dat,
  1088. struct pch_spi_data *data)
  1089. {
  1090. dev_dbg(&board_dat->pdev->dev, "%s ENTRY\n", __func__);
  1091. flush_work(&data->work);
  1092. }
  1093. static int pch_spi_get_resources(struct pch_spi_board_data *board_dat,
  1094. struct pch_spi_data *data)
  1095. {
  1096. int retval = 0;
  1097. dev_dbg(&board_dat->pdev->dev, "%s ENTRY\n", __func__);
  1098. /* reset PCH SPI h/w */
  1099. pch_spi_reset(data->master);
  1100. dev_dbg(&board_dat->pdev->dev,
  1101. "%s pch_spi_reset invoked successfully\n", __func__);
  1102. dev_dbg(&board_dat->pdev->dev, "%s data->irq_reg_sts=true\n", __func__);
  1103. if (retval != 0) {
  1104. dev_err(&board_dat->pdev->dev,
  1105. "%s FAIL:invoking pch_spi_free_resources\n", __func__);
  1106. pch_spi_free_resources(board_dat, data);
  1107. }
  1108. dev_dbg(&board_dat->pdev->dev, "%s Return=%d\n", __func__, retval);
  1109. return retval;
  1110. }
  1111. static void pch_free_dma_buf(struct pch_spi_board_data *board_dat,
  1112. struct pch_spi_data *data)
  1113. {
  1114. struct pch_spi_dma_ctrl *dma;
  1115. dma = &data->dma;
  1116. if (dma->tx_buf_dma)
  1117. dma_free_coherent(&board_dat->pdev->dev, PCH_BUF_SIZE,
  1118. dma->tx_buf_virt, dma->tx_buf_dma);
  1119. if (dma->rx_buf_dma)
  1120. dma_free_coherent(&board_dat->pdev->dev, PCH_BUF_SIZE,
  1121. dma->rx_buf_virt, dma->rx_buf_dma);
  1122. return;
  1123. }
  1124. static void pch_alloc_dma_buf(struct pch_spi_board_data *board_dat,
  1125. struct pch_spi_data *data)
  1126. {
  1127. struct pch_spi_dma_ctrl *dma;
  1128. dma = &data->dma;
  1129. /* Get Consistent memory for Tx DMA */
  1130. dma->tx_buf_virt = dma_alloc_coherent(&board_dat->pdev->dev,
  1131. PCH_BUF_SIZE, &dma->tx_buf_dma, GFP_KERNEL);
  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. }
  1136. static int pch_spi_pd_probe(struct platform_device *plat_dev)
  1137. {
  1138. int ret;
  1139. struct spi_master *master;
  1140. struct pch_spi_board_data *board_dat = dev_get_platdata(&plat_dev->dev);
  1141. struct pch_spi_data *data;
  1142. dev_dbg(&plat_dev->dev, "%s:debug\n", __func__);
  1143. master = spi_alloc_master(&board_dat->pdev->dev,
  1144. sizeof(struct pch_spi_data));
  1145. if (!master) {
  1146. dev_err(&plat_dev->dev, "spi_alloc_master[%d] failed.\n",
  1147. plat_dev->id);
  1148. return -ENOMEM;
  1149. }
  1150. data = spi_master_get_devdata(master);
  1151. data->master = master;
  1152. platform_set_drvdata(plat_dev, data);
  1153. /* baseaddress + address offset) */
  1154. data->io_base_addr = pci_resource_start(board_dat->pdev, 1) +
  1155. PCH_ADDRESS_SIZE * plat_dev->id;
  1156. data->io_remap_addr = pci_iomap(board_dat->pdev, 1, 0);
  1157. if (!data->io_remap_addr) {
  1158. dev_err(&plat_dev->dev, "%s pci_iomap failed\n", __func__);
  1159. ret = -ENOMEM;
  1160. goto err_pci_iomap;
  1161. }
  1162. data->io_remap_addr += PCH_ADDRESS_SIZE * plat_dev->id;
  1163. dev_dbg(&plat_dev->dev, "[ch%d] remap_addr=%p\n",
  1164. plat_dev->id, data->io_remap_addr);
  1165. /* initialize members of SPI master */
  1166. master->num_chipselect = PCH_MAX_CS;
  1167. master->transfer = pch_spi_transfer;
  1168. master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
  1169. master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
  1170. master->max_speed_hz = PCH_MAX_BAUDRATE;
  1171. data->board_dat = board_dat;
  1172. data->plat_dev = plat_dev;
  1173. data->n_curnt_chip = 255;
  1174. data->status = STATUS_RUNNING;
  1175. data->ch = plat_dev->id;
  1176. data->use_dma = use_dma;
  1177. INIT_LIST_HEAD(&data->queue);
  1178. spin_lock_init(&data->lock);
  1179. INIT_WORK(&data->work, pch_spi_process_messages);
  1180. init_waitqueue_head(&data->wait);
  1181. ret = pch_spi_get_resources(board_dat, data);
  1182. if (ret) {
  1183. dev_err(&plat_dev->dev, "%s fail(retval=%d)\n", __func__, ret);
  1184. goto err_spi_get_resources;
  1185. }
  1186. ret = request_irq(board_dat->pdev->irq, pch_spi_handler,
  1187. IRQF_SHARED, KBUILD_MODNAME, data);
  1188. if (ret) {
  1189. dev_err(&plat_dev->dev,
  1190. "%s request_irq failed\n", __func__);
  1191. goto err_request_irq;
  1192. }
  1193. data->irq_reg_sts = true;
  1194. pch_spi_set_master_mode(master);
  1195. if (use_dma) {
  1196. dev_info(&plat_dev->dev, "Use DMA for data transfers\n");
  1197. pch_alloc_dma_buf(board_dat, data);
  1198. }
  1199. ret = spi_register_master(master);
  1200. if (ret != 0) {
  1201. dev_err(&plat_dev->dev,
  1202. "%s spi_register_master FAILED\n", __func__);
  1203. goto err_spi_register_master;
  1204. }
  1205. return 0;
  1206. err_spi_register_master:
  1207. pch_free_dma_buf(board_dat, data);
  1208. free_irq(board_dat->pdev->irq, data);
  1209. err_request_irq:
  1210. pch_spi_free_resources(board_dat, data);
  1211. err_spi_get_resources:
  1212. pci_iounmap(board_dat->pdev, data->io_remap_addr);
  1213. err_pci_iomap:
  1214. spi_master_put(master);
  1215. return ret;
  1216. }
  1217. static int pch_spi_pd_remove(struct platform_device *plat_dev)
  1218. {
  1219. struct pch_spi_board_data *board_dat = dev_get_platdata(&plat_dev->dev);
  1220. struct pch_spi_data *data = platform_get_drvdata(plat_dev);
  1221. int count;
  1222. unsigned long flags;
  1223. dev_dbg(&plat_dev->dev, "%s:[ch%d] irq=%d\n",
  1224. __func__, plat_dev->id, board_dat->pdev->irq);
  1225. if (use_dma)
  1226. pch_free_dma_buf(board_dat, data);
  1227. /* check for any pending messages; no action is taken if the queue
  1228. * is still full; but at least we tried. Unload anyway */
  1229. count = 500;
  1230. spin_lock_irqsave(&data->lock, flags);
  1231. data->status = STATUS_EXITING;
  1232. while ((list_empty(&data->queue) == 0) && --count) {
  1233. dev_dbg(&board_dat->pdev->dev, "%s :queue not empty\n",
  1234. __func__);
  1235. spin_unlock_irqrestore(&data->lock, flags);
  1236. msleep(PCH_SLEEP_TIME);
  1237. spin_lock_irqsave(&data->lock, flags);
  1238. }
  1239. spin_unlock_irqrestore(&data->lock, flags);
  1240. pch_spi_free_resources(board_dat, data);
  1241. /* disable interrupts & free IRQ */
  1242. if (data->irq_reg_sts) {
  1243. /* disable interrupts */
  1244. pch_spi_setclr_reg(data->master, PCH_SPCR, 0, PCH_ALL);
  1245. data->irq_reg_sts = false;
  1246. free_irq(board_dat->pdev->irq, data);
  1247. }
  1248. pci_iounmap(board_dat->pdev, data->io_remap_addr);
  1249. spi_unregister_master(data->master);
  1250. return 0;
  1251. }
  1252. #ifdef CONFIG_PM
  1253. static int pch_spi_pd_suspend(struct platform_device *pd_dev,
  1254. pm_message_t state)
  1255. {
  1256. u8 count;
  1257. struct pch_spi_board_data *board_dat = dev_get_platdata(&pd_dev->dev);
  1258. struct pch_spi_data *data = platform_get_drvdata(pd_dev);
  1259. dev_dbg(&pd_dev->dev, "%s ENTRY\n", __func__);
  1260. if (!board_dat) {
  1261. dev_err(&pd_dev->dev,
  1262. "%s pci_get_drvdata returned NULL\n", __func__);
  1263. return -EFAULT;
  1264. }
  1265. /* check if the current message is processed:
  1266. Only after thats done the transfer will be suspended */
  1267. count = 255;
  1268. while ((--count) > 0) {
  1269. if (!(data->bcurrent_msg_processing))
  1270. break;
  1271. msleep(PCH_SLEEP_TIME);
  1272. }
  1273. /* Free IRQ */
  1274. if (data->irq_reg_sts) {
  1275. /* disable all interrupts */
  1276. pch_spi_setclr_reg(data->master, PCH_SPCR, 0, PCH_ALL);
  1277. pch_spi_reset(data->master);
  1278. free_irq(board_dat->pdev->irq, data);
  1279. data->irq_reg_sts = false;
  1280. dev_dbg(&pd_dev->dev,
  1281. "%s free_irq invoked successfully.\n", __func__);
  1282. }
  1283. return 0;
  1284. }
  1285. static int pch_spi_pd_resume(struct platform_device *pd_dev)
  1286. {
  1287. struct pch_spi_board_data *board_dat = dev_get_platdata(&pd_dev->dev);
  1288. struct pch_spi_data *data = platform_get_drvdata(pd_dev);
  1289. int retval;
  1290. if (!board_dat) {
  1291. dev_err(&pd_dev->dev,
  1292. "%s pci_get_drvdata returned NULL\n", __func__);
  1293. return -EFAULT;
  1294. }
  1295. if (!data->irq_reg_sts) {
  1296. /* register IRQ */
  1297. retval = request_irq(board_dat->pdev->irq, pch_spi_handler,
  1298. IRQF_SHARED, KBUILD_MODNAME, data);
  1299. if (retval < 0) {
  1300. dev_err(&pd_dev->dev,
  1301. "%s request_irq failed\n", __func__);
  1302. return retval;
  1303. }
  1304. /* reset PCH SPI h/w */
  1305. pch_spi_reset(data->master);
  1306. pch_spi_set_master_mode(data->master);
  1307. data->irq_reg_sts = true;
  1308. }
  1309. return 0;
  1310. }
  1311. #else
  1312. #define pch_spi_pd_suspend NULL
  1313. #define pch_spi_pd_resume NULL
  1314. #endif
  1315. static struct platform_driver pch_spi_pd_driver = {
  1316. .driver = {
  1317. .name = "pch-spi",
  1318. },
  1319. .probe = pch_spi_pd_probe,
  1320. .remove = pch_spi_pd_remove,
  1321. .suspend = pch_spi_pd_suspend,
  1322. .resume = pch_spi_pd_resume
  1323. };
  1324. static int pch_spi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  1325. {
  1326. struct pch_spi_board_data *board_dat;
  1327. struct platform_device *pd_dev = NULL;
  1328. int retval;
  1329. int i;
  1330. struct pch_pd_dev_save *pd_dev_save;
  1331. pd_dev_save = kzalloc(sizeof(struct pch_pd_dev_save), GFP_KERNEL);
  1332. if (!pd_dev_save)
  1333. return -ENOMEM;
  1334. board_dat = kzalloc(sizeof(struct pch_spi_board_data), GFP_KERNEL);
  1335. if (!board_dat) {
  1336. retval = -ENOMEM;
  1337. goto err_no_mem;
  1338. }
  1339. retval = pci_request_regions(pdev, KBUILD_MODNAME);
  1340. if (retval) {
  1341. dev_err(&pdev->dev, "%s request_region failed\n", __func__);
  1342. goto pci_request_regions;
  1343. }
  1344. board_dat->pdev = pdev;
  1345. board_dat->num = id->driver_data;
  1346. pd_dev_save->num = id->driver_data;
  1347. pd_dev_save->board_dat = board_dat;
  1348. retval = pci_enable_device(pdev);
  1349. if (retval) {
  1350. dev_err(&pdev->dev, "%s pci_enable_device failed\n", __func__);
  1351. goto pci_enable_device;
  1352. }
  1353. for (i = 0; i < board_dat->num; i++) {
  1354. pd_dev = platform_device_alloc("pch-spi", i);
  1355. if (!pd_dev) {
  1356. dev_err(&pdev->dev, "platform_device_alloc failed\n");
  1357. retval = -ENOMEM;
  1358. goto err_platform_device;
  1359. }
  1360. pd_dev_save->pd_save[i] = pd_dev;
  1361. pd_dev->dev.parent = &pdev->dev;
  1362. retval = platform_device_add_data(pd_dev, board_dat,
  1363. sizeof(*board_dat));
  1364. if (retval) {
  1365. dev_err(&pdev->dev,
  1366. "platform_device_add_data failed\n");
  1367. platform_device_put(pd_dev);
  1368. goto err_platform_device;
  1369. }
  1370. retval = platform_device_add(pd_dev);
  1371. if (retval) {
  1372. dev_err(&pdev->dev, "platform_device_add failed\n");
  1373. platform_device_put(pd_dev);
  1374. goto err_platform_device;
  1375. }
  1376. }
  1377. pci_set_drvdata(pdev, pd_dev_save);
  1378. return 0;
  1379. err_platform_device:
  1380. while (--i >= 0)
  1381. platform_device_unregister(pd_dev_save->pd_save[i]);
  1382. pci_disable_device(pdev);
  1383. pci_enable_device:
  1384. pci_release_regions(pdev);
  1385. pci_request_regions:
  1386. kfree(board_dat);
  1387. err_no_mem:
  1388. kfree(pd_dev_save);
  1389. return retval;
  1390. }
  1391. static void pch_spi_remove(struct pci_dev *pdev)
  1392. {
  1393. int i;
  1394. struct pch_pd_dev_save *pd_dev_save = pci_get_drvdata(pdev);
  1395. dev_dbg(&pdev->dev, "%s ENTRY:pdev=%p\n", __func__, pdev);
  1396. for (i = 0; i < pd_dev_save->num; i++)
  1397. platform_device_unregister(pd_dev_save->pd_save[i]);
  1398. pci_disable_device(pdev);
  1399. pci_release_regions(pdev);
  1400. kfree(pd_dev_save->board_dat);
  1401. kfree(pd_dev_save);
  1402. }
  1403. #ifdef CONFIG_PM
  1404. static int pch_spi_suspend(struct pci_dev *pdev, pm_message_t state)
  1405. {
  1406. int retval;
  1407. struct pch_pd_dev_save *pd_dev_save = pci_get_drvdata(pdev);
  1408. dev_dbg(&pdev->dev, "%s ENTRY\n", __func__);
  1409. pd_dev_save->board_dat->suspend_sts = true;
  1410. /* save config space */
  1411. retval = pci_save_state(pdev);
  1412. if (retval == 0) {
  1413. pci_enable_wake(pdev, PCI_D3hot, 0);
  1414. pci_disable_device(pdev);
  1415. pci_set_power_state(pdev, PCI_D3hot);
  1416. } else {
  1417. dev_err(&pdev->dev, "%s pci_save_state failed\n", __func__);
  1418. }
  1419. return retval;
  1420. }
  1421. static int pch_spi_resume(struct pci_dev *pdev)
  1422. {
  1423. int retval;
  1424. struct pch_pd_dev_save *pd_dev_save = pci_get_drvdata(pdev);
  1425. dev_dbg(&pdev->dev, "%s ENTRY\n", __func__);
  1426. pci_set_power_state(pdev, PCI_D0);
  1427. pci_restore_state(pdev);
  1428. retval = pci_enable_device(pdev);
  1429. if (retval < 0) {
  1430. dev_err(&pdev->dev,
  1431. "%s pci_enable_device failed\n", __func__);
  1432. } else {
  1433. pci_enable_wake(pdev, PCI_D3hot, 0);
  1434. /* set suspend status to false */
  1435. pd_dev_save->board_dat->suspend_sts = false;
  1436. }
  1437. return retval;
  1438. }
  1439. #else
  1440. #define pch_spi_suspend NULL
  1441. #define pch_spi_resume NULL
  1442. #endif
  1443. static struct pci_driver pch_spi_pcidev_driver = {
  1444. .name = "pch_spi",
  1445. .id_table = pch_spi_pcidev_id,
  1446. .probe = pch_spi_probe,
  1447. .remove = pch_spi_remove,
  1448. .suspend = pch_spi_suspend,
  1449. .resume = pch_spi_resume,
  1450. };
  1451. static int __init pch_spi_init(void)
  1452. {
  1453. int ret;
  1454. ret = platform_driver_register(&pch_spi_pd_driver);
  1455. if (ret)
  1456. return ret;
  1457. ret = pci_register_driver(&pch_spi_pcidev_driver);
  1458. if (ret) {
  1459. platform_driver_unregister(&pch_spi_pd_driver);
  1460. return ret;
  1461. }
  1462. return 0;
  1463. }
  1464. module_init(pch_spi_init);
  1465. static void __exit pch_spi_exit(void)
  1466. {
  1467. pci_unregister_driver(&pch_spi_pcidev_driver);
  1468. platform_driver_unregister(&pch_spi_pd_driver);
  1469. }
  1470. module_exit(pch_spi_exit);
  1471. module_param(use_dma, int, 0644);
  1472. MODULE_PARM_DESC(use_dma,
  1473. "to use DMA for data transfers pass 1 else 0; default 1");
  1474. MODULE_LICENSE("GPL");
  1475. MODULE_DESCRIPTION("Intel EG20T PCH/LAPIS Semiconductor ML7xxx IOH SPI Driver");
  1476. MODULE_DEVICE_TABLE(pci, pch_spi_pcidev_id);