tegra30_ahub.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*
  2. * tegra30_ahub.c - Tegra30 AHUB driver
  3. *
  4. * Copyright (c) 2011,2012, NVIDIA CORPORATION. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/clk.h>
  19. #include <linux/device.h>
  20. #include <linux/io.h>
  21. #include <linux/module.h>
  22. #include <linux/of_platform.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/pm_runtime.h>
  25. #include <linux/regmap.h>
  26. #include <linux/slab.h>
  27. #include <mach/clk.h>
  28. #include <mach/dma.h>
  29. #include <sound/soc.h>
  30. #include "tegra30_ahub.h"
  31. #define DRV_NAME "tegra30-ahub"
  32. static struct tegra30_ahub *ahub;
  33. static inline void tegra30_apbif_write(u32 reg, u32 val)
  34. {
  35. regmap_write(ahub->regmap_apbif, reg, val);
  36. }
  37. static inline u32 tegra30_apbif_read(u32 reg)
  38. {
  39. u32 val;
  40. regmap_read(ahub->regmap_apbif, reg, &val);
  41. return val;
  42. }
  43. static inline void tegra30_audio_write(u32 reg, u32 val)
  44. {
  45. regmap_write(ahub->regmap_ahub, reg, val);
  46. }
  47. static int tegra30_ahub_runtime_suspend(struct device *dev)
  48. {
  49. regcache_cache_only(ahub->regmap_apbif, true);
  50. regcache_cache_only(ahub->regmap_ahub, true);
  51. clk_disable(ahub->clk_apbif);
  52. clk_disable(ahub->clk_d_audio);
  53. return 0;
  54. }
  55. /*
  56. * clk_apbif isn't required for an I2S<->I2S configuration where no PCM data
  57. * is read from or sent to memory. However, that's not something the rest of
  58. * the driver supports right now, so we'll just treat the two clocks as one
  59. * for now.
  60. *
  61. * These functions should not be a plain ref-count. Instead, each active stream
  62. * contributes some requirement to the minimum clock rate, so starting or
  63. * stopping streams should dynamically adjust the clock as required. However,
  64. * this is not yet implemented.
  65. */
  66. static int tegra30_ahub_runtime_resume(struct device *dev)
  67. {
  68. int ret;
  69. ret = clk_enable(ahub->clk_d_audio);
  70. if (ret) {
  71. dev_err(dev, "clk_enable d_audio failed: %d\n", ret);
  72. return ret;
  73. }
  74. ret = clk_enable(ahub->clk_apbif);
  75. if (ret) {
  76. dev_err(dev, "clk_enable apbif failed: %d\n", ret);
  77. clk_disable(ahub->clk_d_audio);
  78. return ret;
  79. }
  80. regcache_cache_only(ahub->regmap_apbif, false);
  81. regcache_cache_only(ahub->regmap_ahub, false);
  82. return 0;
  83. }
  84. int tegra30_ahub_allocate_rx_fifo(enum tegra30_ahub_rxcif *rxcif,
  85. unsigned long *fiforeg,
  86. unsigned long *reqsel)
  87. {
  88. int channel;
  89. u32 reg, val;
  90. channel = find_first_zero_bit(ahub->rx_usage,
  91. TEGRA30_AHUB_CHANNEL_CTRL_COUNT);
  92. if (channel >= TEGRA30_AHUB_CHANNEL_CTRL_COUNT)
  93. return -EBUSY;
  94. __set_bit(channel, ahub->rx_usage);
  95. *rxcif = TEGRA30_AHUB_RXCIF_APBIF_RX0 + channel;
  96. *fiforeg = ahub->apbif_addr + TEGRA30_AHUB_CHANNEL_RXFIFO +
  97. (channel * TEGRA30_AHUB_CHANNEL_RXFIFO_STRIDE);
  98. *reqsel = ahub->dma_sel + channel;
  99. reg = TEGRA30_AHUB_CHANNEL_CTRL +
  100. (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
  101. val = tegra30_apbif_read(reg);
  102. val &= ~(TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_MASK |
  103. TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_MASK);
  104. val |= (7 << TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_SHIFT) |
  105. TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_EN |
  106. TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_16;
  107. tegra30_apbif_write(reg, val);
  108. reg = TEGRA30_AHUB_CIF_RX_CTRL +
  109. (channel * TEGRA30_AHUB_CIF_RX_CTRL_STRIDE);
  110. val = (0 << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) |
  111. (1 << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
  112. (1 << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) |
  113. TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 |
  114. TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16 |
  115. TEGRA30_AUDIOCIF_CTRL_DIRECTION_RX;
  116. tegra30_apbif_write(reg, val);
  117. return 0;
  118. }
  119. EXPORT_SYMBOL_GPL(tegra30_ahub_allocate_rx_fifo);
  120. int tegra30_ahub_enable_rx_fifo(enum tegra30_ahub_rxcif rxcif)
  121. {
  122. int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
  123. int reg, val;
  124. reg = TEGRA30_AHUB_CHANNEL_CTRL +
  125. (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
  126. val = tegra30_apbif_read(reg);
  127. val |= TEGRA30_AHUB_CHANNEL_CTRL_RX_EN;
  128. tegra30_apbif_write(reg, val);
  129. return 0;
  130. }
  131. EXPORT_SYMBOL_GPL(tegra30_ahub_enable_rx_fifo);
  132. int tegra30_ahub_disable_rx_fifo(enum tegra30_ahub_rxcif rxcif)
  133. {
  134. int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
  135. int reg, val;
  136. reg = TEGRA30_AHUB_CHANNEL_CTRL +
  137. (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
  138. val = tegra30_apbif_read(reg);
  139. val &= ~TEGRA30_AHUB_CHANNEL_CTRL_RX_EN;
  140. tegra30_apbif_write(reg, val);
  141. return 0;
  142. }
  143. EXPORT_SYMBOL_GPL(tegra30_ahub_disable_rx_fifo);
  144. int tegra30_ahub_free_rx_fifo(enum tegra30_ahub_rxcif rxcif)
  145. {
  146. int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
  147. __clear_bit(channel, ahub->rx_usage);
  148. return 0;
  149. }
  150. EXPORT_SYMBOL_GPL(tegra30_ahub_free_rx_fifo);
  151. int tegra30_ahub_allocate_tx_fifo(enum tegra30_ahub_txcif *txcif,
  152. unsigned long *fiforeg,
  153. unsigned long *reqsel)
  154. {
  155. int channel;
  156. u32 reg, val;
  157. channel = find_first_zero_bit(ahub->tx_usage,
  158. TEGRA30_AHUB_CHANNEL_CTRL_COUNT);
  159. if (channel >= TEGRA30_AHUB_CHANNEL_CTRL_COUNT)
  160. return -EBUSY;
  161. __set_bit(channel, ahub->tx_usage);
  162. *txcif = TEGRA30_AHUB_TXCIF_APBIF_TX0 + channel;
  163. *fiforeg = ahub->apbif_addr + TEGRA30_AHUB_CHANNEL_TXFIFO +
  164. (channel * TEGRA30_AHUB_CHANNEL_TXFIFO_STRIDE);
  165. *reqsel = ahub->dma_sel + channel;
  166. reg = TEGRA30_AHUB_CHANNEL_CTRL +
  167. (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
  168. val = tegra30_apbif_read(reg);
  169. val &= ~(TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_MASK |
  170. TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_MASK);
  171. val |= (7 << TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_SHIFT) |
  172. TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_EN |
  173. TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_16;
  174. tegra30_apbif_write(reg, val);
  175. reg = TEGRA30_AHUB_CIF_TX_CTRL +
  176. (channel * TEGRA30_AHUB_CIF_TX_CTRL_STRIDE);
  177. val = (0 << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) |
  178. (1 << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
  179. (1 << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) |
  180. TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 |
  181. TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16 |
  182. TEGRA30_AUDIOCIF_CTRL_DIRECTION_TX;
  183. tegra30_apbif_write(reg, val);
  184. return 0;
  185. }
  186. EXPORT_SYMBOL_GPL(tegra30_ahub_allocate_tx_fifo);
  187. int tegra30_ahub_enable_tx_fifo(enum tegra30_ahub_txcif txcif)
  188. {
  189. int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
  190. int reg, val;
  191. reg = TEGRA30_AHUB_CHANNEL_CTRL +
  192. (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
  193. val = tegra30_apbif_read(reg);
  194. val |= TEGRA30_AHUB_CHANNEL_CTRL_TX_EN;
  195. tegra30_apbif_write(reg, val);
  196. return 0;
  197. }
  198. EXPORT_SYMBOL_GPL(tegra30_ahub_enable_tx_fifo);
  199. int tegra30_ahub_disable_tx_fifo(enum tegra30_ahub_txcif txcif)
  200. {
  201. int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
  202. int reg, val;
  203. reg = TEGRA30_AHUB_CHANNEL_CTRL +
  204. (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
  205. val = tegra30_apbif_read(reg);
  206. val &= ~TEGRA30_AHUB_CHANNEL_CTRL_TX_EN;
  207. tegra30_apbif_write(reg, val);
  208. return 0;
  209. }
  210. EXPORT_SYMBOL_GPL(tegra30_ahub_disable_tx_fifo);
  211. int tegra30_ahub_free_tx_fifo(enum tegra30_ahub_txcif txcif)
  212. {
  213. int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
  214. __clear_bit(channel, ahub->tx_usage);
  215. return 0;
  216. }
  217. EXPORT_SYMBOL_GPL(tegra30_ahub_free_tx_fifo);
  218. int tegra30_ahub_set_rx_cif_source(enum tegra30_ahub_rxcif rxcif,
  219. enum tegra30_ahub_txcif txcif)
  220. {
  221. int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
  222. int reg;
  223. reg = TEGRA30_AHUB_AUDIO_RX +
  224. (channel * TEGRA30_AHUB_AUDIO_RX_STRIDE);
  225. tegra30_audio_write(reg, 1 << txcif);
  226. return 0;
  227. }
  228. EXPORT_SYMBOL_GPL(tegra30_ahub_set_rx_cif_source);
  229. int tegra30_ahub_unset_rx_cif_source(enum tegra30_ahub_rxcif rxcif)
  230. {
  231. int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
  232. int reg;
  233. reg = TEGRA30_AHUB_AUDIO_RX +
  234. (channel * TEGRA30_AHUB_AUDIO_RX_STRIDE);
  235. tegra30_audio_write(reg, 0);
  236. return 0;
  237. }
  238. EXPORT_SYMBOL_GPL(tegra30_ahub_unset_rx_cif_source);
  239. static const char * const configlink_clocks[] __devinitconst = {
  240. "i2s0",
  241. "i2s1",
  242. "i2s2",
  243. "i2s3",
  244. "i2s4",
  245. "dam0",
  246. "dam1",
  247. "dam2",
  248. "spdif_in",
  249. };
  250. struct of_dev_auxdata ahub_auxdata[] __devinitdata = {
  251. OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080300, "tegra30-i2s.0", NULL),
  252. OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080400, "tegra30-i2s.1", NULL),
  253. OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080500, "tegra30-i2s.2", NULL),
  254. OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080600, "tegra30-i2s.3", NULL),
  255. OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080700, "tegra30-i2s.4", NULL),
  256. {}
  257. };
  258. #define LAST_REG(name) \
  259. (TEGRA30_AHUB_##name + \
  260. (TEGRA30_AHUB_##name##_STRIDE * TEGRA30_AHUB_##name##_COUNT) - 4)
  261. #define REG_IN_ARRAY(reg, name) \
  262. ((reg >= TEGRA30_AHUB_##name) && \
  263. (reg <= LAST_REG(name) && \
  264. (!((reg - TEGRA30_AHUB_##name) % TEGRA30_AHUB_##name##_STRIDE))))
  265. static bool tegra30_ahub_apbif_wr_rd_reg(struct device *dev, unsigned int reg)
  266. {
  267. switch (reg) {
  268. case TEGRA30_AHUB_CONFIG_LINK_CTRL:
  269. case TEGRA30_AHUB_MISC_CTRL:
  270. case TEGRA30_AHUB_APBDMA_LIVE_STATUS:
  271. case TEGRA30_AHUB_I2S_LIVE_STATUS:
  272. case TEGRA30_AHUB_SPDIF_LIVE_STATUS:
  273. case TEGRA30_AHUB_I2S_INT_MASK:
  274. case TEGRA30_AHUB_DAM_INT_MASK:
  275. case TEGRA30_AHUB_SPDIF_INT_MASK:
  276. case TEGRA30_AHUB_APBIF_INT_MASK:
  277. case TEGRA30_AHUB_I2S_INT_STATUS:
  278. case TEGRA30_AHUB_DAM_INT_STATUS:
  279. case TEGRA30_AHUB_SPDIF_INT_STATUS:
  280. case TEGRA30_AHUB_APBIF_INT_STATUS:
  281. case TEGRA30_AHUB_I2S_INT_SOURCE:
  282. case TEGRA30_AHUB_DAM_INT_SOURCE:
  283. case TEGRA30_AHUB_SPDIF_INT_SOURCE:
  284. case TEGRA30_AHUB_APBIF_INT_SOURCE:
  285. case TEGRA30_AHUB_I2S_INT_SET:
  286. case TEGRA30_AHUB_DAM_INT_SET:
  287. case TEGRA30_AHUB_SPDIF_INT_SET:
  288. case TEGRA30_AHUB_APBIF_INT_SET:
  289. return true;
  290. default:
  291. break;
  292. };
  293. if (REG_IN_ARRAY(reg, CHANNEL_CTRL) ||
  294. REG_IN_ARRAY(reg, CHANNEL_CLEAR) ||
  295. REG_IN_ARRAY(reg, CHANNEL_STATUS) ||
  296. REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
  297. REG_IN_ARRAY(reg, CHANNEL_RXFIFO) ||
  298. REG_IN_ARRAY(reg, CIF_TX_CTRL) ||
  299. REG_IN_ARRAY(reg, CIF_RX_CTRL) ||
  300. REG_IN_ARRAY(reg, DAM_LIVE_STATUS))
  301. return true;
  302. return false;
  303. }
  304. static bool tegra30_ahub_apbif_volatile_reg(struct device *dev,
  305. unsigned int reg)
  306. {
  307. switch (reg) {
  308. case TEGRA30_AHUB_CONFIG_LINK_CTRL:
  309. case TEGRA30_AHUB_MISC_CTRL:
  310. case TEGRA30_AHUB_APBDMA_LIVE_STATUS:
  311. case TEGRA30_AHUB_I2S_LIVE_STATUS:
  312. case TEGRA30_AHUB_SPDIF_LIVE_STATUS:
  313. case TEGRA30_AHUB_I2S_INT_STATUS:
  314. case TEGRA30_AHUB_DAM_INT_STATUS:
  315. case TEGRA30_AHUB_SPDIF_INT_STATUS:
  316. case TEGRA30_AHUB_APBIF_INT_STATUS:
  317. case TEGRA30_AHUB_I2S_INT_SET:
  318. case TEGRA30_AHUB_DAM_INT_SET:
  319. case TEGRA30_AHUB_SPDIF_INT_SET:
  320. case TEGRA30_AHUB_APBIF_INT_SET:
  321. return true;
  322. default:
  323. break;
  324. };
  325. if (REG_IN_ARRAY(reg, CHANNEL_CLEAR) ||
  326. REG_IN_ARRAY(reg, CHANNEL_STATUS) ||
  327. REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
  328. REG_IN_ARRAY(reg, CHANNEL_RXFIFO) ||
  329. REG_IN_ARRAY(reg, DAM_LIVE_STATUS))
  330. return true;
  331. return false;
  332. }
  333. static bool tegra30_ahub_apbif_precious_reg(struct device *dev,
  334. unsigned int reg)
  335. {
  336. if (REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
  337. REG_IN_ARRAY(reg, CHANNEL_RXFIFO))
  338. return true;
  339. return false;
  340. }
  341. static const struct regmap_config tegra30_ahub_apbif_regmap_config = {
  342. .name = "apbif",
  343. .reg_bits = 32,
  344. .val_bits = 32,
  345. .reg_stride = 4,
  346. .max_register = TEGRA30_AHUB_APBIF_INT_SET,
  347. .writeable_reg = tegra30_ahub_apbif_wr_rd_reg,
  348. .readable_reg = tegra30_ahub_apbif_wr_rd_reg,
  349. .volatile_reg = tegra30_ahub_apbif_volatile_reg,
  350. .precious_reg = tegra30_ahub_apbif_precious_reg,
  351. .cache_type = REGCACHE_RBTREE,
  352. };
  353. static bool tegra30_ahub_ahub_wr_rd_reg(struct device *dev, unsigned int reg)
  354. {
  355. if (REG_IN_ARRAY(reg, AUDIO_RX))
  356. return true;
  357. return false;
  358. }
  359. static const struct regmap_config tegra30_ahub_ahub_regmap_config = {
  360. .name = "ahub",
  361. .reg_bits = 32,
  362. .val_bits = 32,
  363. .reg_stride = 4,
  364. .max_register = LAST_REG(AUDIO_RX),
  365. .writeable_reg = tegra30_ahub_ahub_wr_rd_reg,
  366. .readable_reg = tegra30_ahub_ahub_wr_rd_reg,
  367. .cache_type = REGCACHE_RBTREE,
  368. };
  369. static int __devinit tegra30_ahub_probe(struct platform_device *pdev)
  370. {
  371. struct clk *clk;
  372. int i;
  373. struct resource *res0, *res1, *region;
  374. u32 of_dma[2];
  375. void __iomem *regs_apbif, *regs_ahub;
  376. int ret = 0;
  377. if (ahub)
  378. return -ENODEV;
  379. /*
  380. * The AHUB hosts a register bus: the "configlink". For this to
  381. * operate correctly, all devices on this bus must be out of reset.
  382. * Ensure that here.
  383. */
  384. for (i = 0; i < ARRAY_SIZE(configlink_clocks); i++) {
  385. clk = clk_get_sys(NULL, configlink_clocks[i]);
  386. if (IS_ERR(clk)) {
  387. dev_err(&pdev->dev, "Can't get clock %s\n",
  388. configlink_clocks[i]);
  389. ret = PTR_ERR(clk);
  390. goto err;
  391. }
  392. tegra_periph_reset_deassert(clk);
  393. clk_put(clk);
  394. }
  395. ahub = devm_kzalloc(&pdev->dev, sizeof(struct tegra30_ahub),
  396. GFP_KERNEL);
  397. if (!ahub) {
  398. dev_err(&pdev->dev, "Can't allocate tegra30_ahub\n");
  399. ret = -ENOMEM;
  400. goto err;
  401. }
  402. dev_set_drvdata(&pdev->dev, ahub);
  403. ahub->dev = &pdev->dev;
  404. ahub->clk_d_audio = clk_get(&pdev->dev, "d_audio");
  405. if (IS_ERR(ahub->clk_d_audio)) {
  406. dev_err(&pdev->dev, "Can't retrieve ahub d_audio clock\n");
  407. ret = PTR_ERR(ahub->clk_d_audio);
  408. goto err;
  409. }
  410. ahub->clk_apbif = clk_get(&pdev->dev, "apbif");
  411. if (IS_ERR(ahub->clk_apbif)) {
  412. dev_err(&pdev->dev, "Can't retrieve ahub apbif clock\n");
  413. ret = PTR_ERR(ahub->clk_apbif);
  414. goto err_clk_put_d_audio;
  415. }
  416. if (of_property_read_u32_array(pdev->dev.of_node,
  417. "nvidia,dma-request-selector",
  418. of_dma, 2) < 0) {
  419. dev_err(&pdev->dev,
  420. "Missing property nvidia,dma-request-selector\n");
  421. ret = -ENODEV;
  422. goto err_clk_put_d_audio;
  423. }
  424. ahub->dma_sel = of_dma[1];
  425. res0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  426. if (!res0) {
  427. dev_err(&pdev->dev, "No apbif memory resource\n");
  428. ret = -ENODEV;
  429. goto err_clk_put_apbif;
  430. }
  431. region = devm_request_mem_region(&pdev->dev, res0->start,
  432. resource_size(res0), DRV_NAME);
  433. if (!region) {
  434. dev_err(&pdev->dev, "request region apbif failed\n");
  435. ret = -EBUSY;
  436. goto err_clk_put_apbif;
  437. }
  438. ahub->apbif_addr = res0->start;
  439. regs_apbif = devm_ioremap(&pdev->dev, res0->start,
  440. resource_size(res0));
  441. if (!regs_apbif) {
  442. dev_err(&pdev->dev, "ioremap apbif failed\n");
  443. ret = -ENOMEM;
  444. goto err_clk_put_apbif;
  445. }
  446. ahub->regmap_apbif = devm_regmap_init_mmio(&pdev->dev, regs_apbif,
  447. &tegra30_ahub_apbif_regmap_config);
  448. if (IS_ERR(ahub->regmap_apbif)) {
  449. dev_err(&pdev->dev, "apbif regmap init failed\n");
  450. ret = PTR_ERR(ahub->regmap_apbif);
  451. goto err_clk_put_apbif;
  452. }
  453. regcache_cache_only(ahub->regmap_apbif, true);
  454. res1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  455. if (!res1) {
  456. dev_err(&pdev->dev, "No ahub memory resource\n");
  457. ret = -ENODEV;
  458. goto err_clk_put_apbif;
  459. }
  460. region = devm_request_mem_region(&pdev->dev, res1->start,
  461. resource_size(res1), DRV_NAME);
  462. if (!region) {
  463. dev_err(&pdev->dev, "request region ahub failed\n");
  464. ret = -EBUSY;
  465. goto err_clk_put_apbif;
  466. }
  467. regs_ahub = devm_ioremap(&pdev->dev, res1->start,
  468. resource_size(res1));
  469. if (!regs_ahub) {
  470. dev_err(&pdev->dev, "ioremap ahub failed\n");
  471. ret = -ENOMEM;
  472. goto err_clk_put_apbif;
  473. }
  474. ahub->regmap_ahub = devm_regmap_init_mmio(&pdev->dev, regs_ahub,
  475. &tegra30_ahub_ahub_regmap_config);
  476. if (IS_ERR(ahub->regmap_ahub)) {
  477. dev_err(&pdev->dev, "ahub regmap init failed\n");
  478. ret = PTR_ERR(ahub->regmap_ahub);
  479. goto err_clk_put_apbif;
  480. }
  481. regcache_cache_only(ahub->regmap_ahub, true);
  482. pm_runtime_enable(&pdev->dev);
  483. if (!pm_runtime_enabled(&pdev->dev)) {
  484. ret = tegra30_ahub_runtime_resume(&pdev->dev);
  485. if (ret)
  486. goto err_pm_disable;
  487. }
  488. of_platform_populate(pdev->dev.of_node, NULL, ahub_auxdata,
  489. &pdev->dev);
  490. return 0;
  491. err_pm_disable:
  492. pm_runtime_disable(&pdev->dev);
  493. err_clk_put_apbif:
  494. clk_put(ahub->clk_apbif);
  495. err_clk_put_d_audio:
  496. clk_put(ahub->clk_d_audio);
  497. ahub = 0;
  498. err:
  499. return ret;
  500. }
  501. static int __devexit tegra30_ahub_remove(struct platform_device *pdev)
  502. {
  503. if (!ahub)
  504. return -ENODEV;
  505. pm_runtime_disable(&pdev->dev);
  506. if (!pm_runtime_status_suspended(&pdev->dev))
  507. tegra30_ahub_runtime_suspend(&pdev->dev);
  508. clk_put(ahub->clk_apbif);
  509. clk_put(ahub->clk_d_audio);
  510. ahub = 0;
  511. return 0;
  512. }
  513. static const struct of_device_id tegra30_ahub_of_match[] __devinitconst = {
  514. { .compatible = "nvidia,tegra30-ahub", },
  515. {},
  516. };
  517. static const struct dev_pm_ops tegra30_ahub_pm_ops __devinitconst = {
  518. SET_RUNTIME_PM_OPS(tegra30_ahub_runtime_suspend,
  519. tegra30_ahub_runtime_resume, NULL)
  520. };
  521. static struct platform_driver tegra30_ahub_driver = {
  522. .probe = tegra30_ahub_probe,
  523. .remove = __devexit_p(tegra30_ahub_remove),
  524. .driver = {
  525. .name = DRV_NAME,
  526. .owner = THIS_MODULE,
  527. .of_match_table = tegra30_ahub_of_match,
  528. .pm = &tegra30_ahub_pm_ops,
  529. },
  530. };
  531. module_platform_driver(tegra30_ahub_driver);
  532. MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
  533. MODULE_DESCRIPTION("Tegra30 AHUB driver");
  534. MODULE_LICENSE("GPL v2");
  535. MODULE_ALIAS("platform:" DRV_NAME);