.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * |
---|
3 | 4 | * Implementation of primary ALSA driver code base for NVIDIA Tegra HDA. |
---|
4 | | - * |
---|
5 | | - * This program is free software; you can redistribute it and/or modify it |
---|
6 | | - * under the terms and conditions of the GNU General Public License, |
---|
7 | | - * version 2, as published by the Free Software Foundation. |
---|
8 | | - * |
---|
9 | | - * This program is distributed in the hope it will be useful, but WITHOUT |
---|
10 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
11 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
---|
12 | | - * more details. |
---|
13 | | - * |
---|
14 | | - * You should have received a copy of the GNU General Public License |
---|
15 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | | - * |
---|
17 | 5 | */ |
---|
18 | 6 | |
---|
19 | 7 | #include <linux/clk.h> |
---|
.. | .. |
---|
29 | 17 | #include <linux/moduleparam.h> |
---|
30 | 18 | #include <linux/mutex.h> |
---|
31 | 19 | #include <linux/of_device.h> |
---|
| 20 | +#include <linux/reset.h> |
---|
32 | 21 | #include <linux/slab.h> |
---|
33 | 22 | #include <linux/time.h> |
---|
| 23 | +#include <linux/string.h> |
---|
| 24 | +#include <linux/pm_runtime.h> |
---|
34 | 25 | |
---|
35 | 26 | #include <sound/core.h> |
---|
36 | 27 | #include <sound/initval.h> |
---|
37 | 28 | |
---|
38 | | -#include "hda_codec.h" |
---|
| 29 | +#include <sound/hda_codec.h> |
---|
39 | 30 | #include "hda_controller.h" |
---|
40 | 31 | |
---|
41 | 32 | /* Defines for Nvidia Tegra HDA support */ |
---|
.. | .. |
---|
62 | 53 | #define HDA_IPFS_INTR_MASK 0x188 |
---|
63 | 54 | #define HDA_IPFS_EN_INTR (1 << 16) |
---|
64 | 55 | |
---|
| 56 | +/* FPCI */ |
---|
| 57 | +#define FPCI_DBG_CFG_2 0x10F4 |
---|
| 58 | +#define FPCI_GCAP_NSDO_SHIFT 18 |
---|
| 59 | +#define FPCI_GCAP_NSDO_MASK (0x3 << FPCI_GCAP_NSDO_SHIFT) |
---|
| 60 | + |
---|
65 | 61 | /* max number of SDs */ |
---|
66 | 62 | #define NUM_CAPTURE_SD 1 |
---|
67 | 63 | #define NUM_PLAYBACK_SD 1 |
---|
68 | 64 | |
---|
| 65 | +/* |
---|
| 66 | + * Tegra194 does not reflect correct number of SDO lines. Below macro |
---|
| 67 | + * is used to update the GCAP register to workaround the issue. |
---|
| 68 | + */ |
---|
| 69 | +#define TEGRA194_NUM_SDO_LINES 4 |
---|
| 70 | + |
---|
69 | 71 | struct hda_tegra { |
---|
70 | 72 | struct azx chip; |
---|
71 | 73 | struct device *dev; |
---|
72 | | - struct clk *hda_clk; |
---|
73 | | - struct clk *hda2codec_2x_clk; |
---|
74 | | - struct clk *hda2hdmi_clk; |
---|
| 74 | + struct reset_control *reset; |
---|
| 75 | + struct clk_bulk_data clocks[3]; |
---|
| 76 | + unsigned int nclocks; |
---|
75 | 77 | void __iomem *regs; |
---|
76 | 78 | struct work_struct probe_work; |
---|
77 | 79 | }; |
---|
.. | .. |
---|
85 | 87 | #define power_save 0 |
---|
86 | 88 | #endif |
---|
87 | 89 | |
---|
88 | | -/* |
---|
89 | | - * DMA page allocation ops. |
---|
90 | | - */ |
---|
91 | | -static int dma_alloc_pages(struct hdac_bus *bus, int type, size_t size, |
---|
92 | | - struct snd_dma_buffer *buf) |
---|
93 | | -{ |
---|
94 | | - return snd_dma_alloc_pages(type, bus->dev, size, buf); |
---|
95 | | -} |
---|
96 | | - |
---|
97 | | -static void dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf) |
---|
98 | | -{ |
---|
99 | | - snd_dma_free_pages(buf); |
---|
100 | | -} |
---|
101 | | - |
---|
102 | | -static int substream_alloc_pages(struct azx *chip, |
---|
103 | | - struct snd_pcm_substream *substream, |
---|
104 | | - size_t size) |
---|
105 | | -{ |
---|
106 | | - return snd_pcm_lib_malloc_pages(substream, size); |
---|
107 | | -} |
---|
108 | | - |
---|
109 | | -static int substream_free_pages(struct azx *chip, |
---|
110 | | - struct snd_pcm_substream *substream) |
---|
111 | | -{ |
---|
112 | | - return snd_pcm_lib_free_pages(substream); |
---|
113 | | -} |
---|
114 | | - |
---|
115 | | -/* |
---|
116 | | - * Register access ops. Tegra HDA register access is DWORD only. |
---|
117 | | - */ |
---|
118 | | -static void hda_tegra_writel(u32 value, u32 __iomem *addr) |
---|
119 | | -{ |
---|
120 | | - writel(value, addr); |
---|
121 | | -} |
---|
122 | | - |
---|
123 | | -static u32 hda_tegra_readl(u32 __iomem *addr) |
---|
124 | | -{ |
---|
125 | | - return readl(addr); |
---|
126 | | -} |
---|
127 | | - |
---|
128 | | -static void hda_tegra_writew(u16 value, u16 __iomem *addr) |
---|
129 | | -{ |
---|
130 | | - unsigned int shift = ((unsigned long)(addr) & 0x3) << 3; |
---|
131 | | - void __iomem *dword_addr = (void __iomem *)((unsigned long)(addr) & ~0x3); |
---|
132 | | - u32 v; |
---|
133 | | - |
---|
134 | | - v = readl(dword_addr); |
---|
135 | | - v &= ~(0xffff << shift); |
---|
136 | | - v |= value << shift; |
---|
137 | | - writel(v, dword_addr); |
---|
138 | | -} |
---|
139 | | - |
---|
140 | | -static u16 hda_tegra_readw(u16 __iomem *addr) |
---|
141 | | -{ |
---|
142 | | - unsigned int shift = ((unsigned long)(addr) & 0x3) << 3; |
---|
143 | | - void __iomem *dword_addr = (void __iomem *)((unsigned long)(addr) & ~0x3); |
---|
144 | | - u32 v; |
---|
145 | | - |
---|
146 | | - v = readl(dword_addr); |
---|
147 | | - return (v >> shift) & 0xffff; |
---|
148 | | -} |
---|
149 | | - |
---|
150 | | -static void hda_tegra_writeb(u8 value, u8 __iomem *addr) |
---|
151 | | -{ |
---|
152 | | - unsigned int shift = ((unsigned long)(addr) & 0x3) << 3; |
---|
153 | | - void __iomem *dword_addr = (void __iomem *)((unsigned long)(addr) & ~0x3); |
---|
154 | | - u32 v; |
---|
155 | | - |
---|
156 | | - v = readl(dword_addr); |
---|
157 | | - v &= ~(0xff << shift); |
---|
158 | | - v |= value << shift; |
---|
159 | | - writel(v, dword_addr); |
---|
160 | | -} |
---|
161 | | - |
---|
162 | | -static u8 hda_tegra_readb(u8 __iomem *addr) |
---|
163 | | -{ |
---|
164 | | - unsigned int shift = ((unsigned long)(addr) & 0x3) << 3; |
---|
165 | | - void __iomem *dword_addr = (void __iomem *)((unsigned long)(addr) & ~0x3); |
---|
166 | | - u32 v; |
---|
167 | | - |
---|
168 | | - v = readl(dword_addr); |
---|
169 | | - return (v >> shift) & 0xff; |
---|
170 | | -} |
---|
171 | | - |
---|
172 | | -static const struct hdac_io_ops hda_tegra_io_ops = { |
---|
173 | | - .reg_writel = hda_tegra_writel, |
---|
174 | | - .reg_readl = hda_tegra_readl, |
---|
175 | | - .reg_writew = hda_tegra_writew, |
---|
176 | | - .reg_readw = hda_tegra_readw, |
---|
177 | | - .reg_writeb = hda_tegra_writeb, |
---|
178 | | - .reg_readb = hda_tegra_readb, |
---|
179 | | - .dma_alloc_pages = dma_alloc_pages, |
---|
180 | | - .dma_free_pages = dma_free_pages, |
---|
181 | | -}; |
---|
182 | | - |
---|
183 | | -static const struct hda_controller_ops hda_tegra_ops = { |
---|
184 | | - .substream_alloc_pages = substream_alloc_pages, |
---|
185 | | - .substream_free_pages = substream_free_pages, |
---|
186 | | -}; |
---|
| 90 | +static const struct hda_controller_ops hda_tegra_ops; /* nothing special */ |
---|
187 | 91 | |
---|
188 | 92 | static void hda_tegra_init(struct hda_tegra *hda) |
---|
189 | 93 | { |
---|
.. | .. |
---|
210 | 114 | writel(v, hda->regs + HDA_IPFS_INTR_MASK); |
---|
211 | 115 | } |
---|
212 | 116 | |
---|
213 | | -static int hda_tegra_enable_clocks(struct hda_tegra *data) |
---|
214 | | -{ |
---|
215 | | - int rc; |
---|
216 | | - |
---|
217 | | - rc = clk_prepare_enable(data->hda_clk); |
---|
218 | | - if (rc) |
---|
219 | | - return rc; |
---|
220 | | - rc = clk_prepare_enable(data->hda2codec_2x_clk); |
---|
221 | | - if (rc) |
---|
222 | | - goto disable_hda; |
---|
223 | | - rc = clk_prepare_enable(data->hda2hdmi_clk); |
---|
224 | | - if (rc) |
---|
225 | | - goto disable_codec_2x; |
---|
226 | | - |
---|
227 | | - return 0; |
---|
228 | | - |
---|
229 | | -disable_codec_2x: |
---|
230 | | - clk_disable_unprepare(data->hda2codec_2x_clk); |
---|
231 | | -disable_hda: |
---|
232 | | - clk_disable_unprepare(data->hda_clk); |
---|
233 | | - return rc; |
---|
234 | | -} |
---|
235 | | - |
---|
236 | | -#ifdef CONFIG_PM_SLEEP |
---|
237 | | -static void hda_tegra_disable_clocks(struct hda_tegra *data) |
---|
238 | | -{ |
---|
239 | | - clk_disable_unprepare(data->hda2hdmi_clk); |
---|
240 | | - clk_disable_unprepare(data->hda2codec_2x_clk); |
---|
241 | | - clk_disable_unprepare(data->hda_clk); |
---|
242 | | -} |
---|
243 | | - |
---|
244 | 117 | /* |
---|
245 | 118 | * power management |
---|
246 | 119 | */ |
---|
247 | | -static int hda_tegra_suspend(struct device *dev) |
---|
| 120 | +static int __maybe_unused hda_tegra_suspend(struct device *dev) |
---|
248 | 121 | { |
---|
249 | 122 | struct snd_card *card = dev_get_drvdata(dev); |
---|
250 | | - struct azx *chip = card->private_data; |
---|
251 | | - struct hda_tegra *hda = container_of(chip, struct hda_tegra, chip); |
---|
252 | | - struct hdac_bus *bus = azx_bus(chip); |
---|
| 123 | + int rc; |
---|
253 | 124 | |
---|
| 125 | + rc = pm_runtime_force_suspend(dev); |
---|
| 126 | + if (rc < 0) |
---|
| 127 | + return rc; |
---|
254 | 128 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
---|
255 | | - |
---|
256 | | - azx_stop_chip(chip); |
---|
257 | | - synchronize_irq(bus->irq); |
---|
258 | | - azx_enter_link_reset(chip); |
---|
259 | | - hda_tegra_disable_clocks(hda); |
---|
260 | 129 | |
---|
261 | 130 | return 0; |
---|
262 | 131 | } |
---|
263 | 132 | |
---|
264 | | -static int hda_tegra_resume(struct device *dev) |
---|
| 133 | +static int __maybe_unused hda_tegra_resume(struct device *dev) |
---|
265 | 134 | { |
---|
266 | 135 | struct snd_card *card = dev_get_drvdata(dev); |
---|
267 | | - struct azx *chip = card->private_data; |
---|
268 | | - struct hda_tegra *hda = container_of(chip, struct hda_tegra, chip); |
---|
| 136 | + int rc; |
---|
269 | 137 | |
---|
270 | | - hda_tegra_enable_clocks(hda); |
---|
271 | | - |
---|
272 | | - hda_tegra_init(hda); |
---|
273 | | - |
---|
274 | | - azx_init_chip(chip, 1); |
---|
275 | | - |
---|
| 138 | + rc = pm_runtime_force_resume(dev); |
---|
| 139 | + if (rc < 0) |
---|
| 140 | + return rc; |
---|
276 | 141 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
---|
277 | 142 | |
---|
278 | 143 | return 0; |
---|
279 | 144 | } |
---|
280 | | -#endif /* CONFIG_PM_SLEEP */ |
---|
| 145 | + |
---|
| 146 | +static int __maybe_unused hda_tegra_runtime_suspend(struct device *dev) |
---|
| 147 | +{ |
---|
| 148 | + struct snd_card *card = dev_get_drvdata(dev); |
---|
| 149 | + struct azx *chip = card->private_data; |
---|
| 150 | + struct hda_tegra *hda = container_of(chip, struct hda_tegra, chip); |
---|
| 151 | + |
---|
| 152 | + if (chip && chip->running) { |
---|
| 153 | + /* enable controller wake up event */ |
---|
| 154 | + azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) | |
---|
| 155 | + STATESTS_INT_MASK); |
---|
| 156 | + |
---|
| 157 | + azx_stop_chip(chip); |
---|
| 158 | + azx_enter_link_reset(chip); |
---|
| 159 | + } |
---|
| 160 | + clk_bulk_disable_unprepare(hda->nclocks, hda->clocks); |
---|
| 161 | + |
---|
| 162 | + return 0; |
---|
| 163 | +} |
---|
| 164 | + |
---|
| 165 | +static int __maybe_unused hda_tegra_runtime_resume(struct device *dev) |
---|
| 166 | +{ |
---|
| 167 | + struct snd_card *card = dev_get_drvdata(dev); |
---|
| 168 | + struct azx *chip = card->private_data; |
---|
| 169 | + struct hda_tegra *hda = container_of(chip, struct hda_tegra, chip); |
---|
| 170 | + int rc; |
---|
| 171 | + |
---|
| 172 | + if (!chip->running) { |
---|
| 173 | + rc = reset_control_assert(hda->reset); |
---|
| 174 | + if (rc) |
---|
| 175 | + return rc; |
---|
| 176 | + } |
---|
| 177 | + |
---|
| 178 | + rc = clk_bulk_prepare_enable(hda->nclocks, hda->clocks); |
---|
| 179 | + if (rc != 0) |
---|
| 180 | + return rc; |
---|
| 181 | + if (chip && chip->running) { |
---|
| 182 | + hda_tegra_init(hda); |
---|
| 183 | + azx_init_chip(chip, 1); |
---|
| 184 | + /* disable controller wake up event*/ |
---|
| 185 | + azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) & |
---|
| 186 | + ~STATESTS_INT_MASK); |
---|
| 187 | + } else { |
---|
| 188 | + usleep_range(10, 100); |
---|
| 189 | + |
---|
| 190 | + rc = reset_control_deassert(hda->reset); |
---|
| 191 | + if (rc) |
---|
| 192 | + return rc; |
---|
| 193 | + } |
---|
| 194 | + |
---|
| 195 | + return 0; |
---|
| 196 | +} |
---|
281 | 197 | |
---|
282 | 198 | static const struct dev_pm_ops hda_tegra_pm = { |
---|
283 | 199 | SET_SYSTEM_SLEEP_PM_OPS(hda_tegra_suspend, hda_tegra_resume) |
---|
| 200 | + SET_RUNTIME_PM_OPS(hda_tegra_runtime_suspend, |
---|
| 201 | + hda_tegra_runtime_resume, |
---|
| 202 | + NULL) |
---|
284 | 203 | }; |
---|
285 | 204 | |
---|
286 | 205 | static int hda_tegra_dev_disconnect(struct snd_device *device) |
---|
.. | .. |
---|
318 | 237 | struct hdac_bus *bus = azx_bus(chip); |
---|
319 | 238 | struct device *dev = hda->dev; |
---|
320 | 239 | struct resource *res; |
---|
321 | | - int err; |
---|
322 | | - |
---|
323 | | - hda->hda_clk = devm_clk_get(dev, "hda"); |
---|
324 | | - if (IS_ERR(hda->hda_clk)) { |
---|
325 | | - dev_err(dev, "failed to get hda clock\n"); |
---|
326 | | - return PTR_ERR(hda->hda_clk); |
---|
327 | | - } |
---|
328 | | - hda->hda2codec_2x_clk = devm_clk_get(dev, "hda2codec_2x"); |
---|
329 | | - if (IS_ERR(hda->hda2codec_2x_clk)) { |
---|
330 | | - dev_err(dev, "failed to get hda2codec_2x clock\n"); |
---|
331 | | - return PTR_ERR(hda->hda2codec_2x_clk); |
---|
332 | | - } |
---|
333 | | - hda->hda2hdmi_clk = devm_clk_get(dev, "hda2hdmi"); |
---|
334 | | - if (IS_ERR(hda->hda2hdmi_clk)) { |
---|
335 | | - dev_err(dev, "failed to get hda2hdmi clock\n"); |
---|
336 | | - return PTR_ERR(hda->hda2hdmi_clk); |
---|
337 | | - } |
---|
338 | 240 | |
---|
339 | 241 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
340 | 242 | hda->regs = devm_ioremap_resource(dev, res); |
---|
.. | .. |
---|
344 | 246 | bus->remap_addr = hda->regs + HDA_BAR0; |
---|
345 | 247 | bus->addr = res->start + HDA_BAR0; |
---|
346 | 248 | |
---|
347 | | - err = hda_tegra_enable_clocks(hda); |
---|
348 | | - if (err) { |
---|
349 | | - dev_err(dev, "failed to get enable clocks\n"); |
---|
350 | | - return err; |
---|
351 | | - } |
---|
352 | | - |
---|
353 | 249 | hda_tegra_init(hda); |
---|
354 | 250 | |
---|
355 | 251 | return 0; |
---|
.. | .. |
---|
357 | 253 | |
---|
358 | 254 | static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev) |
---|
359 | 255 | { |
---|
| 256 | + struct hda_tegra *hda = container_of(chip, struct hda_tegra, chip); |
---|
360 | 257 | struct hdac_bus *bus = azx_bus(chip); |
---|
361 | 258 | struct snd_card *card = chip->card; |
---|
362 | 259 | int err; |
---|
363 | 260 | unsigned short gcap; |
---|
364 | 261 | int irq_id = platform_get_irq(pdev, 0); |
---|
| 262 | + const char *sname, *drv_name = "tegra-hda"; |
---|
| 263 | + struct device_node *np = pdev->dev.of_node; |
---|
365 | 264 | |
---|
366 | 265 | if (irq_id < 0) |
---|
367 | 266 | return irq_id; |
---|
.. | .. |
---|
379 | 278 | return err; |
---|
380 | 279 | } |
---|
381 | 280 | bus->irq = irq_id; |
---|
| 281 | + bus->dma_stop_delay = 100; |
---|
| 282 | + card->sync_irq = bus->irq; |
---|
382 | 283 | |
---|
383 | | - synchronize_irq(bus->irq); |
---|
| 284 | + /* |
---|
| 285 | + * Tegra194 has 4 SDO lines and the STRIPE can be used to |
---|
| 286 | + * indicate how many of the SDO lines the stream should be |
---|
| 287 | + * striped. But GCAP register does not reflect the true |
---|
| 288 | + * capability of HW. Below workaround helps to fix this. |
---|
| 289 | + * |
---|
| 290 | + * GCAP_NSDO is bits 19:18 in T_AZA_DBG_CFG_2, |
---|
| 291 | + * 0 for 1 SDO, 1 for 2 SDO, 2 for 4 SDO lines. |
---|
| 292 | + */ |
---|
| 293 | + if (of_device_is_compatible(np, "nvidia,tegra194-hda")) { |
---|
| 294 | + u32 val; |
---|
| 295 | + |
---|
| 296 | + dev_info(card->dev, "Override SDO lines to %u\n", |
---|
| 297 | + TEGRA194_NUM_SDO_LINES); |
---|
| 298 | + |
---|
| 299 | + val = readl(hda->regs + FPCI_DBG_CFG_2) & ~FPCI_GCAP_NSDO_MASK; |
---|
| 300 | + val |= (TEGRA194_NUM_SDO_LINES >> 1) << FPCI_GCAP_NSDO_SHIFT; |
---|
| 301 | + writel(val, hda->regs + FPCI_DBG_CFG_2); |
---|
| 302 | + } |
---|
384 | 303 | |
---|
385 | 304 | gcap = azx_readw(chip, GCAP); |
---|
386 | 305 | dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap); |
---|
| 306 | + |
---|
| 307 | + chip->align_buffer_size = 1; |
---|
387 | 308 | |
---|
388 | 309 | /* read number of streams from GCAP register instead of using |
---|
389 | 310 | * hardcoded value |
---|
.. | .. |
---|
416 | 337 | /* initialize chip */ |
---|
417 | 338 | azx_init_chip(chip, 1); |
---|
418 | 339 | |
---|
| 340 | + /* |
---|
| 341 | + * Playback (for 44.1K/48K, 2-channel, 16-bps) fails with |
---|
| 342 | + * 4 SDO lines due to legacy design limitation. Following |
---|
| 343 | + * is, from HD Audio Specification (Revision 1.0a), used to |
---|
| 344 | + * control striping of the stream across multiple SDO lines |
---|
| 345 | + * for sample rates <= 48K. |
---|
| 346 | + * |
---|
| 347 | + * { ((num_channels * bits_per_sample) / number of SDOs) >= 8 } |
---|
| 348 | + * |
---|
| 349 | + * Due to legacy design issue it is recommended that above |
---|
| 350 | + * ratio must be greater than 8. Since number of SDO lines is |
---|
| 351 | + * in powers of 2, next available ratio is 16 which can be |
---|
| 352 | + * used as a limiting factor here. |
---|
| 353 | + */ |
---|
| 354 | + if (of_device_is_compatible(np, "nvidia,tegra30-hda")) |
---|
| 355 | + chip->bus.core.sdo_limit = 16; |
---|
| 356 | + |
---|
419 | 357 | /* codec detection */ |
---|
420 | 358 | if (!bus->codec_mask) { |
---|
421 | 359 | dev_err(card->dev, "no codecs found!\n"); |
---|
422 | 360 | return -ENODEV; |
---|
423 | 361 | } |
---|
424 | 362 | |
---|
425 | | - strcpy(card->driver, "tegra-hda"); |
---|
426 | | - strcpy(card->shortname, "tegra-hda"); |
---|
| 363 | + /* driver name */ |
---|
| 364 | + strncpy(card->driver, drv_name, sizeof(card->driver)); |
---|
| 365 | + /* shortname for card */ |
---|
| 366 | + sname = of_get_property(np, "nvidia,model", NULL); |
---|
| 367 | + if (!sname) |
---|
| 368 | + sname = drv_name; |
---|
| 369 | + if (strlen(sname) > sizeof(card->shortname)) |
---|
| 370 | + dev_info(card->dev, "truncating shortname for card\n"); |
---|
| 371 | + strncpy(card->shortname, sname, sizeof(card->shortname)); |
---|
| 372 | + |
---|
| 373 | + /* longname for card */ |
---|
427 | 374 | snprintf(card->longname, sizeof(card->longname), |
---|
428 | 375 | "%s at 0x%lx irq %i", |
---|
429 | 376 | card->shortname, bus->addr, bus->irq); |
---|
.. | .. |
---|
441 | 388 | unsigned int driver_caps, |
---|
442 | 389 | struct hda_tegra *hda) |
---|
443 | 390 | { |
---|
444 | | - static struct snd_device_ops ops = { |
---|
| 391 | + static const struct snd_device_ops ops = { |
---|
445 | 392 | .dev_disconnect = hda_tegra_dev_disconnect, |
---|
446 | 393 | .dev_free = hda_tegra_dev_free, |
---|
447 | 394 | }; |
---|
.. | .. |
---|
465 | 412 | |
---|
466 | 413 | INIT_WORK(&hda->probe_work, hda_tegra_probe_work); |
---|
467 | 414 | |
---|
468 | | - err = azx_bus_init(chip, NULL, &hda_tegra_io_ops); |
---|
| 415 | + err = azx_bus_init(chip, NULL); |
---|
469 | 416 | if (err < 0) |
---|
470 | 417 | return err; |
---|
471 | 418 | |
---|
472 | | - chip->bus.needs_damn_long_delay = 1; |
---|
| 419 | + chip->bus.core.sync_write = 0; |
---|
| 420 | + chip->bus.core.needs_damn_long_delay = 1; |
---|
| 421 | + chip->bus.core.aligned_mmio = 1; |
---|
473 | 422 | |
---|
474 | 423 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); |
---|
475 | 424 | if (err < 0) { |
---|
.. | .. |
---|
482 | 431 | |
---|
483 | 432 | static const struct of_device_id hda_tegra_match[] = { |
---|
484 | 433 | { .compatible = "nvidia,tegra30-hda" }, |
---|
| 434 | + { .compatible = "nvidia,tegra194-hda" }, |
---|
485 | 435 | {}, |
---|
486 | 436 | }; |
---|
487 | 437 | MODULE_DEVICE_TABLE(of, hda_tegra_match); |
---|
488 | 438 | |
---|
489 | 439 | static int hda_tegra_probe(struct platform_device *pdev) |
---|
490 | 440 | { |
---|
491 | | - const unsigned int driver_flags = AZX_DCAPS_CORBRP_SELF_CLEAR; |
---|
| 441 | + const unsigned int driver_flags = AZX_DCAPS_CORBRP_SELF_CLEAR | |
---|
| 442 | + AZX_DCAPS_PM_RUNTIME | |
---|
| 443 | + AZX_DCAPS_4K_BDLE_BOUNDARY; |
---|
492 | 444 | struct snd_card *card; |
---|
493 | 445 | struct azx *chip; |
---|
494 | 446 | struct hda_tegra *hda; |
---|
.. | .. |
---|
507 | 459 | return err; |
---|
508 | 460 | } |
---|
509 | 461 | |
---|
| 462 | + hda->reset = devm_reset_control_array_get_exclusive(&pdev->dev); |
---|
| 463 | + if (IS_ERR(hda->reset)) { |
---|
| 464 | + err = PTR_ERR(hda->reset); |
---|
| 465 | + goto out_free; |
---|
| 466 | + } |
---|
| 467 | + |
---|
| 468 | + hda->clocks[hda->nclocks++].id = "hda"; |
---|
| 469 | + hda->clocks[hda->nclocks++].id = "hda2hdmi"; |
---|
| 470 | + hda->clocks[hda->nclocks++].id = "hda2codec_2x"; |
---|
| 471 | + |
---|
| 472 | + err = devm_clk_bulk_get(&pdev->dev, hda->nclocks, hda->clocks); |
---|
| 473 | + if (err < 0) |
---|
| 474 | + goto out_free; |
---|
| 475 | + |
---|
510 | 476 | err = hda_tegra_create(card, driver_flags, hda); |
---|
511 | 477 | if (err < 0) |
---|
512 | 478 | goto out_free; |
---|
513 | 479 | card->private_data = chip; |
---|
514 | 480 | |
---|
515 | 481 | dev_set_drvdata(&pdev->dev, card); |
---|
| 482 | + |
---|
| 483 | + pm_runtime_enable(hda->dev); |
---|
| 484 | + if (!azx_has_pm_runtime(chip)) |
---|
| 485 | + pm_runtime_forbid(hda->dev); |
---|
| 486 | + |
---|
516 | 487 | schedule_work(&hda->probe_work); |
---|
517 | 488 | |
---|
518 | 489 | return 0; |
---|
.. | .. |
---|
529 | 500 | struct platform_device *pdev = to_platform_device(hda->dev); |
---|
530 | 501 | int err; |
---|
531 | 502 | |
---|
| 503 | + pm_runtime_get_sync(hda->dev); |
---|
532 | 504 | err = hda_tegra_first_init(chip, pdev); |
---|
533 | 505 | if (err < 0) |
---|
534 | 506 | goto out_free; |
---|
535 | 507 | |
---|
536 | 508 | /* create codec instances */ |
---|
537 | | - err = azx_probe_codecs(chip, 0); |
---|
| 509 | + err = azx_probe_codecs(chip, 8); |
---|
538 | 510 | if (err < 0) |
---|
539 | 511 | goto out_free; |
---|
540 | 512 | |
---|
.. | .. |
---|
550 | 522 | snd_hda_set_power_save(&chip->bus, power_save * 1000); |
---|
551 | 523 | |
---|
552 | 524 | out_free: |
---|
| 525 | + pm_runtime_put(hda->dev); |
---|
553 | 526 | return; /* no error return from async probe */ |
---|
554 | 527 | } |
---|
555 | 528 | |
---|
556 | 529 | static int hda_tegra_remove(struct platform_device *pdev) |
---|
557 | 530 | { |
---|
558 | | - return snd_card_free(dev_get_drvdata(&pdev->dev)); |
---|
| 531 | + int ret; |
---|
| 532 | + |
---|
| 533 | + ret = snd_card_free(dev_get_drvdata(&pdev->dev)); |
---|
| 534 | + pm_runtime_disable(&pdev->dev); |
---|
| 535 | + |
---|
| 536 | + return ret; |
---|
559 | 537 | } |
---|
560 | 538 | |
---|
561 | 539 | static void hda_tegra_shutdown(struct platform_device *pdev) |
---|