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