x86/xen: resume timer irqs early
[linux/fpc-iii.git] / sound / soc / tegra / tegra30_ahub.c
blobd554d46d08b550788a1bd0ad706f8ed7948a318a
1 /*
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
13 * more details.
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>
21 #include <linux/io.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)
43 u32 val;
44 regmap_read(ahub->regmap_apbif, reg, &val);
45 return 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);
61 return 0;
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
68 * for now.
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)
77 int ret;
79 ret = clk_prepare_enable(ahub->clk_d_audio);
80 if (ret) {
81 dev_err(dev, "clk_enable d_audio failed: %d\n", ret);
82 return ret;
84 ret = clk_prepare_enable(ahub->clk_apbif);
85 if (ret) {
86 dev_err(dev, "clk_enable apbif failed: %d\n", ret);
87 clk_disable(ahub->clk_d_audio);
88 return ret;
91 regcache_cache_only(ahub->regmap_apbif, false);
92 regcache_cache_only(ahub->regmap_ahub, false);
94 return 0;
97 int tegra30_ahub_allocate_rx_fifo(enum tegra30_ahub_rxcif *rxcif,
98 dma_addr_t *fiforeg,
99 unsigned int *reqsel)
101 int channel;
102 u32 reg, val;
104 channel = find_first_zero_bit(ahub->rx_usage,
105 TEGRA30_AHUB_CHANNEL_CTRL_COUNT);
106 if (channel >= TEGRA30_AHUB_CHANNEL_CTRL_COUNT)
107 return -EBUSY;
109 __set_bit(channel, ahub->rx_usage);
111 *rxcif = TEGRA30_AHUB_RXCIF_APBIF_RX0 + channel;
112 *fiforeg = ahub->apbif_addr + TEGRA30_AHUB_CHANNEL_RXFIFO +
113 (channel * TEGRA30_AHUB_CHANNEL_RXFIFO_STRIDE);
114 *reqsel = ahub->dma_sel + channel;
116 reg = TEGRA30_AHUB_CHANNEL_CTRL +
117 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
118 val = tegra30_apbif_read(reg);
119 val &= ~(TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_MASK |
120 TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_MASK);
121 val |= (7 << TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_SHIFT) |
122 TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_EN |
123 TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_16;
124 tegra30_apbif_write(reg, val);
126 reg = TEGRA30_AHUB_CIF_RX_CTRL +
127 (channel * TEGRA30_AHUB_CIF_RX_CTRL_STRIDE);
128 val = (0 << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) |
129 (1 << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
130 (1 << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) |
131 TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 |
132 TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16 |
133 TEGRA30_AUDIOCIF_CTRL_DIRECTION_RX;
134 tegra30_apbif_write(reg, val);
136 return 0;
138 EXPORT_SYMBOL_GPL(tegra30_ahub_allocate_rx_fifo);
140 int tegra30_ahub_enable_rx_fifo(enum tegra30_ahub_rxcif rxcif)
142 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
143 int reg, val;
145 reg = TEGRA30_AHUB_CHANNEL_CTRL +
146 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
147 val = tegra30_apbif_read(reg);
148 val |= TEGRA30_AHUB_CHANNEL_CTRL_RX_EN;
149 tegra30_apbif_write(reg, val);
151 return 0;
153 EXPORT_SYMBOL_GPL(tegra30_ahub_enable_rx_fifo);
155 int tegra30_ahub_disable_rx_fifo(enum tegra30_ahub_rxcif rxcif)
157 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
158 int reg, val;
160 reg = TEGRA30_AHUB_CHANNEL_CTRL +
161 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
162 val = tegra30_apbif_read(reg);
163 val &= ~TEGRA30_AHUB_CHANNEL_CTRL_RX_EN;
164 tegra30_apbif_write(reg, val);
166 return 0;
168 EXPORT_SYMBOL_GPL(tegra30_ahub_disable_rx_fifo);
170 int tegra30_ahub_free_rx_fifo(enum tegra30_ahub_rxcif rxcif)
172 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
174 __clear_bit(channel, ahub->rx_usage);
176 return 0;
178 EXPORT_SYMBOL_GPL(tegra30_ahub_free_rx_fifo);
180 int tegra30_ahub_allocate_tx_fifo(enum tegra30_ahub_txcif *txcif,
181 dma_addr_t *fiforeg,
182 unsigned int *reqsel)
184 int channel;
185 u32 reg, val;
187 channel = find_first_zero_bit(ahub->tx_usage,
188 TEGRA30_AHUB_CHANNEL_CTRL_COUNT);
189 if (channel >= TEGRA30_AHUB_CHANNEL_CTRL_COUNT)
190 return -EBUSY;
192 __set_bit(channel, ahub->tx_usage);
194 *txcif = TEGRA30_AHUB_TXCIF_APBIF_TX0 + channel;
195 *fiforeg = ahub->apbif_addr + TEGRA30_AHUB_CHANNEL_TXFIFO +
196 (channel * TEGRA30_AHUB_CHANNEL_TXFIFO_STRIDE);
197 *reqsel = ahub->dma_sel + channel;
199 reg = TEGRA30_AHUB_CHANNEL_CTRL +
200 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
201 val = tegra30_apbif_read(reg);
202 val &= ~(TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_MASK |
203 TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_MASK);
204 val |= (7 << TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_SHIFT) |
205 TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_EN |
206 TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_16;
207 tegra30_apbif_write(reg, val);
209 reg = TEGRA30_AHUB_CIF_TX_CTRL +
210 (channel * TEGRA30_AHUB_CIF_TX_CTRL_STRIDE);
211 val = (0 << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) |
212 (1 << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
213 (1 << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) |
214 TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 |
215 TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16 |
216 TEGRA30_AUDIOCIF_CTRL_DIRECTION_TX;
217 tegra30_apbif_write(reg, val);
219 return 0;
221 EXPORT_SYMBOL_GPL(tegra30_ahub_allocate_tx_fifo);
223 int tegra30_ahub_enable_tx_fifo(enum tegra30_ahub_txcif txcif)
225 int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
226 int reg, val;
228 reg = TEGRA30_AHUB_CHANNEL_CTRL +
229 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
230 val = tegra30_apbif_read(reg);
231 val |= TEGRA30_AHUB_CHANNEL_CTRL_TX_EN;
232 tegra30_apbif_write(reg, val);
234 return 0;
236 EXPORT_SYMBOL_GPL(tegra30_ahub_enable_tx_fifo);
238 int tegra30_ahub_disable_tx_fifo(enum tegra30_ahub_txcif txcif)
240 int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
241 int reg, val;
243 reg = TEGRA30_AHUB_CHANNEL_CTRL +
244 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
245 val = tegra30_apbif_read(reg);
246 val &= ~TEGRA30_AHUB_CHANNEL_CTRL_TX_EN;
247 tegra30_apbif_write(reg, val);
249 return 0;
251 EXPORT_SYMBOL_GPL(tegra30_ahub_disable_tx_fifo);
253 int tegra30_ahub_free_tx_fifo(enum tegra30_ahub_txcif txcif)
255 int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
257 __clear_bit(channel, ahub->tx_usage);
259 return 0;
261 EXPORT_SYMBOL_GPL(tegra30_ahub_free_tx_fifo);
263 int tegra30_ahub_set_rx_cif_source(enum tegra30_ahub_rxcif rxcif,
264 enum tegra30_ahub_txcif txcif)
266 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
267 int reg;
269 reg = TEGRA30_AHUB_AUDIO_RX +
270 (channel * TEGRA30_AHUB_AUDIO_RX_STRIDE);
271 tegra30_audio_write(reg, 1 << txcif);
273 return 0;
275 EXPORT_SYMBOL_GPL(tegra30_ahub_set_rx_cif_source);
277 int tegra30_ahub_unset_rx_cif_source(enum tegra30_ahub_rxcif rxcif)
279 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
280 int reg;
282 reg = TEGRA30_AHUB_AUDIO_RX +
283 (channel * TEGRA30_AHUB_AUDIO_RX_STRIDE);
284 tegra30_audio_write(reg, 0);
286 return 0;
288 EXPORT_SYMBOL_GPL(tegra30_ahub_unset_rx_cif_source);
290 #define CLK_LIST_MASK_TEGRA30 BIT(0)
291 #define CLK_LIST_MASK_TEGRA114 BIT(1)
293 #define CLK_LIST_MASK_TEGRA30_OR_LATER \
294 (CLK_LIST_MASK_TEGRA30 | CLK_LIST_MASK_TEGRA114)
296 static const struct {
297 const char *clk_name;
298 u32 clk_list_mask;
299 } configlink_clocks[] = {
300 { "i2s0", CLK_LIST_MASK_TEGRA30_OR_LATER },
301 { "i2s1", CLK_LIST_MASK_TEGRA30_OR_LATER },
302 { "i2s2", CLK_LIST_MASK_TEGRA30_OR_LATER },
303 { "i2s3", CLK_LIST_MASK_TEGRA30_OR_LATER },
304 { "i2s4", CLK_LIST_MASK_TEGRA30_OR_LATER },
305 { "dam0", CLK_LIST_MASK_TEGRA30_OR_LATER },
306 { "dam1", CLK_LIST_MASK_TEGRA30_OR_LATER },
307 { "dam2", CLK_LIST_MASK_TEGRA30_OR_LATER },
308 { "spdif_in", CLK_LIST_MASK_TEGRA30_OR_LATER },
309 { "amx", CLK_LIST_MASK_TEGRA114 },
310 { "adx", CLK_LIST_MASK_TEGRA114 },
313 #define LAST_REG(name) \
314 (TEGRA30_AHUB_##name + \
315 (TEGRA30_AHUB_##name##_STRIDE * TEGRA30_AHUB_##name##_COUNT) - 4)
317 #define REG_IN_ARRAY(reg, name) \
318 ((reg >= TEGRA30_AHUB_##name) && \
319 (reg <= LAST_REG(name) && \
320 (!((reg - TEGRA30_AHUB_##name) % TEGRA30_AHUB_##name##_STRIDE))))
322 static bool tegra30_ahub_apbif_wr_rd_reg(struct device *dev, unsigned int reg)
324 switch (reg) {
325 case TEGRA30_AHUB_CONFIG_LINK_CTRL:
326 case TEGRA30_AHUB_MISC_CTRL:
327 case TEGRA30_AHUB_APBDMA_LIVE_STATUS:
328 case TEGRA30_AHUB_I2S_LIVE_STATUS:
329 case TEGRA30_AHUB_SPDIF_LIVE_STATUS:
330 case TEGRA30_AHUB_I2S_INT_MASK:
331 case TEGRA30_AHUB_DAM_INT_MASK:
332 case TEGRA30_AHUB_SPDIF_INT_MASK:
333 case TEGRA30_AHUB_APBIF_INT_MASK:
334 case TEGRA30_AHUB_I2S_INT_STATUS:
335 case TEGRA30_AHUB_DAM_INT_STATUS:
336 case TEGRA30_AHUB_SPDIF_INT_STATUS:
337 case TEGRA30_AHUB_APBIF_INT_STATUS:
338 case TEGRA30_AHUB_I2S_INT_SOURCE:
339 case TEGRA30_AHUB_DAM_INT_SOURCE:
340 case TEGRA30_AHUB_SPDIF_INT_SOURCE:
341 case TEGRA30_AHUB_APBIF_INT_SOURCE:
342 case TEGRA30_AHUB_I2S_INT_SET:
343 case TEGRA30_AHUB_DAM_INT_SET:
344 case TEGRA30_AHUB_SPDIF_INT_SET:
345 case TEGRA30_AHUB_APBIF_INT_SET:
346 return true;
347 default:
348 break;
351 if (REG_IN_ARRAY(reg, CHANNEL_CTRL) ||
352 REG_IN_ARRAY(reg, CHANNEL_CLEAR) ||
353 REG_IN_ARRAY(reg, CHANNEL_STATUS) ||
354 REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
355 REG_IN_ARRAY(reg, CHANNEL_RXFIFO) ||
356 REG_IN_ARRAY(reg, CIF_TX_CTRL) ||
357 REG_IN_ARRAY(reg, CIF_RX_CTRL) ||
358 REG_IN_ARRAY(reg, DAM_LIVE_STATUS))
359 return true;
361 return false;
364 static bool tegra30_ahub_apbif_volatile_reg(struct device *dev,
365 unsigned int reg)
367 switch (reg) {
368 case TEGRA30_AHUB_CONFIG_LINK_CTRL:
369 case TEGRA30_AHUB_MISC_CTRL:
370 case TEGRA30_AHUB_APBDMA_LIVE_STATUS:
371 case TEGRA30_AHUB_I2S_LIVE_STATUS:
372 case TEGRA30_AHUB_SPDIF_LIVE_STATUS:
373 case TEGRA30_AHUB_I2S_INT_STATUS:
374 case TEGRA30_AHUB_DAM_INT_STATUS:
375 case TEGRA30_AHUB_SPDIF_INT_STATUS:
376 case TEGRA30_AHUB_APBIF_INT_STATUS:
377 case TEGRA30_AHUB_I2S_INT_SET:
378 case TEGRA30_AHUB_DAM_INT_SET:
379 case TEGRA30_AHUB_SPDIF_INT_SET:
380 case TEGRA30_AHUB_APBIF_INT_SET:
381 return true;
382 default:
383 break;
386 if (REG_IN_ARRAY(reg, CHANNEL_CLEAR) ||
387 REG_IN_ARRAY(reg, CHANNEL_STATUS) ||
388 REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
389 REG_IN_ARRAY(reg, CHANNEL_RXFIFO) ||
390 REG_IN_ARRAY(reg, DAM_LIVE_STATUS))
391 return true;
393 return false;
396 static bool tegra30_ahub_apbif_precious_reg(struct device *dev,
397 unsigned int reg)
399 if (REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
400 REG_IN_ARRAY(reg, CHANNEL_RXFIFO))
401 return true;
403 return false;
406 static const struct regmap_config tegra30_ahub_apbif_regmap_config = {
407 .name = "apbif",
408 .reg_bits = 32,
409 .val_bits = 32,
410 .reg_stride = 4,
411 .max_register = TEGRA30_AHUB_APBIF_INT_SET,
412 .writeable_reg = tegra30_ahub_apbif_wr_rd_reg,
413 .readable_reg = tegra30_ahub_apbif_wr_rd_reg,
414 .volatile_reg = tegra30_ahub_apbif_volatile_reg,
415 .precious_reg = tegra30_ahub_apbif_precious_reg,
416 .cache_type = REGCACHE_RBTREE,
419 static bool tegra30_ahub_ahub_wr_rd_reg(struct device *dev, unsigned int reg)
421 if (REG_IN_ARRAY(reg, AUDIO_RX))
422 return true;
424 return false;
427 static const struct regmap_config tegra30_ahub_ahub_regmap_config = {
428 .name = "ahub",
429 .reg_bits = 32,
430 .val_bits = 32,
431 .reg_stride = 4,
432 .max_register = LAST_REG(AUDIO_RX),
433 .writeable_reg = tegra30_ahub_ahub_wr_rd_reg,
434 .readable_reg = tegra30_ahub_ahub_wr_rd_reg,
435 .cache_type = REGCACHE_RBTREE,
438 static struct tegra30_ahub_soc_data soc_data_tegra30 = {
439 .clk_list_mask = CLK_LIST_MASK_TEGRA30,
442 static struct tegra30_ahub_soc_data soc_data_tegra114 = {
443 .clk_list_mask = CLK_LIST_MASK_TEGRA114,
446 static const struct of_device_id tegra30_ahub_of_match[] = {
447 { .compatible = "nvidia,tegra114-ahub", .data = &soc_data_tegra114 },
448 { .compatible = "nvidia,tegra30-ahub", .data = &soc_data_tegra30 },
452 static int tegra30_ahub_probe(struct platform_device *pdev)
454 const struct of_device_id *match;
455 const struct tegra30_ahub_soc_data *soc_data;
456 struct clk *clk;
457 int i;
458 struct resource *res0, *res1, *region;
459 u32 of_dma[2];
460 void __iomem *regs_apbif, *regs_ahub;
461 int ret = 0;
463 if (ahub)
464 return -ENODEV;
466 match = of_match_device(tegra30_ahub_of_match, &pdev->dev);
467 if (!match)
468 return -EINVAL;
469 soc_data = match->data;
472 * The AHUB hosts a register bus: the "configlink". For this to
473 * operate correctly, all devices on this bus must be out of reset.
474 * Ensure that here.
476 for (i = 0; i < ARRAY_SIZE(configlink_clocks); i++) {
477 if (!(configlink_clocks[i].clk_list_mask &
478 soc_data->clk_list_mask))
479 continue;
480 clk = clk_get(&pdev->dev, configlink_clocks[i].clk_name);
481 if (IS_ERR(clk)) {
482 dev_err(&pdev->dev, "Can't get clock %s\n",
483 configlink_clocks[i].clk_name);
484 ret = PTR_ERR(clk);
485 goto err;
487 tegra_periph_reset_deassert(clk);
488 clk_put(clk);
491 ahub = devm_kzalloc(&pdev->dev, sizeof(struct tegra30_ahub),
492 GFP_KERNEL);
493 if (!ahub) {
494 dev_err(&pdev->dev, "Can't allocate tegra30_ahub\n");
495 ret = -ENOMEM;
496 goto err;
498 dev_set_drvdata(&pdev->dev, ahub);
500 ahub->dev = &pdev->dev;
502 ahub->clk_d_audio = clk_get(&pdev->dev, "d_audio");
503 if (IS_ERR(ahub->clk_d_audio)) {
504 dev_err(&pdev->dev, "Can't retrieve ahub d_audio clock\n");
505 ret = PTR_ERR(ahub->clk_d_audio);
506 goto err;
509 ahub->clk_apbif = clk_get(&pdev->dev, "apbif");
510 if (IS_ERR(ahub->clk_apbif)) {
511 dev_err(&pdev->dev, "Can't retrieve ahub apbif clock\n");
512 ret = PTR_ERR(ahub->clk_apbif);
513 goto err_clk_put_d_audio;
516 if (of_property_read_u32_array(pdev->dev.of_node,
517 "nvidia,dma-request-selector",
518 of_dma, 2) < 0) {
519 dev_err(&pdev->dev,
520 "Missing property nvidia,dma-request-selector\n");
521 ret = -ENODEV;
522 goto err_clk_put_d_audio;
524 ahub->dma_sel = of_dma[1];
526 res0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
527 if (!res0) {
528 dev_err(&pdev->dev, "No apbif memory resource\n");
529 ret = -ENODEV;
530 goto err_clk_put_apbif;
533 region = devm_request_mem_region(&pdev->dev, res0->start,
534 resource_size(res0), DRV_NAME);
535 if (!region) {
536 dev_err(&pdev->dev, "request region apbif failed\n");
537 ret = -EBUSY;
538 goto err_clk_put_apbif;
540 ahub->apbif_addr = res0->start;
542 regs_apbif = devm_ioremap(&pdev->dev, res0->start,
543 resource_size(res0));
544 if (!regs_apbif) {
545 dev_err(&pdev->dev, "ioremap apbif failed\n");
546 ret = -ENOMEM;
547 goto err_clk_put_apbif;
550 ahub->regmap_apbif = devm_regmap_init_mmio(&pdev->dev, regs_apbif,
551 &tegra30_ahub_apbif_regmap_config);
552 if (IS_ERR(ahub->regmap_apbif)) {
553 dev_err(&pdev->dev, "apbif regmap init failed\n");
554 ret = PTR_ERR(ahub->regmap_apbif);
555 goto err_clk_put_apbif;
557 regcache_cache_only(ahub->regmap_apbif, true);
559 res1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
560 if (!res1) {
561 dev_err(&pdev->dev, "No ahub memory resource\n");
562 ret = -ENODEV;
563 goto err_clk_put_apbif;
566 region = devm_request_mem_region(&pdev->dev, res1->start,
567 resource_size(res1), DRV_NAME);
568 if (!region) {
569 dev_err(&pdev->dev, "request region ahub failed\n");
570 ret = -EBUSY;
571 goto err_clk_put_apbif;
574 regs_ahub = devm_ioremap(&pdev->dev, res1->start,
575 resource_size(res1));
576 if (!regs_ahub) {
577 dev_err(&pdev->dev, "ioremap ahub failed\n");
578 ret = -ENOMEM;
579 goto err_clk_put_apbif;
582 ahub->regmap_ahub = devm_regmap_init_mmio(&pdev->dev, regs_ahub,
583 &tegra30_ahub_ahub_regmap_config);
584 if (IS_ERR(ahub->regmap_ahub)) {
585 dev_err(&pdev->dev, "ahub regmap init failed\n");
586 ret = PTR_ERR(ahub->regmap_ahub);
587 goto err_clk_put_apbif;
589 regcache_cache_only(ahub->regmap_ahub, true);
591 pm_runtime_enable(&pdev->dev);
592 if (!pm_runtime_enabled(&pdev->dev)) {
593 ret = tegra30_ahub_runtime_resume(&pdev->dev);
594 if (ret)
595 goto err_pm_disable;
598 of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
600 return 0;
602 err_pm_disable:
603 pm_runtime_disable(&pdev->dev);
604 err_clk_put_apbif:
605 clk_put(ahub->clk_apbif);
606 err_clk_put_d_audio:
607 clk_put(ahub->clk_d_audio);
608 ahub = NULL;
609 err:
610 return ret;
613 static int tegra30_ahub_remove(struct platform_device *pdev)
615 if (!ahub)
616 return -ENODEV;
618 pm_runtime_disable(&pdev->dev);
619 if (!pm_runtime_status_suspended(&pdev->dev))
620 tegra30_ahub_runtime_suspend(&pdev->dev);
622 clk_put(ahub->clk_apbif);
623 clk_put(ahub->clk_d_audio);
625 ahub = NULL;
627 return 0;
630 #ifdef CONFIG_PM_SLEEP
631 static int tegra30_ahub_suspend(struct device *dev)
633 regcache_mark_dirty(ahub->regmap_ahub);
634 regcache_mark_dirty(ahub->regmap_apbif);
636 return 0;
639 static int tegra30_ahub_resume(struct device *dev)
641 int ret;
643 ret = pm_runtime_get_sync(dev);
644 if (ret < 0)
645 return ret;
646 ret = regcache_sync(ahub->regmap_ahub);
647 ret |= regcache_sync(ahub->regmap_apbif);
648 pm_runtime_put(dev);
650 return ret;
652 #endif
654 static const struct dev_pm_ops tegra30_ahub_pm_ops = {
655 SET_RUNTIME_PM_OPS(tegra30_ahub_runtime_suspend,
656 tegra30_ahub_runtime_resume, NULL)
657 SET_SYSTEM_SLEEP_PM_OPS(tegra30_ahub_suspend, tegra30_ahub_resume)
660 static struct platform_driver tegra30_ahub_driver = {
661 .probe = tegra30_ahub_probe,
662 .remove = tegra30_ahub_remove,
663 .driver = {
664 .name = DRV_NAME,
665 .owner = THIS_MODULE,
666 .of_match_table = tegra30_ahub_of_match,
667 .pm = &tegra30_ahub_pm_ops,
670 module_platform_driver(tegra30_ahub_driver);
672 MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
673 MODULE_DESCRIPTION("Tegra30 AHUB driver");
674 MODULE_LICENSE("GPL v2");
675 MODULE_ALIAS("platform:" DRV_NAME);
676 MODULE_DEVICE_TABLE(of, tegra30_ahub_of_match);