spi-orion.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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. /*
  111. * Given the core_clk (tclk_hz) and the target rate (speed) we
  112. * determine the best values for SPR (in [0 .. 15]) and SPPR (in
  113. * [0..7]) such that
  114. *
  115. * core_clk / (SPR * 2 ** SPPR)
  116. *
  117. * is as big as possible but not bigger than speed.
  118. */
  119. /* best integer divider: */
  120. unsigned divider = DIV_ROUND_UP(tclk_hz, speed);
  121. unsigned spr, sppr;
  122. if (divider < 16) {
  123. /* This is the easy case, divider is less than 16 */
  124. spr = divider;
  125. sppr = 0;
  126. } else {
  127. unsigned two_pow_sppr;
  128. /*
  129. * Find the highest bit set in divider. This and the
  130. * three next bits define SPR (apart from rounding).
  131. * SPPR is then the number of zero bits that must be
  132. * appended:
  133. */
  134. sppr = fls(divider) - 4;
  135. /*
  136. * As SPR only has 4 bits, we have to round divider up
  137. * to the next multiple of 2 ** sppr.
  138. */
  139. two_pow_sppr = 1 << sppr;
  140. divider = (divider + two_pow_sppr - 1) & -two_pow_sppr;
  141. /*
  142. * recalculate sppr as rounding up divider might have
  143. * increased it enough to change the position of the
  144. * highest set bit. In this case the bit that now
  145. * doesn't make it into SPR is 0, so there is no need to
  146. * round again.
  147. */
  148. sppr = fls(divider) - 4;
  149. spr = divider >> sppr;
  150. /*
  151. * Now do range checking. SPR is constructed to have a
  152. * width of 4 bits, so this is fine for sure. So we
  153. * still need to check for sppr to fit into 3 bits:
  154. */
  155. if (sppr > 7)
  156. return -EINVAL;
  157. }
  158. prescale = ((sppr & 0x6) << 5) | ((sppr & 0x1) << 4) | spr;
  159. } else {
  160. /*
  161. * the supported rates are: 4,6,8...30
  162. * round up as we look for equal or less speed
  163. */
  164. rate = DIV_ROUND_UP(tclk_hz, speed);
  165. rate = roundup(rate, 2);
  166. /* check if requested speed is too small */
  167. if (rate > 30)
  168. return -EINVAL;
  169. if (rate < 4)
  170. rate = 4;
  171. /* Convert the rate to SPI clock divisor value. */
  172. prescale = 0x10 + rate/2;
  173. }
  174. reg = readl(spi_reg(orion_spi, ORION_SPI_IF_CONFIG_REG));
  175. reg = ((reg & ~devdata->prescale_mask) | prescale);
  176. writel(reg, spi_reg(orion_spi, ORION_SPI_IF_CONFIG_REG));
  177. return 0;
  178. }
  179. static void
  180. orion_spi_mode_set(struct spi_device *spi)
  181. {
  182. u32 reg;
  183. struct orion_spi *orion_spi;
  184. orion_spi = spi_master_get_devdata(spi->master);
  185. reg = readl(spi_reg(orion_spi, ORION_SPI_IF_CONFIG_REG));
  186. reg &= ~ORION_SPI_MODE_MASK;
  187. if (spi->mode & SPI_CPOL)
  188. reg |= ORION_SPI_MODE_CPOL;
  189. if (spi->mode & SPI_CPHA)
  190. reg |= ORION_SPI_MODE_CPHA;
  191. writel(reg, spi_reg(orion_spi, ORION_SPI_IF_CONFIG_REG));
  192. }
  193. static void
  194. orion_spi_50mhz_ac_timing_erratum(struct spi_device *spi, unsigned int speed)
  195. {
  196. u32 reg;
  197. struct orion_spi *orion_spi;
  198. orion_spi = spi_master_get_devdata(spi->master);
  199. /*
  200. * Erratum description: (Erratum NO. FE-9144572) The device
  201. * SPI interface supports frequencies of up to 50 MHz.
  202. * However, due to this erratum, when the device core clock is
  203. * 250 MHz and the SPI interfaces is configured for 50MHz SPI
  204. * clock and CPOL=CPHA=1 there might occur data corruption on
  205. * reads from the SPI device.
  206. * Erratum Workaround:
  207. * Work in one of the following configurations:
  208. * 1. Set CPOL=CPHA=0 in "SPI Interface Configuration
  209. * Register".
  210. * 2. Set TMISO_SAMPLE value to 0x2 in "SPI Timing Parameters 1
  211. * Register" before setting the interface.
  212. */
  213. reg = readl(spi_reg(orion_spi, ORION_SPI_TIMING_PARAMS_REG));
  214. reg &= ~ORION_SPI_TMISO_SAMPLE_MASK;
  215. if (clk_get_rate(orion_spi->clk) == 250000000 &&
  216. speed == 50000000 && spi->mode & SPI_CPOL &&
  217. spi->mode & SPI_CPHA)
  218. reg |= ORION_SPI_TMISO_SAMPLE_2;
  219. else
  220. reg |= ORION_SPI_TMISO_SAMPLE_1; /* This is the default value */
  221. writel(reg, spi_reg(orion_spi, ORION_SPI_TIMING_PARAMS_REG));
  222. }
  223. /*
  224. * called only when no transfer is active on the bus
  225. */
  226. static int
  227. orion_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
  228. {
  229. struct orion_spi *orion_spi;
  230. unsigned int speed = spi->max_speed_hz;
  231. unsigned int bits_per_word = spi->bits_per_word;
  232. int rc;
  233. orion_spi = spi_master_get_devdata(spi->master);
  234. if ((t != NULL) && t->speed_hz)
  235. speed = t->speed_hz;
  236. if ((t != NULL) && t->bits_per_word)
  237. bits_per_word = t->bits_per_word;
  238. orion_spi_mode_set(spi);
  239. if (orion_spi->devdata->is_errata_50mhz_ac)
  240. orion_spi_50mhz_ac_timing_erratum(spi, speed);
  241. rc = orion_spi_baudrate_set(spi, speed);
  242. if (rc)
  243. return rc;
  244. if (bits_per_word == 16)
  245. orion_spi_setbits(orion_spi, ORION_SPI_IF_CONFIG_REG,
  246. ORION_SPI_IF_8_16_BIT_MODE);
  247. else
  248. orion_spi_clrbits(orion_spi, ORION_SPI_IF_CONFIG_REG,
  249. ORION_SPI_IF_8_16_BIT_MODE);
  250. return 0;
  251. }
  252. static void orion_spi_set_cs(struct spi_device *spi, bool enable)
  253. {
  254. struct orion_spi *orion_spi;
  255. orion_spi = spi_master_get_devdata(spi->master);
  256. orion_spi_clrbits(orion_spi, ORION_SPI_IF_CTRL_REG, ORION_SPI_CS_MASK);
  257. orion_spi_setbits(orion_spi, ORION_SPI_IF_CTRL_REG,
  258. ORION_SPI_CS(spi->chip_select));
  259. /* Chip select logic is inverted from spi_set_cs */
  260. if (!enable)
  261. orion_spi_setbits(orion_spi, ORION_SPI_IF_CTRL_REG, 0x1);
  262. else
  263. orion_spi_clrbits(orion_spi, ORION_SPI_IF_CTRL_REG, 0x1);
  264. }
  265. static inline int orion_spi_wait_till_ready(struct orion_spi *orion_spi)
  266. {
  267. int i;
  268. for (i = 0; i < ORION_SPI_WAIT_RDY_MAX_LOOP; i++) {
  269. if (readl(spi_reg(orion_spi, ORION_SPI_INT_CAUSE_REG)))
  270. return 1;
  271. udelay(1);
  272. }
  273. return -1;
  274. }
  275. static inline int
  276. orion_spi_write_read_8bit(struct spi_device *spi,
  277. const u8 **tx_buf, u8 **rx_buf)
  278. {
  279. void __iomem *tx_reg, *rx_reg, *int_reg;
  280. struct orion_spi *orion_spi;
  281. orion_spi = spi_master_get_devdata(spi->master);
  282. tx_reg = spi_reg(orion_spi, ORION_SPI_DATA_OUT_REG);
  283. rx_reg = spi_reg(orion_spi, ORION_SPI_DATA_IN_REG);
  284. int_reg = spi_reg(orion_spi, ORION_SPI_INT_CAUSE_REG);
  285. /* clear the interrupt cause register */
  286. writel(0x0, int_reg);
  287. if (tx_buf && *tx_buf)
  288. writel(*(*tx_buf)++, tx_reg);
  289. else
  290. writel(0, tx_reg);
  291. if (orion_spi_wait_till_ready(orion_spi) < 0) {
  292. dev_err(&spi->dev, "TXS timed out\n");
  293. return -1;
  294. }
  295. if (rx_buf && *rx_buf)
  296. *(*rx_buf)++ = readl(rx_reg);
  297. return 1;
  298. }
  299. static inline int
  300. orion_spi_write_read_16bit(struct spi_device *spi,
  301. const u16 **tx_buf, u16 **rx_buf)
  302. {
  303. void __iomem *tx_reg, *rx_reg, *int_reg;
  304. struct orion_spi *orion_spi;
  305. orion_spi = spi_master_get_devdata(spi->master);
  306. tx_reg = spi_reg(orion_spi, ORION_SPI_DATA_OUT_REG);
  307. rx_reg = spi_reg(orion_spi, ORION_SPI_DATA_IN_REG);
  308. int_reg = spi_reg(orion_spi, ORION_SPI_INT_CAUSE_REG);
  309. /* clear the interrupt cause register */
  310. writel(0x0, int_reg);
  311. if (tx_buf && *tx_buf)
  312. writel(__cpu_to_le16(get_unaligned((*tx_buf)++)), tx_reg);
  313. else
  314. writel(0, tx_reg);
  315. if (orion_spi_wait_till_ready(orion_spi) < 0) {
  316. dev_err(&spi->dev, "TXS timed out\n");
  317. return -1;
  318. }
  319. if (rx_buf && *rx_buf)
  320. put_unaligned(__le16_to_cpu(readl(rx_reg)), (*rx_buf)++);
  321. return 1;
  322. }
  323. static unsigned int
  324. orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer)
  325. {
  326. unsigned int count;
  327. int word_len;
  328. word_len = spi->bits_per_word;
  329. count = xfer->len;
  330. if (word_len == 8) {
  331. const u8 *tx = xfer->tx_buf;
  332. u8 *rx = xfer->rx_buf;
  333. do {
  334. if (orion_spi_write_read_8bit(spi, &tx, &rx) < 0)
  335. goto out;
  336. count--;
  337. } while (count);
  338. } else if (word_len == 16) {
  339. const u16 *tx = xfer->tx_buf;
  340. u16 *rx = xfer->rx_buf;
  341. do {
  342. if (orion_spi_write_read_16bit(spi, &tx, &rx) < 0)
  343. goto out;
  344. count -= 2;
  345. } while (count);
  346. }
  347. out:
  348. return xfer->len - count;
  349. }
  350. static int orion_spi_transfer_one(struct spi_master *master,
  351. struct spi_device *spi,
  352. struct spi_transfer *t)
  353. {
  354. int status = 0;
  355. status = orion_spi_setup_transfer(spi, t);
  356. if (status < 0)
  357. return status;
  358. if (t->len)
  359. orion_spi_write_read(spi, t);
  360. return status;
  361. }
  362. static int orion_spi_setup(struct spi_device *spi)
  363. {
  364. return orion_spi_setup_transfer(spi, NULL);
  365. }
  366. static int orion_spi_reset(struct orion_spi *orion_spi)
  367. {
  368. /* Verify that the CS is deasserted */
  369. orion_spi_clrbits(orion_spi, ORION_SPI_IF_CTRL_REG, 0x1);
  370. return 0;
  371. }
  372. static const struct orion_spi_dev orion_spi_dev_data = {
  373. .typ = ORION_SPI,
  374. .min_divisor = 4,
  375. .max_divisor = 30,
  376. .prescale_mask = ORION_SPI_CLK_PRESCALE_MASK,
  377. };
  378. static const struct orion_spi_dev armada_370_spi_dev_data = {
  379. .typ = ARMADA_SPI,
  380. .min_divisor = 4,
  381. .max_divisor = 1920,
  382. .max_hz = 50000000,
  383. .prescale_mask = ARMADA_SPI_CLK_PRESCALE_MASK,
  384. };
  385. static const struct orion_spi_dev armada_xp_spi_dev_data = {
  386. .typ = ARMADA_SPI,
  387. .max_hz = 50000000,
  388. .max_divisor = 1920,
  389. .prescale_mask = ARMADA_SPI_CLK_PRESCALE_MASK,
  390. };
  391. static const struct orion_spi_dev armada_375_spi_dev_data = {
  392. .typ = ARMADA_SPI,
  393. .min_divisor = 15,
  394. .max_divisor = 1920,
  395. .prescale_mask = ARMADA_SPI_CLK_PRESCALE_MASK,
  396. };
  397. static const struct orion_spi_dev armada_380_spi_dev_data = {
  398. .typ = ARMADA_SPI,
  399. .max_hz = 50000000,
  400. .max_divisor = 1920,
  401. .prescale_mask = ARMADA_SPI_CLK_PRESCALE_MASK,
  402. .is_errata_50mhz_ac = true,
  403. };
  404. static const struct of_device_id orion_spi_of_match_table[] = {
  405. {
  406. .compatible = "marvell,orion-spi",
  407. .data = &orion_spi_dev_data,
  408. },
  409. {
  410. .compatible = "marvell,armada-370-spi",
  411. .data = &armada_370_spi_dev_data,
  412. },
  413. {
  414. .compatible = "marvell,armada-375-spi",
  415. .data = &armada_375_spi_dev_data,
  416. },
  417. {
  418. .compatible = "marvell,armada-380-spi",
  419. .data = &armada_380_spi_dev_data,
  420. },
  421. {
  422. .compatible = "marvell,armada-390-spi",
  423. .data = &armada_xp_spi_dev_data,
  424. },
  425. {
  426. .compatible = "marvell,armada-xp-spi",
  427. .data = &armada_xp_spi_dev_data,
  428. },
  429. {}
  430. };
  431. MODULE_DEVICE_TABLE(of, orion_spi_of_match_table);
  432. static int orion_spi_probe(struct platform_device *pdev)
  433. {
  434. const struct of_device_id *of_id;
  435. const struct orion_spi_dev *devdata;
  436. struct spi_master *master;
  437. struct orion_spi *spi;
  438. struct resource *r;
  439. unsigned long tclk_hz;
  440. int status = 0;
  441. master = spi_alloc_master(&pdev->dev, sizeof(*spi));
  442. if (master == NULL) {
  443. dev_dbg(&pdev->dev, "master allocation failed\n");
  444. return -ENOMEM;
  445. }
  446. if (pdev->id != -1)
  447. master->bus_num = pdev->id;
  448. if (pdev->dev.of_node) {
  449. u32 cell_index;
  450. if (!of_property_read_u32(pdev->dev.of_node, "cell-index",
  451. &cell_index))
  452. master->bus_num = cell_index;
  453. }
  454. /* we support only mode 0, and no options */
  455. master->mode_bits = SPI_CPHA | SPI_CPOL;
  456. master->set_cs = orion_spi_set_cs;
  457. master->transfer_one = orion_spi_transfer_one;
  458. master->num_chipselect = ORION_NUM_CHIPSELECTS;
  459. master->setup = orion_spi_setup;
  460. master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
  461. master->auto_runtime_pm = true;
  462. platform_set_drvdata(pdev, master);
  463. spi = spi_master_get_devdata(master);
  464. spi->master = master;
  465. of_id = of_match_device(orion_spi_of_match_table, &pdev->dev);
  466. devdata = (of_id) ? of_id->data : &orion_spi_dev_data;
  467. spi->devdata = devdata;
  468. spi->clk = devm_clk_get(&pdev->dev, NULL);
  469. if (IS_ERR(spi->clk)) {
  470. status = PTR_ERR(spi->clk);
  471. goto out;
  472. }
  473. status = clk_prepare_enable(spi->clk);
  474. if (status)
  475. goto out;
  476. tclk_hz = clk_get_rate(spi->clk);
  477. /*
  478. * With old device tree, armada-370-spi could be used with
  479. * Armada XP, however for this SoC the maximum frequency is
  480. * 50MHz instead of tclk/4. On Armada 370, tclk cannot be
  481. * higher than 200MHz. So, in order to be able to handle both
  482. * SoCs, we can take the minimum of 50MHz and tclk/4.
  483. */
  484. if (of_device_is_compatible(pdev->dev.of_node,
  485. "marvell,armada-370-spi"))
  486. master->max_speed_hz = min(devdata->max_hz,
  487. DIV_ROUND_UP(tclk_hz, devdata->min_divisor));
  488. else if (devdata->min_divisor)
  489. master->max_speed_hz =
  490. DIV_ROUND_UP(tclk_hz, devdata->min_divisor);
  491. else
  492. master->max_speed_hz = devdata->max_hz;
  493. master->min_speed_hz = DIV_ROUND_UP(tclk_hz, devdata->max_divisor);
  494. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  495. spi->base = devm_ioremap_resource(&pdev->dev, r);
  496. if (IS_ERR(spi->base)) {
  497. status = PTR_ERR(spi->base);
  498. goto out_rel_clk;
  499. }
  500. pm_runtime_set_active(&pdev->dev);
  501. pm_runtime_use_autosuspend(&pdev->dev);
  502. pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
  503. pm_runtime_enable(&pdev->dev);
  504. status = orion_spi_reset(spi);
  505. if (status < 0)
  506. goto out_rel_pm;
  507. pm_runtime_mark_last_busy(&pdev->dev);
  508. pm_runtime_put_autosuspend(&pdev->dev);
  509. master->dev.of_node = pdev->dev.of_node;
  510. status = spi_register_master(master);
  511. if (status < 0)
  512. goto out_rel_pm;
  513. return status;
  514. out_rel_pm:
  515. pm_runtime_disable(&pdev->dev);
  516. out_rel_clk:
  517. clk_disable_unprepare(spi->clk);
  518. out:
  519. spi_master_put(master);
  520. return status;
  521. }
  522. static int orion_spi_remove(struct platform_device *pdev)
  523. {
  524. struct spi_master *master = platform_get_drvdata(pdev);
  525. struct orion_spi *spi = spi_master_get_devdata(master);
  526. pm_runtime_get_sync(&pdev->dev);
  527. clk_disable_unprepare(spi->clk);
  528. spi_unregister_master(master);
  529. pm_runtime_disable(&pdev->dev);
  530. return 0;
  531. }
  532. MODULE_ALIAS("platform:" DRIVER_NAME);
  533. #ifdef CONFIG_PM
  534. static int orion_spi_runtime_suspend(struct device *dev)
  535. {
  536. struct spi_master *master = dev_get_drvdata(dev);
  537. struct orion_spi *spi = spi_master_get_devdata(master);
  538. clk_disable_unprepare(spi->clk);
  539. return 0;
  540. }
  541. static int orion_spi_runtime_resume(struct device *dev)
  542. {
  543. struct spi_master *master = dev_get_drvdata(dev);
  544. struct orion_spi *spi = spi_master_get_devdata(master);
  545. return clk_prepare_enable(spi->clk);
  546. }
  547. #endif
  548. static const struct dev_pm_ops orion_spi_pm_ops = {
  549. SET_RUNTIME_PM_OPS(orion_spi_runtime_suspend,
  550. orion_spi_runtime_resume,
  551. NULL)
  552. };
  553. static struct platform_driver orion_spi_driver = {
  554. .driver = {
  555. .name = DRIVER_NAME,
  556. .pm = &orion_spi_pm_ops,
  557. .of_match_table = of_match_ptr(orion_spi_of_match_table),
  558. },
  559. .probe = orion_spi_probe,
  560. .remove = orion_spi_remove,
  561. };
  562. module_platform_driver(orion_spi_driver);
  563. MODULE_DESCRIPTION("Orion SPI driver");
  564. MODULE_AUTHOR("Shadi Ammouri <shadi@marvell.com>");
  565. MODULE_LICENSE("GPL");