spi-orion.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * Marvell Orion SPI controller driver
  3. *
  4. * Author: Shadi Ammouri <shadi@marvell.com>
  5. * Copyright (C) 2007-2008 Marvell Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/interrupt.h>
  12. #include <linux/delay.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/err.h>
  15. #include <linux/io.h>
  16. #include <linux/spi/spi.h>
  17. #include <linux/module.h>
  18. #include <linux/pm_runtime.h>
  19. #include <linux/of.h>
  20. #include <linux/of_device.h>
  21. #include <linux/clk.h>
  22. #include <linux/sizes.h>
  23. #include <asm/unaligned.h>
  24. #define DRIVER_NAME "orion_spi"
  25. /* Runtime PM autosuspend timeout: PM is fairly light on this driver */
  26. #define SPI_AUTOSUSPEND_TIMEOUT 200
  27. /* Some SoCs using this driver support up to 8 chip selects.
  28. * It is up to the implementer to only use the chip selects
  29. * that are available.
  30. */
  31. #define ORION_NUM_CHIPSELECTS 8
  32. #define ORION_SPI_WAIT_RDY_MAX_LOOP 2000 /* in usec */
  33. #define ORION_SPI_IF_CTRL_REG 0x00
  34. #define ORION_SPI_IF_CONFIG_REG 0x04
  35. #define ORION_SPI_DATA_OUT_REG 0x08
  36. #define ORION_SPI_DATA_IN_REG 0x0c
  37. #define ORION_SPI_INT_CAUSE_REG 0x10
  38. #define ORION_SPI_TIMING_PARAMS_REG 0x18
  39. #define ORION_SPI_TMISO_SAMPLE_MASK (0x3 << 6)
  40. #define ORION_SPI_TMISO_SAMPLE_1 (1 << 6)
  41. #define ORION_SPI_TMISO_SAMPLE_2 (2 << 6)
  42. #define ORION_SPI_MODE_CPOL (1 << 11)
  43. #define ORION_SPI_MODE_CPHA (1 << 12)
  44. #define ORION_SPI_IF_8_16_BIT_MODE (1 << 5)
  45. #define ORION_SPI_CLK_PRESCALE_MASK 0x1F
  46. #define ARMADA_SPI_CLK_PRESCALE_MASK 0xDF
  47. #define ORION_SPI_MODE_MASK (ORION_SPI_MODE_CPOL | \
  48. ORION_SPI_MODE_CPHA)
  49. #define ORION_SPI_CS_MASK 0x1C
  50. #define ORION_SPI_CS_SHIFT 2
  51. #define ORION_SPI_CS(cs) ((cs << ORION_SPI_CS_SHIFT) & \
  52. ORION_SPI_CS_MASK)
  53. enum orion_spi_type {
  54. ORION_SPI,
  55. ARMADA_SPI,
  56. };
  57. struct orion_spi_dev {
  58. enum orion_spi_type typ;
  59. /*
  60. * min_divisor and max_hz should be exclusive, the only we can
  61. * have both is for managing the armada-370-spi case with old
  62. * device tree
  63. */
  64. unsigned long max_hz;
  65. unsigned int min_divisor;
  66. unsigned int max_divisor;
  67. u32 prescale_mask;
  68. bool is_errata_50mhz_ac;
  69. };
  70. struct orion_spi {
  71. struct spi_master *master;
  72. void __iomem *base;
  73. struct clk *clk;
  74. const struct orion_spi_dev *devdata;
  75. };
  76. static inline void __iomem *spi_reg(struct orion_spi *orion_spi, u32 reg)
  77. {
  78. return orion_spi->base + reg;
  79. }
  80. static inline void
  81. orion_spi_setbits(struct orion_spi *orion_spi, u32 reg, u32 mask)
  82. {
  83. void __iomem *reg_addr = spi_reg(orion_spi, reg);
  84. u32 val;
  85. val = readl(reg_addr);
  86. val |= mask;
  87. writel(val, reg_addr);
  88. }
  89. static inline void
  90. orion_spi_clrbits(struct orion_spi *orion_spi, u32 reg, u32 mask)
  91. {
  92. void __iomem *reg_addr = spi_reg(orion_spi, reg);
  93. u32 val;
  94. val = readl(reg_addr);
  95. val &= ~mask;
  96. writel(val, reg_addr);
  97. }
  98. static int orion_spi_baudrate_set(struct spi_device *spi, unsigned int speed)
  99. {
  100. u32 tclk_hz;
  101. u32 rate;
  102. u32 prescale;
  103. u32 reg;
  104. struct orion_spi *orion_spi;
  105. const struct orion_spi_dev *devdata;
  106. orion_spi = spi_master_get_devdata(spi->master);
  107. devdata = orion_spi->devdata;
  108. tclk_hz = clk_get_rate(orion_spi->clk);
  109. if (devdata->typ == ARMADA_SPI) {
  110. unsigned int clk, spr, sppr, sppr2, err;
  111. unsigned int best_spr, best_sppr, best_err;
  112. best_err = speed;
  113. best_spr = 0;
  114. best_sppr = 0;
  115. /* Iterate over the valid range looking for best fit */
  116. for (sppr = 0; sppr < 8; sppr++) {
  117. sppr2 = 0x1 << sppr;
  118. spr = tclk_hz / sppr2;
  119. spr = DIV_ROUND_UP(spr, speed);
  120. if ((spr == 0) || (spr > 15))
  121. continue;
  122. clk = tclk_hz / (spr * sppr2);
  123. err = speed - clk;
  124. if (err < best_err) {
  125. best_spr = spr;
  126. best_sppr = sppr;
  127. best_err = err;
  128. }
  129. }
  130. if ((best_sppr == 0) && (best_spr == 0))
  131. return -EINVAL;
  132. prescale = ((best_sppr & 0x6) << 5) |
  133. ((best_sppr & 0x1) << 4) | best_spr;
  134. } else {
  135. /*
  136. * the supported rates are: 4,6,8...30
  137. * round up as we look for equal or less speed
  138. */
  139. rate = DIV_ROUND_UP(tclk_hz, speed);
  140. rate = roundup(rate, 2);
  141. /* check if requested speed is too small */
  142. if (rate > 30)
  143. return -EINVAL;
  144. if (rate < 4)
  145. rate = 4;
  146. /* Convert the rate to SPI clock divisor value. */
  147. prescale = 0x10 + rate/2;
  148. }
  149. reg = readl(spi_reg(orion_spi, ORION_SPI_IF_CONFIG_REG));
  150. reg = ((reg & ~devdata->prescale_mask) | prescale);
  151. writel(reg, spi_reg(orion_spi, ORION_SPI_IF_CONFIG_REG));
  152. return 0;
  153. }
  154. static void
  155. orion_spi_mode_set(struct spi_device *spi)
  156. {
  157. u32 reg;
  158. struct orion_spi *orion_spi;
  159. orion_spi = spi_master_get_devdata(spi->master);
  160. reg = readl(spi_reg(orion_spi, ORION_SPI_IF_CONFIG_REG));
  161. reg &= ~ORION_SPI_MODE_MASK;
  162. if (spi->mode & SPI_CPOL)
  163. reg |= ORION_SPI_MODE_CPOL;
  164. if (spi->mode & SPI_CPHA)
  165. reg |= ORION_SPI_MODE_CPHA;
  166. writel(reg, spi_reg(orion_spi, ORION_SPI_IF_CONFIG_REG));
  167. }
  168. static void
  169. orion_spi_50mhz_ac_timing_erratum(struct spi_device *spi, unsigned int speed)
  170. {
  171. u32 reg;
  172. struct orion_spi *orion_spi;
  173. orion_spi = spi_master_get_devdata(spi->master);
  174. /*
  175. * Erratum description: (Erratum NO. FE-9144572) The device
  176. * SPI interface supports frequencies of up to 50 MHz.
  177. * However, due to this erratum, when the device core clock is
  178. * 250 MHz and the SPI interfaces is configured for 50MHz SPI
  179. * clock and CPOL=CPHA=1 there might occur data corruption on
  180. * reads from the SPI device.
  181. * Erratum Workaround:
  182. * Work in one of the following configurations:
  183. * 1. Set CPOL=CPHA=0 in "SPI Interface Configuration
  184. * Register".
  185. * 2. Set TMISO_SAMPLE value to 0x2 in "SPI Timing Parameters 1
  186. * Register" before setting the interface.
  187. */
  188. reg = readl(spi_reg(orion_spi, ORION_SPI_TIMING_PARAMS_REG));
  189. reg &= ~ORION_SPI_TMISO_SAMPLE_MASK;
  190. if (clk_get_rate(orion_spi->clk) == 250000000 &&
  191. speed == 50000000 && spi->mode & SPI_CPOL &&
  192. spi->mode & SPI_CPHA)
  193. reg |= ORION_SPI_TMISO_SAMPLE_2;
  194. else
  195. reg |= ORION_SPI_TMISO_SAMPLE_1; /* This is the default value */
  196. writel(reg, spi_reg(orion_spi, ORION_SPI_TIMING_PARAMS_REG));
  197. }
  198. /*
  199. * called only when no transfer is active on the bus
  200. */
  201. static int
  202. orion_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
  203. {
  204. struct orion_spi *orion_spi;
  205. unsigned int speed = spi->max_speed_hz;
  206. unsigned int bits_per_word = spi->bits_per_word;
  207. int rc;
  208. orion_spi = spi_master_get_devdata(spi->master);
  209. if ((t != NULL) && t->speed_hz)
  210. speed = t->speed_hz;
  211. if ((t != NULL) && t->bits_per_word)
  212. bits_per_word = t->bits_per_word;
  213. orion_spi_mode_set(spi);
  214. if (orion_spi->devdata->is_errata_50mhz_ac)
  215. orion_spi_50mhz_ac_timing_erratum(spi, speed);
  216. rc = orion_spi_baudrate_set(spi, speed);
  217. if (rc)
  218. return rc;
  219. if (bits_per_word == 16)
  220. orion_spi_setbits(orion_spi, ORION_SPI_IF_CONFIG_REG,
  221. ORION_SPI_IF_8_16_BIT_MODE);
  222. else
  223. orion_spi_clrbits(orion_spi, ORION_SPI_IF_CONFIG_REG,
  224. ORION_SPI_IF_8_16_BIT_MODE);
  225. return 0;
  226. }
  227. static void orion_spi_set_cs(struct spi_device *spi, bool enable)
  228. {
  229. struct orion_spi *orion_spi;
  230. orion_spi = spi_master_get_devdata(spi->master);
  231. orion_spi_clrbits(orion_spi, ORION_SPI_IF_CTRL_REG, ORION_SPI_CS_MASK);
  232. orion_spi_setbits(orion_spi, ORION_SPI_IF_CTRL_REG,
  233. ORION_SPI_CS(spi->chip_select));
  234. /* Chip select logic is inverted from spi_set_cs */
  235. if (!enable)
  236. orion_spi_setbits(orion_spi, ORION_SPI_IF_CTRL_REG, 0x1);
  237. else
  238. orion_spi_clrbits(orion_spi, ORION_SPI_IF_CTRL_REG, 0x1);
  239. }
  240. static inline int orion_spi_wait_till_ready(struct orion_spi *orion_spi)
  241. {
  242. int i;
  243. for (i = 0; i < ORION_SPI_WAIT_RDY_MAX_LOOP; i++) {
  244. if (readl(spi_reg(orion_spi, ORION_SPI_INT_CAUSE_REG)))
  245. return 1;
  246. udelay(1);
  247. }
  248. return -1;
  249. }
  250. static inline int
  251. orion_spi_write_read_8bit(struct spi_device *spi,
  252. const u8 **tx_buf, u8 **rx_buf)
  253. {
  254. void __iomem *tx_reg, *rx_reg, *int_reg;
  255. struct orion_spi *orion_spi;
  256. orion_spi = spi_master_get_devdata(spi->master);
  257. tx_reg = spi_reg(orion_spi, ORION_SPI_DATA_OUT_REG);
  258. rx_reg = spi_reg(orion_spi, ORION_SPI_DATA_IN_REG);
  259. int_reg = spi_reg(orion_spi, ORION_SPI_INT_CAUSE_REG);
  260. /* clear the interrupt cause register */
  261. writel(0x0, int_reg);
  262. if (tx_buf && *tx_buf)
  263. writel(*(*tx_buf)++, tx_reg);
  264. else
  265. writel(0, tx_reg);
  266. if (orion_spi_wait_till_ready(orion_spi) < 0) {
  267. dev_err(&spi->dev, "TXS timed out\n");
  268. return -1;
  269. }
  270. if (rx_buf && *rx_buf)
  271. *(*rx_buf)++ = readl(rx_reg);
  272. return 1;
  273. }
  274. static inline int
  275. orion_spi_write_read_16bit(struct spi_device *spi,
  276. const u16 **tx_buf, u16 **rx_buf)
  277. {
  278. void __iomem *tx_reg, *rx_reg, *int_reg;
  279. struct orion_spi *orion_spi;
  280. orion_spi = spi_master_get_devdata(spi->master);
  281. tx_reg = spi_reg(orion_spi, ORION_SPI_DATA_OUT_REG);
  282. rx_reg = spi_reg(orion_spi, ORION_SPI_DATA_IN_REG);
  283. int_reg = spi_reg(orion_spi, ORION_SPI_INT_CAUSE_REG);
  284. /* clear the interrupt cause register */
  285. writel(0x0, int_reg);
  286. if (tx_buf && *tx_buf)
  287. writel(__cpu_to_le16(get_unaligned((*tx_buf)++)), tx_reg);
  288. else
  289. writel(0, tx_reg);
  290. if (orion_spi_wait_till_ready(orion_spi) < 0) {
  291. dev_err(&spi->dev, "TXS timed out\n");
  292. return -1;
  293. }
  294. if (rx_buf && *rx_buf)
  295. put_unaligned(__le16_to_cpu(readl(rx_reg)), (*rx_buf)++);
  296. return 1;
  297. }
  298. static unsigned int
  299. orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer)
  300. {
  301. unsigned int count;
  302. int word_len;
  303. word_len = spi->bits_per_word;
  304. count = xfer->len;
  305. if (word_len == 8) {
  306. const u8 *tx = xfer->tx_buf;
  307. u8 *rx = xfer->rx_buf;
  308. do {
  309. if (orion_spi_write_read_8bit(spi, &tx, &rx) < 0)
  310. goto out;
  311. count--;
  312. } while (count);
  313. } else if (word_len == 16) {
  314. const u16 *tx = xfer->tx_buf;
  315. u16 *rx = xfer->rx_buf;
  316. do {
  317. if (orion_spi_write_read_16bit(spi, &tx, &rx) < 0)
  318. goto out;
  319. count -= 2;
  320. } while (count);
  321. }
  322. out:
  323. return xfer->len - count;
  324. }
  325. static int orion_spi_transfer_one(struct spi_master *master,
  326. struct spi_device *spi,
  327. struct spi_transfer *t)
  328. {
  329. int status = 0;
  330. status = orion_spi_setup_transfer(spi, t);
  331. if (status < 0)
  332. return status;
  333. if (t->len)
  334. orion_spi_write_read(spi, t);
  335. return status;
  336. }
  337. static int orion_spi_setup(struct spi_device *spi)
  338. {
  339. return orion_spi_setup_transfer(spi, NULL);
  340. }
  341. static int orion_spi_reset(struct orion_spi *orion_spi)
  342. {
  343. /* Verify that the CS is deasserted */
  344. orion_spi_clrbits(orion_spi, ORION_SPI_IF_CTRL_REG, 0x1);
  345. return 0;
  346. }
  347. static const struct orion_spi_dev orion_spi_dev_data = {
  348. .typ = ORION_SPI,
  349. .min_divisor = 4,
  350. .max_divisor = 30,
  351. .prescale_mask = ORION_SPI_CLK_PRESCALE_MASK,
  352. };
  353. static const struct orion_spi_dev armada_370_spi_dev_data = {
  354. .typ = ARMADA_SPI,
  355. .min_divisor = 4,
  356. .max_divisor = 1920,
  357. .max_hz = 50000000,
  358. .prescale_mask = ARMADA_SPI_CLK_PRESCALE_MASK,
  359. };
  360. static const struct orion_spi_dev armada_xp_spi_dev_data = {
  361. .typ = ARMADA_SPI,
  362. .max_hz = 50000000,
  363. .max_divisor = 1920,
  364. .prescale_mask = ARMADA_SPI_CLK_PRESCALE_MASK,
  365. };
  366. static const struct orion_spi_dev armada_375_spi_dev_data = {
  367. .typ = ARMADA_SPI,
  368. .min_divisor = 15,
  369. .max_divisor = 1920,
  370. .prescale_mask = ARMADA_SPI_CLK_PRESCALE_MASK,
  371. };
  372. static const struct orion_spi_dev armada_380_spi_dev_data = {
  373. .typ = ARMADA_SPI,
  374. .max_hz = 50000000,
  375. .max_divisor = 1920,
  376. .prescale_mask = ARMADA_SPI_CLK_PRESCALE_MASK,
  377. .is_errata_50mhz_ac = true,
  378. };
  379. static const struct of_device_id orion_spi_of_match_table[] = {
  380. {
  381. .compatible = "marvell,orion-spi",
  382. .data = &orion_spi_dev_data,
  383. },
  384. {
  385. .compatible = "marvell,armada-370-spi",
  386. .data = &armada_370_spi_dev_data,
  387. },
  388. {
  389. .compatible = "marvell,armada-375-spi",
  390. .data = &armada_375_spi_dev_data,
  391. },
  392. {
  393. .compatible = "marvell,armada-380-spi",
  394. .data = &armada_380_spi_dev_data,
  395. },
  396. {
  397. .compatible = "marvell,armada-390-spi",
  398. .data = &armada_xp_spi_dev_data,
  399. },
  400. {
  401. .compatible = "marvell,armada-xp-spi",
  402. .data = &armada_xp_spi_dev_data,
  403. },
  404. {}
  405. };
  406. MODULE_DEVICE_TABLE(of, orion_spi_of_match_table);
  407. static int orion_spi_probe(struct platform_device *pdev)
  408. {
  409. const struct of_device_id *of_id;
  410. const struct orion_spi_dev *devdata;
  411. struct spi_master *master;
  412. struct orion_spi *spi;
  413. struct resource *r;
  414. unsigned long tclk_hz;
  415. int status = 0;
  416. master = spi_alloc_master(&pdev->dev, sizeof(*spi));
  417. if (master == NULL) {
  418. dev_dbg(&pdev->dev, "master allocation failed\n");
  419. return -ENOMEM;
  420. }
  421. if (pdev->id != -1)
  422. master->bus_num = pdev->id;
  423. if (pdev->dev.of_node) {
  424. u32 cell_index;
  425. if (!of_property_read_u32(pdev->dev.of_node, "cell-index",
  426. &cell_index))
  427. master->bus_num = cell_index;
  428. }
  429. /* we support only mode 0, and no options */
  430. master->mode_bits = SPI_CPHA | SPI_CPOL;
  431. master->set_cs = orion_spi_set_cs;
  432. master->transfer_one = orion_spi_transfer_one;
  433. master->num_chipselect = ORION_NUM_CHIPSELECTS;
  434. master->setup = orion_spi_setup;
  435. master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
  436. master->auto_runtime_pm = true;
  437. platform_set_drvdata(pdev, master);
  438. spi = spi_master_get_devdata(master);
  439. spi->master = master;
  440. of_id = of_match_device(orion_spi_of_match_table, &pdev->dev);
  441. devdata = (of_id) ? of_id->data : &orion_spi_dev_data;
  442. spi->devdata = devdata;
  443. spi->clk = devm_clk_get(&pdev->dev, NULL);
  444. if (IS_ERR(spi->clk)) {
  445. status = PTR_ERR(spi->clk);
  446. goto out;
  447. }
  448. status = clk_prepare_enable(spi->clk);
  449. if (status)
  450. goto out;
  451. tclk_hz = clk_get_rate(spi->clk);
  452. /*
  453. * With old device tree, armada-370-spi could be used with
  454. * Armada XP, however for this SoC the maximum frequency is
  455. * 50MHz instead of tclk/4. On Armada 370, tclk cannot be
  456. * higher than 200MHz. So, in order to be able to handle both
  457. * SoCs, we can take the minimum of 50MHz and tclk/4.
  458. */
  459. if (of_device_is_compatible(pdev->dev.of_node,
  460. "marvell,armada-370-spi"))
  461. master->max_speed_hz = min(devdata->max_hz,
  462. DIV_ROUND_UP(tclk_hz, devdata->min_divisor));
  463. else if (devdata->min_divisor)
  464. master->max_speed_hz =
  465. DIV_ROUND_UP(tclk_hz, devdata->min_divisor);
  466. else
  467. master->max_speed_hz = devdata->max_hz;
  468. master->min_speed_hz = DIV_ROUND_UP(tclk_hz, devdata->max_divisor);
  469. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  470. spi->base = devm_ioremap_resource(&pdev->dev, r);
  471. if (IS_ERR(spi->base)) {
  472. status = PTR_ERR(spi->base);
  473. goto out_rel_clk;
  474. }
  475. pm_runtime_set_active(&pdev->dev);
  476. pm_runtime_use_autosuspend(&pdev->dev);
  477. pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
  478. pm_runtime_enable(&pdev->dev);
  479. status = orion_spi_reset(spi);
  480. if (status < 0)
  481. goto out_rel_pm;
  482. pm_runtime_mark_last_busy(&pdev->dev);
  483. pm_runtime_put_autosuspend(&pdev->dev);
  484. master->dev.of_node = pdev->dev.of_node;
  485. status = spi_register_master(master);
  486. if (status < 0)
  487. goto out_rel_pm;
  488. return status;
  489. out_rel_pm:
  490. pm_runtime_disable(&pdev->dev);
  491. out_rel_clk:
  492. clk_disable_unprepare(spi->clk);
  493. out:
  494. spi_master_put(master);
  495. return status;
  496. }
  497. static int orion_spi_remove(struct platform_device *pdev)
  498. {
  499. struct spi_master *master = platform_get_drvdata(pdev);
  500. struct orion_spi *spi = spi_master_get_devdata(master);
  501. pm_runtime_get_sync(&pdev->dev);
  502. clk_disable_unprepare(spi->clk);
  503. spi_unregister_master(master);
  504. pm_runtime_disable(&pdev->dev);
  505. return 0;
  506. }
  507. MODULE_ALIAS("platform:" DRIVER_NAME);
  508. #ifdef CONFIG_PM
  509. static int orion_spi_runtime_suspend(struct device *dev)
  510. {
  511. struct spi_master *master = dev_get_drvdata(dev);
  512. struct orion_spi *spi = spi_master_get_devdata(master);
  513. clk_disable_unprepare(spi->clk);
  514. return 0;
  515. }
  516. static int orion_spi_runtime_resume(struct device *dev)
  517. {
  518. struct spi_master *master = dev_get_drvdata(dev);
  519. struct orion_spi *spi = spi_master_get_devdata(master);
  520. return clk_prepare_enable(spi->clk);
  521. }
  522. #endif
  523. static const struct dev_pm_ops orion_spi_pm_ops = {
  524. SET_RUNTIME_PM_OPS(orion_spi_runtime_suspend,
  525. orion_spi_runtime_resume,
  526. NULL)
  527. };
  528. static struct platform_driver orion_spi_driver = {
  529. .driver = {
  530. .name = DRIVER_NAME,
  531. .pm = &orion_spi_pm_ops,
  532. .of_match_table = of_match_ptr(orion_spi_of_match_table),
  533. },
  534. .probe = orion_spi_probe,
  535. .remove = orion_spi_remove,
  536. };
  537. module_platform_driver(orion_spi_driver);
  538. MODULE_DESCRIPTION("Orion SPI driver");
  539. MODULE_AUTHOR("Shadi Ammouri <shadi@marvell.com>");
  540. MODULE_LICENSE("GPL");