2 * tegra30_ahub.c - Tegra30 AHUB driver
4 * Copyright (c) 2011,2012, NVIDIA CORPORATION. All rights reserved.
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.
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
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/>.
19 #include <linux/clk.h>
20 #include <linux/device.h>
22 #include <linux/module.h>
23 #include <linux/of_platform.h>
24 #include <linux/platform_device.h>
25 #include <linux/pm_runtime.h>
26 #include <linux/regmap.h>
27 #include <linux/slab.h>
28 #include <linux/clk/tegra.h>
29 #include <sound/soc.h>
30 #include "tegra30_ahub.h"
32 #define DRV_NAME "tegra30-ahub"
34 static struct tegra30_ahub *ahub;
36 static inline void tegra30_apbif_write(u32 reg, u32 val)
38 regmap_write(ahub->regmap_apbif, reg, val);
41 static inline u32 tegra30_apbif_read(u32 reg)
44 regmap_read(ahub->regmap_apbif, reg, &val);
48 static inline void tegra30_audio_write(u32 reg, u32 val)
50 regmap_write(ahub->regmap_ahub, reg, val);
53 static int tegra30_ahub_runtime_suspend(struct device *dev)
55 regcache_cache_only(ahub->regmap_apbif, true);
56 regcache_cache_only(ahub->regmap_ahub, true);
58 clk_disable_unprepare(ahub->clk_apbif);
59 clk_disable_unprepare(ahub->clk_d_audio);
65 * clk_apbif isn't required for an I2S<->I2S configuration where no PCM data
66 * is read from or sent to memory. However, that's not something the rest of
67 * the driver supports right now, so we'll just treat the two clocks as one
70 * These functions should not be a plain ref-count. Instead, each active stream
71 * contributes some requirement to the minimum clock rate, so starting or
72 * stopping streams should dynamically adjust the clock as required. However,
73 * this is not yet implemented.
75 static int tegra30_ahub_runtime_resume(struct device *dev)
79 ret = clk_prepare_enable(ahub->clk_d_audio);
81 dev_err(dev, "clk_enable d_audio failed: %d\n", ret);
84 ret = clk_prepare_enable(ahub->clk_apbif);
86 dev_err(dev, "clk_enable apbif failed: %d\n", ret);
87 clk_disable(ahub->clk_d_audio);
91 regcache_cache_only(ahub->regmap_apbif, false);
92 regcache_cache_only(ahub->regmap_ahub, false);
97 int tegra30_ahub_allocate_rx_fifo(enum tegra30_ahub_rxcif *rxcif,
103 struct tegra30_ahub_cif_conf cif_conf;
105 channel = find_first_zero_bit(ahub->rx_usage,
106 TEGRA30_AHUB_CHANNEL_CTRL_COUNT);
107 if (channel >= TEGRA30_AHUB_CHANNEL_CTRL_COUNT)
110 __set_bit(channel, ahub->rx_usage);
112 *rxcif = TEGRA30_AHUB_RXCIF_APBIF_RX0 + channel;
113 *fiforeg = ahub->apbif_addr + TEGRA30_AHUB_CHANNEL_RXFIFO +
114 (channel * TEGRA30_AHUB_CHANNEL_RXFIFO_STRIDE);
115 *reqsel = ahub->dma_sel + channel;
117 reg = TEGRA30_AHUB_CHANNEL_CTRL +
118 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
119 val = tegra30_apbif_read(reg);
120 val &= ~(TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_MASK |
121 TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_MASK);
122 val |= (7 << TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_SHIFT) |
123 TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_EN |
124 TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_16;
125 tegra30_apbif_write(reg, val);
127 cif_conf.threshold = 0;
128 cif_conf.audio_channels = 2;
129 cif_conf.client_channels = 2;
130 cif_conf.audio_bits = TEGRA30_AUDIOCIF_BITS_16;
131 cif_conf.client_bits = TEGRA30_AUDIOCIF_BITS_16;
133 cif_conf.stereo_conv = 0;
134 cif_conf.replicate = 0;
135 cif_conf.direction = TEGRA30_AUDIOCIF_DIRECTION_RX;
136 cif_conf.truncate = 0;
137 cif_conf.mono_conv = 0;
139 reg = TEGRA30_AHUB_CIF_RX_CTRL +
140 (channel * TEGRA30_AHUB_CIF_RX_CTRL_STRIDE);
141 ahub->soc_data->set_audio_cif(ahub->regmap_apbif, reg, &cif_conf);
145 EXPORT_SYMBOL_GPL(tegra30_ahub_allocate_rx_fifo);
147 int tegra30_ahub_enable_rx_fifo(enum tegra30_ahub_rxcif rxcif)
149 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
152 reg = TEGRA30_AHUB_CHANNEL_CTRL +
153 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
154 val = tegra30_apbif_read(reg);
155 val |= TEGRA30_AHUB_CHANNEL_CTRL_RX_EN;
156 tegra30_apbif_write(reg, val);
160 EXPORT_SYMBOL_GPL(tegra30_ahub_enable_rx_fifo);
162 int tegra30_ahub_disable_rx_fifo(enum tegra30_ahub_rxcif rxcif)
164 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
167 reg = TEGRA30_AHUB_CHANNEL_CTRL +
168 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
169 val = tegra30_apbif_read(reg);
170 val &= ~TEGRA30_AHUB_CHANNEL_CTRL_RX_EN;
171 tegra30_apbif_write(reg, val);
175 EXPORT_SYMBOL_GPL(tegra30_ahub_disable_rx_fifo);
177 int tegra30_ahub_free_rx_fifo(enum tegra30_ahub_rxcif rxcif)
179 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
181 __clear_bit(channel, ahub->rx_usage);
185 EXPORT_SYMBOL_GPL(tegra30_ahub_free_rx_fifo);
187 int tegra30_ahub_allocate_tx_fifo(enum tegra30_ahub_txcif *txcif,
189 unsigned int *reqsel)
193 struct tegra30_ahub_cif_conf cif_conf;
195 channel = find_first_zero_bit(ahub->tx_usage,
196 TEGRA30_AHUB_CHANNEL_CTRL_COUNT);
197 if (channel >= TEGRA30_AHUB_CHANNEL_CTRL_COUNT)
200 __set_bit(channel, ahub->tx_usage);
202 *txcif = TEGRA30_AHUB_TXCIF_APBIF_TX0 + channel;
203 *fiforeg = ahub->apbif_addr + TEGRA30_AHUB_CHANNEL_TXFIFO +
204 (channel * TEGRA30_AHUB_CHANNEL_TXFIFO_STRIDE);
205 *reqsel = ahub->dma_sel + channel;
207 reg = TEGRA30_AHUB_CHANNEL_CTRL +
208 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
209 val = tegra30_apbif_read(reg);
210 val &= ~(TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_MASK |
211 TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_MASK);
212 val |= (7 << TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_SHIFT) |
213 TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_EN |
214 TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_16;
215 tegra30_apbif_write(reg, val);
217 cif_conf.threshold = 0;
218 cif_conf.audio_channels = 2;
219 cif_conf.client_channels = 2;
220 cif_conf.audio_bits = TEGRA30_AUDIOCIF_BITS_16;
221 cif_conf.client_bits = TEGRA30_AUDIOCIF_BITS_16;
223 cif_conf.stereo_conv = 0;
224 cif_conf.replicate = 0;
225 cif_conf.direction = TEGRA30_AUDIOCIF_DIRECTION_TX;
226 cif_conf.truncate = 0;
227 cif_conf.mono_conv = 0;
229 reg = TEGRA30_AHUB_CIF_TX_CTRL +
230 (channel * TEGRA30_AHUB_CIF_TX_CTRL_STRIDE);
231 ahub->soc_data->set_audio_cif(ahub->regmap_apbif, reg, &cif_conf);
235 EXPORT_SYMBOL_GPL(tegra30_ahub_allocate_tx_fifo);
237 int tegra30_ahub_enable_tx_fifo(enum tegra30_ahub_txcif txcif)
239 int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
242 reg = TEGRA30_AHUB_CHANNEL_CTRL +
243 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
244 val = tegra30_apbif_read(reg);
245 val |= TEGRA30_AHUB_CHANNEL_CTRL_TX_EN;
246 tegra30_apbif_write(reg, val);
250 EXPORT_SYMBOL_GPL(tegra30_ahub_enable_tx_fifo);
252 int tegra30_ahub_disable_tx_fifo(enum tegra30_ahub_txcif txcif)
254 int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
257 reg = TEGRA30_AHUB_CHANNEL_CTRL +
258 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
259 val = tegra30_apbif_read(reg);
260 val &= ~TEGRA30_AHUB_CHANNEL_CTRL_TX_EN;
261 tegra30_apbif_write(reg, val);
265 EXPORT_SYMBOL_GPL(tegra30_ahub_disable_tx_fifo);
267 int tegra30_ahub_free_tx_fifo(enum tegra30_ahub_txcif txcif)
269 int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
271 __clear_bit(channel, ahub->tx_usage);
275 EXPORT_SYMBOL_GPL(tegra30_ahub_free_tx_fifo);
277 int tegra30_ahub_set_rx_cif_source(enum tegra30_ahub_rxcif rxcif,
278 enum tegra30_ahub_txcif txcif)
280 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
283 reg = TEGRA30_AHUB_AUDIO_RX +
284 (channel * TEGRA30_AHUB_AUDIO_RX_STRIDE);
285 tegra30_audio_write(reg, 1 << txcif);
289 EXPORT_SYMBOL_GPL(tegra30_ahub_set_rx_cif_source);
291 int tegra30_ahub_unset_rx_cif_source(enum tegra30_ahub_rxcif rxcif)
293 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
296 reg = TEGRA30_AHUB_AUDIO_RX +
297 (channel * TEGRA30_AHUB_AUDIO_RX_STRIDE);
298 tegra30_audio_write(reg, 0);
302 EXPORT_SYMBOL_GPL(tegra30_ahub_unset_rx_cif_source);
304 #define CLK_LIST_MASK_TEGRA30 BIT(0)
305 #define CLK_LIST_MASK_TEGRA114 BIT(1)
307 #define CLK_LIST_MASK_TEGRA30_OR_LATER \
308 (CLK_LIST_MASK_TEGRA30 | CLK_LIST_MASK_TEGRA114)
310 static const struct {
311 const char *clk_name;
313 } configlink_clocks[] = {
314 { "i2s0", CLK_LIST_MASK_TEGRA30_OR_LATER },
315 { "i2s1", CLK_LIST_MASK_TEGRA30_OR_LATER },
316 { "i2s2", CLK_LIST_MASK_TEGRA30_OR_LATER },
317 { "i2s3", CLK_LIST_MASK_TEGRA30_OR_LATER },
318 { "i2s4", CLK_LIST_MASK_TEGRA30_OR_LATER },
319 { "dam0", CLK_LIST_MASK_TEGRA30_OR_LATER },
320 { "dam1", CLK_LIST_MASK_TEGRA30_OR_LATER },
321 { "dam2", CLK_LIST_MASK_TEGRA30_OR_LATER },
322 { "spdif_in", CLK_LIST_MASK_TEGRA30_OR_LATER },
323 { "amx", CLK_LIST_MASK_TEGRA114 },
324 { "adx", CLK_LIST_MASK_TEGRA114 },
327 #define LAST_REG(name) \
328 (TEGRA30_AHUB_##name + \
329 (TEGRA30_AHUB_##name##_STRIDE * TEGRA30_AHUB_##name##_COUNT) - 4)
331 #define REG_IN_ARRAY(reg, name) \
332 ((reg >= TEGRA30_AHUB_##name) && \
333 (reg <= LAST_REG(name) && \
334 (!((reg - TEGRA30_AHUB_##name) % TEGRA30_AHUB_##name##_STRIDE))))
336 static bool tegra30_ahub_apbif_wr_rd_reg(struct device *dev, unsigned int reg)
339 case TEGRA30_AHUB_CONFIG_LINK_CTRL:
340 case TEGRA30_AHUB_MISC_CTRL:
341 case TEGRA30_AHUB_APBDMA_LIVE_STATUS:
342 case TEGRA30_AHUB_I2S_LIVE_STATUS:
343 case TEGRA30_AHUB_SPDIF_LIVE_STATUS:
344 case TEGRA30_AHUB_I2S_INT_MASK:
345 case TEGRA30_AHUB_DAM_INT_MASK:
346 case TEGRA30_AHUB_SPDIF_INT_MASK:
347 case TEGRA30_AHUB_APBIF_INT_MASK:
348 case TEGRA30_AHUB_I2S_INT_STATUS:
349 case TEGRA30_AHUB_DAM_INT_STATUS:
350 case TEGRA30_AHUB_SPDIF_INT_STATUS:
351 case TEGRA30_AHUB_APBIF_INT_STATUS:
352 case TEGRA30_AHUB_I2S_INT_SOURCE:
353 case TEGRA30_AHUB_DAM_INT_SOURCE:
354 case TEGRA30_AHUB_SPDIF_INT_SOURCE:
355 case TEGRA30_AHUB_APBIF_INT_SOURCE:
356 case TEGRA30_AHUB_I2S_INT_SET:
357 case TEGRA30_AHUB_DAM_INT_SET:
358 case TEGRA30_AHUB_SPDIF_INT_SET:
359 case TEGRA30_AHUB_APBIF_INT_SET:
365 if (REG_IN_ARRAY(reg, CHANNEL_CTRL) ||
366 REG_IN_ARRAY(reg, CHANNEL_CLEAR) ||
367 REG_IN_ARRAY(reg, CHANNEL_STATUS) ||
368 REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
369 REG_IN_ARRAY(reg, CHANNEL_RXFIFO) ||
370 REG_IN_ARRAY(reg, CIF_TX_CTRL) ||
371 REG_IN_ARRAY(reg, CIF_RX_CTRL) ||
372 REG_IN_ARRAY(reg, DAM_LIVE_STATUS))
378 static bool tegra30_ahub_apbif_volatile_reg(struct device *dev,
382 case TEGRA30_AHUB_CONFIG_LINK_CTRL:
383 case TEGRA30_AHUB_MISC_CTRL:
384 case TEGRA30_AHUB_APBDMA_LIVE_STATUS:
385 case TEGRA30_AHUB_I2S_LIVE_STATUS:
386 case TEGRA30_AHUB_SPDIF_LIVE_STATUS:
387 case TEGRA30_AHUB_I2S_INT_STATUS:
388 case TEGRA30_AHUB_DAM_INT_STATUS:
389 case TEGRA30_AHUB_SPDIF_INT_STATUS:
390 case TEGRA30_AHUB_APBIF_INT_STATUS:
391 case TEGRA30_AHUB_I2S_INT_SET:
392 case TEGRA30_AHUB_DAM_INT_SET:
393 case TEGRA30_AHUB_SPDIF_INT_SET:
394 case TEGRA30_AHUB_APBIF_INT_SET:
400 if (REG_IN_ARRAY(reg, CHANNEL_CLEAR) ||
401 REG_IN_ARRAY(reg, CHANNEL_STATUS) ||
402 REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
403 REG_IN_ARRAY(reg, CHANNEL_RXFIFO) ||
404 REG_IN_ARRAY(reg, DAM_LIVE_STATUS))
410 static bool tegra30_ahub_apbif_precious_reg(struct device *dev,
413 if (REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
414 REG_IN_ARRAY(reg, CHANNEL_RXFIFO))
420 static const struct regmap_config tegra30_ahub_apbif_regmap_config = {
425 .max_register = TEGRA30_AHUB_APBIF_INT_SET,
426 .writeable_reg = tegra30_ahub_apbif_wr_rd_reg,
427 .readable_reg = tegra30_ahub_apbif_wr_rd_reg,
428 .volatile_reg = tegra30_ahub_apbif_volatile_reg,
429 .precious_reg = tegra30_ahub_apbif_precious_reg,
430 .cache_type = REGCACHE_RBTREE,
433 static bool tegra30_ahub_ahub_wr_rd_reg(struct device *dev, unsigned int reg)
435 if (REG_IN_ARRAY(reg, AUDIO_RX))
441 static const struct regmap_config tegra30_ahub_ahub_regmap_config = {
446 .max_register = LAST_REG(AUDIO_RX),
447 .writeable_reg = tegra30_ahub_ahub_wr_rd_reg,
448 .readable_reg = tegra30_ahub_ahub_wr_rd_reg,
449 .cache_type = REGCACHE_RBTREE,
452 static struct tegra30_ahub_soc_data soc_data_tegra30 = {
453 .clk_list_mask = CLK_LIST_MASK_TEGRA30,
454 .set_audio_cif = tegra30_ahub_set_cif,
457 static struct tegra30_ahub_soc_data soc_data_tegra114 = {
458 .clk_list_mask = CLK_LIST_MASK_TEGRA114,
459 .set_audio_cif = tegra30_ahub_set_cif,
462 static struct tegra30_ahub_soc_data soc_data_tegra124 = {
463 .clk_list_mask = CLK_LIST_MASK_TEGRA114,
464 .set_audio_cif = tegra124_ahub_set_cif,
467 static const struct of_device_id tegra30_ahub_of_match[] = {
468 { .compatible = "nvidia,tegra124-ahub", .data = &soc_data_tegra124 },
469 { .compatible = "nvidia,tegra114-ahub", .data = &soc_data_tegra114 },
470 { .compatible = "nvidia,tegra30-ahub", .data = &soc_data_tegra30 },
474 static int tegra30_ahub_probe(struct platform_device *pdev)
476 const struct of_device_id *match;
477 const struct tegra30_ahub_soc_data *soc_data;
480 struct resource *res0, *res1, *region;
482 void __iomem *regs_apbif, *regs_ahub;
488 match = of_match_device(tegra30_ahub_of_match, &pdev->dev);
491 soc_data = match->data;
494 * The AHUB hosts a register bus: the "configlink". For this to
495 * operate correctly, all devices on this bus must be out of reset.
498 for (i = 0; i < ARRAY_SIZE(configlink_clocks); i++) {
499 if (!(configlink_clocks[i].clk_list_mask &
500 soc_data->clk_list_mask))
502 clk = clk_get(&pdev->dev, configlink_clocks[i].clk_name);
504 dev_err(&pdev->dev, "Can't get clock %s\n",
505 configlink_clocks[i].clk_name);
509 tegra_periph_reset_deassert(clk);
513 ahub = devm_kzalloc(&pdev->dev, sizeof(struct tegra30_ahub),
516 dev_err(&pdev->dev, "Can't allocate tegra30_ahub\n");
520 dev_set_drvdata(&pdev->dev, ahub);
522 ahub->soc_data = soc_data;
523 ahub->dev = &pdev->dev;
525 ahub->clk_d_audio = clk_get(&pdev->dev, "d_audio");
526 if (IS_ERR(ahub->clk_d_audio)) {
527 dev_err(&pdev->dev, "Can't retrieve ahub d_audio clock\n");
528 ret = PTR_ERR(ahub->clk_d_audio);
532 ahub->clk_apbif = clk_get(&pdev->dev, "apbif");
533 if (IS_ERR(ahub->clk_apbif)) {
534 dev_err(&pdev->dev, "Can't retrieve ahub apbif clock\n");
535 ret = PTR_ERR(ahub->clk_apbif);
536 goto err_clk_put_d_audio;
539 if (of_property_read_u32_array(pdev->dev.of_node,
540 "nvidia,dma-request-selector",
543 "Missing property nvidia,dma-request-selector\n");
545 goto err_clk_put_d_audio;
547 ahub->dma_sel = of_dma[1];
549 res0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
551 dev_err(&pdev->dev, "No apbif memory resource\n");
553 goto err_clk_put_apbif;
556 region = devm_request_mem_region(&pdev->dev, res0->start,
557 resource_size(res0), DRV_NAME);
559 dev_err(&pdev->dev, "request region apbif failed\n");
561 goto err_clk_put_apbif;
563 ahub->apbif_addr = res0->start;
565 regs_apbif = devm_ioremap(&pdev->dev, res0->start,
566 resource_size(res0));
568 dev_err(&pdev->dev, "ioremap apbif failed\n");
570 goto err_clk_put_apbif;
573 ahub->regmap_apbif = devm_regmap_init_mmio(&pdev->dev, regs_apbif,
574 &tegra30_ahub_apbif_regmap_config);
575 if (IS_ERR(ahub->regmap_apbif)) {
576 dev_err(&pdev->dev, "apbif regmap init failed\n");
577 ret = PTR_ERR(ahub->regmap_apbif);
578 goto err_clk_put_apbif;
580 regcache_cache_only(ahub->regmap_apbif, true);
582 res1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
584 dev_err(&pdev->dev, "No ahub memory resource\n");
586 goto err_clk_put_apbif;
589 region = devm_request_mem_region(&pdev->dev, res1->start,
590 resource_size(res1), DRV_NAME);
592 dev_err(&pdev->dev, "request region ahub failed\n");
594 goto err_clk_put_apbif;
597 regs_ahub = devm_ioremap(&pdev->dev, res1->start,
598 resource_size(res1));
600 dev_err(&pdev->dev, "ioremap ahub failed\n");
602 goto err_clk_put_apbif;
605 ahub->regmap_ahub = devm_regmap_init_mmio(&pdev->dev, regs_ahub,
606 &tegra30_ahub_ahub_regmap_config);
607 if (IS_ERR(ahub->regmap_ahub)) {
608 dev_err(&pdev->dev, "ahub regmap init failed\n");
609 ret = PTR_ERR(ahub->regmap_ahub);
610 goto err_clk_put_apbif;
612 regcache_cache_only(ahub->regmap_ahub, true);
614 pm_runtime_enable(&pdev->dev);
615 if (!pm_runtime_enabled(&pdev->dev)) {
616 ret = tegra30_ahub_runtime_resume(&pdev->dev);
621 of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
626 pm_runtime_disable(&pdev->dev);
628 clk_put(ahub->clk_apbif);
630 clk_put(ahub->clk_d_audio);
636 static int tegra30_ahub_remove(struct platform_device *pdev)
641 pm_runtime_disable(&pdev->dev);
642 if (!pm_runtime_status_suspended(&pdev->dev))
643 tegra30_ahub_runtime_suspend(&pdev->dev);
645 clk_put(ahub->clk_apbif);
646 clk_put(ahub->clk_d_audio);
653 #ifdef CONFIG_PM_SLEEP
654 static int tegra30_ahub_suspend(struct device *dev)
656 regcache_mark_dirty(ahub->regmap_ahub);
657 regcache_mark_dirty(ahub->regmap_apbif);
662 static int tegra30_ahub_resume(struct device *dev)
666 ret = pm_runtime_get_sync(dev);
669 ret = regcache_sync(ahub->regmap_ahub);
670 ret |= regcache_sync(ahub->regmap_apbif);
677 static const struct dev_pm_ops tegra30_ahub_pm_ops = {
678 SET_RUNTIME_PM_OPS(tegra30_ahub_runtime_suspend,
679 tegra30_ahub_runtime_resume, NULL)
680 SET_SYSTEM_SLEEP_PM_OPS(tegra30_ahub_suspend, tegra30_ahub_resume)
683 static struct platform_driver tegra30_ahub_driver = {
684 .probe = tegra30_ahub_probe,
685 .remove = tegra30_ahub_remove,
688 .owner = THIS_MODULE,
689 .of_match_table = tegra30_ahub_of_match,
690 .pm = &tegra30_ahub_pm_ops,
693 module_platform_driver(tegra30_ahub_driver);
695 void tegra30_ahub_set_cif(struct regmap *regmap, unsigned int reg,
696 struct tegra30_ahub_cif_conf *conf)
700 value = (conf->threshold <<
701 TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) |
702 ((conf->audio_channels - 1) <<
703 TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
704 ((conf->client_channels - 1) <<
705 TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) |
707 TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT) |
708 (conf->client_bits <<
709 TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT) |
711 TEGRA30_AUDIOCIF_CTRL_EXPAND_SHIFT) |
712 (conf->stereo_conv <<
713 TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT) |
715 TEGRA30_AUDIOCIF_CTRL_REPLICATE_SHIFT) |
717 TEGRA30_AUDIOCIF_CTRL_DIRECTION_SHIFT) |
719 TEGRA30_AUDIOCIF_CTRL_TRUNCATE_SHIFT) |
721 TEGRA30_AUDIOCIF_CTRL_MONO_CONV_SHIFT);
723 regmap_write(regmap, reg, value);
725 EXPORT_SYMBOL_GPL(tegra30_ahub_set_cif);
727 void tegra124_ahub_set_cif(struct regmap *regmap, unsigned int reg,
728 struct tegra30_ahub_cif_conf *conf)
732 value = (conf->threshold <<
733 TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) |
734 ((conf->audio_channels - 1) <<
735 TEGRA124_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
736 ((conf->client_channels - 1) <<
737 TEGRA124_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) |
739 TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT) |
740 (conf->client_bits <<
741 TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT) |
743 TEGRA30_AUDIOCIF_CTRL_EXPAND_SHIFT) |
744 (conf->stereo_conv <<
745 TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT) |
747 TEGRA30_AUDIOCIF_CTRL_REPLICATE_SHIFT) |
749 TEGRA30_AUDIOCIF_CTRL_DIRECTION_SHIFT) |
751 TEGRA30_AUDIOCIF_CTRL_TRUNCATE_SHIFT) |
753 TEGRA30_AUDIOCIF_CTRL_MONO_CONV_SHIFT);
755 regmap_write(regmap, reg, value);
757 EXPORT_SYMBOL_GPL(tegra124_ahub_set_cif);
759 MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
760 MODULE_DESCRIPTION("Tegra30 AHUB driver");
761 MODULE_LICENSE("GPL v2");
762 MODULE_ALIAS("platform:" DRV_NAME);
763 MODULE_DEVICE_TABLE(of, tegra30_ahub_of_match);