2 * tegra30_ahub.c - Tegra30 AHUB driver
4 * Copyright (c) 2011-2014, 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);
98 * for TDM mode, ahub has to run faster than I2S controller. This will avoid
99 * FIFO overflow/underflow, the causes of slot-hopping symptoms
101 void tegra30_ahub_clock_set_rate(int rate)
103 clk_set_rate(ahub->clk_d_audio, rate);
105 EXPORT_SYMBOL_GPL(tegra30_ahub_clock_set_rate);
107 void tegra30_ahub_enable_clocks(void)
109 pm_runtime_get_sync(ahub->dev);
111 EXPORT_SYMBOL_GPL(tegra30_ahub_enable_clocks);
113 void tegra30_ahub_disable_clocks(void)
115 pm_runtime_put(ahub->dev);
117 EXPORT_SYMBOL_GPL(tegra30_ahub_disable_clocks);
119 static int tegra30_ahub_soft_reset_rx_channel(int channel)
123 reg = TEGRA30_AHUB_CHANNEL_CLEAR +
124 (channel * TEGRA30_AHUB_CIF_RX_CTRL_STRIDE);
125 val = TEGRA30_AHUB_CHANNEL_CLEAR_RX_SOFT_RESET;
126 tegra30_apbif_write(reg, val);
130 static int tegra30_ahub_soft_reset_tx_channel(int channel)
134 reg = TEGRA30_AHUB_CHANNEL_CLEAR +
135 (channel * TEGRA30_AHUB_CIF_TX_CTRL_STRIDE);
136 val = TEGRA30_AHUB_CHANNEL_CLEAR_TX_SOFT_RESET;
137 tegra30_apbif_write(reg, val);
141 int tegra30_ahub_allocate_rx_fifo(enum tegra30_ahub_rxcif *rxcif,
142 unsigned long *fiforeg,
143 unsigned long *reqsel)
148 channel = find_first_zero_bit(ahub->rx_usage,
149 TEGRA30_AHUB_CHANNEL_CTRL_COUNT);
150 if (channel >= TEGRA30_AHUB_CHANNEL_CTRL_COUNT)
153 __set_bit(channel, ahub->rx_usage);
155 *rxcif = TEGRA30_AHUB_RXCIF_APBIF_RX0 + channel;
156 *fiforeg = ahub->apbif_addr + TEGRA30_AHUB_CHANNEL_RXFIFO +
157 (channel * TEGRA30_AHUB_CHANNEL_RXFIFO_STRIDE);
158 *reqsel = ahub->dma_sel + channel;
160 tegra30_ahub_soft_reset_rx_channel(channel);
162 reg = TEGRA30_AHUB_CHANNEL_CTRL +
163 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
164 val = tegra30_apbif_read(reg);
165 val &= ~(TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_MASK |
166 TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_MASK);
167 val |= (7 << TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_SHIFT) |
168 TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_EN |
169 TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_16;
170 tegra30_apbif_write(reg, val);
172 reg = TEGRA30_AHUB_CIF_RX_CTRL +
173 (channel * TEGRA30_AHUB_CIF_RX_CTRL_STRIDE);
174 val = (0 << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) |
175 (1 << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
176 (1 << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) |
177 TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 |
178 TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16 |
179 TEGRA30_AUDIOCIF_CTRL_DIRECTION_RX;
180 tegra30_apbif_write(reg, val);
184 EXPORT_SYMBOL_GPL(tegra30_ahub_allocate_rx_fifo);
186 int tegra30_ahub_rx_fifo_is_enabled(int i2s_id)
190 val = tegra30_apbif_read(TEGRA30_AHUB_I2S_LIVE_STATUS);
191 mask = (TEGRA30_AHUB_I2S_LIVE_STATUS_I2S0_RX_FIFO_ENABLED << (i2s_id*2));
195 EXPORT_SYMBOL_GPL(tegra30_ahub_rx_fifo_is_enabled);
197 int tegra30_ahub_tx_fifo_is_enabled(int i2s_id)
201 val = tegra30_apbif_read(TEGRA30_AHUB_I2S_LIVE_STATUS);
202 mask = (TEGRA30_AHUB_I2S_LIVE_STATUS_I2S0_TX_FIFO_ENABLED << (i2s_id*2));
207 EXPORT_SYMBOL_GPL(tegra30_ahub_tx_fifo_is_enabled);
210 int tegra30_ahub_rx_fifo_is_empty(int i2s_id)
214 val = tegra30_apbif_read(TEGRA30_AHUB_I2S_LIVE_STATUS);
215 mask = (TEGRA30_AHUB_I2S_LIVE_STATUS_I2S0_RX_FIFO_EMPTY << (i2s_id*2));
219 EXPORT_SYMBOL(tegra30_ahub_rx_fifo_is_empty);
221 int tegra30_ahub_tx_fifo_is_empty(int i2s_id)
225 val = tegra30_apbif_read(TEGRA30_AHUB_I2S_LIVE_STATUS);
226 mask = (TEGRA30_AHUB_I2S_LIVE_STATUS_I2S0_TX_FIFO_EMPTY << (i2s_id*2));
231 EXPORT_SYMBOL(tegra30_ahub_tx_fifo_is_empty);
234 int tegra30_ahub_dam_ch0_is_enabled(int dam_id)
238 val = tegra30_apbif_read((TEGRA30_AHUB_DAM_LIVE_STATUS) +
239 (dam_id * TEGRA30_AHUB_DAM_LIVE_STATUS_STRIDE));
240 mask = TEGRA30_AHUB_DAM_LIVE_STATUS_RX0_ENABLED;
245 EXPORT_SYMBOL_GPL(tegra30_ahub_dam_ch0_is_enabled);
247 int tegra30_ahub_dam_ch1_is_enabled(int dam_id)
251 val = tegra30_apbif_read((TEGRA30_AHUB_DAM_LIVE_STATUS) +
252 (dam_id * TEGRA30_AHUB_DAM_LIVE_STATUS_STRIDE));
253 mask = TEGRA30_AHUB_DAM_LIVE_STATUS_RX1_ENABLED;
258 EXPORT_SYMBOL_GPL(tegra30_ahub_dam_ch1_is_enabled);
260 int tegra30_ahub_dam_tx_is_enabled(int dam_id)
264 val = tegra30_apbif_read((TEGRA30_AHUB_DAM_LIVE_STATUS) +
265 (dam_id * TEGRA30_AHUB_DAM_LIVE_STATUS_STRIDE));
266 mask = TEGRA30_AHUB_DAM_LIVE_STATUS_TX_ENABLED;
271 EXPORT_SYMBOL_GPL(tegra30_ahub_dam_tx_is_enabled);
274 int tegra30_ahub_dam_ch0_is_empty(int dam_id)
278 val = tegra30_apbif_read((TEGRA30_AHUB_DAM_LIVE_STATUS) +
279 (dam_id * TEGRA30_AHUB_DAM_LIVE_STATUS_STRIDE));
280 mask = TEGRA30_AHUB_DAM_LIVE_STATUS_RX0FIFO_EMPTY;
285 EXPORT_SYMBOL(tegra30_ahub_dam_ch0_is_empty);
287 int tegra30_ahub_dam_ch1_is_empty(int dam_id)
291 val = tegra30_apbif_read((TEGRA30_AHUB_DAM_LIVE_STATUS) +
292 (dam_id * TEGRA30_AHUB_DAM_LIVE_STATUS_STRIDE));
293 mask = TEGRA30_AHUB_DAM_LIVE_STATUS_RX1FIFO_EMPTY;
298 EXPORT_SYMBOL(tegra30_ahub_dam_ch1_is_empty);
300 int tegra30_ahub_dam_tx_is_empty(int dam_id)
304 val = tegra30_apbif_read((TEGRA30_AHUB_DAM_LIVE_STATUS) +
305 (dam_id * TEGRA30_AHUB_DAM_LIVE_STATUS_STRIDE));
306 mask = TEGRA30_AHUB_DAM_LIVE_STATUS_TXFIFO_EMPTY;
311 EXPORT_SYMBOL(tegra30_ahub_dam_tx_is_empty);
314 int tegra30_ahub_set_rx_fifo_pack_mode(enum tegra30_ahub_rxcif rxcif,
315 unsigned int pack_mode)
317 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
320 reg = TEGRA30_AHUB_CHANNEL_CTRL +
321 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
322 val = tegra30_apbif_read(reg);
324 val &= ~TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_MASK;
325 val &= ~TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_EN;
327 if ((pack_mode == TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_16) ||
328 (pack_mode == TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_8_4))
329 val |= (TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_EN |
331 tegra30_apbif_write(reg, val);
335 EXPORT_SYMBOL_GPL(tegra30_ahub_set_rx_fifo_pack_mode);
337 int tegra30_ahub_set_tx_fifo_pack_mode(enum tegra30_ahub_txcif txcif,
338 unsigned int pack_mode)
340 int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
343 reg = TEGRA30_AHUB_CHANNEL_CTRL +
344 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
345 val = tegra30_apbif_read(reg);
347 val &= ~TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_MASK;
348 val &= ~TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_EN;
350 if ((pack_mode == TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_16) ||
351 (pack_mode == TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_8_4))
352 val |= (TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_EN |
354 tegra30_apbif_write(reg, val);
358 EXPORT_SYMBOL_GPL(tegra30_ahub_set_tx_fifo_pack_mode);
360 int tegra30_ahub_enable_rx_fifo(enum tegra30_ahub_rxcif rxcif)
362 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
365 reg = TEGRA30_AHUB_CHANNEL_CTRL +
366 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
367 val = tegra30_apbif_read(reg);
368 val |= TEGRA30_AHUB_CHANNEL_CTRL_RX_EN;
369 tegra30_apbif_write(reg, val);
373 EXPORT_SYMBOL_GPL(tegra30_ahub_enable_rx_fifo);
375 int tegra30_ahub_disable_rx_fifo(enum tegra30_ahub_rxcif rxcif)
377 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
380 reg = TEGRA30_AHUB_CHANNEL_CTRL +
381 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
382 val = tegra30_apbif_read(reg);
383 val &= ~TEGRA30_AHUB_CHANNEL_CTRL_RX_EN;
384 tegra30_apbif_write(reg, val);
388 EXPORT_SYMBOL_GPL(tegra30_ahub_disable_rx_fifo);
390 int tegra30_ahub_free_rx_fifo(enum tegra30_ahub_rxcif rxcif)
392 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
394 __clear_bit(channel, ahub->rx_usage);
398 EXPORT_SYMBOL_GPL(tegra30_ahub_free_rx_fifo);
400 int tegra30_ahub_allocate_tx_fifo(enum tegra30_ahub_txcif *txcif,
401 unsigned long *fiforeg,
402 unsigned long *reqsel)
407 channel = find_first_zero_bit(ahub->tx_usage,
408 TEGRA30_AHUB_CHANNEL_CTRL_COUNT);
409 if (channel >= TEGRA30_AHUB_CHANNEL_CTRL_COUNT)
412 __set_bit(channel, ahub->tx_usage);
414 *txcif = TEGRA30_AHUB_TXCIF_APBIF_TX0 + channel;
415 *fiforeg = ahub->apbif_addr + TEGRA30_AHUB_CHANNEL_TXFIFO +
416 (channel * TEGRA30_AHUB_CHANNEL_TXFIFO_STRIDE);
417 *reqsel = ahub->dma_sel + channel;
419 tegra30_ahub_soft_reset_tx_channel(channel);
421 reg = TEGRA30_AHUB_CHANNEL_CTRL +
422 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
423 val = tegra30_apbif_read(reg);
424 val &= ~(TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_MASK |
425 TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_MASK);
426 val |= (7 << TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_SHIFT) |
427 TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_EN |
428 TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_16;
429 tegra30_apbif_write(reg, val);
431 reg = TEGRA30_AHUB_CIF_TX_CTRL +
432 (channel * TEGRA30_AHUB_CIF_TX_CTRL_STRIDE);
433 val = (0 << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) |
434 (1 << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
435 (1 << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) |
436 TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 |
437 TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16 |
438 TEGRA30_AUDIOCIF_CTRL_DIRECTION_TX;
439 tegra30_apbif_write(reg, val);
443 EXPORT_SYMBOL_GPL(tegra30_ahub_allocate_tx_fifo);
445 int tegra30_ahub_enable_tx_fifo(enum tegra30_ahub_txcif txcif)
447 int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
450 reg = TEGRA30_AHUB_CHANNEL_CTRL +
451 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
452 val = tegra30_apbif_read(reg);
453 val |= TEGRA30_AHUB_CHANNEL_CTRL_TX_EN;
454 tegra30_apbif_write(reg, val);
458 EXPORT_SYMBOL_GPL(tegra30_ahub_enable_tx_fifo);
460 int tegra30_ahub_disable_tx_fifo(enum tegra30_ahub_txcif txcif)
462 int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
465 reg = TEGRA30_AHUB_CHANNEL_CTRL +
466 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
467 val = tegra30_apbif_read(reg);
468 val &= ~TEGRA30_AHUB_CHANNEL_CTRL_TX_EN;
469 tegra30_apbif_write(reg, val);
473 EXPORT_SYMBOL_GPL(tegra30_ahub_disable_tx_fifo);
475 int tegra30_ahub_free_tx_fifo(enum tegra30_ahub_txcif txcif)
477 int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
479 __clear_bit(channel, ahub->tx_usage);
483 EXPORT_SYMBOL_GPL(tegra30_ahub_free_tx_fifo);
485 int tegra30_ahub_set_rx_cif_source(enum tegra30_ahub_rxcif rxcif,
486 enum tegra30_ahub_txcif txcif)
488 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
491 reg = TEGRA30_AHUB_AUDIO_RX +
492 (channel * TEGRA30_AHUB_AUDIO_RX_STRIDE);
493 tegra30_audio_write(reg, 1 << txcif);
497 EXPORT_SYMBOL_GPL(tegra30_ahub_set_rx_cif_source);
499 int tegra30_ahub_unset_rx_cif_source(enum tegra30_ahub_rxcif rxcif)
501 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
504 reg = TEGRA30_AHUB_AUDIO_RX +
505 (channel * TEGRA30_AHUB_AUDIO_RX_STRIDE);
506 tegra30_audio_write(reg, 0);
510 EXPORT_SYMBOL_GPL(tegra30_ahub_unset_rx_cif_source);
512 int tegra30_ahub_set_rx_cif_channels(enum tegra30_ahub_rxcif rxcif,
513 unsigned int audio_ch,
514 unsigned int client_ch)
516 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
517 unsigned int reg, val;
519 reg = TEGRA30_AHUB_CIF_RX_CTRL +
520 (channel * TEGRA30_AHUB_CIF_RX_CTRL_STRIDE);
521 val = tegra30_apbif_read(reg);
522 val &= ~(TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK |
523 TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK);
524 val |= ((audio_ch - 1) << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
525 ((client_ch - 1) << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT);
526 tegra30_apbif_write(reg, val);
530 EXPORT_SYMBOL_GPL(tegra30_ahub_set_rx_cif_channels);
532 int tegra30_ahub_set_rx_cif_stereo_conv(enum tegra30_ahub_rxcif rxcif)
534 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
535 unsigned int reg, val;
537 tegra30_ahub_enable_clocks();
539 reg = TEGRA30_AHUB_CIF_RX_CTRL +
540 (channel * TEGRA30_AHUB_CIF_RX_CTRL_STRIDE);
541 val = tegra30_apbif_read(reg);
542 val &= ~TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_MASK;
543 val |= TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_AVG;
544 tegra30_apbif_write(reg, val);
546 tegra30_ahub_disable_clocks();
551 int tegra30_ahub_set_tx_cif_channels(enum tegra30_ahub_txcif txcif,
552 unsigned int audio_ch,
553 unsigned int client_ch)
555 int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
556 unsigned int reg, val;
558 reg = TEGRA30_AHUB_CIF_TX_CTRL +
559 (channel * TEGRA30_AHUB_CIF_TX_CTRL_STRIDE);
560 val = tegra30_apbif_read(reg);
561 val &= ~(TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK |
562 TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK);
563 val |= ((audio_ch - 1) << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
564 ((client_ch - 1) << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT);
566 tegra30_apbif_write(reg, val);
570 EXPORT_SYMBOL_GPL(tegra30_ahub_set_tx_cif_channels);
572 int tegra30_ahub_set_rx_cif_bits(enum tegra30_ahub_rxcif rxcif,
573 unsigned int audio_bits,
574 unsigned int client_bits)
576 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
577 unsigned int reg, val;
579 reg = TEGRA30_AHUB_CIF_RX_CTRL +
580 (channel * TEGRA30_AHUB_CIF_RX_CTRL_STRIDE);
581 val = tegra30_apbif_read(reg);
582 val &= ~(TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_MASK |
583 TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_MASK);
584 val |= ((audio_bits) << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT) |
585 ((client_bits) << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT);
586 tegra30_apbif_write(reg, val);
590 EXPORT_SYMBOL_GPL(tegra30_ahub_set_rx_cif_bits);
592 int tegra30_ahub_set_tx_cif_bits(enum tegra30_ahub_txcif txcif,
593 unsigned int audio_bits,
594 unsigned int client_bits)
596 int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
597 unsigned int reg, val;
599 reg = TEGRA30_AHUB_CIF_TX_CTRL +
600 (channel * TEGRA30_AHUB_CIF_TX_CTRL_STRIDE);
601 val = tegra30_apbif_read(reg);
602 val &= ~(TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_MASK |
603 TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_MASK);
604 val |= ((audio_bits) << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT) |
605 ((client_bits) << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT);
607 tegra30_apbif_write(reg, val);
611 EXPORT_SYMBOL_GPL(tegra30_ahub_set_tx_cif_bits);
613 static const char * const configlink_clocks[] = {
623 #ifndef CONFIG_ARCH_TEGRA_14x_SOC
626 #if defined(CONFIG_ARCH_TEGRA_11x_SOC) || defined(CONFIG_ARCH_TEGRA_12x_SOC)
630 #ifdef CONFIG_ARCH_TEGRA_12x_SOC
642 struct of_dev_auxdata ahub_auxdata[] = {
643 OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080300, "tegra30-i2s.0", NULL),
644 OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080400, "tegra30-i2s.1", NULL),
645 OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080500, "tegra30-i2s.2", NULL),
646 OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080600, "tegra30-i2s.3", NULL),
647 OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080700, "tegra30-i2s.4", NULL),
648 OF_DEV_AUXDATA("nvidia,tegra30-dam", 0x70080800, "tegra30-dam.0", NULL),
649 OF_DEV_AUXDATA("nvidia,tegra30-dam", 0x70080900, "tegra30-dam.1", NULL),
650 OF_DEV_AUXDATA("nvidia,tegra30-dam", 0x70080A00, "tegra30-dam.2", NULL),
651 OF_DEV_AUXDATA("nvidia,tegra30-spdif", 0x70080B00, "tegra30-spdif",
656 #define LAST_REG(name) \
657 (TEGRA30_AHUB_##name + \
658 (TEGRA30_AHUB_##name##_STRIDE * TEGRA30_AHUB_##name##_COUNT) - 4)
660 #define REG_IN_ARRAY(reg, name) \
661 ((reg >= TEGRA30_AHUB_##name) && \
662 (reg <= LAST_REG(name) && \
663 (!((reg - TEGRA30_AHUB_##name) % TEGRA30_AHUB_##name##_STRIDE))))
665 static bool tegra30_ahub_apbif_wr_rd_reg(struct device *dev, unsigned int reg)
668 case TEGRA30_AHUB_CONFIG_LINK_CTRL:
669 case TEGRA30_AHUB_MISC_CTRL:
670 case TEGRA30_AHUB_APBDMA_LIVE_STATUS:
671 case TEGRA30_AHUB_I2S_LIVE_STATUS:
672 case TEGRA30_AHUB_SPDIF_LIVE_STATUS:
673 case TEGRA30_AHUB_I2S_INT_MASK:
674 case TEGRA30_AHUB_DAM_INT_MASK:
675 case TEGRA30_AHUB_SPDIF_INT_MASK:
676 case TEGRA30_AHUB_APBIF_INT_MASK:
677 case TEGRA30_AHUB_I2S_INT_STATUS:
678 case TEGRA30_AHUB_DAM_INT_STATUS:
679 case TEGRA30_AHUB_SPDIF_INT_STATUS:
680 case TEGRA30_AHUB_APBIF_INT_STATUS:
681 case TEGRA30_AHUB_I2S_INT_SOURCE:
682 case TEGRA30_AHUB_DAM_INT_SOURCE:
683 case TEGRA30_AHUB_SPDIF_INT_SOURCE:
684 case TEGRA30_AHUB_APBIF_INT_SOURCE:
685 case TEGRA30_AHUB_I2S_INT_SET:
686 case TEGRA30_AHUB_DAM_INT_SET:
687 case TEGRA30_AHUB_SPDIF_INT_SET:
688 case TEGRA30_AHUB_APBIF_INT_SET:
694 if (REG_IN_ARRAY(reg, CHANNEL_CTRL) ||
695 REG_IN_ARRAY(reg, CHANNEL_CLEAR) ||
696 REG_IN_ARRAY(reg, CHANNEL_STATUS) ||
697 REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
698 REG_IN_ARRAY(reg, CHANNEL_RXFIFO) ||
699 REG_IN_ARRAY(reg, CIF_TX_CTRL) ||
700 REG_IN_ARRAY(reg, CIF_RX_CTRL) ||
701 REG_IN_ARRAY(reg, DAM_LIVE_STATUS))
707 static bool tegra30_ahub_apbif_volatile_reg(struct device *dev,
711 case TEGRA30_AHUB_CONFIG_LINK_CTRL:
712 case TEGRA30_AHUB_MISC_CTRL:
713 case TEGRA30_AHUB_APBDMA_LIVE_STATUS:
714 case TEGRA30_AHUB_I2S_LIVE_STATUS:
715 case TEGRA30_AHUB_SPDIF_LIVE_STATUS:
716 case TEGRA30_AHUB_I2S_INT_STATUS:
717 case TEGRA30_AHUB_DAM_INT_STATUS:
718 case TEGRA30_AHUB_SPDIF_INT_STATUS:
719 case TEGRA30_AHUB_APBIF_INT_STATUS:
720 case TEGRA30_AHUB_I2S_INT_SET:
721 case TEGRA30_AHUB_DAM_INT_SET:
722 case TEGRA30_AHUB_SPDIF_INT_SET:
723 case TEGRA30_AHUB_APBIF_INT_SET:
729 if (REG_IN_ARRAY(reg, CHANNEL_CLEAR) ||
730 REG_IN_ARRAY(reg, CHANNEL_STATUS) ||
731 REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
732 REG_IN_ARRAY(reg, CHANNEL_RXFIFO) ||
733 REG_IN_ARRAY(reg, DAM_LIVE_STATUS))
739 static bool tegra30_ahub_apbif_precious_reg(struct device *dev,
742 if (REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
743 REG_IN_ARRAY(reg, CHANNEL_RXFIFO))
749 static const struct regmap_config tegra30_ahub_apbif_regmap_config = {
754 .max_register = TEGRA30_AHUB_APBIF_INT_SET,
755 .writeable_reg = tegra30_ahub_apbif_wr_rd_reg,
756 .readable_reg = tegra30_ahub_apbif_wr_rd_reg,
757 .volatile_reg = tegra30_ahub_apbif_volatile_reg,
758 .precious_reg = tegra30_ahub_apbif_precious_reg,
759 .cache_type = REGCACHE_RBTREE,
762 static bool tegra30_ahub_ahub_wr_rd_reg(struct device *dev, unsigned int reg)
764 if (REG_IN_ARRAY(reg, AUDIO_RX))
770 static const struct regmap_config tegra30_ahub_ahub_regmap_config = {
775 .max_register = LAST_REG(AUDIO_RX),
776 .writeable_reg = tegra30_ahub_ahub_wr_rd_reg,
777 .readable_reg = tegra30_ahub_ahub_wr_rd_reg,
778 .cache_type = REGCACHE_RBTREE,
781 static int tegra30_ahub_probe(struct platform_device *pdev)
785 struct resource *res0, *res1, *region;
787 void __iomem *regs_apbif, *regs_ahub;
794 * The AHUB hosts a register bus: the "configlink". For this to
795 * operate correctly, all devices on this bus must be out of reset.
798 for (i = 0; i < ARRAY_SIZE(configlink_clocks); i++) {
799 clk = clk_get_sys(NULL, configlink_clocks[i]);
801 dev_err(&pdev->dev, "Can't get clock %s\n",
802 configlink_clocks[i]);
806 tegra_periph_reset_deassert(clk);
810 ahub = devm_kzalloc(&pdev->dev, sizeof(struct tegra30_ahub),
813 dev_err(&pdev->dev, "Can't allocate tegra30_ahub\n");
817 dev_set_drvdata(&pdev->dev, ahub);
819 ahub->dev = &pdev->dev;
821 ahub->clk_d_audio = clk_get(&pdev->dev, "d_audio");
822 if (IS_ERR(ahub->clk_d_audio)) {
823 dev_err(&pdev->dev, "Can't retrieve ahub d_audio clock\n");
824 ret = PTR_ERR(ahub->clk_d_audio);
828 ahub->clk_apbif = clk_get(&pdev->dev, "apbif");
829 if (IS_ERR(ahub->clk_apbif)) {
830 dev_err(&pdev->dev, "Can't retrieve ahub apbif clock\n");
831 ret = PTR_ERR(ahub->clk_apbif);
832 goto err_clk_put_d_audio;
835 if (!(pdev->dev.of_node))
838 if (of_property_read_u32_array(pdev->dev.of_node,
839 "nvidia,dma-request-selector",
842 "Missing property nvidia,dma-request-selector\n");
844 goto err_clk_put_d_audio;
846 ahub->dma_sel = of_dma[1];
849 res0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
851 dev_err(&pdev->dev, "No apbif memory resource\n");
853 goto err_clk_put_apbif;
856 region = devm_request_mem_region(&pdev->dev, res0->start,
857 resource_size(res0), DRV_NAME);
859 dev_err(&pdev->dev, "request region apbif failed\n");
861 goto err_clk_put_apbif;
863 ahub->apbif_addr = res0->start;
865 regs_apbif = devm_ioremap(&pdev->dev, res0->start,
866 resource_size(res0));
868 dev_err(&pdev->dev, "ioremap apbif failed\n");
870 goto err_clk_put_apbif;
873 ahub->regmap_apbif = devm_regmap_init_mmio(&pdev->dev, regs_apbif,
874 &tegra30_ahub_apbif_regmap_config);
875 if (IS_ERR(ahub->regmap_apbif)) {
876 dev_err(&pdev->dev, "apbif regmap init failed\n");
877 ret = PTR_ERR(ahub->regmap_apbif);
878 goto err_clk_put_apbif;
880 regcache_cache_only(ahub->regmap_apbif, true);
882 res1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
884 dev_err(&pdev->dev, "No ahub memory resource\n");
886 goto err_clk_put_apbif;
889 region = devm_request_mem_region(&pdev->dev, res1->start,
890 resource_size(res1), DRV_NAME);
892 dev_err(&pdev->dev, "request region ahub failed\n");
894 goto err_clk_put_apbif;
897 regs_ahub = devm_ioremap(&pdev->dev, res1->start,
898 resource_size(res1));
900 dev_err(&pdev->dev, "ioremap ahub failed\n");
902 goto err_clk_put_apbif;
905 ahub->regmap_ahub = devm_regmap_init_mmio(&pdev->dev, regs_ahub,
906 &tegra30_ahub_ahub_regmap_config);
907 if (IS_ERR(ahub->regmap_ahub)) {
908 dev_err(&pdev->dev, "ahub regmap init failed\n");
909 ret = PTR_ERR(ahub->regmap_ahub);
910 goto err_clk_put_apbif;
912 regcache_cache_only(ahub->regmap_ahub, true);
914 pm_runtime_enable(&pdev->dev);
915 if (!pm_runtime_enabled(&pdev->dev)) {
916 ret = tegra30_ahub_runtime_resume(&pdev->dev);
921 if (pdev->dev.of_node)
922 of_platform_populate(pdev->dev.of_node, NULL, ahub_auxdata,
928 pm_runtime_disable(&pdev->dev);
930 clk_put(ahub->clk_apbif);
932 clk_put(ahub->clk_d_audio);
938 static int tegra30_ahub_remove(struct platform_device *pdev)
943 pm_runtime_disable(&pdev->dev);
944 if (!pm_runtime_status_suspended(&pdev->dev))
945 tegra30_ahub_runtime_suspend(&pdev->dev);
947 clk_put(ahub->clk_apbif);
948 clk_put(ahub->clk_d_audio);
955 static const struct of_device_id tegra30_ahub_of_match[] = {
956 { .compatible = "nvidia,tegra30-ahub", },
960 static const struct dev_pm_ops tegra30_ahub_pm_ops = {
961 SET_RUNTIME_PM_OPS(tegra30_ahub_runtime_suspend,
962 tegra30_ahub_runtime_resume, NULL)
965 static struct platform_driver tegra30_ahub_driver = {
966 .probe = tegra30_ahub_probe,
967 .remove = tegra30_ahub_remove,
970 .owner = THIS_MODULE,
971 .of_match_table = tegra30_ahub_of_match,
972 .pm = &tegra30_ahub_pm_ops,
975 module_platform_driver(tegra30_ahub_driver);
977 MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
978 MODULE_DESCRIPTION("Tegra30 AHUB driver");
979 MODULE_LICENSE("GPL v2");
980 MODULE_ALIAS("platform:" DRV_NAME);
981 MODULE_DEVICE_TABLE(of, tegra30_ahub_of_match);