0033-SPI-MIPS-lantiq-adds-spi-xway.patch 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  1. From e75df4f96373e5d16f8ca13aa031e54cdcfeda62 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Wed, 13 Mar 2013 09:29:37 +0100
  4. Subject: [PATCH 33/36] SPI: MIPS: lantiq: adds spi-xway
  5. This patch adds support for the SPI core found on several Lantiq SoCs.
  6. The Driver has been runtime tested in combination with m25p80 Flash Devices
  7. on Amazon_SE and VR9.
  8. Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>
  9. Signed-off-by: John Crispin <blogic@openwrt.org>
  10. ---
  11. drivers/spi/Kconfig | 8 +
  12. drivers/spi/Makefile | 1 +
  13. drivers/spi/spi-xway.c | 977 ++++++++++++++++++++++++++++++++++++++++++++++++
  14. 3 files changed, 986 insertions(+)
  15. create mode 100644 drivers/spi/spi-xway.c
  16. --- a/drivers/spi/Kconfig
  17. +++ b/drivers/spi/Kconfig
  18. @@ -597,6 +597,14 @@ config SPI_NUC900
  19. help
  20. SPI driver for Nuvoton NUC900 series ARM SoCs
  21. +config SPI_XWAY
  22. + tristate "Lantiq XWAY SPI controller"
  23. + depends on LANTIQ && SOC_TYPE_XWAY
  24. + select SPI_BITBANG
  25. + help
  26. + This driver supports the Lantiq SoC SPI controller in master
  27. + mode.
  28. +
  29. #
  30. # Add new SPI master controllers in alphabetical order above this line
  31. #
  32. --- a/drivers/spi/Makefile
  33. +++ b/drivers/spi/Makefile
  34. @@ -86,3 +86,4 @@ obj-$(CONFIG_SPI_TXX9) += spi-txx9.o
  35. obj-$(CONFIG_SPI_XCOMM) += spi-xcomm.o
  36. obj-$(CONFIG_SPI_XILINX) += spi-xilinx.o
  37. obj-$(CONFIG_SPI_XTENSA_XTFPGA) += spi-xtensa-xtfpga.o
  38. +obj-$(CONFIG_SPI_XWAY) += spi-xway.o
  39. --- /dev/null
  40. +++ b/drivers/spi/spi-xway.c
  41. @@ -0,0 +1,1003 @@
  42. +/*
  43. + * Lantiq SoC SPI controller
  44. + *
  45. + * Copyright (C) 2011 Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>
  46. + * Copyright (C) 2012 John Crispin <blogic@openwrt.org>
  47. + *
  48. + * This program is free software; you can distribute it and/or modify it
  49. + * under the terms of the GNU General Public License (Version 2) as
  50. + * published by the Free Software Foundation.
  51. + */
  52. +
  53. +#include <linux/init.h>
  54. +#include <linux/module.h>
  55. +#include <linux/workqueue.h>
  56. +#include <linux/platform_device.h>
  57. +#include <linux/io.h>
  58. +#include <linux/sched.h>
  59. +#include <linux/delay.h>
  60. +#include <linux/interrupt.h>
  61. +#include <linux/completion.h>
  62. +#include <linux/spinlock.h>
  63. +#include <linux/err.h>
  64. +#include <linux/clk.h>
  65. +#include <linux/spi/spi.h>
  66. +#include <linux/spi/spi_bitbang.h>
  67. +#include <linux/of_irq.h>
  68. +
  69. +#include <lantiq_soc.h>
  70. +
  71. +#define LTQ_SPI_CLC 0x00 /* Clock control */
  72. +#define LTQ_SPI_PISEL 0x04 /* Port input select */
  73. +#define LTQ_SPI_ID 0x08 /* Identification */
  74. +#define LTQ_SPI_CON 0x10 /* Control */
  75. +#define LTQ_SPI_STAT 0x14 /* Status */
  76. +#define LTQ_SPI_WHBSTATE 0x18 /* Write HW modified state */
  77. +#define LTQ_SPI_TB 0x20 /* Transmit buffer */
  78. +#define LTQ_SPI_RB 0x24 /* Receive buffer */
  79. +#define LTQ_SPI_RXFCON 0x30 /* Receive FIFO control */
  80. +#define LTQ_SPI_TXFCON 0x34 /* Transmit FIFO control */
  81. +#define LTQ_SPI_FSTAT 0x38 /* FIFO status */
  82. +#define LTQ_SPI_BRT 0x40 /* Baudrate timer */
  83. +#define LTQ_SPI_BRSTAT 0x44 /* Baudrate timer status */
  84. +#define LTQ_SPI_SFCON 0x60 /* Serial frame control */
  85. +#define LTQ_SPI_SFSTAT 0x64 /* Serial frame status */
  86. +#define LTQ_SPI_GPOCON 0x70 /* General purpose output control */
  87. +#define LTQ_SPI_GPOSTAT 0x74 /* General purpose output status */
  88. +#define LTQ_SPI_FGPO 0x78 /* Forced general purpose output */
  89. +#define LTQ_SPI_RXREQ 0x80 /* Receive request */
  90. +#define LTQ_SPI_RXCNT 0x84 /* Receive count */
  91. +#define LTQ_SPI_DMACON 0xEC /* DMA control */
  92. +#define LTQ_SPI_IRNEN 0xF4 /* Interrupt node enable */
  93. +#define LTQ_SPI_IRNICR 0xF8 /* Interrupt node interrupt capture */
  94. +#define LTQ_SPI_IRNCR 0xFC /* Interrupt node control */
  95. +
  96. +#define LTQ_SPI_CLC_SMC_SHIFT 16 /* Clock divider for sleep mode */
  97. +#define LTQ_SPI_CLC_SMC_MASK 0xFF
  98. +#define LTQ_SPI_CLC_RMC_SHIFT 8 /* Clock divider for normal run mode */
  99. +#define LTQ_SPI_CLC_RMC_MASK 0xFF
  100. +#define LTQ_SPI_CLC_DISS BIT(1) /* Disable status bit */
  101. +#define LTQ_SPI_CLC_DISR BIT(0) /* Disable request bit */
  102. +
  103. +#define LTQ_SPI_ID_TXFS_SHIFT 24 /* Implemented TX FIFO size */
  104. +#define LTQ_SPI_ID_TXFS_MASK 0x3F
  105. +#define LTQ_SPI_ID_RXFS_SHIFT 16 /* Implemented RX FIFO size */
  106. +#define LTQ_SPI_ID_RXFS_MASK 0x3F
  107. +#define LTQ_SPI_ID_REV_MASK 0x1F /* Hardware revision number */
  108. +#define LTQ_SPI_ID_CFG BIT(5) /* DMA interface support */
  109. +
  110. +#define LTQ_SPI_CON_BM_SHIFT 16 /* Data width selection */
  111. +#define LTQ_SPI_CON_BM_MASK 0x1F
  112. +#define LTQ_SPI_CON_EM BIT(24) /* Echo mode */
  113. +#define LTQ_SPI_CON_IDLE BIT(23) /* Idle bit value */
  114. +#define LTQ_SPI_CON_ENBV BIT(22) /* Enable byte valid control */
  115. +#define LTQ_SPI_CON_RUEN BIT(12) /* Receive underflow error enable */
  116. +#define LTQ_SPI_CON_TUEN BIT(11) /* Transmit underflow error enable */
  117. +#define LTQ_SPI_CON_AEN BIT(10) /* Abort error enable */
  118. +#define LTQ_SPI_CON_REN BIT(9) /* Receive overflow error enable */
  119. +#define LTQ_SPI_CON_TEN BIT(8) /* Transmit overflow error enable */
  120. +#define LTQ_SPI_CON_LB BIT(7) /* Loopback control */
  121. +#define LTQ_SPI_CON_PO BIT(6) /* Clock polarity control */
  122. +#define LTQ_SPI_CON_PH BIT(5) /* Clock phase control */
  123. +#define LTQ_SPI_CON_HB BIT(4) /* Heading control */
  124. +#define LTQ_SPI_CON_RXOFF BIT(1) /* Switch receiver off */
  125. +#define LTQ_SPI_CON_TXOFF BIT(0) /* Switch transmitter off */
  126. +
  127. +#define LTQ_SPI_STAT_RXBV_MASK 0x7
  128. +#define LTQ_SPI_STAT_RXBV_SHIFT 28
  129. +#define LTQ_SPI_STAT_BSY BIT(13) /* Busy flag */
  130. +#define LTQ_SPI_STAT_RUE BIT(12) /* Receive underflow error flag */
  131. +#define LTQ_SPI_STAT_TUE BIT(11) /* Transmit underflow error flag */
  132. +#define LTQ_SPI_STAT_AE BIT(10) /* Abort error flag */
  133. +#define LTQ_SPI_STAT_RE BIT(9) /* Receive error flag */
  134. +#define LTQ_SPI_STAT_TE BIT(8) /* Transmit error flag */
  135. +#define LTQ_SPI_STAT_MS BIT(1) /* Master/slave select bit */
  136. +#define LTQ_SPI_STAT_EN BIT(0) /* Enable bit */
  137. +
  138. +#define LTQ_SPI_WHBSTATE_SETTUE BIT(15) /* Set transmit underflow error flag */
  139. +#define LTQ_SPI_WHBSTATE_SETAE BIT(14) /* Set abort error flag */
  140. +#define LTQ_SPI_WHBSTATE_SETRE BIT(13) /* Set receive error flag */
  141. +#define LTQ_SPI_WHBSTATE_SETTE BIT(12) /* Set transmit error flag */
  142. +#define LTQ_SPI_WHBSTATE_CLRTUE BIT(11) /* Clear transmit underflow error
  143. + flag */
  144. +#define LTQ_SPI_WHBSTATE_CLRAE BIT(10) /* Clear abort error flag */
  145. +#define LTQ_SPI_WHBSTATE_CLRRE BIT(9) /* Clear receive error flag */
  146. +#define LTQ_SPI_WHBSTATE_CLRTE BIT(8) /* Clear transmit error flag */
  147. +#define LTQ_SPI_WHBSTATE_SETME BIT(7) /* Set mode error flag */
  148. +#define LTQ_SPI_WHBSTATE_CLRME BIT(6) /* Clear mode error flag */
  149. +#define LTQ_SPI_WHBSTATE_SETRUE BIT(5) /* Set receive underflow error flag */
  150. +#define LTQ_SPI_WHBSTATE_CLRRUE BIT(4) /* Clear receive underflow error flag */
  151. +#define LTQ_SPI_WHBSTATE_SETMS BIT(3) /* Set master select bit */
  152. +#define LTQ_SPI_WHBSTATE_CLRMS BIT(2) /* Clear master select bit */
  153. +#define LTQ_SPI_WHBSTATE_SETEN BIT(1) /* Set enable bit (operational mode) */
  154. +#define LTQ_SPI_WHBSTATE_CLREN BIT(0) /* Clear enable bit (config mode */
  155. +#define LTQ_SPI_WHBSTATE_CLR_ERRORS 0x0F50
  156. +
  157. +#define LTQ_SPI_RXFCON_RXFITL_SHIFT 8 /* FIFO interrupt trigger level */
  158. +#define LTQ_SPI_RXFCON_RXFITL_MASK 0x3F
  159. +#define LTQ_SPI_RXFCON_RXFLU BIT(1) /* FIFO flush */
  160. +#define LTQ_SPI_RXFCON_RXFEN BIT(0) /* FIFO enable */
  161. +
  162. +#define LTQ_SPI_TXFCON_TXFITL_SHIFT 8 /* FIFO interrupt trigger level */
  163. +#define LTQ_SPI_TXFCON_TXFITL_MASK 0x3F
  164. +#define LTQ_SPI_TXFCON_TXFLU BIT(1) /* FIFO flush */
  165. +#define LTQ_SPI_TXFCON_TXFEN BIT(0) /* FIFO enable */
  166. +
  167. +#define LTQ_SPI_FSTAT_RXFFL_MASK 0x3f
  168. +#define LTQ_SPI_FSTAT_RXFFL_SHIFT 0
  169. +#define LTQ_SPI_FSTAT_TXFFL_MASK 0x3f
  170. +#define LTQ_SPI_FSTAT_TXFFL_SHIFT 8
  171. +
  172. +#define LTQ_SPI_GPOCON_ISCSBN_SHIFT 8
  173. +#define LTQ_SPI_GPOCON_INVOUTN_SHIFT 0
  174. +
  175. +#define LTQ_SPI_FGPO_SETOUTN_SHIFT 8
  176. +#define LTQ_SPI_FGPO_CLROUTN_SHIFT 0
  177. +
  178. +#define LTQ_SPI_RXREQ_RXCNT_MASK 0xFFFF /* Receive count value */
  179. +#define LTQ_SPI_RXCNT_TODO_MASK 0xFFFF /* Recevie to-do value */
  180. +
  181. +#define LTQ_SPI_IRNEN_F BIT(3) /* Frame end interrupt request */
  182. +#define LTQ_SPI_IRNEN_E BIT(2) /* Error end interrupt request */
  183. +#define LTQ_SPI_IRNEN_T BIT(0) /* Transmit end interrupt request */
  184. +#define LTQ_SPI_IRNEN_R BIT(1) /* Receive end interrupt request */
  185. +#define LTQ_SPI_IRNEN_T_XWAY BIT(1) /* Transmit end interrupt request */
  186. +#define LTQ_SPI_IRNEN_R_XWAY BIT(0) /* Receive end interrupt request */
  187. +#define LTQ_SPI_IRNEN_ALL 0xF
  188. +
  189. +struct ltq_spi {
  190. + struct spi_bitbang bitbang;
  191. + struct completion done;
  192. + spinlock_t lock;
  193. +
  194. + struct device *dev;
  195. + void __iomem *base;
  196. + struct clk *fpiclk;
  197. + struct clk *spiclk;
  198. +
  199. + int status;
  200. + int irq[3];
  201. +
  202. + const u8 *tx;
  203. + u8 *rx;
  204. + u32 tx_cnt;
  205. + u32 rx_cnt;
  206. + u32 len;
  207. + struct spi_transfer *curr_transfer;
  208. +
  209. + u32 (*get_tx) (struct ltq_spi *);
  210. +
  211. + u16 txfs;
  212. + u16 rxfs;
  213. + unsigned dma_support:1;
  214. + unsigned cfg_mode:1;
  215. +
  216. + u32 irnen_t;
  217. + u32 irnen_r;
  218. +};
  219. +
  220. +static inline struct ltq_spi *ltq_spi_to_hw(struct spi_device *spi)
  221. +{
  222. + return spi_master_get_devdata(spi->master);
  223. +}
  224. +
  225. +static inline u32 ltq_spi_reg_read(struct ltq_spi *hw, u32 reg)
  226. +{
  227. + return ioread32be(hw->base + reg);
  228. +}
  229. +
  230. +static inline void ltq_spi_reg_write(struct ltq_spi *hw, u32 val, u32 reg)
  231. +{
  232. + iowrite32be(val, hw->base + reg);
  233. +}
  234. +
  235. +static inline void ltq_spi_reg_setbit(struct ltq_spi *hw, u32 bits, u32 reg)
  236. +{
  237. + u32 val;
  238. +
  239. + val = ltq_spi_reg_read(hw, reg);
  240. + val |= bits;
  241. + ltq_spi_reg_write(hw, val, reg);
  242. +}
  243. +
  244. +static inline void ltq_spi_reg_clearbit(struct ltq_spi *hw, u32 bits, u32 reg)
  245. +{
  246. + u32 val;
  247. +
  248. + val = ltq_spi_reg_read(hw, reg);
  249. + val &= ~bits;
  250. + ltq_spi_reg_write(hw, val, reg);
  251. +}
  252. +
  253. +static void ltq_spi_hw_enable(struct ltq_spi *hw)
  254. +{
  255. + u32 clc;
  256. +
  257. + /* Power-up module */
  258. + clk_enable(hw->spiclk);
  259. +
  260. + /*
  261. + * Set clock divider for run mode to 1 to
  262. + * run at same frequency as FPI bus
  263. + */
  264. + clc = (1 << LTQ_SPI_CLC_RMC_SHIFT);
  265. + ltq_spi_reg_write(hw, clc, LTQ_SPI_CLC);
  266. +}
  267. +
  268. +static void ltq_spi_hw_disable(struct ltq_spi *hw)
  269. +{
  270. + /* Set clock divider to 0 and set module disable bit */
  271. + ltq_spi_reg_write(hw, LTQ_SPI_CLC_DISS, LTQ_SPI_CLC);
  272. +
  273. + /* Power-down module */
  274. + clk_disable(hw->spiclk);
  275. +}
  276. +
  277. +static void ltq_spi_reset_fifos(struct ltq_spi *hw)
  278. +{
  279. + u32 val;
  280. +
  281. + /*
  282. + * Enable and flush FIFOs. Set interrupt trigger level to
  283. + * half of FIFO count implemented in hardware.
  284. + */
  285. + if (hw->txfs > 1) {
  286. + val = hw->txfs << (LTQ_SPI_TXFCON_TXFITL_SHIFT - 1);
  287. + val |= LTQ_SPI_TXFCON_TXFEN | LTQ_SPI_TXFCON_TXFLU;
  288. + ltq_spi_reg_write(hw, val, LTQ_SPI_TXFCON);
  289. + }
  290. +
  291. + if (hw->rxfs > 1) {
  292. + val = hw->rxfs << (LTQ_SPI_RXFCON_RXFITL_SHIFT - 1);
  293. + val |= LTQ_SPI_RXFCON_RXFEN | LTQ_SPI_RXFCON_RXFLU;
  294. + ltq_spi_reg_write(hw, val, LTQ_SPI_RXFCON);
  295. + }
  296. +}
  297. +
  298. +static inline int ltq_spi_wait_ready(struct ltq_spi *hw)
  299. +{
  300. + u32 stat;
  301. + unsigned long timeout;
  302. +
  303. + timeout = jiffies + msecs_to_jiffies(200);
  304. +
  305. + do {
  306. + stat = ltq_spi_reg_read(hw, LTQ_SPI_STAT);
  307. + if (!(stat & LTQ_SPI_STAT_BSY))
  308. + return 0;
  309. +
  310. + cond_resched();
  311. + } while (!time_after_eq(jiffies, timeout));
  312. +
  313. + dev_err(hw->dev, "SPI wait ready timed out stat: %x\n", stat);
  314. +
  315. + return -ETIMEDOUT;
  316. +}
  317. +
  318. +static void ltq_spi_config_mode_set(struct ltq_spi *hw)
  319. +{
  320. + if (hw->cfg_mode)
  321. + return;
  322. +
  323. + /*
  324. + * Putting the SPI module in config mode is only safe if no
  325. + * transfer is in progress as indicated by busy flag STATE.BSY.
  326. + */
  327. + if (ltq_spi_wait_ready(hw)) {
  328. + ltq_spi_reset_fifos(hw);
  329. + hw->status = -ETIMEDOUT;
  330. + }
  331. + ltq_spi_reg_write(hw, LTQ_SPI_WHBSTATE_CLREN, LTQ_SPI_WHBSTATE);
  332. +
  333. + hw->cfg_mode = 1;
  334. +}
  335. +
  336. +static void ltq_spi_run_mode_set(struct ltq_spi *hw)
  337. +{
  338. + if (!hw->cfg_mode)
  339. + return;
  340. +
  341. + ltq_spi_reg_write(hw, LTQ_SPI_WHBSTATE_SETEN, LTQ_SPI_WHBSTATE);
  342. +
  343. + hw->cfg_mode = 0;
  344. +}
  345. +
  346. +static u32 ltq_spi_tx_word_u8(struct ltq_spi *hw)
  347. +{
  348. + const u8 *tx = hw->tx;
  349. + u32 data = *tx++;
  350. +
  351. + hw->tx_cnt++;
  352. + hw->tx++;
  353. +
  354. + return data;
  355. +}
  356. +
  357. +static u32 ltq_spi_tx_word_u16(struct ltq_spi *hw)
  358. +{
  359. + const u16 *tx = (u16 *) hw->tx;
  360. + u32 data = *tx++;
  361. +
  362. + hw->tx_cnt += 2;
  363. + hw->tx += 2;
  364. +
  365. + return data;
  366. +}
  367. +
  368. +static u32 ltq_spi_tx_word_u32(struct ltq_spi *hw)
  369. +{
  370. + const u32 *tx = (u32 *) hw->tx;
  371. + u32 data = *tx++;
  372. +
  373. + hw->tx_cnt += 4;
  374. + hw->tx += 4;
  375. +
  376. + return data;
  377. +}
  378. +
  379. +static void ltq_spi_bits_per_word_set(struct spi_device *spi)
  380. +{
  381. + struct ltq_spi *hw = ltq_spi_to_hw(spi);
  382. + u32 bm;
  383. + u8 bits_per_word = spi->bits_per_word;
  384. +
  385. + /*
  386. + * Use either default value of SPI device or value
  387. + * from current transfer.
  388. + */
  389. + if (hw->curr_transfer && hw->curr_transfer->bits_per_word)
  390. + bits_per_word = hw->curr_transfer->bits_per_word;
  391. +
  392. + if (bits_per_word <= 8)
  393. + hw->get_tx = ltq_spi_tx_word_u8;
  394. + else if (bits_per_word <= 16)
  395. + hw->get_tx = ltq_spi_tx_word_u16;
  396. + else if (bits_per_word <= 32)
  397. + hw->get_tx = ltq_spi_tx_word_u32;
  398. +
  399. + /* CON.BM value = bits_per_word - 1 */
  400. + bm = (bits_per_word - 1) << LTQ_SPI_CON_BM_SHIFT;
  401. +
  402. + ltq_spi_reg_clearbit(hw, LTQ_SPI_CON_BM_MASK <<
  403. + LTQ_SPI_CON_BM_SHIFT, LTQ_SPI_CON);
  404. + ltq_spi_reg_setbit(hw, bm, LTQ_SPI_CON);
  405. +}
  406. +
  407. +static void ltq_spi_speed_set(struct spi_device *spi)
  408. +{
  409. + struct ltq_spi *hw = ltq_spi_to_hw(spi);
  410. + u32 br, max_speed_hz, spi_clk;
  411. + u32 speed_hz = spi->max_speed_hz;
  412. +
  413. + /*
  414. + * Use either default value of SPI device or value
  415. + * from current transfer.
  416. + */
  417. + if (hw->curr_transfer && hw->curr_transfer->speed_hz)
  418. + speed_hz = hw->curr_transfer->speed_hz;
  419. +
  420. + /*
  421. + * SPI module clock is derived from FPI bus clock dependent on
  422. + * divider value in CLC.RMS which is always set to 1.
  423. + */
  424. + spi_clk = clk_get_rate(hw->fpiclk);
  425. +
  426. + /*
  427. + * Maximum SPI clock frequency in master mode is half of
  428. + * SPI module clock frequency. Maximum reload value of
  429. + * baudrate generator BR is 2^16.
  430. + */
  431. + max_speed_hz = spi_clk / 2;
  432. + if (speed_hz >= max_speed_hz)
  433. + br = 0;
  434. + else
  435. + br = (max_speed_hz / speed_hz) - 1;
  436. +
  437. + if (br > 0xFFFF)
  438. + br = 0xFFFF;
  439. +
  440. + ltq_spi_reg_write(hw, br, LTQ_SPI_BRT);
  441. +}
  442. +
  443. +static void ltq_spi_clockmode_set(struct spi_device *spi)
  444. +{
  445. + struct ltq_spi *hw = ltq_spi_to_hw(spi);
  446. + u32 con;
  447. +
  448. + con = ltq_spi_reg_read(hw, LTQ_SPI_CON);
  449. +
  450. + /*
  451. + * SPI mode mapping in CON register:
  452. + * Mode CPOL CPHA CON.PO CON.PH
  453. + * 0 0 0 0 1
  454. + * 1 0 1 0 0
  455. + * 2 1 0 1 1
  456. + * 3 1 1 1 0
  457. + */
  458. + if (spi->mode & SPI_CPHA)
  459. + con &= ~LTQ_SPI_CON_PH;
  460. + else
  461. + con |= LTQ_SPI_CON_PH;
  462. +
  463. + if (spi->mode & SPI_CPOL)
  464. + con |= LTQ_SPI_CON_PO;
  465. + else
  466. + con &= ~LTQ_SPI_CON_PO;
  467. +
  468. + /* Set heading control */
  469. + if (spi->mode & SPI_LSB_FIRST)
  470. + con &= ~LTQ_SPI_CON_HB;
  471. + else
  472. + con |= LTQ_SPI_CON_HB;
  473. +
  474. + ltq_spi_reg_write(hw, con, LTQ_SPI_CON);
  475. +}
  476. +
  477. +static void ltq_spi_xmit_set(struct ltq_spi *hw, struct spi_transfer *t)
  478. +{
  479. + u32 con;
  480. +
  481. + con = ltq_spi_reg_read(hw, LTQ_SPI_CON);
  482. +
  483. + if (t) {
  484. + if (t->tx_buf && t->rx_buf) {
  485. + con &= ~(LTQ_SPI_CON_TXOFF | LTQ_SPI_CON_RXOFF);
  486. + } else if (t->rx_buf) {
  487. + con &= ~LTQ_SPI_CON_RXOFF;
  488. + con |= LTQ_SPI_CON_TXOFF;
  489. + } else if (t->tx_buf) {
  490. + con &= ~LTQ_SPI_CON_TXOFF;
  491. + con |= LTQ_SPI_CON_RXOFF;
  492. + }
  493. + } else
  494. + con |= (LTQ_SPI_CON_TXOFF | LTQ_SPI_CON_RXOFF);
  495. +
  496. + ltq_spi_reg_write(hw, con, LTQ_SPI_CON);
  497. +}
  498. +
  499. +static void ltq_spi_internal_cs_activate(struct spi_device *spi)
  500. +{
  501. + struct ltq_spi *hw = ltq_spi_to_hw(spi);
  502. + u32 fgpo;
  503. +
  504. + fgpo = (1 << (spi->chip_select + LTQ_SPI_FGPO_CLROUTN_SHIFT));
  505. + ltq_spi_reg_setbit(hw, fgpo, LTQ_SPI_FGPO);
  506. +}
  507. +
  508. +static void ltq_spi_internal_cs_deactivate(struct spi_device *spi)
  509. +{
  510. + struct ltq_spi *hw = ltq_spi_to_hw(spi);
  511. + u32 fgpo;
  512. +
  513. + fgpo = (1 << (spi->chip_select + LTQ_SPI_FGPO_SETOUTN_SHIFT));
  514. + ltq_spi_reg_setbit(hw, fgpo, LTQ_SPI_FGPO);
  515. +}
  516. +
  517. +static void ltq_spi_chipselect(struct spi_device *spi, int cs)
  518. +{
  519. + struct ltq_spi *hw = ltq_spi_to_hw(spi);
  520. +
  521. + if (ltq_spi_wait_ready(hw))
  522. + dev_err(&spi->dev, "wait failed\n");
  523. +
  524. + switch (cs) {
  525. + case BITBANG_CS_ACTIVE:
  526. + ltq_spi_bits_per_word_set(spi);
  527. + ltq_spi_speed_set(spi);
  528. + ltq_spi_clockmode_set(spi);
  529. + ltq_spi_run_mode_set(hw);
  530. + ltq_spi_internal_cs_activate(spi);
  531. + break;
  532. +
  533. + case BITBANG_CS_INACTIVE:
  534. + ltq_spi_internal_cs_deactivate(spi);
  535. + ltq_spi_config_mode_set(hw);
  536. + break;
  537. + }
  538. +}
  539. +
  540. +static int ltq_spi_setup_transfer(struct spi_device *spi,
  541. + struct spi_transfer *t)
  542. +{
  543. + struct ltq_spi *hw = ltq_spi_to_hw(spi);
  544. + u8 bits_per_word = spi->bits_per_word;
  545. +
  546. + hw->curr_transfer = t;
  547. +
  548. + if (t && t->bits_per_word)
  549. + bits_per_word = t->bits_per_word;
  550. +
  551. + if (bits_per_word > 32)
  552. + return -EINVAL;
  553. +
  554. + return 0;
  555. +}
  556. +
  557. +static int ltq_spi_setup(struct spi_device *spi)
  558. +{
  559. + struct ltq_spi *hw = ltq_spi_to_hw(spi);
  560. + u32 gpocon, fgpo;
  561. +
  562. + /* Set default word length to 8 if not set */
  563. + if (!spi->bits_per_word)
  564. + spi->bits_per_word = 8;
  565. +
  566. + if (spi->bits_per_word > 32)
  567. + return -EINVAL;
  568. +
  569. + /*
  570. + * Up to six GPIOs can be connected to the SPI module
  571. + * via GPIO alternate function to control the chip select lines.
  572. + */
  573. + gpocon = (1 << (spi->chip_select +
  574. + LTQ_SPI_GPOCON_ISCSBN_SHIFT));
  575. +
  576. + if (spi->mode & SPI_CS_HIGH)
  577. + gpocon |= (1 << spi->chip_select);
  578. +
  579. + fgpo = (1 << (spi->chip_select + LTQ_SPI_FGPO_SETOUTN_SHIFT));
  580. +
  581. + ltq_spi_reg_setbit(hw, gpocon, LTQ_SPI_GPOCON);
  582. + ltq_spi_reg_setbit(hw, fgpo, LTQ_SPI_FGPO);
  583. +
  584. + return 0;
  585. +}
  586. +
  587. +static void ltq_spi_cleanup(struct spi_device *spi)
  588. +{
  589. +
  590. +}
  591. +
  592. +static void ltq_spi_txfifo_write(struct ltq_spi *hw)
  593. +{
  594. + u32 fstat, data;
  595. + u16 fifo_space;
  596. +
  597. + /* Determine how much FIFOs are free for TX data */
  598. + fstat = ltq_spi_reg_read(hw, LTQ_SPI_FSTAT);
  599. + fifo_space = hw->txfs - ((fstat >> LTQ_SPI_FSTAT_TXFFL_SHIFT) &
  600. + LTQ_SPI_FSTAT_TXFFL_MASK);
  601. +
  602. + if (!fifo_space)
  603. + return;
  604. +
  605. + while (hw->tx_cnt < hw->len && fifo_space) {
  606. + data = hw->get_tx(hw);
  607. + ltq_spi_reg_write(hw, data, LTQ_SPI_TB);
  608. + fifo_space--;
  609. + }
  610. +}
  611. +
  612. +static void ltq_spi_rxfifo_read(struct ltq_spi *hw)
  613. +{
  614. + u32 fstat, data, *rx32;
  615. + u16 fifo_fill;
  616. + u8 rxbv, shift, *rx8;
  617. +
  618. + /* Determine how much FIFOs are filled with RX data */
  619. + fstat = ltq_spi_reg_read(hw, LTQ_SPI_FSTAT);
  620. + fifo_fill = ((fstat >> LTQ_SPI_FSTAT_RXFFL_SHIFT)
  621. + & LTQ_SPI_FSTAT_RXFFL_MASK);
  622. +
  623. + if (!fifo_fill)
  624. + return;
  625. +
  626. + /*
  627. + * The 32 bit FIFO is always used completely independent from the
  628. + * bits_per_word value. Thus four bytes have to be read at once
  629. + * per FIFO.
  630. + */
  631. + rx32 = (u32 *) hw->rx;
  632. + while (hw->len - hw->rx_cnt >= 4 && fifo_fill) {
  633. + *rx32++ = ltq_spi_reg_read(hw, LTQ_SPI_RB);
  634. + hw->rx_cnt += 4;
  635. + hw->rx += 4;
  636. + fifo_fill--;
  637. + }
  638. +
  639. + /*
  640. + * If there are remaining bytes, read byte count from STAT.RXBV
  641. + * register and read the data byte-wise.
  642. + */
  643. + while (fifo_fill && hw->rx_cnt < hw->len) {
  644. + rxbv = (ltq_spi_reg_read(hw, LTQ_SPI_STAT) >>
  645. + LTQ_SPI_STAT_RXBV_SHIFT) & LTQ_SPI_STAT_RXBV_MASK;
  646. + data = ltq_spi_reg_read(hw, LTQ_SPI_RB);
  647. +
  648. + shift = (rxbv - 1) * 8;
  649. + rx8 = hw->rx;
  650. +
  651. + while (rxbv) {
  652. + *rx8++ = (data >> shift) & 0xFF;
  653. + rxbv--;
  654. + shift -= 8;
  655. + hw->rx_cnt++;
  656. + hw->rx++;
  657. + }
  658. +
  659. + fifo_fill--;
  660. + }
  661. +}
  662. +
  663. +static void ltq_spi_rxreq_set(struct ltq_spi *hw)
  664. +{
  665. + u32 rxreq, rxreq_max, rxtodo;
  666. + u32 fstat, fifo_fill;
  667. +
  668. + rxtodo = ltq_spi_reg_read(hw, LTQ_SPI_RXCNT) & LTQ_SPI_RXCNT_TODO_MASK;
  669. +
  670. + /*
  671. + * Check if there is remaining data in the FIFO before starting a new
  672. + * receive request. The controller might have processed some more data
  673. + * since the last FIFO poll.
  674. + */
  675. + fstat = ltq_spi_reg_read(hw, LTQ_SPI_FSTAT);
  676. + fifo_fill = ((fstat >> LTQ_SPI_FSTAT_RXFFL_SHIFT)
  677. + & LTQ_SPI_FSTAT_RXFFL_MASK);
  678. + if (fifo_fill)
  679. + return;
  680. +
  681. + /*
  682. + * In RX-only mode the serial clock is activated only after writing
  683. + * the expected amount of RX bytes into RXREQ register.
  684. + * To avoid receive overflows at high clocks it is better to request
  685. + * only the amount of bytes that fits into all FIFOs. This value
  686. + * depends on the FIFO size implemented in hardware.
  687. + */
  688. + rxreq = hw->len - hw->rx_cnt;
  689. + rxreq_max = hw->rxfs << 2;
  690. + rxreq = min(rxreq_max, rxreq);
  691. +
  692. + if (!rxtodo && rxreq)
  693. + ltq_spi_reg_write(hw, rxreq, LTQ_SPI_RXREQ);
  694. +}
  695. +
  696. +static inline void ltq_spi_complete(struct ltq_spi *hw)
  697. +{
  698. + complete(&hw->done);
  699. +}
  700. +
  701. +irqreturn_t ltq_spi_tx_irq(int irq, void *data)
  702. +{
  703. + struct ltq_spi *hw = data;
  704. + unsigned long flags;
  705. + int completed = 0;
  706. +
  707. + spin_lock_irqsave(&hw->lock, flags);
  708. +
  709. + if (hw->tx_cnt < hw->len)
  710. + ltq_spi_txfifo_write(hw);
  711. +
  712. + if (hw->tx_cnt == hw->len)
  713. + completed = 1;
  714. +
  715. + spin_unlock_irqrestore(&hw->lock, flags);
  716. +
  717. + if (completed)
  718. + ltq_spi_complete(hw);
  719. +
  720. + return IRQ_HANDLED;
  721. +}
  722. +
  723. +irqreturn_t ltq_spi_rx_irq(int irq, void *data)
  724. +{
  725. + struct ltq_spi *hw = data;
  726. + unsigned long flags;
  727. + int completed = 0;
  728. +
  729. + spin_lock_irqsave(&hw->lock, flags);
  730. +
  731. + if (hw->rx_cnt < hw->len) {
  732. + ltq_spi_rxfifo_read(hw);
  733. +
  734. + if (hw->tx && hw->tx_cnt < hw->len)
  735. + ltq_spi_txfifo_write(hw);
  736. + }
  737. +
  738. + if (hw->rx_cnt == hw->len)
  739. + completed = 1;
  740. + else if (!hw->tx)
  741. + ltq_spi_rxreq_set(hw);
  742. +
  743. + spin_unlock_irqrestore(&hw->lock, flags);
  744. +
  745. + if (completed)
  746. + ltq_spi_complete(hw);
  747. +
  748. + return IRQ_HANDLED;
  749. +}
  750. +
  751. +irqreturn_t ltq_spi_err_irq(int irq, void *data)
  752. +{
  753. + struct ltq_spi *hw = data;
  754. + unsigned long flags;
  755. +
  756. + spin_lock_irqsave(&hw->lock, flags);
  757. +
  758. + /* Disable all interrupts */
  759. + ltq_spi_reg_clearbit(hw, LTQ_SPI_IRNEN_ALL, LTQ_SPI_IRNEN);
  760. +
  761. + dev_err(hw->dev, "error %x\n", ltq_spi_reg_read(hw, LTQ_SPI_STAT));
  762. +
  763. + /* Clear all error flags */
  764. + ltq_spi_reg_write(hw, LTQ_SPI_WHBSTATE_CLR_ERRORS, LTQ_SPI_WHBSTATE);
  765. +
  766. + /* Flush FIFOs */
  767. + ltq_spi_reg_setbit(hw, LTQ_SPI_RXFCON_RXFLU, LTQ_SPI_RXFCON);
  768. + ltq_spi_reg_setbit(hw, LTQ_SPI_TXFCON_TXFLU, LTQ_SPI_TXFCON);
  769. +
  770. + hw->status = -EIO;
  771. + spin_unlock_irqrestore(&hw->lock, flags);
  772. +
  773. + ltq_spi_complete(hw);
  774. +
  775. + return IRQ_HANDLED;
  776. +}
  777. +
  778. +static int ltq_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
  779. +{
  780. + struct ltq_spi *hw = ltq_spi_to_hw(spi);
  781. + u32 irq_flags = 0;
  782. +
  783. + hw->tx = t->tx_buf;
  784. + hw->rx = t->rx_buf;
  785. + hw->len = t->len;
  786. + hw->tx_cnt = 0;
  787. + hw->rx_cnt = 0;
  788. + hw->status = 0;
  789. + init_completion(&hw->done);
  790. +
  791. + ltq_spi_xmit_set(hw, t);
  792. +
  793. + /* Enable error interrupts */
  794. + ltq_spi_reg_setbit(hw, LTQ_SPI_IRNEN_E, LTQ_SPI_IRNEN);
  795. +
  796. + if (hw->tx) {
  797. + /* Initially fill TX FIFO with as much data as possible */
  798. + ltq_spi_txfifo_write(hw);
  799. + irq_flags |= hw->irnen_t;
  800. +
  801. + /* Always enable RX interrupt in Full Duplex mode */
  802. + if (hw->rx)
  803. + irq_flags |= hw->irnen_r;
  804. + } else if (hw->rx) {
  805. + /* Start RX clock */
  806. + ltq_spi_rxreq_set(hw);
  807. +
  808. + /* Enable RX interrupt to receive data from RX FIFOs */
  809. + irq_flags |= hw->irnen_r;
  810. + }
  811. +
  812. + /* Enable TX or RX interrupts */
  813. + ltq_spi_reg_setbit(hw, irq_flags, LTQ_SPI_IRNEN);
  814. + wait_for_completion(&hw->done);
  815. +
  816. + /* Disable all interrupts */
  817. + ltq_spi_reg_clearbit(hw, LTQ_SPI_IRNEN_ALL, LTQ_SPI_IRNEN);
  818. +
  819. + /*
  820. + * Return length of current transfer for bitbang utility code if
  821. + * no errors occured during transmission.
  822. + */
  823. + if (!hw->status)
  824. + hw->status = hw->len;
  825. +
  826. + return hw->status;
  827. +}
  828. +
  829. +static const struct ltq_spi_irq_map {
  830. + char *name;
  831. + irq_handler_t handler;
  832. +} ltq_spi_irqs[] = {
  833. + { "spi_rx", ltq_spi_rx_irq },
  834. + { "spi_tx", ltq_spi_tx_irq },
  835. + { "spi_err", ltq_spi_err_irq },
  836. +};
  837. +
  838. +static int ltq_spi_probe(struct platform_device *pdev)
  839. +{
  840. + struct resource irqres[3];
  841. + struct spi_master *master;
  842. + struct resource *r;
  843. + struct ltq_spi *hw;
  844. + int ret, i;
  845. + u32 data, id;
  846. +
  847. + if (of_irq_to_resource_table(pdev->dev.of_node, irqres, 3) != 3) {
  848. + dev_err(&pdev->dev, "IRQ settings missing in device tree\n");
  849. + return -EINVAL;
  850. + }
  851. +
  852. + master = spi_alloc_master(&pdev->dev, sizeof(struct ltq_spi));
  853. + if (!master) {
  854. + dev_err(&pdev->dev, "spi_alloc_master\n");
  855. + ret = -ENOMEM;
  856. + goto err;
  857. + }
  858. +
  859. + hw = spi_master_get_devdata(master);
  860. +
  861. + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  862. + if (r == NULL) {
  863. + dev_err(&pdev->dev, "platform_get_resource\n");
  864. + ret = -ENOENT;
  865. + goto err_master;
  866. + }
  867. +
  868. + r = devm_request_mem_region(&pdev->dev, r->start, resource_size(r),
  869. + pdev->name);
  870. + if (!r) {
  871. + dev_err(&pdev->dev, "failed to request memory region\n");
  872. + ret = -ENXIO;
  873. + goto err_master;
  874. + }
  875. +
  876. + hw->base = devm_ioremap_nocache(&pdev->dev, r->start, resource_size(r));
  877. + if (!hw->base) {
  878. + dev_err(&pdev->dev, "failed to remap memory region\n");
  879. + ret = -ENXIO;
  880. + goto err_master;
  881. + }
  882. +
  883. + memset(hw->irq, 0, sizeof(hw->irq));
  884. + for (i = 0; i < ARRAY_SIZE(ltq_spi_irqs); i++) {
  885. + hw->irq[i] = irqres[i].start;
  886. + ret = request_irq(hw->irq[i], ltq_spi_irqs[i].handler,
  887. + 0, ltq_spi_irqs[i].name, hw);
  888. + if (ret) {
  889. + dev_err(&pdev->dev, "failed to request %s irq (%d)\n",
  890. + ltq_spi_irqs[i].name, hw->irq[i]);
  891. + goto err_irq;
  892. + }
  893. + }
  894. +
  895. + hw->fpiclk = clk_get_fpi();
  896. + if (IS_ERR(hw->fpiclk)) {
  897. + dev_err(&pdev->dev, "failed to get fpi clock\n");
  898. + ret = PTR_ERR(hw->fpiclk);
  899. + goto err_clk;
  900. + }
  901. +
  902. + hw->spiclk = clk_get(&pdev->dev, NULL);
  903. + if (IS_ERR(hw->spiclk)) {
  904. + dev_err(&pdev->dev, "failed to get spi clock gate\n");
  905. + ret = PTR_ERR(hw->spiclk);
  906. + goto err_clk;
  907. + }
  908. +
  909. + hw->bitbang.master = spi_master_get(master);
  910. + hw->bitbang.chipselect = ltq_spi_chipselect;
  911. + hw->bitbang.setup_transfer = ltq_spi_setup_transfer;
  912. + hw->bitbang.txrx_bufs = ltq_spi_txrx_bufs;
  913. +
  914. + if (of_machine_is_compatible("lantiq,ase")) {
  915. + master->num_chipselect = 3;
  916. +
  917. + hw->irnen_t = LTQ_SPI_IRNEN_T_XWAY;
  918. + hw->irnen_r = LTQ_SPI_IRNEN_R_XWAY;
  919. + } else {
  920. + master->num_chipselect = 6;
  921. +
  922. + hw->irnen_t = LTQ_SPI_IRNEN_T;
  923. + hw->irnen_r = LTQ_SPI_IRNEN_R;
  924. + }
  925. +
  926. + master->bus_num = pdev->id;
  927. + master->setup = ltq_spi_setup;
  928. + master->cleanup = ltq_spi_cleanup;
  929. + master->dev.of_node = pdev->dev.of_node;
  930. +
  931. + hw->dev = &pdev->dev;
  932. + init_completion(&hw->done);
  933. + spin_lock_init(&hw->lock);
  934. +
  935. + ltq_spi_hw_enable(hw);
  936. +
  937. + /* Read module capabilities */
  938. + id = ltq_spi_reg_read(hw, LTQ_SPI_ID);
  939. + hw->txfs = (id >> LTQ_SPI_ID_TXFS_SHIFT) & LTQ_SPI_ID_TXFS_MASK;
  940. + hw->rxfs = (id >> LTQ_SPI_ID_RXFS_SHIFT) & LTQ_SPI_ID_RXFS_MASK;
  941. + hw->dma_support = (id & LTQ_SPI_ID_CFG) ? 1 : 0;
  942. +
  943. + ltq_spi_config_mode_set(hw);
  944. +
  945. + /* Enable error checking, disable TX/RX, set idle value high */
  946. + data = LTQ_SPI_CON_RUEN | LTQ_SPI_CON_AEN |
  947. + LTQ_SPI_CON_TEN | LTQ_SPI_CON_REN |
  948. + LTQ_SPI_CON_TXOFF | LTQ_SPI_CON_RXOFF | LTQ_SPI_CON_IDLE;
  949. + ltq_spi_reg_write(hw, data, LTQ_SPI_CON);
  950. +
  951. + /* Enable master mode and clear error flags */
  952. + ltq_spi_reg_write(hw, LTQ_SPI_WHBSTATE_SETMS |
  953. + LTQ_SPI_WHBSTATE_CLR_ERRORS, LTQ_SPI_WHBSTATE);
  954. +
  955. + /* Reset GPIO/CS registers */
  956. + ltq_spi_reg_write(hw, 0x0, LTQ_SPI_GPOCON);
  957. + ltq_spi_reg_write(hw, 0xFF00, LTQ_SPI_FGPO);
  958. +
  959. + /* Enable and flush FIFOs */
  960. + ltq_spi_reset_fifos(hw);
  961. +
  962. + ret = spi_bitbang_start(&hw->bitbang);
  963. + if (ret) {
  964. + dev_err(&pdev->dev, "spi_bitbang_start failed\n");
  965. + goto err_bitbang;
  966. + }
  967. +
  968. + platform_set_drvdata(pdev, hw);
  969. +
  970. + pr_info("Lantiq SoC SPI controller rev %u (TXFS %u, RXFS %u, DMA %u)\n",
  971. + id & LTQ_SPI_ID_REV_MASK, hw->txfs, hw->rxfs, hw->dma_support);
  972. +
  973. + return 0;
  974. +
  975. +err_bitbang:
  976. + ltq_spi_hw_disable(hw);
  977. +
  978. +err_clk:
  979. + if (hw->fpiclk)
  980. + clk_put(hw->fpiclk);
  981. + if (hw->spiclk)
  982. + clk_put(hw->spiclk);
  983. +
  984. +err_irq:
  985. + clk_put(hw->fpiclk);
  986. +
  987. + for (; i > 0; i--)
  988. + free_irq(hw->irq[i], hw);
  989. +
  990. +err_master:
  991. + spi_master_put(master);
  992. +
  993. +err:
  994. + return ret;
  995. +}
  996. +
  997. +static int ltq_spi_remove(struct platform_device *pdev)
  998. +{
  999. + struct ltq_spi *hw = platform_get_drvdata(pdev);
  1000. + int i;
  1001. +
  1002. + spi_bitbang_stop(&hw->bitbang);
  1003. +
  1004. + platform_set_drvdata(pdev, NULL);
  1005. +
  1006. + ltq_spi_config_mode_set(hw);
  1007. + ltq_spi_hw_disable(hw);
  1008. +
  1009. + for (i = 0; i < ARRAY_SIZE(hw->irq); i++)
  1010. + if (0 < hw->irq[i])
  1011. + free_irq(hw->irq[i], hw);
  1012. +
  1013. + if (hw->fpiclk)
  1014. + clk_put(hw->fpiclk);
  1015. + if (hw->spiclk)
  1016. + clk_put(hw->spiclk);
  1017. +
  1018. + spi_master_put(hw->bitbang.master);
  1019. +
  1020. + return 0;
  1021. +}
  1022. +
  1023. +static const struct of_device_id ltq_spi_match[] = {
  1024. + { .compatible = "lantiq,spi-xway" },
  1025. + {},
  1026. +};
  1027. +MODULE_DEVICE_TABLE(of, ltq_spi_match);
  1028. +
  1029. +static struct platform_driver ltq_spi_driver = {
  1030. + .probe = ltq_spi_probe,
  1031. + .remove = ltq_spi_remove,
  1032. + .driver = {
  1033. + .name = "spi-xway",
  1034. + .owner = THIS_MODULE,
  1035. + .of_match_table = ltq_spi_match,
  1036. + },
  1037. +};
  1038. +
  1039. +module_platform_driver(ltq_spi_driver);
  1040. +
  1041. +MODULE_DESCRIPTION("Lantiq SoC SPI controller driver");
  1042. +MODULE_AUTHOR("Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>");
  1043. +MODULE_LICENSE("GPL");
  1044. +MODULE_ALIAS("platform:spi-xway");