diff options
84 files changed, 4229 insertions, 3076 deletions
diff --git a/Documentation/sound/alsa/HD-Audio-Models.txt b/Documentation/sound/alsa/HD-Audio-Models.txt index 5a3163cac6c3..ec099d4343f2 100644 --- a/Documentation/sound/alsa/HD-Audio-Models.txt +++ b/Documentation/sound/alsa/HD-Audio-Models.txt | |||
@@ -11,7 +11,10 @@ ALC880 | |||
11 | 11 | ||
12 | ALC260 | 12 | ALC260 |
13 | ====== | 13 | ====== |
14 | N/A | 14 | gpio1 Enable GPIO1 |
15 | coef Enable EAPD via COEF table | ||
16 | fujitsu Quirk for FSC S7020 | ||
17 | fujitsu-jwse Quirk for FSC S7020 with jack modes and HP mic support | ||
15 | 18 | ||
16 | ALC262 | 19 | ALC262 |
17 | ====== | 20 | ====== |
@@ -20,8 +23,9 @@ ALC262 | |||
20 | ALC267/268 | 23 | ALC267/268 |
21 | ========== | 24 | ========== |
22 | inv-dmic Inverted internal mic workaround | 25 | inv-dmic Inverted internal mic workaround |
26 | hp-eapd Disable HP EAPD on NID 0x15 | ||
23 | 27 | ||
24 | ALC269/270/275/276/28x/29x | 28 | ALC22x/23x/25x/269/27x/28x/29x (and vendor-specific ALC3xxx models) |
25 | ====== | 29 | ====== |
26 | laptop-amic Laptops with analog-mic input | 30 | laptop-amic Laptops with analog-mic input |
27 | laptop-dmic Laptops with digital-mic input | 31 | laptop-dmic Laptops with digital-mic input |
@@ -29,9 +33,15 @@ ALC269/270/275/276/28x/29x | |||
29 | alc271-dmic Enable ALC271X digital mic workaround | 33 | alc271-dmic Enable ALC271X digital mic workaround |
30 | inv-dmic Inverted internal mic workaround | 34 | inv-dmic Inverted internal mic workaround |
31 | headset-mic Indicates a combined headset (headphone+mic) jack | 35 | headset-mic Indicates a combined headset (headphone+mic) jack |
36 | headset-mode More comprehensive headset support for ALC269 & co | ||
37 | headset-mode-no-hp-mic Headset mode support without headphone mic | ||
32 | lenovo-dock Enables docking station I/O for some Lenovos | 38 | lenovo-dock Enables docking station I/O for some Lenovos |
39 | hp-gpio-led GPIO LED support on HP laptops | ||
33 | dell-headset-multi Headset jack, which can also be used as mic-in | 40 | dell-headset-multi Headset jack, which can also be used as mic-in |
34 | dell-headset-dock Headset jack (without mic-in), and also dock I/O | 41 | dell-headset-dock Headset jack (without mic-in), and also dock I/O |
42 | alc283-dac-wcaps Fixups for Chromebook with ALC283 | ||
43 | alc283-sense-combo Combo jack sensing on ALC283 | ||
44 | tpt440-dock Pin configs for Lenovo Thinkpad Dock support | ||
35 | 45 | ||
36 | ALC66x/67x/892 | 46 | ALC66x/67x/892 |
37 | ============== | 47 | ============== |
diff --git a/Documentation/sound/alsa/Jack-Controls.txt b/Documentation/sound/alsa/Jack-Controls.txt new file mode 100644 index 000000000000..fe1c5e0c8555 --- /dev/null +++ b/Documentation/sound/alsa/Jack-Controls.txt | |||
@@ -0,0 +1,43 @@ | |||
1 | Why we need Jack kcontrols | ||
2 | ========================== | ||
3 | |||
4 | ALSA uses kcontrols to export audio controls(switch, volume, Mux, ...) | ||
5 | to user space. This means userspace applications like pulseaudio can | ||
6 | switch off headphones and switch on speakers when no headphones are | ||
7 | pluged in. | ||
8 | |||
9 | The old ALSA jack code only created input devices for each registered | ||
10 | jack. These jack input devices are not readable by userspace devices | ||
11 | that run as non root. | ||
12 | |||
13 | The new jack code creates embedded jack kcontrols for each jack that | ||
14 | can be read by any process. | ||
15 | |||
16 | This can be combined with UCM to allow userspace to route audio more | ||
17 | intelligently based on jack insertion or removal events. | ||
18 | |||
19 | Jack Kcontrol Internals | ||
20 | ======================= | ||
21 | |||
22 | Each jack will have a kcontrol list, so that we can create a kcontrol | ||
23 | and attach it to the jack, at jack creation stage. We can also add a | ||
24 | kcontrol to an existing jack, at anytime when required. | ||
25 | |||
26 | Those kcontrols will be freed automatically when the Jack is freed. | ||
27 | |||
28 | How to use jack kcontrols | ||
29 | ========================= | ||
30 | |||
31 | In order to keep compatibility, snd_jack_new() has been modified by | ||
32 | adding two params :- | ||
33 | |||
34 | - @initial_kctl: if true, create a kcontrol and add it to the jack | ||
35 | list. | ||
36 | - @phantom_jack: Don't create a input device for phantom jacks. | ||
37 | |||
38 | HDA jacks can set phantom_jack to true in order to create a phantom | ||
39 | jack and set initial_kctl to true to create an initial kcontrol with | ||
40 | the correct id. | ||
41 | |||
42 | ASoC jacks should set initial_kctl as false. The pin name will be | ||
43 | assigned as the jack kcontrol name. | ||
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h index 3da1af46625c..7d88f4f51594 100644 --- a/drivers/gpu/drm/i915/i915_reg.h +++ b/drivers/gpu/drm/i915/i915_reg.h | |||
@@ -6477,6 +6477,9 @@ enum skl_disp_power_wells { | |||
6477 | #define AUDIO_CP_READY(trans) ((1 << 1) << ((trans) * 4)) | 6477 | #define AUDIO_CP_READY(trans) ((1 << 1) << ((trans) * 4)) |
6478 | #define AUDIO_ELD_VALID(trans) ((1 << 0) << ((trans) * 4)) | 6478 | #define AUDIO_ELD_VALID(trans) ((1 << 0) << ((trans) * 4)) |
6479 | 6479 | ||
6480 | #define HSW_AUD_CHICKENBIT 0x65f10 | ||
6481 | #define SKL_AUD_CODEC_WAKE_SIGNAL (1 << 15) | ||
6482 | |||
6480 | /* HSW Power Wells */ | 6483 | /* HSW Power Wells */ |
6481 | #define HSW_PWR_WELL_BIOS 0x45400 /* CTL1 */ | 6484 | #define HSW_PWR_WELL_BIOS 0x45400 /* CTL1 */ |
6482 | #define HSW_PWR_WELL_DRIVER 0x45404 /* CTL2 */ | 6485 | #define HSW_PWR_WELL_DRIVER 0x45404 /* CTL2 */ |
diff --git a/drivers/gpu/drm/i915/intel_audio.c b/drivers/gpu/drm/i915/intel_audio.c index 2396cc702d18..ef342571ae6a 100644 --- a/drivers/gpu/drm/i915/intel_audio.c +++ b/drivers/gpu/drm/i915/intel_audio.c | |||
@@ -475,6 +475,32 @@ static void i915_audio_component_put_power(struct device *dev) | |||
475 | intel_display_power_put(dev_to_i915(dev), POWER_DOMAIN_AUDIO); | 475 | intel_display_power_put(dev_to_i915(dev), POWER_DOMAIN_AUDIO); |
476 | } | 476 | } |
477 | 477 | ||
478 | static void i915_audio_component_codec_wake_override(struct device *dev, | ||
479 | bool enable) | ||
480 | { | ||
481 | struct drm_i915_private *dev_priv = dev_to_i915(dev); | ||
482 | u32 tmp; | ||
483 | |||
484 | if (!IS_SKYLAKE(dev_priv)) | ||
485 | return; | ||
486 | |||
487 | /* | ||
488 | * Enable/disable generating the codec wake signal, overriding the | ||
489 | * internal logic to generate the codec wake to controller. | ||
490 | */ | ||
491 | tmp = I915_READ(HSW_AUD_CHICKENBIT); | ||
492 | tmp &= ~SKL_AUD_CODEC_WAKE_SIGNAL; | ||
493 | I915_WRITE(HSW_AUD_CHICKENBIT, tmp); | ||
494 | usleep_range(1000, 1500); | ||
495 | |||
496 | if (enable) { | ||
497 | tmp = I915_READ(HSW_AUD_CHICKENBIT); | ||
498 | tmp |= SKL_AUD_CODEC_WAKE_SIGNAL; | ||
499 | I915_WRITE(HSW_AUD_CHICKENBIT, tmp); | ||
500 | usleep_range(1000, 1500); | ||
501 | } | ||
502 | } | ||
503 | |||
478 | /* Get CDCLK in kHz */ | 504 | /* Get CDCLK in kHz */ |
479 | static int i915_audio_component_get_cdclk_freq(struct device *dev) | 505 | static int i915_audio_component_get_cdclk_freq(struct device *dev) |
480 | { | 506 | { |
@@ -495,6 +521,7 @@ static const struct i915_audio_component_ops i915_audio_component_ops = { | |||
495 | .owner = THIS_MODULE, | 521 | .owner = THIS_MODULE, |
496 | .get_power = i915_audio_component_get_power, | 522 | .get_power = i915_audio_component_get_power, |
497 | .put_power = i915_audio_component_put_power, | 523 | .put_power = i915_audio_component_put_power, |
524 | .codec_wake_override = i915_audio_component_codec_wake_override, | ||
498 | .get_cdclk_freq = i915_audio_component_get_cdclk_freq, | 525 | .get_cdclk_freq = i915_audio_component_get_cdclk_freq, |
499 | }; | 526 | }; |
500 | 527 | ||
diff --git a/include/drm/i915_component.h b/include/drm/i915_component.h index 3e2f22e5bf3c..c9a8b64aa33b 100644 --- a/include/drm/i915_component.h +++ b/include/drm/i915_component.h | |||
@@ -31,6 +31,7 @@ struct i915_audio_component { | |||
31 | struct module *owner; | 31 | struct module *owner; |
32 | void (*get_power)(struct device *); | 32 | void (*get_power)(struct device *); |
33 | void (*put_power)(struct device *); | 33 | void (*put_power)(struct device *); |
34 | void (*codec_wake_override)(struct device *, bool enable); | ||
34 | int (*get_cdclk_freq)(struct device *); | 35 | int (*get_cdclk_freq)(struct device *); |
35 | } *ops; | 36 | } *ops; |
36 | }; | 37 | }; |
diff --git a/include/sound/control.h b/include/sound/control.h index 95aad6d3fd1a..21d047f229a1 100644 --- a/include/sound/control.h +++ b/include/sound/control.h | |||
@@ -252,7 +252,7 @@ void snd_ctl_sync_vmaster(struct snd_kcontrol *kctl, bool hook_only); | |||
252 | * Helper functions for jack-detection controls | 252 | * Helper functions for jack-detection controls |
253 | */ | 253 | */ |
254 | struct snd_kcontrol * | 254 | struct snd_kcontrol * |
255 | snd_kctl_jack_new(const char *name, int idx, void *private_data); | 255 | snd_kctl_jack_new(const char *name, struct snd_card *card); |
256 | void snd_kctl_jack_report(struct snd_card *card, | 256 | void snd_kctl_jack_report(struct snd_card *card, |
257 | struct snd_kcontrol *kctl, bool status); | 257 | struct snd_kcontrol *kctl, bool status); |
258 | 258 | ||
diff --git a/include/sound/core.h b/include/sound/core.h index b12931f513f4..cdfecafff0f4 100644 --- a/include/sound/core.h +++ b/include/sound/core.h | |||
@@ -224,16 +224,13 @@ void *snd_lookup_oss_minor_data(unsigned int minor, int type); | |||
224 | #endif | 224 | #endif |
225 | 225 | ||
226 | int snd_minor_info_init(void); | 226 | int snd_minor_info_init(void); |
227 | int snd_minor_info_done(void); | ||
228 | 227 | ||
229 | /* sound_oss.c */ | 228 | /* sound_oss.c */ |
230 | 229 | ||
231 | #ifdef CONFIG_SND_OSSEMUL | 230 | #ifdef CONFIG_SND_OSSEMUL |
232 | int snd_minor_info_oss_init(void); | 231 | int snd_minor_info_oss_init(void); |
233 | int snd_minor_info_oss_done(void); | ||
234 | #else | 232 | #else |
235 | static inline int snd_minor_info_oss_init(void) { return 0; } | 233 | static inline int snd_minor_info_oss_init(void) { return 0; } |
236 | static inline int snd_minor_info_oss_done(void) { return 0; } | ||
237 | #endif | 234 | #endif |
238 | 235 | ||
239 | /* memory.c */ | 236 | /* memory.c */ |
@@ -262,7 +259,6 @@ int snd_card_free_when_closed(struct snd_card *card); | |||
262 | void snd_card_set_id(struct snd_card *card, const char *id); | 259 | void snd_card_set_id(struct snd_card *card, const char *id); |
263 | int snd_card_register(struct snd_card *card); | 260 | int snd_card_register(struct snd_card *card); |
264 | int snd_card_info_init(void); | 261 | int snd_card_info_init(void); |
265 | int snd_card_info_done(void); | ||
266 | int snd_card_add_dev_attr(struct snd_card *card, | 262 | int snd_card_add_dev_attr(struct snd_card *card, |
267 | const struct attribute_group *group); | 263 | const struct attribute_group *group); |
268 | int snd_component_add(struct snd_card *card, const char *component); | 264 | int snd_component_add(struct snd_card *card, const char *component); |
diff --git a/include/sound/emu10k1.h b/include/sound/emu10k1.h index 0de95ccb92cf..5bd134651f5e 100644 --- a/include/sound/emu10k1.h +++ b/include/sound/emu10k1.h | |||
@@ -41,7 +41,8 @@ | |||
41 | 41 | ||
42 | #define EMUPAGESIZE 4096 | 42 | #define EMUPAGESIZE 4096 |
43 | #define MAXREQVOICES 8 | 43 | #define MAXREQVOICES 8 |
44 | #define MAXPAGES 8192 | 44 | #define MAXPAGES0 4096 /* 32 bit mode */ |
45 | #define MAXPAGES1 8192 /* 31 bit mode */ | ||
45 | #define RESERVED 0 | 46 | #define RESERVED 0 |
46 | #define NUM_MIDI 16 | 47 | #define NUM_MIDI 16 |
47 | #define NUM_G 64 /* use all channels */ | 48 | #define NUM_G 64 /* use all channels */ |
@@ -50,8 +51,7 @@ | |||
50 | 51 | ||
51 | /* FIXME? - according to the OSS driver the EMU10K1 needs a 29 bit DMA mask */ | 52 | /* FIXME? - according to the OSS driver the EMU10K1 needs a 29 bit DMA mask */ |
52 | #define EMU10K1_DMA_MASK 0x7fffffffUL /* 31bit */ | 53 | #define EMU10K1_DMA_MASK 0x7fffffffUL /* 31bit */ |
53 | #define AUDIGY_DMA_MASK 0x7fffffffUL /* 31bit FIXME - 32 should work? */ | 54 | #define AUDIGY_DMA_MASK 0xffffffffUL /* 32bit mode */ |
54 | /* See ALSA bug #1276 - rlrevell */ | ||
55 | 55 | ||
56 | #define TMEMSIZE 256*1024 | 56 | #define TMEMSIZE 256*1024 |
57 | #define TMEMSIZEREG 4 | 57 | #define TMEMSIZEREG 4 |
@@ -466,8 +466,11 @@ | |||
466 | 466 | ||
467 | #define MAPB 0x0d /* Cache map B */ | 467 | #define MAPB 0x0d /* Cache map B */ |
468 | 468 | ||
469 | #define MAP_PTE_MASK 0xffffe000 /* The 19 MSBs of the PTE indexed by the PTI */ | 469 | #define MAP_PTE_MASK0 0xfffff000 /* The 20 MSBs of the PTE indexed by the PTI */ |
470 | #define MAP_PTI_MASK 0x00001fff /* The 13 bit index to one of the 8192 PTE dwords */ | 470 | #define MAP_PTI_MASK0 0x00000fff /* The 12 bit index to one of the 4096 PTE dwords */ |
471 | |||
472 | #define MAP_PTE_MASK1 0xffffe000 /* The 19 MSBs of the PTE indexed by the PTI */ | ||
473 | #define MAP_PTI_MASK1 0x00001fff /* The 13 bit index to one of the 8192 PTE dwords */ | ||
471 | 474 | ||
472 | /* 0x0e, 0x0f: Not used */ | 475 | /* 0x0e, 0x0f: Not used */ |
473 | 476 | ||
@@ -1704,6 +1707,7 @@ struct snd_emu10k1 { | |||
1704 | unsigned short model; /* subsystem id */ | 1707 | unsigned short model; /* subsystem id */ |
1705 | unsigned int card_type; /* EMU10K1_CARD_* */ | 1708 | unsigned int card_type; /* EMU10K1_CARD_* */ |
1706 | unsigned int ecard_ctrl; /* ecard control bits */ | 1709 | unsigned int ecard_ctrl; /* ecard control bits */ |
1710 | unsigned int address_mode; /* address mode */ | ||
1707 | unsigned long dma_mask; /* PCI DMA mask */ | 1711 | unsigned long dma_mask; /* PCI DMA mask */ |
1708 | unsigned int delay_pcm_irq; /* in samples */ | 1712 | unsigned int delay_pcm_irq; /* in samples */ |
1709 | int max_cache_pages; /* max memory size / PAGE_SIZE */ | 1713 | int max_cache_pages; /* max memory size / PAGE_SIZE */ |
diff --git a/include/sound/hda_i915.h b/include/sound/hda_i915.h new file mode 100644 index 000000000000..adb5ba5cbd9d --- /dev/null +++ b/include/sound/hda_i915.h | |||
@@ -0,0 +1,36 @@ | |||
1 | /* | ||
2 | * HD-Audio helpers to sync with i915 driver | ||
3 | */ | ||
4 | #ifndef __SOUND_HDA_I915_H | ||
5 | #define __SOUND_HDA_I915_H | ||
6 | |||
7 | #ifdef CONFIG_SND_HDA_I915 | ||
8 | int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable); | ||
9 | int snd_hdac_display_power(struct hdac_bus *bus, bool enable); | ||
10 | int snd_hdac_get_display_clk(struct hdac_bus *bus); | ||
11 | int snd_hdac_i915_init(struct hdac_bus *bus); | ||
12 | int snd_hdac_i915_exit(struct hdac_bus *bus); | ||
13 | #else | ||
14 | static int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable) | ||
15 | { | ||
16 | return 0; | ||
17 | } | ||
18 | static inline int snd_hdac_display_power(struct hdac_bus *bus, bool enable) | ||
19 | { | ||
20 | return 0; | ||
21 | } | ||
22 | static inline int snd_hdac_get_display_clk(struct hdac_bus *bus) | ||
23 | { | ||
24 | return 0; | ||
25 | } | ||
26 | static inline int snd_hdac_i915_init(struct hdac_bus *bus) | ||
27 | { | ||
28 | return -ENODEV; | ||
29 | } | ||
30 | static inline int snd_hdac_i915_exit(struct hdac_bus *bus) | ||
31 | { | ||
32 | return 0; | ||
33 | } | ||
34 | #endif | ||
35 | |||
36 | #endif /* __SOUND_HDA_I915_H */ | ||
diff --git a/include/sound/hda_register.h b/include/sound/hda_register.h new file mode 100644 index 000000000000..0c7536e30fa4 --- /dev/null +++ b/include/sound/hda_register.h | |||
@@ -0,0 +1,156 @@ | |||
1 | /* | ||
2 | * HD-audio controller (Azalia) registers and helpers | ||
3 | * | ||
4 | * For traditional reasons, we still use azx_ prefix here | ||
5 | */ | ||
6 | |||
7 | #ifndef __SOUND_HDA_REGISTER_H | ||
8 | #define __SOUND_HDA_REGISTER_H | ||
9 | |||
10 | #include <linux/io.h> | ||
11 | #include <sound/hdaudio.h> | ||
12 | |||
13 | #define AZX_REG_GCAP 0x00 | ||
14 | #define AZX_GCAP_64OK (1 << 0) /* 64bit address support */ | ||
15 | #define AZX_GCAP_NSDO (3 << 1) /* # of serial data out signals */ | ||
16 | #define AZX_GCAP_BSS (31 << 3) /* # of bidirectional streams */ | ||
17 | #define AZX_GCAP_ISS (15 << 8) /* # of input streams */ | ||
18 | #define AZX_GCAP_OSS (15 << 12) /* # of output streams */ | ||
19 | #define AZX_REG_VMIN 0x02 | ||
20 | #define AZX_REG_VMAJ 0x03 | ||
21 | #define AZX_REG_OUTPAY 0x04 | ||
22 | #define AZX_REG_INPAY 0x06 | ||
23 | #define AZX_REG_GCTL 0x08 | ||
24 | #define AZX_GCTL_RESET (1 << 0) /* controller reset */ | ||
25 | #define AZX_GCTL_FCNTRL (1 << 1) /* flush control */ | ||
26 | #define AZX_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */ | ||
27 | #define AZX_REG_WAKEEN 0x0c | ||
28 | #define AZX_REG_STATESTS 0x0e | ||
29 | #define AZX_REG_GSTS 0x10 | ||
30 | #define AZX_GSTS_FSTS (1 << 1) /* flush status */ | ||
31 | #define AZX_REG_INTCTL 0x20 | ||
32 | #define AZX_REG_INTSTS 0x24 | ||
33 | #define AZX_REG_WALLCLK 0x30 /* 24Mhz source */ | ||
34 | #define AZX_REG_OLD_SSYNC 0x34 /* SSYNC for old ICH */ | ||
35 | #define AZX_REG_SSYNC 0x38 | ||
36 | #define AZX_REG_CORBLBASE 0x40 | ||
37 | #define AZX_REG_CORBUBASE 0x44 | ||
38 | #define AZX_REG_CORBWP 0x48 | ||
39 | #define AZX_REG_CORBRP 0x4a | ||
40 | #define AZX_CORBRP_RST (1 << 15) /* read pointer reset */ | ||
41 | #define AZX_REG_CORBCTL 0x4c | ||
42 | #define AZX_CORBCTL_RUN (1 << 1) /* enable DMA */ | ||
43 | #define AZX_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */ | ||
44 | #define AZX_REG_CORBSTS 0x4d | ||
45 | #define AZX_CORBSTS_CMEI (1 << 0) /* memory error indication */ | ||
46 | #define AZX_REG_CORBSIZE 0x4e | ||
47 | |||
48 | #define AZX_REG_RIRBLBASE 0x50 | ||
49 | #define AZX_REG_RIRBUBASE 0x54 | ||
50 | #define AZX_REG_RIRBWP 0x58 | ||
51 | #define AZX_RIRBWP_RST (1 << 15) /* write pointer reset */ | ||
52 | #define AZX_REG_RINTCNT 0x5a | ||
53 | #define AZX_REG_RIRBCTL 0x5c | ||
54 | #define AZX_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */ | ||
55 | #define AZX_RBCTL_DMA_EN (1 << 1) /* enable DMA */ | ||
56 | #define AZX_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */ | ||
57 | #define AZX_REG_RIRBSTS 0x5d | ||
58 | #define AZX_RBSTS_IRQ (1 << 0) /* response irq */ | ||
59 | #define AZX_RBSTS_OVERRUN (1 << 2) /* overrun irq */ | ||
60 | #define AZX_REG_RIRBSIZE 0x5e | ||
61 | |||
62 | #define AZX_REG_IC 0x60 | ||
63 | #define AZX_REG_IR 0x64 | ||
64 | #define AZX_REG_IRS 0x68 | ||
65 | #define AZX_IRS_VALID (1<<1) | ||
66 | #define AZX_IRS_BUSY (1<<0) | ||
67 | |||
68 | #define AZX_REG_DPLBASE 0x70 | ||
69 | #define AZX_REG_DPUBASE 0x74 | ||
70 | #define AZX_DPLBASE_ENABLE 0x1 /* Enable position buffer */ | ||
71 | |||
72 | /* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ | ||
73 | enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 }; | ||
74 | |||
75 | /* stream register offsets from stream base */ | ||
76 | #define AZX_REG_SD_CTL 0x00 | ||
77 | #define AZX_REG_SD_STS 0x03 | ||
78 | #define AZX_REG_SD_LPIB 0x04 | ||
79 | #define AZX_REG_SD_CBL 0x08 | ||
80 | #define AZX_REG_SD_LVI 0x0c | ||
81 | #define AZX_REG_SD_FIFOW 0x0e | ||
82 | #define AZX_REG_SD_FIFOSIZE 0x10 | ||
83 | #define AZX_REG_SD_FORMAT 0x12 | ||
84 | #define AZX_REG_SD_BDLPL 0x18 | ||
85 | #define AZX_REG_SD_BDLPU 0x1c | ||
86 | |||
87 | /* Haswell/Broadwell display HD-A controller Extended Mode registers */ | ||
88 | #define AZX_REG_HSW_EM4 0x100c | ||
89 | #define AZX_REG_HSW_EM5 0x1010 | ||
90 | |||
91 | /* PCI space */ | ||
92 | #define AZX_PCIREG_TCSEL 0x44 | ||
93 | |||
94 | /* | ||
95 | * other constants | ||
96 | */ | ||
97 | |||
98 | /* max number of fragments - we may use more if allocating more pages for BDL */ | ||
99 | #define BDL_SIZE 4096 | ||
100 | #define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16) | ||
101 | #define AZX_MAX_FRAG 32 | ||
102 | /* max buffer size - no h/w limit, you can increase as you like */ | ||
103 | #define AZX_MAX_BUF_SIZE (1024*1024*1024) | ||
104 | |||
105 | /* RIRB int mask: overrun[2], response[0] */ | ||
106 | #define RIRB_INT_RESPONSE 0x01 | ||
107 | #define RIRB_INT_OVERRUN 0x04 | ||
108 | #define RIRB_INT_MASK 0x05 | ||
109 | |||
110 | /* STATESTS int mask: S3,SD2,SD1,SD0 */ | ||
111 | #define STATESTS_INT_MASK ((1 << HDA_MAX_CODECS) - 1) | ||
112 | |||
113 | /* SD_CTL bits */ | ||
114 | #define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */ | ||
115 | #define SD_CTL_DMA_START 0x02 /* stream DMA start bit */ | ||
116 | #define SD_CTL_STRIPE (3 << 16) /* stripe control */ | ||
117 | #define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */ | ||
118 | #define SD_CTL_DIR (1 << 19) /* bi-directional stream */ | ||
119 | #define SD_CTL_STREAM_TAG_MASK (0xf << 20) | ||
120 | #define SD_CTL_STREAM_TAG_SHIFT 20 | ||
121 | |||
122 | /* SD_CTL and SD_STS */ | ||
123 | #define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */ | ||
124 | #define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */ | ||
125 | #define SD_INT_COMPLETE 0x04 /* completion interrupt */ | ||
126 | #define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\ | ||
127 | SD_INT_COMPLETE) | ||
128 | |||
129 | /* SD_STS */ | ||
130 | #define SD_STS_FIFO_READY 0x20 /* FIFO ready */ | ||
131 | |||
132 | /* INTCTL and INTSTS */ | ||
133 | #define AZX_INT_ALL_STREAM 0xff /* all stream interrupts */ | ||
134 | #define AZX_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */ | ||
135 | #define AZX_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */ | ||
136 | |||
137 | /* below are so far hardcoded - should read registers in future */ | ||
138 | #define AZX_MAX_CORB_ENTRIES 256 | ||
139 | #define AZX_MAX_RIRB_ENTRIES 256 | ||
140 | |||
141 | /* | ||
142 | * helpers to read the stream position | ||
143 | */ | ||
144 | static inline unsigned int | ||
145 | snd_hdac_stream_get_pos_lpib(struct hdac_stream *stream) | ||
146 | { | ||
147 | return snd_hdac_stream_readl(stream, SD_LPIB); | ||
148 | } | ||
149 | |||
150 | static inline unsigned int | ||
151 | snd_hdac_stream_get_pos_posbuf(struct hdac_stream *stream) | ||
152 | { | ||
153 | return le32_to_cpu(*stream->posbuf); | ||
154 | } | ||
155 | |||
156 | #endif /* __SOUND_HDA_REGISTER_H */ | ||
diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h index 2a8aa9dfb83d..64fff4db81bb 100644 --- a/include/sound/hdaudio.h +++ b/include/sound/hdaudio.h | |||
@@ -6,12 +6,18 @@ | |||
6 | #define __SOUND_HDAUDIO_H | 6 | #define __SOUND_HDAUDIO_H |
7 | 7 | ||
8 | #include <linux/device.h> | 8 | #include <linux/device.h> |
9 | #include <linux/interrupt.h> | ||
10 | #include <linux/timecounter.h> | ||
11 | #include <sound/core.h> | ||
12 | #include <sound/memalloc.h> | ||
9 | #include <sound/hda_verbs.h> | 13 | #include <sound/hda_verbs.h> |
14 | #include <drm/i915_component.h> | ||
10 | 15 | ||
11 | /* codec node id */ | 16 | /* codec node id */ |
12 | typedef u16 hda_nid_t; | 17 | typedef u16 hda_nid_t; |
13 | 18 | ||
14 | struct hdac_bus; | 19 | struct hdac_bus; |
20 | struct hdac_stream; | ||
15 | struct hdac_device; | 21 | struct hdac_device; |
16 | struct hdac_driver; | 22 | struct hdac_driver; |
17 | struct hdac_widget_tree; | 23 | struct hdac_widget_tree; |
@@ -69,6 +75,7 @@ struct hdac_device { | |||
69 | 75 | ||
70 | /* misc flags */ | 76 | /* misc flags */ |
71 | atomic_t in_pm; /* suspend/resume being performed */ | 77 | atomic_t in_pm; /* suspend/resume being performed */ |
78 | bool link_power_control:1; | ||
72 | 79 | ||
73 | /* sysfs */ | 80 | /* sysfs */ |
74 | struct hdac_widget_tree *widgets; | 81 | struct hdac_widget_tree *widgets; |
@@ -85,6 +92,7 @@ struct hdac_device { | |||
85 | enum { | 92 | enum { |
86 | HDA_DEV_CORE, | 93 | HDA_DEV_CORE, |
87 | HDA_DEV_LEGACY, | 94 | HDA_DEV_LEGACY, |
95 | HDA_DEV_ASOC, | ||
88 | }; | 96 | }; |
89 | 97 | ||
90 | /* direction */ | 98 | /* direction */ |
@@ -118,6 +126,15 @@ int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid, | |||
118 | hda_nid_t *conn_list, int max_conns); | 126 | hda_nid_t *conn_list, int max_conns); |
119 | int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid, | 127 | int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid, |
120 | hda_nid_t *start_id); | 128 | hda_nid_t *start_id); |
129 | unsigned int snd_hdac_calc_stream_format(unsigned int rate, | ||
130 | unsigned int channels, | ||
131 | unsigned int format, | ||
132 | unsigned int maxbps, | ||
133 | unsigned short spdif_ctls); | ||
134 | int snd_hdac_query_supported_pcm(struct hdac_device *codec, hda_nid_t nid, | ||
135 | u32 *ratesp, u64 *formatsp, unsigned int *bpsp); | ||
136 | bool snd_hdac_is_supported_format(struct hdac_device *codec, hda_nid_t nid, | ||
137 | unsigned int format); | ||
121 | 138 | ||
122 | /** | 139 | /** |
123 | * snd_hdac_read_parm - read a codec parameter | 140 | * snd_hdac_read_parm - read a codec parameter |
@@ -161,7 +178,7 @@ struct hdac_driver { | |||
161 | #define drv_to_hdac_driver(_drv) container_of(_drv, struct hdac_driver, driver) | 178 | #define drv_to_hdac_driver(_drv) container_of(_drv, struct hdac_driver, driver) |
162 | 179 | ||
163 | /* | 180 | /* |
164 | * HD-audio bus base driver | 181 | * Bus verb operators |
165 | */ | 182 | */ |
166 | struct hdac_bus_ops { | 183 | struct hdac_bus_ops { |
167 | /* send a single command */ | 184 | /* send a single command */ |
@@ -169,13 +186,59 @@ struct hdac_bus_ops { | |||
169 | /* get a response from the last command */ | 186 | /* get a response from the last command */ |
170 | int (*get_response)(struct hdac_bus *bus, unsigned int addr, | 187 | int (*get_response)(struct hdac_bus *bus, unsigned int addr, |
171 | unsigned int *res); | 188 | unsigned int *res); |
189 | /* control the link power */ | ||
190 | int (*link_power)(struct hdac_bus *bus, bool enable); | ||
191 | }; | ||
192 | |||
193 | /* | ||
194 | * Lowlevel I/O operators | ||
195 | */ | ||
196 | struct hdac_io_ops { | ||
197 | /* mapped register accesses */ | ||
198 | void (*reg_writel)(u32 value, u32 __iomem *addr); | ||
199 | u32 (*reg_readl)(u32 __iomem *addr); | ||
200 | void (*reg_writew)(u16 value, u16 __iomem *addr); | ||
201 | u16 (*reg_readw)(u16 __iomem *addr); | ||
202 | void (*reg_writeb)(u8 value, u8 __iomem *addr); | ||
203 | u8 (*reg_readb)(u8 __iomem *addr); | ||
204 | /* Allocation ops */ | ||
205 | int (*dma_alloc_pages)(struct hdac_bus *bus, int type, size_t size, | ||
206 | struct snd_dma_buffer *buf); | ||
207 | void (*dma_free_pages)(struct hdac_bus *bus, | ||
208 | struct snd_dma_buffer *buf); | ||
172 | }; | 209 | }; |
173 | 210 | ||
174 | #define HDA_UNSOL_QUEUE_SIZE 64 | 211 | #define HDA_UNSOL_QUEUE_SIZE 64 |
212 | #define HDA_MAX_CODECS 8 /* limit by controller side */ | ||
213 | |||
214 | /* HD Audio class code */ | ||
215 | #define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403 | ||
175 | 216 | ||
217 | /* | ||
218 | * CORB/RIRB | ||
219 | * | ||
220 | * Each CORB entry is 4byte, RIRB is 8byte | ||
221 | */ | ||
222 | struct hdac_rb { | ||
223 | __le32 *buf; /* virtual address of CORB/RIRB buffer */ | ||
224 | dma_addr_t addr; /* physical address of CORB/RIRB buffer */ | ||
225 | unsigned short rp, wp; /* RIRB read/write pointers */ | ||
226 | int cmds[HDA_MAX_CODECS]; /* number of pending requests */ | ||
227 | u32 res[HDA_MAX_CODECS]; /* last read value */ | ||
228 | }; | ||
229 | |||
230 | /* | ||
231 | * HD-audio bus base driver | ||
232 | */ | ||
176 | struct hdac_bus { | 233 | struct hdac_bus { |
177 | struct device *dev; | 234 | struct device *dev; |
178 | const struct hdac_bus_ops *ops; | 235 | const struct hdac_bus_ops *ops; |
236 | const struct hdac_io_ops *io_ops; | ||
237 | |||
238 | /* h/w resources */ | ||
239 | unsigned long addr; | ||
240 | void __iomem *remap_addr; | ||
241 | int irq; | ||
179 | 242 | ||
180 | /* codec linked list */ | 243 | /* codec linked list */ |
181 | struct list_head codec_list; | 244 | struct list_head codec_list; |
@@ -189,18 +252,49 @@ struct hdac_bus { | |||
189 | unsigned int unsol_rp, unsol_wp; | 252 | unsigned int unsol_rp, unsol_wp; |
190 | struct work_struct unsol_work; | 253 | struct work_struct unsol_work; |
191 | 254 | ||
255 | /* bit flags of detected codecs */ | ||
256 | unsigned long codec_mask; | ||
257 | |||
192 | /* bit flags of powered codecs */ | 258 | /* bit flags of powered codecs */ |
193 | unsigned long codec_powered; | 259 | unsigned long codec_powered; |
194 | 260 | ||
195 | /* flags */ | 261 | /* CORB/RIRB */ |
262 | struct hdac_rb corb; | ||
263 | struct hdac_rb rirb; | ||
264 | unsigned int last_cmd[HDA_MAX_CODECS]; /* last sent command */ | ||
265 | |||
266 | /* CORB/RIRB and position buffers */ | ||
267 | struct snd_dma_buffer rb; | ||
268 | struct snd_dma_buffer posbuf; | ||
269 | |||
270 | /* hdac_stream linked list */ | ||
271 | struct list_head stream_list; | ||
272 | |||
273 | /* operation state */ | ||
274 | bool chip_init:1; /* h/w initialized */ | ||
275 | |||
276 | /* behavior flags */ | ||
196 | bool sync_write:1; /* sync after verb write */ | 277 | bool sync_write:1; /* sync after verb write */ |
278 | bool use_posbuf:1; /* use position buffer */ | ||
279 | bool snoop:1; /* enable snooping */ | ||
280 | bool align_bdle_4k:1; /* BDLE align 4K boundary */ | ||
281 | bool reverse_assign:1; /* assign devices in reverse order */ | ||
282 | bool corbrp_self_clear:1; /* CORBRP clears itself after reset */ | ||
283 | |||
284 | int bdl_pos_adj; /* BDL position adjustment */ | ||
197 | 285 | ||
198 | /* locks */ | 286 | /* locks */ |
287 | spinlock_t reg_lock; | ||
199 | struct mutex cmd_mutex; | 288 | struct mutex cmd_mutex; |
289 | |||
290 | /* i915 component interface */ | ||
291 | struct i915_audio_component *audio_component; | ||
292 | int i915_power_refcount; | ||
200 | }; | 293 | }; |
201 | 294 | ||
202 | int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev, | 295 | int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev, |
203 | const struct hdac_bus_ops *ops); | 296 | const struct hdac_bus_ops *ops, |
297 | const struct hdac_io_ops *io_ops); | ||
204 | void snd_hdac_bus_exit(struct hdac_bus *bus); | 298 | void snd_hdac_bus_exit(struct hdac_bus *bus); |
205 | int snd_hdac_bus_exec_verb(struct hdac_bus *bus, unsigned int addr, | 299 | int snd_hdac_bus_exec_verb(struct hdac_bus *bus, unsigned int addr, |
206 | unsigned int cmd, unsigned int *res); | 300 | unsigned int cmd, unsigned int *res); |
@@ -222,6 +316,201 @@ static inline void snd_hdac_codec_link_down(struct hdac_device *codec) | |||
222 | clear_bit(codec->addr, &codec->bus->codec_powered); | 316 | clear_bit(codec->addr, &codec->bus->codec_powered); |
223 | } | 317 | } |
224 | 318 | ||
319 | int snd_hdac_bus_send_cmd(struct hdac_bus *bus, unsigned int val); | ||
320 | int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr, | ||
321 | unsigned int *res); | ||
322 | int snd_hdac_link_power(struct hdac_device *codec, bool enable); | ||
323 | |||
324 | bool snd_hdac_bus_init_chip(struct hdac_bus *bus, bool full_reset); | ||
325 | void snd_hdac_bus_stop_chip(struct hdac_bus *bus); | ||
326 | void snd_hdac_bus_init_cmd_io(struct hdac_bus *bus); | ||
327 | void snd_hdac_bus_stop_cmd_io(struct hdac_bus *bus); | ||
328 | void snd_hdac_bus_enter_link_reset(struct hdac_bus *bus); | ||
329 | void snd_hdac_bus_exit_link_reset(struct hdac_bus *bus); | ||
330 | |||
331 | void snd_hdac_bus_update_rirb(struct hdac_bus *bus); | ||
332 | void snd_hdac_bus_handle_stream_irq(struct hdac_bus *bus, unsigned int status, | ||
333 | void (*ack)(struct hdac_bus *, | ||
334 | struct hdac_stream *)); | ||
335 | |||
336 | int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus); | ||
337 | void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus); | ||
338 | |||
339 | /* | ||
340 | * macros for easy use | ||
341 | */ | ||
342 | #define _snd_hdac_chip_write(type, chip, reg, value) \ | ||
343 | ((chip)->io_ops->reg_write ## type(value, (chip)->remap_addr + (reg))) | ||
344 | #define _snd_hdac_chip_read(type, chip, reg) \ | ||
345 | ((chip)->io_ops->reg_read ## type((chip)->remap_addr + (reg))) | ||
346 | |||
347 | /* read/write a register, pass without AZX_REG_ prefix */ | ||
348 | #define snd_hdac_chip_writel(chip, reg, value) \ | ||
349 | _snd_hdac_chip_write(l, chip, AZX_REG_ ## reg, value) | ||
350 | #define snd_hdac_chip_writew(chip, reg, value) \ | ||
351 | _snd_hdac_chip_write(w, chip, AZX_REG_ ## reg, value) | ||
352 | #define snd_hdac_chip_writeb(chip, reg, value) \ | ||
353 | _snd_hdac_chip_write(b, chip, AZX_REG_ ## reg, value) | ||
354 | #define snd_hdac_chip_readl(chip, reg) \ | ||
355 | _snd_hdac_chip_read(l, chip, AZX_REG_ ## reg) | ||
356 | #define snd_hdac_chip_readw(chip, reg) \ | ||
357 | _snd_hdac_chip_read(w, chip, AZX_REG_ ## reg) | ||
358 | #define snd_hdac_chip_readb(chip, reg) \ | ||
359 | _snd_hdac_chip_read(b, chip, AZX_REG_ ## reg) | ||
360 | |||
361 | /* update a register, pass without AZX_REG_ prefix */ | ||
362 | #define snd_hdac_chip_updatel(chip, reg, mask, val) \ | ||
363 | snd_hdac_chip_writel(chip, reg, \ | ||
364 | (snd_hdac_chip_readl(chip, reg) & ~(mask)) | (val)) | ||
365 | #define snd_hdac_chip_updatew(chip, reg, mask, val) \ | ||
366 | snd_hdac_chip_writew(chip, reg, \ | ||
367 | (snd_hdac_chip_readw(chip, reg) & ~(mask)) | (val)) | ||
368 | #define snd_hdac_chip_updateb(chip, reg, mask, val) \ | ||
369 | snd_hdac_chip_writeb(chip, reg, \ | ||
370 | (snd_hdac_chip_readb(chip, reg) & ~(mask)) | (val)) | ||
371 | |||
372 | /* | ||
373 | * HD-audio stream | ||
374 | */ | ||
375 | struct hdac_stream { | ||
376 | struct hdac_bus *bus; | ||
377 | struct snd_dma_buffer bdl; /* BDL buffer */ | ||
378 | __le32 *posbuf; /* position buffer pointer */ | ||
379 | int direction; /* playback / capture (SNDRV_PCM_STREAM_*) */ | ||
380 | |||
381 | unsigned int bufsize; /* size of the play buffer in bytes */ | ||
382 | unsigned int period_bytes; /* size of the period in bytes */ | ||
383 | unsigned int frags; /* number for period in the play buffer */ | ||
384 | unsigned int fifo_size; /* FIFO size */ | ||
385 | |||
386 | void __iomem *sd_addr; /* stream descriptor pointer */ | ||
387 | |||
388 | u32 sd_int_sta_mask; /* stream int status mask */ | ||
389 | |||
390 | /* pcm support */ | ||
391 | struct snd_pcm_substream *substream; /* assigned substream, | ||
392 | * set in PCM open | ||
393 | */ | ||
394 | unsigned int format_val; /* format value to be set in the | ||
395 | * controller and the codec | ||
396 | */ | ||
397 | unsigned char stream_tag; /* assigned stream */ | ||
398 | unsigned char index; /* stream index */ | ||
399 | int assigned_key; /* last device# key assigned to */ | ||
400 | |||
401 | bool opened:1; | ||
402 | bool running:1; | ||
403 | bool prepared:1; | ||
404 | bool no_period_wakeup:1; | ||
405 | bool locked:1; | ||
406 | |||
407 | /* timestamp */ | ||
408 | unsigned long start_wallclk; /* start + minimum wallclk */ | ||
409 | unsigned long period_wallclk; /* wallclk for period */ | ||
410 | struct timecounter tc; | ||
411 | struct cyclecounter cc; | ||
412 | int delay_negative_threshold; | ||
413 | |||
414 | struct list_head list; | ||
415 | #ifdef CONFIG_SND_HDA_DSP_LOADER | ||
416 | /* DSP access mutex */ | ||
417 | struct mutex dsp_mutex; | ||
418 | #endif | ||
419 | }; | ||
420 | |||
421 | void snd_hdac_stream_init(struct hdac_bus *bus, struct hdac_stream *azx_dev, | ||
422 | int idx, int direction, int tag); | ||
423 | struct hdac_stream *snd_hdac_stream_assign(struct hdac_bus *bus, | ||
424 | struct snd_pcm_substream *substream); | ||
425 | void snd_hdac_stream_release(struct hdac_stream *azx_dev); | ||
426 | |||
427 | int snd_hdac_stream_setup(struct hdac_stream *azx_dev); | ||
428 | void snd_hdac_stream_cleanup(struct hdac_stream *azx_dev); | ||
429 | int snd_hdac_stream_setup_periods(struct hdac_stream *azx_dev); | ||
430 | int snd_hdac_stream_set_params(struct hdac_stream *azx_dev, | ||
431 | unsigned int format_val); | ||
432 | void snd_hdac_stream_start(struct hdac_stream *azx_dev, bool fresh_start); | ||
433 | void snd_hdac_stream_clear(struct hdac_stream *azx_dev); | ||
434 | void snd_hdac_stream_stop(struct hdac_stream *azx_dev); | ||
435 | void snd_hdac_stream_reset(struct hdac_stream *azx_dev); | ||
436 | void snd_hdac_stream_sync_trigger(struct hdac_stream *azx_dev, bool set, | ||
437 | unsigned int streams, unsigned int reg); | ||
438 | void snd_hdac_stream_sync(struct hdac_stream *azx_dev, bool start, | ||
439 | unsigned int streams); | ||
440 | void snd_hdac_stream_timecounter_init(struct hdac_stream *azx_dev, | ||
441 | unsigned int streams); | ||
442 | /* | ||
443 | * macros for easy use | ||
444 | */ | ||
445 | #define _snd_hdac_stream_write(type, dev, reg, value) \ | ||
446 | ((dev)->bus->io_ops->reg_write ## type(value, (dev)->sd_addr + (reg))) | ||
447 | #define _snd_hdac_stream_read(type, dev, reg) \ | ||
448 | ((dev)->bus->io_ops->reg_read ## type((dev)->sd_addr + (reg))) | ||
449 | |||
450 | /* read/write a register, pass without AZX_REG_ prefix */ | ||
451 | #define snd_hdac_stream_writel(dev, reg, value) \ | ||
452 | _snd_hdac_stream_write(l, dev, AZX_REG_ ## reg, value) | ||
453 | #define snd_hdac_stream_writew(dev, reg, value) \ | ||
454 | _snd_hdac_stream_write(w, dev, AZX_REG_ ## reg, value) | ||
455 | #define snd_hdac_stream_writeb(dev, reg, value) \ | ||
456 | _snd_hdac_stream_write(b, dev, AZX_REG_ ## reg, value) | ||
457 | #define snd_hdac_stream_readl(dev, reg) \ | ||
458 | _snd_hdac_stream_read(l, dev, AZX_REG_ ## reg) | ||
459 | #define snd_hdac_stream_readw(dev, reg) \ | ||
460 | _snd_hdac_stream_read(w, dev, AZX_REG_ ## reg) | ||
461 | #define snd_hdac_stream_readb(dev, reg) \ | ||
462 | _snd_hdac_stream_read(b, dev, AZX_REG_ ## reg) | ||
463 | |||
464 | /* update a register, pass without AZX_REG_ prefix */ | ||
465 | #define snd_hdac_stream_updatel(dev, reg, mask, val) \ | ||
466 | snd_hdac_stream_writel(dev, reg, \ | ||
467 | (snd_hdac_stream_readl(dev, reg) & \ | ||
468 | ~(mask)) | (val)) | ||
469 | #define snd_hdac_stream_updatew(dev, reg, mask, val) \ | ||
470 | snd_hdac_stream_writew(dev, reg, \ | ||
471 | (snd_hdac_stream_readw(dev, reg) & \ | ||
472 | ~(mask)) | (val)) | ||
473 | #define snd_hdac_stream_updateb(dev, reg, mask, val) \ | ||
474 | snd_hdac_stream_writeb(dev, reg, \ | ||
475 | (snd_hdac_stream_readb(dev, reg) & \ | ||
476 | ~(mask)) | (val)) | ||
477 | |||
478 | #ifdef CONFIG_SND_HDA_DSP_LOADER | ||
479 | /* DSP lock helpers */ | ||
480 | #define snd_hdac_dsp_lock_init(dev) mutex_init(&(dev)->dsp_mutex) | ||
481 | #define snd_hdac_dsp_lock(dev) mutex_lock(&(dev)->dsp_mutex) | ||
482 | #define snd_hdac_dsp_unlock(dev) mutex_unlock(&(dev)->dsp_mutex) | ||
483 | #define snd_hdac_stream_is_locked(dev) ((dev)->locked) | ||
484 | /* DSP loader helpers */ | ||
485 | int snd_hdac_dsp_prepare(struct hdac_stream *azx_dev, unsigned int format, | ||
486 | unsigned int byte_size, struct snd_dma_buffer *bufp); | ||
487 | void snd_hdac_dsp_trigger(struct hdac_stream *azx_dev, bool start); | ||
488 | void snd_hdac_dsp_cleanup(struct hdac_stream *azx_dev, | ||
489 | struct snd_dma_buffer *dmab); | ||
490 | #else /* CONFIG_SND_HDA_DSP_LOADER */ | ||
491 | #define snd_hdac_dsp_lock_init(dev) do {} while (0) | ||
492 | #define snd_hdac_dsp_lock(dev) do {} while (0) | ||
493 | #define snd_hdac_dsp_unlock(dev) do {} while (0) | ||
494 | #define snd_hdac_stream_is_locked(dev) 0 | ||
495 | |||
496 | static inline int | ||
497 | snd_hdac_dsp_prepare(struct hdac_stream *azx_dev, unsigned int format, | ||
498 | unsigned int byte_size, struct snd_dma_buffer *bufp) | ||
499 | { | ||
500 | return 0; | ||
501 | } | ||
502 | |||
503 | static inline void snd_hdac_dsp_trigger(struct hdac_stream *azx_dev, bool start) | ||
504 | { | ||
505 | } | ||
506 | |||
507 | static inline void snd_hdac_dsp_cleanup(struct hdac_stream *azx_dev, | ||
508 | struct snd_dma_buffer *dmab) | ||
509 | { | ||
510 | } | ||
511 | #endif /* CONFIG_SND_HDA_DSP_LOADER */ | ||
512 | |||
513 | |||
225 | /* | 514 | /* |
226 | * generic array helpers | 515 | * generic array helpers |
227 | */ | 516 | */ |
diff --git a/include/sound/info.h b/include/sound/info.h index 9ca1a493d370..16269951bafc 100644 --- a/include/sound/info.h +++ b/include/sound/info.h | |||
@@ -23,6 +23,8 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <linux/poll.h> | 25 | #include <linux/poll.h> |
26 | #include <linux/seq_file.h> | ||
27 | #include <sound/core.h> | ||
26 | 28 | ||
27 | /* buffer for information */ | 29 | /* buffer for information */ |
28 | struct snd_info_buffer { | 30 | struct snd_info_buffer { |
@@ -92,10 +94,8 @@ struct snd_info_entry { | |||
92 | 94 | ||
93 | #if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_PROC_FS) | 95 | #if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_PROC_FS) |
94 | int snd_info_minor_register(void); | 96 | int snd_info_minor_register(void); |
95 | int snd_info_minor_unregister(void); | ||
96 | #else | 97 | #else |
97 | #define snd_info_minor_register() /* NOP */ | 98 | #define snd_info_minor_register() 0 |
98 | #define snd_info_minor_unregister() /* NOP */ | ||
99 | #endif | 99 | #endif |
100 | 100 | ||
101 | 101 | ||
@@ -110,8 +110,18 @@ void snd_card_info_read_oss(struct snd_info_buffer *buffer); | |||
110 | static inline void snd_card_info_read_oss(struct snd_info_buffer *buffer) {} | 110 | static inline void snd_card_info_read_oss(struct snd_info_buffer *buffer) {} |
111 | #endif | 111 | #endif |
112 | 112 | ||
113 | __printf(2, 3) | 113 | /** |
114 | int snd_iprintf(struct snd_info_buffer *buffer, const char *fmt, ...); | 114 | * snd_iprintf - printf on the procfs buffer |
115 | * @buf: the procfs buffer | ||
116 | * @fmt: the printf format | ||
117 | * | ||
118 | * Outputs the string on the procfs buffer just like printf(). | ||
119 | * | ||
120 | * Return: zero for success, or a negative error code. | ||
121 | */ | ||
122 | #define snd_iprintf(buf, fmt, args...) \ | ||
123 | seq_printf((struct seq_file *)(buf)->buffer, fmt, ##args) | ||
124 | |||
115 | int snd_info_init(void); | 125 | int snd_info_init(void); |
116 | int snd_info_done(void); | 126 | int snd_info_done(void); |
117 | 127 | ||
@@ -135,8 +145,12 @@ void snd_info_card_id_change(struct snd_card *card); | |||
135 | int snd_info_register(struct snd_info_entry *entry); | 145 | int snd_info_register(struct snd_info_entry *entry); |
136 | 146 | ||
137 | /* for card drivers */ | 147 | /* for card drivers */ |
138 | int snd_card_proc_new(struct snd_card *card, const char *name, | 148 | static inline int snd_card_proc_new(struct snd_card *card, const char *name, |
139 | struct snd_info_entry **entryp); | 149 | struct snd_info_entry **entryp) |
150 | { | ||
151 | *entryp = snd_info_create_card_entry(card, name, card->proc_root); | ||
152 | return *entryp ? 0 : -ENOMEM; | ||
153 | } | ||
140 | 154 | ||
141 | static inline void snd_info_set_text_ops(struct snd_info_entry *entry, | 155 | static inline void snd_info_set_text_ops(struct snd_info_entry *entry, |
142 | void *private_data, | 156 | void *private_data, |
@@ -175,7 +189,6 @@ static inline int snd_card_proc_new(struct snd_card *card, const char *name, | |||
175 | static inline void snd_info_set_text_ops(struct snd_info_entry *entry __attribute__((unused)), | 189 | static inline void snd_info_set_text_ops(struct snd_info_entry *entry __attribute__((unused)), |
176 | void *private_data, | 190 | void *private_data, |
177 | void (*read)(struct snd_info_entry *, struct snd_info_buffer *)) {} | 191 | void (*read)(struct snd_info_entry *, struct snd_info_buffer *)) {} |
178 | |||
179 | static inline int snd_info_check_reserved_words(const char *str) { return 1; } | 192 | static inline int snd_info_check_reserved_words(const char *str) { return 1; } |
180 | 193 | ||
181 | #endif | 194 | #endif |
diff --git a/include/sound/jack.h b/include/sound/jack.h index 218235030ebc..23bede121c78 100644 --- a/include/sound/jack.h +++ b/include/sound/jack.h | |||
@@ -73,6 +73,8 @@ enum snd_jack_types { | |||
73 | 73 | ||
74 | struct snd_jack { | 74 | struct snd_jack { |
75 | struct input_dev *input_dev; | 75 | struct input_dev *input_dev; |
76 | struct list_head kctl_list; | ||
77 | struct snd_card *card; | ||
76 | int registered; | 78 | int registered; |
77 | int type; | 79 | int type; |
78 | const char *id; | 80 | const char *id; |
@@ -85,7 +87,8 @@ struct snd_jack { | |||
85 | #ifdef CONFIG_SND_JACK | 87 | #ifdef CONFIG_SND_JACK |
86 | 88 | ||
87 | int snd_jack_new(struct snd_card *card, const char *id, int type, | 89 | int snd_jack_new(struct snd_card *card, const char *id, int type, |
88 | struct snd_jack **jack); | 90 | struct snd_jack **jack, bool initial_kctl, bool phantom_jack); |
91 | int snd_jack_add_new_kctl(struct snd_jack *jack, const char * name, int mask); | ||
89 | void snd_jack_set_parent(struct snd_jack *jack, struct device *parent); | 92 | void snd_jack_set_parent(struct snd_jack *jack, struct device *parent); |
90 | int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type, | 93 | int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type, |
91 | int keytype); | 94 | int keytype); |
@@ -93,9 +96,13 @@ int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type, | |||
93 | void snd_jack_report(struct snd_jack *jack, int status); | 96 | void snd_jack_report(struct snd_jack *jack, int status); |
94 | 97 | ||
95 | #else | 98 | #else |
96 | |||
97 | static inline int snd_jack_new(struct snd_card *card, const char *id, int type, | 99 | static inline int snd_jack_new(struct snd_card *card, const char *id, int type, |
98 | struct snd_jack **jack) | 100 | struct snd_jack **jack, bool initial_kctl, bool phantom_jack) |
101 | { | ||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | static inline int snd_jack_add_new_kctl(struct snd_jack *jack, const char * name, int mask) | ||
99 | { | 106 | { |
100 | return 0; | 107 | return 0; |
101 | } | 108 | } |
diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 0cb7f3f5df7b..691e7ee0a510 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h | |||
@@ -224,9 +224,10 @@ typedef int (*snd_pcm_hw_rule_func_t)(struct snd_pcm_hw_params *params, | |||
224 | 224 | ||
225 | struct snd_pcm_hw_rule { | 225 | struct snd_pcm_hw_rule { |
226 | unsigned int cond; | 226 | unsigned int cond; |
227 | snd_pcm_hw_rule_func_t func; | ||
228 | int var; | 227 | int var; |
229 | int deps[4]; | 228 | int deps[4]; |
229 | |||
230 | snd_pcm_hw_rule_func_t func; | ||
230 | void *private; | 231 | void *private; |
231 | }; | 232 | }; |
232 | 233 | ||
@@ -273,8 +274,8 @@ struct snd_pcm_hw_constraint_ratdens { | |||
273 | }; | 274 | }; |
274 | 275 | ||
275 | struct snd_pcm_hw_constraint_list { | 276 | struct snd_pcm_hw_constraint_list { |
276 | unsigned int count; | ||
277 | const unsigned int *list; | 277 | const unsigned int *list; |
278 | unsigned int count; | ||
278 | unsigned int mask; | 279 | unsigned int mask; |
279 | }; | 280 | }; |
280 | 281 | ||
diff --git a/sound/core/Kconfig b/sound/core/Kconfig index 1507469425ec..937f5c763899 100644 --- a/sound/core/Kconfig +++ b/sound/core/Kconfig | |||
@@ -227,9 +227,6 @@ config SND_PCM_XRUN_DEBUG | |||
227 | config SND_VMASTER | 227 | config SND_VMASTER |
228 | bool | 228 | bool |
229 | 229 | ||
230 | config SND_KCTL_JACK | ||
231 | bool | ||
232 | |||
233 | config SND_DMA_SGBUF | 230 | config SND_DMA_SGBUF |
234 | def_bool y | 231 | def_bool y |
235 | depends on X86 | 232 | depends on X86 |
diff --git a/sound/core/Makefile b/sound/core/Makefile index 2b925fcc95ea..73871b63a092 100644 --- a/sound/core/Makefile +++ b/sound/core/Makefile | |||
@@ -3,12 +3,15 @@ | |||
3 | # Copyright (c) 1999,2001 by Jaroslav Kysela <perex@perex.cz> | 3 | # Copyright (c) 1999,2001 by Jaroslav Kysela <perex@perex.cz> |
4 | # | 4 | # |
5 | 5 | ||
6 | snd-y := sound.o init.o memory.o info.o control.o misc.o device.o | 6 | snd-y := sound.o init.o memory.o control.o misc.o device.o |
7 | ifneq ($(CONFIG_PROC_FS),) | ||
8 | snd-y += info.o | ||
9 | snd-$(CONFIG_SND_OSSEMUL) += info_oss.o | ||
10 | endif | ||
7 | snd-$(CONFIG_ISA_DMA_API) += isadma.o | 11 | snd-$(CONFIG_ISA_DMA_API) += isadma.o |
8 | snd-$(CONFIG_SND_OSSEMUL) += sound_oss.o info_oss.o | 12 | snd-$(CONFIG_SND_OSSEMUL) += sound_oss.o |
9 | snd-$(CONFIG_SND_VMASTER) += vmaster.o | 13 | snd-$(CONFIG_SND_VMASTER) += vmaster.o |
10 | snd-$(CONFIG_SND_KCTL_JACK) += ctljack.o | 14 | snd-$(CONFIG_SND_JACK) += ctljack.o jack.o |
11 | snd-$(CONFIG_SND_JACK) += jack.o | ||
12 | 15 | ||
13 | snd-pcm-y := pcm.o pcm_native.o pcm_lib.o pcm_timer.o pcm_misc.o \ | 16 | snd-pcm-y := pcm.o pcm_native.o pcm_lib.o pcm_timer.o pcm_misc.o \ |
14 | pcm_memory.o memalloc.o | 17 | pcm_memory.o memalloc.o |
diff --git a/sound/core/ctljack.c b/sound/core/ctljack.c index e4b38fbe51da..8f8d1033425c 100644 --- a/sound/core/ctljack.c +++ b/sound/core/ctljack.c | |||
@@ -31,19 +31,49 @@ static struct snd_kcontrol_new jack_detect_kctl = { | |||
31 | .get = jack_detect_kctl_get, | 31 | .get = jack_detect_kctl_get, |
32 | }; | 32 | }; |
33 | 33 | ||
34 | static int get_available_index(struct snd_card *card, const char *name) | ||
35 | { | ||
36 | struct snd_ctl_elem_id sid; | ||
37 | |||
38 | memset(&sid, 0, sizeof(sid)); | ||
39 | |||
40 | sid.index = 0; | ||
41 | sid.iface = SNDRV_CTL_ELEM_IFACE_CARD; | ||
42 | strlcpy(sid.name, name, sizeof(sid.name)); | ||
43 | |||
44 | while (snd_ctl_find_id(card, &sid)) | ||
45 | sid.index++; | ||
46 | |||
47 | return sid.index; | ||
48 | } | ||
49 | |||
50 | static void jack_kctl_name_gen(char *name, const char *src_name, int size) | ||
51 | { | ||
52 | size_t count = strlen(src_name); | ||
53 | bool need_cat = true; | ||
54 | |||
55 | /* remove redundant " Jack" from src_name */ | ||
56 | if (count >= 5) | ||
57 | need_cat = strncmp(&src_name[count - 5], " Jack", 5) ? true : false; | ||
58 | |||
59 | snprintf(name, size, need_cat ? "%s Jack" : "%s", src_name); | ||
60 | |||
61 | } | ||
62 | |||
34 | struct snd_kcontrol * | 63 | struct snd_kcontrol * |
35 | snd_kctl_jack_new(const char *name, int idx, void *private_data) | 64 | snd_kctl_jack_new(const char *name, struct snd_card *card) |
36 | { | 65 | { |
37 | struct snd_kcontrol *kctl; | 66 | struct snd_kcontrol *kctl; |
38 | kctl = snd_ctl_new1(&jack_detect_kctl, private_data); | 67 | |
68 | kctl = snd_ctl_new1(&jack_detect_kctl, NULL); | ||
39 | if (!kctl) | 69 | if (!kctl) |
40 | return NULL; | 70 | return NULL; |
41 | snprintf(kctl->id.name, sizeof(kctl->id.name), "%s Jack", name); | 71 | |
42 | kctl->id.index = idx; | 72 | jack_kctl_name_gen(kctl->id.name, name, sizeof(kctl->id.name)); |
73 | kctl->id.index = get_available_index(card, name); | ||
43 | kctl->private_value = 0; | 74 | kctl->private_value = 0; |
44 | return kctl; | 75 | return kctl; |
45 | } | 76 | } |
46 | EXPORT_SYMBOL_GPL(snd_kctl_jack_new); | ||
47 | 77 | ||
48 | void snd_kctl_jack_report(struct snd_card *card, | 78 | void snd_kctl_jack_report(struct snd_card *card, |
49 | struct snd_kcontrol *kctl, bool status) | 79 | struct snd_kcontrol *kctl, bool status) |
@@ -53,4 +83,3 @@ void snd_kctl_jack_report(struct snd_card *card, | |||
53 | kctl->private_value = status; | 83 | kctl->private_value = status; |
54 | snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); | 84 | snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); |
55 | } | 85 | } |
56 | EXPORT_SYMBOL_GPL(snd_kctl_jack_report); | ||
diff --git a/sound/core/info.c b/sound/core/info.c index 9f404e965ea2..895362a696c9 100644 --- a/sound/core/info.c +++ b/sound/core/info.c | |||
@@ -33,12 +33,6 @@ | |||
33 | #include <linux/mutex.h> | 33 | #include <linux/mutex.h> |
34 | #include <stdarg.h> | 34 | #include <stdarg.h> |
35 | 35 | ||
36 | /* | ||
37 | * | ||
38 | */ | ||
39 | |||
40 | #ifdef CONFIG_PROC_FS | ||
41 | |||
42 | int snd_info_check_reserved_words(const char *str) | 36 | int snd_info_check_reserved_words(const char *str) |
43 | { | 37 | { |
44 | static char *reserved[] = | 38 | static char *reserved[] = |
@@ -78,81 +72,51 @@ struct snd_info_private_data { | |||
78 | }; | 72 | }; |
79 | 73 | ||
80 | static int snd_info_version_init(void); | 74 | static int snd_info_version_init(void); |
81 | static int snd_info_version_done(void); | ||
82 | static void snd_info_disconnect(struct snd_info_entry *entry); | 75 | static void snd_info_disconnect(struct snd_info_entry *entry); |
83 | 76 | ||
77 | /* | ||
84 | 78 | ||
85 | /* resize the proc r/w buffer */ | 79 | */ |
86 | static int resize_info_buffer(struct snd_info_buffer *buffer, | ||
87 | unsigned int nsize) | ||
88 | { | ||
89 | char *nbuf; | ||
90 | 80 | ||
91 | nsize = PAGE_ALIGN(nsize); | 81 | static struct snd_info_entry *snd_proc_root; |
92 | nbuf = krealloc(buffer->buffer, nsize, GFP_KERNEL | __GFP_ZERO); | 82 | struct snd_info_entry *snd_seq_root; |
93 | if (! nbuf) | 83 | EXPORT_SYMBOL(snd_seq_root); |
94 | return -ENOMEM; | ||
95 | 84 | ||
96 | buffer->buffer = nbuf; | 85 | #ifdef CONFIG_SND_OSSEMUL |
97 | buffer->len = nsize; | 86 | struct snd_info_entry *snd_oss_root; |
98 | return 0; | 87 | #endif |
99 | } | ||
100 | 88 | ||
101 | /** | 89 | static int alloc_info_private(struct snd_info_entry *entry, |
102 | * snd_iprintf - printf on the procfs buffer | 90 | struct snd_info_private_data **ret) |
103 | * @buffer: the procfs buffer | ||
104 | * @fmt: the printf format | ||
105 | * | ||
106 | * Outputs the string on the procfs buffer just like printf(). | ||
107 | * | ||
108 | * Return: The size of output string, or a negative error code. | ||
109 | */ | ||
110 | int snd_iprintf(struct snd_info_buffer *buffer, const char *fmt, ...) | ||
111 | { | 91 | { |
112 | va_list args; | 92 | struct snd_info_private_data *data; |
113 | int len, res; | ||
114 | int err = 0; | ||
115 | 93 | ||
116 | might_sleep(); | 94 | if (!entry || !entry->p) |
117 | if (buffer->stop || buffer->error) | 95 | return -ENODEV; |
118 | return 0; | 96 | if (!try_module_get(entry->module)) |
119 | len = buffer->len - buffer->size; | 97 | return -EFAULT; |
120 | va_start(args, fmt); | 98 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
121 | for (;;) { | 99 | if (!data) { |
122 | va_list ap; | 100 | module_put(entry->module); |
123 | va_copy(ap, args); | 101 | return -ENOMEM; |
124 | res = vsnprintf(buffer->buffer + buffer->curr, len, fmt, ap); | ||
125 | va_end(ap); | ||
126 | if (res < len) | ||
127 | break; | ||
128 | err = resize_info_buffer(buffer, buffer->len + PAGE_SIZE); | ||
129 | if (err < 0) | ||
130 | break; | ||
131 | len = buffer->len - buffer->size; | ||
132 | } | 102 | } |
133 | va_end(args); | 103 | data->entry = entry; |
134 | 104 | *ret = data; | |
135 | if (err < 0) | 105 | return 0; |
136 | return err; | ||
137 | buffer->curr += res; | ||
138 | buffer->size += res; | ||
139 | return res; | ||
140 | } | 106 | } |
141 | 107 | ||
142 | EXPORT_SYMBOL(snd_iprintf); | 108 | static bool valid_pos(loff_t pos, size_t count) |
109 | { | ||
110 | if (pos < 0 || (long) pos != pos || (ssize_t) count < 0) | ||
111 | return false; | ||
112 | if ((unsigned long) pos + (unsigned long) count < (unsigned long) pos) | ||
113 | return false; | ||
114 | return true; | ||
115 | } | ||
143 | 116 | ||
144 | /* | 117 | /* |
145 | 118 | * file ops for binary proc files | |
146 | */ | 119 | */ |
147 | |||
148 | static struct proc_dir_entry *snd_proc_root; | ||
149 | struct snd_info_entry *snd_seq_root; | ||
150 | EXPORT_SYMBOL(snd_seq_root); | ||
151 | |||
152 | #ifdef CONFIG_SND_OSSEMUL | ||
153 | struct snd_info_entry *snd_oss_root; | ||
154 | #endif | ||
155 | |||
156 | static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig) | 120 | static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig) |
157 | { | 121 | { |
158 | struct snd_info_private_data *data; | 122 | struct snd_info_private_data *data; |
@@ -162,17 +126,14 @@ static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig) | |||
162 | data = file->private_data; | 126 | data = file->private_data; |
163 | entry = data->entry; | 127 | entry = data->entry; |
164 | mutex_lock(&entry->access); | 128 | mutex_lock(&entry->access); |
165 | if (entry->content == SNDRV_INFO_CONTENT_DATA && | 129 | if (entry->c.ops->llseek) { |
166 | entry->c.ops->llseek) { | ||
167 | offset = entry->c.ops->llseek(entry, | 130 | offset = entry->c.ops->llseek(entry, |
168 | data->file_private_data, | 131 | data->file_private_data, |
169 | file, offset, orig); | 132 | file, offset, orig); |
170 | goto out; | 133 | goto out; |
171 | } | 134 | } |
172 | if (entry->content == SNDRV_INFO_CONTENT_DATA) | 135 | |
173 | size = entry->size; | 136 | size = entry->size; |
174 | else | ||
175 | size = 0; | ||
176 | switch (orig) { | 137 | switch (orig) { |
177 | case SEEK_SET: | 138 | case SEEK_SET: |
178 | break; | 139 | break; |
@@ -201,45 +162,20 @@ static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig) | |||
201 | static ssize_t snd_info_entry_read(struct file *file, char __user *buffer, | 162 | static ssize_t snd_info_entry_read(struct file *file, char __user *buffer, |
202 | size_t count, loff_t * offset) | 163 | size_t count, loff_t * offset) |
203 | { | 164 | { |
204 | struct snd_info_private_data *data; | 165 | struct snd_info_private_data *data = file->private_data; |
205 | struct snd_info_entry *entry; | 166 | struct snd_info_entry *entry = data->entry; |
206 | struct snd_info_buffer *buf; | 167 | size_t size; |
207 | size_t size = 0; | ||
208 | loff_t pos; | 168 | loff_t pos; |
209 | 169 | ||
210 | data = file->private_data; | ||
211 | if (snd_BUG_ON(!data)) | ||
212 | return -ENXIO; | ||
213 | pos = *offset; | 170 | pos = *offset; |
214 | if (pos < 0 || (long) pos != pos || (ssize_t) count < 0) | 171 | if (!valid_pos(pos, count)) |
215 | return -EIO; | ||
216 | if ((unsigned long) pos + (unsigned long) count < (unsigned long) pos) | ||
217 | return -EIO; | 172 | return -EIO; |
218 | entry = data->entry; | 173 | if (pos >= entry->size) |
219 | switch (entry->content) { | 174 | return 0; |
220 | case SNDRV_INFO_CONTENT_TEXT: | 175 | size = entry->size - pos; |
221 | buf = data->rbuffer; | 176 | size = min(count, size); |
222 | if (buf == NULL) | 177 | size = entry->c.ops->read(entry, data->file_private_data, |
223 | return -EIO; | 178 | file, buffer, size, pos); |
224 | if (pos >= buf->size) | ||
225 | return 0; | ||
226 | size = buf->size - pos; | ||
227 | size = min(count, size); | ||
228 | if (copy_to_user(buffer, buf->buffer + pos, size)) | ||
229 | return -EFAULT; | ||
230 | break; | ||
231 | case SNDRV_INFO_CONTENT_DATA: | ||
232 | if (pos >= entry->size) | ||
233 | return 0; | ||
234 | if (entry->c.ops->read) { | ||
235 | size = entry->size - pos; | ||
236 | size = min(count, size); | ||
237 | size = entry->c.ops->read(entry, | ||
238 | data->file_private_data, | ||
239 | file, buffer, size, pos); | ||
240 | } | ||
241 | break; | ||
242 | } | ||
243 | if ((ssize_t) size > 0) | 179 | if ((ssize_t) size > 0) |
244 | *offset = pos + size; | 180 | *offset = pos + size; |
245 | return size; | 181 | return size; |
@@ -248,347 +184,319 @@ static ssize_t snd_info_entry_read(struct file *file, char __user *buffer, | |||
248 | static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer, | 184 | static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer, |
249 | size_t count, loff_t * offset) | 185 | size_t count, loff_t * offset) |
250 | { | 186 | { |
251 | struct snd_info_private_data *data; | 187 | struct snd_info_private_data *data = file->private_data; |
252 | struct snd_info_entry *entry; | 188 | struct snd_info_entry *entry = data->entry; |
253 | struct snd_info_buffer *buf; | ||
254 | ssize_t size = 0; | 189 | ssize_t size = 0; |
255 | loff_t pos; | 190 | loff_t pos; |
256 | 191 | ||
257 | data = file->private_data; | ||
258 | if (snd_BUG_ON(!data)) | ||
259 | return -ENXIO; | ||
260 | entry = data->entry; | ||
261 | pos = *offset; | 192 | pos = *offset; |
262 | if (pos < 0 || (long) pos != pos || (ssize_t) count < 0) | 193 | if (!valid_pos(pos, count)) |
263 | return -EIO; | ||
264 | if ((unsigned long) pos + (unsigned long) count < (unsigned long) pos) | ||
265 | return -EIO; | 194 | return -EIO; |
266 | switch (entry->content) { | 195 | if (count > 0) { |
267 | case SNDRV_INFO_CONTENT_TEXT: | 196 | size_t maxsize = entry->size - pos; |
268 | buf = data->wbuffer; | 197 | count = min(count, maxsize); |
269 | if (buf == NULL) | 198 | size = entry->c.ops->write(entry, data->file_private_data, |
270 | return -EIO; | 199 | file, buffer, count, pos); |
271 | mutex_lock(&entry->access); | ||
272 | if (pos + count >= buf->len) { | ||
273 | if (resize_info_buffer(buf, pos + count)) { | ||
274 | mutex_unlock(&entry->access); | ||
275 | return -ENOMEM; | ||
276 | } | ||
277 | } | ||
278 | if (copy_from_user(buf->buffer + pos, buffer, count)) { | ||
279 | mutex_unlock(&entry->access); | ||
280 | return -EFAULT; | ||
281 | } | ||
282 | buf->size = pos + count; | ||
283 | mutex_unlock(&entry->access); | ||
284 | size = count; | ||
285 | break; | ||
286 | case SNDRV_INFO_CONTENT_DATA: | ||
287 | if (entry->c.ops->write && count > 0) { | ||
288 | size_t maxsize = entry->size - pos; | ||
289 | count = min(count, maxsize); | ||
290 | size = entry->c.ops->write(entry, | ||
291 | data->file_private_data, | ||
292 | file, buffer, count, pos); | ||
293 | } | ||
294 | break; | ||
295 | } | 200 | } |
296 | if ((ssize_t) size > 0) | 201 | if (size > 0) |
297 | *offset = pos + size; | 202 | *offset = pos + size; |
298 | return size; | 203 | return size; |
299 | } | 204 | } |
300 | 205 | ||
301 | static int snd_info_entry_open(struct inode *inode, struct file *file) | 206 | static unsigned int snd_info_entry_poll(struct file *file, poll_table *wait) |
302 | { | 207 | { |
208 | struct snd_info_private_data *data = file->private_data; | ||
209 | struct snd_info_entry *entry = data->entry; | ||
210 | unsigned int mask = 0; | ||
211 | |||
212 | if (entry->c.ops->poll) | ||
213 | return entry->c.ops->poll(entry, | ||
214 | data->file_private_data, | ||
215 | file, wait); | ||
216 | if (entry->c.ops->read) | ||
217 | mask |= POLLIN | POLLRDNORM; | ||
218 | if (entry->c.ops->write) | ||
219 | mask |= POLLOUT | POLLWRNORM; | ||
220 | return mask; | ||
221 | } | ||
222 | |||
223 | static long snd_info_entry_ioctl(struct file *file, unsigned int cmd, | ||
224 | unsigned long arg) | ||
225 | { | ||
226 | struct snd_info_private_data *data = file->private_data; | ||
227 | struct snd_info_entry *entry = data->entry; | ||
228 | |||
229 | if (!entry->c.ops->ioctl) | ||
230 | return -ENOTTY; | ||
231 | return entry->c.ops->ioctl(entry, data->file_private_data, | ||
232 | file, cmd, arg); | ||
233 | } | ||
234 | |||
235 | static int snd_info_entry_mmap(struct file *file, struct vm_area_struct *vma) | ||
236 | { | ||
237 | struct inode *inode = file_inode(file); | ||
238 | struct snd_info_private_data *data; | ||
303 | struct snd_info_entry *entry; | 239 | struct snd_info_entry *entry; |
240 | |||
241 | data = file->private_data; | ||
242 | if (data == NULL) | ||
243 | return 0; | ||
244 | entry = data->entry; | ||
245 | if (!entry->c.ops->mmap) | ||
246 | return -ENXIO; | ||
247 | return entry->c.ops->mmap(entry, data->file_private_data, | ||
248 | inode, file, vma); | ||
249 | } | ||
250 | |||
251 | static int snd_info_entry_open(struct inode *inode, struct file *file) | ||
252 | { | ||
253 | struct snd_info_entry *entry = PDE_DATA(inode); | ||
304 | struct snd_info_private_data *data; | 254 | struct snd_info_private_data *data; |
305 | struct snd_info_buffer *buffer; | ||
306 | int mode, err; | 255 | int mode, err; |
307 | 256 | ||
308 | mutex_lock(&info_mutex); | 257 | mutex_lock(&info_mutex); |
309 | entry = PDE_DATA(inode); | 258 | err = alloc_info_private(entry, &data); |
310 | if (entry == NULL || ! entry->p) { | 259 | if (err < 0) |
311 | mutex_unlock(&info_mutex); | 260 | goto unlock; |
312 | return -ENODEV; | 261 | |
313 | } | ||
314 | if (!try_module_get(entry->module)) { | ||
315 | err = -EFAULT; | ||
316 | goto __error1; | ||
317 | } | ||
318 | mode = file->f_flags & O_ACCMODE; | 262 | mode = file->f_flags & O_ACCMODE; |
319 | if (mode == O_RDONLY || mode == O_RDWR) { | 263 | if (((mode == O_RDONLY || mode == O_RDWR) && !entry->c.ops->read) || |
320 | if ((entry->content == SNDRV_INFO_CONTENT_DATA && | 264 | ((mode == O_WRONLY || mode == O_RDWR) && !entry->c.ops->write)) { |
321 | entry->c.ops->read == NULL)) { | 265 | err = -ENODEV; |
322 | err = -ENODEV; | 266 | goto error; |
323 | goto __error; | ||
324 | } | ||
325 | } | 267 | } |
326 | if (mode == O_WRONLY || mode == O_RDWR) { | 268 | |
327 | if ((entry->content == SNDRV_INFO_CONTENT_DATA && | 269 | if (entry->c.ops->open) { |
328 | entry->c.ops->write == NULL)) { | 270 | err = entry->c.ops->open(entry, mode, &data->file_private_data); |
329 | err = -ENODEV; | 271 | if (err < 0) |
330 | goto __error; | 272 | goto error; |
331 | } | ||
332 | } | ||
333 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
334 | if (data == NULL) { | ||
335 | err = -ENOMEM; | ||
336 | goto __error; | ||
337 | } | ||
338 | data->entry = entry; | ||
339 | switch (entry->content) { | ||
340 | case SNDRV_INFO_CONTENT_TEXT: | ||
341 | if (mode == O_RDONLY || mode == O_RDWR) { | ||
342 | buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); | ||
343 | if (buffer == NULL) | ||
344 | goto __nomem; | ||
345 | data->rbuffer = buffer; | ||
346 | buffer->len = PAGE_SIZE; | ||
347 | buffer->buffer = kzalloc(buffer->len, GFP_KERNEL); | ||
348 | if (buffer->buffer == NULL) | ||
349 | goto __nomem; | ||
350 | } | ||
351 | if (mode == O_WRONLY || mode == O_RDWR) { | ||
352 | buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); | ||
353 | if (buffer == NULL) | ||
354 | goto __nomem; | ||
355 | data->wbuffer = buffer; | ||
356 | buffer->len = PAGE_SIZE; | ||
357 | buffer->buffer = kmalloc(buffer->len, GFP_KERNEL); | ||
358 | if (buffer->buffer == NULL) | ||
359 | goto __nomem; | ||
360 | } | ||
361 | break; | ||
362 | case SNDRV_INFO_CONTENT_DATA: /* data */ | ||
363 | if (entry->c.ops->open) { | ||
364 | if ((err = entry->c.ops->open(entry, mode, | ||
365 | &data->file_private_data)) < 0) { | ||
366 | kfree(data); | ||
367 | goto __error; | ||
368 | } | ||
369 | } | ||
370 | break; | ||
371 | } | 273 | } |
274 | |||
372 | file->private_data = data; | 275 | file->private_data = data; |
373 | mutex_unlock(&info_mutex); | 276 | mutex_unlock(&info_mutex); |
374 | if (entry->content == SNDRV_INFO_CONTENT_TEXT && | ||
375 | (mode == O_RDONLY || mode == O_RDWR)) { | ||
376 | if (entry->c.text.read) { | ||
377 | mutex_lock(&entry->access); | ||
378 | entry->c.text.read(entry, data->rbuffer); | ||
379 | mutex_unlock(&entry->access); | ||
380 | } | ||
381 | } | ||
382 | return 0; | 277 | return 0; |
383 | 278 | ||
384 | __nomem: | 279 | error: |
385 | if (data->rbuffer) { | ||
386 | kfree(data->rbuffer->buffer); | ||
387 | kfree(data->rbuffer); | ||
388 | } | ||
389 | if (data->wbuffer) { | ||
390 | kfree(data->wbuffer->buffer); | ||
391 | kfree(data->wbuffer); | ||
392 | } | ||
393 | kfree(data); | 280 | kfree(data); |
394 | err = -ENOMEM; | ||
395 | __error: | ||
396 | module_put(entry->module); | 281 | module_put(entry->module); |
397 | __error1: | 282 | unlock: |
398 | mutex_unlock(&info_mutex); | 283 | mutex_unlock(&info_mutex); |
399 | return err; | 284 | return err; |
400 | } | 285 | } |
401 | 286 | ||
402 | static int snd_info_entry_release(struct inode *inode, struct file *file) | 287 | static int snd_info_entry_release(struct inode *inode, struct file *file) |
403 | { | 288 | { |
404 | struct snd_info_entry *entry; | 289 | struct snd_info_private_data *data = file->private_data; |
405 | struct snd_info_private_data *data; | 290 | struct snd_info_entry *entry = data->entry; |
406 | int mode; | ||
407 | 291 | ||
408 | mode = file->f_flags & O_ACCMODE; | 292 | if (entry->c.ops->release) |
409 | data = file->private_data; | 293 | entry->c.ops->release(entry, file->f_flags & O_ACCMODE, |
410 | entry = data->entry; | 294 | data->file_private_data); |
411 | switch (entry->content) { | ||
412 | case SNDRV_INFO_CONTENT_TEXT: | ||
413 | if (data->rbuffer) { | ||
414 | kfree(data->rbuffer->buffer); | ||
415 | kfree(data->rbuffer); | ||
416 | } | ||
417 | if (data->wbuffer) { | ||
418 | if (entry->c.text.write) { | ||
419 | entry->c.text.write(entry, data->wbuffer); | ||
420 | if (data->wbuffer->error) { | ||
421 | if (entry->card) | ||
422 | dev_warn(entry->card->dev, "info: data write error to %s (%i)\n", | ||
423 | entry->name, | ||
424 | data->wbuffer->error); | ||
425 | else | ||
426 | pr_warn("ALSA: info: data write error to %s (%i)\n", | ||
427 | entry->name, | ||
428 | data->wbuffer->error); | ||
429 | } | ||
430 | } | ||
431 | kfree(data->wbuffer->buffer); | ||
432 | kfree(data->wbuffer); | ||
433 | } | ||
434 | break; | ||
435 | case SNDRV_INFO_CONTENT_DATA: | ||
436 | if (entry->c.ops->release) | ||
437 | entry->c.ops->release(entry, mode, | ||
438 | data->file_private_data); | ||
439 | break; | ||
440 | } | ||
441 | module_put(entry->module); | 295 | module_put(entry->module); |
442 | kfree(data); | 296 | kfree(data); |
443 | return 0; | 297 | return 0; |
444 | } | 298 | } |
445 | 299 | ||
446 | static unsigned int snd_info_entry_poll(struct file *file, poll_table * wait) | 300 | static const struct file_operations snd_info_entry_operations = |
447 | { | 301 | { |
448 | struct snd_info_private_data *data; | 302 | .owner = THIS_MODULE, |
449 | struct snd_info_entry *entry; | 303 | .llseek = snd_info_entry_llseek, |
450 | unsigned int mask; | 304 | .read = snd_info_entry_read, |
305 | .write = snd_info_entry_write, | ||
306 | .poll = snd_info_entry_poll, | ||
307 | .unlocked_ioctl = snd_info_entry_ioctl, | ||
308 | .mmap = snd_info_entry_mmap, | ||
309 | .open = snd_info_entry_open, | ||
310 | .release = snd_info_entry_release, | ||
311 | }; | ||
451 | 312 | ||
452 | data = file->private_data; | 313 | /* |
453 | if (data == NULL) | 314 | * file ops for text proc files |
454 | return 0; | 315 | */ |
455 | entry = data->entry; | 316 | static ssize_t snd_info_text_entry_write(struct file *file, |
456 | mask = 0; | 317 | const char __user *buffer, |
457 | switch (entry->content) { | 318 | size_t count, loff_t *offset) |
458 | case SNDRV_INFO_CONTENT_DATA: | 319 | { |
459 | if (entry->c.ops->poll) | 320 | struct seq_file *m = file->private_data; |
460 | return entry->c.ops->poll(entry, | 321 | struct snd_info_private_data *data = m->private; |
461 | data->file_private_data, | 322 | struct snd_info_entry *entry = data->entry; |
462 | file, wait); | 323 | struct snd_info_buffer *buf; |
463 | if (entry->c.ops->read) | 324 | loff_t pos; |
464 | mask |= POLLIN | POLLRDNORM; | 325 | size_t next; |
465 | if (entry->c.ops->write) | 326 | int err = 0; |
466 | mask |= POLLOUT | POLLWRNORM; | 327 | |
467 | break; | 328 | pos = *offset; |
329 | if (!valid_pos(pos, count)) | ||
330 | return -EIO; | ||
331 | next = pos + count; | ||
332 | mutex_lock(&entry->access); | ||
333 | buf = data->wbuffer; | ||
334 | if (!buf) { | ||
335 | data->wbuffer = buf = kzalloc(sizeof(*buf), GFP_KERNEL); | ||
336 | if (!buf) { | ||
337 | err = -ENOMEM; | ||
338 | goto error; | ||
339 | } | ||
468 | } | 340 | } |
469 | return mask; | 341 | if (next > buf->len) { |
342 | char *nbuf = krealloc(buf->buffer, PAGE_ALIGN(next), | ||
343 | GFP_KERNEL | __GFP_ZERO); | ||
344 | if (!nbuf) { | ||
345 | err = -ENOMEM; | ||
346 | goto error; | ||
347 | } | ||
348 | buf->buffer = nbuf; | ||
349 | buf->len = PAGE_ALIGN(next); | ||
350 | } | ||
351 | if (copy_from_user(buf->buffer + pos, buffer, count)) { | ||
352 | err = -EFAULT; | ||
353 | goto error; | ||
354 | } | ||
355 | buf->size = next; | ||
356 | error: | ||
357 | mutex_unlock(&entry->access); | ||
358 | if (err < 0) | ||
359 | return err; | ||
360 | *offset = next; | ||
361 | return count; | ||
470 | } | 362 | } |
471 | 363 | ||
472 | static long snd_info_entry_ioctl(struct file *file, unsigned int cmd, | 364 | static int snd_info_seq_show(struct seq_file *seq, void *p) |
473 | unsigned long arg) | ||
474 | { | 365 | { |
475 | struct snd_info_private_data *data; | 366 | struct snd_info_private_data *data = seq->private; |
476 | struct snd_info_entry *entry; | 367 | struct snd_info_entry *entry = data->entry; |
477 | 368 | ||
478 | data = file->private_data; | 369 | if (entry->c.text.read) { |
479 | if (data == NULL) | 370 | data->rbuffer->buffer = (char *)seq; /* XXX hack! */ |
480 | return 0; | 371 | entry->c.text.read(entry, data->rbuffer); |
481 | entry = data->entry; | ||
482 | switch (entry->content) { | ||
483 | case SNDRV_INFO_CONTENT_DATA: | ||
484 | if (entry->c.ops->ioctl) | ||
485 | return entry->c.ops->ioctl(entry, | ||
486 | data->file_private_data, | ||
487 | file, cmd, arg); | ||
488 | break; | ||
489 | } | 372 | } |
490 | return -ENOTTY; | 373 | return 0; |
491 | } | 374 | } |
492 | 375 | ||
493 | static int snd_info_entry_mmap(struct file *file, struct vm_area_struct *vma) | 376 | static int snd_info_text_entry_open(struct inode *inode, struct file *file) |
494 | { | 377 | { |
495 | struct inode *inode = file_inode(file); | 378 | struct snd_info_entry *entry = PDE_DATA(inode); |
496 | struct snd_info_private_data *data; | 379 | struct snd_info_private_data *data; |
497 | struct snd_info_entry *entry; | 380 | int err; |
498 | 381 | ||
499 | data = file->private_data; | 382 | mutex_lock(&info_mutex); |
500 | if (data == NULL) | 383 | err = alloc_info_private(entry, &data); |
501 | return 0; | 384 | if (err < 0) |
502 | entry = data->entry; | 385 | goto unlock; |
503 | switch (entry->content) { | 386 | |
504 | case SNDRV_INFO_CONTENT_DATA: | 387 | data->rbuffer = kzalloc(sizeof(*data->rbuffer), GFP_KERNEL); |
505 | if (entry->c.ops->mmap) | 388 | if (!data->rbuffer) { |
506 | return entry->c.ops->mmap(entry, | 389 | err = -ENOMEM; |
507 | data->file_private_data, | 390 | goto error; |
508 | inode, file, vma); | ||
509 | break; | ||
510 | } | 391 | } |
511 | return -ENXIO; | 392 | if (entry->size) |
393 | err = single_open_size(file, snd_info_seq_show, data, | ||
394 | entry->size); | ||
395 | else | ||
396 | err = single_open(file, snd_info_seq_show, data); | ||
397 | if (err < 0) | ||
398 | goto error; | ||
399 | mutex_unlock(&info_mutex); | ||
400 | return 0; | ||
401 | |||
402 | error: | ||
403 | kfree(data->rbuffer); | ||
404 | kfree(data); | ||
405 | module_put(entry->module); | ||
406 | unlock: | ||
407 | mutex_unlock(&info_mutex); | ||
408 | return err; | ||
512 | } | 409 | } |
513 | 410 | ||
514 | static const struct file_operations snd_info_entry_operations = | 411 | static int snd_info_text_entry_release(struct inode *inode, struct file *file) |
412 | { | ||
413 | struct seq_file *m = file->private_data; | ||
414 | struct snd_info_private_data *data = m->private; | ||
415 | struct snd_info_entry *entry = data->entry; | ||
416 | |||
417 | if (data->wbuffer && entry->c.text.write) | ||
418 | entry->c.text.write(entry, data->wbuffer); | ||
419 | |||
420 | single_release(inode, file); | ||
421 | kfree(data->rbuffer); | ||
422 | if (data->wbuffer) { | ||
423 | kfree(data->wbuffer->buffer); | ||
424 | kfree(data->wbuffer); | ||
425 | } | ||
426 | |||
427 | module_put(entry->module); | ||
428 | kfree(data); | ||
429 | return 0; | ||
430 | } | ||
431 | |||
432 | static const struct file_operations snd_info_text_entry_ops = | ||
515 | { | 433 | { |
516 | .owner = THIS_MODULE, | 434 | .owner = THIS_MODULE, |
517 | .llseek = snd_info_entry_llseek, | 435 | .open = snd_info_text_entry_open, |
518 | .read = snd_info_entry_read, | 436 | .release = snd_info_text_entry_release, |
519 | .write = snd_info_entry_write, | 437 | .write = snd_info_text_entry_write, |
520 | .poll = snd_info_entry_poll, | 438 | .llseek = seq_lseek, |
521 | .unlocked_ioctl = snd_info_entry_ioctl, | 439 | .read = seq_read, |
522 | .mmap = snd_info_entry_mmap, | ||
523 | .open = snd_info_entry_open, | ||
524 | .release = snd_info_entry_release, | ||
525 | }; | 440 | }; |
526 | 441 | ||
527 | int __init snd_info_init(void) | 442 | static struct snd_info_entry *create_subdir(struct module *mod, |
443 | const char *name) | ||
528 | { | 444 | { |
529 | struct proc_dir_entry *p; | 445 | struct snd_info_entry *entry; |
530 | 446 | ||
531 | p = proc_mkdir("asound", NULL); | 447 | entry = snd_info_create_module_entry(mod, name, NULL); |
532 | if (p == NULL) | 448 | if (!entry) |
449 | return NULL; | ||
450 | entry->mode = S_IFDIR | S_IRUGO | S_IXUGO; | ||
451 | if (snd_info_register(entry) < 0) { | ||
452 | snd_info_free_entry(entry); | ||
453 | return NULL; | ||
454 | } | ||
455 | return entry; | ||
456 | } | ||
457 | |||
458 | static struct snd_info_entry * | ||
459 | snd_info_create_entry(const char *name, struct snd_info_entry *parent); | ||
460 | |||
461 | int __init snd_info_init(void) | ||
462 | { | ||
463 | snd_proc_root = snd_info_create_entry("asound", NULL); | ||
464 | if (!snd_proc_root) | ||
533 | return -ENOMEM; | 465 | return -ENOMEM; |
534 | snd_proc_root = p; | 466 | snd_proc_root->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
467 | snd_proc_root->p = proc_mkdir("asound", NULL); | ||
468 | if (!snd_proc_root->p) | ||
469 | goto error; | ||
535 | #ifdef CONFIG_SND_OSSEMUL | 470 | #ifdef CONFIG_SND_OSSEMUL |
536 | { | 471 | snd_oss_root = create_subdir(THIS_MODULE, "oss"); |
537 | struct snd_info_entry *entry; | 472 | if (!snd_oss_root) |
538 | if ((entry = snd_info_create_module_entry(THIS_MODULE, "oss", NULL)) == NULL) | 473 | goto error; |
539 | return -ENOMEM; | ||
540 | entry->mode = S_IFDIR | S_IRUGO | S_IXUGO; | ||
541 | if (snd_info_register(entry) < 0) { | ||
542 | snd_info_free_entry(entry); | ||
543 | return -ENOMEM; | ||
544 | } | ||
545 | snd_oss_root = entry; | ||
546 | } | ||
547 | #endif | 474 | #endif |
548 | #if IS_ENABLED(CONFIG_SND_SEQUENCER) | 475 | #if IS_ENABLED(CONFIG_SND_SEQUENCER) |
549 | { | 476 | snd_seq_root = create_subdir(THIS_MODULE, "seq"); |
550 | struct snd_info_entry *entry; | 477 | if (!snd_seq_root) |
551 | if ((entry = snd_info_create_module_entry(THIS_MODULE, "seq", NULL)) == NULL) | 478 | goto error; |
552 | return -ENOMEM; | ||
553 | entry->mode = S_IFDIR | S_IRUGO | S_IXUGO; | ||
554 | if (snd_info_register(entry) < 0) { | ||
555 | snd_info_free_entry(entry); | ||
556 | return -ENOMEM; | ||
557 | } | ||
558 | snd_seq_root = entry; | ||
559 | } | ||
560 | #endif | 479 | #endif |
561 | snd_info_version_init(); | 480 | if (snd_info_version_init() < 0 || |
562 | snd_minor_info_init(); | 481 | snd_minor_info_init() < 0 || |
563 | snd_minor_info_oss_init(); | 482 | snd_minor_info_oss_init() < 0 || |
564 | snd_card_info_init(); | 483 | snd_card_info_init() < 0 || |
484 | snd_info_minor_register() < 0) | ||
485 | goto error; | ||
565 | return 0; | 486 | return 0; |
487 | |||
488 | error: | ||
489 | snd_info_free_entry(snd_proc_root); | ||
490 | return -ENOMEM; | ||
566 | } | 491 | } |
567 | 492 | ||
568 | int __exit snd_info_done(void) | 493 | int __exit snd_info_done(void) |
569 | { | 494 | { |
570 | snd_card_info_done(); | 495 | snd_info_free_entry(snd_proc_root); |
571 | snd_minor_info_oss_done(); | ||
572 | snd_minor_info_done(); | ||
573 | snd_info_version_done(); | ||
574 | if (snd_proc_root) { | ||
575 | #if IS_ENABLED(CONFIG_SND_SEQUENCER) | ||
576 | snd_info_free_entry(snd_seq_root); | ||
577 | #endif | ||
578 | #ifdef CONFIG_SND_OSSEMUL | ||
579 | snd_info_free_entry(snd_oss_root); | ||
580 | #endif | ||
581 | proc_remove(snd_proc_root); | ||
582 | } | ||
583 | return 0; | 496 | return 0; |
584 | } | 497 | } |
585 | 498 | ||
586 | /* | 499 | /* |
587 | |||
588 | */ | ||
589 | |||
590 | |||
591 | /* | ||
592 | * create a card proc file | 500 | * create a card proc file |
593 | * called from init.c | 501 | * called from init.c |
594 | */ | 502 | */ |
@@ -601,33 +509,58 @@ int snd_info_card_create(struct snd_card *card) | |||
601 | return -ENXIO; | 509 | return -ENXIO; |
602 | 510 | ||
603 | sprintf(str, "card%i", card->number); | 511 | sprintf(str, "card%i", card->number); |
604 | if ((entry = snd_info_create_module_entry(card->module, str, NULL)) == NULL) | 512 | entry = create_subdir(card->module, str); |
605 | return -ENOMEM; | 513 | if (!entry) |
606 | entry->mode = S_IFDIR | S_IRUGO | S_IXUGO; | ||
607 | if (snd_info_register(entry) < 0) { | ||
608 | snd_info_free_entry(entry); | ||
609 | return -ENOMEM; | 514 | return -ENOMEM; |
610 | } | ||
611 | card->proc_root = entry; | 515 | card->proc_root = entry; |
612 | return 0; | 516 | return 0; |
613 | } | 517 | } |
614 | 518 | ||
519 | /* register all pending info entries */ | ||
520 | static int snd_info_register_recursive(struct snd_info_entry *entry) | ||
521 | { | ||
522 | struct snd_info_entry *p; | ||
523 | int err; | ||
524 | |||
525 | if (!entry->p) { | ||
526 | err = snd_info_register(entry); | ||
527 | if (err < 0) | ||
528 | return err; | ||
529 | } | ||
530 | |||
531 | list_for_each_entry(p, &entry->children, list) { | ||
532 | err = snd_info_register_recursive(p); | ||
533 | if (err < 0) | ||
534 | return err; | ||
535 | } | ||
536 | |||
537 | return 0; | ||
538 | } | ||
539 | |||
615 | /* | 540 | /* |
616 | * register the card proc file | 541 | * register the card proc file |
617 | * called from init.c | 542 | * called from init.c |
543 | * can be called multiple times for reinitialization | ||
618 | */ | 544 | */ |
619 | int snd_info_card_register(struct snd_card *card) | 545 | int snd_info_card_register(struct snd_card *card) |
620 | { | 546 | { |
621 | struct proc_dir_entry *p; | 547 | struct proc_dir_entry *p; |
548 | int err; | ||
622 | 549 | ||
623 | if (snd_BUG_ON(!card)) | 550 | if (snd_BUG_ON(!card)) |
624 | return -ENXIO; | 551 | return -ENXIO; |
625 | 552 | ||
553 | err = snd_info_register_recursive(card->proc_root); | ||
554 | if (err < 0) | ||
555 | return err; | ||
556 | |||
626 | if (!strcmp(card->id, card->proc_root->name)) | 557 | if (!strcmp(card->id, card->proc_root->name)) |
627 | return 0; | 558 | return 0; |
628 | 559 | ||
629 | p = proc_symlink(card->id, snd_proc_root, card->proc_root->name); | 560 | if (card->proc_root_link) |
630 | if (p == NULL) | 561 | return 0; |
562 | p = proc_symlink(card->id, snd_proc_root->p, card->proc_root->name); | ||
563 | if (!p) | ||
631 | return -ENOMEM; | 564 | return -ENOMEM; |
632 | card->proc_root_link = p; | 565 | card->proc_root_link = p; |
633 | return 0; | 566 | return 0; |
@@ -645,7 +578,7 @@ void snd_info_card_id_change(struct snd_card *card) | |||
645 | } | 578 | } |
646 | if (strcmp(card->id, card->proc_root->name)) | 579 | if (strcmp(card->id, card->proc_root->name)) |
647 | card->proc_root_link = proc_symlink(card->id, | 580 | card->proc_root_link = proc_symlink(card->id, |
648 | snd_proc_root, | 581 | snd_proc_root->p, |
649 | card->proc_root->name); | 582 | card->proc_root->name); |
650 | mutex_unlock(&info_mutex); | 583 | mutex_unlock(&info_mutex); |
651 | } | 584 | } |
@@ -753,9 +686,10 @@ const char *snd_info_get_str(char *dest, const char *src, int len) | |||
753 | 686 | ||
754 | EXPORT_SYMBOL(snd_info_get_str); | 687 | EXPORT_SYMBOL(snd_info_get_str); |
755 | 688 | ||
756 | /** | 689 | /* |
757 | * snd_info_create_entry - create an info entry | 690 | * snd_info_create_entry - create an info entry |
758 | * @name: the proc file name | 691 | * @name: the proc file name |
692 | * @parent: the parent directory | ||
759 | * | 693 | * |
760 | * Creates an info entry with the given file name and initializes as | 694 | * Creates an info entry with the given file name and initializes as |
761 | * the default state. | 695 | * the default state. |
@@ -765,7 +699,8 @@ EXPORT_SYMBOL(snd_info_get_str); | |||
765 | * | 699 | * |
766 | * Return: The pointer of the new instance, or %NULL on failure. | 700 | * Return: The pointer of the new instance, or %NULL on failure. |
767 | */ | 701 | */ |
768 | static struct snd_info_entry *snd_info_create_entry(const char *name) | 702 | static struct snd_info_entry * |
703 | snd_info_create_entry(const char *name, struct snd_info_entry *parent) | ||
769 | { | 704 | { |
770 | struct snd_info_entry *entry; | 705 | struct snd_info_entry *entry; |
771 | entry = kzalloc(sizeof(*entry), GFP_KERNEL); | 706 | entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
@@ -781,6 +716,9 @@ static struct snd_info_entry *snd_info_create_entry(const char *name) | |||
781 | mutex_init(&entry->access); | 716 | mutex_init(&entry->access); |
782 | INIT_LIST_HEAD(&entry->children); | 717 | INIT_LIST_HEAD(&entry->children); |
783 | INIT_LIST_HEAD(&entry->list); | 718 | INIT_LIST_HEAD(&entry->list); |
719 | entry->parent = parent; | ||
720 | if (parent) | ||
721 | list_add_tail(&entry->list, &parent->children); | ||
784 | return entry; | 722 | return entry; |
785 | } | 723 | } |
786 | 724 | ||
@@ -798,11 +736,9 @@ struct snd_info_entry *snd_info_create_module_entry(struct module * module, | |||
798 | const char *name, | 736 | const char *name, |
799 | struct snd_info_entry *parent) | 737 | struct snd_info_entry *parent) |
800 | { | 738 | { |
801 | struct snd_info_entry *entry = snd_info_create_entry(name); | 739 | struct snd_info_entry *entry = snd_info_create_entry(name, parent); |
802 | if (entry) { | 740 | if (entry) |
803 | entry->module = module; | 741 | entry->module = module; |
804 | entry->parent = parent; | ||
805 | } | ||
806 | return entry; | 742 | return entry; |
807 | } | 743 | } |
808 | 744 | ||
@@ -822,11 +758,10 @@ struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card, | |||
822 | const char *name, | 758 | const char *name, |
823 | struct snd_info_entry * parent) | 759 | struct snd_info_entry * parent) |
824 | { | 760 | { |
825 | struct snd_info_entry *entry = snd_info_create_entry(name); | 761 | struct snd_info_entry *entry = snd_info_create_entry(name, parent); |
826 | if (entry) { | 762 | if (entry) { |
827 | entry->module = card->module; | 763 | entry->module = card->module; |
828 | entry->card = card; | 764 | entry->card = card; |
829 | entry->parent = parent; | ||
830 | } | 765 | } |
831 | return entry; | 766 | return entry; |
832 | } | 767 | } |
@@ -835,95 +770,39 @@ EXPORT_SYMBOL(snd_info_create_card_entry); | |||
835 | 770 | ||
836 | static void snd_info_disconnect(struct snd_info_entry *entry) | 771 | static void snd_info_disconnect(struct snd_info_entry *entry) |
837 | { | 772 | { |
838 | struct list_head *p, *n; | 773 | struct snd_info_entry *p; |
839 | struct proc_dir_entry *root; | ||
840 | |||
841 | list_for_each_safe(p, n, &entry->children) { | ||
842 | snd_info_disconnect(list_entry(p, struct snd_info_entry, list)); | ||
843 | } | ||
844 | 774 | ||
845 | if (! entry->p) | 775 | if (!entry->p) |
846 | return; | 776 | return; |
847 | list_del_init(&entry->list); | 777 | list_for_each_entry(p, &entry->children, list) |
848 | root = entry->parent == NULL ? snd_proc_root : entry->parent->p; | 778 | snd_info_disconnect(p); |
849 | snd_BUG_ON(!root); | ||
850 | proc_remove(entry->p); | 779 | proc_remove(entry->p); |
851 | entry->p = NULL; | 780 | entry->p = NULL; |
852 | } | 781 | } |
853 | 782 | ||
854 | static int snd_info_dev_free_entry(struct snd_device *device) | ||
855 | { | ||
856 | struct snd_info_entry *entry = device->device_data; | ||
857 | snd_info_free_entry(entry); | ||
858 | return 0; | ||
859 | } | ||
860 | |||
861 | static int snd_info_dev_register_entry(struct snd_device *device) | ||
862 | { | ||
863 | struct snd_info_entry *entry = device->device_data; | ||
864 | return snd_info_register(entry); | ||
865 | } | ||
866 | |||
867 | /** | ||
868 | * snd_card_proc_new - create an info entry for the given card | ||
869 | * @card: the card instance | ||
870 | * @name: the file name | ||
871 | * @entryp: the pointer to store the new info entry | ||
872 | * | ||
873 | * Creates a new info entry and assigns it to the given card. | ||
874 | * Unlike snd_info_create_card_entry(), this function registers the | ||
875 | * info entry as an ALSA device component, so that it can be | ||
876 | * unregistered/released without explicit call. | ||
877 | * Also, you don't have to register this entry via snd_info_register(), | ||
878 | * since this will be registered by snd_card_register() automatically. | ||
879 | * | ||
880 | * The parent is assumed as card->proc_root. | ||
881 | * | ||
882 | * For releasing this entry, use snd_device_free() instead of | ||
883 | * snd_info_free_entry(). | ||
884 | * | ||
885 | * Return: Zero if successful, or a negative error code on failure. | ||
886 | */ | ||
887 | int snd_card_proc_new(struct snd_card *card, const char *name, | ||
888 | struct snd_info_entry **entryp) | ||
889 | { | ||
890 | static struct snd_device_ops ops = { | ||
891 | .dev_free = snd_info_dev_free_entry, | ||
892 | .dev_register = snd_info_dev_register_entry, | ||
893 | /* disconnect is done via snd_info_card_disconnect() */ | ||
894 | }; | ||
895 | struct snd_info_entry *entry; | ||
896 | int err; | ||
897 | |||
898 | entry = snd_info_create_card_entry(card, name, card->proc_root); | ||
899 | if (! entry) | ||
900 | return -ENOMEM; | ||
901 | if ((err = snd_device_new(card, SNDRV_DEV_INFO, entry, &ops)) < 0) { | ||
902 | snd_info_free_entry(entry); | ||
903 | return err; | ||
904 | } | ||
905 | if (entryp) | ||
906 | *entryp = entry; | ||
907 | return 0; | ||
908 | } | ||
909 | |||
910 | EXPORT_SYMBOL(snd_card_proc_new); | ||
911 | |||
912 | /** | 783 | /** |
913 | * snd_info_free_entry - release the info entry | 784 | * snd_info_free_entry - release the info entry |
914 | * @entry: the info entry | 785 | * @entry: the info entry |
915 | * | 786 | * |
916 | * Releases the info entry. Don't call this after registered. | 787 | * Releases the info entry. |
917 | */ | 788 | */ |
918 | void snd_info_free_entry(struct snd_info_entry * entry) | 789 | void snd_info_free_entry(struct snd_info_entry * entry) |
919 | { | 790 | { |
920 | if (entry == NULL) | 791 | struct snd_info_entry *p, *n; |
792 | |||
793 | if (!entry) | ||
921 | return; | 794 | return; |
922 | if (entry->p) { | 795 | if (entry->p) { |
923 | mutex_lock(&info_mutex); | 796 | mutex_lock(&info_mutex); |
924 | snd_info_disconnect(entry); | 797 | snd_info_disconnect(entry); |
925 | mutex_unlock(&info_mutex); | 798 | mutex_unlock(&info_mutex); |
926 | } | 799 | } |
800 | |||
801 | /* free all children at first */ | ||
802 | list_for_each_entry_safe(p, n, &entry->children, list) | ||
803 | snd_info_free_entry(p); | ||
804 | |||
805 | list_del(&entry->list); | ||
927 | kfree(entry->name); | 806 | kfree(entry->name); |
928 | if (entry->private_free) | 807 | if (entry->private_free) |
929 | entry->private_free(entry); | 808 | entry->private_free(entry); |
@@ -946,7 +825,7 @@ int snd_info_register(struct snd_info_entry * entry) | |||
946 | 825 | ||
947 | if (snd_BUG_ON(!entry)) | 826 | if (snd_BUG_ON(!entry)) |
948 | return -ENXIO; | 827 | return -ENXIO; |
949 | root = entry->parent == NULL ? snd_proc_root : entry->parent->p; | 828 | root = entry->parent == NULL ? snd_proc_root->p : entry->parent->p; |
950 | mutex_lock(&info_mutex); | 829 | mutex_lock(&info_mutex); |
951 | if (S_ISDIR(entry->mode)) { | 830 | if (S_ISDIR(entry->mode)) { |
952 | p = proc_mkdir_mode(entry->name, entry->mode, root); | 831 | p = proc_mkdir_mode(entry->name, entry->mode, root); |
@@ -955,8 +834,13 @@ int snd_info_register(struct snd_info_entry * entry) | |||
955 | return -ENOMEM; | 834 | return -ENOMEM; |
956 | } | 835 | } |
957 | } else { | 836 | } else { |
837 | const struct file_operations *ops; | ||
838 | if (entry->content == SNDRV_INFO_CONTENT_DATA) | ||
839 | ops = &snd_info_entry_operations; | ||
840 | else | ||
841 | ops = &snd_info_text_entry_ops; | ||
958 | p = proc_create_data(entry->name, entry->mode, root, | 842 | p = proc_create_data(entry->name, entry->mode, root, |
959 | &snd_info_entry_operations, entry); | 843 | ops, entry); |
960 | if (!p) { | 844 | if (!p) { |
961 | mutex_unlock(&info_mutex); | 845 | mutex_unlock(&info_mutex); |
962 | return -ENOMEM; | 846 | return -ENOMEM; |
@@ -964,8 +848,6 @@ int snd_info_register(struct snd_info_entry * entry) | |||
964 | proc_set_size(p, entry->size); | 848 | proc_set_size(p, entry->size); |
965 | } | 849 | } |
966 | entry->p = p; | 850 | entry->p = p; |
967 | if (entry->parent) | ||
968 | list_add_tail(&entry->list, &entry->parent->children); | ||
969 | mutex_unlock(&info_mutex); | 851 | mutex_unlock(&info_mutex); |
970 | return 0; | 852 | return 0; |
971 | } | 853 | } |
@@ -976,8 +858,6 @@ EXPORT_SYMBOL(snd_info_register); | |||
976 | 858 | ||
977 | */ | 859 | */ |
978 | 860 | ||
979 | static struct snd_info_entry *snd_info_version_entry; | ||
980 | |||
981 | static void snd_info_version_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) | 861 | static void snd_info_version_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) |
982 | { | 862 | { |
983 | snd_iprintf(buffer, | 863 | snd_iprintf(buffer, |
@@ -993,18 +873,5 @@ static int __init snd_info_version_init(void) | |||
993 | if (entry == NULL) | 873 | if (entry == NULL) |
994 | return -ENOMEM; | 874 | return -ENOMEM; |
995 | entry->c.text.read = snd_info_version_read; | 875 | entry->c.text.read = snd_info_version_read; |
996 | if (snd_info_register(entry) < 0) { | 876 | return snd_info_register(entry); /* freed in error path */ |
997 | snd_info_free_entry(entry); | ||
998 | return -ENOMEM; | ||
999 | } | ||
1000 | snd_info_version_entry = entry; | ||
1001 | return 0; | ||
1002 | } | 877 | } |
1003 | |||
1004 | static int __exit snd_info_version_done(void) | ||
1005 | { | ||
1006 | snd_info_free_entry(snd_info_version_entry); | ||
1007 | return 0; | ||
1008 | } | ||
1009 | |||
1010 | #endif /* CONFIG_PROC_FS */ | ||
diff --git a/sound/core/info_oss.c b/sound/core/info_oss.c index 83c29dbff9c0..1478c8dfd473 100644 --- a/sound/core/info_oss.c +++ b/sound/core/info_oss.c | |||
@@ -29,15 +29,12 @@ | |||
29 | #include <linux/utsname.h> | 29 | #include <linux/utsname.h> |
30 | #include <linux/mutex.h> | 30 | #include <linux/mutex.h> |
31 | 31 | ||
32 | #if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_PROC_FS) | ||
33 | |||
34 | /* | 32 | /* |
35 | * OSS compatible part | 33 | * OSS compatible part |
36 | */ | 34 | */ |
37 | 35 | ||
38 | static DEFINE_MUTEX(strings); | 36 | static DEFINE_MUTEX(strings); |
39 | static char *snd_sndstat_strings[SNDRV_CARDS][SNDRV_OSS_INFO_DEV_COUNT]; | 37 | static char *snd_sndstat_strings[SNDRV_CARDS][SNDRV_OSS_INFO_DEV_COUNT]; |
40 | static struct snd_info_entry *snd_sndstat_proc_entry; | ||
41 | 38 | ||
42 | int snd_oss_info_register(int dev, int num, char *string) | 39 | int snd_oss_info_register(int dev, int num, char *string) |
43 | { | 40 | { |
@@ -112,27 +109,15 @@ static void snd_sndstat_proc_read(struct snd_info_entry *entry, | |||
112 | snd_sndstat_show_strings(buffer, "Mixers", SNDRV_OSS_INFO_DEV_MIXERS); | 109 | snd_sndstat_show_strings(buffer, "Mixers", SNDRV_OSS_INFO_DEV_MIXERS); |
113 | } | 110 | } |
114 | 111 | ||
115 | int snd_info_minor_register(void) | 112 | int __init snd_info_minor_register(void) |
116 | { | 113 | { |
117 | struct snd_info_entry *entry; | 114 | struct snd_info_entry *entry; |
118 | 115 | ||
119 | memset(snd_sndstat_strings, 0, sizeof(snd_sndstat_strings)); | 116 | memset(snd_sndstat_strings, 0, sizeof(snd_sndstat_strings)); |
120 | if ((entry = snd_info_create_module_entry(THIS_MODULE, "sndstat", snd_oss_root)) != NULL) { | 117 | entry = snd_info_create_module_entry(THIS_MODULE, "sndstat", |
121 | entry->c.text.read = snd_sndstat_proc_read; | 118 | snd_oss_root); |
122 | if (snd_info_register(entry) < 0) { | 119 | if (!entry) |
123 | snd_info_free_entry(entry); | 120 | return -ENOMEM; |
124 | entry = NULL; | 121 | entry->c.text.read = snd_sndstat_proc_read; |
125 | } | 122 | return snd_info_register(entry); /* freed in error path */ |
126 | } | ||
127 | snd_sndstat_proc_entry = entry; | ||
128 | return 0; | ||
129 | } | 123 | } |
130 | |||
131 | int snd_info_minor_unregister(void) | ||
132 | { | ||
133 | snd_info_free_entry(snd_sndstat_proc_entry); | ||
134 | snd_sndstat_proc_entry = NULL; | ||
135 | return 0; | ||
136 | } | ||
137 | |||
138 | #endif /* CONFIG_SND_OSSEMUL */ | ||
diff --git a/sound/core/init.c b/sound/core/init.c index 04734e047bfe..f8abd2d8144e 100644 --- a/sound/core/init.c +++ b/sound/core/init.c | |||
@@ -107,26 +107,20 @@ static void snd_card_id_read(struct snd_info_entry *entry, | |||
107 | snd_iprintf(buffer, "%s\n", entry->card->id); | 107 | snd_iprintf(buffer, "%s\n", entry->card->id); |
108 | } | 108 | } |
109 | 109 | ||
110 | static inline int init_info_for_card(struct snd_card *card) | 110 | static int init_info_for_card(struct snd_card *card) |
111 | { | 111 | { |
112 | int err; | 112 | int err; |
113 | struct snd_info_entry *entry; | 113 | struct snd_info_entry *entry; |
114 | 114 | ||
115 | if ((err = snd_info_card_register(card)) < 0) { | 115 | entry = snd_info_create_card_entry(card, "id", card->proc_root); |
116 | dev_dbg(card->dev, "unable to create card info\n"); | 116 | if (!entry) { |
117 | return err; | ||
118 | } | ||
119 | if ((entry = snd_info_create_card_entry(card, "id", card->proc_root)) == NULL) { | ||
120 | dev_dbg(card->dev, "unable to create card entry\n"); | 117 | dev_dbg(card->dev, "unable to create card entry\n"); |
121 | return err; | 118 | return err; |
122 | } | 119 | } |
123 | entry->c.text.read = snd_card_id_read; | 120 | entry->c.text.read = snd_card_id_read; |
124 | if (snd_info_register(entry) < 0) { | ||
125 | snd_info_free_entry(entry); | ||
126 | entry = NULL; | ||
127 | } | ||
128 | card->proc_id = entry; | 121 | card->proc_id = entry; |
129 | return 0; | 122 | |
123 | return snd_info_card_register(card); | ||
130 | } | 124 | } |
131 | #else /* !CONFIG_PROC_FS */ | 125 | #else /* !CONFIG_PROC_FS */ |
132 | #define init_info_for_card(card) | 126 | #define init_info_for_card(card) |
@@ -756,7 +750,7 @@ int snd_card_register(struct snd_card *card) | |||
756 | if (snd_cards[card->number]) { | 750 | if (snd_cards[card->number]) { |
757 | /* already registered */ | 751 | /* already registered */ |
758 | mutex_unlock(&snd_card_mutex); | 752 | mutex_unlock(&snd_card_mutex); |
759 | return 0; | 753 | return snd_info_card_register(card); /* register pending info */ |
760 | } | 754 | } |
761 | if (*card->id) { | 755 | if (*card->id) { |
762 | /* make a unique id name from the given string */ | 756 | /* make a unique id name from the given string */ |
@@ -783,8 +777,6 @@ int snd_card_register(struct snd_card *card) | |||
783 | EXPORT_SYMBOL(snd_card_register); | 777 | EXPORT_SYMBOL(snd_card_register); |
784 | 778 | ||
785 | #ifdef CONFIG_PROC_FS | 779 | #ifdef CONFIG_PROC_FS |
786 | static struct snd_info_entry *snd_card_info_entry; | ||
787 | |||
788 | static void snd_card_info_read(struct snd_info_entry *entry, | 780 | static void snd_card_info_read(struct snd_info_entry *entry, |
789 | struct snd_info_buffer *buffer) | 781 | struct snd_info_buffer *buffer) |
790 | { | 782 | { |
@@ -810,7 +802,6 @@ static void snd_card_info_read(struct snd_info_entry *entry, | |||
810 | } | 802 | } |
811 | 803 | ||
812 | #ifdef CONFIG_SND_OSSEMUL | 804 | #ifdef CONFIG_SND_OSSEMUL |
813 | |||
814 | void snd_card_info_read_oss(struct snd_info_buffer *buffer) | 805 | void snd_card_info_read_oss(struct snd_info_buffer *buffer) |
815 | { | 806 | { |
816 | int idx, count; | 807 | int idx, count; |
@@ -832,7 +823,6 @@ void snd_card_info_read_oss(struct snd_info_buffer *buffer) | |||
832 | #endif | 823 | #endif |
833 | 824 | ||
834 | #ifdef MODULE | 825 | #ifdef MODULE |
835 | static struct snd_info_entry *snd_card_module_info_entry; | ||
836 | static void snd_card_module_info_read(struct snd_info_entry *entry, | 826 | static void snd_card_module_info_read(struct snd_info_entry *entry, |
837 | struct snd_info_buffer *buffer) | 827 | struct snd_info_buffer *buffer) |
838 | { | 828 | { |
@@ -857,35 +847,20 @@ int __init snd_card_info_init(void) | |||
857 | if (! entry) | 847 | if (! entry) |
858 | return -ENOMEM; | 848 | return -ENOMEM; |
859 | entry->c.text.read = snd_card_info_read; | 849 | entry->c.text.read = snd_card_info_read; |
860 | if (snd_info_register(entry) < 0) { | 850 | if (snd_info_register(entry) < 0) |
861 | snd_info_free_entry(entry); | 851 | return -ENOMEM; /* freed in error path */ |
862 | return -ENOMEM; | ||
863 | } | ||
864 | snd_card_info_entry = entry; | ||
865 | 852 | ||
866 | #ifdef MODULE | 853 | #ifdef MODULE |
867 | entry = snd_info_create_module_entry(THIS_MODULE, "modules", NULL); | 854 | entry = snd_info_create_module_entry(THIS_MODULE, "modules", NULL); |
868 | if (entry) { | 855 | if (!entry) |
869 | entry->c.text.read = snd_card_module_info_read; | 856 | return -ENOMEM; |
870 | if (snd_info_register(entry) < 0) | 857 | entry->c.text.read = snd_card_module_info_read; |
871 | snd_info_free_entry(entry); | 858 | if (snd_info_register(entry) < 0) |
872 | else | 859 | return -ENOMEM; /* freed in error path */ |
873 | snd_card_module_info_entry = entry; | ||
874 | } | ||
875 | #endif | 860 | #endif |
876 | 861 | ||
877 | return 0; | 862 | return 0; |
878 | } | 863 | } |
879 | |||
880 | int __exit snd_card_info_done(void) | ||
881 | { | ||
882 | snd_info_free_entry(snd_card_info_entry); | ||
883 | #ifdef MODULE | ||
884 | snd_info_free_entry(snd_card_module_info_entry); | ||
885 | #endif | ||
886 | return 0; | ||
887 | } | ||
888 | |||
889 | #endif /* CONFIG_PROC_FS */ | 864 | #endif /* CONFIG_PROC_FS */ |
890 | 865 | ||
891 | /** | 866 | /** |
diff --git a/sound/core/jack.c b/sound/core/jack.c index 8658578eb584..7237acbdcbbc 100644 --- a/sound/core/jack.c +++ b/sound/core/jack.c | |||
@@ -24,6 +24,13 @@ | |||
24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
25 | #include <sound/jack.h> | 25 | #include <sound/jack.h> |
26 | #include <sound/core.h> | 26 | #include <sound/core.h> |
27 | #include <sound/control.h> | ||
28 | |||
29 | struct snd_jack_kctl { | ||
30 | struct snd_kcontrol *kctl; | ||
31 | struct list_head list; /* list of controls belong to the same jack */ | ||
32 | unsigned int mask_bits; /* only masked status bits are reported via kctl */ | ||
33 | }; | ||
27 | 34 | ||
28 | static int jack_switch_types[SND_JACK_SWITCH_TYPES] = { | 35 | static int jack_switch_types[SND_JACK_SWITCH_TYPES] = { |
29 | SW_HEADPHONE_INSERT, | 36 | SW_HEADPHONE_INSERT, |
@@ -54,7 +61,13 @@ static int snd_jack_dev_disconnect(struct snd_device *device) | |||
54 | static int snd_jack_dev_free(struct snd_device *device) | 61 | static int snd_jack_dev_free(struct snd_device *device) |
55 | { | 62 | { |
56 | struct snd_jack *jack = device->device_data; | 63 | struct snd_jack *jack = device->device_data; |
64 | struct snd_card *card = device->card; | ||
65 | struct snd_jack_kctl *jack_kctl, *tmp_jack_kctl; | ||
57 | 66 | ||
67 | list_for_each_entry_safe(jack_kctl, tmp_jack_kctl, &jack->kctl_list, list) { | ||
68 | list_del_init(&jack_kctl->list); | ||
69 | snd_ctl_remove(card, jack_kctl->kctl); | ||
70 | } | ||
58 | if (jack->private_free) | 71 | if (jack->private_free) |
59 | jack->private_free(jack); | 72 | jack->private_free(jack); |
60 | 73 | ||
@@ -74,6 +87,10 @@ static int snd_jack_dev_register(struct snd_device *device) | |||
74 | 87 | ||
75 | snprintf(jack->name, sizeof(jack->name), "%s %s", | 88 | snprintf(jack->name, sizeof(jack->name), "%s %s", |
76 | card->shortname, jack->id); | 89 | card->shortname, jack->id); |
90 | |||
91 | if (!jack->input_dev) | ||
92 | return 0; | ||
93 | |||
77 | jack->input_dev->name = jack->name; | 94 | jack->input_dev->name = jack->name; |
78 | 95 | ||
79 | /* Default to the sound card device. */ | 96 | /* Default to the sound card device. */ |
@@ -100,6 +117,77 @@ static int snd_jack_dev_register(struct snd_device *device) | |||
100 | return err; | 117 | return err; |
101 | } | 118 | } |
102 | 119 | ||
120 | static void snd_jack_kctl_private_free(struct snd_kcontrol *kctl) | ||
121 | { | ||
122 | struct snd_jack_kctl *jack_kctl; | ||
123 | |||
124 | jack_kctl = kctl->private_data; | ||
125 | if (jack_kctl) { | ||
126 | list_del(&jack_kctl->list); | ||
127 | kfree(jack_kctl); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | static void snd_jack_kctl_add(struct snd_jack *jack, struct snd_jack_kctl *jack_kctl) | ||
132 | { | ||
133 | list_add_tail(&jack_kctl->list, &jack->kctl_list); | ||
134 | } | ||
135 | |||
136 | static struct snd_jack_kctl * snd_jack_kctl_new(struct snd_card *card, const char *name, unsigned int mask) | ||
137 | { | ||
138 | struct snd_kcontrol *kctl; | ||
139 | struct snd_jack_kctl *jack_kctl; | ||
140 | int err; | ||
141 | |||
142 | kctl = snd_kctl_jack_new(name, card); | ||
143 | if (!kctl) | ||
144 | return NULL; | ||
145 | |||
146 | err = snd_ctl_add(card, kctl); | ||
147 | if (err < 0) | ||
148 | return NULL; | ||
149 | |||
150 | jack_kctl = kzalloc(sizeof(*jack_kctl), GFP_KERNEL); | ||
151 | |||
152 | if (!jack_kctl) | ||
153 | goto error; | ||
154 | |||
155 | jack_kctl->kctl = kctl; | ||
156 | jack_kctl->mask_bits = mask; | ||
157 | |||
158 | kctl->private_data = jack_kctl; | ||
159 | kctl->private_free = snd_jack_kctl_private_free; | ||
160 | |||
161 | return jack_kctl; | ||
162 | error: | ||
163 | snd_ctl_free_one(kctl); | ||
164 | return NULL; | ||
165 | } | ||
166 | |||
167 | /** | ||
168 | * snd_jack_add_new_kctl - Create a new snd_jack_kctl and add it to jack | ||
169 | * @jack: the jack instance which the kctl will attaching to | ||
170 | * @name: the name for the snd_kcontrol object | ||
171 | * @mask: a bitmask of enum snd_jack_type values that can be detected | ||
172 | * by this snd_jack_kctl object. | ||
173 | * | ||
174 | * Creates a new snd_kcontrol object and adds it to the jack kctl_list. | ||
175 | * | ||
176 | * Return: Zero if successful, or a negative error code on failure. | ||
177 | */ | ||
178 | int snd_jack_add_new_kctl(struct snd_jack *jack, const char * name, int mask) | ||
179 | { | ||
180 | struct snd_jack_kctl *jack_kctl; | ||
181 | |||
182 | jack_kctl = snd_jack_kctl_new(jack->card, name, mask); | ||
183 | if (!jack_kctl) | ||
184 | return -ENOMEM; | ||
185 | |||
186 | snd_jack_kctl_add(jack, jack_kctl); | ||
187 | return 0; | ||
188 | } | ||
189 | EXPORT_SYMBOL(snd_jack_add_new_kctl); | ||
190 | |||
103 | /** | 191 | /** |
104 | * snd_jack_new - Create a new jack | 192 | * snd_jack_new - Create a new jack |
105 | * @card: the card instance | 193 | * @card: the card instance |
@@ -107,6 +195,8 @@ static int snd_jack_dev_register(struct snd_device *device) | |||
107 | * @type: a bitmask of enum snd_jack_type values that can be detected by | 195 | * @type: a bitmask of enum snd_jack_type values that can be detected by |
108 | * this jack | 196 | * this jack |
109 | * @jjack: Used to provide the allocated jack object to the caller. | 197 | * @jjack: Used to provide the allocated jack object to the caller. |
198 | * @initial_kctl: if true, create a kcontrol and add it to the jack list. | ||
199 | * @phantom_jack: Don't create a input device for phantom jacks. | ||
110 | * | 200 | * |
111 | * Creates a new jack object. | 201 | * Creates a new jack object. |
112 | * | 202 | * |
@@ -114,9 +204,10 @@ static int snd_jack_dev_register(struct snd_device *device) | |||
114 | * On success @jjack will be initialised. | 204 | * On success @jjack will be initialised. |
115 | */ | 205 | */ |
116 | int snd_jack_new(struct snd_card *card, const char *id, int type, | 206 | int snd_jack_new(struct snd_card *card, const char *id, int type, |
117 | struct snd_jack **jjack) | 207 | struct snd_jack **jjack, bool initial_kctl, bool phantom_jack) |
118 | { | 208 | { |
119 | struct snd_jack *jack; | 209 | struct snd_jack *jack; |
210 | struct snd_jack_kctl *jack_kctl = NULL; | ||
120 | int err; | 211 | int err; |
121 | int i; | 212 | int i; |
122 | static struct snd_device_ops ops = { | 213 | static struct snd_device_ops ops = { |
@@ -125,31 +216,47 @@ int snd_jack_new(struct snd_card *card, const char *id, int type, | |||
125 | .dev_disconnect = snd_jack_dev_disconnect, | 216 | .dev_disconnect = snd_jack_dev_disconnect, |
126 | }; | 217 | }; |
127 | 218 | ||
219 | if (initial_kctl) { | ||
220 | jack_kctl = snd_jack_kctl_new(card, id, type); | ||
221 | if (!jack_kctl) | ||
222 | return -ENOMEM; | ||
223 | } | ||
224 | |||
128 | jack = kzalloc(sizeof(struct snd_jack), GFP_KERNEL); | 225 | jack = kzalloc(sizeof(struct snd_jack), GFP_KERNEL); |
129 | if (jack == NULL) | 226 | if (jack == NULL) |
130 | return -ENOMEM; | 227 | return -ENOMEM; |
131 | 228 | ||
132 | jack->id = kstrdup(id, GFP_KERNEL); | 229 | jack->id = kstrdup(id, GFP_KERNEL); |
133 | 230 | ||
134 | jack->input_dev = input_allocate_device(); | 231 | /* don't creat input device for phantom jack */ |
135 | if (jack->input_dev == NULL) { | 232 | if (!phantom_jack) { |
136 | err = -ENOMEM; | 233 | jack->input_dev = input_allocate_device(); |
137 | goto fail_input; | 234 | if (jack->input_dev == NULL) { |
138 | } | 235 | err = -ENOMEM; |
236 | goto fail_input; | ||
237 | } | ||
139 | 238 | ||
140 | jack->input_dev->phys = "ALSA"; | 239 | jack->input_dev->phys = "ALSA"; |
141 | 240 | ||
142 | jack->type = type; | 241 | jack->type = type; |
143 | 242 | ||
144 | for (i = 0; i < SND_JACK_SWITCH_TYPES; i++) | 243 | for (i = 0; i < SND_JACK_SWITCH_TYPES; i++) |
145 | if (type & (1 << i)) | 244 | if (type & (1 << i)) |
146 | input_set_capability(jack->input_dev, EV_SW, | 245 | input_set_capability(jack->input_dev, EV_SW, |
147 | jack_switch_types[i]); | 246 | jack_switch_types[i]); |
247 | |||
248 | } | ||
148 | 249 | ||
149 | err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops); | 250 | err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops); |
150 | if (err < 0) | 251 | if (err < 0) |
151 | goto fail_input; | 252 | goto fail_input; |
152 | 253 | ||
254 | jack->card = card; | ||
255 | INIT_LIST_HEAD(&jack->kctl_list); | ||
256 | |||
257 | if (initial_kctl) | ||
258 | snd_jack_kctl_add(jack, jack_kctl); | ||
259 | |||
153 | *jjack = jack; | 260 | *jjack = jack; |
154 | 261 | ||
155 | return 0; | 262 | return 0; |
@@ -175,6 +282,8 @@ EXPORT_SYMBOL(snd_jack_new); | |||
175 | void snd_jack_set_parent(struct snd_jack *jack, struct device *parent) | 282 | void snd_jack_set_parent(struct snd_jack *jack, struct device *parent) |
176 | { | 283 | { |
177 | WARN_ON(jack->registered); | 284 | WARN_ON(jack->registered); |
285 | if (!jack->input_dev) | ||
286 | return; | ||
178 | 287 | ||
179 | jack->input_dev->dev.parent = parent; | 288 | jack->input_dev->dev.parent = parent; |
180 | } | 289 | } |
@@ -230,11 +339,19 @@ EXPORT_SYMBOL(snd_jack_set_key); | |||
230 | */ | 339 | */ |
231 | void snd_jack_report(struct snd_jack *jack, int status) | 340 | void snd_jack_report(struct snd_jack *jack, int status) |
232 | { | 341 | { |
342 | struct snd_jack_kctl *jack_kctl; | ||
233 | int i; | 343 | int i; |
234 | 344 | ||
235 | if (!jack) | 345 | if (!jack) |
236 | return; | 346 | return; |
237 | 347 | ||
348 | list_for_each_entry(jack_kctl, &jack->kctl_list, list) | ||
349 | snd_kctl_jack_report(jack->card, jack_kctl->kctl, | ||
350 | status & jack_kctl->mask_bits); | ||
351 | |||
352 | if (!jack->input_dev) | ||
353 | return; | ||
354 | |||
238 | for (i = 0; i < ARRAY_SIZE(jack->key); i++) { | 355 | for (i = 0; i < ARRAY_SIZE(jack->key); i++) { |
239 | int testbit = SND_JACK_BTN_0 >> i; | 356 | int testbit = SND_JACK_BTN_0 >> i; |
240 | 357 | ||
@@ -252,9 +369,6 @@ void snd_jack_report(struct snd_jack *jack, int status) | |||
252 | } | 369 | } |
253 | 370 | ||
254 | input_sync(jack->input_dev); | 371 | input_sync(jack->input_dev); |
372 | |||
255 | } | 373 | } |
256 | EXPORT_SYMBOL(snd_jack_report); | 374 | EXPORT_SYMBOL(snd_jack_report); |
257 | |||
258 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
259 | MODULE_DESCRIPTION("Jack detection support for ALSA"); | ||
260 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/core/seq/Makefile b/sound/core/seq/Makefile index 941f64a853eb..b29ffe835205 100644 --- a/sound/core/seq/Makefile +++ b/sound/core/seq/Makefile | |||
@@ -6,7 +6,8 @@ | |||
6 | snd-seq-device-objs := seq_device.o | 6 | snd-seq-device-objs := seq_device.o |
7 | snd-seq-objs := seq.o seq_lock.o seq_clientmgr.o seq_memory.o seq_queue.o \ | 7 | snd-seq-objs := seq.o seq_lock.o seq_clientmgr.o seq_memory.o seq_queue.o \ |
8 | seq_fifo.o seq_prioq.o seq_timer.o \ | 8 | seq_fifo.o seq_prioq.o seq_timer.o \ |
9 | seq_system.o seq_ports.o seq_info.o | 9 | seq_system.o seq_ports.o |
10 | snd-seq-$(CONFIG_PROC_FS) += seq_info.o | ||
10 | snd-seq-midi-objs := seq_midi.o | 11 | snd-seq-midi-objs := seq_midi.o |
11 | snd-seq-midi-emul-objs := seq_midi_emul.o | 12 | snd-seq-midi-emul-objs := seq_midi_emul.o |
12 | snd-seq-midi-event-objs := seq_midi_event.o | 13 | snd-seq-midi-event-objs := seq_midi_event.o |
diff --git a/sound/core/seq/seq_info.c b/sound/core/seq/seq_info.c index acf7769419f0..97015447b9b3 100644 --- a/sound/core/seq/seq_info.c +++ b/sound/core/seq/seq_info.c | |||
@@ -27,7 +27,6 @@ | |||
27 | #include "seq_clientmgr.h" | 27 | #include "seq_clientmgr.h" |
28 | #include "seq_timer.h" | 28 | #include "seq_timer.h" |
29 | 29 | ||
30 | #ifdef CONFIG_PROC_FS | ||
31 | static struct snd_info_entry *queues_entry; | 30 | static struct snd_info_entry *queues_entry; |
32 | static struct snd_info_entry *clients_entry; | 31 | static struct snd_info_entry *clients_entry; |
33 | static struct snd_info_entry *timer_entry; | 32 | static struct snd_info_entry *timer_entry; |
@@ -51,6 +50,13 @@ create_info_entry(char *name, void (*read)(struct snd_info_entry *, | |||
51 | return entry; | 50 | return entry; |
52 | } | 51 | } |
53 | 52 | ||
53 | static void free_info_entries(void) | ||
54 | { | ||
55 | snd_info_free_entry(queues_entry); | ||
56 | snd_info_free_entry(clients_entry); | ||
57 | snd_info_free_entry(timer_entry); | ||
58 | } | ||
59 | |||
54 | /* create all our /proc entries */ | 60 | /* create all our /proc entries */ |
55 | int __init snd_seq_info_init(void) | 61 | int __init snd_seq_info_init(void) |
56 | { | 62 | { |
@@ -59,14 +65,17 @@ int __init snd_seq_info_init(void) | |||
59 | clients_entry = create_info_entry("clients", | 65 | clients_entry = create_info_entry("clients", |
60 | snd_seq_info_clients_read); | 66 | snd_seq_info_clients_read); |
61 | timer_entry = create_info_entry("timer", snd_seq_info_timer_read); | 67 | timer_entry = create_info_entry("timer", snd_seq_info_timer_read); |
68 | if (!queues_entry || !clients_entry || !timer_entry) | ||
69 | goto error; | ||
62 | return 0; | 70 | return 0; |
71 | |||
72 | error: | ||
73 | free_info_entries(); | ||
74 | return -ENOMEM; | ||
63 | } | 75 | } |
64 | 76 | ||
65 | int __exit snd_seq_info_done(void) | 77 | int __exit snd_seq_info_done(void) |
66 | { | 78 | { |
67 | snd_info_free_entry(queues_entry); | 79 | free_info_entries(); |
68 | snd_info_free_entry(clients_entry); | ||
69 | snd_info_free_entry(timer_entry); | ||
70 | return 0; | 80 | return 0; |
71 | } | 81 | } |
72 | #endif | ||
diff --git a/sound/core/sound.c b/sound/core/sound.c index 5fc93d00572a..e5d37bd7c226 100644 --- a/sound/core/sound.c +++ b/sound/core/sound.c | |||
@@ -334,9 +334,6 @@ EXPORT_SYMBOL(snd_unregister_device); | |||
334 | /* | 334 | /* |
335 | * INFO PART | 335 | * INFO PART |
336 | */ | 336 | */ |
337 | |||
338 | static struct snd_info_entry *snd_minor_info_entry; | ||
339 | |||
340 | static const char *snd_device_type_name(int type) | 337 | static const char *snd_device_type_name(int type) |
341 | { | 338 | { |
342 | switch (type) { | 339 | switch (type) { |
@@ -389,21 +386,10 @@ int __init snd_minor_info_init(void) | |||
389 | struct snd_info_entry *entry; | 386 | struct snd_info_entry *entry; |
390 | 387 | ||
391 | entry = snd_info_create_module_entry(THIS_MODULE, "devices", NULL); | 388 | entry = snd_info_create_module_entry(THIS_MODULE, "devices", NULL); |
392 | if (entry) { | 389 | if (!entry) |
393 | entry->c.text.read = snd_minor_info_read; | 390 | return -ENOMEM; |
394 | if (snd_info_register(entry) < 0) { | 391 | entry->c.text.read = snd_minor_info_read; |
395 | snd_info_free_entry(entry); | 392 | return snd_info_register(entry); /* freed in error path */ |
396 | entry = NULL; | ||
397 | } | ||
398 | } | ||
399 | snd_minor_info_entry = entry; | ||
400 | return 0; | ||
401 | } | ||
402 | |||
403 | int __exit snd_minor_info_done(void) | ||
404 | { | ||
405 | snd_info_free_entry(snd_minor_info_entry); | ||
406 | return 0; | ||
407 | } | 393 | } |
408 | #endif /* CONFIG_PROC_FS */ | 394 | #endif /* CONFIG_PROC_FS */ |
409 | 395 | ||
@@ -423,7 +409,6 @@ static int __init alsa_sound_init(void) | |||
423 | unregister_chrdev(major, "alsa"); | 409 | unregister_chrdev(major, "alsa"); |
424 | return -ENOMEM; | 410 | return -ENOMEM; |
425 | } | 411 | } |
426 | snd_info_minor_register(); | ||
427 | #ifndef MODULE | 412 | #ifndef MODULE |
428 | pr_info("Advanced Linux Sound Architecture Driver Initialized.\n"); | 413 | pr_info("Advanced Linux Sound Architecture Driver Initialized.\n"); |
429 | #endif | 414 | #endif |
@@ -432,7 +417,6 @@ static int __init alsa_sound_init(void) | |||
432 | 417 | ||
433 | static void __exit alsa_sound_exit(void) | 418 | static void __exit alsa_sound_exit(void) |
434 | { | 419 | { |
435 | snd_info_minor_unregister(); | ||
436 | snd_info_done(); | 420 | snd_info_done(); |
437 | unregister_chrdev(major, "alsa"); | 421 | unregister_chrdev(major, "alsa"); |
438 | } | 422 | } |
diff --git a/sound/core/sound_oss.c b/sound/core/sound_oss.c index 573a65eb2b79..86e2d91dd375 100644 --- a/sound/core/sound_oss.c +++ b/sound/core/sound_oss.c | |||
@@ -19,12 +19,6 @@ | |||
19 | * | 19 | * |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifdef CONFIG_SND_OSSEMUL | ||
23 | |||
24 | #if !IS_ENABLED(CONFIG_SOUND) | ||
25 | #error "Enable the OSS soundcore multiplexer (CONFIG_SOUND) in the kernel." | ||
26 | #endif | ||
27 | |||
28 | #include <linux/init.h> | 22 | #include <linux/init.h> |
29 | #include <linux/export.h> | 23 | #include <linux/export.h> |
30 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
@@ -214,9 +208,6 @@ EXPORT_SYMBOL(snd_unregister_oss_device); | |||
214 | */ | 208 | */ |
215 | 209 | ||
216 | #ifdef CONFIG_PROC_FS | 210 | #ifdef CONFIG_PROC_FS |
217 | |||
218 | static struct snd_info_entry *snd_minor_info_oss_entry; | ||
219 | |||
220 | static const char *snd_oss_device_type_name(int type) | 211 | static const char *snd_oss_device_type_name(int type) |
221 | { | 212 | { |
222 | switch (type) { | 213 | switch (type) { |
@@ -263,22 +254,9 @@ int __init snd_minor_info_oss_init(void) | |||
263 | struct snd_info_entry *entry; | 254 | struct snd_info_entry *entry; |
264 | 255 | ||
265 | entry = snd_info_create_module_entry(THIS_MODULE, "devices", snd_oss_root); | 256 | entry = snd_info_create_module_entry(THIS_MODULE, "devices", snd_oss_root); |
266 | if (entry) { | 257 | if (!entry) |
267 | entry->c.text.read = snd_minor_info_oss_read; | 258 | return -ENOMEM; |
268 | if (snd_info_register(entry) < 0) { | 259 | entry->c.text.read = snd_minor_info_oss_read; |
269 | snd_info_free_entry(entry); | 260 | return snd_info_register(entry); /* freed in error path */ |
270 | entry = NULL; | ||
271 | } | ||
272 | } | ||
273 | snd_minor_info_oss_entry = entry; | ||
274 | return 0; | ||
275 | } | ||
276 | |||
277 | int __exit snd_minor_info_oss_done(void) | ||
278 | { | ||
279 | snd_info_free_entry(snd_minor_info_oss_entry); | ||
280 | return 0; | ||
281 | } | 261 | } |
282 | #endif /* CONFIG_PROC_FS */ | 262 | #endif /* CONFIG_PROC_FS */ |
283 | |||
284 | #endif /* CONFIG_SND_OSSEMUL */ | ||
diff --git a/sound/hda/Kconfig b/sound/hda/Kconfig index 001c6588a5ff..ac5ffac2a272 100644 --- a/sound/hda/Kconfig +++ b/sound/hda/Kconfig | |||
@@ -1,3 +1,12 @@ | |||
1 | config SND_HDA_CORE | 1 | config SND_HDA_CORE |
2 | tristate | 2 | tristate |
3 | select REGMAP | 3 | select REGMAP |
4 | |||
5 | config SND_HDA_DSP_LOADER | ||
6 | bool | ||
7 | |||
8 | config SND_HDA_I915 | ||
9 | bool | ||
10 | default y | ||
11 | depends on DRM_I915 | ||
12 | depends on SND_HDA_CORE | ||
diff --git a/sound/hda/Makefile b/sound/hda/Makefile index 7a359f5b7e25..55dd465c7042 100644 --- a/sound/hda/Makefile +++ b/sound/hda/Makefile | |||
@@ -1,7 +1,10 @@ | |||
1 | snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o hdac_sysfs.o \ | 1 | snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o hdac_sysfs.o \ |
2 | hdac_regmap.o array.o | 2 | hdac_regmap.o hdac_controller.o hdac_stream.o array.o |
3 | 3 | ||
4 | snd-hda-core-objs += trace.o | 4 | snd-hda-core-objs += trace.o |
5 | CFLAGS_trace.o := -I$(src) | 5 | CFLAGS_trace.o := -I$(src) |
6 | 6 | ||
7 | # for sync with i915 gfx driver | ||
8 | snd-hda-core-$(CONFIG_SND_HDA_I915) += hdac_i915.o | ||
9 | |||
7 | obj-$(CONFIG_SND_HDA_CORE) += snd-hda-core.o | 10 | obj-$(CONFIG_SND_HDA_CORE) += snd-hda-core.o |
diff --git a/sound/hda/hdac_bus.c b/sound/hda/hdac_bus.c index 8e262da74f6a..27c447e4fe5c 100644 --- a/sound/hda/hdac_bus.c +++ b/sound/hda/hdac_bus.c | |||
@@ -11,21 +11,36 @@ | |||
11 | 11 | ||
12 | static void process_unsol_events(struct work_struct *work); | 12 | static void process_unsol_events(struct work_struct *work); |
13 | 13 | ||
14 | static const struct hdac_bus_ops default_ops = { | ||
15 | .command = snd_hdac_bus_send_cmd, | ||
16 | .get_response = snd_hdac_bus_get_response, | ||
17 | }; | ||
18 | |||
14 | /** | 19 | /** |
15 | * snd_hdac_bus_init - initialize a HD-audio bas bus | 20 | * snd_hdac_bus_init - initialize a HD-audio bas bus |
16 | * @bus: the pointer to bus object | 21 | * @bus: the pointer to bus object |
22 | * @ops: bus verb operators | ||
23 | * @io_ops: lowlevel I/O operators | ||
17 | * | 24 | * |
18 | * Returns 0 if successful, or a negative error code. | 25 | * Returns 0 if successful, or a negative error code. |
19 | */ | 26 | */ |
20 | int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev, | 27 | int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev, |
21 | const struct hdac_bus_ops *ops) | 28 | const struct hdac_bus_ops *ops, |
29 | const struct hdac_io_ops *io_ops) | ||
22 | { | 30 | { |
23 | memset(bus, 0, sizeof(*bus)); | 31 | memset(bus, 0, sizeof(*bus)); |
24 | bus->dev = dev; | 32 | bus->dev = dev; |
25 | bus->ops = ops; | 33 | if (ops) |
34 | bus->ops = ops; | ||
35 | else | ||
36 | bus->ops = &default_ops; | ||
37 | bus->io_ops = io_ops; | ||
38 | INIT_LIST_HEAD(&bus->stream_list); | ||
26 | INIT_LIST_HEAD(&bus->codec_list); | 39 | INIT_LIST_HEAD(&bus->codec_list); |
27 | INIT_WORK(&bus->unsol_work, process_unsol_events); | 40 | INIT_WORK(&bus->unsol_work, process_unsol_events); |
41 | spin_lock_init(&bus->reg_lock); | ||
28 | mutex_init(&bus->cmd_mutex); | 42 | mutex_init(&bus->cmd_mutex); |
43 | bus->irq = -1; | ||
29 | return 0; | 44 | return 0; |
30 | } | 45 | } |
31 | EXPORT_SYMBOL_GPL(snd_hdac_bus_init); | 46 | EXPORT_SYMBOL_GPL(snd_hdac_bus_init); |
@@ -36,6 +51,7 @@ EXPORT_SYMBOL_GPL(snd_hdac_bus_init); | |||
36 | */ | 51 | */ |
37 | void snd_hdac_bus_exit(struct hdac_bus *bus) | 52 | void snd_hdac_bus_exit(struct hdac_bus *bus) |
38 | { | 53 | { |
54 | WARN_ON(!list_empty(&bus->stream_list)); | ||
39 | WARN_ON(!list_empty(&bus->codec_list)); | 55 | WARN_ON(!list_empty(&bus->codec_list)); |
40 | cancel_work_sync(&bus->unsol_work); | 56 | cancel_work_sync(&bus->unsol_work); |
41 | } | 57 | } |
diff --git a/sound/hda/hdac_controller.c b/sound/hda/hdac_controller.c new file mode 100644 index 000000000000..b5a17cb510a0 --- /dev/null +++ b/sound/hda/hdac_controller.c | |||
@@ -0,0 +1,507 @@ | |||
1 | /* | ||
2 | * HD-audio controller helpers | ||
3 | */ | ||
4 | |||
5 | #include <linux/kernel.h> | ||
6 | #include <linux/delay.h> | ||
7 | #include <linux/export.h> | ||
8 | #include <sound/core.h> | ||
9 | #include <sound/hdaudio.h> | ||
10 | #include <sound/hda_register.h> | ||
11 | |||
12 | /* clear CORB read pointer properly */ | ||
13 | static void azx_clear_corbrp(struct hdac_bus *bus) | ||
14 | { | ||
15 | int timeout; | ||
16 | |||
17 | for (timeout = 1000; timeout > 0; timeout--) { | ||
18 | if (snd_hdac_chip_readw(bus, CORBRP) & AZX_CORBRP_RST) | ||
19 | break; | ||
20 | udelay(1); | ||
21 | } | ||
22 | if (timeout <= 0) | ||
23 | dev_err(bus->dev, "CORB reset timeout#1, CORBRP = %d\n", | ||
24 | snd_hdac_chip_readw(bus, CORBRP)); | ||
25 | |||
26 | snd_hdac_chip_writew(bus, CORBRP, 0); | ||
27 | for (timeout = 1000; timeout > 0; timeout--) { | ||
28 | if (snd_hdac_chip_readw(bus, CORBRP) == 0) | ||
29 | break; | ||
30 | udelay(1); | ||
31 | } | ||
32 | if (timeout <= 0) | ||
33 | dev_err(bus->dev, "CORB reset timeout#2, CORBRP = %d\n", | ||
34 | snd_hdac_chip_readw(bus, CORBRP)); | ||
35 | } | ||
36 | |||
37 | /** | ||
38 | * snd_hdac_bus_init_cmd_io - set up CORB/RIRB buffers | ||
39 | * @bus: HD-audio core bus | ||
40 | */ | ||
41 | void snd_hdac_bus_init_cmd_io(struct hdac_bus *bus) | ||
42 | { | ||
43 | spin_lock_irq(&bus->reg_lock); | ||
44 | /* CORB set up */ | ||
45 | bus->corb.addr = bus->rb.addr; | ||
46 | bus->corb.buf = (__le32 *)bus->rb.area; | ||
47 | snd_hdac_chip_writel(bus, CORBLBASE, (u32)bus->corb.addr); | ||
48 | snd_hdac_chip_writel(bus, CORBUBASE, upper_32_bits(bus->corb.addr)); | ||
49 | |||
50 | /* set the corb size to 256 entries (ULI requires explicitly) */ | ||
51 | snd_hdac_chip_writeb(bus, CORBSIZE, 0x02); | ||
52 | /* set the corb write pointer to 0 */ | ||
53 | snd_hdac_chip_writew(bus, CORBWP, 0); | ||
54 | |||
55 | /* reset the corb hw read pointer */ | ||
56 | snd_hdac_chip_writew(bus, CORBRP, AZX_CORBRP_RST); | ||
57 | if (!bus->corbrp_self_clear) | ||
58 | azx_clear_corbrp(bus); | ||
59 | |||
60 | /* enable corb dma */ | ||
61 | snd_hdac_chip_writeb(bus, CORBCTL, AZX_CORBCTL_RUN); | ||
62 | |||
63 | /* RIRB set up */ | ||
64 | bus->rirb.addr = bus->rb.addr + 2048; | ||
65 | bus->rirb.buf = (__le32 *)(bus->rb.area + 2048); | ||
66 | bus->rirb.wp = bus->rirb.rp = 0; | ||
67 | memset(bus->rirb.cmds, 0, sizeof(bus->rirb.cmds)); | ||
68 | snd_hdac_chip_writel(bus, RIRBLBASE, (u32)bus->rirb.addr); | ||
69 | snd_hdac_chip_writel(bus, RIRBUBASE, upper_32_bits(bus->rirb.addr)); | ||
70 | |||
71 | /* set the rirb size to 256 entries (ULI requires explicitly) */ | ||
72 | snd_hdac_chip_writeb(bus, RIRBSIZE, 0x02); | ||
73 | /* reset the rirb hw write pointer */ | ||
74 | snd_hdac_chip_writew(bus, RIRBWP, AZX_RIRBWP_RST); | ||
75 | /* set N=1, get RIRB response interrupt for new entry */ | ||
76 | snd_hdac_chip_writew(bus, RINTCNT, 1); | ||
77 | /* enable rirb dma and response irq */ | ||
78 | snd_hdac_chip_writeb(bus, RIRBCTL, AZX_RBCTL_DMA_EN | AZX_RBCTL_IRQ_EN); | ||
79 | spin_unlock_irq(&bus->reg_lock); | ||
80 | } | ||
81 | EXPORT_SYMBOL_GPL(snd_hdac_bus_init_cmd_io); | ||
82 | |||
83 | /** | ||
84 | * snd_hdac_bus_stop_cmd_io - clean up CORB/RIRB buffers | ||
85 | * @bus: HD-audio core bus | ||
86 | */ | ||
87 | void snd_hdac_bus_stop_cmd_io(struct hdac_bus *bus) | ||
88 | { | ||
89 | spin_lock_irq(&bus->reg_lock); | ||
90 | /* disable ringbuffer DMAs */ | ||
91 | snd_hdac_chip_writeb(bus, RIRBCTL, 0); | ||
92 | snd_hdac_chip_writeb(bus, CORBCTL, 0); | ||
93 | /* disable unsolicited responses */ | ||
94 | snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_UNSOL, 0); | ||
95 | spin_unlock_irq(&bus->reg_lock); | ||
96 | } | ||
97 | EXPORT_SYMBOL_GPL(snd_hdac_bus_stop_cmd_io); | ||
98 | |||
99 | static unsigned int azx_command_addr(u32 cmd) | ||
100 | { | ||
101 | unsigned int addr = cmd >> 28; | ||
102 | |||
103 | if (snd_BUG_ON(addr >= HDA_MAX_CODECS)) | ||
104 | addr = 0; | ||
105 | return addr; | ||
106 | } | ||
107 | |||
108 | /** | ||
109 | * snd_hdac_bus_send_cmd - send a command verb via CORB | ||
110 | * @bus: HD-audio core bus | ||
111 | * @val: encoded verb value to send | ||
112 | * | ||
113 | * Returns zero for success or a negative error code. | ||
114 | */ | ||
115 | int snd_hdac_bus_send_cmd(struct hdac_bus *bus, unsigned int val) | ||
116 | { | ||
117 | unsigned int addr = azx_command_addr(val); | ||
118 | unsigned int wp, rp; | ||
119 | |||
120 | spin_lock_irq(&bus->reg_lock); | ||
121 | |||
122 | bus->last_cmd[azx_command_addr(val)] = val; | ||
123 | |||
124 | /* add command to corb */ | ||
125 | wp = snd_hdac_chip_readw(bus, CORBWP); | ||
126 | if (wp == 0xffff) { | ||
127 | /* something wrong, controller likely turned to D3 */ | ||
128 | spin_unlock_irq(&bus->reg_lock); | ||
129 | return -EIO; | ||
130 | } | ||
131 | wp++; | ||
132 | wp %= AZX_MAX_CORB_ENTRIES; | ||
133 | |||
134 | rp = snd_hdac_chip_readw(bus, CORBRP); | ||
135 | if (wp == rp) { | ||
136 | /* oops, it's full */ | ||
137 | spin_unlock_irq(&bus->reg_lock); | ||
138 | return -EAGAIN; | ||
139 | } | ||
140 | |||
141 | bus->rirb.cmds[addr]++; | ||
142 | bus->corb.buf[wp] = cpu_to_le32(val); | ||
143 | snd_hdac_chip_writew(bus, CORBWP, wp); | ||
144 | |||
145 | spin_unlock_irq(&bus->reg_lock); | ||
146 | |||
147 | return 0; | ||
148 | } | ||
149 | EXPORT_SYMBOL_GPL(snd_hdac_bus_send_cmd); | ||
150 | |||
151 | #define AZX_RIRB_EX_UNSOL_EV (1<<4) | ||
152 | |||
153 | /** | ||
154 | * snd_hdac_bus_update_rirb - retrieve RIRB entries | ||
155 | * @bus: HD-audio core bus | ||
156 | * | ||
157 | * Usually called from interrupt handler. | ||
158 | */ | ||
159 | void snd_hdac_bus_update_rirb(struct hdac_bus *bus) | ||
160 | { | ||
161 | unsigned int rp, wp; | ||
162 | unsigned int addr; | ||
163 | u32 res, res_ex; | ||
164 | |||
165 | wp = snd_hdac_chip_readw(bus, RIRBWP); | ||
166 | if (wp == 0xffff) { | ||
167 | /* something wrong, controller likely turned to D3 */ | ||
168 | return; | ||
169 | } | ||
170 | |||
171 | if (wp == bus->rirb.wp) | ||
172 | return; | ||
173 | bus->rirb.wp = wp; | ||
174 | |||
175 | while (bus->rirb.rp != wp) { | ||
176 | bus->rirb.rp++; | ||
177 | bus->rirb.rp %= AZX_MAX_RIRB_ENTRIES; | ||
178 | |||
179 | rp = bus->rirb.rp << 1; /* an RIRB entry is 8-bytes */ | ||
180 | res_ex = le32_to_cpu(bus->rirb.buf[rp + 1]); | ||
181 | res = le32_to_cpu(bus->rirb.buf[rp]); | ||
182 | addr = res_ex & 0xf; | ||
183 | if (addr >= HDA_MAX_CODECS) { | ||
184 | dev_err(bus->dev, | ||
185 | "spurious response %#x:%#x, rp = %d, wp = %d", | ||
186 | res, res_ex, bus->rirb.rp, wp); | ||
187 | snd_BUG(); | ||
188 | } else if (res_ex & AZX_RIRB_EX_UNSOL_EV) | ||
189 | snd_hdac_bus_queue_event(bus, res, res_ex); | ||
190 | else if (bus->rirb.cmds[addr]) { | ||
191 | bus->rirb.res[addr] = res; | ||
192 | bus->rirb.cmds[addr]--; | ||
193 | } else { | ||
194 | dev_err_ratelimited(bus->dev, | ||
195 | "spurious response %#x:%#x, last cmd=%#08x\n", | ||
196 | res, res_ex, bus->last_cmd[addr]); | ||
197 | } | ||
198 | } | ||
199 | } | ||
200 | EXPORT_SYMBOL_GPL(snd_hdac_bus_update_rirb); | ||
201 | |||
202 | /** | ||
203 | * snd_hdac_bus_get_response - receive a response via RIRB | ||
204 | * @bus: HD-audio core bus | ||
205 | * @addr: codec address | ||
206 | * @res: pointer to store the value, NULL when not needed | ||
207 | * | ||
208 | * Returns zero if a value is read, or a negative error code. | ||
209 | */ | ||
210 | int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr, | ||
211 | unsigned int *res) | ||
212 | { | ||
213 | unsigned long timeout; | ||
214 | unsigned long loopcounter; | ||
215 | |||
216 | timeout = jiffies + msecs_to_jiffies(1000); | ||
217 | |||
218 | for (loopcounter = 0;; loopcounter++) { | ||
219 | spin_lock_irq(&bus->reg_lock); | ||
220 | if (!bus->rirb.cmds[addr]) { | ||
221 | if (res) | ||
222 | *res = bus->rirb.res[addr]; /* the last value */ | ||
223 | spin_unlock_irq(&bus->reg_lock); | ||
224 | return 0; | ||
225 | } | ||
226 | spin_unlock_irq(&bus->reg_lock); | ||
227 | if (time_after(jiffies, timeout)) | ||
228 | break; | ||
229 | if (loopcounter > 3000) | ||
230 | msleep(2); /* temporary workaround */ | ||
231 | else { | ||
232 | udelay(10); | ||
233 | cond_resched(); | ||
234 | } | ||
235 | } | ||
236 | |||
237 | return -EIO; | ||
238 | } | ||
239 | EXPORT_SYMBOL_GPL(snd_hdac_bus_get_response); | ||
240 | |||
241 | /* | ||
242 | * Lowlevel interface | ||
243 | */ | ||
244 | |||
245 | /** | ||
246 | * snd_hdac_bus_enter_link_reset - enter link reset | ||
247 | * @bus: HD-audio core bus | ||
248 | * | ||
249 | * Enter to the link reset state. | ||
250 | */ | ||
251 | void snd_hdac_bus_enter_link_reset(struct hdac_bus *bus) | ||
252 | { | ||
253 | unsigned long timeout; | ||
254 | |||
255 | /* reset controller */ | ||
256 | snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_RESET, 0); | ||
257 | |||
258 | timeout = jiffies + msecs_to_jiffies(100); | ||
259 | while ((snd_hdac_chip_readb(bus, GCTL) & AZX_GCTL_RESET) && | ||
260 | time_before(jiffies, timeout)) | ||
261 | usleep_range(500, 1000); | ||
262 | } | ||
263 | EXPORT_SYMBOL_GPL(snd_hdac_bus_enter_link_reset); | ||
264 | |||
265 | /** | ||
266 | * snd_hdac_bus_exit_link_reset - exit link reset | ||
267 | * @bus: HD-audio core bus | ||
268 | * | ||
269 | * Exit from the link reset state. | ||
270 | */ | ||
271 | void snd_hdac_bus_exit_link_reset(struct hdac_bus *bus) | ||
272 | { | ||
273 | unsigned long timeout; | ||
274 | |||
275 | snd_hdac_chip_updateb(bus, GCTL, 0, AZX_GCTL_RESET); | ||
276 | |||
277 | timeout = jiffies + msecs_to_jiffies(100); | ||
278 | while (!snd_hdac_chip_readb(bus, GCTL) && time_before(jiffies, timeout)) | ||
279 | usleep_range(500, 1000); | ||
280 | } | ||
281 | EXPORT_SYMBOL_GPL(snd_hdac_bus_exit_link_reset); | ||
282 | |||
283 | /* reset codec link */ | ||
284 | static int azx_reset(struct hdac_bus *bus, bool full_reset) | ||
285 | { | ||
286 | if (!full_reset) | ||
287 | goto skip_reset; | ||
288 | |||
289 | /* clear STATESTS */ | ||
290 | snd_hdac_chip_writew(bus, STATESTS, STATESTS_INT_MASK); | ||
291 | |||
292 | /* reset controller */ | ||
293 | snd_hdac_bus_enter_link_reset(bus); | ||
294 | |||
295 | /* delay for >= 100us for codec PLL to settle per spec | ||
296 | * Rev 0.9 section 5.5.1 | ||
297 | */ | ||
298 | usleep_range(500, 1000); | ||
299 | |||
300 | /* Bring controller out of reset */ | ||
301 | snd_hdac_bus_exit_link_reset(bus); | ||
302 | |||
303 | /* Brent Chartrand said to wait >= 540us for codecs to initialize */ | ||
304 | usleep_range(1000, 1200); | ||
305 | |||
306 | skip_reset: | ||
307 | /* check to see if controller is ready */ | ||
308 | if (!snd_hdac_chip_readb(bus, GCTL)) { | ||
309 | dev_dbg(bus->dev, "azx_reset: controller not ready!\n"); | ||
310 | return -EBUSY; | ||
311 | } | ||
312 | |||
313 | /* Accept unsolicited responses */ | ||
314 | snd_hdac_chip_updatel(bus, GCTL, 0, AZX_GCTL_UNSOL); | ||
315 | |||
316 | /* detect codecs */ | ||
317 | if (!bus->codec_mask) { | ||
318 | bus->codec_mask = snd_hdac_chip_readw(bus, STATESTS); | ||
319 | dev_dbg(bus->dev, "codec_mask = 0x%lx\n", bus->codec_mask); | ||
320 | } | ||
321 | |||
322 | return 0; | ||
323 | } | ||
324 | |||
325 | /* enable interrupts */ | ||
326 | static void azx_int_enable(struct hdac_bus *bus) | ||
327 | { | ||
328 | /* enable controller CIE and GIE */ | ||
329 | snd_hdac_chip_updatel(bus, INTCTL, 0, AZX_INT_CTRL_EN | AZX_INT_GLOBAL_EN); | ||
330 | } | ||
331 | |||
332 | /* disable interrupts */ | ||
333 | static void azx_int_disable(struct hdac_bus *bus) | ||
334 | { | ||
335 | struct hdac_stream *azx_dev; | ||
336 | |||
337 | /* disable interrupts in stream descriptor */ | ||
338 | list_for_each_entry(azx_dev, &bus->stream_list, list) | ||
339 | snd_hdac_stream_updateb(azx_dev, SD_CTL, SD_INT_MASK, 0); | ||
340 | |||
341 | /* disable SIE for all streams */ | ||
342 | snd_hdac_chip_writeb(bus, INTCTL, 0); | ||
343 | |||
344 | /* disable controller CIE and GIE */ | ||
345 | snd_hdac_chip_updatel(bus, INTCTL, AZX_INT_CTRL_EN | AZX_INT_GLOBAL_EN, 0); | ||
346 | } | ||
347 | |||
348 | /* clear interrupts */ | ||
349 | static void azx_int_clear(struct hdac_bus *bus) | ||
350 | { | ||
351 | struct hdac_stream *azx_dev; | ||
352 | |||
353 | /* clear stream status */ | ||
354 | list_for_each_entry(azx_dev, &bus->stream_list, list) | ||
355 | snd_hdac_stream_writeb(azx_dev, SD_STS, SD_INT_MASK); | ||
356 | |||
357 | /* clear STATESTS */ | ||
358 | snd_hdac_chip_writew(bus, STATESTS, STATESTS_INT_MASK); | ||
359 | |||
360 | /* clear rirb status */ | ||
361 | snd_hdac_chip_writeb(bus, RIRBSTS, RIRB_INT_MASK); | ||
362 | |||
363 | /* clear int status */ | ||
364 | snd_hdac_chip_writel(bus, INTSTS, AZX_INT_CTRL_EN | AZX_INT_ALL_STREAM); | ||
365 | } | ||
366 | |||
367 | /** | ||
368 | * snd_hdac_bus_init_chip - reset and start the controller registers | ||
369 | * @bus: HD-audio core bus | ||
370 | * @full_reset: Do full reset | ||
371 | */ | ||
372 | bool snd_hdac_bus_init_chip(struct hdac_bus *bus, bool full_reset) | ||
373 | { | ||
374 | if (bus->chip_init) | ||
375 | return false; | ||
376 | |||
377 | /* reset controller */ | ||
378 | azx_reset(bus, full_reset); | ||
379 | |||
380 | /* initialize interrupts */ | ||
381 | azx_int_clear(bus); | ||
382 | azx_int_enable(bus); | ||
383 | |||
384 | /* initialize the codec command I/O */ | ||
385 | snd_hdac_bus_init_cmd_io(bus); | ||
386 | |||
387 | /* program the position buffer */ | ||
388 | if (bus->use_posbuf && bus->posbuf.addr) { | ||
389 | snd_hdac_chip_writel(bus, DPLBASE, (u32)bus->posbuf.addr); | ||
390 | snd_hdac_chip_writel(bus, DPUBASE, upper_32_bits(bus->posbuf.addr)); | ||
391 | } | ||
392 | |||
393 | bus->chip_init = true; | ||
394 | return true; | ||
395 | } | ||
396 | EXPORT_SYMBOL_GPL(snd_hdac_bus_init_chip); | ||
397 | |||
398 | /** | ||
399 | * snd_hdac_bus_stop_chip - disable the whole IRQ and I/Os | ||
400 | * @bus: HD-audio core bus | ||
401 | */ | ||
402 | void snd_hdac_bus_stop_chip(struct hdac_bus *bus) | ||
403 | { | ||
404 | if (!bus->chip_init) | ||
405 | return; | ||
406 | |||
407 | /* disable interrupts */ | ||
408 | azx_int_disable(bus); | ||
409 | azx_int_clear(bus); | ||
410 | |||
411 | /* disable CORB/RIRB */ | ||
412 | snd_hdac_bus_stop_cmd_io(bus); | ||
413 | |||
414 | /* disable position buffer */ | ||
415 | if (bus->posbuf.addr) { | ||
416 | snd_hdac_chip_writel(bus, DPLBASE, 0); | ||
417 | snd_hdac_chip_writel(bus, DPUBASE, 0); | ||
418 | } | ||
419 | |||
420 | bus->chip_init = false; | ||
421 | } | ||
422 | EXPORT_SYMBOL_GPL(snd_hdac_bus_stop_chip); | ||
423 | |||
424 | /** | ||
425 | * snd_hdac_bus_handle_stream_irq - interrupt handler for streams | ||
426 | * @bus: HD-audio core bus | ||
427 | * @status: INTSTS register value | ||
428 | * @ask: callback to be called for woken streams | ||
429 | */ | ||
430 | void snd_hdac_bus_handle_stream_irq(struct hdac_bus *bus, unsigned int status, | ||
431 | void (*ack)(struct hdac_bus *, | ||
432 | struct hdac_stream *)) | ||
433 | { | ||
434 | struct hdac_stream *azx_dev; | ||
435 | u8 sd_status; | ||
436 | |||
437 | list_for_each_entry(azx_dev, &bus->stream_list, list) { | ||
438 | if (status & azx_dev->sd_int_sta_mask) { | ||
439 | sd_status = snd_hdac_stream_readb(azx_dev, SD_STS); | ||
440 | snd_hdac_stream_writeb(azx_dev, SD_STS, SD_INT_MASK); | ||
441 | if (!azx_dev->substream || !azx_dev->running || | ||
442 | !(sd_status & SD_INT_COMPLETE)) | ||
443 | continue; | ||
444 | if (ack) | ||
445 | ack(bus, azx_dev); | ||
446 | } | ||
447 | } | ||
448 | } | ||
449 | EXPORT_SYMBOL_GPL(snd_hdac_bus_handle_stream_irq); | ||
450 | |||
451 | /** | ||
452 | * snd_hdac_bus_alloc_stream_pages - allocate BDL and other buffers | ||
453 | * @bus: HD-audio core bus | ||
454 | * | ||
455 | * Call this after assigning the all streams. | ||
456 | * Returns zero for success, or a negative error code. | ||
457 | */ | ||
458 | int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus) | ||
459 | { | ||
460 | struct hdac_stream *s; | ||
461 | int num_streams = 0; | ||
462 | int err; | ||
463 | |||
464 | list_for_each_entry(s, &bus->stream_list, list) { | ||
465 | /* allocate memory for the BDL for each stream */ | ||
466 | err = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, | ||
467 | BDL_SIZE, &s->bdl); | ||
468 | num_streams++; | ||
469 | if (err < 0) | ||
470 | return -ENOMEM; | ||
471 | } | ||
472 | |||
473 | if (WARN_ON(!num_streams)) | ||
474 | return -EINVAL; | ||
475 | /* allocate memory for the position buffer */ | ||
476 | err = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, | ||
477 | num_streams * 8, &bus->posbuf); | ||
478 | if (err < 0) | ||
479 | return -ENOMEM; | ||
480 | list_for_each_entry(s, &bus->stream_list, list) | ||
481 | s->posbuf = (__le32 *)(bus->posbuf.area + s->index * 8); | ||
482 | |||
483 | /* single page (at least 4096 bytes) must suffice for both ringbuffes */ | ||
484 | return bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, | ||
485 | PAGE_SIZE, &bus->rb); | ||
486 | } | ||
487 | EXPORT_SYMBOL_GPL(snd_hdac_bus_alloc_stream_pages); | ||
488 | |||
489 | /** | ||
490 | * snd_hdac_bus_free_stream_pages - release BDL and other buffers | ||
491 | * @bus: HD-audio core bus | ||
492 | */ | ||
493 | void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus) | ||
494 | { | ||
495 | struct hdac_stream *s; | ||
496 | |||
497 | list_for_each_entry(s, &bus->stream_list, list) { | ||
498 | if (s->bdl.area) | ||
499 | bus->io_ops->dma_free_pages(bus, &s->bdl); | ||
500 | } | ||
501 | |||
502 | if (bus->rb.area) | ||
503 | bus->io_ops->dma_free_pages(bus, &bus->rb); | ||
504 | if (bus->posbuf.area) | ||
505 | bus->io_ops->dma_free_pages(bus, &bus->posbuf); | ||
506 | } | ||
507 | EXPORT_SYMBOL_GPL(snd_hdac_bus_free_stream_pages); | ||
diff --git a/sound/hda/hdac_device.c b/sound/hda/hdac_device.c index f75bf5622687..cdee7103f649 100644 --- a/sound/hda/hdac_device.c +++ b/sound/hda/hdac_device.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <linux/pm_runtime.h> | 10 | #include <linux/pm_runtime.h> |
11 | #include <sound/hdaudio.h> | 11 | #include <sound/hdaudio.h> |
12 | #include <sound/hda_regmap.h> | 12 | #include <sound/hda_regmap.h> |
13 | #include <sound/pcm.h> | ||
13 | #include "local.h" | 14 | #include "local.h" |
14 | 15 | ||
15 | static void setup_fg_nodes(struct hdac_device *codec); | 16 | static void setup_fg_nodes(struct hdac_device *codec); |
@@ -551,6 +552,21 @@ void snd_hdac_power_down_pm(struct hdac_device *codec) | |||
551 | EXPORT_SYMBOL_GPL(snd_hdac_power_down_pm); | 552 | EXPORT_SYMBOL_GPL(snd_hdac_power_down_pm); |
552 | #endif | 553 | #endif |
553 | 554 | ||
555 | /* | ||
556 | * Enable/disable the link power for a codec. | ||
557 | */ | ||
558 | int snd_hdac_link_power(struct hdac_device *codec, bool enable) | ||
559 | { | ||
560 | if (!codec->link_power_control) | ||
561 | return 0; | ||
562 | |||
563 | if (codec->bus->ops->link_power) | ||
564 | return codec->bus->ops->link_power(codec->bus, enable); | ||
565 | else | ||
566 | return -EINVAL; | ||
567 | } | ||
568 | EXPORT_SYMBOL_GPL(snd_hdac_link_power); | ||
569 | |||
554 | /* codec vendor labels */ | 570 | /* codec vendor labels */ |
555 | struct hda_vendor_id { | 571 | struct hda_vendor_id { |
556 | unsigned int id; | 572 | unsigned int id; |
@@ -597,3 +613,302 @@ static int get_codec_vendor_name(struct hdac_device *codec) | |||
597 | codec->vendor_name = kasprintf(GFP_KERNEL, "Generic %04x", vendor_id); | 613 | codec->vendor_name = kasprintf(GFP_KERNEL, "Generic %04x", vendor_id); |
598 | return codec->vendor_name ? 0 : -ENOMEM; | 614 | return codec->vendor_name ? 0 : -ENOMEM; |
599 | } | 615 | } |
616 | |||
617 | /* | ||
618 | * stream formats | ||
619 | */ | ||
620 | struct hda_rate_tbl { | ||
621 | unsigned int hz; | ||
622 | unsigned int alsa_bits; | ||
623 | unsigned int hda_fmt; | ||
624 | }; | ||
625 | |||
626 | /* rate = base * mult / div */ | ||
627 | #define HDA_RATE(base, mult, div) \ | ||
628 | (AC_FMT_BASE_##base##K | (((mult) - 1) << AC_FMT_MULT_SHIFT) | \ | ||
629 | (((div) - 1) << AC_FMT_DIV_SHIFT)) | ||
630 | |||
631 | static struct hda_rate_tbl rate_bits[] = { | ||
632 | /* rate in Hz, ALSA rate bitmask, HDA format value */ | ||
633 | |||
634 | /* autodetected value used in snd_hda_query_supported_pcm */ | ||
635 | { 8000, SNDRV_PCM_RATE_8000, HDA_RATE(48, 1, 6) }, | ||
636 | { 11025, SNDRV_PCM_RATE_11025, HDA_RATE(44, 1, 4) }, | ||
637 | { 16000, SNDRV_PCM_RATE_16000, HDA_RATE(48, 1, 3) }, | ||
638 | { 22050, SNDRV_PCM_RATE_22050, HDA_RATE(44, 1, 2) }, | ||
639 | { 32000, SNDRV_PCM_RATE_32000, HDA_RATE(48, 2, 3) }, | ||
640 | { 44100, SNDRV_PCM_RATE_44100, HDA_RATE(44, 1, 1) }, | ||
641 | { 48000, SNDRV_PCM_RATE_48000, HDA_RATE(48, 1, 1) }, | ||
642 | { 88200, SNDRV_PCM_RATE_88200, HDA_RATE(44, 2, 1) }, | ||
643 | { 96000, SNDRV_PCM_RATE_96000, HDA_RATE(48, 2, 1) }, | ||
644 | { 176400, SNDRV_PCM_RATE_176400, HDA_RATE(44, 4, 1) }, | ||
645 | { 192000, SNDRV_PCM_RATE_192000, HDA_RATE(48, 4, 1) }, | ||
646 | #define AC_PAR_PCM_RATE_BITS 11 | ||
647 | /* up to bits 10, 384kHZ isn't supported properly */ | ||
648 | |||
649 | /* not autodetected value */ | ||
650 | { 9600, SNDRV_PCM_RATE_KNOT, HDA_RATE(48, 1, 5) }, | ||
651 | |||
652 | { 0 } /* terminator */ | ||
653 | }; | ||
654 | |||
655 | /** | ||
656 | * snd_hdac_calc_stream_format - calculate the format bitset | ||
657 | * @rate: the sample rate | ||
658 | * @channels: the number of channels | ||
659 | * @format: the PCM format (SNDRV_PCM_FORMAT_XXX) | ||
660 | * @maxbps: the max. bps | ||
661 | * @spdif_ctls: HD-audio SPDIF status bits (0 if irrelevant) | ||
662 | * | ||
663 | * Calculate the format bitset from the given rate, channels and th PCM format. | ||
664 | * | ||
665 | * Return zero if invalid. | ||
666 | */ | ||
667 | unsigned int snd_hdac_calc_stream_format(unsigned int rate, | ||
668 | unsigned int channels, | ||
669 | unsigned int format, | ||
670 | unsigned int maxbps, | ||
671 | unsigned short spdif_ctls) | ||
672 | { | ||
673 | int i; | ||
674 | unsigned int val = 0; | ||
675 | |||
676 | for (i = 0; rate_bits[i].hz; i++) | ||
677 | if (rate_bits[i].hz == rate) { | ||
678 | val = rate_bits[i].hda_fmt; | ||
679 | break; | ||
680 | } | ||
681 | if (!rate_bits[i].hz) | ||
682 | return 0; | ||
683 | |||
684 | if (channels == 0 || channels > 8) | ||
685 | return 0; | ||
686 | val |= channels - 1; | ||
687 | |||
688 | switch (snd_pcm_format_width(format)) { | ||
689 | case 8: | ||
690 | val |= AC_FMT_BITS_8; | ||
691 | break; | ||
692 | case 16: | ||
693 | val |= AC_FMT_BITS_16; | ||
694 | break; | ||
695 | case 20: | ||
696 | case 24: | ||
697 | case 32: | ||
698 | if (maxbps >= 32 || format == SNDRV_PCM_FORMAT_FLOAT_LE) | ||
699 | val |= AC_FMT_BITS_32; | ||
700 | else if (maxbps >= 24) | ||
701 | val |= AC_FMT_BITS_24; | ||
702 | else | ||
703 | val |= AC_FMT_BITS_20; | ||
704 | break; | ||
705 | default: | ||
706 | return 0; | ||
707 | } | ||
708 | |||
709 | if (spdif_ctls & AC_DIG1_NONAUDIO) | ||
710 | val |= AC_FMT_TYPE_NON_PCM; | ||
711 | |||
712 | return val; | ||
713 | } | ||
714 | EXPORT_SYMBOL_GPL(snd_hdac_calc_stream_format); | ||
715 | |||
716 | static unsigned int query_pcm_param(struct hdac_device *codec, hda_nid_t nid) | ||
717 | { | ||
718 | unsigned int val = 0; | ||
719 | |||
720 | if (nid != codec->afg && | ||
721 | (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) | ||
722 | val = snd_hdac_read_parm(codec, nid, AC_PAR_PCM); | ||
723 | if (!val || val == -1) | ||
724 | val = snd_hdac_read_parm(codec, codec->afg, AC_PAR_PCM); | ||
725 | if (!val || val == -1) | ||
726 | return 0; | ||
727 | return val; | ||
728 | } | ||
729 | |||
730 | static unsigned int query_stream_param(struct hdac_device *codec, hda_nid_t nid) | ||
731 | { | ||
732 | unsigned int streams = snd_hdac_read_parm(codec, nid, AC_PAR_STREAM); | ||
733 | |||
734 | if (!streams || streams == -1) | ||
735 | streams = snd_hdac_read_parm(codec, codec->afg, AC_PAR_STREAM); | ||
736 | if (!streams || streams == -1) | ||
737 | return 0; | ||
738 | return streams; | ||
739 | } | ||
740 | |||
741 | /** | ||
742 | * snd_hdac_query_supported_pcm - query the supported PCM rates and formats | ||
743 | * @codec: the codec object | ||
744 | * @nid: NID to query | ||
745 | * @ratesp: the pointer to store the detected rate bitflags | ||
746 | * @formatsp: the pointer to store the detected formats | ||
747 | * @bpsp: the pointer to store the detected format widths | ||
748 | * | ||
749 | * Queries the supported PCM rates and formats. The NULL @ratesp, @formatsp | ||
750 | * or @bsps argument is ignored. | ||
751 | * | ||
752 | * Returns 0 if successful, otherwise a negative error code. | ||
753 | */ | ||
754 | int snd_hdac_query_supported_pcm(struct hdac_device *codec, hda_nid_t nid, | ||
755 | u32 *ratesp, u64 *formatsp, unsigned int *bpsp) | ||
756 | { | ||
757 | unsigned int i, val, wcaps; | ||
758 | |||
759 | wcaps = get_wcaps(codec, nid); | ||
760 | val = query_pcm_param(codec, nid); | ||
761 | |||
762 | if (ratesp) { | ||
763 | u32 rates = 0; | ||
764 | for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++) { | ||
765 | if (val & (1 << i)) | ||
766 | rates |= rate_bits[i].alsa_bits; | ||
767 | } | ||
768 | if (rates == 0) { | ||
769 | dev_err(&codec->dev, | ||
770 | "rates == 0 (nid=0x%x, val=0x%x, ovrd=%i)\n", | ||
771 | nid, val, | ||
772 | (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0); | ||
773 | return -EIO; | ||
774 | } | ||
775 | *ratesp = rates; | ||
776 | } | ||
777 | |||
778 | if (formatsp || bpsp) { | ||
779 | u64 formats = 0; | ||
780 | unsigned int streams, bps; | ||
781 | |||
782 | streams = query_stream_param(codec, nid); | ||
783 | if (!streams) | ||
784 | return -EIO; | ||
785 | |||
786 | bps = 0; | ||
787 | if (streams & AC_SUPFMT_PCM) { | ||
788 | if (val & AC_SUPPCM_BITS_8) { | ||
789 | formats |= SNDRV_PCM_FMTBIT_U8; | ||
790 | bps = 8; | ||
791 | } | ||
792 | if (val & AC_SUPPCM_BITS_16) { | ||
793 | formats |= SNDRV_PCM_FMTBIT_S16_LE; | ||
794 | bps = 16; | ||
795 | } | ||
796 | if (wcaps & AC_WCAP_DIGITAL) { | ||
797 | if (val & AC_SUPPCM_BITS_32) | ||
798 | formats |= SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE; | ||
799 | if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24)) | ||
800 | formats |= SNDRV_PCM_FMTBIT_S32_LE; | ||
801 | if (val & AC_SUPPCM_BITS_24) | ||
802 | bps = 24; | ||
803 | else if (val & AC_SUPPCM_BITS_20) | ||
804 | bps = 20; | ||
805 | } else if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24| | ||
806 | AC_SUPPCM_BITS_32)) { | ||
807 | formats |= SNDRV_PCM_FMTBIT_S32_LE; | ||
808 | if (val & AC_SUPPCM_BITS_32) | ||
809 | bps = 32; | ||
810 | else if (val & AC_SUPPCM_BITS_24) | ||
811 | bps = 24; | ||
812 | else if (val & AC_SUPPCM_BITS_20) | ||
813 | bps = 20; | ||
814 | } | ||
815 | } | ||
816 | #if 0 /* FIXME: CS4206 doesn't work, which is the only codec supporting float */ | ||
817 | if (streams & AC_SUPFMT_FLOAT32) { | ||
818 | formats |= SNDRV_PCM_FMTBIT_FLOAT_LE; | ||
819 | if (!bps) | ||
820 | bps = 32; | ||
821 | } | ||
822 | #endif | ||
823 | if (streams == AC_SUPFMT_AC3) { | ||
824 | /* should be exclusive */ | ||
825 | /* temporary hack: we have still no proper support | ||
826 | * for the direct AC3 stream... | ||
827 | */ | ||
828 | formats |= SNDRV_PCM_FMTBIT_U8; | ||
829 | bps = 8; | ||
830 | } | ||
831 | if (formats == 0) { | ||
832 | dev_err(&codec->dev, | ||
833 | "formats == 0 (nid=0x%x, val=0x%x, ovrd=%i, streams=0x%x)\n", | ||
834 | nid, val, | ||
835 | (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0, | ||
836 | streams); | ||
837 | return -EIO; | ||
838 | } | ||
839 | if (formatsp) | ||
840 | *formatsp = formats; | ||
841 | if (bpsp) | ||
842 | *bpsp = bps; | ||
843 | } | ||
844 | |||
845 | return 0; | ||
846 | } | ||
847 | EXPORT_SYMBOL_GPL(snd_hdac_query_supported_pcm); | ||
848 | |||
849 | /** | ||
850 | * snd_hdac_is_supported_format - Check the validity of the format | ||
851 | * @codec: the codec object | ||
852 | * @nid: NID to check | ||
853 | * @format: the HD-audio format value to check | ||
854 | * | ||
855 | * Check whether the given node supports the format value. | ||
856 | * | ||
857 | * Returns true if supported, false if not. | ||
858 | */ | ||
859 | bool snd_hdac_is_supported_format(struct hdac_device *codec, hda_nid_t nid, | ||
860 | unsigned int format) | ||
861 | { | ||
862 | int i; | ||
863 | unsigned int val = 0, rate, stream; | ||
864 | |||
865 | val = query_pcm_param(codec, nid); | ||
866 | if (!val) | ||
867 | return false; | ||
868 | |||
869 | rate = format & 0xff00; | ||
870 | for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++) | ||
871 | if (rate_bits[i].hda_fmt == rate) { | ||
872 | if (val & (1 << i)) | ||
873 | break; | ||
874 | return false; | ||
875 | } | ||
876 | if (i >= AC_PAR_PCM_RATE_BITS) | ||
877 | return false; | ||
878 | |||
879 | stream = query_stream_param(codec, nid); | ||
880 | if (!stream) | ||
881 | return false; | ||
882 | |||
883 | if (stream & AC_SUPFMT_PCM) { | ||
884 | switch (format & 0xf0) { | ||
885 | case 0x00: | ||
886 | if (!(val & AC_SUPPCM_BITS_8)) | ||
887 | return false; | ||
888 | break; | ||
889 | case 0x10: | ||
890 | if (!(val & AC_SUPPCM_BITS_16)) | ||
891 | return false; | ||
892 | break; | ||
893 | case 0x20: | ||
894 | if (!(val & AC_SUPPCM_BITS_20)) | ||
895 | return false; | ||
896 | break; | ||
897 | case 0x30: | ||
898 | if (!(val & AC_SUPPCM_BITS_24)) | ||
899 | return false; | ||
900 | break; | ||
901 | case 0x40: | ||
902 | if (!(val & AC_SUPPCM_BITS_32)) | ||
903 | return false; | ||
904 | break; | ||
905 | default: | ||
906 | return false; | ||
907 | } | ||
908 | } else { | ||
909 | /* FIXME: check for float32 and AC3? */ | ||
910 | } | ||
911 | |||
912 | return true; | ||
913 | } | ||
914 | EXPORT_SYMBOL_GPL(snd_hdac_is_supported_format); | ||
diff --git a/sound/hda/hdac_i915.c b/sound/hda/hdac_i915.c new file mode 100644 index 000000000000..cb78c25585ac --- /dev/null +++ b/sound/hda/hdac_i915.c | |||
@@ -0,0 +1,193 @@ | |||
1 | /* | ||
2 | * hdac_i915.c - routines for sync between HD-A core and i915 display driver | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms of the GNU General Public License as published by the Free | ||
6 | * Software Foundation; either version 2 of the License, or (at your option) | ||
7 | * any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, but | ||
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
12 | * for more details. | ||
13 | */ | ||
14 | |||
15 | #include <linux/init.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/pci.h> | ||
18 | #include <linux/component.h> | ||
19 | #include <drm/i915_component.h> | ||
20 | #include <sound/core.h> | ||
21 | #include <sound/hdaudio.h> | ||
22 | #include <sound/hda_i915.h> | ||
23 | |||
24 | static struct i915_audio_component *hdac_acomp; | ||
25 | |||
26 | int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable) | ||
27 | { | ||
28 | struct i915_audio_component *acomp = bus->audio_component; | ||
29 | |||
30 | if (!acomp->ops) | ||
31 | return -ENODEV; | ||
32 | |||
33 | if (!acomp->ops->codec_wake_override) { | ||
34 | dev_warn(bus->dev, | ||
35 | "Invalid codec wake callback\n"); | ||
36 | return 0; | ||
37 | } | ||
38 | |||
39 | dev_dbg(bus->dev, "%s codec wakeup\n", | ||
40 | enable ? "enable" : "disable"); | ||
41 | |||
42 | acomp->ops->codec_wake_override(acomp->dev, enable); | ||
43 | |||
44 | return 0; | ||
45 | } | ||
46 | EXPORT_SYMBOL_GPL(snd_hdac_set_codec_wakeup); | ||
47 | |||
48 | int snd_hdac_display_power(struct hdac_bus *bus, bool enable) | ||
49 | { | ||
50 | struct i915_audio_component *acomp = bus->audio_component; | ||
51 | |||
52 | if (!acomp->ops) | ||
53 | return -ENODEV; | ||
54 | |||
55 | dev_dbg(bus->dev, "display power %s\n", | ||
56 | enable ? "enable" : "disable"); | ||
57 | |||
58 | if (enable) { | ||
59 | if (!bus->i915_power_refcount++) | ||
60 | acomp->ops->get_power(acomp->dev); | ||
61 | } else { | ||
62 | WARN_ON(!bus->i915_power_refcount); | ||
63 | if (!--bus->i915_power_refcount) | ||
64 | acomp->ops->put_power(acomp->dev); | ||
65 | } | ||
66 | |||
67 | return 0; | ||
68 | } | ||
69 | EXPORT_SYMBOL_GPL(snd_hdac_display_power); | ||
70 | |||
71 | int snd_hdac_get_display_clk(struct hdac_bus *bus) | ||
72 | { | ||
73 | struct i915_audio_component *acomp = bus->audio_component; | ||
74 | |||
75 | if (!acomp->ops) | ||
76 | return -ENODEV; | ||
77 | |||
78 | return acomp->ops->get_cdclk_freq(acomp->dev); | ||
79 | } | ||
80 | EXPORT_SYMBOL_GPL(snd_hdac_get_display_clk); | ||
81 | |||
82 | static int hdac_component_master_bind(struct device *dev) | ||
83 | { | ||
84 | struct i915_audio_component *acomp = hdac_acomp; | ||
85 | int ret; | ||
86 | |||
87 | ret = component_bind_all(dev, acomp); | ||
88 | if (ret < 0) | ||
89 | return ret; | ||
90 | |||
91 | if (WARN_ON(!(acomp->dev && acomp->ops && acomp->ops->get_power && | ||
92 | acomp->ops->put_power && acomp->ops->get_cdclk_freq))) { | ||
93 | ret = -EINVAL; | ||
94 | goto out_unbind; | ||
95 | } | ||
96 | |||
97 | /* | ||
98 | * Atm, we don't support dynamic unbinding initiated by the child | ||
99 | * component, so pin its containing module until we unbind. | ||
100 | */ | ||
101 | if (!try_module_get(acomp->ops->owner)) { | ||
102 | ret = -ENODEV; | ||
103 | goto out_unbind; | ||
104 | } | ||
105 | |||
106 | return 0; | ||
107 | |||
108 | out_unbind: | ||
109 | component_unbind_all(dev, acomp); | ||
110 | |||
111 | return ret; | ||
112 | } | ||
113 | |||
114 | static void hdac_component_master_unbind(struct device *dev) | ||
115 | { | ||
116 | struct i915_audio_component *acomp = hdac_acomp; | ||
117 | |||
118 | module_put(acomp->ops->owner); | ||
119 | component_unbind_all(dev, acomp); | ||
120 | WARN_ON(acomp->ops || acomp->dev); | ||
121 | } | ||
122 | |||
123 | static const struct component_master_ops hdac_component_master_ops = { | ||
124 | .bind = hdac_component_master_bind, | ||
125 | .unbind = hdac_component_master_unbind, | ||
126 | }; | ||
127 | |||
128 | static int hdac_component_master_match(struct device *dev, void *data) | ||
129 | { | ||
130 | /* i915 is the only supported component */ | ||
131 | return !strcmp(dev->driver->name, "i915"); | ||
132 | } | ||
133 | |||
134 | int snd_hdac_i915_init(struct hdac_bus *bus) | ||
135 | { | ||
136 | struct component_match *match = NULL; | ||
137 | struct device *dev = bus->dev; | ||
138 | struct i915_audio_component *acomp; | ||
139 | int ret; | ||
140 | |||
141 | acomp = kzalloc(sizeof(*acomp), GFP_KERNEL); | ||
142 | if (!acomp) | ||
143 | return -ENOMEM; | ||
144 | bus->audio_component = acomp; | ||
145 | hdac_acomp = acomp; | ||
146 | |||
147 | component_match_add(dev, &match, hdac_component_master_match, bus); | ||
148 | ret = component_master_add_with_match(dev, &hdac_component_master_ops, | ||
149 | match); | ||
150 | if (ret < 0) | ||
151 | goto out_err; | ||
152 | |||
153 | /* | ||
154 | * Atm, we don't support deferring the component binding, so make sure | ||
155 | * i915 is loaded and that the binding successfully completes. | ||
156 | */ | ||
157 | request_module("i915"); | ||
158 | |||
159 | if (!acomp->ops) { | ||
160 | ret = -ENODEV; | ||
161 | goto out_master_del; | ||
162 | } | ||
163 | dev_dbg(dev, "bound to i915 component master\n"); | ||
164 | |||
165 | return 0; | ||
166 | out_master_del: | ||
167 | component_master_del(dev, &hdac_component_master_ops); | ||
168 | out_err: | ||
169 | kfree(acomp); | ||
170 | bus->audio_component = NULL; | ||
171 | dev_err(dev, "failed to add i915 component master (%d)\n", ret); | ||
172 | |||
173 | return ret; | ||
174 | } | ||
175 | EXPORT_SYMBOL_GPL(snd_hdac_i915_init); | ||
176 | |||
177 | int snd_hdac_i915_exit(struct hdac_bus *bus) | ||
178 | { | ||
179 | struct device *dev = bus->dev; | ||
180 | struct i915_audio_component *acomp = bus->audio_component; | ||
181 | |||
182 | WARN_ON(bus->i915_power_refcount); | ||
183 | if (bus->i915_power_refcount > 0 && acomp && acomp->ops) | ||
184 | acomp->ops->put_power(acomp->dev); | ||
185 | |||
186 | component_master_del(dev, &hdac_component_master_ops); | ||
187 | |||
188 | kfree(acomp); | ||
189 | bus->audio_component = NULL; | ||
190 | |||
191 | return 0; | ||
192 | } | ||
193 | EXPORT_SYMBOL_GPL(snd_hdac_i915_exit); | ||
diff --git a/sound/hda/hdac_stream.c b/sound/hda/hdac_stream.c new file mode 100644 index 000000000000..4c15d0accc9e --- /dev/null +++ b/sound/hda/hdac_stream.c | |||
@@ -0,0 +1,697 @@ | |||
1 | /* | ||
2 | * HD-audio stream operations | ||
3 | */ | ||
4 | |||
5 | #include <linux/kernel.h> | ||
6 | #include <linux/delay.h> | ||
7 | #include <linux/export.h> | ||
8 | #include <linux/clocksource.h> | ||
9 | #include <sound/core.h> | ||
10 | #include <sound/pcm.h> | ||
11 | #include <sound/hdaudio.h> | ||
12 | #include <sound/hda_register.h> | ||
13 | #include "trace.h" | ||
14 | |||
15 | /** | ||
16 | * snd_hdac_stream_init - initialize each stream (aka device) | ||
17 | * @bus: HD-audio core bus | ||
18 | * @azx_dev: HD-audio core stream object to initialize | ||
19 | * @idx: stream index number | ||
20 | * @direction: stream direction (SNDRV_PCM_STREAM_PLAYBACK or SNDRV_PCM_STREAM_CAPTURE) | ||
21 | * @tag: the tag id to assign | ||
22 | * | ||
23 | * Assign the starting bdl address to each stream (device) and initialize. | ||
24 | */ | ||
25 | void snd_hdac_stream_init(struct hdac_bus *bus, struct hdac_stream *azx_dev, | ||
26 | int idx, int direction, int tag) | ||
27 | { | ||
28 | azx_dev->bus = bus; | ||
29 | /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ | ||
30 | azx_dev->sd_addr = bus->remap_addr + (0x20 * idx + 0x80); | ||
31 | /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */ | ||
32 | azx_dev->sd_int_sta_mask = 1 << idx; | ||
33 | azx_dev->index = idx; | ||
34 | azx_dev->direction = direction; | ||
35 | azx_dev->stream_tag = tag; | ||
36 | snd_hdac_dsp_lock_init(azx_dev); | ||
37 | list_add_tail(&azx_dev->list, &bus->stream_list); | ||
38 | } | ||
39 | EXPORT_SYMBOL_GPL(snd_hdac_stream_init); | ||
40 | |||
41 | /** | ||
42 | * snd_hdac_stream_start - start a stream | ||
43 | * @azx_dev: HD-audio core stream to start | ||
44 | * @fresh_start: false = wallclock timestamp relative to period wallclock | ||
45 | * | ||
46 | * Start a stream, set start_wallclk and set the running flag. | ||
47 | */ | ||
48 | void snd_hdac_stream_start(struct hdac_stream *azx_dev, bool fresh_start) | ||
49 | { | ||
50 | struct hdac_bus *bus = azx_dev->bus; | ||
51 | |||
52 | trace_snd_hdac_stream_start(bus, azx_dev); | ||
53 | |||
54 | azx_dev->start_wallclk = snd_hdac_chip_readl(bus, WALLCLK); | ||
55 | if (!fresh_start) | ||
56 | azx_dev->start_wallclk -= azx_dev->period_wallclk; | ||
57 | |||
58 | /* enable SIE */ | ||
59 | snd_hdac_chip_updatel(bus, INTCTL, 0, 1 << azx_dev->index); | ||
60 | /* set DMA start and interrupt mask */ | ||
61 | snd_hdac_stream_updateb(azx_dev, SD_CTL, | ||
62 | 0, SD_CTL_DMA_START | SD_INT_MASK); | ||
63 | azx_dev->running = true; | ||
64 | } | ||
65 | EXPORT_SYMBOL_GPL(snd_hdac_stream_start); | ||
66 | |||
67 | /** | ||
68 | * snd_hdac_stream_clear - stop a stream DMA | ||
69 | * @azx_dev: HD-audio core stream to stop | ||
70 | */ | ||
71 | void snd_hdac_stream_clear(struct hdac_stream *azx_dev) | ||
72 | { | ||
73 | snd_hdac_stream_updateb(azx_dev, SD_CTL, | ||
74 | SD_CTL_DMA_START | SD_INT_MASK, 0); | ||
75 | snd_hdac_stream_writeb(azx_dev, SD_STS, SD_INT_MASK); /* to be sure */ | ||
76 | azx_dev->running = false; | ||
77 | } | ||
78 | EXPORT_SYMBOL_GPL(snd_hdac_stream_clear); | ||
79 | |||
80 | /** | ||
81 | * snd_hdac_stream_stop - stop a stream | ||
82 | * @azx_dev: HD-audio core stream to stop | ||
83 | * | ||
84 | * Stop a stream DMA and disable stream interrupt | ||
85 | */ | ||
86 | void snd_hdac_stream_stop(struct hdac_stream *azx_dev) | ||
87 | { | ||
88 | trace_snd_hdac_stream_stop(azx_dev->bus, azx_dev); | ||
89 | |||
90 | snd_hdac_stream_clear(azx_dev); | ||
91 | /* disable SIE */ | ||
92 | snd_hdac_chip_updatel(azx_dev->bus, INTCTL, 1 << azx_dev->index, 0); | ||
93 | } | ||
94 | EXPORT_SYMBOL_GPL(snd_hdac_stream_stop); | ||
95 | |||
96 | /** | ||
97 | * snd_hdac_stream_reset - reset a stream | ||
98 | * @azx_dev: HD-audio core stream to reset | ||
99 | */ | ||
100 | void snd_hdac_stream_reset(struct hdac_stream *azx_dev) | ||
101 | { | ||
102 | unsigned char val; | ||
103 | int timeout; | ||
104 | |||
105 | snd_hdac_stream_clear(azx_dev); | ||
106 | |||
107 | snd_hdac_stream_updateb(azx_dev, SD_CTL, 0, SD_CTL_STREAM_RESET); | ||
108 | udelay(3); | ||
109 | timeout = 300; | ||
110 | do { | ||
111 | val = snd_hdac_stream_readb(azx_dev, SD_CTL) & | ||
112 | SD_CTL_STREAM_RESET; | ||
113 | if (val) | ||
114 | break; | ||
115 | } while (--timeout); | ||
116 | val &= ~SD_CTL_STREAM_RESET; | ||
117 | snd_hdac_stream_writeb(azx_dev, SD_CTL, val); | ||
118 | udelay(3); | ||
119 | |||
120 | timeout = 300; | ||
121 | /* waiting for hardware to report that the stream is out of reset */ | ||
122 | do { | ||
123 | val = snd_hdac_stream_readb(azx_dev, SD_CTL) & | ||
124 | SD_CTL_STREAM_RESET; | ||
125 | if (!val) | ||
126 | break; | ||
127 | } while (--timeout); | ||
128 | |||
129 | /* reset first position - may not be synced with hw at this time */ | ||
130 | if (azx_dev->posbuf) | ||
131 | *azx_dev->posbuf = 0; | ||
132 | } | ||
133 | EXPORT_SYMBOL_GPL(snd_hdac_stream_reset); | ||
134 | |||
135 | /** | ||
136 | * snd_hdac_stream_setup - set up the SD for streaming | ||
137 | * @azx_dev: HD-audio core stream to set up | ||
138 | */ | ||
139 | int snd_hdac_stream_setup(struct hdac_stream *azx_dev) | ||
140 | { | ||
141 | struct hdac_bus *bus = azx_dev->bus; | ||
142 | struct snd_pcm_runtime *runtime; | ||
143 | unsigned int val; | ||
144 | |||
145 | if (azx_dev->substream) | ||
146 | runtime = azx_dev->substream->runtime; | ||
147 | else | ||
148 | runtime = NULL; | ||
149 | /* make sure the run bit is zero for SD */ | ||
150 | snd_hdac_stream_clear(azx_dev); | ||
151 | /* program the stream_tag */ | ||
152 | val = snd_hdac_stream_readl(azx_dev, SD_CTL); | ||
153 | val = (val & ~SD_CTL_STREAM_TAG_MASK) | | ||
154 | (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT); | ||
155 | if (!bus->snoop) | ||
156 | val |= SD_CTL_TRAFFIC_PRIO; | ||
157 | snd_hdac_stream_writel(azx_dev, SD_CTL, val); | ||
158 | |||
159 | /* program the length of samples in cyclic buffer */ | ||
160 | snd_hdac_stream_writel(azx_dev, SD_CBL, azx_dev->bufsize); | ||
161 | |||
162 | /* program the stream format */ | ||
163 | /* this value needs to be the same as the one programmed */ | ||
164 | snd_hdac_stream_writew(azx_dev, SD_FORMAT, azx_dev->format_val); | ||
165 | |||
166 | /* program the stream LVI (last valid index) of the BDL */ | ||
167 | snd_hdac_stream_writew(azx_dev, SD_LVI, azx_dev->frags - 1); | ||
168 | |||
169 | /* program the BDL address */ | ||
170 | /* lower BDL address */ | ||
171 | snd_hdac_stream_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr); | ||
172 | /* upper BDL address */ | ||
173 | snd_hdac_stream_writel(azx_dev, SD_BDLPU, | ||
174 | upper_32_bits(azx_dev->bdl.addr)); | ||
175 | |||
176 | /* enable the position buffer */ | ||
177 | if (bus->use_posbuf && bus->posbuf.addr) { | ||
178 | if (!(snd_hdac_chip_readl(bus, DPLBASE) & AZX_DPLBASE_ENABLE)) | ||
179 | snd_hdac_chip_writel(bus, DPLBASE, | ||
180 | (u32)bus->posbuf.addr | AZX_DPLBASE_ENABLE); | ||
181 | } | ||
182 | |||
183 | /* set the interrupt enable bits in the descriptor control register */ | ||
184 | snd_hdac_stream_updatel(azx_dev, SD_CTL, 0, SD_INT_MASK); | ||
185 | |||
186 | if (azx_dev->direction == SNDRV_PCM_STREAM_PLAYBACK) | ||
187 | azx_dev->fifo_size = | ||
188 | snd_hdac_stream_readw(azx_dev, SD_FIFOSIZE) + 1; | ||
189 | else | ||
190 | azx_dev->fifo_size = 0; | ||
191 | |||
192 | /* when LPIB delay correction gives a small negative value, | ||
193 | * we ignore it; currently set the threshold statically to | ||
194 | * 64 frames | ||
195 | */ | ||
196 | if (runtime && runtime->period_size > 64) | ||
197 | azx_dev->delay_negative_threshold = | ||
198 | -frames_to_bytes(runtime, 64); | ||
199 | else | ||
200 | azx_dev->delay_negative_threshold = 0; | ||
201 | |||
202 | /* wallclk has 24Mhz clock source */ | ||
203 | if (runtime) | ||
204 | azx_dev->period_wallclk = (((runtime->period_size * 24000) / | ||
205 | runtime->rate) * 1000); | ||
206 | |||
207 | return 0; | ||
208 | } | ||
209 | EXPORT_SYMBOL_GPL(snd_hdac_stream_setup); | ||
210 | |||
211 | /** | ||
212 | * snd_hdac_stream_cleanup - cleanup a stream | ||
213 | * @azx_dev: HD-audio core stream to clean up | ||
214 | */ | ||
215 | void snd_hdac_stream_cleanup(struct hdac_stream *azx_dev) | ||
216 | { | ||
217 | snd_hdac_stream_writel(azx_dev, SD_BDLPL, 0); | ||
218 | snd_hdac_stream_writel(azx_dev, SD_BDLPU, 0); | ||
219 | snd_hdac_stream_writel(azx_dev, SD_CTL, 0); | ||
220 | azx_dev->bufsize = 0; | ||
221 | azx_dev->period_bytes = 0; | ||
222 | azx_dev->format_val = 0; | ||
223 | } | ||
224 | EXPORT_SYMBOL_GPL(snd_hdac_stream_cleanup); | ||
225 | |||
226 | /** | ||
227 | * snd_hdac_stream_assign - assign a stream for the PCM | ||
228 | * @bus: HD-audio core bus | ||
229 | * @substream: PCM substream to assign | ||
230 | * | ||
231 | * Look for an unused stream for the given PCM substream, assign it | ||
232 | * and return the stream object. If no stream is free, returns NULL. | ||
233 | * The function tries to keep using the same stream object when it's used | ||
234 | * beforehand. Also, when bus->reverse_assign flag is set, the last free | ||
235 | * or matching entry is returned. This is needed for some strange codecs. | ||
236 | */ | ||
237 | struct hdac_stream *snd_hdac_stream_assign(struct hdac_bus *bus, | ||
238 | struct snd_pcm_substream *substream) | ||
239 | { | ||
240 | struct hdac_stream *azx_dev; | ||
241 | struct hdac_stream *res = NULL; | ||
242 | |||
243 | /* make a non-zero unique key for the substream */ | ||
244 | int key = (substream->pcm->device << 16) | (substream->number << 2) | | ||
245 | (substream->stream + 1); | ||
246 | |||
247 | list_for_each_entry(azx_dev, &bus->stream_list, list) { | ||
248 | if (azx_dev->direction != substream->stream) | ||
249 | continue; | ||
250 | if (azx_dev->opened) | ||
251 | continue; | ||
252 | if (azx_dev->assigned_key == key) { | ||
253 | res = azx_dev; | ||
254 | break; | ||
255 | } | ||
256 | if (!res || bus->reverse_assign) | ||
257 | res = azx_dev; | ||
258 | } | ||
259 | if (res) { | ||
260 | spin_lock_irq(&bus->reg_lock); | ||
261 | res->opened = 1; | ||
262 | res->running = 0; | ||
263 | res->assigned_key = key; | ||
264 | res->substream = substream; | ||
265 | spin_unlock_irq(&bus->reg_lock); | ||
266 | } | ||
267 | return res; | ||
268 | } | ||
269 | EXPORT_SYMBOL_GPL(snd_hdac_stream_assign); | ||
270 | |||
271 | /** | ||
272 | * snd_hdac_stream_release - release the assigned stream | ||
273 | * @azx_dev: HD-audio core stream to release | ||
274 | * | ||
275 | * Release the stream that has been assigned by snd_hdac_stream_assign(). | ||
276 | */ | ||
277 | void snd_hdac_stream_release(struct hdac_stream *azx_dev) | ||
278 | { | ||
279 | struct hdac_bus *bus = azx_dev->bus; | ||
280 | |||
281 | spin_lock_irq(&bus->reg_lock); | ||
282 | azx_dev->opened = 0; | ||
283 | azx_dev->running = 0; | ||
284 | azx_dev->substream = NULL; | ||
285 | spin_unlock_irq(&bus->reg_lock); | ||
286 | } | ||
287 | EXPORT_SYMBOL_GPL(snd_hdac_stream_release); | ||
288 | |||
289 | /* | ||
290 | * set up a BDL entry | ||
291 | */ | ||
292 | static int setup_bdle(struct hdac_bus *bus, | ||
293 | struct snd_dma_buffer *dmab, | ||
294 | struct hdac_stream *azx_dev, __le32 **bdlp, | ||
295 | int ofs, int size, int with_ioc) | ||
296 | { | ||
297 | __le32 *bdl = *bdlp; | ||
298 | |||
299 | while (size > 0) { | ||
300 | dma_addr_t addr; | ||
301 | int chunk; | ||
302 | |||
303 | if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES) | ||
304 | return -EINVAL; | ||
305 | |||
306 | addr = snd_sgbuf_get_addr(dmab, ofs); | ||
307 | /* program the address field of the BDL entry */ | ||
308 | bdl[0] = cpu_to_le32((u32)addr); | ||
309 | bdl[1] = cpu_to_le32(upper_32_bits(addr)); | ||
310 | /* program the size field of the BDL entry */ | ||
311 | chunk = snd_sgbuf_get_chunk_size(dmab, ofs, size); | ||
312 | /* one BDLE cannot cross 4K boundary on CTHDA chips */ | ||
313 | if (bus->align_bdle_4k) { | ||
314 | u32 remain = 0x1000 - (ofs & 0xfff); | ||
315 | |||
316 | if (chunk > remain) | ||
317 | chunk = remain; | ||
318 | } | ||
319 | bdl[2] = cpu_to_le32(chunk); | ||
320 | /* program the IOC to enable interrupt | ||
321 | * only when the whole fragment is processed | ||
322 | */ | ||
323 | size -= chunk; | ||
324 | bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01); | ||
325 | bdl += 4; | ||
326 | azx_dev->frags++; | ||
327 | ofs += chunk; | ||
328 | } | ||
329 | *bdlp = bdl; | ||
330 | return ofs; | ||
331 | } | ||
332 | |||
333 | /** | ||
334 | * snd_hdac_stream_setup_periods - set up BDL entries | ||
335 | * @azx_dev: HD-audio core stream to set up | ||
336 | * | ||
337 | * Set up the buffer descriptor table of the given stream based on the | ||
338 | * period and buffer sizes of the assigned PCM substream. | ||
339 | */ | ||
340 | int snd_hdac_stream_setup_periods(struct hdac_stream *azx_dev) | ||
341 | { | ||
342 | struct hdac_bus *bus = azx_dev->bus; | ||
343 | struct snd_pcm_substream *substream = azx_dev->substream; | ||
344 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
345 | __le32 *bdl; | ||
346 | int i, ofs, periods, period_bytes; | ||
347 | int pos_adj, pos_align; | ||
348 | |||
349 | /* reset BDL address */ | ||
350 | snd_hdac_stream_writel(azx_dev, SD_BDLPL, 0); | ||
351 | snd_hdac_stream_writel(azx_dev, SD_BDLPU, 0); | ||
352 | |||
353 | period_bytes = azx_dev->period_bytes; | ||
354 | periods = azx_dev->bufsize / period_bytes; | ||
355 | |||
356 | /* program the initial BDL entries */ | ||
357 | bdl = (__le32 *)azx_dev->bdl.area; | ||
358 | ofs = 0; | ||
359 | azx_dev->frags = 0; | ||
360 | |||
361 | pos_adj = bus->bdl_pos_adj; | ||
362 | if (!azx_dev->no_period_wakeup && pos_adj > 0) { | ||
363 | pos_align = pos_adj; | ||
364 | pos_adj = (pos_adj * runtime->rate + 47999) / 48000; | ||
365 | if (!pos_adj) | ||
366 | pos_adj = pos_align; | ||
367 | else | ||
368 | pos_adj = ((pos_adj + pos_align - 1) / pos_align) * | ||
369 | pos_align; | ||
370 | pos_adj = frames_to_bytes(runtime, pos_adj); | ||
371 | if (pos_adj >= period_bytes) { | ||
372 | dev_warn(bus->dev, "Too big adjustment %d\n", | ||
373 | pos_adj); | ||
374 | pos_adj = 0; | ||
375 | } else { | ||
376 | ofs = setup_bdle(bus, snd_pcm_get_dma_buf(substream), | ||
377 | azx_dev, | ||
378 | &bdl, ofs, pos_adj, true); | ||
379 | if (ofs < 0) | ||
380 | goto error; | ||
381 | } | ||
382 | } else | ||
383 | pos_adj = 0; | ||
384 | |||
385 | for (i = 0; i < periods; i++) { | ||
386 | if (i == periods - 1 && pos_adj) | ||
387 | ofs = setup_bdle(bus, snd_pcm_get_dma_buf(substream), | ||
388 | azx_dev, &bdl, ofs, | ||
389 | period_bytes - pos_adj, 0); | ||
390 | else | ||
391 | ofs = setup_bdle(bus, snd_pcm_get_dma_buf(substream), | ||
392 | azx_dev, &bdl, ofs, | ||
393 | period_bytes, | ||
394 | !azx_dev->no_period_wakeup); | ||
395 | if (ofs < 0) | ||
396 | goto error; | ||
397 | } | ||
398 | return 0; | ||
399 | |||
400 | error: | ||
401 | dev_err(bus->dev, "Too many BDL entries: buffer=%d, period=%d\n", | ||
402 | azx_dev->bufsize, period_bytes); | ||
403 | return -EINVAL; | ||
404 | } | ||
405 | EXPORT_SYMBOL_GPL(snd_hdac_stream_setup_periods); | ||
406 | |||
407 | /* snd_hdac_stream_set_params - set stream parameters | ||
408 | * @azx_dev: HD-audio core stream for which parameters are to be set | ||
409 | * @format_val: format value parameter | ||
410 | * | ||
411 | * Setup the HD-audio core stream parameters from substream of the stream | ||
412 | * and passed format value | ||
413 | */ | ||
414 | int snd_hdac_stream_set_params(struct hdac_stream *azx_dev, | ||
415 | unsigned int format_val) | ||
416 | { | ||
417 | |||
418 | unsigned int bufsize, period_bytes; | ||
419 | struct snd_pcm_substream *substream = azx_dev->substream; | ||
420 | struct snd_pcm_runtime *runtime; | ||
421 | int err; | ||
422 | |||
423 | if (!substream) | ||
424 | return -EINVAL; | ||
425 | runtime = substream->runtime; | ||
426 | bufsize = snd_pcm_lib_buffer_bytes(substream); | ||
427 | period_bytes = snd_pcm_lib_period_bytes(substream); | ||
428 | |||
429 | if (bufsize != azx_dev->bufsize || | ||
430 | period_bytes != azx_dev->period_bytes || | ||
431 | format_val != azx_dev->format_val || | ||
432 | runtime->no_period_wakeup != azx_dev->no_period_wakeup) { | ||
433 | azx_dev->bufsize = bufsize; | ||
434 | azx_dev->period_bytes = period_bytes; | ||
435 | azx_dev->format_val = format_val; | ||
436 | azx_dev->no_period_wakeup = runtime->no_period_wakeup; | ||
437 | err = snd_hdac_stream_setup_periods(azx_dev); | ||
438 | if (err < 0) | ||
439 | return err; | ||
440 | } | ||
441 | return 0; | ||
442 | } | ||
443 | EXPORT_SYMBOL_GPL(snd_hdac_stream_set_params); | ||
444 | |||
445 | static cycle_t azx_cc_read(const struct cyclecounter *cc) | ||
446 | { | ||
447 | struct hdac_stream *azx_dev = container_of(cc, struct hdac_stream, cc); | ||
448 | |||
449 | return snd_hdac_chip_readl(azx_dev->bus, WALLCLK); | ||
450 | } | ||
451 | |||
452 | static void azx_timecounter_init(struct hdac_stream *azx_dev, | ||
453 | bool force, cycle_t last) | ||
454 | { | ||
455 | struct timecounter *tc = &azx_dev->tc; | ||
456 | struct cyclecounter *cc = &azx_dev->cc; | ||
457 | u64 nsec; | ||
458 | |||
459 | cc->read = azx_cc_read; | ||
460 | cc->mask = CLOCKSOURCE_MASK(32); | ||
461 | |||
462 | /* | ||
463 | * Converting from 24 MHz to ns means applying a 125/3 factor. | ||
464 | * To avoid any saturation issues in intermediate operations, | ||
465 | * the 125 factor is applied first. The division is applied | ||
466 | * last after reading the timecounter value. | ||
467 | * Applying the 1/3 factor as part of the multiplication | ||
468 | * requires at least 20 bits for a decent precision, however | ||
469 | * overflows occur after about 4 hours or less, not a option. | ||
470 | */ | ||
471 | |||
472 | cc->mult = 125; /* saturation after 195 years */ | ||
473 | cc->shift = 0; | ||
474 | |||
475 | nsec = 0; /* audio time is elapsed time since trigger */ | ||
476 | timecounter_init(tc, cc, nsec); | ||
477 | if (force) { | ||
478 | /* | ||
479 | * force timecounter to use predefined value, | ||
480 | * used for synchronized starts | ||
481 | */ | ||
482 | tc->cycle_last = last; | ||
483 | } | ||
484 | } | ||
485 | |||
486 | /** | ||
487 | * snd_hdac_stream_timecounter_init - initialize time counter | ||
488 | * @azx_dev: HD-audio core stream (master stream) | ||
489 | * @streams: bit flags of streams to set up | ||
490 | * | ||
491 | * Initializes the time counter of streams marked by the bit flags (each | ||
492 | * bit corresponds to the stream index). | ||
493 | * The trigger timestamp of PCM substream assigned to the given stream is | ||
494 | * updated accordingly, too. | ||
495 | */ | ||
496 | void snd_hdac_stream_timecounter_init(struct hdac_stream *azx_dev, | ||
497 | unsigned int streams) | ||
498 | { | ||
499 | struct hdac_bus *bus = azx_dev->bus; | ||
500 | struct snd_pcm_runtime *runtime = azx_dev->substream->runtime; | ||
501 | struct hdac_stream *s; | ||
502 | bool inited = false; | ||
503 | cycle_t cycle_last = 0; | ||
504 | int i = 0; | ||
505 | |||
506 | list_for_each_entry(s, &bus->stream_list, list) { | ||
507 | if (streams & (1 << i)) { | ||
508 | azx_timecounter_init(s, inited, cycle_last); | ||
509 | if (!inited) { | ||
510 | inited = true; | ||
511 | cycle_last = s->tc.cycle_last; | ||
512 | } | ||
513 | } | ||
514 | i++; | ||
515 | } | ||
516 | |||
517 | snd_pcm_gettime(runtime, &runtime->trigger_tstamp); | ||
518 | runtime->trigger_tstamp_latched = true; | ||
519 | } | ||
520 | EXPORT_SYMBOL_GPL(snd_hdac_stream_timecounter_init); | ||
521 | |||
522 | /** | ||
523 | * snd_hdac_stream_sync_trigger - turn on/off stream sync register | ||
524 | * @azx_dev: HD-audio core stream (master stream) | ||
525 | * @streams: bit flags of streams to sync | ||
526 | */ | ||
527 | void snd_hdac_stream_sync_trigger(struct hdac_stream *azx_dev, bool set, | ||
528 | unsigned int streams, unsigned int reg) | ||
529 | { | ||
530 | struct hdac_bus *bus = azx_dev->bus; | ||
531 | unsigned int val; | ||
532 | |||
533 | if (!reg) | ||
534 | reg = AZX_REG_SSYNC; | ||
535 | val = _snd_hdac_chip_read(l, bus, reg); | ||
536 | if (set) | ||
537 | val |= streams; | ||
538 | else | ||
539 | val &= ~streams; | ||
540 | _snd_hdac_chip_write(l, bus, reg, val); | ||
541 | } | ||
542 | EXPORT_SYMBOL_GPL(snd_hdac_stream_sync_trigger); | ||
543 | |||
544 | /** | ||
545 | * snd_hdac_stream_sync - sync with start/strop trigger operation | ||
546 | * @azx_dev: HD-audio core stream (master stream) | ||
547 | * @start: true = start, false = stop | ||
548 | * @streams: bit flags of streams to sync | ||
549 | * | ||
550 | * For @start = true, wait until all FIFOs get ready. | ||
551 | * For @start = false, wait until all RUN bits are cleared. | ||
552 | */ | ||
553 | void snd_hdac_stream_sync(struct hdac_stream *azx_dev, bool start, | ||
554 | unsigned int streams) | ||
555 | { | ||
556 | struct hdac_bus *bus = azx_dev->bus; | ||
557 | int i, nwait, timeout; | ||
558 | struct hdac_stream *s; | ||
559 | |||
560 | for (timeout = 5000; timeout; timeout--) { | ||
561 | nwait = 0; | ||
562 | i = 0; | ||
563 | list_for_each_entry(s, &bus->stream_list, list) { | ||
564 | if (streams & (1 << i)) { | ||
565 | if (start) { | ||
566 | /* check FIFO gets ready */ | ||
567 | if (!(snd_hdac_stream_readb(s, SD_STS) & | ||
568 | SD_STS_FIFO_READY)) | ||
569 | nwait++; | ||
570 | } else { | ||
571 | /* check RUN bit is cleared */ | ||
572 | if (snd_hdac_stream_readb(s, SD_CTL) & | ||
573 | SD_CTL_DMA_START) | ||
574 | nwait++; | ||
575 | } | ||
576 | } | ||
577 | i++; | ||
578 | } | ||
579 | if (!nwait) | ||
580 | break; | ||
581 | cpu_relax(); | ||
582 | } | ||
583 | } | ||
584 | EXPORT_SYMBOL_GPL(snd_hdac_stream_sync); | ||
585 | |||
586 | #ifdef CONFIG_SND_HDA_DSP_LOADER | ||
587 | /** | ||
588 | * snd_hdac_dsp_prepare - prepare for DSP loading | ||
589 | * @azx_dev: HD-audio core stream used for DSP loading | ||
590 | * @format: HD-audio stream format | ||
591 | * @byte_size: data chunk byte size | ||
592 | * @bufp: allocated buffer | ||
593 | * | ||
594 | * Allocate the buffer for the given size and set up the given stream for | ||
595 | * DSP loading. Returns the stream tag (>= 0), or a negative error code. | ||
596 | */ | ||
597 | int snd_hdac_dsp_prepare(struct hdac_stream *azx_dev, unsigned int format, | ||
598 | unsigned int byte_size, struct snd_dma_buffer *bufp) | ||
599 | { | ||
600 | struct hdac_bus *bus = azx_dev->bus; | ||
601 | u32 *bdl; | ||
602 | int err; | ||
603 | |||
604 | snd_hdac_dsp_lock(azx_dev); | ||
605 | spin_lock_irq(&bus->reg_lock); | ||
606 | if (azx_dev->running || azx_dev->locked) { | ||
607 | spin_unlock_irq(&bus->reg_lock); | ||
608 | err = -EBUSY; | ||
609 | goto unlock; | ||
610 | } | ||
611 | azx_dev->locked = true; | ||
612 | spin_unlock_irq(&bus->reg_lock); | ||
613 | |||
614 | err = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV_SG, | ||
615 | byte_size, bufp); | ||
616 | if (err < 0) | ||
617 | goto err_alloc; | ||
618 | |||
619 | azx_dev->substream = NULL; | ||
620 | azx_dev->bufsize = byte_size; | ||
621 | azx_dev->period_bytes = byte_size; | ||
622 | azx_dev->format_val = format; | ||
623 | |||
624 | snd_hdac_stream_reset(azx_dev); | ||
625 | |||
626 | /* reset BDL address */ | ||
627 | snd_hdac_stream_writel(azx_dev, SD_BDLPL, 0); | ||
628 | snd_hdac_stream_writel(azx_dev, SD_BDLPU, 0); | ||
629 | |||
630 | azx_dev->frags = 0; | ||
631 | bdl = (u32 *)azx_dev->bdl.area; | ||
632 | err = setup_bdle(bus, bufp, azx_dev, &bdl, 0, byte_size, 0); | ||
633 | if (err < 0) | ||
634 | goto error; | ||
635 | |||
636 | snd_hdac_stream_setup(azx_dev); | ||
637 | snd_hdac_dsp_unlock(azx_dev); | ||
638 | return azx_dev->stream_tag; | ||
639 | |||
640 | error: | ||
641 | bus->io_ops->dma_free_pages(bus, bufp); | ||
642 | err_alloc: | ||
643 | spin_lock_irq(&bus->reg_lock); | ||
644 | azx_dev->locked = false; | ||
645 | spin_unlock_irq(&bus->reg_lock); | ||
646 | unlock: | ||
647 | snd_hdac_dsp_unlock(azx_dev); | ||
648 | return err; | ||
649 | } | ||
650 | EXPORT_SYMBOL_GPL(snd_hdac_dsp_prepare); | ||
651 | |||
652 | /** | ||
653 | * snd_hdac_dsp_trigger - start / stop DSP loading | ||
654 | * @azx_dev: HD-audio core stream used for DSP loading | ||
655 | * @start: trigger start or stop | ||
656 | */ | ||
657 | void snd_hdac_dsp_trigger(struct hdac_stream *azx_dev, bool start) | ||
658 | { | ||
659 | if (start) | ||
660 | snd_hdac_stream_start(azx_dev, true); | ||
661 | else | ||
662 | snd_hdac_stream_stop(azx_dev); | ||
663 | } | ||
664 | EXPORT_SYMBOL_GPL(snd_hdac_dsp_trigger); | ||
665 | |||
666 | /** | ||
667 | * snd_hdac_dsp_cleanup - clean up the stream from DSP loading to normal | ||
668 | * @azx_dev: HD-audio core stream used for DSP loading | ||
669 | * @dmab: buffer used by DSP loading | ||
670 | */ | ||
671 | void snd_hdac_dsp_cleanup(struct hdac_stream *azx_dev, | ||
672 | struct snd_dma_buffer *dmab) | ||
673 | { | ||
674 | struct hdac_bus *bus = azx_dev->bus; | ||
675 | |||
676 | if (!dmab->area || !azx_dev->locked) | ||
677 | return; | ||
678 | |||
679 | snd_hdac_dsp_lock(azx_dev); | ||
680 | /* reset BDL address */ | ||
681 | snd_hdac_stream_writel(azx_dev, SD_BDLPL, 0); | ||
682 | snd_hdac_stream_writel(azx_dev, SD_BDLPU, 0); | ||
683 | snd_hdac_stream_writel(azx_dev, SD_CTL, 0); | ||
684 | azx_dev->bufsize = 0; | ||
685 | azx_dev->period_bytes = 0; | ||
686 | azx_dev->format_val = 0; | ||
687 | |||
688 | bus->io_ops->dma_free_pages(bus, dmab); | ||
689 | dmab->area = NULL; | ||
690 | |||
691 | spin_lock_irq(&bus->reg_lock); | ||
692 | azx_dev->locked = false; | ||
693 | spin_unlock_irq(&bus->reg_lock); | ||
694 | snd_hdac_dsp_unlock(azx_dev); | ||
695 | } | ||
696 | EXPORT_SYMBOL_GPL(snd_hdac_dsp_cleanup); | ||
697 | #endif /* CONFIG_SND_HDA_DSP_LOADER */ | ||
diff --git a/sound/hda/trace.h b/sound/hda/trace.h index 33a7eb5573d4..e27e2c0b7b17 100644 --- a/sound/hda/trace.h +++ b/sound/hda/trace.h | |||
@@ -50,6 +50,33 @@ TRACE_EVENT(hda_unsol_event, | |||
50 | ), | 50 | ), |
51 | TP_printk("%s", __get_str(msg)) | 51 | TP_printk("%s", __get_str(msg)) |
52 | ); | 52 | ); |
53 | |||
54 | DECLARE_EVENT_CLASS(hdac_stream, | ||
55 | TP_PROTO(struct hdac_bus *bus, struct hdac_stream *azx_dev), | ||
56 | |||
57 | TP_ARGS(bus, azx_dev), | ||
58 | |||
59 | TP_STRUCT__entry( | ||
60 | __field(unsigned char, stream_tag) | ||
61 | ), | ||
62 | |||
63 | TP_fast_assign( | ||
64 | __entry->stream_tag = (azx_dev)->stream_tag; | ||
65 | ), | ||
66 | |||
67 | TP_printk("stream_tag: %d", __entry->stream_tag) | ||
68 | ); | ||
69 | |||
70 | DEFINE_EVENT(hdac_stream, snd_hdac_stream_start, | ||
71 | TP_PROTO(struct hdac_bus *bus, struct hdac_stream *azx_dev), | ||
72 | TP_ARGS(bus, azx_dev) | ||
73 | ); | ||
74 | |||
75 | DEFINE_EVENT(hdac_stream, snd_hdac_stream_stop, | ||
76 | TP_PROTO(struct hdac_bus *bus, struct hdac_stream *azx_dev), | ||
77 | TP_ARGS(bus, azx_dev) | ||
78 | ); | ||
79 | |||
53 | #endif /* __HDAC_TRACE_H */ | 80 | #endif /* __HDAC_TRACE_H */ |
54 | 81 | ||
55 | /* This part must be outside protection */ | 82 | /* This part must be outside protection */ |
diff --git a/sound/oss/ad1848.c b/sound/oss/ad1848.c index ec1ee07df59d..10c8de1f8d29 100644 --- a/sound/oss/ad1848.c +++ b/sound/oss/ad1848.c | |||
@@ -2860,6 +2860,7 @@ static struct { | |||
2860 | {NULL} | 2860 | {NULL} |
2861 | }; | 2861 | }; |
2862 | 2862 | ||
2863 | #ifdef MODULE | ||
2863 | static struct isapnp_device_id id_table[] = { | 2864 | static struct isapnp_device_id id_table[] = { |
2864 | { ISAPNP_VENDOR('C','M','I'), ISAPNP_DEVICE(0x0001), | 2865 | { ISAPNP_VENDOR('C','M','I'), ISAPNP_DEVICE(0x0001), |
2865 | ISAPNP_VENDOR('@','@','@'), ISAPNP_FUNCTION(0x0001), 0 }, | 2866 | ISAPNP_VENDOR('@','@','@'), ISAPNP_FUNCTION(0x0001), 0 }, |
@@ -2877,6 +2878,7 @@ static struct isapnp_device_id id_table[] = { | |||
2877 | }; | 2878 | }; |
2878 | 2879 | ||
2879 | MODULE_DEVICE_TABLE(isapnp, id_table); | 2880 | MODULE_DEVICE_TABLE(isapnp, id_table); |
2881 | #endif | ||
2880 | 2882 | ||
2881 | static struct pnp_dev *activate_dev(char *devname, char *resname, struct pnp_dev *dev) | 2883 | static struct pnp_dev *activate_dev(char *devname, char *resname, struct pnp_dev *dev) |
2882 | { | 2884 | { |
diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c index 66ddd981d1d5..1fc6d8bc09e5 100644 --- a/sound/pci/ad1889.c +++ b/sound/pci/ad1889.c | |||
@@ -898,8 +898,8 @@ snd_ad1889_create(struct snd_card *card, | |||
898 | return err; | 898 | return err; |
899 | 899 | ||
900 | /* check PCI availability (32bit DMA) */ | 900 | /* check PCI availability (32bit DMA) */ |
901 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 || | 901 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0 || |
902 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) { | 902 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) { |
903 | dev_err(card->dev, "error setting 32-bit DMA mask.\n"); | 903 | dev_err(card->dev, "error setting 32-bit DMA mask.\n"); |
904 | pci_disable_device(pci); | 904 | pci_disable_device(pci); |
905 | return -ENXIO; | 905 | return -ENXIO; |
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c index c8d499575c01..36470af7eda7 100644 --- a/sound/pci/ali5451/ali5451.c +++ b/sound/pci/ali5451/ali5451.c | |||
@@ -2105,8 +2105,8 @@ static int snd_ali_create(struct snd_card *card, | |||
2105 | if (err < 0) | 2105 | if (err < 0) |
2106 | return err; | 2106 | return err; |
2107 | /* check, if we can restrict PCI DMA transfers to 31 bits */ | 2107 | /* check, if we can restrict PCI DMA transfers to 31 bits */ |
2108 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(31)) < 0 || | 2108 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(31)) < 0 || |
2109 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(31)) < 0) { | 2109 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(31)) < 0) { |
2110 | dev_err(card->dev, | 2110 | dev_err(card->dev, |
2111 | "architecture does not support 31bit PCI busmaster DMA\n"); | 2111 | "architecture does not support 31bit PCI busmaster DMA\n"); |
2112 | pci_disable_device(pci); | 2112 | pci_disable_device(pci); |
diff --git a/sound/pci/als300.c b/sound/pci/als300.c index 57e034f208dc..add3176398d3 100644 --- a/sound/pci/als300.c +++ b/sound/pci/als300.c | |||
@@ -658,8 +658,8 @@ static int snd_als300_create(struct snd_card *card, | |||
658 | if ((err = pci_enable_device(pci)) < 0) | 658 | if ((err = pci_enable_device(pci)) < 0) |
659 | return err; | 659 | return err; |
660 | 660 | ||
661 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 || | 661 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(28)) < 0 || |
662 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) { | 662 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(28)) < 0) { |
663 | dev_err(card->dev, "error setting 28bit DMA mask\n"); | 663 | dev_err(card->dev, "error setting 28bit DMA mask\n"); |
664 | pci_disable_device(pci); | 664 | pci_disable_device(pci); |
665 | return -ENXIO; | 665 | return -ENXIO; |
diff --git a/sound/pci/als4000.c b/sound/pci/als4000.c index a3dea464134d..ff39a0c7277b 100644 --- a/sound/pci/als4000.c +++ b/sound/pci/als4000.c | |||
@@ -871,8 +871,8 @@ static int snd_card_als4000_probe(struct pci_dev *pci, | |||
871 | return err; | 871 | return err; |
872 | } | 872 | } |
873 | /* check, if we can restrict PCI DMA transfers to 24 bits */ | 873 | /* check, if we can restrict PCI DMA transfers to 24 bits */ |
874 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 || | 874 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(24)) < 0 || |
875 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) { | 875 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(24)) < 0) { |
876 | dev_err(&pci->dev, "architecture does not support 24bit PCI busmaster DMA\n"); | 876 | dev_err(&pci->dev, "architecture does not support 24bit PCI busmaster DMA\n"); |
877 | pci_disable_device(pci); | 877 | pci_disable_device(pci); |
878 | return -ENXIO; | 878 | return -ENXIO; |
diff --git a/sound/pci/au88x0/au88x0.c b/sound/pci/au88x0/au88x0.c index 996369134ea8..32092184bbf2 100644 --- a/sound/pci/au88x0/au88x0.c +++ b/sound/pci/au88x0/au88x0.c | |||
@@ -150,8 +150,8 @@ snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip) | |||
150 | // check PCI availability (DMA). | 150 | // check PCI availability (DMA). |
151 | if ((err = pci_enable_device(pci)) < 0) | 151 | if ((err = pci_enable_device(pci)) < 0) |
152 | return err; | 152 | return err; |
153 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 || | 153 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0 || |
154 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) { | 154 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) { |
155 | dev_err(card->dev, "error to set DMA mask\n"); | 155 | dev_err(card->dev, "error to set DMA mask\n"); |
156 | pci_disable_device(pci); | 156 | pci_disable_device(pci); |
157 | return -ENXIO; | 157 | return -ENXIO; |
diff --git a/sound/pci/aw2/aw2-alsa.c b/sound/pci/aw2/aw2-alsa.c index 8d2fee7b33bd..167714303070 100644 --- a/sound/pci/aw2/aw2-alsa.c +++ b/sound/pci/aw2/aw2-alsa.c | |||
@@ -258,8 +258,8 @@ static int snd_aw2_create(struct snd_card *card, | |||
258 | pci_set_master(pci); | 258 | pci_set_master(pci); |
259 | 259 | ||
260 | /* check PCI availability (32bit DMA) */ | 260 | /* check PCI availability (32bit DMA) */ |
261 | if ((pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0) || | 261 | if ((dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) || |
262 | (pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0)) { | 262 | (dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)) < 0)) { |
263 | dev_err(card->dev, "Impossible to set 32bit mask DMA\n"); | 263 | dev_err(card->dev, "Impossible to set 32bit mask DMA\n"); |
264 | pci_disable_device(pci); | 264 | pci_disable_device(pci); |
265 | return -ENXIO; | 265 | return -ENXIO; |
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c index 33b2a0af1b59..07a4acc99541 100644 --- a/sound/pci/azt3328.c +++ b/sound/pci/azt3328.c | |||
@@ -2420,8 +2420,8 @@ snd_azf3328_create(struct snd_card *card, | |||
2420 | chip->irq = -1; | 2420 | chip->irq = -1; |
2421 | 2421 | ||
2422 | /* check if we can restrict PCI DMA transfers to 24 bits */ | 2422 | /* check if we can restrict PCI DMA transfers to 24 bits */ |
2423 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 || | 2423 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(24)) < 0 || |
2424 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) { | 2424 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(24)) < 0) { |
2425 | dev_err(card->dev, | 2425 | dev_err(card->dev, |
2426 | "architecture does not support 24bit PCI busmaster DMA\n" | 2426 | "architecture does not support 24bit PCI busmaster DMA\n" |
2427 | ); | 2427 | ); |
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c index dd75b7536fa2..0b31732eb4dc 100644 --- a/sound/pci/ca0106/ca0106_main.c +++ b/sound/pci/ca0106/ca0106_main.c | |||
@@ -1676,8 +1676,8 @@ static int snd_ca0106_create(int dev, struct snd_card *card, | |||
1676 | err = pci_enable_device(pci); | 1676 | err = pci_enable_device(pci); |
1677 | if (err < 0) | 1677 | if (err < 0) |
1678 | return err; | 1678 | return err; |
1679 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 || | 1679 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0 || |
1680 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) { | 1680 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) { |
1681 | dev_err(card->dev, "error to set 32bit mask DMA\n"); | 1681 | dev_err(card->dev, "error to set 32bit mask DMA\n"); |
1682 | pci_disable_device(pci); | 1682 | pci_disable_device(pci); |
1683 | return -ENXIO; | 1683 | return -ENXIO; |
diff --git a/sound/pci/cs5535audio/cs5535audio.c b/sound/pci/cs5535audio/cs5535audio.c index 963b912550d4..de409cda50aa 100644 --- a/sound/pci/cs5535audio/cs5535audio.c +++ b/sound/pci/cs5535audio/cs5535audio.c | |||
@@ -289,8 +289,8 @@ static int snd_cs5535audio_create(struct snd_card *card, | |||
289 | if ((err = pci_enable_device(pci)) < 0) | 289 | if ((err = pci_enable_device(pci)) < 0) |
290 | return err; | 290 | return err; |
291 | 291 | ||
292 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 || | 292 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0 || |
293 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) { | 293 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) { |
294 | dev_warn(card->dev, "unable to get 32bit dma\n"); | 294 | dev_warn(card->dev, "unable to get 32bit dma\n"); |
295 | err = -ENXIO; | 295 | err = -ENXIO; |
296 | goto pcifail; | 296 | goto pcifail; |
diff --git a/sound/pci/ctxfi/cthw20k1.c b/sound/pci/ctxfi/cthw20k1.c index 1cac55fd1139..9667cbfb0ca2 100644 --- a/sound/pci/ctxfi/cthw20k1.c +++ b/sound/pci/ctxfi/cthw20k1.c | |||
@@ -1910,8 +1910,8 @@ static int hw_card_start(struct hw *hw) | |||
1910 | return err; | 1910 | return err; |
1911 | 1911 | ||
1912 | /* Set DMA transfer mask */ | 1912 | /* Set DMA transfer mask */ |
1913 | if (pci_set_dma_mask(pci, CT_XFI_DMA_MASK) < 0 || | 1913 | if (dma_set_mask(&pci->dev, CT_XFI_DMA_MASK) < 0 || |
1914 | pci_set_consistent_dma_mask(pci, CT_XFI_DMA_MASK) < 0) { | 1914 | dma_set_coherent_mask(&pci->dev, CT_XFI_DMA_MASK) < 0) { |
1915 | dev_err(hw->card->dev, | 1915 | dev_err(hw->card->dev, |
1916 | "architecture does not support PCI busmaster DMA with mask 0x%llx\n", | 1916 | "architecture does not support PCI busmaster DMA with mask 0x%llx\n", |
1917 | CT_XFI_DMA_MASK); | 1917 | CT_XFI_DMA_MASK); |
diff --git a/sound/pci/ctxfi/cthw20k2.c b/sound/pci/ctxfi/cthw20k2.c index 955ad871e9a8..9dc2950e1ab7 100644 --- a/sound/pci/ctxfi/cthw20k2.c +++ b/sound/pci/ctxfi/cthw20k2.c | |||
@@ -2035,8 +2035,8 @@ static int hw_card_start(struct hw *hw) | |||
2035 | return err; | 2035 | return err; |
2036 | 2036 | ||
2037 | /* Set DMA transfer mask */ | 2037 | /* Set DMA transfer mask */ |
2038 | if (pci_set_dma_mask(pci, CT_XFI_DMA_MASK) < 0 || | 2038 | if (dma_set_mask(&pci->dev, CT_XFI_DMA_MASK) < 0 || |
2039 | pci_set_consistent_dma_mask(pci, CT_XFI_DMA_MASK) < 0) { | 2039 | dma_set_coherent_mask(&pci->dev, CT_XFI_DMA_MASK) < 0) { |
2040 | dev_err(hw->card->dev, | 2040 | dev_err(hw->card->dev, |
2041 | "architecture does not support PCI busmaster DMA with mask 0x%llx\n", | 2041 | "architecture does not support PCI busmaster DMA with mask 0x%llx\n", |
2042 | CT_XFI_DMA_MASK); | 2042 | CT_XFI_DMA_MASK); |
diff --git a/sound/pci/emu10k1/emu10k1.c b/sound/pci/emu10k1/emu10k1.c index 37d0220a094c..db7a2e5e4a14 100644 --- a/sound/pci/emu10k1/emu10k1.c +++ b/sound/pci/emu10k1/emu10k1.c | |||
@@ -183,8 +183,10 @@ static int snd_card_emu10k1_probe(struct pci_dev *pci, | |||
183 | } | 183 | } |
184 | #endif | 184 | #endif |
185 | 185 | ||
186 | strcpy(card->driver, emu->card_capabilities->driver); | 186 | strlcpy(card->driver, emu->card_capabilities->driver, |
187 | strcpy(card->shortname, emu->card_capabilities->name); | 187 | sizeof(card->driver)); |
188 | strlcpy(card->shortname, emu->card_capabilities->name, | ||
189 | sizeof(card->shortname)); | ||
188 | snprintf(card->longname, sizeof(card->longname), | 190 | snprintf(card->longname, sizeof(card->longname), |
189 | "%s (rev.%d, serial:0x%x) at 0x%lx, irq %i", | 191 | "%s (rev.%d, serial:0x%x) at 0x%lx, irq %i", |
190 | card->shortname, emu->revision, emu->serial, emu->port, emu->irq); | 192 | card->shortname, emu->revision, emu->serial, emu->port, emu->irq); |
diff --git a/sound/pci/emu10k1/emu10k1_callback.c b/sound/pci/emu10k1/emu10k1_callback.c index 874cd76c7b7f..d2c7ea3a7610 100644 --- a/sound/pci/emu10k1/emu10k1_callback.c +++ b/sound/pci/emu10k1/emu10k1_callback.c | |||
@@ -415,7 +415,7 @@ start_voice(struct snd_emux_voice *vp) | |||
415 | snd_emu10k1_ptr_write(hw, Z2, ch, 0); | 415 | snd_emu10k1_ptr_write(hw, Z2, ch, 0); |
416 | 416 | ||
417 | /* invalidate maps */ | 417 | /* invalidate maps */ |
418 | temp = (hw->silent_page.addr << 1) | MAP_PTI_MASK; | 418 | temp = (hw->silent_page.addr << hw->address_mode) | (hw->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0); |
419 | snd_emu10k1_ptr_write(hw, MAPA, ch, temp); | 419 | snd_emu10k1_ptr_write(hw, MAPA, ch, temp); |
420 | snd_emu10k1_ptr_write(hw, MAPB, ch, temp); | 420 | snd_emu10k1_ptr_write(hw, MAPB, ch, temp); |
421 | #if 0 | 421 | #if 0 |
@@ -436,7 +436,7 @@ start_voice(struct snd_emux_voice *vp) | |||
436 | snd_emu10k1_ptr_write(hw, CDF, ch, sample); | 436 | snd_emu10k1_ptr_write(hw, CDF, ch, sample); |
437 | 437 | ||
438 | /* invalidate maps */ | 438 | /* invalidate maps */ |
439 | temp = ((unsigned int)hw->silent_page.addr << 1) | MAP_PTI_MASK; | 439 | temp = ((unsigned int)hw->silent_page.addr << hw_address_mode) | (hw->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0); |
440 | snd_emu10k1_ptr_write(hw, MAPA, ch, temp); | 440 | snd_emu10k1_ptr_write(hw, MAPA, ch, temp); |
441 | snd_emu10k1_ptr_write(hw, MAPB, ch, temp); | 441 | snd_emu10k1_ptr_write(hw, MAPB, ch, temp); |
442 | 442 | ||
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c index 54079f5d5673..54219fd662a1 100644 --- a/sound/pci/emu10k1/emu10k1_main.c +++ b/sound/pci/emu10k1/emu10k1_main.c | |||
@@ -282,7 +282,7 @@ static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume) | |||
282 | snd_emu10k1_ptr_write(emu, TCB, 0, 0); /* taken from original driver */ | 282 | snd_emu10k1_ptr_write(emu, TCB, 0, 0); /* taken from original driver */ |
283 | snd_emu10k1_ptr_write(emu, TCBS, 0, 4); /* taken from original driver */ | 283 | snd_emu10k1_ptr_write(emu, TCBS, 0, 4); /* taken from original driver */ |
284 | 284 | ||
285 | silent_page = (emu->silent_page.addr << 1) | MAP_PTI_MASK; | 285 | silent_page = (emu->silent_page.addr << emu->address_mode) | (emu->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0); |
286 | for (ch = 0; ch < NUM_G; ch++) { | 286 | for (ch = 0; ch < NUM_G; ch++) { |
287 | snd_emu10k1_ptr_write(emu, MAPA, ch, silent_page); | 287 | snd_emu10k1_ptr_write(emu, MAPA, ch, silent_page); |
288 | snd_emu10k1_ptr_write(emu, MAPB, ch, silent_page); | 288 | snd_emu10k1_ptr_write(emu, MAPB, ch, silent_page); |
@@ -348,6 +348,11 @@ static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume) | |||
348 | outl(reg | A_IOCFG_GPOUT0, emu->port + A_IOCFG); | 348 | outl(reg | A_IOCFG_GPOUT0, emu->port + A_IOCFG); |
349 | } | 349 | } |
350 | 350 | ||
351 | if (emu->address_mode == 0) { | ||
352 | /* use 16M in 4G */ | ||
353 | outl(inl(emu->port + HCFG) | HCFG_EXPANDED_MEM, emu->port + HCFG); | ||
354 | } | ||
355 | |||
351 | return 0; | 356 | return 0; |
352 | } | 357 | } |
353 | 358 | ||
@@ -1446,7 +1451,7 @@ static struct snd_emu_chip_details emu_chip_details[] = { | |||
1446 | * | 1451 | * |
1447 | */ | 1452 | */ |
1448 | {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x20011102, | 1453 | {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x20011102, |
1449 | .driver = "Audigy2", .name = "SB Audigy 2 ZS Notebook [SB0530]", | 1454 | .driver = "Audigy2", .name = "Audigy 2 ZS Notebook [SB0530]", |
1450 | .id = "Audigy2", | 1455 | .id = "Audigy2", |
1451 | .emu10k2_chip = 1, | 1456 | .emu10k2_chip = 1, |
1452 | .ca0108_chip = 1, | 1457 | .ca0108_chip = 1, |
@@ -1596,7 +1601,7 @@ static struct snd_emu_chip_details emu_chip_details[] = { | |||
1596 | .adc_1361t = 1, /* 24 bit capture instead of 16bit */ | 1601 | .adc_1361t = 1, /* 24 bit capture instead of 16bit */ |
1597 | .ac97_chip = 1} , | 1602 | .ac97_chip = 1} , |
1598 | {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102, | 1603 | {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102, |
1599 | .driver = "Audigy2", .name = "SB Audigy 2 Platinum EX [SB0280]", | 1604 | .driver = "Audigy2", .name = "Audigy 2 Platinum EX [SB0280]", |
1600 | .id = "Audigy2", | 1605 | .id = "Audigy2", |
1601 | .emu10k2_chip = 1, | 1606 | .emu10k2_chip = 1, |
1602 | .ca0102_chip = 1, | 1607 | .ca0102_chip = 1, |
@@ -1902,10 +1907,12 @@ int snd_emu10k1_create(struct snd_card *card, | |||
1902 | 1907 | ||
1903 | is_audigy = emu->audigy = c->emu10k2_chip; | 1908 | is_audigy = emu->audigy = c->emu10k2_chip; |
1904 | 1909 | ||
1910 | /* set addressing mode */ | ||
1911 | emu->address_mode = is_audigy ? 0 : 1; | ||
1905 | /* set the DMA transfer mask */ | 1912 | /* set the DMA transfer mask */ |
1906 | emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK; | 1913 | emu->dma_mask = emu->address_mode ? EMU10K1_DMA_MASK : AUDIGY_DMA_MASK; |
1907 | if (pci_set_dma_mask(pci, emu->dma_mask) < 0 || | 1914 | if (dma_set_mask(&pci->dev, emu->dma_mask) < 0 || |
1908 | pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) { | 1915 | dma_set_coherent_mask(&pci->dev, emu->dma_mask) < 0) { |
1909 | dev_err(card->dev, | 1916 | dev_err(card->dev, |
1910 | "architecture does not support PCI busmaster DMA with mask 0x%lx\n", | 1917 | "architecture does not support PCI busmaster DMA with mask 0x%lx\n", |
1911 | emu->dma_mask); | 1918 | emu->dma_mask); |
@@ -1928,7 +1935,7 @@ int snd_emu10k1_create(struct snd_card *card, | |||
1928 | 1935 | ||
1929 | emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT; | 1936 | emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT; |
1930 | if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), | 1937 | if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), |
1931 | 32 * 1024, &emu->ptb_pages) < 0) { | 1938 | (emu->address_mode ? 32 : 16) * 1024, &emu->ptb_pages) < 0) { |
1932 | err = -ENOMEM; | 1939 | err = -ENOMEM; |
1933 | goto error; | 1940 | goto error; |
1934 | } | 1941 | } |
@@ -2027,8 +2034,8 @@ int snd_emu10k1_create(struct snd_card *card, | |||
2027 | 2034 | ||
2028 | /* Clear silent pages and set up pointers */ | 2035 | /* Clear silent pages and set up pointers */ |
2029 | memset(emu->silent_page.area, 0, PAGE_SIZE); | 2036 | memset(emu->silent_page.area, 0, PAGE_SIZE); |
2030 | silent_page = emu->silent_page.addr << 1; | 2037 | silent_page = emu->silent_page.addr << emu->address_mode; |
2031 | for (idx = 0; idx < MAXPAGES; idx++) | 2038 | for (idx = 0; idx < (emu->address_mode ? MAXPAGES1 : MAXPAGES0); idx++) |
2032 | ((u32 *)emu->ptb_pages.area)[idx] = cpu_to_le32(silent_page | idx); | 2039 | ((u32 *)emu->ptb_pages.area)[idx] = cpu_to_le32(silent_page | idx); |
2033 | 2040 | ||
2034 | /* set up voice indices */ | 2041 | /* set up voice indices */ |
diff --git a/sound/pci/emu10k1/emupcm.c b/sound/pci/emu10k1/emupcm.c index 0dc07385af0e..14a305bd8a98 100644 --- a/sound/pci/emu10k1/emupcm.c +++ b/sound/pci/emu10k1/emupcm.c | |||
@@ -380,7 +380,7 @@ static void snd_emu10k1_pcm_init_voice(struct snd_emu10k1 *emu, | |||
380 | snd_emu10k1_ptr_write(emu, Z1, voice, 0); | 380 | snd_emu10k1_ptr_write(emu, Z1, voice, 0); |
381 | snd_emu10k1_ptr_write(emu, Z2, voice, 0); | 381 | snd_emu10k1_ptr_write(emu, Z2, voice, 0); |
382 | /* invalidate maps */ | 382 | /* invalidate maps */ |
383 | silent_page = ((unsigned int)emu->silent_page.addr << 1) | MAP_PTI_MASK; | 383 | silent_page = ((unsigned int)emu->silent_page.addr << emu->address_mode) | (emu->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0); |
384 | snd_emu10k1_ptr_write(emu, MAPA, voice, silent_page); | 384 | snd_emu10k1_ptr_write(emu, MAPA, voice, silent_page); |
385 | snd_emu10k1_ptr_write(emu, MAPB, voice, silent_page); | 385 | snd_emu10k1_ptr_write(emu, MAPB, voice, silent_page); |
386 | /* modulation envelope */ | 386 | /* modulation envelope */ |
diff --git a/sound/pci/emu10k1/memory.c b/sound/pci/emu10k1/memory.c index c68e6dd2fa67..4f1f69be1865 100644 --- a/sound/pci/emu10k1/memory.c +++ b/sound/pci/emu10k1/memory.c | |||
@@ -34,10 +34,11 @@ | |||
34 | * aligned pages in others | 34 | * aligned pages in others |
35 | */ | 35 | */ |
36 | #define __set_ptb_entry(emu,page,addr) \ | 36 | #define __set_ptb_entry(emu,page,addr) \ |
37 | (((u32 *)(emu)->ptb_pages.area)[page] = cpu_to_le32(((addr) << 1) | (page))) | 37 | (((u32 *)(emu)->ptb_pages.area)[page] = cpu_to_le32(((addr) << (emu->address_mode)) | (page))) |
38 | 38 | ||
39 | #define UNIT_PAGES (PAGE_SIZE / EMUPAGESIZE) | 39 | #define UNIT_PAGES (PAGE_SIZE / EMUPAGESIZE) |
40 | #define MAX_ALIGN_PAGES (MAXPAGES / UNIT_PAGES) | 40 | #define MAX_ALIGN_PAGES0 (MAXPAGES0 / UNIT_PAGES) |
41 | #define MAX_ALIGN_PAGES1 (MAXPAGES1 / UNIT_PAGES) | ||
41 | /* get aligned page from offset address */ | 42 | /* get aligned page from offset address */ |
42 | #define get_aligned_page(offset) ((offset) >> PAGE_SHIFT) | 43 | #define get_aligned_page(offset) ((offset) >> PAGE_SHIFT) |
43 | /* get offset address from aligned page */ | 44 | /* get offset address from aligned page */ |
@@ -124,7 +125,7 @@ static int search_empty_map_area(struct snd_emu10k1 *emu, int npages, struct lis | |||
124 | } | 125 | } |
125 | page = blk->mapped_page + blk->pages; | 126 | page = blk->mapped_page + blk->pages; |
126 | } | 127 | } |
127 | size = MAX_ALIGN_PAGES - page; | 128 | size = (emu->address_mode ? MAX_ALIGN_PAGES1 : MAX_ALIGN_PAGES0) - page; |
128 | if (size >= max_size) { | 129 | if (size >= max_size) { |
129 | *nextp = pos; | 130 | *nextp = pos; |
130 | return page; | 131 | return page; |
@@ -181,7 +182,7 @@ static int unmap_memblk(struct snd_emu10k1 *emu, struct snd_emu10k1_memblk *blk) | |||
181 | q = get_emu10k1_memblk(p, mapped_link); | 182 | q = get_emu10k1_memblk(p, mapped_link); |
182 | end_page = q->mapped_page; | 183 | end_page = q->mapped_page; |
183 | } else | 184 | } else |
184 | end_page = MAX_ALIGN_PAGES; | 185 | end_page = (emu->address_mode ? MAX_ALIGN_PAGES1 : MAX_ALIGN_PAGES0); |
185 | 186 | ||
186 | /* remove links */ | 187 | /* remove links */ |
187 | list_del(&blk->mapped_link); | 188 | list_del(&blk->mapped_link); |
@@ -307,7 +308,7 @@ snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *subst | |||
307 | if (snd_BUG_ON(!emu)) | 308 | if (snd_BUG_ON(!emu)) |
308 | return NULL; | 309 | return NULL; |
309 | if (snd_BUG_ON(runtime->dma_bytes <= 0 || | 310 | if (snd_BUG_ON(runtime->dma_bytes <= 0 || |
310 | runtime->dma_bytes >= MAXPAGES * EMUPAGESIZE)) | 311 | runtime->dma_bytes >= (emu->address_mode ? MAXPAGES1 : MAXPAGES0) * EMUPAGESIZE)) |
311 | return NULL; | 312 | return NULL; |
312 | hdr = emu->memhdr; | 313 | hdr = emu->memhdr; |
313 | if (snd_BUG_ON(!hdr)) | 314 | if (snd_BUG_ON(!hdr)) |
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c index e1858d9d23d8..8963d7688fb0 100644 --- a/sound/pci/es1938.c +++ b/sound/pci/es1938.c | |||
@@ -1580,8 +1580,8 @@ static int snd_es1938_create(struct snd_card *card, | |||
1580 | if ((err = pci_enable_device(pci)) < 0) | 1580 | if ((err = pci_enable_device(pci)) < 0) |
1581 | return err; | 1581 | return err; |
1582 | /* check, if we can restrict PCI DMA transfers to 24 bits */ | 1582 | /* check, if we can restrict PCI DMA transfers to 24 bits */ |
1583 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 || | 1583 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(24)) < 0 || |
1584 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) { | 1584 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(24)) < 0) { |
1585 | dev_err(card->dev, | 1585 | dev_err(card->dev, |
1586 | "architecture does not support 24bit PCI busmaster DMA\n"); | 1586 | "architecture does not support 24bit PCI busmaster DMA\n"); |
1587 | pci_disable_device(pci); | 1587 | pci_disable_device(pci); |
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c index 059f3846d7b8..e0d9363dc7fd 100644 --- a/sound/pci/es1968.c +++ b/sound/pci/es1968.c | |||
@@ -2689,8 +2689,8 @@ static int snd_es1968_create(struct snd_card *card, | |||
2689 | if ((err = pci_enable_device(pci)) < 0) | 2689 | if ((err = pci_enable_device(pci)) < 0) |
2690 | return err; | 2690 | return err; |
2691 | /* check, if we can restrict PCI DMA transfers to 28 bits */ | 2691 | /* check, if we can restrict PCI DMA transfers to 28 bits */ |
2692 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 || | 2692 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(28)) < 0 || |
2693 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) { | 2693 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(28)) < 0) { |
2694 | dev_err(card->dev, | 2694 | dev_err(card->dev, |
2695 | "architecture does not support 28bit PCI busmaster DMA\n"); | 2695 | "architecture does not support 28bit PCI busmaster DMA\n"); |
2696 | pci_disable_device(pci); | 2696 | pci_disable_device(pci); |
diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig index a5ed1c181784..98ced971cb43 100644 --- a/sound/pci/hda/Kconfig +++ b/sound/pci/hda/Kconfig | |||
@@ -4,7 +4,7 @@ config SND_HDA | |||
4 | tristate | 4 | tristate |
5 | select SND_PCM | 5 | select SND_PCM |
6 | select SND_VMASTER | 6 | select SND_VMASTER |
7 | select SND_KCTL_JACK | 7 | select SND_JACK if INPUT=y || INPUT=SND |
8 | select SND_HDA_CORE | 8 | select SND_HDA_CORE |
9 | 9 | ||
10 | config SND_HDA_INTEL | 10 | config SND_HDA_INTEL |
@@ -38,9 +38,6 @@ config SND_HDA_TEGRA | |||
38 | 38 | ||
39 | if SND_HDA | 39 | if SND_HDA |
40 | 40 | ||
41 | config SND_HDA_DSP_LOADER | ||
42 | bool | ||
43 | |||
44 | config SND_HDA_PREALLOC_SIZE | 41 | config SND_HDA_PREALLOC_SIZE |
45 | int "Pre-allocated buffer size for HD-audio driver" | 42 | int "Pre-allocated buffer size for HD-audio driver" |
46 | range 0 32768 | 43 | range 0 32768 |
@@ -87,14 +84,6 @@ config SND_HDA_INPUT_BEEP_MODE | |||
87 | Set 1 to always enable the digital beep interface for HD-audio by | 84 | Set 1 to always enable the digital beep interface for HD-audio by |
88 | default. | 85 | default. |
89 | 86 | ||
90 | config SND_HDA_INPUT_JACK | ||
91 | bool "Support jack plugging notification via input layer" | ||
92 | depends on INPUT=y || INPUT=SND | ||
93 | select SND_JACK | ||
94 | help | ||
95 | Say Y here to enable the jack plugging notification via | ||
96 | input layer. | ||
97 | |||
98 | config SND_HDA_PATCH_LOADER | 87 | config SND_HDA_PATCH_LOADER |
99 | bool "Support initialization patch loading for HD-audio" | 88 | bool "Support initialization patch loading for HD-audio" |
100 | select FW_LOADER | 89 | select FW_LOADER |
@@ -156,11 +145,6 @@ config SND_HDA_CODEC_HDMI | |||
156 | comment "Set to Y if you want auto-loading the codec driver" | 145 | comment "Set to Y if you want auto-loading the codec driver" |
157 | depends on SND_HDA=y && SND_HDA_CODEC_HDMI=m | 146 | depends on SND_HDA=y && SND_HDA_CODEC_HDMI=m |
158 | 147 | ||
159 | config SND_HDA_I915 | ||
160 | bool | ||
161 | default y | ||
162 | depends on DRM_I915 | ||
163 | |||
164 | config SND_HDA_CODEC_CIRRUS | 148 | config SND_HDA_CODEC_CIRRUS |
165 | tristate "Build Cirrus Logic codec support" | 149 | tristate "Build Cirrus Logic codec support" |
166 | select SND_HDA_GENERIC | 150 | select SND_HDA_GENERIC |
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile index af78fb33a4fd..90e69b243b41 100644 --- a/sound/pci/hda/Makefile +++ b/sound/pci/hda/Makefile | |||
@@ -1,16 +1,15 @@ | |||
1 | snd-hda-intel-objs := hda_intel.o | 1 | snd-hda-intel-objs := hda_intel.o |
2 | snd-hda-controller-objs := hda_controller.o | ||
3 | snd-hda-tegra-objs := hda_tegra.o | 2 | snd-hda-tegra-objs := hda_tegra.o |
4 | # for haswell power well | ||
5 | snd-hda-intel-$(CONFIG_SND_HDA_I915) += hda_i915.o | ||
6 | 3 | ||
7 | snd-hda-codec-y := hda_bind.o hda_codec.o hda_jack.o hda_auto_parser.o hda_sysfs.o | 4 | snd-hda-codec-y := hda_bind.o hda_codec.o hda_jack.o hda_auto_parser.o hda_sysfs.o |
5 | snd-hda-codec-y += hda_controller.o | ||
8 | snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o | 6 | snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o |
9 | snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o | 7 | snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o |
10 | snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o | 8 | snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o |
11 | 9 | ||
12 | # for trace-points | 10 | # for trace-points |
13 | CFLAGS_hda_controller.o := -I$(src) | 11 | CFLAGS_hda_controller.o := -I$(src) |
12 | CFLAGS_hda_intel.o := -I$(src) | ||
14 | 13 | ||
15 | snd-hda-codec-generic-objs := hda_generic.o | 14 | snd-hda-codec-generic-objs := hda_generic.o |
16 | snd-hda-codec-realtek-objs := patch_realtek.o | 15 | snd-hda-codec-realtek-objs := patch_realtek.o |
@@ -27,7 +26,6 @@ snd-hda-codec-hdmi-objs := patch_hdmi.o hda_eld.o | |||
27 | 26 | ||
28 | # common driver | 27 | # common driver |
29 | obj-$(CONFIG_SND_HDA) := snd-hda-codec.o | 28 | obj-$(CONFIG_SND_HDA) := snd-hda-codec.o |
30 | obj-$(CONFIG_SND_HDA) += snd-hda-controller.o | ||
31 | 29 | ||
32 | # codec drivers | 30 | # codec drivers |
33 | obj-$(CONFIG_SND_HDA_GENERIC) += snd-hda-codec-generic.o | 31 | obj-$(CONFIG_SND_HDA_GENERIC) += snd-hda-codec-generic.o |
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 873ed1bce12b..54380ed03697 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c | |||
@@ -146,11 +146,11 @@ static int codec_exec_verb(struct hdac_device *dev, unsigned int cmd, | |||
146 | bus->no_response_fallback = 0; | 146 | bus->no_response_fallback = 0; |
147 | mutex_unlock(&bus->core.cmd_mutex); | 147 | mutex_unlock(&bus->core.cmd_mutex); |
148 | snd_hda_power_down_pm(codec); | 148 | snd_hda_power_down_pm(codec); |
149 | if (!codec_in_pm(codec) && res && err < 0 && bus->rirb_error) { | 149 | if (!codec_in_pm(codec) && res && err == -EAGAIN) { |
150 | if (bus->response_reset) { | 150 | if (bus->response_reset) { |
151 | codec_dbg(codec, | 151 | codec_dbg(codec, |
152 | "resetting BUS due to fatal communication error\n"); | 152 | "resetting BUS due to fatal communication error\n"); |
153 | bus->ops.bus_reset(bus); | 153 | snd_hda_bus_reset(bus); |
154 | } | 154 | } |
155 | goto again; | 155 | goto again; |
156 | } | 156 | } |
@@ -436,9 +436,8 @@ static unsigned int get_num_devices(struct hda_codec *codec, hda_nid_t nid) | |||
436 | get_wcaps_type(wcaps) != AC_WID_PIN) | 436 | get_wcaps_type(wcaps) != AC_WID_PIN) |
437 | return 0; | 437 | return 0; |
438 | 438 | ||
439 | parm = snd_hda_param_read(codec, nid, AC_PAR_DEVLIST_LEN); | 439 | if (_snd_hdac_read_parm(&codec->core, nid, AC_PAR_DEVLIST_LEN, &parm)) |
440 | if (parm == -1 && codec->bus->rirb_error) | 440 | return 0; /* error */ |
441 | parm = 0; | ||
442 | return parm & AC_DEV_LIST_LEN_MASK; | 441 | return parm & AC_DEV_LIST_LEN_MASK; |
443 | } | 442 | } |
444 | 443 | ||
@@ -467,10 +466,9 @@ int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, | |||
467 | 466 | ||
468 | devices = 0; | 467 | devices = 0; |
469 | while (devices < dev_len) { | 468 | while (devices < dev_len) { |
470 | parm = snd_hda_codec_read(codec, nid, 0, | 469 | if (snd_hdac_read(&codec->core, nid, |
471 | AC_VERB_GET_DEVICE_LIST, devices); | 470 | AC_VERB_GET_DEVICE_LIST, devices, &parm)) |
472 | if (parm == -1 && codec->bus->rirb_error) | 471 | break; /* error */ |
473 | break; | ||
474 | 472 | ||
475 | for (i = 0; i < 8; i++) { | 473 | for (i = 0; i < 8; i++) { |
476 | dev_list[devices] = (u8)parm; | 474 | dev_list[devices] = (u8)parm; |
@@ -484,96 +482,6 @@ int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, | |||
484 | } | 482 | } |
485 | 483 | ||
486 | /* | 484 | /* |
487 | * destructor | ||
488 | */ | ||
489 | static void snd_hda_bus_free(struct hda_bus *bus) | ||
490 | { | ||
491 | if (!bus) | ||
492 | return; | ||
493 | if (bus->ops.private_free) | ||
494 | bus->ops.private_free(bus); | ||
495 | snd_hdac_bus_exit(&bus->core); | ||
496 | kfree(bus); | ||
497 | } | ||
498 | |||
499 | static int snd_hda_bus_dev_free(struct snd_device *device) | ||
500 | { | ||
501 | snd_hda_bus_free(device->device_data); | ||
502 | return 0; | ||
503 | } | ||
504 | |||
505 | static int snd_hda_bus_dev_disconnect(struct snd_device *device) | ||
506 | { | ||
507 | struct hda_bus *bus = device->device_data; | ||
508 | bus->shutdown = 1; | ||
509 | return 0; | ||
510 | } | ||
511 | |||
512 | /* hdac_bus_ops translations */ | ||
513 | static int _hda_bus_command(struct hdac_bus *_bus, unsigned int cmd) | ||
514 | { | ||
515 | struct hda_bus *bus = container_of(_bus, struct hda_bus, core); | ||
516 | return bus->ops.command(bus, cmd); | ||
517 | } | ||
518 | |||
519 | static int _hda_bus_get_response(struct hdac_bus *_bus, unsigned int addr, | ||
520 | unsigned int *res) | ||
521 | { | ||
522 | struct hda_bus *bus = container_of(_bus, struct hda_bus, core); | ||
523 | *res = bus->ops.get_response(bus, addr); | ||
524 | return bus->rirb_error ? -EIO : 0; | ||
525 | } | ||
526 | |||
527 | static const struct hdac_bus_ops bus_ops = { | ||
528 | .command = _hda_bus_command, | ||
529 | .get_response = _hda_bus_get_response, | ||
530 | }; | ||
531 | |||
532 | /** | ||
533 | * snd_hda_bus_new - create a HDA bus | ||
534 | * @card: the card entry | ||
535 | * @busp: the pointer to store the created bus instance | ||
536 | * | ||
537 | * Returns 0 if successful, or a negative error code. | ||
538 | */ | ||
539 | int snd_hda_bus_new(struct snd_card *card, | ||
540 | struct hda_bus **busp) | ||
541 | { | ||
542 | struct hda_bus *bus; | ||
543 | int err; | ||
544 | static struct snd_device_ops dev_ops = { | ||
545 | .dev_disconnect = snd_hda_bus_dev_disconnect, | ||
546 | .dev_free = snd_hda_bus_dev_free, | ||
547 | }; | ||
548 | |||
549 | if (busp) | ||
550 | *busp = NULL; | ||
551 | |||
552 | bus = kzalloc(sizeof(*bus), GFP_KERNEL); | ||
553 | if (!bus) | ||
554 | return -ENOMEM; | ||
555 | |||
556 | err = snd_hdac_bus_init(&bus->core, card->dev, &bus_ops); | ||
557 | if (err < 0) { | ||
558 | kfree(bus); | ||
559 | return err; | ||
560 | } | ||
561 | |||
562 | bus->card = card; | ||
563 | mutex_init(&bus->prepare_mutex); | ||
564 | |||
565 | err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops); | ||
566 | if (err < 0) { | ||
567 | snd_hda_bus_free(bus); | ||
568 | return err; | ||
569 | } | ||
570 | if (busp) | ||
571 | *busp = bus; | ||
572 | return 0; | ||
573 | } | ||
574 | EXPORT_SYMBOL_GPL(snd_hda_bus_new); | ||
575 | |||
576 | /* | ||
577 | * read widget caps for each widget and store in cache | 485 | * read widget caps for each widget and store in cache |
578 | */ | 486 | */ |
579 | static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node) | 487 | static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node) |
@@ -873,14 +781,15 @@ struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec, | |||
873 | struct hda_pcm *pcm; | 781 | struct hda_pcm *pcm; |
874 | va_list args; | 782 | va_list args; |
875 | 783 | ||
876 | va_start(args, fmt); | ||
877 | pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); | 784 | pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); |
878 | if (!pcm) | 785 | if (!pcm) |
879 | return NULL; | 786 | return NULL; |
880 | 787 | ||
881 | pcm->codec = codec; | 788 | pcm->codec = codec; |
882 | kref_init(&pcm->kref); | 789 | kref_init(&pcm->kref); |
790 | va_start(args, fmt); | ||
883 | pcm->name = kvasprintf(GFP_KERNEL, fmt, args); | 791 | pcm->name = kvasprintf(GFP_KERNEL, fmt, args); |
792 | va_end(args); | ||
884 | if (!pcm->name) { | 793 | if (!pcm->name) { |
885 | kfree(pcm); | 794 | kfree(pcm); |
886 | return NULL; | 795 | return NULL; |
@@ -949,6 +858,7 @@ void snd_hda_codec_register(struct hda_codec *codec) | |||
949 | return; | 858 | return; |
950 | if (device_is_registered(hda_codec_dev(codec))) { | 859 | if (device_is_registered(hda_codec_dev(codec))) { |
951 | snd_hda_register_beep_device(codec); | 860 | snd_hda_register_beep_device(codec); |
861 | snd_hdac_link_power(&codec->core, true); | ||
952 | pm_runtime_enable(hda_codec_dev(codec)); | 862 | pm_runtime_enable(hda_codec_dev(codec)); |
953 | /* it was powered up in snd_hda_codec_new(), now all done */ | 863 | /* it was powered up in snd_hda_codec_new(), now all done */ |
954 | snd_hda_power_down(codec); | 864 | snd_hda_power_down(codec); |
@@ -975,6 +885,7 @@ static int snd_hda_codec_dev_free(struct snd_device *device) | |||
975 | struct hda_codec *codec = device->device_data; | 885 | struct hda_codec *codec = device->device_data; |
976 | 886 | ||
977 | codec->in_freeing = 1; | 887 | codec->in_freeing = 1; |
888 | snd_hdac_link_power(&codec->core, false); | ||
978 | snd_hdac_device_unregister(&codec->core); | 889 | snd_hdac_device_unregister(&codec->core); |
979 | put_device(hda_codec_dev(codec)); | 890 | put_device(hda_codec_dev(codec)); |
980 | return 0; | 891 | return 0; |
@@ -2082,6 +1993,16 @@ static struct snd_kcontrol_new vmaster_mute_mode = { | |||
2082 | .put = vmaster_mute_mode_put, | 1993 | .put = vmaster_mute_mode_put, |
2083 | }; | 1994 | }; |
2084 | 1995 | ||
1996 | /* meta hook to call each driver's vmaster hook */ | ||
1997 | static void vmaster_hook(void *private_data, int enabled) | ||
1998 | { | ||
1999 | struct hda_vmaster_mute_hook *hook = private_data; | ||
2000 | |||
2001 | if (hook->mute_mode != HDA_VMUTE_FOLLOW_MASTER) | ||
2002 | enabled = hook->mute_mode; | ||
2003 | hook->hook(hook->codec, enabled); | ||
2004 | } | ||
2005 | |||
2085 | /** | 2006 | /** |
2086 | * snd_hda_add_vmaster_hook - Add a vmaster hook for mute-LED | 2007 | * snd_hda_add_vmaster_hook - Add a vmaster hook for mute-LED |
2087 | * @codec: the HDA codec | 2008 | * @codec: the HDA codec |
@@ -2100,9 +2021,9 @@ int snd_hda_add_vmaster_hook(struct hda_codec *codec, | |||
2100 | 2021 | ||
2101 | if (!hook->hook || !hook->sw_kctl) | 2022 | if (!hook->hook || !hook->sw_kctl) |
2102 | return 0; | 2023 | return 0; |
2103 | snd_ctl_add_vmaster_hook(hook->sw_kctl, hook->hook, codec); | ||
2104 | hook->codec = codec; | 2024 | hook->codec = codec; |
2105 | hook->mute_mode = HDA_VMUTE_FOLLOW_MASTER; | 2025 | hook->mute_mode = HDA_VMUTE_FOLLOW_MASTER; |
2026 | snd_ctl_add_vmaster_hook(hook->sw_kctl, vmaster_hook, hook); | ||
2106 | if (!expose_enum_ctl) | 2027 | if (!expose_enum_ctl) |
2107 | return 0; | 2028 | return 0; |
2108 | kctl = snd_ctl_new1(&vmaster_mute_mode, hook); | 2029 | kctl = snd_ctl_new1(&vmaster_mute_mode, hook); |
@@ -2128,14 +2049,7 @@ void snd_hda_sync_vmaster_hook(struct hda_vmaster_mute_hook *hook) | |||
2128 | */ | 2049 | */ |
2129 | if (hook->codec->bus->shutdown) | 2050 | if (hook->codec->bus->shutdown) |
2130 | return; | 2051 | return; |
2131 | switch (hook->mute_mode) { | 2052 | snd_ctl_sync_vmaster_hook(hook->sw_kctl); |
2132 | case HDA_VMUTE_FOLLOW_MASTER: | ||
2133 | snd_ctl_sync_vmaster_hook(hook->sw_kctl); | ||
2134 | break; | ||
2135 | default: | ||
2136 | hook->hook(hook->codec, hook->mute_mode); | ||
2137 | break; | ||
2138 | } | ||
2139 | } | 2053 | } |
2140 | EXPORT_SYMBOL_GPL(snd_hda_sync_vmaster_hook); | 2054 | EXPORT_SYMBOL_GPL(snd_hda_sync_vmaster_hook); |
2141 | 2055 | ||
@@ -3194,6 +3108,7 @@ static int hda_codec_runtime_suspend(struct device *dev) | |||
3194 | if (codec_has_clkstop(codec) && codec_has_epss(codec) && | 3108 | if (codec_has_clkstop(codec) && codec_has_epss(codec) && |
3195 | (state & AC_PWRST_CLK_STOP_OK)) | 3109 | (state & AC_PWRST_CLK_STOP_OK)) |
3196 | snd_hdac_codec_link_down(&codec->core); | 3110 | snd_hdac_codec_link_down(&codec->core); |
3111 | snd_hdac_link_power(&codec->core, false); | ||
3197 | return 0; | 3112 | return 0; |
3198 | } | 3113 | } |
3199 | 3114 | ||
@@ -3201,6 +3116,7 @@ static int hda_codec_runtime_resume(struct device *dev) | |||
3201 | { | 3116 | { |
3202 | struct hda_codec *codec = dev_to_hda_codec(dev); | 3117 | struct hda_codec *codec = dev_to_hda_codec(dev); |
3203 | 3118 | ||
3119 | snd_hdac_link_power(&codec->core, true); | ||
3204 | snd_hdac_codec_link_up(&codec->core); | 3120 | snd_hdac_codec_link_up(&codec->core); |
3205 | hda_call_codec_resume(codec); | 3121 | hda_call_codec_resume(codec); |
3206 | pm_runtime_mark_last_busy(dev); | 3122 | pm_runtime_mark_last_busy(dev); |
@@ -3284,311 +3200,6 @@ int snd_hda_codec_build_controls(struct hda_codec *codec) | |||
3284 | } | 3200 | } |
3285 | 3201 | ||
3286 | /* | 3202 | /* |
3287 | * stream formats | ||
3288 | */ | ||
3289 | struct hda_rate_tbl { | ||
3290 | unsigned int hz; | ||
3291 | unsigned int alsa_bits; | ||
3292 | unsigned int hda_fmt; | ||
3293 | }; | ||
3294 | |||
3295 | /* rate = base * mult / div */ | ||
3296 | #define HDA_RATE(base, mult, div) \ | ||
3297 | (AC_FMT_BASE_##base##K | (((mult) - 1) << AC_FMT_MULT_SHIFT) | \ | ||
3298 | (((div) - 1) << AC_FMT_DIV_SHIFT)) | ||
3299 | |||
3300 | static struct hda_rate_tbl rate_bits[] = { | ||
3301 | /* rate in Hz, ALSA rate bitmask, HDA format value */ | ||
3302 | |||
3303 | /* autodetected value used in snd_hda_query_supported_pcm */ | ||
3304 | { 8000, SNDRV_PCM_RATE_8000, HDA_RATE(48, 1, 6) }, | ||
3305 | { 11025, SNDRV_PCM_RATE_11025, HDA_RATE(44, 1, 4) }, | ||
3306 | { 16000, SNDRV_PCM_RATE_16000, HDA_RATE(48, 1, 3) }, | ||
3307 | { 22050, SNDRV_PCM_RATE_22050, HDA_RATE(44, 1, 2) }, | ||
3308 | { 32000, SNDRV_PCM_RATE_32000, HDA_RATE(48, 2, 3) }, | ||
3309 | { 44100, SNDRV_PCM_RATE_44100, HDA_RATE(44, 1, 1) }, | ||
3310 | { 48000, SNDRV_PCM_RATE_48000, HDA_RATE(48, 1, 1) }, | ||
3311 | { 88200, SNDRV_PCM_RATE_88200, HDA_RATE(44, 2, 1) }, | ||
3312 | { 96000, SNDRV_PCM_RATE_96000, HDA_RATE(48, 2, 1) }, | ||
3313 | { 176400, SNDRV_PCM_RATE_176400, HDA_RATE(44, 4, 1) }, | ||
3314 | { 192000, SNDRV_PCM_RATE_192000, HDA_RATE(48, 4, 1) }, | ||
3315 | #define AC_PAR_PCM_RATE_BITS 11 | ||
3316 | /* up to bits 10, 384kHZ isn't supported properly */ | ||
3317 | |||
3318 | /* not autodetected value */ | ||
3319 | { 9600, SNDRV_PCM_RATE_KNOT, HDA_RATE(48, 1, 5) }, | ||
3320 | |||
3321 | { 0 } /* terminator */ | ||
3322 | }; | ||
3323 | |||
3324 | /** | ||
3325 | * snd_hda_calc_stream_format - calculate format bitset | ||
3326 | * @codec: HD-audio codec | ||
3327 | * @rate: the sample rate | ||
3328 | * @channels: the number of channels | ||
3329 | * @format: the PCM format (SNDRV_PCM_FORMAT_XXX) | ||
3330 | * @maxbps: the max. bps | ||
3331 | * @spdif_ctls: HD-audio SPDIF status bits (0 if irrelevant) | ||
3332 | * | ||
3333 | * Calculate the format bitset from the given rate, channels and th PCM format. | ||
3334 | * | ||
3335 | * Return zero if invalid. | ||
3336 | */ | ||
3337 | unsigned int snd_hda_calc_stream_format(struct hda_codec *codec, | ||
3338 | unsigned int rate, | ||
3339 | unsigned int channels, | ||
3340 | unsigned int format, | ||
3341 | unsigned int maxbps, | ||
3342 | unsigned short spdif_ctls) | ||
3343 | { | ||
3344 | int i; | ||
3345 | unsigned int val = 0; | ||
3346 | |||
3347 | for (i = 0; rate_bits[i].hz; i++) | ||
3348 | if (rate_bits[i].hz == rate) { | ||
3349 | val = rate_bits[i].hda_fmt; | ||
3350 | break; | ||
3351 | } | ||
3352 | if (!rate_bits[i].hz) { | ||
3353 | codec_dbg(codec, "invalid rate %d\n", rate); | ||
3354 | return 0; | ||
3355 | } | ||
3356 | |||
3357 | if (channels == 0 || channels > 8) { | ||
3358 | codec_dbg(codec, "invalid channels %d\n", channels); | ||
3359 | return 0; | ||
3360 | } | ||
3361 | val |= channels - 1; | ||
3362 | |||
3363 | switch (snd_pcm_format_width(format)) { | ||
3364 | case 8: | ||
3365 | val |= AC_FMT_BITS_8; | ||
3366 | break; | ||
3367 | case 16: | ||
3368 | val |= AC_FMT_BITS_16; | ||
3369 | break; | ||
3370 | case 20: | ||
3371 | case 24: | ||
3372 | case 32: | ||
3373 | if (maxbps >= 32 || format == SNDRV_PCM_FORMAT_FLOAT_LE) | ||
3374 | val |= AC_FMT_BITS_32; | ||
3375 | else if (maxbps >= 24) | ||
3376 | val |= AC_FMT_BITS_24; | ||
3377 | else | ||
3378 | val |= AC_FMT_BITS_20; | ||
3379 | break; | ||
3380 | default: | ||
3381 | codec_dbg(codec, "invalid format width %d\n", | ||
3382 | snd_pcm_format_width(format)); | ||
3383 | return 0; | ||
3384 | } | ||
3385 | |||
3386 | if (spdif_ctls & AC_DIG1_NONAUDIO) | ||
3387 | val |= AC_FMT_TYPE_NON_PCM; | ||
3388 | |||
3389 | return val; | ||
3390 | } | ||
3391 | EXPORT_SYMBOL_GPL(snd_hda_calc_stream_format); | ||
3392 | |||
3393 | static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid) | ||
3394 | { | ||
3395 | unsigned int val = 0; | ||
3396 | if (nid != codec->core.afg && | ||
3397 | (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) | ||
3398 | val = snd_hda_param_read(codec, nid, AC_PAR_PCM); | ||
3399 | if (!val || val == -1) | ||
3400 | val = snd_hda_param_read(codec, codec->core.afg, AC_PAR_PCM); | ||
3401 | if (!val || val == -1) | ||
3402 | return 0; | ||
3403 | return val; | ||
3404 | } | ||
3405 | |||
3406 | static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid) | ||
3407 | { | ||
3408 | unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM); | ||
3409 | if (!streams || streams == -1) | ||
3410 | streams = snd_hda_param_read(codec, codec->core.afg, AC_PAR_STREAM); | ||
3411 | if (!streams || streams == -1) | ||
3412 | return 0; | ||
3413 | return streams; | ||
3414 | } | ||
3415 | |||
3416 | /** | ||
3417 | * snd_hda_query_supported_pcm - query the supported PCM rates and formats | ||
3418 | * @codec: the HDA codec | ||
3419 | * @nid: NID to query | ||
3420 | * @ratesp: the pointer to store the detected rate bitflags | ||
3421 | * @formatsp: the pointer to store the detected formats | ||
3422 | * @bpsp: the pointer to store the detected format widths | ||
3423 | * | ||
3424 | * Queries the supported PCM rates and formats. The NULL @ratesp, @formatsp | ||
3425 | * or @bsps argument is ignored. | ||
3426 | * | ||
3427 | * Returns 0 if successful, otherwise a negative error code. | ||
3428 | */ | ||
3429 | int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid, | ||
3430 | u32 *ratesp, u64 *formatsp, unsigned int *bpsp) | ||
3431 | { | ||
3432 | unsigned int i, val, wcaps; | ||
3433 | |||
3434 | wcaps = get_wcaps(codec, nid); | ||
3435 | val = query_pcm_param(codec, nid); | ||
3436 | |||
3437 | if (ratesp) { | ||
3438 | u32 rates = 0; | ||
3439 | for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++) { | ||
3440 | if (val & (1 << i)) | ||
3441 | rates |= rate_bits[i].alsa_bits; | ||
3442 | } | ||
3443 | if (rates == 0) { | ||
3444 | codec_err(codec, | ||
3445 | "rates == 0 (nid=0x%x, val=0x%x, ovrd=%i)\n", | ||
3446 | nid, val, | ||
3447 | (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0); | ||
3448 | return -EIO; | ||
3449 | } | ||
3450 | *ratesp = rates; | ||
3451 | } | ||
3452 | |||
3453 | if (formatsp || bpsp) { | ||
3454 | u64 formats = 0; | ||
3455 | unsigned int streams, bps; | ||
3456 | |||
3457 | streams = query_stream_param(codec, nid); | ||
3458 | if (!streams) | ||
3459 | return -EIO; | ||
3460 | |||
3461 | bps = 0; | ||
3462 | if (streams & AC_SUPFMT_PCM) { | ||
3463 | if (val & AC_SUPPCM_BITS_8) { | ||
3464 | formats |= SNDRV_PCM_FMTBIT_U8; | ||
3465 | bps = 8; | ||
3466 | } | ||
3467 | if (val & AC_SUPPCM_BITS_16) { | ||
3468 | formats |= SNDRV_PCM_FMTBIT_S16_LE; | ||
3469 | bps = 16; | ||
3470 | } | ||
3471 | if (wcaps & AC_WCAP_DIGITAL) { | ||
3472 | if (val & AC_SUPPCM_BITS_32) | ||
3473 | formats |= SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE; | ||
3474 | if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24)) | ||
3475 | formats |= SNDRV_PCM_FMTBIT_S32_LE; | ||
3476 | if (val & AC_SUPPCM_BITS_24) | ||
3477 | bps = 24; | ||
3478 | else if (val & AC_SUPPCM_BITS_20) | ||
3479 | bps = 20; | ||
3480 | } else if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24| | ||
3481 | AC_SUPPCM_BITS_32)) { | ||
3482 | formats |= SNDRV_PCM_FMTBIT_S32_LE; | ||
3483 | if (val & AC_SUPPCM_BITS_32) | ||
3484 | bps = 32; | ||
3485 | else if (val & AC_SUPPCM_BITS_24) | ||
3486 | bps = 24; | ||
3487 | else if (val & AC_SUPPCM_BITS_20) | ||
3488 | bps = 20; | ||
3489 | } | ||
3490 | } | ||
3491 | #if 0 /* FIXME: CS4206 doesn't work, which is the only codec supporting float */ | ||
3492 | if (streams & AC_SUPFMT_FLOAT32) { | ||
3493 | formats |= SNDRV_PCM_FMTBIT_FLOAT_LE; | ||
3494 | if (!bps) | ||
3495 | bps = 32; | ||
3496 | } | ||
3497 | #endif | ||
3498 | if (streams == AC_SUPFMT_AC3) { | ||
3499 | /* should be exclusive */ | ||
3500 | /* temporary hack: we have still no proper support | ||
3501 | * for the direct AC3 stream... | ||
3502 | */ | ||
3503 | formats |= SNDRV_PCM_FMTBIT_U8; | ||
3504 | bps = 8; | ||
3505 | } | ||
3506 | if (formats == 0) { | ||
3507 | codec_err(codec, | ||
3508 | "formats == 0 (nid=0x%x, val=0x%x, ovrd=%i, streams=0x%x)\n", | ||
3509 | nid, val, | ||
3510 | (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0, | ||
3511 | streams); | ||
3512 | return -EIO; | ||
3513 | } | ||
3514 | if (formatsp) | ||
3515 | *formatsp = formats; | ||
3516 | if (bpsp) | ||
3517 | *bpsp = bps; | ||
3518 | } | ||
3519 | |||
3520 | return 0; | ||
3521 | } | ||
3522 | EXPORT_SYMBOL_GPL(snd_hda_query_supported_pcm); | ||
3523 | |||
3524 | /** | ||
3525 | * snd_hda_is_supported_format - Check the validity of the format | ||
3526 | * @codec: HD-audio codec | ||
3527 | * @nid: NID to check | ||
3528 | * @format: the HD-audio format value to check | ||
3529 | * | ||
3530 | * Check whether the given node supports the format value. | ||
3531 | * | ||
3532 | * Returns 1 if supported, 0 if not. | ||
3533 | */ | ||
3534 | int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid, | ||
3535 | unsigned int format) | ||
3536 | { | ||
3537 | int i; | ||
3538 | unsigned int val = 0, rate, stream; | ||
3539 | |||
3540 | val = query_pcm_param(codec, nid); | ||
3541 | if (!val) | ||
3542 | return 0; | ||
3543 | |||
3544 | rate = format & 0xff00; | ||
3545 | for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++) | ||
3546 | if (rate_bits[i].hda_fmt == rate) { | ||
3547 | if (val & (1 << i)) | ||
3548 | break; | ||
3549 | return 0; | ||
3550 | } | ||
3551 | if (i >= AC_PAR_PCM_RATE_BITS) | ||
3552 | return 0; | ||
3553 | |||
3554 | stream = query_stream_param(codec, nid); | ||
3555 | if (!stream) | ||
3556 | return 0; | ||
3557 | |||
3558 | if (stream & AC_SUPFMT_PCM) { | ||
3559 | switch (format & 0xf0) { | ||
3560 | case 0x00: | ||
3561 | if (!(val & AC_SUPPCM_BITS_8)) | ||
3562 | return 0; | ||
3563 | break; | ||
3564 | case 0x10: | ||
3565 | if (!(val & AC_SUPPCM_BITS_16)) | ||
3566 | return 0; | ||
3567 | break; | ||
3568 | case 0x20: | ||
3569 | if (!(val & AC_SUPPCM_BITS_20)) | ||
3570 | return 0; | ||
3571 | break; | ||
3572 | case 0x30: | ||
3573 | if (!(val & AC_SUPPCM_BITS_24)) | ||
3574 | return 0; | ||
3575 | break; | ||
3576 | case 0x40: | ||
3577 | if (!(val & AC_SUPPCM_BITS_32)) | ||
3578 | return 0; | ||
3579 | break; | ||
3580 | default: | ||
3581 | return 0; | ||
3582 | } | ||
3583 | } else { | ||
3584 | /* FIXME: check for float32 and AC3? */ | ||
3585 | } | ||
3586 | |||
3587 | return 1; | ||
3588 | } | ||
3589 | EXPORT_SYMBOL_GPL(snd_hda_is_supported_format); | ||
3590 | |||
3591 | /* | ||
3592 | * PCM stuff | 3203 | * PCM stuff |
3593 | */ | 3204 | */ |
3594 | static int hda_pcm_default_open_close(struct hda_pcm_stream *hinfo, | 3205 | static int hda_pcm_default_open_close(struct hda_pcm_stream *hinfo, |
@@ -3800,9 +3411,6 @@ int snd_hda_codec_build_pcms(struct hda_codec *codec) | |||
3800 | struct hda_pcm *cpcm; | 3411 | struct hda_pcm *cpcm; |
3801 | int dev, err; | 3412 | int dev, err; |
3802 | 3413 | ||
3803 | if (snd_BUG_ON(!bus->ops.attach_pcm)) | ||
3804 | return -EINVAL; | ||
3805 | |||
3806 | err = snd_hda_codec_parse_pcms(codec); | 3414 | err = snd_hda_codec_parse_pcms(codec); |
3807 | if (err < 0) { | 3415 | if (err < 0) { |
3808 | snd_hda_codec_reset(codec); | 3416 | snd_hda_codec_reset(codec); |
@@ -3820,7 +3428,7 @@ int snd_hda_codec_build_pcms(struct hda_codec *codec) | |||
3820 | if (dev < 0) | 3428 | if (dev < 0) |
3821 | continue; /* no fatal error */ | 3429 | continue; /* no fatal error */ |
3822 | cpcm->device = dev; | 3430 | cpcm->device = dev; |
3823 | err = bus->ops.attach_pcm(bus, codec, cpcm); | 3431 | err = snd_hda_attach_pcm_stream(bus, codec, cpcm); |
3824 | if (err < 0) { | 3432 | if (err < 0) { |
3825 | codec_err(codec, | 3433 | codec_err(codec, |
3826 | "cannot attach PCM stream %d for codec #%d\n", | 3434 | "cannot attach PCM stream %d for codec #%d\n", |
@@ -4490,10 +4098,10 @@ int snd_hda_add_imux_item(struct hda_codec *codec, | |||
4490 | EXPORT_SYMBOL_GPL(snd_hda_add_imux_item); | 4098 | EXPORT_SYMBOL_GPL(snd_hda_add_imux_item); |
4491 | 4099 | ||
4492 | /** | 4100 | /** |
4493 | * snd_hda_bus_reset - Reset the bus | 4101 | * snd_hda_bus_reset_codecs - Reset the bus |
4494 | * @bus: HD-audio bus | 4102 | * @bus: HD-audio bus |
4495 | */ | 4103 | */ |
4496 | void snd_hda_bus_reset(struct hda_bus *bus) | 4104 | void snd_hda_bus_reset_codecs(struct hda_bus *bus) |
4497 | { | 4105 | { |
4498 | struct hda_codec *codec; | 4106 | struct hda_codec *codec; |
4499 | 4107 | ||
@@ -4508,7 +4116,6 @@ void snd_hda_bus_reset(struct hda_bus *bus) | |||
4508 | #endif | 4116 | #endif |
4509 | } | 4117 | } |
4510 | } | 4118 | } |
4511 | EXPORT_SYMBOL_GPL(snd_hda_bus_reset); | ||
4512 | 4119 | ||
4513 | /** | 4120 | /** |
4514 | * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer | 4121 | * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer |
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 9075ac28dc4b..ed7e9cfd699a 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h | |||
@@ -40,32 +40,6 @@ struct hda_codec; | |||
40 | struct hda_pcm; | 40 | struct hda_pcm; |
41 | struct hda_pcm_stream; | 41 | struct hda_pcm_stream; |
42 | 42 | ||
43 | /* bus operators */ | ||
44 | struct hda_bus_ops { | ||
45 | /* send a single command */ | ||
46 | int (*command)(struct hda_bus *bus, unsigned int cmd); | ||
47 | /* get a response from the last command */ | ||
48 | unsigned int (*get_response)(struct hda_bus *bus, unsigned int addr); | ||
49 | /* free the private data */ | ||
50 | void (*private_free)(struct hda_bus *); | ||
51 | /* attach a PCM stream */ | ||
52 | int (*attach_pcm)(struct hda_bus *bus, struct hda_codec *codec, | ||
53 | struct hda_pcm *pcm); | ||
54 | /* reset bus for retry verb */ | ||
55 | void (*bus_reset)(struct hda_bus *bus); | ||
56 | #ifdef CONFIG_SND_HDA_DSP_LOADER | ||
57 | /* prepare DSP transfer */ | ||
58 | int (*load_dsp_prepare)(struct hda_bus *bus, unsigned int format, | ||
59 | unsigned int byte_size, | ||
60 | struct snd_dma_buffer *bufp); | ||
61 | /* start/stop DSP transfer */ | ||
62 | void (*load_dsp_trigger)(struct hda_bus *bus, bool start); | ||
63 | /* clean up DSP transfer */ | ||
64 | void (*load_dsp_cleanup)(struct hda_bus *bus, | ||
65 | struct snd_dma_buffer *dmab); | ||
66 | #endif | ||
67 | }; | ||
68 | |||
69 | /* | 43 | /* |
70 | * codec bus | 44 | * codec bus |
71 | * | 45 | * |
@@ -77,10 +51,8 @@ struct hda_bus { | |||
77 | 51 | ||
78 | struct snd_card *card; | 52 | struct snd_card *card; |
79 | 53 | ||
80 | void *private_data; | ||
81 | struct pci_dev *pci; | 54 | struct pci_dev *pci; |
82 | const char *modelname; | 55 | const char *modelname; |
83 | struct hda_bus_ops ops; | ||
84 | 56 | ||
85 | struct mutex prepare_mutex; | 57 | struct mutex prepare_mutex; |
86 | 58 | ||
@@ -92,7 +64,6 @@ struct hda_bus { | |||
92 | unsigned int allow_bus_reset:1; /* allow bus reset at fatal error */ | 64 | unsigned int allow_bus_reset:1; /* allow bus reset at fatal error */ |
93 | /* status for codec/controller */ | 65 | /* status for codec/controller */ |
94 | unsigned int shutdown :1; /* being unloaded */ | 66 | unsigned int shutdown :1; /* being unloaded */ |
95 | unsigned int rirb_error:1; /* error in codec communication */ | ||
96 | unsigned int response_reset:1; /* controller was reset */ | 67 | unsigned int response_reset:1; /* controller was reset */ |
97 | unsigned int in_reset:1; /* during reset operation */ | 68 | unsigned int in_reset:1; /* during reset operation */ |
98 | unsigned int no_response_fallback:1; /* don't fallback at RIRB error */ | 69 | unsigned int no_response_fallback:1; /* don't fallback at RIRB error */ |
@@ -100,6 +71,9 @@ struct hda_bus { | |||
100 | int primary_dig_out_type; /* primary digital out PCM type */ | 71 | int primary_dig_out_type; /* primary digital out PCM type */ |
101 | }; | 72 | }; |
102 | 73 | ||
74 | /* from hdac_bus to hda_bus */ | ||
75 | #define to_hda_bus(bus) container_of(bus, struct hda_bus, core) | ||
76 | |||
103 | /* | 77 | /* |
104 | * codec preset | 78 | * codec preset |
105 | * | 79 | * |
@@ -300,10 +274,8 @@ struct hda_codec { | |||
300 | unsigned long jackpoll_interval; /* In jiffies. Zero means no poll, rely on unsol events */ | 274 | unsigned long jackpoll_interval; /* In jiffies. Zero means no poll, rely on unsol events */ |
301 | struct delayed_work jackpoll_work; | 275 | struct delayed_work jackpoll_work; |
302 | 276 | ||
303 | #ifdef CONFIG_SND_HDA_INPUT_JACK | ||
304 | /* jack detection */ | 277 | /* jack detection */ |
305 | struct snd_array jacks; | 278 | struct snd_array jacks; |
306 | #endif | ||
307 | 279 | ||
308 | int depop_delay; /* depop delay in ms, -1 for default delay time */ | 280 | int depop_delay; /* depop delay in ms, -1 for default delay time */ |
309 | 281 | ||
@@ -328,7 +300,10 @@ struct hda_codec { | |||
328 | /* | 300 | /* |
329 | * constructors | 301 | * constructors |
330 | */ | 302 | */ |
331 | int snd_hda_bus_new(struct snd_card *card, struct hda_bus **busp); | 303 | int snd_hda_bus_new(struct snd_card *card, |
304 | const struct hdac_bus_ops *ops, | ||
305 | const struct hdac_io_ops *io_ops, | ||
306 | struct hda_bus **busp); | ||
332 | int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, | 307 | int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, |
333 | unsigned int codec_addr, struct hda_codec **codecp); | 308 | unsigned int codec_addr, struct hda_codec **codecp); |
334 | int snd_hda_codec_configure(struct hda_codec *codec); | 309 | int snd_hda_codec_configure(struct hda_codec *codec); |
@@ -367,8 +342,6 @@ int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux, | |||
367 | hda_nid_t nid, int recursive); | 342 | hda_nid_t nid, int recursive); |
368 | int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, | 343 | int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, |
369 | u8 *dev_list, int max_devices); | 344 | u8 *dev_list, int max_devices); |
370 | int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid, | ||
371 | u32 *ratesp, u64 *formatsp, unsigned int *bpsp); | ||
372 | 345 | ||
373 | struct hda_verb { | 346 | struct hda_verb { |
374 | hda_nid_t nid; | 347 | hda_nid_t nid; |
@@ -460,17 +433,17 @@ void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid, | |||
460 | int do_now); | 433 | int do_now); |
461 | #define snd_hda_codec_cleanup_stream(codec, nid) \ | 434 | #define snd_hda_codec_cleanup_stream(codec, nid) \ |
462 | __snd_hda_codec_cleanup_stream(codec, nid, 0) | 435 | __snd_hda_codec_cleanup_stream(codec, nid, 0) |
463 | unsigned int snd_hda_calc_stream_format(struct hda_codec *codec, | 436 | |
464 | unsigned int rate, | 437 | #define snd_hda_query_supported_pcm(codec, nid, ratesp, fmtsp, bpsp) \ |
465 | unsigned int channels, | 438 | snd_hdac_query_supported_pcm(&(codec)->core, nid, ratesp, fmtsp, bpsp) |
466 | unsigned int format, | 439 | #define snd_hda_is_supported_format(codec, nid, fmt) \ |
467 | unsigned int maxbps, | 440 | snd_hdac_is_supported_format(&(codec)->core, nid, fmt) |
468 | unsigned short spdif_ctls); | ||
469 | int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid, | ||
470 | unsigned int format); | ||
471 | 441 | ||
472 | extern const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[]; | 442 | extern const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[]; |
473 | 443 | ||
444 | int snd_hda_attach_pcm_stream(struct hda_bus *_bus, struct hda_codec *codec, | ||
445 | struct hda_pcm *cpcm); | ||
446 | |||
474 | /* | 447 | /* |
475 | * Misc | 448 | * Misc |
476 | */ | 449 | */ |
@@ -481,6 +454,7 @@ void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, | |||
481 | int snd_hda_lock_devices(struct hda_bus *bus); | 454 | int snd_hda_lock_devices(struct hda_bus *bus); |
482 | void snd_hda_unlock_devices(struct hda_bus *bus); | 455 | void snd_hda_unlock_devices(struct hda_bus *bus); |
483 | void snd_hda_bus_reset(struct hda_bus *bus); | 456 | void snd_hda_bus_reset(struct hda_bus *bus); |
457 | void snd_hda_bus_reset_codecs(struct hda_bus *bus); | ||
484 | 458 | ||
485 | /* | 459 | /* |
486 | * power management | 460 | * power management |
@@ -526,24 +500,12 @@ int snd_hda_load_patch(struct hda_bus *bus, size_t size, const void *buf); | |||
526 | #endif | 500 | #endif |
527 | 501 | ||
528 | #ifdef CONFIG_SND_HDA_DSP_LOADER | 502 | #ifdef CONFIG_SND_HDA_DSP_LOADER |
529 | static inline int | 503 | int snd_hda_codec_load_dsp_prepare(struct hda_codec *codec, unsigned int format, |
530 | snd_hda_codec_load_dsp_prepare(struct hda_codec *codec, unsigned int format, | 504 | unsigned int size, |
531 | unsigned int size, | 505 | struct snd_dma_buffer *bufp); |
532 | struct snd_dma_buffer *bufp) | 506 | void snd_hda_codec_load_dsp_trigger(struct hda_codec *codec, bool start); |
533 | { | 507 | void snd_hda_codec_load_dsp_cleanup(struct hda_codec *codec, |
534 | return codec->bus->ops.load_dsp_prepare(codec->bus, format, size, bufp); | 508 | struct snd_dma_buffer *dmab); |
535 | } | ||
536 | static inline void | ||
537 | snd_hda_codec_load_dsp_trigger(struct hda_codec *codec, bool start) | ||
538 | { | ||
539 | return codec->bus->ops.load_dsp_trigger(codec->bus, start); | ||
540 | } | ||
541 | static inline void | ||
542 | snd_hda_codec_load_dsp_cleanup(struct hda_codec *codec, | ||
543 | struct snd_dma_buffer *dmab) | ||
544 | { | ||
545 | return codec->bus->ops.load_dsp_cleanup(codec->bus, dmab); | ||
546 | } | ||
547 | #else | 509 | #else |
548 | static inline int | 510 | static inline int |
549 | snd_hda_codec_load_dsp_prepare(struct hda_codec *codec, unsigned int format, | 511 | snd_hda_codec_load_dsp_prepare(struct hda_codec *codec, unsigned int format, |
diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index 26ce990592a0..944455997fdc 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c | |||
@@ -32,229 +32,29 @@ | |||
32 | #include "hda_controller.h" | 32 | #include "hda_controller.h" |
33 | 33 | ||
34 | #define CREATE_TRACE_POINTS | 34 | #define CREATE_TRACE_POINTS |
35 | #include "hda_intel_trace.h" | 35 | #include "hda_controller_trace.h" |
36 | 36 | ||
37 | /* DSP lock helpers */ | 37 | /* DSP lock helpers */ |
38 | #ifdef CONFIG_SND_HDA_DSP_LOADER | 38 | #define dsp_lock(dev) snd_hdac_dsp_lock(azx_stream(dev)) |
39 | #define dsp_lock_init(dev) mutex_init(&(dev)->dsp_mutex) | 39 | #define dsp_unlock(dev) snd_hdac_dsp_unlock(azx_stream(dev)) |
40 | #define dsp_lock(dev) mutex_lock(&(dev)->dsp_mutex) | 40 | #define dsp_is_locked(dev) snd_hdac_stream_is_locked(azx_stream(dev)) |
41 | #define dsp_unlock(dev) mutex_unlock(&(dev)->dsp_mutex) | ||
42 | #define dsp_is_locked(dev) ((dev)->locked) | ||
43 | #else | ||
44 | #define dsp_lock_init(dev) do {} while (0) | ||
45 | #define dsp_lock(dev) do {} while (0) | ||
46 | #define dsp_unlock(dev) do {} while (0) | ||
47 | #define dsp_is_locked(dev) 0 | ||
48 | #endif | ||
49 | |||
50 | /* | ||
51 | * AZX stream operations. | ||
52 | */ | ||
53 | |||
54 | /* start a stream */ | ||
55 | static void azx_stream_start(struct azx *chip, struct azx_dev *azx_dev) | ||
56 | { | ||
57 | /* | ||
58 | * Before stream start, initialize parameter | ||
59 | */ | ||
60 | azx_dev->insufficient = 1; | ||
61 | |||
62 | /* enable SIE */ | ||
63 | azx_writel(chip, INTCTL, | ||
64 | azx_readl(chip, INTCTL) | (1 << azx_dev->index)); | ||
65 | /* set DMA start and interrupt mask */ | ||
66 | azx_sd_writeb(chip, azx_dev, SD_CTL, | ||
67 | azx_sd_readb(chip, azx_dev, SD_CTL) | | ||
68 | SD_CTL_DMA_START | SD_INT_MASK); | ||
69 | } | ||
70 | |||
71 | /* stop DMA */ | ||
72 | static void azx_stream_clear(struct azx *chip, struct azx_dev *azx_dev) | ||
73 | { | ||
74 | azx_sd_writeb(chip, azx_dev, SD_CTL, | ||
75 | azx_sd_readb(chip, azx_dev, SD_CTL) & | ||
76 | ~(SD_CTL_DMA_START | SD_INT_MASK)); | ||
77 | azx_sd_writeb(chip, azx_dev, SD_STS, SD_INT_MASK); /* to be sure */ | ||
78 | } | ||
79 | |||
80 | /* stop a stream */ | ||
81 | void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev) | ||
82 | { | ||
83 | azx_stream_clear(chip, azx_dev); | ||
84 | /* disable SIE */ | ||
85 | azx_writel(chip, INTCTL, | ||
86 | azx_readl(chip, INTCTL) & ~(1 << azx_dev->index)); | ||
87 | } | ||
88 | EXPORT_SYMBOL_GPL(azx_stream_stop); | ||
89 | |||
90 | /* reset stream */ | ||
91 | static void azx_stream_reset(struct azx *chip, struct azx_dev *azx_dev) | ||
92 | { | ||
93 | unsigned char val; | ||
94 | int timeout; | ||
95 | |||
96 | azx_stream_clear(chip, azx_dev); | ||
97 | |||
98 | azx_sd_writeb(chip, azx_dev, SD_CTL, | ||
99 | azx_sd_readb(chip, azx_dev, SD_CTL) | | ||
100 | SD_CTL_STREAM_RESET); | ||
101 | udelay(3); | ||
102 | timeout = 300; | ||
103 | while (!((val = azx_sd_readb(chip, azx_dev, SD_CTL)) & | ||
104 | SD_CTL_STREAM_RESET) && --timeout) | ||
105 | ; | ||
106 | val &= ~SD_CTL_STREAM_RESET; | ||
107 | azx_sd_writeb(chip, azx_dev, SD_CTL, val); | ||
108 | udelay(3); | ||
109 | |||
110 | timeout = 300; | ||
111 | /* waiting for hardware to report that the stream is out of reset */ | ||
112 | while (((val = azx_sd_readb(chip, azx_dev, SD_CTL)) & | ||
113 | SD_CTL_STREAM_RESET) && --timeout) | ||
114 | ; | ||
115 | |||
116 | /* reset first position - may not be synced with hw at this time */ | ||
117 | *azx_dev->posbuf = 0; | ||
118 | } | ||
119 | |||
120 | /* | ||
121 | * set up the SD for streaming | ||
122 | */ | ||
123 | static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev) | ||
124 | { | ||
125 | unsigned int val; | ||
126 | /* make sure the run bit is zero for SD */ | ||
127 | azx_stream_clear(chip, azx_dev); | ||
128 | /* program the stream_tag */ | ||
129 | val = azx_sd_readl(chip, azx_dev, SD_CTL); | ||
130 | val = (val & ~SD_CTL_STREAM_TAG_MASK) | | ||
131 | (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT); | ||
132 | if (!azx_snoop(chip)) | ||
133 | val |= SD_CTL_TRAFFIC_PRIO; | ||
134 | azx_sd_writel(chip, azx_dev, SD_CTL, val); | ||
135 | |||
136 | /* program the length of samples in cyclic buffer */ | ||
137 | azx_sd_writel(chip, azx_dev, SD_CBL, azx_dev->bufsize); | ||
138 | |||
139 | /* program the stream format */ | ||
140 | /* this value needs to be the same as the one programmed */ | ||
141 | azx_sd_writew(chip, azx_dev, SD_FORMAT, azx_dev->format_val); | ||
142 | |||
143 | /* program the stream LVI (last valid index) of the BDL */ | ||
144 | azx_sd_writew(chip, azx_dev, SD_LVI, azx_dev->frags - 1); | ||
145 | |||
146 | /* program the BDL address */ | ||
147 | /* lower BDL address */ | ||
148 | azx_sd_writel(chip, azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr); | ||
149 | /* upper BDL address */ | ||
150 | azx_sd_writel(chip, azx_dev, SD_BDLPU, | ||
151 | upper_32_bits(azx_dev->bdl.addr)); | ||
152 | |||
153 | /* enable the position buffer */ | ||
154 | if (chip->get_position[0] != azx_get_pos_lpib || | ||
155 | chip->get_position[1] != azx_get_pos_lpib) { | ||
156 | if (!(azx_readl(chip, DPLBASE) & AZX_DPLBASE_ENABLE)) | ||
157 | azx_writel(chip, DPLBASE, | ||
158 | (u32)chip->posbuf.addr | AZX_DPLBASE_ENABLE); | ||
159 | } | ||
160 | |||
161 | /* set the interrupt enable bits in the descriptor control register */ | ||
162 | azx_sd_writel(chip, azx_dev, SD_CTL, | ||
163 | azx_sd_readl(chip, azx_dev, SD_CTL) | SD_INT_MASK); | ||
164 | |||
165 | return 0; | ||
166 | } | ||
167 | 41 | ||
168 | /* assign a stream for the PCM */ | 42 | /* assign a stream for the PCM */ |
169 | static inline struct azx_dev * | 43 | static inline struct azx_dev * |
170 | azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream) | 44 | azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream) |
171 | { | 45 | { |
172 | int dev, i, nums; | 46 | struct hdac_stream *s; |
173 | struct azx_dev *res = NULL; | 47 | |
174 | /* make a non-zero unique key for the substream */ | 48 | s = snd_hdac_stream_assign(azx_bus(chip), substream); |
175 | int key = (substream->pcm->device << 16) | (substream->number << 2) | | 49 | if (!s) |
176 | (substream->stream + 1); | 50 | return NULL; |
177 | 51 | return stream_to_azx_dev(s); | |
178 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
179 | dev = chip->playback_index_offset; | ||
180 | nums = chip->playback_streams; | ||
181 | } else { | ||
182 | dev = chip->capture_index_offset; | ||
183 | nums = chip->capture_streams; | ||
184 | } | ||
185 | for (i = 0; i < nums; i++, dev++) { | ||
186 | struct azx_dev *azx_dev = &chip->azx_dev[dev]; | ||
187 | dsp_lock(azx_dev); | ||
188 | if (!azx_dev->opened && !dsp_is_locked(azx_dev)) { | ||
189 | if (azx_dev->assigned_key == key) { | ||
190 | azx_dev->opened = 1; | ||
191 | azx_dev->assigned_key = key; | ||
192 | dsp_unlock(azx_dev); | ||
193 | return azx_dev; | ||
194 | } | ||
195 | if (!res || | ||
196 | (chip->driver_caps & AZX_DCAPS_REVERSE_ASSIGN)) | ||
197 | res = azx_dev; | ||
198 | } | ||
199 | dsp_unlock(azx_dev); | ||
200 | } | ||
201 | if (res) { | ||
202 | dsp_lock(res); | ||
203 | res->opened = 1; | ||
204 | res->assigned_key = key; | ||
205 | dsp_unlock(res); | ||
206 | } | ||
207 | return res; | ||
208 | } | 52 | } |
209 | 53 | ||
210 | /* release the assigned stream */ | 54 | /* release the assigned stream */ |
211 | static inline void azx_release_device(struct azx_dev *azx_dev) | 55 | static inline void azx_release_device(struct azx_dev *azx_dev) |
212 | { | 56 | { |
213 | azx_dev->opened = 0; | 57 | snd_hdac_stream_release(azx_stream(azx_dev)); |
214 | } | ||
215 | |||
216 | static cycle_t azx_cc_read(const struct cyclecounter *cc) | ||
217 | { | ||
218 | struct azx_dev *azx_dev = container_of(cc, struct azx_dev, azx_cc); | ||
219 | struct snd_pcm_substream *substream = azx_dev->substream; | ||
220 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); | ||
221 | struct azx *chip = apcm->chip; | ||
222 | |||
223 | return azx_readl(chip, WALLCLK); | ||
224 | } | ||
225 | |||
226 | static void azx_timecounter_init(struct snd_pcm_substream *substream, | ||
227 | bool force, cycle_t last) | ||
228 | { | ||
229 | struct azx_dev *azx_dev = get_azx_dev(substream); | ||
230 | struct timecounter *tc = &azx_dev->azx_tc; | ||
231 | struct cyclecounter *cc = &azx_dev->azx_cc; | ||
232 | u64 nsec; | ||
233 | |||
234 | cc->read = azx_cc_read; | ||
235 | cc->mask = CLOCKSOURCE_MASK(32); | ||
236 | |||
237 | /* | ||
238 | * Converting from 24 MHz to ns means applying a 125/3 factor. | ||
239 | * To avoid any saturation issues in intermediate operations, | ||
240 | * the 125 factor is applied first. The division is applied | ||
241 | * last after reading the timecounter value. | ||
242 | * Applying the 1/3 factor as part of the multiplication | ||
243 | * requires at least 20 bits for a decent precision, however | ||
244 | * overflows occur after about 4 hours or less, not a option. | ||
245 | */ | ||
246 | |||
247 | cc->mult = 125; /* saturation after 195 years */ | ||
248 | cc->shift = 0; | ||
249 | |||
250 | nsec = 0; /* audio time is elapsed time since trigger */ | ||
251 | timecounter_init(tc, cc, nsec); | ||
252 | if (force) | ||
253 | /* | ||
254 | * force timecounter to use predefined value, | ||
255 | * used for synchronized starts | ||
256 | */ | ||
257 | tc->cycle_last = last; | ||
258 | } | 58 | } |
259 | 59 | ||
260 | static inline struct hda_pcm_stream * | 60 | static inline struct hda_pcm_stream * |
@@ -285,119 +85,6 @@ static u64 azx_adjust_codec_delay(struct snd_pcm_substream *substream, | |||
285 | } | 85 | } |
286 | 86 | ||
287 | /* | 87 | /* |
288 | * set up a BDL entry | ||
289 | */ | ||
290 | static int setup_bdle(struct azx *chip, | ||
291 | struct snd_dma_buffer *dmab, | ||
292 | struct azx_dev *azx_dev, u32 **bdlp, | ||
293 | int ofs, int size, int with_ioc) | ||
294 | { | ||
295 | u32 *bdl = *bdlp; | ||
296 | |||
297 | while (size > 0) { | ||
298 | dma_addr_t addr; | ||
299 | int chunk; | ||
300 | |||
301 | if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES) | ||
302 | return -EINVAL; | ||
303 | |||
304 | addr = snd_sgbuf_get_addr(dmab, ofs); | ||
305 | /* program the address field of the BDL entry */ | ||
306 | bdl[0] = cpu_to_le32((u32)addr); | ||
307 | bdl[1] = cpu_to_le32(upper_32_bits(addr)); | ||
308 | /* program the size field of the BDL entry */ | ||
309 | chunk = snd_sgbuf_get_chunk_size(dmab, ofs, size); | ||
310 | /* one BDLE cannot cross 4K boundary on CTHDA chips */ | ||
311 | if (chip->driver_caps & AZX_DCAPS_4K_BDLE_BOUNDARY) { | ||
312 | u32 remain = 0x1000 - (ofs & 0xfff); | ||
313 | if (chunk > remain) | ||
314 | chunk = remain; | ||
315 | } | ||
316 | bdl[2] = cpu_to_le32(chunk); | ||
317 | /* program the IOC to enable interrupt | ||
318 | * only when the whole fragment is processed | ||
319 | */ | ||
320 | size -= chunk; | ||
321 | bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01); | ||
322 | bdl += 4; | ||
323 | azx_dev->frags++; | ||
324 | ofs += chunk; | ||
325 | } | ||
326 | *bdlp = bdl; | ||
327 | return ofs; | ||
328 | } | ||
329 | |||
330 | /* | ||
331 | * set up BDL entries | ||
332 | */ | ||
333 | static int azx_setup_periods(struct azx *chip, | ||
334 | struct snd_pcm_substream *substream, | ||
335 | struct azx_dev *azx_dev) | ||
336 | { | ||
337 | u32 *bdl; | ||
338 | int i, ofs, periods, period_bytes; | ||
339 | int pos_adj = 0; | ||
340 | |||
341 | /* reset BDL address */ | ||
342 | azx_sd_writel(chip, azx_dev, SD_BDLPL, 0); | ||
343 | azx_sd_writel(chip, azx_dev, SD_BDLPU, 0); | ||
344 | |||
345 | period_bytes = azx_dev->period_bytes; | ||
346 | periods = azx_dev->bufsize / period_bytes; | ||
347 | |||
348 | /* program the initial BDL entries */ | ||
349 | bdl = (u32 *)azx_dev->bdl.area; | ||
350 | ofs = 0; | ||
351 | azx_dev->frags = 0; | ||
352 | |||
353 | if (chip->bdl_pos_adj) | ||
354 | pos_adj = chip->bdl_pos_adj[chip->dev_index]; | ||
355 | if (!azx_dev->no_period_wakeup && pos_adj > 0) { | ||
356 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
357 | int pos_align = pos_adj; | ||
358 | pos_adj = (pos_adj * runtime->rate + 47999) / 48000; | ||
359 | if (!pos_adj) | ||
360 | pos_adj = pos_align; | ||
361 | else | ||
362 | pos_adj = ((pos_adj + pos_align - 1) / pos_align) * | ||
363 | pos_align; | ||
364 | pos_adj = frames_to_bytes(runtime, pos_adj); | ||
365 | if (pos_adj >= period_bytes) { | ||
366 | dev_warn(chip->card->dev,"Too big adjustment %d\n", | ||
367 | pos_adj); | ||
368 | pos_adj = 0; | ||
369 | } else { | ||
370 | ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream), | ||
371 | azx_dev, | ||
372 | &bdl, ofs, pos_adj, true); | ||
373 | if (ofs < 0) | ||
374 | goto error; | ||
375 | } | ||
376 | } else | ||
377 | pos_adj = 0; | ||
378 | |||
379 | for (i = 0; i < periods; i++) { | ||
380 | if (i == periods - 1 && pos_adj) | ||
381 | ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream), | ||
382 | azx_dev, &bdl, ofs, | ||
383 | period_bytes - pos_adj, 0); | ||
384 | else | ||
385 | ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream), | ||
386 | azx_dev, &bdl, ofs, | ||
387 | period_bytes, | ||
388 | !azx_dev->no_period_wakeup); | ||
389 | if (ofs < 0) | ||
390 | goto error; | ||
391 | } | ||
392 | return 0; | ||
393 | |||
394 | error: | ||
395 | dev_err(chip->card->dev, "Too many BDL entries: buffer=%d, period=%d\n", | ||
396 | azx_dev->bufsize, period_bytes); | ||
397 | return -EINVAL; | ||
398 | } | ||
399 | |||
400 | /* | ||
401 | * PCM ops | 88 | * PCM ops |
402 | */ | 89 | */ |
403 | 90 | ||
@@ -407,13 +94,9 @@ static int azx_pcm_close(struct snd_pcm_substream *substream) | |||
407 | struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); | 94 | struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); |
408 | struct azx *chip = apcm->chip; | 95 | struct azx *chip = apcm->chip; |
409 | struct azx_dev *azx_dev = get_azx_dev(substream); | 96 | struct azx_dev *azx_dev = get_azx_dev(substream); |
410 | unsigned long flags; | ||
411 | 97 | ||
98 | trace_azx_pcm_close(chip, azx_dev); | ||
412 | mutex_lock(&chip->open_mutex); | 99 | mutex_lock(&chip->open_mutex); |
413 | spin_lock_irqsave(&chip->reg_lock, flags); | ||
414 | azx_dev->substream = NULL; | ||
415 | azx_dev->running = 0; | ||
416 | spin_unlock_irqrestore(&chip->reg_lock, flags); | ||
417 | azx_release_device(azx_dev); | 100 | azx_release_device(azx_dev); |
418 | if (hinfo->ops.close) | 101 | if (hinfo->ops.close) |
419 | hinfo->ops.close(hinfo, apcm->codec, substream); | 102 | hinfo->ops.close(hinfo, apcm->codec, substream); |
@@ -428,18 +111,23 @@ static int azx_pcm_hw_params(struct snd_pcm_substream *substream, | |||
428 | { | 111 | { |
429 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); | 112 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
430 | struct azx *chip = apcm->chip; | 113 | struct azx *chip = apcm->chip; |
114 | struct azx_dev *azx_dev = get_azx_dev(substream); | ||
431 | int ret; | 115 | int ret; |
432 | 116 | ||
433 | dsp_lock(get_azx_dev(substream)); | 117 | trace_azx_pcm_hw_params(chip, azx_dev); |
434 | if (dsp_is_locked(get_azx_dev(substream))) { | 118 | dsp_lock(azx_dev); |
119 | if (dsp_is_locked(azx_dev)) { | ||
435 | ret = -EBUSY; | 120 | ret = -EBUSY; |
436 | goto unlock; | 121 | goto unlock; |
437 | } | 122 | } |
438 | 123 | ||
124 | azx_dev->core.bufsize = 0; | ||
125 | azx_dev->core.period_bytes = 0; | ||
126 | azx_dev->core.format_val = 0; | ||
439 | ret = chip->ops->substream_alloc_pages(chip, substream, | 127 | ret = chip->ops->substream_alloc_pages(chip, substream, |
440 | params_buffer_bytes(hw_params)); | 128 | params_buffer_bytes(hw_params)); |
441 | unlock: | 129 | unlock: |
442 | dsp_unlock(get_azx_dev(substream)); | 130 | dsp_unlock(azx_dev); |
443 | return ret; | 131 | return ret; |
444 | } | 132 | } |
445 | 133 | ||
@@ -453,19 +141,13 @@ static int azx_pcm_hw_free(struct snd_pcm_substream *substream) | |||
453 | 141 | ||
454 | /* reset BDL address */ | 142 | /* reset BDL address */ |
455 | dsp_lock(azx_dev); | 143 | dsp_lock(azx_dev); |
456 | if (!dsp_is_locked(azx_dev)) { | 144 | if (!dsp_is_locked(azx_dev)) |
457 | azx_sd_writel(chip, azx_dev, SD_BDLPL, 0); | 145 | snd_hdac_stream_cleanup(azx_stream(azx_dev)); |
458 | azx_sd_writel(chip, azx_dev, SD_BDLPU, 0); | ||
459 | azx_sd_writel(chip, azx_dev, SD_CTL, 0); | ||
460 | azx_dev->bufsize = 0; | ||
461 | azx_dev->period_bytes = 0; | ||
462 | azx_dev->format_val = 0; | ||
463 | } | ||
464 | 146 | ||
465 | snd_hda_codec_cleanup(apcm->codec, hinfo, substream); | 147 | snd_hda_codec_cleanup(apcm->codec, hinfo, substream); |
466 | 148 | ||
467 | err = chip->ops->substream_free_pages(chip, substream); | 149 | err = chip->ops->substream_free_pages(chip, substream); |
468 | azx_dev->prepared = 0; | 150 | azx_stream(azx_dev)->prepared = 0; |
469 | dsp_unlock(azx_dev); | 151 | dsp_unlock(azx_dev); |
470 | return err; | 152 | return err; |
471 | } | 153 | } |
@@ -477,21 +159,21 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream) | |||
477 | struct azx_dev *azx_dev = get_azx_dev(substream); | 159 | struct azx_dev *azx_dev = get_azx_dev(substream); |
478 | struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); | 160 | struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); |
479 | struct snd_pcm_runtime *runtime = substream->runtime; | 161 | struct snd_pcm_runtime *runtime = substream->runtime; |
480 | unsigned int bufsize, period_bytes, format_val, stream_tag; | 162 | unsigned int format_val, stream_tag; |
481 | int err; | 163 | int err; |
482 | struct hda_spdif_out *spdif = | 164 | struct hda_spdif_out *spdif = |
483 | snd_hda_spdif_out_of_nid(apcm->codec, hinfo->nid); | 165 | snd_hda_spdif_out_of_nid(apcm->codec, hinfo->nid); |
484 | unsigned short ctls = spdif ? spdif->ctls : 0; | 166 | unsigned short ctls = spdif ? spdif->ctls : 0; |
485 | 167 | ||
168 | trace_azx_pcm_prepare(chip, azx_dev); | ||
486 | dsp_lock(azx_dev); | 169 | dsp_lock(azx_dev); |
487 | if (dsp_is_locked(azx_dev)) { | 170 | if (dsp_is_locked(azx_dev)) { |
488 | err = -EBUSY; | 171 | err = -EBUSY; |
489 | goto unlock; | 172 | goto unlock; |
490 | } | 173 | } |
491 | 174 | ||
492 | azx_stream_reset(chip, azx_dev); | 175 | snd_hdac_stream_reset(azx_stream(azx_dev)); |
493 | format_val = snd_hda_calc_stream_format(apcm->codec, | 176 | format_val = snd_hdac_calc_stream_format(runtime->rate, |
494 | runtime->rate, | ||
495 | runtime->channels, | 177 | runtime->channels, |
496 | runtime->format, | 178 | runtime->format, |
497 | hinfo->maxbps, | 179 | hinfo->maxbps, |
@@ -504,55 +186,23 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream) | |||
504 | goto unlock; | 186 | goto unlock; |
505 | } | 187 | } |
506 | 188 | ||
507 | bufsize = snd_pcm_lib_buffer_bytes(substream); | 189 | err = snd_hdac_stream_set_params(azx_stream(azx_dev), format_val); |
508 | period_bytes = snd_pcm_lib_period_bytes(substream); | 190 | if (err < 0) |
509 | 191 | goto unlock; | |
510 | dev_dbg(chip->card->dev, "azx_pcm_prepare: bufsize=0x%x, format=0x%x\n", | ||
511 | bufsize, format_val); | ||
512 | |||
513 | if (bufsize != azx_dev->bufsize || | ||
514 | period_bytes != azx_dev->period_bytes || | ||
515 | format_val != azx_dev->format_val || | ||
516 | runtime->no_period_wakeup != azx_dev->no_period_wakeup) { | ||
517 | azx_dev->bufsize = bufsize; | ||
518 | azx_dev->period_bytes = period_bytes; | ||
519 | azx_dev->format_val = format_val; | ||
520 | azx_dev->no_period_wakeup = runtime->no_period_wakeup; | ||
521 | err = azx_setup_periods(chip, substream, azx_dev); | ||
522 | if (err < 0) | ||
523 | goto unlock; | ||
524 | } | ||
525 | 192 | ||
526 | /* when LPIB delay correction gives a small negative value, | 193 | snd_hdac_stream_setup(azx_stream(azx_dev)); |
527 | * we ignore it; currently set the threshold statically to | ||
528 | * 64 frames | ||
529 | */ | ||
530 | if (runtime->period_size > 64) | ||
531 | azx_dev->delay_negative_threshold = -frames_to_bytes(runtime, 64); | ||
532 | else | ||
533 | azx_dev->delay_negative_threshold = 0; | ||
534 | |||
535 | /* wallclk has 24Mhz clock source */ | ||
536 | azx_dev->period_wallclk = (((runtime->period_size * 24000) / | ||
537 | runtime->rate) * 1000); | ||
538 | azx_setup_controller(chip, azx_dev); | ||
539 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
540 | azx_dev->fifo_size = | ||
541 | azx_sd_readw(chip, azx_dev, SD_FIFOSIZE) + 1; | ||
542 | else | ||
543 | azx_dev->fifo_size = 0; | ||
544 | 194 | ||
545 | stream_tag = azx_dev->stream_tag; | 195 | stream_tag = azx_dev->core.stream_tag; |
546 | /* CA-IBG chips need the playback stream starting from 1 */ | 196 | /* CA-IBG chips need the playback stream starting from 1 */ |
547 | if ((chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) && | 197 | if ((chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) && |
548 | stream_tag > chip->capture_streams) | 198 | stream_tag > chip->capture_streams) |
549 | stream_tag -= chip->capture_streams; | 199 | stream_tag -= chip->capture_streams; |
550 | err = snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag, | 200 | err = snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag, |
551 | azx_dev->format_val, substream); | 201 | azx_dev->core.format_val, substream); |
552 | 202 | ||
553 | unlock: | 203 | unlock: |
554 | if (!err) | 204 | if (!err) |
555 | azx_dev->prepared = 1; | 205 | azx_stream(azx_dev)->prepared = 1; |
556 | dsp_unlock(azx_dev); | 206 | dsp_unlock(azx_dev); |
557 | return err; | 207 | return err; |
558 | } | 208 | } |
@@ -561,28 +211,36 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) | |||
561 | { | 211 | { |
562 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); | 212 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
563 | struct azx *chip = apcm->chip; | 213 | struct azx *chip = apcm->chip; |
214 | struct hdac_bus *bus = azx_bus(chip); | ||
564 | struct azx_dev *azx_dev; | 215 | struct azx_dev *azx_dev; |
565 | struct snd_pcm_substream *s; | 216 | struct snd_pcm_substream *s; |
566 | int rstart = 0, start, nsync = 0, sbits = 0; | 217 | struct hdac_stream *hstr; |
567 | int nwait, timeout; | 218 | bool start; |
219 | int sbits = 0; | ||
220 | int sync_reg; | ||
568 | 221 | ||
569 | azx_dev = get_azx_dev(substream); | 222 | azx_dev = get_azx_dev(substream); |
570 | trace_azx_pcm_trigger(chip, azx_dev, cmd); | 223 | trace_azx_pcm_trigger(chip, azx_dev, cmd); |
571 | 224 | ||
572 | if (dsp_is_locked(azx_dev) || !azx_dev->prepared) | 225 | hstr = azx_stream(azx_dev); |
226 | if (chip->driver_caps & AZX_DCAPS_OLD_SSYNC) | ||
227 | sync_reg = AZX_REG_OLD_SSYNC; | ||
228 | else | ||
229 | sync_reg = AZX_REG_SSYNC; | ||
230 | |||
231 | if (dsp_is_locked(azx_dev) || !hstr->prepared) | ||
573 | return -EPIPE; | 232 | return -EPIPE; |
574 | 233 | ||
575 | switch (cmd) { | 234 | switch (cmd) { |
576 | case SNDRV_PCM_TRIGGER_START: | 235 | case SNDRV_PCM_TRIGGER_START: |
577 | rstart = 1; | ||
578 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | 236 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
579 | case SNDRV_PCM_TRIGGER_RESUME: | 237 | case SNDRV_PCM_TRIGGER_RESUME: |
580 | start = 1; | 238 | start = true; |
581 | break; | 239 | break; |
582 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | 240 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
583 | case SNDRV_PCM_TRIGGER_SUSPEND: | 241 | case SNDRV_PCM_TRIGGER_SUSPEND: |
584 | case SNDRV_PCM_TRIGGER_STOP: | 242 | case SNDRV_PCM_TRIGGER_STOP: |
585 | start = 0; | 243 | start = false; |
586 | break; | 244 | break; |
587 | default: | 245 | default: |
588 | return -EINVAL; | 246 | return -EINVAL; |
@@ -592,115 +250,55 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) | |||
592 | if (s->pcm->card != substream->pcm->card) | 250 | if (s->pcm->card != substream->pcm->card) |
593 | continue; | 251 | continue; |
594 | azx_dev = get_azx_dev(s); | 252 | azx_dev = get_azx_dev(s); |
595 | sbits |= 1 << azx_dev->index; | 253 | sbits |= 1 << azx_dev->core.index; |
596 | nsync++; | ||
597 | snd_pcm_trigger_done(s, substream); | 254 | snd_pcm_trigger_done(s, substream); |
598 | } | 255 | } |
599 | 256 | ||
600 | spin_lock(&chip->reg_lock); | 257 | spin_lock(&bus->reg_lock); |
601 | 258 | ||
602 | /* first, set SYNC bits of corresponding streams */ | 259 | /* first, set SYNC bits of corresponding streams */ |
603 | if (chip->driver_caps & AZX_DCAPS_OLD_SSYNC) | 260 | snd_hdac_stream_sync_trigger(hstr, true, sbits, sync_reg); |
604 | azx_writel(chip, OLD_SSYNC, | ||
605 | azx_readl(chip, OLD_SSYNC) | sbits); | ||
606 | else | ||
607 | azx_writel(chip, SSYNC, azx_readl(chip, SSYNC) | sbits); | ||
608 | 261 | ||
609 | snd_pcm_group_for_each_entry(s, substream) { | 262 | snd_pcm_group_for_each_entry(s, substream) { |
610 | if (s->pcm->card != substream->pcm->card) | 263 | if (s->pcm->card != substream->pcm->card) |
611 | continue; | 264 | continue; |
612 | azx_dev = get_azx_dev(s); | 265 | azx_dev = get_azx_dev(s); |
613 | if (start) { | 266 | if (start) { |
614 | azx_dev->start_wallclk = azx_readl(chip, WALLCLK); | 267 | azx_dev->insufficient = 1; |
615 | if (!rstart) | 268 | snd_hdac_stream_start(azx_stream(azx_dev), true); |
616 | azx_dev->start_wallclk -= | ||
617 | azx_dev->period_wallclk; | ||
618 | azx_stream_start(chip, azx_dev); | ||
619 | } else { | 269 | } else { |
620 | azx_stream_stop(chip, azx_dev); | 270 | snd_hdac_stream_stop(azx_stream(azx_dev)); |
621 | } | ||
622 | azx_dev->running = start; | ||
623 | } | ||
624 | spin_unlock(&chip->reg_lock); | ||
625 | if (start) { | ||
626 | /* wait until all FIFOs get ready */ | ||
627 | for (timeout = 5000; timeout; timeout--) { | ||
628 | nwait = 0; | ||
629 | snd_pcm_group_for_each_entry(s, substream) { | ||
630 | if (s->pcm->card != substream->pcm->card) | ||
631 | continue; | ||
632 | azx_dev = get_azx_dev(s); | ||
633 | if (!(azx_sd_readb(chip, azx_dev, SD_STS) & | ||
634 | SD_STS_FIFO_READY)) | ||
635 | nwait++; | ||
636 | } | ||
637 | if (!nwait) | ||
638 | break; | ||
639 | cpu_relax(); | ||
640 | } | ||
641 | } else { | ||
642 | /* wait until all RUN bits are cleared */ | ||
643 | for (timeout = 5000; timeout; timeout--) { | ||
644 | nwait = 0; | ||
645 | snd_pcm_group_for_each_entry(s, substream) { | ||
646 | if (s->pcm->card != substream->pcm->card) | ||
647 | continue; | ||
648 | azx_dev = get_azx_dev(s); | ||
649 | if (azx_sd_readb(chip, azx_dev, SD_CTL) & | ||
650 | SD_CTL_DMA_START) | ||
651 | nwait++; | ||
652 | } | ||
653 | if (!nwait) | ||
654 | break; | ||
655 | cpu_relax(); | ||
656 | } | 271 | } |
657 | } | 272 | } |
658 | spin_lock(&chip->reg_lock); | 273 | spin_unlock(&bus->reg_lock); |
274 | |||
275 | snd_hdac_stream_sync(hstr, start, sbits); | ||
276 | |||
277 | spin_lock(&bus->reg_lock); | ||
659 | /* reset SYNC bits */ | 278 | /* reset SYNC bits */ |
660 | if (chip->driver_caps & AZX_DCAPS_OLD_SSYNC) | 279 | snd_hdac_stream_sync_trigger(hstr, false, sbits, sync_reg); |
661 | azx_writel(chip, OLD_SSYNC, | 280 | if (start) |
662 | azx_readl(chip, OLD_SSYNC) & ~sbits); | 281 | snd_hdac_stream_timecounter_init(hstr, sbits); |
663 | else | 282 | spin_unlock(&bus->reg_lock); |
664 | azx_writel(chip, SSYNC, azx_readl(chip, SSYNC) & ~sbits); | ||
665 | if (start) { | ||
666 | azx_timecounter_init(substream, 0, 0); | ||
667 | snd_pcm_gettime(substream->runtime, &substream->runtime->trigger_tstamp); | ||
668 | substream->runtime->trigger_tstamp_latched = true; | ||
669 | |||
670 | if (nsync > 1) { | ||
671 | cycle_t cycle_last; | ||
672 | |||
673 | /* same start cycle for master and group */ | ||
674 | azx_dev = get_azx_dev(substream); | ||
675 | cycle_last = azx_dev->azx_tc.cycle_last; | ||
676 | |||
677 | snd_pcm_group_for_each_entry(s, substream) { | ||
678 | if (s->pcm->card != substream->pcm->card) | ||
679 | continue; | ||
680 | azx_timecounter_init(s, 1, cycle_last); | ||
681 | } | ||
682 | } | ||
683 | } | ||
684 | spin_unlock(&chip->reg_lock); | ||
685 | return 0; | 283 | return 0; |
686 | } | 284 | } |
687 | 285 | ||
688 | unsigned int azx_get_pos_lpib(struct azx *chip, struct azx_dev *azx_dev) | 286 | unsigned int azx_get_pos_lpib(struct azx *chip, struct azx_dev *azx_dev) |
689 | { | 287 | { |
690 | return azx_sd_readl(chip, azx_dev, SD_LPIB); | 288 | return snd_hdac_stream_get_pos_lpib(azx_stream(azx_dev)); |
691 | } | 289 | } |
692 | EXPORT_SYMBOL_GPL(azx_get_pos_lpib); | 290 | EXPORT_SYMBOL_GPL(azx_get_pos_lpib); |
693 | 291 | ||
694 | unsigned int azx_get_pos_posbuf(struct azx *chip, struct azx_dev *azx_dev) | 292 | unsigned int azx_get_pos_posbuf(struct azx *chip, struct azx_dev *azx_dev) |
695 | { | 293 | { |
696 | return le32_to_cpu(*azx_dev->posbuf); | 294 | return snd_hdac_stream_get_pos_posbuf(azx_stream(azx_dev)); |
697 | } | 295 | } |
698 | EXPORT_SYMBOL_GPL(azx_get_pos_posbuf); | 296 | EXPORT_SYMBOL_GPL(azx_get_pos_posbuf); |
699 | 297 | ||
700 | unsigned int azx_get_position(struct azx *chip, | 298 | unsigned int azx_get_position(struct azx *chip, |
701 | struct azx_dev *azx_dev) | 299 | struct azx_dev *azx_dev) |
702 | { | 300 | { |
703 | struct snd_pcm_substream *substream = azx_dev->substream; | 301 | struct snd_pcm_substream *substream = azx_dev->core.substream; |
704 | unsigned int pos; | 302 | unsigned int pos; |
705 | int stream = substream->stream; | 303 | int stream = substream->stream; |
706 | int delay = 0; | 304 | int delay = 0; |
@@ -710,7 +308,7 @@ unsigned int azx_get_position(struct azx *chip, | |||
710 | else /* use the position buffer as default */ | 308 | else /* use the position buffer as default */ |
711 | pos = azx_get_pos_posbuf(chip, azx_dev); | 309 | pos = azx_get_pos_posbuf(chip, azx_dev); |
712 | 310 | ||
713 | if (pos >= azx_dev->bufsize) | 311 | if (pos >= azx_dev->core.bufsize) |
714 | pos = 0; | 312 | pos = 0; |
715 | 313 | ||
716 | if (substream->runtime) { | 314 | if (substream->runtime) { |
@@ -752,7 +350,7 @@ static int azx_get_time_info(struct snd_pcm_substream *substream, | |||
752 | 350 | ||
753 | snd_pcm_gettime(substream->runtime, system_ts); | 351 | snd_pcm_gettime(substream->runtime, system_ts); |
754 | 352 | ||
755 | nsec = timecounter_read(&azx_dev->azx_tc); | 353 | nsec = timecounter_read(&azx_dev->core.tc); |
756 | nsec = div_u64(nsec, 3); /* can be optimized */ | 354 | nsec = div_u64(nsec, 3); /* can be optimized */ |
757 | if (audio_tstamp_config->report_delay) | 355 | if (audio_tstamp_config->report_delay) |
758 | nsec = azx_adjust_codec_delay(substream, nsec); | 356 | nsec = azx_adjust_codec_delay(substream, nsec); |
@@ -802,17 +400,18 @@ static int azx_pcm_open(struct snd_pcm_substream *substream) | |||
802 | struct azx *chip = apcm->chip; | 400 | struct azx *chip = apcm->chip; |
803 | struct azx_dev *azx_dev; | 401 | struct azx_dev *azx_dev; |
804 | struct snd_pcm_runtime *runtime = substream->runtime; | 402 | struct snd_pcm_runtime *runtime = substream->runtime; |
805 | unsigned long flags; | ||
806 | int err; | 403 | int err; |
807 | int buff_step; | 404 | int buff_step; |
808 | 405 | ||
809 | snd_hda_codec_pcm_get(apcm->info); | 406 | snd_hda_codec_pcm_get(apcm->info); |
810 | mutex_lock(&chip->open_mutex); | 407 | mutex_lock(&chip->open_mutex); |
811 | azx_dev = azx_assign_device(chip, substream); | 408 | azx_dev = azx_assign_device(chip, substream); |
409 | trace_azx_pcm_open(chip, azx_dev); | ||
812 | if (azx_dev == NULL) { | 410 | if (azx_dev == NULL) { |
813 | err = -EBUSY; | 411 | err = -EBUSY; |
814 | goto unlock; | 412 | goto unlock; |
815 | } | 413 | } |
414 | runtime->private_data = azx_dev; | ||
816 | runtime->hw = azx_pcm_hw; | 415 | runtime->hw = azx_pcm_hw; |
817 | runtime->hw.channels_min = hinfo->channels_min; | 416 | runtime->hw.channels_min = hinfo->channels_min; |
818 | runtime->hw.channels_max = hinfo->channels_max; | 417 | runtime->hw.channels_max = hinfo->channels_max; |
@@ -874,12 +473,6 @@ static int azx_pcm_open(struct snd_pcm_substream *substream) | |||
874 | runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_LINK_ATIME; | 473 | runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_LINK_ATIME; |
875 | } | 474 | } |
876 | 475 | ||
877 | spin_lock_irqsave(&chip->reg_lock, flags); | ||
878 | azx_dev->substream = substream; | ||
879 | azx_dev->running = 0; | ||
880 | spin_unlock_irqrestore(&chip->reg_lock, flags); | ||
881 | |||
882 | runtime->private_data = azx_dev; | ||
883 | snd_pcm_set_sync(substream); | 476 | snd_pcm_set_sync(substream); |
884 | mutex_unlock(&chip->open_mutex); | 477 | mutex_unlock(&chip->open_mutex); |
885 | return 0; | 478 | return 0; |
@@ -928,10 +521,11 @@ static void azx_pcm_free(struct snd_pcm *pcm) | |||
928 | 521 | ||
929 | #define MAX_PREALLOC_SIZE (32 * 1024 * 1024) | 522 | #define MAX_PREALLOC_SIZE (32 * 1024 * 1024) |
930 | 523 | ||
931 | static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, | 524 | int snd_hda_attach_pcm_stream(struct hda_bus *_bus, struct hda_codec *codec, |
932 | struct hda_pcm *cpcm) | 525 | struct hda_pcm *cpcm) |
933 | { | 526 | { |
934 | struct azx *chip = bus->private_data; | 527 | struct hdac_bus *bus = &_bus->core; |
528 | struct azx *chip = bus_to_azx(bus); | ||
935 | struct snd_pcm *pcm; | 529 | struct snd_pcm *pcm; |
936 | struct azx_pcm *apcm; | 530 | struct azx_pcm *apcm; |
937 | int pcm_dev = cpcm->device; | 531 | int pcm_dev = cpcm->device; |
@@ -979,89 +573,6 @@ static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, | |||
979 | return 0; | 573 | return 0; |
980 | } | 574 | } |
981 | 575 | ||
982 | /* | ||
983 | * CORB / RIRB interface | ||
984 | */ | ||
985 | static int azx_alloc_cmd_io(struct azx *chip) | ||
986 | { | ||
987 | /* single page (at least 4096 bytes) must suffice for both ringbuffes */ | ||
988 | return chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV, | ||
989 | PAGE_SIZE, &chip->rb); | ||
990 | } | ||
991 | |||
992 | static void azx_init_cmd_io(struct azx *chip) | ||
993 | { | ||
994 | int timeout; | ||
995 | |||
996 | spin_lock_irq(&chip->reg_lock); | ||
997 | /* CORB set up */ | ||
998 | chip->corb.addr = chip->rb.addr; | ||
999 | chip->corb.buf = (u32 *)chip->rb.area; | ||
1000 | azx_writel(chip, CORBLBASE, (u32)chip->corb.addr); | ||
1001 | azx_writel(chip, CORBUBASE, upper_32_bits(chip->corb.addr)); | ||
1002 | |||
1003 | /* set the corb size to 256 entries (ULI requires explicitly) */ | ||
1004 | azx_writeb(chip, CORBSIZE, 0x02); | ||
1005 | /* set the corb write pointer to 0 */ | ||
1006 | azx_writew(chip, CORBWP, 0); | ||
1007 | |||
1008 | /* reset the corb hw read pointer */ | ||
1009 | azx_writew(chip, CORBRP, AZX_CORBRP_RST); | ||
1010 | if (!(chip->driver_caps & AZX_DCAPS_CORBRP_SELF_CLEAR)) { | ||
1011 | for (timeout = 1000; timeout > 0; timeout--) { | ||
1012 | if ((azx_readw(chip, CORBRP) & AZX_CORBRP_RST) == AZX_CORBRP_RST) | ||
1013 | break; | ||
1014 | udelay(1); | ||
1015 | } | ||
1016 | if (timeout <= 0) | ||
1017 | dev_err(chip->card->dev, "CORB reset timeout#1, CORBRP = %d\n", | ||
1018 | azx_readw(chip, CORBRP)); | ||
1019 | |||
1020 | azx_writew(chip, CORBRP, 0); | ||
1021 | for (timeout = 1000; timeout > 0; timeout--) { | ||
1022 | if (azx_readw(chip, CORBRP) == 0) | ||
1023 | break; | ||
1024 | udelay(1); | ||
1025 | } | ||
1026 | if (timeout <= 0) | ||
1027 | dev_err(chip->card->dev, "CORB reset timeout#2, CORBRP = %d\n", | ||
1028 | azx_readw(chip, CORBRP)); | ||
1029 | } | ||
1030 | |||
1031 | /* enable corb dma */ | ||
1032 | azx_writeb(chip, CORBCTL, AZX_CORBCTL_RUN); | ||
1033 | |||
1034 | /* RIRB set up */ | ||
1035 | chip->rirb.addr = chip->rb.addr + 2048; | ||
1036 | chip->rirb.buf = (u32 *)(chip->rb.area + 2048); | ||
1037 | chip->rirb.wp = chip->rirb.rp = 0; | ||
1038 | memset(chip->rirb.cmds, 0, sizeof(chip->rirb.cmds)); | ||
1039 | azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr); | ||
1040 | azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr)); | ||
1041 | |||
1042 | /* set the rirb size to 256 entries (ULI requires explicitly) */ | ||
1043 | azx_writeb(chip, RIRBSIZE, 0x02); | ||
1044 | /* reset the rirb hw write pointer */ | ||
1045 | azx_writew(chip, RIRBWP, AZX_RIRBWP_RST); | ||
1046 | /* set N=1, get RIRB response interrupt for new entry */ | ||
1047 | if (chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) | ||
1048 | azx_writew(chip, RINTCNT, 0xc0); | ||
1049 | else | ||
1050 | azx_writew(chip, RINTCNT, 1); | ||
1051 | /* enable rirb dma and response irq */ | ||
1052 | azx_writeb(chip, RIRBCTL, AZX_RBCTL_DMA_EN | AZX_RBCTL_IRQ_EN); | ||
1053 | spin_unlock_irq(&chip->reg_lock); | ||
1054 | } | ||
1055 | |||
1056 | static void azx_free_cmd_io(struct azx *chip) | ||
1057 | { | ||
1058 | spin_lock_irq(&chip->reg_lock); | ||
1059 | /* disable ringbuffer DMAs */ | ||
1060 | azx_writeb(chip, RIRBCTL, 0); | ||
1061 | azx_writeb(chip, CORBCTL, 0); | ||
1062 | spin_unlock_irq(&chip->reg_lock); | ||
1063 | } | ||
1064 | |||
1065 | static unsigned int azx_command_addr(u32 cmd) | 576 | static unsigned int azx_command_addr(u32 cmd) |
1066 | { | 577 | { |
1067 | unsigned int addr = cmd >> 28; | 578 | unsigned int addr = cmd >> 28; |
@@ -1074,92 +585,12 @@ static unsigned int azx_command_addr(u32 cmd) | |||
1074 | return addr; | 585 | return addr; |
1075 | } | 586 | } |
1076 | 587 | ||
1077 | /* send a command */ | ||
1078 | static int azx_corb_send_cmd(struct hda_bus *bus, u32 val) | ||
1079 | { | ||
1080 | struct azx *chip = bus->private_data; | ||
1081 | unsigned int addr = azx_command_addr(val); | ||
1082 | unsigned int wp, rp; | ||
1083 | |||
1084 | spin_lock_irq(&chip->reg_lock); | ||
1085 | |||
1086 | /* add command to corb */ | ||
1087 | wp = azx_readw(chip, CORBWP); | ||
1088 | if (wp == 0xffff) { | ||
1089 | /* something wrong, controller likely turned to D3 */ | ||
1090 | spin_unlock_irq(&chip->reg_lock); | ||
1091 | return -EIO; | ||
1092 | } | ||
1093 | wp++; | ||
1094 | wp %= AZX_MAX_CORB_ENTRIES; | ||
1095 | |||
1096 | rp = azx_readw(chip, CORBRP); | ||
1097 | if (wp == rp) { | ||
1098 | /* oops, it's full */ | ||
1099 | spin_unlock_irq(&chip->reg_lock); | ||
1100 | return -EAGAIN; | ||
1101 | } | ||
1102 | |||
1103 | chip->rirb.cmds[addr]++; | ||
1104 | chip->corb.buf[wp] = cpu_to_le32(val); | ||
1105 | azx_writew(chip, CORBWP, wp); | ||
1106 | |||
1107 | spin_unlock_irq(&chip->reg_lock); | ||
1108 | |||
1109 | return 0; | ||
1110 | } | ||
1111 | |||
1112 | #define AZX_RIRB_EX_UNSOL_EV (1<<4) | ||
1113 | |||
1114 | /* retrieve RIRB entry - called from interrupt handler */ | ||
1115 | static void azx_update_rirb(struct azx *chip) | ||
1116 | { | ||
1117 | unsigned int rp, wp; | ||
1118 | unsigned int addr; | ||
1119 | u32 res, res_ex; | ||
1120 | |||
1121 | wp = azx_readw(chip, RIRBWP); | ||
1122 | if (wp == 0xffff) { | ||
1123 | /* something wrong, controller likely turned to D3 */ | ||
1124 | return; | ||
1125 | } | ||
1126 | |||
1127 | if (wp == chip->rirb.wp) | ||
1128 | return; | ||
1129 | chip->rirb.wp = wp; | ||
1130 | |||
1131 | while (chip->rirb.rp != wp) { | ||
1132 | chip->rirb.rp++; | ||
1133 | chip->rirb.rp %= AZX_MAX_RIRB_ENTRIES; | ||
1134 | |||
1135 | rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */ | ||
1136 | res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]); | ||
1137 | res = le32_to_cpu(chip->rirb.buf[rp]); | ||
1138 | addr = res_ex & 0xf; | ||
1139 | if ((addr >= AZX_MAX_CODECS) || !(chip->codec_mask & (1 << addr))) { | ||
1140 | dev_err(chip->card->dev, "spurious response %#x:%#x, rp = %d, wp = %d", | ||
1141 | res, res_ex, | ||
1142 | chip->rirb.rp, wp); | ||
1143 | snd_BUG(); | ||
1144 | } else if (res_ex & AZX_RIRB_EX_UNSOL_EV) | ||
1145 | snd_hda_queue_unsol_event(chip->bus, res, res_ex); | ||
1146 | else if (chip->rirb.cmds[addr]) { | ||
1147 | chip->rirb.res[addr] = res; | ||
1148 | smp_wmb(); | ||
1149 | chip->rirb.cmds[addr]--; | ||
1150 | } else if (printk_ratelimit()) { | ||
1151 | dev_err(chip->card->dev, "spurious response %#x:%#x, last cmd=%#08x\n", | ||
1152 | res, res_ex, | ||
1153 | chip->last_cmd[addr]); | ||
1154 | } | ||
1155 | } | ||
1156 | } | ||
1157 | |||
1158 | /* receive a response */ | 588 | /* receive a response */ |
1159 | static unsigned int azx_rirb_get_response(struct hda_bus *bus, | 589 | static int azx_rirb_get_response(struct hdac_bus *bus, unsigned int addr, |
1160 | unsigned int addr) | 590 | unsigned int *res) |
1161 | { | 591 | { |
1162 | struct azx *chip = bus->private_data; | 592 | struct azx *chip = bus_to_azx(bus); |
593 | struct hda_bus *hbus = &chip->bus; | ||
1163 | unsigned long timeout; | 594 | unsigned long timeout; |
1164 | unsigned long loopcounter; | 595 | unsigned long loopcounter; |
1165 | int do_poll = 0; | 596 | int do_poll = 0; |
@@ -1168,22 +599,21 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus, | |||
1168 | timeout = jiffies + msecs_to_jiffies(1000); | 599 | timeout = jiffies + msecs_to_jiffies(1000); |
1169 | 600 | ||
1170 | for (loopcounter = 0;; loopcounter++) { | 601 | for (loopcounter = 0;; loopcounter++) { |
1171 | if (chip->polling_mode || do_poll) { | 602 | spin_lock_irq(&bus->reg_lock); |
1172 | spin_lock_irq(&chip->reg_lock); | 603 | if (chip->polling_mode || do_poll) |
1173 | azx_update_rirb(chip); | 604 | snd_hdac_bus_update_rirb(bus); |
1174 | spin_unlock_irq(&chip->reg_lock); | 605 | if (!bus->rirb.cmds[addr]) { |
1175 | } | ||
1176 | if (!chip->rirb.cmds[addr]) { | ||
1177 | smp_rmb(); | ||
1178 | bus->rirb_error = 0; | ||
1179 | |||
1180 | if (!do_poll) | 606 | if (!do_poll) |
1181 | chip->poll_count = 0; | 607 | chip->poll_count = 0; |
1182 | return chip->rirb.res[addr]; /* the last value */ | 608 | if (res) |
609 | *res = bus->rirb.res[addr]; /* the last value */ | ||
610 | spin_unlock_irq(&bus->reg_lock); | ||
611 | return 0; | ||
1183 | } | 612 | } |
613 | spin_unlock_irq(&bus->reg_lock); | ||
1184 | if (time_after(jiffies, timeout)) | 614 | if (time_after(jiffies, timeout)) |
1185 | break; | 615 | break; |
1186 | if (bus->needs_damn_long_delay || loopcounter > 3000) | 616 | if (hbus->needs_damn_long_delay || loopcounter > 3000) |
1187 | msleep(2); /* temporary workaround */ | 617 | msleep(2); /* temporary workaround */ |
1188 | else { | 618 | else { |
1189 | udelay(10); | 619 | udelay(10); |
@@ -1191,13 +621,13 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus, | |||
1191 | } | 621 | } |
1192 | } | 622 | } |
1193 | 623 | ||
1194 | if (bus->no_response_fallback) | 624 | if (hbus->no_response_fallback) |
1195 | return -1; | 625 | return -EIO; |
1196 | 626 | ||
1197 | if (!chip->polling_mode && chip->poll_count < 2) { | 627 | if (!chip->polling_mode && chip->poll_count < 2) { |
1198 | dev_dbg(chip->card->dev, | 628 | dev_dbg(chip->card->dev, |
1199 | "azx_get_response timeout, polling the codec once: last cmd=0x%08x\n", | 629 | "azx_get_response timeout, polling the codec once: last cmd=0x%08x\n", |
1200 | chip->last_cmd[addr]); | 630 | bus->last_cmd[addr]); |
1201 | do_poll = 1; | 631 | do_poll = 1; |
1202 | chip->poll_count++; | 632 | chip->poll_count++; |
1203 | goto again; | 633 | goto again; |
@@ -1207,7 +637,7 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus, | |||
1207 | if (!chip->polling_mode) { | 637 | if (!chip->polling_mode) { |
1208 | dev_warn(chip->card->dev, | 638 | dev_warn(chip->card->dev, |
1209 | "azx_get_response timeout, switching to polling mode: last cmd=0x%08x\n", | 639 | "azx_get_response timeout, switching to polling mode: last cmd=0x%08x\n", |
1210 | chip->last_cmd[addr]); | 640 | bus->last_cmd[addr]); |
1211 | chip->polling_mode = 1; | 641 | chip->polling_mode = 1; |
1212 | goto again; | 642 | goto again; |
1213 | } | 643 | } |
@@ -1215,12 +645,10 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus, | |||
1215 | if (chip->msi) { | 645 | if (chip->msi) { |
1216 | dev_warn(chip->card->dev, | 646 | dev_warn(chip->card->dev, |
1217 | "No response from codec, disabling MSI: last cmd=0x%08x\n", | 647 | "No response from codec, disabling MSI: last cmd=0x%08x\n", |
1218 | chip->last_cmd[addr]); | 648 | bus->last_cmd[addr]); |
1219 | if (chip->ops->disable_msi_reset_irq(chip) && | 649 | if (chip->ops->disable_msi_reset_irq && |
1220 | chip->ops->disable_msi_reset_irq(chip) < 0) { | 650 | chip->ops->disable_msi_reset_irq(chip) < 0) |
1221 | bus->rirb_error = 1; | 651 | return -EIO; |
1222 | return -1; | ||
1223 | } | ||
1224 | goto again; | 652 | goto again; |
1225 | } | 653 | } |
1226 | 654 | ||
@@ -1229,28 +657,24 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus, | |||
1229 | * phase, this is likely an access to a non-existing codec | 657 | * phase, this is likely an access to a non-existing codec |
1230 | * slot. Better to return an error and reset the system. | 658 | * slot. Better to return an error and reset the system. |
1231 | */ | 659 | */ |
1232 | return -1; | 660 | return -EIO; |
1233 | } | 661 | } |
1234 | 662 | ||
1235 | /* a fatal communication error; need either to reset or to fallback | 663 | /* a fatal communication error; need either to reset or to fallback |
1236 | * to the single_cmd mode | 664 | * to the single_cmd mode |
1237 | */ | 665 | */ |
1238 | bus->rirb_error = 1; | 666 | if (hbus->allow_bus_reset && !hbus->response_reset && !hbus->in_reset) { |
1239 | if (bus->allow_bus_reset && !bus->response_reset && !bus->in_reset) { | 667 | hbus->response_reset = 1; |
1240 | bus->response_reset = 1; | 668 | return -EAGAIN; /* give a chance to retry */ |
1241 | return -1; /* give a chance to retry */ | ||
1242 | } | 669 | } |
1243 | 670 | ||
1244 | dev_err(chip->card->dev, | 671 | dev_err(chip->card->dev, |
1245 | "azx_get_response timeout, switching to single_cmd mode: last cmd=0x%08x\n", | 672 | "azx_get_response timeout, switching to single_cmd mode: last cmd=0x%08x\n", |
1246 | chip->last_cmd[addr]); | 673 | bus->last_cmd[addr]); |
1247 | chip->single_cmd = 1; | 674 | chip->single_cmd = 1; |
1248 | bus->response_reset = 0; | 675 | hbus->response_reset = 0; |
1249 | /* release CORB/RIRB */ | 676 | snd_hdac_bus_stop_cmd_io(bus); |
1250 | azx_free_cmd_io(chip); | 677 | return -EIO; |
1251 | /* disable unsolicited responses */ | ||
1252 | azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~AZX_GCTL_UNSOL); | ||
1253 | return -1; | ||
1254 | } | 678 | } |
1255 | 679 | ||
1256 | /* | 680 | /* |
@@ -1272,7 +696,7 @@ static int azx_single_wait_for_response(struct azx *chip, unsigned int addr) | |||
1272 | /* check IRV busy bit */ | 696 | /* check IRV busy bit */ |
1273 | if (azx_readw(chip, IRS) & AZX_IRS_VALID) { | 697 | if (azx_readw(chip, IRS) & AZX_IRS_VALID) { |
1274 | /* reuse rirb.res as the response return value */ | 698 | /* reuse rirb.res as the response return value */ |
1275 | chip->rirb.res[addr] = azx_readl(chip, IR); | 699 | azx_bus(chip)->rirb.res[addr] = azx_readl(chip, IR); |
1276 | return 0; | 700 | return 0; |
1277 | } | 701 | } |
1278 | udelay(1); | 702 | udelay(1); |
@@ -1280,18 +704,18 @@ static int azx_single_wait_for_response(struct azx *chip, unsigned int addr) | |||
1280 | if (printk_ratelimit()) | 704 | if (printk_ratelimit()) |
1281 | dev_dbg(chip->card->dev, "get_response timeout: IRS=0x%x\n", | 705 | dev_dbg(chip->card->dev, "get_response timeout: IRS=0x%x\n", |
1282 | azx_readw(chip, IRS)); | 706 | azx_readw(chip, IRS)); |
1283 | chip->rirb.res[addr] = -1; | 707 | azx_bus(chip)->rirb.res[addr] = -1; |
1284 | return -EIO; | 708 | return -EIO; |
1285 | } | 709 | } |
1286 | 710 | ||
1287 | /* send a command */ | 711 | /* send a command */ |
1288 | static int azx_single_send_cmd(struct hda_bus *bus, u32 val) | 712 | static int azx_single_send_cmd(struct hdac_bus *bus, u32 val) |
1289 | { | 713 | { |
1290 | struct azx *chip = bus->private_data; | 714 | struct azx *chip = bus_to_azx(bus); |
1291 | unsigned int addr = azx_command_addr(val); | 715 | unsigned int addr = azx_command_addr(val); |
1292 | int timeout = 50; | 716 | int timeout = 50; |
1293 | 717 | ||
1294 | bus->rirb_error = 0; | 718 | bus->last_cmd[azx_command_addr(val)] = val; |
1295 | while (timeout--) { | 719 | while (timeout--) { |
1296 | /* check ICB busy bit */ | 720 | /* check ICB busy bit */ |
1297 | if (!((azx_readw(chip, IRS) & AZX_IRS_BUSY))) { | 721 | if (!((azx_readw(chip, IRS) & AZX_IRS_BUSY))) { |
@@ -1313,11 +737,12 @@ static int azx_single_send_cmd(struct hda_bus *bus, u32 val) | |||
1313 | } | 737 | } |
1314 | 738 | ||
1315 | /* receive a response */ | 739 | /* receive a response */ |
1316 | static unsigned int azx_single_get_response(struct hda_bus *bus, | 740 | static int azx_single_get_response(struct hdac_bus *bus, unsigned int addr, |
1317 | unsigned int addr) | 741 | unsigned int *res) |
1318 | { | 742 | { |
1319 | struct azx *chip = bus->private_data; | 743 | if (res) |
1320 | return chip->rirb.res[addr]; | 744 | *res = bus->rirb.res[addr]; |
745 | return 0; | ||
1321 | } | 746 | } |
1322 | 747 | ||
1323 | /* | 748 | /* |
@@ -1328,32 +753,48 @@ static unsigned int azx_single_get_response(struct hda_bus *bus, | |||
1328 | */ | 753 | */ |
1329 | 754 | ||
1330 | /* send a command */ | 755 | /* send a command */ |
1331 | static int azx_send_cmd(struct hda_bus *bus, unsigned int val) | 756 | static int azx_send_cmd(struct hdac_bus *bus, unsigned int val) |
1332 | { | 757 | { |
1333 | struct azx *chip = bus->private_data; | 758 | struct azx *chip = bus_to_azx(bus); |
1334 | 759 | ||
1335 | if (chip->disabled) | 760 | if (chip->disabled) |
1336 | return 0; | 761 | return 0; |
1337 | chip->last_cmd[azx_command_addr(val)] = val; | ||
1338 | if (chip->single_cmd) | 762 | if (chip->single_cmd) |
1339 | return azx_single_send_cmd(bus, val); | 763 | return azx_single_send_cmd(bus, val); |
1340 | else | 764 | else |
1341 | return azx_corb_send_cmd(bus, val); | 765 | return snd_hdac_bus_send_cmd(bus, val); |
1342 | } | 766 | } |
1343 | 767 | ||
1344 | /* get a response */ | 768 | /* get a response */ |
1345 | static unsigned int azx_get_response(struct hda_bus *bus, | 769 | static int azx_get_response(struct hdac_bus *bus, unsigned int addr, |
1346 | unsigned int addr) | 770 | unsigned int *res) |
1347 | { | 771 | { |
1348 | struct azx *chip = bus->private_data; | 772 | struct azx *chip = bus_to_azx(bus); |
773 | |||
1349 | if (chip->disabled) | 774 | if (chip->disabled) |
1350 | return 0; | 775 | return 0; |
1351 | if (chip->single_cmd) | 776 | if (chip->single_cmd) |
1352 | return azx_single_get_response(bus, addr); | 777 | return azx_single_get_response(bus, addr, res); |
778 | else | ||
779 | return azx_rirb_get_response(bus, addr, res); | ||
780 | } | ||
781 | |||
782 | static int azx_link_power(struct hdac_bus *bus, bool enable) | ||
783 | { | ||
784 | struct azx *chip = bus_to_azx(bus); | ||
785 | |||
786 | if (chip->ops->link_power) | ||
787 | return chip->ops->link_power(chip, enable); | ||
1353 | else | 788 | else |
1354 | return azx_rirb_get_response(bus, addr); | 789 | return -EINVAL; |
1355 | } | 790 | } |
1356 | 791 | ||
792 | static const struct hdac_bus_ops bus_core_ops = { | ||
793 | .command = azx_send_cmd, | ||
794 | .get_response = azx_get_response, | ||
795 | .link_power = azx_link_power, | ||
796 | }; | ||
797 | |||
1357 | #ifdef CONFIG_SND_HDA_DSP_LOADER | 798 | #ifdef CONFIG_SND_HDA_DSP_LOADER |
1358 | /* | 799 | /* |
1359 | * DSP loading code (e.g. for CA0132) | 800 | * DSP loading code (e.g. for CA0132) |
@@ -1363,339 +804,132 @@ static unsigned int azx_get_response(struct hda_bus *bus, | |||
1363 | static struct azx_dev * | 804 | static struct azx_dev * |
1364 | azx_get_dsp_loader_dev(struct azx *chip) | 805 | azx_get_dsp_loader_dev(struct azx *chip) |
1365 | { | 806 | { |
1366 | return &chip->azx_dev[chip->playback_index_offset]; | 807 | struct hdac_bus *bus = azx_bus(chip); |
808 | struct hdac_stream *s; | ||
809 | |||
810 | list_for_each_entry(s, &bus->stream_list, list) | ||
811 | if (s->index == chip->playback_index_offset) | ||
812 | return stream_to_azx_dev(s); | ||
813 | |||
814 | return NULL; | ||
1367 | } | 815 | } |
1368 | 816 | ||
1369 | static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format, | 817 | int snd_hda_codec_load_dsp_prepare(struct hda_codec *codec, unsigned int format, |
1370 | unsigned int byte_size, | 818 | unsigned int byte_size, |
1371 | struct snd_dma_buffer *bufp) | 819 | struct snd_dma_buffer *bufp) |
1372 | { | 820 | { |
1373 | u32 *bdl; | 821 | struct hdac_bus *bus = &codec->bus->core; |
1374 | struct azx *chip = bus->private_data; | 822 | struct azx *chip = bus_to_azx(bus); |
1375 | struct azx_dev *azx_dev; | 823 | struct azx_dev *azx_dev; |
824 | struct hdac_stream *hstr; | ||
825 | bool saved = false; | ||
1376 | int err; | 826 | int err; |
1377 | 827 | ||
1378 | azx_dev = azx_get_dsp_loader_dev(chip); | 828 | azx_dev = azx_get_dsp_loader_dev(chip); |
1379 | 829 | hstr = azx_stream(azx_dev); | |
1380 | dsp_lock(azx_dev); | 830 | spin_lock_irq(&bus->reg_lock); |
1381 | spin_lock_irq(&chip->reg_lock); | 831 | if (hstr->opened) { |
1382 | if (azx_dev->running || azx_dev->locked) { | 832 | chip->saved_azx_dev = *azx_dev; |
1383 | spin_unlock_irq(&chip->reg_lock); | 833 | saved = true; |
1384 | err = -EBUSY; | ||
1385 | goto unlock; | ||
1386 | } | 834 | } |
1387 | azx_dev->prepared = 0; | 835 | spin_unlock_irq(&bus->reg_lock); |
1388 | chip->saved_azx_dev = *azx_dev; | ||
1389 | azx_dev->locked = 1; | ||
1390 | spin_unlock_irq(&chip->reg_lock); | ||
1391 | |||
1392 | err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV_SG, | ||
1393 | byte_size, bufp); | ||
1394 | if (err < 0) | ||
1395 | goto err_alloc; | ||
1396 | 836 | ||
1397 | azx_dev->bufsize = byte_size; | 837 | err = snd_hdac_dsp_prepare(hstr, format, byte_size, bufp); |
1398 | azx_dev->period_bytes = byte_size; | 838 | if (err < 0) { |
1399 | azx_dev->format_val = format; | 839 | spin_lock_irq(&bus->reg_lock); |
1400 | 840 | if (saved) | |
1401 | azx_stream_reset(chip, azx_dev); | 841 | *azx_dev = chip->saved_azx_dev; |
1402 | 842 | spin_unlock_irq(&bus->reg_lock); | |
1403 | /* reset BDL address */ | 843 | return err; |
1404 | azx_sd_writel(chip, azx_dev, SD_BDLPL, 0); | 844 | } |
1405 | azx_sd_writel(chip, azx_dev, SD_BDLPU, 0); | ||
1406 | |||
1407 | azx_dev->frags = 0; | ||
1408 | bdl = (u32 *)azx_dev->bdl.area; | ||
1409 | err = setup_bdle(chip, bufp, azx_dev, &bdl, 0, byte_size, 0); | ||
1410 | if (err < 0) | ||
1411 | goto error; | ||
1412 | |||
1413 | azx_setup_controller(chip, azx_dev); | ||
1414 | dsp_unlock(azx_dev); | ||
1415 | return azx_dev->stream_tag; | ||
1416 | 845 | ||
1417 | error: | 846 | hstr->prepared = 0; |
1418 | chip->ops->dma_free_pages(chip, bufp); | ||
1419 | err_alloc: | ||
1420 | spin_lock_irq(&chip->reg_lock); | ||
1421 | if (azx_dev->opened) | ||
1422 | *azx_dev = chip->saved_azx_dev; | ||
1423 | azx_dev->locked = 0; | ||
1424 | spin_unlock_irq(&chip->reg_lock); | ||
1425 | unlock: | ||
1426 | dsp_unlock(azx_dev); | ||
1427 | return err; | 847 | return err; |
1428 | } | 848 | } |
849 | EXPORT_SYMBOL_GPL(snd_hda_codec_load_dsp_prepare); | ||
1429 | 850 | ||
1430 | static void azx_load_dsp_trigger(struct hda_bus *bus, bool start) | 851 | void snd_hda_codec_load_dsp_trigger(struct hda_codec *codec, bool start) |
1431 | { | 852 | { |
1432 | struct azx *chip = bus->private_data; | 853 | struct hdac_bus *bus = &codec->bus->core; |
854 | struct azx *chip = bus_to_azx(bus); | ||
1433 | struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip); | 855 | struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip); |
1434 | 856 | ||
1435 | if (start) | 857 | snd_hdac_dsp_trigger(azx_stream(azx_dev), start); |
1436 | azx_stream_start(chip, azx_dev); | ||
1437 | else | ||
1438 | azx_stream_stop(chip, azx_dev); | ||
1439 | azx_dev->running = start; | ||
1440 | } | 858 | } |
859 | EXPORT_SYMBOL_GPL(snd_hda_codec_load_dsp_trigger); | ||
1441 | 860 | ||
1442 | static void azx_load_dsp_cleanup(struct hda_bus *bus, | 861 | void snd_hda_codec_load_dsp_cleanup(struct hda_codec *codec, |
1443 | struct snd_dma_buffer *dmab) | 862 | struct snd_dma_buffer *dmab) |
1444 | { | 863 | { |
1445 | struct azx *chip = bus->private_data; | 864 | struct hdac_bus *bus = &codec->bus->core; |
865 | struct azx *chip = bus_to_azx(bus); | ||
1446 | struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip); | 866 | struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip); |
867 | struct hdac_stream *hstr = azx_stream(azx_dev); | ||
1447 | 868 | ||
1448 | if (!dmab->area || !azx_dev->locked) | 869 | if (!dmab->area || !hstr->locked) |
1449 | return; | 870 | return; |
1450 | 871 | ||
1451 | dsp_lock(azx_dev); | 872 | snd_hdac_dsp_cleanup(hstr, dmab); |
1452 | /* reset BDL address */ | 873 | spin_lock_irq(&bus->reg_lock); |
1453 | azx_sd_writel(chip, azx_dev, SD_BDLPL, 0); | 874 | if (hstr->opened) |
1454 | azx_sd_writel(chip, azx_dev, SD_BDLPU, 0); | ||
1455 | azx_sd_writel(chip, azx_dev, SD_CTL, 0); | ||
1456 | azx_dev->bufsize = 0; | ||
1457 | azx_dev->period_bytes = 0; | ||
1458 | azx_dev->format_val = 0; | ||
1459 | |||
1460 | chip->ops->dma_free_pages(chip, dmab); | ||
1461 | dmab->area = NULL; | ||
1462 | |||
1463 | spin_lock_irq(&chip->reg_lock); | ||
1464 | if (azx_dev->opened) | ||
1465 | *azx_dev = chip->saved_azx_dev; | 875 | *azx_dev = chip->saved_azx_dev; |
1466 | azx_dev->locked = 0; | 876 | hstr->locked = false; |
1467 | spin_unlock_irq(&chip->reg_lock); | 877 | spin_unlock_irq(&bus->reg_lock); |
1468 | dsp_unlock(azx_dev); | ||
1469 | } | 878 | } |
879 | EXPORT_SYMBOL_GPL(snd_hda_codec_load_dsp_cleanup); | ||
1470 | #endif /* CONFIG_SND_HDA_DSP_LOADER */ | 880 | #endif /* CONFIG_SND_HDA_DSP_LOADER */ |
1471 | 881 | ||
1472 | int azx_alloc_stream_pages(struct azx *chip) | ||
1473 | { | ||
1474 | int i, err; | ||
1475 | |||
1476 | for (i = 0; i < chip->num_streams; i++) { | ||
1477 | dsp_lock_init(&chip->azx_dev[i]); | ||
1478 | /* allocate memory for the BDL for each stream */ | ||
1479 | err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV, | ||
1480 | BDL_SIZE, | ||
1481 | &chip->azx_dev[i].bdl); | ||
1482 | if (err < 0) | ||
1483 | return -ENOMEM; | ||
1484 | } | ||
1485 | /* allocate memory for the position buffer */ | ||
1486 | err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV, | ||
1487 | chip->num_streams * 8, &chip->posbuf); | ||
1488 | if (err < 0) | ||
1489 | return -ENOMEM; | ||
1490 | |||
1491 | /* allocate CORB/RIRB */ | ||
1492 | err = azx_alloc_cmd_io(chip); | ||
1493 | if (err < 0) | ||
1494 | return err; | ||
1495 | return 0; | ||
1496 | } | ||
1497 | EXPORT_SYMBOL_GPL(azx_alloc_stream_pages); | ||
1498 | |||
1499 | void azx_free_stream_pages(struct azx *chip) | ||
1500 | { | ||
1501 | int i; | ||
1502 | if (chip->azx_dev) { | ||
1503 | for (i = 0; i < chip->num_streams; i++) | ||
1504 | if (chip->azx_dev[i].bdl.area) | ||
1505 | chip->ops->dma_free_pages( | ||
1506 | chip, &chip->azx_dev[i].bdl); | ||
1507 | } | ||
1508 | if (chip->rb.area) | ||
1509 | chip->ops->dma_free_pages(chip, &chip->rb); | ||
1510 | if (chip->posbuf.area) | ||
1511 | chip->ops->dma_free_pages(chip, &chip->posbuf); | ||
1512 | } | ||
1513 | EXPORT_SYMBOL_GPL(azx_free_stream_pages); | ||
1514 | |||
1515 | /* | 882 | /* |
1516 | * Lowlevel interface | 883 | * reset and start the controller registers |
1517 | */ | 884 | */ |
1518 | 885 | void azx_init_chip(struct azx *chip, bool full_reset) | |
1519 | /* enter link reset */ | ||
1520 | void azx_enter_link_reset(struct azx *chip) | ||
1521 | { | ||
1522 | unsigned long timeout; | ||
1523 | |||
1524 | /* reset controller */ | ||
1525 | azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~AZX_GCTL_RESET); | ||
1526 | |||
1527 | timeout = jiffies + msecs_to_jiffies(100); | ||
1528 | while ((azx_readb(chip, GCTL) & AZX_GCTL_RESET) && | ||
1529 | time_before(jiffies, timeout)) | ||
1530 | usleep_range(500, 1000); | ||
1531 | } | ||
1532 | EXPORT_SYMBOL_GPL(azx_enter_link_reset); | ||
1533 | |||
1534 | /* exit link reset */ | ||
1535 | static void azx_exit_link_reset(struct azx *chip) | ||
1536 | { | ||
1537 | unsigned long timeout; | ||
1538 | |||
1539 | azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | AZX_GCTL_RESET); | ||
1540 | |||
1541 | timeout = jiffies + msecs_to_jiffies(100); | ||
1542 | while (!azx_readb(chip, GCTL) && | ||
1543 | time_before(jiffies, timeout)) | ||
1544 | usleep_range(500, 1000); | ||
1545 | } | ||
1546 | |||
1547 | /* reset codec link */ | ||
1548 | static int azx_reset(struct azx *chip, bool full_reset) | ||
1549 | { | ||
1550 | if (!full_reset) | ||
1551 | goto __skip; | ||
1552 | |||
1553 | /* clear STATESTS */ | ||
1554 | azx_writew(chip, STATESTS, STATESTS_INT_MASK); | ||
1555 | |||
1556 | /* reset controller */ | ||
1557 | azx_enter_link_reset(chip); | ||
1558 | |||
1559 | /* delay for >= 100us for codec PLL to settle per spec | ||
1560 | * Rev 0.9 section 5.5.1 | ||
1561 | */ | ||
1562 | usleep_range(500, 1000); | ||
1563 | |||
1564 | /* Bring controller out of reset */ | ||
1565 | azx_exit_link_reset(chip); | ||
1566 | |||
1567 | /* Brent Chartrand said to wait >= 540us for codecs to initialize */ | ||
1568 | usleep_range(1000, 1200); | ||
1569 | |||
1570 | __skip: | ||
1571 | /* check to see if controller is ready */ | ||
1572 | if (!azx_readb(chip, GCTL)) { | ||
1573 | dev_dbg(chip->card->dev, "azx_reset: controller not ready!\n"); | ||
1574 | return -EBUSY; | ||
1575 | } | ||
1576 | |||
1577 | /* Accept unsolicited responses */ | ||
1578 | if (!chip->single_cmd) | ||
1579 | azx_writel(chip, GCTL, azx_readl(chip, GCTL) | | ||
1580 | AZX_GCTL_UNSOL); | ||
1581 | |||
1582 | /* detect codecs */ | ||
1583 | if (!chip->codec_mask) { | ||
1584 | chip->codec_mask = azx_readw(chip, STATESTS); | ||
1585 | dev_dbg(chip->card->dev, "codec_mask = 0x%x\n", | ||
1586 | chip->codec_mask); | ||
1587 | } | ||
1588 | |||
1589 | return 0; | ||
1590 | } | ||
1591 | |||
1592 | /* enable interrupts */ | ||
1593 | static void azx_int_enable(struct azx *chip) | ||
1594 | { | ||
1595 | /* enable controller CIE and GIE */ | ||
1596 | azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) | | ||
1597 | AZX_INT_CTRL_EN | AZX_INT_GLOBAL_EN); | ||
1598 | } | ||
1599 | |||
1600 | /* disable interrupts */ | ||
1601 | static void azx_int_disable(struct azx *chip) | ||
1602 | { | ||
1603 | int i; | ||
1604 | |||
1605 | /* disable interrupts in stream descriptor */ | ||
1606 | for (i = 0; i < chip->num_streams; i++) { | ||
1607 | struct azx_dev *azx_dev = &chip->azx_dev[i]; | ||
1608 | azx_sd_writeb(chip, azx_dev, SD_CTL, | ||
1609 | azx_sd_readb(chip, azx_dev, SD_CTL) & | ||
1610 | ~SD_INT_MASK); | ||
1611 | } | ||
1612 | |||
1613 | /* disable SIE for all streams */ | ||
1614 | azx_writeb(chip, INTCTL, 0); | ||
1615 | |||
1616 | /* disable controller CIE and GIE */ | ||
1617 | azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) & | ||
1618 | ~(AZX_INT_CTRL_EN | AZX_INT_GLOBAL_EN)); | ||
1619 | } | ||
1620 | |||
1621 | /* clear interrupts */ | ||
1622 | static void azx_int_clear(struct azx *chip) | ||
1623 | { | 886 | { |
1624 | int i; | 887 | if (snd_hdac_bus_init_chip(azx_bus(chip), full_reset)) { |
1625 | 888 | /* correct RINTCNT for CXT */ | |
1626 | /* clear stream status */ | 889 | if (chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) |
1627 | for (i = 0; i < chip->num_streams; i++) { | 890 | azx_writew(chip, RINTCNT, 0xc0); |
1628 | struct azx_dev *azx_dev = &chip->azx_dev[i]; | ||
1629 | azx_sd_writeb(chip, azx_dev, SD_STS, SD_INT_MASK); | ||
1630 | } | 891 | } |
1631 | |||
1632 | /* clear STATESTS */ | ||
1633 | azx_writew(chip, STATESTS, STATESTS_INT_MASK); | ||
1634 | |||
1635 | /* clear rirb status */ | ||
1636 | azx_writeb(chip, RIRBSTS, RIRB_INT_MASK); | ||
1637 | |||
1638 | /* clear int status */ | ||
1639 | azx_writel(chip, INTSTS, AZX_INT_CTRL_EN | AZX_INT_ALL_STREAM); | ||
1640 | } | 892 | } |
893 | EXPORT_SYMBOL_GPL(azx_init_chip); | ||
1641 | 894 | ||
1642 | /* | 895 | void azx_stop_all_streams(struct azx *chip) |
1643 | * reset and start the controller registers | ||
1644 | */ | ||
1645 | void azx_init_chip(struct azx *chip, bool full_reset) | ||
1646 | { | 896 | { |
1647 | if (chip->initialized) | 897 | struct hdac_bus *bus = azx_bus(chip); |
1648 | return; | 898 | struct hdac_stream *s; |
1649 | |||
1650 | /* reset controller */ | ||
1651 | azx_reset(chip, full_reset); | ||
1652 | |||
1653 | /* initialize interrupts */ | ||
1654 | azx_int_clear(chip); | ||
1655 | azx_int_enable(chip); | ||
1656 | |||
1657 | /* initialize the codec command I/O */ | ||
1658 | if (!chip->single_cmd) | ||
1659 | azx_init_cmd_io(chip); | ||
1660 | |||
1661 | /* program the position buffer */ | ||
1662 | azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr); | ||
1663 | azx_writel(chip, DPUBASE, upper_32_bits(chip->posbuf.addr)); | ||
1664 | 899 | ||
1665 | chip->initialized = 1; | 900 | list_for_each_entry(s, &bus->stream_list, list) |
901 | snd_hdac_stream_stop(s); | ||
1666 | } | 902 | } |
1667 | EXPORT_SYMBOL_GPL(azx_init_chip); | 903 | EXPORT_SYMBOL_GPL(azx_stop_all_streams); |
1668 | 904 | ||
1669 | void azx_stop_chip(struct azx *chip) | 905 | void azx_stop_chip(struct azx *chip) |
1670 | { | 906 | { |
1671 | if (!chip->initialized) | 907 | snd_hdac_bus_stop_chip(azx_bus(chip)); |
1672 | return; | ||
1673 | |||
1674 | /* disable interrupts */ | ||
1675 | azx_int_disable(chip); | ||
1676 | azx_int_clear(chip); | ||
1677 | |||
1678 | /* disable CORB/RIRB */ | ||
1679 | azx_free_cmd_io(chip); | ||
1680 | |||
1681 | /* disable position buffer */ | ||
1682 | azx_writel(chip, DPLBASE, 0); | ||
1683 | azx_writel(chip, DPUBASE, 0); | ||
1684 | |||
1685 | chip->initialized = 0; | ||
1686 | } | 908 | } |
1687 | EXPORT_SYMBOL_GPL(azx_stop_chip); | 909 | EXPORT_SYMBOL_GPL(azx_stop_chip); |
1688 | 910 | ||
1689 | /* | 911 | /* |
1690 | * interrupt handler | 912 | * interrupt handler |
1691 | */ | 913 | */ |
914 | static void stream_update(struct hdac_bus *bus, struct hdac_stream *s) | ||
915 | { | ||
916 | struct azx *chip = bus_to_azx(bus); | ||
917 | struct azx_dev *azx_dev = stream_to_azx_dev(s); | ||
918 | |||
919 | /* check whether this IRQ is really acceptable */ | ||
920 | if (!chip->ops->position_check || | ||
921 | chip->ops->position_check(chip, azx_dev)) { | ||
922 | spin_unlock(&bus->reg_lock); | ||
923 | snd_pcm_period_elapsed(azx_stream(azx_dev)->substream); | ||
924 | spin_lock(&bus->reg_lock); | ||
925 | } | ||
926 | } | ||
927 | |||
1692 | irqreturn_t azx_interrupt(int irq, void *dev_id) | 928 | irqreturn_t azx_interrupt(int irq, void *dev_id) |
1693 | { | 929 | { |
1694 | struct azx *chip = dev_id; | 930 | struct azx *chip = dev_id; |
1695 | struct azx_dev *azx_dev; | 931 | struct hdac_bus *bus = azx_bus(chip); |
1696 | u32 status; | 932 | u32 status; |
1697 | u8 sd_status; | ||
1698 | int i; | ||
1699 | 933 | ||
1700 | #ifdef CONFIG_PM | 934 | #ifdef CONFIG_PM |
1701 | if (azx_has_pm_runtime(chip)) | 935 | if (azx_has_pm_runtime(chip)) |
@@ -1703,36 +937,20 @@ irqreturn_t azx_interrupt(int irq, void *dev_id) | |||
1703 | return IRQ_NONE; | 937 | return IRQ_NONE; |
1704 | #endif | 938 | #endif |
1705 | 939 | ||
1706 | spin_lock(&chip->reg_lock); | 940 | spin_lock(&bus->reg_lock); |
1707 | 941 | ||
1708 | if (chip->disabled) { | 942 | if (chip->disabled) { |
1709 | spin_unlock(&chip->reg_lock); | 943 | spin_unlock(&bus->reg_lock); |
1710 | return IRQ_NONE; | 944 | return IRQ_NONE; |
1711 | } | 945 | } |
1712 | 946 | ||
1713 | status = azx_readl(chip, INTSTS); | 947 | status = azx_readl(chip, INTSTS); |
1714 | if (status == 0 || status == 0xffffffff) { | 948 | if (status == 0 || status == 0xffffffff) { |
1715 | spin_unlock(&chip->reg_lock); | 949 | spin_unlock(&bus->reg_lock); |
1716 | return IRQ_NONE; | 950 | return IRQ_NONE; |
1717 | } | 951 | } |
1718 | 952 | ||
1719 | for (i = 0; i < chip->num_streams; i++) { | 953 | snd_hdac_bus_handle_stream_irq(bus, status, stream_update); |
1720 | azx_dev = &chip->azx_dev[i]; | ||
1721 | if (status & azx_dev->sd_int_sta_mask) { | ||
1722 | sd_status = azx_sd_readb(chip, azx_dev, SD_STS); | ||
1723 | azx_sd_writeb(chip, azx_dev, SD_STS, SD_INT_MASK); | ||
1724 | if (!azx_dev->substream || !azx_dev->running || | ||
1725 | !(sd_status & SD_INT_COMPLETE)) | ||
1726 | continue; | ||
1727 | /* check whether this IRQ is really acceptable */ | ||
1728 | if (!chip->ops->position_check || | ||
1729 | chip->ops->position_check(chip, azx_dev)) { | ||
1730 | spin_unlock(&chip->reg_lock); | ||
1731 | snd_pcm_period_elapsed(azx_dev->substream); | ||
1732 | spin_lock(&chip->reg_lock); | ||
1733 | } | ||
1734 | } | ||
1735 | } | ||
1736 | 954 | ||
1737 | /* clear rirb int */ | 955 | /* clear rirb int */ |
1738 | status = azx_readb(chip, RIRBSTS); | 956 | status = azx_readb(chip, RIRBSTS); |
@@ -1740,12 +958,12 @@ irqreturn_t azx_interrupt(int irq, void *dev_id) | |||
1740 | if (status & RIRB_INT_RESPONSE) { | 958 | if (status & RIRB_INT_RESPONSE) { |
1741 | if (chip->driver_caps & AZX_DCAPS_RIRB_PRE_DELAY) | 959 | if (chip->driver_caps & AZX_DCAPS_RIRB_PRE_DELAY) |
1742 | udelay(80); | 960 | udelay(80); |
1743 | azx_update_rirb(chip); | 961 | snd_hdac_bus_update_rirb(bus); |
1744 | } | 962 | } |
1745 | azx_writeb(chip, RIRBSTS, RIRB_INT_MASK); | 963 | azx_writeb(chip, RIRBSTS, RIRB_INT_MASK); |
1746 | } | 964 | } |
1747 | 965 | ||
1748 | spin_unlock(&chip->reg_lock); | 966 | spin_unlock(&bus->reg_lock); |
1749 | 967 | ||
1750 | return IRQ_HANDLED; | 968 | return IRQ_HANDLED; |
1751 | } | 969 | } |
@@ -1762,29 +980,31 @@ static int probe_codec(struct azx *chip, int addr) | |||
1762 | { | 980 | { |
1763 | unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) | | 981 | unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) | |
1764 | (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID; | 982 | (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID; |
1765 | unsigned int res; | 983 | struct hdac_bus *bus = azx_bus(chip); |
984 | int err; | ||
985 | unsigned int res = -1; | ||
1766 | 986 | ||
1767 | mutex_lock(&chip->bus->core.cmd_mutex); | 987 | mutex_lock(&bus->cmd_mutex); |
1768 | chip->probing = 1; | 988 | chip->probing = 1; |
1769 | azx_send_cmd(chip->bus, cmd); | 989 | azx_send_cmd(bus, cmd); |
1770 | res = azx_get_response(chip->bus, addr); | 990 | err = azx_get_response(bus, addr, &res); |
1771 | chip->probing = 0; | 991 | chip->probing = 0; |
1772 | mutex_unlock(&chip->bus->core.cmd_mutex); | 992 | mutex_unlock(&bus->cmd_mutex); |
1773 | if (res == -1) | 993 | if (err < 0 || res == -1) |
1774 | return -EIO; | 994 | return -EIO; |
1775 | dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr); | 995 | dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr); |
1776 | return 0; | 996 | return 0; |
1777 | } | 997 | } |
1778 | 998 | ||
1779 | static void azx_bus_reset(struct hda_bus *bus) | 999 | void snd_hda_bus_reset(struct hda_bus *bus) |
1780 | { | 1000 | { |
1781 | struct azx *chip = bus->private_data; | 1001 | struct azx *chip = bus_to_azx(&bus->core); |
1782 | 1002 | ||
1783 | bus->in_reset = 1; | 1003 | bus->in_reset = 1; |
1784 | azx_stop_chip(chip); | 1004 | azx_stop_chip(chip); |
1785 | azx_init_chip(chip, true); | 1005 | azx_init_chip(chip, true); |
1786 | if (chip->initialized) | 1006 | if (bus->core.chip_init) |
1787 | snd_hda_bus_reset(chip->bus); | 1007 | snd_hda_bus_reset_codecs(bus); |
1788 | bus->in_reset = 0; | 1008 | bus->in_reset = 0; |
1789 | } | 1009 | } |
1790 | 1010 | ||
@@ -1809,33 +1029,30 @@ static int get_jackpoll_interval(struct azx *chip) | |||
1809 | return j; | 1029 | return j; |
1810 | } | 1030 | } |
1811 | 1031 | ||
1812 | static struct hda_bus_ops bus_ops = { | ||
1813 | .command = azx_send_cmd, | ||
1814 | .get_response = azx_get_response, | ||
1815 | .attach_pcm = azx_attach_pcm_stream, | ||
1816 | .bus_reset = azx_bus_reset, | ||
1817 | #ifdef CONFIG_SND_HDA_DSP_LOADER | ||
1818 | .load_dsp_prepare = azx_load_dsp_prepare, | ||
1819 | .load_dsp_trigger = azx_load_dsp_trigger, | ||
1820 | .load_dsp_cleanup = azx_load_dsp_cleanup, | ||
1821 | #endif | ||
1822 | }; | ||
1823 | |||
1824 | /* HD-audio bus initialization */ | 1032 | /* HD-audio bus initialization */ |
1825 | int azx_bus_create(struct azx *chip, const char *model) | 1033 | int azx_bus_init(struct azx *chip, const char *model, |
1034 | const struct hdac_io_ops *io_ops) | ||
1826 | { | 1035 | { |
1827 | struct hda_bus *bus; | 1036 | struct hda_bus *bus = &chip->bus; |
1828 | int err; | 1037 | int err; |
1829 | 1038 | ||
1830 | err = snd_hda_bus_new(chip->card, &bus); | 1039 | err = snd_hdac_bus_init(&bus->core, chip->card->dev, &bus_core_ops, |
1040 | io_ops); | ||
1831 | if (err < 0) | 1041 | if (err < 0) |
1832 | return err; | 1042 | return err; |
1833 | 1043 | ||
1834 | chip->bus = bus; | 1044 | bus->card = chip->card; |
1835 | bus->private_data = chip; | 1045 | mutex_init(&bus->prepare_mutex); |
1836 | bus->pci = chip->pci; | 1046 | bus->pci = chip->pci; |
1837 | bus->modelname = model; | 1047 | bus->modelname = model; |
1838 | bus->ops = bus_ops; | 1048 | bus->core.snoop = azx_snoop(chip); |
1049 | if (chip->get_position[0] != azx_get_pos_lpib || | ||
1050 | chip->get_position[1] != azx_get_pos_lpib) | ||
1051 | bus->core.use_posbuf = true; | ||
1052 | if (chip->bdl_pos_adj) | ||
1053 | bus->core.bdl_pos_adj = chip->bdl_pos_adj[chip->dev_index]; | ||
1054 | if (chip->driver_caps & AZX_DCAPS_CORBRP_SELF_CLEAR) | ||
1055 | bus->core.corbrp_self_clear = true; | ||
1839 | 1056 | ||
1840 | if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) { | 1057 | if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) { |
1841 | dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n"); | 1058 | dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n"); |
@@ -1854,12 +1071,12 @@ int azx_bus_create(struct azx *chip, const char *model) | |||
1854 | 1071 | ||
1855 | return 0; | 1072 | return 0; |
1856 | } | 1073 | } |
1857 | EXPORT_SYMBOL_GPL(azx_bus_create); | 1074 | EXPORT_SYMBOL_GPL(azx_bus_init); |
1858 | 1075 | ||
1859 | /* Probe codecs */ | 1076 | /* Probe codecs */ |
1860 | int azx_probe_codecs(struct azx *chip, unsigned int max_slots) | 1077 | int azx_probe_codecs(struct azx *chip, unsigned int max_slots) |
1861 | { | 1078 | { |
1862 | struct hda_bus *bus = chip->bus; | 1079 | struct hdac_bus *bus = azx_bus(chip); |
1863 | int c, codecs, err; | 1080 | int c, codecs, err; |
1864 | 1081 | ||
1865 | codecs = 0; | 1082 | codecs = 0; |
@@ -1868,14 +1085,14 @@ int azx_probe_codecs(struct azx *chip, unsigned int max_slots) | |||
1868 | 1085 | ||
1869 | /* First try to probe all given codec slots */ | 1086 | /* First try to probe all given codec slots */ |
1870 | for (c = 0; c < max_slots; c++) { | 1087 | for (c = 0; c < max_slots; c++) { |
1871 | if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { | 1088 | if ((bus->codec_mask & (1 << c)) & chip->codec_probe_mask) { |
1872 | if (probe_codec(chip, c) < 0) { | 1089 | if (probe_codec(chip, c) < 0) { |
1873 | /* Some BIOSen give you wrong codec addresses | 1090 | /* Some BIOSen give you wrong codec addresses |
1874 | * that don't exist | 1091 | * that don't exist |
1875 | */ | 1092 | */ |
1876 | dev_warn(chip->card->dev, | 1093 | dev_warn(chip->card->dev, |
1877 | "Codec #%d probe error; disabling it...\n", c); | 1094 | "Codec #%d probe error; disabling it...\n", c); |
1878 | chip->codec_mask &= ~(1 << c); | 1095 | bus->codec_mask &= ~(1 << c); |
1879 | /* More badly, accessing to a non-existing | 1096 | /* More badly, accessing to a non-existing |
1880 | * codec often screws up the controller chip, | 1097 | * codec often screws up the controller chip, |
1881 | * and disturbs the further communications. | 1098 | * and disturbs the further communications. |
@@ -1891,9 +1108,9 @@ int azx_probe_codecs(struct azx *chip, unsigned int max_slots) | |||
1891 | 1108 | ||
1892 | /* Then create codec instances */ | 1109 | /* Then create codec instances */ |
1893 | for (c = 0; c < max_slots; c++) { | 1110 | for (c = 0; c < max_slots; c++) { |
1894 | if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { | 1111 | if ((bus->codec_mask & (1 << c)) & chip->codec_probe_mask) { |
1895 | struct hda_codec *codec; | 1112 | struct hda_codec *codec; |
1896 | err = snd_hda_codec_new(bus, bus->card, c, &codec); | 1113 | err = snd_hda_codec_new(&chip->bus, chip->card, c, &codec); |
1897 | if (err < 0) | 1114 | if (err < 0) |
1898 | continue; | 1115 | continue; |
1899 | codec->jackpoll_interval = get_jackpoll_interval(chip); | 1116 | codec->jackpoll_interval = get_jackpoll_interval(chip); |
@@ -1913,40 +1130,39 @@ EXPORT_SYMBOL_GPL(azx_probe_codecs); | |||
1913 | int azx_codec_configure(struct azx *chip) | 1130 | int azx_codec_configure(struct azx *chip) |
1914 | { | 1131 | { |
1915 | struct hda_codec *codec; | 1132 | struct hda_codec *codec; |
1916 | list_for_each_codec(codec, chip->bus) { | 1133 | list_for_each_codec(codec, &chip->bus) { |
1917 | snd_hda_codec_configure(codec); | 1134 | snd_hda_codec_configure(codec); |
1918 | } | 1135 | } |
1919 | return 0; | 1136 | return 0; |
1920 | } | 1137 | } |
1921 | EXPORT_SYMBOL_GPL(azx_codec_configure); | 1138 | EXPORT_SYMBOL_GPL(azx_codec_configure); |
1922 | 1139 | ||
1923 | 1140 | static int stream_direction(struct azx *chip, unsigned char index) | |
1924 | static bool is_input_stream(struct azx *chip, unsigned char index) | ||
1925 | { | 1141 | { |
1926 | return (index >= chip->capture_index_offset && | 1142 | if (index >= chip->capture_index_offset && |
1927 | index < chip->capture_index_offset + chip->capture_streams); | 1143 | index < chip->capture_index_offset + chip->capture_streams) |
1144 | return SNDRV_PCM_STREAM_CAPTURE; | ||
1145 | return SNDRV_PCM_STREAM_PLAYBACK; | ||
1928 | } | 1146 | } |
1929 | 1147 | ||
1930 | /* initialize SD streams */ | 1148 | /* initialize SD streams */ |
1931 | int azx_init_stream(struct azx *chip) | 1149 | int azx_init_streams(struct azx *chip) |
1932 | { | 1150 | { |
1933 | int i; | 1151 | int i; |
1934 | int in_stream_tag = 0; | 1152 | int stream_tags[2] = { 0, 0 }; |
1935 | int out_stream_tag = 0; | ||
1936 | 1153 | ||
1937 | /* initialize each stream (aka device) | 1154 | /* initialize each stream (aka device) |
1938 | * assign the starting bdl address to each stream (device) | 1155 | * assign the starting bdl address to each stream (device) |
1939 | * and initialize | 1156 | * and initialize |
1940 | */ | 1157 | */ |
1941 | for (i = 0; i < chip->num_streams; i++) { | 1158 | for (i = 0; i < chip->num_streams; i++) { |
1942 | struct azx_dev *azx_dev = &chip->azx_dev[i]; | 1159 | struct azx_dev *azx_dev = kzalloc(sizeof(*azx_dev), GFP_KERNEL); |
1943 | azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8); | 1160 | int dir, tag; |
1944 | /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ | 1161 | |
1945 | azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80); | 1162 | if (!azx_dev) |
1946 | /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */ | 1163 | return -ENOMEM; |
1947 | azx_dev->sd_int_sta_mask = 1 << i; | ||
1948 | azx_dev->index = i; | ||
1949 | 1164 | ||
1165 | dir = stream_direction(chip, i); | ||
1950 | /* stream tag must be unique throughout | 1166 | /* stream tag must be unique throughout |
1951 | * the stream direction group, | 1167 | * the stream direction group, |
1952 | * valid values 1...15 | 1168 | * valid values 1...15 |
@@ -1954,17 +1170,26 @@ int azx_init_stream(struct azx *chip) | |||
1954 | * AZX_DCAPS_SEPARATE_STREAM_TAG is used | 1170 | * AZX_DCAPS_SEPARATE_STREAM_TAG is used |
1955 | */ | 1171 | */ |
1956 | if (chip->driver_caps & AZX_DCAPS_SEPARATE_STREAM_TAG) | 1172 | if (chip->driver_caps & AZX_DCAPS_SEPARATE_STREAM_TAG) |
1957 | azx_dev->stream_tag = | 1173 | tag = ++stream_tags[dir]; |
1958 | is_input_stream(chip, i) ? | ||
1959 | ++in_stream_tag : | ||
1960 | ++out_stream_tag; | ||
1961 | else | 1174 | else |
1962 | azx_dev->stream_tag = i + 1; | 1175 | tag = i + 1; |
1176 | snd_hdac_stream_init(azx_bus(chip), azx_stream(azx_dev), | ||
1177 | i, dir, tag); | ||
1963 | } | 1178 | } |
1964 | 1179 | ||
1965 | return 0; | 1180 | return 0; |
1966 | } | 1181 | } |
1967 | EXPORT_SYMBOL_GPL(azx_init_stream); | 1182 | EXPORT_SYMBOL_GPL(azx_init_streams); |
1968 | 1183 | ||
1969 | MODULE_LICENSE("GPL"); | 1184 | void azx_free_streams(struct azx *chip) |
1970 | MODULE_DESCRIPTION("Common HDA driver functions"); | 1185 | { |
1186 | struct hdac_bus *bus = azx_bus(chip); | ||
1187 | struct hdac_stream *s; | ||
1188 | |||
1189 | while (!list_empty(&bus->stream_list)) { | ||
1190 | s = list_first_entry(&bus->stream_list, struct hdac_stream, list); | ||
1191 | list_del(&s->list); | ||
1192 | kfree(stream_to_azx_dev(s)); | ||
1193 | } | ||
1194 | } | ||
1195 | EXPORT_SYMBOL_GPL(azx_free_streams); | ||
diff --git a/sound/pci/hda/hda_controller.h b/sound/pci/hda/hda_controller.h index 0efdb094d21c..314105cd5061 100644 --- a/sound/pci/hda/hda_controller.h +++ b/sound/pci/hda/hda_controller.h | |||
@@ -21,135 +21,10 @@ | |||
21 | #include <sound/pcm.h> | 21 | #include <sound/pcm.h> |
22 | #include <sound/initval.h> | 22 | #include <sound/initval.h> |
23 | #include "hda_codec.h" | 23 | #include "hda_codec.h" |
24 | #include <sound/hda_register.h> | ||
24 | 25 | ||
25 | /* | 26 | #define AZX_MAX_CODECS HDA_MAX_CODECS |
26 | * registers | ||
27 | */ | ||
28 | #define AZX_REG_GCAP 0x00 | ||
29 | #define AZX_GCAP_64OK (1 << 0) /* 64bit address support */ | ||
30 | #define AZX_GCAP_NSDO (3 << 1) /* # of serial data out signals */ | ||
31 | #define AZX_GCAP_BSS (31 << 3) /* # of bidirectional streams */ | ||
32 | #define AZX_GCAP_ISS (15 << 8) /* # of input streams */ | ||
33 | #define AZX_GCAP_OSS (15 << 12) /* # of output streams */ | ||
34 | #define AZX_REG_VMIN 0x02 | ||
35 | #define AZX_REG_VMAJ 0x03 | ||
36 | #define AZX_REG_OUTPAY 0x04 | ||
37 | #define AZX_REG_INPAY 0x06 | ||
38 | #define AZX_REG_GCTL 0x08 | ||
39 | #define AZX_GCTL_RESET (1 << 0) /* controller reset */ | ||
40 | #define AZX_GCTL_FCNTRL (1 << 1) /* flush control */ | ||
41 | #define AZX_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */ | ||
42 | #define AZX_REG_WAKEEN 0x0c | ||
43 | #define AZX_REG_STATESTS 0x0e | ||
44 | #define AZX_REG_GSTS 0x10 | ||
45 | #define AZX_GSTS_FSTS (1 << 1) /* flush status */ | ||
46 | #define AZX_REG_INTCTL 0x20 | ||
47 | #define AZX_REG_INTSTS 0x24 | ||
48 | #define AZX_REG_WALLCLK 0x30 /* 24Mhz source */ | ||
49 | #define AZX_REG_OLD_SSYNC 0x34 /* SSYNC for old ICH */ | ||
50 | #define AZX_REG_SSYNC 0x38 | ||
51 | #define AZX_REG_CORBLBASE 0x40 | ||
52 | #define AZX_REG_CORBUBASE 0x44 | ||
53 | #define AZX_REG_CORBWP 0x48 | ||
54 | #define AZX_REG_CORBRP 0x4a | ||
55 | #define AZX_CORBRP_RST (1 << 15) /* read pointer reset */ | ||
56 | #define AZX_REG_CORBCTL 0x4c | ||
57 | #define AZX_CORBCTL_RUN (1 << 1) /* enable DMA */ | ||
58 | #define AZX_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */ | ||
59 | #define AZX_REG_CORBSTS 0x4d | ||
60 | #define AZX_CORBSTS_CMEI (1 << 0) /* memory error indication */ | ||
61 | #define AZX_REG_CORBSIZE 0x4e | ||
62 | |||
63 | #define AZX_REG_RIRBLBASE 0x50 | ||
64 | #define AZX_REG_RIRBUBASE 0x54 | ||
65 | #define AZX_REG_RIRBWP 0x58 | ||
66 | #define AZX_RIRBWP_RST (1 << 15) /* write pointer reset */ | ||
67 | #define AZX_REG_RINTCNT 0x5a | ||
68 | #define AZX_REG_RIRBCTL 0x5c | ||
69 | #define AZX_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */ | ||
70 | #define AZX_RBCTL_DMA_EN (1 << 1) /* enable DMA */ | ||
71 | #define AZX_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */ | ||
72 | #define AZX_REG_RIRBSTS 0x5d | ||
73 | #define AZX_RBSTS_IRQ (1 << 0) /* response irq */ | ||
74 | #define AZX_RBSTS_OVERRUN (1 << 2) /* overrun irq */ | ||
75 | #define AZX_REG_RIRBSIZE 0x5e | ||
76 | |||
77 | #define AZX_REG_IC 0x60 | ||
78 | #define AZX_REG_IR 0x64 | ||
79 | #define AZX_REG_IRS 0x68 | ||
80 | #define AZX_IRS_VALID (1<<1) | ||
81 | #define AZX_IRS_BUSY (1<<0) | ||
82 | |||
83 | #define AZX_REG_DPLBASE 0x70 | ||
84 | #define AZX_REG_DPUBASE 0x74 | ||
85 | #define AZX_DPLBASE_ENABLE 0x1 /* Enable position buffer */ | ||
86 | |||
87 | /* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ | ||
88 | enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 }; | ||
89 | |||
90 | /* stream register offsets from stream base */ | ||
91 | #define AZX_REG_SD_CTL 0x00 | ||
92 | #define AZX_REG_SD_STS 0x03 | ||
93 | #define AZX_REG_SD_LPIB 0x04 | ||
94 | #define AZX_REG_SD_CBL 0x08 | ||
95 | #define AZX_REG_SD_LVI 0x0c | ||
96 | #define AZX_REG_SD_FIFOW 0x0e | ||
97 | #define AZX_REG_SD_FIFOSIZE 0x10 | ||
98 | #define AZX_REG_SD_FORMAT 0x12 | ||
99 | #define AZX_REG_SD_BDLPL 0x18 | ||
100 | #define AZX_REG_SD_BDLPU 0x1c | ||
101 | |||
102 | /* PCI space */ | ||
103 | #define AZX_PCIREG_TCSEL 0x44 | ||
104 | |||
105 | /* | ||
106 | * other constants | ||
107 | */ | ||
108 | |||
109 | /* max number of fragments - we may use more if allocating more pages for BDL */ | ||
110 | #define BDL_SIZE 4096 | ||
111 | #define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16) | ||
112 | #define AZX_MAX_FRAG 32 | ||
113 | /* max buffer size - no h/w limit, you can increase as you like */ | ||
114 | #define AZX_MAX_BUF_SIZE (1024*1024*1024) | ||
115 | |||
116 | /* RIRB int mask: overrun[2], response[0] */ | ||
117 | #define RIRB_INT_RESPONSE 0x01 | ||
118 | #define RIRB_INT_OVERRUN 0x04 | ||
119 | #define RIRB_INT_MASK 0x05 | ||
120 | |||
121 | /* STATESTS int mask: S3,SD2,SD1,SD0 */ | ||
122 | #define AZX_MAX_CODECS 8 | ||
123 | #define AZX_DEFAULT_CODECS 4 | 27 | #define AZX_DEFAULT_CODECS 4 |
124 | #define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1) | ||
125 | |||
126 | /* SD_CTL bits */ | ||
127 | #define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */ | ||
128 | #define SD_CTL_DMA_START 0x02 /* stream DMA start bit */ | ||
129 | #define SD_CTL_STRIPE (3 << 16) /* stripe control */ | ||
130 | #define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */ | ||
131 | #define SD_CTL_DIR (1 << 19) /* bi-directional stream */ | ||
132 | #define SD_CTL_STREAM_TAG_MASK (0xf << 20) | ||
133 | #define SD_CTL_STREAM_TAG_SHIFT 20 | ||
134 | |||
135 | /* SD_CTL and SD_STS */ | ||
136 | #define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */ | ||
137 | #define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */ | ||
138 | #define SD_INT_COMPLETE 0x04 /* completion interrupt */ | ||
139 | #define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\ | ||
140 | SD_INT_COMPLETE) | ||
141 | |||
142 | /* SD_STS */ | ||
143 | #define SD_STS_FIFO_READY 0x20 /* FIFO ready */ | ||
144 | |||
145 | /* INTCTL and INTSTS */ | ||
146 | #define AZX_INT_ALL_STREAM 0xff /* all stream interrupts */ | ||
147 | #define AZX_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */ | ||
148 | #define AZX_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */ | ||
149 | |||
150 | /* below are so far hardcoded - should read registers in future */ | ||
151 | #define AZX_MAX_CORB_ENTRIES 256 | ||
152 | #define AZX_MAX_RIRB_ENTRIES 256 | ||
153 | 28 | ||
154 | /* driver quirks (capabilities) */ | 29 | /* driver quirks (capabilities) */ |
155 | /* bits 0-7 are used for indicating driver type */ | 30 | /* bits 0-7 are used for indicating driver type */ |
@@ -183,40 +58,10 @@ enum { | |||
183 | AZX_SNOOP_TYPE_NVIDIA, | 58 | AZX_SNOOP_TYPE_NVIDIA, |
184 | }; | 59 | }; |
185 | 60 | ||
186 | /* HD Audio class code */ | ||
187 | #define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403 | ||
188 | |||
189 | struct azx_dev { | 61 | struct azx_dev { |
190 | struct snd_dma_buffer bdl; /* BDL buffer */ | 62 | struct hdac_stream core; |
191 | u32 *posbuf; /* position buffer pointer */ | 63 | |
192 | |||
193 | unsigned int bufsize; /* size of the play buffer in bytes */ | ||
194 | unsigned int period_bytes; /* size of the period in bytes */ | ||
195 | unsigned int frags; /* number for period in the play buffer */ | ||
196 | unsigned int fifo_size; /* FIFO size */ | ||
197 | unsigned long start_wallclk; /* start + minimum wallclk */ | ||
198 | unsigned long period_wallclk; /* wallclk for period */ | ||
199 | |||
200 | void __iomem *sd_addr; /* stream descriptor pointer */ | ||
201 | |||
202 | u32 sd_int_sta_mask; /* stream int status mask */ | ||
203 | |||
204 | /* pcm support */ | ||
205 | struct snd_pcm_substream *substream; /* assigned substream, | ||
206 | * set in PCM open | ||
207 | */ | ||
208 | unsigned int format_val; /* format value to be set in the | ||
209 | * controller and the codec | ||
210 | */ | ||
211 | unsigned char stream_tag; /* assigned stream */ | ||
212 | unsigned char index; /* stream index */ | ||
213 | int assigned_key; /* last device# key assigned to */ | ||
214 | |||
215 | unsigned int opened:1; | ||
216 | unsigned int running:1; | ||
217 | unsigned int irq_pending:1; | 64 | unsigned int irq_pending:1; |
218 | unsigned int prepared:1; | ||
219 | unsigned int locked:1; | ||
220 | /* | 65 | /* |
221 | * For VIA: | 66 | * For VIA: |
222 | * A flag to ensure DMA position is 0 | 67 | * A flag to ensure DMA position is 0 |
@@ -224,50 +69,17 @@ struct azx_dev { | |||
224 | */ | 69 | */ |
225 | unsigned int insufficient:1; | 70 | unsigned int insufficient:1; |
226 | unsigned int wc_marked:1; | 71 | unsigned int wc_marked:1; |
227 | unsigned int no_period_wakeup:1; | ||
228 | |||
229 | struct timecounter azx_tc; | ||
230 | struct cyclecounter azx_cc; | ||
231 | |||
232 | int delay_negative_threshold; | ||
233 | |||
234 | #ifdef CONFIG_SND_HDA_DSP_LOADER | ||
235 | /* Allows dsp load to have sole access to the playback stream. */ | ||
236 | struct mutex dsp_mutex; | ||
237 | #endif | ||
238 | }; | 72 | }; |
239 | 73 | ||
240 | /* CORB/RIRB */ | 74 | #define azx_stream(dev) (&(dev)->core) |
241 | struct azx_rb { | 75 | #define stream_to_azx_dev(s) container_of(s, struct azx_dev, core) |
242 | u32 *buf; /* CORB/RIRB buffer | ||
243 | * Each CORB entry is 4byte, RIRB is 8byte | ||
244 | */ | ||
245 | dma_addr_t addr; /* physical address of CORB/RIRB buffer */ | ||
246 | /* for RIRB */ | ||
247 | unsigned short rp, wp; /* read/write pointers */ | ||
248 | int cmds[AZX_MAX_CODECS]; /* number of pending requests */ | ||
249 | u32 res[AZX_MAX_CODECS]; /* last read value */ | ||
250 | }; | ||
251 | 76 | ||
252 | struct azx; | 77 | struct azx; |
253 | 78 | ||
254 | /* Functions to read/write to hda registers. */ | 79 | /* Functions to read/write to hda registers. */ |
255 | struct hda_controller_ops { | 80 | struct hda_controller_ops { |
256 | /* Register Access */ | ||
257 | void (*reg_writel)(u32 value, u32 __iomem *addr); | ||
258 | u32 (*reg_readl)(u32 __iomem *addr); | ||
259 | void (*reg_writew)(u16 value, u16 __iomem *addr); | ||
260 | u16 (*reg_readw)(u16 __iomem *addr); | ||
261 | void (*reg_writeb)(u8 value, u8 __iomem *addr); | ||
262 | u8 (*reg_readb)(u8 __iomem *addr); | ||
263 | /* Disable msi if supported, PCI only */ | 81 | /* Disable msi if supported, PCI only */ |
264 | int (*disable_msi_reset_irq)(struct azx *); | 82 | int (*disable_msi_reset_irq)(struct azx *); |
265 | /* Allocation ops */ | ||
266 | int (*dma_alloc_pages)(struct azx *chip, | ||
267 | int type, | ||
268 | size_t size, | ||
269 | struct snd_dma_buffer *buf); | ||
270 | void (*dma_free_pages)(struct azx *chip, struct snd_dma_buffer *buf); | ||
271 | int (*substream_alloc_pages)(struct azx *chip, | 83 | int (*substream_alloc_pages)(struct azx *chip, |
272 | struct snd_pcm_substream *substream, | 84 | struct snd_pcm_substream *substream, |
273 | size_t size); | 85 | size_t size); |
@@ -277,6 +89,8 @@ struct hda_controller_ops { | |||
277 | struct vm_area_struct *area); | 89 | struct vm_area_struct *area); |
278 | /* Check if current position is acceptable */ | 90 | /* Check if current position is acceptable */ |
279 | int (*position_check)(struct azx *chip, struct azx_dev *azx_dev); | 91 | int (*position_check)(struct azx *chip, struct azx_dev *azx_dev); |
92 | /* enable/disable the link power */ | ||
93 | int (*link_power)(struct azx *chip, bool enable); | ||
280 | }; | 94 | }; |
281 | 95 | ||
282 | struct azx_pcm { | 96 | struct azx_pcm { |
@@ -291,6 +105,8 @@ typedef unsigned int (*azx_get_pos_callback_t)(struct azx *, struct azx_dev *); | |||
291 | typedef int (*azx_get_delay_callback_t)(struct azx *, struct azx_dev *, unsigned int pos); | 105 | typedef int (*azx_get_delay_callback_t)(struct azx *, struct azx_dev *, unsigned int pos); |
292 | 106 | ||
293 | struct azx { | 107 | struct azx { |
108 | struct hda_bus bus; | ||
109 | |||
294 | struct snd_card *card; | 110 | struct snd_card *card; |
295 | struct pci_dev *pci; | 111 | struct pci_dev *pci; |
296 | int dev_index; | 112 | int dev_index; |
@@ -312,35 +128,16 @@ struct azx { | |||
312 | azx_get_pos_callback_t get_position[2]; | 128 | azx_get_pos_callback_t get_position[2]; |
313 | azx_get_delay_callback_t get_delay[2]; | 129 | azx_get_delay_callback_t get_delay[2]; |
314 | 130 | ||
315 | /* pci resources */ | ||
316 | unsigned long addr; | ||
317 | void __iomem *remap_addr; | ||
318 | int irq; | ||
319 | |||
320 | /* locks */ | 131 | /* locks */ |
321 | spinlock_t reg_lock; | ||
322 | struct mutex open_mutex; /* Prevents concurrent open/close operations */ | 132 | struct mutex open_mutex; /* Prevents concurrent open/close operations */ |
323 | 133 | ||
324 | /* streams (x num_streams) */ | ||
325 | struct azx_dev *azx_dev; | ||
326 | |||
327 | /* PCM */ | 134 | /* PCM */ |
328 | struct list_head pcm_list; /* azx_pcm list */ | 135 | struct list_head pcm_list; /* azx_pcm list */ |
329 | 136 | ||
330 | /* HD codec */ | 137 | /* HD codec */ |
331 | unsigned short codec_mask; | ||
332 | int codec_probe_mask; /* copied from probe_mask option */ | 138 | int codec_probe_mask; /* copied from probe_mask option */ |
333 | struct hda_bus *bus; | ||
334 | unsigned int beep_mode; | 139 | unsigned int beep_mode; |
335 | 140 | ||
336 | /* CORB/RIRB */ | ||
337 | struct azx_rb corb; | ||
338 | struct azx_rb rirb; | ||
339 | |||
340 | /* CORB/RIRB and position buffers */ | ||
341 | struct snd_dma_buffer rb; | ||
342 | struct snd_dma_buffer posbuf; | ||
343 | |||
344 | #ifdef CONFIG_SND_HDA_PATCH_LOADER | 141 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
345 | const struct firmware *fw; | 142 | const struct firmware *fw; |
346 | #endif | 143 | #endif |
@@ -349,7 +146,6 @@ struct azx { | |||
349 | const int *bdl_pos_adj; | 146 | const int *bdl_pos_adj; |
350 | int poll_count; | 147 | int poll_count; |
351 | unsigned int running:1; | 148 | unsigned int running:1; |
352 | unsigned int initialized:1; | ||
353 | unsigned int single_cmd:1; | 149 | unsigned int single_cmd:1; |
354 | unsigned int polling_mode:1; | 150 | unsigned int polling_mode:1; |
355 | unsigned int msi:1; | 151 | unsigned int msi:1; |
@@ -359,14 +155,14 @@ struct azx { | |||
359 | unsigned int region_requested:1; | 155 | unsigned int region_requested:1; |
360 | unsigned int disabled:1; /* disabled by VGA-switcher */ | 156 | unsigned int disabled:1; /* disabled by VGA-switcher */ |
361 | 157 | ||
362 | /* for debugging */ | ||
363 | unsigned int last_cmd[AZX_MAX_CODECS]; | ||
364 | |||
365 | #ifdef CONFIG_SND_HDA_DSP_LOADER | 158 | #ifdef CONFIG_SND_HDA_DSP_LOADER |
366 | struct azx_dev saved_azx_dev; | 159 | struct azx_dev saved_azx_dev; |
367 | #endif | 160 | #endif |
368 | }; | 161 | }; |
369 | 162 | ||
163 | #define azx_bus(chip) (&(chip)->bus.core) | ||
164 | #define bus_to_azx(_bus) container_of(_bus, struct azx, bus.core) | ||
165 | |||
370 | #ifdef CONFIG_X86 | 166 | #ifdef CONFIG_X86 |
371 | #define azx_snoop(chip) ((chip)->snoop) | 167 | #define azx_snoop(chip) ((chip)->snoop) |
372 | #else | 168 | #else |
@@ -378,30 +174,17 @@ struct azx { | |||
378 | */ | 174 | */ |
379 | 175 | ||
380 | #define azx_writel(chip, reg, value) \ | 176 | #define azx_writel(chip, reg, value) \ |
381 | ((chip)->ops->reg_writel(value, (chip)->remap_addr + AZX_REG_##reg)) | 177 | snd_hdac_chip_writel(azx_bus(chip), reg, value) |
382 | #define azx_readl(chip, reg) \ | 178 | #define azx_readl(chip, reg) \ |
383 | ((chip)->ops->reg_readl((chip)->remap_addr + AZX_REG_##reg)) | 179 | snd_hdac_chip_readl(azx_bus(chip), reg) |
384 | #define azx_writew(chip, reg, value) \ | 180 | #define azx_writew(chip, reg, value) \ |
385 | ((chip)->ops->reg_writew(value, (chip)->remap_addr + AZX_REG_##reg)) | 181 | snd_hdac_chip_writew(azx_bus(chip), reg, value) |
386 | #define azx_readw(chip, reg) \ | 182 | #define azx_readw(chip, reg) \ |
387 | ((chip)->ops->reg_readw((chip)->remap_addr + AZX_REG_##reg)) | 183 | snd_hdac_chip_readw(azx_bus(chip), reg) |
388 | #define azx_writeb(chip, reg, value) \ | 184 | #define azx_writeb(chip, reg, value) \ |
389 | ((chip)->ops->reg_writeb(value, (chip)->remap_addr + AZX_REG_##reg)) | 185 | snd_hdac_chip_writeb(azx_bus(chip), reg, value) |
390 | #define azx_readb(chip, reg) \ | 186 | #define azx_readb(chip, reg) \ |
391 | ((chip)->ops->reg_readb((chip)->remap_addr + AZX_REG_##reg)) | 187 | snd_hdac_chip_readb(azx_bus(chip), reg) |
392 | |||
393 | #define azx_sd_writel(chip, dev, reg, value) \ | ||
394 | ((chip)->ops->reg_writel(value, (dev)->sd_addr + AZX_REG_##reg)) | ||
395 | #define azx_sd_readl(chip, dev, reg) \ | ||
396 | ((chip)->ops->reg_readl((dev)->sd_addr + AZX_REG_##reg)) | ||
397 | #define azx_sd_writew(chip, dev, reg, value) \ | ||
398 | ((chip)->ops->reg_writew(value, (dev)->sd_addr + AZX_REG_##reg)) | ||
399 | #define azx_sd_readw(chip, dev, reg) \ | ||
400 | ((chip)->ops->reg_readw((dev)->sd_addr + AZX_REG_##reg)) | ||
401 | #define azx_sd_writeb(chip, dev, reg, value) \ | ||
402 | ((chip)->ops->reg_writeb(value, (dev)->sd_addr + AZX_REG_##reg)) | ||
403 | #define azx_sd_readb(chip, dev, reg) \ | ||
404 | ((chip)->ops->reg_readb((dev)->sd_addr + AZX_REG_##reg)) | ||
405 | 188 | ||
406 | #define azx_has_pm_runtime(chip) \ | 189 | #define azx_has_pm_runtime(chip) \ |
407 | ((chip)->driver_caps & AZX_DCAPS_PM_RUNTIME) | 190 | ((chip)->driver_caps & AZX_DCAPS_PM_RUNTIME) |
@@ -416,22 +199,27 @@ unsigned int azx_get_pos_lpib(struct azx *chip, struct azx_dev *azx_dev); | |||
416 | unsigned int azx_get_pos_posbuf(struct azx *chip, struct azx_dev *azx_dev); | 199 | unsigned int azx_get_pos_posbuf(struct azx *chip, struct azx_dev *azx_dev); |
417 | 200 | ||
418 | /* Stream control. */ | 201 | /* Stream control. */ |
419 | void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev); | 202 | void azx_stop_all_streams(struct azx *chip); |
420 | 203 | ||
421 | /* Allocation functions. */ | 204 | /* Allocation functions. */ |
422 | int azx_alloc_stream_pages(struct azx *chip); | 205 | #define azx_alloc_stream_pages(chip) \ |
423 | void azx_free_stream_pages(struct azx *chip); | 206 | snd_hdac_bus_alloc_stream_pages(azx_bus(chip)) |
207 | #define azx_free_stream_pages(chip) \ | ||
208 | snd_hdac_bus_free_stream_pages(azx_bus(chip)) | ||
424 | 209 | ||
425 | /* Low level azx interface */ | 210 | /* Low level azx interface */ |
426 | void azx_init_chip(struct azx *chip, bool full_reset); | 211 | void azx_init_chip(struct azx *chip, bool full_reset); |
427 | void azx_stop_chip(struct azx *chip); | 212 | void azx_stop_chip(struct azx *chip); |
428 | void azx_enter_link_reset(struct azx *chip); | 213 | #define azx_enter_link_reset(chip) \ |
214 | snd_hdac_bus_enter_link_reset(azx_bus(chip)) | ||
429 | irqreturn_t azx_interrupt(int irq, void *dev_id); | 215 | irqreturn_t azx_interrupt(int irq, void *dev_id); |
430 | 216 | ||
431 | /* Codec interface */ | 217 | /* Codec interface */ |
432 | int azx_bus_create(struct azx *chip, const char *model); | 218 | int azx_bus_init(struct azx *chip, const char *model, |
219 | const struct hdac_io_ops *io_ops); | ||
433 | int azx_probe_codecs(struct azx *chip, unsigned int max_slots); | 220 | int azx_probe_codecs(struct azx *chip, unsigned int max_slots); |
434 | int azx_codec_configure(struct azx *chip); | 221 | int azx_codec_configure(struct azx *chip); |
435 | int azx_init_stream(struct azx *chip); | 222 | int azx_init_streams(struct azx *chip); |
223 | void azx_free_streams(struct azx *chip); | ||
436 | 224 | ||
437 | #endif /* __SOUND_HDA_CONTROLLER_H */ | 225 | #endif /* __SOUND_HDA_CONTROLLER_H */ |
diff --git a/sound/pci/hda/hda_controller_trace.h b/sound/pci/hda/hda_controller_trace.h new file mode 100644 index 000000000000..3e18d99bfb70 --- /dev/null +++ b/sound/pci/hda/hda_controller_trace.h | |||
@@ -0,0 +1,98 @@ | |||
1 | #undef TRACE_SYSTEM | ||
2 | #define TRACE_SYSTEM hda_controller | ||
3 | #define TRACE_INCLUDE_FILE hda_controller_trace | ||
4 | |||
5 | #if !defined(_TRACE_HDA_CONTROLLER_H) || defined(TRACE_HEADER_MULTI_READ) | ||
6 | #define _TRACE_HDA_CONTROLLER_H | ||
7 | |||
8 | #include <linux/tracepoint.h> | ||
9 | |||
10 | struct azx; | ||
11 | struct azx_dev; | ||
12 | |||
13 | TRACE_EVENT(azx_pcm_trigger, | ||
14 | |||
15 | TP_PROTO(struct azx *chip, struct azx_dev *dev, int cmd), | ||
16 | |||
17 | TP_ARGS(chip, dev, cmd), | ||
18 | |||
19 | TP_STRUCT__entry( | ||
20 | __field( int, card ) | ||
21 | __field( int, idx ) | ||
22 | __field( int, cmd ) | ||
23 | ), | ||
24 | |||
25 | TP_fast_assign( | ||
26 | __entry->card = (chip)->card->number; | ||
27 | __entry->idx = (dev)->core.index; | ||
28 | __entry->cmd = cmd; | ||
29 | ), | ||
30 | |||
31 | TP_printk("[%d:%d] cmd=%d", __entry->card, __entry->idx, __entry->cmd) | ||
32 | ); | ||
33 | |||
34 | TRACE_EVENT(azx_get_position, | ||
35 | |||
36 | TP_PROTO(struct azx *chip, struct azx_dev *dev, unsigned int pos, unsigned int delay), | ||
37 | |||
38 | TP_ARGS(chip, dev, pos, delay), | ||
39 | |||
40 | TP_STRUCT__entry( | ||
41 | __field( int, card ) | ||
42 | __field( int, idx ) | ||
43 | __field( unsigned int, pos ) | ||
44 | __field( unsigned int, delay ) | ||
45 | ), | ||
46 | |||
47 | TP_fast_assign( | ||
48 | __entry->card = (chip)->card->number; | ||
49 | __entry->idx = (dev)->core.index; | ||
50 | __entry->pos = pos; | ||
51 | __entry->delay = delay; | ||
52 | ), | ||
53 | |||
54 | TP_printk("[%d:%d] pos=%u, delay=%u", __entry->card, __entry->idx, __entry->pos, __entry->delay) | ||
55 | ); | ||
56 | |||
57 | DECLARE_EVENT_CLASS(azx_pcm, | ||
58 | TP_PROTO(struct azx *chip, struct azx_dev *azx_dev), | ||
59 | |||
60 | TP_ARGS(chip, azx_dev), | ||
61 | |||
62 | TP_STRUCT__entry( | ||
63 | __field( unsigned char, stream_tag ) | ||
64 | ), | ||
65 | |||
66 | TP_fast_assign( | ||
67 | __entry->stream_tag = (azx_dev)->core.stream_tag; | ||
68 | ), | ||
69 | |||
70 | TP_printk("stream_tag: %d", __entry->stream_tag) | ||
71 | ); | ||
72 | |||
73 | DEFINE_EVENT(azx_pcm, azx_pcm_open, | ||
74 | TP_PROTO(struct azx *chip, struct azx_dev *azx_dev), | ||
75 | TP_ARGS(chip, azx_dev) | ||
76 | ); | ||
77 | |||
78 | DEFINE_EVENT(azx_pcm, azx_pcm_close, | ||
79 | TP_PROTO(struct azx *chip, struct azx_dev *azx_dev), | ||
80 | TP_ARGS(chip, azx_dev) | ||
81 | ); | ||
82 | |||
83 | DEFINE_EVENT(azx_pcm, azx_pcm_hw_params, | ||
84 | TP_PROTO(struct azx *chip, struct azx_dev *azx_dev), | ||
85 | TP_ARGS(chip, azx_dev) | ||
86 | ); | ||
87 | |||
88 | DEFINE_EVENT(azx_pcm, azx_pcm_prepare, | ||
89 | TP_PROTO(struct azx *chip, struct azx_dev *azx_dev), | ||
90 | TP_ARGS(chip, azx_dev) | ||
91 | ); | ||
92 | |||
93 | #endif /* _TRACE_HDA_CONTROLLER_H */ | ||
94 | |||
95 | /* This part must be outside protection */ | ||
96 | #undef TRACE_INCLUDE_PATH | ||
97 | #define TRACE_INCLUDE_PATH . | ||
98 | #include <trace/define_trace.h> | ||
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index 3d2597b7037b..788f969b1a68 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c | |||
@@ -3259,7 +3259,8 @@ static int create_input_ctls(struct hda_codec *codec) | |||
3259 | val = PIN_IN; | 3259 | val = PIN_IN; |
3260 | if (cfg->inputs[i].type == AUTO_PIN_MIC) | 3260 | if (cfg->inputs[i].type == AUTO_PIN_MIC) |
3261 | val |= snd_hda_get_default_vref(codec, pin); | 3261 | val |= snd_hda_get_default_vref(codec, pin); |
3262 | if (pin != spec->hp_mic_pin) | 3262 | if (pin != spec->hp_mic_pin && |
3263 | !snd_hda_codec_get_pin_target(codec, pin)) | ||
3263 | set_pin_target(codec, pin, val, false); | 3264 | set_pin_target(codec, pin, val, false); |
3264 | 3265 | ||
3265 | if (mixer) { | 3266 | if (mixer) { |
diff --git a/sound/pci/hda/hda_i915.c b/sound/pci/hda/hda_i915.c deleted file mode 100644 index 3052a2b095f7..000000000000 --- a/sound/pci/hda/hda_i915.c +++ /dev/null | |||
@@ -1,196 +0,0 @@ | |||
1 | /* | ||
2 | * hda_i915.c - routines for Haswell HDA controller power well support | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms of the GNU General Public License as published by the Free | ||
6 | * Software Foundation; either version 2 of the License, or (at your option) | ||
7 | * any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, but | ||
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
12 | * for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software Foundation, | ||
16 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
17 | */ | ||
18 | |||
19 | #include <linux/init.h> | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/pci.h> | ||
22 | #include <linux/component.h> | ||
23 | #include <drm/i915_component.h> | ||
24 | #include <sound/core.h> | ||
25 | #include "hda_controller.h" | ||
26 | #include "hda_intel.h" | ||
27 | |||
28 | /* Intel HSW/BDW display HDA controller Extended Mode registers. | ||
29 | * EM4 (M value) and EM5 (N Value) are used to convert CDClk (Core Display | ||
30 | * Clock) to 24MHz BCLK: BCLK = CDCLK * M / N | ||
31 | * The values will be lost when the display power well is disabled. | ||
32 | */ | ||
33 | #define AZX_REG_EM4 0x100c | ||
34 | #define AZX_REG_EM5 0x1010 | ||
35 | |||
36 | int hda_display_power(struct hda_intel *hda, bool enable) | ||
37 | { | ||
38 | struct i915_audio_component *acomp = &hda->audio_component; | ||
39 | |||
40 | if (!acomp->ops) | ||
41 | return -ENODEV; | ||
42 | |||
43 | dev_dbg(&hda->chip.pci->dev, "display power %s\n", | ||
44 | enable ? "enable" : "disable"); | ||
45 | if (enable) | ||
46 | acomp->ops->get_power(acomp->dev); | ||
47 | else | ||
48 | acomp->ops->put_power(acomp->dev); | ||
49 | |||
50 | return 0; | ||
51 | } | ||
52 | |||
53 | void haswell_set_bclk(struct hda_intel *hda) | ||
54 | { | ||
55 | int cdclk_freq; | ||
56 | unsigned int bclk_m, bclk_n; | ||
57 | struct i915_audio_component *acomp = &hda->audio_component; | ||
58 | struct pci_dev *pci = hda->chip.pci; | ||
59 | |||
60 | /* Only Haswell/Broadwell need set BCLK */ | ||
61 | if (pci->device != 0x0a0c && pci->device != 0x0c0c | ||
62 | && pci->device != 0x0d0c && pci->device != 0x160c) | ||
63 | return; | ||
64 | |||
65 | if (!acomp->ops) | ||
66 | return; | ||
67 | |||
68 | cdclk_freq = acomp->ops->get_cdclk_freq(acomp->dev); | ||
69 | switch (cdclk_freq) { | ||
70 | case 337500: | ||
71 | bclk_m = 16; | ||
72 | bclk_n = 225; | ||
73 | break; | ||
74 | |||
75 | case 450000: | ||
76 | default: /* default CDCLK 450MHz */ | ||
77 | bclk_m = 4; | ||
78 | bclk_n = 75; | ||
79 | break; | ||
80 | |||
81 | case 540000: | ||
82 | bclk_m = 4; | ||
83 | bclk_n = 90; | ||
84 | break; | ||
85 | |||
86 | case 675000: | ||
87 | bclk_m = 8; | ||
88 | bclk_n = 225; | ||
89 | break; | ||
90 | } | ||
91 | |||
92 | azx_writew(&hda->chip, EM4, bclk_m); | ||
93 | azx_writew(&hda->chip, EM5, bclk_n); | ||
94 | } | ||
95 | |||
96 | static int hda_component_master_bind(struct device *dev) | ||
97 | { | ||
98 | struct snd_card *card = dev_get_drvdata(dev); | ||
99 | struct azx *chip = card->private_data; | ||
100 | struct hda_intel *hda = container_of(chip, struct hda_intel, chip); | ||
101 | struct i915_audio_component *acomp = &hda->audio_component; | ||
102 | int ret; | ||
103 | |||
104 | ret = component_bind_all(dev, acomp); | ||
105 | if (ret < 0) | ||
106 | return ret; | ||
107 | |||
108 | if (WARN_ON(!(acomp->dev && acomp->ops && acomp->ops->get_power && | ||
109 | acomp->ops->put_power && acomp->ops->get_cdclk_freq))) { | ||
110 | ret = -EINVAL; | ||
111 | goto out_unbind; | ||
112 | } | ||
113 | |||
114 | /* | ||
115 | * Atm, we don't support dynamic unbinding initiated by the child | ||
116 | * component, so pin its containing module until we unbind. | ||
117 | */ | ||
118 | if (!try_module_get(acomp->ops->owner)) { | ||
119 | ret = -ENODEV; | ||
120 | goto out_unbind; | ||
121 | } | ||
122 | |||
123 | return 0; | ||
124 | |||
125 | out_unbind: | ||
126 | component_unbind_all(dev, acomp); | ||
127 | |||
128 | return ret; | ||
129 | } | ||
130 | |||
131 | static void hda_component_master_unbind(struct device *dev) | ||
132 | { | ||
133 | struct snd_card *card = dev_get_drvdata(dev); | ||
134 | struct azx *chip = card->private_data; | ||
135 | struct hda_intel *hda = container_of(chip, struct hda_intel, chip); | ||
136 | struct i915_audio_component *acomp = &hda->audio_component; | ||
137 | |||
138 | module_put(acomp->ops->owner); | ||
139 | component_unbind_all(dev, acomp); | ||
140 | WARN_ON(acomp->ops || acomp->dev); | ||
141 | } | ||
142 | |||
143 | static const struct component_master_ops hda_component_master_ops = { | ||
144 | .bind = hda_component_master_bind, | ||
145 | .unbind = hda_component_master_unbind, | ||
146 | }; | ||
147 | |||
148 | static int hda_component_master_match(struct device *dev, void *data) | ||
149 | { | ||
150 | /* i915 is the only supported component */ | ||
151 | return !strcmp(dev->driver->name, "i915"); | ||
152 | } | ||
153 | |||
154 | int hda_i915_init(struct hda_intel *hda) | ||
155 | { | ||
156 | struct component_match *match = NULL; | ||
157 | struct device *dev = &hda->chip.pci->dev; | ||
158 | struct i915_audio_component *acomp = &hda->audio_component; | ||
159 | int ret; | ||
160 | |||
161 | component_match_add(dev, &match, hda_component_master_match, hda); | ||
162 | ret = component_master_add_with_match(dev, &hda_component_master_ops, | ||
163 | match); | ||
164 | if (ret < 0) | ||
165 | goto out_err; | ||
166 | |||
167 | /* | ||
168 | * Atm, we don't support deferring the component binding, so make sure | ||
169 | * i915 is loaded and that the binding successfully completes. | ||
170 | */ | ||
171 | request_module("i915"); | ||
172 | |||
173 | if (!acomp->ops) { | ||
174 | ret = -ENODEV; | ||
175 | goto out_master_del; | ||
176 | } | ||
177 | |||
178 | dev_dbg(dev, "bound to i915 component master\n"); | ||
179 | |||
180 | return 0; | ||
181 | out_master_del: | ||
182 | component_master_del(dev, &hda_component_master_ops); | ||
183 | out_err: | ||
184 | dev_err(dev, "failed to add i915 component master (%d)\n", ret); | ||
185 | |||
186 | return ret; | ||
187 | } | ||
188 | |||
189 | int hda_i915_exit(struct hda_intel *hda) | ||
190 | { | ||
191 | struct device *dev = &hda->chip.pci->dev; | ||
192 | |||
193 | component_master_del(dev, &hda_component_master_ops); | ||
194 | |||
195 | return 0; | ||
196 | } | ||
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 34040d26c94f..391e4f834436 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c | |||
@@ -57,6 +57,8 @@ | |||
57 | #endif | 57 | #endif |
58 | #include <sound/core.h> | 58 | #include <sound/core.h> |
59 | #include <sound/initval.h> | 59 | #include <sound/initval.h> |
60 | #include <sound/hdaudio.h> | ||
61 | #include <sound/hda_i915.h> | ||
60 | #include <linux/vgaarb.h> | 62 | #include <linux/vgaarb.h> |
61 | #include <linux/vga_switcheroo.h> | 63 | #include <linux/vga_switcheroo.h> |
62 | #include <linux/firmware.h> | 64 | #include <linux/firmware.h> |
@@ -64,6 +66,9 @@ | |||
64 | #include "hda_controller.h" | 66 | #include "hda_controller.h" |
65 | #include "hda_intel.h" | 67 | #include "hda_intel.h" |
66 | 68 | ||
69 | #define CREATE_TRACE_POINTS | ||
70 | #include "hda_intel_trace.h" | ||
71 | |||
67 | /* position fix mode */ | 72 | /* position fix mode */ |
68 | enum { | 73 | enum { |
69 | POS_FIX_AUTO, | 74 | POS_FIX_AUTO, |
@@ -491,11 +496,22 @@ static void azx_init_pci(struct azx *chip) | |||
491 | } | 496 | } |
492 | } | 497 | } |
493 | 498 | ||
499 | static void hda_intel_init_chip(struct azx *chip, bool full_reset) | ||
500 | { | ||
501 | struct hdac_bus *bus = azx_bus(chip); | ||
502 | |||
503 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) | ||
504 | snd_hdac_set_codec_wakeup(bus, true); | ||
505 | azx_init_chip(chip, full_reset); | ||
506 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) | ||
507 | snd_hdac_set_codec_wakeup(bus, false); | ||
508 | } | ||
509 | |||
494 | /* calculate runtime delay from LPIB */ | 510 | /* calculate runtime delay from LPIB */ |
495 | static int azx_get_delay_from_lpib(struct azx *chip, struct azx_dev *azx_dev, | 511 | static int azx_get_delay_from_lpib(struct azx *chip, struct azx_dev *azx_dev, |
496 | unsigned int pos) | 512 | unsigned int pos) |
497 | { | 513 | { |
498 | struct snd_pcm_substream *substream = azx_dev->substream; | 514 | struct snd_pcm_substream *substream = azx_dev->core.substream; |
499 | int stream = substream->stream; | 515 | int stream = substream->stream; |
500 | unsigned int lpib_pos = azx_get_pos_lpib(chip, azx_dev); | 516 | unsigned int lpib_pos = azx_get_pos_lpib(chip, azx_dev); |
501 | int delay; | 517 | int delay; |
@@ -505,16 +521,16 @@ static int azx_get_delay_from_lpib(struct azx *chip, struct azx_dev *azx_dev, | |||
505 | else | 521 | else |
506 | delay = lpib_pos - pos; | 522 | delay = lpib_pos - pos; |
507 | if (delay < 0) { | 523 | if (delay < 0) { |
508 | if (delay >= azx_dev->delay_negative_threshold) | 524 | if (delay >= azx_dev->core.delay_negative_threshold) |
509 | delay = 0; | 525 | delay = 0; |
510 | else | 526 | else |
511 | delay += azx_dev->bufsize; | 527 | delay += azx_dev->core.bufsize; |
512 | } | 528 | } |
513 | 529 | ||
514 | if (delay >= azx_dev->period_bytes) { | 530 | if (delay >= azx_dev->core.period_bytes) { |
515 | dev_info(chip->card->dev, | 531 | dev_info(chip->card->dev, |
516 | "Unstable LPIB (%d >= %d); disabling LPIB delay counting\n", | 532 | "Unstable LPIB (%d >= %d); disabling LPIB delay counting\n", |
517 | delay, azx_dev->period_bytes); | 533 | delay, azx_dev->core.period_bytes); |
518 | delay = 0; | 534 | delay = 0; |
519 | chip->driver_caps &= ~AZX_DCAPS_COUNT_LPIB_DELAY; | 535 | chip->driver_caps &= ~AZX_DCAPS_COUNT_LPIB_DELAY; |
520 | chip->get_delay[stream] = NULL; | 536 | chip->get_delay[stream] = NULL; |
@@ -543,6 +559,14 @@ static int azx_position_check(struct azx *chip, struct azx_dev *azx_dev) | |||
543 | return 0; | 559 | return 0; |
544 | } | 560 | } |
545 | 561 | ||
562 | /* Enable/disable i915 display power for the link */ | ||
563 | static int azx_intel_link_power(struct azx *chip, bool enable) | ||
564 | { | ||
565 | struct hdac_bus *bus = azx_bus(chip); | ||
566 | |||
567 | return snd_hdac_display_power(bus, enable); | ||
568 | } | ||
569 | |||
546 | /* | 570 | /* |
547 | * Check whether the current DMA position is acceptable for updating | 571 | * Check whether the current DMA position is acceptable for updating |
548 | * periods. Returns non-zero if it's OK. | 572 | * periods. Returns non-zero if it's OK. |
@@ -554,13 +578,13 @@ static int azx_position_check(struct azx *chip, struct azx_dev *azx_dev) | |||
554 | */ | 578 | */ |
555 | static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev) | 579 | static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev) |
556 | { | 580 | { |
557 | struct snd_pcm_substream *substream = azx_dev->substream; | 581 | struct snd_pcm_substream *substream = azx_dev->core.substream; |
558 | int stream = substream->stream; | 582 | int stream = substream->stream; |
559 | u32 wallclk; | 583 | u32 wallclk; |
560 | unsigned int pos; | 584 | unsigned int pos; |
561 | 585 | ||
562 | wallclk = azx_readl(chip, WALLCLK) - azx_dev->start_wallclk; | 586 | wallclk = azx_readl(chip, WALLCLK) - azx_dev->core.start_wallclk; |
563 | if (wallclk < (azx_dev->period_wallclk * 2) / 3) | 587 | if (wallclk < (azx_dev->core.period_wallclk * 2) / 3) |
564 | return -1; /* bogus (too early) interrupt */ | 588 | return -1; /* bogus (too early) interrupt */ |
565 | 589 | ||
566 | if (chip->get_position[stream]) | 590 | if (chip->get_position[stream]) |
@@ -571,6 +595,9 @@ static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev) | |||
571 | dev_info(chip->card->dev, | 595 | dev_info(chip->card->dev, |
572 | "Invalid position buffer, using LPIB read method instead.\n"); | 596 | "Invalid position buffer, using LPIB read method instead.\n"); |
573 | chip->get_position[stream] = azx_get_pos_lpib; | 597 | chip->get_position[stream] = azx_get_pos_lpib; |
598 | if (chip->get_position[0] == azx_get_pos_lpib && | ||
599 | chip->get_position[1] == azx_get_pos_lpib) | ||
600 | azx_bus(chip)->use_posbuf = false; | ||
574 | pos = azx_get_pos_lpib(chip, azx_dev); | 601 | pos = azx_get_pos_lpib(chip, azx_dev); |
575 | chip->get_delay[stream] = NULL; | 602 | chip->get_delay[stream] = NULL; |
576 | } else { | 603 | } else { |
@@ -580,17 +607,17 @@ static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev) | |||
580 | } | 607 | } |
581 | } | 608 | } |
582 | 609 | ||
583 | if (pos >= azx_dev->bufsize) | 610 | if (pos >= azx_dev->core.bufsize) |
584 | pos = 0; | 611 | pos = 0; |
585 | 612 | ||
586 | if (WARN_ONCE(!azx_dev->period_bytes, | 613 | if (WARN_ONCE(!azx_dev->core.period_bytes, |
587 | "hda-intel: zero azx_dev->period_bytes")) | 614 | "hda-intel: zero azx_dev->period_bytes")) |
588 | return -1; /* this shouldn't happen! */ | 615 | return -1; /* this shouldn't happen! */ |
589 | if (wallclk < (azx_dev->period_wallclk * 5) / 4 && | 616 | if (wallclk < (azx_dev->core.period_wallclk * 5) / 4 && |
590 | pos % azx_dev->period_bytes > azx_dev->period_bytes / 2) | 617 | pos % azx_dev->core.period_bytes > azx_dev->core.period_bytes / 2) |
591 | /* NG - it's below the first next period boundary */ | 618 | /* NG - it's below the first next period boundary */ |
592 | return chip->bdl_pos_adj[chip->dev_index] ? 0 : -1; | 619 | return chip->bdl_pos_adj[chip->dev_index] ? 0 : -1; |
593 | azx_dev->start_wallclk += wallclk; | 620 | azx_dev->core.start_wallclk += wallclk; |
594 | return 1; /* OK, it's fine */ | 621 | return 1; /* OK, it's fine */ |
595 | } | 622 | } |
596 | 623 | ||
@@ -601,7 +628,9 @@ static void azx_irq_pending_work(struct work_struct *work) | |||
601 | { | 628 | { |
602 | struct hda_intel *hda = container_of(work, struct hda_intel, irq_pending_work); | 629 | struct hda_intel *hda = container_of(work, struct hda_intel, irq_pending_work); |
603 | struct azx *chip = &hda->chip; | 630 | struct azx *chip = &hda->chip; |
604 | int i, pending, ok; | 631 | struct hdac_bus *bus = azx_bus(chip); |
632 | struct hdac_stream *s; | ||
633 | int pending, ok; | ||
605 | 634 | ||
606 | if (!hda->irq_pending_warned) { | 635 | if (!hda->irq_pending_warned) { |
607 | dev_info(chip->card->dev, | 636 | dev_info(chip->card->dev, |
@@ -612,25 +641,25 @@ static void azx_irq_pending_work(struct work_struct *work) | |||
612 | 641 | ||
613 | for (;;) { | 642 | for (;;) { |
614 | pending = 0; | 643 | pending = 0; |
615 | spin_lock_irq(&chip->reg_lock); | 644 | spin_lock_irq(&bus->reg_lock); |
616 | for (i = 0; i < chip->num_streams; i++) { | 645 | list_for_each_entry(s, &bus->stream_list, list) { |
617 | struct azx_dev *azx_dev = &chip->azx_dev[i]; | 646 | struct azx_dev *azx_dev = stream_to_azx_dev(s); |
618 | if (!azx_dev->irq_pending || | 647 | if (!azx_dev->irq_pending || |
619 | !azx_dev->substream || | 648 | !s->substream || |
620 | !azx_dev->running) | 649 | !s->running) |
621 | continue; | 650 | continue; |
622 | ok = azx_position_ok(chip, azx_dev); | 651 | ok = azx_position_ok(chip, azx_dev); |
623 | if (ok > 0) { | 652 | if (ok > 0) { |
624 | azx_dev->irq_pending = 0; | 653 | azx_dev->irq_pending = 0; |
625 | spin_unlock(&chip->reg_lock); | 654 | spin_unlock(&bus->reg_lock); |
626 | snd_pcm_period_elapsed(azx_dev->substream); | 655 | snd_pcm_period_elapsed(s->substream); |
627 | spin_lock(&chip->reg_lock); | 656 | spin_lock(&bus->reg_lock); |
628 | } else if (ok < 0) { | 657 | } else if (ok < 0) { |
629 | pending = 0; /* too early */ | 658 | pending = 0; /* too early */ |
630 | } else | 659 | } else |
631 | pending++; | 660 | pending++; |
632 | } | 661 | } |
633 | spin_unlock_irq(&chip->reg_lock); | 662 | spin_unlock_irq(&bus->reg_lock); |
634 | if (!pending) | 663 | if (!pending) |
635 | return; | 664 | return; |
636 | msleep(1); | 665 | msleep(1); |
@@ -640,16 +669,21 @@ static void azx_irq_pending_work(struct work_struct *work) | |||
640 | /* clear irq_pending flags and assure no on-going workq */ | 669 | /* clear irq_pending flags and assure no on-going workq */ |
641 | static void azx_clear_irq_pending(struct azx *chip) | 670 | static void azx_clear_irq_pending(struct azx *chip) |
642 | { | 671 | { |
643 | int i; | 672 | struct hdac_bus *bus = azx_bus(chip); |
673 | struct hdac_stream *s; | ||
644 | 674 | ||
645 | spin_lock_irq(&chip->reg_lock); | 675 | spin_lock_irq(&bus->reg_lock); |
646 | for (i = 0; i < chip->num_streams; i++) | 676 | list_for_each_entry(s, &bus->stream_list, list) { |
647 | chip->azx_dev[i].irq_pending = 0; | 677 | struct azx_dev *azx_dev = stream_to_azx_dev(s); |
648 | spin_unlock_irq(&chip->reg_lock); | 678 | azx_dev->irq_pending = 0; |
679 | } | ||
680 | spin_unlock_irq(&bus->reg_lock); | ||
649 | } | 681 | } |
650 | 682 | ||
651 | static int azx_acquire_irq(struct azx *chip, int do_disconnect) | 683 | static int azx_acquire_irq(struct azx *chip, int do_disconnect) |
652 | { | 684 | { |
685 | struct hdac_bus *bus = azx_bus(chip); | ||
686 | |||
653 | if (request_irq(chip->pci->irq, azx_interrupt, | 687 | if (request_irq(chip->pci->irq, azx_interrupt, |
654 | chip->msi ? 0 : IRQF_SHARED, | 688 | chip->msi ? 0 : IRQF_SHARED, |
655 | KBUILD_MODNAME, chip)) { | 689 | KBUILD_MODNAME, chip)) { |
@@ -660,7 +694,7 @@ static int azx_acquire_irq(struct azx *chip, int do_disconnect) | |||
660 | snd_card_disconnect(chip->card); | 694 | snd_card_disconnect(chip->card); |
661 | return -1; | 695 | return -1; |
662 | } | 696 | } |
663 | chip->irq = chip->pci->irq; | 697 | bus->irq = chip->pci->irq; |
664 | pci_intx(chip->pci, !chip->msi); | 698 | pci_intx(chip->pci, !chip->msi); |
665 | return 0; | 699 | return 0; |
666 | } | 700 | } |
@@ -673,8 +707,8 @@ static unsigned int azx_via_get_position(struct azx *chip, | |||
673 | unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos; | 707 | unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos; |
674 | unsigned int fifo_size; | 708 | unsigned int fifo_size; |
675 | 709 | ||
676 | link_pos = azx_sd_readl(chip, azx_dev, SD_LPIB); | 710 | link_pos = snd_hdac_stream_get_pos_lpib(azx_stream(azx_dev)); |
677 | if (azx_dev->substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | 711 | if (azx_dev->core.substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
678 | /* Playback, no problem using link position */ | 712 | /* Playback, no problem using link position */ |
679 | return link_pos; | 713 | return link_pos; |
680 | } | 714 | } |
@@ -683,13 +717,14 @@ static unsigned int azx_via_get_position(struct azx *chip, | |||
683 | /* For new chipset, | 717 | /* For new chipset, |
684 | * use mod to get the DMA position just like old chipset | 718 | * use mod to get the DMA position just like old chipset |
685 | */ | 719 | */ |
686 | mod_dma_pos = le32_to_cpu(*azx_dev->posbuf); | 720 | mod_dma_pos = le32_to_cpu(*azx_dev->core.posbuf); |
687 | mod_dma_pos %= azx_dev->period_bytes; | 721 | mod_dma_pos %= azx_dev->core.period_bytes; |
688 | 722 | ||
689 | /* azx_dev->fifo_size can't get FIFO size of in stream. | 723 | /* azx_dev->fifo_size can't get FIFO size of in stream. |
690 | * Get from base address + offset. | 724 | * Get from base address + offset. |
691 | */ | 725 | */ |
692 | fifo_size = readw(chip->remap_addr + VIA_IN_STREAM0_FIFO_SIZE_OFFSET); | 726 | fifo_size = readw(azx_bus(chip)->remap_addr + |
727 | VIA_IN_STREAM0_FIFO_SIZE_OFFSET); | ||
693 | 728 | ||
694 | if (azx_dev->insufficient) { | 729 | if (azx_dev->insufficient) { |
695 | /* Link position never gather than FIFO size */ | 730 | /* Link position never gather than FIFO size */ |
@@ -700,20 +735,20 @@ static unsigned int azx_via_get_position(struct azx *chip, | |||
700 | } | 735 | } |
701 | 736 | ||
702 | if (link_pos <= fifo_size) | 737 | if (link_pos <= fifo_size) |
703 | mini_pos = azx_dev->bufsize + link_pos - fifo_size; | 738 | mini_pos = azx_dev->core.bufsize + link_pos - fifo_size; |
704 | else | 739 | else |
705 | mini_pos = link_pos - fifo_size; | 740 | mini_pos = link_pos - fifo_size; |
706 | 741 | ||
707 | /* Find nearest previous boudary */ | 742 | /* Find nearest previous boudary */ |
708 | mod_mini_pos = mini_pos % azx_dev->period_bytes; | 743 | mod_mini_pos = mini_pos % azx_dev->core.period_bytes; |
709 | mod_link_pos = link_pos % azx_dev->period_bytes; | 744 | mod_link_pos = link_pos % azx_dev->core.period_bytes; |
710 | if (mod_link_pos >= fifo_size) | 745 | if (mod_link_pos >= fifo_size) |
711 | bound_pos = link_pos - mod_link_pos; | 746 | bound_pos = link_pos - mod_link_pos; |
712 | else if (mod_dma_pos >= mod_mini_pos) | 747 | else if (mod_dma_pos >= mod_mini_pos) |
713 | bound_pos = mini_pos - mod_mini_pos; | 748 | bound_pos = mini_pos - mod_mini_pos; |
714 | else { | 749 | else { |
715 | bound_pos = mini_pos - mod_mini_pos + azx_dev->period_bytes; | 750 | bound_pos = mini_pos - mod_mini_pos + azx_dev->core.period_bytes; |
716 | if (bound_pos >= azx_dev->bufsize) | 751 | if (bound_pos >= azx_dev->core.bufsize) |
717 | bound_pos = 0; | 752 | bound_pos = 0; |
718 | } | 753 | } |
719 | 754 | ||
@@ -755,9 +790,9 @@ static int param_set_xint(const char *val, const struct kernel_param *kp) | |||
755 | mutex_lock(&card_list_lock); | 790 | mutex_lock(&card_list_lock); |
756 | list_for_each_entry(hda, &card_list, list) { | 791 | list_for_each_entry(hda, &card_list, list) { |
757 | chip = &hda->chip; | 792 | chip = &hda->chip; |
758 | if (!chip->bus || chip->disabled) | 793 | if (!hda->probe_continued || chip->disabled) |
759 | continue; | 794 | continue; |
760 | snd_hda_set_power_save(chip->bus, power_save * 1000); | 795 | snd_hda_set_power_save(&chip->bus, power_save * 1000); |
761 | } | 796 | } |
762 | mutex_unlock(&card_list_lock); | 797 | mutex_unlock(&card_list_lock); |
763 | return 0; | 798 | return 0; |
@@ -767,6 +802,50 @@ static int param_set_xint(const char *val, const struct kernel_param *kp) | |||
767 | #define azx_del_card_list(chip) /* NOP */ | 802 | #define azx_del_card_list(chip) /* NOP */ |
768 | #endif /* CONFIG_PM */ | 803 | #endif /* CONFIG_PM */ |
769 | 804 | ||
805 | /* Intel HSW/BDW display HDA controller is in GPU. Both its power and link BCLK | ||
806 | * depends on GPU. Two Extended Mode registers EM4 (M value) and EM5 (N Value) | ||
807 | * are used to convert CDClk (Core Display Clock) to 24MHz BCLK: | ||
808 | * BCLK = CDCLK * M / N | ||
809 | * The values will be lost when the display power well is disabled and need to | ||
810 | * be restored to avoid abnormal playback speed. | ||
811 | */ | ||
812 | static void haswell_set_bclk(struct hda_intel *hda) | ||
813 | { | ||
814 | struct azx *chip = &hda->chip; | ||
815 | int cdclk_freq; | ||
816 | unsigned int bclk_m, bclk_n; | ||
817 | |||
818 | if (!hda->need_i915_power) | ||
819 | return; | ||
820 | |||
821 | cdclk_freq = snd_hdac_get_display_clk(azx_bus(chip)); | ||
822 | switch (cdclk_freq) { | ||
823 | case 337500: | ||
824 | bclk_m = 16; | ||
825 | bclk_n = 225; | ||
826 | break; | ||
827 | |||
828 | case 450000: | ||
829 | default: /* default CDCLK 450MHz */ | ||
830 | bclk_m = 4; | ||
831 | bclk_n = 75; | ||
832 | break; | ||
833 | |||
834 | case 540000: | ||
835 | bclk_m = 4; | ||
836 | bclk_n = 90; | ||
837 | break; | ||
838 | |||
839 | case 675000: | ||
840 | bclk_m = 8; | ||
841 | bclk_n = 225; | ||
842 | break; | ||
843 | } | ||
844 | |||
845 | azx_writew(chip, HSW_EM4, bclk_m); | ||
846 | azx_writew(chip, HSW_EM5, bclk_n); | ||
847 | } | ||
848 | |||
770 | #if defined(CONFIG_PM_SLEEP) || defined(SUPPORT_VGA_SWITCHEROO) | 849 | #if defined(CONFIG_PM_SLEEP) || defined(SUPPORT_VGA_SWITCHEROO) |
771 | /* | 850 | /* |
772 | * power management | 851 | * power management |
@@ -776,6 +855,7 @@ static int azx_suspend(struct device *dev) | |||
776 | struct snd_card *card = dev_get_drvdata(dev); | 855 | struct snd_card *card = dev_get_drvdata(dev); |
777 | struct azx *chip; | 856 | struct azx *chip; |
778 | struct hda_intel *hda; | 857 | struct hda_intel *hda; |
858 | struct hdac_bus *bus; | ||
779 | 859 | ||
780 | if (!card) | 860 | if (!card) |
781 | return 0; | 861 | return 0; |
@@ -785,19 +865,23 @@ static int azx_suspend(struct device *dev) | |||
785 | if (chip->disabled || hda->init_failed) | 865 | if (chip->disabled || hda->init_failed) |
786 | return 0; | 866 | return 0; |
787 | 867 | ||
868 | bus = azx_bus(chip); | ||
788 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); | 869 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
789 | azx_clear_irq_pending(chip); | 870 | azx_clear_irq_pending(chip); |
790 | azx_stop_chip(chip); | 871 | azx_stop_chip(chip); |
791 | azx_enter_link_reset(chip); | 872 | azx_enter_link_reset(chip); |
792 | if (chip->irq >= 0) { | 873 | if (bus->irq >= 0) { |
793 | free_irq(chip->irq, chip); | 874 | free_irq(bus->irq, chip); |
794 | chip->irq = -1; | 875 | bus->irq = -1; |
795 | } | 876 | } |
796 | 877 | ||
797 | if (chip->msi) | 878 | if (chip->msi) |
798 | pci_disable_msi(chip->pci); | 879 | pci_disable_msi(chip->pci); |
799 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) | 880 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL |
800 | hda_display_power(hda, false); | 881 | && hda->need_i915_power) |
882 | snd_hdac_display_power(bus, false); | ||
883 | |||
884 | trace_azx_suspend(chip); | ||
801 | return 0; | 885 | return 0; |
802 | } | 886 | } |
803 | 887 | ||
@@ -816,8 +900,9 @@ static int azx_resume(struct device *dev) | |||
816 | if (chip->disabled || hda->init_failed) | 900 | if (chip->disabled || hda->init_failed) |
817 | return 0; | 901 | return 0; |
818 | 902 | ||
819 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { | 903 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL |
820 | hda_display_power(hda, true); | 904 | && hda->need_i915_power) { |
905 | snd_hdac_display_power(azx_bus(chip), true); | ||
821 | haswell_set_bclk(hda); | 906 | haswell_set_bclk(hda); |
822 | } | 907 | } |
823 | if (chip->msi) | 908 | if (chip->msi) |
@@ -827,9 +912,11 @@ static int azx_resume(struct device *dev) | |||
827 | return -EIO; | 912 | return -EIO; |
828 | azx_init_pci(chip); | 913 | azx_init_pci(chip); |
829 | 914 | ||
830 | azx_init_chip(chip, true); | 915 | hda_intel_init_chip(chip, true); |
831 | 916 | ||
832 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); | 917 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
918 | |||
919 | trace_azx_resume(chip); | ||
833 | return 0; | 920 | return 0; |
834 | } | 921 | } |
835 | #endif /* CONFIG_PM_SLEEP || SUPPORT_VGA_SWITCHEROO */ | 922 | #endif /* CONFIG_PM_SLEEP || SUPPORT_VGA_SWITCHEROO */ |
@@ -859,9 +946,11 @@ static int azx_runtime_suspend(struct device *dev) | |||
859 | azx_stop_chip(chip); | 946 | azx_stop_chip(chip); |
860 | azx_enter_link_reset(chip); | 947 | azx_enter_link_reset(chip); |
861 | azx_clear_irq_pending(chip); | 948 | azx_clear_irq_pending(chip); |
862 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) | 949 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL |
863 | hda_display_power(hda, false); | 950 | && hda->need_i915_power) |
951 | snd_hdac_display_power(azx_bus(chip), false); | ||
864 | 952 | ||
953 | trace_azx_runtime_suspend(chip); | ||
865 | return 0; | 954 | return 0; |
866 | } | 955 | } |
867 | 956 | ||
@@ -870,7 +959,7 @@ static int azx_runtime_resume(struct device *dev) | |||
870 | struct snd_card *card = dev_get_drvdata(dev); | 959 | struct snd_card *card = dev_get_drvdata(dev); |
871 | struct azx *chip; | 960 | struct azx *chip; |
872 | struct hda_intel *hda; | 961 | struct hda_intel *hda; |
873 | struct hda_bus *bus; | 962 | struct hdac_bus *bus; |
874 | struct hda_codec *codec; | 963 | struct hda_codec *codec; |
875 | int status; | 964 | int status; |
876 | 965 | ||
@@ -885,20 +974,24 @@ static int azx_runtime_resume(struct device *dev) | |||
885 | if (!azx_has_pm_runtime(chip)) | 974 | if (!azx_has_pm_runtime(chip)) |
886 | return 0; | 975 | return 0; |
887 | 976 | ||
888 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { | 977 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL |
889 | hda_display_power(hda, true); | 978 | && hda->need_i915_power) { |
979 | bus = azx_bus(chip); | ||
980 | snd_hdac_display_power(bus, true); | ||
890 | haswell_set_bclk(hda); | 981 | haswell_set_bclk(hda); |
982 | /* toggle codec wakeup bit for STATESTS read */ | ||
983 | snd_hdac_set_codec_wakeup(bus, true); | ||
984 | snd_hdac_set_codec_wakeup(bus, false); | ||
891 | } | 985 | } |
892 | 986 | ||
893 | /* Read STATESTS before controller reset */ | 987 | /* Read STATESTS before controller reset */ |
894 | status = azx_readw(chip, STATESTS); | 988 | status = azx_readw(chip, STATESTS); |
895 | 989 | ||
896 | azx_init_pci(chip); | 990 | azx_init_pci(chip); |
897 | azx_init_chip(chip, true); | 991 | hda_intel_init_chip(chip, true); |
898 | 992 | ||
899 | bus = chip->bus; | 993 | if (status) { |
900 | if (status && bus) { | 994 | list_for_each_codec(codec, &chip->bus) |
901 | list_for_each_codec(codec, bus) | ||
902 | if (status & (1 << codec->addr)) | 995 | if (status & (1 << codec->addr)) |
903 | schedule_delayed_work(&codec->jackpoll_work, | 996 | schedule_delayed_work(&codec->jackpoll_work, |
904 | codec->jackpoll_interval); | 997 | codec->jackpoll_interval); |
@@ -908,6 +1001,7 @@ static int azx_runtime_resume(struct device *dev) | |||
908 | azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) & | 1001 | azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) & |
909 | ~STATESTS_INT_MASK); | 1002 | ~STATESTS_INT_MASK); |
910 | 1003 | ||
1004 | trace_azx_runtime_resume(chip); | ||
911 | return 0; | 1005 | return 0; |
912 | } | 1006 | } |
913 | 1007 | ||
@@ -926,7 +1020,7 @@ static int azx_runtime_idle(struct device *dev) | |||
926 | return 0; | 1020 | return 0; |
927 | 1021 | ||
928 | if (!power_save_controller || !azx_has_pm_runtime(chip) || | 1022 | if (!power_save_controller || !azx_has_pm_runtime(chip) || |
929 | chip->bus->core.codec_powered) | 1023 | azx_bus(chip)->codec_powered) |
930 | return -EBUSY; | 1024 | return -EBUSY; |
931 | 1025 | ||
932 | return 0; | 1026 | return 0; |
@@ -964,7 +1058,7 @@ static void azx_vs_set_state(struct pci_dev *pci, | |||
964 | if (chip->disabled == disabled) | 1058 | if (chip->disabled == disabled) |
965 | return; | 1059 | return; |
966 | 1060 | ||
967 | if (!chip->bus) { | 1061 | if (!hda->probe_continued) { |
968 | chip->disabled = disabled; | 1062 | chip->disabled = disabled; |
969 | if (!disabled) { | 1063 | if (!disabled) { |
970 | dev_info(chip->card->dev, | 1064 | dev_info(chip->card->dev, |
@@ -985,11 +1079,11 @@ static void azx_vs_set_state(struct pci_dev *pci, | |||
985 | * put ourselves there */ | 1079 | * put ourselves there */ |
986 | pci->current_state = PCI_D3cold; | 1080 | pci->current_state = PCI_D3cold; |
987 | chip->disabled = true; | 1081 | chip->disabled = true; |
988 | if (snd_hda_lock_devices(chip->bus)) | 1082 | if (snd_hda_lock_devices(&chip->bus)) |
989 | dev_warn(chip->card->dev, | 1083 | dev_warn(chip->card->dev, |
990 | "Cannot lock devices!\n"); | 1084 | "Cannot lock devices!\n"); |
991 | } else { | 1085 | } else { |
992 | snd_hda_unlock_devices(chip->bus); | 1086 | snd_hda_unlock_devices(&chip->bus); |
993 | pm_runtime_get_noresume(card->dev); | 1087 | pm_runtime_get_noresume(card->dev); |
994 | chip->disabled = false; | 1088 | chip->disabled = false; |
995 | azx_resume(card->dev); | 1089 | azx_resume(card->dev); |
@@ -1006,11 +1100,11 @@ static bool azx_vs_can_switch(struct pci_dev *pci) | |||
1006 | wait_for_completion(&hda->probe_wait); | 1100 | wait_for_completion(&hda->probe_wait); |
1007 | if (hda->init_failed) | 1101 | if (hda->init_failed) |
1008 | return false; | 1102 | return false; |
1009 | if (chip->disabled || !chip->bus) | 1103 | if (chip->disabled || !hda->probe_continued) |
1010 | return true; | 1104 | return true; |
1011 | if (snd_hda_lock_devices(chip->bus)) | 1105 | if (snd_hda_lock_devices(&chip->bus)) |
1012 | return false; | 1106 | return false; |
1013 | snd_hda_unlock_devices(chip->bus); | 1107 | snd_hda_unlock_devices(&chip->bus); |
1014 | return true; | 1108 | return true; |
1015 | } | 1109 | } |
1016 | 1110 | ||
@@ -1043,7 +1137,7 @@ static int register_vga_switcheroo(struct azx *chip) | |||
1043 | */ | 1137 | */ |
1044 | err = vga_switcheroo_register_audio_client(chip->pci, &azx_vs_ops, | 1138 | err = vga_switcheroo_register_audio_client(chip->pci, &azx_vs_ops, |
1045 | VGA_SWITCHEROO_DIS, | 1139 | VGA_SWITCHEROO_DIS, |
1046 | chip->bus != NULL); | 1140 | hda->probe_continued); |
1047 | if (err < 0) | 1141 | if (err < 0) |
1048 | return err; | 1142 | return err; |
1049 | hda->vga_switcheroo_registered = 1; | 1143 | hda->vga_switcheroo_registered = 1; |
@@ -1066,7 +1160,7 @@ static int azx_free(struct azx *chip) | |||
1066 | { | 1160 | { |
1067 | struct pci_dev *pci = chip->pci; | 1161 | struct pci_dev *pci = chip->pci; |
1068 | struct hda_intel *hda = container_of(chip, struct hda_intel, chip); | 1162 | struct hda_intel *hda = container_of(chip, struct hda_intel, chip); |
1069 | int i; | 1163 | struct hdac_bus *bus = azx_bus(chip); |
1070 | 1164 | ||
1071 | if (azx_has_pm_runtime(chip) && chip->running) | 1165 | if (azx_has_pm_runtime(chip) && chip->running) |
1072 | pm_runtime_get_noresume(&pci->dev); | 1166 | pm_runtime_get_noresume(&pci->dev); |
@@ -1077,42 +1171,54 @@ static int azx_free(struct azx *chip) | |||
1077 | complete_all(&hda->probe_wait); | 1171 | complete_all(&hda->probe_wait); |
1078 | 1172 | ||
1079 | if (use_vga_switcheroo(hda)) { | 1173 | if (use_vga_switcheroo(hda)) { |
1080 | if (chip->disabled && chip->bus) | 1174 | if (chip->disabled && hda->probe_continued) |
1081 | snd_hda_unlock_devices(chip->bus); | 1175 | snd_hda_unlock_devices(&chip->bus); |
1082 | if (hda->vga_switcheroo_registered) | 1176 | if (hda->vga_switcheroo_registered) |
1083 | vga_switcheroo_unregister_client(chip->pci); | 1177 | vga_switcheroo_unregister_client(chip->pci); |
1084 | } | 1178 | } |
1085 | 1179 | ||
1086 | if (chip->initialized) { | 1180 | if (bus->chip_init) { |
1087 | azx_clear_irq_pending(chip); | 1181 | azx_clear_irq_pending(chip); |
1088 | for (i = 0; i < chip->num_streams; i++) | 1182 | azx_stop_all_streams(chip); |
1089 | azx_stream_stop(chip, &chip->azx_dev[i]); | ||
1090 | azx_stop_chip(chip); | 1183 | azx_stop_chip(chip); |
1091 | } | 1184 | } |
1092 | 1185 | ||
1093 | if (chip->irq >= 0) | 1186 | if (bus->irq >= 0) |
1094 | free_irq(chip->irq, (void*)chip); | 1187 | free_irq(bus->irq, (void*)chip); |
1095 | if (chip->msi) | 1188 | if (chip->msi) |
1096 | pci_disable_msi(chip->pci); | 1189 | pci_disable_msi(chip->pci); |
1097 | iounmap(chip->remap_addr); | 1190 | iounmap(bus->remap_addr); |
1098 | 1191 | ||
1099 | azx_free_stream_pages(chip); | 1192 | azx_free_stream_pages(chip); |
1193 | azx_free_streams(chip); | ||
1194 | snd_hdac_bus_exit(bus); | ||
1195 | |||
1100 | if (chip->region_requested) | 1196 | if (chip->region_requested) |
1101 | pci_release_regions(chip->pci); | 1197 | pci_release_regions(chip->pci); |
1198 | |||
1102 | pci_disable_device(chip->pci); | 1199 | pci_disable_device(chip->pci); |
1103 | kfree(chip->azx_dev); | ||
1104 | #ifdef CONFIG_SND_HDA_PATCH_LOADER | 1200 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
1105 | release_firmware(chip->fw); | 1201 | release_firmware(chip->fw); |
1106 | #endif | 1202 | #endif |
1203 | |||
1107 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { | 1204 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { |
1108 | hda_display_power(hda, false); | 1205 | if (hda->need_i915_power) |
1109 | hda_i915_exit(hda); | 1206 | snd_hdac_display_power(bus, false); |
1207 | snd_hdac_i915_exit(bus); | ||
1110 | } | 1208 | } |
1111 | kfree(hda); | 1209 | kfree(hda); |
1112 | 1210 | ||
1113 | return 0; | 1211 | return 0; |
1114 | } | 1212 | } |
1115 | 1213 | ||
1214 | static int azx_dev_disconnect(struct snd_device *device) | ||
1215 | { | ||
1216 | struct azx *chip = device->device_data; | ||
1217 | |||
1218 | chip->bus.shutdown = 1; | ||
1219 | return 0; | ||
1220 | } | ||
1221 | |||
1116 | static int azx_dev_free(struct snd_device *device) | 1222 | static int azx_dev_free(struct snd_device *device) |
1117 | { | 1223 | { |
1118 | return azx_free(device->device_data); | 1224 | return azx_free(device->device_data); |
@@ -1279,9 +1385,9 @@ static void check_probe_mask(struct azx *chip, int dev) | |||
1279 | /* check forced option */ | 1385 | /* check forced option */ |
1280 | if (chip->codec_probe_mask != -1 && | 1386 | if (chip->codec_probe_mask != -1 && |
1281 | (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) { | 1387 | (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) { |
1282 | chip->codec_mask = chip->codec_probe_mask & 0xff; | 1388 | azx_bus(chip)->codec_mask = chip->codec_probe_mask & 0xff; |
1283 | dev_info(chip->card->dev, "codec_mask forced to 0x%x\n", | 1389 | dev_info(chip->card->dev, "codec_mask forced to 0x%x\n", |
1284 | chip->codec_mask); | 1390 | (int)azx_bus(chip)->codec_mask); |
1285 | } | 1391 | } |
1286 | } | 1392 | } |
1287 | 1393 | ||
@@ -1368,12 +1474,15 @@ static void azx_probe_work(struct work_struct *work) | |||
1368 | /* | 1474 | /* |
1369 | * constructor | 1475 | * constructor |
1370 | */ | 1476 | */ |
1477 | static const struct hdac_io_ops pci_hda_io_ops; | ||
1478 | static const struct hda_controller_ops pci_hda_ops; | ||
1479 | |||
1371 | static int azx_create(struct snd_card *card, struct pci_dev *pci, | 1480 | static int azx_create(struct snd_card *card, struct pci_dev *pci, |
1372 | int dev, unsigned int driver_caps, | 1481 | int dev, unsigned int driver_caps, |
1373 | const struct hda_controller_ops *hda_ops, | ||
1374 | struct azx **rchip) | 1482 | struct azx **rchip) |
1375 | { | 1483 | { |
1376 | static struct snd_device_ops ops = { | 1484 | static struct snd_device_ops ops = { |
1485 | .dev_disconnect = azx_dev_disconnect, | ||
1377 | .dev_free = azx_dev_free, | 1486 | .dev_free = azx_dev_free, |
1378 | }; | 1487 | }; |
1379 | struct hda_intel *hda; | 1488 | struct hda_intel *hda; |
@@ -1393,12 +1502,10 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci, | |||
1393 | } | 1502 | } |
1394 | 1503 | ||
1395 | chip = &hda->chip; | 1504 | chip = &hda->chip; |
1396 | spin_lock_init(&chip->reg_lock); | ||
1397 | mutex_init(&chip->open_mutex); | 1505 | mutex_init(&chip->open_mutex); |
1398 | chip->card = card; | 1506 | chip->card = card; |
1399 | chip->pci = pci; | 1507 | chip->pci = pci; |
1400 | chip->ops = hda_ops; | 1508 | chip->ops = &pci_hda_ops; |
1401 | chip->irq = -1; | ||
1402 | chip->driver_caps = driver_caps; | 1509 | chip->driver_caps = driver_caps; |
1403 | chip->driver_type = driver_caps & 0xff; | 1510 | chip->driver_type = driver_caps & 0xff; |
1404 | check_msi(chip); | 1511 | check_msi(chip); |
@@ -1430,6 +1537,13 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci, | |||
1430 | } | 1537 | } |
1431 | chip->bdl_pos_adj = bdl_pos_adj; | 1538 | chip->bdl_pos_adj = bdl_pos_adj; |
1432 | 1539 | ||
1540 | err = azx_bus_init(chip, model[dev], &pci_hda_io_ops); | ||
1541 | if (err < 0) { | ||
1542 | kfree(hda); | ||
1543 | pci_disable_device(pci); | ||
1544 | return err; | ||
1545 | } | ||
1546 | |||
1433 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); | 1547 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); |
1434 | if (err < 0) { | 1548 | if (err < 0) { |
1435 | dev_err(card->dev, "Error creating device [card]!\n"); | 1549 | dev_err(card->dev, "Error creating device [card]!\n"); |
@@ -1450,6 +1564,7 @@ static int azx_first_init(struct azx *chip) | |||
1450 | int dev = chip->dev_index; | 1564 | int dev = chip->dev_index; |
1451 | struct pci_dev *pci = chip->pci; | 1565 | struct pci_dev *pci = chip->pci; |
1452 | struct snd_card *card = chip->card; | 1566 | struct snd_card *card = chip->card; |
1567 | struct hdac_bus *bus = azx_bus(chip); | ||
1453 | int err; | 1568 | int err; |
1454 | unsigned short gcap; | 1569 | unsigned short gcap; |
1455 | unsigned int dma_bits = 64; | 1570 | unsigned int dma_bits = 64; |
@@ -1469,9 +1584,9 @@ static int azx_first_init(struct azx *chip) | |||
1469 | return err; | 1584 | return err; |
1470 | chip->region_requested = 1; | 1585 | chip->region_requested = 1; |
1471 | 1586 | ||
1472 | chip->addr = pci_resource_start(pci, 0); | 1587 | bus->addr = pci_resource_start(pci, 0); |
1473 | chip->remap_addr = pci_ioremap_bar(pci, 0); | 1588 | bus->remap_addr = pci_ioremap_bar(pci, 0); |
1474 | if (chip->remap_addr == NULL) { | 1589 | if (bus->remap_addr == NULL) { |
1475 | dev_err(card->dev, "ioremap error\n"); | 1590 | dev_err(card->dev, "ioremap error\n"); |
1476 | return -ENXIO; | 1591 | return -ENXIO; |
1477 | } | 1592 | } |
@@ -1489,7 +1604,7 @@ static int azx_first_init(struct azx *chip) | |||
1489 | return -EBUSY; | 1604 | return -EBUSY; |
1490 | 1605 | ||
1491 | pci_set_master(pci); | 1606 | pci_set_master(pci); |
1492 | synchronize_irq(chip->irq); | 1607 | synchronize_irq(bus->irq); |
1493 | 1608 | ||
1494 | gcap = azx_readw(chip, GCAP); | 1609 | gcap = azx_readw(chip, GCAP); |
1495 | dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap); | 1610 | dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap); |
@@ -1531,11 +1646,11 @@ static int azx_first_init(struct azx *chip) | |||
1531 | /* allow 64bit DMA address if supported by H/W */ | 1646 | /* allow 64bit DMA address if supported by H/W */ |
1532 | if (!(gcap & AZX_GCAP_64OK)) | 1647 | if (!(gcap & AZX_GCAP_64OK)) |
1533 | dma_bits = 32; | 1648 | dma_bits = 32; |
1534 | if (!pci_set_dma_mask(pci, DMA_BIT_MASK(dma_bits))) { | 1649 | if (!dma_set_mask(&pci->dev, DMA_BIT_MASK(dma_bits))) { |
1535 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(dma_bits)); | 1650 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(dma_bits)); |
1536 | } else { | 1651 | } else { |
1537 | pci_set_dma_mask(pci, DMA_BIT_MASK(32)); | 1652 | dma_set_mask(&pci->dev, DMA_BIT_MASK(32)); |
1538 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)); | 1653 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)); |
1539 | } | 1654 | } |
1540 | 1655 | ||
1541 | /* read number of streams from GCAP register instead of using | 1656 | /* read number of streams from GCAP register instead of using |
@@ -1566,17 +1681,15 @@ static int azx_first_init(struct azx *chip) | |||
1566 | chip->capture_index_offset = 0; | 1681 | chip->capture_index_offset = 0; |
1567 | chip->playback_index_offset = chip->capture_streams; | 1682 | chip->playback_index_offset = chip->capture_streams; |
1568 | chip->num_streams = chip->playback_streams + chip->capture_streams; | 1683 | chip->num_streams = chip->playback_streams + chip->capture_streams; |
1569 | chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev), | ||
1570 | GFP_KERNEL); | ||
1571 | if (!chip->azx_dev) | ||
1572 | return -ENOMEM; | ||
1573 | 1684 | ||
1574 | err = azx_alloc_stream_pages(chip); | 1685 | /* initialize streams */ |
1686 | err = azx_init_streams(chip); | ||
1575 | if (err < 0) | 1687 | if (err < 0) |
1576 | return err; | 1688 | return err; |
1577 | 1689 | ||
1578 | /* initialize streams */ | 1690 | err = azx_alloc_stream_pages(chip); |
1579 | azx_init_stream(chip); | 1691 | if (err < 0) |
1692 | return err; | ||
1580 | 1693 | ||
1581 | /* initialize chip */ | 1694 | /* initialize chip */ |
1582 | azx_init_pci(chip); | 1695 | azx_init_pci(chip); |
@@ -1588,10 +1701,10 @@ static int azx_first_init(struct azx *chip) | |||
1588 | haswell_set_bclk(hda); | 1701 | haswell_set_bclk(hda); |
1589 | } | 1702 | } |
1590 | 1703 | ||
1591 | azx_init_chip(chip, (probe_only[dev] & 2) == 0); | 1704 | hda_intel_init_chip(chip, (probe_only[dev] & 2) == 0); |
1592 | 1705 | ||
1593 | /* codec detection */ | 1706 | /* codec detection */ |
1594 | if (!chip->codec_mask) { | 1707 | if (!azx_bus(chip)->codec_mask) { |
1595 | dev_err(card->dev, "no codecs found!\n"); | 1708 | dev_err(card->dev, "no codecs found!\n"); |
1596 | return -ENODEV; | 1709 | return -ENODEV; |
1597 | } | 1710 | } |
@@ -1601,7 +1714,7 @@ static int azx_first_init(struct azx *chip) | |||
1601 | sizeof(card->shortname)); | 1714 | sizeof(card->shortname)); |
1602 | snprintf(card->longname, sizeof(card->longname), | 1715 | snprintf(card->longname, sizeof(card->longname), |
1603 | "%s at 0x%lx irq %i", | 1716 | "%s at 0x%lx irq %i", |
1604 | card->shortname, chip->addr, chip->irq); | 1717 | card->shortname, bus->addr, bus->irq); |
1605 | 1718 | ||
1606 | return 0; | 1719 | return 0; |
1607 | } | 1720 | } |
@@ -1670,10 +1783,11 @@ static u8 pci_azx_readb(u8 __iomem *addr) | |||
1670 | 1783 | ||
1671 | static int disable_msi_reset_irq(struct azx *chip) | 1784 | static int disable_msi_reset_irq(struct azx *chip) |
1672 | { | 1785 | { |
1786 | struct hdac_bus *bus = azx_bus(chip); | ||
1673 | int err; | 1787 | int err; |
1674 | 1788 | ||
1675 | free_irq(chip->irq, chip); | 1789 | free_irq(bus->irq, chip); |
1676 | chip->irq = -1; | 1790 | bus->irq = -1; |
1677 | pci_disable_msi(chip->pci); | 1791 | pci_disable_msi(chip->pci); |
1678 | chip->msi = 0; | 1792 | chip->msi = 0; |
1679 | err = azx_acquire_irq(chip, 1); | 1793 | err = azx_acquire_irq(chip, 1); |
@@ -1684,15 +1798,16 @@ static int disable_msi_reset_irq(struct azx *chip) | |||
1684 | } | 1798 | } |
1685 | 1799 | ||
1686 | /* DMA page allocation helpers. */ | 1800 | /* DMA page allocation helpers. */ |
1687 | static int dma_alloc_pages(struct azx *chip, | 1801 | static int dma_alloc_pages(struct hdac_bus *bus, |
1688 | int type, | 1802 | int type, |
1689 | size_t size, | 1803 | size_t size, |
1690 | struct snd_dma_buffer *buf) | 1804 | struct snd_dma_buffer *buf) |
1691 | { | 1805 | { |
1806 | struct azx *chip = bus_to_azx(bus); | ||
1692 | int err; | 1807 | int err; |
1693 | 1808 | ||
1694 | err = snd_dma_alloc_pages(type, | 1809 | err = snd_dma_alloc_pages(type, |
1695 | chip->card->dev, | 1810 | bus->dev, |
1696 | size, buf); | 1811 | size, buf); |
1697 | if (err < 0) | 1812 | if (err < 0) |
1698 | return err; | 1813 | return err; |
@@ -1700,8 +1815,10 @@ static int dma_alloc_pages(struct azx *chip, | |||
1700 | return 0; | 1815 | return 0; |
1701 | } | 1816 | } |
1702 | 1817 | ||
1703 | static void dma_free_pages(struct azx *chip, struct snd_dma_buffer *buf) | 1818 | static void dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf) |
1704 | { | 1819 | { |
1820 | struct azx *chip = bus_to_azx(bus); | ||
1821 | |||
1705 | mark_pages_wc(chip, buf, false); | 1822 | mark_pages_wc(chip, buf, false); |
1706 | snd_dma_free_pages(buf); | 1823 | snd_dma_free_pages(buf); |
1707 | } | 1824 | } |
@@ -1714,9 +1831,6 @@ static int substream_alloc_pages(struct azx *chip, | |||
1714 | int ret; | 1831 | int ret; |
1715 | 1832 | ||
1716 | mark_runtime_wc(chip, azx_dev, substream, false); | 1833 | mark_runtime_wc(chip, azx_dev, substream, false); |
1717 | azx_dev->bufsize = 0; | ||
1718 | azx_dev->period_bytes = 0; | ||
1719 | azx_dev->format_val = 0; | ||
1720 | ret = snd_pcm_lib_malloc_pages(substream, size); | 1834 | ret = snd_pcm_lib_malloc_pages(substream, size); |
1721 | if (ret < 0) | 1835 | if (ret < 0) |
1722 | return ret; | 1836 | return ret; |
@@ -1743,20 +1857,24 @@ static void pcm_mmap_prepare(struct snd_pcm_substream *substream, | |||
1743 | #endif | 1857 | #endif |
1744 | } | 1858 | } |
1745 | 1859 | ||
1746 | static const struct hda_controller_ops pci_hda_ops = { | 1860 | static const struct hdac_io_ops pci_hda_io_ops = { |
1747 | .reg_writel = pci_azx_writel, | 1861 | .reg_writel = pci_azx_writel, |
1748 | .reg_readl = pci_azx_readl, | 1862 | .reg_readl = pci_azx_readl, |
1749 | .reg_writew = pci_azx_writew, | 1863 | .reg_writew = pci_azx_writew, |
1750 | .reg_readw = pci_azx_readw, | 1864 | .reg_readw = pci_azx_readw, |
1751 | .reg_writeb = pci_azx_writeb, | 1865 | .reg_writeb = pci_azx_writeb, |
1752 | .reg_readb = pci_azx_readb, | 1866 | .reg_readb = pci_azx_readb, |
1753 | .disable_msi_reset_irq = disable_msi_reset_irq, | ||
1754 | .dma_alloc_pages = dma_alloc_pages, | 1867 | .dma_alloc_pages = dma_alloc_pages, |
1755 | .dma_free_pages = dma_free_pages, | 1868 | .dma_free_pages = dma_free_pages, |
1869 | }; | ||
1870 | |||
1871 | static const struct hda_controller_ops pci_hda_ops = { | ||
1872 | .disable_msi_reset_irq = disable_msi_reset_irq, | ||
1756 | .substream_alloc_pages = substream_alloc_pages, | 1873 | .substream_alloc_pages = substream_alloc_pages, |
1757 | .substream_free_pages = substream_free_pages, | 1874 | .substream_free_pages = substream_free_pages, |
1758 | .pcm_mmap_prepare = pcm_mmap_prepare, | 1875 | .pcm_mmap_prepare = pcm_mmap_prepare, |
1759 | .position_check = azx_position_check, | 1876 | .position_check = azx_position_check, |
1877 | .link_power = azx_intel_link_power, | ||
1760 | }; | 1878 | }; |
1761 | 1879 | ||
1762 | static int azx_probe(struct pci_dev *pci, | 1880 | static int azx_probe(struct pci_dev *pci, |
@@ -1783,8 +1901,7 @@ static int azx_probe(struct pci_dev *pci, | |||
1783 | return err; | 1901 | return err; |
1784 | } | 1902 | } |
1785 | 1903 | ||
1786 | err = azx_create(card, pci, dev, pci_id->driver_data, | 1904 | err = azx_create(card, pci, dev, pci_id->driver_data, &chip); |
1787 | &pci_hda_ops, &chip); | ||
1788 | if (err < 0) | 1905 | if (err < 0) |
1789 | goto out_free; | 1906 | goto out_free; |
1790 | card->private_data = chip; | 1907 | card->private_data = chip; |
@@ -1846,23 +1963,33 @@ static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] = { | |||
1846 | static int azx_probe_continue(struct azx *chip) | 1963 | static int azx_probe_continue(struct azx *chip) |
1847 | { | 1964 | { |
1848 | struct hda_intel *hda = container_of(chip, struct hda_intel, chip); | 1965 | struct hda_intel *hda = container_of(chip, struct hda_intel, chip); |
1966 | struct hdac_bus *bus = azx_bus(chip); | ||
1849 | struct pci_dev *pci = chip->pci; | 1967 | struct pci_dev *pci = chip->pci; |
1850 | int dev = chip->dev_index; | 1968 | int dev = chip->dev_index; |
1851 | int err; | 1969 | int err; |
1852 | 1970 | ||
1853 | /* Request power well for Haswell HDA controller and codec */ | 1971 | hda->probe_continued = 1; |
1972 | |||
1973 | /* Request display power well for the HDA controller or codec. For | ||
1974 | * Haswell/Broadwell, both the display HDA controller and codec need | ||
1975 | * this power. For other platforms, like Baytrail/Braswell, only the | ||
1976 | * display codec needs the power and it can be released after probe. | ||
1977 | */ | ||
1854 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { | 1978 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { |
1855 | #ifdef CONFIG_SND_HDA_I915 | 1979 | /* Baytral/Braswell controllers don't need this power */ |
1856 | err = hda_i915_init(hda); | 1980 | if (pci->device != 0x0f04 && pci->device != 0x2284) |
1981 | hda->need_i915_power = 1; | ||
1982 | |||
1983 | err = snd_hdac_i915_init(bus); | ||
1857 | if (err < 0) | 1984 | if (err < 0) |
1858 | goto out_free; | 1985 | goto i915_power_fail; |
1859 | err = hda_display_power(hda, true); | 1986 | |
1987 | err = snd_hdac_display_power(bus, true); | ||
1860 | if (err < 0) { | 1988 | if (err < 0) { |
1861 | dev_err(chip->card->dev, | 1989 | dev_err(chip->card->dev, |
1862 | "Cannot turn on display power on i915\n"); | 1990 | "Cannot turn on display power on i915\n"); |
1863 | goto out_free; | 1991 | goto i915_power_fail; |
1864 | } | 1992 | } |
1865 | #endif | ||
1866 | } | 1993 | } |
1867 | 1994 | ||
1868 | err = azx_first_init(chip); | 1995 | err = azx_first_init(chip); |
@@ -1874,17 +2001,13 @@ static int azx_probe_continue(struct azx *chip) | |||
1874 | #endif | 2001 | #endif |
1875 | 2002 | ||
1876 | /* create codec instances */ | 2003 | /* create codec instances */ |
1877 | err = azx_bus_create(chip, model[dev]); | ||
1878 | if (err < 0) | ||
1879 | goto out_free; | ||
1880 | |||
1881 | err = azx_probe_codecs(chip, azx_max_codecs[chip->driver_type]); | 2004 | err = azx_probe_codecs(chip, azx_max_codecs[chip->driver_type]); |
1882 | if (err < 0) | 2005 | if (err < 0) |
1883 | goto out_free; | 2006 | goto out_free; |
1884 | 2007 | ||
1885 | #ifdef CONFIG_SND_HDA_PATCH_LOADER | 2008 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
1886 | if (chip->fw) { | 2009 | if (chip->fw) { |
1887 | err = snd_hda_load_patch(chip->bus, chip->fw->size, | 2010 | err = snd_hda_load_patch(&chip->bus, chip->fw->size, |
1888 | chip->fw->data); | 2011 | chip->fw->data); |
1889 | if (err < 0) | 2012 | if (err < 0) |
1890 | goto out_free; | 2013 | goto out_free; |
@@ -1906,11 +2029,16 @@ static int azx_probe_continue(struct azx *chip) | |||
1906 | 2029 | ||
1907 | chip->running = 1; | 2030 | chip->running = 1; |
1908 | azx_add_card_list(chip); | 2031 | azx_add_card_list(chip); |
1909 | snd_hda_set_power_save(chip->bus, power_save * 1000); | 2032 | snd_hda_set_power_save(&chip->bus, power_save * 1000); |
1910 | if (azx_has_pm_runtime(chip) || hda->use_vga_switcheroo) | 2033 | if (azx_has_pm_runtime(chip) || hda->use_vga_switcheroo) |
1911 | pm_runtime_put_noidle(&pci->dev); | 2034 | pm_runtime_put_noidle(&pci->dev); |
1912 | 2035 | ||
1913 | out_free: | 2036 | out_free: |
2037 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL | ||
2038 | && !hda->need_i915_power) | ||
2039 | snd_hdac_display_power(bus, false); | ||
2040 | |||
2041 | i915_power_fail: | ||
1914 | if (err < 0) | 2042 | if (err < 0) |
1915 | hda->init_failed = 1; | 2043 | hda->init_failed = 1; |
1916 | complete_all(&hda->probe_wait); | 2044 | complete_all(&hda->probe_wait); |
diff --git a/sound/pci/hda/hda_intel.h b/sound/pci/hda/hda_intel.h index d5231f7216a7..354f0bbed833 100644 --- a/sound/pci/hda/hda_intel.h +++ b/sound/pci/hda/hda_intel.h | |||
@@ -16,7 +16,6 @@ | |||
16 | #ifndef __SOUND_HDA_INTEL_H | 16 | #ifndef __SOUND_HDA_INTEL_H |
17 | #define __SOUND_HDA_INTEL_H | 17 | #define __SOUND_HDA_INTEL_H |
18 | 18 | ||
19 | #include <drm/i915_component.h> | ||
20 | #include "hda_controller.h" | 19 | #include "hda_controller.h" |
21 | 20 | ||
22 | struct hda_intel { | 21 | struct hda_intel { |
@@ -34,6 +33,7 @@ struct hda_intel { | |||
34 | 33 | ||
35 | /* extra flags */ | 34 | /* extra flags */ |
36 | unsigned int irq_pending_warned:1; | 35 | unsigned int irq_pending_warned:1; |
36 | unsigned int probe_continued:1; | ||
37 | 37 | ||
38 | /* VGA-switcheroo setup */ | 38 | /* VGA-switcheroo setup */ |
39 | unsigned int use_vga_switcheroo:1; | 39 | unsigned int use_vga_switcheroo:1; |
@@ -43,29 +43,7 @@ struct hda_intel { | |||
43 | /* secondary power domain for hdmi audio under vga device */ | 43 | /* secondary power domain for hdmi audio under vga device */ |
44 | struct dev_pm_domain hdmi_pm_domain; | 44 | struct dev_pm_domain hdmi_pm_domain; |
45 | 45 | ||
46 | /* i915 component interface */ | 46 | bool need_i915_power:1; /* the hda controller needs i915 power */ |
47 | struct i915_audio_component audio_component; | ||
48 | }; | 47 | }; |
49 | 48 | ||
50 | #ifdef CONFIG_SND_HDA_I915 | ||
51 | int hda_display_power(struct hda_intel *hda, bool enable); | ||
52 | void haswell_set_bclk(struct hda_intel *hda); | ||
53 | int hda_i915_init(struct hda_intel *hda); | ||
54 | int hda_i915_exit(struct hda_intel *hda); | ||
55 | #else | ||
56 | static inline int hda_display_power(struct hda_intel *hda, bool enable) | ||
57 | { | ||
58 | return 0; | ||
59 | } | ||
60 | static inline void haswell_set_bclk(struct hda_intel *hda) { return; } | ||
61 | static inline int hda_i915_init(struct hda_intel *hda) | ||
62 | { | ||
63 | return -ENODEV; | ||
64 | } | ||
65 | static inline int hda_i915_exit(struct hda_intel *hda) | ||
66 | { | ||
67 | return 0; | ||
68 | } | ||
69 | #endif | ||
70 | |||
71 | #endif | 49 | #endif |
diff --git a/sound/pci/hda/hda_intel_trace.h b/sound/pci/hda/hda_intel_trace.h index 7b5e4c2cf9d5..0922d8b1b17d 100644 --- a/sound/pci/hda/hda_intel_trace.h +++ b/sound/pci/hda/hda_intel_trace.h | |||
@@ -7,52 +7,43 @@ | |||
7 | 7 | ||
8 | #include <linux/tracepoint.h> | 8 | #include <linux/tracepoint.h> |
9 | 9 | ||
10 | struct azx; | 10 | DECLARE_EVENT_CLASS(hda_pm, |
11 | struct azx_dev; | 11 | TP_PROTO(struct azx *chip), |
12 | 12 | ||
13 | TRACE_EVENT(azx_pcm_trigger, | 13 | TP_ARGS(chip), |
14 | |||
15 | TP_PROTO(struct azx *chip, struct azx_dev *dev, int cmd), | ||
16 | |||
17 | TP_ARGS(chip, dev, cmd), | ||
18 | 14 | ||
19 | TP_STRUCT__entry( | 15 | TP_STRUCT__entry( |
20 | __field( int, card ) | 16 | __field(int, dev_index) |
21 | __field( int, idx ) | ||
22 | __field( int, cmd ) | ||
23 | ), | 17 | ), |
24 | 18 | ||
25 | TP_fast_assign( | 19 | TP_fast_assign( |
26 | __entry->card = (chip)->card->number; | 20 | __entry->dev_index = (chip)->dev_index; |
27 | __entry->idx = (dev)->index; | ||
28 | __entry->cmd = cmd; | ||
29 | ), | 21 | ), |
30 | 22 | ||
31 | TP_printk("[%d:%d] cmd=%d", __entry->card, __entry->idx, __entry->cmd) | 23 | TP_printk("card index: %d", __entry->dev_index) |
32 | ); | 24 | ); |
33 | 25 | ||
34 | TRACE_EVENT(azx_get_position, | 26 | DEFINE_EVENT(hda_pm, azx_suspend, |
35 | 27 | TP_PROTO(struct azx *chip), | |
36 | TP_PROTO(struct azx *chip, struct azx_dev *dev, unsigned int pos, unsigned int delay), | 28 | TP_ARGS(chip) |
37 | 29 | ); | |
38 | TP_ARGS(chip, dev, pos, delay), | ||
39 | 30 | ||
40 | TP_STRUCT__entry( | 31 | DEFINE_EVENT(hda_pm, azx_resume, |
41 | __field( int, card ) | 32 | TP_PROTO(struct azx *chip), |
42 | __field( int, idx ) | 33 | TP_ARGS(chip) |
43 | __field( unsigned int, pos ) | 34 | ); |
44 | __field( unsigned int, delay ) | ||
45 | ), | ||
46 | 35 | ||
47 | TP_fast_assign( | 36 | #ifdef CONFIG_PM |
48 | __entry->card = (chip)->card->number; | 37 | DEFINE_EVENT(hda_pm, azx_runtime_suspend, |
49 | __entry->idx = (dev)->index; | 38 | TP_PROTO(struct azx *chip), |
50 | __entry->pos = pos; | 39 | TP_ARGS(chip) |
51 | __entry->delay = delay; | 40 | ); |
52 | ), | ||
53 | 41 | ||
54 | TP_printk("[%d:%d] pos=%u, delay=%u", __entry->card, __entry->idx, __entry->pos, __entry->delay) | 42 | DEFINE_EVENT(hda_pm, azx_runtime_resume, |
43 | TP_PROTO(struct azx *chip), | ||
44 | TP_ARGS(chip) | ||
55 | ); | 45 | ); |
46 | #endif | ||
56 | 47 | ||
57 | #endif /* _TRACE_HDA_INTEL_H */ | 48 | #endif /* _TRACE_HDA_INTEL_H */ |
58 | 49 | ||
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c index d7cfe7b8c32b..366efbf87d41 100644 --- a/sound/pci/hda/hda_jack.c +++ b/sound/pci/hda/hda_jack.c | |||
@@ -132,11 +132,11 @@ void snd_hda_jack_tbl_clear(struct hda_codec *codec) | |||
132 | 132 | ||
133 | for (i = 0; i < codec->jacktbl.used; i++, jack++) { | 133 | for (i = 0; i < codec->jacktbl.used; i++, jack++) { |
134 | struct hda_jack_callback *cb, *next; | 134 | struct hda_jack_callback *cb, *next; |
135 | #ifdef CONFIG_SND_HDA_INPUT_JACK | 135 | |
136 | /* free jack instances manually when clearing/reconfiguring */ | 136 | /* free jack instances manually when clearing/reconfiguring */ |
137 | if (!codec->bus->shutdown && jack->jack) | 137 | if (!codec->bus->shutdown && jack->jack) |
138 | snd_device_free(codec->card, jack->jack); | 138 | snd_device_free(codec->card, jack->jack); |
139 | #endif | 139 | |
140 | for (cb = jack->callback; cb; cb = next) { | 140 | for (cb = jack->callback; cb; cb = next) { |
141 | next = cb->next; | 141 | next = cb->next; |
142 | kfree(cb); | 142 | kfree(cb); |
@@ -337,20 +337,15 @@ void snd_hda_jack_report_sync(struct hda_codec *codec) | |||
337 | jack = codec->jacktbl.list; | 337 | jack = codec->jacktbl.list; |
338 | for (i = 0; i < codec->jacktbl.used; i++, jack++) | 338 | for (i = 0; i < codec->jacktbl.used; i++, jack++) |
339 | if (jack->nid) { | 339 | if (jack->nid) { |
340 | if (!jack->kctl || jack->block_report) | 340 | if (!jack->jack || jack->block_report) |
341 | continue; | 341 | continue; |
342 | state = get_jack_plug_state(jack->pin_sense); | 342 | state = get_jack_plug_state(jack->pin_sense); |
343 | snd_kctl_jack_report(codec->card, jack->kctl, state); | 343 | snd_jack_report(jack->jack, |
344 | #ifdef CONFIG_SND_HDA_INPUT_JACK | 344 | state ? jack->type : 0); |
345 | if (jack->jack) | ||
346 | snd_jack_report(jack->jack, | ||
347 | state ? jack->type : 0); | ||
348 | #endif | ||
349 | } | 345 | } |
350 | } | 346 | } |
351 | EXPORT_SYMBOL_GPL(snd_hda_jack_report_sync); | 347 | EXPORT_SYMBOL_GPL(snd_hda_jack_report_sync); |
352 | 348 | ||
353 | #ifdef CONFIG_SND_HDA_INPUT_JACK | ||
354 | /* guess the jack type from the pin-config */ | 349 | /* guess the jack type from the pin-config */ |
355 | static int get_input_jack_type(struct hda_codec *codec, hda_nid_t nid) | 350 | static int get_input_jack_type(struct hda_codec *codec, hda_nid_t nid) |
356 | { | 351 | { |
@@ -377,54 +372,42 @@ static void hda_free_jack_priv(struct snd_jack *jack) | |||
377 | jacks->nid = 0; | 372 | jacks->nid = 0; |
378 | jacks->jack = NULL; | 373 | jacks->jack = NULL; |
379 | } | 374 | } |
380 | #endif | ||
381 | 375 | ||
382 | /** | 376 | /** |
383 | * snd_hda_jack_add_kctl - Add a kctl for the given pin | 377 | * snd_hda_jack_add_kctl - Add a kctl for the given pin |
384 | * @codec: the HDA codec | 378 | * @codec: the HDA codec |
385 | * @nid: pin NID to assign | 379 | * @nid: pin NID to assign |
386 | * @name: string name for the jack | 380 | * @name: string name for the jack |
387 | * @idx: index number for the jack | ||
388 | * @phantom_jack: flag to deal as a phantom jack | 381 | * @phantom_jack: flag to deal as a phantom jack |
389 | * | 382 | * |
390 | * This assigns a jack-detection kctl to the given pin. The kcontrol | 383 | * This assigns a jack-detection kctl to the given pin. The kcontrol |
391 | * will have the given name and index. | 384 | * will have the given name and index. |
392 | */ | 385 | */ |
393 | static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, | 386 | static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, |
394 | const char *name, int idx, bool phantom_jack) | 387 | const char *name, bool phantom_jack) |
395 | { | 388 | { |
396 | struct hda_jack_tbl *jack; | 389 | struct hda_jack_tbl *jack; |
397 | struct snd_kcontrol *kctl; | 390 | int err, state, type; |
398 | int err, state; | ||
399 | 391 | ||
400 | jack = snd_hda_jack_tbl_new(codec, nid); | 392 | jack = snd_hda_jack_tbl_new(codec, nid); |
401 | if (!jack) | 393 | if (!jack) |
402 | return 0; | 394 | return 0; |
403 | if (jack->kctl) | 395 | if (jack->jack) |
404 | return 0; /* already created */ | 396 | return 0; /* already created */ |
405 | kctl = snd_kctl_jack_new(name, idx, codec); | 397 | |
406 | if (!kctl) | 398 | type = get_input_jack_type(codec, nid); |
407 | return -ENOMEM; | 399 | err = snd_jack_new(codec->card, name, type, |
408 | err = snd_hda_ctl_add(codec, nid, kctl); | 400 | &jack->jack, true, phantom_jack); |
409 | if (err < 0) | 401 | if (err < 0) |
410 | return err; | 402 | return err; |
411 | jack->kctl = kctl; | ||
412 | jack->phantom_jack = !!phantom_jack; | ||
413 | 403 | ||
404 | jack->phantom_jack = !!phantom_jack; | ||
405 | jack->type = type; | ||
406 | jack->jack->private_data = jack; | ||
407 | jack->jack->private_free = hda_free_jack_priv; | ||
414 | state = snd_hda_jack_detect(codec, nid); | 408 | state = snd_hda_jack_detect(codec, nid); |
415 | snd_kctl_jack_report(codec->card, kctl, state); | 409 | snd_jack_report(jack->jack, state ? jack->type : 0); |
416 | #ifdef CONFIG_SND_HDA_INPUT_JACK | 410 | |
417 | if (!phantom_jack) { | ||
418 | jack->type = get_input_jack_type(codec, nid); | ||
419 | err = snd_jack_new(codec->card, name, jack->type, | ||
420 | &jack->jack); | ||
421 | if (err < 0) | ||
422 | return err; | ||
423 | jack->jack->private_data = jack; | ||
424 | jack->jack->private_free = hda_free_jack_priv; | ||
425 | snd_jack_report(jack->jack, state ? jack->type : 0); | ||
426 | } | ||
427 | #endif | ||
428 | return 0; | 411 | return 0; |
429 | } | 412 | } |
430 | 413 | ||
@@ -433,44 +416,23 @@ static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, | |||
433 | * @codec: the HDA codec | 416 | * @codec: the HDA codec |
434 | * @nid: pin NID | 417 | * @nid: pin NID |
435 | * @name: the name string for the jack ctl | 418 | * @name: the name string for the jack ctl |
436 | * @idx: the ctl index for the jack ctl | ||
437 | * | 419 | * |
438 | * This is a simple helper calling __snd_hda_jack_add_kctl(). | 420 | * This is a simple helper calling __snd_hda_jack_add_kctl(). |
439 | */ | 421 | */ |
440 | int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, | 422 | int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, |
441 | const char *name, int idx) | 423 | const char *name) |
442 | { | 424 | { |
443 | return __snd_hda_jack_add_kctl(codec, nid, name, idx, false); | 425 | return __snd_hda_jack_add_kctl(codec, nid, name, false); |
444 | } | 426 | } |
445 | EXPORT_SYMBOL_GPL(snd_hda_jack_add_kctl); | 427 | EXPORT_SYMBOL_GPL(snd_hda_jack_add_kctl); |
446 | 428 | ||
447 | /* get the unique index number for the given kctl name */ | ||
448 | static int get_unique_index(struct hda_codec *codec, const char *name, int idx) | ||
449 | { | ||
450 | struct hda_jack_tbl *jack; | ||
451 | int i, len = strlen(name); | ||
452 | again: | ||
453 | jack = codec->jacktbl.list; | ||
454 | for (i = 0; i < codec->jacktbl.used; i++, jack++) { | ||
455 | /* jack->kctl.id contains "XXX Jack" name string with index */ | ||
456 | if (jack->kctl && | ||
457 | !strncmp(name, jack->kctl->id.name, len) && | ||
458 | !strcmp(" Jack", jack->kctl->id.name + len) && | ||
459 | jack->kctl->id.index == idx) { | ||
460 | idx++; | ||
461 | goto again; | ||
462 | } | ||
463 | } | ||
464 | return idx; | ||
465 | } | ||
466 | |||
467 | static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid, | 429 | static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid, |
468 | const struct auto_pin_cfg *cfg, | 430 | const struct auto_pin_cfg *cfg, |
469 | const char *base_name) | 431 | const char *base_name) |
470 | { | 432 | { |
471 | unsigned int def_conf, conn; | 433 | unsigned int def_conf, conn; |
472 | char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; | 434 | char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; |
473 | int idx, err; | 435 | int err; |
474 | bool phantom_jack; | 436 | bool phantom_jack; |
475 | 437 | ||
476 | if (!nid) | 438 | if (!nid) |
@@ -482,16 +444,14 @@ static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid, | |||
482 | phantom_jack = (conn != AC_JACK_PORT_COMPLEX) || | 444 | phantom_jack = (conn != AC_JACK_PORT_COMPLEX) || |
483 | !is_jack_detectable(codec, nid); | 445 | !is_jack_detectable(codec, nid); |
484 | 446 | ||
485 | if (base_name) { | 447 | if (base_name) |
486 | strlcpy(name, base_name, sizeof(name)); | 448 | strlcpy(name, base_name, sizeof(name)); |
487 | idx = 0; | 449 | else |
488 | } else | 450 | snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), NULL); |
489 | snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), &idx); | ||
490 | if (phantom_jack) | 451 | if (phantom_jack) |
491 | /* Example final name: "Internal Mic Phantom Jack" */ | 452 | /* Example final name: "Internal Mic Phantom Jack" */ |
492 | strncat(name, " Phantom", sizeof(name) - strlen(name) - 1); | 453 | strncat(name, " Phantom", sizeof(name) - strlen(name) - 1); |
493 | idx = get_unique_index(codec, name, idx); | 454 | err = __snd_hda_jack_add_kctl(codec, nid, name, phantom_jack); |
494 | err = __snd_hda_jack_add_kctl(codec, nid, name, idx, phantom_jack); | ||
495 | if (err < 0) | 455 | if (err < 0) |
496 | return err; | 456 | return err; |
497 | 457 | ||
diff --git a/sound/pci/hda/hda_jack.h b/sound/pci/hda/hda_jack.h index b279e327a23b..387d30984dfe 100644 --- a/sound/pci/hda/hda_jack.h +++ b/sound/pci/hda/hda_jack.h | |||
@@ -39,11 +39,8 @@ struct hda_jack_tbl { | |||
39 | unsigned int block_report:1; /* in a transitional state - do not report to userspace */ | 39 | unsigned int block_report:1; /* in a transitional state - do not report to userspace */ |
40 | hda_nid_t gating_jack; /* valid when gating jack plugged */ | 40 | hda_nid_t gating_jack; /* valid when gating jack plugged */ |
41 | hda_nid_t gated_jack; /* gated is dependent on this jack */ | 41 | hda_nid_t gated_jack; /* gated is dependent on this jack */ |
42 | struct snd_kcontrol *kctl; /* assigned kctl for jack-detection */ | ||
43 | #ifdef CONFIG_SND_HDA_INPUT_JACK | ||
44 | int type; | 42 | int type; |
45 | struct snd_jack *jack; | 43 | struct snd_jack *jack; |
46 | #endif | ||
47 | }; | 44 | }; |
48 | 45 | ||
49 | struct hda_jack_tbl * | 46 | struct hda_jack_tbl * |
@@ -85,7 +82,7 @@ static inline bool snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid) | |||
85 | bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid); | 82 | bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid); |
86 | 83 | ||
87 | int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, | 84 | int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, |
88 | const char *name, int idx); | 85 | const char *name); |
89 | int snd_hda_jack_add_kctls(struct hda_codec *codec, | 86 | int snd_hda_jack_add_kctls(struct hda_codec *codec, |
90 | const struct auto_pin_cfg *cfg); | 87 | const struct auto_pin_cfg *cfg); |
91 | 88 | ||
diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c index 2e4fd5c56d3b..477742cb70a2 100644 --- a/sound/pci/hda/hda_tegra.c +++ b/sound/pci/hda/hda_tegra.c | |||
@@ -87,13 +87,13 @@ MODULE_PARM_DESC(power_save, | |||
87 | /* | 87 | /* |
88 | * DMA page allocation ops. | 88 | * DMA page allocation ops. |
89 | */ | 89 | */ |
90 | static int dma_alloc_pages(struct azx *chip, int type, size_t size, | 90 | static int dma_alloc_pages(struct hdac_bus *bus, int type, size_t size, |
91 | struct snd_dma_buffer *buf) | 91 | struct snd_dma_buffer *buf) |
92 | { | 92 | { |
93 | return snd_dma_alloc_pages(type, chip->card->dev, size, buf); | 93 | return snd_dma_alloc_pages(type, bus->dev, size, buf); |
94 | } | 94 | } |
95 | 95 | ||
96 | static void dma_free_pages(struct azx *chip, struct snd_dma_buffer *buf) | 96 | static void dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf) |
97 | { | 97 | { |
98 | snd_dma_free_pages(buf); | 98 | snd_dma_free_pages(buf); |
99 | } | 99 | } |
@@ -102,11 +102,6 @@ static int substream_alloc_pages(struct azx *chip, | |||
102 | struct snd_pcm_substream *substream, | 102 | struct snd_pcm_substream *substream, |
103 | size_t size) | 103 | size_t size) |
104 | { | 104 | { |
105 | struct azx_dev *azx_dev = get_azx_dev(substream); | ||
106 | |||
107 | azx_dev->bufsize = 0; | ||
108 | azx_dev->period_bytes = 0; | ||
109 | azx_dev->format_val = 0; | ||
110 | return snd_pcm_lib_malloc_pages(substream, size); | 105 | return snd_pcm_lib_malloc_pages(substream, size); |
111 | } | 106 | } |
112 | 107 | ||
@@ -173,7 +168,7 @@ static u8 hda_tegra_readb(u8 *addr) | |||
173 | return (v >> shift) & 0xff; | 168 | return (v >> shift) & 0xff; |
174 | } | 169 | } |
175 | 170 | ||
176 | static const struct hda_controller_ops hda_tegra_ops = { | 171 | static const struct hdac_io_ops hda_tegra_io_ops = { |
177 | .reg_writel = hda_tegra_writel, | 172 | .reg_writel = hda_tegra_writel, |
178 | .reg_readl = hda_tegra_readl, | 173 | .reg_readl = hda_tegra_readl, |
179 | .reg_writew = hda_tegra_writew, | 174 | .reg_writew = hda_tegra_writew, |
@@ -182,6 +177,9 @@ static const struct hda_controller_ops hda_tegra_ops = { | |||
182 | .reg_readb = hda_tegra_readb, | 177 | .reg_readb = hda_tegra_readb, |
183 | .dma_alloc_pages = dma_alloc_pages, | 178 | .dma_alloc_pages = dma_alloc_pages, |
184 | .dma_free_pages = dma_free_pages, | 179 | .dma_free_pages = dma_free_pages, |
180 | }; | ||
181 | |||
182 | static const struct hda_controller_ops hda_tegra_ops = { | ||
185 | .substream_alloc_pages = substream_alloc_pages, | 183 | .substream_alloc_pages = substream_alloc_pages, |
186 | .substream_free_pages = substream_free_pages, | 184 | .substream_free_pages = substream_free_pages, |
187 | }; | 185 | }; |
@@ -282,21 +280,29 @@ static const struct dev_pm_ops hda_tegra_pm = { | |||
282 | SET_SYSTEM_SLEEP_PM_OPS(hda_tegra_suspend, hda_tegra_resume) | 280 | SET_SYSTEM_SLEEP_PM_OPS(hda_tegra_suspend, hda_tegra_resume) |
283 | }; | 281 | }; |
284 | 282 | ||
283 | static int hda_tegra_dev_disconnect(struct snd_device *device) | ||
284 | { | ||
285 | struct azx *chip = device->device_data; | ||
286 | |||
287 | chip->bus.shutdown = 1; | ||
288 | return 0; | ||
289 | } | ||
290 | |||
285 | /* | 291 | /* |
286 | * destructor | 292 | * destructor |
287 | */ | 293 | */ |
288 | static int hda_tegra_dev_free(struct snd_device *device) | 294 | static int hda_tegra_dev_free(struct snd_device *device) |
289 | { | 295 | { |
290 | int i; | ||
291 | struct azx *chip = device->device_data; | 296 | struct azx *chip = device->device_data; |
292 | 297 | ||
293 | if (chip->initialized) { | 298 | if (azx_bus(chip)->chip_init) { |
294 | for (i = 0; i < chip->num_streams; i++) | 299 | azx_stop_all_streams(chip); |
295 | azx_stream_stop(chip, &chip->azx_dev[i]); | ||
296 | azx_stop_chip(chip); | 300 | azx_stop_chip(chip); |
297 | } | 301 | } |
298 | 302 | ||
299 | azx_free_stream_pages(chip); | 303 | azx_free_stream_pages(chip); |
304 | azx_free_streams(chip); | ||
305 | snd_hdac_bus_exit(azx_bus(chip)); | ||
300 | 306 | ||
301 | return 0; | 307 | return 0; |
302 | } | 308 | } |
@@ -304,31 +310,40 @@ static int hda_tegra_dev_free(struct snd_device *device) | |||
304 | static int hda_tegra_init_chip(struct azx *chip, struct platform_device *pdev) | 310 | static int hda_tegra_init_chip(struct azx *chip, struct platform_device *pdev) |
305 | { | 311 | { |
306 | struct hda_tegra *hda = container_of(chip, struct hda_tegra, chip); | 312 | struct hda_tegra *hda = container_of(chip, struct hda_tegra, chip); |
313 | struct hdac_bus *bus = azx_bus(chip); | ||
307 | struct device *dev = hda->dev; | 314 | struct device *dev = hda->dev; |
308 | struct resource *res; | 315 | struct resource *res; |
309 | int err; | 316 | int err; |
310 | 317 | ||
311 | hda->hda_clk = devm_clk_get(dev, "hda"); | 318 | hda->hda_clk = devm_clk_get(dev, "hda"); |
312 | if (IS_ERR(hda->hda_clk)) | 319 | if (IS_ERR(hda->hda_clk)) { |
320 | dev_err(dev, "failed to get hda clock\n"); | ||
313 | return PTR_ERR(hda->hda_clk); | 321 | return PTR_ERR(hda->hda_clk); |
322 | } | ||
314 | hda->hda2codec_2x_clk = devm_clk_get(dev, "hda2codec_2x"); | 323 | hda->hda2codec_2x_clk = devm_clk_get(dev, "hda2codec_2x"); |
315 | if (IS_ERR(hda->hda2codec_2x_clk)) | 324 | if (IS_ERR(hda->hda2codec_2x_clk)) { |
325 | dev_err(dev, "failed to get hda2codec_2x clock\n"); | ||
316 | return PTR_ERR(hda->hda2codec_2x_clk); | 326 | return PTR_ERR(hda->hda2codec_2x_clk); |
327 | } | ||
317 | hda->hda2hdmi_clk = devm_clk_get(dev, "hda2hdmi"); | 328 | hda->hda2hdmi_clk = devm_clk_get(dev, "hda2hdmi"); |
318 | if (IS_ERR(hda->hda2hdmi_clk)) | 329 | if (IS_ERR(hda->hda2hdmi_clk)) { |
330 | dev_err(dev, "failed to get hda2hdmi clock\n"); | ||
319 | return PTR_ERR(hda->hda2hdmi_clk); | 331 | return PTR_ERR(hda->hda2hdmi_clk); |
332 | } | ||
320 | 333 | ||
321 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 334 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
322 | hda->regs = devm_ioremap_resource(dev, res); | 335 | hda->regs = devm_ioremap_resource(dev, res); |
323 | if (IS_ERR(hda->regs)) | 336 | if (IS_ERR(hda->regs)) |
324 | return PTR_ERR(hda->regs); | 337 | return PTR_ERR(hda->regs); |
325 | 338 | ||
326 | chip->remap_addr = hda->regs + HDA_BAR0; | 339 | bus->remap_addr = hda->regs + HDA_BAR0; |
327 | chip->addr = res->start + HDA_BAR0; | 340 | bus->addr = res->start + HDA_BAR0; |
328 | 341 | ||
329 | err = hda_tegra_enable_clocks(hda); | 342 | err = hda_tegra_enable_clocks(hda); |
330 | if (err) | 343 | if (err) { |
344 | dev_err(dev, "failed to get enable clocks\n"); | ||
331 | return err; | 345 | return err; |
346 | } | ||
332 | 347 | ||
333 | hda_tegra_init(hda); | 348 | hda_tegra_init(hda); |
334 | 349 | ||
@@ -337,6 +352,7 @@ static int hda_tegra_init_chip(struct azx *chip, struct platform_device *pdev) | |||
337 | 352 | ||
338 | static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev) | 353 | static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev) |
339 | { | 354 | { |
355 | struct hdac_bus *bus = azx_bus(chip); | ||
340 | struct snd_card *card = chip->card; | 356 | struct snd_card *card = chip->card; |
341 | int err; | 357 | int err; |
342 | unsigned short gcap; | 358 | unsigned short gcap; |
@@ -354,9 +370,9 @@ static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev) | |||
354 | irq_id); | 370 | irq_id); |
355 | return err; | 371 | return err; |
356 | } | 372 | } |
357 | chip->irq = irq_id; | 373 | bus->irq = irq_id; |
358 | 374 | ||
359 | synchronize_irq(chip->irq); | 375 | synchronize_irq(bus->irq); |
360 | 376 | ||
361 | gcap = azx_readw(chip, GCAP); | 377 | gcap = azx_readw(chip, GCAP); |
362 | dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap); | 378 | dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap); |
@@ -374,23 +390,26 @@ static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev) | |||
374 | chip->capture_index_offset = 0; | 390 | chip->capture_index_offset = 0; |
375 | chip->playback_index_offset = chip->capture_streams; | 391 | chip->playback_index_offset = chip->capture_streams; |
376 | chip->num_streams = chip->playback_streams + chip->capture_streams; | 392 | chip->num_streams = chip->playback_streams + chip->capture_streams; |
377 | chip->azx_dev = devm_kcalloc(card->dev, chip->num_streams, | ||
378 | sizeof(*chip->azx_dev), GFP_KERNEL); | ||
379 | if (!chip->azx_dev) | ||
380 | return -ENOMEM; | ||
381 | 393 | ||
382 | err = azx_alloc_stream_pages(chip); | 394 | /* initialize streams */ |
383 | if (err < 0) | 395 | err = azx_init_streams(chip); |
396 | if (err < 0) { | ||
397 | dev_err(card->dev, "failed to initialize streams: %d\n", err); | ||
384 | return err; | 398 | return err; |
399 | } | ||
385 | 400 | ||
386 | /* initialize streams */ | 401 | err = azx_alloc_stream_pages(chip); |
387 | azx_init_stream(chip); | 402 | if (err < 0) { |
403 | dev_err(card->dev, "failed to allocate stream pages: %d\n", | ||
404 | err); | ||
405 | return err; | ||
406 | } | ||
388 | 407 | ||
389 | /* initialize chip */ | 408 | /* initialize chip */ |
390 | azx_init_chip(chip, 1); | 409 | azx_init_chip(chip, 1); |
391 | 410 | ||
392 | /* codec detection */ | 411 | /* codec detection */ |
393 | if (!chip->codec_mask) { | 412 | if (!bus->codec_mask) { |
394 | dev_err(card->dev, "no codecs found!\n"); | 413 | dev_err(card->dev, "no codecs found!\n"); |
395 | return -ENODEV; | 414 | return -ENODEV; |
396 | } | 415 | } |
@@ -399,7 +418,7 @@ static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev) | |||
399 | strcpy(card->shortname, "tegra-hda"); | 418 | strcpy(card->shortname, "tegra-hda"); |
400 | snprintf(card->longname, sizeof(card->longname), | 419 | snprintf(card->longname, sizeof(card->longname), |
401 | "%s at 0x%lx irq %i", | 420 | "%s at 0x%lx irq %i", |
402 | card->shortname, chip->addr, chip->irq); | 421 | card->shortname, bus->addr, bus->irq); |
403 | 422 | ||
404 | return 0; | 423 | return 0; |
405 | } | 424 | } |
@@ -409,10 +428,10 @@ static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev) | |||
409 | */ | 428 | */ |
410 | static int hda_tegra_create(struct snd_card *card, | 429 | static int hda_tegra_create(struct snd_card *card, |
411 | unsigned int driver_caps, | 430 | unsigned int driver_caps, |
412 | const struct hda_controller_ops *hda_ops, | ||
413 | struct hda_tegra *hda) | 431 | struct hda_tegra *hda) |
414 | { | 432 | { |
415 | static struct snd_device_ops ops = { | 433 | static struct snd_device_ops ops = { |
434 | .dev_disconnect = hda_tegra_dev_disconnect, | ||
416 | .dev_free = hda_tegra_dev_free, | 435 | .dev_free = hda_tegra_dev_free, |
417 | }; | 436 | }; |
418 | struct azx *chip; | 437 | struct azx *chip; |
@@ -420,11 +439,9 @@ static int hda_tegra_create(struct snd_card *card, | |||
420 | 439 | ||
421 | chip = &hda->chip; | 440 | chip = &hda->chip; |
422 | 441 | ||
423 | spin_lock_init(&chip->reg_lock); | ||
424 | mutex_init(&chip->open_mutex); | 442 | mutex_init(&chip->open_mutex); |
425 | chip->card = card; | 443 | chip->card = card; |
426 | chip->ops = hda_ops; | 444 | chip->ops = &hda_tegra_ops; |
427 | chip->irq = -1; | ||
428 | chip->driver_caps = driver_caps; | 445 | chip->driver_caps = driver_caps; |
429 | chip->driver_type = driver_caps & 0xff; | 446 | chip->driver_type = driver_caps & 0xff; |
430 | chip->dev_index = 0; | 447 | chip->dev_index = 0; |
@@ -435,6 +452,10 @@ static int hda_tegra_create(struct snd_card *card, | |||
435 | chip->single_cmd = false; | 452 | chip->single_cmd = false; |
436 | chip->snoop = true; | 453 | chip->snoop = true; |
437 | 454 | ||
455 | err = azx_bus_init(chip, NULL, &hda_tegra_io_ops); | ||
456 | if (err < 0) | ||
457 | return err; | ||
458 | |||
438 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); | 459 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); |
439 | if (err < 0) { | 460 | if (err < 0) { |
440 | dev_err(card->dev, "Error creating device\n"); | 461 | dev_err(card->dev, "Error creating device\n"); |
@@ -452,11 +473,12 @@ MODULE_DEVICE_TABLE(of, hda_tegra_match); | |||
452 | 473 | ||
453 | static int hda_tegra_probe(struct platform_device *pdev) | 474 | static int hda_tegra_probe(struct platform_device *pdev) |
454 | { | 475 | { |
476 | const unsigned int driver_flags = AZX_DCAPS_RIRB_DELAY | | ||
477 | AZX_DCAPS_CORBRP_SELF_CLEAR; | ||
455 | struct snd_card *card; | 478 | struct snd_card *card; |
456 | struct azx *chip; | 479 | struct azx *chip; |
457 | struct hda_tegra *hda; | 480 | struct hda_tegra *hda; |
458 | int err; | 481 | int err; |
459 | const unsigned int driver_flags = AZX_DCAPS_RIRB_DELAY; | ||
460 | 482 | ||
461 | hda = devm_kzalloc(&pdev->dev, sizeof(*hda), GFP_KERNEL); | 483 | hda = devm_kzalloc(&pdev->dev, sizeof(*hda), GFP_KERNEL); |
462 | if (!hda) | 484 | if (!hda) |
@@ -471,7 +493,7 @@ static int hda_tegra_probe(struct platform_device *pdev) | |||
471 | return err; | 493 | return err; |
472 | } | 494 | } |
473 | 495 | ||
474 | err = hda_tegra_create(card, driver_flags, &hda_tegra_ops, hda); | 496 | err = hda_tegra_create(card, driver_flags, hda); |
475 | if (err < 0) | 497 | if (err < 0) |
476 | goto out_free; | 498 | goto out_free; |
477 | card->private_data = chip; | 499 | card->private_data = chip; |
@@ -483,10 +505,6 @@ static int hda_tegra_probe(struct platform_device *pdev) | |||
483 | goto out_free; | 505 | goto out_free; |
484 | 506 | ||
485 | /* create codec instances */ | 507 | /* create codec instances */ |
486 | err = azx_bus_create(chip, NULL); | ||
487 | if (err < 0) | ||
488 | goto out_free; | ||
489 | |||
490 | err = azx_probe_codecs(chip, 0); | 508 | err = azx_probe_codecs(chip, 0); |
491 | if (err < 0) | 509 | if (err < 0) |
492 | goto out_free; | 510 | goto out_free; |
@@ -500,7 +518,7 @@ static int hda_tegra_probe(struct platform_device *pdev) | |||
500 | goto out_free; | 518 | goto out_free; |
501 | 519 | ||
502 | chip->running = 1; | 520 | chip->running = 1; |
503 | snd_hda_set_power_save(chip->bus, power_save * 1000); | 521 | snd_hda_set_power_save(&chip->bus, power_save * 1000); |
504 | 522 | ||
505 | return 0; | 523 | return 0; |
506 | 524 | ||
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c index 4a4e7b282e4f..8dec790dae45 100644 --- a/sound/pci/hda/patch_ca0132.c +++ b/sound/pci/hda/patch_ca0132.c | |||
@@ -43,8 +43,6 @@ | |||
43 | #define FLOAT_TWO 0x40000000 | 43 | #define FLOAT_TWO 0x40000000 |
44 | #define FLOAT_MINUS_5 0xc0a00000 | 44 | #define FLOAT_MINUS_5 0xc0a00000 |
45 | 45 | ||
46 | #define UNSOL_TAG_HP 0x10 | ||
47 | #define UNSOL_TAG_AMIC1 0x12 | ||
48 | #define UNSOL_TAG_DSP 0x16 | 46 | #define UNSOL_TAG_DSP 0x16 |
49 | 47 | ||
50 | #define DSP_DMA_WRITE_BUFLEN_INIT (1UL<<18) | 48 | #define DSP_DMA_WRITE_BUFLEN_INIT (1UL<<18) |
@@ -703,8 +701,8 @@ struct ca0132_spec { | |||
703 | unsigned int num_mixers; | 701 | unsigned int num_mixers; |
704 | const struct hda_verb *base_init_verbs; | 702 | const struct hda_verb *base_init_verbs; |
705 | const struct hda_verb *base_exit_verbs; | 703 | const struct hda_verb *base_exit_verbs; |
706 | const struct hda_verb *init_verbs[5]; | 704 | const struct hda_verb *chip_init_verbs; |
707 | unsigned int num_init_verbs; /* exclude base init verbs */ | 705 | struct hda_verb *spec_init_verbs; |
708 | struct auto_pin_cfg autocfg; | 706 | struct auto_pin_cfg autocfg; |
709 | 707 | ||
710 | /* Nodes configurations */ | 708 | /* Nodes configurations */ |
@@ -719,6 +717,8 @@ struct ca0132_spec { | |||
719 | unsigned int num_inputs; | 717 | unsigned int num_inputs; |
720 | hda_nid_t shared_mic_nid; | 718 | hda_nid_t shared_mic_nid; |
721 | hda_nid_t shared_out_nid; | 719 | hda_nid_t shared_out_nid; |
720 | hda_nid_t unsol_tag_hp; | ||
721 | hda_nid_t unsol_tag_amic1; | ||
722 | 722 | ||
723 | /* chip access */ | 723 | /* chip access */ |
724 | struct mutex chipio_mutex; /* chip access mutex */ | 724 | struct mutex chipio_mutex; /* chip access mutex */ |
@@ -748,6 +748,7 @@ struct ca0132_spec { | |||
748 | 748 | ||
749 | struct hda_codec *codec; | 749 | struct hda_codec *codec; |
750 | struct delayed_work unsol_hp_work; | 750 | struct delayed_work unsol_hp_work; |
751 | int quirk; | ||
751 | 752 | ||
752 | #ifdef ENABLE_TUNING_CONTROLS | 753 | #ifdef ENABLE_TUNING_CONTROLS |
753 | long cur_ctl_vals[TUNING_CTLS_COUNT]; | 754 | long cur_ctl_vals[TUNING_CTLS_COUNT]; |
@@ -755,6 +756,19 @@ struct ca0132_spec { | |||
755 | }; | 756 | }; |
756 | 757 | ||
757 | /* | 758 | /* |
759 | * CA0132 quirks table | ||
760 | */ | ||
761 | enum { | ||
762 | QUIRK_NONE, | ||
763 | QUIRK_ALIENWARE, | ||
764 | }; | ||
765 | |||
766 | static const struct snd_pci_quirk ca0132_quirks[] = { | ||
767 | SND_PCI_QUIRK(0x1028, 0x0685, "Alienware 15", QUIRK_ALIENWARE), | ||
768 | {} | ||
769 | }; | ||
770 | |||
771 | /* | ||
758 | * CA0132 codec access | 772 | * CA0132 codec access |
759 | */ | 773 | */ |
760 | static unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid, | 774 | static unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid, |
@@ -2052,11 +2066,8 @@ static int dma_convert_to_hda_format(struct hda_codec *codec, | |||
2052 | { | 2066 | { |
2053 | unsigned int format_val; | 2067 | unsigned int format_val; |
2054 | 2068 | ||
2055 | format_val = snd_hda_calc_stream_format(codec, | 2069 | format_val = snd_hdac_calc_stream_format(sample_rate, |
2056 | sample_rate, | 2070 | channels, SNDRV_PCM_FORMAT_S32_LE, 32, 0); |
2057 | channels, | ||
2058 | SNDRV_PCM_FORMAT_S32_LE, | ||
2059 | 32, 0); | ||
2060 | 2071 | ||
2061 | if (hda_format) | 2072 | if (hda_format) |
2062 | *hda_format = (unsigned short)format_val; | 2073 | *hda_format = (unsigned short)format_val; |
@@ -3227,7 +3238,7 @@ static void ca0132_unsol_hp_delayed(struct work_struct *work) | |||
3227 | struct hda_jack_tbl *jack; | 3238 | struct hda_jack_tbl *jack; |
3228 | 3239 | ||
3229 | ca0132_select_out(spec->codec); | 3240 | ca0132_select_out(spec->codec); |
3230 | jack = snd_hda_jack_tbl_get(spec->codec, UNSOL_TAG_HP); | 3241 | jack = snd_hda_jack_tbl_get(spec->codec, spec->unsol_tag_hp); |
3231 | if (jack) { | 3242 | if (jack) { |
3232 | jack->block_report = 0; | 3243 | jack->block_report = 0; |
3233 | snd_hda_jack_report_sync(spec->codec); | 3244 | snd_hda_jack_report_sync(spec->codec); |
@@ -4417,8 +4428,9 @@ static void amic_callback(struct hda_codec *codec, struct hda_jack_callback *cb) | |||
4417 | 4428 | ||
4418 | static void ca0132_init_unsol(struct hda_codec *codec) | 4429 | static void ca0132_init_unsol(struct hda_codec *codec) |
4419 | { | 4430 | { |
4420 | snd_hda_jack_detect_enable_callback(codec, UNSOL_TAG_HP, hp_callback); | 4431 | struct ca0132_spec *spec = codec->spec; |
4421 | snd_hda_jack_detect_enable_callback(codec, UNSOL_TAG_AMIC1, | 4432 | snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_hp, hp_callback); |
4433 | snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_amic1, | ||
4422 | amic_callback); | 4434 | amic_callback); |
4423 | snd_hda_jack_detect_enable_callback(codec, UNSOL_TAG_DSP, | 4435 | snd_hda_jack_detect_enable_callback(codec, UNSOL_TAG_DSP, |
4424 | ca0132_process_dsp_response); | 4436 | ca0132_process_dsp_response); |
@@ -4479,17 +4491,6 @@ static struct hda_verb ca0132_init_verbs0[] = { | |||
4479 | {} | 4491 | {} |
4480 | }; | 4492 | }; |
4481 | 4493 | ||
4482 | static struct hda_verb ca0132_init_verbs1[] = { | ||
4483 | {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | UNSOL_TAG_HP}, | ||
4484 | {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | UNSOL_TAG_AMIC1}, | ||
4485 | /* config EAPD */ | ||
4486 | {0x0b, 0x78D, 0x00}, | ||
4487 | /*{0x0b, AC_VERB_SET_EAPD_BTLENABLE, 0x02},*/ | ||
4488 | /*{0x10, 0x78D, 0x02},*/ | ||
4489 | /*{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x02},*/ | ||
4490 | {} | ||
4491 | }; | ||
4492 | |||
4493 | static void ca0132_init_chip(struct hda_codec *codec) | 4494 | static void ca0132_init_chip(struct hda_codec *codec) |
4494 | { | 4495 | { |
4495 | struct ca0132_spec *spec = codec->spec; | 4496 | struct ca0132_spec *spec = codec->spec; |
@@ -4569,8 +4570,8 @@ static int ca0132_init(struct hda_codec *codec) | |||
4569 | 4570 | ||
4570 | init_input(codec, cfg->dig_in_pin, spec->dig_in); | 4571 | init_input(codec, cfg->dig_in_pin, spec->dig_in); |
4571 | 4572 | ||
4572 | for (i = 0; i < spec->num_init_verbs; i++) | 4573 | snd_hda_sequence_write(codec, spec->chip_init_verbs); |
4573 | snd_hda_sequence_write(codec, spec->init_verbs[i]); | 4574 | snd_hda_sequence_write(codec, spec->spec_init_verbs); |
4574 | 4575 | ||
4575 | ca0132_select_out(codec); | 4576 | ca0132_select_out(codec); |
4576 | ca0132_select_mic(codec); | 4577 | ca0132_select_mic(codec); |
@@ -4591,6 +4592,7 @@ static void ca0132_free(struct hda_codec *codec) | |||
4591 | snd_hda_sequence_write(codec, spec->base_exit_verbs); | 4592 | snd_hda_sequence_write(codec, spec->base_exit_verbs); |
4592 | ca0132_exit_chip(codec); | 4593 | ca0132_exit_chip(codec); |
4593 | snd_hda_power_down(codec); | 4594 | snd_hda_power_down(codec); |
4595 | kfree(spec->spec_init_verbs); | ||
4594 | kfree(codec->spec); | 4596 | kfree(codec->spec); |
4595 | } | 4597 | } |
4596 | 4598 | ||
@@ -4617,18 +4619,25 @@ static void ca0132_config(struct hda_codec *codec) | |||
4617 | 4619 | ||
4618 | spec->num_outputs = 2; | 4620 | spec->num_outputs = 2; |
4619 | spec->out_pins[0] = 0x0b; /* speaker out */ | 4621 | spec->out_pins[0] = 0x0b; /* speaker out */ |
4620 | spec->out_pins[1] = 0x10; /* headphone out */ | 4622 | if (spec->quirk == QUIRK_ALIENWARE) { |
4623 | codec_dbg(codec, "ca0132_config: QUIRK_ALIENWARE applied.\n"); | ||
4624 | spec->out_pins[1] = 0x0f; | ||
4625 | } else{ | ||
4626 | spec->out_pins[1] = 0x10; /* headphone out */ | ||
4627 | } | ||
4621 | spec->shared_out_nid = 0x2; | 4628 | spec->shared_out_nid = 0x2; |
4629 | spec->unsol_tag_hp = spec->out_pins[1]; | ||
4622 | 4630 | ||
4623 | spec->num_inputs = 3; | ||
4624 | spec->adcs[0] = 0x7; /* digital mic / analog mic1 */ | 4631 | spec->adcs[0] = 0x7; /* digital mic / analog mic1 */ |
4625 | spec->adcs[1] = 0x8; /* analog mic2 */ | 4632 | spec->adcs[1] = 0x8; /* analog mic2 */ |
4626 | spec->adcs[2] = 0xa; /* what u hear */ | 4633 | spec->adcs[2] = 0xa; /* what u hear */ |
4627 | spec->shared_mic_nid = 0x7; | ||
4628 | 4634 | ||
4635 | spec->num_inputs = 3; | ||
4629 | spec->input_pins[0] = 0x12; | 4636 | spec->input_pins[0] = 0x12; |
4630 | spec->input_pins[1] = 0x11; | 4637 | spec->input_pins[1] = 0x11; |
4631 | spec->input_pins[2] = 0x13; | 4638 | spec->input_pins[2] = 0x13; |
4639 | spec->shared_mic_nid = 0x7; | ||
4640 | spec->unsol_tag_amic1 = spec->input_pins[0]; | ||
4632 | 4641 | ||
4633 | /* SPDIF I/O */ | 4642 | /* SPDIF I/O */ |
4634 | spec->dig_out = 0x05; | 4643 | spec->dig_out = 0x05; |
@@ -4641,10 +4650,56 @@ static void ca0132_config(struct hda_codec *codec) | |||
4641 | cfg->dig_in_type = HDA_PCM_TYPE_SPDIF; | 4650 | cfg->dig_in_type = HDA_PCM_TYPE_SPDIF; |
4642 | } | 4651 | } |
4643 | 4652 | ||
4653 | static int ca0132_prepare_verbs(struct hda_codec *codec) | ||
4654 | { | ||
4655 | /* Verbs + terminator (an empty element) */ | ||
4656 | #define NUM_SPEC_VERBS 4 | ||
4657 | struct ca0132_spec *spec = codec->spec; | ||
4658 | |||
4659 | spec->chip_init_verbs = ca0132_init_verbs0; | ||
4660 | spec->spec_init_verbs = kzalloc(sizeof(struct hda_verb) * NUM_SPEC_VERBS, GFP_KERNEL); | ||
4661 | if (!spec->spec_init_verbs) | ||
4662 | return -ENOMEM; | ||
4663 | |||
4664 | /* HP jack autodetection */ | ||
4665 | spec->spec_init_verbs[0].nid = spec->unsol_tag_hp; | ||
4666 | spec->spec_init_verbs[0].param = AC_VERB_SET_UNSOLICITED_ENABLE; | ||
4667 | spec->spec_init_verbs[0].verb = AC_USRSP_EN | spec->unsol_tag_hp; | ||
4668 | |||
4669 | /* MIC1 jack autodetection */ | ||
4670 | spec->spec_init_verbs[1].nid = spec->unsol_tag_amic1; | ||
4671 | spec->spec_init_verbs[1].param = AC_VERB_SET_UNSOLICITED_ENABLE; | ||
4672 | spec->spec_init_verbs[1].verb = AC_USRSP_EN | spec->unsol_tag_amic1; | ||
4673 | |||
4674 | /* config EAPD */ | ||
4675 | spec->spec_init_verbs[2].nid = 0x0b; | ||
4676 | spec->spec_init_verbs[2].param = 0x78D; | ||
4677 | spec->spec_init_verbs[2].verb = 0x00; | ||
4678 | |||
4679 | /* Previously commented configuration */ | ||
4680 | /* | ||
4681 | spec->spec_init_verbs[3].nid = 0x0b; | ||
4682 | spec->spec_init_verbs[3].param = AC_VERB_SET_EAPD_BTLENABLE; | ||
4683 | spec->spec_init_verbs[3].verb = 0x02; | ||
4684 | |||
4685 | spec->spec_init_verbs[4].nid = 0x10; | ||
4686 | spec->spec_init_verbs[4].param = 0x78D; | ||
4687 | spec->spec_init_verbs[4].verb = 0x02; | ||
4688 | |||
4689 | spec->spec_init_verbs[5].nid = 0x10; | ||
4690 | spec->spec_init_verbs[5].param = AC_VERB_SET_EAPD_BTLENABLE; | ||
4691 | spec->spec_init_verbs[5].verb = 0x02; | ||
4692 | */ | ||
4693 | |||
4694 | /* Terminator: spec->spec_init_verbs[NUM_SPEC_VERBS-1] */ | ||
4695 | return 0; | ||
4696 | } | ||
4697 | |||
4644 | static int patch_ca0132(struct hda_codec *codec) | 4698 | static int patch_ca0132(struct hda_codec *codec) |
4645 | { | 4699 | { |
4646 | struct ca0132_spec *spec; | 4700 | struct ca0132_spec *spec; |
4647 | int err; | 4701 | int err; |
4702 | const struct snd_pci_quirk *quirk; | ||
4648 | 4703 | ||
4649 | codec_dbg(codec, "patch_ca0132\n"); | 4704 | codec_dbg(codec, "patch_ca0132\n"); |
4650 | 4705 | ||
@@ -4654,15 +4709,19 @@ static int patch_ca0132(struct hda_codec *codec) | |||
4654 | codec->spec = spec; | 4709 | codec->spec = spec; |
4655 | spec->codec = codec; | 4710 | spec->codec = codec; |
4656 | 4711 | ||
4712 | /* Detect codec quirk */ | ||
4713 | quirk = snd_pci_quirk_lookup(codec->bus->pci, ca0132_quirks); | ||
4714 | if (quirk) | ||
4715 | spec->quirk = quirk->value; | ||
4716 | else | ||
4717 | spec->quirk = QUIRK_NONE; | ||
4718 | |||
4657 | spec->dsp_state = DSP_DOWNLOAD_INIT; | 4719 | spec->dsp_state = DSP_DOWNLOAD_INIT; |
4658 | spec->num_mixers = 1; | 4720 | spec->num_mixers = 1; |
4659 | spec->mixers[0] = ca0132_mixer; | 4721 | spec->mixers[0] = ca0132_mixer; |
4660 | 4722 | ||
4661 | spec->base_init_verbs = ca0132_base_init_verbs; | 4723 | spec->base_init_verbs = ca0132_base_init_verbs; |
4662 | spec->base_exit_verbs = ca0132_base_exit_verbs; | 4724 | spec->base_exit_verbs = ca0132_base_exit_verbs; |
4663 | spec->init_verbs[0] = ca0132_init_verbs0; | ||
4664 | spec->init_verbs[1] = ca0132_init_verbs1; | ||
4665 | spec->num_init_verbs = 2; | ||
4666 | 4725 | ||
4667 | INIT_DELAYED_WORK(&spec->unsol_hp_work, ca0132_unsol_hp_delayed); | 4726 | INIT_DELAYED_WORK(&spec->unsol_hp_work, ca0132_unsol_hp_delayed); |
4668 | 4727 | ||
@@ -4670,6 +4729,10 @@ static int patch_ca0132(struct hda_codec *codec) | |||
4670 | 4729 | ||
4671 | ca0132_config(codec); | 4730 | ca0132_config(codec); |
4672 | 4731 | ||
4732 | err = ca0132_prepare_verbs(codec); | ||
4733 | if (err < 0) | ||
4734 | return err; | ||
4735 | |||
4673 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | 4736 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
4674 | if (err < 0) | 4737 | if (err < 0) |
4675 | return err; | 4738 | return err; |
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index 5f44f60a6389..ef8a5627a281 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c | |||
@@ -592,7 +592,7 @@ static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index) | |||
592 | static void eld_proc_free(struct hdmi_spec_per_pin *per_pin) | 592 | static void eld_proc_free(struct hdmi_spec_per_pin *per_pin) |
593 | { | 593 | { |
594 | if (!per_pin->codec->bus->shutdown && per_pin->proc_entry) { | 594 | if (!per_pin->codec->bus->shutdown && per_pin->proc_entry) { |
595 | snd_device_free(per_pin->codec->card, per_pin->proc_entry); | 595 | snd_info_free_entry(per_pin->proc_entry); |
596 | per_pin->proc_entry = NULL; | 596 | per_pin->proc_entry = NULL; |
597 | } | 597 | } |
598 | } | 598 | } |
@@ -2049,9 +2049,7 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec) | |||
2049 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { | 2049 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
2050 | struct hda_pcm *info; | 2050 | struct hda_pcm *info; |
2051 | struct hda_pcm_stream *pstr; | 2051 | struct hda_pcm_stream *pstr; |
2052 | struct hdmi_spec_per_pin *per_pin; | ||
2053 | 2052 | ||
2054 | per_pin = get_pin(spec, pin_idx); | ||
2055 | info = snd_hda_codec_pcm_new(codec, "HDMI %d", pin_idx); | 2053 | info = snd_hda_codec_pcm_new(codec, "HDMI %d", pin_idx); |
2056 | if (!info) | 2054 | if (!info) |
2057 | return -ENOMEM; | 2055 | return -ENOMEM; |
@@ -2081,7 +2079,7 @@ static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx) | |||
2081 | strncat(hdmi_str, " Phantom", | 2079 | strncat(hdmi_str, " Phantom", |
2082 | sizeof(hdmi_str) - strlen(hdmi_str) - 1); | 2080 | sizeof(hdmi_str) - strlen(hdmi_str) - 1); |
2083 | 2081 | ||
2084 | return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str, 0); | 2082 | return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str); |
2085 | } | 2083 | } |
2086 | 2084 | ||
2087 | static int generic_hdmi_build_controls(struct hda_codec *codec) | 2085 | static int generic_hdmi_build_controls(struct hda_codec *codec) |
@@ -2335,6 +2333,15 @@ static int patch_generic_hdmi(struct hda_codec *codec) | |||
2335 | intel_haswell_fixup_enable_dp12(codec); | 2333 | intel_haswell_fixup_enable_dp12(codec); |
2336 | } | 2334 | } |
2337 | 2335 | ||
2336 | /* For Valleyview/Cherryview, only the display codec is in the display | ||
2337 | * power well and can use link_power ops to request/release the power. | ||
2338 | * For Haswell/Broadwell, the controller is also in the power well and | ||
2339 | * can cover the codec power request, and so need not set this flag. | ||
2340 | * For previous platforms, there is no such power well feature. | ||
2341 | */ | ||
2342 | if (is_valleyview_plus(codec)) | ||
2343 | codec->core.link_power_control = 1; | ||
2344 | |||
2338 | if (is_haswell_plus(codec) || is_valleyview_plus(codec)) | 2345 | if (is_haswell_plus(codec) || is_valleyview_plus(codec)) |
2339 | codec->depop_delay = 0; | 2346 | codec->depop_delay = 0; |
2340 | 2347 | ||
@@ -2923,6 +2930,171 @@ static int patch_nvhdmi(struct hda_codec *codec) | |||
2923 | } | 2930 | } |
2924 | 2931 | ||
2925 | /* | 2932 | /* |
2933 | * The HDA codec on NVIDIA Tegra contains two scratch registers that are | ||
2934 | * accessed using vendor-defined verbs. These registers can be used for | ||
2935 | * interoperability between the HDA and HDMI drivers. | ||
2936 | */ | ||
2937 | |||
2938 | /* Audio Function Group node */ | ||
2939 | #define NVIDIA_AFG_NID 0x01 | ||
2940 | |||
2941 | /* | ||
2942 | * The SCRATCH0 register is used to notify the HDMI codec of changes in audio | ||
2943 | * format. On Tegra, bit 31 is used as a trigger that causes an interrupt to | ||
2944 | * be raised in the HDMI codec. The remainder of the bits is arbitrary. This | ||
2945 | * implementation stores the HDA format (see AC_FMT_*) in bits [15:0] and an | ||
2946 | * additional bit (at position 30) to signal the validity of the format. | ||
2947 | * | ||
2948 | * | 31 | 30 | 29 16 | 15 0 | | ||
2949 | * +---------+-------+--------+--------+ | ||
2950 | * | TRIGGER | VALID | UNUSED | FORMAT | | ||
2951 | * +-----------------------------------| | ||
2952 | * | ||
2953 | * Note that for the trigger bit to take effect it needs to change value | ||
2954 | * (i.e. it needs to be toggled). | ||
2955 | */ | ||
2956 | #define NVIDIA_GET_SCRATCH0 0xfa6 | ||
2957 | #define NVIDIA_SET_SCRATCH0_BYTE0 0xfa7 | ||
2958 | #define NVIDIA_SET_SCRATCH0_BYTE1 0xfa8 | ||
2959 | #define NVIDIA_SET_SCRATCH0_BYTE2 0xfa9 | ||
2960 | #define NVIDIA_SET_SCRATCH0_BYTE3 0xfaa | ||
2961 | #define NVIDIA_SCRATCH_TRIGGER (1 << 7) | ||
2962 | #define NVIDIA_SCRATCH_VALID (1 << 6) | ||
2963 | |||
2964 | #define NVIDIA_GET_SCRATCH1 0xfab | ||
2965 | #define NVIDIA_SET_SCRATCH1_BYTE0 0xfac | ||
2966 | #define NVIDIA_SET_SCRATCH1_BYTE1 0xfad | ||
2967 | #define NVIDIA_SET_SCRATCH1_BYTE2 0xfae | ||
2968 | #define NVIDIA_SET_SCRATCH1_BYTE3 0xfaf | ||
2969 | |||
2970 | /* | ||
2971 | * The format parameter is the HDA audio format (see AC_FMT_*). If set to 0, | ||
2972 | * the format is invalidated so that the HDMI codec can be disabled. | ||
2973 | */ | ||
2974 | static void tegra_hdmi_set_format(struct hda_codec *codec, unsigned int format) | ||
2975 | { | ||
2976 | unsigned int value; | ||
2977 | |||
2978 | /* bits [31:30] contain the trigger and valid bits */ | ||
2979 | value = snd_hda_codec_read(codec, NVIDIA_AFG_NID, 0, | ||
2980 | NVIDIA_GET_SCRATCH0, 0); | ||
2981 | value = (value >> 24) & 0xff; | ||
2982 | |||
2983 | /* bits [15:0] are used to store the HDA format */ | ||
2984 | snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0, | ||
2985 | NVIDIA_SET_SCRATCH0_BYTE0, | ||
2986 | (format >> 0) & 0xff); | ||
2987 | snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0, | ||
2988 | NVIDIA_SET_SCRATCH0_BYTE1, | ||
2989 | (format >> 8) & 0xff); | ||
2990 | |||
2991 | /* bits [16:24] are unused */ | ||
2992 | snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0, | ||
2993 | NVIDIA_SET_SCRATCH0_BYTE2, 0); | ||
2994 | |||
2995 | /* | ||
2996 | * Bit 30 signals that the data is valid and hence that HDMI audio can | ||
2997 | * be enabled. | ||
2998 | */ | ||
2999 | if (format == 0) | ||
3000 | value &= ~NVIDIA_SCRATCH_VALID; | ||
3001 | else | ||
3002 | value |= NVIDIA_SCRATCH_VALID; | ||
3003 | |||
3004 | /* | ||
3005 | * Whenever the trigger bit is toggled, an interrupt is raised in the | ||
3006 | * HDMI codec. The HDMI driver will use that as trigger to update its | ||
3007 | * configuration. | ||
3008 | */ | ||
3009 | value ^= NVIDIA_SCRATCH_TRIGGER; | ||
3010 | |||
3011 | snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0, | ||
3012 | NVIDIA_SET_SCRATCH0_BYTE3, value); | ||
3013 | } | ||
3014 | |||
3015 | static int tegra_hdmi_pcm_prepare(struct hda_pcm_stream *hinfo, | ||
3016 | struct hda_codec *codec, | ||
3017 | unsigned int stream_tag, | ||
3018 | unsigned int format, | ||
3019 | struct snd_pcm_substream *substream) | ||
3020 | { | ||
3021 | int err; | ||
3022 | |||
3023 | err = generic_hdmi_playback_pcm_prepare(hinfo, codec, stream_tag, | ||
3024 | format, substream); | ||
3025 | if (err < 0) | ||
3026 | return err; | ||
3027 | |||
3028 | /* notify the HDMI codec of the format change */ | ||
3029 | tegra_hdmi_set_format(codec, format); | ||
3030 | |||
3031 | return 0; | ||
3032 | } | ||
3033 | |||
3034 | static int tegra_hdmi_pcm_cleanup(struct hda_pcm_stream *hinfo, | ||
3035 | struct hda_codec *codec, | ||
3036 | struct snd_pcm_substream *substream) | ||
3037 | { | ||
3038 | /* invalidate the format in the HDMI codec */ | ||
3039 | tegra_hdmi_set_format(codec, 0); | ||
3040 | |||
3041 | return generic_hdmi_playback_pcm_cleanup(hinfo, codec, substream); | ||
3042 | } | ||
3043 | |||
3044 | static struct hda_pcm *hda_find_pcm_by_type(struct hda_codec *codec, int type) | ||
3045 | { | ||
3046 | struct hdmi_spec *spec = codec->spec; | ||
3047 | unsigned int i; | ||
3048 | |||
3049 | for (i = 0; i < spec->num_pins; i++) { | ||
3050 | struct hda_pcm *pcm = get_pcm_rec(spec, i); | ||
3051 | |||
3052 | if (pcm->pcm_type == type) | ||
3053 | return pcm; | ||
3054 | } | ||
3055 | |||
3056 | return NULL; | ||
3057 | } | ||
3058 | |||
3059 | static int tegra_hdmi_build_pcms(struct hda_codec *codec) | ||
3060 | { | ||
3061 | struct hda_pcm_stream *stream; | ||
3062 | struct hda_pcm *pcm; | ||
3063 | int err; | ||
3064 | |||
3065 | err = generic_hdmi_build_pcms(codec); | ||
3066 | if (err < 0) | ||
3067 | return err; | ||
3068 | |||
3069 | pcm = hda_find_pcm_by_type(codec, HDA_PCM_TYPE_HDMI); | ||
3070 | if (!pcm) | ||
3071 | return -ENODEV; | ||
3072 | |||
3073 | /* | ||
3074 | * Override ->prepare() and ->cleanup() operations to notify the HDMI | ||
3075 | * codec about format changes. | ||
3076 | */ | ||
3077 | stream = &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK]; | ||
3078 | stream->ops.prepare = tegra_hdmi_pcm_prepare; | ||
3079 | stream->ops.cleanup = tegra_hdmi_pcm_cleanup; | ||
3080 | |||
3081 | return 0; | ||
3082 | } | ||
3083 | |||
3084 | static int patch_tegra_hdmi(struct hda_codec *codec) | ||
3085 | { | ||
3086 | int err; | ||
3087 | |||
3088 | err = patch_generic_hdmi(codec); | ||
3089 | if (err) | ||
3090 | return err; | ||
3091 | |||
3092 | codec->patch_ops.build_pcms = tegra_hdmi_build_pcms; | ||
3093 | |||
3094 | return 0; | ||
3095 | } | ||
3096 | |||
3097 | /* | ||
2926 | * ATI/AMD-specific implementations | 3098 | * ATI/AMD-specific implementations |
2927 | */ | 3099 | */ |
2928 | 3100 | ||
@@ -3321,7 +3493,10 @@ static const struct hda_codec_preset snd_hda_preset_hdmi[] = { | |||
3321 | { .id = 0x10de001a, .name = "GPU 1a HDMI/DP", .patch = patch_nvhdmi }, | 3493 | { .id = 0x10de001a, .name = "GPU 1a HDMI/DP", .patch = patch_nvhdmi }, |
3322 | { .id = 0x10de001b, .name = "GPU 1b HDMI/DP", .patch = patch_nvhdmi }, | 3494 | { .id = 0x10de001b, .name = "GPU 1b HDMI/DP", .patch = patch_nvhdmi }, |
3323 | { .id = 0x10de001c, .name = "GPU 1c HDMI/DP", .patch = patch_nvhdmi }, | 3495 | { .id = 0x10de001c, .name = "GPU 1c HDMI/DP", .patch = patch_nvhdmi }, |
3324 | { .id = 0x10de0028, .name = "Tegra12x HDMI", .patch = patch_nvhdmi }, | 3496 | { .id = 0x10de0020, .name = "Tegra30 HDMI", .patch = patch_tegra_hdmi }, |
3497 | { .id = 0x10de0022, .name = "Tegra114 HDMI", .patch = patch_tegra_hdmi }, | ||
3498 | { .id = 0x10de0028, .name = "Tegra124 HDMI", .patch = patch_tegra_hdmi }, | ||
3499 | { .id = 0x10de0029, .name = "Tegra210 HDMI/DP", .patch = patch_tegra_hdmi }, | ||
3325 | { .id = 0x10de0040, .name = "GPU 40 HDMI/DP", .patch = patch_nvhdmi }, | 3500 | { .id = 0x10de0040, .name = "GPU 40 HDMI/DP", .patch = patch_nvhdmi }, |
3326 | { .id = 0x10de0041, .name = "GPU 41 HDMI/DP", .patch = patch_nvhdmi }, | 3501 | { .id = 0x10de0041, .name = "GPU 41 HDMI/DP", .patch = patch_nvhdmi }, |
3327 | { .id = 0x10de0042, .name = "GPU 42 HDMI/DP", .patch = patch_nvhdmi }, | 3502 | { .id = 0x10de0042, .name = "GPU 42 HDMI/DP", .patch = patch_nvhdmi }, |
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index 06199e4e930f..4d11fbfca5e2 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c | |||
@@ -3583,6 +3583,7 @@ static void alc_headset_mode_unplugged(struct hda_codec *codec) | |||
3583 | break; | 3583 | break; |
3584 | case 0x10ec0286: | 3584 | case 0x10ec0286: |
3585 | case 0x10ec0288: | 3585 | case 0x10ec0288: |
3586 | case 0x10ec0298: | ||
3586 | alc_process_coef_fw(codec, coef0288); | 3587 | alc_process_coef_fw(codec, coef0288); |
3587 | break; | 3588 | break; |
3588 | case 0x10ec0292: | 3589 | case 0x10ec0292: |
@@ -3657,6 +3658,7 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin, | |||
3657 | break; | 3658 | break; |
3658 | case 0x10ec0286: | 3659 | case 0x10ec0286: |
3659 | case 0x10ec0288: | 3660 | case 0x10ec0288: |
3661 | case 0x10ec0298: | ||
3660 | alc_update_coef_idx(codec, 0x4f, 0x000c, 0); | 3662 | alc_update_coef_idx(codec, 0x4f, 0x000c, 0); |
3661 | snd_hda_set_pin_ctl_cache(codec, hp_pin, 0); | 3663 | snd_hda_set_pin_ctl_cache(codec, hp_pin, 0); |
3662 | alc_process_coef_fw(codec, coef0288); | 3664 | alc_process_coef_fw(codec, coef0288); |
@@ -3736,6 +3738,7 @@ static void alc_headset_mode_default(struct hda_codec *codec) | |||
3736 | break; | 3738 | break; |
3737 | case 0x10ec0286: | 3739 | case 0x10ec0286: |
3738 | case 0x10ec0288: | 3740 | case 0x10ec0288: |
3741 | case 0x10ec0298: | ||
3739 | alc_process_coef_fw(codec, coef0288); | 3742 | alc_process_coef_fw(codec, coef0288); |
3740 | break; | 3743 | break; |
3741 | break; | 3744 | break; |
@@ -3801,6 +3804,9 @@ static void alc_headset_mode_ctia(struct hda_codec *codec) | |||
3801 | case 0x10ec0283: | 3804 | case 0x10ec0283: |
3802 | alc_process_coef_fw(codec, coef0233); | 3805 | alc_process_coef_fw(codec, coef0233); |
3803 | break; | 3806 | break; |
3807 | case 0x10ec0298: | ||
3808 | alc_update_coef_idx(codec, 0x8e, 0x0070, 0x0020);/* Headset output enable */ | ||
3809 | /* ALC298 jack type setting is the same with ALC286/ALC288 */ | ||
3804 | case 0x10ec0286: | 3810 | case 0x10ec0286: |
3805 | case 0x10ec0288: | 3811 | case 0x10ec0288: |
3806 | alc_update_coef_idx(codec, 0x4f, 0xfcc0, 0xd400); | 3812 | alc_update_coef_idx(codec, 0x4f, 0xfcc0, 0xd400); |
@@ -3869,6 +3875,9 @@ static void alc_headset_mode_omtp(struct hda_codec *codec) | |||
3869 | case 0x10ec0283: | 3875 | case 0x10ec0283: |
3870 | alc_process_coef_fw(codec, coef0233); | 3876 | alc_process_coef_fw(codec, coef0233); |
3871 | break; | 3877 | break; |
3878 | case 0x10ec0298: | ||
3879 | alc_update_coef_idx(codec, 0x8e, 0x0070, 0x0010);/* Headset output enable */ | ||
3880 | /* ALC298 jack type setting is the same with ALC286/ALC288 */ | ||
3872 | case 0x10ec0286: | 3881 | case 0x10ec0286: |
3873 | case 0x10ec0288: | 3882 | case 0x10ec0288: |
3874 | alc_update_coef_idx(codec, 0x4f, 0xfcc0, 0xe400); | 3883 | alc_update_coef_idx(codec, 0x4f, 0xfcc0, 0xe400); |
@@ -3931,6 +3940,9 @@ static void alc_determine_headset_type(struct hda_codec *codec) | |||
3931 | val = alc_read_coef_idx(codec, 0x46); | 3940 | val = alc_read_coef_idx(codec, 0x46); |
3932 | is_ctia = (val & 0x0070) == 0x0070; | 3941 | is_ctia = (val & 0x0070) == 0x0070; |
3933 | break; | 3942 | break; |
3943 | case 0x10ec0298: | ||
3944 | alc_update_coef_idx(codec, 0x8e, 0x0070, 0x0020); /* Headset output enable */ | ||
3945 | /* ALC298 check jack type is the same with ALC286/ALC288 */ | ||
3934 | case 0x10ec0286: | 3946 | case 0x10ec0286: |
3935 | case 0x10ec0288: | 3947 | case 0x10ec0288: |
3936 | alc_process_coef_fw(codec, coef0288); | 3948 | alc_process_coef_fw(codec, coef0288); |
@@ -4190,11 +4202,18 @@ static void alc_shutup_dell_xps13(struct hda_codec *codec) | |||
4190 | static void alc_fixup_dell_xps13(struct hda_codec *codec, | 4202 | static void alc_fixup_dell_xps13(struct hda_codec *codec, |
4191 | const struct hda_fixup *fix, int action) | 4203 | const struct hda_fixup *fix, int action) |
4192 | { | 4204 | { |
4193 | if (action == HDA_FIXUP_ACT_PROBE) { | 4205 | struct alc_spec *spec = codec->spec; |
4194 | struct alc_spec *spec = codec->spec; | 4206 | struct hda_input_mux *imux = &spec->gen.input_mux; |
4195 | struct hda_input_mux *imux = &spec->gen.input_mux; | 4207 | int i; |
4196 | int i; | ||
4197 | 4208 | ||
4209 | switch (action) { | ||
4210 | case HDA_FIXUP_ACT_PRE_PROBE: | ||
4211 | /* mic pin 0x19 must be initialized with Vref Hi-Z, otherwise | ||
4212 | * it causes a click noise at start up | ||
4213 | */ | ||
4214 | snd_hda_codec_set_pin_target(codec, 0x19, PIN_VREFHIZ); | ||
4215 | break; | ||
4216 | case HDA_FIXUP_ACT_PROBE: | ||
4198 | spec->shutup = alc_shutup_dell_xps13; | 4217 | spec->shutup = alc_shutup_dell_xps13; |
4199 | 4218 | ||
4200 | /* Make the internal mic the default input source. */ | 4219 | /* Make the internal mic the default input source. */ |
@@ -4204,6 +4223,7 @@ static void alc_fixup_dell_xps13(struct hda_codec *codec, | |||
4204 | break; | 4223 | break; |
4205 | } | 4224 | } |
4206 | } | 4225 | } |
4226 | break; | ||
4207 | } | 4227 | } |
4208 | } | 4228 | } |
4209 | 4229 | ||
@@ -4484,6 +4504,7 @@ enum { | |||
4484 | ALC288_FIXUP_DELL_HEADSET_MODE, | 4504 | ALC288_FIXUP_DELL_HEADSET_MODE, |
4485 | ALC288_FIXUP_DELL1_MIC_NO_PRESENCE, | 4505 | ALC288_FIXUP_DELL1_MIC_NO_PRESENCE, |
4486 | ALC288_FIXUP_DELL_XPS_13_GPIO6, | 4506 | ALC288_FIXUP_DELL_XPS_13_GPIO6, |
4507 | ALC298_FIXUP_DELL1_MIC_NO_PRESENCE, | ||
4487 | }; | 4508 | }; |
4488 | 4509 | ||
4489 | static const struct hda_fixup alc269_fixups[] = { | 4510 | static const struct hda_fixup alc269_fixups[] = { |
@@ -5006,6 +5027,16 @@ static const struct hda_fixup alc269_fixups[] = { | |||
5006 | .chained = true, | 5027 | .chained = true, |
5007 | .chain_id = ALC288_FIXUP_DELL1_MIC_NO_PRESENCE | 5028 | .chain_id = ALC288_FIXUP_DELL1_MIC_NO_PRESENCE |
5008 | }, | 5029 | }, |
5030 | [ALC298_FIXUP_DELL1_MIC_NO_PRESENCE] = { | ||
5031 | .type = HDA_FIXUP_PINS, | ||
5032 | .v.pins = (const struct hda_pintbl[]) { | ||
5033 | { 0x18, 0x01a1913c }, /* use as headset mic, without its own jack detect */ | ||
5034 | { 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */ | ||
5035 | { } | ||
5036 | }, | ||
5037 | .chained = true, | ||
5038 | .chain_id = ALC269_FIXUP_HEADSET_MODE | ||
5039 | }, | ||
5009 | }; | 5040 | }; |
5010 | 5041 | ||
5011 | static const struct snd_pci_quirk alc269_fixup_tbl[] = { | 5042 | static const struct snd_pci_quirk alc269_fixup_tbl[] = { |
@@ -5211,6 +5242,8 @@ static const struct hda_model_fixup alc269_fixup_models[] = { | |||
5211 | {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"}, | 5242 | {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"}, |
5212 | {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"}, | 5243 | {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"}, |
5213 | {.id = ALC269_FIXUP_HEADSET_MIC, .name = "headset-mic"}, | 5244 | {.id = ALC269_FIXUP_HEADSET_MIC, .name = "headset-mic"}, |
5245 | {.id = ALC269_FIXUP_HEADSET_MODE, .name = "headset-mode"}, | ||
5246 | {.id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC, .name = "headset-mode-no-hp-mic"}, | ||
5214 | {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"}, | 5247 | {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"}, |
5215 | {.id = ALC269_FIXUP_HP_GPIO_LED, .name = "hp-gpio-led"}, | 5248 | {.id = ALC269_FIXUP_HP_GPIO_LED, .name = "hp-gpio-led"}, |
5216 | {.id = ALC269_FIXUP_DELL1_MIC_NO_PRESENCE, .name = "dell-headset-multi"}, | 5249 | {.id = ALC269_FIXUP_DELL1_MIC_NO_PRESENCE, .name = "dell-headset-multi"}, |
@@ -5269,6 +5302,13 @@ static const struct hda_model_fixup alc269_fixup_models[] = { | |||
5269 | {0x1d, 0x40700001}, \ | 5302 | {0x1d, 0x40700001}, \ |
5270 | {0x1e, 0x411111f0} | 5303 | {0x1e, 0x411111f0} |
5271 | 5304 | ||
5305 | #define ALC298_STANDARD_PINS \ | ||
5306 | {0x18, 0x411111f0}, \ | ||
5307 | {0x19, 0x411111f0}, \ | ||
5308 | {0x1a, 0x411111f0}, \ | ||
5309 | {0x1e, 0x411111f0}, \ | ||
5310 | {0x1f, 0x411111f0} | ||
5311 | |||
5272 | static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = { | 5312 | static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = { |
5273 | SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL2_MIC_NO_PRESENCE, | 5313 | SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL2_MIC_NO_PRESENCE, |
5274 | ALC255_STANDARD_PINS, | 5314 | ALC255_STANDARD_PINS, |
@@ -5534,6 +5574,14 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = { | |||
5534 | {0x16, 0x411111f0}, | 5574 | {0x16, 0x411111f0}, |
5535 | {0x18, 0x411111f0}, | 5575 | {0x18, 0x411111f0}, |
5536 | {0x19, 0x411111f0}), | 5576 | {0x19, 0x411111f0}), |
5577 | SND_HDA_PIN_QUIRK(0x10ec0298, 0x1028, "Dell", ALC298_FIXUP_DELL1_MIC_NO_PRESENCE, | ||
5578 | ALC298_STANDARD_PINS, | ||
5579 | {0x12, 0x90a60130}, | ||
5580 | {0x13, 0x40000000}, | ||
5581 | {0x14, 0x411111f0}, | ||
5582 | {0x17, 0x90170140}, | ||
5583 | {0x1d, 0x4068a36d}, | ||
5584 | {0x21, 0x03211020}), | ||
5537 | {} | 5585 | {} |
5538 | }; | 5586 | }; |
5539 | 5587 | ||
diff --git a/sound/pci/hda/thinkpad_helper.c b/sound/pci/hda/thinkpad_helper.c index 0a4ad5feb82e..d51703e30523 100644 --- a/sound/pci/hda/thinkpad_helper.c +++ b/sound/pci/hda/thinkpad_helper.c | |||
@@ -72,6 +72,7 @@ static void hda_fixup_thinkpad_acpi(struct hda_codec *codec, | |||
72 | if (led_set_func(TPACPI_LED_MUTE, false) >= 0) { | 72 | if (led_set_func(TPACPI_LED_MUTE, false) >= 0) { |
73 | old_vmaster_hook = spec->vmaster_mute.hook; | 73 | old_vmaster_hook = spec->vmaster_mute.hook; |
74 | spec->vmaster_mute.hook = update_tpacpi_mute_led; | 74 | spec->vmaster_mute.hook = update_tpacpi_mute_led; |
75 | spec->vmaster_mute_enum = 1; | ||
75 | removefunc = false; | 76 | removefunc = false; |
76 | } | 77 | } |
77 | if (led_set_func(TPACPI_LED_MICMUTE, false) >= 0) { | 78 | if (led_set_func(TPACPI_LED_MICMUTE, false) >= 0) { |
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c index f7b1523e8a82..8ae3bb7975d1 100644 --- a/sound/pci/ice1712/ice1712.c +++ b/sound/pci/ice1712/ice1712.c | |||
@@ -2530,8 +2530,8 @@ static int snd_ice1712_create(struct snd_card *card, | |||
2530 | if (err < 0) | 2530 | if (err < 0) |
2531 | return err; | 2531 | return err; |
2532 | /* check, if we can restrict PCI DMA transfers to 28 bits */ | 2532 | /* check, if we can restrict PCI DMA transfers to 28 bits */ |
2533 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 || | 2533 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(28)) < 0 || |
2534 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) { | 2534 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(28)) < 0) { |
2535 | dev_err(card->dev, | 2535 | dev_err(card->dev, |
2536 | "architecture does not support 28bit PCI busmaster DMA\n"); | 2536 | "architecture does not support 28bit PCI busmaster DMA\n"); |
2537 | pci_disable_device(pci); | 2537 | pci_disable_device(pci); |
diff --git a/sound/pci/lx6464es/lx6464es.c b/sound/pci/lx6464es/lx6464es.c index 601315a1f58f..32c6f6ba1442 100644 --- a/sound/pci/lx6464es/lx6464es.c +++ b/sound/pci/lx6464es/lx6464es.c | |||
@@ -981,7 +981,7 @@ static int snd_lx6464es_create(struct snd_card *card, | |||
981 | pci_set_master(pci); | 981 | pci_set_master(pci); |
982 | 982 | ||
983 | /* check if we can restrict PCI DMA transfers to 32 bits */ | 983 | /* check if we can restrict PCI DMA transfers to 32 bits */ |
984 | err = pci_set_dma_mask(pci, DMA_BIT_MASK(32)); | 984 | err = dma_set_mask(&pci->dev, DMA_BIT_MASK(32)); |
985 | if (err < 0) { | 985 | if (err < 0) { |
986 | dev_err(card->dev, | 986 | dev_err(card->dev, |
987 | "architecture does not support 32bit PCI busmaster DMA\n"); | 987 | "architecture does not support 32bit PCI busmaster DMA\n"); |
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c index 9be660993bd0..72e89cedc52d 100644 --- a/sound/pci/maestro3.c +++ b/sound/pci/maestro3.c | |||
@@ -2537,8 +2537,8 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci, | |||
2537 | return -EIO; | 2537 | return -EIO; |
2538 | 2538 | ||
2539 | /* check, if we can restrict PCI DMA transfers to 28 bits */ | 2539 | /* check, if we can restrict PCI DMA transfers to 28 bits */ |
2540 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 || | 2540 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(28)) < 0 || |
2541 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) { | 2541 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(28)) < 0) { |
2542 | dev_err(card->dev, | 2542 | dev_err(card->dev, |
2543 | "architecture does not support 28bit PCI busmaster DMA\n"); | 2543 | "architecture does not support 28bit PCI busmaster DMA\n"); |
2544 | pci_disable_device(pci); | 2544 | pci_disable_device(pci); |
diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c index c3a9f39f8d61..bc81b9f75ed0 100644 --- a/sound/pci/mixart/mixart.c +++ b/sound/pci/mixart/mixart.c | |||
@@ -1269,7 +1269,7 @@ static int snd_mixart_probe(struct pci_dev *pci, | |||
1269 | pci_set_master(pci); | 1269 | pci_set_master(pci); |
1270 | 1270 | ||
1271 | /* check if we can restrict PCI DMA transfers to 32 bits */ | 1271 | /* check if we can restrict PCI DMA transfers to 32 bits */ |
1272 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0) { | 1272 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) { |
1273 | dev_err(&pci->dev, | 1273 | dev_err(&pci->dev, |
1274 | "architecture does not support 32bit PCI busmaster DMA\n"); | 1274 | "architecture does not support 32bit PCI busmaster DMA\n"); |
1275 | pci_disable_device(pci); | 1275 | pci_disable_device(pci); |
diff --git a/sound/pci/oxygen/xonar_wm87x6.c b/sound/pci/oxygen/xonar_wm87x6.c index 6ce68604c25e..90ac479f389f 100644 --- a/sound/pci/oxygen/xonar_wm87x6.c +++ b/sound/pci/oxygen/xonar_wm87x6.c | |||
@@ -286,7 +286,7 @@ static void xonar_ds_init(struct oxygen *chip) | |||
286 | xonar_enable_output(chip); | 286 | xonar_enable_output(chip); |
287 | 287 | ||
288 | snd_jack_new(chip->card, "Headphone", | 288 | snd_jack_new(chip->card, "Headphone", |
289 | SND_JACK_HEADPHONE, &data->hp_jack); | 289 | SND_JACK_HEADPHONE, &data->hp_jack, false, false); |
290 | xonar_ds_handle_hp_jack(chip); | 290 | xonar_ds_handle_hp_jack(chip); |
291 | 291 | ||
292 | snd_component_add(chip->card, "WM8776"); | 292 | snd_component_add(chip->card, "WM8776"); |
diff --git a/sound/pci/pcxhr/pcxhr.c b/sound/pci/pcxhr/pcxhr.c index c6092e48ceb6..9293235281dc 100644 --- a/sound/pci/pcxhr/pcxhr.c +++ b/sound/pci/pcxhr/pcxhr.c | |||
@@ -1537,7 +1537,7 @@ static int pcxhr_probe(struct pci_dev *pci, | |||
1537 | pci_set_master(pci); | 1537 | pci_set_master(pci); |
1538 | 1538 | ||
1539 | /* check if we can restrict PCI DMA transfers to 32 bits */ | 1539 | /* check if we can restrict PCI DMA transfers to 32 bits */ |
1540 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0) { | 1540 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) { |
1541 | dev_err(&pci->dev, | 1541 | dev_err(&pci->dev, |
1542 | "architecture does not support 32bit PCI busmaster DMA\n"); | 1542 | "architecture does not support 32bit PCI busmaster DMA\n"); |
1543 | pci_disable_device(pci); | 1543 | pci_disable_device(pci); |
diff --git a/sound/pci/sis7019.c b/sound/pci/sis7019.c index efe669b80256..f3860b850210 100644 --- a/sound/pci/sis7019.c +++ b/sound/pci/sis7019.c | |||
@@ -383,9 +383,9 @@ static void __sis_map_silence(struct sis7019 *sis) | |||
383 | { | 383 | { |
384 | /* Helper function: must hold sis->voice_lock on entry */ | 384 | /* Helper function: must hold sis->voice_lock on entry */ |
385 | if (!sis->silence_users) | 385 | if (!sis->silence_users) |
386 | sis->silence_dma_addr = pci_map_single(sis->pci, | 386 | sis->silence_dma_addr = dma_map_single(&sis->pci->dev, |
387 | sis->suspend_state[0], | 387 | sis->suspend_state[0], |
388 | 4096, PCI_DMA_TODEVICE); | 388 | 4096, DMA_TO_DEVICE); |
389 | sis->silence_users++; | 389 | sis->silence_users++; |
390 | } | 390 | } |
391 | 391 | ||
@@ -394,8 +394,8 @@ static void __sis_unmap_silence(struct sis7019 *sis) | |||
394 | /* Helper function: must hold sis->voice_lock on entry */ | 394 | /* Helper function: must hold sis->voice_lock on entry */ |
395 | sis->silence_users--; | 395 | sis->silence_users--; |
396 | if (!sis->silence_users) | 396 | if (!sis->silence_users) |
397 | pci_unmap_single(sis->pci, sis->silence_dma_addr, 4096, | 397 | dma_unmap_single(&sis->pci->dev, sis->silence_dma_addr, 4096, |
398 | PCI_DMA_TODEVICE); | 398 | DMA_TO_DEVICE); |
399 | } | 399 | } |
400 | 400 | ||
401 | static void sis_free_voice(struct sis7019 *sis, struct voice *voice) | 401 | static void sis_free_voice(struct sis7019 *sis, struct voice *voice) |
@@ -1325,7 +1325,7 @@ static int sis_chip_create(struct snd_card *card, | |||
1325 | if (rc) | 1325 | if (rc) |
1326 | goto error_out; | 1326 | goto error_out; |
1327 | 1327 | ||
1328 | rc = pci_set_dma_mask(pci, DMA_BIT_MASK(30)); | 1328 | rc = dma_set_mask(&pci->dev, DMA_BIT_MASK(30)); |
1329 | if (rc < 0) { | 1329 | if (rc < 0) { |
1330 | dev_err(&pci->dev, "architecture does not support 30-bit PCI busmaster DMA"); | 1330 | dev_err(&pci->dev, "architecture does not support 30-bit PCI busmaster DMA"); |
1331 | goto error_out_enabled; | 1331 | goto error_out_enabled; |
diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c index 0f40624a4275..1b6fad7d4d56 100644 --- a/sound/pci/sonicvibes.c +++ b/sound/pci/sonicvibes.c | |||
@@ -1259,8 +1259,8 @@ static int snd_sonicvibes_create(struct snd_card *card, | |||
1259 | if ((err = pci_enable_device(pci)) < 0) | 1259 | if ((err = pci_enable_device(pci)) < 0) |
1260 | return err; | 1260 | return err; |
1261 | /* check, if we can restrict PCI DMA transfers to 24 bits */ | 1261 | /* check, if we can restrict PCI DMA transfers to 24 bits */ |
1262 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 || | 1262 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(24)) < 0 || |
1263 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) { | 1263 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(24)) < 0) { |
1264 | dev_err(card->dev, | 1264 | dev_err(card->dev, |
1265 | "architecture does not support 24bit PCI busmaster DMA\n"); | 1265 | "architecture does not support 24bit PCI busmaster DMA\n"); |
1266 | pci_disable_device(pci); | 1266 | pci_disable_device(pci); |
diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c index b72be035f785..599d2b7eb5b8 100644 --- a/sound/pci/trident/trident_main.c +++ b/sound/pci/trident/trident_main.c | |||
@@ -3551,8 +3551,8 @@ int snd_trident_create(struct snd_card *card, | |||
3551 | if ((err = pci_enable_device(pci)) < 0) | 3551 | if ((err = pci_enable_device(pci)) < 0) |
3552 | return err; | 3552 | return err; |
3553 | /* check, if we can restrict PCI DMA transfers to 30 bits */ | 3553 | /* check, if we can restrict PCI DMA transfers to 30 bits */ |
3554 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(30)) < 0 || | 3554 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(30)) < 0 || |
3555 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(30)) < 0) { | 3555 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(30)) < 0) { |
3556 | dev_err(card->dev, | 3556 | dev_err(card->dev, |
3557 | "architecture does not support 30bit PCI busmaster DMA\n"); | 3557 | "architecture does not support 30bit PCI busmaster DMA\n"); |
3558 | pci_disable_device(pci); | 3558 | pci_disable_device(pci); |
diff --git a/sound/ppc/keywest.c b/sound/ppc/keywest.c index 0d1c27e911b8..d7627bae0836 100644 --- a/sound/ppc/keywest.c +++ b/sound/ppc/keywest.c | |||
@@ -52,7 +52,7 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter) | |||
52 | return -EINVAL; | 52 | return -EINVAL; |
53 | 53 | ||
54 | if (strncmp(adapter->name, "mac-io", 6)) | 54 | if (strncmp(adapter->name, "mac-io", 6)) |
55 | return 0; /* ignored */ | 55 | return -EINVAL; /* ignored */ |
56 | 56 | ||
57 | memset(&info, 0, sizeof(struct i2c_board_info)); | 57 | memset(&info, 0, sizeof(struct i2c_board_info)); |
58 | strlcpy(info.type, "keywest", I2C_NAME_SIZE); | 58 | strlcpy(info.type, "keywest", I2C_NAME_SIZE); |
@@ -100,7 +100,6 @@ static struct i2c_driver keywest_driver = { | |||
100 | .driver = { | 100 | .driver = { |
101 | .name = "PMac Keywest Audio", | 101 | .name = "PMac Keywest Audio", |
102 | }, | 102 | }, |
103 | .attach_adapter = keywest_attach_adapter, | ||
104 | .probe = keywest_probe, | 103 | .probe = keywest_probe, |
105 | .remove = keywest_remove, | 104 | .remove = keywest_remove, |
106 | .id_table = keywest_i2c_id, | 105 | .id_table = keywest_i2c_id, |
@@ -132,16 +131,32 @@ int snd_pmac_tumbler_post_init(void) | |||
132 | /* exported */ | 131 | /* exported */ |
133 | int snd_pmac_keywest_init(struct pmac_keywest *i2c) | 132 | int snd_pmac_keywest_init(struct pmac_keywest *i2c) |
134 | { | 133 | { |
135 | int err; | 134 | struct i2c_adapter *adap; |
135 | int err, i = 0; | ||
136 | 136 | ||
137 | if (keywest_ctx) | 137 | if (keywest_ctx) |
138 | return -EBUSY; | 138 | return -EBUSY; |
139 | 139 | ||
140 | adap = i2c_get_adapter(0); | ||
141 | if (!adap) | ||
142 | return -EPROBE_DEFER; | ||
143 | |||
140 | keywest_ctx = i2c; | 144 | keywest_ctx = i2c; |
141 | 145 | ||
142 | if ((err = i2c_add_driver(&keywest_driver))) { | 146 | if ((err = i2c_add_driver(&keywest_driver))) { |
143 | snd_printk(KERN_ERR "cannot register keywest i2c driver\n"); | 147 | snd_printk(KERN_ERR "cannot register keywest i2c driver\n"); |
148 | i2c_put_adapter(adap); | ||
144 | return err; | 149 | return err; |
145 | } | 150 | } |
146 | return 0; | 151 | |
152 | /* We assume Macs have consecutive I2C bus numbers starting at 0 */ | ||
153 | while (adap) { | ||
154 | err = keywest_attach_adapter(adap); | ||
155 | if (!err) | ||
156 | return 0; | ||
157 | i2c_put_adapter(adap); | ||
158 | adap = i2c_get_adapter(++i); | ||
159 | } | ||
160 | |||
161 | return -ENODEV; | ||
147 | } | 162 | } |
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c index 9f60c25c4568..87ca9806f3ee 100644 --- a/sound/soc/soc-jack.c +++ b/sound/soc/soc-jack.c | |||
@@ -48,7 +48,7 @@ int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type, | |||
48 | INIT_LIST_HEAD(&jack->jack_zones); | 48 | INIT_LIST_HEAD(&jack->jack_zones); |
49 | BLOCKING_INIT_NOTIFIER_HEAD(&jack->notifier); | 49 | BLOCKING_INIT_NOTIFIER_HEAD(&jack->notifier); |
50 | 50 | ||
51 | ret = snd_jack_new(card->snd_card, id, type, &jack->jack); | 51 | ret = snd_jack_new(card->snd_card, id, type, &jack->jack, false, false); |
52 | if (ret) | 52 | if (ret) |
53 | return ret; | 53 | return ret; |
54 | 54 | ||
@@ -197,6 +197,7 @@ int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count, | |||
197 | 197 | ||
198 | INIT_LIST_HEAD(&pins[i].list); | 198 | INIT_LIST_HEAD(&pins[i].list); |
199 | list_add(&(pins[i].list), &jack->pins); | 199 | list_add(&(pins[i].list), &jack->pins); |
200 | snd_jack_add_new_kctl(jack->jack, pins[i].pin, pins[i].mask); | ||
200 | } | 201 | } |
201 | 202 | ||
202 | /* Update to reflect the last reported status; canned jack | 203 | /* Update to reflect the last reported status; canned jack |
diff --git a/sound/synth/emux/emux_oss.c b/sound/synth/emux/emux_oss.c index ab37add269ae..82e350e9501c 100644 --- a/sound/synth/emux/emux_oss.c +++ b/sound/synth/emux/emux_oss.c | |||
@@ -118,12 +118,8 @@ snd_emux_open_seq_oss(struct snd_seq_oss_arg *arg, void *closure) | |||
118 | if (snd_BUG_ON(!arg || !emu)) | 118 | if (snd_BUG_ON(!arg || !emu)) |
119 | return -ENXIO; | 119 | return -ENXIO; |
120 | 120 | ||
121 | mutex_lock(&emu->register_mutex); | 121 | if (!snd_emux_inc_count(emu)) |
122 | |||
123 | if (!snd_emux_inc_count(emu)) { | ||
124 | mutex_unlock(&emu->register_mutex); | ||
125 | return -EFAULT; | 122 | return -EFAULT; |
126 | } | ||
127 | 123 | ||
128 | memset(&callback, 0, sizeof(callback)); | 124 | memset(&callback, 0, sizeof(callback)); |
129 | callback.owner = THIS_MODULE; | 125 | callback.owner = THIS_MODULE; |
@@ -135,7 +131,6 @@ snd_emux_open_seq_oss(struct snd_seq_oss_arg *arg, void *closure) | |||
135 | if (p == NULL) { | 131 | if (p == NULL) { |
136 | snd_printk(KERN_ERR "can't create port\n"); | 132 | snd_printk(KERN_ERR "can't create port\n"); |
137 | snd_emux_dec_count(emu); | 133 | snd_emux_dec_count(emu); |
138 | mutex_unlock(&emu->register_mutex); | ||
139 | return -ENOMEM; | 134 | return -ENOMEM; |
140 | } | 135 | } |
141 | 136 | ||
@@ -148,8 +143,6 @@ snd_emux_open_seq_oss(struct snd_seq_oss_arg *arg, void *closure) | |||
148 | reset_port_mode(p, arg->seq_mode); | 143 | reset_port_mode(p, arg->seq_mode); |
149 | 144 | ||
150 | snd_emux_reset_port(p); | 145 | snd_emux_reset_port(p); |
151 | |||
152 | mutex_unlock(&emu->register_mutex); | ||
153 | return 0; | 146 | return 0; |
154 | } | 147 | } |
155 | 148 | ||
@@ -195,13 +188,11 @@ snd_emux_close_seq_oss(struct snd_seq_oss_arg *arg) | |||
195 | if (snd_BUG_ON(!emu)) | 188 | if (snd_BUG_ON(!emu)) |
196 | return -ENXIO; | 189 | return -ENXIO; |
197 | 190 | ||
198 | mutex_lock(&emu->register_mutex); | ||
199 | snd_emux_sounds_off_all(p); | 191 | snd_emux_sounds_off_all(p); |
200 | snd_soundfont_close_check(emu->sflist, SF_CLIENT_NO(p->chset.port)); | 192 | snd_soundfont_close_check(emu->sflist, SF_CLIENT_NO(p->chset.port)); |
201 | snd_seq_event_port_detach(p->chset.client, p->chset.port); | 193 | snd_seq_event_port_detach(p->chset.client, p->chset.port); |
202 | snd_emux_dec_count(emu); | 194 | snd_emux_dec_count(emu); |
203 | 195 | ||
204 | mutex_unlock(&emu->register_mutex); | ||
205 | return 0; | 196 | return 0; |
206 | } | 197 | } |
207 | 198 | ||
diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c index 7778b8e19782..a0209204ae48 100644 --- a/sound/synth/emux/emux_seq.c +++ b/sound/synth/emux/emux_seq.c | |||
@@ -124,12 +124,10 @@ snd_emux_detach_seq(struct snd_emux *emu) | |||
124 | if (emu->voices) | 124 | if (emu->voices) |
125 | snd_emux_terminate_all(emu); | 125 | snd_emux_terminate_all(emu); |
126 | 126 | ||
127 | mutex_lock(&emu->register_mutex); | ||
128 | if (emu->client >= 0) { | 127 | if (emu->client >= 0) { |
129 | snd_seq_delete_kernel_client(emu->client); | 128 | snd_seq_delete_kernel_client(emu->client); |
130 | emu->client = -1; | 129 | emu->client = -1; |
131 | } | 130 | } |
132 | mutex_unlock(&emu->register_mutex); | ||
133 | } | 131 | } |
134 | 132 | ||
135 | 133 | ||
@@ -269,8 +267,8 @@ snd_emux_event_input(struct snd_seq_event *ev, int direct, void *private_data, | |||
269 | /* | 267 | /* |
270 | * increment usage count | 268 | * increment usage count |
271 | */ | 269 | */ |
272 | int | 270 | static int |
273 | snd_emux_inc_count(struct snd_emux *emu) | 271 | __snd_emux_inc_count(struct snd_emux *emu) |
274 | { | 272 | { |
275 | emu->used++; | 273 | emu->used++; |
276 | if (!try_module_get(emu->ops.owner)) | 274 | if (!try_module_get(emu->ops.owner)) |
@@ -284,12 +282,21 @@ snd_emux_inc_count(struct snd_emux *emu) | |||
284 | return 1; | 282 | return 1; |
285 | } | 283 | } |
286 | 284 | ||
285 | int snd_emux_inc_count(struct snd_emux *emu) | ||
286 | { | ||
287 | int ret; | ||
288 | |||
289 | mutex_lock(&emu->register_mutex); | ||
290 | ret = __snd_emux_inc_count(emu); | ||
291 | mutex_unlock(&emu->register_mutex); | ||
292 | return ret; | ||
293 | } | ||
287 | 294 | ||
288 | /* | 295 | /* |
289 | * decrease usage count | 296 | * decrease usage count |
290 | */ | 297 | */ |
291 | void | 298 | static void |
292 | snd_emux_dec_count(struct snd_emux *emu) | 299 | __snd_emux_dec_count(struct snd_emux *emu) |
293 | { | 300 | { |
294 | module_put(emu->card->module); | 301 | module_put(emu->card->module); |
295 | emu->used--; | 302 | emu->used--; |
@@ -298,6 +305,12 @@ snd_emux_dec_count(struct snd_emux *emu) | |||
298 | module_put(emu->ops.owner); | 305 | module_put(emu->ops.owner); |
299 | } | 306 | } |
300 | 307 | ||
308 | void snd_emux_dec_count(struct snd_emux *emu) | ||
309 | { | ||
310 | mutex_lock(&emu->register_mutex); | ||
311 | __snd_emux_dec_count(emu); | ||
312 | mutex_unlock(&emu->register_mutex); | ||
313 | } | ||
301 | 314 | ||
302 | /* | 315 | /* |
303 | * Routine that is called upon a first use of a particular port | 316 | * Routine that is called upon a first use of a particular port |
@@ -317,7 +330,7 @@ snd_emux_use(void *private_data, struct snd_seq_port_subscribe *info) | |||
317 | 330 | ||
318 | mutex_lock(&emu->register_mutex); | 331 | mutex_lock(&emu->register_mutex); |
319 | snd_emux_init_port(p); | 332 | snd_emux_init_port(p); |
320 | snd_emux_inc_count(emu); | 333 | __snd_emux_inc_count(emu); |
321 | mutex_unlock(&emu->register_mutex); | 334 | mutex_unlock(&emu->register_mutex); |
322 | return 0; | 335 | return 0; |
323 | } | 336 | } |
@@ -340,7 +353,7 @@ snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *info) | |||
340 | 353 | ||
341 | mutex_lock(&emu->register_mutex); | 354 | mutex_lock(&emu->register_mutex); |
342 | snd_emux_sounds_off_all(p); | 355 | snd_emux_sounds_off_all(p); |
343 | snd_emux_dec_count(emu); | 356 | __snd_emux_dec_count(emu); |
344 | mutex_unlock(&emu->register_mutex); | 357 | mutex_unlock(&emu->register_mutex); |
345 | return 0; | 358 | return 0; |
346 | } | 359 | } |