tegra30_ahub.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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 <linux/clk/tegra.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. #define LAST_REG(name) \
  250. (TEGRA30_AHUB_##name + \
  251. (TEGRA30_AHUB_##name##_STRIDE * TEGRA30_AHUB_##name##_COUNT) - 4)
  252. #define REG_IN_ARRAY(reg, name) \
  253. ((reg >= TEGRA30_AHUB_##name) && \
  254. (reg <= LAST_REG(name) && \
  255. (!((reg - TEGRA30_AHUB_##name) % TEGRA30_AHUB_##name##_STRIDE))))
  256. static bool tegra30_ahub_apbif_wr_rd_reg(struct device *dev, unsigned int reg)
  257. {
  258. switch (reg) {
  259. case TEGRA30_AHUB_CONFIG_LINK_CTRL:
  260. case TEGRA30_AHUB_MISC_CTRL:
  261. case TEGRA30_AHUB_APBDMA_LIVE_STATUS:
  262. case TEGRA30_AHUB_I2S_LIVE_STATUS:
  263. case TEGRA30_AHUB_SPDIF_LIVE_STATUS:
  264. case TEGRA30_AHUB_I2S_INT_MASK:
  265. case TEGRA30_AHUB_DAM_INT_MASK:
  266. case TEGRA30_AHUB_SPDIF_INT_MASK:
  267. case TEGRA30_AHUB_APBIF_INT_MASK:
  268. case TEGRA30_AHUB_I2S_INT_STATUS:
  269. case TEGRA30_AHUB_DAM_INT_STATUS:
  270. case TEGRA30_AHUB_SPDIF_INT_STATUS:
  271. case TEGRA30_AHUB_APBIF_INT_STATUS:
  272. case TEGRA30_AHUB_I2S_INT_SOURCE:
  273. case TEGRA30_AHUB_DAM_INT_SOURCE:
  274. case TEGRA30_AHUB_SPDIF_INT_SOURCE:
  275. case TEGRA30_AHUB_APBIF_INT_SOURCE:
  276. case TEGRA30_AHUB_I2S_INT_SET:
  277. case TEGRA30_AHUB_DAM_INT_SET:
  278. case TEGRA30_AHUB_SPDIF_INT_SET:
  279. case TEGRA30_AHUB_APBIF_INT_SET:
  280. return true;
  281. default:
  282. break;
  283. };
  284. if (REG_IN_ARRAY(reg, CHANNEL_CTRL) ||
  285. REG_IN_ARRAY(reg, CHANNEL_CLEAR) ||
  286. REG_IN_ARRAY(reg, CHANNEL_STATUS) ||
  287. REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
  288. REG_IN_ARRAY(reg, CHANNEL_RXFIFO) ||
  289. REG_IN_ARRAY(reg, CIF_TX_CTRL) ||
  290. REG_IN_ARRAY(reg, CIF_RX_CTRL) ||
  291. REG_IN_ARRAY(reg, DAM_LIVE_STATUS))
  292. return true;
  293. return false;
  294. }
  295. static bool tegra30_ahub_apbif_volatile_reg(struct device *dev,
  296. unsigned int reg)
  297. {
  298. switch (reg) {
  299. case TEGRA30_AHUB_CONFIG_LINK_CTRL:
  300. case TEGRA30_AHUB_MISC_CTRL:
  301. case TEGRA30_AHUB_APBDMA_LIVE_STATUS:
  302. case TEGRA30_AHUB_I2S_LIVE_STATUS:
  303. case TEGRA30_AHUB_SPDIF_LIVE_STATUS:
  304. case TEGRA30_AHUB_I2S_INT_STATUS:
  305. case TEGRA30_AHUB_DAM_INT_STATUS:
  306. case TEGRA30_AHUB_SPDIF_INT_STATUS:
  307. case TEGRA30_AHUB_APBIF_INT_STATUS:
  308. case TEGRA30_AHUB_I2S_INT_SET:
  309. case TEGRA30_AHUB_DAM_INT_SET:
  310. case TEGRA30_AHUB_SPDIF_INT_SET:
  311. case TEGRA30_AHUB_APBIF_INT_SET:
  312. return true;
  313. default:
  314. break;
  315. };
  316. if (REG_IN_ARRAY(reg, CHANNEL_CLEAR) ||
  317. REG_IN_ARRAY(reg, CHANNEL_STATUS) ||
  318. REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
  319. REG_IN_ARRAY(reg, CHANNEL_RXFIFO) ||
  320. REG_IN_ARRAY(reg, DAM_LIVE_STATUS))
  321. return true;
  322. return false;
  323. }
  324. static bool tegra30_ahub_apbif_precious_reg(struct device *dev,
  325. unsigned int reg)
  326. {
  327. if (REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
  328. REG_IN_ARRAY(reg, CHANNEL_RXFIFO))
  329. return true;
  330. return false;
  331. }
  332. static const struct regmap_config tegra30_ahub_apbif_regmap_config = {
  333. .name = "apbif",
  334. .reg_bits = 32,
  335. .val_bits = 32,
  336. .reg_stride = 4,
  337. .max_register = TEGRA30_AHUB_APBIF_INT_SET,
  338. .writeable_reg = tegra30_ahub_apbif_wr_rd_reg,
  339. .readable_reg = tegra30_ahub_apbif_wr_rd_reg,
  340. .volatile_reg = tegra30_ahub_apbif_volatile_reg,
  341. .precious_reg = tegra30_ahub_apbif_precious_reg,
  342. .cache_type = REGCACHE_RBTREE,
  343. };
  344. static bool tegra30_ahub_ahub_wr_rd_reg(struct device *dev, unsigned int reg)
  345. {
  346. if (REG_IN_ARRAY(reg, AUDIO_RX))
  347. return true;
  348. return false;
  349. }
  350. static const struct regmap_config tegra30_ahub_ahub_regmap_config = {
  351. .name = "ahub",
  352. .reg_bits = 32,
  353. .val_bits = 32,
  354. .reg_stride = 4,
  355. .max_register = LAST_REG(AUDIO_RX),
  356. .writeable_reg = tegra30_ahub_ahub_wr_rd_reg,
  357. .readable_reg = tegra30_ahub_ahub_wr_rd_reg,
  358. .cache_type = REGCACHE_RBTREE,
  359. };
  360. static int tegra30_ahub_probe(struct platform_device *pdev)
  361. {
  362. struct clk *clk;
  363. int i;
  364. struct resource *res0, *res1, *region;
  365. u32 of_dma[2];
  366. void __iomem *regs_apbif, *regs_ahub;
  367. int ret = 0;
  368. if (ahub)
  369. return -ENODEV;
  370. /*
  371. * The AHUB hosts a register bus: the "configlink". For this to
  372. * operate correctly, all devices on this bus must be out of reset.
  373. * Ensure that here.
  374. */
  375. for (i = 0; i < ARRAY_SIZE(configlink_clocks); i++) {
  376. clk = clk_get(&pdev->dev, configlink_clocks[i]);
  377. if (IS_ERR(clk)) {
  378. dev_err(&pdev->dev, "Can't get clock %s\n",
  379. configlink_clocks[i]);
  380. ret = PTR_ERR(clk);
  381. goto err;
  382. }
  383. tegra_periph_reset_deassert(clk);
  384. clk_put(clk);
  385. }
  386. ahub = devm_kzalloc(&pdev->dev, sizeof(struct tegra30_ahub),
  387. GFP_KERNEL);
  388. if (!ahub) {
  389. dev_err(&pdev->dev, "Can't allocate tegra30_ahub\n");
  390. ret = -ENOMEM;
  391. goto err;
  392. }
  393. dev_set_drvdata(&pdev->dev, ahub);
  394. ahub->dev = &pdev->dev;
  395. ahub->clk_d_audio = clk_get(&pdev->dev, "d_audio");
  396. if (IS_ERR(ahub->clk_d_audio)) {
  397. dev_err(&pdev->dev, "Can't retrieve ahub d_audio clock\n");
  398. ret = PTR_ERR(ahub->clk_d_audio);
  399. goto err;
  400. }
  401. ahub->clk_apbif = clk_get(&pdev->dev, "apbif");
  402. if (IS_ERR(ahub->clk_apbif)) {
  403. dev_err(&pdev->dev, "Can't retrieve ahub apbif clock\n");
  404. ret = PTR_ERR(ahub->clk_apbif);
  405. goto err_clk_put_d_audio;
  406. }
  407. if (of_property_read_u32_array(pdev->dev.of_node,
  408. "nvidia,dma-request-selector",
  409. of_dma, 2) < 0) {
  410. dev_err(&pdev->dev,
  411. "Missing property nvidia,dma-request-selector\n");
  412. ret = -ENODEV;
  413. goto err_clk_put_d_audio;
  414. }
  415. ahub->dma_sel = of_dma[1];
  416. res0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  417. if (!res0) {
  418. dev_err(&pdev->dev, "No apbif memory resource\n");
  419. ret = -ENODEV;
  420. goto err_clk_put_apbif;
  421. }
  422. region = devm_request_mem_region(&pdev->dev, res0->start,
  423. resource_size(res0), DRV_NAME);
  424. if (!region) {
  425. dev_err(&pdev->dev, "request region apbif failed\n");
  426. ret = -EBUSY;
  427. goto err_clk_put_apbif;
  428. }
  429. ahub->apbif_addr = res0->start;
  430. regs_apbif = devm_ioremap(&pdev->dev, res0->start,
  431. resource_size(res0));
  432. if (!regs_apbif) {
  433. dev_err(&pdev->dev, "ioremap apbif failed\n");
  434. ret = -ENOMEM;
  435. goto err_clk_put_apbif;
  436. }
  437. ahub->regmap_apbif = devm_regmap_init_mmio(&pdev->dev, regs_apbif,
  438. &tegra30_ahub_apbif_regmap_config);
  439. if (IS_ERR(ahub->regmap_apbif)) {
  440. dev_err(&pdev->dev, "apbif regmap init failed\n");
  441. ret = PTR_ERR(ahub->regmap_apbif);
  442. goto err_clk_put_apbif;
  443. }
  444. regcache_cache_only(ahub->regmap_apbif, true);
  445. res1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  446. if (!res1) {
  447. dev_err(&pdev->dev, "No ahub memory resource\n");
  448. ret = -ENODEV;
  449. goto err_clk_put_apbif;
  450. }
  451. region = devm_request_mem_region(&pdev->dev, res1->start,
  452. resource_size(res1), DRV_NAME);
  453. if (!region) {
  454. dev_err(&pdev->dev, "request region ahub failed\n");
  455. ret = -EBUSY;
  456. goto err_clk_put_apbif;
  457. }
  458. regs_ahub = devm_ioremap(&pdev->dev, res1->start,
  459. resource_size(res1));
  460. if (!regs_ahub) {
  461. dev_err(&pdev->dev, "ioremap ahub failed\n");
  462. ret = -ENOMEM;
  463. goto err_clk_put_apbif;
  464. }
  465. ahub->regmap_ahub = devm_regmap_init_mmio(&pdev->dev, regs_ahub,
  466. &tegra30_ahub_ahub_regmap_config);
  467. if (IS_ERR(ahub->regmap_ahub)) {
  468. dev_err(&pdev->dev, "ahub regmap init failed\n");
  469. ret = PTR_ERR(ahub->regmap_ahub);
  470. goto err_clk_put_apbif;
  471. }
  472. regcache_cache_only(ahub->regmap_ahub, true);
  473. pm_runtime_enable(&pdev->dev);
  474. if (!pm_runtime_enabled(&pdev->dev)) {
  475. ret = tegra30_ahub_runtime_resume(&pdev->dev);
  476. if (ret)
  477. goto err_pm_disable;
  478. }
  479. of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
  480. return 0;
  481. err_pm_disable:
  482. pm_runtime_disable(&pdev->dev);
  483. err_clk_put_apbif:
  484. clk_put(ahub->clk_apbif);
  485. err_clk_put_d_audio:
  486. clk_put(ahub->clk_d_audio);
  487. ahub = NULL;
  488. err:
  489. return ret;
  490. }
  491. static int tegra30_ahub_remove(struct platform_device *pdev)
  492. {
  493. if (!ahub)
  494. return -ENODEV;
  495. pm_runtime_disable(&pdev->dev);
  496. if (!pm_runtime_status_suspended(&pdev->dev))
  497. tegra30_ahub_runtime_suspend(&pdev->dev);
  498. clk_put(ahub->clk_apbif);
  499. clk_put(ahub->clk_d_audio);
  500. ahub = NULL;
  501. return 0;
  502. }
  503. static const struct of_device_id tegra30_ahub_of_match[] = {
  504. { .compatible = "nvidia,tegra30-ahub", },
  505. {},
  506. };
  507. static const struct dev_pm_ops tegra30_ahub_pm_ops = {
  508. SET_RUNTIME_PM_OPS(tegra30_ahub_runtime_suspend,
  509. tegra30_ahub_runtime_resume, NULL)
  510. };
  511. static struct platform_driver tegra30_ahub_driver = {
  512. .probe = tegra30_ahub_probe,
  513. .remove = tegra30_ahub_remove,
  514. .driver = {
  515. .name = DRV_NAME,
  516. .owner = THIS_MODULE,
  517. .of_match_table = tegra30_ahub_of_match,
  518. .pm = &tegra30_ahub_pm_ops,
  519. },
  520. };
  521. module_platform_driver(tegra30_ahub_driver);
  522. MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
  523. MODULE_DESCRIPTION("Tegra30 AHUB driver");
  524. MODULE_LICENSE("GPL v2");
  525. MODULE_ALIAS("platform:" DRV_NAME);
  526. MODULE_DEVICE_TABLE(of, tegra30_ahub_of_match);