aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2015-03-23 08:14:02 -0400
committerTakashi Iwai <tiwai@suse.de>2015-03-23 08:14:02 -0400
commit3372dbdd8ca11f51be8c6a30b2bc79eb04c4a902 (patch)
treed4499bf5a5665b4820ffaf96bce55bf6b895195e
parentbc465aa9d045feb0e13b4a8f32cc33c1943f62d6 (diff)
parent967b1307b69b8ada8b331e01046ad1ef83742e99 (diff)
Merge branch 'for-next' into topic/hda-core
-rw-r--r--Documentation/devicetree/bindings/sound/nvidia,tegra-audio-max98090.txt1
-rw-r--r--Documentation/sound/alsa/HD-Audio.txt6
-rw-r--r--Documentation/sound/alsa/timestamping.txt200
-rw-r--r--include/sound/compress_driver.h4
-rw-r--r--include/sound/control.h2
-rw-r--r--include/sound/core.h3
-rw-r--r--include/sound/pcm.h66
-rw-r--r--include/sound/pcm_params.h7
-rw-r--r--include/sound/seq_device.h46
-rw-r--r--include/sound/seq_kernel.h6
-rw-r--r--include/sound/soc.h18
-rw-r--r--include/uapi/sound/asequencer.h1
-rw-r--r--include/uapi/sound/asound.h39
-rw-r--r--include/uapi/sound/compress_offload.h2
-rw-r--r--include/uapi/sound/emu10k1.h3
-rw-r--r--include/uapi/sound/hdspm.h6
-rw-r--r--sound/aoa/soundbus/i2sbus/core.c2
-rw-r--r--sound/core/control.c271
-rw-r--r--sound/core/device.c47
-rw-r--r--sound/core/hwdep.c4
-rw-r--r--sound/core/init.c5
-rw-r--r--sound/core/oss/mixer_oss.c4
-rw-r--r--sound/core/oss/pcm_oss.c1
-rw-r--r--sound/core/pcm.c105
-rw-r--r--sound/core/pcm_compat.c28
-rw-r--r--sound/core/pcm_dmaengine.c4
-rw-r--r--sound/core/pcm_lib.c88
-rw-r--r--sound/core/pcm_native.c41
-rw-r--r--sound/core/rawmidi.c8
-rw-r--r--sound/core/seq/oss/seq_oss.c22
-rw-r--r--sound/core/seq/oss/seq_oss_init.c4
-rw-r--r--sound/core/seq/oss/seq_oss_midi.c5
-rw-r--r--sound/core/seq/oss/seq_oss_readq.c9
-rw-r--r--sound/core/seq/oss/seq_oss_synth.c12
-rw-r--r--sound/core/seq/oss/seq_oss_synth.h4
-rw-r--r--sound/core/seq/seq_device.c571
-rw-r--r--sound/core/seq/seq_dummy.c6
-rw-r--r--sound/core/seq/seq_fifo.c4
-rw-r--r--sound/core/seq/seq_memory.c8
-rw-r--r--sound/core/seq/seq_midi.c36
-rw-r--r--sound/core/seq/seq_ports.c4
-rw-r--r--sound/core/seq/seq_prioq.c4
-rw-r--r--sound/core/seq/seq_queue.c4
-rw-r--r--sound/core/seq/seq_timer.c4
-rw-r--r--sound/core/sound.c14
-rw-r--r--sound/core/timer.c4
-rw-r--r--sound/drivers/opl3/opl3_seq.c34
-rw-r--r--sound/drivers/opl4/opl4_seq.c33
-rw-r--r--sound/firewire/amdtp.c8
-rw-r--r--sound/firewire/fireworks/fireworks_transaction.c2
-rw-r--r--sound/isa/sb/emu8000_synth.c35
-rw-r--r--sound/oss/opl3.c4
-rw-r--r--sound/oss/sb_ess.c19
-rw-r--r--sound/oss/sb_midi.c6
-rw-r--r--sound/oss/sys_timer.c35
-rw-r--r--sound/pci/ac97/ac97_codec.c1
-rw-r--r--sound/pci/ac97/ac97_patch.c27
-rw-r--r--sound/pci/azt3328.c7
-rw-r--r--sound/pci/cmipci.c2
-rw-r--r--sound/pci/emu10k1/emu10k1_synth.c35
-rw-r--r--sound/pci/hda/Makefile2
-rw-r--r--sound/pci/hda/hda_beep.c33
-rw-r--r--sound/pci/hda/hda_beep.h1
-rw-r--r--sound/pci/hda/hda_bind.c342
-rw-r--r--sound/pci/hda/hda_codec.c1225
-rw-r--r--sound/pci/hda/hda_codec.h162
-rw-r--r--sound/pci/hda/hda_controller.c263
-rw-r--r--sound/pci/hda/hda_controller.h397
-rw-r--r--sound/pci/hda/hda_generic.c549
-rw-r--r--sound/pci/hda/hda_generic.h9
-rw-r--r--sound/pci/hda/hda_hwdep.c5
-rw-r--r--sound/pci/hda/hda_i915.c2
-rw-r--r--sound/pci/hda/hda_intel.c89
-rw-r--r--sound/pci/hda/hda_intel.h2
-rw-r--r--sound/pci/hda/hda_jack.c8
-rw-r--r--sound/pci/hda/hda_local.h59
-rw-r--r--sound/pci/hda/hda_priv.h406
-rw-r--r--sound/pci/hda/hda_proc.c8
-rw-r--r--sound/pci/hda/hda_sysfs.c2
-rw-r--r--sound/pci/hda/hda_tegra.c50
-rw-r--r--sound/pci/hda/hda_trace.h28
-rw-r--r--sound/pci/hda/patch_analog.c16
-rw-r--r--sound/pci/hda/patch_ca0110.c16
-rw-r--r--sound/pci/hda/patch_ca0132.c50
-rw-r--r--sound/pci/hda/patch_cirrus.c16
-rw-r--r--sound/pci/hda/patch_cmedia.c16
-rw-r--r--sound/pci/hda/patch_conexant.c16
-rw-r--r--sound/pci/hda/patch_hdmi.c71
-rw-r--r--sound/pci/hda/patch_realtek.c59
-rw-r--r--sound/pci/hda/patch_si3054.c27
-rw-r--r--sound/pci/hda/patch_sigmatel.c31
-rw-r--r--sound/pci/hda/patch_via.c695
-rw-r--r--sound/pci/ice1712/wtm.c172
-rw-r--r--sound/pci/rme9652/hdspm.c141
-rw-r--r--sound/soc/atmel/atmel_ssc_dai.c111
-rw-r--r--sound/soc/atmel/atmel_ssc_dai.h1
-rw-r--r--sound/soc/codecs/Kconfig18
-rw-r--r--sound/soc/codecs/Makefile4
-rw-r--r--sound/soc/codecs/adau1977.c17
-rw-r--r--sound/soc/codecs/cs35l32.c19
-rw-r--r--sound/soc/codecs/cs4265.c19
-rw-r--r--sound/soc/codecs/max98357a.c11
-rw-r--r--sound/soc/codecs/pcm512x.c178
-rw-r--r--sound/soc/codecs/rt286.c17
-rw-r--r--sound/soc/codecs/rt5670.h3
-rw-r--r--sound/soc/codecs/rt5677.c44
-rw-r--r--sound/soc/codecs/rt5677.h6
-rw-r--r--sound/soc/codecs/sn95031.c14
-rw-r--r--sound/soc/codecs/sn95031.h3
-rw-r--r--sound/soc/codecs/sta350.c30
-rw-r--r--sound/soc/codecs/tas2552.c13
-rw-r--r--sound/soc/codecs/wm8804-i2c.c64
-rw-r--r--sound/soc/codecs/wm8804-spi.c56
-rw-r--r--sound/soc/codecs/wm8804.c281
-rw-r--r--sound/soc/codecs/wm8804.h7
-rw-r--r--sound/soc/codecs/wm_adsp.c13
-rw-r--r--sound/soc/davinci/Kconfig18
-rw-r--r--sound/soc/davinci/Makefile2
-rw-r--r--sound/soc/davinci/davinci-i2s.c67
-rw-r--r--sound/soc/davinci/davinci-mcasp.c99
-rw-r--r--sound/soc/davinci/davinci-pcm.c861
-rw-r--r--sound/soc/davinci/davinci-pcm.h41
-rw-r--r--sound/soc/davinci/davinci-vcif.c55
-rw-r--r--sound/soc/fsl/fsl-asoc-card.c6
-rw-r--r--sound/soc/fsl/imx-es8328.c6
-rw-r--r--sound/soc/fsl/wm1133-ev1.c12
-rw-r--r--sound/soc/generic/simple-card.c20
-rw-r--r--sound/soc/intel/broadwell.c16
-rw-r--r--sound/soc/intel/byt-max98090.c11
-rw-r--r--sound/soc/intel/bytcr_dpcm_rt5640.c4
-rw-r--r--sound/soc/intel/cht_bsw_rt5645.c16
-rw-r--r--sound/soc/intel/cht_bsw_rt5672.c9
-rw-r--r--sound/soc/intel/haswell.c4
-rw-r--r--sound/soc/intel/mfld_machine.c24
-rw-r--r--sound/soc/intel/sst-mfld-platform-pcm.c60
-rw-r--r--sound/soc/intel/sst-mfld-platform.h1
-rw-r--r--sound/soc/intel/sst/sst.c128
-rw-r--r--sound/soc/intel/sst/sst.h12
-rw-r--r--sound/soc/intel/sst/sst_drv_interface.c65
-rw-r--r--sound/soc/intel/sst/sst_loader.c10
-rw-r--r--sound/soc/omap/Kconfig4
-rw-r--r--sound/soc/omap/ams-delta.c4
-rw-r--r--sound/soc/omap/omap-abe-twl6040.c10
-rw-r--r--sound/soc/omap/omap-pcm.c21
-rw-r--r--sound/soc/omap/omap-twl4030.c12
-rw-r--r--sound/soc/omap/rx51.c6
-rw-r--r--sound/soc/pxa/hx4700.c11
-rw-r--r--sound/soc/pxa/palm27x.c11
-rw-r--r--sound/soc/pxa/ttc-dkb.c15
-rw-r--r--sound/soc/pxa/z2.c10
-rw-r--r--sound/soc/samsung/h1940_uda1380.c9
-rw-r--r--sound/soc/samsung/littlemill.c12
-rw-r--r--sound/soc/samsung/lowland.c14
-rw-r--r--sound/soc/samsung/rx1950_uda1380.c9
-rw-r--r--sound/soc/samsung/smartq_wm8987.c11
-rw-r--r--sound/soc/samsung/speyside.c14
-rw-r--r--sound/soc/samsung/tobermory.c13
-rw-r--r--sound/soc/soc-core.c16
-rw-r--r--sound/soc/soc-jack.c42
-rw-r--r--sound/soc/soc-pcm.c1
-rw-r--r--sound/soc/tegra/tegra_alc5632.c9
-rw-r--r--sound/soc/tegra/tegra_max98090.c26
-rw-r--r--sound/soc/tegra/tegra_rt5640.c10
-rw-r--r--sound/soc/tegra/tegra_rt5677.c14
-rw-r--r--sound/soc/tegra/tegra_wm8903.c18
-rw-r--r--sound/usb/quirks.c40
166 files changed, 4283 insertions, 5504 deletions
diff --git a/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-max98090.txt b/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-max98090.txt
index c949abc2992f..c3495beba358 100644
--- a/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-max98090.txt
+++ b/Documentation/devicetree/bindings/sound/nvidia,tegra-audio-max98090.txt
@@ -18,6 +18,7 @@ Required properties:
18 * Headphones 18 * Headphones
19 * Speakers 19 * Speakers
20 * Mic Jack 20 * Mic Jack
21 * Int Mic
21 22
22- nvidia,i2s-controller : The phandle of the Tegra I2S controller that's 23- nvidia,i2s-controller : The phandle of the Tegra I2S controller that's
23 connected to the CODEC. 24 connected to the CODEC.
diff --git a/Documentation/sound/alsa/HD-Audio.txt b/Documentation/sound/alsa/HD-Audio.txt
index 42a0a39b77e6..e7193aac669c 100644
--- a/Documentation/sound/alsa/HD-Audio.txt
+++ b/Documentation/sound/alsa/HD-Audio.txt
@@ -466,7 +466,11 @@ The generic parser supports the following hints:
466- add_jack_modes (bool): add "xxx Jack Mode" enum controls to each 466- add_jack_modes (bool): add "xxx Jack Mode" enum controls to each
467 I/O jack for allowing to change the headphone amp and mic bias VREF 467 I/O jack for allowing to change the headphone amp and mic bias VREF
468 capabilities 468 capabilities
469- power_down_unused (bool): power down the unused widgets 469- power_save_node (bool): advanced power management for each widget,
470 controlling the power sate (D0/D3) of each widget node depending on
471 the actual pin and stream states
472- power_down_unused (bool): power down the unused widgets, a subset of
473 power_save_node, and will be dropped in future
470- add_hp_mic (bool): add the headphone to capture source if possible 474- add_hp_mic (bool): add the headphone to capture source if possible
471- hp_mic_detect (bool): enable/disable the hp/mic shared input for a 475- hp_mic_detect (bool): enable/disable the hp/mic shared input for a
472 single built-in mic case; default true 476 single built-in mic case; default true
diff --git a/Documentation/sound/alsa/timestamping.txt b/Documentation/sound/alsa/timestamping.txt
new file mode 100644
index 000000000000..0b191a23f534
--- /dev/null
+++ b/Documentation/sound/alsa/timestamping.txt
@@ -0,0 +1,200 @@
1The ALSA API can provide two different system timestamps:
2
3- Trigger_tstamp is the system time snapshot taken when the .trigger
4callback is invoked. This snapshot is taken by the ALSA core in the
5general case, but specific hardware may have synchronization
6capabilities or conversely may only be able to provide a correct
7estimate with a delay. In the latter two cases, the low-level driver
8is responsible for updating the trigger_tstamp at the most appropriate
9and precise moment. Applications should not rely solely on the first
10trigger_tstamp but update their internal calculations if the driver
11provides a refined estimate with a delay.
12
13- tstamp is the current system timestamp updated during the last
14event or application query.
15The difference (tstamp - trigger_tstamp) defines the elapsed time.
16
17The ALSA API provides reports two basic pieces of information, avail
18and delay, which combined with the trigger and current system
19timestamps allow for applications to keep track of the 'fullness' of
20the ring buffer and the amount of queued samples.
21
22The use of these different pointers and time information depends on
23the application needs:
24
25- 'avail' reports how much can be written in the ring buffer
26- 'delay' reports the time it will take to hear a new sample after all
27queued samples have been played out.
28
29When timestamps are enabled, the avail/delay information is reported
30along with a snapshot of system time. Applications can select from
31CLOCK_REALTIME (NTP corrections including going backwards),
32CLOCK_MONOTONIC (NTP corrections but never going backwards),
33CLOCK_MONOTIC_RAW (without NTP corrections) and change the mode
34dynamically with sw_params
35
36
37The ALSA API also provide an audio_tstamp which reflects the passage
38of time as measured by different components of audio hardware. In
39ascii-art, this could be represented as follows (for the playback
40case):
41
42
43--------------------------------------------------------------> time
44 ^ ^ ^ ^ ^
45 | | | | |
46 analog link dma app FullBuffer
47 time time time time time
48 | | | | |
49 |< codec delay >|<--hw delay-->|<queued samples>|<---avail->|
50 |<----------------- delay---------------------->| |
51 |<----ring buffer length---->|
52
53The analog time is taken at the last stage of the playback, as close
54as possible to the actual transducer
55
56The link time is taken at the output of the SOC/chipset as the samples
57are pushed on a link. The link time can be directly measured if
58supported in hardware by sample counters or wallclocks (e.g. with
59HDAudio 24MHz or PTP clock for networked solutions) or indirectly
60estimated (e.g. with the frame counter in USB).
61
62The DMA time is measured using counters - typically the least reliable
63of all measurements due to the bursty natured of DMA transfers.
64
65The app time corresponds to the time tracked by an application after
66writing in the ring buffer.
67
68The application can query what the hardware supports, define which
69audio time it wants reported by selecting the relevant settings in
70audio_tstamp_config fields, get an estimate of the timestamp
71accuracy. It can also request the delay-to-analog be included in the
72measurement. Direct access to the link time is very interesting on
73platforms that provide an embedded DSP; measuring directly the link
74time with dedicated hardware, possibly synchronized with system time,
75removes the need to keep track of internal DSP processing times and
76latency.
77
78In case the application requests an audio tstamp that is not supported
79in hardware/low-level driver, the type is overridden as DEFAULT and the
80timestamp will report the DMA time based on the hw_pointer value.
81
82For backwards compatibility with previous implementations that did not
83provide timestamp selection, with a zero-valued COMPAT timestamp type
84the results will default to the HDAudio wall clock for playback
85streams and to the DMA time (hw_ptr) in all other cases.
86
87The audio timestamp accuracy can be returned to user-space, so that
88appropriate decisions are made:
89
90- for dma time (default), the granularity of the transfers can be
91 inferred from the steps between updates and in turn provide
92 information on how much the application pointer can be rewound
93 safely.
94
95- the link time can be used to track long-term drifts between audio
96 and system time using the (tstamp-trigger_tstamp)/audio_tstamp
97 ratio, the precision helps define how much smoothing/low-pass
98 filtering is required. The link time can be either reset on startup
99 or reported as is (the latter being useful to compare progress of
100 different streams - but may require the wallclock to be always
101 running and not wrap-around during idle periods). If supported in
102 hardware, the absolute link time could also be used to define a
103 precise start time (patches WIP)
104
105- including the delay in the audio timestamp may
106 counter-intuitively not increase the precision of timestamps, e.g. if a
107 codec includes variable-latency DSP processing or a chain of
108 hardware components the delay is typically not known with precision.
109
110The accuracy is reported in nanosecond units (using an unsigned 32-bit
111word), which gives a max precision of 4.29s, more than enough for
112audio applications...
113
114Due to the varied nature of timestamping needs, even for a single
115application, the audio_tstamp_config can be changed dynamically. In
116the STATUS ioctl, the parameters are read-only and do not allow for
117any application selection. To work around this limitation without
118impacting legacy applications, a new STATUS_EXT ioctl is introduced
119with read/write parameters. ALSA-lib will be modified to make use of
120STATUS_EXT and effectively deprecate STATUS.
121
122The ALSA API only allows for a single audio timestamp to be reported
123at a time. This is a conscious design decision, reading the audio
124timestamps from hardware registers or from IPC takes time, the more
125timestamps are read the more imprecise the combined measurements
126are. To avoid any interpretation issues, a single (system, audio)
127timestamp is reported. Applications that need different timestamps
128will be required to issue multiple queries and perform an
129interpolation of the results
130
131In some hardware-specific configuration, the system timestamp is
132latched by a low-level audio subsytem, and the information provided
133back to the driver. Due to potential delays in the communication with
134the hardware, there is a risk of misalignment with the avail and delay
135information. To make sure applications are not confused, a
136driver_timestamp field is added in the snd_pcm_status structure; this
137timestamp shows when the information is put together by the driver
138before returning from the STATUS and STATUS_EXT ioctl. in most cases
139this driver_timestamp will be identical to the regular system tstamp.
140
141Examples of typestamping with HDaudio:
142
1431. DMA timestamp, no compensation for DMA+analog delay
144$ ./audio_time -p --ts_type=1
145playback: systime: 341121338 nsec, audio time 342000000 nsec, systime delta -878662
146playback: systime: 426236663 nsec, audio time 427187500 nsec, systime delta -950837
147playback: systime: 597080580 nsec, audio time 598000000 nsec, systime delta -919420
148playback: systime: 682059782 nsec, audio time 683020833 nsec, systime delta -961051
149playback: systime: 852896415 nsec, audio time 853854166 nsec, systime delta -957751
150playback: systime: 937903344 nsec, audio time 938854166 nsec, systime delta -950822
151
1522. DMA timestamp, compensation for DMA+analog delay
153$ ./audio_time -p --ts_type=1 -d
154playback: systime: 341053347 nsec, audio time 341062500 nsec, systime delta -9153
155playback: systime: 426072447 nsec, audio time 426062500 nsec, systime delta 9947
156playback: systime: 596899518 nsec, audio time 596895833 nsec, systime delta 3685
157playback: systime: 681915317 nsec, audio time 681916666 nsec, systime delta -1349
158playback: systime: 852741306 nsec, audio time 852750000 nsec, systime delta -8694
159
1603. link timestamp, compensation for DMA+analog delay
161$ ./audio_time -p --ts_type=2 -d
162playback: systime: 341060004 nsec, audio time 341062791 nsec, systime delta -2787
163playback: systime: 426242074 nsec, audio time 426244875 nsec, systime delta -2801
164playback: systime: 597080992 nsec, audio time 597084583 nsec, systime delta -3591
165playback: systime: 682084512 nsec, audio time 682088291 nsec, systime delta -3779
166playback: systime: 852936229 nsec, audio time 852940916 nsec, systime delta -4687
167playback: systime: 938107562 nsec, audio time 938112708 nsec, systime delta -5146
168
169Example 1 shows that the timestamp at the DMA level is close to 1ms
170ahead of the actual playback time (as a side time this sort of
171measurement can help define rewind safeguards). Compensating for the
172DMA-link delay in example 2 helps remove the hardware buffering abut
173the information is still very jittery, with up to one sample of
174error. In example 3 where the timestamps are measured with the link
175wallclock, the timestamps show a monotonic behavior and a lower
176dispersion.
177
178Example 3 and 4 are with USB audio class. Example 3 shows a high
179offset between audio time and system time due to buffering. Example 4
180shows how compensating for the delay exposes a 1ms accuracy (due to
181the use of the frame counter by the driver)
182
183Example 3: DMA timestamp, no compensation for delay, delta of ~5ms
184$ ./audio_time -p -Dhw:1 -t1
185playback: systime: 120174019 nsec, audio time 125000000 nsec, systime delta -4825981
186playback: systime: 245041136 nsec, audio time 250000000 nsec, systime delta -4958864
187playback: systime: 370106088 nsec, audio time 375000000 nsec, systime delta -4893912
188playback: systime: 495040065 nsec, audio time 500000000 nsec, systime delta -4959935
189playback: systime: 620038179 nsec, audio time 625000000 nsec, systime delta -4961821
190playback: systime: 745087741 nsec, audio time 750000000 nsec, systime delta -4912259
191playback: systime: 870037336 nsec, audio time 875000000 nsec, systime delta -4962664
192
193Example 4: DMA timestamp, compensation for delay, delay of ~1ms
194$ ./audio_time -p -Dhw:1 -t1 -d
195playback: systime: 120190520 nsec, audio time 120000000 nsec, systime delta 190520
196playback: systime: 245036740 nsec, audio time 244000000 nsec, systime delta 1036740
197playback: systime: 370034081 nsec, audio time 369000000 nsec, systime delta 1034081
198playback: systime: 495159907 nsec, audio time 494000000 nsec, systime delta 1159907
199playback: systime: 620098824 nsec, audio time 619000000 nsec, systime delta 1098824
200playback: systime: 745031847 nsec, audio time 744000000 nsec, systime delta 1031847
diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
index f48089d364c5..fa1d05512c09 100644
--- a/include/sound/compress_driver.h
+++ b/include/sound/compress_driver.h
@@ -70,7 +70,7 @@ struct snd_compr_runtime {
70 * @device: device pointer 70 * @device: device pointer
71 * @direction: stream direction, playback/recording 71 * @direction: stream direction, playback/recording
72 * @metadata_set: metadata set flag, true when set 72 * @metadata_set: metadata set flag, true when set
73 * @next_track: has userspace signall next track transistion, true when set 73 * @next_track: has userspace signal next track transition, true when set
74 * @private_data: pointer to DSP private data 74 * @private_data: pointer to DSP private data
75 */ 75 */
76struct snd_compr_stream { 76struct snd_compr_stream {
@@ -95,7 +95,7 @@ struct snd_compr_stream {
95 * and the stream properties 95 * and the stream properties
96 * @get_params: retrieve the codec parameters, mandatory 96 * @get_params: retrieve the codec parameters, mandatory
97 * @set_metadata: Set the metadata values for a stream 97 * @set_metadata: Set the metadata values for a stream
98 * @get_metadata: retreives the requested metadata values from stream 98 * @get_metadata: retrieves the requested metadata values from stream
99 * @trigger: Trigger operations like start, pause, resume, drain, stop. 99 * @trigger: Trigger operations like start, pause, resume, drain, stop.
100 * This callback is mandatory 100 * This callback is mandatory
101 * @pointer: Retrieve current h/w pointer information. Mandatory 101 * @pointer: Retrieve current h/w pointer information. Mandatory
diff --git a/include/sound/control.h b/include/sound/control.h
index 75f3054023f7..95aad6d3fd1a 100644
--- a/include/sound/control.h
+++ b/include/sound/control.h
@@ -227,7 +227,7 @@ snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave)
227 * Add a virtual slave control to the given master. 227 * Add a virtual slave control to the given master.
228 * Unlike snd_ctl_add_slave(), the element added via this function 228 * Unlike snd_ctl_add_slave(), the element added via this function
229 * is supposed to have volatile values, and get callback is called 229 * is supposed to have volatile values, and get callback is called
230 * at each time quried from the master. 230 * at each time queried from the master.
231 * 231 *
232 * When the control peeks the hardware values directly and the value 232 * When the control peeks the hardware values directly and the value
233 * can be changed by other means than the put callback of the element, 233 * can be changed by other means than the put callback of the element,
diff --git a/include/sound/core.h b/include/sound/core.h
index da5748289968..b12931f513f4 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
@@ -278,7 +278,8 @@ int snd_device_new(struct snd_card *card, enum snd_device_type type,
278 void *device_data, struct snd_device_ops *ops); 278 void *device_data, struct snd_device_ops *ops);
279int snd_device_register(struct snd_card *card, void *device_data); 279int snd_device_register(struct snd_card *card, void *device_data);
280int snd_device_register_all(struct snd_card *card); 280int snd_device_register_all(struct snd_card *card);
281int snd_device_disconnect_all(struct snd_card *card); 281void snd_device_disconnect(struct snd_card *card, void *device_data);
282void snd_device_disconnect_all(struct snd_card *card);
282void snd_device_free(struct snd_card *card, void *device_data); 283void snd_device_free(struct snd_card *card, void *device_data);
283void snd_device_free_all(struct snd_card *card); 284void snd_device_free_all(struct snd_card *card);
284 285
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index c0ddb7e69c28..0cb7f3f5df7b 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -60,6 +60,9 @@ struct snd_pcm_hardware {
60 60
61struct snd_pcm_substream; 61struct snd_pcm_substream;
62 62
63struct snd_pcm_audio_tstamp_config; /* definitions further down */
64struct snd_pcm_audio_tstamp_report;
65
63struct snd_pcm_ops { 66struct snd_pcm_ops {
64 int (*open)(struct snd_pcm_substream *substream); 67 int (*open)(struct snd_pcm_substream *substream);
65 int (*close)(struct snd_pcm_substream *substream); 68 int (*close)(struct snd_pcm_substream *substream);
@@ -71,8 +74,10 @@ struct snd_pcm_ops {
71 int (*prepare)(struct snd_pcm_substream *substream); 74 int (*prepare)(struct snd_pcm_substream *substream);
72 int (*trigger)(struct snd_pcm_substream *substream, int cmd); 75 int (*trigger)(struct snd_pcm_substream *substream, int cmd);
73 snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *substream); 76 snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *substream);
74 int (*wall_clock)(struct snd_pcm_substream *substream, 77 int (*get_time_info)(struct snd_pcm_substream *substream,
75 struct timespec *audio_ts); 78 struct timespec *system_ts, struct timespec *audio_ts,
79 struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
80 struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
76 int (*copy)(struct snd_pcm_substream *substream, int channel, 81 int (*copy)(struct snd_pcm_substream *substream, int channel,
77 snd_pcm_uframes_t pos, 82 snd_pcm_uframes_t pos,
78 void __user *buf, snd_pcm_uframes_t count); 83 void __user *buf, snd_pcm_uframes_t count);
@@ -281,6 +286,58 @@ struct snd_pcm_hw_constraint_ranges {
281 286
282struct snd_pcm_hwptr_log; 287struct snd_pcm_hwptr_log;
283 288
289/*
290 * userspace-provided audio timestamp config to kernel,
291 * structure is for internal use only and filled with dedicated unpack routine
292 */
293struct snd_pcm_audio_tstamp_config {
294 /* 5 of max 16 bits used */
295 u32 type_requested:4;
296 u32 report_delay:1; /* add total delay to A/D or D/A */
297};
298
299static inline void snd_pcm_unpack_audio_tstamp_config(__u32 data,
300 struct snd_pcm_audio_tstamp_config *config)
301{
302 config->type_requested = data & 0xF;
303 config->report_delay = (data >> 4) & 1;
304}
305
306/*
307 * kernel-provided audio timestamp report to user-space
308 * structure is for internal use only and read by dedicated pack routine
309 */
310struct snd_pcm_audio_tstamp_report {
311 /* 6 of max 16 bits used for bit-fields */
312
313 /* for backwards compatibility */
314 u32 valid:1;
315
316 /* actual type if hardware could not support requested timestamp */
317 u32 actual_type:4;
318
319 /* accuracy represented in ns units */
320 u32 accuracy_report:1; /* 0 if accuracy unknown, 1 if accuracy field is valid */
321 u32 accuracy; /* up to 4.29s, will be packed in separate field */
322};
323
324static inline void snd_pcm_pack_audio_tstamp_report(__u32 *data, __u32 *accuracy,
325 const struct snd_pcm_audio_tstamp_report *report)
326{
327 u32 tmp;
328
329 tmp = report->accuracy_report;
330 tmp <<= 4;
331 tmp |= report->actual_type;
332 tmp <<= 1;
333 tmp |= report->valid;
334
335 *data &= 0xffff; /* zero-clear MSBs */
336 *data |= (tmp << 16);
337 *accuracy = report->accuracy;
338}
339
340
284struct snd_pcm_runtime { 341struct snd_pcm_runtime {
285 /* -- Status -- */ 342 /* -- Status -- */
286 struct snd_pcm_substream *trigger_master; 343 struct snd_pcm_substream *trigger_master;
@@ -361,6 +418,11 @@ struct snd_pcm_runtime {
361 418
362 struct snd_dma_buffer *dma_buffer_p; /* allocated buffer */ 419 struct snd_dma_buffer *dma_buffer_p; /* allocated buffer */
363 420
421 /* -- audio timestamp config -- */
422 struct snd_pcm_audio_tstamp_config audio_tstamp_config;
423 struct snd_pcm_audio_tstamp_report audio_tstamp_report;
424 struct timespec driver_tstamp;
425
364#if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) 426#if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
365 /* -- OSS things -- */ 427 /* -- OSS things -- */
366 struct snd_pcm_oss_runtime oss; 428 struct snd_pcm_oss_runtime oss;
diff --git a/include/sound/pcm_params.h b/include/sound/pcm_params.h
index 3c45f3924ba7..c704357775fc 100644
--- a/include/sound/pcm_params.h
+++ b/include/sound/pcm_params.h
@@ -366,4 +366,11 @@ static inline int params_physical_width(const struct snd_pcm_hw_params *p)
366 return snd_pcm_format_physical_width(params_format(p)); 366 return snd_pcm_format_physical_width(params_format(p));
367} 367}
368 368
369static inline void
370params_set_format(struct snd_pcm_hw_params *p, snd_pcm_format_t fmt)
371{
372 snd_mask_set(hw_param_mask(p, SNDRV_PCM_HW_PARAM_FORMAT),
373 (__force int)fmt);
374}
375
369#endif /* __SOUND_PCM_PARAMS_H */ 376#endif /* __SOUND_PCM_PARAMS_H */
diff --git a/include/sound/seq_device.h b/include/sound/seq_device.h
index 2b5f24cc7548..ddc0d504cf39 100644
--- a/include/sound/seq_device.h
+++ b/include/sound/seq_device.h
@@ -25,29 +25,26 @@
25 * registered device information 25 * registered device information
26 */ 26 */
27 27
28#define ID_LEN 32
29
30/* status flag */
31#define SNDRV_SEQ_DEVICE_FREE 0
32#define SNDRV_SEQ_DEVICE_REGISTERED 1
33
34struct snd_seq_device { 28struct snd_seq_device {
35 /* device info */ 29 /* device info */
36 struct snd_card *card; /* sound card */ 30 struct snd_card *card; /* sound card */
37 int device; /* device number */ 31 int device; /* device number */
38 char id[ID_LEN]; /* driver id */ 32 const char *id; /* driver id */
39 char name[80]; /* device name */ 33 char name[80]; /* device name */
40 int argsize; /* size of the argument */ 34 int argsize; /* size of the argument */
41 void *driver_data; /* private data for driver */ 35 void *driver_data; /* private data for driver */
42 int status; /* flag - read only */
43 void *private_data; /* private data for the caller */ 36 void *private_data; /* private data for the caller */
44 void (*private_free)(struct snd_seq_device *device); 37 void (*private_free)(struct snd_seq_device *device);
45 struct list_head list; /* link to next device */ 38 struct device dev;
46}; 39};
47 40
41#define to_seq_dev(_dev) \
42 container_of(_dev, struct snd_seq_device, dev)
43
44/* sequencer driver */
48 45
49/* driver operators 46/* driver operators
50 * init_device: 47 * probe:
51 * Initialize the device with given parameters. 48 * Initialize the device with given parameters.
52 * Typically, 49 * Typically,
53 * 1. call snd_hwdep_new 50 * 1. call snd_hwdep_new
@@ -55,25 +52,40 @@ struct snd_seq_device {
55 * 3. call snd_hwdep_register 52 * 3. call snd_hwdep_register
56 * 4. store the instance to dev->driver_data pointer. 53 * 4. store the instance to dev->driver_data pointer.
57 * 54 *
58 * free_device: 55 * remove:
59 * Release the private data. 56 * Release the private data.
60 * Typically, call snd_device_free(dev->card, dev->driver_data) 57 * Typically, call snd_device_free(dev->card, dev->driver_data)
61 */ 58 */
62struct snd_seq_dev_ops { 59struct snd_seq_driver {
63 int (*init_device)(struct snd_seq_device *dev); 60 struct device_driver driver;
64 int (*free_device)(struct snd_seq_device *dev); 61 char *id;
62 int argsize;
65}; 63};
66 64
65#define to_seq_drv(_drv) \
66 container_of(_drv, struct snd_seq_driver, driver)
67
67/* 68/*
68 * prototypes 69 * prototypes
69 */ 70 */
71#ifdef CONFIG_MODULES
70void snd_seq_device_load_drivers(void); 72void snd_seq_device_load_drivers(void);
71int snd_seq_device_new(struct snd_card *card, int device, char *id, int argsize, struct snd_seq_device **result); 73#else
72int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry, int argsize); 74#define snd_seq_device_load_drivers()
73int snd_seq_device_unregister_driver(char *id); 75#endif
76int snd_seq_device_new(struct snd_card *card, int device, const char *id,
77 int argsize, struct snd_seq_device **result);
74 78
75#define SNDRV_SEQ_DEVICE_ARGPTR(dev) (void *)((char *)(dev) + sizeof(struct snd_seq_device)) 79#define SNDRV_SEQ_DEVICE_ARGPTR(dev) (void *)((char *)(dev) + sizeof(struct snd_seq_device))
76 80
81int __must_check __snd_seq_driver_register(struct snd_seq_driver *drv,
82 struct module *mod);
83#define snd_seq_driver_register(drv) \
84 __snd_seq_driver_register(drv, THIS_MODULE)
85void snd_seq_driver_unregister(struct snd_seq_driver *drv);
86
87#define module_snd_seq_driver(drv) \
88 module_driver(drv, snd_seq_driver_register, snd_seq_driver_unregister)
77 89
78/* 90/*
79 * id strings for generic devices 91 * id strings for generic devices
diff --git a/include/sound/seq_kernel.h b/include/sound/seq_kernel.h
index 18a2ac58b88f..feb58d455560 100644
--- a/include/sound/seq_kernel.h
+++ b/include/sound/seq_kernel.h
@@ -99,13 +99,9 @@ int snd_seq_event_port_attach(int client, struct snd_seq_port_callback *pcbp,
99int snd_seq_event_port_detach(int client, int port); 99int snd_seq_event_port_detach(int client, int port);
100 100
101#ifdef CONFIG_MODULES 101#ifdef CONFIG_MODULES
102void snd_seq_autoload_lock(void);
103void snd_seq_autoload_unlock(void);
104void snd_seq_autoload_init(void); 102void snd_seq_autoload_init(void);
105#define snd_seq_autoload_exit() snd_seq_autoload_lock() 103void snd_seq_autoload_exit(void);
106#else 104#else
107#define snd_seq_autoload_lock()
108#define snd_seq_autoload_unlock()
109#define snd_seq_autoload_init() 105#define snd_seq_autoload_init()
110#define snd_seq_autoload_exit() 106#define snd_seq_autoload_exit()
111#endif 107#endif
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 0d1ade195628..b371aef9819f 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -450,8 +450,10 @@ int soc_dai_hw_params(struct snd_pcm_substream *substream,
450 struct snd_soc_dai *dai); 450 struct snd_soc_dai *dai);
451 451
452/* Jack reporting */ 452/* Jack reporting */
453int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type, 453int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type,
454 struct snd_soc_jack *jack); 454 struct snd_soc_jack *jack, struct snd_soc_jack_pin *pins,
455 unsigned int num_pins);
456
455void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask); 457void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
456int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count, 458int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
457 struct snd_soc_jack_pin *pins); 459 struct snd_soc_jack_pin *pins);
@@ -659,7 +661,7 @@ struct snd_soc_jack_gpio {
659struct snd_soc_jack { 661struct snd_soc_jack {
660 struct mutex mutex; 662 struct mutex mutex;
661 struct snd_jack *jack; 663 struct snd_jack *jack;
662 struct snd_soc_codec *codec; 664 struct snd_soc_card *card;
663 struct list_head pins; 665 struct list_head pins;
664 int status; 666 int status;
665 struct blocking_notifier_head notifier; 667 struct blocking_notifier_head notifier;
@@ -954,6 +956,9 @@ struct snd_soc_dai_link {
954 unsigned int symmetric_channels:1; 956 unsigned int symmetric_channels:1;
955 unsigned int symmetric_samplebits:1; 957 unsigned int symmetric_samplebits:1;
956 958
959 /* Mark this pcm with non atomic ops */
960 bool nonatomic;
961
957 /* Do not create a PCM for this DAI link (Backend link) */ 962 /* Do not create a PCM for this DAI link (Backend link) */
958 unsigned int no_pcm:1; 963 unsigned int no_pcm:1;
959 964
@@ -1071,11 +1076,16 @@ struct snd_soc_card {
1071 1076
1072 /* 1077 /*
1073 * Card-specific routes and widgets. 1078 * Card-specific routes and widgets.
1079 * Note: of_dapm_xxx for Device Tree; Otherwise for driver build-in.
1074 */ 1080 */
1075 const struct snd_soc_dapm_widget *dapm_widgets; 1081 const struct snd_soc_dapm_widget *dapm_widgets;
1076 int num_dapm_widgets; 1082 int num_dapm_widgets;
1077 const struct snd_soc_dapm_route *dapm_routes; 1083 const struct snd_soc_dapm_route *dapm_routes;
1078 int num_dapm_routes; 1084 int num_dapm_routes;
1085 const struct snd_soc_dapm_widget *of_dapm_widgets;
1086 int num_of_dapm_widgets;
1087 const struct snd_soc_dapm_route *of_dapm_routes;
1088 int num_of_dapm_routes;
1079 bool fully_routed; 1089 bool fully_routed;
1080 1090
1081 struct work_struct deferred_resume_work; 1091 struct work_struct deferred_resume_work;
@@ -1469,7 +1479,7 @@ static inline struct snd_soc_codec *snd_soc_kcontrol_codec(
1469} 1479}
1470 1480
1471/** 1481/**
1472 * snd_soc_kcontrol_platform() - Returns the platform that registerd the control 1482 * snd_soc_kcontrol_platform() - Returns the platform that registered the control
1473 * @kcontrol: The control for which to get the platform 1483 * @kcontrol: The control for which to get the platform
1474 * 1484 *
1475 * Note: This function will only work correctly if the control has been 1485 * Note: This function will only work correctly if the control has been
diff --git a/include/uapi/sound/asequencer.h b/include/uapi/sound/asequencer.h
index 09c8a00ea503..5a5fa4956ebd 100644
--- a/include/uapi/sound/asequencer.h
+++ b/include/uapi/sound/asequencer.h
@@ -22,6 +22,7 @@
22#ifndef _UAPI__SOUND_ASEQUENCER_H 22#ifndef _UAPI__SOUND_ASEQUENCER_H
23#define _UAPI__SOUND_ASEQUENCER_H 23#define _UAPI__SOUND_ASEQUENCER_H
24 24
25#include <sound/asound.h>
25 26
26/** version of the sequencer */ 27/** version of the sequencer */
27#define SNDRV_SEQ_VERSION SNDRV_PROTOCOL_VERSION (1, 0, 1) 28#define SNDRV_SEQ_VERSION SNDRV_PROTOCOL_VERSION (1, 0, 1)
diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h
index 0e88e7a0f0eb..46145a5277fe 100644
--- a/include/uapi/sound/asound.h
+++ b/include/uapi/sound/asound.h
@@ -25,6 +25,9 @@
25 25
26#include <linux/types.h> 26#include <linux/types.h>
27 27
28#ifndef __KERNEL__
29#include <stdlib.h>
30#endif
28 31
29/* 32/*
30 * protocol version 33 * protocol version
@@ -140,7 +143,7 @@ struct snd_hwdep_dsp_image {
140 * * 143 * *
141 *****************************************************************************/ 144 *****************************************************************************/
142 145
143#define SNDRV_PCM_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 12) 146#define SNDRV_PCM_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 13)
144 147
145typedef unsigned long snd_pcm_uframes_t; 148typedef unsigned long snd_pcm_uframes_t;
146typedef signed long snd_pcm_sframes_t; 149typedef signed long snd_pcm_sframes_t;
@@ -267,10 +270,17 @@ typedef int __bitwise snd_pcm_subformat_t;
267#define SNDRV_PCM_INFO_JOINT_DUPLEX 0x00200000 /* playback and capture stream are somewhat correlated */ 270#define SNDRV_PCM_INFO_JOINT_DUPLEX 0x00200000 /* playback and capture stream are somewhat correlated */
268#define SNDRV_PCM_INFO_SYNC_START 0x00400000 /* pcm support some kind of sync go */ 271#define SNDRV_PCM_INFO_SYNC_START 0x00400000 /* pcm support some kind of sync go */
269#define SNDRV_PCM_INFO_NO_PERIOD_WAKEUP 0x00800000 /* period wakeup can be disabled */ 272#define SNDRV_PCM_INFO_NO_PERIOD_WAKEUP 0x00800000 /* period wakeup can be disabled */
270#define SNDRV_PCM_INFO_HAS_WALL_CLOCK 0x01000000 /* has audio wall clock for audio/system time sync */ 273#define SNDRV_PCM_INFO_HAS_WALL_CLOCK 0x01000000 /* (Deprecated)has audio wall clock for audio/system time sync */
274#define SNDRV_PCM_INFO_HAS_LINK_ATIME 0x01000000 /* report hardware link audio time, reset on startup */
275#define SNDRV_PCM_INFO_HAS_LINK_ABSOLUTE_ATIME 0x02000000 /* report absolute hardware link audio time, not reset on startup */
276#define SNDRV_PCM_INFO_HAS_LINK_ESTIMATED_ATIME 0x04000000 /* report estimated link audio time */
277#define SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME 0x08000000 /* report synchronized audio/system time */
278
271#define SNDRV_PCM_INFO_DRAIN_TRIGGER 0x40000000 /* internal kernel flag - trigger in drain */ 279#define SNDRV_PCM_INFO_DRAIN_TRIGGER 0x40000000 /* internal kernel flag - trigger in drain */
272#define SNDRV_PCM_INFO_FIFO_IN_FRAMES 0x80000000 /* internal kernel flag - FIFO size is in frames */ 280#define SNDRV_PCM_INFO_FIFO_IN_FRAMES 0x80000000 /* internal kernel flag - FIFO size is in frames */
273 281
282
283
274typedef int __bitwise snd_pcm_state_t; 284typedef int __bitwise snd_pcm_state_t;
275#define SNDRV_PCM_STATE_OPEN ((__force snd_pcm_state_t) 0) /* stream is open */ 285#define SNDRV_PCM_STATE_OPEN ((__force snd_pcm_state_t) 0) /* stream is open */
276#define SNDRV_PCM_STATE_SETUP ((__force snd_pcm_state_t) 1) /* stream has a setup */ 286#define SNDRV_PCM_STATE_SETUP ((__force snd_pcm_state_t) 1) /* stream has a setup */
@@ -408,6 +418,22 @@ struct snd_pcm_channel_info {
408 unsigned int step; /* samples distance in bits */ 418 unsigned int step; /* samples distance in bits */
409}; 419};
410 420
421enum {
422 /*
423 * first definition for backwards compatibility only,
424 * maps to wallclock/link time for HDAudio playback and DEFAULT/DMA time for everything else
425 */
426 SNDRV_PCM_AUDIO_TSTAMP_TYPE_COMPAT = 0,
427
428 /* timestamp definitions */
429 SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT = 1, /* DMA time, reported as per hw_ptr */
430 SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK = 2, /* link time reported by sample or wallclock counter, reset on startup */
431 SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_ABSOLUTE = 3, /* link time reported by sample or wallclock counter, not reset on startup */
432 SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_ESTIMATED = 4, /* link time estimated indirectly */
433 SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED = 5, /* link time synchronized with system time */
434 SNDRV_PCM_AUDIO_TSTAMP_TYPE_LAST = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED
435};
436
411struct snd_pcm_status { 437struct snd_pcm_status {
412 snd_pcm_state_t state; /* stream state */ 438 snd_pcm_state_t state; /* stream state */
413 struct timespec trigger_tstamp; /* time when stream was started/stopped/paused */ 439 struct timespec trigger_tstamp; /* time when stream was started/stopped/paused */
@@ -419,9 +445,11 @@ struct snd_pcm_status {
419 snd_pcm_uframes_t avail_max; /* max frames available on hw since last status */ 445 snd_pcm_uframes_t avail_max; /* max frames available on hw since last status */
420 snd_pcm_uframes_t overrange; /* count of ADC (capture) overrange detections from last status */ 446 snd_pcm_uframes_t overrange; /* count of ADC (capture) overrange detections from last status */
421 snd_pcm_state_t suspended_state; /* suspended stream state */ 447 snd_pcm_state_t suspended_state; /* suspended stream state */
422 __u32 reserved_alignment; /* must be filled with zero */ 448 __u32 audio_tstamp_data; /* needed for 64-bit alignment, used for configs/report to/from userspace */
423 struct timespec audio_tstamp; /* from sample counter or wall clock */ 449 struct timespec audio_tstamp; /* sample counter, wall clock, PHC or on-demand sync'ed */
424 unsigned char reserved[56-sizeof(struct timespec)]; /* must be filled with zero */ 450 struct timespec driver_tstamp; /* useful in case reference system tstamp is reported with delay */
451 __u32 audio_tstamp_accuracy; /* in ns units, only valid if indicated in audio_tstamp_data */
452 unsigned char reserved[52-2*sizeof(struct timespec)]; /* must be filled with zero */
425}; 453};
426 454
427struct snd_pcm_mmap_status { 455struct snd_pcm_mmap_status {
@@ -534,6 +562,7 @@ enum {
534#define SNDRV_PCM_IOCTL_DELAY _IOR('A', 0x21, snd_pcm_sframes_t) 562#define SNDRV_PCM_IOCTL_DELAY _IOR('A', 0x21, snd_pcm_sframes_t)
535#define SNDRV_PCM_IOCTL_HWSYNC _IO('A', 0x22) 563#define SNDRV_PCM_IOCTL_HWSYNC _IO('A', 0x22)
536#define SNDRV_PCM_IOCTL_SYNC_PTR _IOWR('A', 0x23, struct snd_pcm_sync_ptr) 564#define SNDRV_PCM_IOCTL_SYNC_PTR _IOWR('A', 0x23, struct snd_pcm_sync_ptr)
565#define SNDRV_PCM_IOCTL_STATUS_EXT _IOWR('A', 0x24, struct snd_pcm_status)
537#define SNDRV_PCM_IOCTL_CHANNEL_INFO _IOR('A', 0x32, struct snd_pcm_channel_info) 566#define SNDRV_PCM_IOCTL_CHANNEL_INFO _IOR('A', 0x32, struct snd_pcm_channel_info)
538#define SNDRV_PCM_IOCTL_PREPARE _IO('A', 0x40) 567#define SNDRV_PCM_IOCTL_PREPARE _IO('A', 0x40)
539#define SNDRV_PCM_IOCTL_RESET _IO('A', 0x41) 568#define SNDRV_PCM_IOCTL_RESET _IO('A', 0x41)
diff --git a/include/uapi/sound/compress_offload.h b/include/uapi/sound/compress_offload.h
index 22ed8cb7800b..e00d8cbfc628 100644
--- a/include/uapi/sound/compress_offload.h
+++ b/include/uapi/sound/compress_offload.h
@@ -75,7 +75,7 @@ struct snd_compr_tstamp {
75/** 75/**
76 * struct snd_compr_avail - avail descriptor 76 * struct snd_compr_avail - avail descriptor
77 * @avail: Number of bytes available in ring buffer for writing/reading 77 * @avail: Number of bytes available in ring buffer for writing/reading
78 * @tstamp: timestamp infomation 78 * @tstamp: timestamp information
79 */ 79 */
80struct snd_compr_avail { 80struct snd_compr_avail {
81 __u64 avail; 81 __u64 avail;
diff --git a/include/uapi/sound/emu10k1.h b/include/uapi/sound/emu10k1.h
index d1bbaf78457a..ec1535bb6aed 100644
--- a/include/uapi/sound/emu10k1.h
+++ b/include/uapi/sound/emu10k1.h
@@ -23,8 +23,7 @@
23#define _UAPI__SOUND_EMU10K1_H 23#define _UAPI__SOUND_EMU10K1_H
24 24
25#include <linux/types.h> 25#include <linux/types.h>
26 26#include <sound/asound.h>
27
28 27
29/* 28/*
30 * ---- FX8010 ---- 29 * ---- FX8010 ----
diff --git a/include/uapi/sound/hdspm.h b/include/uapi/sound/hdspm.h
index b357f1a5e29c..5737332d38f2 100644
--- a/include/uapi/sound/hdspm.h
+++ b/include/uapi/sound/hdspm.h
@@ -20,6 +20,12 @@
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */ 21 */
22 22
23#ifdef __KERNEL__
24#include <linux/types.h>
25#else
26#include <stdint.h>
27#endif
28
23/* Maximum channels is 64 even on 56Mode you have 64playbacks to matrix */ 29/* Maximum channels is 64 even on 56Mode you have 64playbacks to matrix */
24#define HDSPM_MAX_CHANNELS 64 30#define HDSPM_MAX_CHANNELS 64
25 31
diff --git a/sound/aoa/soundbus/i2sbus/core.c b/sound/aoa/soundbus/i2sbus/core.c
index b9737fae656a..1cbf210080a1 100644
--- a/sound/aoa/soundbus/i2sbus/core.c
+++ b/sound/aoa/soundbus/i2sbus/core.c
@@ -31,7 +31,7 @@ module_param(force, int, 0444);
31MODULE_PARM_DESC(force, "Force loading i2sbus even when" 31MODULE_PARM_DESC(force, "Force loading i2sbus even when"
32 " no layout-id property is present"); 32 " no layout-id property is present");
33 33
34static struct of_device_id i2sbus_match[] = { 34static const struct of_device_id i2sbus_match[] = {
35 { .name = "i2s" }, 35 { .name = "i2s" },
36 { } 36 { }
37}; 37};
diff --git a/sound/core/control.c b/sound/core/control.c
index eeb691d1911f..d677c27746e9 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -192,36 +192,41 @@ void snd_ctl_notify(struct snd_card *card, unsigned int mask,
192EXPORT_SYMBOL(snd_ctl_notify); 192EXPORT_SYMBOL(snd_ctl_notify);
193 193
194/** 194/**
195 * snd_ctl_new - create a control instance from the template 195 * snd_ctl_new - create a new control instance with some elements
196 * @control: the control template 196 * @kctl: the pointer to store new control instance
197 * @access: the default control access 197 * @count: the number of elements in this control
198 * @access: the default access flags for elements in this control
199 * @file: given when locking these elements
198 * 200 *
199 * Allocates a new struct snd_kcontrol instance and copies the given template 201 * Allocates a memory object for a new control instance. The instance has
200 * to the new instance. It does not copy volatile data (access). 202 * elements as many as the given number (@count). Each element has given
203 * access permissions (@access). Each element is locked when @file is given.
201 * 204 *
202 * Return: The pointer of the new instance, or %NULL on failure. 205 * Return: 0 on success, error code on failure
203 */ 206 */
204static struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control, 207static int snd_ctl_new(struct snd_kcontrol **kctl, unsigned int count,
205 unsigned int access) 208 unsigned int access, struct snd_ctl_file *file)
206{ 209{
207 struct snd_kcontrol *kctl; 210 unsigned int size;
208 unsigned int idx; 211 unsigned int idx;
209 212
210 if (snd_BUG_ON(!control || !control->count)) 213 if (count == 0 || count > MAX_CONTROL_COUNT)
211 return NULL; 214 return -EINVAL;
212 215
213 if (control->count > MAX_CONTROL_COUNT) 216 size = sizeof(struct snd_kcontrol);
214 return NULL; 217 size += sizeof(struct snd_kcontrol_volatile) * count;
215 218
216 kctl = kzalloc(sizeof(*kctl) + sizeof(struct snd_kcontrol_volatile) * control->count, GFP_KERNEL); 219 *kctl = kzalloc(size, GFP_KERNEL);
217 if (kctl == NULL) { 220 if (!*kctl)
218 pr_err("ALSA: Cannot allocate control instance\n"); 221 return -ENOMEM;
219 return NULL; 222
223 for (idx = 0; idx < count; idx++) {
224 (*kctl)->vd[idx].access = access;
225 (*kctl)->vd[idx].owner = file;
220 } 226 }
221 *kctl = *control; 227 (*kctl)->count = count;
222 for (idx = 0; idx < kctl->count; idx++) 228
223 kctl->vd[idx].access = access; 229 return 0;
224 return kctl;
225} 230}
226 231
227/** 232/**
@@ -238,37 +243,53 @@ static struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control,
238struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol, 243struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol,
239 void *private_data) 244 void *private_data)
240{ 245{
241 struct snd_kcontrol kctl; 246 struct snd_kcontrol *kctl;
247 unsigned int count;
242 unsigned int access; 248 unsigned int access;
249 int err;
243 250
244 if (snd_BUG_ON(!ncontrol || !ncontrol->info)) 251 if (snd_BUG_ON(!ncontrol || !ncontrol->info))
245 return NULL; 252 return NULL;
246 memset(&kctl, 0, sizeof(kctl)); 253
247 kctl.id.iface = ncontrol->iface; 254 count = ncontrol->count;
248 kctl.id.device = ncontrol->device; 255 if (count == 0)
249 kctl.id.subdevice = ncontrol->subdevice; 256 count = 1;
257
258 access = ncontrol->access;
259 if (access == 0)
260 access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
261 access &= (SNDRV_CTL_ELEM_ACCESS_READWRITE |
262 SNDRV_CTL_ELEM_ACCESS_VOLATILE |
263 SNDRV_CTL_ELEM_ACCESS_INACTIVE |
264 SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE |
265 SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND |
266 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK);
267
268 err = snd_ctl_new(&kctl, count, access, NULL);
269 if (err < 0)
270 return NULL;
271
272 /* The 'numid' member is decided when calling snd_ctl_add(). */
273 kctl->id.iface = ncontrol->iface;
274 kctl->id.device = ncontrol->device;
275 kctl->id.subdevice = ncontrol->subdevice;
250 if (ncontrol->name) { 276 if (ncontrol->name) {
251 strlcpy(kctl.id.name, ncontrol->name, sizeof(kctl.id.name)); 277 strlcpy(kctl->id.name, ncontrol->name, sizeof(kctl->id.name));
252 if (strcmp(ncontrol->name, kctl.id.name) != 0) 278 if (strcmp(ncontrol->name, kctl->id.name) != 0)
253 pr_warn("ALSA: Control name '%s' truncated to '%s'\n", 279 pr_warn("ALSA: Control name '%s' truncated to '%s'\n",
254 ncontrol->name, kctl.id.name); 280 ncontrol->name, kctl->id.name);
255 } 281 }
256 kctl.id.index = ncontrol->index; 282 kctl->id.index = ncontrol->index;
257 kctl.count = ncontrol->count ? ncontrol->count : 1; 283
258 access = ncontrol->access == 0 ? SNDRV_CTL_ELEM_ACCESS_READWRITE : 284 kctl->info = ncontrol->info;
259 (ncontrol->access & (SNDRV_CTL_ELEM_ACCESS_READWRITE| 285 kctl->get = ncontrol->get;
260 SNDRV_CTL_ELEM_ACCESS_VOLATILE| 286 kctl->put = ncontrol->put;
261 SNDRV_CTL_ELEM_ACCESS_INACTIVE| 287 kctl->tlv.p = ncontrol->tlv.p;
262 SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE| 288
263 SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND| 289 kctl->private_value = ncontrol->private_value;
264 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK)); 290 kctl->private_data = private_data;
265 kctl.info = ncontrol->info; 291
266 kctl.get = ncontrol->get; 292 return kctl;
267 kctl.put = ncontrol->put;
268 kctl.tlv.p = ncontrol->tlv.p;
269 kctl.private_value = ncontrol->private_value;
270 kctl.private_data = private_data;
271 return snd_ctl_new(&kctl, access);
272} 293}
273EXPORT_SYMBOL(snd_ctl_new1); 294EXPORT_SYMBOL(snd_ctl_new1);
274 295
@@ -1161,84 +1182,102 @@ static void snd_ctl_elem_user_free(struct snd_kcontrol *kcontrol)
1161static int snd_ctl_elem_add(struct snd_ctl_file *file, 1182static int snd_ctl_elem_add(struct snd_ctl_file *file,
1162 struct snd_ctl_elem_info *info, int replace) 1183 struct snd_ctl_elem_info *info, int replace)
1163{ 1184{
1185 /* The capacity of struct snd_ctl_elem_value.value.*/
1186 static const unsigned int value_sizes[] = {
1187 [SNDRV_CTL_ELEM_TYPE_BOOLEAN] = sizeof(long),
1188 [SNDRV_CTL_ELEM_TYPE_INTEGER] = sizeof(long),
1189 [SNDRV_CTL_ELEM_TYPE_ENUMERATED] = sizeof(unsigned int),
1190 [SNDRV_CTL_ELEM_TYPE_BYTES] = sizeof(unsigned char),
1191 [SNDRV_CTL_ELEM_TYPE_IEC958] = sizeof(struct snd_aes_iec958),
1192 [SNDRV_CTL_ELEM_TYPE_INTEGER64] = sizeof(long long),
1193 };
1194 static const unsigned int max_value_counts[] = {
1195 [SNDRV_CTL_ELEM_TYPE_BOOLEAN] = 128,
1196 [SNDRV_CTL_ELEM_TYPE_INTEGER] = 128,
1197 [SNDRV_CTL_ELEM_TYPE_ENUMERATED] = 128,
1198 [SNDRV_CTL_ELEM_TYPE_BYTES] = 512,
1199 [SNDRV_CTL_ELEM_TYPE_IEC958] = 1,
1200 [SNDRV_CTL_ELEM_TYPE_INTEGER64] = 64,
1201 };
1164 struct snd_card *card = file->card; 1202 struct snd_card *card = file->card;
1165 struct snd_kcontrol kctl, *_kctl; 1203 struct snd_kcontrol *kctl;
1204 unsigned int count;
1166 unsigned int access; 1205 unsigned int access;
1167 long private_size; 1206 long private_size;
1168 struct user_element *ue; 1207 struct user_element *ue;
1169 int idx, err; 1208 int err;
1170 1209
1171 if (info->count < 1)
1172 return -EINVAL;
1173 if (!*info->id.name) 1210 if (!*info->id.name)
1174 return -EINVAL; 1211 return -EINVAL;
1175 if (strnlen(info->id.name, sizeof(info->id.name)) >= sizeof(info->id.name)) 1212 if (strnlen(info->id.name, sizeof(info->id.name)) >= sizeof(info->id.name))
1176 return -EINVAL; 1213 return -EINVAL;
1177 access = info->access == 0 ? SNDRV_CTL_ELEM_ACCESS_READWRITE :
1178 (info->access & (SNDRV_CTL_ELEM_ACCESS_READWRITE|
1179 SNDRV_CTL_ELEM_ACCESS_INACTIVE|
1180 SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE));
1181 info->id.numid = 0;
1182 memset(&kctl, 0, sizeof(kctl));
1183 1214
1215 /* Delete a control to replace them if needed. */
1184 if (replace) { 1216 if (replace) {
1217 info->id.numid = 0;
1185 err = snd_ctl_remove_user_ctl(file, &info->id); 1218 err = snd_ctl_remove_user_ctl(file, &info->id);
1186 if (err) 1219 if (err)
1187 return err; 1220 return err;
1188 } 1221 }
1189 1222
1190 if (card->user_ctl_count >= MAX_USER_CONTROLS) 1223 /*
1224 * The number of userspace controls are counted control by control,
1225 * not element by element.
1226 */
1227 if (card->user_ctl_count + 1 > MAX_USER_CONTROLS)
1191 return -ENOMEM; 1228 return -ENOMEM;
1192 1229
1193 memcpy(&kctl.id, &info->id, sizeof(info->id)); 1230 /* Check the number of elements for this userspace control. */
1194 kctl.count = info->owner ? info->owner : 1; 1231 count = info->owner;
1195 access |= SNDRV_CTL_ELEM_ACCESS_USER; 1232 if (count == 0)
1196 if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) 1233 count = 1;
1197 kctl.info = snd_ctl_elem_user_enum_info; 1234
1198 else 1235 /* Arrange access permissions if needed. */
1199 kctl.info = snd_ctl_elem_user_info; 1236 access = info->access;
1200 if (access & SNDRV_CTL_ELEM_ACCESS_READ) 1237 if (access == 0)
1201 kctl.get = snd_ctl_elem_user_get; 1238 access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1202 if (access & SNDRV_CTL_ELEM_ACCESS_WRITE) 1239 access &= (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1203 kctl.put = snd_ctl_elem_user_put; 1240 SNDRV_CTL_ELEM_ACCESS_INACTIVE |
1204 if (access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) { 1241 SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE);
1205 kctl.tlv.c = snd_ctl_elem_user_tlv; 1242 if (access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE)
1206 access |= SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; 1243 access |= SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
1207 } 1244 access |= SNDRV_CTL_ELEM_ACCESS_USER;
1208 switch (info->type) { 1245
1209 case SNDRV_CTL_ELEM_TYPE_BOOLEAN: 1246 /*
1210 case SNDRV_CTL_ELEM_TYPE_INTEGER: 1247 * Check information and calculate the size of data specific to
1211 private_size = sizeof(long); 1248 * this userspace control.
1212 if (info->count > 128) 1249 */
1213 return -EINVAL; 1250 if (info->type < SNDRV_CTL_ELEM_TYPE_BOOLEAN ||
1214 break; 1251 info->type > SNDRV_CTL_ELEM_TYPE_INTEGER64)
1215 case SNDRV_CTL_ELEM_TYPE_INTEGER64:
1216 private_size = sizeof(long long);
1217 if (info->count > 64)
1218 return -EINVAL;
1219 break;
1220 case SNDRV_CTL_ELEM_TYPE_ENUMERATED:
1221 private_size = sizeof(unsigned int);
1222 if (info->count > 128 || info->value.enumerated.items == 0)
1223 return -EINVAL;
1224 break;
1225 case SNDRV_CTL_ELEM_TYPE_BYTES:
1226 private_size = sizeof(unsigned char);
1227 if (info->count > 512)
1228 return -EINVAL;
1229 break;
1230 case SNDRV_CTL_ELEM_TYPE_IEC958:
1231 private_size = sizeof(struct snd_aes_iec958);
1232 if (info->count != 1)
1233 return -EINVAL;
1234 break;
1235 default:
1236 return -EINVAL; 1252 return -EINVAL;
1237 } 1253 if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED &&
1238 private_size *= info->count; 1254 info->value.enumerated.items == 0)
1239 ue = kzalloc(sizeof(struct user_element) + private_size, GFP_KERNEL); 1255 return -EINVAL;
1240 if (ue == NULL) 1256 if (info->count < 1 ||
1257 info->count > max_value_counts[info->type])
1258 return -EINVAL;
1259 private_size = value_sizes[info->type] * info->count;
1260
1261 /*
1262 * Keep memory object for this userspace control. After passing this
1263 * code block, the instance should be freed by snd_ctl_free_one().
1264 *
1265 * Note that these elements in this control are locked.
1266 */
1267 err = snd_ctl_new(&kctl, count, access, file);
1268 if (err < 0)
1269 return err;
1270 memcpy(&kctl->id, &info->id, sizeof(kctl->id));
1271 kctl->private_data = kzalloc(sizeof(struct user_element) + private_size,
1272 GFP_KERNEL);
1273 if (kctl->private_data == NULL) {
1274 kfree(kctl);
1241 return -ENOMEM; 1275 return -ENOMEM;
1276 }
1277 kctl->private_free = snd_ctl_elem_user_free;
1278
1279 /* Set private data for this userspace control. */
1280 ue = (struct user_element *)kctl->private_data;
1242 ue->card = card; 1281 ue->card = card;
1243 ue->info = *info; 1282 ue->info = *info;
1244 ue->info.access = 0; 1283 ue->info.access = 0;
@@ -1247,21 +1286,25 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
1247 if (ue->info.type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) { 1286 if (ue->info.type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) {
1248 err = snd_ctl_elem_init_enum_names(ue); 1287 err = snd_ctl_elem_init_enum_names(ue);
1249 if (err < 0) { 1288 if (err < 0) {
1250 kfree(ue); 1289 snd_ctl_free_one(kctl);
1251 return err; 1290 return err;
1252 } 1291 }
1253 } 1292 }
1254 kctl.private_free = snd_ctl_elem_user_free; 1293
1255 _kctl = snd_ctl_new(&kctl, access); 1294 /* Set callback functions. */
1256 if (_kctl == NULL) { 1295 if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED)
1257 kfree(ue->priv_data); 1296 kctl->info = snd_ctl_elem_user_enum_info;
1258 kfree(ue); 1297 else
1259 return -ENOMEM; 1298 kctl->info = snd_ctl_elem_user_info;
1260 } 1299 if (access & SNDRV_CTL_ELEM_ACCESS_READ)
1261 _kctl->private_data = ue; 1300 kctl->get = snd_ctl_elem_user_get;
1262 for (idx = 0; idx < _kctl->count; idx++) 1301 if (access & SNDRV_CTL_ELEM_ACCESS_WRITE)
1263 _kctl->vd[idx].owner = file; 1302 kctl->put = snd_ctl_elem_user_put;
1264 err = snd_ctl_add(card, _kctl); 1303 if (access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE)
1304 kctl->tlv.c = snd_ctl_elem_user_tlv;
1305
1306 /* This function manage to free the instance on failure. */
1307 err = snd_ctl_add(card, kctl);
1265 if (err < 0) 1308 if (err < 0)
1266 return err; 1309 return err;
1267 1310
diff --git a/sound/core/device.c b/sound/core/device.c
index 41bec3075ae5..8918838b1999 100644
--- a/sound/core/device.c
+++ b/sound/core/device.c
@@ -50,10 +50,8 @@ int snd_device_new(struct snd_card *card, enum snd_device_type type,
50 if (snd_BUG_ON(!card || !device_data || !ops)) 50 if (snd_BUG_ON(!card || !device_data || !ops))
51 return -ENXIO; 51 return -ENXIO;
52 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 52 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
53 if (dev == NULL) { 53 if (!dev)
54 dev_err(card->dev, "Cannot allocate device, type=%d\n", type);
55 return -ENOMEM; 54 return -ENOMEM;
56 }
57 INIT_LIST_HEAD(&dev->list); 55 INIT_LIST_HEAD(&dev->list);
58 dev->card = card; 56 dev->card = card;
59 dev->type = type; 57 dev->type = type;
@@ -73,7 +71,7 @@ int snd_device_new(struct snd_card *card, enum snd_device_type type,
73} 71}
74EXPORT_SYMBOL(snd_device_new); 72EXPORT_SYMBOL(snd_device_new);
75 73
76static int __snd_device_disconnect(struct snd_device *dev) 74static void __snd_device_disconnect(struct snd_device *dev)
77{ 75{
78 if (dev->state == SNDRV_DEV_REGISTERED) { 76 if (dev->state == SNDRV_DEV_REGISTERED) {
79 if (dev->ops->dev_disconnect && 77 if (dev->ops->dev_disconnect &&
@@ -81,7 +79,6 @@ static int __snd_device_disconnect(struct snd_device *dev)
81 dev_err(dev->card->dev, "device disconnect failure\n"); 79 dev_err(dev->card->dev, "device disconnect failure\n");
82 dev->state = SNDRV_DEV_DISCONNECTED; 80 dev->state = SNDRV_DEV_DISCONNECTED;
83 } 81 }
84 return 0;
85} 82}
86 83
87static void __snd_device_free(struct snd_device *dev) 84static void __snd_device_free(struct snd_device *dev)
@@ -109,6 +106,34 @@ static struct snd_device *look_for_dev(struct snd_card *card, void *device_data)
109} 106}
110 107
111/** 108/**
109 * snd_device_disconnect - disconnect the device
110 * @card: the card instance
111 * @device_data: the data pointer to disconnect
112 *
113 * Turns the device into the disconnection state, invoking
114 * dev_disconnect callback, if the device was already registered.
115 *
116 * Usually called from snd_card_disconnect().
117 *
118 * Return: Zero if successful, or a negative error code on failure or if the
119 * device not found.
120 */
121void snd_device_disconnect(struct snd_card *card, void *device_data)
122{
123 struct snd_device *dev;
124
125 if (snd_BUG_ON(!card || !device_data))
126 return;
127 dev = look_for_dev(card, device_data);
128 if (dev)
129 __snd_device_disconnect(dev);
130 else
131 dev_dbg(card->dev, "device disconnect %p (from %pF), not found\n",
132 device_data, __builtin_return_address(0));
133}
134EXPORT_SYMBOL_GPL(snd_device_disconnect);
135
136/**
112 * snd_device_free - release the device from the card 137 * snd_device_free - release the device from the card
113 * @card: the card instance 138 * @card: the card instance
114 * @device_data: the data pointer to release 139 * @device_data: the data pointer to release
@@ -195,18 +220,14 @@ int snd_device_register_all(struct snd_card *card)
195 * disconnect all the devices on the card. 220 * disconnect all the devices on the card.
196 * called from init.c 221 * called from init.c
197 */ 222 */
198int snd_device_disconnect_all(struct snd_card *card) 223void snd_device_disconnect_all(struct snd_card *card)
199{ 224{
200 struct snd_device *dev; 225 struct snd_device *dev;
201 int err = 0;
202 226
203 if (snd_BUG_ON(!card)) 227 if (snd_BUG_ON(!card))
204 return -ENXIO; 228 return;
205 list_for_each_entry_reverse(dev, &card->devices, list) { 229 list_for_each_entry_reverse(dev, &card->devices, list)
206 if (__snd_device_disconnect(dev) < 0) 230 __snd_device_disconnect(dev);
207 err = -ENXIO;
208 }
209 return err;
210} 231}
211 232
212/* 233/*
diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c
index 84244a5143cf..51692c8a39ea 100644
--- a/sound/core/hwdep.c
+++ b/sound/core/hwdep.c
@@ -378,10 +378,8 @@ int snd_hwdep_new(struct snd_card *card, char *id, int device,
378 if (rhwdep) 378 if (rhwdep)
379 *rhwdep = NULL; 379 *rhwdep = NULL;
380 hwdep = kzalloc(sizeof(*hwdep), GFP_KERNEL); 380 hwdep = kzalloc(sizeof(*hwdep), GFP_KERNEL);
381 if (hwdep == NULL) { 381 if (!hwdep)
382 dev_err(card->dev, "hwdep: cannot allocate\n");
383 return -ENOMEM; 382 return -ENOMEM;
384 }
385 383
386 init_waitqueue_head(&hwdep->open_wait); 384 init_waitqueue_head(&hwdep->open_wait);
387 mutex_init(&hwdep->open_mutex); 385 mutex_init(&hwdep->open_mutex);
diff --git a/sound/core/init.c b/sound/core/init.c
index 35419054821c..04734e047bfe 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -400,7 +400,6 @@ static const struct file_operations snd_shutdown_f_ops =
400int snd_card_disconnect(struct snd_card *card) 400int snd_card_disconnect(struct snd_card *card)
401{ 401{
402 struct snd_monitor_file *mfile; 402 struct snd_monitor_file *mfile;
403 int err;
404 403
405 if (!card) 404 if (!card)
406 return -EINVAL; 405 return -EINVAL;
@@ -445,9 +444,7 @@ int snd_card_disconnect(struct snd_card *card)
445#endif 444#endif
446 445
447 /* notify all devices that we are disconnected */ 446 /* notify all devices that we are disconnected */
448 err = snd_device_disconnect_all(card); 447 snd_device_disconnect_all(card);
449 if (err < 0)
450 dev_err(card->dev, "not all devices for card %i can be disconnected\n", card->number);
451 448
452 snd_info_card_disconnect(card); 449 snd_info_card_disconnect(card);
453 if (card->registered) { 450 if (card->registered) {
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
index 5e6349f00ecd..056f8e274851 100644
--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -1212,10 +1212,8 @@ static void snd_mixer_oss_proc_write(struct snd_info_entry *entry,
1212 /* not changed */ 1212 /* not changed */
1213 goto __unlock; 1213 goto __unlock;
1214 tbl = kmalloc(sizeof(*tbl), GFP_KERNEL); 1214 tbl = kmalloc(sizeof(*tbl), GFP_KERNEL);
1215 if (! tbl) { 1215 if (!tbl)
1216 pr_err("ALSA: mixer_oss: no memory\n");
1217 goto __unlock; 1216 goto __unlock;
1218 }
1219 tbl->oss_id = ch; 1217 tbl->oss_id = ch;
1220 tbl->name = kstrdup(str, GFP_KERNEL); 1218 tbl->name = kstrdup(str, GFP_KERNEL);
1221 if (! tbl->name) { 1219 if (! tbl->name) {
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index 80423a4ccab6..58550cc93f28 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -854,7 +854,6 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
854 params = kmalloc(sizeof(*params), GFP_KERNEL); 854 params = kmalloc(sizeof(*params), GFP_KERNEL);
855 sparams = kmalloc(sizeof(*sparams), GFP_KERNEL); 855 sparams = kmalloc(sizeof(*sparams), GFP_KERNEL);
856 if (!sw_params || !params || !sparams) { 856 if (!sw_params || !params || !sparams) {
857 pcm_dbg(substream->pcm, "No memory\n");
858 err = -ENOMEM; 857 err = -ENOMEM;
859 goto failure; 858 goto failure;
860 } 859 }
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 0345e53a340c..b25bcf5b8644 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -49,8 +49,6 @@ static struct snd_pcm *snd_pcm_get(struct snd_card *card, int device)
49 struct snd_pcm *pcm; 49 struct snd_pcm *pcm;
50 50
51 list_for_each_entry(pcm, &snd_pcm_devices, list) { 51 list_for_each_entry(pcm, &snd_pcm_devices, list) {
52 if (pcm->internal)
53 continue;
54 if (pcm->card == card && pcm->device == device) 52 if (pcm->card == card && pcm->device == device)
55 return pcm; 53 return pcm;
56 } 54 }
@@ -62,8 +60,6 @@ static int snd_pcm_next(struct snd_card *card, int device)
62 struct snd_pcm *pcm; 60 struct snd_pcm *pcm;
63 61
64 list_for_each_entry(pcm, &snd_pcm_devices, list) { 62 list_for_each_entry(pcm, &snd_pcm_devices, list) {
65 if (pcm->internal)
66 continue;
67 if (pcm->card == card && pcm->device > device) 63 if (pcm->card == card && pcm->device > device)
68 return pcm->device; 64 return pcm->device;
69 else if (pcm->card->number > card->number) 65 else if (pcm->card->number > card->number)
@@ -76,6 +72,9 @@ static int snd_pcm_add(struct snd_pcm *newpcm)
76{ 72{
77 struct snd_pcm *pcm; 73 struct snd_pcm *pcm;
78 74
75 if (newpcm->internal)
76 return 0;
77
79 list_for_each_entry(pcm, &snd_pcm_devices, list) { 78 list_for_each_entry(pcm, &snd_pcm_devices, list) {
80 if (pcm->card == newpcm->card && pcm->device == newpcm->device) 79 if (pcm->card == newpcm->card && pcm->device == newpcm->device)
81 return -EBUSY; 80 return -EBUSY;
@@ -344,11 +343,8 @@ static void snd_pcm_proc_info_read(struct snd_pcm_substream *substream,
344 return; 343 return;
345 344
346 info = kmalloc(sizeof(*info), GFP_KERNEL); 345 info = kmalloc(sizeof(*info), GFP_KERNEL);
347 if (! info) { 346 if (!info)
348 pcm_dbg(substream->pcm,
349 "snd_pcm_proc_info_read: cannot malloc\n");
350 return; 347 return;
351 }
352 348
353 err = snd_pcm_info(substream, info); 349 err = snd_pcm_info(substream, info);
354 if (err < 0) { 350 if (err < 0) {
@@ -718,10 +714,8 @@ int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
718 prev = NULL; 714 prev = NULL;
719 for (idx = 0, prev = NULL; idx < substream_count; idx++) { 715 for (idx = 0, prev = NULL; idx < substream_count; idx++) {
720 substream = kzalloc(sizeof(*substream), GFP_KERNEL); 716 substream = kzalloc(sizeof(*substream), GFP_KERNEL);
721 if (substream == NULL) { 717 if (!substream)
722 pcm_err(pcm, "Cannot allocate PCM substream\n");
723 return -ENOMEM; 718 return -ENOMEM;
724 }
725 substream->pcm = pcm; 719 substream->pcm = pcm;
726 substream->pstr = pstr; 720 substream->pstr = pstr;
727 substream->number = idx; 721 substream->number = idx;
@@ -775,13 +769,14 @@ static int _snd_pcm_new(struct snd_card *card, const char *id, int device,
775 if (rpcm) 769 if (rpcm)
776 *rpcm = NULL; 770 *rpcm = NULL;
777 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); 771 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
778 if (pcm == NULL) { 772 if (!pcm)
779 dev_err(card->dev, "Cannot allocate PCM\n");
780 return -ENOMEM; 773 return -ENOMEM;
781 }
782 pcm->card = card; 774 pcm->card = card;
783 pcm->device = device; 775 pcm->device = device;
784 pcm->internal = internal; 776 pcm->internal = internal;
777 mutex_init(&pcm->open_mutex);
778 init_waitqueue_head(&pcm->open_wait);
779 INIT_LIST_HEAD(&pcm->list);
785 if (id) 780 if (id)
786 strlcpy(pcm->id, id, sizeof(pcm->id)); 781 strlcpy(pcm->id, id, sizeof(pcm->id));
787 if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) { 782 if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) {
@@ -792,8 +787,6 @@ static int _snd_pcm_new(struct snd_card *card, const char *id, int device,
792 snd_pcm_free(pcm); 787 snd_pcm_free(pcm);
793 return err; 788 return err;
794 } 789 }
795 mutex_init(&pcm->open_mutex);
796 init_waitqueue_head(&pcm->open_wait);
797 if ((err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops)) < 0) { 790 if ((err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops)) < 0) {
798 snd_pcm_free(pcm); 791 snd_pcm_free(pcm);
799 return err; 792 return err;
@@ -888,8 +881,9 @@ static int snd_pcm_free(struct snd_pcm *pcm)
888 881
889 if (!pcm) 882 if (!pcm)
890 return 0; 883 return 0;
891 list_for_each_entry(notify, &snd_pcm_notify_list, list) { 884 if (!pcm->internal) {
892 notify->n_unregister(pcm); 885 list_for_each_entry(notify, &snd_pcm_notify_list, list)
886 notify->n_unregister(pcm);
893 } 887 }
894 if (pcm->private_free) 888 if (pcm->private_free)
895 pcm->private_free(pcm); 889 pcm->private_free(pcm);
@@ -919,6 +913,9 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
919 913
920 if (snd_BUG_ON(!pcm || !rsubstream)) 914 if (snd_BUG_ON(!pcm || !rsubstream))
921 return -ENXIO; 915 return -ENXIO;
916 if (snd_BUG_ON(stream != SNDRV_PCM_STREAM_PLAYBACK &&
917 stream != SNDRV_PCM_STREAM_CAPTURE))
918 return -EINVAL;
922 *rsubstream = NULL; 919 *rsubstream = NULL;
923 pstr = &pcm->streams[stream]; 920 pstr = &pcm->streams[stream];
924 if (pstr->substream == NULL || pstr->substream_count == 0) 921 if (pstr->substream == NULL || pstr->substream_count == 0)
@@ -927,25 +924,14 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
927 card = pcm->card; 924 card = pcm->card;
928 prefer_subdevice = snd_ctl_get_preferred_subdevice(card, SND_CTL_SUBDEV_PCM); 925 prefer_subdevice = snd_ctl_get_preferred_subdevice(card, SND_CTL_SUBDEV_PCM);
929 926
930 switch (stream) { 927 if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) {
931 case SNDRV_PCM_STREAM_PLAYBACK: 928 int opposite = !stream;
932 if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) { 929
933 for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; substream; substream = substream->next) { 930 for (substream = pcm->streams[opposite].substream; substream;
934 if (SUBSTREAM_BUSY(substream)) 931 substream = substream->next) {
935 return -EAGAIN; 932 if (SUBSTREAM_BUSY(substream))
936 } 933 return -EAGAIN;
937 }
938 break;
939 case SNDRV_PCM_STREAM_CAPTURE:
940 if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) {
941 for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next) {
942 if (SUBSTREAM_BUSY(substream))
943 return -EAGAIN;
944 }
945 } 934 }
946 break;
947 default:
948 return -EINVAL;
949 } 935 }
950 936
951 if (file->f_flags & O_APPEND) { 937 if (file->f_flags & O_APPEND) {
@@ -968,15 +954,12 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
968 return 0; 954 return 0;
969 } 955 }
970 956
971 if (prefer_subdevice >= 0) { 957 for (substream = pstr->substream; substream; substream = substream->next) {
972 for (substream = pstr->substream; substream; substream = substream->next) 958 if (!SUBSTREAM_BUSY(substream) &&
973 if (!SUBSTREAM_BUSY(substream) && substream->number == prefer_subdevice) 959 (prefer_subdevice == -1 ||
974 goto __ok; 960 substream->number == prefer_subdevice))
975 }
976 for (substream = pstr->substream; substream; substream = substream->next)
977 if (!SUBSTREAM_BUSY(substream))
978 break; 961 break;
979 __ok: 962 }
980 if (substream == NULL) 963 if (substream == NULL)
981 return -EAGAIN; 964 return -EAGAIN;
982 965
@@ -1086,15 +1069,16 @@ static int snd_pcm_dev_register(struct snd_device *device)
1086 if (snd_BUG_ON(!device || !device->device_data)) 1069 if (snd_BUG_ON(!device || !device->device_data))
1087 return -ENXIO; 1070 return -ENXIO;
1088 pcm = device->device_data; 1071 pcm = device->device_data;
1072 if (pcm->internal)
1073 return 0;
1074
1089 mutex_lock(&register_mutex); 1075 mutex_lock(&register_mutex);
1090 err = snd_pcm_add(pcm); 1076 err = snd_pcm_add(pcm);
1091 if (err) { 1077 if (err)
1092 mutex_unlock(&register_mutex); 1078 goto unlock;
1093 return err;
1094 }
1095 for (cidx = 0; cidx < 2; cidx++) { 1079 for (cidx = 0; cidx < 2; cidx++) {
1096 int devtype = -1; 1080 int devtype = -1;
1097 if (pcm->streams[cidx].substream == NULL || pcm->internal) 1081 if (pcm->streams[cidx].substream == NULL)
1098 continue; 1082 continue;
1099 switch (cidx) { 1083 switch (cidx) {
1100 case SNDRV_PCM_STREAM_PLAYBACK: 1084 case SNDRV_PCM_STREAM_PLAYBACK:
@@ -1109,9 +1093,8 @@ static int snd_pcm_dev_register(struct snd_device *device)
1109 &snd_pcm_f_ops[cidx], pcm, 1093 &snd_pcm_f_ops[cidx], pcm,
1110 &pcm->streams[cidx].dev); 1094 &pcm->streams[cidx].dev);
1111 if (err < 0) { 1095 if (err < 0) {
1112 list_del(&pcm->list); 1096 list_del_init(&pcm->list);
1113 mutex_unlock(&register_mutex); 1097 goto unlock;
1114 return err;
1115 } 1098 }
1116 1099
1117 for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) 1100 for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
@@ -1121,8 +1104,9 @@ static int snd_pcm_dev_register(struct snd_device *device)
1121 list_for_each_entry(notify, &snd_pcm_notify_list, list) 1104 list_for_each_entry(notify, &snd_pcm_notify_list, list)
1122 notify->n_register(pcm); 1105 notify->n_register(pcm);
1123 1106
1107 unlock:
1124 mutex_unlock(&register_mutex); 1108 mutex_unlock(&register_mutex);
1125 return 0; 1109 return err;
1126} 1110}
1127 1111
1128static int snd_pcm_dev_disconnect(struct snd_device *device) 1112static int snd_pcm_dev_disconnect(struct snd_device *device)
@@ -1133,13 +1117,10 @@ static int snd_pcm_dev_disconnect(struct snd_device *device)
1133 int cidx; 1117 int cidx;
1134 1118
1135 mutex_lock(&register_mutex); 1119 mutex_lock(&register_mutex);
1136 if (list_empty(&pcm->list))
1137 goto unlock;
1138
1139 mutex_lock(&pcm->open_mutex); 1120 mutex_lock(&pcm->open_mutex);
1140 wake_up(&pcm->open_wait); 1121 wake_up(&pcm->open_wait);
1141 list_del_init(&pcm->list); 1122 list_del_init(&pcm->list);
1142 for (cidx = 0; cidx < 2; cidx++) 1123 for (cidx = 0; cidx < 2; cidx++) {
1143 for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) { 1124 for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) {
1144 snd_pcm_stream_lock_irq(substream); 1125 snd_pcm_stream_lock_irq(substream);
1145 if (substream->runtime) { 1126 if (substream->runtime) {
@@ -1149,18 +1130,20 @@ static int snd_pcm_dev_disconnect(struct snd_device *device)
1149 } 1130 }
1150 snd_pcm_stream_unlock_irq(substream); 1131 snd_pcm_stream_unlock_irq(substream);
1151 } 1132 }
1152 list_for_each_entry(notify, &snd_pcm_notify_list, list) { 1133 }
1153 notify->n_disconnect(pcm); 1134 if (!pcm->internal) {
1135 list_for_each_entry(notify, &snd_pcm_notify_list, list)
1136 notify->n_disconnect(pcm);
1154 } 1137 }
1155 for (cidx = 0; cidx < 2; cidx++) { 1138 for (cidx = 0; cidx < 2; cidx++) {
1156 snd_unregister_device(&pcm->streams[cidx].dev); 1139 if (!pcm->internal)
1140 snd_unregister_device(&pcm->streams[cidx].dev);
1157 if (pcm->streams[cidx].chmap_kctl) { 1141 if (pcm->streams[cidx].chmap_kctl) {
1158 snd_ctl_remove(pcm->card, pcm->streams[cidx].chmap_kctl); 1142 snd_ctl_remove(pcm->card, pcm->streams[cidx].chmap_kctl);
1159 pcm->streams[cidx].chmap_kctl = NULL; 1143 pcm->streams[cidx].chmap_kctl = NULL;
1160 } 1144 }
1161 } 1145 }
1162 mutex_unlock(&pcm->open_mutex); 1146 mutex_unlock(&pcm->open_mutex);
1163 unlock:
1164 mutex_unlock(&register_mutex); 1147 mutex_unlock(&register_mutex);
1165 return 0; 1148 return 0;
1166} 1149}
diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
index 2d957ba63557..b48b434444ed 100644
--- a/sound/core/pcm_compat.c
+++ b/sound/core/pcm_compat.c
@@ -194,18 +194,30 @@ struct snd_pcm_status32 {
194 u32 avail_max; 194 u32 avail_max;
195 u32 overrange; 195 u32 overrange;
196 s32 suspended_state; 196 s32 suspended_state;
197 u32 reserved_alignment; 197 u32 audio_tstamp_data;
198 struct compat_timespec audio_tstamp; 198 struct compat_timespec audio_tstamp;
199 unsigned char reserved[56-sizeof(struct compat_timespec)]; 199 struct compat_timespec driver_tstamp;
200 u32 audio_tstamp_accuracy;
201 unsigned char reserved[52-2*sizeof(struct compat_timespec)];
200} __attribute__((packed)); 202} __attribute__((packed));
201 203
202 204
203static int snd_pcm_status_user_compat(struct snd_pcm_substream *substream, 205static int snd_pcm_status_user_compat(struct snd_pcm_substream *substream,
204 struct snd_pcm_status32 __user *src) 206 struct snd_pcm_status32 __user *src,
207 bool ext)
205{ 208{
206 struct snd_pcm_status status; 209 struct snd_pcm_status status;
207 int err; 210 int err;
208 211
212 memset(&status, 0, sizeof(status));
213 /*
214 * with extension, parameters are read/write,
215 * get audio_tstamp_data from user,
216 * ignore rest of status structure
217 */
218 if (ext && get_user(status.audio_tstamp_data,
219 (u32 __user *)(&src->audio_tstamp_data)))
220 return -EFAULT;
209 err = snd_pcm_status(substream, &status); 221 err = snd_pcm_status(substream, &status);
210 if (err < 0) 222 if (err < 0)
211 return err; 223 return err;
@@ -222,7 +234,10 @@ static int snd_pcm_status_user_compat(struct snd_pcm_substream *substream,
222 put_user(status.avail_max, &src->avail_max) || 234 put_user(status.avail_max, &src->avail_max) ||
223 put_user(status.overrange, &src->overrange) || 235 put_user(status.overrange, &src->overrange) ||
224 put_user(status.suspended_state, &src->suspended_state) || 236 put_user(status.suspended_state, &src->suspended_state) ||
225 compat_put_timespec(&status.audio_tstamp, &src->audio_tstamp)) 237 put_user(status.audio_tstamp_data, &src->audio_tstamp_data) ||
238 compat_put_timespec(&status.audio_tstamp, &src->audio_tstamp) ||
239 compat_put_timespec(&status.driver_tstamp, &src->driver_tstamp) ||
240 put_user(status.audio_tstamp_accuracy, &src->audio_tstamp_accuracy))
226 return -EFAULT; 241 return -EFAULT;
227 242
228 return err; 243 return err;
@@ -457,6 +472,7 @@ enum {
457 SNDRV_PCM_IOCTL_HW_PARAMS32 = _IOWR('A', 0x11, struct snd_pcm_hw_params32), 472 SNDRV_PCM_IOCTL_HW_PARAMS32 = _IOWR('A', 0x11, struct snd_pcm_hw_params32),
458 SNDRV_PCM_IOCTL_SW_PARAMS32 = _IOWR('A', 0x13, struct snd_pcm_sw_params32), 473 SNDRV_PCM_IOCTL_SW_PARAMS32 = _IOWR('A', 0x13, struct snd_pcm_sw_params32),
459 SNDRV_PCM_IOCTL_STATUS32 = _IOR('A', 0x20, struct snd_pcm_status32), 474 SNDRV_PCM_IOCTL_STATUS32 = _IOR('A', 0x20, struct snd_pcm_status32),
475 SNDRV_PCM_IOCTL_STATUS_EXT32 = _IOWR('A', 0x24, struct snd_pcm_status32),
460 SNDRV_PCM_IOCTL_DELAY32 = _IOR('A', 0x21, s32), 476 SNDRV_PCM_IOCTL_DELAY32 = _IOR('A', 0x21, s32),
461 SNDRV_PCM_IOCTL_CHANNEL_INFO32 = _IOR('A', 0x32, struct snd_pcm_channel_info32), 477 SNDRV_PCM_IOCTL_CHANNEL_INFO32 = _IOR('A', 0x32, struct snd_pcm_channel_info32),
462 SNDRV_PCM_IOCTL_REWIND32 = _IOW('A', 0x46, u32), 478 SNDRV_PCM_IOCTL_REWIND32 = _IOW('A', 0x46, u32),
@@ -517,7 +533,9 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l
517 case SNDRV_PCM_IOCTL_SW_PARAMS32: 533 case SNDRV_PCM_IOCTL_SW_PARAMS32:
518 return snd_pcm_ioctl_sw_params_compat(substream, argp); 534 return snd_pcm_ioctl_sw_params_compat(substream, argp);
519 case SNDRV_PCM_IOCTL_STATUS32: 535 case SNDRV_PCM_IOCTL_STATUS32:
520 return snd_pcm_status_user_compat(substream, argp); 536 return snd_pcm_status_user_compat(substream, argp, false);
537 case SNDRV_PCM_IOCTL_STATUS_EXT32:
538 return snd_pcm_status_user_compat(substream, argp, true);
521 case SNDRV_PCM_IOCTL_SYNC_PTR32: 539 case SNDRV_PCM_IOCTL_SYNC_PTR32:
522 return snd_pcm_ioctl_sync_ptr_compat(substream, argp); 540 return snd_pcm_ioctl_sync_ptr_compat(substream, argp);
523 case SNDRV_PCM_IOCTL_CHANNEL_INFO32: 541 case SNDRV_PCM_IOCTL_CHANNEL_INFO32:
diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c
index 6542c4083594..fba365a78390 100644
--- a/sound/core/pcm_dmaengine.c
+++ b/sound/core/pcm_dmaengine.c
@@ -289,7 +289,7 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_request_channel);
289 * 289 *
290 * The function should usually be called from the pcm open callback. Note that 290 * The function should usually be called from the pcm open callback. Note that
291 * this function will use private_data field of the substream's runtime. So it 291 * this function will use private_data field of the substream's runtime. So it
292 * is not availabe to your pcm driver implementation. 292 * is not available to your pcm driver implementation.
293 */ 293 */
294int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream, 294int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream,
295 struct dma_chan *chan) 295 struct dma_chan *chan)
@@ -328,7 +328,7 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open);
328 * This function will request a DMA channel using the passed filter function and 328 * This function will request a DMA channel using the passed filter function and
329 * data. The function should usually be called from the pcm open callback. Note 329 * data. The function should usually be called from the pcm open callback. Note
330 * that this function will use private_data field of the substream's runtime. So 330 * that this function will use private_data field of the substream's runtime. So
331 * it is not availabe to your pcm driver implementation. 331 * it is not available to your pcm driver implementation.
332 */ 332 */
333int snd_dmaengine_pcm_open_request_chan(struct snd_pcm_substream *substream, 333int snd_dmaengine_pcm_open_request_chan(struct snd_pcm_substream *substream,
334 dma_filter_fn filter_fn, void *filter_data) 334 dma_filter_fn filter_fn, void *filter_data)
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index ffd656012ab8..ac6b33f3779c 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -232,6 +232,49 @@ int snd_pcm_update_state(struct snd_pcm_substream *substream,
232 return 0; 232 return 0;
233} 233}
234 234
235static void update_audio_tstamp(struct snd_pcm_substream *substream,
236 struct timespec *curr_tstamp,
237 struct timespec *audio_tstamp)
238{
239 struct snd_pcm_runtime *runtime = substream->runtime;
240 u64 audio_frames, audio_nsecs;
241 struct timespec driver_tstamp;
242
243 if (runtime->tstamp_mode != SNDRV_PCM_TSTAMP_ENABLE)
244 return;
245
246 if (!(substream->ops->get_time_info) ||
247 (runtime->audio_tstamp_report.actual_type ==
248 SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT)) {
249
250 /*
251 * provide audio timestamp derived from pointer position
252 * add delay only if requested
253 */
254
255 audio_frames = runtime->hw_ptr_wrap + runtime->status->hw_ptr;
256
257 if (runtime->audio_tstamp_config.report_delay) {
258 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
259 audio_frames -= runtime->delay;
260 else
261 audio_frames += runtime->delay;
262 }
263 audio_nsecs = div_u64(audio_frames * 1000000000LL,
264 runtime->rate);
265 *audio_tstamp = ns_to_timespec(audio_nsecs);
266 }
267 runtime->status->audio_tstamp = *audio_tstamp;
268 runtime->status->tstamp = *curr_tstamp;
269
270 /*
271 * re-take a driver timestamp to let apps detect if the reference tstamp
272 * read by low-level hardware was provided with a delay
273 */
274 snd_pcm_gettime(substream->runtime, (struct timespec *)&driver_tstamp);
275 runtime->driver_tstamp = driver_tstamp;
276}
277
235static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream, 278static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
236 unsigned int in_interrupt) 279 unsigned int in_interrupt)
237{ 280{
@@ -256,11 +299,18 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
256 pos = substream->ops->pointer(substream); 299 pos = substream->ops->pointer(substream);
257 curr_jiffies = jiffies; 300 curr_jiffies = jiffies;
258 if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { 301 if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
259 snd_pcm_gettime(runtime, (struct timespec *)&curr_tstamp); 302 if ((substream->ops->get_time_info) &&
260 303 (runtime->audio_tstamp_config.type_requested != SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT)) {
261 if ((runtime->hw.info & SNDRV_PCM_INFO_HAS_WALL_CLOCK) && 304 substream->ops->get_time_info(substream, &curr_tstamp,
262 (substream->ops->wall_clock)) 305 &audio_tstamp,
263 substream->ops->wall_clock(substream, &audio_tstamp); 306 &runtime->audio_tstamp_config,
307 &runtime->audio_tstamp_report);
308
309 /* re-test in case tstamp type is not supported in hardware and was demoted to DEFAULT */
310 if (runtime->audio_tstamp_report.actual_type == SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT)
311 snd_pcm_gettime(runtime, (struct timespec *)&curr_tstamp);
312 } else
313 snd_pcm_gettime(runtime, (struct timespec *)&curr_tstamp);
264 } 314 }
265 315
266 if (pos == SNDRV_PCM_POS_XRUN) { 316 if (pos == SNDRV_PCM_POS_XRUN) {
@@ -403,8 +453,10 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
403 } 453 }
404 454
405 no_delta_check: 455 no_delta_check:
406 if (runtime->status->hw_ptr == new_hw_ptr) 456 if (runtime->status->hw_ptr == new_hw_ptr) {
457 update_audio_tstamp(substream, &curr_tstamp, &audio_tstamp);
407 return 0; 458 return 0;
459 }
408 460
409 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && 461 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
410 runtime->silence_size > 0) 462 runtime->silence_size > 0)
@@ -426,30 +478,8 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
426 snd_BUG_ON(crossed_boundary != 1); 478 snd_BUG_ON(crossed_boundary != 1);
427 runtime->hw_ptr_wrap += runtime->boundary; 479 runtime->hw_ptr_wrap += runtime->boundary;
428 } 480 }
429 if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
430 runtime->status->tstamp = curr_tstamp;
431 481
432 if (!(runtime->hw.info & SNDRV_PCM_INFO_HAS_WALL_CLOCK)) { 482 update_audio_tstamp(substream, &curr_tstamp, &audio_tstamp);
433 /*
434 * no wall clock available, provide audio timestamp
435 * derived from pointer position+delay
436 */
437 u64 audio_frames, audio_nsecs;
438
439 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
440 audio_frames = runtime->hw_ptr_wrap
441 + runtime->status->hw_ptr
442 - runtime->delay;
443 else
444 audio_frames = runtime->hw_ptr_wrap
445 + runtime->status->hw_ptr
446 + runtime->delay;
447 audio_nsecs = div_u64(audio_frames * 1000000000LL,
448 runtime->rate);
449 audio_tstamp = ns_to_timespec(audio_nsecs);
450 }
451 runtime->status->audio_tstamp = audio_tstamp;
452 }
453 483
454 return snd_pcm_update_state(substream, runtime); 484 return snd_pcm_update_state(substream, runtime);
455} 485}
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 279e24f61305..abe1e811e660 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -707,6 +707,23 @@ int snd_pcm_status(struct snd_pcm_substream *substream,
707 struct snd_pcm_runtime *runtime = substream->runtime; 707 struct snd_pcm_runtime *runtime = substream->runtime;
708 708
709 snd_pcm_stream_lock_irq(substream); 709 snd_pcm_stream_lock_irq(substream);
710
711 snd_pcm_unpack_audio_tstamp_config(status->audio_tstamp_data,
712 &runtime->audio_tstamp_config);
713
714 /* backwards compatible behavior */
715 if (runtime->audio_tstamp_config.type_requested ==
716 SNDRV_PCM_AUDIO_TSTAMP_TYPE_COMPAT) {
717 if (runtime->hw.info & SNDRV_PCM_INFO_HAS_WALL_CLOCK)
718 runtime->audio_tstamp_config.type_requested =
719 SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK;
720 else
721 runtime->audio_tstamp_config.type_requested =
722 SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT;
723 runtime->audio_tstamp_report.valid = 0;
724 } else
725 runtime->audio_tstamp_report.valid = 1;
726
710 status->state = runtime->status->state; 727 status->state = runtime->status->state;
711 status->suspended_state = runtime->status->suspended_state; 728 status->suspended_state = runtime->status->suspended_state;
712 if (status->state == SNDRV_PCM_STATE_OPEN) 729 if (status->state == SNDRV_PCM_STATE_OPEN)
@@ -716,8 +733,15 @@ int snd_pcm_status(struct snd_pcm_substream *substream,
716 snd_pcm_update_hw_ptr(substream); 733 snd_pcm_update_hw_ptr(substream);
717 if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { 734 if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
718 status->tstamp = runtime->status->tstamp; 735 status->tstamp = runtime->status->tstamp;
736 status->driver_tstamp = runtime->driver_tstamp;
719 status->audio_tstamp = 737 status->audio_tstamp =
720 runtime->status->audio_tstamp; 738 runtime->status->audio_tstamp;
739 if (runtime->audio_tstamp_report.valid == 1)
740 /* backwards compatibility, no report provided in COMPAT mode */
741 snd_pcm_pack_audio_tstamp_report(&status->audio_tstamp_data,
742 &status->audio_tstamp_accuracy,
743 &runtime->audio_tstamp_report);
744
721 goto _tstamp_end; 745 goto _tstamp_end;
722 } 746 }
723 } else { 747 } else {
@@ -753,12 +777,21 @@ int snd_pcm_status(struct snd_pcm_substream *substream,
753} 777}
754 778
755static int snd_pcm_status_user(struct snd_pcm_substream *substream, 779static int snd_pcm_status_user(struct snd_pcm_substream *substream,
756 struct snd_pcm_status __user * _status) 780 struct snd_pcm_status __user * _status,
781 bool ext)
757{ 782{
758 struct snd_pcm_status status; 783 struct snd_pcm_status status;
759 int res; 784 int res;
760 785
761 memset(&status, 0, sizeof(status)); 786 memset(&status, 0, sizeof(status));
787 /*
788 * with extension, parameters are read/write,
789 * get audio_tstamp_data from user,
790 * ignore rest of status structure
791 */
792 if (ext && get_user(status.audio_tstamp_data,
793 (u32 __user *)(&_status->audio_tstamp_data)))
794 return -EFAULT;
762 res = snd_pcm_status(substream, &status); 795 res = snd_pcm_status(substream, &status);
763 if (res < 0) 796 if (res < 0)
764 return res; 797 return res;
@@ -2725,7 +2758,9 @@ static int snd_pcm_common_ioctl1(struct file *file,
2725 case SNDRV_PCM_IOCTL_SW_PARAMS: 2758 case SNDRV_PCM_IOCTL_SW_PARAMS:
2726 return snd_pcm_sw_params_user(substream, arg); 2759 return snd_pcm_sw_params_user(substream, arg);
2727 case SNDRV_PCM_IOCTL_STATUS: 2760 case SNDRV_PCM_IOCTL_STATUS:
2728 return snd_pcm_status_user(substream, arg); 2761 return snd_pcm_status_user(substream, arg, false);
2762 case SNDRV_PCM_IOCTL_STATUS_EXT:
2763 return snd_pcm_status_user(substream, arg, true);
2729 case SNDRV_PCM_IOCTL_CHANNEL_INFO: 2764 case SNDRV_PCM_IOCTL_CHANNEL_INFO:
2730 return snd_pcm_channel_info_user(substream, arg); 2765 return snd_pcm_channel_info_user(substream, arg);
2731 case SNDRV_PCM_IOCTL_PREPARE: 2766 case SNDRV_PCM_IOCTL_PREPARE:
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index b5a748596fc4..a7759846fbaa 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -1429,10 +1429,8 @@ static int snd_rawmidi_alloc_substreams(struct snd_rawmidi *rmidi,
1429 1429
1430 for (idx = 0; idx < count; idx++) { 1430 for (idx = 0; idx < count; idx++) {
1431 substream = kzalloc(sizeof(*substream), GFP_KERNEL); 1431 substream = kzalloc(sizeof(*substream), GFP_KERNEL);
1432 if (substream == NULL) { 1432 if (!substream)
1433 rmidi_err(rmidi, "rawmidi: cannot allocate substream\n");
1434 return -ENOMEM; 1433 return -ENOMEM;
1435 }
1436 substream->stream = direction; 1434 substream->stream = direction;
1437 substream->number = idx; 1435 substream->number = idx;
1438 substream->rmidi = rmidi; 1436 substream->rmidi = rmidi;
@@ -1479,10 +1477,8 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,
1479 if (rrawmidi) 1477 if (rrawmidi)
1480 *rrawmidi = NULL; 1478 *rrawmidi = NULL;
1481 rmidi = kzalloc(sizeof(*rmidi), GFP_KERNEL); 1479 rmidi = kzalloc(sizeof(*rmidi), GFP_KERNEL);
1482 if (rmidi == NULL) { 1480 if (!rmidi)
1483 dev_err(card->dev, "rawmidi: cannot allocate\n");
1484 return -ENOMEM; 1481 return -ENOMEM;
1485 }
1486 rmidi->card = card; 1482 rmidi->card = card;
1487 rmidi->device = device; 1483 rmidi->device = device;
1488 mutex_init(&rmidi->open_mutex); 1484 mutex_init(&rmidi->open_mutex);
diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
index 16d42679e43f..72873a46afeb 100644
--- a/sound/core/seq/oss/seq_oss.c
+++ b/sound/core/seq/oss/seq_oss.c
@@ -65,15 +65,20 @@ static unsigned int odev_poll(struct file *file, poll_table * wait);
65 * module interface 65 * module interface
66 */ 66 */
67 67
68static struct snd_seq_driver seq_oss_synth_driver = {
69 .driver = {
70 .name = KBUILD_MODNAME,
71 .probe = snd_seq_oss_synth_probe,
72 .remove = snd_seq_oss_synth_remove,
73 },
74 .id = SNDRV_SEQ_DEV_ID_OSS,
75 .argsize = sizeof(struct snd_seq_oss_reg),
76};
77
68static int __init alsa_seq_oss_init(void) 78static int __init alsa_seq_oss_init(void)
69{ 79{
70 int rc; 80 int rc;
71 static struct snd_seq_dev_ops ops = {
72 snd_seq_oss_synth_register,
73 snd_seq_oss_synth_unregister,
74 };
75 81
76 snd_seq_autoload_lock();
77 if ((rc = register_device()) < 0) 82 if ((rc = register_device()) < 0)
78 goto error; 83 goto error;
79 if ((rc = register_proc()) < 0) { 84 if ((rc = register_proc()) < 0) {
@@ -86,8 +91,8 @@ static int __init alsa_seq_oss_init(void)
86 goto error; 91 goto error;
87 } 92 }
88 93
89 if ((rc = snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OSS, &ops, 94 rc = snd_seq_driver_register(&seq_oss_synth_driver);
90 sizeof(struct snd_seq_oss_reg))) < 0) { 95 if (rc < 0) {
91 snd_seq_oss_delete_client(); 96 snd_seq_oss_delete_client();
92 unregister_proc(); 97 unregister_proc();
93 unregister_device(); 98 unregister_device();
@@ -98,13 +103,12 @@ static int __init alsa_seq_oss_init(void)
98 snd_seq_oss_synth_init(); 103 snd_seq_oss_synth_init();
99 104
100 error: 105 error:
101 snd_seq_autoload_unlock();
102 return rc; 106 return rc;
103} 107}
104 108
105static void __exit alsa_seq_oss_exit(void) 109static void __exit alsa_seq_oss_exit(void)
106{ 110{
107 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_OSS); 111 snd_seq_driver_unregister(&seq_oss_synth_driver);
108 snd_seq_oss_delete_client(); 112 snd_seq_oss_delete_client();
109 unregister_proc(); 113 unregister_proc();
110 unregister_device(); 114 unregister_device();
diff --git a/sound/core/seq/oss/seq_oss_init.c b/sound/core/seq/oss/seq_oss_init.c
index b0e32e161dd1..2de3feff70d0 100644
--- a/sound/core/seq/oss/seq_oss_init.c
+++ b/sound/core/seq/oss/seq_oss_init.c
@@ -188,10 +188,8 @@ snd_seq_oss_open(struct file *file, int level)
188 struct seq_oss_devinfo *dp; 188 struct seq_oss_devinfo *dp;
189 189
190 dp = kzalloc(sizeof(*dp), GFP_KERNEL); 190 dp = kzalloc(sizeof(*dp), GFP_KERNEL);
191 if (!dp) { 191 if (!dp)
192 pr_err("ALSA: seq_oss: can't malloc device info\n");
193 return -ENOMEM; 192 return -ENOMEM;
194 }
195 193
196 dp->cseq = system_client; 194 dp->cseq = system_client;
197 dp->port = -1; 195 dp->port = -1;
diff --git a/sound/core/seq/oss/seq_oss_midi.c b/sound/core/seq/oss/seq_oss_midi.c
index e79cc44b1394..96e8395ae586 100644
--- a/sound/core/seq/oss/seq_oss_midi.c
+++ b/sound/core/seq/oss/seq_oss_midi.c
@@ -173,10 +173,9 @@ snd_seq_oss_midi_check_new_port(struct snd_seq_port_info *pinfo)
173 /* 173 /*
174 * allocate midi info record 174 * allocate midi info record
175 */ 175 */
176 if ((mdev = kzalloc(sizeof(*mdev), GFP_KERNEL)) == NULL) { 176 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
177 pr_err("ALSA: seq_oss: can't malloc midi info\n"); 177 if (!mdev)
178 return -ENOMEM; 178 return -ENOMEM;
179 }
180 179
181 /* copy the port information */ 180 /* copy the port information */
182 mdev->client = pinfo->addr.client; 181 mdev->client = pinfo->addr.client;
diff --git a/sound/core/seq/oss/seq_oss_readq.c b/sound/core/seq/oss/seq_oss_readq.c
index 654d17a5023c..c080c73cea04 100644
--- a/sound/core/seq/oss/seq_oss_readq.c
+++ b/sound/core/seq/oss/seq_oss_readq.c
@@ -47,13 +47,12 @@ snd_seq_oss_readq_new(struct seq_oss_devinfo *dp, int maxlen)
47{ 47{
48 struct seq_oss_readq *q; 48 struct seq_oss_readq *q;
49 49
50 if ((q = kzalloc(sizeof(*q), GFP_KERNEL)) == NULL) { 50 q = kzalloc(sizeof(*q), GFP_KERNEL);
51 pr_err("ALSA: seq_oss: can't malloc read queue\n"); 51 if (!q)
52 return NULL; 52 return NULL;
53 }
54 53
55 if ((q->q = kcalloc(maxlen, sizeof(union evrec), GFP_KERNEL)) == NULL) { 54 q->q = kcalloc(maxlen, sizeof(union evrec), GFP_KERNEL);
56 pr_err("ALSA: seq_oss: can't malloc read queue buffer\n"); 55 if (!q->q) {
57 kfree(q); 56 kfree(q);
58 return NULL; 57 return NULL;
59 } 58 }
diff --git a/sound/core/seq/oss/seq_oss_synth.c b/sound/core/seq/oss/seq_oss_synth.c
index 701feb71b700..48e4fe1b68ab 100644
--- a/sound/core/seq/oss/seq_oss_synth.c
+++ b/sound/core/seq/oss/seq_oss_synth.c
@@ -98,17 +98,17 @@ snd_seq_oss_synth_init(void)
98 * registration of the synth device 98 * registration of the synth device
99 */ 99 */
100int 100int
101snd_seq_oss_synth_register(struct snd_seq_device *dev) 101snd_seq_oss_synth_probe(struct device *_dev)
102{ 102{
103 struct snd_seq_device *dev = to_seq_dev(_dev);
103 int i; 104 int i;
104 struct seq_oss_synth *rec; 105 struct seq_oss_synth *rec;
105 struct snd_seq_oss_reg *reg = SNDRV_SEQ_DEVICE_ARGPTR(dev); 106 struct snd_seq_oss_reg *reg = SNDRV_SEQ_DEVICE_ARGPTR(dev);
106 unsigned long flags; 107 unsigned long flags;
107 108
108 if ((rec = kzalloc(sizeof(*rec), GFP_KERNEL)) == NULL) { 109 rec = kzalloc(sizeof(*rec), GFP_KERNEL);
109 pr_err("ALSA: seq_oss: can't malloc synth info\n"); 110 if (!rec)
110 return -ENOMEM; 111 return -ENOMEM;
111 }
112 rec->seq_device = -1; 112 rec->seq_device = -1;
113 rec->synth_type = reg->type; 113 rec->synth_type = reg->type;
114 rec->synth_subtype = reg->subtype; 114 rec->synth_subtype = reg->subtype;
@@ -149,8 +149,9 @@ snd_seq_oss_synth_register(struct snd_seq_device *dev)
149 149
150 150
151int 151int
152snd_seq_oss_synth_unregister(struct snd_seq_device *dev) 152snd_seq_oss_synth_remove(struct device *_dev)
153{ 153{
154 struct snd_seq_device *dev = to_seq_dev(_dev);
154 int index; 155 int index;
155 struct seq_oss_synth *rec = dev->driver_data; 156 struct seq_oss_synth *rec = dev->driver_data;
156 unsigned long flags; 157 unsigned long flags;
@@ -247,7 +248,6 @@ snd_seq_oss_synth_setup(struct seq_oss_devinfo *dp)
247 if (info->nr_voices > 0) { 248 if (info->nr_voices > 0) {
248 info->ch = kcalloc(info->nr_voices, sizeof(struct seq_oss_chinfo), GFP_KERNEL); 249 info->ch = kcalloc(info->nr_voices, sizeof(struct seq_oss_chinfo), GFP_KERNEL);
249 if (!info->ch) { 250 if (!info->ch) {
250 pr_err("ALSA: seq_oss: Cannot malloc voices\n");
251 rec->oper.close(&info->arg); 251 rec->oper.close(&info->arg);
252 module_put(rec->oper.owner); 252 module_put(rec->oper.owner);
253 snd_use_lock_free(&rec->use_lock); 253 snd_use_lock_free(&rec->use_lock);
diff --git a/sound/core/seq/oss/seq_oss_synth.h b/sound/core/seq/oss/seq_oss_synth.h
index dbdfcbb80eaa..74ac55f166b6 100644
--- a/sound/core/seq/oss/seq_oss_synth.h
+++ b/sound/core/seq/oss/seq_oss_synth.h
@@ -28,8 +28,8 @@
28#include <sound/seq_device.h> 28#include <sound/seq_device.h>
29 29
30void snd_seq_oss_synth_init(void); 30void snd_seq_oss_synth_init(void);
31int snd_seq_oss_synth_register(struct snd_seq_device *dev); 31int snd_seq_oss_synth_probe(struct device *dev);
32int snd_seq_oss_synth_unregister(struct snd_seq_device *dev); 32int snd_seq_oss_synth_remove(struct device *dev);
33void snd_seq_oss_synth_setup(struct seq_oss_devinfo *dp); 33void snd_seq_oss_synth_setup(struct seq_oss_devinfo *dp);
34void snd_seq_oss_synth_setup_midi(struct seq_oss_devinfo *dp); 34void snd_seq_oss_synth_setup_midi(struct seq_oss_devinfo *dp);
35void snd_seq_oss_synth_cleanup(struct seq_oss_devinfo *dp); 35void snd_seq_oss_synth_cleanup(struct seq_oss_devinfo *dp);
diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
index 0631bdadd12b..d99f99d61983 100644
--- a/sound/core/seq/seq_device.c
+++ b/sound/core/seq/seq_device.c
@@ -36,6 +36,7 @@
36 * 36 *
37 */ 37 */
38 38
39#include <linux/device.h>
39#include <linux/init.h> 40#include <linux/init.h>
40#include <linux/module.h> 41#include <linux/module.h>
41#include <sound/core.h> 42#include <sound/core.h>
@@ -51,140 +52,78 @@ MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
51MODULE_DESCRIPTION("ALSA sequencer device management"); 52MODULE_DESCRIPTION("ALSA sequencer device management");
52MODULE_LICENSE("GPL"); 53MODULE_LICENSE("GPL");
53 54
54/* driver state */ 55/*
55#define DRIVER_EMPTY 0 56 * bus definition
56#define DRIVER_LOADED (1<<0) 57 */
57#define DRIVER_REQUESTED (1<<1) 58static int snd_seq_bus_match(struct device *dev, struct device_driver *drv)
58#define DRIVER_LOCKED (1<<2) 59{
59#define DRIVER_REQUESTING (1<<3) 60 struct snd_seq_device *sdev = to_seq_dev(dev);
60 61 struct snd_seq_driver *sdrv = to_seq_drv(drv);
61struct ops_list {
62 char id[ID_LEN]; /* driver id */
63 int driver; /* driver state */
64 int used; /* reference counter */
65 int argsize; /* argument size */
66
67 /* operators */
68 struct snd_seq_dev_ops ops;
69
70 /* registered devices */
71 struct list_head dev_list; /* list of devices */
72 int num_devices; /* number of associated devices */
73 int num_init_devices; /* number of initialized devices */
74 struct mutex reg_mutex;
75
76 struct list_head list; /* next driver */
77};
78 62
63 return strcmp(sdrv->id, sdev->id) == 0 &&
64 sdrv->argsize == sdev->argsize;
65}
79 66
80static LIST_HEAD(opslist); 67static struct bus_type snd_seq_bus_type = {
81static int num_ops; 68 .name = "snd_seq",
82static DEFINE_MUTEX(ops_mutex); 69 .match = snd_seq_bus_match,
83#ifdef CONFIG_PROC_FS 70};
84static struct snd_info_entry *info_entry;
85#endif
86 71
87/* 72/*
88 * prototypes 73 * proc interface -- just for compatibility
89 */ 74 */
90static int snd_seq_device_free(struct snd_seq_device *dev); 75#ifdef CONFIG_PROC_FS
91static int snd_seq_device_dev_free(struct snd_device *device); 76static struct snd_info_entry *info_entry;
92static int snd_seq_device_dev_register(struct snd_device *device);
93static int snd_seq_device_dev_disconnect(struct snd_device *device);
94
95static int init_device(struct snd_seq_device *dev, struct ops_list *ops);
96static int free_device(struct snd_seq_device *dev, struct ops_list *ops);
97static struct ops_list *find_driver(char *id, int create_if_empty);
98static struct ops_list *create_driver(char *id);
99static void unlock_driver(struct ops_list *ops);
100static void remove_drivers(void);
101 77
102/* 78static int print_dev_info(struct device *dev, void *data)
103 * show all drivers and their status 79{
104 */ 80 struct snd_seq_device *sdev = to_seq_dev(dev);
81 struct snd_info_buffer *buffer = data;
82
83 snd_iprintf(buffer, "snd-%s,%s,%d\n", sdev->id,
84 dev->driver ? "loaded" : "empty",
85 dev->driver ? 1 : 0);
86 return 0;
87}
105 88
106#ifdef CONFIG_PROC_FS
107static void snd_seq_device_info(struct snd_info_entry *entry, 89static void snd_seq_device_info(struct snd_info_entry *entry,
108 struct snd_info_buffer *buffer) 90 struct snd_info_buffer *buffer)
109{ 91{
110 struct ops_list *ops; 92 bus_for_each_dev(&snd_seq_bus_type, NULL, buffer, print_dev_info);
111
112 mutex_lock(&ops_mutex);
113 list_for_each_entry(ops, &opslist, list) {
114 snd_iprintf(buffer, "snd-%s%s%s%s,%d\n",
115 ops->id,
116 ops->driver & DRIVER_LOADED ? ",loaded" : (ops->driver == DRIVER_EMPTY ? ",empty" : ""),
117 ops->driver & DRIVER_REQUESTED ? ",requested" : "",
118 ops->driver & DRIVER_LOCKED ? ",locked" : "",
119 ops->num_devices);
120 }
121 mutex_unlock(&ops_mutex);
122} 93}
123#endif 94#endif
124 95
125/* 96/*
126 * load all registered drivers (called from seq_clientmgr.c) 97 * load all registered drivers (called from seq_clientmgr.c)
127 */ 98 */
128 99
129#ifdef CONFIG_MODULES 100#ifdef CONFIG_MODULES
130/* avoid auto-loading during module_init() */ 101/* flag to block auto-loading */
131static atomic_t snd_seq_in_init = ATOMIC_INIT(1); /* blocked as default */ 102static atomic_t snd_seq_in_init = ATOMIC_INIT(1); /* blocked as default */
132void snd_seq_autoload_lock(void)
133{
134 atomic_inc(&snd_seq_in_init);
135}
136 103
137void snd_seq_autoload_unlock(void) 104static int request_seq_drv(struct device *dev, void *data)
138{ 105{
139 atomic_dec(&snd_seq_in_init); 106 struct snd_seq_device *sdev = to_seq_dev(dev);
107
108 if (!dev->driver)
109 request_module("snd-%s", sdev->id);
110 return 0;
140} 111}
141 112
142static void autoload_drivers(void) 113static void autoload_drivers(struct work_struct *work)
143{ 114{
144 /* avoid reentrance */ 115 /* avoid reentrance */
145 if (atomic_inc_return(&snd_seq_in_init) == 1) { 116 if (atomic_inc_return(&snd_seq_in_init) == 1)
146 struct ops_list *ops; 117 bus_for_each_dev(&snd_seq_bus_type, NULL, NULL,
147 118 request_seq_drv);
148 mutex_lock(&ops_mutex);
149 list_for_each_entry(ops, &opslist, list) {
150 if ((ops->driver & DRIVER_REQUESTING) &&
151 !(ops->driver & DRIVER_REQUESTED)) {
152 ops->used++;
153 mutex_unlock(&ops_mutex);
154 ops->driver |= DRIVER_REQUESTED;
155 request_module("snd-%s", ops->id);
156 mutex_lock(&ops_mutex);
157 ops->used--;
158 }
159 }
160 mutex_unlock(&ops_mutex);
161 }
162 atomic_dec(&snd_seq_in_init); 119 atomic_dec(&snd_seq_in_init);
163} 120}
164 121
165static void call_autoload(struct work_struct *work) 122static DECLARE_WORK(autoload_work, autoload_drivers);
166{
167 autoload_drivers();
168}
169
170static DECLARE_WORK(autoload_work, call_autoload);
171
172static void try_autoload(struct ops_list *ops)
173{
174 if (!ops->driver) {
175 ops->driver |= DRIVER_REQUESTING;
176 schedule_work(&autoload_work);
177 }
178}
179 123
180static void queue_autoload_drivers(void) 124static void queue_autoload_drivers(void)
181{ 125{
182 struct ops_list *ops; 126 schedule_work(&autoload_work);
183
184 mutex_lock(&ops_mutex);
185 list_for_each_entry(ops, &opslist, list)
186 try_autoload(ops);
187 mutex_unlock(&ops_mutex);
188} 127}
189 128
190void snd_seq_autoload_init(void) 129void snd_seq_autoload_init(void)
@@ -195,384 +134,143 @@ void snd_seq_autoload_init(void)
195 queue_autoload_drivers(); 134 queue_autoload_drivers();
196#endif 135#endif
197} 136}
198#else 137EXPORT_SYMBOL(snd_seq_autoload_init);
199#define try_autoload(ops) /* NOP */
200#endif
201 138
202void snd_seq_device_load_drivers(void) 139void snd_seq_autoload_exit(void)
203{ 140{
204#ifdef CONFIG_MODULES 141 atomic_inc(&snd_seq_in_init);
205 queue_autoload_drivers();
206 flush_work(&autoload_work);
207#endif
208} 142}
143EXPORT_SYMBOL(snd_seq_autoload_exit);
209 144
210/* 145void snd_seq_device_load_drivers(void)
211 * register a sequencer device
212 * card = card info
213 * device = device number (if any)
214 * id = id of driver
215 * result = return pointer (NULL allowed if unnecessary)
216 */
217int snd_seq_device_new(struct snd_card *card, int device, char *id, int argsize,
218 struct snd_seq_device **result)
219{ 146{
220 struct snd_seq_device *dev; 147 queue_autoload_drivers();
221 struct ops_list *ops; 148 flush_work(&autoload_work);
222 int err;
223 static struct snd_device_ops dops = {
224 .dev_free = snd_seq_device_dev_free,
225 .dev_register = snd_seq_device_dev_register,
226 .dev_disconnect = snd_seq_device_dev_disconnect,
227 };
228
229 if (result)
230 *result = NULL;
231
232 if (snd_BUG_ON(!id))
233 return -EINVAL;
234
235 ops = find_driver(id, 1);
236 if (ops == NULL)
237 return -ENOMEM;
238
239 dev = kzalloc(sizeof(*dev)*2 + argsize, GFP_KERNEL);
240 if (dev == NULL) {
241 unlock_driver(ops);
242 return -ENOMEM;
243 }
244
245 /* set up device info */
246 dev->card = card;
247 dev->device = device;
248 strlcpy(dev->id, id, sizeof(dev->id));
249 dev->argsize = argsize;
250 dev->status = SNDRV_SEQ_DEVICE_FREE;
251
252 /* add this device to the list */
253 mutex_lock(&ops->reg_mutex);
254 list_add_tail(&dev->list, &ops->dev_list);
255 ops->num_devices++;
256 mutex_unlock(&ops->reg_mutex);
257
258 if ((err = snd_device_new(card, SNDRV_DEV_SEQUENCER, dev, &dops)) < 0) {
259 snd_seq_device_free(dev);
260 return err;
261 }
262
263 try_autoload(ops);
264 unlock_driver(ops);
265
266 if (result)
267 *result = dev;
268
269 return 0;
270} 149}
150EXPORT_SYMBOL(snd_seq_device_load_drivers);
151#else
152#define queue_autoload_drivers() /* NOP */
153#endif
271 154
272/* 155/*
273 * free the existing device 156 * device management
274 */ 157 */
275static int snd_seq_device_free(struct snd_seq_device *dev)
276{
277 struct ops_list *ops;
278
279 if (snd_BUG_ON(!dev))
280 return -EINVAL;
281
282 ops = find_driver(dev->id, 0);
283 if (ops == NULL)
284 return -ENXIO;
285
286 /* remove the device from the list */
287 mutex_lock(&ops->reg_mutex);
288 list_del(&dev->list);
289 ops->num_devices--;
290 mutex_unlock(&ops->reg_mutex);
291
292 free_device(dev, ops);
293 if (dev->private_free)
294 dev->private_free(dev);
295 kfree(dev);
296
297 unlock_driver(ops);
298
299 return 0;
300}
301
302static int snd_seq_device_dev_free(struct snd_device *device) 158static int snd_seq_device_dev_free(struct snd_device *device)
303{ 159{
304 struct snd_seq_device *dev = device->device_data; 160 struct snd_seq_device *dev = device->device_data;
305 return snd_seq_device_free(dev); 161
162 put_device(&dev->dev);
163 return 0;
306} 164}
307 165
308/*
309 * register the device
310 */
311static int snd_seq_device_dev_register(struct snd_device *device) 166static int snd_seq_device_dev_register(struct snd_device *device)
312{ 167{
313 struct snd_seq_device *dev = device->device_data; 168 struct snd_seq_device *dev = device->device_data;
314 struct ops_list *ops; 169 int err;
315
316 ops = find_driver(dev->id, 0);
317 if (ops == NULL)
318 return -ENOENT;
319
320 /* initialize this device if the corresponding driver was
321 * already loaded
322 */
323 if (ops->driver & DRIVER_LOADED)
324 init_device(dev, ops);
325 170
326 unlock_driver(ops); 171 err = device_add(&dev->dev);
172 if (err < 0)
173 return err;
174 if (!dev->dev.driver)
175 queue_autoload_drivers();
327 return 0; 176 return 0;
328} 177}
329 178
330/*
331 * disconnect the device
332 */
333static int snd_seq_device_dev_disconnect(struct snd_device *device) 179static int snd_seq_device_dev_disconnect(struct snd_device *device)
334{ 180{
335 struct snd_seq_device *dev = device->device_data; 181 struct snd_seq_device *dev = device->device_data;
336 struct ops_list *ops;
337
338 ops = find_driver(dev->id, 0);
339 if (ops == NULL)
340 return -ENOENT;
341
342 free_device(dev, ops);
343 182
344 unlock_driver(ops); 183 device_del(&dev->dev);
345 return 0; 184 return 0;
346} 185}
347 186
348/* 187static void snd_seq_dev_release(struct device *dev)
349 * register device driver
350 * id = driver id
351 * entry = driver operators - duplicated to each instance
352 */
353int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
354 int argsize)
355{ 188{
356 struct ops_list *ops; 189 struct snd_seq_device *sdev = to_seq_dev(dev);
357 struct snd_seq_device *dev;
358 190
359 if (id == NULL || entry == NULL || 191 if (sdev->private_free)
360 entry->init_device == NULL || entry->free_device == NULL) 192 sdev->private_free(sdev);
361 return -EINVAL; 193 kfree(sdev);
362
363 ops = find_driver(id, 1);
364 if (ops == NULL)
365 return -ENOMEM;
366 if (ops->driver & DRIVER_LOADED) {
367 pr_warn("ALSA: seq: driver_register: driver '%s' already exists\n", id);
368 unlock_driver(ops);
369 return -EBUSY;
370 }
371
372 mutex_lock(&ops->reg_mutex);
373 /* copy driver operators */
374 ops->ops = *entry;
375 ops->driver |= DRIVER_LOADED;
376 ops->argsize = argsize;
377
378 /* initialize existing devices if necessary */
379 list_for_each_entry(dev, &ops->dev_list, list) {
380 init_device(dev, ops);
381 }
382 mutex_unlock(&ops->reg_mutex);
383
384 unlock_driver(ops);
385
386 return 0;
387} 194}
388 195
389
390/*
391 * create driver record
392 */
393static struct ops_list * create_driver(char *id)
394{
395 struct ops_list *ops;
396
397 ops = kzalloc(sizeof(*ops), GFP_KERNEL);
398 if (ops == NULL)
399 return ops;
400
401 /* set up driver entry */
402 strlcpy(ops->id, id, sizeof(ops->id));
403 mutex_init(&ops->reg_mutex);
404 /*
405 * The ->reg_mutex locking rules are per-driver, so we create
406 * separate per-driver lock classes:
407 */
408 lockdep_set_class(&ops->reg_mutex, (struct lock_class_key *)id);
409
410 ops->driver = DRIVER_EMPTY;
411 INIT_LIST_HEAD(&ops->dev_list);
412 /* lock this instance */
413 ops->used = 1;
414
415 /* register driver entry */
416 mutex_lock(&ops_mutex);
417 list_add_tail(&ops->list, &opslist);
418 num_ops++;
419 mutex_unlock(&ops_mutex);
420
421 return ops;
422}
423
424
425/* 196/*
426 * unregister the specified driver 197 * register a sequencer device
198 * card = card info
199 * device = device number (if any)
200 * id = id of driver
201 * result = return pointer (NULL allowed if unnecessary)
427 */ 202 */
428int snd_seq_device_unregister_driver(char *id) 203int snd_seq_device_new(struct snd_card *card, int device, const char *id,
204 int argsize, struct snd_seq_device **result)
429{ 205{
430 struct ops_list *ops;
431 struct snd_seq_device *dev; 206 struct snd_seq_device *dev;
207 int err;
208 static struct snd_device_ops dops = {
209 .dev_free = snd_seq_device_dev_free,
210 .dev_register = snd_seq_device_dev_register,
211 .dev_disconnect = snd_seq_device_dev_disconnect,
212 };
432 213
433 ops = find_driver(id, 0); 214 if (result)
434 if (ops == NULL) 215 *result = NULL;
435 return -ENXIO;
436 if (! (ops->driver & DRIVER_LOADED) ||
437 (ops->driver & DRIVER_LOCKED)) {
438 pr_err("ALSA: seq: driver_unregister: cannot unload driver '%s': status=%x\n",
439 id, ops->driver);
440 unlock_driver(ops);
441 return -EBUSY;
442 }
443
444 /* close and release all devices associated with this driver */
445 mutex_lock(&ops->reg_mutex);
446 ops->driver |= DRIVER_LOCKED; /* do not remove this driver recursively */
447 list_for_each_entry(dev, &ops->dev_list, list) {
448 free_device(dev, ops);
449 }
450
451 ops->driver = 0;
452 if (ops->num_init_devices > 0)
453 pr_err("ALSA: seq: free_driver: init_devices > 0!! (%d)\n",
454 ops->num_init_devices);
455 mutex_unlock(&ops->reg_mutex);
456
457 unlock_driver(ops);
458 216
459 /* remove empty driver entries */ 217 if (snd_BUG_ON(!id))
460 remove_drivers(); 218 return -EINVAL;
461 219
462 return 0; 220 dev = kzalloc(sizeof(*dev) + argsize, GFP_KERNEL);
463} 221 if (!dev)
222 return -ENOMEM;
464 223
224 /* set up device info */
225 dev->card = card;
226 dev->device = device;
227 dev->id = id;
228 dev->argsize = argsize;
465 229
466/* 230 device_initialize(&dev->dev);
467 * remove empty driver entries 231 dev->dev.parent = &card->card_dev;
468 */ 232 dev->dev.bus = &snd_seq_bus_type;
469static void remove_drivers(void) 233 dev->dev.release = snd_seq_dev_release;
470{ 234 dev_set_name(&dev->dev, "%s-%d-%d", dev->id, card->number, device);
471 struct list_head *head;
472
473 mutex_lock(&ops_mutex);
474 head = opslist.next;
475 while (head != &opslist) {
476 struct ops_list *ops = list_entry(head, struct ops_list, list);
477 if (! (ops->driver & DRIVER_LOADED) &&
478 ops->used == 0 && ops->num_devices == 0) {
479 head = head->next;
480 list_del(&ops->list);
481 kfree(ops);
482 num_ops--;
483 } else
484 head = head->next;
485 }
486 mutex_unlock(&ops_mutex);
487}
488 235
489/* 236 /* add this device to the list */
490 * initialize the device - call init_device operator 237 err = snd_device_new(card, SNDRV_DEV_SEQUENCER, dev, &dops);
491 */ 238 if (err < 0) {
492static int init_device(struct snd_seq_device *dev, struct ops_list *ops) 239 put_device(&dev->dev);
493{ 240 return err;
494 if (! (ops->driver & DRIVER_LOADED))
495 return 0; /* driver is not loaded yet */
496 if (dev->status != SNDRV_SEQ_DEVICE_FREE)
497 return 0; /* already initialized */
498 if (ops->argsize != dev->argsize) {
499 pr_err("ALSA: seq: incompatible device '%s' for plug-in '%s' (%d %d)\n",
500 dev->name, ops->id, ops->argsize, dev->argsize);
501 return -EINVAL;
502 }
503 if (ops->ops.init_device(dev) >= 0) {
504 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
505 ops->num_init_devices++;
506 } else {
507 pr_err("ALSA: seq: init_device failed: %s: %s\n",
508 dev->name, dev->id);
509 } 241 }
242
243 if (result)
244 *result = dev;
510 245
511 return 0; 246 return 0;
512} 247}
248EXPORT_SYMBOL(snd_seq_device_new);
513 249
514/* 250/*
515 * release the device - call free_device operator 251 * driver registration
516 */ 252 */
517static int free_device(struct snd_seq_device *dev, struct ops_list *ops) 253int __snd_seq_driver_register(struct snd_seq_driver *drv, struct module *mod)
518{ 254{
519 int result; 255 if (WARN_ON(!drv->driver.name || !drv->id))
520
521 if (! (ops->driver & DRIVER_LOADED))
522 return 0; /* driver is not loaded yet */
523 if (dev->status != SNDRV_SEQ_DEVICE_REGISTERED)
524 return 0; /* not registered */
525 if (ops->argsize != dev->argsize) {
526 pr_err("ALSA: seq: incompatible device '%s' for plug-in '%s' (%d %d)\n",
527 dev->name, ops->id, ops->argsize, dev->argsize);
528 return -EINVAL; 256 return -EINVAL;
529 } 257 drv->driver.bus = &snd_seq_bus_type;
530 if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) { 258 drv->driver.owner = mod;
531 dev->status = SNDRV_SEQ_DEVICE_FREE; 259 return driver_register(&drv->driver);
532 dev->driver_data = NULL;
533 ops->num_init_devices--;
534 } else {
535 pr_err("ALSA: seq: free_device failed: %s: %s\n",
536 dev->name, dev->id);
537 }
538
539 return 0;
540} 260}
261EXPORT_SYMBOL_GPL(__snd_seq_driver_register);
541 262
542/* 263void snd_seq_driver_unregister(struct snd_seq_driver *drv)
543 * find the matching driver with given id
544 */
545static struct ops_list * find_driver(char *id, int create_if_empty)
546{ 264{
547 struct ops_list *ops; 265 driver_unregister(&drv->driver);
548
549 mutex_lock(&ops_mutex);
550 list_for_each_entry(ops, &opslist, list) {
551 if (strcmp(ops->id, id) == 0) {
552 ops->used++;
553 mutex_unlock(&ops_mutex);
554 return ops;
555 }
556 }
557 mutex_unlock(&ops_mutex);
558 if (create_if_empty)
559 return create_driver(id);
560 return NULL;
561} 266}
562 267EXPORT_SYMBOL_GPL(snd_seq_driver_unregister);
563static void unlock_driver(struct ops_list *ops)
564{
565 mutex_lock(&ops_mutex);
566 ops->used--;
567 mutex_unlock(&ops_mutex);
568}
569
570 268
571/* 269/*
572 * module part 270 * module part
573 */ 271 */
574 272
575static int __init alsa_seq_device_init(void) 273static int __init seq_dev_proc_init(void)
576{ 274{
577#ifdef CONFIG_PROC_FS 275#ifdef CONFIG_PROC_FS
578 info_entry = snd_info_create_module_entry(THIS_MODULE, "drivers", 276 info_entry = snd_info_create_module_entry(THIS_MODULE, "drivers",
@@ -589,28 +287,29 @@ static int __init alsa_seq_device_init(void)
589 return 0; 287 return 0;
590} 288}
591 289
290static int __init alsa_seq_device_init(void)
291{
292 int err;
293
294 err = bus_register(&snd_seq_bus_type);
295 if (err < 0)
296 return err;
297 err = seq_dev_proc_init();
298 if (err < 0)
299 bus_unregister(&snd_seq_bus_type);
300 return err;
301}
302
592static void __exit alsa_seq_device_exit(void) 303static void __exit alsa_seq_device_exit(void)
593{ 304{
594#ifdef CONFIG_MODULES 305#ifdef CONFIG_MODULES
595 cancel_work_sync(&autoload_work); 306 cancel_work_sync(&autoload_work);
596#endif 307#endif
597 remove_drivers();
598#ifdef CONFIG_PROC_FS 308#ifdef CONFIG_PROC_FS
599 snd_info_free_entry(info_entry); 309 snd_info_free_entry(info_entry);
600#endif 310#endif
601 if (num_ops) 311 bus_unregister(&snd_seq_bus_type);
602 pr_err("ALSA: seq: drivers not released (%d)\n", num_ops);
603} 312}
604 313
605module_init(alsa_seq_device_init) 314subsys_initcall(alsa_seq_device_init)
606module_exit(alsa_seq_device_exit) 315module_exit(alsa_seq_device_exit)
607
608EXPORT_SYMBOL(snd_seq_device_load_drivers);
609EXPORT_SYMBOL(snd_seq_device_new);
610EXPORT_SYMBOL(snd_seq_device_register_driver);
611EXPORT_SYMBOL(snd_seq_device_unregister_driver);
612#ifdef CONFIG_MODULES
613EXPORT_SYMBOL(snd_seq_autoload_init);
614EXPORT_SYMBOL(snd_seq_autoload_lock);
615EXPORT_SYMBOL(snd_seq_autoload_unlock);
616#endif
diff --git a/sound/core/seq/seq_dummy.c b/sound/core/seq/seq_dummy.c
index 5d905d90d504..d3a2ec4f0561 100644
--- a/sound/core/seq/seq_dummy.c
+++ b/sound/core/seq/seq_dummy.c
@@ -214,11 +214,7 @@ delete_client(void)
214 214
215static int __init alsa_seq_dummy_init(void) 215static int __init alsa_seq_dummy_init(void)
216{ 216{
217 int err; 217 return register_client();
218 snd_seq_autoload_lock();
219 err = register_client();
220 snd_seq_autoload_unlock();
221 return err;
222} 218}
223 219
224static void __exit alsa_seq_dummy_exit(void) 220static void __exit alsa_seq_dummy_exit(void)
diff --git a/sound/core/seq/seq_fifo.c b/sound/core/seq/seq_fifo.c
index 53a403e17c5b..1d5acbe0c08b 100644
--- a/sound/core/seq/seq_fifo.c
+++ b/sound/core/seq/seq_fifo.c
@@ -33,10 +33,8 @@ struct snd_seq_fifo *snd_seq_fifo_new(int poolsize)
33 struct snd_seq_fifo *f; 33 struct snd_seq_fifo *f;
34 34
35 f = kzalloc(sizeof(*f), GFP_KERNEL); 35 f = kzalloc(sizeof(*f), GFP_KERNEL);
36 if (f == NULL) { 36 if (!f)
37 pr_debug("ALSA: seq: malloc failed for snd_seq_fifo_new() \n");
38 return NULL; 37 return NULL;
39 }
40 38
41 f->pool = snd_seq_pool_new(poolsize); 39 f->pool = snd_seq_pool_new(poolsize);
42 if (f->pool == NULL) { 40 if (f->pool == NULL) {
diff --git a/sound/core/seq/seq_memory.c b/sound/core/seq/seq_memory.c
index ba8e4a64e13e..801076687bb1 100644
--- a/sound/core/seq/seq_memory.c
+++ b/sound/core/seq/seq_memory.c
@@ -387,10 +387,8 @@ int snd_seq_pool_init(struct snd_seq_pool *pool)
387 return 0; 387 return 0;
388 388
389 pool->ptr = vmalloc(sizeof(struct snd_seq_event_cell) * pool->size); 389 pool->ptr = vmalloc(sizeof(struct snd_seq_event_cell) * pool->size);
390 if (pool->ptr == NULL) { 390 if (!pool->ptr)
391 pr_debug("ALSA: seq: malloc for sequencer events failed\n");
392 return -ENOMEM; 391 return -ENOMEM;
393 }
394 392
395 /* add new cells to the free cell list */ 393 /* add new cells to the free cell list */
396 spin_lock_irqsave(&pool->lock, flags); 394 spin_lock_irqsave(&pool->lock, flags);
@@ -463,10 +461,8 @@ struct snd_seq_pool *snd_seq_pool_new(int poolsize)
463 461
464 /* create pool block */ 462 /* create pool block */
465 pool = kzalloc(sizeof(*pool), GFP_KERNEL); 463 pool = kzalloc(sizeof(*pool), GFP_KERNEL);
466 if (pool == NULL) { 464 if (!pool)
467 pr_debug("ALSA: seq: malloc failed for pool\n");
468 return NULL; 465 return NULL;
469 }
470 spin_lock_init(&pool->lock); 466 spin_lock_init(&pool->lock);
471 pool->ptr = NULL; 467 pool->ptr = NULL;
472 pool->free = NULL; 468 pool->free = NULL;
diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
index 68fec776da26..5dd0ee258359 100644
--- a/sound/core/seq/seq_midi.c
+++ b/sound/core/seq/seq_midi.c
@@ -273,8 +273,9 @@ static void snd_seq_midisynth_delete(struct seq_midisynth *msynth)
273 273
274/* register new midi synth port */ 274/* register new midi synth port */
275static int 275static int
276snd_seq_midisynth_register_port(struct snd_seq_device *dev) 276snd_seq_midisynth_probe(struct device *_dev)
277{ 277{
278 struct snd_seq_device *dev = to_seq_dev(_dev);
278 struct seq_midisynth_client *client; 279 struct seq_midisynth_client *client;
279 struct seq_midisynth *msynth, *ms; 280 struct seq_midisynth *msynth, *ms;
280 struct snd_seq_port_info *port; 281 struct snd_seq_port_info *port;
@@ -427,8 +428,9 @@ snd_seq_midisynth_register_port(struct snd_seq_device *dev)
427 428
428/* release midi synth port */ 429/* release midi synth port */
429static int 430static int
430snd_seq_midisynth_unregister_port(struct snd_seq_device *dev) 431snd_seq_midisynth_remove(struct device *_dev)
431{ 432{
433 struct snd_seq_device *dev = to_seq_dev(_dev);
432 struct seq_midisynth_client *client; 434 struct seq_midisynth_client *client;
433 struct seq_midisynth *msynth; 435 struct seq_midisynth *msynth;
434 struct snd_card *card = dev->card; 436 struct snd_card *card = dev->card;
@@ -457,24 +459,14 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
457 return 0; 459 return 0;
458} 460}
459 461
462static struct snd_seq_driver seq_midisynth_driver = {
463 .driver = {
464 .name = KBUILD_MODNAME,
465 .probe = snd_seq_midisynth_probe,
466 .remove = snd_seq_midisynth_remove,
467 },
468 .id = SNDRV_SEQ_DEV_ID_MIDISYNTH,
469 .argsize = 0,
470};
460 471
461static int __init alsa_seq_midi_init(void) 472module_snd_seq_driver(seq_midisynth_driver);
462{
463 static struct snd_seq_dev_ops ops = {
464 snd_seq_midisynth_register_port,
465 snd_seq_midisynth_unregister_port,
466 };
467 memset(&synths, 0, sizeof(synths));
468 snd_seq_autoload_lock();
469 snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_MIDISYNTH, &ops, 0);
470 snd_seq_autoload_unlock();
471 return 0;
472}
473
474static void __exit alsa_seq_midi_exit(void)
475{
476 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_MIDISYNTH);
477}
478
479module_init(alsa_seq_midi_init)
480module_exit(alsa_seq_midi_exit)
diff --git a/sound/core/seq/seq_ports.c b/sound/core/seq/seq_ports.c
index 46ff593f618d..55170a20ae72 100644
--- a/sound/core/seq/seq_ports.c
+++ b/sound/core/seq/seq_ports.c
@@ -141,10 +141,8 @@ struct snd_seq_client_port *snd_seq_create_port(struct snd_seq_client *client,
141 141
142 /* create a new port */ 142 /* create a new port */
143 new_port = kzalloc(sizeof(*new_port), GFP_KERNEL); 143 new_port = kzalloc(sizeof(*new_port), GFP_KERNEL);
144 if (! new_port) { 144 if (!new_port)
145 pr_debug("ALSA: seq: malloc failed for registering client port\n");
146 return NULL; /* failure, out of memory */ 145 return NULL; /* failure, out of memory */
147 }
148 /* init port data */ 146 /* init port data */
149 new_port->addr.client = client->number; 147 new_port->addr.client = client->number;
150 new_port->addr.port = -1; 148 new_port->addr.port = -1;
diff --git a/sound/core/seq/seq_prioq.c b/sound/core/seq/seq_prioq.c
index 021b02bc9330..bc1c8488fc2a 100644
--- a/sound/core/seq/seq_prioq.c
+++ b/sound/core/seq/seq_prioq.c
@@ -59,10 +59,8 @@ struct snd_seq_prioq *snd_seq_prioq_new(void)
59 struct snd_seq_prioq *f; 59 struct snd_seq_prioq *f;
60 60
61 f = kzalloc(sizeof(*f), GFP_KERNEL); 61 f = kzalloc(sizeof(*f), GFP_KERNEL);
62 if (f == NULL) { 62 if (!f)
63 pr_debug("ALSA: seq: malloc failed for snd_seq_prioq_new()\n");
64 return NULL; 63 return NULL;
65 }
66 64
67 spin_lock_init(&f->lock); 65 spin_lock_init(&f->lock);
68 f->head = NULL; 66 f->head = NULL;
diff --git a/sound/core/seq/seq_queue.c b/sound/core/seq/seq_queue.c
index aad4878cee55..a0cda38205b9 100644
--- a/sound/core/seq/seq_queue.c
+++ b/sound/core/seq/seq_queue.c
@@ -111,10 +111,8 @@ static struct snd_seq_queue *queue_new(int owner, int locked)
111 struct snd_seq_queue *q; 111 struct snd_seq_queue *q;
112 112
113 q = kzalloc(sizeof(*q), GFP_KERNEL); 113 q = kzalloc(sizeof(*q), GFP_KERNEL);
114 if (q == NULL) { 114 if (!q)
115 pr_debug("ALSA: seq: malloc failed for snd_seq_queue_new()\n");
116 return NULL; 115 return NULL;
117 }
118 116
119 spin_lock_init(&q->owner_lock); 117 spin_lock_init(&q->owner_lock);
120 spin_lock_init(&q->check_lock); 118 spin_lock_init(&q->check_lock);
diff --git a/sound/core/seq/seq_timer.c b/sound/core/seq/seq_timer.c
index e73605393eee..186f1611103c 100644
--- a/sound/core/seq/seq_timer.c
+++ b/sound/core/seq/seq_timer.c
@@ -56,10 +56,8 @@ struct snd_seq_timer *snd_seq_timer_new(void)
56 struct snd_seq_timer *tmr; 56 struct snd_seq_timer *tmr;
57 57
58 tmr = kzalloc(sizeof(*tmr), GFP_KERNEL); 58 tmr = kzalloc(sizeof(*tmr), GFP_KERNEL);
59 if (tmr == NULL) { 59 if (!tmr)
60 pr_debug("ALSA: seq: malloc failed for snd_seq_timer_new() \n");
61 return NULL; 60 return NULL;
62 }
63 spin_lock_init(&tmr->lock); 61 spin_lock_init(&tmr->lock);
64 62
65 /* reset setup to defaults */ 63 /* reset setup to defaults */
diff --git a/sound/core/sound.c b/sound/core/sound.c
index 185cec01ee25..5fc93d00572a 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -186,7 +186,7 @@ static const struct file_operations snd_fops =
186}; 186};
187 187
188#ifdef CONFIG_SND_DYNAMIC_MINORS 188#ifdef CONFIG_SND_DYNAMIC_MINORS
189static int snd_find_free_minor(int type) 189static int snd_find_free_minor(int type, struct snd_card *card, int dev)
190{ 190{
191 int minor; 191 int minor;
192 192
@@ -209,7 +209,7 @@ static int snd_find_free_minor(int type)
209 return -EBUSY; 209 return -EBUSY;
210} 210}
211#else 211#else
212static int snd_kernel_minor(int type, struct snd_card *card, int dev) 212static int snd_find_free_minor(int type, struct snd_card *card, int dev)
213{ 213{
214 int minor; 214 int minor;
215 215
@@ -237,6 +237,8 @@ static int snd_kernel_minor(int type, struct snd_card *card, int dev)
237 } 237 }
238 if (snd_BUG_ON(minor < 0 || minor >= SNDRV_OS_MINORS)) 238 if (snd_BUG_ON(minor < 0 || minor >= SNDRV_OS_MINORS))
239 return -EINVAL; 239 return -EINVAL;
240 if (snd_minors[minor])
241 return -EBUSY;
240 return minor; 242 return minor;
241} 243}
242#endif 244#endif
@@ -276,13 +278,7 @@ int snd_register_device(int type, struct snd_card *card, int dev,
276 preg->private_data = private_data; 278 preg->private_data = private_data;
277 preg->card_ptr = card; 279 preg->card_ptr = card;
278 mutex_lock(&sound_mutex); 280 mutex_lock(&sound_mutex);
279#ifdef CONFIG_SND_DYNAMIC_MINORS 281 minor = snd_find_free_minor(type, card, dev);
280 minor = snd_find_free_minor(type);
281#else
282 minor = snd_kernel_minor(type, card, dev);
283 if (minor >= 0 && snd_minors[minor])
284 minor = -EBUSY;
285#endif
286 if (minor < 0) { 282 if (minor < 0) {
287 err = minor; 283 err = minor;
288 goto error; 284 goto error;
diff --git a/sound/core/timer.c b/sound/core/timer.c
index 490b489d713d..a9a1a047c521 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -774,10 +774,8 @@ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid,
774 if (rtimer) 774 if (rtimer)
775 *rtimer = NULL; 775 *rtimer = NULL;
776 timer = kzalloc(sizeof(*timer), GFP_KERNEL); 776 timer = kzalloc(sizeof(*timer), GFP_KERNEL);
777 if (timer == NULL) { 777 if (!timer)
778 pr_err("ALSA: timer: cannot allocate\n");
779 return -ENOMEM; 778 return -ENOMEM;
780 }
781 timer->tmr_class = tid->dev_class; 779 timer->tmr_class = tid->dev_class;
782 timer->card = card; 780 timer->card = card;
783 timer->tmr_device = tid->device; 781 timer->tmr_device = tid->device;
diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
index a9f618e06a22..fdae5d7f421f 100644
--- a/sound/drivers/opl3/opl3_seq.c
+++ b/sound/drivers/opl3/opl3_seq.c
@@ -216,8 +216,9 @@ static int snd_opl3_synth_create_port(struct snd_opl3 * opl3)
216 216
217/* ------------------------------ */ 217/* ------------------------------ */
218 218
219static int snd_opl3_seq_new_device(struct snd_seq_device *dev) 219static int snd_opl3_seq_probe(struct device *_dev)
220{ 220{
221 struct snd_seq_device *dev = to_seq_dev(_dev);
221 struct snd_opl3 *opl3; 222 struct snd_opl3 *opl3;
222 int client, err; 223 int client, err;
223 char name[32]; 224 char name[32];
@@ -257,8 +258,9 @@ static int snd_opl3_seq_new_device(struct snd_seq_device *dev)
257 return 0; 258 return 0;
258} 259}
259 260
260static int snd_opl3_seq_delete_device(struct snd_seq_device *dev) 261static int snd_opl3_seq_remove(struct device *_dev)
261{ 262{
263 struct snd_seq_device *dev = to_seq_dev(_dev);
262 struct snd_opl3 *opl3; 264 struct snd_opl3 *opl3;
263 265
264 opl3 = *(struct snd_opl3 **)SNDRV_SEQ_DEVICE_ARGPTR(dev); 266 opl3 = *(struct snd_opl3 **)SNDRV_SEQ_DEVICE_ARGPTR(dev);
@@ -275,22 +277,14 @@ static int snd_opl3_seq_delete_device(struct snd_seq_device *dev)
275 return 0; 277 return 0;
276} 278}
277 279
278static int __init alsa_opl3_seq_init(void) 280static struct snd_seq_driver opl3_seq_driver = {
279{ 281 .driver = {
280 static struct snd_seq_dev_ops ops = 282 .name = KBUILD_MODNAME,
281 { 283 .probe = snd_opl3_seq_probe,
282 snd_opl3_seq_new_device, 284 .remove = snd_opl3_seq_remove,
283 snd_opl3_seq_delete_device 285 },
284 }; 286 .id = SNDRV_SEQ_DEV_ID_OPL3,
285 287 .argsize = sizeof(struct snd_opl3 *),
286 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops, 288};
287 sizeof(struct snd_opl3 *));
288}
289
290static void __exit alsa_opl3_seq_exit(void)
291{
292 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_OPL3);
293}
294 289
295module_init(alsa_opl3_seq_init) 290module_snd_seq_driver(opl3_seq_driver);
296module_exit(alsa_opl3_seq_exit)
diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
index 99197699c55a..03d6202f4829 100644
--- a/sound/drivers/opl4/opl4_seq.c
+++ b/sound/drivers/opl4/opl4_seq.c
@@ -124,8 +124,9 @@ static void snd_opl4_seq_free_port(void *private_data)
124 snd_midi_channel_free_set(opl4->chset); 124 snd_midi_channel_free_set(opl4->chset);
125} 125}
126 126
127static int snd_opl4_seq_new_device(struct snd_seq_device *dev) 127static int snd_opl4_seq_probe(struct device *_dev)
128{ 128{
129 struct snd_seq_device *dev = to_seq_dev(_dev);
129 struct snd_opl4 *opl4; 130 struct snd_opl4 *opl4;
130 int client; 131 int client;
131 struct snd_seq_port_callback pcallbacks; 132 struct snd_seq_port_callback pcallbacks;
@@ -180,8 +181,9 @@ static int snd_opl4_seq_new_device(struct snd_seq_device *dev)
180 return 0; 181 return 0;
181} 182}
182 183
183static int snd_opl4_seq_delete_device(struct snd_seq_device *dev) 184static int snd_opl4_seq_remove(struct device *_dev)
184{ 185{
186 struct snd_seq_device *dev = to_seq_dev(_dev);
185 struct snd_opl4 *opl4; 187 struct snd_opl4 *opl4;
186 188
187 opl4 = *(struct snd_opl4 **)SNDRV_SEQ_DEVICE_ARGPTR(dev); 189 opl4 = *(struct snd_opl4 **)SNDRV_SEQ_DEVICE_ARGPTR(dev);
@@ -195,21 +197,14 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
195 return 0; 197 return 0;
196} 198}
197 199
198static int __init alsa_opl4_synth_init(void) 200static struct snd_seq_driver opl4_seq_driver = {
199{ 201 .driver = {
200 static struct snd_seq_dev_ops ops = { 202 .name = KBUILD_MODNAME,
201 snd_opl4_seq_new_device, 203 .probe = snd_opl4_seq_probe,
202 snd_opl4_seq_delete_device 204 .remove = snd_opl4_seq_remove,
203 }; 205 },
204 206 .id = SNDRV_SEQ_DEV_ID_OPL4,
205 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops, 207 .argsize = sizeof(struct snd_opl4 *),
206 sizeof(struct snd_opl4 *)); 208};
207}
208
209static void __exit alsa_opl4_synth_exit(void)
210{
211 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_OPL4);
212}
213 209
214module_init(alsa_opl4_synth_init) 210module_snd_seq_driver(opl4_seq_driver);
215module_exit(alsa_opl4_synth_exit)
diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
index 5cc356db5351..e061355f535f 100644
--- a/sound/firewire/amdtp.c
+++ b/sound/firewire/amdtp.c
@@ -166,10 +166,10 @@ int amdtp_stream_add_pcm_hw_constraints(struct amdtp_stream *s,
166 * One AMDTP packet can include some frames. In blocking mode, the 166 * One AMDTP packet can include some frames. In blocking mode, the
167 * number equals to SYT_INTERVAL. So the number is 8, 16 or 32, 167 * number equals to SYT_INTERVAL. So the number is 8, 16 or 32,
168 * depending on its sampling rate. For accurate period interrupt, it's 168 * depending on its sampling rate. For accurate period interrupt, it's
169 * preferrable to aligh period/buffer sizes to current SYT_INTERVAL. 169 * preferrable to align period/buffer sizes to current SYT_INTERVAL.
170 * 170 *
171 * TODO: These constraints can be improved with propper rules. 171 * TODO: These constraints can be improved with proper rules.
172 * Currently apply LCM of SYT_INTEVALs. 172 * Currently apply LCM of SYT_INTERVALs.
173 */ 173 */
174 err = snd_pcm_hw_constraint_step(runtime, 0, 174 err = snd_pcm_hw_constraint_step(runtime, 0,
175 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 32); 175 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 32);
@@ -270,7 +270,7 @@ static void amdtp_read_s32(struct amdtp_stream *s,
270 * @s: the AMDTP stream to configure 270 * @s: the AMDTP stream to configure
271 * @format: the format of the ALSA PCM device 271 * @format: the format of the ALSA PCM device
272 * 272 *
273 * The sample format must be set after the other paramters (rate/PCM channels/ 273 * The sample format must be set after the other parameters (rate/PCM channels/
274 * MIDI) and before the stream is started, and must not be changed while the 274 * MIDI) and before the stream is started, and must not be changed while the
275 * stream is running. 275 * stream is running.
276 */ 276 */
diff --git a/sound/firewire/fireworks/fireworks_transaction.c b/sound/firewire/fireworks/fireworks_transaction.c
index 2a85e4209f0b..f550808d1784 100644
--- a/sound/firewire/fireworks/fireworks_transaction.c
+++ b/sound/firewire/fireworks/fireworks_transaction.c
@@ -13,7 +13,7 @@
13 * 13 *
14 * Transaction substance: 14 * Transaction substance:
15 * At first, 6 data exist. Following to the data, parameters for each command 15 * At first, 6 data exist. Following to the data, parameters for each command
16 * exist. All of the parameters are 32 bit alighed to big endian. 16 * exist. All of the parameters are 32 bit aligned to big endian.
17 * data[0]: Length of transaction substance 17 * data[0]: Length of transaction substance
18 * data[1]: Transaction version 18 * data[1]: Transaction version
19 * data[2]: Sequence number. This is incremented by the device 19 * data[2]: Sequence number. This is incremented by the device
diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
index 72332dfada9a..4aa719cad331 100644
--- a/sound/isa/sb/emu8000_synth.c
+++ b/sound/isa/sb/emu8000_synth.c
@@ -34,8 +34,9 @@ MODULE_LICENSE("GPL");
34/* 34/*
35 * create a new hardware dependent device for Emu8000 35 * create a new hardware dependent device for Emu8000
36 */ 36 */
37static int snd_emu8000_new_device(struct snd_seq_device *dev) 37static int snd_emu8000_probe(struct device *_dev)
38{ 38{
39 struct snd_seq_device *dev = to_seq_dev(_dev);
39 struct snd_emu8000 *hw; 40 struct snd_emu8000 *hw;
40 struct snd_emux *emu; 41 struct snd_emux *emu;
41 42
@@ -93,8 +94,9 @@ static int snd_emu8000_new_device(struct snd_seq_device *dev)
93/* 94/*
94 * free all resources 95 * free all resources
95 */ 96 */
96static int snd_emu8000_delete_device(struct snd_seq_device *dev) 97static int snd_emu8000_remove(struct device *_dev)
97{ 98{
99 struct snd_seq_device *dev = to_seq_dev(_dev);
98 struct snd_emu8000 *hw; 100 struct snd_emu8000 *hw;
99 101
100 if (dev->driver_data == NULL) 102 if (dev->driver_data == NULL)
@@ -114,21 +116,14 @@ static int snd_emu8000_delete_device(struct snd_seq_device *dev)
114 * INIT part 116 * INIT part
115 */ 117 */
116 118
117static int __init alsa_emu8000_init(void) 119static struct snd_seq_driver emu8000_driver = {
118{ 120 .driver = {
119 121 .name = KBUILD_MODNAME,
120 static struct snd_seq_dev_ops ops = { 122 .probe = snd_emu8000_probe,
121 snd_emu8000_new_device, 123 .remove = snd_emu8000_remove,
122 snd_emu8000_delete_device, 124 },
123 }; 125 .id = SNDRV_SEQ_DEV_ID_EMU8000,
124 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops, 126 .argsize = sizeof(struct snd_emu8000 *),
125 sizeof(struct snd_emu8000*)); 127};
126} 128
127 129module_snd_seq_driver(emu8000_driver);
128static void __exit alsa_emu8000_exit(void)
129{
130 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_EMU8000);
131}
132
133module_init(alsa_emu8000_init)
134module_exit(alsa_emu8000_exit)
diff --git a/sound/oss/opl3.c b/sound/oss/opl3.c
index 607cee4d545e..b6d19adf8f41 100644
--- a/sound/oss/opl3.c
+++ b/sound/oss/opl3.c
@@ -666,7 +666,7 @@ static int opl3_start_note (int dev, int voice, int note, int volume)
666 opl3_command(map->ioaddr, FNUM_LOW + map->voice_num, data); 666 opl3_command(map->ioaddr, FNUM_LOW + map->voice_num, data);
667 667
668 data = 0x20 | ((block & 0x7) << 2) | ((fnum >> 8) & 0x3); 668 data = 0x20 | ((block & 0x7) << 2) | ((fnum >> 8) & 0x3);
669 devc->voc[voice].keyon_byte = data; 669 devc->voc[voice].keyon_byte = data;
670 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num, data); 670 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num, data);
671 if (voice_mode == 4) 671 if (voice_mode == 4)
672 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num + 3, data); 672 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num + 3, data);
@@ -717,7 +717,7 @@ static void freq_to_fnum (int freq, int *block, int *fnum)
717 717
718static void opl3_command (int io_addr, unsigned int addr, unsigned int val) 718static void opl3_command (int io_addr, unsigned int addr, unsigned int val)
719{ 719{
720 int i; 720 int i;
721 721
722 /* 722 /*
723 * The original 2-OP synth requires a quite long delay after writing to a 723 * The original 2-OP synth requires a quite long delay after writing to a
diff --git a/sound/oss/sb_ess.c b/sound/oss/sb_ess.c
index b47a69026f1b..57f7d25a2cd3 100644
--- a/sound/oss/sb_ess.c
+++ b/sound/oss/sb_ess.c
@@ -604,7 +604,7 @@ static void ess_audio_output_block_audio2
604 ess_chgmixer (devc, 0x78, 0x03, 0x03); /* Go */ 604 ess_chgmixer (devc, 0x78, 0x03, 0x03); /* Go */
605 605
606 devc->irq_mode_16 = IMODE_OUTPUT; 606 devc->irq_mode_16 = IMODE_OUTPUT;
607 devc->intr_active_16 = 1; 607 devc->intr_active_16 = 1;
608} 608}
609 609
610static void ess_audio_output_block 610static void ess_audio_output_block
@@ -1183,17 +1183,12 @@ FKS_test (devc);
1183 chip = "ES1688"; 1183 chip = "ES1688";
1184 } 1184 }
1185 1185
1186 printk ( KERN_INFO "ESS chip %s %s%s\n" 1186 printk(KERN_INFO "ESS chip %s %s%s\n", chip,
1187 , chip 1187 (devc->sbmo.esstype == ESSTYPE_DETECT ||
1188 , ( devc->sbmo.esstype == ESSTYPE_DETECT || devc->sbmo.esstype == ESSTYPE_LIKE20 1188 devc->sbmo.esstype == ESSTYPE_LIKE20) ?
1189 ? "detected" 1189 "detected" : "specified",
1190 : "specified" 1190 devc->sbmo.esstype == ESSTYPE_LIKE20 ?
1191 ) 1191 " (kernel 2.0 compatible)" : "");
1192 , ( devc->sbmo.esstype == ESSTYPE_LIKE20
1193 ? " (kernel 2.0 compatible)"
1194 : ""
1195 )
1196 );
1197 1192
1198 sprintf(name,"ESS %s AudioDrive (rev %d)", chip, ess_minor & 0x0f); 1193 sprintf(name,"ESS %s AudioDrive (rev %d)", chip, ess_minor & 0x0f);
1199 } else { 1194 } else {
diff --git a/sound/oss/sb_midi.c b/sound/oss/sb_midi.c
index f139028e85c0..551ee7557b4e 100644
--- a/sound/oss/sb_midi.c
+++ b/sound/oss/sb_midi.c
@@ -179,14 +179,14 @@ void sb_dsp_midi_init(sb_devc * devc, struct module *owner)
179 { 179 {
180 printk(KERN_WARNING "Sound Blaster: failed to allocate MIDI memory.\n"); 180 printk(KERN_WARNING "Sound Blaster: failed to allocate MIDI memory.\n");
181 sound_unload_mididev(dev); 181 sound_unload_mididev(dev);
182 return; 182 return;
183 } 183 }
184 memcpy((char *) midi_devs[dev], (char *) &sb_midi_operations, 184 memcpy((char *) midi_devs[dev], (char *) &sb_midi_operations,
185 sizeof(struct midi_operations)); 185 sizeof(struct midi_operations));
186 186
187 if (owner) 187 if (owner)
188 midi_devs[dev]->owner = owner; 188 midi_devs[dev]->owner = owner;
189 189
190 midi_devs[dev]->devc = devc; 190 midi_devs[dev]->devc = devc;
191 191
192 192
diff --git a/sound/oss/sys_timer.c b/sound/oss/sys_timer.c
index 9f039831114c..2226dda0eff0 100644
--- a/sound/oss/sys_timer.c
+++ b/sound/oss/sys_timer.c
@@ -50,29 +50,24 @@ tmr2ticks(int tmr_value)
50static void 50static void
51poll_def_tmr(unsigned long dummy) 51poll_def_tmr(unsigned long dummy)
52{ 52{
53 if (!opened)
54 return;
55 def_tmr.expires = (1) + jiffies;
56 add_timer(&def_tmr);
53 57
54 if (opened) 58 if (!tmr_running)
55 { 59 return;
56 60
57 { 61 spin_lock(&lock);
58 def_tmr.expires = (1) + jiffies; 62 tmr_ctr++;
59 add_timer(&def_tmr); 63 curr_ticks = ticks_offs + tmr2ticks(tmr_ctr);
60 }
61 64
62 if (tmr_running) 65 if (curr_ticks >= next_event_time) {
63 { 66 next_event_time = (unsigned long) -1;
64 spin_lock(&lock); 67 sequencer_timer(0);
65 tmr_ctr++; 68 }
66 curr_ticks = ticks_offs + tmr2ticks(tmr_ctr); 69
67 70 spin_unlock(&lock);
68 if (curr_ticks >= next_event_time)
69 {
70 next_event_time = (unsigned long) -1;
71 sequencer_timer(0);
72 }
73 spin_unlock(&lock);
74 }
75 }
76} 71}
77 72
78static void 73static void
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 5ee2f17c287c..5bca1a33fed6 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -177,6 +177,7 @@ static const struct ac97_codec_id snd_ac97_codec_ids[] = {
177{ 0x54524123, 0xffffffff, "TR28602", NULL, NULL }, // only guess --jk [TR28023 = eMicro EM28023 (new CT1297)] 177{ 0x54524123, 0xffffffff, "TR28602", NULL, NULL }, // only guess --jk [TR28023 = eMicro EM28023 (new CT1297)]
178{ 0x54584e03, 0xffffffff, "TLV320AIC27", NULL, NULL }, 178{ 0x54584e03, 0xffffffff, "TLV320AIC27", NULL, NULL },
179{ 0x54584e20, 0xffffffff, "TLC320AD9xC", NULL, NULL }, 179{ 0x54584e20, 0xffffffff, "TLC320AD9xC", NULL, NULL },
180{ 0x56494120, 0xfffffff0, "VIA1613", patch_vt1613, NULL },
180{ 0x56494161, 0xffffffff, "VIA1612A", NULL, NULL }, // modified ICE1232 with S/PDIF 181{ 0x56494161, 0xffffffff, "VIA1612A", NULL, NULL }, // modified ICE1232 with S/PDIF
181{ 0x56494170, 0xffffffff, "VIA1617A", patch_vt1617a, NULL }, // modified VT1616 with S/PDIF 182{ 0x56494170, 0xffffffff, "VIA1617A", patch_vt1617a, NULL }, // modified VT1616 with S/PDIF
182{ 0x56494182, 0xffffffff, "VIA1618", patch_vt1618, NULL }, 183{ 0x56494182, 0xffffffff, "VIA1618", patch_vt1618, NULL },
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index ceaac1c41906..f4234edb878c 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -3352,6 +3352,33 @@ static int patch_cm9780(struct snd_ac97 *ac97)
3352} 3352}
3353 3353
3354/* 3354/*
3355 * VIA VT1613 codec
3356 */
3357static const struct snd_kcontrol_new snd_ac97_controls_vt1613[] = {
3358AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
3359};
3360
3361static int patch_vt1613_specific(struct snd_ac97 *ac97)
3362{
3363 return patch_build_controls(ac97, &snd_ac97_controls_vt1613[0],
3364 ARRAY_SIZE(snd_ac97_controls_vt1613));
3365};
3366
3367static const struct snd_ac97_build_ops patch_vt1613_ops = {
3368 .build_specific = patch_vt1613_specific
3369};
3370
3371static int patch_vt1613(struct snd_ac97 *ac97)
3372{
3373 ac97->build_ops = &patch_vt1613_ops;
3374
3375 ac97->flags |= AC97_HAS_NO_VIDEO;
3376 ac97->caps |= AC97_BC_HEADPHONE;
3377
3378 return 0;
3379}
3380
3381/*
3355 * VIA VT1616 codec 3382 * VIA VT1616 codec
3356 */ 3383 */
3357static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = { 3384static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index a40a2b4c8fd7..33b2a0af1b59 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -1385,8 +1385,8 @@ snd_azf3328_ctrl_codec_activity(struct snd_azf3328 *chip,
1385 .running) 1385 .running)
1386 && (!chip->codecs[peer_codecs[codec_type].other2] 1386 && (!chip->codecs[peer_codecs[codec_type].other2]
1387 .running)); 1387 .running));
1388 } 1388 }
1389 if (call_function) 1389 if (call_function)
1390 snd_azf3328_ctrl_enable_codecs(chip, enable); 1390 snd_azf3328_ctrl_enable_codecs(chip, enable);
1391 1391
1392 /* ...and adjust clock, too 1392 /* ...and adjust clock, too
@@ -2126,7 +2126,8 @@ static struct snd_pcm_ops snd_azf3328_i2s_out_ops = {
2126static int 2126static int
2127snd_azf3328_pcm(struct snd_azf3328 *chip) 2127snd_azf3328_pcm(struct snd_azf3328 *chip)
2128{ 2128{
2129enum { AZF_PCMDEV_STD, AZF_PCMDEV_I2S_OUT, NUM_AZF_PCMDEVS }; /* pcm devices */ 2129 /* pcm devices */
2130 enum { AZF_PCMDEV_STD, AZF_PCMDEV_I2S_OUT, NUM_AZF_PCMDEVS };
2130 2131
2131 struct snd_pcm *pcm; 2132 struct snd_pcm *pcm;
2132 int err; 2133 int err;
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 1d0f2cad2f5a..6cf464d9043d 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -2062,7 +2062,7 @@ static int snd_cmipci_get_volume(struct snd_kcontrol *kcontrol,
2062 val = (snd_cmipci_mixer_read(cm, reg.right_reg) >> reg.right_shift) & reg.mask; 2062 val = (snd_cmipci_mixer_read(cm, reg.right_reg) >> reg.right_shift) & reg.mask;
2063 if (reg.invert) 2063 if (reg.invert)
2064 val = reg.mask - val; 2064 val = reg.mask - val;
2065 ucontrol->value.integer.value[1] = val; 2065 ucontrol->value.integer.value[1] = val;
2066 } 2066 }
2067 spin_unlock_irq(&cm->reg_lock); 2067 spin_unlock_irq(&cm->reg_lock);
2068 return 0; 2068 return 0;
diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
index 4c41c903a840..5457d5613f6b 100644
--- a/sound/pci/emu10k1/emu10k1_synth.c
+++ b/sound/pci/emu10k1/emu10k1_synth.c
@@ -29,8 +29,9 @@ MODULE_LICENSE("GPL");
29/* 29/*
30 * create a new hardware dependent device for Emu10k1 30 * create a new hardware dependent device for Emu10k1
31 */ 31 */
32static int snd_emu10k1_synth_new_device(struct snd_seq_device *dev) 32static int snd_emu10k1_synth_probe(struct device *_dev)
33{ 33{
34 struct snd_seq_device *dev = to_seq_dev(_dev);
34 struct snd_emux *emux; 35 struct snd_emux *emux;
35 struct snd_emu10k1 *hw; 36 struct snd_emu10k1 *hw;
36 struct snd_emu10k1_synth_arg *arg; 37 struct snd_emu10k1_synth_arg *arg;
@@ -79,8 +80,9 @@ static int snd_emu10k1_synth_new_device(struct snd_seq_device *dev)
79 return 0; 80 return 0;
80} 81}
81 82
82static int snd_emu10k1_synth_delete_device(struct snd_seq_device *dev) 83static int snd_emu10k1_synth_remove(struct device *_dev)
83{ 84{
85 struct snd_seq_device *dev = to_seq_dev(_dev);
84 struct snd_emux *emux; 86 struct snd_emux *emux;
85 struct snd_emu10k1 *hw; 87 struct snd_emu10k1 *hw;
86 unsigned long flags; 88 unsigned long flags;
@@ -104,21 +106,14 @@ static int snd_emu10k1_synth_delete_device(struct snd_seq_device *dev)
104 * INIT part 106 * INIT part
105 */ 107 */
106 108
107static int __init alsa_emu10k1_synth_init(void) 109static struct snd_seq_driver emu10k1_synth_driver = {
108{ 110 .driver = {
109 111 .name = KBUILD_MODNAME,
110 static struct snd_seq_dev_ops ops = { 112 .probe = snd_emu10k1_synth_probe,
111 snd_emu10k1_synth_new_device, 113 .remove = snd_emu10k1_synth_remove,
112 snd_emu10k1_synth_delete_device, 114 },
113 }; 115 .id = SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH,
114 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops, 116 .argsize = sizeof(struct snd_emu10k1_synth_arg),
115 sizeof(struct snd_emu10k1_synth_arg)); 117};
116} 118
117 119module_snd_seq_driver(emu10k1_synth_driver);
118static void __exit alsa_emu10k1_synth_exit(void)
119{
120 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH);
121}
122
123module_init(alsa_emu10k1_synth_init)
124module_exit(alsa_emu10k1_synth_exit)
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile
index 194f30935e77..96caaebfc19d 100644
--- a/sound/pci/hda/Makefile
+++ b/sound/pci/hda/Makefile
@@ -4,7 +4,7 @@ snd-hda-tegra-objs := hda_tegra.o
4# for haswell power well 4# for haswell power well
5snd-hda-intel-$(CONFIG_SND_HDA_I915) += hda_i915.o 5snd-hda-intel-$(CONFIG_SND_HDA_I915) += hda_i915.o
6 6
7snd-hda-codec-y := hda_codec.o hda_jack.o hda_auto_parser.o hda_sysfs.o 7snd-hda-codec-y := hda_bind.o hda_codec.o hda_jack.o hda_auto_parser.o hda_sysfs.o
8snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o 8snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o
9snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o 9snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
10snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o 10snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
index 1e7de08e77cb..4cdac3a71cae 100644
--- a/sound/pci/hda/hda_beep.c
+++ b/sound/pci/hda/hda_beep.c
@@ -33,30 +33,36 @@ enum {
33 DIGBEEP_HZ_MAX = 12000000, /* 12 KHz */ 33 DIGBEEP_HZ_MAX = 12000000, /* 12 KHz */
34}; 34};
35 35
36static void snd_hda_generate_beep(struct work_struct *work) 36/* generate or stop tone */
37static void generate_tone(struct hda_beep *beep, int tone)
37{ 38{
38 struct hda_beep *beep =
39 container_of(work, struct hda_beep, beep_work);
40 struct hda_codec *codec = beep->codec; 39 struct hda_codec *codec = beep->codec;
41 int tone;
42 40
43 if (!beep->enabled)
44 return;
45
46 tone = beep->tone;
47 if (tone && !beep->playing) { 41 if (tone && !beep->playing) {
48 snd_hda_power_up(codec); 42 snd_hda_power_up(codec);
43 if (beep->power_hook)
44 beep->power_hook(beep, true);
49 beep->playing = 1; 45 beep->playing = 1;
50 } 46 }
51 /* generate tone */
52 snd_hda_codec_write(codec, beep->nid, 0, 47 snd_hda_codec_write(codec, beep->nid, 0,
53 AC_VERB_SET_BEEP_CONTROL, tone); 48 AC_VERB_SET_BEEP_CONTROL, tone);
54 if (!tone && beep->playing) { 49 if (!tone && beep->playing) {
55 beep->playing = 0; 50 beep->playing = 0;
51 if (beep->power_hook)
52 beep->power_hook(beep, false);
56 snd_hda_power_down(codec); 53 snd_hda_power_down(codec);
57 } 54 }
58} 55}
59 56
57static void snd_hda_generate_beep(struct work_struct *work)
58{
59 struct hda_beep *beep =
60 container_of(work, struct hda_beep, beep_work);
61
62 if (beep->enabled)
63 generate_tone(beep, beep->tone);
64}
65
60/* (non-standard) Linear beep tone calculation for IDT/STAC codecs 66/* (non-standard) Linear beep tone calculation for IDT/STAC codecs
61 * 67 *
62 * The tone frequency of beep generator on IDT/STAC codecs is 68 * The tone frequency of beep generator on IDT/STAC codecs is
@@ -130,10 +136,7 @@ static void turn_off_beep(struct hda_beep *beep)
130 cancel_work_sync(&beep->beep_work); 136 cancel_work_sync(&beep->beep_work);
131 if (beep->playing) { 137 if (beep->playing) {
132 /* turn off beep */ 138 /* turn off beep */
133 snd_hda_codec_write(beep->codec, beep->nid, 0, 139 generate_tone(beep, 0);
134 AC_VERB_SET_BEEP_CONTROL, 0);
135 beep->playing = 0;
136 snd_hda_power_down(beep->codec);
137 } 140 }
138} 141}
139 142
@@ -160,6 +163,7 @@ static int snd_hda_do_attach(struct hda_beep *beep)
160 input_dev->name = "HDA Digital PCBeep"; 163 input_dev->name = "HDA Digital PCBeep";
161 input_dev->phys = beep->phys; 164 input_dev->phys = beep->phys;
162 input_dev->id.bustype = BUS_PCI; 165 input_dev->id.bustype = BUS_PCI;
166 input_dev->dev.parent = &codec->card->card_dev;
163 167
164 input_dev->id.vendor = codec->vendor_id >> 16; 168 input_dev->id.vendor = codec->vendor_id >> 16;
165 input_dev->id.product = codec->vendor_id & 0xffff; 169 input_dev->id.product = codec->vendor_id & 0xffff;
@@ -168,7 +172,6 @@ static int snd_hda_do_attach(struct hda_beep *beep)
168 input_dev->evbit[0] = BIT_MASK(EV_SND); 172 input_dev->evbit[0] = BIT_MASK(EV_SND);
169 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); 173 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
170 input_dev->event = snd_hda_beep_event; 174 input_dev->event = snd_hda_beep_event;
171 input_dev->dev.parent = &codec->dev;
172 input_set_drvdata(input_dev, beep); 175 input_set_drvdata(input_dev, beep);
173 176
174 beep->dev = input_dev; 177 beep->dev = input_dev;
@@ -224,7 +227,7 @@ int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
224 if (beep == NULL) 227 if (beep == NULL)
225 return -ENOMEM; 228 return -ENOMEM;
226 snprintf(beep->phys, sizeof(beep->phys), 229 snprintf(beep->phys, sizeof(beep->phys),
227 "card%d/codec#%d/beep0", codec->bus->card->number, codec->addr); 230 "card%d/codec#%d/beep0", codec->card->number, codec->addr);
228 /* enable linear scale */ 231 /* enable linear scale */
229 snd_hda_codec_write_cache(codec, nid, 0, 232 snd_hda_codec_write_cache(codec, nid, 0,
230 AC_VERB_SET_DIGI_CONVERT_2, 0x01); 233 AC_VERB_SET_DIGI_CONVERT_2, 0x01);
diff --git a/sound/pci/hda/hda_beep.h b/sound/pci/hda/hda_beep.h
index a63b5e077332..46524ff7e79e 100644
--- a/sound/pci/hda/hda_beep.h
+++ b/sound/pci/hda/hda_beep.h
@@ -40,6 +40,7 @@ struct hda_beep {
40 unsigned int playing:1; 40 unsigned int playing:1;
41 struct work_struct beep_work; /* scheduled task for beep event */ 41 struct work_struct beep_work; /* scheduled task for beep event */
42 struct mutex mutex; 42 struct mutex mutex;
43 void (*power_hook)(struct hda_beep *beep, bool on);
43}; 44};
44 45
45#ifdef CONFIG_SND_HDA_INPUT_BEEP 46#ifdef CONFIG_SND_HDA_INPUT_BEEP
diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c
new file mode 100644
index 000000000000..1f40ce3c1696
--- /dev/null
+++ b/sound/pci/hda/hda_bind.c
@@ -0,0 +1,342 @@
1/*
2 * HD-audio codec driver binding
3 * Copyright (c) Takashi Iwai <tiwai@suse.de>
4 */
5
6#include <linux/init.h>
7#include <linux/slab.h>
8#include <linux/mutex.h>
9#include <linux/module.h>
10#include <linux/export.h>
11#include <linux/pm.h>
12#include <linux/pm_runtime.h>
13#include <sound/core.h>
14#include "hda_codec.h"
15#include "hda_local.h"
16
17/* codec vendor labels */
18struct hda_vendor_id {
19 unsigned int id;
20 const char *name;
21};
22
23static struct hda_vendor_id hda_vendor_ids[] = {
24 { 0x1002, "ATI" },
25 { 0x1013, "Cirrus Logic" },
26 { 0x1057, "Motorola" },
27 { 0x1095, "Silicon Image" },
28 { 0x10de, "Nvidia" },
29 { 0x10ec, "Realtek" },
30 { 0x1102, "Creative" },
31 { 0x1106, "VIA" },
32 { 0x111d, "IDT" },
33 { 0x11c1, "LSI" },
34 { 0x11d4, "Analog Devices" },
35 { 0x13f6, "C-Media" },
36 { 0x14f1, "Conexant" },
37 { 0x17e8, "Chrontel" },
38 { 0x1854, "LG" },
39 { 0x1aec, "Wolfson Microelectronics" },
40 { 0x1af4, "QEMU" },
41 { 0x434d, "C-Media" },
42 { 0x8086, "Intel" },
43 { 0x8384, "SigmaTel" },
44 {} /* terminator */
45};
46
47/*
48 * find a matching codec preset
49 */
50static int hda_bus_match(struct device *dev, struct device_driver *drv)
51{
52 struct hda_codec *codec = container_of(dev, struct hda_codec, dev);
53 struct hda_codec_driver *driver =
54 container_of(drv, struct hda_codec_driver, driver);
55 const struct hda_codec_preset *preset;
56 /* check probe_id instead of vendor_id if set */
57 u32 id = codec->probe_id ? codec->probe_id : codec->vendor_id;
58
59 for (preset = driver->preset; preset->id; preset++) {
60 u32 mask = preset->mask;
61
62 if (preset->afg && preset->afg != codec->afg)
63 continue;
64 if (preset->mfg && preset->mfg != codec->mfg)
65 continue;
66 if (!mask)
67 mask = ~0;
68 if (preset->id == (id & mask) &&
69 (!preset->rev || preset->rev == codec->revision_id)) {
70 codec->preset = preset;
71 return 1;
72 }
73 }
74 return 0;
75}
76
77/* reset the codec name from the preset */
78static int codec_refresh_name(struct hda_codec *codec, const char *name)
79{
80 char tmp[16];
81
82 kfree(codec->chip_name);
83 if (!name) {
84 sprintf(tmp, "ID %x", codec->vendor_id & 0xffff);
85 name = tmp;
86 }
87 codec->chip_name = kstrdup(name, GFP_KERNEL);
88 return codec->chip_name ? 0 : -ENOMEM;
89}
90
91static int hda_codec_driver_probe(struct device *dev)
92{
93 struct hda_codec *codec = dev_to_hda_codec(dev);
94 struct module *owner = dev->driver->owner;
95 int err;
96
97 if (WARN_ON(!codec->preset))
98 return -EINVAL;
99
100 err = codec_refresh_name(codec, codec->preset->name);
101 if (err < 0)
102 goto error;
103
104 if (!try_module_get(owner)) {
105 err = -EINVAL;
106 goto error;
107 }
108
109 err = codec->preset->patch(codec);
110 if (err < 0)
111 goto error_module;
112
113 err = snd_hda_codec_build_pcms(codec);
114 if (err < 0)
115 goto error_module;
116 err = snd_hda_codec_build_controls(codec);
117 if (err < 0)
118 goto error_module;
119 if (codec->card->registered) {
120 err = snd_card_register(codec->card);
121 if (err < 0)
122 goto error_module;
123 }
124
125 return 0;
126
127 error_module:
128 module_put(owner);
129
130 error:
131 snd_hda_codec_cleanup_for_unbind(codec);
132 return err;
133}
134
135static int hda_codec_driver_remove(struct device *dev)
136{
137 struct hda_codec *codec = dev_to_hda_codec(dev);
138
139 if (codec->patch_ops.free)
140 codec->patch_ops.free(codec);
141 snd_hda_codec_cleanup_for_unbind(codec);
142 module_put(dev->driver->owner);
143 return 0;
144}
145
146static void hda_codec_driver_shutdown(struct device *dev)
147{
148 struct hda_codec *codec = dev_to_hda_codec(dev);
149
150 if (!pm_runtime_suspended(dev) && codec->patch_ops.reboot_notify)
151 codec->patch_ops.reboot_notify(codec);
152}
153
154int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name,
155 struct module *owner)
156{
157 drv->driver.name = name;
158 drv->driver.owner = owner;
159 drv->driver.bus = &snd_hda_bus_type;
160 drv->driver.probe = hda_codec_driver_probe;
161 drv->driver.remove = hda_codec_driver_remove;
162 drv->driver.shutdown = hda_codec_driver_shutdown;
163 drv->driver.pm = &hda_codec_driver_pm;
164 return driver_register(&drv->driver);
165}
166EXPORT_SYMBOL_GPL(__hda_codec_driver_register);
167
168void hda_codec_driver_unregister(struct hda_codec_driver *drv)
169{
170 driver_unregister(&drv->driver);
171}
172EXPORT_SYMBOL_GPL(hda_codec_driver_unregister);
173
174static inline bool codec_probed(struct hda_codec *codec)
175{
176 return device_attach(hda_codec_dev(codec)) > 0 && codec->preset;
177}
178
179/* try to auto-load and bind the codec module */
180static void codec_bind_module(struct hda_codec *codec)
181{
182#ifdef MODULE
183 request_module("snd-hda-codec-id:%08x", codec->vendor_id);
184 if (codec_probed(codec))
185 return;
186 request_module("snd-hda-codec-id:%04x*",
187 (codec->vendor_id >> 16) & 0xffff);
188 if (codec_probed(codec))
189 return;
190#endif
191}
192
193/* store the codec vendor name */
194static int get_codec_vendor_name(struct hda_codec *codec)
195{
196 const struct hda_vendor_id *c;
197 const char *vendor = NULL;
198 u16 vendor_id = codec->vendor_id >> 16;
199 char tmp[16];
200
201 for (c = hda_vendor_ids; c->id; c++) {
202 if (c->id == vendor_id) {
203 vendor = c->name;
204 break;
205 }
206 }
207 if (!vendor) {
208 sprintf(tmp, "Generic %04x", vendor_id);
209 vendor = tmp;
210 }
211 codec->vendor_name = kstrdup(vendor, GFP_KERNEL);
212 if (!codec->vendor_name)
213 return -ENOMEM;
214 return 0;
215}
216
217#if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI)
218/* if all audio out widgets are digital, let's assume the codec as a HDMI/DP */
219static bool is_likely_hdmi_codec(struct hda_codec *codec)
220{
221 hda_nid_t nid = codec->start_nid;
222 int i;
223
224 for (i = 0; i < codec->num_nodes; i++, nid++) {
225 unsigned int wcaps = get_wcaps(codec, nid);
226 switch (get_wcaps_type(wcaps)) {
227 case AC_WID_AUD_IN:
228 return false; /* HDMI parser supports only HDMI out */
229 case AC_WID_AUD_OUT:
230 if (!(wcaps & AC_WCAP_DIGITAL))
231 return false;
232 break;
233 }
234 }
235 return true;
236}
237#else
238/* no HDMI codec parser support */
239#define is_likely_hdmi_codec(codec) false
240#endif /* CONFIG_SND_HDA_CODEC_HDMI */
241
242static int codec_bind_generic(struct hda_codec *codec)
243{
244 if (codec->probe_id)
245 return -ENODEV;
246
247 if (is_likely_hdmi_codec(codec)) {
248 codec->probe_id = HDA_CODEC_ID_GENERIC_HDMI;
249#if IS_MODULE(CONFIG_SND_HDA_CODEC_HDMI)
250 request_module("snd-hda-codec-hdmi");
251#endif
252 if (codec_probed(codec))
253 return 0;
254 }
255
256 codec->probe_id = HDA_CODEC_ID_GENERIC;
257#if IS_MODULE(CONFIG_SND_HDA_GENERIC)
258 request_module("snd-hda-codec-generic");
259#endif
260 if (codec_probed(codec))
261 return 0;
262 return -ENODEV;
263}
264
265#if IS_ENABLED(CONFIG_SND_HDA_GENERIC)
266#define is_generic_config(codec) \
267 (codec->modelname && !strcmp(codec->modelname, "generic"))
268#else
269#define is_generic_config(codec) 0
270#endif
271
272/**
273 * snd_hda_codec_configure - (Re-)configure the HD-audio codec
274 * @codec: the HDA codec
275 *
276 * Start parsing of the given codec tree and (re-)initialize the whole
277 * patch instance.
278 *
279 * Returns 0 if successful or a negative error code.
280 */
281int snd_hda_codec_configure(struct hda_codec *codec)
282{
283 int err;
284
285 if (!codec->vendor_name) {
286 err = get_codec_vendor_name(codec);
287 if (err < 0)
288 return err;
289 }
290
291 if (is_generic_config(codec))
292 codec->probe_id = HDA_CODEC_ID_GENERIC;
293 else
294 codec->probe_id = 0;
295
296 err = device_add(hda_codec_dev(codec));
297 if (err < 0)
298 return err;
299
300 if (!codec->preset)
301 codec_bind_module(codec);
302 if (!codec->preset) {
303 err = codec_bind_generic(codec);
304 if (err < 0) {
305 codec_err(codec, "Unable to bind the codec\n");
306 goto error;
307 }
308 }
309
310 /* audio codec should override the mixer name */
311 if (codec->afg || !*codec->card->mixername)
312 snprintf(codec->card->mixername,
313 sizeof(codec->card->mixername),
314 "%s %s", codec->vendor_name, codec->chip_name);
315 return 0;
316
317 error:
318 device_del(hda_codec_dev(codec));
319 return err;
320}
321EXPORT_SYMBOL_GPL(snd_hda_codec_configure);
322
323/*
324 * bus registration
325 */
326struct bus_type snd_hda_bus_type = {
327 .name = "hdaudio",
328 .match = hda_bus_match,
329};
330
331static int __init hda_codec_init(void)
332{
333 return bus_register(&snd_hda_bus_type);
334}
335
336static void __exit hda_codec_exit(void)
337{
338 bus_unregister(&snd_hda_bus_type);
339}
340
341module_init(hda_codec_init);
342module_exit(hda_codec_exit);
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 2fe86d2e1b09..7e38d6f7314b 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -26,6 +26,8 @@
26#include <linux/mutex.h> 26#include <linux/mutex.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/async.h> 28#include <linux/async.h>
29#include <linux/pm.h>
30#include <linux/pm_runtime.h>
29#include <sound/core.h> 31#include <sound/core.h>
30#include "hda_codec.h" 32#include "hda_codec.h"
31#include <sound/asoundef.h> 33#include <sound/asoundef.h>
@@ -40,92 +42,13 @@
40#define CREATE_TRACE_POINTS 42#define CREATE_TRACE_POINTS
41#include "hda_trace.h" 43#include "hda_trace.h"
42 44
43/*
44 * vendor / preset table
45 */
46
47struct hda_vendor_id {
48 unsigned int id;
49 const char *name;
50};
51
52/* codec vendor labels */
53static struct hda_vendor_id hda_vendor_ids[] = {
54 { 0x1002, "ATI" },
55 { 0x1013, "Cirrus Logic" },
56 { 0x1057, "Motorola" },
57 { 0x1095, "Silicon Image" },
58 { 0x10de, "Nvidia" },
59 { 0x10ec, "Realtek" },
60 { 0x1102, "Creative" },
61 { 0x1106, "VIA" },
62 { 0x111d, "IDT" },
63 { 0x11c1, "LSI" },
64 { 0x11d4, "Analog Devices" },
65 { 0x13f6, "C-Media" },
66 { 0x14f1, "Conexant" },
67 { 0x17e8, "Chrontel" },
68 { 0x1854, "LG" },
69 { 0x1aec, "Wolfson Microelectronics" },
70 { 0x1af4, "QEMU" },
71 { 0x434d, "C-Media" },
72 { 0x8086, "Intel" },
73 { 0x8384, "SigmaTel" },
74 {} /* terminator */
75};
76
77static DEFINE_MUTEX(preset_mutex);
78static LIST_HEAD(hda_preset_tables);
79
80/**
81 * snd_hda_add_codec_preset - Add a codec preset to the chain
82 * @preset: codec preset table to add
83 */
84int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset)
85{
86 mutex_lock(&preset_mutex);
87 list_add_tail(&preset->list, &hda_preset_tables);
88 mutex_unlock(&preset_mutex);
89 return 0;
90}
91EXPORT_SYMBOL_GPL(snd_hda_add_codec_preset);
92
93/**
94 * snd_hda_delete_codec_preset - Delete a codec preset from the chain
95 * @preset: codec preset table to delete
96 */
97int snd_hda_delete_codec_preset(struct hda_codec_preset_list *preset)
98{
99 mutex_lock(&preset_mutex);
100 list_del(&preset->list);
101 mutex_unlock(&preset_mutex);
102 return 0;
103}
104EXPORT_SYMBOL_GPL(snd_hda_delete_codec_preset);
105
106#ifdef CONFIG_PM 45#ifdef CONFIG_PM
107#define codec_in_pm(codec) ((codec)->in_pm) 46#define codec_in_pm(codec) atomic_read(&(codec)->in_pm)
108static void hda_power_work(struct work_struct *work); 47#define hda_codec_is_power_on(codec) \
109static void hda_keep_power_on(struct hda_codec *codec); 48 (!pm_runtime_suspended(hda_codec_dev(codec)))
110#define hda_codec_is_power_on(codec) ((codec)->power_on)
111
112static void hda_call_pm_notify(struct hda_codec *codec, bool power_up)
113{
114 struct hda_bus *bus = codec->bus;
115
116 if ((power_up && codec->pm_up_notified) ||
117 (!power_up && !codec->pm_up_notified))
118 return;
119 if (bus->ops.pm_notify)
120 bus->ops.pm_notify(bus, power_up);
121 codec->pm_up_notified = power_up;
122}
123
124#else 49#else
125#define codec_in_pm(codec) 0 50#define codec_in_pm(codec) 0
126static inline void hda_keep_power_on(struct hda_codec *codec) {}
127#define hda_codec_is_power_on(codec) 1 51#define hda_codec_is_power_on(codec) 1
128#define hda_call_pm_notify(codec, state) {}
129#endif 52#endif
130 53
131/** 54/**
@@ -758,14 +681,11 @@ int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex)
758 struct hda_bus_unsolicited *unsol; 681 struct hda_bus_unsolicited *unsol;
759 unsigned int wp; 682 unsigned int wp;
760 683
761 if (!bus || !bus->workq) 684 if (!bus)
762 return 0; 685 return 0;
763 686
764 trace_hda_unsol_event(bus, res, res_ex); 687 trace_hda_unsol_event(bus, res, res_ex);
765 unsol = bus->unsol; 688 unsol = &bus->unsol;
766 if (!unsol)
767 return 0;
768
769 wp = (unsol->wp + 1) % HDA_UNSOL_QUEUE_SIZE; 689 wp = (unsol->wp + 1) % HDA_UNSOL_QUEUE_SIZE;
770 unsol->wp = wp; 690 unsol->wp = wp;
771 691
@@ -773,7 +693,7 @@ int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex)
773 unsol->queue[wp] = res; 693 unsol->queue[wp] = res;
774 unsol->queue[wp + 1] = res_ex; 694 unsol->queue[wp + 1] = res_ex;
775 695
776 queue_work(bus->workq, &unsol->work); 696 schedule_work(&unsol->work);
777 697
778 return 0; 698 return 0;
779} 699}
@@ -784,9 +704,8 @@ EXPORT_SYMBOL_GPL(snd_hda_queue_unsol_event);
784 */ 704 */
785static void process_unsol_events(struct work_struct *work) 705static void process_unsol_events(struct work_struct *work)
786{ 706{
787 struct hda_bus_unsolicited *unsol = 707 struct hda_bus *bus = container_of(work, struct hda_bus, unsol.work);
788 container_of(work, struct hda_bus_unsolicited, work); 708 struct hda_bus_unsolicited *unsol = &bus->unsol;
789 struct hda_bus *bus = unsol->bus;
790 struct hda_codec *codec; 709 struct hda_codec *codec;
791 unsigned int rp, caddr, res; 710 unsigned int rp, caddr, res;
792 711
@@ -805,27 +724,6 @@ static void process_unsol_events(struct work_struct *work)
805} 724}
806 725
807/* 726/*
808 * initialize unsolicited queue
809 */
810static int init_unsol_queue(struct hda_bus *bus)
811{
812 struct hda_bus_unsolicited *unsol;
813
814 if (bus->unsol) /* already initialized */
815 return 0;
816
817 unsol = kzalloc(sizeof(*unsol), GFP_KERNEL);
818 if (!unsol) {
819 dev_err(bus->card->dev, "can't allocate unsolicited queue\n");
820 return -ENOMEM;
821 }
822 INIT_WORK(&unsol->work, process_unsol_events);
823 unsol->bus = bus;
824 bus->unsol = unsol;
825 return 0;
826}
827
828/*
829 * destructor 727 * destructor
830 */ 728 */
831static void snd_hda_bus_free(struct hda_bus *bus) 729static void snd_hda_bus_free(struct hda_bus *bus)
@@ -834,14 +732,9 @@ static void snd_hda_bus_free(struct hda_bus *bus)
834 return; 732 return;
835 733
836 WARN_ON(!list_empty(&bus->codec_list)); 734 WARN_ON(!list_empty(&bus->codec_list));
837 if (bus->workq) 735 cancel_work_sync(&bus->unsol.work);
838 flush_workqueue(bus->workq);
839 kfree(bus->unsol);
840 if (bus->ops.private_free) 736 if (bus->ops.private_free)
841 bus->ops.private_free(bus); 737 bus->ops.private_free(bus);
842 if (bus->workq)
843 destroy_workqueue(bus->workq);
844
845 kfree(bus); 738 kfree(bus);
846} 739}
847 740
@@ -861,14 +754,12 @@ static int snd_hda_bus_dev_disconnect(struct snd_device *device)
861/** 754/**
862 * snd_hda_bus_new - create a HDA bus 755 * snd_hda_bus_new - create a HDA bus
863 * @card: the card entry 756 * @card: the card entry
864 * @temp: the template for hda_bus information
865 * @busp: the pointer to store the created bus instance 757 * @busp: the pointer to store the created bus instance
866 * 758 *
867 * Returns 0 if successful, or a negative error code. 759 * Returns 0 if successful, or a negative error code.
868 */ 760 */
869int snd_hda_bus_new(struct snd_card *card, 761int snd_hda_bus_new(struct snd_card *card,
870 const struct hda_bus_template *temp, 762 struct hda_bus **busp)
871 struct hda_bus **busp)
872{ 763{
873 struct hda_bus *bus; 764 struct hda_bus *bus;
874 int err; 765 int err;
@@ -877,40 +768,18 @@ int snd_hda_bus_new(struct snd_card *card,
877 .dev_free = snd_hda_bus_dev_free, 768 .dev_free = snd_hda_bus_dev_free,
878 }; 769 };
879 770
880 if (snd_BUG_ON(!temp))
881 return -EINVAL;
882 if (snd_BUG_ON(!temp->ops.command || !temp->ops.get_response))
883 return -EINVAL;
884
885 if (busp) 771 if (busp)
886 *busp = NULL; 772 *busp = NULL;
887 773
888 bus = kzalloc(sizeof(*bus), GFP_KERNEL); 774 bus = kzalloc(sizeof(*bus), GFP_KERNEL);
889 if (bus == NULL) { 775 if (!bus)
890 dev_err(card->dev, "can't allocate struct hda_bus\n");
891 return -ENOMEM; 776 return -ENOMEM;
892 }
893 777
894 bus->card = card; 778 bus->card = card;
895 bus->private_data = temp->private_data;
896 bus->pci = temp->pci;
897 bus->modelname = temp->modelname;
898 bus->power_save = temp->power_save;
899 bus->ops = temp->ops;
900
901 mutex_init(&bus->cmd_mutex); 779 mutex_init(&bus->cmd_mutex);
902 mutex_init(&bus->prepare_mutex); 780 mutex_init(&bus->prepare_mutex);
903 INIT_LIST_HEAD(&bus->codec_list); 781 INIT_LIST_HEAD(&bus->codec_list);
904 782 INIT_WORK(&bus->unsol.work, process_unsol_events);
905 snprintf(bus->workq_name, sizeof(bus->workq_name),
906 "hd-audio%d", card->number);
907 bus->workq = create_singlethread_workqueue(bus->workq_name);
908 if (!bus->workq) {
909 dev_err(card->dev, "cannot create workqueue %s\n",
910 bus->workq_name);
911 kfree(bus);
912 return -ENOMEM;
913 }
914 783
915 err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops); 784 err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops);
916 if (err < 0) { 785 if (err < 0) {
@@ -923,111 +792,6 @@ int snd_hda_bus_new(struct snd_card *card,
923} 792}
924EXPORT_SYMBOL_GPL(snd_hda_bus_new); 793EXPORT_SYMBOL_GPL(snd_hda_bus_new);
925 794
926#if IS_ENABLED(CONFIG_SND_HDA_GENERIC)
927#define is_generic_config(codec) \
928 (codec->modelname && !strcmp(codec->modelname, "generic"))
929#else
930#define is_generic_config(codec) 0
931#endif
932
933#ifdef MODULE
934#define HDA_MODREQ_MAX_COUNT 2 /* two request_modules()'s */
935#else
936#define HDA_MODREQ_MAX_COUNT 0 /* all presets are statically linked */
937#endif
938
939/*
940 * find a matching codec preset
941 */
942static const struct hda_codec_preset *
943find_codec_preset(struct hda_codec *codec)
944{
945 struct hda_codec_preset_list *tbl;
946 const struct hda_codec_preset *preset;
947 unsigned int mod_requested = 0;
948
949 again:
950 mutex_lock(&preset_mutex);
951 list_for_each_entry(tbl, &hda_preset_tables, list) {
952 if (!try_module_get(tbl->owner)) {
953 codec_err(codec, "cannot module_get\n");
954 continue;
955 }
956 for (preset = tbl->preset; preset->id; preset++) {
957 u32 mask = preset->mask;
958 if (preset->afg && preset->afg != codec->afg)
959 continue;
960 if (preset->mfg && preset->mfg != codec->mfg)
961 continue;
962 if (!mask)
963 mask = ~0;
964 if (preset->id == (codec->vendor_id & mask) &&
965 (!preset->rev ||
966 preset->rev == codec->revision_id)) {
967 mutex_unlock(&preset_mutex);
968 codec->owner = tbl->owner;
969 return preset;
970 }
971 }
972 module_put(tbl->owner);
973 }
974 mutex_unlock(&preset_mutex);
975
976 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
977 if (!mod_requested)
978 request_module("snd-hda-codec-id:%08x",
979 codec->vendor_id);
980 else
981 request_module("snd-hda-codec-id:%04x*",
982 (codec->vendor_id >> 16) & 0xffff);
983 mod_requested++;
984 goto again;
985 }
986 return NULL;
987}
988
989/*
990 * get_codec_name - store the codec name
991 */
992static int get_codec_name(struct hda_codec *codec)
993{
994 const struct hda_vendor_id *c;
995 const char *vendor = NULL;
996 u16 vendor_id = codec->vendor_id >> 16;
997 char tmp[16];
998
999 if (codec->vendor_name)
1000 goto get_chip_name;
1001
1002 for (c = hda_vendor_ids; c->id; c++) {
1003 if (c->id == vendor_id) {
1004 vendor = c->name;
1005 break;
1006 }
1007 }
1008 if (!vendor) {
1009 sprintf(tmp, "Generic %04x", vendor_id);
1010 vendor = tmp;
1011 }
1012 codec->vendor_name = kstrdup(vendor, GFP_KERNEL);
1013 if (!codec->vendor_name)
1014 return -ENOMEM;
1015
1016 get_chip_name:
1017 if (codec->chip_name)
1018 return 0;
1019
1020 if (codec->preset && codec->preset->name)
1021 codec->chip_name = kstrdup(codec->preset->name, GFP_KERNEL);
1022 else {
1023 sprintf(tmp, "ID %x", codec->vendor_id & 0xffff);
1024 codec->chip_name = kstrdup(tmp, GFP_KERNEL);
1025 }
1026 if (!codec->chip_name)
1027 return -ENOMEM;
1028 return 0;
1029}
1030
1031/* 795/*
1032 * look for an AFG and MFG nodes 796 * look for an AFG and MFG nodes
1033 */ 797 */
@@ -1290,8 +1054,8 @@ static void hda_jackpoll_work(struct work_struct *work)
1290 if (!codec->jackpoll_interval) 1054 if (!codec->jackpoll_interval)
1291 return; 1055 return;
1292 1056
1293 queue_delayed_work(codec->bus->workq, &codec->jackpoll_work, 1057 schedule_delayed_work(&codec->jackpoll_work,
1294 codec->jackpoll_interval); 1058 codec->jackpoll_interval);
1295} 1059}
1296 1060
1297static void init_hda_cache(struct hda_cache_rec *cache, 1061static void init_hda_cache(struct hda_cache_rec *cache,
@@ -1339,54 +1103,92 @@ get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid)
1339} 1103}
1340 1104
1341/* 1105/*
1342 * Dynamic symbol binding for the codec parsers 1106 * PCM device
1343 */ 1107 */
1108static void release_pcm(struct kref *kref)
1109{
1110 struct hda_pcm *pcm = container_of(kref, struct hda_pcm, kref);
1344 1111
1345#define load_parser(codec, sym) \ 1112 if (pcm->pcm)
1346 ((codec)->parser = (int (*)(struct hda_codec *))symbol_request(sym)) 1113 snd_device_free(pcm->codec->card, pcm->pcm);
1114 clear_bit(pcm->device, pcm->codec->bus->pcm_dev_bits);
1115 kfree(pcm->name);
1116 kfree(pcm);
1117}
1347 1118
1348static void unload_parser(struct hda_codec *codec) 1119void snd_hda_codec_pcm_put(struct hda_pcm *pcm)
1349{ 1120{
1350 if (codec->parser) 1121 kref_put(&pcm->kref, release_pcm);
1351 symbol_put_addr(codec->parser); 1122}
1352 codec->parser = NULL; 1123EXPORT_SYMBOL_GPL(snd_hda_codec_pcm_put);
1124
1125struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec,
1126 const char *fmt, ...)
1127{
1128 struct hda_pcm *pcm;
1129 va_list args;
1130
1131 va_start(args, fmt);
1132 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
1133 if (!pcm)
1134 return NULL;
1135
1136 pcm->codec = codec;
1137 kref_init(&pcm->kref);
1138 pcm->name = kvasprintf(GFP_KERNEL, fmt, args);
1139 if (!pcm->name) {
1140 kfree(pcm);
1141 return NULL;
1142 }
1143
1144 list_add_tail(&pcm->list, &codec->pcm_list_head);
1145 return pcm;
1353} 1146}
1147EXPORT_SYMBOL_GPL(snd_hda_codec_pcm_new);
1354 1148
1355/* 1149/*
1356 * codec destructor 1150 * codec destructor
1357 */ 1151 */
1358static void snd_hda_codec_free(struct hda_codec *codec) 1152static void codec_release_pcms(struct hda_codec *codec)
1153{
1154 struct hda_pcm *pcm, *n;
1155
1156 list_for_each_entry_safe(pcm, n, &codec->pcm_list_head, list) {
1157 list_del_init(&pcm->list);
1158 if (pcm->pcm)
1159 snd_device_disconnect(codec->card, pcm->pcm);
1160 snd_hda_codec_pcm_put(pcm);
1161 }
1162}
1163
1164void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec)
1359{ 1165{
1360 if (!codec)
1361 return;
1362 cancel_delayed_work_sync(&codec->jackpoll_work); 1166 cancel_delayed_work_sync(&codec->jackpoll_work);
1167 if (!codec->in_freeing)
1168 snd_hda_ctls_clear(codec);
1169 codec_release_pcms(codec);
1170 snd_hda_detach_beep_device(codec);
1171 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops));
1363 snd_hda_jack_tbl_clear(codec); 1172 snd_hda_jack_tbl_clear(codec);
1364 free_init_pincfgs(codec); 1173 codec->proc_widget_hook = NULL;
1365#ifdef CONFIG_PM 1174 codec->spec = NULL;
1366 cancel_delayed_work(&codec->power_work); 1175
1367 flush_workqueue(codec->bus->workq); 1176 free_hda_cache(&codec->amp_cache);
1368#endif 1177 free_hda_cache(&codec->cmd_cache);
1369 list_del(&codec->list); 1178 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
1370 snd_array_free(&codec->mixers); 1179 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
1371 snd_array_free(&codec->nids); 1180
1181 /* free only driver_pins so that init_pins + user_pins are restored */
1182 snd_array_free(&codec->driver_pins);
1372 snd_array_free(&codec->cvt_setups); 1183 snd_array_free(&codec->cvt_setups);
1373 snd_array_free(&codec->spdif_out); 1184 snd_array_free(&codec->spdif_out);
1185 snd_array_free(&codec->verbs);
1186 codec->preset = NULL;
1187 codec->slave_dig_outs = NULL;
1188 codec->spdif_status_reset = 0;
1189 snd_array_free(&codec->mixers);
1190 snd_array_free(&codec->nids);
1374 remove_conn_list(codec); 1191 remove_conn_list(codec);
1375 codec->bus->caddr_tbl[codec->addr] = NULL;
1376 if (codec->patch_ops.free)
1377 codec->patch_ops.free(codec);
1378 hda_call_pm_notify(codec, false); /* cancel leftover refcounts */
1379 snd_hda_sysfs_clear(codec);
1380 unload_parser(codec);
1381 module_put(codec->owner);
1382 free_hda_cache(&codec->amp_cache);
1383 free_hda_cache(&codec->cmd_cache);
1384 kfree(codec->vendor_name);
1385 kfree(codec->chip_name);
1386 kfree(codec->modelname);
1387 kfree(codec->wcaps);
1388 codec->bus->num_codecs--;
1389 put_device(&codec->dev);
1390} 1192}
1391 1193
1392static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, 1194static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec,
@@ -1398,11 +1200,12 @@ static unsigned int hda_set_power_state(struct hda_codec *codec,
1398static int snd_hda_codec_dev_register(struct snd_device *device) 1200static int snd_hda_codec_dev_register(struct snd_device *device)
1399{ 1201{
1400 struct hda_codec *codec = device->device_data; 1202 struct hda_codec *codec = device->device_data;
1401 int err = device_add(&codec->dev);
1402 1203
1403 if (err < 0)
1404 return err;
1405 snd_hda_register_beep_device(codec); 1204 snd_hda_register_beep_device(codec);
1205 if (device_is_registered(hda_codec_dev(codec)))
1206 pm_runtime_enable(hda_codec_dev(codec));
1207 /* it was powered up in snd_hda_codec_new(), now all done */
1208 snd_hda_power_down(codec);
1406 return 0; 1209 return 0;
1407} 1210}
1408 1211
@@ -1411,20 +1214,37 @@ static int snd_hda_codec_dev_disconnect(struct snd_device *device)
1411 struct hda_codec *codec = device->device_data; 1214 struct hda_codec *codec = device->device_data;
1412 1215
1413 snd_hda_detach_beep_device(codec); 1216 snd_hda_detach_beep_device(codec);
1414 device_del(&codec->dev);
1415 return 0; 1217 return 0;
1416} 1218}
1417 1219
1418static int snd_hda_codec_dev_free(struct snd_device *device) 1220static int snd_hda_codec_dev_free(struct snd_device *device)
1419{ 1221{
1420 snd_hda_codec_free(device->device_data); 1222 struct hda_codec *codec = device->device_data;
1223
1224 codec->in_freeing = 1;
1225 if (device_is_registered(hda_codec_dev(codec)))
1226 device_del(hda_codec_dev(codec));
1227 put_device(hda_codec_dev(codec));
1421 return 0; 1228 return 0;
1422} 1229}
1423 1230
1424/* just free the container */
1425static void snd_hda_codec_dev_release(struct device *dev) 1231static void snd_hda_codec_dev_release(struct device *dev)
1426{ 1232{
1427 kfree(container_of(dev, struct hda_codec, dev)); 1233 struct hda_codec *codec = dev_to_hda_codec(dev);
1234
1235 free_init_pincfgs(codec);
1236 list_del(&codec->list);
1237 codec->bus->caddr_tbl[codec->addr] = NULL;
1238 clear_bit(codec->addr, &codec->bus->codec_powered);
1239 snd_hda_sysfs_clear(codec);
1240 free_hda_cache(&codec->amp_cache);
1241 free_hda_cache(&codec->cmd_cache);
1242 kfree(codec->vendor_name);
1243 kfree(codec->chip_name);
1244 kfree(codec->modelname);
1245 kfree(codec->wcaps);
1246 codec->bus->num_codecs--;
1247 kfree(codec);
1428} 1248}
1429 1249
1430/** 1250/**
@@ -1435,11 +1255,11 @@ static void snd_hda_codec_dev_release(struct device *dev)
1435 * 1255 *
1436 * Returns 0 if successful, or a negative error code. 1256 * Returns 0 if successful, or a negative error code.
1437 */ 1257 */
1438int snd_hda_codec_new(struct hda_bus *bus, 1258int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card,
1439 unsigned int codec_addr, 1259 unsigned int codec_addr, struct hda_codec **codecp)
1440 struct hda_codec **codecp)
1441{ 1260{
1442 struct hda_codec *codec; 1261 struct hda_codec *codec;
1262 struct device *dev;
1443 char component[31]; 1263 char component[31];
1444 hda_nid_t fg; 1264 hda_nid_t fg;
1445 int err; 1265 int err;
@@ -1455,28 +1275,28 @@ int snd_hda_codec_new(struct hda_bus *bus,
1455 return -EINVAL; 1275 return -EINVAL;
1456 1276
1457 if (bus->caddr_tbl[codec_addr]) { 1277 if (bus->caddr_tbl[codec_addr]) {
1458 dev_err(bus->card->dev, 1278 dev_err(card->dev,
1459 "address 0x%x is already occupied\n", 1279 "address 0x%x is already occupied\n",
1460 codec_addr); 1280 codec_addr);
1461 return -EBUSY; 1281 return -EBUSY;
1462 } 1282 }
1463 1283
1464 codec = kzalloc(sizeof(*codec), GFP_KERNEL); 1284 codec = kzalloc(sizeof(*codec), GFP_KERNEL);
1465 if (codec == NULL) { 1285 if (!codec)
1466 dev_err(bus->card->dev, "can't allocate struct hda_codec\n");
1467 return -ENOMEM; 1286 return -ENOMEM;
1468 }
1469 1287
1470 device_initialize(&codec->dev); 1288 dev = hda_codec_dev(codec);
1471 codec->dev.parent = &bus->card->card_dev; 1289 device_initialize(dev);
1472 codec->dev.class = sound_class; 1290 dev->parent = card->dev;
1473 codec->dev.release = snd_hda_codec_dev_release; 1291 dev->bus = &snd_hda_bus_type;
1474 codec->dev.groups = snd_hda_dev_attr_groups; 1292 dev->release = snd_hda_codec_dev_release;
1475 dev_set_name(&codec->dev, "hdaudioC%dD%d", bus->card->number, 1293 dev->groups = snd_hda_dev_attr_groups;
1476 codec_addr); 1294 dev_set_name(dev, "hdaudioC%dD%d", card->number, codec_addr);
1477 dev_set_drvdata(&codec->dev, codec); /* for sysfs */ 1295 dev_set_drvdata(dev, codec); /* for sysfs */
1296 device_enable_async_suspend(dev);
1478 1297
1479 codec->bus = bus; 1298 codec->bus = bus;
1299 codec->card = card;
1480 codec->addr = codec_addr; 1300 codec->addr = codec_addr;
1481 mutex_init(&codec->spdif_mutex); 1301 mutex_init(&codec->spdif_mutex);
1482 mutex_init(&codec->control_mutex); 1302 mutex_init(&codec->control_mutex);
@@ -1492,19 +1312,20 @@ int snd_hda_codec_new(struct hda_bus *bus,
1492 snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16); 1312 snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16);
1493 snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8); 1313 snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8);
1494 INIT_LIST_HEAD(&codec->conn_list); 1314 INIT_LIST_HEAD(&codec->conn_list);
1315 INIT_LIST_HEAD(&codec->pcm_list_head);
1495 1316
1496 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work); 1317 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work);
1497 codec->depop_delay = -1; 1318 codec->depop_delay = -1;
1498 codec->fixup_id = HDA_FIXUP_ID_NOT_SET; 1319 codec->fixup_id = HDA_FIXUP_ID_NOT_SET;
1499 1320
1500#ifdef CONFIG_PM 1321#ifdef CONFIG_PM
1501 spin_lock_init(&codec->power_lock);
1502 INIT_DELAYED_WORK(&codec->power_work, hda_power_work);
1503 /* snd_hda_codec_new() marks the codec as power-up, and leave it as is. 1322 /* snd_hda_codec_new() marks the codec as power-up, and leave it as is.
1504 * the caller has to power down appropriatley after initialization 1323 * it's powered down later in snd_hda_codec_dev_register().
1505 * phase.
1506 */ 1324 */
1507 hda_keep_power_on(codec); 1325 set_bit(codec->addr, &bus->codec_powered);
1326 pm_runtime_set_active(hda_codec_dev(codec));
1327 pm_runtime_get_noresume(hda_codec_dev(codec));
1328 codec->power_jiffies = jiffies;
1508#endif 1329#endif
1509 1330
1510 snd_hda_sysfs_init(codec); 1331 snd_hda_sysfs_init(codec);
@@ -1537,17 +1358,15 @@ int snd_hda_codec_new(struct hda_bus *bus,
1537 1358
1538 setup_fg_nodes(codec); 1359 setup_fg_nodes(codec);
1539 if (!codec->afg && !codec->mfg) { 1360 if (!codec->afg && !codec->mfg) {
1540 dev_err(bus->card->dev, "no AFG or MFG node found\n"); 1361 codec_err(codec, "no AFG or MFG node found\n");
1541 err = -ENODEV; 1362 err = -ENODEV;
1542 goto error; 1363 goto error;
1543 } 1364 }
1544 1365
1545 fg = codec->afg ? codec->afg : codec->mfg; 1366 fg = codec->afg ? codec->afg : codec->mfg;
1546 err = read_widget_caps(codec, fg); 1367 err = read_widget_caps(codec, fg);
1547 if (err < 0) { 1368 if (err < 0)
1548 dev_err(bus->card->dev, "cannot malloc\n");
1549 goto error; 1369 goto error;
1550 }
1551 err = read_pin_defaults(codec); 1370 err = read_pin_defaults(codec);
1552 if (err < 0) 1371 if (err < 0)
1553 goto error; 1372 goto error;
@@ -1564,11 +1383,6 @@ int snd_hda_codec_new(struct hda_bus *bus,
1564#endif 1383#endif
1565 codec->epss = snd_hda_codec_get_supported_ps(codec, fg, 1384 codec->epss = snd_hda_codec_get_supported_ps(codec, fg,
1566 AC_PWRST_EPSS); 1385 AC_PWRST_EPSS);
1567#ifdef CONFIG_PM
1568 if (!codec->d3_stop_clk || !codec->epss)
1569 bus->power_keep_link_on = 1;
1570#endif
1571
1572 1386
1573 /* power-up all before initialization */ 1387 /* power-up all before initialization */
1574 hda_set_power_state(codec, AC_PWRST_D0); 1388 hda_set_power_state(codec, AC_PWRST_D0);
@@ -1579,9 +1393,9 @@ int snd_hda_codec_new(struct hda_bus *bus,
1579 1393
1580 sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id, 1394 sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id,
1581 codec->subsystem_id, codec->revision_id); 1395 codec->subsystem_id, codec->revision_id);
1582 snd_component_add(codec->bus->card, component); 1396 snd_component_add(card, component);
1583 1397
1584 err = snd_device_new(bus->card, SNDRV_DEV_CODEC, codec, &dev_ops); 1398 err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops);
1585 if (err < 0) 1399 if (err < 0)
1586 goto error; 1400 goto error;
1587 1401
@@ -1590,7 +1404,7 @@ int snd_hda_codec_new(struct hda_bus *bus,
1590 return 0; 1404 return 0;
1591 1405
1592 error: 1406 error:
1593 snd_hda_codec_free(codec); 1407 put_device(hda_codec_dev(codec));
1594 return err; 1408 return err;
1595} 1409}
1596EXPORT_SYMBOL_GPL(snd_hda_codec_new); 1410EXPORT_SYMBOL_GPL(snd_hda_codec_new);
@@ -1613,10 +1427,8 @@ int snd_hda_codec_update_widgets(struct hda_codec *codec)
1613 kfree(codec->wcaps); 1427 kfree(codec->wcaps);
1614 fg = codec->afg ? codec->afg : codec->mfg; 1428 fg = codec->afg ? codec->afg : codec->mfg;
1615 err = read_widget_caps(codec, fg); 1429 err = read_widget_caps(codec, fg);
1616 if (err < 0) { 1430 if (err < 0)
1617 codec_err(codec, "cannot malloc\n");
1618 return err; 1431 return err;
1619 }
1620 1432
1621 snd_array_free(&codec->init_pins); 1433 snd_array_free(&codec->init_pins);
1622 err = read_pin_defaults(codec); 1434 err = read_pin_defaults(codec);
@@ -1625,98 +1437,6 @@ int snd_hda_codec_update_widgets(struct hda_codec *codec)
1625} 1437}
1626EXPORT_SYMBOL_GPL(snd_hda_codec_update_widgets); 1438EXPORT_SYMBOL_GPL(snd_hda_codec_update_widgets);
1627 1439
1628
1629#if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI)
1630/* if all audio out widgets are digital, let's assume the codec as a HDMI/DP */
1631static bool is_likely_hdmi_codec(struct hda_codec *codec)
1632{
1633 hda_nid_t nid = codec->start_nid;
1634 int i;
1635
1636 for (i = 0; i < codec->num_nodes; i++, nid++) {
1637 unsigned int wcaps = get_wcaps(codec, nid);
1638 switch (get_wcaps_type(wcaps)) {
1639 case AC_WID_AUD_IN:
1640 return false; /* HDMI parser supports only HDMI out */
1641 case AC_WID_AUD_OUT:
1642 if (!(wcaps & AC_WCAP_DIGITAL))
1643 return false;
1644 break;
1645 }
1646 }
1647 return true;
1648}
1649#else
1650/* no HDMI codec parser support */
1651#define is_likely_hdmi_codec(codec) false
1652#endif /* CONFIG_SND_HDA_CODEC_HDMI */
1653
1654/**
1655 * snd_hda_codec_configure - (Re-)configure the HD-audio codec
1656 * @codec: the HDA codec
1657 *
1658 * Start parsing of the given codec tree and (re-)initialize the whole
1659 * patch instance.
1660 *
1661 * Returns 0 if successful or a negative error code.
1662 */
1663int snd_hda_codec_configure(struct hda_codec *codec)
1664{
1665 int (*patch)(struct hda_codec *) = NULL;
1666 int err;
1667
1668 codec->preset = find_codec_preset(codec);
1669 if (!codec->vendor_name || !codec->chip_name) {
1670 err = get_codec_name(codec);
1671 if (err < 0)
1672 return err;
1673 }
1674
1675 if (!is_generic_config(codec) && codec->preset)
1676 patch = codec->preset->patch;
1677 if (!patch) {
1678 unload_parser(codec); /* to be sure */
1679 if (is_likely_hdmi_codec(codec)) {
1680#if IS_MODULE(CONFIG_SND_HDA_CODEC_HDMI)
1681 patch = load_parser(codec, snd_hda_parse_hdmi_codec);
1682#elif IS_BUILTIN(CONFIG_SND_HDA_CODEC_HDMI)
1683 patch = snd_hda_parse_hdmi_codec;
1684#endif
1685 }
1686 if (!patch) {
1687#if IS_MODULE(CONFIG_SND_HDA_GENERIC)
1688 patch = load_parser(codec, snd_hda_parse_generic_codec);
1689#elif IS_BUILTIN(CONFIG_SND_HDA_GENERIC)
1690 patch = snd_hda_parse_generic_codec;
1691#endif
1692 }
1693 if (!patch) {
1694 codec_err(codec, "No codec parser is available\n");
1695 return -ENODEV;
1696 }
1697 }
1698
1699 err = patch(codec);
1700 if (err < 0) {
1701 unload_parser(codec);
1702 return err;
1703 }
1704
1705 if (codec->patch_ops.unsol_event) {
1706 err = init_unsol_queue(codec->bus);
1707 if (err < 0)
1708 return err;
1709 }
1710
1711 /* audio codec should override the mixer name */
1712 if (codec->afg || !*codec->bus->card->mixername)
1713 snprintf(codec->bus->card->mixername,
1714 sizeof(codec->bus->card->mixername),
1715 "%s %s", codec->vendor_name, codec->chip_name);
1716 return 0;
1717}
1718EXPORT_SYMBOL_GPL(snd_hda_codec_configure);
1719
1720/* update the stream-id if changed */ 1440/* update the stream-id if changed */
1721static void update_pcm_stream_id(struct hda_codec *codec, 1441static void update_pcm_stream_id(struct hda_codec *codec,
1722 struct hda_cvt_setup *p, hda_nid_t nid, 1442 struct hda_cvt_setup *p, hda_nid_t nid,
@@ -1782,6 +1502,8 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1782 if (!p) 1502 if (!p)
1783 return; 1503 return;
1784 1504
1505 if (codec->patch_ops.stream_pm)
1506 codec->patch_ops.stream_pm(codec, nid, true);
1785 if (codec->pcm_format_first) 1507 if (codec->pcm_format_first)
1786 update_pcm_format(codec, p, nid, format); 1508 update_pcm_format(codec, p, nid, format);
1787 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id); 1509 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id);
@@ -1850,6 +1572,8 @@ static void really_cleanup_stream(struct hda_codec *codec,
1850); 1572);
1851 memset(q, 0, sizeof(*q)); 1573 memset(q, 0, sizeof(*q));
1852 q->nid = nid; 1574 q->nid = nid;
1575 if (codec->patch_ops.stream_pm)
1576 codec->patch_ops.stream_pm(codec, nid, false);
1853} 1577}
1854 1578
1855/* clean up the all conflicting obsolete streams */ 1579/* clean up the all conflicting obsolete streams */
@@ -2192,11 +1916,10 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_amp_read);
2192 1916
2193static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, 1917static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
2194 int direction, int idx, int mask, int val, 1918 int direction, int idx, int mask, int val,
2195 bool init_only) 1919 bool init_only, bool cache_only)
2196{ 1920{
2197 struct hda_amp_info *info; 1921 struct hda_amp_info *info;
2198 unsigned int caps; 1922 unsigned int caps;
2199 unsigned int cache_only;
2200 1923
2201 if (snd_BUG_ON(mask & ~0xff)) 1924 if (snd_BUG_ON(mask & ~0xff))
2202 mask &= 0xff; 1925 mask &= 0xff;
@@ -2214,7 +1937,7 @@ static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
2214 return 0; 1937 return 0;
2215 } 1938 }
2216 info->vol[ch] = val; 1939 info->vol[ch] = val;
2217 cache_only = info->head.dirty = codec->cached_write; 1940 info->head.dirty |= cache_only;
2218 caps = info->amp_caps; 1941 caps = info->amp_caps;
2219 mutex_unlock(&codec->hash_mutex); 1942 mutex_unlock(&codec->hash_mutex);
2220 if (!cache_only) 1943 if (!cache_only)
@@ -2238,7 +1961,8 @@ static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
2238int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, 1961int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
2239 int direction, int idx, int mask, int val) 1962 int direction, int idx, int mask, int val)
2240{ 1963{
2241 return codec_amp_update(codec, nid, ch, direction, idx, mask, val, false); 1964 return codec_amp_update(codec, nid, ch, direction, idx, mask, val,
1965 false, codec->cached_write);
2242} 1966}
2243EXPORT_SYMBOL_GPL(snd_hda_codec_amp_update); 1967EXPORT_SYMBOL_GPL(snd_hda_codec_amp_update);
2244 1968
@@ -2285,7 +2009,8 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_amp_stereo);
2285int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, 2009int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
2286 int dir, int idx, int mask, int val) 2010 int dir, int idx, int mask, int val)
2287{ 2011{
2288 return codec_amp_update(codec, nid, ch, dir, idx, mask, val, true); 2012 return codec_amp_update(codec, nid, ch, dir, idx, mask, val, true,
2013 codec->cached_write);
2289} 2014}
2290EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init); 2015EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init);
2291 2016
@@ -2427,8 +2152,8 @@ update_amp_value(struct hda_codec *codec, hda_nid_t nid,
2427 maxval = get_amp_max_value(codec, nid, dir, 0); 2152 maxval = get_amp_max_value(codec, nid, dir, 0);
2428 if (val > maxval) 2153 if (val > maxval)
2429 val = maxval; 2154 val = maxval;
2430 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, 2155 return codec_amp_update(codec, nid, ch, dir, idx, HDA_AMP_VOLMASK, val,
2431 HDA_AMP_VOLMASK, val); 2156 false, !hda_codec_is_power_on(codec));
2432} 2157}
2433 2158
2434/** 2159/**
@@ -2478,14 +2203,12 @@ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
2478 long *valp = ucontrol->value.integer.value; 2203 long *valp = ucontrol->value.integer.value;
2479 int change = 0; 2204 int change = 0;
2480 2205
2481 snd_hda_power_up(codec);
2482 if (chs & 1) { 2206 if (chs & 1) {
2483 change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp); 2207 change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp);
2484 valp++; 2208 valp++;
2485 } 2209 }
2486 if (chs & 2) 2210 if (chs & 2)
2487 change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp); 2211 change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp);
2488 snd_hda_power_down(codec);
2489 return change; 2212 return change;
2490} 2213}
2491EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_put); 2214EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_put);
@@ -2572,7 +2295,7 @@ find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx)
2572 if (snd_BUG_ON(strlen(name) >= sizeof(id.name))) 2295 if (snd_BUG_ON(strlen(name) >= sizeof(id.name)))
2573 return NULL; 2296 return NULL;
2574 strcpy(id.name, name); 2297 strcpy(id.name, name);
2575 return snd_ctl_find_id(codec->bus->card, &id); 2298 return snd_ctl_find_id(codec->card, &id);
2576} 2299}
2577 2300
2578/** 2301/**
@@ -2636,7 +2359,7 @@ int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
2636 nid = kctl->id.subdevice & 0xffff; 2359 nid = kctl->id.subdevice & 0xffff;
2637 if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG)) 2360 if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG))
2638 kctl->id.subdevice = 0; 2361 kctl->id.subdevice = 0;
2639 err = snd_ctl_add(codec->bus->card, kctl); 2362 err = snd_ctl_add(codec->card, kctl);
2640 if (err < 0) 2363 if (err < 0)
2641 return err; 2364 return err;
2642 item = snd_array_new(&codec->mixers); 2365 item = snd_array_new(&codec->mixers);
@@ -2689,7 +2412,7 @@ void snd_hda_ctls_clear(struct hda_codec *codec)
2689 int i; 2412 int i;
2690 struct hda_nid_item *items = codec->mixers.list; 2413 struct hda_nid_item *items = codec->mixers.list;
2691 for (i = 0; i < codec->mixers.used; i++) 2414 for (i = 0; i < codec->mixers.used; i++)
2692 snd_ctl_remove(codec->bus->card, items[i].kctl); 2415 snd_ctl_remove(codec->card, items[i].kctl);
2693 snd_array_free(&codec->mixers); 2416 snd_array_free(&codec->mixers);
2694 snd_array_free(&codec->nids); 2417 snd_array_free(&codec->nids);
2695} 2418}
@@ -2713,9 +2436,8 @@ int snd_hda_lock_devices(struct hda_bus *bus)
2713 goto err_clear; 2436 goto err_clear;
2714 2437
2715 list_for_each_entry(codec, &bus->codec_list, list) { 2438 list_for_each_entry(codec, &bus->codec_list, list) {
2716 int pcm; 2439 struct hda_pcm *cpcm;
2717 for (pcm = 0; pcm < codec->num_pcms; pcm++) { 2440 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
2718 struct hda_pcm *cpcm = &codec->pcm_info[pcm];
2719 if (!cpcm->pcm) 2441 if (!cpcm->pcm)
2720 continue; 2442 continue;
2721 if (cpcm->pcm->streams[0].substream_opened || 2443 if (cpcm->pcm->streams[0].substream_opened ||
@@ -2742,7 +2464,6 @@ void snd_hda_unlock_devices(struct hda_bus *bus)
2742{ 2464{
2743 struct snd_card *card = bus->card; 2465 struct snd_card *card = bus->card;
2744 2466
2745 card = bus->card;
2746 spin_lock(&card->files_lock); 2467 spin_lock(&card->files_lock);
2747 card->shutdown = 0; 2468 card->shutdown = 0;
2748 spin_unlock(&card->files_lock); 2469 spin_unlock(&card->files_lock);
@@ -2762,51 +2483,13 @@ EXPORT_SYMBOL_GPL(snd_hda_unlock_devices);
2762int snd_hda_codec_reset(struct hda_codec *codec) 2483int snd_hda_codec_reset(struct hda_codec *codec)
2763{ 2484{
2764 struct hda_bus *bus = codec->bus; 2485 struct hda_bus *bus = codec->bus;
2765 struct snd_card *card = bus->card;
2766 int i;
2767 2486
2768 if (snd_hda_lock_devices(bus) < 0) 2487 if (snd_hda_lock_devices(bus) < 0)
2769 return -EBUSY; 2488 return -EBUSY;
2770 2489
2771 /* OK, let it free */ 2490 /* OK, let it free */
2772 cancel_delayed_work_sync(&codec->jackpoll_work); 2491 if (device_is_registered(hda_codec_dev(codec)))
2773#ifdef CONFIG_PM 2492 device_del(hda_codec_dev(codec));
2774 cancel_delayed_work_sync(&codec->power_work);
2775 flush_workqueue(bus->workq);
2776#endif
2777 snd_hda_ctls_clear(codec);
2778 /* release PCMs */
2779 for (i = 0; i < codec->num_pcms; i++) {
2780 if (codec->pcm_info[i].pcm) {
2781 snd_device_free(card, codec->pcm_info[i].pcm);
2782 clear_bit(codec->pcm_info[i].device,
2783 bus->pcm_dev_bits);
2784 }
2785 }
2786 snd_hda_detach_beep_device(codec);
2787 if (codec->patch_ops.free)
2788 codec->patch_ops.free(codec);
2789 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops));
2790 snd_hda_jack_tbl_clear(codec);
2791 codec->proc_widget_hook = NULL;
2792 codec->spec = NULL;
2793 free_hda_cache(&codec->amp_cache);
2794 free_hda_cache(&codec->cmd_cache);
2795 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
2796 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
2797 /* free only driver_pins so that init_pins + user_pins are restored */
2798 snd_array_free(&codec->driver_pins);
2799 snd_array_free(&codec->cvt_setups);
2800 snd_array_free(&codec->spdif_out);
2801 snd_array_free(&codec->verbs);
2802 codec->num_pcms = 0;
2803 codec->pcm_info = NULL;
2804 codec->preset = NULL;
2805 codec->slave_dig_outs = NULL;
2806 codec->spdif_status_reset = 0;
2807 unload_parser(codec);
2808 module_put(codec->owner);
2809 codec->owner = NULL;
2810 2493
2811 /* allow device access again */ 2494 /* allow device access again */
2812 snd_hda_unlock_devices(bus); 2495 snd_hda_unlock_devices(bus);
@@ -3153,19 +2836,19 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
3153 long *valp = ucontrol->value.integer.value; 2836 long *valp = ucontrol->value.integer.value;
3154 int change = 0; 2837 int change = 0;
3155 2838
3156 snd_hda_power_up(codec);
3157 if (chs & 1) { 2839 if (chs & 1) {
3158 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx, 2840 change = codec_amp_update(codec, nid, 0, dir, idx,
3159 HDA_AMP_MUTE, 2841 HDA_AMP_MUTE,
3160 *valp ? 0 : HDA_AMP_MUTE); 2842 *valp ? 0 : HDA_AMP_MUTE, false,
2843 !hda_codec_is_power_on(codec));
3161 valp++; 2844 valp++;
3162 } 2845 }
3163 if (chs & 2) 2846 if (chs & 2)
3164 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx, 2847 change |= codec_amp_update(codec, nid, 1, dir, idx,
3165 HDA_AMP_MUTE, 2848 HDA_AMP_MUTE,
3166 *valp ? 0 : HDA_AMP_MUTE); 2849 *valp ? 0 : HDA_AMP_MUTE, false,
2850 !hda_codec_is_power_on(codec));
3167 hda_call_check_power_status(codec, nid); 2851 hda_call_check_power_status(codec, nid);
3168 snd_hda_power_down(codec);
3169 return change; 2852 return change;
3170} 2853}
3171EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_put); 2854EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_put);
@@ -4212,31 +3895,40 @@ static inline void hda_exec_init_verbs(struct hda_codec *codec) {}
4212#endif 3895#endif
4213 3896
4214#ifdef CONFIG_PM 3897#ifdef CONFIG_PM
3898/* update the power on/off account with the current jiffies */
3899static void update_power_acct(struct hda_codec *codec, bool on)
3900{
3901 unsigned long delta = jiffies - codec->power_jiffies;
3902
3903 if (on)
3904 codec->power_on_acct += delta;
3905 else
3906 codec->power_off_acct += delta;
3907 codec->power_jiffies += delta;
3908}
3909
3910void snd_hda_update_power_acct(struct hda_codec *codec)
3911{
3912 update_power_acct(codec, hda_codec_is_power_on(codec));
3913}
3914
4215/* 3915/*
4216 * call suspend and power-down; used both from PM and power-save 3916 * call suspend and power-down; used both from PM and power-save
4217 * this function returns the power state in the end 3917 * this function returns the power state in the end
4218 */ 3918 */
4219static unsigned int hda_call_codec_suspend(struct hda_codec *codec, bool in_wq) 3919static unsigned int hda_call_codec_suspend(struct hda_codec *codec)
4220{ 3920{
4221 unsigned int state; 3921 unsigned int state;
4222 3922
4223 codec->in_pm = 1; 3923 atomic_inc(&codec->in_pm);
4224 3924
4225 if (codec->patch_ops.suspend) 3925 if (codec->patch_ops.suspend)
4226 codec->patch_ops.suspend(codec); 3926 codec->patch_ops.suspend(codec);
4227 hda_cleanup_all_streams(codec); 3927 hda_cleanup_all_streams(codec);
4228 state = hda_set_power_state(codec, AC_PWRST_D3); 3928 state = hda_set_power_state(codec, AC_PWRST_D3);
4229 /* Cancel delayed work if we aren't currently running from it. */
4230 if (!in_wq)
4231 cancel_delayed_work_sync(&codec->power_work);
4232 spin_lock(&codec->power_lock);
4233 snd_hda_update_power_acct(codec);
4234 trace_hda_power_down(codec); 3929 trace_hda_power_down(codec);
4235 codec->power_on = 0; 3930 update_power_acct(codec, true);
4236 codec->power_transition = 0; 3931 atomic_dec(&codec->in_pm);
4237 codec->power_jiffies = jiffies;
4238 spin_unlock(&codec->power_lock);
4239 codec->in_pm = 0;
4240 return state; 3932 return state;
4241} 3933}
4242 3934
@@ -4261,14 +3953,13 @@ static void hda_mark_cmd_cache_dirty(struct hda_codec *codec)
4261 */ 3953 */
4262static void hda_call_codec_resume(struct hda_codec *codec) 3954static void hda_call_codec_resume(struct hda_codec *codec)
4263{ 3955{
4264 codec->in_pm = 1; 3956 atomic_inc(&codec->in_pm);
4265 3957
3958 trace_hda_power_up(codec);
4266 hda_mark_cmd_cache_dirty(codec); 3959 hda_mark_cmd_cache_dirty(codec);
4267 3960
4268 /* set as if powered on for avoiding re-entering the resume 3961 codec->power_jiffies = jiffies;
4269 * in the resume / power-save sequence 3962
4270 */
4271 hda_keep_power_on(codec);
4272 hda_set_power_state(codec, AC_PWRST_D0); 3963 hda_set_power_state(codec, AC_PWRST_D0);
4273 restore_shutup_pins(codec); 3964 restore_shutup_pins(codec);
4274 hda_exec_init_verbs(codec); 3965 hda_exec_init_verbs(codec);
@@ -4286,64 +3977,63 @@ static void hda_call_codec_resume(struct hda_codec *codec)
4286 hda_jackpoll_work(&codec->jackpoll_work.work); 3977 hda_jackpoll_work(&codec->jackpoll_work.work);
4287 else 3978 else
4288 snd_hda_jack_report_sync(codec); 3979 snd_hda_jack_report_sync(codec);
4289 3980 atomic_dec(&codec->in_pm);
4290 codec->in_pm = 0;
4291 snd_hda_power_down(codec); /* flag down before returning */
4292} 3981}
4293#endif /* CONFIG_PM */
4294 3982
3983static int hda_codec_runtime_suspend(struct device *dev)
3984{
3985 struct hda_codec *codec = dev_to_hda_codec(dev);
3986 struct hda_pcm *pcm;
3987 unsigned int state;
4295 3988
4296/** 3989 cancel_delayed_work_sync(&codec->jackpoll_work);
4297 * snd_hda_build_controls - build mixer controls 3990 list_for_each_entry(pcm, &codec->pcm_list_head, list)
4298 * @bus: the BUS 3991 snd_pcm_suspend_all(pcm->pcm);
4299 * 3992 state = hda_call_codec_suspend(codec);
4300 * Creates mixer controls for each codec included in the bus. 3993 if (codec->d3_stop_clk && codec->epss && (state & AC_PWRST_CLK_STOP_OK))
4301 * 3994 clear_bit(codec->addr, &codec->bus->codec_powered);
4302 * Returns 0 if successful, otherwise a negative error code. 3995 return 0;
4303 */ 3996}
4304int snd_hda_build_controls(struct hda_bus *bus) 3997
3998static int hda_codec_runtime_resume(struct device *dev)
4305{ 3999{
4306 struct hda_codec *codec; 4000 struct hda_codec *codec = dev_to_hda_codec(dev);
4307 4001
4308 list_for_each_entry(codec, &bus->codec_list, list) { 4002 set_bit(codec->addr, &codec->bus->codec_powered);
4309 int err = snd_hda_codec_build_controls(codec); 4003 hda_call_codec_resume(codec);
4310 if (err < 0) { 4004 pm_runtime_mark_last_busy(dev);
4311 codec_err(codec,
4312 "cannot build controls for #%d (error %d)\n",
4313 codec->addr, err);
4314 err = snd_hda_codec_reset(codec);
4315 if (err < 0) {
4316 codec_err(codec,
4317 "cannot revert codec\n");
4318 return err;
4319 }
4320 }
4321 }
4322 return 0; 4005 return 0;
4323} 4006}
4324EXPORT_SYMBOL_GPL(snd_hda_build_controls); 4007#endif /* CONFIG_PM */
4008
4009/* referred in hda_bind.c */
4010const struct dev_pm_ops hda_codec_driver_pm = {
4011 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
4012 pm_runtime_force_resume)
4013 SET_RUNTIME_PM_OPS(hda_codec_runtime_suspend, hda_codec_runtime_resume,
4014 NULL)
4015};
4325 4016
4326/* 4017/*
4327 * add standard channel maps if not specified 4018 * add standard channel maps if not specified
4328 */ 4019 */
4329static int add_std_chmaps(struct hda_codec *codec) 4020static int add_std_chmaps(struct hda_codec *codec)
4330{ 4021{
4331 int i, str, err; 4022 struct hda_pcm *pcm;
4023 int str, err;
4332 4024
4333 for (i = 0; i < codec->num_pcms; i++) { 4025 list_for_each_entry(pcm, &codec->pcm_list_head, list) {
4334 for (str = 0; str < 2; str++) { 4026 for (str = 0; str < 2; str++) {
4335 struct snd_pcm *pcm = codec->pcm_info[i].pcm; 4027 struct hda_pcm_stream *hinfo = &pcm->stream[str];
4336 struct hda_pcm_stream *hinfo =
4337 &codec->pcm_info[i].stream[str];
4338 struct snd_pcm_chmap *chmap; 4028 struct snd_pcm_chmap *chmap;
4339 const struct snd_pcm_chmap_elem *elem; 4029 const struct snd_pcm_chmap_elem *elem;
4340 4030
4341 if (codec->pcm_info[i].own_chmap) 4031 if (pcm->own_chmap)
4342 continue; 4032 continue;
4343 if (!pcm || !hinfo->substreams) 4033 if (!pcm || !hinfo->substreams)
4344 continue; 4034 continue;
4345 elem = hinfo->chmap ? hinfo->chmap : snd_pcm_std_chmaps; 4035 elem = hinfo->chmap ? hinfo->chmap : snd_pcm_std_chmaps;
4346 err = snd_pcm_add_chmap_ctls(pcm, str, elem, 4036 err = snd_pcm_add_chmap_ctls(pcm->pcm, str, elem,
4347 hinfo->channels_max, 4037 hinfo->channels_max,
4348 0, &chmap); 4038 0, &chmap);
4349 if (err < 0) 4039 if (err < 0)
@@ -4792,7 +4482,11 @@ int snd_hda_codec_prepare(struct hda_codec *codec,
4792{ 4482{
4793 int ret; 4483 int ret;
4794 mutex_lock(&codec->bus->prepare_mutex); 4484 mutex_lock(&codec->bus->prepare_mutex);
4795 ret = hinfo->ops.prepare(hinfo, codec, stream, format, substream); 4485 if (hinfo->ops.prepare)
4486 ret = hinfo->ops.prepare(hinfo, codec, stream, format,
4487 substream);
4488 else
4489 ret = -ENODEV;
4796 if (ret >= 0) 4490 if (ret >= 0)
4797 purify_inactive_streams(codec); 4491 purify_inactive_streams(codec);
4798 mutex_unlock(&codec->bus->prepare_mutex); 4492 mutex_unlock(&codec->bus->prepare_mutex);
@@ -4813,7 +4507,8 @@ void snd_hda_codec_cleanup(struct hda_codec *codec,
4813 struct snd_pcm_substream *substream) 4507 struct snd_pcm_substream *substream)
4814{ 4508{
4815 mutex_lock(&codec->bus->prepare_mutex); 4509 mutex_lock(&codec->bus->prepare_mutex);
4816 hinfo->ops.cleanup(hinfo, codec, substream); 4510 if (hinfo->ops.cleanup)
4511 hinfo->ops.cleanup(hinfo, codec, substream);
4817 mutex_unlock(&codec->bus->prepare_mutex); 4512 mutex_unlock(&codec->bus->prepare_mutex);
4818} 4513}
4819EXPORT_SYMBOL_GPL(snd_hda_codec_cleanup); 4514EXPORT_SYMBOL_GPL(snd_hda_codec_cleanup);
@@ -4871,112 +4566,84 @@ static int get_empty_pcm_device(struct hda_bus *bus, unsigned int type)
4871 return -EAGAIN; 4566 return -EAGAIN;
4872} 4567}
4873 4568
4874/* 4569/* call build_pcms ops of the given codec and set up the default parameters */
4875 * attach a new PCM stream 4570int snd_hda_codec_parse_pcms(struct hda_codec *codec)
4876 */
4877static int snd_hda_attach_pcm(struct hda_codec *codec, struct hda_pcm *pcm)
4878{ 4571{
4879 struct hda_bus *bus = codec->bus; 4572 struct hda_pcm *cpcm;
4880 struct hda_pcm_stream *info; 4573 int err;
4881 int stream, err;
4882 4574
4883 if (snd_BUG_ON(!pcm->name)) 4575 if (!list_empty(&codec->pcm_list_head))
4884 return -EINVAL; 4576 return 0; /* already parsed */
4885 for (stream = 0; stream < 2; stream++) { 4577
4886 info = &pcm->stream[stream]; 4578 if (!codec->patch_ops.build_pcms)
4887 if (info->substreams) { 4579 return 0;
4580
4581 err = codec->patch_ops.build_pcms(codec);
4582 if (err < 0) {
4583 codec_err(codec, "cannot build PCMs for #%d (error %d)\n",
4584 codec->addr, err);
4585 return err;
4586 }
4587
4588 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
4589 int stream;
4590
4591 for (stream = 0; stream < 2; stream++) {
4592 struct hda_pcm_stream *info = &cpcm->stream[stream];
4593
4594 if (!info->substreams)
4595 continue;
4888 err = set_pcm_default_values(codec, info); 4596 err = set_pcm_default_values(codec, info);
4889 if (err < 0) 4597 if (err < 0) {
4598 codec_warn(codec,
4599 "fail to setup default for PCM %s\n",
4600 cpcm->name);
4890 return err; 4601 return err;
4602 }
4891 } 4603 }
4892 } 4604 }
4893 return bus->ops.attach_pcm(bus, codec, pcm); 4605
4606 return 0;
4894} 4607}
4895 4608
4896/* assign all PCMs of the given codec */ 4609/* assign all PCMs of the given codec */
4897int snd_hda_codec_build_pcms(struct hda_codec *codec) 4610int snd_hda_codec_build_pcms(struct hda_codec *codec)
4898{ 4611{
4899 unsigned int pcm; 4612 struct hda_bus *bus = codec->bus;
4900 int err; 4613 struct hda_pcm *cpcm;
4614 int dev, err;
4901 4615
4902 if (!codec->num_pcms) { 4616 if (snd_BUG_ON(!bus->ops.attach_pcm))
4903 if (!codec->patch_ops.build_pcms) 4617 return -EINVAL;
4904 return 0; 4618
4905 err = codec->patch_ops.build_pcms(codec); 4619 err = snd_hda_codec_parse_pcms(codec);
4906 if (err < 0) { 4620 if (err < 0) {
4907 codec_err(codec, 4621 snd_hda_codec_reset(codec);
4908 "cannot build PCMs for #%d (error %d)\n", 4622 return err;
4909 codec->addr, err);
4910 err = snd_hda_codec_reset(codec);
4911 if (err < 0) {
4912 codec_err(codec,
4913 "cannot revert codec\n");
4914 return err;
4915 }
4916 }
4917 } 4623 }
4918 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
4919 struct hda_pcm *cpcm = &codec->pcm_info[pcm];
4920 int dev;
4921 4624
4625 /* attach a new PCM streams */
4626 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
4627 if (cpcm->pcm)
4628 continue; /* already attached */
4922 if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams) 4629 if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams)
4923 continue; /* no substreams assigned */ 4630 continue; /* no substreams assigned */
4924 4631
4925 if (!cpcm->pcm) { 4632 dev = get_empty_pcm_device(bus, cpcm->pcm_type);
4926 dev = get_empty_pcm_device(codec->bus, cpcm->pcm_type); 4633 if (dev < 0)
4927 if (dev < 0) 4634 continue; /* no fatal error */
4928 continue; /* no fatal error */ 4635 cpcm->device = dev;
4929 cpcm->device = dev; 4636 err = bus->ops.attach_pcm(bus, codec, cpcm);
4930 err = snd_hda_attach_pcm(codec, cpcm); 4637 if (err < 0) {
4931 if (err < 0) { 4638 codec_err(codec,
4932 codec_err(codec, 4639 "cannot attach PCM stream %d for codec #%d\n",
4933 "cannot attach PCM stream %d for codec #%d\n", 4640 dev, codec->addr);
4934 dev, codec->addr); 4641 continue; /* no fatal error */
4935 continue; /* no fatal error */
4936 }
4937 } 4642 }
4938 } 4643 }
4939 return 0;
4940}
4941 4644
4942/**
4943 * snd_hda_build_pcms - build PCM information
4944 * @bus: the BUS
4945 *
4946 * Create PCM information for each codec included in the bus.
4947 *
4948 * The build_pcms codec patch is requested to set up codec->num_pcms and
4949 * codec->pcm_info properly. The array is referred by the top-level driver
4950 * to create its PCM instances.
4951 * The allocated codec->pcm_info should be released in codec->patch_ops.free
4952 * callback.
4953 *
4954 * At least, substreams, channels_min and channels_max must be filled for
4955 * each stream. substreams = 0 indicates that the stream doesn't exist.
4956 * When rates and/or formats are zero, the supported values are queried
4957 * from the given nid. The nid is used also by the default ops.prepare
4958 * and ops.cleanup callbacks.
4959 *
4960 * The driver needs to call ops.open in its open callback. Similarly,
4961 * ops.close is supposed to be called in the close callback.
4962 * ops.prepare should be called in the prepare or hw_params callback
4963 * with the proper parameters for set up.
4964 * ops.cleanup should be called in hw_free for clean up of streams.
4965 *
4966 * This function returns 0 if successful, or a negative error code.
4967 */
4968int snd_hda_build_pcms(struct hda_bus *bus)
4969{
4970 struct hda_codec *codec;
4971
4972 list_for_each_entry(codec, &bus->codec_list, list) {
4973 int err = snd_hda_codec_build_pcms(codec);
4974 if (err < 0)
4975 return err;
4976 }
4977 return 0; 4645 return 0;
4978} 4646}
4979EXPORT_SYMBOL_GPL(snd_hda_build_pcms);
4980 4647
4981/** 4648/**
4982 * snd_hda_add_new_ctls - create controls from the array 4649 * snd_hda_add_new_ctls - create controls from the array
@@ -5029,127 +4696,70 @@ int snd_hda_add_new_ctls(struct hda_codec *codec,
5029EXPORT_SYMBOL_GPL(snd_hda_add_new_ctls); 4696EXPORT_SYMBOL_GPL(snd_hda_add_new_ctls);
5030 4697
5031#ifdef CONFIG_PM 4698#ifdef CONFIG_PM
5032static void hda_power_work(struct work_struct *work) 4699/**
4700 * snd_hda_power_up - Power-up the codec
4701 * @codec: HD-audio codec
4702 *
4703 * Increment the usage counter and resume the device if not done yet.
4704 */
4705void snd_hda_power_up(struct hda_codec *codec)
5033{ 4706{
5034 struct hda_codec *codec = 4707 struct device *dev = hda_codec_dev(codec);
5035 container_of(work, struct hda_codec, power_work.work);
5036 struct hda_bus *bus = codec->bus;
5037 unsigned int state;
5038 4708
5039 spin_lock(&codec->power_lock); 4709 if (codec_in_pm(codec))
5040 if (codec->power_transition > 0) { /* during power-up sequence? */
5041 spin_unlock(&codec->power_lock);
5042 return;
5043 }
5044 if (!codec->power_on || codec->power_count) {
5045 codec->power_transition = 0;
5046 spin_unlock(&codec->power_lock);
5047 return; 4710 return;
5048 } 4711 pm_runtime_get_sync(dev);
5049 spin_unlock(&codec->power_lock);
5050
5051 state = hda_call_codec_suspend(codec, true);
5052 if (!bus->power_keep_link_on && (state & AC_PWRST_CLK_STOP_OK))
5053 hda_call_pm_notify(codec, false);
5054} 4712}
4713EXPORT_SYMBOL_GPL(snd_hda_power_up);
5055 4714
5056static void hda_keep_power_on(struct hda_codec *codec) 4715/**
5057{ 4716 * snd_hda_power_down - Power-down the codec
5058 spin_lock(&codec->power_lock); 4717 * @codec: HD-audio codec
5059 codec->power_count++; 4718 *
5060 codec->power_on = 1; 4719 * Decrement the usage counter and schedules the autosuspend if none used.
5061 codec->power_jiffies = jiffies; 4720 */
5062 spin_unlock(&codec->power_lock); 4721void snd_hda_power_down(struct hda_codec *codec)
5063 hda_call_pm_notify(codec, true);
5064}
5065
5066/* update the power on/off account with the current jiffies */
5067void snd_hda_update_power_acct(struct hda_codec *codec)
5068{
5069 unsigned long delta = jiffies - codec->power_jiffies;
5070 if (codec->power_on)
5071 codec->power_on_acct += delta;
5072 else
5073 codec->power_off_acct += delta;
5074 codec->power_jiffies += delta;
5075}
5076
5077/* Transition to powered up, if wait_power_down then wait for a pending
5078 * transition to D3 to complete. A pending D3 transition is indicated
5079 * with power_transition == -1. */
5080/* call this with codec->power_lock held! */
5081static void __snd_hda_power_up(struct hda_codec *codec, bool wait_power_down)
5082{ 4722{
5083 /* Return if power_on or transitioning to power_on, unless currently 4723 struct device *dev = hda_codec_dev(codec);
5084 * powering down. */
5085 if ((codec->power_on || codec->power_transition > 0) &&
5086 !(wait_power_down && codec->power_transition < 0))
5087 return;
5088 spin_unlock(&codec->power_lock);
5089
5090 cancel_delayed_work_sync(&codec->power_work);
5091 4724
5092 spin_lock(&codec->power_lock); 4725 if (codec_in_pm(codec))
5093 /* If the power down delayed work was cancelled above before starting,
5094 * then there is no need to go through power up here.
5095 */
5096 if (codec->power_on) {
5097 if (codec->power_transition < 0)
5098 codec->power_transition = 0;
5099 return; 4726 return;
5100 } 4727 pm_runtime_mark_last_busy(dev);
5101 4728 pm_runtime_put_autosuspend(dev);
5102 trace_hda_power_up(codec);
5103 snd_hda_update_power_acct(codec);
5104 codec->power_on = 1;
5105 codec->power_jiffies = jiffies;
5106 codec->power_transition = 1; /* avoid reentrance */
5107 spin_unlock(&codec->power_lock);
5108
5109 hda_call_codec_resume(codec);
5110
5111 spin_lock(&codec->power_lock);
5112 codec->power_transition = 0;
5113} 4729}
4730EXPORT_SYMBOL_GPL(snd_hda_power_down);
5114 4731
5115#define power_save(codec) \ 4732static void codec_set_power_save(struct hda_codec *codec, int delay)
5116 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0)
5117
5118/* Transition to powered down */
5119static void __snd_hda_power_down(struct hda_codec *codec)
5120{ 4733{
5121 if (!codec->power_on || codec->power_count || codec->power_transition) 4734 struct device *dev = hda_codec_dev(codec);
5122 return;
5123 4735
5124 if (power_save(codec)) { 4736 if (delay > 0) {
5125 codec->power_transition = -1; /* avoid reentrance */ 4737 pm_runtime_set_autosuspend_delay(dev, delay);
5126 queue_delayed_work(codec->bus->workq, &codec->power_work, 4738 pm_runtime_use_autosuspend(dev);
5127 msecs_to_jiffies(power_save(codec) * 1000)); 4739 pm_runtime_allow(dev);
4740 if (!pm_runtime_suspended(dev))
4741 pm_runtime_mark_last_busy(dev);
4742 } else {
4743 pm_runtime_dont_use_autosuspend(dev);
4744 pm_runtime_forbid(dev);
5128 } 4745 }
5129} 4746}
5130 4747
5131/** 4748/**
5132 * snd_hda_power_save - Power-up/down/sync the codec 4749 * snd_hda_set_power_save - reprogram autosuspend for the given delay
5133 * @codec: HD-audio codec 4750 * @bus: HD-audio bus
5134 * @delta: the counter delta to change 4751 * @delay: autosuspend delay in msec, 0 = off
5135 * @d3wait: sync for D3 transition complete
5136 * 4752 *
5137 * Change the power-up counter via @delta, and power up or down the hardware 4753 * Synchronize the runtime PM autosuspend state from the power_save option.
5138 * appropriately. For the power-down, queue to the delayed action.
5139 * Passing zero to @delta means to synchronize the power state.
5140 */ 4754 */
5141void snd_hda_power_save(struct hda_codec *codec, int delta, bool d3wait) 4755void snd_hda_set_power_save(struct hda_bus *bus, int delay)
5142{ 4756{
5143 spin_lock(&codec->power_lock); 4757 struct hda_codec *c;
5144 codec->power_count += delta; 4758
5145 trace_hda_power_count(codec); 4759 list_for_each_entry(c, &bus->codec_list, list)
5146 if (delta > 0) 4760 codec_set_power_save(c, delay);
5147 __snd_hda_power_up(codec, d3wait);
5148 else
5149 __snd_hda_power_down(codec);
5150 spin_unlock(&codec->power_lock);
5151} 4761}
5152EXPORT_SYMBOL_GPL(snd_hda_power_save); 4762EXPORT_SYMBOL_GPL(snd_hda_set_power_save);
5153 4763
5154/** 4764/**
5155 * snd_hda_check_amp_list_power - Check the amp list and update the power 4765 * snd_hda_check_amp_list_power - Check the amp list and update the power
@@ -5203,88 +4813,6 @@ EXPORT_SYMBOL_GPL(snd_hda_check_amp_list_power);
5203#endif 4813#endif
5204 4814
5205/* 4815/*
5206 * Channel mode helper
5207 */
5208
5209/**
5210 * snd_hda_ch_mode_info - Info callback helper for the channel mode enum
5211 * @codec: the HDA codec
5212 * @uinfo: pointer to get/store the data
5213 * @chmode: channel mode array
5214 * @num_chmodes: channel mode array size
5215 */
5216int snd_hda_ch_mode_info(struct hda_codec *codec,
5217 struct snd_ctl_elem_info *uinfo,
5218 const struct hda_channel_mode *chmode,
5219 int num_chmodes)
5220{
5221 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5222 uinfo->count = 1;
5223 uinfo->value.enumerated.items = num_chmodes;
5224 if (uinfo->value.enumerated.item >= num_chmodes)
5225 uinfo->value.enumerated.item = num_chmodes - 1;
5226 sprintf(uinfo->value.enumerated.name, "%dch",
5227 chmode[uinfo->value.enumerated.item].channels);
5228 return 0;
5229}
5230EXPORT_SYMBOL_GPL(snd_hda_ch_mode_info);
5231
5232/**
5233 * snd_hda_ch_mode_get - Get callback helper for the channel mode enum
5234 * @codec: the HDA codec
5235 * @ucontrol: pointer to get/store the data
5236 * @chmode: channel mode array
5237 * @num_chmodes: channel mode array size
5238 * @max_channels: max number of channels
5239 */
5240int snd_hda_ch_mode_get(struct hda_codec *codec,
5241 struct snd_ctl_elem_value *ucontrol,
5242 const struct hda_channel_mode *chmode,
5243 int num_chmodes,
5244 int max_channels)
5245{
5246 int i;
5247
5248 for (i = 0; i < num_chmodes; i++) {
5249 if (max_channels == chmode[i].channels) {
5250 ucontrol->value.enumerated.item[0] = i;
5251 break;
5252 }
5253 }
5254 return 0;
5255}
5256EXPORT_SYMBOL_GPL(snd_hda_ch_mode_get);
5257
5258/**
5259 * snd_hda_ch_mode_put - Put callback helper for the channel mode enum
5260 * @codec: the HDA codec
5261 * @ucontrol: pointer to get/store the data
5262 * @chmode: channel mode array
5263 * @num_chmodes: channel mode array size
5264 * @max_channelsp: pointer to store the max channels
5265 */
5266int snd_hda_ch_mode_put(struct hda_codec *codec,
5267 struct snd_ctl_elem_value *ucontrol,
5268 const struct hda_channel_mode *chmode,
5269 int num_chmodes,
5270 int *max_channelsp)
5271{
5272 unsigned int mode;
5273
5274 mode = ucontrol->value.enumerated.item[0];
5275 if (mode >= num_chmodes)
5276 return -EINVAL;
5277 if (*max_channelsp == chmode[mode].channels)
5278 return 0;
5279 /* change the current channel setting */
5280 *max_channelsp = chmode[mode].channels;
5281 if (chmode[mode].sequence)
5282 snd_hda_sequence_write_cache(codec, chmode[mode].sequence);
5283 return 1;
5284}
5285EXPORT_SYMBOL_GPL(snd_hda_ch_mode_put);
5286
5287/*
5288 * input MUX helper 4816 * input MUX helper
5289 */ 4817 */
5290 4818
@@ -5418,24 +4946,6 @@ static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
5418} 4946}
5419 4947
5420/** 4948/**
5421 * snd_hda_bus_reboot_notify - call the reboot notifier of each codec
5422 * @bus: HD-audio bus
5423 */
5424void snd_hda_bus_reboot_notify(struct hda_bus *bus)
5425{
5426 struct hda_codec *codec;
5427
5428 if (!bus)
5429 return;
5430 list_for_each_entry(codec, &bus->codec_list, list) {
5431 if (hda_codec_is_power_on(codec) &&
5432 codec->patch_ops.reboot_notify)
5433 codec->patch_ops.reboot_notify(codec);
5434 }
5435}
5436EXPORT_SYMBOL_GPL(snd_hda_bus_reboot_notify);
5437
5438/**
5439 * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode 4949 * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode
5440 * @codec: the HDA codec 4950 * @codec: the HDA codec
5441 * @mout: hda_multi_out object 4951 * @mout: hda_multi_out object
@@ -5825,77 +5335,26 @@ int snd_hda_add_imux_item(struct hda_codec *codec,
5825} 5335}
5826EXPORT_SYMBOL_GPL(snd_hda_add_imux_item); 5336EXPORT_SYMBOL_GPL(snd_hda_add_imux_item);
5827 5337
5828
5829#ifdef CONFIG_PM
5830/*
5831 * power management
5832 */
5833
5834
5835static void hda_async_suspend(void *data, async_cookie_t cookie)
5836{
5837 hda_call_codec_suspend(data, false);
5838}
5839
5840static void hda_async_resume(void *data, async_cookie_t cookie)
5841{
5842 hda_call_codec_resume(data);
5843}
5844
5845/** 5338/**
5846 * snd_hda_suspend - suspend the codecs 5339 * snd_hda_bus_reset - Reset the bus
5847 * @bus: the HDA bus 5340 * @bus: HD-audio bus
5848 *
5849 * Returns 0 if successful.
5850 */ 5341 */
5851int snd_hda_suspend(struct hda_bus *bus) 5342void snd_hda_bus_reset(struct hda_bus *bus)
5852{ 5343{
5853 struct hda_codec *codec; 5344 struct hda_codec *codec;
5854 ASYNC_DOMAIN_EXCLUSIVE(domain);
5855 5345
5856 list_for_each_entry(codec, &bus->codec_list, list) { 5346 list_for_each_entry(codec, &bus->codec_list, list) {
5347 /* FIXME: maybe a better way needed for forced reset */
5857 cancel_delayed_work_sync(&codec->jackpoll_work); 5348 cancel_delayed_work_sync(&codec->jackpoll_work);
5349#ifdef CONFIG_PM
5858 if (hda_codec_is_power_on(codec)) { 5350 if (hda_codec_is_power_on(codec)) {
5859 if (bus->num_codecs > 1) 5351 hda_call_codec_suspend(codec);
5860 async_schedule_domain(hda_async_suspend, codec,
5861 &domain);
5862 else
5863 hda_call_codec_suspend(codec, false);
5864 }
5865 }
5866
5867 if (bus->num_codecs > 1)
5868 async_synchronize_full_domain(&domain);
5869
5870 return 0;
5871}
5872EXPORT_SYMBOL_GPL(snd_hda_suspend);
5873
5874/**
5875 * snd_hda_resume - resume the codecs
5876 * @bus: the HDA bus
5877 *
5878 * Returns 0 if successful.
5879 */
5880int snd_hda_resume(struct hda_bus *bus)
5881{
5882 struct hda_codec *codec;
5883 ASYNC_DOMAIN_EXCLUSIVE(domain);
5884
5885 list_for_each_entry(codec, &bus->codec_list, list) {
5886 if (bus->num_codecs > 1)
5887 async_schedule_domain(hda_async_resume, codec, &domain);
5888 else
5889 hda_call_codec_resume(codec); 5352 hda_call_codec_resume(codec);
5353 }
5354#endif
5890 } 5355 }
5891
5892 if (bus->num_codecs > 1)
5893 async_synchronize_full_domain(&domain);
5894
5895 return 0;
5896} 5356}
5897EXPORT_SYMBOL_GPL(snd_hda_resume); 5357EXPORT_SYMBOL_GPL(snd_hda_bus_reset);
5898#endif /* CONFIG_PM */
5899 5358
5900/* 5359/*
5901 * generic arrays 5360 * generic arrays
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 9c8820f21f94..ccf355d4a8fa 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -21,6 +21,7 @@
21#ifndef __SOUND_HDA_CODEC_H 21#ifndef __SOUND_HDA_CODEC_H
22#define __SOUND_HDA_CODEC_H 22#define __SOUND_HDA_CODEC_H
23 23
24#include <linux/kref.h>
24#include <sound/info.h> 25#include <sound/info.h>
25#include <sound/control.h> 26#include <sound/control.h>
26#include <sound/pcm.h> 27#include <sound/pcm.h>
@@ -66,7 +67,6 @@ struct hda_beep;
66struct hda_codec; 67struct hda_codec;
67struct hda_pcm; 68struct hda_pcm;
68struct hda_pcm_stream; 69struct hda_pcm_stream;
69struct hda_bus_unsolicited;
70 70
71/* NID type */ 71/* NID type */
72typedef u16 hda_nid_t; 72typedef u16 hda_nid_t;
@@ -84,10 +84,6 @@ struct hda_bus_ops {
84 struct hda_pcm *pcm); 84 struct hda_pcm *pcm);
85 /* reset bus for retry verb */ 85 /* reset bus for retry verb */
86 void (*bus_reset)(struct hda_bus *bus); 86 void (*bus_reset)(struct hda_bus *bus);
87#ifdef CONFIG_PM
88 /* notify power-up/down from codec to controller */
89 void (*pm_notify)(struct hda_bus *bus, bool power_up);
90#endif
91#ifdef CONFIG_SND_HDA_DSP_LOADER 87#ifdef CONFIG_SND_HDA_DSP_LOADER
92 /* prepare DSP transfer */ 88 /* prepare DSP transfer */
93 int (*load_dsp_prepare)(struct hda_bus *bus, unsigned int format, 89 int (*load_dsp_prepare)(struct hda_bus *bus, unsigned int format,
@@ -101,13 +97,14 @@ struct hda_bus_ops {
101#endif 97#endif
102}; 98};
103 99
104/* template to pass to the bus constructor */ 100/* unsolicited event handler */
105struct hda_bus_template { 101#define HDA_UNSOL_QUEUE_SIZE 64
106 void *private_data; 102struct hda_bus_unsolicited {
107 struct pci_dev *pci; 103 /* ring buffer */
108 const char *modelname; 104 u32 queue[HDA_UNSOL_QUEUE_SIZE * 2];
109 int *power_save; 105 unsigned int rp, wp;
110 struct hda_bus_ops ops; 106 /* workqueue */
107 struct work_struct work;
111}; 108};
112 109
113/* 110/*
@@ -119,11 +116,9 @@ struct hda_bus_template {
119struct hda_bus { 116struct hda_bus {
120 struct snd_card *card; 117 struct snd_card *card;
121 118
122 /* copied from template */
123 void *private_data; 119 void *private_data;
124 struct pci_dev *pci; 120 struct pci_dev *pci;
125 const char *modelname; 121 const char *modelname;
126 int *power_save;
127 struct hda_bus_ops ops; 122 struct hda_bus_ops ops;
128 123
129 /* codec linked list */ 124 /* codec linked list */
@@ -136,9 +131,7 @@ struct hda_bus {
136 struct mutex prepare_mutex; 131 struct mutex prepare_mutex;
137 132
138 /* unsolicited event queue */ 133 /* unsolicited event queue */
139 struct hda_bus_unsolicited *unsol; 134 struct hda_bus_unsolicited unsol;
140 char workq_name[16];
141 struct workqueue_struct *workq; /* common workqueue for codecs */
142 135
143 /* assigned PCMs */ 136 /* assigned PCMs */
144 DECLARE_BITMAP(pcm_dev_bits, SNDRV_PCM_DEVICES); 137 DECLARE_BITMAP(pcm_dev_bits, SNDRV_PCM_DEVICES);
@@ -152,10 +145,10 @@ struct hda_bus {
152 unsigned int rirb_error:1; /* error in codec communication */ 145 unsigned int rirb_error:1; /* error in codec communication */
153 unsigned int response_reset:1; /* controller was reset */ 146 unsigned int response_reset:1; /* controller was reset */
154 unsigned int in_reset:1; /* during reset operation */ 147 unsigned int in_reset:1; /* during reset operation */
155 unsigned int power_keep_link_on:1; /* don't power off HDA link */
156 unsigned int no_response_fallback:1; /* don't fallback at RIRB error */ 148 unsigned int no_response_fallback:1; /* don't fallback at RIRB error */
157 149
158 int primary_dig_out_type; /* primary digital out PCM type */ 150 int primary_dig_out_type; /* primary digital out PCM type */
151 unsigned long codec_powered; /* bit flags of powered codecs */
159}; 152};
160 153
161/* 154/*
@@ -175,15 +168,22 @@ struct hda_codec_preset {
175 int (*patch)(struct hda_codec *codec); 168 int (*patch)(struct hda_codec *codec);
176}; 169};
177 170
178struct hda_codec_preset_list { 171#define HDA_CODEC_ID_GENERIC_HDMI 0x00000101
172#define HDA_CODEC_ID_GENERIC 0x00000201
173
174struct hda_codec_driver {
175 struct device_driver driver;
179 const struct hda_codec_preset *preset; 176 const struct hda_codec_preset *preset;
180 struct module *owner;
181 struct list_head list;
182}; 177};
183 178
184/* initial hook */ 179int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name,
185int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset); 180 struct module *owner);
186int snd_hda_delete_codec_preset(struct hda_codec_preset_list *preset); 181#define hda_codec_driver_register(drv) \
182 __hda_codec_driver_register(drv, KBUILD_MODNAME, THIS_MODULE)
183void hda_codec_driver_unregister(struct hda_codec_driver *drv);
184#define module_hda_codec_driver(drv) \
185 module_driver(drv, hda_codec_driver_register, \
186 hda_codec_driver_unregister)
187 187
188/* ops set by the preset patch */ 188/* ops set by the preset patch */
189struct hda_codec_ops { 189struct hda_codec_ops {
@@ -200,6 +200,7 @@ struct hda_codec_ops {
200 int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid); 200 int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid);
201#endif 201#endif
202 void (*reboot_notify)(struct hda_codec *codec); 202 void (*reboot_notify)(struct hda_codec *codec);
203 void (*stream_pm)(struct hda_codec *codec, hda_nid_t nid, bool on);
203}; 204};
204 205
205/* record for amp information cache */ 206/* record for amp information cache */
@@ -267,12 +268,17 @@ struct hda_pcm {
267 int device; /* device number to assign */ 268 int device; /* device number to assign */
268 struct snd_pcm *pcm; /* assigned PCM instance */ 269 struct snd_pcm *pcm; /* assigned PCM instance */
269 bool own_chmap; /* codec driver provides own channel maps */ 270 bool own_chmap; /* codec driver provides own channel maps */
271 /* private: */
272 struct hda_codec *codec;
273 struct kref kref;
274 struct list_head list;
270}; 275};
271 276
272/* codec information */ 277/* codec information */
273struct hda_codec { 278struct hda_codec {
274 struct device dev; 279 struct device dev;
275 struct hda_bus *bus; 280 struct hda_bus *bus;
281 struct snd_card *card;
276 unsigned int addr; /* codec addr*/ 282 unsigned int addr; /* codec addr*/
277 struct list_head list; /* list point */ 283 struct list_head list; /* list point */
278 284
@@ -287,11 +293,10 @@ struct hda_codec {
287 u32 vendor_id; 293 u32 vendor_id;
288 u32 subsystem_id; 294 u32 subsystem_id;
289 u32 revision_id; 295 u32 revision_id;
296 u32 probe_id; /* overridden id for probing */
290 297
291 /* detected preset */ 298 /* detected preset */
292 const struct hda_codec_preset *preset; 299 const struct hda_codec_preset *preset;
293 struct module *owner;
294 int (*parser)(struct hda_codec *codec);
295 const char *vendor_name; /* codec vendor name */ 300 const char *vendor_name; /* codec vendor name */
296 const char *chip_name; /* codec chip name */ 301 const char *chip_name; /* codec chip name */
297 const char *modelname; /* model name for preset */ 302 const char *modelname; /* model name for preset */
@@ -300,8 +305,7 @@ struct hda_codec {
300 struct hda_codec_ops patch_ops; 305 struct hda_codec_ops patch_ops;
301 306
302 /* PCM to create, set by patch_ops.build_pcms callback */ 307 /* PCM to create, set by patch_ops.build_pcms callback */
303 unsigned int num_pcms; 308 struct list_head pcm_list_head;
304 struct hda_pcm *pcm_info;
305 309
306 /* codec specific info */ 310 /* codec specific info */
307 void *spec; 311 void *spec;
@@ -345,6 +349,7 @@ struct hda_codec {
345#endif 349#endif
346 350
347 /* misc flags */ 351 /* misc flags */
352 unsigned int in_freeing:1; /* being released */
348 unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each 353 unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each
349 * status change 354 * status change
350 * (e.g. Realtek codecs) 355 * (e.g. Realtek codecs)
@@ -366,18 +371,13 @@ struct hda_codec {
366 unsigned int cached_write:1; /* write only to caches */ 371 unsigned int cached_write:1; /* write only to caches */
367 unsigned int dp_mst:1; /* support DP1.2 Multi-stream transport */ 372 unsigned int dp_mst:1; /* support DP1.2 Multi-stream transport */
368 unsigned int dump_coef:1; /* dump processing coefs in codec proc file */ 373 unsigned int dump_coef:1; /* dump processing coefs in codec proc file */
374 unsigned int power_save_node:1; /* advanced PM for each widget */
369#ifdef CONFIG_PM 375#ifdef CONFIG_PM
370 unsigned int power_on :1; /* current (global) power-state */
371 unsigned int d3_stop_clk:1; /* support D3 operation without BCLK */ 376 unsigned int d3_stop_clk:1; /* support D3 operation without BCLK */
372 unsigned int pm_up_notified:1; /* PM notified to controller */ 377 atomic_t in_pm; /* suspend/resume being performed */
373 unsigned int in_pm:1; /* suspend/resume being performed */
374 int power_transition; /* power-state in transition */
375 int power_count; /* current (global) power refcount */
376 struct delayed_work power_work; /* delayed task for powerdown */
377 unsigned long power_on_acct; 378 unsigned long power_on_acct;
378 unsigned long power_off_acct; 379 unsigned long power_off_acct;
379 unsigned long power_jiffies; 380 unsigned long power_jiffies;
380 spinlock_t power_lock;
381#endif 381#endif
382 382
383 /* filter the requested power state per nid */ 383 /* filter the requested power state per nid */
@@ -409,6 +409,11 @@ struct hda_codec {
409 struct snd_array verbs; 409 struct snd_array verbs;
410}; 410};
411 411
412#define dev_to_hda_codec(_dev) container_of(_dev, struct hda_codec, dev)
413#define hda_codec_dev(_dev) (&(_dev)->dev)
414
415extern struct bus_type snd_hda_bus_type;
416
412/* direction */ 417/* direction */
413enum { 418enum {
414 HDA_INPUT, HDA_OUTPUT 419 HDA_INPUT, HDA_OUTPUT
@@ -420,10 +425,9 @@ enum {
420/* 425/*
421 * constructors 426 * constructors
422 */ 427 */
423int snd_hda_bus_new(struct snd_card *card, const struct hda_bus_template *temp, 428int snd_hda_bus_new(struct snd_card *card, struct hda_bus **busp);
424 struct hda_bus **busp); 429int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card,
425int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr, 430 unsigned int codec_addr, struct hda_codec **codecp);
426 struct hda_codec **codecp);
427int snd_hda_codec_configure(struct hda_codec *codec); 431int snd_hda_codec_configure(struct hda_codec *codec);
428int snd_hda_codec_update_widgets(struct hda_codec *codec); 432int snd_hda_codec_update_widgets(struct hda_codec *codec);
429 433
@@ -512,15 +516,24 @@ void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid);
512/* 516/*
513 * Mixer 517 * Mixer
514 */ 518 */
515int snd_hda_build_controls(struct hda_bus *bus);
516int snd_hda_codec_build_controls(struct hda_codec *codec); 519int snd_hda_codec_build_controls(struct hda_codec *codec);
517 520
518/* 521/*
519 * PCM 522 * PCM
520 */ 523 */
521int snd_hda_build_pcms(struct hda_bus *bus); 524int snd_hda_codec_parse_pcms(struct hda_codec *codec);
522int snd_hda_codec_build_pcms(struct hda_codec *codec); 525int snd_hda_codec_build_pcms(struct hda_codec *codec);
523 526
527__printf(2, 3)
528struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec,
529 const char *fmt, ...);
530
531static inline void snd_hda_codec_pcm_get(struct hda_pcm *pcm)
532{
533 kref_get(&pcm->kref);
534}
535void snd_hda_codec_pcm_put(struct hda_pcm *pcm);
536
524int snd_hda_codec_prepare(struct hda_codec *codec, 537int snd_hda_codec_prepare(struct hda_codec *codec,
525 struct hda_pcm_stream *hinfo, 538 struct hda_pcm_stream *hinfo,
526 unsigned int stream, 539 unsigned int stream,
@@ -552,20 +565,17 @@ extern const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[];
552 * Misc 565 * Misc
553 */ 566 */
554void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen); 567void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen);
555void snd_hda_bus_reboot_notify(struct hda_bus *bus);
556void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, 568void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg,
557 unsigned int power_state); 569 unsigned int power_state);
558 570
559int snd_hda_lock_devices(struct hda_bus *bus); 571int snd_hda_lock_devices(struct hda_bus *bus);
560void snd_hda_unlock_devices(struct hda_bus *bus); 572void snd_hda_unlock_devices(struct hda_bus *bus);
573void snd_hda_bus_reset(struct hda_bus *bus);
561 574
562/* 575/*
563 * power management 576 * power management
564 */ 577 */
565#ifdef CONFIG_PM 578extern const struct dev_pm_ops hda_codec_driver_pm;
566int snd_hda_suspend(struct hda_bus *bus);
567int snd_hda_resume(struct hda_bus *bus);
568#endif
569 579
570static inline 580static inline
571int hda_call_check_power_status(struct hda_codec *codec, hda_nid_t nid) 581int hda_call_check_power_status(struct hda_codec *codec, hda_nid_t nid)
@@ -588,64 +598,16 @@ const char *snd_hda_get_jack_location(u32 cfg);
588 * power saving 598 * power saving
589 */ 599 */
590#ifdef CONFIG_PM 600#ifdef CONFIG_PM
591void snd_hda_power_save(struct hda_codec *codec, int delta, bool d3wait); 601void snd_hda_power_up(struct hda_codec *codec);
602void snd_hda_power_down(struct hda_codec *codec);
603void snd_hda_set_power_save(struct hda_bus *bus, int delay);
592void snd_hda_update_power_acct(struct hda_codec *codec); 604void snd_hda_update_power_acct(struct hda_codec *codec);
593#else 605#else
594static inline void snd_hda_power_save(struct hda_codec *codec, int delta, 606static inline void snd_hda_power_up(struct hda_codec *codec) {}
595 bool d3wait) {} 607static inline void snd_hda_power_down(struct hda_codec *codec) {}
608static inline void snd_hda_set_power_save(struct hda_bus *bus, int delay) {}
596#endif 609#endif
597 610
598/**
599 * snd_hda_power_up - Power-up the codec
600 * @codec: HD-audio codec
601 *
602 * Increment the power-up counter and power up the hardware really when
603 * not turned on yet.
604 */
605static inline void snd_hda_power_up(struct hda_codec *codec)
606{
607 snd_hda_power_save(codec, 1, false);
608}
609
610/**
611 * snd_hda_power_up_d3wait - Power-up the codec after waiting for any pending
612 * D3 transition to complete. This differs from snd_hda_power_up() when
613 * power_transition == -1. snd_hda_power_up sees this case as a nop,
614 * snd_hda_power_up_d3wait waits for the D3 transition to complete then powers
615 * back up.
616 * @codec: HD-audio codec
617 *
618 * Cancel any power down operation hapenning on the work queue, then power up.
619 */
620static inline void snd_hda_power_up_d3wait(struct hda_codec *codec)
621{
622 snd_hda_power_save(codec, 1, true);
623}
624
625/**
626 * snd_hda_power_down - Power-down the codec
627 * @codec: HD-audio codec
628 *
629 * Decrement the power-up counter and schedules the power-off work if
630 * the counter rearches to zero.
631 */
632static inline void snd_hda_power_down(struct hda_codec *codec)
633{
634 snd_hda_power_save(codec, -1, false);
635}
636
637/**
638 * snd_hda_power_sync - Synchronize the power-save status
639 * @codec: HD-audio codec
640 *
641 * Synchronize the actual power state with the power account;
642 * called when power_save parameter is changed
643 */
644static inline void snd_hda_power_sync(struct hda_codec *codec)
645{
646 snd_hda_power_save(codec, 0, false);
647}
648
649#ifdef CONFIG_SND_HDA_PATCH_LOADER 611#ifdef CONFIG_SND_HDA_PATCH_LOADER
650/* 612/*
651 * patch firmware 613 * patch firmware
diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c
index 17c2637d842c..4fd0b2ef26e9 100644
--- a/sound/pci/hda/hda_controller.c
+++ b/sound/pci/hda/hda_controller.c
@@ -27,10 +27,8 @@
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/pm_runtime.h> 28#include <linux/pm_runtime.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/reboot.h>
31#include <sound/core.h> 30#include <sound/core.h>
32#include <sound/initval.h> 31#include <sound/initval.h>
33#include "hda_priv.h"
34#include "hda_controller.h" 32#include "hda_controller.h"
35 33
36#define CREATE_TRACE_POINTS 34#define CREATE_TRACE_POINTS
@@ -259,11 +257,18 @@ static void azx_timecounter_init(struct snd_pcm_substream *substream,
259 tc->cycle_last = last; 257 tc->cycle_last = last;
260} 258}
261 259
260static inline struct hda_pcm_stream *
261to_hda_pcm_stream(struct snd_pcm_substream *substream)
262{
263 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
264 return &apcm->info->stream[substream->stream];
265}
266
262static u64 azx_adjust_codec_delay(struct snd_pcm_substream *substream, 267static u64 azx_adjust_codec_delay(struct snd_pcm_substream *substream,
263 u64 nsec) 268 u64 nsec)
264{ 269{
265 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 270 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
266 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 271 struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream);
267 u64 codec_frames, codec_nsecs; 272 u64 codec_frames, codec_nsecs;
268 273
269 if (!hinfo->ops.get_delay) 274 if (!hinfo->ops.get_delay)
@@ -399,7 +404,7 @@ static int azx_setup_periods(struct azx *chip,
399static int azx_pcm_close(struct snd_pcm_substream *substream) 404static int azx_pcm_close(struct snd_pcm_substream *substream)
400{ 405{
401 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 406 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
402 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 407 struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream);
403 struct azx *chip = apcm->chip; 408 struct azx *chip = apcm->chip;
404 struct azx_dev *azx_dev = get_azx_dev(substream); 409 struct azx_dev *azx_dev = get_azx_dev(substream);
405 unsigned long flags; 410 unsigned long flags;
@@ -410,9 +415,11 @@ static int azx_pcm_close(struct snd_pcm_substream *substream)
410 azx_dev->running = 0; 415 azx_dev->running = 0;
411 spin_unlock_irqrestore(&chip->reg_lock, flags); 416 spin_unlock_irqrestore(&chip->reg_lock, flags);
412 azx_release_device(azx_dev); 417 azx_release_device(azx_dev);
413 hinfo->ops.close(hinfo, apcm->codec, substream); 418 if (hinfo->ops.close)
419 hinfo->ops.close(hinfo, apcm->codec, substream);
414 snd_hda_power_down(apcm->codec); 420 snd_hda_power_down(apcm->codec);
415 mutex_unlock(&chip->open_mutex); 421 mutex_unlock(&chip->open_mutex);
422 snd_hda_codec_pcm_put(apcm->info);
416 return 0; 423 return 0;
417} 424}
418 425
@@ -441,7 +448,7 @@ static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
441 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 448 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
442 struct azx_dev *azx_dev = get_azx_dev(substream); 449 struct azx_dev *azx_dev = get_azx_dev(substream);
443 struct azx *chip = apcm->chip; 450 struct azx *chip = apcm->chip;
444 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 451 struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream);
445 int err; 452 int err;
446 453
447 /* reset BDL address */ 454 /* reset BDL address */
@@ -468,7 +475,7 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
468 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 475 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
469 struct azx *chip = apcm->chip; 476 struct azx *chip = apcm->chip;
470 struct azx_dev *azx_dev = get_azx_dev(substream); 477 struct azx_dev *azx_dev = get_azx_dev(substream);
471 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 478 struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream);
472 struct snd_pcm_runtime *runtime = substream->runtime; 479 struct snd_pcm_runtime *runtime = substream->runtime;
473 unsigned int bufsize, period_bytes, format_val, stream_tag; 480 unsigned int bufsize, period_bytes, format_val, stream_tag;
474 int err; 481 int err;
@@ -708,7 +715,7 @@ unsigned int azx_get_position(struct azx *chip,
708 715
709 if (substream->runtime) { 716 if (substream->runtime) {
710 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 717 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
711 struct hda_pcm_stream *hinfo = apcm->hinfo[stream]; 718 struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream);
712 719
713 if (chip->get_delay[stream]) 720 if (chip->get_delay[stream])
714 delay += chip->get_delay[stream](chip, azx_dev, pos); 721 delay += chip->get_delay[stream](chip, azx_dev, pos);
@@ -732,17 +739,32 @@ static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
732 azx_get_position(chip, azx_dev)); 739 azx_get_position(chip, azx_dev));
733} 740}
734 741
735static int azx_get_wallclock_tstamp(struct snd_pcm_substream *substream, 742static int azx_get_time_info(struct snd_pcm_substream *substream,
736 struct timespec *ts) 743 struct timespec *system_ts, struct timespec *audio_ts,
744 struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
745 struct snd_pcm_audio_tstamp_report *audio_tstamp_report)
737{ 746{
738 struct azx_dev *azx_dev = get_azx_dev(substream); 747 struct azx_dev *azx_dev = get_azx_dev(substream);
739 u64 nsec; 748 u64 nsec;
740 749
741 nsec = timecounter_read(&azx_dev->azx_tc); 750 if ((substream->runtime->hw.info & SNDRV_PCM_INFO_HAS_LINK_ATIME) &&
742 nsec = div_u64(nsec, 3); /* can be optimized */ 751 (audio_tstamp_config->type_requested == SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK)) {
743 nsec = azx_adjust_codec_delay(substream, nsec); 752
753 snd_pcm_gettime(substream->runtime, system_ts);
744 754
745 *ts = ns_to_timespec(nsec); 755 nsec = timecounter_read(&azx_dev->azx_tc);
756 nsec = div_u64(nsec, 3); /* can be optimized */
757 if (audio_tstamp_config->report_delay)
758 nsec = azx_adjust_codec_delay(substream, nsec);
759
760 *audio_ts = ns_to_timespec(nsec);
761
762 audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK;
763 audio_tstamp_report->accuracy_report = 1; /* rest of structure is valid */
764 audio_tstamp_report->accuracy = 42; /* 24 MHz WallClock == 42ns resolution */
765
766 } else
767 audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT;
746 768
747 return 0; 769 return 0;
748} 770}
@@ -756,7 +778,8 @@ static struct snd_pcm_hardware azx_pcm_hw = {
756 /* SNDRV_PCM_INFO_RESUME |*/ 778 /* SNDRV_PCM_INFO_RESUME |*/
757 SNDRV_PCM_INFO_PAUSE | 779 SNDRV_PCM_INFO_PAUSE |
758 SNDRV_PCM_INFO_SYNC_START | 780 SNDRV_PCM_INFO_SYNC_START |
759 SNDRV_PCM_INFO_HAS_WALL_CLOCK | 781 SNDRV_PCM_INFO_HAS_WALL_CLOCK | /* legacy */
782 SNDRV_PCM_INFO_HAS_LINK_ATIME |
760 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP), 783 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP),
761 .formats = SNDRV_PCM_FMTBIT_S16_LE, 784 .formats = SNDRV_PCM_FMTBIT_S16_LE,
762 .rates = SNDRV_PCM_RATE_48000, 785 .rates = SNDRV_PCM_RATE_48000,
@@ -775,7 +798,7 @@ static struct snd_pcm_hardware azx_pcm_hw = {
775static int azx_pcm_open(struct snd_pcm_substream *substream) 798static int azx_pcm_open(struct snd_pcm_substream *substream)
776{ 799{
777 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 800 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
778 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 801 struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream);
779 struct azx *chip = apcm->chip; 802 struct azx *chip = apcm->chip;
780 struct azx_dev *azx_dev; 803 struct azx_dev *azx_dev;
781 struct snd_pcm_runtime *runtime = substream->runtime; 804 struct snd_pcm_runtime *runtime = substream->runtime;
@@ -783,11 +806,12 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
783 int err; 806 int err;
784 int buff_step; 807 int buff_step;
785 808
809 snd_hda_codec_pcm_get(apcm->info);
786 mutex_lock(&chip->open_mutex); 810 mutex_lock(&chip->open_mutex);
787 azx_dev = azx_assign_device(chip, substream); 811 azx_dev = azx_assign_device(chip, substream);
788 if (azx_dev == NULL) { 812 if (azx_dev == NULL) {
789 mutex_unlock(&chip->open_mutex); 813 err = -EBUSY;
790 return -EBUSY; 814 goto unlock;
791 } 815 }
792 runtime->hw = azx_pcm_hw; 816 runtime->hw = azx_pcm_hw;
793 runtime->hw.channels_min = hinfo->channels_min; 817 runtime->hw.channels_min = hinfo->channels_min;
@@ -821,13 +845,14 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
821 buff_step); 845 buff_step);
822 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 846 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
823 buff_step); 847 buff_step);
824 snd_hda_power_up_d3wait(apcm->codec); 848 snd_hda_power_up(apcm->codec);
825 err = hinfo->ops.open(hinfo, apcm->codec, substream); 849 if (hinfo->ops.open)
850 err = hinfo->ops.open(hinfo, apcm->codec, substream);
851 else
852 err = -ENODEV;
826 if (err < 0) { 853 if (err < 0) {
827 azx_release_device(azx_dev); 854 azx_release_device(azx_dev);
828 snd_hda_power_down(apcm->codec); 855 goto powerdown;
829 mutex_unlock(&chip->open_mutex);
830 return err;
831 } 856 }
832 snd_pcm_limit_hw_rates(runtime); 857 snd_pcm_limit_hw_rates(runtime);
833 /* sanity check */ 858 /* sanity check */
@@ -836,16 +861,18 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
836 snd_BUG_ON(!runtime->hw.formats) || 861 snd_BUG_ON(!runtime->hw.formats) ||
837 snd_BUG_ON(!runtime->hw.rates)) { 862 snd_BUG_ON(!runtime->hw.rates)) {
838 azx_release_device(azx_dev); 863 azx_release_device(azx_dev);
839 hinfo->ops.close(hinfo, apcm->codec, substream); 864 if (hinfo->ops.close)
840 snd_hda_power_down(apcm->codec); 865 hinfo->ops.close(hinfo, apcm->codec, substream);
841 mutex_unlock(&chip->open_mutex); 866 err = -EINVAL;
842 return -EINVAL; 867 goto powerdown;
843 } 868 }
844 869
845 /* disable WALLCLOCK timestamps for capture streams 870 /* disable LINK_ATIME timestamps for capture streams
846 until we figure out how to handle digital inputs */ 871 until we figure out how to handle digital inputs */
847 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) 872 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
848 runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK; 873 runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK; /* legacy */
874 runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_LINK_ATIME;
875 }
849 876
850 spin_lock_irqsave(&chip->reg_lock, flags); 877 spin_lock_irqsave(&chip->reg_lock, flags);
851 azx_dev->substream = substream; 878 azx_dev->substream = substream;
@@ -856,6 +883,13 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
856 snd_pcm_set_sync(substream); 883 snd_pcm_set_sync(substream);
857 mutex_unlock(&chip->open_mutex); 884 mutex_unlock(&chip->open_mutex);
858 return 0; 885 return 0;
886
887 powerdown:
888 snd_hda_power_down(apcm->codec);
889 unlock:
890 mutex_unlock(&chip->open_mutex);
891 snd_hda_codec_pcm_put(apcm->info);
892 return err;
859} 893}
860 894
861static int azx_pcm_mmap(struct snd_pcm_substream *substream, 895static int azx_pcm_mmap(struct snd_pcm_substream *substream,
@@ -877,7 +911,7 @@ static struct snd_pcm_ops azx_pcm_ops = {
877 .prepare = azx_pcm_prepare, 911 .prepare = azx_pcm_prepare,
878 .trigger = azx_pcm_trigger, 912 .trigger = azx_pcm_trigger,
879 .pointer = azx_pcm_pointer, 913 .pointer = azx_pcm_pointer,
880 .wall_clock = azx_get_wallclock_tstamp, 914 .get_time_info = azx_get_time_info,
881 .mmap = azx_pcm_mmap, 915 .mmap = azx_pcm_mmap,
882 .page = snd_pcm_sgbuf_ops_page, 916 .page = snd_pcm_sgbuf_ops_page,
883}; 917};
@@ -887,6 +921,7 @@ static void azx_pcm_free(struct snd_pcm *pcm)
887 struct azx_pcm *apcm = pcm->private_data; 921 struct azx_pcm *apcm = pcm->private_data;
888 if (apcm) { 922 if (apcm) {
889 list_del(&apcm->list); 923 list_del(&apcm->list);
924 apcm->info->pcm = NULL;
890 kfree(apcm); 925 kfree(apcm);
891 } 926 }
892} 927}
@@ -923,6 +958,7 @@ static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
923 apcm->chip = chip; 958 apcm->chip = chip;
924 apcm->pcm = pcm; 959 apcm->pcm = pcm;
925 apcm->codec = codec; 960 apcm->codec = codec;
961 apcm->info = cpcm;
926 pcm->private_data = apcm; 962 pcm->private_data = apcm;
927 pcm->private_free = azx_pcm_free; 963 pcm->private_free = azx_pcm_free;
928 if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM) 964 if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM)
@@ -930,7 +966,6 @@ static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
930 list_add_tail(&apcm->list, &chip->pcm_list); 966 list_add_tail(&apcm->list, &chip->pcm_list);
931 cpcm->pcm = pcm; 967 cpcm->pcm = pcm;
932 for (s = 0; s < 2; s++) { 968 for (s = 0; s < 2; s++) {
933 apcm->hinfo[s] = &cpcm->stream[s];
934 if (cpcm->stream[s].substreams) 969 if (cpcm->stream[s].substreams)
935 snd_pcm_set_ops(pcm, s, &azx_pcm_ops); 970 snd_pcm_set_ops(pcm, s, &azx_pcm_ops);
936 } 971 }
@@ -941,9 +976,6 @@ static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
941 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 976 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
942 chip->card->dev, 977 chip->card->dev,
943 size, MAX_PREALLOC_SIZE); 978 size, MAX_PREALLOC_SIZE);
944 /* link to codec */
945 for (s = 0; s < 2; s++)
946 pcm->streams[s].dev.parent = &codec->dev;
947 return 0; 979 return 0;
948} 980}
949 981
@@ -952,14 +984,9 @@ static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
952 */ 984 */
953static int azx_alloc_cmd_io(struct azx *chip) 985static int azx_alloc_cmd_io(struct azx *chip)
954{ 986{
955 int err;
956
957 /* single page (at least 4096 bytes) must suffice for both ringbuffes */ 987 /* single page (at least 4096 bytes) must suffice for both ringbuffes */
958 err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV, 988 return chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
959 PAGE_SIZE, &chip->rb); 989 PAGE_SIZE, &chip->rb);
960 if (err < 0)
961 dev_err(chip->card->dev, "cannot allocate CORB/RIRB\n");
962 return err;
963} 990}
964 991
965static void azx_init_cmd_io(struct azx *chip) 992static void azx_init_cmd_io(struct azx *chip)
@@ -1445,7 +1472,6 @@ static void azx_load_dsp_cleanup(struct hda_bus *bus,
1445int azx_alloc_stream_pages(struct azx *chip) 1472int azx_alloc_stream_pages(struct azx *chip)
1446{ 1473{
1447 int i, err; 1474 int i, err;
1448 struct snd_card *card = chip->card;
1449 1475
1450 for (i = 0; i < chip->num_streams; i++) { 1476 for (i = 0; i < chip->num_streams; i++) {
1451 dsp_lock_init(&chip->azx_dev[i]); 1477 dsp_lock_init(&chip->azx_dev[i]);
@@ -1453,18 +1479,14 @@ int azx_alloc_stream_pages(struct azx *chip)
1453 err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV, 1479 err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
1454 BDL_SIZE, 1480 BDL_SIZE,
1455 &chip->azx_dev[i].bdl); 1481 &chip->azx_dev[i].bdl);
1456 if (err < 0) { 1482 if (err < 0)
1457 dev_err(card->dev, "cannot allocate BDL\n");
1458 return -ENOMEM; 1483 return -ENOMEM;
1459 }
1460 } 1484 }
1461 /* allocate memory for the position buffer */ 1485 /* allocate memory for the position buffer */
1462 err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV, 1486 err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
1463 chip->num_streams * 8, &chip->posbuf); 1487 chip->num_streams * 8, &chip->posbuf);
1464 if (err < 0) { 1488 if (err < 0)
1465 dev_err(card->dev, "cannot allocate posbuf\n");
1466 return -ENOMEM; 1489 return -ENOMEM;
1467 }
1468 1490
1469 /* allocate CORB/RIRB */ 1491 /* allocate CORB/RIRB */
1470 err = azx_alloc_cmd_io(chip); 1492 err = azx_alloc_cmd_io(chip);
@@ -1676,7 +1698,7 @@ irqreturn_t azx_interrupt(int irq, void *dev_id)
1676 int i; 1698 int i;
1677 1699
1678#ifdef CONFIG_PM 1700#ifdef CONFIG_PM
1679 if (chip->driver_caps & AZX_DCAPS_PM_RUNTIME) 1701 if (azx_has_pm_runtime(chip))
1680 if (!pm_runtime_active(chip->card->dev)) 1702 if (!pm_runtime_active(chip->card->dev))
1681 return IRQ_NONE; 1703 return IRQ_NONE;
1682#endif 1704#endif
@@ -1761,34 +1783,11 @@ static void azx_bus_reset(struct hda_bus *bus)
1761 bus->in_reset = 1; 1783 bus->in_reset = 1;
1762 azx_stop_chip(chip); 1784 azx_stop_chip(chip);
1763 azx_init_chip(chip, true); 1785 azx_init_chip(chip, true);
1764#ifdef CONFIG_PM 1786 if (chip->initialized)
1765 if (chip->initialized) { 1787 snd_hda_bus_reset(chip->bus);
1766 struct azx_pcm *p;
1767 list_for_each_entry(p, &chip->pcm_list, list)
1768 snd_pcm_suspend_all(p->pcm);
1769 snd_hda_suspend(chip->bus);
1770 snd_hda_resume(chip->bus);
1771 }
1772#endif
1773 bus->in_reset = 0; 1788 bus->in_reset = 0;
1774} 1789}
1775 1790
1776#ifdef CONFIG_PM
1777/* power-up/down the controller */
1778static void azx_power_notify(struct hda_bus *bus, bool power_up)
1779{
1780 struct azx *chip = bus->private_data;
1781
1782 if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME))
1783 return;
1784
1785 if (power_up)
1786 pm_runtime_get_sync(chip->card->dev);
1787 else
1788 pm_runtime_put_sync(chip->card->dev);
1789}
1790#endif
1791
1792static int get_jackpoll_interval(struct azx *chip) 1791static int get_jackpoll_interval(struct azx *chip)
1793{ 1792{
1794 int i; 1793 int i;
@@ -1810,41 +1809,59 @@ static int get_jackpoll_interval(struct azx *chip)
1810 return j; 1809 return j;
1811} 1810}
1812 1811
1813/* Codec initialization */ 1812static struct hda_bus_ops bus_ops = {
1814int azx_codec_create(struct azx *chip, const char *model, 1813 .command = azx_send_cmd,
1815 unsigned int max_slots, 1814 .get_response = azx_get_response,
1816 int *power_save_to) 1815 .attach_pcm = azx_attach_pcm_stream,
1817{ 1816 .bus_reset = azx_bus_reset,
1818 struct hda_bus_template bus_temp;
1819 int c, codecs, err;
1820
1821 memset(&bus_temp, 0, sizeof(bus_temp));
1822 bus_temp.private_data = chip;
1823 bus_temp.modelname = model;
1824 bus_temp.pci = chip->pci;
1825 bus_temp.ops.command = azx_send_cmd;
1826 bus_temp.ops.get_response = azx_get_response;
1827 bus_temp.ops.attach_pcm = azx_attach_pcm_stream;
1828 bus_temp.ops.bus_reset = azx_bus_reset;
1829#ifdef CONFIG_PM
1830 bus_temp.power_save = power_save_to;
1831 bus_temp.ops.pm_notify = azx_power_notify;
1832#endif
1833#ifdef CONFIG_SND_HDA_DSP_LOADER 1817#ifdef CONFIG_SND_HDA_DSP_LOADER
1834 bus_temp.ops.load_dsp_prepare = azx_load_dsp_prepare; 1818 .load_dsp_prepare = azx_load_dsp_prepare,
1835 bus_temp.ops.load_dsp_trigger = azx_load_dsp_trigger; 1819 .load_dsp_trigger = azx_load_dsp_trigger,
1836 bus_temp.ops.load_dsp_cleanup = azx_load_dsp_cleanup; 1820 .load_dsp_cleanup = azx_load_dsp_cleanup,
1837#endif 1821#endif
1822};
1823
1824/* HD-audio bus initialization */
1825int azx_bus_create(struct azx *chip, const char *model)
1826{
1827 struct hda_bus *bus;
1828 int err;
1838 1829
1839 err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus); 1830 err = snd_hda_bus_new(chip->card, &bus);
1840 if (err < 0) 1831 if (err < 0)
1841 return err; 1832 return err;
1842 1833
1834 chip->bus = bus;
1835 bus->private_data = chip;
1836 bus->pci = chip->pci;
1837 bus->modelname = model;
1838 bus->ops = bus_ops;
1839
1843 if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) { 1840 if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) {
1844 dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n"); 1841 dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n");
1845 chip->bus->needs_damn_long_delay = 1; 1842 bus->needs_damn_long_delay = 1;
1843 }
1844
1845 /* AMD chipsets often cause the communication stalls upon certain
1846 * sequence like the pin-detection. It seems that forcing the synced
1847 * access works around the stall. Grrr...
1848 */
1849 if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) {
1850 dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n");
1851 bus->sync_write = 1;
1852 bus->allow_bus_reset = 1;
1846 } 1853 }
1847 1854
1855 return 0;
1856}
1857EXPORT_SYMBOL_GPL(azx_bus_create);
1858
1859/* Probe codecs */
1860int azx_probe_codecs(struct azx *chip, unsigned int max_slots)
1861{
1862 struct hda_bus *bus = chip->bus;
1863 int c, codecs, err;
1864
1848 codecs = 0; 1865 codecs = 0;
1849 if (!max_slots) 1866 if (!max_slots)
1850 max_slots = AZX_DEFAULT_CODECS; 1867 max_slots = AZX_DEFAULT_CODECS;
@@ -1872,21 +1889,11 @@ int azx_codec_create(struct azx *chip, const char *model,
1872 } 1889 }
1873 } 1890 }
1874 1891
1875 /* AMD chipsets often cause the communication stalls upon certain
1876 * sequence like the pin-detection. It seems that forcing the synced
1877 * access works around the stall. Grrr...
1878 */
1879 if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) {
1880 dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n");
1881 chip->bus->sync_write = 1;
1882 chip->bus->allow_bus_reset = 1;
1883 }
1884
1885 /* Then create codec instances */ 1892 /* Then create codec instances */
1886 for (c = 0; c < max_slots; c++) { 1893 for (c = 0; c < max_slots; c++) {
1887 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { 1894 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
1888 struct hda_codec *codec; 1895 struct hda_codec *codec;
1889 err = snd_hda_codec_new(chip->bus, c, &codec); 1896 err = snd_hda_codec_new(bus, bus->card, c, &codec);
1890 if (err < 0) 1897 if (err < 0)
1891 continue; 1898 continue;
1892 codec->jackpoll_interval = get_jackpoll_interval(chip); 1899 codec->jackpoll_interval = get_jackpoll_interval(chip);
@@ -1900,7 +1907,7 @@ int azx_codec_create(struct azx *chip, const char *model,
1900 } 1907 }
1901 return 0; 1908 return 0;
1902} 1909}
1903EXPORT_SYMBOL_GPL(azx_codec_create); 1910EXPORT_SYMBOL_GPL(azx_probe_codecs);
1904 1911
1905/* configure each codec instance */ 1912/* configure each codec instance */
1906int azx_codec_configure(struct azx *chip) 1913int azx_codec_configure(struct azx *chip)
@@ -1913,13 +1920,6 @@ int azx_codec_configure(struct azx *chip)
1913} 1920}
1914EXPORT_SYMBOL_GPL(azx_codec_configure); 1921EXPORT_SYMBOL_GPL(azx_codec_configure);
1915 1922
1916/* mixer creation - all stuff is implemented in hda module */
1917int azx_mixer_create(struct azx *chip)
1918{
1919 return snd_hda_build_controls(chip->bus);
1920}
1921EXPORT_SYMBOL_GPL(azx_mixer_create);
1922
1923 1923
1924static bool is_input_stream(struct azx *chip, unsigned char index) 1924static bool is_input_stream(struct azx *chip, unsigned char index)
1925{ 1925{
@@ -1966,30 +1966,5 @@ int azx_init_stream(struct azx *chip)
1966} 1966}
1967EXPORT_SYMBOL_GPL(azx_init_stream); 1967EXPORT_SYMBOL_GPL(azx_init_stream);
1968 1968
1969/*
1970 * reboot notifier for hang-up problem at power-down
1971 */
1972static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf)
1973{
1974 struct azx *chip = container_of(nb, struct azx, reboot_notifier);
1975 snd_hda_bus_reboot_notify(chip->bus);
1976 azx_stop_chip(chip);
1977 return NOTIFY_OK;
1978}
1979
1980void azx_notifier_register(struct azx *chip)
1981{
1982 chip->reboot_notifier.notifier_call = azx_halt;
1983 register_reboot_notifier(&chip->reboot_notifier);
1984}
1985EXPORT_SYMBOL_GPL(azx_notifier_register);
1986
1987void azx_notifier_unregister(struct azx *chip)
1988{
1989 if (chip->reboot_notifier.notifier_call)
1990 unregister_reboot_notifier(&chip->reboot_notifier);
1991}
1992EXPORT_SYMBOL_GPL(azx_notifier_unregister);
1993
1994MODULE_LICENSE("GPL"); 1969MODULE_LICENSE("GPL");
1995MODULE_DESCRIPTION("Common HDA driver functions"); 1970MODULE_DESCRIPTION("Common HDA driver functions");
diff --git a/sound/pci/hda/hda_controller.h b/sound/pci/hda/hda_controller.h
index c90d10fd4d8f..be1b7ded8d82 100644
--- a/sound/pci/hda/hda_controller.h
+++ b/sound/pci/hda/hda_controller.h
@@ -15,10 +15,396 @@
15#ifndef __SOUND_HDA_CONTROLLER_H 15#ifndef __SOUND_HDA_CONTROLLER_H
16#define __SOUND_HDA_CONTROLLER_H 16#define __SOUND_HDA_CONTROLLER_H
17 17
18#include <linux/timecounter.h>
19#include <linux/interrupt.h>
18#include <sound/core.h> 20#include <sound/core.h>
21#include <sound/pcm.h>
19#include <sound/initval.h> 22#include <sound/initval.h>
20#include "hda_codec.h" 23#include "hda_codec.h"
21#include "hda_priv.h" 24
25/*
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 */
88enum { 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
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
154/* driver quirks (capabilities) */
155/* bits 0-7 are used for indicating driver type */
156#define AZX_DCAPS_NO_TCSEL (1 << 8) /* No Intel TCSEL bit */
157#define AZX_DCAPS_NO_MSI (1 << 9) /* No MSI support */
158#define AZX_DCAPS_SNOOP_MASK (3 << 10) /* snoop type mask */
159#define AZX_DCAPS_SNOOP_OFF (1 << 12) /* snoop default off */
160#define AZX_DCAPS_RIRB_DELAY (1 << 13) /* Long delay in read loop */
161#define AZX_DCAPS_RIRB_PRE_DELAY (1 << 14) /* Put a delay before read */
162#define AZX_DCAPS_CTX_WORKAROUND (1 << 15) /* X-Fi workaround */
163#define AZX_DCAPS_POSFIX_LPIB (1 << 16) /* Use LPIB as default */
164#define AZX_DCAPS_POSFIX_VIA (1 << 17) /* Use VIACOMBO as default */
165#define AZX_DCAPS_NO_64BIT (1 << 18) /* No 64bit address */
166#define AZX_DCAPS_SYNC_WRITE (1 << 19) /* sync each cmd write */
167#define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */
168#define AZX_DCAPS_NO_ALIGN_BUFSIZE (1 << 21) /* no buffer size alignment */
169/* 22 unused */
170#define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23) /* BDLE in 4k boundary */
171#define AZX_DCAPS_REVERSE_ASSIGN (1 << 24) /* Assign devices in reverse order */
172#define AZX_DCAPS_COUNT_LPIB_DELAY (1 << 25) /* Take LPIB as delay */
173#define AZX_DCAPS_PM_RUNTIME (1 << 26) /* runtime PM support */
174#define AZX_DCAPS_I915_POWERWELL (1 << 27) /* HSW i915 powerwell support */
175#define AZX_DCAPS_CORBRP_SELF_CLEAR (1 << 28) /* CORBRP clears itself after reset */
176#define AZX_DCAPS_NO_MSI64 (1 << 29) /* Stick to 32-bit MSIs */
177#define AZX_DCAPS_SEPARATE_STREAM_TAG (1 << 30) /* capture and playback use separate stream tag */
178
179enum {
180 AZX_SNOOP_TYPE_NONE,
181 AZX_SNOOP_TYPE_SCH,
182 AZX_SNOOP_TYPE_ATI,
183 AZX_SNOOP_TYPE_NVIDIA,
184};
185
186/* HD Audio class code */
187#define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
188
189struct azx_dev {
190 struct snd_dma_buffer bdl; /* BDL buffer */
191 u32 *posbuf; /* position buffer pointer */
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;
218 unsigned int prepared:1;
219 unsigned int locked:1;
220 /*
221 * For VIA:
222 * A flag to ensure DMA position is 0
223 * when link position is not greater than FIFO size
224 */
225 unsigned int insufficient:1;
226 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};
239
240/* CORB/RIRB */
241struct azx_rb {
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
252struct azx;
253
254/* Functions to read/write to hda registers. */
255struct 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 */
264 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,
272 struct snd_pcm_substream *substream,
273 size_t size);
274 int (*substream_free_pages)(struct azx *chip,
275 struct snd_pcm_substream *substream);
276 void (*pcm_mmap_prepare)(struct snd_pcm_substream *substream,
277 struct vm_area_struct *area);
278 /* Check if current position is acceptable */
279 int (*position_check)(struct azx *chip, struct azx_dev *azx_dev);
280};
281
282struct azx_pcm {
283 struct azx *chip;
284 struct snd_pcm *pcm;
285 struct hda_codec *codec;
286 struct hda_pcm *info;
287 struct list_head list;
288};
289
290typedef unsigned int (*azx_get_pos_callback_t)(struct azx *, struct azx_dev *);
291typedef int (*azx_get_delay_callback_t)(struct azx *, struct azx_dev *, unsigned int pos);
292
293struct azx {
294 struct snd_card *card;
295 struct pci_dev *pci;
296 int dev_index;
297
298 /* chip type specific */
299 int driver_type;
300 unsigned int driver_caps;
301 int playback_streams;
302 int playback_index_offset;
303 int capture_streams;
304 int capture_index_offset;
305 int num_streams;
306 const int *jackpoll_ms; /* per-card jack poll interval */
307
308 /* Register interaction. */
309 const struct hda_controller_ops *ops;
310
311 /* position adjustment callbacks */
312 azx_get_pos_callback_t get_position[2];
313 azx_get_delay_callback_t get_delay[2];
314
315 /* pci resources */
316 unsigned long addr;
317 void __iomem *remap_addr;
318 int irq;
319
320 /* locks */
321 spinlock_t reg_lock;
322 struct mutex open_mutex; /* Prevents concurrent open/close operations */
323
324 /* streams (x num_streams) */
325 struct azx_dev *azx_dev;
326
327 /* PCM */
328 struct list_head pcm_list; /* azx_pcm list */
329
330 /* HD codec */
331 unsigned short codec_mask;
332 int codec_probe_mask; /* copied from probe_mask option */
333 struct hda_bus *bus;
334 unsigned int beep_mode;
335
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
345 const struct firmware *fw;
346#endif
347
348 /* flags */
349 const int *bdl_pos_adj;
350 int poll_count;
351 unsigned int running:1;
352 unsigned int initialized:1;
353 unsigned int single_cmd:1;
354 unsigned int polling_mode:1;
355 unsigned int msi:1;
356 unsigned int probing:1; /* codec probing phase */
357 unsigned int snoop:1;
358 unsigned int align_buffer_size:1;
359 unsigned int region_requested:1;
360 unsigned int disabled:1; /* disabled by VGA-switcher */
361
362 /* for debugging */
363 unsigned int last_cmd[AZX_MAX_CODECS];
364
365#ifdef CONFIG_SND_HDA_DSP_LOADER
366 struct azx_dev saved_azx_dev;
367#endif
368};
369
370#ifdef CONFIG_X86
371#define azx_snoop(chip) ((chip)->snoop)
372#else
373#define azx_snoop(chip) true
374#endif
375
376/*
377 * macros for easy use
378 */
379
380#define azx_writel(chip, reg, value) \
381 ((chip)->ops->reg_writel(value, (chip)->remap_addr + AZX_REG_##reg))
382#define azx_readl(chip, reg) \
383 ((chip)->ops->reg_readl((chip)->remap_addr + AZX_REG_##reg))
384#define azx_writew(chip, reg, value) \
385 ((chip)->ops->reg_writew(value, (chip)->remap_addr + AZX_REG_##reg))
386#define azx_readw(chip, reg) \
387 ((chip)->ops->reg_readw((chip)->remap_addr + AZX_REG_##reg))
388#define azx_writeb(chip, reg, value) \
389 ((chip)->ops->reg_writeb(value, (chip)->remap_addr + AZX_REG_##reg))
390#define azx_readb(chip, reg) \
391 ((chip)->ops->reg_readb((chip)->remap_addr + AZX_REG_##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
406#define azx_has_pm_runtime(chip) \
407 (!AZX_DCAPS_PM_RUNTIME || ((chip)->driver_caps & AZX_DCAPS_PM_RUNTIME))
22 408
23/* PCM setup */ 409/* PCM setup */
24static inline struct azx_dev *get_azx_dev(struct snd_pcm_substream *substream) 410static inline struct azx_dev *get_azx_dev(struct snd_pcm_substream *substream)
@@ -43,14 +429,9 @@ void azx_enter_link_reset(struct azx *chip);
43irqreturn_t azx_interrupt(int irq, void *dev_id); 429irqreturn_t azx_interrupt(int irq, void *dev_id);
44 430
45/* Codec interface */ 431/* Codec interface */
46int azx_codec_create(struct azx *chip, const char *model, 432int azx_bus_create(struct azx *chip, const char *model);
47 unsigned int max_slots, 433int azx_probe_codecs(struct azx *chip, unsigned int max_slots);
48 int *power_save_to);
49int azx_codec_configure(struct azx *chip); 434int azx_codec_configure(struct azx *chip);
50int azx_mixer_create(struct azx *chip);
51int azx_init_stream(struct azx *chip); 435int azx_init_stream(struct azx *chip);
52 436
53void azx_notifier_register(struct azx *chip);
54void azx_notifier_unregister(struct azx *chip);
55
56#endif /* __SOUND_HDA_CONTROLLER_H */ 437#endif /* __SOUND_HDA_CONTROLLER_H */
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index 8ec5289f8e05..0ef2459cd05f 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -140,6 +140,9 @@ static void parse_user_hints(struct hda_codec *codec)
140 val = snd_hda_get_bool_hint(codec, "single_adc_amp"); 140 val = snd_hda_get_bool_hint(codec, "single_adc_amp");
141 if (val >= 0) 141 if (val >= 0)
142 codec->single_adc_amp = !!val; 142 codec->single_adc_amp = !!val;
143 val = snd_hda_get_bool_hint(codec, "power_save_node");
144 if (val >= 0)
145 codec->power_save_node = !!val;
143 146
144 val = snd_hda_get_bool_hint(codec, "auto_mute"); 147 val = snd_hda_get_bool_hint(codec, "auto_mute");
145 if (val >= 0) 148 if (val >= 0)
@@ -648,12 +651,24 @@ static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
648 unsigned int dir, unsigned int idx) 651 unsigned int dir, unsigned int idx)
649{ 652{
650 struct hda_gen_spec *spec = codec->spec; 653 struct hda_gen_spec *spec = codec->spec;
654 int type = get_wcaps_type(get_wcaps(codec, nid));
651 int i, n; 655 int i, n;
652 656
657 if (nid == codec->afg)
658 return true;
659
653 for (n = 0; n < spec->paths.used; n++) { 660 for (n = 0; n < spec->paths.used; n++) {
654 struct nid_path *path = snd_array_elem(&spec->paths, n); 661 struct nid_path *path = snd_array_elem(&spec->paths, n);
655 if (!path->active) 662 if (!path->active)
656 continue; 663 continue;
664 if (codec->power_save_node) {
665 if (!path->stream_enabled)
666 continue;
667 /* ignore unplugged paths except for DAC/ADC */
668 if (!(path->pin_enabled || path->pin_fixed) &&
669 type != AC_WID_AUD_OUT && type != AC_WID_AUD_IN)
670 continue;
671 }
657 for (i = 0; i < path->depth; i++) { 672 for (i = 0; i < path->depth; i++) {
658 if (path->path[i] == nid) { 673 if (path->path[i] == nid) {
659 if (dir == HDA_OUTPUT || path->idx[i] == idx) 674 if (dir == HDA_OUTPUT || path->idx[i] == idx)
@@ -807,6 +822,44 @@ static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
807 } 822 }
808} 823}
809 824
825/* sync power of each widget in the the given path */
826static hda_nid_t path_power_update(struct hda_codec *codec,
827 struct nid_path *path,
828 bool allow_powerdown)
829{
830 hda_nid_t nid, changed = 0;
831 int i, state;
832
833 for (i = 0; i < path->depth; i++) {
834 nid = path->path[i];
835 if (nid == codec->afg)
836 continue;
837 if (!allow_powerdown || is_active_nid_for_any(codec, nid))
838 state = AC_PWRST_D0;
839 else
840 state = AC_PWRST_D3;
841 if (!snd_hda_check_power_state(codec, nid, state)) {
842 snd_hda_codec_write(codec, nid, 0,
843 AC_VERB_SET_POWER_STATE, state);
844 changed = nid;
845 /* here we assume that widget attributes (e.g. amp,
846 * pinctl connection) don't change with local power
847 * state change. If not, need to sync the cache.
848 */
849 }
850 }
851 return changed;
852}
853
854/* do sync with the last power state change */
855static void sync_power_state_change(struct hda_codec *codec, hda_nid_t nid)
856{
857 if (nid) {
858 msleep(10);
859 snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
860 }
861}
862
810/** 863/**
811 * snd_hda_activate_path - activate or deactivate the given path 864 * snd_hda_activate_path - activate or deactivate the given path
812 * @codec: the HDA codec 865 * @codec: the HDA codec
@@ -825,15 +878,13 @@ void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
825 if (!enable) 878 if (!enable)
826 path->active = false; 879 path->active = false;
827 880
881 /* make sure the widget is powered up */
882 if (enable && (spec->power_down_unused || codec->power_save_node))
883 path_power_update(codec, path, codec->power_save_node);
884
828 for (i = path->depth - 1; i >= 0; i--) { 885 for (i = path->depth - 1; i >= 0; i--) {
829 hda_nid_t nid = path->path[i]; 886 hda_nid_t nid = path->path[i];
830 if (enable && spec->power_down_unused) { 887
831 /* make sure the widget is powered up */
832 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0))
833 snd_hda_codec_write(codec, nid, 0,
834 AC_VERB_SET_POWER_STATE,
835 AC_PWRST_D0);
836 }
837 if (enable && path->multi[i]) 888 if (enable && path->multi[i])
838 snd_hda_codec_update_cache(codec, nid, 0, 889 snd_hda_codec_update_cache(codec, nid, 0,
839 AC_VERB_SET_CONNECT_SEL, 890 AC_VERB_SET_CONNECT_SEL,
@@ -853,28 +904,10 @@ EXPORT_SYMBOL_GPL(snd_hda_activate_path);
853static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path) 904static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path)
854{ 905{
855 struct hda_gen_spec *spec = codec->spec; 906 struct hda_gen_spec *spec = codec->spec;
856 bool changed = false;
857 int i;
858 907
859 if (!spec->power_down_unused || path->active) 908 if (!(spec->power_down_unused || codec->power_save_node) || path->active)
860 return; 909 return;
861 910 sync_power_state_change(codec, path_power_update(codec, path, true));
862 for (i = 0; i < path->depth; i++) {
863 hda_nid_t nid = path->path[i];
864 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D3) &&
865 !is_active_nid_for_any(codec, nid)) {
866 snd_hda_codec_write(codec, nid, 0,
867 AC_VERB_SET_POWER_STATE,
868 AC_PWRST_D3);
869 changed = true;
870 }
871 }
872
873 if (changed) {
874 msleep(10);
875 snd_hda_codec_read(codec, path->path[0], 0,
876 AC_VERB_GET_POWER_STATE, 0);
877 }
878} 911}
879 912
880/* turn on/off EAPD on the given pin */ 913/* turn on/off EAPD on the given pin */
@@ -1574,6 +1607,7 @@ static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
1574 return 0; 1607 return 0;
1575 /* print_nid_path(codec, "output-aamix", path); */ 1608 /* print_nid_path(codec, "output-aamix", path); */
1576 path->active = false; /* unused as default */ 1609 path->active = false; /* unused as default */
1610 path->pin_fixed = true; /* static route */
1577 return snd_hda_get_path_idx(codec, path); 1611 return snd_hda_get_path_idx(codec, path);
1578} 1612}
1579 1613
@@ -2998,6 +3032,7 @@ static int new_analog_input(struct hda_codec *codec, int input_idx,
2998 } 3032 }
2999 3033
3000 path->active = true; 3034 path->active = true;
3035 path->stream_enabled = true; /* no DAC/ADC involved */
3001 err = add_loopback_list(spec, mix_nid, idx); 3036 err = add_loopback_list(spec, mix_nid, idx);
3002 if (err < 0) 3037 if (err < 0)
3003 return err; 3038 return err;
@@ -3009,6 +3044,8 @@ static int new_analog_input(struct hda_codec *codec, int input_idx,
3009 if (path) { 3044 if (path) {
3010 print_nid_path(codec, "loopback-merge", path); 3045 print_nid_path(codec, "loopback-merge", path);
3011 path->active = true; 3046 path->active = true;
3047 path->pin_fixed = true; /* static route */
3048 path->stream_enabled = true; /* no DAC/ADC involved */
3012 spec->loopback_merge_path = 3049 spec->loopback_merge_path =
3013 snd_hda_get_path_idx(codec, path); 3050 snd_hda_get_path_idx(codec, path);
3014 } 3051 }
@@ -3810,6 +3847,7 @@ static void parse_digital(struct hda_codec *codec)
3810 continue; 3847 continue;
3811 print_nid_path(codec, "digout", path); 3848 print_nid_path(codec, "digout", path);
3812 path->active = true; 3849 path->active = true;
3850 path->pin_fixed = true; /* no jack detection */
3813 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path); 3851 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path);
3814 set_pin_target(codec, pin, PIN_OUT, false); 3852 set_pin_target(codec, pin, PIN_OUT, false);
3815 if (!nums) { 3853 if (!nums) {
@@ -3837,6 +3875,7 @@ static void parse_digital(struct hda_codec *codec)
3837 if (path) { 3875 if (path) {
3838 print_nid_path(codec, "digin", path); 3876 print_nid_path(codec, "digin", path);
3839 path->active = true; 3877 path->active = true;
3878 path->pin_fixed = true; /* no jack */
3840 spec->dig_in_nid = dig_nid; 3879 spec->dig_in_nid = dig_nid;
3841 spec->digin_path = snd_hda_get_path_idx(codec, path); 3880 spec->digin_path = snd_hda_get_path_idx(codec, path);
3842 set_pin_target(codec, pin, PIN_IN, false); 3881 set_pin_target(codec, pin, PIN_IN, false);
@@ -3896,6 +3935,229 @@ static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
3896 return 1; 3935 return 1;
3897} 3936}
3898 3937
3938/* power up/down widgets in the all paths that match with the given NID
3939 * as terminals (either start- or endpoint)
3940 *
3941 * returns the last changed NID, or zero if unchanged.
3942 */
3943static hda_nid_t set_path_power(struct hda_codec *codec, hda_nid_t nid,
3944 int pin_state, int stream_state)
3945{
3946 struct hda_gen_spec *spec = codec->spec;
3947 hda_nid_t last, changed = 0;
3948 struct nid_path *path;
3949 int n;
3950
3951 for (n = 0; n < spec->paths.used; n++) {
3952 path = snd_array_elem(&spec->paths, n);
3953 if (path->path[0] == nid ||
3954 path->path[path->depth - 1] == nid) {
3955 bool pin_old = path->pin_enabled;
3956 bool stream_old = path->stream_enabled;
3957
3958 if (pin_state >= 0)
3959 path->pin_enabled = pin_state;
3960 if (stream_state >= 0)
3961 path->stream_enabled = stream_state;
3962 if ((!path->pin_fixed && path->pin_enabled != pin_old)
3963 || path->stream_enabled != stream_old) {
3964 last = path_power_update(codec, path, true);
3965 if (last)
3966 changed = last;
3967 }
3968 }
3969 }
3970 return changed;
3971}
3972
3973/* power up/down the paths of the given pin according to the jack state;
3974 * power = 0/1 : only power up/down if it matches with the jack state,
3975 * < 0 : force power up/down to follow the jack sate
3976 *
3977 * returns the last changed NID, or zero if unchanged.
3978 */
3979static hda_nid_t set_pin_power_jack(struct hda_codec *codec, hda_nid_t pin,
3980 int power)
3981{
3982 bool on;
3983
3984 if (!codec->power_save_node)
3985 return 0;
3986
3987 on = snd_hda_jack_detect_state(codec, pin) != HDA_JACK_NOT_PRESENT;
3988 if (power >= 0 && on != power)
3989 return 0;
3990 return set_path_power(codec, pin, on, -1);
3991}
3992
3993static void pin_power_callback(struct hda_codec *codec,
3994 struct hda_jack_callback *jack,
3995 bool on)
3996{
3997 if (jack && jack->tbl->nid)
3998 sync_power_state_change(codec,
3999 set_pin_power_jack(codec, jack->tbl->nid, on));
4000}
4001
4002/* callback only doing power up -- called at first */
4003static void pin_power_up_callback(struct hda_codec *codec,
4004 struct hda_jack_callback *jack)
4005{
4006 pin_power_callback(codec, jack, true);
4007}
4008
4009/* callback only doing power down -- called at last */
4010static void pin_power_down_callback(struct hda_codec *codec,
4011 struct hda_jack_callback *jack)
4012{
4013 pin_power_callback(codec, jack, false);
4014}
4015
4016/* set up the power up/down callbacks */
4017static void add_pin_power_ctls(struct hda_codec *codec, int num_pins,
4018 const hda_nid_t *pins, bool on)
4019{
4020 int i;
4021 hda_jack_callback_fn cb =
4022 on ? pin_power_up_callback : pin_power_down_callback;
4023
4024 for (i = 0; i < num_pins && pins[i]; i++) {
4025 if (is_jack_detectable(codec, pins[i]))
4026 snd_hda_jack_detect_enable_callback(codec, pins[i], cb);
4027 else
4028 set_path_power(codec, pins[i], true, -1);
4029 }
4030}
4031
4032/* enabled power callback to each available I/O pin with jack detections;
4033 * the digital I/O pins are excluded because of the unreliable detectsion
4034 */
4035static void add_all_pin_power_ctls(struct hda_codec *codec, bool on)
4036{
4037 struct hda_gen_spec *spec = codec->spec;
4038 struct auto_pin_cfg *cfg = &spec->autocfg;
4039 int i;
4040
4041 if (!codec->power_save_node)
4042 return;
4043 add_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins, on);
4044 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
4045 add_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins, on);
4046 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
4047 add_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins, on);
4048 for (i = 0; i < cfg->num_inputs; i++)
4049 add_pin_power_ctls(codec, 1, &cfg->inputs[i].pin, on);
4050}
4051
4052/* sync path power up/down with the jack states of given pins */
4053static void sync_pin_power_ctls(struct hda_codec *codec, int num_pins,
4054 const hda_nid_t *pins)
4055{
4056 int i;
4057
4058 for (i = 0; i < num_pins && pins[i]; i++)
4059 if (is_jack_detectable(codec, pins[i]))
4060 set_pin_power_jack(codec, pins[i], -1);
4061}
4062
4063/* sync path power up/down with pins; called at init and resume */
4064static void sync_all_pin_power_ctls(struct hda_codec *codec)
4065{
4066 struct hda_gen_spec *spec = codec->spec;
4067 struct auto_pin_cfg *cfg = &spec->autocfg;
4068 int i;
4069
4070 if (!codec->power_save_node)
4071 return;
4072 sync_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins);
4073 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
4074 sync_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins);
4075 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
4076 sync_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins);
4077 for (i = 0; i < cfg->num_inputs; i++)
4078 sync_pin_power_ctls(codec, 1, &cfg->inputs[i].pin);
4079}
4080
4081/* add fake paths if not present yet */
4082static int add_fake_paths(struct hda_codec *codec, hda_nid_t nid,
4083 int num_pins, const hda_nid_t *pins)
4084{
4085 struct hda_gen_spec *spec = codec->spec;
4086 struct nid_path *path;
4087 int i;
4088
4089 for (i = 0; i < num_pins; i++) {
4090 if (!pins[i])
4091 break;
4092 if (get_nid_path(codec, nid, pins[i], 0))
4093 continue;
4094 path = snd_array_new(&spec->paths);
4095 if (!path)
4096 return -ENOMEM;
4097 memset(path, 0, sizeof(*path));
4098 path->depth = 2;
4099 path->path[0] = nid;
4100 path->path[1] = pins[i];
4101 path->active = true;
4102 }
4103 return 0;
4104}
4105
4106/* create fake paths to all outputs from beep */
4107static int add_fake_beep_paths(struct hda_codec *codec)
4108{
4109 struct hda_gen_spec *spec = codec->spec;
4110 struct auto_pin_cfg *cfg = &spec->autocfg;
4111 hda_nid_t nid = spec->beep_nid;
4112 int err;
4113
4114 if (!codec->power_save_node || !nid)
4115 return 0;
4116 err = add_fake_paths(codec, nid, cfg->line_outs, cfg->line_out_pins);
4117 if (err < 0)
4118 return err;
4119 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
4120 err = add_fake_paths(codec, nid, cfg->hp_outs, cfg->hp_pins);
4121 if (err < 0)
4122 return err;
4123 }
4124 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
4125 err = add_fake_paths(codec, nid, cfg->speaker_outs,
4126 cfg->speaker_pins);
4127 if (err < 0)
4128 return err;
4129 }
4130 return 0;
4131}
4132
4133/* power up/down beep widget and its output paths */
4134static void beep_power_hook(struct hda_beep *beep, bool on)
4135{
4136 set_path_power(beep->codec, beep->nid, -1, on);
4137}
4138
4139/**
4140 * snd_hda_gen_fix_pin_power - Fix the power of the given pin widget to D0
4141 * @codec: the HDA codec
4142 * @pin: NID of pin to fix
4143 */
4144int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin)
4145{
4146 struct hda_gen_spec *spec = codec->spec;
4147 struct nid_path *path;
4148
4149 path = snd_array_new(&spec->paths);
4150 if (!path)
4151 return -ENOMEM;
4152 memset(path, 0, sizeof(*path));
4153 path->depth = 1;
4154 path->path[0] = pin;
4155 path->active = true;
4156 path->pin_fixed = true;
4157 path->stream_enabled = true;
4158 return 0;
4159}
4160EXPORT_SYMBOL_GPL(snd_hda_gen_fix_pin_power);
3899 4161
3900/* 4162/*
3901 * Jack detections for HP auto-mute and mic-switch 4163 * Jack detections for HP auto-mute and mic-switch
@@ -3933,6 +4195,10 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
3933 if (!nid) 4195 if (!nid)
3934 break; 4196 break;
3935 4197
4198 oldval = snd_hda_codec_get_pin_target(codec, nid);
4199 if (oldval & PIN_IN)
4200 continue; /* no mute for inputs */
4201
3936 if (spec->auto_mute_via_amp) { 4202 if (spec->auto_mute_via_amp) {
3937 struct nid_path *path; 4203 struct nid_path *path;
3938 hda_nid_t mute_nid; 4204 hda_nid_t mute_nid;
@@ -3947,29 +4213,33 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
3947 spec->mute_bits |= (1ULL << mute_nid); 4213 spec->mute_bits |= (1ULL << mute_nid);
3948 else 4214 else
3949 spec->mute_bits &= ~(1ULL << mute_nid); 4215 spec->mute_bits &= ~(1ULL << mute_nid);
3950 set_pin_eapd(codec, nid, !mute);
3951 continue; 4216 continue;
4217 } else {
4218 /* don't reset VREF value in case it's controlling
4219 * the amp (see alc861_fixup_asus_amp_vref_0f())
4220 */
4221 if (spec->keep_vref_in_automute)
4222 val = oldval & ~PIN_HP;
4223 else
4224 val = 0;
4225 if (!mute)
4226 val |= oldval;
4227 /* here we call update_pin_ctl() so that the pinctl is
4228 * changed without changing the pinctl target value;
4229 * the original target value will be still referred at
4230 * the init / resume again
4231 */
4232 update_pin_ctl(codec, nid, val);
3952 } 4233 }
3953 4234
3954 oldval = snd_hda_codec_get_pin_target(codec, nid);
3955 if (oldval & PIN_IN)
3956 continue; /* no mute for inputs */
3957 /* don't reset VREF value in case it's controlling
3958 * the amp (see alc861_fixup_asus_amp_vref_0f())
3959 */
3960 if (spec->keep_vref_in_automute)
3961 val = oldval & ~PIN_HP;
3962 else
3963 val = 0;
3964 if (!mute)
3965 val |= oldval;
3966 /* here we call update_pin_ctl() so that the pinctl is changed
3967 * without changing the pinctl target value;
3968 * the original target value will be still referred at the
3969 * init / resume again
3970 */
3971 update_pin_ctl(codec, nid, val);
3972 set_pin_eapd(codec, nid, !mute); 4235 set_pin_eapd(codec, nid, !mute);
4236 if (codec->power_save_node) {
4237 bool on = !mute;
4238 if (on)
4239 on = snd_hda_jack_detect_state(codec, nid)
4240 != HDA_JACK_NOT_PRESENT;
4241 set_path_power(codec, nid, on, -1);
4242 }
3973 } 4243 }
3974} 4244}
3975 4245
@@ -4466,6 +4736,21 @@ static void mute_all_mixer_nid(struct hda_codec *codec, hda_nid_t mix)
4466} 4736}
4467 4737
4468/** 4738/**
4739 * snd_hda_gen_stream_pm - Stream power management callback
4740 * @codec: the HDA codec
4741 * @nid: audio widget
4742 * @on: power on/off flag
4743 *
4744 * Set this in patch_ops.stream_pm. Only valid with power_save_node flag.
4745 */
4746void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on)
4747{
4748 if (codec->power_save_node)
4749 set_path_power(codec, nid, -1, on);
4750}
4751EXPORT_SYMBOL_GPL(snd_hda_gen_stream_pm);
4752
4753/**
4469 * snd_hda_gen_parse_auto_config - Parse the given BIOS configuration and 4754 * snd_hda_gen_parse_auto_config - Parse the given BIOS configuration and
4470 * set up the hda_gen_spec 4755 * set up the hda_gen_spec
4471 * @codec: the HDA codec 4756 * @codec: the HDA codec
@@ -4549,6 +4834,9 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4549 if (err < 0) 4834 if (err < 0)
4550 return err; 4835 return err;
4551 4836
4837 /* add power-down pin callbacks at first */
4838 add_all_pin_power_ctls(codec, false);
4839
4552 spec->const_channel_count = spec->ext_channel_count; 4840 spec->const_channel_count = spec->ext_channel_count;
4553 /* check the multiple speaker and headphone pins */ 4841 /* check the multiple speaker and headphone pins */
4554 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) 4842 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
@@ -4618,6 +4906,9 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4618 } 4906 }
4619 } 4907 }
4620 4908
4909 /* add power-up pin callbacks at last */
4910 add_all_pin_power_ctls(codec, true);
4911
4621 /* mute all aamix input initially */ 4912 /* mute all aamix input initially */
4622 if (spec->mixer_nid) 4913 if (spec->mixer_nid)
4623 mute_all_mixer_nid(codec, spec->mixer_nid); 4914 mute_all_mixer_nid(codec, spec->mixer_nid);
@@ -4625,13 +4916,19 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4625 dig_only: 4916 dig_only:
4626 parse_digital(codec); 4917 parse_digital(codec);
4627 4918
4628 if (spec->power_down_unused) 4919 if (spec->power_down_unused || codec->power_save_node)
4629 codec->power_filter = snd_hda_gen_path_power_filter; 4920 codec->power_filter = snd_hda_gen_path_power_filter;
4630 4921
4631 if (!spec->no_analog && spec->beep_nid) { 4922 if (!spec->no_analog && spec->beep_nid) {
4632 err = snd_hda_attach_beep_device(codec, spec->beep_nid); 4923 err = snd_hda_attach_beep_device(codec, spec->beep_nid);
4633 if (err < 0) 4924 if (err < 0)
4634 return err; 4925 return err;
4926 if (codec->beep && codec->power_save_node) {
4927 err = add_fake_beep_paths(codec);
4928 if (err < 0)
4929 return err;
4930 codec->beep->power_hook = beep_power_hook;
4931 }
4635 } 4932 }
4636 4933
4637 return 1; 4934 return 1;
@@ -4675,7 +4972,7 @@ int snd_hda_gen_build_controls(struct hda_codec *codec)
4675 err = snd_hda_create_dig_out_ctls(codec, 4972 err = snd_hda_create_dig_out_ctls(codec,
4676 spec->multiout.dig_out_nid, 4973 spec->multiout.dig_out_nid,
4677 spec->multiout.dig_out_nid, 4974 spec->multiout.dig_out_nid,
4678 spec->pcm_rec[1].pcm_type); 4975 spec->pcm_rec[1]->pcm_type);
4679 if (err < 0) 4976 if (err < 0)
4680 return err; 4977 return err;
4681 if (!spec->no_analog) { 4978 if (!spec->no_analog) {
@@ -5137,6 +5434,33 @@ static void fill_pcm_stream_name(char *str, size_t len, const char *sfx,
5137 strlcat(str, sfx, len); 5434 strlcat(str, sfx, len);
5138} 5435}
5139 5436
5437/* copy PCM stream info from @default_str, and override non-NULL entries
5438 * from @spec_str and @nid
5439 */
5440static void setup_pcm_stream(struct hda_pcm_stream *str,
5441 const struct hda_pcm_stream *default_str,
5442 const struct hda_pcm_stream *spec_str,
5443 hda_nid_t nid)
5444{
5445 *str = *default_str;
5446 if (nid)
5447 str->nid = nid;
5448 if (spec_str) {
5449 if (spec_str->substreams)
5450 str->substreams = spec_str->substreams;
5451 if (spec_str->channels_min)
5452 str->channels_min = spec_str->channels_min;
5453 if (spec_str->channels_max)
5454 str->channels_max = spec_str->channels_max;
5455 if (spec_str->rates)
5456 str->rates = spec_str->rates;
5457 if (spec_str->formats)
5458 str->formats = spec_str->formats;
5459 if (spec_str->maxbps)
5460 str->maxbps = spec_str->maxbps;
5461 }
5462}
5463
5140/** 5464/**
5141 * snd_hda_gen_build_pcms - build PCM streams based on the parsed results 5465 * snd_hda_gen_build_pcms - build PCM streams based on the parsed results
5142 * @codec: the HDA codec 5466 * @codec: the HDA codec
@@ -5146,27 +5470,25 @@ static void fill_pcm_stream_name(char *str, size_t len, const char *sfx,
5146int snd_hda_gen_build_pcms(struct hda_codec *codec) 5470int snd_hda_gen_build_pcms(struct hda_codec *codec)
5147{ 5471{
5148 struct hda_gen_spec *spec = codec->spec; 5472 struct hda_gen_spec *spec = codec->spec;
5149 struct hda_pcm *info = spec->pcm_rec; 5473 struct hda_pcm *info;
5150 const struct hda_pcm_stream *p;
5151 bool have_multi_adcs; 5474 bool have_multi_adcs;
5152 5475
5153 codec->num_pcms = 1;
5154 codec->pcm_info = info;
5155
5156 if (spec->no_analog) 5476 if (spec->no_analog)
5157 goto skip_analog; 5477 goto skip_analog;
5158 5478
5159 fill_pcm_stream_name(spec->stream_name_analog, 5479 fill_pcm_stream_name(spec->stream_name_analog,
5160 sizeof(spec->stream_name_analog), 5480 sizeof(spec->stream_name_analog),
5161 " Analog", codec->chip_name); 5481 " Analog", codec->chip_name);
5162 info->name = spec->stream_name_analog; 5482 info = snd_hda_codec_pcm_new(codec, "%s", spec->stream_name_analog);
5483 if (!info)
5484 return -ENOMEM;
5485 spec->pcm_rec[0] = info;
5163 5486
5164 if (spec->multiout.num_dacs > 0) { 5487 if (spec->multiout.num_dacs > 0) {
5165 p = spec->stream_analog_playback; 5488 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5166 if (!p) 5489 &pcm_analog_playback,
5167 p = &pcm_analog_playback; 5490 spec->stream_analog_playback,
5168 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; 5491 spec->multiout.dac_nids[0]);
5169 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
5170 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 5492 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
5171 spec->multiout.max_channels; 5493 spec->multiout.max_channels;
5172 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT && 5494 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
@@ -5175,15 +5497,11 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec)
5175 snd_pcm_2_1_chmaps; 5497 snd_pcm_2_1_chmaps;
5176 } 5498 }
5177 if (spec->num_adc_nids) { 5499 if (spec->num_adc_nids) {
5178 p = spec->stream_analog_capture; 5500 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5179 if (!p) { 5501 (spec->dyn_adc_switch ?
5180 if (spec->dyn_adc_switch) 5502 &dyn_adc_pcm_analog_capture : &pcm_analog_capture),
5181 p = &dyn_adc_pcm_analog_capture; 5503 spec->stream_analog_capture,
5182 else 5504 spec->adc_nids[0]);
5183 p = &pcm_analog_capture;
5184 }
5185 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
5186 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
5187 } 5505 }
5188 5506
5189 skip_analog: 5507 skip_analog:
@@ -5192,28 +5510,26 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec)
5192 fill_pcm_stream_name(spec->stream_name_digital, 5510 fill_pcm_stream_name(spec->stream_name_digital,
5193 sizeof(spec->stream_name_digital), 5511 sizeof(spec->stream_name_digital),
5194 " Digital", codec->chip_name); 5512 " Digital", codec->chip_name);
5195 codec->num_pcms = 2; 5513 info = snd_hda_codec_pcm_new(codec, "%s",
5514 spec->stream_name_digital);
5515 if (!info)
5516 return -ENOMEM;
5196 codec->slave_dig_outs = spec->multiout.slave_dig_outs; 5517 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
5197 info = spec->pcm_rec + 1; 5518 spec->pcm_rec[1] = info;
5198 info->name = spec->stream_name_digital;
5199 if (spec->dig_out_type) 5519 if (spec->dig_out_type)
5200 info->pcm_type = spec->dig_out_type; 5520 info->pcm_type = spec->dig_out_type;
5201 else 5521 else
5202 info->pcm_type = HDA_PCM_TYPE_SPDIF; 5522 info->pcm_type = HDA_PCM_TYPE_SPDIF;
5203 if (spec->multiout.dig_out_nid) { 5523 if (spec->multiout.dig_out_nid)
5204 p = spec->stream_digital_playback; 5524 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5205 if (!p) 5525 &pcm_digital_playback,
5206 p = &pcm_digital_playback; 5526 spec->stream_digital_playback,
5207 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; 5527 spec->multiout.dig_out_nid);
5208 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; 5528 if (spec->dig_in_nid)
5209 } 5529 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5210 if (spec->dig_in_nid) { 5530 &pcm_digital_capture,
5211 p = spec->stream_digital_capture; 5531 spec->stream_digital_capture,
5212 if (!p) 5532 spec->dig_in_nid);
5213 p = &pcm_digital_capture;
5214 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
5215 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
5216 }
5217 } 5533 }
5218 5534
5219 if (spec->no_analog) 5535 if (spec->no_analog)
@@ -5229,34 +5545,29 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec)
5229 fill_pcm_stream_name(spec->stream_name_alt_analog, 5545 fill_pcm_stream_name(spec->stream_name_alt_analog,
5230 sizeof(spec->stream_name_alt_analog), 5546 sizeof(spec->stream_name_alt_analog),
5231 " Alt Analog", codec->chip_name); 5547 " Alt Analog", codec->chip_name);
5232 codec->num_pcms = 3; 5548 info = snd_hda_codec_pcm_new(codec, "%s",
5233 info = spec->pcm_rec + 2; 5549 spec->stream_name_alt_analog);
5234 info->name = spec->stream_name_alt_analog; 5550 if (!info)
5235 if (spec->alt_dac_nid) { 5551 return -ENOMEM;
5236 p = spec->stream_analog_alt_playback; 5552 spec->pcm_rec[2] = info;
5237 if (!p) 5553 if (spec->alt_dac_nid)
5238 p = &pcm_analog_alt_playback; 5554 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5239 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; 5555 &pcm_analog_alt_playback,
5240 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 5556 spec->stream_analog_alt_playback,
5241 spec->alt_dac_nid; 5557 spec->alt_dac_nid);
5242 } else { 5558 else
5243 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 5559 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5244 pcm_null_stream; 5560 &pcm_null_stream, NULL, 0);
5245 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
5246 }
5247 if (have_multi_adcs) { 5561 if (have_multi_adcs) {
5248 p = spec->stream_analog_alt_capture; 5562 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5249 if (!p) 5563 &pcm_analog_alt_capture,
5250 p = &pcm_analog_alt_capture; 5564 spec->stream_analog_alt_capture,
5251 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; 5565 spec->adc_nids[1]);
5252 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
5253 spec->adc_nids[1];
5254 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 5566 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
5255 spec->num_adc_nids - 1; 5567 spec->num_adc_nids - 1;
5256 } else { 5568 } else {
5257 info->stream[SNDRV_PCM_STREAM_CAPTURE] = 5569 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5258 pcm_null_stream; 5570 &pcm_null_stream, NULL, 0);
5259 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
5260 } 5571 }
5261 } 5572 }
5262 5573
@@ -5464,6 +5775,8 @@ int snd_hda_gen_init(struct hda_codec *codec)
5464 5775
5465 clear_unsol_on_unused_pins(codec); 5776 clear_unsol_on_unused_pins(codec);
5466 5777
5778 sync_all_pin_power_ctls(codec);
5779
5467 /* call init functions of standard auto-mute helpers */ 5780 /* call init functions of standard auto-mute helpers */
5468 update_automute_all(codec); 5781 update_automute_all(codec);
5469 5782
@@ -5524,13 +5837,11 @@ static const struct hda_codec_ops generic_patch_ops = {
5524#endif 5837#endif
5525}; 5838};
5526 5839
5527/** 5840/*
5528 * snd_hda_parse_generic_codec - Generic codec parser 5841 * snd_hda_parse_generic_codec - Generic codec parser
5529 * @codec: the HDA codec 5842 * @codec: the HDA codec
5530 *
5531 * This should be called from the HDA codec core.
5532 */ 5843 */
5533int snd_hda_parse_generic_codec(struct hda_codec *codec) 5844static int snd_hda_parse_generic_codec(struct hda_codec *codec)
5534{ 5845{
5535 struct hda_gen_spec *spec; 5846 struct hda_gen_spec *spec;
5536 int err; 5847 int err;
@@ -5556,7 +5867,17 @@ error:
5556 snd_hda_gen_free(codec); 5867 snd_hda_gen_free(codec);
5557 return err; 5868 return err;
5558} 5869}
5559EXPORT_SYMBOL_GPL(snd_hda_parse_generic_codec); 5870
5871static const struct hda_codec_preset snd_hda_preset_generic[] = {
5872 { .id = HDA_CODEC_ID_GENERIC, .patch = snd_hda_parse_generic_codec },
5873 {} /* terminator */
5874};
5875
5876static struct hda_codec_driver generic_driver = {
5877 .preset = snd_hda_preset_generic,
5878};
5879
5880module_hda_codec_driver(generic_driver);
5560 5881
5561MODULE_LICENSE("GPL"); 5882MODULE_LICENSE("GPL");
5562MODULE_DESCRIPTION("Generic HD-audio codec parser"); 5883MODULE_DESCRIPTION("Generic HD-audio codec parser");
diff --git a/sound/pci/hda/hda_generic.h b/sound/pci/hda/hda_generic.h
index 3d852660443a..56e4139b9032 100644
--- a/sound/pci/hda/hda_generic.h
+++ b/sound/pci/hda/hda_generic.h
@@ -46,7 +46,10 @@ struct nid_path {
46 unsigned char idx[MAX_NID_PATH_DEPTH]; 46 unsigned char idx[MAX_NID_PATH_DEPTH];
47 unsigned char multi[MAX_NID_PATH_DEPTH]; 47 unsigned char multi[MAX_NID_PATH_DEPTH];
48 unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */ 48 unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */
49 bool active; 49 bool active:1; /* activated by driver */
50 bool pin_enabled:1; /* pins are enabled */
51 bool pin_fixed:1; /* path with fixed pin */
52 bool stream_enabled:1; /* stream is active */
50}; 53};
51 54
52/* mic/line-in auto switching entry */ 55/* mic/line-in auto switching entry */
@@ -144,7 +147,7 @@ struct hda_gen_spec {
144 int const_channel_count; /* channel count for all */ 147 int const_channel_count; /* channel count for all */
145 148
146 /* PCM information */ 149 /* PCM information */
147 struct hda_pcm pcm_rec[3]; /* used in build_pcms() */ 150 struct hda_pcm *pcm_rec[3]; /* used in build_pcms() */
148 151
149 /* dynamic controls, init_verbs and input_mux */ 152 /* dynamic controls, init_verbs and input_mux */
150 struct auto_pin_cfg autocfg; 153 struct auto_pin_cfg autocfg;
@@ -340,5 +343,7 @@ int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid);
340unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec, 343unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
341 hda_nid_t nid, 344 hda_nid_t nid,
342 unsigned int power_state); 345 unsigned int power_state);
346void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on);
347int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin);
343 348
344#endif /* __SOUND_HDA_GENERIC_H */ 349#endif /* __SOUND_HDA_GENERIC_H */
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
index 11b5a42b4ec8..57df06e76968 100644
--- a/sound/pci/hda/hda_hwdep.c
+++ b/sound/pci/hda/hda_hwdep.c
@@ -101,7 +101,7 @@ int snd_hda_create_hwdep(struct hda_codec *codec)
101 int err; 101 int err;
102 102
103 sprintf(hwname, "HDA Codec %d", codec->addr); 103 sprintf(hwname, "HDA Codec %d", codec->addr);
104 err = snd_hwdep_new(codec->bus->card, hwname, codec->addr, &hwdep); 104 err = snd_hwdep_new(codec->card, hwname, codec->addr, &hwdep);
105 if (err < 0) 105 if (err < 0)
106 return err; 106 return err;
107 codec->hwdep = hwdep; 107 codec->hwdep = hwdep;
@@ -116,9 +116,6 @@ int snd_hda_create_hwdep(struct hda_codec *codec)
116 hwdep->ops.ioctl_compat = hda_hwdep_ioctl_compat; 116 hwdep->ops.ioctl_compat = hda_hwdep_ioctl_compat;
117#endif 117#endif
118 118
119 /* link to codec */
120 hwdep->dev.parent = &codec->dev;
121
122 /* for sysfs */ 119 /* for sysfs */
123 hwdep->dev.groups = snd_hda_dev_attr_groups; 120 hwdep->dev.groups = snd_hda_dev_attr_groups;
124 dev_set_drvdata(&hwdep->dev, codec); 121 dev_set_drvdata(&hwdep->dev, codec);
diff --git a/sound/pci/hda/hda_i915.c b/sound/pci/hda/hda_i915.c
index 714894527e06..52a85d87c23c 100644
--- a/sound/pci/hda/hda_i915.c
+++ b/sound/pci/hda/hda_i915.c
@@ -22,7 +22,7 @@
22#include <linux/component.h> 22#include <linux/component.h>
23#include <drm/i915_component.h> 23#include <drm/i915_component.h>
24#include <sound/core.h> 24#include <sound/core.h>
25#include "hda_priv.h" 25#include "hda_controller.h"
26#include "hda_intel.h" 26#include "hda_intel.h"
27 27
28/* Intel HSW/BDW display HDA controller Extended Mode registers. 28/* Intel HSW/BDW display HDA controller Extended Mode registers.
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 4ca3d5d02436..060f7a2b1aeb 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -62,7 +62,6 @@
62#include <linux/firmware.h> 62#include <linux/firmware.h>
63#include "hda_codec.h" 63#include "hda_codec.h"
64#include "hda_controller.h" 64#include "hda_controller.h"
65#include "hda_priv.h"
66#include "hda_intel.h" 65#include "hda_intel.h"
67 66
68/* position fix mode */ 67/* position fix mode */
@@ -174,7 +173,6 @@ static struct kernel_param_ops param_ops_xint = {
174#define param_check_xint param_check_int 173#define param_check_xint param_check_int
175 174
176static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT; 175static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
177static int *power_save_addr = &power_save;
178module_param(power_save, xint, 0644); 176module_param(power_save, xint, 0644);
179MODULE_PARM_DESC(power_save, "Automatic power-saving timeout " 177MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
180 "(in second, 0 = disable)."); 178 "(in second, 0 = disable).");
@@ -187,7 +185,7 @@ static bool power_save_controller = 1;
187module_param(power_save_controller, bool, 0644); 185module_param(power_save_controller, bool, 0644);
188MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode."); 186MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode.");
189#else 187#else
190static int *power_save_addr; 188#define power_save 0
191#endif /* CONFIG_PM */ 189#endif /* CONFIG_PM */
192 190
193static int align_buffer_size = -1; 191static int align_buffer_size = -1;
@@ -530,10 +528,10 @@ static int azx_position_check(struct azx *chip, struct azx_dev *azx_dev)
530 if (ok == 1) { 528 if (ok == 1) {
531 azx_dev->irq_pending = 0; 529 azx_dev->irq_pending = 0;
532 return ok; 530 return ok;
533 } else if (ok == 0 && chip->bus && chip->bus->workq) { 531 } else if (ok == 0) {
534 /* bogus IRQ, process it later */ 532 /* bogus IRQ, process it later */
535 azx_dev->irq_pending = 1; 533 azx_dev->irq_pending = 1;
536 queue_work(chip->bus->workq, &hda->irq_pending_work); 534 schedule_work(&hda->irq_pending_work);
537 } 535 }
538 return 0; 536 return 0;
539} 537}
@@ -741,7 +739,6 @@ static int param_set_xint(const char *val, const struct kernel_param *kp)
741{ 739{
742 struct hda_intel *hda; 740 struct hda_intel *hda;
743 struct azx *chip; 741 struct azx *chip;
744 struct hda_codec *c;
745 int prev = power_save; 742 int prev = power_save;
746 int ret = param_set_int(val, kp); 743 int ret = param_set_int(val, kp);
747 744
@@ -753,8 +750,7 @@ static int param_set_xint(const char *val, const struct kernel_param *kp)
753 chip = &hda->chip; 750 chip = &hda->chip;
754 if (!chip->bus || chip->disabled) 751 if (!chip->bus || chip->disabled)
755 continue; 752 continue;
756 list_for_each_entry(c, &chip->bus->codec_list, list) 753 snd_hda_set_power_save(chip->bus, power_save * 1000);
757 snd_hda_power_sync(c);
758 } 754 }
759 mutex_unlock(&card_list_lock); 755 mutex_unlock(&card_list_lock);
760 return 0; 756 return 0;
@@ -773,7 +769,6 @@ static int azx_suspend(struct device *dev)
773 struct snd_card *card = dev_get_drvdata(dev); 769 struct snd_card *card = dev_get_drvdata(dev);
774 struct azx *chip; 770 struct azx *chip;
775 struct hda_intel *hda; 771 struct hda_intel *hda;
776 struct azx_pcm *p;
777 772
778 if (!card) 773 if (!card)
779 return 0; 774 return 0;
@@ -785,10 +780,6 @@ static int azx_suspend(struct device *dev)
785 780
786 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 781 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
787 azx_clear_irq_pending(chip); 782 azx_clear_irq_pending(chip);
788 list_for_each_entry(p, &chip->pcm_list, list)
789 snd_pcm_suspend_all(p->pcm);
790 if (chip->initialized)
791 snd_hda_suspend(chip->bus);
792 azx_stop_chip(chip); 783 azx_stop_chip(chip);
793 azx_enter_link_reset(chip); 784 azx_enter_link_reset(chip);
794 if (chip->irq >= 0) { 785 if (chip->irq >= 0) {
@@ -831,7 +822,6 @@ static int azx_resume(struct device *dev)
831 822
832 azx_init_chip(chip, true); 823 azx_init_chip(chip, true);
833 824
834 snd_hda_resume(chip->bus);
835 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 825 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
836 return 0; 826 return 0;
837} 827}
@@ -852,7 +842,7 @@ static int azx_runtime_suspend(struct device *dev)
852 if (chip->disabled || hda->init_failed) 842 if (chip->disabled || hda->init_failed)
853 return 0; 843 return 0;
854 844
855 if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) 845 if (!azx_has_pm_runtime(chip))
856 return 0; 846 return 0;
857 847
858 /* enable controller wake up event */ 848 /* enable controller wake up event */
@@ -885,7 +875,7 @@ static int azx_runtime_resume(struct device *dev)
885 if (chip->disabled || hda->init_failed) 875 if (chip->disabled || hda->init_failed)
886 return 0; 876 return 0;
887 877
888 if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) 878 if (!azx_has_pm_runtime(chip))
889 return 0; 879 return 0;
890 880
891 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { 881 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
@@ -903,8 +893,8 @@ static int azx_runtime_resume(struct device *dev)
903 if (status && bus) { 893 if (status && bus) {
904 list_for_each_entry(codec, &bus->codec_list, list) 894 list_for_each_entry(codec, &bus->codec_list, list)
905 if (status & (1 << codec->addr)) 895 if (status & (1 << codec->addr))
906 queue_delayed_work(codec->bus->workq, 896 schedule_delayed_work(&codec->jackpoll_work,
907 &codec->jackpoll_work, codec->jackpoll_interval); 897 codec->jackpoll_interval);
908 } 898 }
909 899
910 /* disable controller Wake Up event*/ 900 /* disable controller Wake Up event*/
@@ -928,8 +918,8 @@ static int azx_runtime_idle(struct device *dev)
928 if (chip->disabled || hda->init_failed) 918 if (chip->disabled || hda->init_failed)
929 return 0; 919 return 0;
930 920
931 if (!power_save_controller || 921 if (!power_save_controller || !azx_has_pm_runtime(chip) ||
932 !(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) 922 chip->bus->codec_powered)
933 return -EBUSY; 923 return -EBUSY;
934 924
935 return 0; 925 return 0;
@@ -1071,14 +1061,11 @@ static int azx_free(struct azx *chip)
1071 struct hda_intel *hda = container_of(chip, struct hda_intel, chip); 1061 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
1072 int i; 1062 int i;
1073 1063
1074 if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME) 1064 if (azx_has_pm_runtime(chip) && chip->running)
1075 && chip->running)
1076 pm_runtime_get_noresume(&pci->dev); 1065 pm_runtime_get_noresume(&pci->dev);
1077 1066
1078 azx_del_card_list(chip); 1067 azx_del_card_list(chip);
1079 1068
1080 azx_notifier_unregister(chip);
1081
1082 hda->init_failed = 1; /* to be sure */ 1069 hda->init_failed = 1; /* to be sure */
1083 complete_all(&hda->probe_wait); 1070 complete_all(&hda->probe_wait);
1084 1071
@@ -1394,7 +1381,6 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
1394 1381
1395 hda = kzalloc(sizeof(*hda), GFP_KERNEL); 1382 hda = kzalloc(sizeof(*hda), GFP_KERNEL);
1396 if (!hda) { 1383 if (!hda) {
1397 dev_err(card->dev, "Cannot allocate hda\n");
1398 pci_disable_device(pci); 1384 pci_disable_device(pci);
1399 return -ENOMEM; 1385 return -ENOMEM;
1400 } 1386 }
@@ -1575,10 +1561,8 @@ static int azx_first_init(struct azx *chip)
1575 chip->num_streams = chip->playback_streams + chip->capture_streams; 1561 chip->num_streams = chip->playback_streams + chip->capture_streams;
1576 chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev), 1562 chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev),
1577 GFP_KERNEL); 1563 GFP_KERNEL);
1578 if (!chip->azx_dev) { 1564 if (!chip->azx_dev)
1579 dev_err(card->dev, "cannot malloc azx_dev\n");
1580 return -ENOMEM; 1565 return -ENOMEM;
1581 }
1582 1566
1583 err = azx_alloc_stream_pages(chip); 1567 err = azx_alloc_stream_pages(chip);
1584 if (err < 0) 1568 if (err < 0)
@@ -1615,19 +1599,6 @@ static int azx_first_init(struct azx *chip)
1615 return 0; 1599 return 0;
1616} 1600}
1617 1601
1618static void power_down_all_codecs(struct azx *chip)
1619{
1620#ifdef CONFIG_PM
1621 /* The codecs were powered up in snd_hda_codec_new().
1622 * Now all initialization done, so turn them down if possible
1623 */
1624 struct hda_codec *codec;
1625 list_for_each_entry(codec, &chip->bus->codec_list, list) {
1626 snd_hda_power_down(codec);
1627 }
1628#endif
1629}
1630
1631#ifdef CONFIG_SND_HDA_PATCH_LOADER 1602#ifdef CONFIG_SND_HDA_PATCH_LOADER
1632/* callback from request_firmware_nowait() */ 1603/* callback from request_firmware_nowait() */
1633static void azx_firmware_cb(const struct firmware *fw, void *context) 1604static void azx_firmware_cb(const struct firmware *fw, void *context)
@@ -1896,12 +1867,14 @@ static int azx_probe_continue(struct azx *chip)
1896#endif 1867#endif
1897 1868
1898 /* create codec instances */ 1869 /* create codec instances */
1899 err = azx_codec_create(chip, model[dev], 1870 err = azx_bus_create(chip, model[dev]);
1900 azx_max_codecs[chip->driver_type], 1871 if (err < 0)
1901 power_save_addr); 1872 goto out_free;
1902 1873
1874 err = azx_probe_codecs(chip, azx_max_codecs[chip->driver_type]);
1903 if (err < 0) 1875 if (err < 0)
1904 goto out_free; 1876 goto out_free;
1877
1905#ifdef CONFIG_SND_HDA_PATCH_LOADER 1878#ifdef CONFIG_SND_HDA_PATCH_LOADER
1906 if (chip->fw) { 1879 if (chip->fw) {
1907 err = snd_hda_load_patch(chip->bus, chip->fw->size, 1880 err = snd_hda_load_patch(chip->bus, chip->fw->size,
@@ -1920,25 +1893,14 @@ static int azx_probe_continue(struct azx *chip)
1920 goto out_free; 1893 goto out_free;
1921 } 1894 }
1922 1895
1923 /* create PCM streams */
1924 err = snd_hda_build_pcms(chip->bus);
1925 if (err < 0)
1926 goto out_free;
1927
1928 /* create mixer controls */
1929 err = azx_mixer_create(chip);
1930 if (err < 0)
1931 goto out_free;
1932
1933 err = snd_card_register(chip->card); 1896 err = snd_card_register(chip->card);
1934 if (err < 0) 1897 if (err < 0)
1935 goto out_free; 1898 goto out_free;
1936 1899
1937 chip->running = 1; 1900 chip->running = 1;
1938 power_down_all_codecs(chip);
1939 azx_notifier_register(chip);
1940 azx_add_card_list(chip); 1901 azx_add_card_list(chip);
1941 if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME) || hda->use_vga_switcheroo) 1902 snd_hda_set_power_save(chip->bus, power_save * 1000);
1903 if (azx_has_pm_runtime(chip) || hda->use_vga_switcheroo)
1942 pm_runtime_put_noidle(&pci->dev); 1904 pm_runtime_put_noidle(&pci->dev);
1943 1905
1944out_free: 1906out_free:
@@ -1956,6 +1918,18 @@ static void azx_remove(struct pci_dev *pci)
1956 snd_card_free(card); 1918 snd_card_free(card);
1957} 1919}
1958 1920
1921static void azx_shutdown(struct pci_dev *pci)
1922{
1923 struct snd_card *card = pci_get_drvdata(pci);
1924 struct azx *chip;
1925
1926 if (!card)
1927 return;
1928 chip = card->private_data;
1929 if (chip && chip->running)
1930 azx_stop_chip(chip);
1931}
1932
1959/* PCI IDs */ 1933/* PCI IDs */
1960static const struct pci_device_id azx_ids[] = { 1934static const struct pci_device_id azx_ids[] = {
1961 /* CPT */ 1935 /* CPT */
@@ -2178,6 +2152,7 @@ static struct pci_driver azx_driver = {
2178 .id_table = azx_ids, 2152 .id_table = azx_ids,
2179 .probe = azx_probe, 2153 .probe = azx_probe,
2180 .remove = azx_remove, 2154 .remove = azx_remove,
2155 .shutdown = azx_shutdown,
2181 .driver = { 2156 .driver = {
2182 .pm = AZX_PM_OPS, 2157 .pm = AZX_PM_OPS,
2183 }, 2158 },
diff --git a/sound/pci/hda/hda_intel.h b/sound/pci/hda/hda_intel.h
index 348611835476..d5231f7216a7 100644
--- a/sound/pci/hda/hda_intel.h
+++ b/sound/pci/hda/hda_intel.h
@@ -17,7 +17,7 @@
17#define __SOUND_HDA_INTEL_H 17#define __SOUND_HDA_INTEL_H
18 18
19#include <drm/i915_component.h> 19#include <drm/i915_component.h>
20#include "hda_priv.h" 20#include "hda_controller.h"
21 21
22struct hda_intel { 22struct hda_intel {
23 struct azx chip; 23 struct azx chip;
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
index e664307617bd..d7cfe7b8c32b 100644
--- a/sound/pci/hda/hda_jack.c
+++ b/sound/pci/hda/hda_jack.c
@@ -135,7 +135,7 @@ void snd_hda_jack_tbl_clear(struct hda_codec *codec)
135#ifdef CONFIG_SND_HDA_INPUT_JACK 135#ifdef CONFIG_SND_HDA_INPUT_JACK
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->bus->card, jack->jack); 138 snd_device_free(codec->card, jack->jack);
139#endif 139#endif
140 for (cb = jack->callback; cb; cb = next) { 140 for (cb = jack->callback; cb; cb = next) {
141 next = cb->next; 141 next = cb->next;
@@ -340,7 +340,7 @@ void snd_hda_jack_report_sync(struct hda_codec *codec)
340 if (!jack->kctl || jack->block_report) 340 if (!jack->kctl || 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->bus->card, jack->kctl, state); 343 snd_kctl_jack_report(codec->card, jack->kctl, state);
344#ifdef CONFIG_SND_HDA_INPUT_JACK 344#ifdef CONFIG_SND_HDA_INPUT_JACK
345 if (jack->jack) 345 if (jack->jack)
346 snd_jack_report(jack->jack, 346 snd_jack_report(jack->jack,
@@ -412,11 +412,11 @@ static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
412 jack->phantom_jack = !!phantom_jack; 412 jack->phantom_jack = !!phantom_jack;
413 413
414 state = snd_hda_jack_detect(codec, nid); 414 state = snd_hda_jack_detect(codec, nid);
415 snd_kctl_jack_report(codec->bus->card, kctl, state); 415 snd_kctl_jack_report(codec->card, kctl, state);
416#ifdef CONFIG_SND_HDA_INPUT_JACK 416#ifdef CONFIG_SND_HDA_INPUT_JACK
417 if (!phantom_jack) { 417 if (!phantom_jack) {
418 jack->type = get_input_jack_type(codec, nid); 418 jack->type = get_input_jack_type(codec, nid);
419 err = snd_jack_new(codec->bus->card, name, jack->type, 419 err = snd_jack_new(codec->card, name, jack->type,
420 &jack->jack); 420 &jack->jack);
421 if (err < 0) 421 if (err < 0)
422 return err; 422 return err;
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 62658f2f8c9f..1d001647fc47 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -150,6 +150,7 @@ int __snd_hda_add_vmaster(struct hda_codec *codec, char *name,
150#define snd_hda_add_vmaster(codec, name, tlv, slaves, suffix) \ 150#define snd_hda_add_vmaster(codec, name, tlv, slaves, suffix) \
151 __snd_hda_add_vmaster(codec, name, tlv, slaves, suffix, true, NULL) 151 __snd_hda_add_vmaster(codec, name, tlv, slaves, suffix, true, NULL)
152int snd_hda_codec_reset(struct hda_codec *codec); 152int snd_hda_codec_reset(struct hda_codec *codec);
153void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec);
153 154
154enum { 155enum {
155 HDA_VMUTE_OFF, 156 HDA_VMUTE_OFF,
@@ -273,29 +274,6 @@ int snd_hda_add_imux_item(struct hda_codec *codec,
273 int index, int *type_index_ret); 274 int index, int *type_index_ret);
274 275
275/* 276/*
276 * Channel mode helper
277 */
278struct hda_channel_mode {
279 int channels;
280 const struct hda_verb *sequence;
281};
282
283int snd_hda_ch_mode_info(struct hda_codec *codec,
284 struct snd_ctl_elem_info *uinfo,
285 const struct hda_channel_mode *chmode,
286 int num_chmodes);
287int snd_hda_ch_mode_get(struct hda_codec *codec,
288 struct snd_ctl_elem_value *ucontrol,
289 const struct hda_channel_mode *chmode,
290 int num_chmodes,
291 int max_channels);
292int snd_hda_ch_mode_put(struct hda_codec *codec,
293 struct snd_ctl_elem_value *ucontrol,
294 const struct hda_channel_mode *chmode,
295 int num_chmodes,
296 int *max_channelsp);
297
298/*
299 * Multi-channel / digital-out PCM helper 277 * Multi-channel / digital-out PCM helper
300 */ 278 */
301 279
@@ -351,12 +329,6 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
351 struct hda_multi_out *mout); 329 struct hda_multi_out *mout);
352 330
353/* 331/*
354 * generic codec parser
355 */
356int snd_hda_parse_generic_codec(struct hda_codec *codec);
357int snd_hda_parse_hdmi_codec(struct hda_codec *codec);
358
359/*
360 * generic proc interface 332 * generic proc interface
361 */ 333 */
362#ifdef CONFIG_PROC_FS 334#ifdef CONFIG_PROC_FS
@@ -466,23 +438,6 @@ void snd_hda_pick_pin_fixup(struct hda_codec *codec,
466 const struct snd_hda_pin_quirk *pin_quirk, 438 const struct snd_hda_pin_quirk *pin_quirk,
467 const struct hda_fixup *fixlist); 439 const struct hda_fixup *fixlist);
468 440
469
470/*
471 * unsolicited event handler
472 */
473
474#define HDA_UNSOL_QUEUE_SIZE 64
475
476struct hda_bus_unsolicited {
477 /* ring buffer */
478 u32 queue[HDA_UNSOL_QUEUE_SIZE * 2];
479 unsigned int rp, wp;
480
481 /* workqueue */
482 struct work_struct work;
483 struct hda_bus *bus;
484};
485
486/* helper macros to retrieve pin default-config values */ 441/* helper macros to retrieve pin default-config values */
487#define get_defcfg_connect(cfg) \ 442#define get_defcfg_connect(cfg) \
488 ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT) 443 ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
@@ -800,9 +755,13 @@ void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
800 755
801/* 756/*
802 */ 757 */
803#define codec_err(codec, fmt, args...) dev_err(&(codec)->dev, fmt, ##args) 758#define codec_err(codec, fmt, args...) \
804#define codec_warn(codec, fmt, args...) dev_warn(&(codec)->dev, fmt, ##args) 759 dev_err(hda_codec_dev(codec), fmt, ##args)
805#define codec_info(codec, fmt, args...) dev_info(&(codec)->dev, fmt, ##args) 760#define codec_warn(codec, fmt, args...) \
806#define codec_dbg(codec, fmt, args...) dev_dbg(&(codec)->dev, fmt, ##args) 761 dev_warn(hda_codec_dev(codec), fmt, ##args)
762#define codec_info(codec, fmt, args...) \
763 dev_info(hda_codec_dev(codec), fmt, ##args)
764#define codec_dbg(codec, fmt, args...) \
765 dev_dbg(hda_codec_dev(codec), fmt, ##args)
807 766
808#endif /* __SOUND_HDA_LOCAL_H */ 767#endif /* __SOUND_HDA_LOCAL_H */
diff --git a/sound/pci/hda/hda_priv.h b/sound/pci/hda/hda_priv.h
deleted file mode 100644
index daf458299753..000000000000
--- a/sound/pci/hda/hda_priv.h
+++ /dev/null
@@ -1,406 +0,0 @@
1/*
2 * Common defines for the alsa driver code base for HD Audio.
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 WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef __SOUND_HDA_PRIV_H
16#define __SOUND_HDA_PRIV_H
17
18#include <linux/timecounter.h>
19#include <sound/core.h>
20#include <sound/pcm.h>
21
22/*
23 * registers
24 */
25#define AZX_REG_GCAP 0x00
26#define AZX_GCAP_64OK (1 << 0) /* 64bit address support */
27#define AZX_GCAP_NSDO (3 << 1) /* # of serial data out signals */
28#define AZX_GCAP_BSS (31 << 3) /* # of bidirectional streams */
29#define AZX_GCAP_ISS (15 << 8) /* # of input streams */
30#define AZX_GCAP_OSS (15 << 12) /* # of output streams */
31#define AZX_REG_VMIN 0x02
32#define AZX_REG_VMAJ 0x03
33#define AZX_REG_OUTPAY 0x04
34#define AZX_REG_INPAY 0x06
35#define AZX_REG_GCTL 0x08
36#define AZX_GCTL_RESET (1 << 0) /* controller reset */
37#define AZX_GCTL_FCNTRL (1 << 1) /* flush control */
38#define AZX_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */
39#define AZX_REG_WAKEEN 0x0c
40#define AZX_REG_STATESTS 0x0e
41#define AZX_REG_GSTS 0x10
42#define AZX_GSTS_FSTS (1 << 1) /* flush status */
43#define AZX_REG_INTCTL 0x20
44#define AZX_REG_INTSTS 0x24
45#define AZX_REG_WALLCLK 0x30 /* 24Mhz source */
46#define AZX_REG_OLD_SSYNC 0x34 /* SSYNC for old ICH */
47#define AZX_REG_SSYNC 0x38
48#define AZX_REG_CORBLBASE 0x40
49#define AZX_REG_CORBUBASE 0x44
50#define AZX_REG_CORBWP 0x48
51#define AZX_REG_CORBRP 0x4a
52#define AZX_CORBRP_RST (1 << 15) /* read pointer reset */
53#define AZX_REG_CORBCTL 0x4c
54#define AZX_CORBCTL_RUN (1 << 1) /* enable DMA */
55#define AZX_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */
56#define AZX_REG_CORBSTS 0x4d
57#define AZX_CORBSTS_CMEI (1 << 0) /* memory error indication */
58#define AZX_REG_CORBSIZE 0x4e
59
60#define AZX_REG_RIRBLBASE 0x50
61#define AZX_REG_RIRBUBASE 0x54
62#define AZX_REG_RIRBWP 0x58
63#define AZX_RIRBWP_RST (1 << 15) /* write pointer reset */
64#define AZX_REG_RINTCNT 0x5a
65#define AZX_REG_RIRBCTL 0x5c
66#define AZX_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */
67#define AZX_RBCTL_DMA_EN (1 << 1) /* enable DMA */
68#define AZX_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */
69#define AZX_REG_RIRBSTS 0x5d
70#define AZX_RBSTS_IRQ (1 << 0) /* response irq */
71#define AZX_RBSTS_OVERRUN (1 << 2) /* overrun irq */
72#define AZX_REG_RIRBSIZE 0x5e
73
74#define AZX_REG_IC 0x60
75#define AZX_REG_IR 0x64
76#define AZX_REG_IRS 0x68
77#define AZX_IRS_VALID (1<<1)
78#define AZX_IRS_BUSY (1<<0)
79
80#define AZX_REG_DPLBASE 0x70
81#define AZX_REG_DPUBASE 0x74
82#define AZX_DPLBASE_ENABLE 0x1 /* Enable position buffer */
83
84/* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
85enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
86
87/* stream register offsets from stream base */
88#define AZX_REG_SD_CTL 0x00
89#define AZX_REG_SD_STS 0x03
90#define AZX_REG_SD_LPIB 0x04
91#define AZX_REG_SD_CBL 0x08
92#define AZX_REG_SD_LVI 0x0c
93#define AZX_REG_SD_FIFOW 0x0e
94#define AZX_REG_SD_FIFOSIZE 0x10
95#define AZX_REG_SD_FORMAT 0x12
96#define AZX_REG_SD_BDLPL 0x18
97#define AZX_REG_SD_BDLPU 0x1c
98
99/* PCI space */
100#define AZX_PCIREG_TCSEL 0x44
101
102/*
103 * other constants
104 */
105
106/* max number of fragments - we may use more if allocating more pages for BDL */
107#define BDL_SIZE 4096
108#define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
109#define AZX_MAX_FRAG 32
110/* max buffer size - no h/w limit, you can increase as you like */
111#define AZX_MAX_BUF_SIZE (1024*1024*1024)
112
113/* RIRB int mask: overrun[2], response[0] */
114#define RIRB_INT_RESPONSE 0x01
115#define RIRB_INT_OVERRUN 0x04
116#define RIRB_INT_MASK 0x05
117
118/* STATESTS int mask: S3,SD2,SD1,SD0 */
119#define AZX_MAX_CODECS 8
120#define AZX_DEFAULT_CODECS 4
121#define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1)
122
123/* SD_CTL bits */
124#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
125#define SD_CTL_DMA_START 0x02 /* stream DMA start bit */
126#define SD_CTL_STRIPE (3 << 16) /* stripe control */
127#define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
128#define SD_CTL_DIR (1 << 19) /* bi-directional stream */
129#define SD_CTL_STREAM_TAG_MASK (0xf << 20)
130#define SD_CTL_STREAM_TAG_SHIFT 20
131
132/* SD_CTL and SD_STS */
133#define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */
134#define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */
135#define SD_INT_COMPLETE 0x04 /* completion interrupt */
136#define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
137 SD_INT_COMPLETE)
138
139/* SD_STS */
140#define SD_STS_FIFO_READY 0x20 /* FIFO ready */
141
142/* INTCTL and INTSTS */
143#define AZX_INT_ALL_STREAM 0xff /* all stream interrupts */
144#define AZX_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */
145#define AZX_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */
146
147/* below are so far hardcoded - should read registers in future */
148#define AZX_MAX_CORB_ENTRIES 256
149#define AZX_MAX_RIRB_ENTRIES 256
150
151/* driver quirks (capabilities) */
152/* bits 0-7 are used for indicating driver type */
153#define AZX_DCAPS_NO_TCSEL (1 << 8) /* No Intel TCSEL bit */
154#define AZX_DCAPS_NO_MSI (1 << 9) /* No MSI support */
155#define AZX_DCAPS_SNOOP_MASK (3 << 10) /* snoop type mask */
156#define AZX_DCAPS_SNOOP_OFF (1 << 12) /* snoop default off */
157#define AZX_DCAPS_RIRB_DELAY (1 << 13) /* Long delay in read loop */
158#define AZX_DCAPS_RIRB_PRE_DELAY (1 << 14) /* Put a delay before read */
159#define AZX_DCAPS_CTX_WORKAROUND (1 << 15) /* X-Fi workaround */
160#define AZX_DCAPS_POSFIX_LPIB (1 << 16) /* Use LPIB as default */
161#define AZX_DCAPS_POSFIX_VIA (1 << 17) /* Use VIACOMBO as default */
162#define AZX_DCAPS_NO_64BIT (1 << 18) /* No 64bit address */
163#define AZX_DCAPS_SYNC_WRITE (1 << 19) /* sync each cmd write */
164#define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */
165#define AZX_DCAPS_NO_ALIGN_BUFSIZE (1 << 21) /* no buffer size alignment */
166/* 22 unused */
167#define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23) /* BDLE in 4k boundary */
168#define AZX_DCAPS_REVERSE_ASSIGN (1 << 24) /* Assign devices in reverse order */
169#define AZX_DCAPS_COUNT_LPIB_DELAY (1 << 25) /* Take LPIB as delay */
170#define AZX_DCAPS_PM_RUNTIME (1 << 26) /* runtime PM support */
171#define AZX_DCAPS_I915_POWERWELL (1 << 27) /* HSW i915 powerwell support */
172#define AZX_DCAPS_CORBRP_SELF_CLEAR (1 << 28) /* CORBRP clears itself after reset */
173#define AZX_DCAPS_NO_MSI64 (1 << 29) /* Stick to 32-bit MSIs */
174#define AZX_DCAPS_SEPARATE_STREAM_TAG (1 << 30) /* capture and playback use separate stream tag */
175
176enum {
177 AZX_SNOOP_TYPE_NONE ,
178 AZX_SNOOP_TYPE_SCH,
179 AZX_SNOOP_TYPE_ATI,
180 AZX_SNOOP_TYPE_NVIDIA,
181};
182
183/* HD Audio class code */
184#define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
185
186struct azx_dev {
187 struct snd_dma_buffer bdl; /* BDL buffer */
188 u32 *posbuf; /* position buffer pointer */
189
190 unsigned int bufsize; /* size of the play buffer in bytes */
191 unsigned int period_bytes; /* size of the period in bytes */
192 unsigned int frags; /* number for period in the play buffer */
193 unsigned int fifo_size; /* FIFO size */
194 unsigned long start_wallclk; /* start + minimum wallclk */
195 unsigned long period_wallclk; /* wallclk for period */
196
197 void __iomem *sd_addr; /* stream descriptor pointer */
198
199 u32 sd_int_sta_mask; /* stream int status mask */
200
201 /* pcm support */
202 struct snd_pcm_substream *substream; /* assigned substream,
203 * set in PCM open
204 */
205 unsigned int format_val; /* format value to be set in the
206 * controller and the codec
207 */
208 unsigned char stream_tag; /* assigned stream */
209 unsigned char index; /* stream index */
210 int assigned_key; /* last device# key assigned to */
211
212 unsigned int opened:1;
213 unsigned int running:1;
214 unsigned int irq_pending:1;
215 unsigned int prepared:1;
216 unsigned int locked:1;
217 /*
218 * For VIA:
219 * A flag to ensure DMA position is 0
220 * when link position is not greater than FIFO size
221 */
222 unsigned int insufficient:1;
223 unsigned int wc_marked:1;
224 unsigned int no_period_wakeup:1;
225
226 struct timecounter azx_tc;
227 struct cyclecounter azx_cc;
228
229 int delay_negative_threshold;
230
231#ifdef CONFIG_SND_HDA_DSP_LOADER
232 /* Allows dsp load to have sole access to the playback stream. */
233 struct mutex dsp_mutex;
234#endif
235};
236
237/* CORB/RIRB */
238struct azx_rb {
239 u32 *buf; /* CORB/RIRB buffer
240 * Each CORB entry is 4byte, RIRB is 8byte
241 */
242 dma_addr_t addr; /* physical address of CORB/RIRB buffer */
243 /* for RIRB */
244 unsigned short rp, wp; /* read/write pointers */
245 int cmds[AZX_MAX_CODECS]; /* number of pending requests */
246 u32 res[AZX_MAX_CODECS]; /* last read value */
247};
248
249struct azx;
250
251/* Functions to read/write to hda registers. */
252struct hda_controller_ops {
253 /* Register Access */
254 void (*reg_writel)(u32 value, u32 __iomem *addr);
255 u32 (*reg_readl)(u32 __iomem *addr);
256 void (*reg_writew)(u16 value, u16 __iomem *addr);
257 u16 (*reg_readw)(u16 __iomem *addr);
258 void (*reg_writeb)(u8 value, u8 __iomem *addr);
259 u8 (*reg_readb)(u8 __iomem *addr);
260 /* Disable msi if supported, PCI only */
261 int (*disable_msi_reset_irq)(struct azx *);
262 /* Allocation ops */
263 int (*dma_alloc_pages)(struct azx *chip,
264 int type,
265 size_t size,
266 struct snd_dma_buffer *buf);
267 void (*dma_free_pages)(struct azx *chip, struct snd_dma_buffer *buf);
268 int (*substream_alloc_pages)(struct azx *chip,
269 struct snd_pcm_substream *substream,
270 size_t size);
271 int (*substream_free_pages)(struct azx *chip,
272 struct snd_pcm_substream *substream);
273 void (*pcm_mmap_prepare)(struct snd_pcm_substream *substream,
274 struct vm_area_struct *area);
275 /* Check if current position is acceptable */
276 int (*position_check)(struct azx *chip, struct azx_dev *azx_dev);
277};
278
279struct azx_pcm {
280 struct azx *chip;
281 struct snd_pcm *pcm;
282 struct hda_codec *codec;
283 struct hda_pcm_stream *hinfo[2];
284 struct list_head list;
285};
286
287typedef unsigned int (*azx_get_pos_callback_t)(struct azx *, struct azx_dev *);
288typedef int (*azx_get_delay_callback_t)(struct azx *, struct azx_dev *, unsigned int pos);
289
290struct azx {
291 struct snd_card *card;
292 struct pci_dev *pci;
293 int dev_index;
294
295 /* chip type specific */
296 int driver_type;
297 unsigned int driver_caps;
298 int playback_streams;
299 int playback_index_offset;
300 int capture_streams;
301 int capture_index_offset;
302 int num_streams;
303 const int *jackpoll_ms; /* per-card jack poll interval */
304
305 /* Register interaction. */
306 const struct hda_controller_ops *ops;
307
308 /* position adjustment callbacks */
309 azx_get_pos_callback_t get_position[2];
310 azx_get_delay_callback_t get_delay[2];
311
312 /* pci resources */
313 unsigned long addr;
314 void __iomem *remap_addr;
315 int irq;
316
317 /* locks */
318 spinlock_t reg_lock;
319 struct mutex open_mutex; /* Prevents concurrent open/close operations */
320
321 /* streams (x num_streams) */
322 struct azx_dev *azx_dev;
323
324 /* PCM */
325 struct list_head pcm_list; /* azx_pcm list */
326
327 /* HD codec */
328 unsigned short codec_mask;
329 int codec_probe_mask; /* copied from probe_mask option */
330 struct hda_bus *bus;
331 unsigned int beep_mode;
332
333 /* CORB/RIRB */
334 struct azx_rb corb;
335 struct azx_rb rirb;
336
337 /* CORB/RIRB and position buffers */
338 struct snd_dma_buffer rb;
339 struct snd_dma_buffer posbuf;
340
341#ifdef CONFIG_SND_HDA_PATCH_LOADER
342 const struct firmware *fw;
343#endif
344
345 /* flags */
346 const int *bdl_pos_adj;
347 int poll_count;
348 unsigned int running:1;
349 unsigned int initialized:1;
350 unsigned int single_cmd:1;
351 unsigned int polling_mode:1;
352 unsigned int msi:1;
353 unsigned int probing:1; /* codec probing phase */
354 unsigned int snoop:1;
355 unsigned int align_buffer_size:1;
356 unsigned int region_requested:1;
357 unsigned int disabled:1; /* disabled by VGA-switcher */
358
359 /* for debugging */
360 unsigned int last_cmd[AZX_MAX_CODECS];
361
362 /* reboot notifier (for mysterious hangup problem at power-down) */
363 struct notifier_block reboot_notifier;
364
365#ifdef CONFIG_SND_HDA_DSP_LOADER
366 struct azx_dev saved_azx_dev;
367#endif
368};
369
370#ifdef CONFIG_X86
371#define azx_snoop(chip) ((chip)->snoop)
372#else
373#define azx_snoop(chip) true
374#endif
375
376/*
377 * macros for easy use
378 */
379
380#define azx_writel(chip, reg, value) \
381 ((chip)->ops->reg_writel(value, (chip)->remap_addr + AZX_REG_##reg))
382#define azx_readl(chip, reg) \
383 ((chip)->ops->reg_readl((chip)->remap_addr + AZX_REG_##reg))
384#define azx_writew(chip, reg, value) \
385 ((chip)->ops->reg_writew(value, (chip)->remap_addr + AZX_REG_##reg))
386#define azx_readw(chip, reg) \
387 ((chip)->ops->reg_readw((chip)->remap_addr + AZX_REG_##reg))
388#define azx_writeb(chip, reg, value) \
389 ((chip)->ops->reg_writeb(value, (chip)->remap_addr + AZX_REG_##reg))
390#define azx_readb(chip, reg) \
391 ((chip)->ops->reg_readb((chip)->remap_addr + AZX_REG_##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
406#endif /* __SOUND_HDA_PRIV_H */
diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
index 05e19f78b4cb..dacfe74a2a1f 100644
--- a/sound/pci/hda/hda_proc.c
+++ b/sound/pci/hda/hda_proc.c
@@ -99,10 +99,10 @@ static void print_nid_array(struct snd_info_buffer *buffer,
99static void print_nid_pcms(struct snd_info_buffer *buffer, 99static void print_nid_pcms(struct snd_info_buffer *buffer,
100 struct hda_codec *codec, hda_nid_t nid) 100 struct hda_codec *codec, hda_nid_t nid)
101{ 101{
102 int pcm, type; 102 int type;
103 struct hda_pcm *cpcm; 103 struct hda_pcm *cpcm;
104 for (pcm = 0; pcm < codec->num_pcms; pcm++) { 104
105 cpcm = &codec->pcm_info[pcm]; 105 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
106 for (type = 0; type < 2; type++) { 106 for (type = 0; type < 2; type++) {
107 if (cpcm->stream[type].nid != nid || cpcm->pcm == NULL) 107 if (cpcm->stream[type].nid != nid || cpcm->pcm == NULL)
108 continue; 108 continue;
@@ -861,7 +861,7 @@ int snd_hda_codec_proc_new(struct hda_codec *codec)
861 int err; 861 int err;
862 862
863 snprintf(name, sizeof(name), "codec#%d", codec->addr); 863 snprintf(name, sizeof(name), "codec#%d", codec->addr);
864 err = snd_card_proc_new(codec->bus->card, name, &entry); 864 err = snd_card_proc_new(codec->card, name, &entry);
865 if (err < 0) 865 if (err < 0)
866 return err; 866 return err;
867 867
diff --git a/sound/pci/hda/hda_sysfs.c b/sound/pci/hda/hda_sysfs.c
index ccc962a1699f..e13c75d67847 100644
--- a/sound/pci/hda/hda_sysfs.c
+++ b/sound/pci/hda/hda_sysfs.c
@@ -149,7 +149,7 @@ static int reconfig_codec(struct hda_codec *codec)
149 err = snd_hda_codec_build_controls(codec); 149 err = snd_hda_codec_build_controls(codec);
150 if (err < 0) 150 if (err < 0)
151 goto error; 151 goto error;
152 err = snd_card_register(codec->bus->card); 152 err = snd_card_register(codec->card);
153 error: 153 error:
154 snd_hda_power_down(codec); 154 snd_hda_power_down(codec);
155 return err; 155 return err;
diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c
index 375e94f4cf52..2e4fd5c56d3b 100644
--- a/sound/pci/hda/hda_tegra.c
+++ b/sound/pci/hda/hda_tegra.c
@@ -37,7 +37,6 @@
37 37
38#include "hda_codec.h" 38#include "hda_codec.h"
39#include "hda_controller.h" 39#include "hda_controller.h"
40#include "hda_priv.h"
41 40
42/* Defines for Nvidia Tegra HDA support */ 41/* Defines for Nvidia Tegra HDA support */
43#define HDA_BAR0 0x8000 42#define HDA_BAR0 0x8000
@@ -82,7 +81,7 @@ module_param(power_save, bint, 0644);
82MODULE_PARM_DESC(power_save, 81MODULE_PARM_DESC(power_save,
83 "Automatic power-saving timeout (in seconds, 0 = disable)."); 82 "Automatic power-saving timeout (in seconds, 0 = disable).");
84#else 83#else
85static int power_save = 0; 84#define power_save 0
86#endif 85#endif
87 86
88/* 87/*
@@ -250,14 +249,9 @@ static int hda_tegra_suspend(struct device *dev)
250{ 249{
251 struct snd_card *card = dev_get_drvdata(dev); 250 struct snd_card *card = dev_get_drvdata(dev);
252 struct azx *chip = card->private_data; 251 struct azx *chip = card->private_data;
253 struct azx_pcm *p;
254 struct hda_tegra *hda = container_of(chip, struct hda_tegra, chip); 252 struct hda_tegra *hda = container_of(chip, struct hda_tegra, chip);
255 253
256 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 254 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
257 list_for_each_entry(p, &chip->pcm_list, list)
258 snd_pcm_suspend_all(p->pcm);
259 if (chip->initialized)
260 snd_hda_suspend(chip->bus);
261 255
262 azx_stop_chip(chip); 256 azx_stop_chip(chip);
263 azx_enter_link_reset(chip); 257 azx_enter_link_reset(chip);
@@ -278,7 +272,6 @@ static int hda_tegra_resume(struct device *dev)
278 272
279 azx_init_chip(chip, 1); 273 azx_init_chip(chip, 1);
280 274
281 snd_hda_resume(chip->bus);
282 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 275 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
283 276
284 return 0; 277 return 0;
@@ -297,8 +290,6 @@ static int hda_tegra_dev_free(struct snd_device *device)
297 int i; 290 int i;
298 struct azx *chip = device->device_data; 291 struct azx *chip = device->device_data;
299 292
300 azx_notifier_unregister(chip);
301
302 if (chip->initialized) { 293 if (chip->initialized) {
303 for (i = 0; i < chip->num_streams; i++) 294 for (i = 0; i < chip->num_streams; i++)
304 azx_stream_stop(chip, &chip->azx_dev[i]); 295 azx_stream_stop(chip, &chip->azx_dev[i]);
@@ -344,17 +335,6 @@ static int hda_tegra_init_chip(struct azx *chip, struct platform_device *pdev)
344 return 0; 335 return 0;
345} 336}
346 337
347/*
348 * The codecs were powered up in snd_hda_codec_new().
349 * Now all initialization done, so turn them down if possible
350 */
351static void power_down_all_codecs(struct azx *chip)
352{
353 struct hda_codec *codec;
354 list_for_each_entry(codec, &chip->bus->codec_list, list)
355 snd_hda_power_down(codec);
356}
357
358static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev) 338static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev)
359{ 339{
360 struct snd_card *card = chip->card; 340 struct snd_card *card = chip->card;
@@ -503,21 +483,15 @@ static int hda_tegra_probe(struct platform_device *pdev)
503 goto out_free; 483 goto out_free;
504 484
505 /* create codec instances */ 485 /* create codec instances */
506 err = azx_codec_create(chip, NULL, 0, &power_save); 486 err = azx_bus_create(chip, NULL);
507 if (err < 0) 487 if (err < 0)
508 goto out_free; 488 goto out_free;
509 489
510 err = azx_codec_configure(chip); 490 err = azx_probe_codecs(chip, 0);
511 if (err < 0) 491 if (err < 0)
512 goto out_free; 492 goto out_free;
513 493
514 /* create PCM streams */ 494 err = azx_codec_configure(chip);
515 err = snd_hda_build_pcms(chip->bus);
516 if (err < 0)
517 goto out_free;
518
519 /* create mixer controls */
520 err = azx_mixer_create(chip);
521 if (err < 0) 495 if (err < 0)
522 goto out_free; 496 goto out_free;
523 497
@@ -526,8 +500,7 @@ static int hda_tegra_probe(struct platform_device *pdev)
526 goto out_free; 500 goto out_free;
527 501
528 chip->running = 1; 502 chip->running = 1;
529 power_down_all_codecs(chip); 503 snd_hda_set_power_save(chip->bus, power_save * 1000);
530 azx_notifier_register(chip);
531 504
532 return 0; 505 return 0;
533 506
@@ -541,6 +514,18 @@ static int hda_tegra_remove(struct platform_device *pdev)
541 return snd_card_free(dev_get_drvdata(&pdev->dev)); 514 return snd_card_free(dev_get_drvdata(&pdev->dev));
542} 515}
543 516
517static void hda_tegra_shutdown(struct platform_device *pdev)
518{
519 struct snd_card *card = dev_get_drvdata(&pdev->dev);
520 struct azx *chip;
521
522 if (!card)
523 return;
524 chip = card->private_data;
525 if (chip && chip->running)
526 azx_stop_chip(chip);
527}
528
544static struct platform_driver tegra_platform_hda = { 529static struct platform_driver tegra_platform_hda = {
545 .driver = { 530 .driver = {
546 .name = "tegra-hda", 531 .name = "tegra-hda",
@@ -549,6 +534,7 @@ static struct platform_driver tegra_platform_hda = {
549 }, 534 },
550 .probe = hda_tegra_probe, 535 .probe = hda_tegra_probe,
551 .remove = hda_tegra_remove, 536 .remove = hda_tegra_remove,
537 .shutdown = hda_tegra_shutdown,
552}; 538};
553module_platform_driver(tegra_platform_hda); 539module_platform_driver(tegra_platform_hda);
554 540
diff --git a/sound/pci/hda/hda_trace.h b/sound/pci/hda/hda_trace.h
index 3a1c63161eb1..7fedfa862419 100644
--- a/sound/pci/hda/hda_trace.h
+++ b/sound/pci/hda/hda_trace.h
@@ -23,7 +23,7 @@ DECLARE_EVENT_CLASS(hda_cmd,
23 ), 23 ),
24 24
25 TP_fast_assign( 25 TP_fast_assign(
26 __entry->card = (codec)->bus->card->number; 26 __entry->card = (codec)->card->number;
27 __entry->addr = (codec)->addr; 27 __entry->addr = (codec)->addr;
28 __entry->val = (val); 28 __entry->val = (val);
29 ), 29 ),
@@ -71,7 +71,7 @@ DECLARE_EVENT_CLASS(hda_power,
71 ), 71 ),
72 72
73 TP_fast_assign( 73 TP_fast_assign(
74 __entry->card = (codec)->bus->card->number; 74 __entry->card = (codec)->card->number;
75 __entry->addr = (codec)->addr; 75 __entry->addr = (codec)->addr;
76 ), 76 ),
77 77
@@ -87,30 +87,6 @@ DEFINE_EVENT(hda_power, hda_power_up,
87 TP_PROTO(struct hda_codec *codec), 87 TP_PROTO(struct hda_codec *codec),
88 TP_ARGS(codec) 88 TP_ARGS(codec)
89); 89);
90
91TRACE_EVENT(hda_power_count,
92 TP_PROTO(struct hda_codec *codec),
93 TP_ARGS(codec),
94 TP_STRUCT__entry(
95 __field( unsigned int, card )
96 __field( unsigned int, addr )
97 __field( int, power_count )
98 __field( int, power_on )
99 __field( int, power_transition )
100 ),
101
102 TP_fast_assign(
103 __entry->card = (codec)->bus->card->number;
104 __entry->addr = (codec)->addr;
105 __entry->power_count = (codec)->power_count;
106 __entry->power_on = (codec)->power_on;
107 __entry->power_transition = (codec)->power_transition;
108 ),
109
110 TP_printk("[%d:%d] power_count=%d, power_on=%d, power_transition=%d",
111 __entry->card, __entry->addr, __entry->power_count,
112 __entry->power_on, __entry->power_transition)
113);
114#endif /* CONFIG_PM */ 90#endif /* CONFIG_PM */
115 91
116TRACE_EVENT(hda_unsol_event, 92TRACE_EVENT(hda_unsol_event,
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index d285904cdb64..af4c7be86c27 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -1194,20 +1194,8 @@ MODULE_ALIAS("snd-hda-codec-id:11d4*");
1194MODULE_LICENSE("GPL"); 1194MODULE_LICENSE("GPL");
1195MODULE_DESCRIPTION("Analog Devices HD-audio codec"); 1195MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1196 1196
1197static struct hda_codec_preset_list analog_list = { 1197static struct hda_codec_driver analog_driver = {
1198 .preset = snd_hda_preset_analog, 1198 .preset = snd_hda_preset_analog,
1199 .owner = THIS_MODULE,
1200}; 1199};
1201 1200
1202static int __init patch_analog_init(void) 1201module_hda_codec_driver(analog_driver);
1203{
1204 return snd_hda_add_codec_preset(&analog_list);
1205}
1206
1207static void __exit patch_analog_exit(void)
1208{
1209 snd_hda_delete_codec_preset(&analog_list);
1210}
1211
1212module_init(patch_analog_init)
1213module_exit(patch_analog_exit)
diff --git a/sound/pci/hda/patch_ca0110.c b/sound/pci/hda/patch_ca0110.c
index 5e65999e0d8e..447302695195 100644
--- a/sound/pci/hda/patch_ca0110.c
+++ b/sound/pci/hda/patch_ca0110.c
@@ -98,20 +98,8 @@ MODULE_ALIAS("snd-hda-codec-id:1102000d");
98MODULE_LICENSE("GPL"); 98MODULE_LICENSE("GPL");
99MODULE_DESCRIPTION("Creative CA0110-IBG HD-audio codec"); 99MODULE_DESCRIPTION("Creative CA0110-IBG HD-audio codec");
100 100
101static struct hda_codec_preset_list ca0110_list = { 101static struct hda_codec_driver ca0110_driver = {
102 .preset = snd_hda_preset_ca0110, 102 .preset = snd_hda_preset_ca0110,
103 .owner = THIS_MODULE,
104}; 103};
105 104
106static int __init patch_ca0110_init(void) 105module_hda_codec_driver(ca0110_driver);
107{
108 return snd_hda_add_codec_preset(&ca0110_list);
109}
110
111static void __exit patch_ca0110_exit(void)
112{
113 snd_hda_delete_codec_preset(&ca0110_list);
114}
115
116module_init(patch_ca0110_init)
117module_exit(patch_ca0110_exit)
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index e0383eea9880..72d20652df50 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -719,7 +719,6 @@ struct ca0132_spec {
719 unsigned int num_inputs; 719 unsigned int num_inputs;
720 hda_nid_t shared_mic_nid; 720 hda_nid_t shared_mic_nid;
721 hda_nid_t shared_out_nid; 721 hda_nid_t shared_out_nid;
722 struct hda_pcm pcm_rec[5]; /* PCM information */
723 722
724 /* chip access */ 723 /* chip access */
725 struct mutex chipio_mutex; /* chip access mutex */ 724 struct mutex chipio_mutex; /* chip access mutex */
@@ -4036,12 +4035,11 @@ static struct hda_pcm_stream ca0132_pcm_digital_capture = {
4036static int ca0132_build_pcms(struct hda_codec *codec) 4035static int ca0132_build_pcms(struct hda_codec *codec)
4037{ 4036{
4038 struct ca0132_spec *spec = codec->spec; 4037 struct ca0132_spec *spec = codec->spec;
4039 struct hda_pcm *info = spec->pcm_rec; 4038 struct hda_pcm *info;
4040 4039
4041 codec->pcm_info = info; 4040 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog");
4042 codec->num_pcms = 0; 4041 if (!info)
4043 4042 return -ENOMEM;
4044 info->name = "CA0132 Analog";
4045 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback; 4043 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback;
4046 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0]; 4044 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0];
4047 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 4045 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
@@ -4049,27 +4047,27 @@ static int ca0132_build_pcms(struct hda_codec *codec)
4049 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture; 4047 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
4050 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1; 4048 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
4051 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0]; 4049 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
4052 codec->num_pcms++;
4053 4050
4054 info++; 4051 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog Mic-In2");
4055 info->name = "CA0132 Analog Mic-In2"; 4052 if (!info)
4053 return -ENOMEM;
4056 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture; 4054 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
4057 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1; 4055 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
4058 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[1]; 4056 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[1];
4059 codec->num_pcms++;
4060 4057
4061 info++; 4058 info = snd_hda_codec_pcm_new(codec, "CA0132 What U Hear");
4062 info->name = "CA0132 What U Hear"; 4059 if (!info)
4060 return -ENOMEM;
4063 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture; 4061 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
4064 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1; 4062 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
4065 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[2]; 4063 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[2];
4066 codec->num_pcms++;
4067 4064
4068 if (!spec->dig_out && !spec->dig_in) 4065 if (!spec->dig_out && !spec->dig_in)
4069 return 0; 4066 return 0;
4070 4067
4071 info++; 4068 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
4072 info->name = "CA0132 Digital"; 4069 if (!info)
4070 return -ENOMEM;
4073 info->pcm_type = HDA_PCM_TYPE_SPDIF; 4071 info->pcm_type = HDA_PCM_TYPE_SPDIF;
4074 if (spec->dig_out) { 4072 if (spec->dig_out) {
4075 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 4073 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
@@ -4081,7 +4079,6 @@ static int ca0132_build_pcms(struct hda_codec *codec)
4081 ca0132_pcm_digital_capture; 4079 ca0132_pcm_digital_capture;
4082 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in; 4080 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
4083 } 4081 }
4084 codec->num_pcms++;
4085 4082
4086 return 0; 4083 return 0;
4087} 4084}
@@ -4352,7 +4349,7 @@ static bool ca0132_download_dsp_images(struct hda_codec *codec)
4352 const struct dsp_image_seg *dsp_os_image; 4349 const struct dsp_image_seg *dsp_os_image;
4353 const struct firmware *fw_entry; 4350 const struct firmware *fw_entry;
4354 4351
4355 if (request_firmware(&fw_entry, EFX_FILE, codec->bus->card->dev) != 0) 4352 if (request_firmware(&fw_entry, EFX_FILE, codec->card->dev) != 0)
4356 return false; 4353 return false;
4357 4354
4358 dsp_os_image = (struct dsp_image_seg *)(fw_entry->data); 4355 dsp_os_image = (struct dsp_image_seg *)(fw_entry->data);
@@ -4413,8 +4410,7 @@ static void hp_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
4413 * state machine run. 4410 * state machine run.
4414 */ 4411 */
4415 cancel_delayed_work_sync(&spec->unsol_hp_work); 4412 cancel_delayed_work_sync(&spec->unsol_hp_work);
4416 queue_delayed_work(codec->bus->workq, &spec->unsol_hp_work, 4413 schedule_delayed_work(&spec->unsol_hp_work, msecs_to_jiffies(500));
4417 msecs_to_jiffies(500));
4418 cb->tbl->block_report = 1; 4414 cb->tbl->block_report = 1;
4419} 4415}
4420 4416
@@ -4702,20 +4698,8 @@ MODULE_ALIAS("snd-hda-codec-id:11020011");
4702MODULE_LICENSE("GPL"); 4698MODULE_LICENSE("GPL");
4703MODULE_DESCRIPTION("Creative Sound Core3D codec"); 4699MODULE_DESCRIPTION("Creative Sound Core3D codec");
4704 4700
4705static struct hda_codec_preset_list ca0132_list = { 4701static struct hda_codec_driver ca0132_driver = {
4706 .preset = snd_hda_preset_ca0132, 4702 .preset = snd_hda_preset_ca0132,
4707 .owner = THIS_MODULE,
4708}; 4703};
4709 4704
4710static int __init patch_ca0132_init(void) 4705module_hda_codec_driver(ca0132_driver);
4711{
4712 return snd_hda_add_codec_preset(&ca0132_list);
4713}
4714
4715static void __exit patch_ca0132_exit(void)
4716{
4717 snd_hda_delete_codec_preset(&ca0132_list);
4718}
4719
4720module_init(patch_ca0132_init)
4721module_exit(patch_ca0132_exit)
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
index dd2b3d92071f..50e9dd675579 100644
--- a/sound/pci/hda/patch_cirrus.c
+++ b/sound/pci/hda/patch_cirrus.c
@@ -1221,20 +1221,8 @@ MODULE_ALIAS("snd-hda-codec-id:10134213");
1221MODULE_LICENSE("GPL"); 1221MODULE_LICENSE("GPL");
1222MODULE_DESCRIPTION("Cirrus Logic HD-audio codec"); 1222MODULE_DESCRIPTION("Cirrus Logic HD-audio codec");
1223 1223
1224static struct hda_codec_preset_list cirrus_list = { 1224static struct hda_codec_driver cirrus_driver = {
1225 .preset = snd_hda_preset_cirrus, 1225 .preset = snd_hda_preset_cirrus,
1226 .owner = THIS_MODULE,
1227}; 1226};
1228 1227
1229static int __init patch_cirrus_init(void) 1228module_hda_codec_driver(cirrus_driver);
1230{
1231 return snd_hda_add_codec_preset(&cirrus_list);
1232}
1233
1234static void __exit patch_cirrus_exit(void)
1235{
1236 snd_hda_delete_codec_preset(&cirrus_list);
1237}
1238
1239module_init(patch_cirrus_init)
1240module_exit(patch_cirrus_exit)
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index c895a8f21192..617d9012e78a 100644
--- a/sound/pci/hda/patch_cmedia.c
+++ b/sound/pci/hda/patch_cmedia.c
@@ -137,20 +137,8 @@ MODULE_ALIAS("snd-hda-codec-id:434d4980");
137MODULE_LICENSE("GPL"); 137MODULE_LICENSE("GPL");
138MODULE_DESCRIPTION("C-Media HD-audio codec"); 138MODULE_DESCRIPTION("C-Media HD-audio codec");
139 139
140static struct hda_codec_preset_list cmedia_list = { 140static struct hda_codec_driver cmedia_driver = {
141 .preset = snd_hda_preset_cmedia, 141 .preset = snd_hda_preset_cmedia,
142 .owner = THIS_MODULE,
143}; 142};
144 143
145static int __init patch_cmedia_init(void) 144module_hda_codec_driver(cmedia_driver);
146{
147 return snd_hda_add_codec_preset(&cmedia_list);
148}
149
150static void __exit patch_cmedia_exit(void)
151{
152 snd_hda_delete_codec_preset(&cmedia_list);
153}
154
155module_init(patch_cmedia_init)
156module_exit(patch_cmedia_exit)
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index da67ea8645a6..5aa466a13e43 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -1018,20 +1018,8 @@ MODULE_ALIAS("snd-hda-codec-id:14f151d7");
1018MODULE_LICENSE("GPL"); 1018MODULE_LICENSE("GPL");
1019MODULE_DESCRIPTION("Conexant HD-audio codec"); 1019MODULE_DESCRIPTION("Conexant HD-audio codec");
1020 1020
1021static struct hda_codec_preset_list conexant_list = { 1021static struct hda_codec_driver conexant_driver = {
1022 .preset = snd_hda_preset_conexant, 1022 .preset = snd_hda_preset_conexant,
1023 .owner = THIS_MODULE,
1024}; 1023};
1025 1024
1026static int __init patch_conexant_init(void) 1025module_hda_codec_driver(conexant_driver);
1027{
1028 return snd_hda_add_codec_preset(&conexant_list);
1029}
1030
1031static void __exit patch_conexant_exit(void)
1032{
1033 snd_hda_delete_codec_preset(&conexant_list);
1034}
1035
1036module_init(patch_conexant_init)
1037module_exit(patch_conexant_exit)
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index b422e406a9cb..7e9ff7b16e56 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -86,7 +86,6 @@ struct hdmi_spec_per_pin {
86 bool non_pcm; 86 bool non_pcm;
87 bool chmap_set; /* channel-map override by ALSA API? */ 87 bool chmap_set; /* channel-map override by ALSA API? */
88 unsigned char chmap[8]; /* ALSA API channel-map */ 88 unsigned char chmap[8]; /* ALSA API channel-map */
89 char pcm_name[8]; /* filled in build_pcm callbacks */
90#ifdef CONFIG_PROC_FS 89#ifdef CONFIG_PROC_FS
91 struct snd_info_entry *proc_entry; 90 struct snd_info_entry *proc_entry;
92#endif 91#endif
@@ -132,7 +131,7 @@ struct hdmi_spec {
132 131
133 int num_pins; 132 int num_pins;
134 struct snd_array pins; /* struct hdmi_spec_per_pin */ 133 struct snd_array pins; /* struct hdmi_spec_per_pin */
135 struct snd_array pcm_rec; /* struct hda_pcm */ 134 struct hda_pcm *pcm_rec[16];
136 unsigned int channels_max; /* max over all cvts */ 135 unsigned int channels_max; /* max over all cvts */
137 136
138 struct hdmi_eld temp_eld; 137 struct hdmi_eld temp_eld;
@@ -355,8 +354,7 @@ static struct cea_channel_speaker_allocation channel_allocations[] = {
355 ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx)) 354 ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx))
356#define get_cvt(spec, idx) \ 355#define get_cvt(spec, idx) \
357 ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx)) 356 ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx))
358#define get_pcm_rec(spec, idx) \ 357#define get_pcm_rec(spec, idx) ((spec)->pcm_rec[idx])
359 ((struct hda_pcm *)snd_array_elem(&spec->pcm_rec, idx))
360 358
361static int pin_nid_to_pin_index(struct hda_codec *codec, hda_nid_t pin_nid) 359static int pin_nid_to_pin_index(struct hda_codec *codec, hda_nid_t pin_nid)
362{ 360{
@@ -579,7 +577,7 @@ static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
579 int err; 577 int err;
580 578
581 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index); 579 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
582 err = snd_card_proc_new(codec->bus->card, name, &entry); 580 err = snd_card_proc_new(codec->card, name, &entry);
583 if (err < 0) 581 if (err < 0)
584 return err; 582 return err;
585 583
@@ -594,7 +592,7 @@ static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
594static void eld_proc_free(struct hdmi_spec_per_pin *per_pin) 592static void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
595{ 593{
596 if (!per_pin->codec->bus->shutdown && per_pin->proc_entry) { 594 if (!per_pin->codec->bus->shutdown && per_pin->proc_entry) {
597 snd_device_free(per_pin->codec->bus->card, per_pin->proc_entry); 595 snd_device_free(per_pin->codec->card, per_pin->proc_entry);
598 per_pin->proc_entry = NULL; 596 per_pin->proc_entry = NULL;
599 } 597 }
600} 598}
@@ -1578,9 +1576,8 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1578 update_eld = true; 1576 update_eld = true;
1579 } 1577 }
1580 else if (repoll) { 1578 else if (repoll) {
1581 queue_delayed_work(codec->bus->workq, 1579 schedule_delayed_work(&per_pin->work,
1582 &per_pin->work, 1580 msecs_to_jiffies(300));
1583 msecs_to_jiffies(300));
1584 goto unlock; 1581 goto unlock;
1585 } 1582 }
1586 } 1583 }
@@ -1624,7 +1621,7 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1624 } 1621 }
1625 1622
1626 if (eld_changed) 1623 if (eld_changed)
1627 snd_ctl_notify(codec->bus->card, 1624 snd_ctl_notify(codec->card,
1628 SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, 1625 SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO,
1629 &per_pin->eld_ctl->id); 1626 &per_pin->eld_ctl->id);
1630 unlock: 1627 unlock:
@@ -2056,11 +2053,10 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec)
2056 struct hdmi_spec_per_pin *per_pin; 2053 struct hdmi_spec_per_pin *per_pin;
2057 2054
2058 per_pin = get_pin(spec, pin_idx); 2055 per_pin = get_pin(spec, pin_idx);
2059 sprintf(per_pin->pcm_name, "HDMI %d", pin_idx); 2056 info = snd_hda_codec_pcm_new(codec, "HDMI %d", pin_idx);
2060 info = snd_array_new(&spec->pcm_rec);
2061 if (!info) 2057 if (!info)
2062 return -ENOMEM; 2058 return -ENOMEM;
2063 info->name = per_pin->pcm_name; 2059 spec->pcm_rec[pin_idx] = info;
2064 info->pcm_type = HDA_PCM_TYPE_HDMI; 2060 info->pcm_type = HDA_PCM_TYPE_HDMI;
2065 info->own_chmap = true; 2061 info->own_chmap = true;
2066 2062
@@ -2070,9 +2066,6 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec)
2070 /* other pstr fields are set in open */ 2066 /* other pstr fields are set in open */
2071 } 2067 }
2072 2068
2073 codec->num_pcms = spec->num_pins;
2074 codec->pcm_info = spec->pcm_rec.list;
2075
2076 return 0; 2069 return 0;
2077} 2070}
2078 2071
@@ -2125,13 +2118,15 @@ static int generic_hdmi_build_controls(struct hda_codec *codec)
2125 2118
2126 /* add channel maps */ 2119 /* add channel maps */
2127 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2120 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2121 struct hda_pcm *pcm;
2128 struct snd_pcm_chmap *chmap; 2122 struct snd_pcm_chmap *chmap;
2129 struct snd_kcontrol *kctl; 2123 struct snd_kcontrol *kctl;
2130 int i; 2124 int i;
2131 2125
2132 if (!codec->pcm_info[pin_idx].pcm) 2126 pcm = spec->pcm_rec[pin_idx];
2127 if (!pcm || !pcm->pcm)
2133 break; 2128 break;
2134 err = snd_pcm_add_chmap_ctls(codec->pcm_info[pin_idx].pcm, 2129 err = snd_pcm_add_chmap_ctls(pcm->pcm,
2135 SNDRV_PCM_STREAM_PLAYBACK, 2130 SNDRV_PCM_STREAM_PLAYBACK,
2136 NULL, 0, pin_idx, &chmap); 2131 NULL, 0, pin_idx, &chmap);
2137 if (err < 0) 2132 if (err < 0)
@@ -2186,14 +2181,12 @@ static void hdmi_array_init(struct hdmi_spec *spec, int nums)
2186{ 2181{
2187 snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums); 2182 snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums);
2188 snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums); 2183 snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums);
2189 snd_array_init(&spec->pcm_rec, sizeof(struct hda_pcm), nums);
2190} 2184}
2191 2185
2192static void hdmi_array_free(struct hdmi_spec *spec) 2186static void hdmi_array_free(struct hdmi_spec *spec)
2193{ 2187{
2194 snd_array_free(&spec->pins); 2188 snd_array_free(&spec->pins);
2195 snd_array_free(&spec->cvts); 2189 snd_array_free(&spec->cvts);
2196 snd_array_free(&spec->pcm_rec);
2197} 2190}
2198 2191
2199static void generic_hdmi_free(struct hda_codec *codec) 2192static void generic_hdmi_free(struct hda_codec *codec)
@@ -2204,11 +2197,10 @@ static void generic_hdmi_free(struct hda_codec *codec)
2204 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2197 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2205 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2198 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2206 2199
2207 cancel_delayed_work(&per_pin->work); 2200 cancel_delayed_work_sync(&per_pin->work);
2208 eld_proc_free(per_pin); 2201 eld_proc_free(per_pin);
2209 } 2202 }
2210 2203
2211 flush_workqueue(codec->bus->workq);
2212 hdmi_array_free(spec); 2204 hdmi_array_free(spec);
2213 kfree(spec); 2205 kfree(spec);
2214} 2206}
@@ -2381,11 +2373,10 @@ static int simple_playback_build_pcms(struct hda_codec *codec)
2381 chans = get_wcaps(codec, per_cvt->cvt_nid); 2373 chans = get_wcaps(codec, per_cvt->cvt_nid);
2382 chans = get_wcaps_channels(chans); 2374 chans = get_wcaps_channels(chans);
2383 2375
2384 info = snd_array_new(&spec->pcm_rec); 2376 info = snd_hda_codec_pcm_new(codec, "HDMI 0");
2385 if (!info) 2377 if (!info)
2386 return -ENOMEM; 2378 return -ENOMEM;
2387 info->name = get_pin(spec, 0)->pcm_name; 2379 spec->pcm_rec[0] = info;
2388 sprintf(info->name, "HDMI 0");
2389 info->pcm_type = HDA_PCM_TYPE_HDMI; 2380 info->pcm_type = HDA_PCM_TYPE_HDMI;
2390 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; 2381 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
2391 *pstr = spec->pcm_playback; 2382 *pstr = spec->pcm_playback;
@@ -2393,9 +2384,6 @@ static int simple_playback_build_pcms(struct hda_codec *codec)
2393 if (pstr->channels_max <= 2 && chans && chans <= 16) 2384 if (pstr->channels_max <= 2 && chans && chans <= 16)
2394 pstr->channels_max = chans; 2385 pstr->channels_max = chans;
2395 2386
2396 codec->num_pcms = 1;
2397 codec->pcm_info = info;
2398
2399 return 0; 2387 return 0;
2400} 2388}
2401 2389
@@ -3301,15 +3289,6 @@ static int patch_via_hdmi(struct hda_codec *codec)
3301} 3289}
3302 3290
3303/* 3291/*
3304 * called from hda_codec.c for generic HDMI support
3305 */
3306int snd_hda_parse_hdmi_codec(struct hda_codec *codec)
3307{
3308 return patch_generic_hdmi(codec);
3309}
3310EXPORT_SYMBOL_GPL(snd_hda_parse_hdmi_codec);
3311
3312/*
3313 * patch entries 3292 * patch entries
3314 */ 3293 */
3315static const struct hda_codec_preset snd_hda_preset_hdmi[] = { 3294static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
@@ -3373,6 +3352,8 @@ static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
3373{ .id = 0x80862882, .name = "Valleyview2 HDMI", .patch = patch_generic_hdmi }, 3352{ .id = 0x80862882, .name = "Valleyview2 HDMI", .patch = patch_generic_hdmi },
3374{ .id = 0x80862883, .name = "Braswell HDMI", .patch = patch_generic_hdmi }, 3353{ .id = 0x80862883, .name = "Braswell HDMI", .patch = patch_generic_hdmi },
3375{ .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_generic_hdmi }, 3354{ .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_generic_hdmi },
3355/* special ID for generic HDMI */
3356{ .id = HDA_CODEC_ID_GENERIC_HDMI, .patch = patch_generic_hdmi },
3376{} /* terminator */ 3357{} /* terminator */
3377}; 3358};
3378 3359
@@ -3442,20 +3423,8 @@ MODULE_ALIAS("snd-hda-codec-intelhdmi");
3442MODULE_ALIAS("snd-hda-codec-nvhdmi"); 3423MODULE_ALIAS("snd-hda-codec-nvhdmi");
3443MODULE_ALIAS("snd-hda-codec-atihdmi"); 3424MODULE_ALIAS("snd-hda-codec-atihdmi");
3444 3425
3445static struct hda_codec_preset_list intel_list = { 3426static struct hda_codec_driver hdmi_driver = {
3446 .preset = snd_hda_preset_hdmi, 3427 .preset = snd_hda_preset_hdmi,
3447 .owner = THIS_MODULE,
3448}; 3428};
3449 3429
3450static int __init patch_hdmi_init(void) 3430module_hda_codec_driver(hdmi_driver);
3451{
3452 return snd_hda_add_codec_preset(&intel_list);
3453}
3454
3455static void __exit patch_hdmi_exit(void)
3456{
3457 snd_hda_delete_codec_preset(&intel_list);
3458}
3459
3460module_init(patch_hdmi_init)
3461module_exit(patch_hdmi_exit)
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 526398a4a442..124eacf67fc4 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -2602,53 +2602,12 @@ static int patch_alc268(struct hda_codec *codec)
2602 * ALC269 2602 * ALC269
2603 */ 2603 */
2604 2604
2605static int playback_pcm_open(struct hda_pcm_stream *hinfo,
2606 struct hda_codec *codec,
2607 struct snd_pcm_substream *substream)
2608{
2609 struct hda_gen_spec *spec = codec->spec;
2610 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2611 hinfo);
2612}
2613
2614static int playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2615 struct hda_codec *codec,
2616 unsigned int stream_tag,
2617 unsigned int format,
2618 struct snd_pcm_substream *substream)
2619{
2620 struct hda_gen_spec *spec = codec->spec;
2621 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2622 stream_tag, format, substream);
2623}
2624
2625static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2626 struct hda_codec *codec,
2627 struct snd_pcm_substream *substream)
2628{
2629 struct hda_gen_spec *spec = codec->spec;
2630 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2631}
2632
2633static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { 2605static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
2634 .substreams = 1,
2635 .channels_min = 2,
2636 .channels_max = 8,
2637 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ 2606 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
2638 /* NID is set in alc_build_pcms */
2639 .ops = {
2640 .open = playback_pcm_open,
2641 .prepare = playback_pcm_prepare,
2642 .cleanup = playback_pcm_cleanup
2643 },
2644}; 2607};
2645 2608
2646static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = { 2609static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
2647 .substreams = 1,
2648 .channels_min = 2,
2649 .channels_max = 2,
2650 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ 2610 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
2651 /* NID is set in alc_build_pcms */
2652}; 2611};
2653 2612
2654/* different alc269-variants */ 2613/* different alc269-variants */
@@ -5850,7 +5809,7 @@ static void alc_fixup_bass_chmap(struct hda_codec *codec,
5850{ 5809{
5851 if (action == HDA_FIXUP_ACT_BUILD) { 5810 if (action == HDA_FIXUP_ACT_BUILD) {
5852 struct alc_spec *spec = codec->spec; 5811 struct alc_spec *spec = codec->spec;
5853 spec->gen.pcm_rec[0].stream[0].chmap = asus_pcm_2_1_chmaps; 5812 spec->gen.pcm_rec[0]->stream[0].chmap = asus_pcm_2_1_chmaps;
5854 } 5813 }
5855} 5814}
5856 5815
@@ -6521,20 +6480,8 @@ MODULE_ALIAS("snd-hda-codec-id:10ec*");
6521MODULE_LICENSE("GPL"); 6480MODULE_LICENSE("GPL");
6522MODULE_DESCRIPTION("Realtek HD-audio codec"); 6481MODULE_DESCRIPTION("Realtek HD-audio codec");
6523 6482
6524static struct hda_codec_preset_list realtek_list = { 6483static struct hda_codec_driver realtek_driver = {
6525 .preset = snd_hda_preset_realtek, 6484 .preset = snd_hda_preset_realtek,
6526 .owner = THIS_MODULE,
6527}; 6485};
6528 6486
6529static int __init patch_realtek_init(void) 6487module_hda_codec_driver(realtek_driver);
6530{
6531 return snd_hda_add_codec_preset(&realtek_list);
6532}
6533
6534static void __exit patch_realtek_exit(void)
6535{
6536 snd_hda_delete_codec_preset(&realtek_list);
6537}
6538
6539module_init(patch_realtek_init)
6540module_exit(patch_realtek_exit)
diff --git a/sound/pci/hda/patch_si3054.c b/sound/pci/hda/patch_si3054.c
index 3208ad69583e..df243134baa8 100644
--- a/sound/pci/hda/patch_si3054.c
+++ b/sound/pci/hda/patch_si3054.c
@@ -83,7 +83,6 @@
83 83
84struct si3054_spec { 84struct si3054_spec {
85 unsigned international; 85 unsigned international;
86 struct hda_pcm pcm;
87}; 86};
88 87
89 88
@@ -199,11 +198,11 @@ static const struct hda_pcm_stream si3054_pcm = {
199 198
200static int si3054_build_pcms(struct hda_codec *codec) 199static int si3054_build_pcms(struct hda_codec *codec)
201{ 200{
202 struct si3054_spec *spec = codec->spec; 201 struct hda_pcm *info;
203 struct hda_pcm *info = &spec->pcm; 202
204 codec->num_pcms = 1; 203 info = snd_hda_codec_pcm_new(codec, "Si3054 Modem");
205 codec->pcm_info = info; 204 if (!info)
206 info->name = "Si3054 Modem"; 205 return -ENOMEM;
207 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = si3054_pcm; 206 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = si3054_pcm;
208 info->stream[SNDRV_PCM_STREAM_CAPTURE] = si3054_pcm; 207 info->stream[SNDRV_PCM_STREAM_CAPTURE] = si3054_pcm;
209 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = codec->mfg; 208 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = codec->mfg;
@@ -319,20 +318,8 @@ MODULE_ALIAS("snd-hda-codec-id:18540018");
319MODULE_LICENSE("GPL"); 318MODULE_LICENSE("GPL");
320MODULE_DESCRIPTION("Si3054 HD-audio modem codec"); 319MODULE_DESCRIPTION("Si3054 HD-audio modem codec");
321 320
322static struct hda_codec_preset_list si3054_list = { 321static struct hda_codec_driver si3054_driver = {
323 .preset = snd_hda_preset_si3054, 322 .preset = snd_hda_preset_si3054,
324 .owner = THIS_MODULE,
325}; 323};
326 324
327static int __init patch_si3054_init(void) 325module_hda_codec_driver(si3054_driver);
328{
329 return snd_hda_add_codec_preset(&si3054_list);
330}
331
332static void __exit patch_si3054_exit(void)
333{
334 snd_hda_delete_codec_preset(&si3054_list);
335}
336
337module_init(patch_si3054_init)
338module_exit(patch_si3054_exit)
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 87eff3173ce9..5b7c173adcb8 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -2132,8 +2132,10 @@ static void stac92hd83xxx_fixup_hp_mic_led(struct hda_codec *codec,
2132 2132
2133 if (action == HDA_FIXUP_ACT_PRE_PROBE) { 2133 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2134 spec->mic_mute_led_gpio = 0x08; /* GPIO3 */ 2134 spec->mic_mute_led_gpio = 0x08; /* GPIO3 */
2135#ifdef CONFIG_PM
2135 /* resetting controller clears GPIO, so we need to keep on */ 2136 /* resetting controller clears GPIO, so we need to keep on */
2136 codec->bus->power_keep_link_on = 1; 2137 codec->d3_stop_clk = 0;
2138#endif
2137 } 2139 }
2138} 2140}
2139 2141
@@ -4223,6 +4225,12 @@ static int stac_parse_auto_config(struct hda_codec *codec)
4223 if (err < 0) 4225 if (err < 0)
4224 return err; 4226 return err;
4225 4227
4228 if (spec->vref_mute_led_nid) {
4229 err = snd_hda_gen_fix_pin_power(codec, spec->vref_mute_led_nid);
4230 if (err < 0)
4231 return err;
4232 }
4233
4226 /* setup analog beep controls */ 4234 /* setup analog beep controls */
4227 if (spec->anabeep_nid > 0) { 4235 if (spec->anabeep_nid > 0) {
4228 err = stac_auto_create_beep_ctls(codec, 4236 err = stac_auto_create_beep_ctls(codec,
@@ -4392,6 +4400,7 @@ static const struct hda_codec_ops stac_patch_ops = {
4392#ifdef CONFIG_PM 4400#ifdef CONFIG_PM
4393 .suspend = stac_suspend, 4401 .suspend = stac_suspend,
4394#endif 4402#endif
4403 .stream_pm = snd_hda_gen_stream_pm,
4395 .reboot_notify = stac_shutup, 4404 .reboot_notify = stac_shutup,
4396}; 4405};
4397 4406
@@ -4485,6 +4494,7 @@ static int patch_stac92hd73xx(struct hda_codec *codec)
4485 return err; 4494 return err;
4486 4495
4487 spec = codec->spec; 4496 spec = codec->spec;
4497 codec->power_save_node = 1;
4488 spec->linear_tone_beep = 0; 4498 spec->linear_tone_beep = 0;
4489 spec->gen.mixer_nid = 0x1d; 4499 spec->gen.mixer_nid = 0x1d;
4490 spec->have_spdif_mux = 1; 4500 spec->have_spdif_mux = 1;
@@ -4590,6 +4600,7 @@ static int patch_stac92hd83xxx(struct hda_codec *codec)
4590 codec->epss = 0; /* longer delay needed for D3 */ 4600 codec->epss = 0; /* longer delay needed for D3 */
4591 4601
4592 spec = codec->spec; 4602 spec = codec->spec;
4603 codec->power_save_node = 1;
4593 spec->linear_tone_beep = 0; 4604 spec->linear_tone_beep = 0;
4594 spec->gen.own_eapd_ctl = 1; 4605 spec->gen.own_eapd_ctl = 1;
4595 spec->gen.power_down_unused = 1; 4606 spec->gen.power_down_unused = 1;
@@ -4639,6 +4650,7 @@ static int patch_stac92hd95(struct hda_codec *codec)
4639 codec->epss = 0; /* longer delay needed for D3 */ 4650 codec->epss = 0; /* longer delay needed for D3 */
4640 4651
4641 spec = codec->spec; 4652 spec = codec->spec;
4653 codec->power_save_node = 1;
4642 spec->linear_tone_beep = 0; 4654 spec->linear_tone_beep = 0;
4643 spec->gen.own_eapd_ctl = 1; 4655 spec->gen.own_eapd_ctl = 1;
4644 spec->gen.power_down_unused = 1; 4656 spec->gen.power_down_unused = 1;
@@ -4680,6 +4692,7 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
4680 return err; 4692 return err;
4681 4693
4682 spec = codec->spec; 4694 spec = codec->spec;
4695 codec->power_save_node = 1;
4683 spec->linear_tone_beep = 0; 4696 spec->linear_tone_beep = 0;
4684 spec->gen.own_eapd_ctl = 1; 4697 spec->gen.own_eapd_ctl = 1;
4685 spec->gen.power_down_unused = 1; 4698 spec->gen.power_down_unused = 1;
@@ -5091,20 +5104,8 @@ MODULE_ALIAS("snd-hda-codec-id:111d*");
5091MODULE_LICENSE("GPL"); 5104MODULE_LICENSE("GPL");
5092MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec"); 5105MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
5093 5106
5094static struct hda_codec_preset_list sigmatel_list = { 5107static struct hda_codec_driver sigmatel_driver = {
5095 .preset = snd_hda_preset_sigmatel, 5108 .preset = snd_hda_preset_sigmatel,
5096 .owner = THIS_MODULE,
5097}; 5109};
5098 5110
5099static int __init patch_sigmatel_init(void) 5111module_hda_codec_driver(sigmatel_driver);
5100{
5101 return snd_hda_add_codec_preset(&sigmatel_list);
5102}
5103
5104static void __exit patch_sigmatel_exit(void)
5105{
5106 snd_hda_delete_codec_preset(&sigmatel_list);
5107}
5108
5109module_init(patch_sigmatel_init)
5110module_exit(patch_sigmatel_exit)
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index 3de6d3d779c9..485663bb9101 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -99,7 +99,6 @@ struct via_spec {
99 99
100 /* HP mode source */ 100 /* HP mode source */
101 unsigned int dmic_enabled; 101 unsigned int dmic_enabled;
102 unsigned int no_pin_power_ctl;
103 enum VIA_HDA_CODEC codec_type; 102 enum VIA_HDA_CODEC codec_type;
104 103
105 /* analog low-power control */ 104 /* analog low-power control */
@@ -108,9 +107,6 @@ struct via_spec {
108 /* work to check hp jack state */ 107 /* work to check hp jack state */
109 int hp_work_active; 108 int hp_work_active;
110 int vt1708_jack_detect; 109 int vt1708_jack_detect;
111
112 void (*set_widgets_power_state)(struct hda_codec *codec);
113 unsigned int dac_stream_tag[4];
114}; 110};
115 111
116static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); 112static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
@@ -133,11 +129,12 @@ static struct via_spec *via_new_spec(struct hda_codec *codec)
133 /* VT1708BCE & VT1708S are almost same */ 129 /* VT1708BCE & VT1708S are almost same */
134 if (spec->codec_type == VT1708BCE) 130 if (spec->codec_type == VT1708BCE)
135 spec->codec_type = VT1708S; 131 spec->codec_type = VT1708S;
136 spec->no_pin_power_ctl = 1;
137 spec->gen.indep_hp = 1; 132 spec->gen.indep_hp = 1;
138 spec->gen.keep_eapd_on = 1; 133 spec->gen.keep_eapd_on = 1;
139 spec->gen.pcm_playback_hook = via_playback_pcm_hook; 134 spec->gen.pcm_playback_hook = via_playback_pcm_hook;
140 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO; 135 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
136 codec->power_save_node = 1;
137 spec->gen.power_down_unused = 1;
141 return spec; 138 return spec;
142} 139}
143 140
@@ -222,98 +219,13 @@ static void vt1708_update_hp_work(struct hda_codec *codec)
222 if (!spec->hp_work_active) { 219 if (!spec->hp_work_active) {
223 codec->jackpoll_interval = msecs_to_jiffies(100); 220 codec->jackpoll_interval = msecs_to_jiffies(100);
224 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0); 221 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0);
225 queue_delayed_work(codec->bus->workq, 222 schedule_delayed_work(&codec->jackpoll_work, 0);
226 &codec->jackpoll_work, 0);
227 spec->hp_work_active = true; 223 spec->hp_work_active = true;
228 } 224 }
229 } else if (!hp_detect_with_aa(codec)) 225 } else if (!hp_detect_with_aa(codec))
230 vt1708_stop_hp_work(codec); 226 vt1708_stop_hp_work(codec);
231} 227}
232 228
233static void set_widgets_power_state(struct hda_codec *codec)
234{
235#if 0 /* FIXME: the assumed connections don't match always with the
236 * actual routes by the generic parser, so better to disable
237 * the control for safety.
238 */
239 struct via_spec *spec = codec->spec;
240 if (spec->set_widgets_power_state)
241 spec->set_widgets_power_state(codec);
242#endif
243}
244
245static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
246 unsigned int parm)
247{
248 if (snd_hda_check_power_state(codec, nid, parm))
249 return;
250 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
251}
252
253static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
254 unsigned int parm, unsigned int index)
255{
256 struct via_spec *spec = codec->spec;
257 unsigned int format;
258
259 if (snd_hda_check_power_state(codec, nid, parm))
260 return;
261 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
262 if (format && (spec->dac_stream_tag[index] != format))
263 spec->dac_stream_tag[index] = format;
264
265 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
266 if (parm == AC_PWRST_D0) {
267 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
268 if (!format && (spec->dac_stream_tag[index] != format))
269 snd_hda_codec_write(codec, nid, 0,
270 AC_VERB_SET_CHANNEL_STREAMID,
271 spec->dac_stream_tag[index]);
272 }
273}
274
275static bool smart51_enabled(struct hda_codec *codec)
276{
277 struct via_spec *spec = codec->spec;
278 return spec->gen.ext_channel_count > 2;
279}
280
281static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
282{
283 struct via_spec *spec = codec->spec;
284 int i;
285
286 for (i = 0; i < spec->gen.multi_ios; i++)
287 if (spec->gen.multi_io[i].pin == pin)
288 return true;
289 return false;
290}
291
292static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
293 unsigned int *affected_parm)
294{
295 unsigned parm;
296 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
297 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
298 >> AC_DEFCFG_MISC_SHIFT
299 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
300 struct via_spec *spec = codec->spec;
301 unsigned present = 0;
302
303 no_presence |= spec->no_pin_power_ctl;
304 if (!no_presence)
305 present = snd_hda_jack_detect(codec, nid);
306 if ((smart51_enabled(codec) && is_smart51_pins(codec, nid))
307 || ((no_presence || present)
308 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
309 *affected_parm = AC_PWRST_D0; /* if it's connected */
310 parm = AC_PWRST_D0;
311 } else
312 parm = AC_PWRST_D3;
313
314 update_power_state(codec, nid, parm);
315}
316
317static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, 229static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
318 struct snd_ctl_elem_info *uinfo) 230 struct snd_ctl_elem_info *uinfo)
319{ 231{
@@ -324,8 +236,7 @@ static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
324 struct snd_ctl_elem_value *ucontrol) 236 struct snd_ctl_elem_value *ucontrol)
325{ 237{
326 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 238 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
327 struct via_spec *spec = codec->spec; 239 ucontrol->value.enumerated.item[0] = codec->power_save_node;
328 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
329 return 0; 240 return 0;
330} 241}
331 242
@@ -334,12 +245,12 @@ static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
334{ 245{
335 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 246 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
336 struct via_spec *spec = codec->spec; 247 struct via_spec *spec = codec->spec;
337 unsigned int val = !ucontrol->value.enumerated.item[0]; 248 bool val = !!ucontrol->value.enumerated.item[0];
338 249
339 if (val == spec->no_pin_power_ctl) 250 if (val == codec->power_save_node)
340 return 0; 251 return 0;
341 spec->no_pin_power_ctl = val; 252 codec->power_save_node = val;
342 set_widgets_power_state(codec); 253 spec->gen.power_down_unused = val;
343 analog_low_current_mode(codec); 254 analog_low_current_mode(codec);
344 return 1; 255 return 1;
345} 256}
@@ -384,7 +295,7 @@ static void __analog_low_current_mode(struct hda_codec *codec, bool force)
384 bool enable; 295 bool enable;
385 unsigned int verb, parm; 296 unsigned int verb, parm;
386 297
387 if (spec->no_pin_power_ctl) 298 if (!codec->power_save_node)
388 enable = false; 299 enable = false;
389 else 300 else
390 enable = is_aa_path_mute(codec) && !spec->gen.active_streams; 301 enable = is_aa_path_mute(codec) && !spec->gen.active_streams;
@@ -441,8 +352,7 @@ static int via_build_controls(struct hda_codec *codec)
441 if (err < 0) 352 if (err < 0)
442 return err; 353 return err;
443 354
444 if (spec->set_widgets_power_state) 355 spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
445 spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
446 356
447 for (i = 0; i < spec->num_mixers; i++) { 357 for (i = 0; i < spec->num_mixers; i++) {
448 err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 358 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
@@ -486,7 +396,6 @@ static int via_suspend(struct hda_codec *codec)
486static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) 396static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
487{ 397{
488 struct via_spec *spec = codec->spec; 398 struct via_spec *spec = codec->spec;
489 set_widgets_power_state(codec);
490 analog_low_current_mode(codec); 399 analog_low_current_mode(codec);
491 vt1708_update_hp_work(codec); 400 vt1708_update_hp_work(codec);
492 return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid); 401 return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid);
@@ -574,34 +483,6 @@ static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = {
574 {} /* terminator */ 483 {} /* terminator */
575}; 484};
576 485
577static void via_jack_powerstate_event(struct hda_codec *codec,
578 struct hda_jack_callback *tbl)
579{
580 set_widgets_power_state(codec);
581}
582
583static void via_set_jack_unsol_events(struct hda_codec *codec)
584{
585 struct via_spec *spec = codec->spec;
586 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
587 hda_nid_t pin;
588 int i;
589
590 for (i = 0; i < cfg->line_outs; i++) {
591 pin = cfg->line_out_pins[i];
592 if (pin && is_jack_detectable(codec, pin))
593 snd_hda_jack_detect_enable_callback(codec, pin,
594 via_jack_powerstate_event);
595 }
596
597 for (i = 0; i < cfg->num_inputs; i++) {
598 pin = cfg->line_out_pins[i];
599 if (pin && is_jack_detectable(codec, pin))
600 snd_hda_jack_detect_enable_callback(codec, pin,
601 via_jack_powerstate_event);
602 }
603}
604
605static const struct badness_table via_main_out_badness = { 486static const struct badness_table via_main_out_badness = {
606 .no_primary_dac = 0x10000, 487 .no_primary_dac = 0x10000,
607 .no_dac = 0x4000, 488 .no_dac = 0x4000,
@@ -635,7 +516,9 @@ static int via_parse_auto_config(struct hda_codec *codec)
635 if (err < 0) 516 if (err < 0)
636 return err; 517 return err;
637 518
638 via_set_jack_unsol_events(codec); 519 /* disable widget PM at start for compatibility */
520 codec->power_save_node = 0;
521 spec->gen.power_down_unused = 0;
639 return 0; 522 return 0;
640} 523}
641 524
@@ -648,7 +531,6 @@ static int via_init(struct hda_codec *codec)
648 snd_hda_sequence_write(codec, spec->init_verbs[i]); 531 snd_hda_sequence_write(codec, spec->init_verbs[i]);
649 532
650 /* init power states */ 533 /* init power states */
651 set_widgets_power_state(codec);
652 __analog_low_current_mode(codec, true); 534 __analog_low_current_mode(codec, true);
653 535
654 snd_hda_gen_init(codec); 536 snd_hda_gen_init(codec);
@@ -683,8 +565,10 @@ static int vt1708_build_pcms(struct hda_codec *codec)
683 * 24bit samples are used. Until any workaround is found, 565 * 24bit samples are used. Until any workaround is found,
684 * disable the 24bit format, so far. 566 * disable the 24bit format, so far.
685 */ 567 */
686 for (i = 0; i < codec->num_pcms; i++) { 568 for (i = 0; i < ARRAY_SIZE(spec->gen.pcm_rec); i++) {
687 struct hda_pcm *info = &spec->gen.pcm_rec[i]; 569 struct hda_pcm *info = spec->gen.pcm_rec[i];
570 if (!info)
571 continue;
688 if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams || 572 if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams ||
689 info->pcm_type != HDA_PCM_TYPE_AUDIO) 573 info->pcm_type != HDA_PCM_TYPE_AUDIO)
690 continue; 574 continue;
@@ -766,78 +650,6 @@ static int patch_vt1709(struct hda_codec *codec)
766 return 0; 650 return 0;
767} 651}
768 652
769static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
770{
771 struct via_spec *spec = codec->spec;
772 int imux_is_smixer;
773 unsigned int parm;
774 int is_8ch = 0;
775 if ((spec->codec_type != VT1708B_4CH) &&
776 (codec->vendor_id != 0x11064397))
777 is_8ch = 1;
778
779 /* SW0 (17h) = stereo mixer */
780 imux_is_smixer =
781 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
782 == ((spec->codec_type == VT1708S) ? 5 : 0));
783 /* inputs */
784 /* PW 1/2/5 (1ah/1bh/1eh) */
785 parm = AC_PWRST_D3;
786 set_pin_power_state(codec, 0x1a, &parm);
787 set_pin_power_state(codec, 0x1b, &parm);
788 set_pin_power_state(codec, 0x1e, &parm);
789 if (imux_is_smixer)
790 parm = AC_PWRST_D0;
791 /* SW0 (17h), AIW 0/1 (13h/14h) */
792 update_power_state(codec, 0x17, parm);
793 update_power_state(codec, 0x13, parm);
794 update_power_state(codec, 0x14, parm);
795
796 /* outputs */
797 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
798 parm = AC_PWRST_D3;
799 set_pin_power_state(codec, 0x19, &parm);
800 if (smart51_enabled(codec))
801 set_pin_power_state(codec, 0x1b, &parm);
802 update_power_state(codec, 0x18, parm);
803 update_power_state(codec, 0x11, parm);
804
805 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
806 if (is_8ch) {
807 parm = AC_PWRST_D3;
808 set_pin_power_state(codec, 0x22, &parm);
809 if (smart51_enabled(codec))
810 set_pin_power_state(codec, 0x1a, &parm);
811 update_power_state(codec, 0x26, parm);
812 update_power_state(codec, 0x24, parm);
813 } else if (codec->vendor_id == 0x11064397) {
814 /* PW7(23h), SW2(27h), AOW2(25h) */
815 parm = AC_PWRST_D3;
816 set_pin_power_state(codec, 0x23, &parm);
817 if (smart51_enabled(codec))
818 set_pin_power_state(codec, 0x1a, &parm);
819 update_power_state(codec, 0x27, parm);
820 update_power_state(codec, 0x25, parm);
821 }
822
823 /* PW 3/4/7 (1ch/1dh/23h) */
824 parm = AC_PWRST_D3;
825 /* force to D0 for internal Speaker */
826 set_pin_power_state(codec, 0x1c, &parm);
827 set_pin_power_state(codec, 0x1d, &parm);
828 if (is_8ch)
829 set_pin_power_state(codec, 0x23, &parm);
830
831 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
832 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
833 update_power_state(codec, 0x10, parm);
834 if (is_8ch) {
835 update_power_state(codec, 0x25, parm);
836 update_power_state(codec, 0x27, parm);
837 } else if (codec->vendor_id == 0x11064397 && spec->gen.indep_hp_enabled)
838 update_power_state(codec, 0x25, parm);
839}
840
841static int patch_vt1708S(struct hda_codec *codec); 653static int patch_vt1708S(struct hda_codec *codec);
842static int patch_vt1708B(struct hda_codec *codec) 654static int patch_vt1708B(struct hda_codec *codec)
843{ 655{
@@ -862,9 +674,6 @@ static int patch_vt1708B(struct hda_codec *codec)
862 } 674 }
863 675
864 codec->patch_ops = via_patch_ops; 676 codec->patch_ops = via_patch_ops;
865
866 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
867
868 return 0; 677 return 0;
869} 678}
870 679
@@ -907,16 +716,16 @@ static int patch_vt1708S(struct hda_codec *codec)
907 if (get_codec_type(codec) == VT1708BCE) { 716 if (get_codec_type(codec) == VT1708BCE) {
908 kfree(codec->chip_name); 717 kfree(codec->chip_name);
909 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); 718 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
910 snprintf(codec->bus->card->mixername, 719 snprintf(codec->card->mixername,
911 sizeof(codec->bus->card->mixername), 720 sizeof(codec->card->mixername),
912 "%s %s", codec->vendor_name, codec->chip_name); 721 "%s %s", codec->vendor_name, codec->chip_name);
913 } 722 }
914 /* correct names for VT1705 */ 723 /* correct names for VT1705 */
915 if (codec->vendor_id == 0x11064397) { 724 if (codec->vendor_id == 0x11064397) {
916 kfree(codec->chip_name); 725 kfree(codec->chip_name);
917 codec->chip_name = kstrdup("VT1705", GFP_KERNEL); 726 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
918 snprintf(codec->bus->card->mixername, 727 snprintf(codec->card->mixername,
919 sizeof(codec->bus->card->mixername), 728 sizeof(codec->card->mixername),
920 "%s %s", codec->vendor_name, codec->chip_name); 729 "%s %s", codec->vendor_name, codec->chip_name);
921 } 730 }
922 731
@@ -930,8 +739,6 @@ static int patch_vt1708S(struct hda_codec *codec)
930 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs; 739 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
931 740
932 codec->patch_ops = via_patch_ops; 741 codec->patch_ops = via_patch_ops;
933
934 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
935 return 0; 742 return 0;
936} 743}
937 744
@@ -945,36 +752,6 @@ static const struct hda_verb vt1702_init_verbs[] = {
945 { } 752 { }
946}; 753};
947 754
948static void set_widgets_power_state_vt1702(struct hda_codec *codec)
949{
950 int imux_is_smixer =
951 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
952 unsigned int parm;
953 /* inputs */
954 /* PW 1/2/5 (14h/15h/18h) */
955 parm = AC_PWRST_D3;
956 set_pin_power_state(codec, 0x14, &parm);
957 set_pin_power_state(codec, 0x15, &parm);
958 set_pin_power_state(codec, 0x18, &parm);
959 if (imux_is_smixer)
960 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
961 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
962 update_power_state(codec, 0x13, parm);
963 update_power_state(codec, 0x12, parm);
964 update_power_state(codec, 0x1f, parm);
965 update_power_state(codec, 0x20, parm);
966
967 /* outputs */
968 /* PW 3/4 (16h/17h) */
969 parm = AC_PWRST_D3;
970 set_pin_power_state(codec, 0x17, &parm);
971 set_pin_power_state(codec, 0x16, &parm);
972 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
973 update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
974 update_power_state(codec, 0x10, parm);
975 update_power_state(codec, 0x1d, parm);
976}
977
978static int patch_vt1702(struct hda_codec *codec) 755static int patch_vt1702(struct hda_codec *codec)
979{ 756{
980 struct via_spec *spec; 757 struct via_spec *spec;
@@ -1004,8 +781,6 @@ static int patch_vt1702(struct hda_codec *codec)
1004 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs; 781 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
1005 782
1006 codec->patch_ops = via_patch_ops; 783 codec->patch_ops = via_patch_ops;
1007
1008 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
1009 return 0; 784 return 0;
1010} 785}
1011 786
@@ -1020,71 +795,6 @@ static const struct hda_verb vt1718S_init_verbs[] = {
1020 { } 795 { }
1021}; 796};
1022 797
1023static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
1024{
1025 struct via_spec *spec = codec->spec;
1026 int imux_is_smixer;
1027 unsigned int parm, parm2;
1028 /* MUX6 (1eh) = stereo mixer */
1029 imux_is_smixer =
1030 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
1031 /* inputs */
1032 /* PW 5/6/7 (29h/2ah/2bh) */
1033 parm = AC_PWRST_D3;
1034 set_pin_power_state(codec, 0x29, &parm);
1035 set_pin_power_state(codec, 0x2a, &parm);
1036 set_pin_power_state(codec, 0x2b, &parm);
1037 if (imux_is_smixer)
1038 parm = AC_PWRST_D0;
1039 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
1040 update_power_state(codec, 0x1e, parm);
1041 update_power_state(codec, 0x1f, parm);
1042 update_power_state(codec, 0x10, parm);
1043 update_power_state(codec, 0x11, parm);
1044
1045 /* outputs */
1046 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
1047 parm = AC_PWRST_D3;
1048 set_pin_power_state(codec, 0x27, &parm);
1049 update_power_state(codec, 0x1a, parm);
1050 parm2 = parm; /* for pin 0x0b */
1051
1052 /* PW2 (26h), AOW2 (ah) */
1053 parm = AC_PWRST_D3;
1054 set_pin_power_state(codec, 0x26, &parm);
1055 if (smart51_enabled(codec))
1056 set_pin_power_state(codec, 0x2b, &parm);
1057 update_power_state(codec, 0xa, parm);
1058
1059 /* PW0 (24h), AOW0 (8h) */
1060 parm = AC_PWRST_D3;
1061 set_pin_power_state(codec, 0x24, &parm);
1062 if (!spec->gen.indep_hp_enabled) /* check for redirected HP */
1063 set_pin_power_state(codec, 0x28, &parm);
1064 update_power_state(codec, 0x8, parm);
1065 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
1066 parm = parm2;
1067 update_power_state(codec, 0xb, parm);
1068 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1069 update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
1070
1071 /* PW1 (25h), AOW1 (9h) */
1072 parm = AC_PWRST_D3;
1073 set_pin_power_state(codec, 0x25, &parm);
1074 if (smart51_enabled(codec))
1075 set_pin_power_state(codec, 0x2a, &parm);
1076 update_power_state(codec, 0x9, parm);
1077
1078 if (spec->gen.indep_hp_enabled) {
1079 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
1080 parm = AC_PWRST_D3;
1081 set_pin_power_state(codec, 0x28, &parm);
1082 update_power_state(codec, 0x1b, parm);
1083 update_power_state(codec, 0x34, parm);
1084 update_power_state(codec, 0xc, parm);
1085 }
1086}
1087
1088/* Add a connection to the primary DAC from AA-mixer for some codecs 798/* Add a connection to the primary DAC from AA-mixer for some codecs
1089 * This isn't listed from the raw info, but the chip has a secret connection. 799 * This isn't listed from the raw info, but the chip has a secret connection.
1090 */ 800 */
@@ -1145,9 +855,6 @@ static int patch_vt1718S(struct hda_codec *codec)
1145 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs; 855 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
1146 856
1147 codec->patch_ops = via_patch_ops; 857 codec->patch_ops = via_patch_ops;
1148
1149 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
1150
1151 return 0; 858 return 0;
1152} 859}
1153 860
@@ -1187,7 +894,6 @@ static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
1187 snd_hda_codec_write(codec, 0x26, 0, 894 snd_hda_codec_write(codec, 0x26, 0,
1188 AC_VERB_SET_CONNECT_SEL, index); 895 AC_VERB_SET_CONNECT_SEL, index);
1189 spec->dmic_enabled = index; 896 spec->dmic_enabled = index;
1190 set_widgets_power_state(codec);
1191 return 1; 897 return 1;
1192} 898}
1193 899
@@ -1222,95 +928,6 @@ static const struct hda_verb vt1716S_init_verbs[] = {
1222 { } 928 { }
1223}; 929};
1224 930
1225static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
1226{
1227 struct via_spec *spec = codec->spec;
1228 int imux_is_smixer;
1229 unsigned int parm;
1230 unsigned int mono_out, present;
1231 /* SW0 (17h) = stereo mixer */
1232 imux_is_smixer =
1233 (snd_hda_codec_read(codec, 0x17, 0,
1234 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
1235 /* inputs */
1236 /* PW 1/2/5 (1ah/1bh/1eh) */
1237 parm = AC_PWRST_D3;
1238 set_pin_power_state(codec, 0x1a, &parm);
1239 set_pin_power_state(codec, 0x1b, &parm);
1240 set_pin_power_state(codec, 0x1e, &parm);
1241 if (imux_is_smixer)
1242 parm = AC_PWRST_D0;
1243 /* SW0 (17h), AIW0(13h) */
1244 update_power_state(codec, 0x17, parm);
1245 update_power_state(codec, 0x13, parm);
1246
1247 parm = AC_PWRST_D3;
1248 set_pin_power_state(codec, 0x1e, &parm);
1249 /* PW11 (22h) */
1250 if (spec->dmic_enabled)
1251 set_pin_power_state(codec, 0x22, &parm);
1252 else
1253 update_power_state(codec, 0x22, AC_PWRST_D3);
1254
1255 /* SW2(26h), AIW1(14h) */
1256 update_power_state(codec, 0x26, parm);
1257 update_power_state(codec, 0x14, parm);
1258
1259 /* outputs */
1260 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
1261 parm = AC_PWRST_D3;
1262 set_pin_power_state(codec, 0x19, &parm);
1263 /* Smart 5.1 PW2(1bh) */
1264 if (smart51_enabled(codec))
1265 set_pin_power_state(codec, 0x1b, &parm);
1266 update_power_state(codec, 0x18, parm);
1267 update_power_state(codec, 0x11, parm);
1268
1269 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
1270 parm = AC_PWRST_D3;
1271 set_pin_power_state(codec, 0x23, &parm);
1272 /* Smart 5.1 PW1(1ah) */
1273 if (smart51_enabled(codec))
1274 set_pin_power_state(codec, 0x1a, &parm);
1275 update_power_state(codec, 0x27, parm);
1276
1277 /* Smart 5.1 PW5(1eh) */
1278 if (smart51_enabled(codec))
1279 set_pin_power_state(codec, 0x1e, &parm);
1280 update_power_state(codec, 0x25, parm);
1281
1282 /* Mono out */
1283 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
1284 present = snd_hda_jack_detect(codec, 0x1c);
1285
1286 if (present)
1287 mono_out = 0;
1288 else {
1289 present = snd_hda_jack_detect(codec, 0x1d);
1290 if (!spec->gen.indep_hp_enabled && present)
1291 mono_out = 0;
1292 else
1293 mono_out = 1;
1294 }
1295 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
1296 update_power_state(codec, 0x28, parm);
1297 update_power_state(codec, 0x29, parm);
1298 update_power_state(codec, 0x2a, parm);
1299
1300 /* PW 3/4 (1ch/1dh) */
1301 parm = AC_PWRST_D3;
1302 set_pin_power_state(codec, 0x1c, &parm);
1303 set_pin_power_state(codec, 0x1d, &parm);
1304 /* HP Independent Mode, power on AOW3 */
1305 if (spec->gen.indep_hp_enabled)
1306 update_power_state(codec, 0x25, parm);
1307
1308 /* force to D0 for internal Speaker */
1309 /* MW0 (16h), AOW0 (10h) */
1310 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
1311 update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
1312}
1313
1314static int patch_vt1716S(struct hda_codec *codec) 931static int patch_vt1716S(struct hda_codec *codec)
1315{ 932{
1316 struct via_spec *spec; 933 struct via_spec *spec;
@@ -1338,8 +955,6 @@ static int patch_vt1716S(struct hda_codec *codec)
1338 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; 955 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
1339 956
1340 codec->patch_ops = via_patch_ops; 957 codec->patch_ops = via_patch_ops;
1341
1342 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
1343 return 0; 958 return 0;
1344} 959}
1345 960
@@ -1365,98 +980,6 @@ static const struct hda_verb vt1802_init_verbs[] = {
1365 { } 980 { }
1366}; 981};
1367 982
1368static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
1369{
1370 struct via_spec *spec = codec->spec;
1371 int imux_is_smixer;
1372 unsigned int parm;
1373 unsigned int present;
1374 /* MUX9 (1eh) = stereo mixer */
1375 imux_is_smixer =
1376 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
1377 /* inputs */
1378 /* PW 5/6/7 (29h/2ah/2bh) */
1379 parm = AC_PWRST_D3;
1380 set_pin_power_state(codec, 0x29, &parm);
1381 set_pin_power_state(codec, 0x2a, &parm);
1382 set_pin_power_state(codec, 0x2b, &parm);
1383 parm = AC_PWRST_D0;
1384 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
1385 update_power_state(codec, 0x1e, parm);
1386 update_power_state(codec, 0x1f, parm);
1387 update_power_state(codec, 0x10, parm);
1388 update_power_state(codec, 0x11, parm);
1389
1390 /* outputs */
1391 /* AOW0 (8h)*/
1392 update_power_state(codec, 0x8, parm);
1393
1394 if (spec->codec_type == VT1802) {
1395 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1396 parm = AC_PWRST_D3;
1397 set_pin_power_state(codec, 0x28, &parm);
1398 update_power_state(codec, 0x18, parm);
1399 update_power_state(codec, 0x38, parm);
1400 } else {
1401 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
1402 parm = AC_PWRST_D3;
1403 set_pin_power_state(codec, 0x26, &parm);
1404 update_power_state(codec, 0x1c, parm);
1405 update_power_state(codec, 0x37, parm);
1406 }
1407
1408 if (spec->codec_type == VT1802) {
1409 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1410 parm = AC_PWRST_D3;
1411 set_pin_power_state(codec, 0x25, &parm);
1412 update_power_state(codec, 0x15, parm);
1413 update_power_state(codec, 0x35, parm);
1414 } else {
1415 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
1416 parm = AC_PWRST_D3;
1417 set_pin_power_state(codec, 0x25, &parm);
1418 update_power_state(codec, 0x19, parm);
1419 update_power_state(codec, 0x35, parm);
1420 }
1421
1422 if (spec->gen.indep_hp_enabled)
1423 update_power_state(codec, 0x9, AC_PWRST_D0);
1424
1425 /* Class-D */
1426 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
1427 present = snd_hda_jack_detect(codec, 0x25);
1428
1429 parm = AC_PWRST_D3;
1430 set_pin_power_state(codec, 0x24, &parm);
1431 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
1432 if (spec->codec_type == VT1802)
1433 update_power_state(codec, 0x14, parm);
1434 else
1435 update_power_state(codec, 0x18, parm);
1436 update_power_state(codec, 0x34, parm);
1437
1438 /* Mono Out */
1439 present = snd_hda_jack_detect(codec, 0x26);
1440
1441 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
1442 if (spec->codec_type == VT1802) {
1443 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
1444 update_power_state(codec, 0x33, parm);
1445 update_power_state(codec, 0x1c, parm);
1446 update_power_state(codec, 0x3c, parm);
1447 } else {
1448 /* PW15 (31h), MW8(17h), MUX8(3bh) */
1449 update_power_state(codec, 0x31, parm);
1450 update_power_state(codec, 0x17, parm);
1451 update_power_state(codec, 0x3b, parm);
1452 }
1453 /* MW9 (21h) */
1454 if (imux_is_smixer || !is_aa_path_mute(codec))
1455 update_power_state(codec, 0x21, AC_PWRST_D0);
1456 else
1457 update_power_state(codec, 0x21, AC_PWRST_D3);
1458}
1459
1460/* 983/*
1461 * pin fix-up 984 * pin fix-up
1462 */ 985 */
@@ -1540,8 +1063,6 @@ static int patch_vt2002P(struct hda_codec *codec)
1540 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs; 1063 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
1541 1064
1542 codec->patch_ops = via_patch_ops; 1065 codec->patch_ops = via_patch_ops;
1543
1544 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
1545 return 0; 1066 return 0;
1546} 1067}
1547 1068
@@ -1555,81 +1076,6 @@ static const struct hda_verb vt1812_init_verbs[] = {
1555 { } 1076 { }
1556}; 1077};
1557 1078
1558static void set_widgets_power_state_vt1812(struct hda_codec *codec)
1559{
1560 struct via_spec *spec = codec->spec;
1561 unsigned int parm;
1562 unsigned int present;
1563 /* inputs */
1564 /* PW 5/6/7 (29h/2ah/2bh) */
1565 parm = AC_PWRST_D3;
1566 set_pin_power_state(codec, 0x29, &parm);
1567 set_pin_power_state(codec, 0x2a, &parm);
1568 set_pin_power_state(codec, 0x2b, &parm);
1569 parm = AC_PWRST_D0;
1570 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1571 update_power_state(codec, 0x1e, parm);
1572 update_power_state(codec, 0x1f, parm);
1573 update_power_state(codec, 0x10, parm);
1574 update_power_state(codec, 0x11, parm);
1575
1576 /* outputs */
1577 /* AOW0 (8h)*/
1578 update_power_state(codec, 0x8, AC_PWRST_D0);
1579
1580 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1581 parm = AC_PWRST_D3;
1582 set_pin_power_state(codec, 0x28, &parm);
1583 update_power_state(codec, 0x18, parm);
1584 update_power_state(codec, 0x38, parm);
1585
1586 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1587 parm = AC_PWRST_D3;
1588 set_pin_power_state(codec, 0x25, &parm);
1589 update_power_state(codec, 0x15, parm);
1590 update_power_state(codec, 0x35, parm);
1591 if (spec->gen.indep_hp_enabled)
1592 update_power_state(codec, 0x9, AC_PWRST_D0);
1593
1594 /* Internal Speaker */
1595 /* PW0 (24h), MW0(14h), MUX0(34h) */
1596 present = snd_hda_jack_detect(codec, 0x25);
1597
1598 parm = AC_PWRST_D3;
1599 set_pin_power_state(codec, 0x24, &parm);
1600 if (present) {
1601 update_power_state(codec, 0x14, AC_PWRST_D3);
1602 update_power_state(codec, 0x34, AC_PWRST_D3);
1603 } else {
1604 update_power_state(codec, 0x14, AC_PWRST_D0);
1605 update_power_state(codec, 0x34, AC_PWRST_D0);
1606 }
1607
1608
1609 /* Mono Out */
1610 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1611 present = snd_hda_jack_detect(codec, 0x28);
1612
1613 parm = AC_PWRST_D3;
1614 set_pin_power_state(codec, 0x31, &parm);
1615 if (present) {
1616 update_power_state(codec, 0x1c, AC_PWRST_D3);
1617 update_power_state(codec, 0x3c, AC_PWRST_D3);
1618 update_power_state(codec, 0x3e, AC_PWRST_D3);
1619 } else {
1620 update_power_state(codec, 0x1c, AC_PWRST_D0);
1621 update_power_state(codec, 0x3c, AC_PWRST_D0);
1622 update_power_state(codec, 0x3e, AC_PWRST_D0);
1623 }
1624
1625 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1626 parm = AC_PWRST_D3;
1627 set_pin_power_state(codec, 0x33, &parm);
1628 update_power_state(codec, 0x1d, parm);
1629 update_power_state(codec, 0x3d, parm);
1630
1631}
1632
1633/* patch for vt1812 */ 1079/* patch for vt1812 */
1634static int patch_vt1812(struct hda_codec *codec) 1080static int patch_vt1812(struct hda_codec *codec)
1635{ 1081{
@@ -1656,8 +1102,6 @@ static int patch_vt1812(struct hda_codec *codec)
1656 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs; 1102 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
1657 1103
1658 codec->patch_ops = via_patch_ops; 1104 codec->patch_ops = via_patch_ops;
1659
1660 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
1661 return 0; 1105 return 0;
1662} 1106}
1663 1107
@@ -1673,84 +1117,6 @@ static const struct hda_verb vt3476_init_verbs[] = {
1673 { } 1117 { }
1674}; 1118};
1675 1119
1676static void set_widgets_power_state_vt3476(struct hda_codec *codec)
1677{
1678 struct via_spec *spec = codec->spec;
1679 int imux_is_smixer;
1680 unsigned int parm, parm2;
1681 /* MUX10 (1eh) = stereo mixer */
1682 imux_is_smixer =
1683 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4;
1684 /* inputs */
1685 /* PW 5/6/7 (29h/2ah/2bh) */
1686 parm = AC_PWRST_D3;
1687 set_pin_power_state(codec, 0x29, &parm);
1688 set_pin_power_state(codec, 0x2a, &parm);
1689 set_pin_power_state(codec, 0x2b, &parm);
1690 if (imux_is_smixer)
1691 parm = AC_PWRST_D0;
1692 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1693 update_power_state(codec, 0x1e, parm);
1694 update_power_state(codec, 0x1f, parm);
1695 update_power_state(codec, 0x10, parm);
1696 update_power_state(codec, 0x11, parm);
1697
1698 /* outputs */
1699 /* PW3 (27h), MW3(37h), AOW3 (bh) */
1700 if (spec->codec_type == VT1705CF) {
1701 parm = AC_PWRST_D3;
1702 update_power_state(codec, 0x27, parm);
1703 update_power_state(codec, 0x37, parm);
1704 } else {
1705 parm = AC_PWRST_D3;
1706 set_pin_power_state(codec, 0x27, &parm);
1707 update_power_state(codec, 0x37, parm);
1708 }
1709
1710 /* PW2 (26h), MW2(36h), AOW2 (ah) */
1711 parm = AC_PWRST_D3;
1712 set_pin_power_state(codec, 0x26, &parm);
1713 update_power_state(codec, 0x36, parm);
1714 if (smart51_enabled(codec)) {
1715 /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
1716 set_pin_power_state(codec, 0x2b, &parm);
1717 update_power_state(codec, 0x3b, parm);
1718 update_power_state(codec, 0x1b, parm);
1719 }
1720 update_conv_power_state(codec, 0xa, parm, 2);
1721
1722 /* PW1 (25h), MW1(35h), AOW1 (9h) */
1723 parm = AC_PWRST_D3;
1724 set_pin_power_state(codec, 0x25, &parm);
1725 update_power_state(codec, 0x35, parm);
1726 if (smart51_enabled(codec)) {
1727 /* PW6(2ah), MW6(3ah), MUX6(1ah) */
1728 set_pin_power_state(codec, 0x2a, &parm);
1729 update_power_state(codec, 0x3a, parm);
1730 update_power_state(codec, 0x1a, parm);
1731 }
1732 update_conv_power_state(codec, 0x9, parm, 1);
1733
1734 /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
1735 parm = AC_PWRST_D3;
1736 set_pin_power_state(codec, 0x28, &parm);
1737 update_power_state(codec, 0x38, parm);
1738 update_power_state(codec, 0x18, parm);
1739 if (spec->gen.indep_hp_enabled)
1740 update_conv_power_state(codec, 0xb, parm, 3);
1741 parm2 = parm; /* for pin 0x0b */
1742
1743 /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
1744 parm = AC_PWRST_D3;
1745 set_pin_power_state(codec, 0x24, &parm);
1746 update_power_state(codec, 0x34, parm);
1747 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
1748 parm = parm2;
1749 update_conv_power_state(codec, 0x8, parm, 0);
1750 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1751 update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm);
1752}
1753
1754static int patch_vt3476(struct hda_codec *codec) 1120static int patch_vt3476(struct hda_codec *codec)
1755{ 1121{
1756 struct via_spec *spec; 1122 struct via_spec *spec;
@@ -1774,9 +1140,6 @@ static int patch_vt3476(struct hda_codec *codec)
1774 spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs; 1140 spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;
1775 1141
1776 codec->patch_ops = via_patch_ops; 1142 codec->patch_ops = via_patch_ops;
1777
1778 spec->set_widgets_power_state = set_widgets_power_state_vt3476;
1779
1780 return 0; 1143 return 0;
1781} 1144}
1782 1145
@@ -1884,23 +1247,11 @@ static const struct hda_codec_preset snd_hda_preset_via[] = {
1884 1247
1885MODULE_ALIAS("snd-hda-codec-id:1106*"); 1248MODULE_ALIAS("snd-hda-codec-id:1106*");
1886 1249
1887static struct hda_codec_preset_list via_list = { 1250static struct hda_codec_driver via_driver = {
1888 .preset = snd_hda_preset_via, 1251 .preset = snd_hda_preset_via,
1889 .owner = THIS_MODULE,
1890}; 1252};
1891 1253
1892MODULE_LICENSE("GPL"); 1254MODULE_LICENSE("GPL");
1893MODULE_DESCRIPTION("VIA HD-audio codec"); 1255MODULE_DESCRIPTION("VIA HD-audio codec");
1894 1256
1895static int __init patch_via_init(void) 1257module_hda_codec_driver(via_driver);
1896{
1897 return snd_hda_add_codec_preset(&via_list);
1898}
1899
1900static void __exit patch_via_exit(void)
1901{
1902 snd_hda_delete_codec_preset(&via_list);
1903}
1904
1905module_init(patch_via_init)
1906module_exit(patch_via_exit)
diff --git a/sound/pci/ice1712/wtm.c b/sound/pci/ice1712/wtm.c
index bcf30a387b87..9906119e0954 100644
--- a/sound/pci/ice1712/wtm.c
+++ b/sound/pci/ice1712/wtm.c
@@ -29,12 +29,19 @@
29#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30#include <linux/init.h> 30#include <linux/init.h>
31#include <sound/core.h> 31#include <sound/core.h>
32#include <sound/tlv.h>
33#include <linux/slab.h>
32 34
33#include "ice1712.h" 35#include "ice1712.h"
34#include "envy24ht.h" 36#include "envy24ht.h"
35#include "wtm.h" 37#include "wtm.h"
36#include "stac946x.h" 38#include "stac946x.h"
37 39
40struct wtm_spec {
41 /* rate change needs atomic mute/unmute of all dacs*/
42 struct mutex mute_mutex;
43};
44
38 45
39/* 46/*
40 * 2*ADC 6*DAC no1 ringbuffer r/w on i2c bus 47 * 2*ADC 6*DAC no1 ringbuffer r/w on i2c bus
@@ -68,15 +75,65 @@ static inline unsigned char stac9460_2_get(struct snd_ice1712 *ice, int reg)
68/* 75/*
69 * DAC mute control 76 * DAC mute control
70 */ 77 */
78static void stac9460_dac_mute_all(struct snd_ice1712 *ice, unsigned char mute,
79 unsigned short int *change_mask)
80{
81 unsigned char new, old;
82 int id, idx, change;
83
84 /*stac9460 1*/
85 for (id = 0; id < 7; id++) {
86 if (*change_mask & (0x01 << id)) {
87 if (id == 0)
88 idx = STAC946X_MASTER_VOLUME;
89 else
90 idx = STAC946X_LF_VOLUME - 1 + id;
91 old = stac9460_get(ice, idx);
92 new = (~mute << 7 & 0x80) | (old & ~0x80);
93 change = (new != old);
94 if (change) {
95 stac9460_put(ice, idx, new);
96 *change_mask = *change_mask | (0x01 << id);
97 } else {
98 *change_mask = *change_mask & ~(0x01 << id);
99 }
100 }
101 }
102
103 /*stac9460 2*/
104 for (id = 0; id < 3; id++) {
105 if (*change_mask & (0x01 << (id + 7))) {
106 if (id == 0)
107 idx = STAC946X_MASTER_VOLUME;
108 else
109 idx = STAC946X_LF_VOLUME - 1 + id;
110 old = stac9460_2_get(ice, idx);
111 new = (~mute << 7 & 0x80) | (old & ~0x80);
112 change = (new != old);
113 if (change) {
114 stac9460_2_put(ice, idx, new);
115 *change_mask = *change_mask | (0x01 << id);
116 } else {
117 *change_mask = *change_mask & ~(0x01 << id);
118 }
119 }
120 }
121}
122
123
124
71#define stac9460_dac_mute_info snd_ctl_boolean_mono_info 125#define stac9460_dac_mute_info snd_ctl_boolean_mono_info
72 126
73static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol, 127static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol,
74 struct snd_ctl_elem_value *ucontrol) 128 struct snd_ctl_elem_value *ucontrol)
75{ 129{
76 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 130 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
131 struct wtm_spec *spec = ice->spec;
77 unsigned char val; 132 unsigned char val;
78 int idx, id; 133 int idx, id;
79 134
135 mutex_lock(&spec->mute_mutex);
136
80 if (kcontrol->private_value) { 137 if (kcontrol->private_value) {
81 idx = STAC946X_MASTER_VOLUME; 138 idx = STAC946X_MASTER_VOLUME;
82 id = 0; 139 id = 0;
@@ -89,6 +146,8 @@ static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol,
89 else 146 else
90 val = stac9460_2_get(ice, idx - 6); 147 val = stac9460_2_get(ice, idx - 6);
91 ucontrol->value.integer.value[0] = (~val >> 7) & 0x1; 148 ucontrol->value.integer.value[0] = (~val >> 7) & 0x1;
149
150 mutex_unlock(&spec->mute_mutex);
92 return 0; 151 return 0;
93} 152}
94 153
@@ -338,8 +397,14 @@ static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol,
338/* 397/*
339 * MIC / LINE switch fonction 398 * MIC / LINE switch fonction
340 */ 399 */
400static int stac9460_mic_sw_info(struct snd_kcontrol *kcontrol,
401 struct snd_ctl_elem_info *uinfo)
402{
403 static const char * const texts[2] = { "Line In", "Mic" };
404
405 return snd_ctl_enum_info(uinfo, 1, 2, texts);
406}
341 407
342#define stac9460_mic_sw_info snd_ctl_boolean_mono_info
343 408
344static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol, 409static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol,
345 struct snd_ctl_elem_value *ucontrol) 410 struct snd_ctl_elem_value *ucontrol)
@@ -353,7 +418,7 @@ static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol,
353 val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE); 418 val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
354 else 419 else
355 val = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE); 420 val = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE);
356 ucontrol->value.integer.value[0] = ~val>>7 & 0x1; 421 ucontrol->value.enumerated.item[0] = (val >> 7) & 0x1;
357 return 0; 422 return 0;
358} 423}
359 424
@@ -369,7 +434,7 @@ static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
369 old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE); 434 old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
370 else 435 else
371 old = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE); 436 old = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE);
372 new = (~ucontrol->value.integer.value[0] << 7 & 0x80) | (old & ~0x80); 437 new = (ucontrol->value.enumerated.item[0] << 7 & 0x80) | (old & ~0x80);
373 change = (new != old); 438 change = (new != old);
374 if (change) { 439 if (change) {
375 if (id == 0) 440 if (id == 0)
@@ -380,17 +445,63 @@ static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
380 return change; 445 return change;
381} 446}
382 447
448
449/*
450 * Handler for setting correct codec rate - called when rate change is detected
451 */
452static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)
453{
454 unsigned char old, new;
455 unsigned short int changed;
456 struct wtm_spec *spec = ice->spec;
457
458 if (rate == 0) /* no hint - S/PDIF input is master, simply return */
459 return;
460 else if (rate <= 48000)
461 new = 0x08; /* 256x, base rate mode */
462 else if (rate <= 96000)
463 new = 0x11; /* 256x, mid rate mode */
464 else
465 new = 0x12; /* 128x, high rate mode */
466
467 old = stac9460_get(ice, STAC946X_MASTER_CLOCKING);
468 if (old == new)
469 return;
470 /* change detected, setting master clock, muting first */
471 /* due to possible conflicts with mute controls - mutexing */
472 mutex_lock(&spec->mute_mutex);
473 /* we have to remember current mute status for each DAC */
474 changed = 0xFFFF;
475 stac9460_dac_mute_all(ice, 0, &changed);
476 /*printk(KERN_DEBUG "Rate change: %d, new MC: 0x%02x\n", rate, new);*/
477 stac9460_put(ice, STAC946X_MASTER_CLOCKING, new);
478 stac9460_2_put(ice, STAC946X_MASTER_CLOCKING, new);
479 udelay(10);
480 /* unmuting - only originally unmuted dacs -
481 * i.e. those changed when muting */
482 stac9460_dac_mute_all(ice, 1, &changed);
483 mutex_unlock(&spec->mute_mutex);
484}
485
486
487/*Limits value in dB for fader*/
488static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0);
489static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0);
490
383/* 491/*
384 * Control tabs 492 * Control tabs
385 */ 493 */
386static struct snd_kcontrol_new stac9640_controls[] = { 494static struct snd_kcontrol_new stac9640_controls[] = {
387 { 495 {
388 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 496 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
497 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
498 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
389 .name = "Master Playback Switch", 499 .name = "Master Playback Switch",
390 .info = stac9460_dac_mute_info, 500 .info = stac9460_dac_mute_info,
391 .get = stac9460_dac_mute_get, 501 .get = stac9460_dac_mute_get,
392 .put = stac9460_dac_mute_put, 502 .put = stac9460_dac_mute_put,
393 .private_value = 1 503 .private_value = 1,
504 .tlv = { .p = db_scale_dac }
394 }, 505 },
395 { 506 {
396 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 507 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -402,7 +513,7 @@ static struct snd_kcontrol_new stac9640_controls[] = {
402 }, 513 },
403 { 514 {
404 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 515 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
405 .name = "MIC/Line switch", 516 .name = "MIC/Line Input Enum",
406 .count = 2, 517 .count = 2,
407 .info = stac9460_mic_sw_info, 518 .info = stac9460_mic_sw_info,
408 .get = stac9460_mic_sw_get, 519 .get = stac9460_mic_sw_get,
@@ -419,11 +530,15 @@ static struct snd_kcontrol_new stac9640_controls[] = {
419 }, 530 },
420 { 531 {
421 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 532 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
533 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
534 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
535
422 .name = "DAC Volume", 536 .name = "DAC Volume",
423 .count = 8, 537 .count = 8,
424 .info = stac9460_dac_vol_info, 538 .info = stac9460_dac_vol_info,
425 .get = stac9460_dac_vol_get, 539 .get = stac9460_dac_vol_get,
426 .put = stac9460_dac_vol_put, 540 .put = stac9460_dac_vol_put,
541 .tlv = { .p = db_scale_dac }
427 }, 542 },
428 { 543 {
429 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 544 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -435,12 +550,15 @@ static struct snd_kcontrol_new stac9640_controls[] = {
435 }, 550 },
436 { 551 {
437 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 552 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
553 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
554 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
555
438 .name = "ADC Volume", 556 .name = "ADC Volume",
439 .count = 2, 557 .count = 2,
440 .info = stac9460_adc_vol_info, 558 .info = stac9460_adc_vol_info,
441 .get = stac9460_adc_vol_get, 559 .get = stac9460_adc_vol_get,
442 .put = stac9460_adc_vol_put, 560 .put = stac9460_adc_vol_put,
443 561 .tlv = { .p = db_scale_adc }
444 } 562 }
445}; 563};
446 564
@@ -463,41 +581,53 @@ static int wtm_add_controls(struct snd_ice1712 *ice)
463 581
464static int wtm_init(struct snd_ice1712 *ice) 582static int wtm_init(struct snd_ice1712 *ice)
465{ 583{
466 static unsigned short stac_inits_prodigy[] = { 584 static unsigned short stac_inits_wtm[] = {
467 STAC946X_RESET, 0, 585 STAC946X_RESET, 0,
586 STAC946X_MASTER_CLOCKING, 0x11,
468 (unsigned short)-1 587 (unsigned short)-1
469 }; 588 };
470 unsigned short *p; 589 unsigned short *p;
590 struct wtm_spec *spec;
471 591
472 /*WTM 192M*/ 592 /*WTM 192M*/
473 ice->num_total_dacs = 8; 593 ice->num_total_dacs = 8;
474 ice->num_total_adcs = 4; 594 ice->num_total_adcs = 4;
475 ice->force_rdma1 = 1; 595 ice->force_rdma1 = 1;
476 596
597 /*init mutex for dac mute conflict*/
598 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
599 if (!spec)
600 return -ENOMEM;
601 ice->spec = spec;
602 mutex_init(&spec->mute_mutex);
603
604
477 /*initialize codec*/ 605 /*initialize codec*/
478 p = stac_inits_prodigy; 606 p = stac_inits_wtm;
479 for (; *p != (unsigned short)-1; p += 2) { 607 for (; *p != (unsigned short)-1; p += 2) {
480 stac9460_put(ice, p[0], p[1]); 608 stac9460_put(ice, p[0], p[1]);
481 stac9460_2_put(ice, p[0], p[1]); 609 stac9460_2_put(ice, p[0], p[1]);
482 } 610 }
611 ice->gpio.set_pro_rate = stac9460_set_rate_val;
483 return 0; 612 return 0;
484} 613}
485 614
486 615
487static unsigned char wtm_eeprom[] = { 616static unsigned char wtm_eeprom[] = {
488 0x47, /*SYSCONF: clock 192KHz, 4ADC, 8DAC */ 617 [ICE_EEP2_SYSCONF] = 0x67, /*SYSCONF: clock 192KHz, mpu401,
489 0x80, /* ACLINK : I2S */ 618 4ADC, 8DAC */
490 0xf8, /* I2S: vol; 96k, 24bit, 192k */ 619 [ICE_EEP2_ACLINK] = 0x80, /* ACLINK : I2S */
491 0xc1 /*SPDIF: out-en, spidf ext out*/, 620 [ICE_EEP2_I2S] = 0xf8, /* I2S: vol; 96k, 24bit, 192k */
492 0x9f, /* GPIO_DIR */ 621 [ICE_EEP2_SPDIF] = 0xc1, /*SPDIF: out-en, spidf ext out*/
493 0xff, /* GPIO_DIR1 */ 622 [ICE_EEP2_GPIO_DIR] = 0x9f,
494 0x7f, /* GPIO_DIR2 */ 623 [ICE_EEP2_GPIO_DIR1] = 0xff,
495 0x9f, /* GPIO_MASK */ 624 [ICE_EEP2_GPIO_DIR2] = 0x7f,
496 0xff, /* GPIO_MASK1 */ 625 [ICE_EEP2_GPIO_MASK] = 0x9f,
497 0x7f, /* GPIO_MASK2 */ 626 [ICE_EEP2_GPIO_MASK1] = 0xff,
498 0x16, /* GPIO_STATE */ 627 [ICE_EEP2_GPIO_MASK2] = 0x7f,
499 0x80, /* GPIO_STATE1 */ 628 [ICE_EEP2_GPIO_STATE] = 0x16,
500 0x00, /* GPIO_STATE2 */ 629 [ICE_EEP2_GPIO_STATE1] = 0x80,
630 [ICE_EEP2_GPIO_STATE2] = 0x00,
501}; 631};
502 632
503 633
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index ca67f896d117..cb666c73712d 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -6043,23 +6043,30 @@ hdspm_hw_constraints_aes32_sample_rates = {
6043 .mask = 0 6043 .mask = 0
6044}; 6044};
6045 6045
6046static int snd_hdspm_playback_open(struct snd_pcm_substream *substream) 6046static int snd_hdspm_open(struct snd_pcm_substream *substream)
6047{ 6047{
6048 struct hdspm *hdspm = snd_pcm_substream_chip(substream); 6048 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6049 struct snd_pcm_runtime *runtime = substream->runtime; 6049 struct snd_pcm_runtime *runtime = substream->runtime;
6050 bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
6050 6051
6051 spin_lock_irq(&hdspm->lock); 6052 spin_lock_irq(&hdspm->lock);
6052
6053 snd_pcm_set_sync(substream); 6053 snd_pcm_set_sync(substream);
6054 runtime->hw = (playback) ? snd_hdspm_playback_subinfo :
6055 snd_hdspm_capture_subinfo;
6054 6056
6057 if (playback) {
6058 if (hdspm->capture_substream == NULL)
6059 hdspm_stop_audio(hdspm);
6055 6060
6056 runtime->hw = snd_hdspm_playback_subinfo; 6061 hdspm->playback_pid = current->pid;
6057 6062 hdspm->playback_substream = substream;
6058 if (hdspm->capture_substream == NULL) 6063 } else {
6059 hdspm_stop_audio(hdspm); 6064 if (hdspm->playback_substream == NULL)
6065 hdspm_stop_audio(hdspm);
6060 6066
6061 hdspm->playback_pid = current->pid; 6067 hdspm->capture_pid = current->pid;
6062 hdspm->playback_substream = substream; 6068 hdspm->capture_substream = substream;
6069 }
6063 6070
6064 spin_unlock_irq(&hdspm->lock); 6071 spin_unlock_irq(&hdspm->lock);
6065 6072
@@ -6094,108 +6101,42 @@ static int snd_hdspm_playback_open(struct snd_pcm_substream *substream)
6094 &hdspm_hw_constraints_aes32_sample_rates); 6101 &hdspm_hw_constraints_aes32_sample_rates);
6095 } else { 6102 } else {
6096 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 6103 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6097 snd_hdspm_hw_rule_rate_out_channels, hdspm, 6104 (playback ?
6105 snd_hdspm_hw_rule_rate_out_channels :
6106 snd_hdspm_hw_rule_rate_in_channels), hdspm,
6098 SNDRV_PCM_HW_PARAM_CHANNELS, -1); 6107 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6099 } 6108 }
6100 6109
6101 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 6110 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6102 snd_hdspm_hw_rule_out_channels, hdspm, 6111 (playback ? snd_hdspm_hw_rule_out_channels :
6112 snd_hdspm_hw_rule_in_channels), hdspm,
6103 SNDRV_PCM_HW_PARAM_CHANNELS, -1); 6113 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6104 6114
6105 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 6115 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6106 snd_hdspm_hw_rule_out_channels_rate, hdspm, 6116 (playback ? snd_hdspm_hw_rule_out_channels_rate :
6117 snd_hdspm_hw_rule_in_channels_rate), hdspm,
6107 SNDRV_PCM_HW_PARAM_RATE, -1); 6118 SNDRV_PCM_HW_PARAM_RATE, -1);
6108 6119
6109 return 0; 6120 return 0;
6110} 6121}
6111 6122
6112static int snd_hdspm_playback_release(struct snd_pcm_substream *substream) 6123static int snd_hdspm_release(struct snd_pcm_substream *substream)
6113{ 6124{
6114 struct hdspm *hdspm = snd_pcm_substream_chip(substream); 6125 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6126 bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
6115 6127
6116 spin_lock_irq(&hdspm->lock); 6128 spin_lock_irq(&hdspm->lock);
6117 6129
6118 hdspm->playback_pid = -1; 6130 if (playback) {
6119 hdspm->playback_substream = NULL; 6131 hdspm->playback_pid = -1;
6120 6132 hdspm->playback_substream = NULL;
6121 spin_unlock_irq(&hdspm->lock);
6122
6123 return 0;
6124}
6125
6126
6127static int snd_hdspm_capture_open(struct snd_pcm_substream *substream)
6128{
6129 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6130 struct snd_pcm_runtime *runtime = substream->runtime;
6131
6132 spin_lock_irq(&hdspm->lock);
6133 snd_pcm_set_sync(substream);
6134 runtime->hw = snd_hdspm_capture_subinfo;
6135
6136 if (hdspm->playback_substream == NULL)
6137 hdspm_stop_audio(hdspm);
6138
6139 hdspm->capture_pid = current->pid;
6140 hdspm->capture_substream = substream;
6141
6142 spin_unlock_irq(&hdspm->lock);
6143
6144 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
6145 snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
6146
6147 switch (hdspm->io_type) {
6148 case AIO:
6149 case RayDAT:
6150 snd_pcm_hw_constraint_minmax(runtime,
6151 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6152 32, 4096);
6153 snd_pcm_hw_constraint_minmax(runtime,
6154 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
6155 16384, 16384);
6156 break;
6157
6158 default:
6159 snd_pcm_hw_constraint_minmax(runtime,
6160 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6161 64, 8192);
6162 snd_pcm_hw_constraint_minmax(runtime,
6163 SNDRV_PCM_HW_PARAM_PERIODS,
6164 2, 2);
6165 break;
6166 }
6167
6168 if (AES32 == hdspm->io_type) {
6169 runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
6170 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6171 &hdspm_hw_constraints_aes32_sample_rates);
6172 } else { 6133 } else {
6173 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 6134 hdspm->capture_pid = -1;
6174 snd_hdspm_hw_rule_rate_in_channels, hdspm, 6135 hdspm->capture_substream = NULL;
6175 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6176 } 6136 }
6177 6137
6178 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6179 snd_hdspm_hw_rule_in_channels, hdspm,
6180 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6181
6182 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6183 snd_hdspm_hw_rule_in_channels_rate, hdspm,
6184 SNDRV_PCM_HW_PARAM_RATE, -1);
6185
6186 return 0;
6187}
6188
6189static int snd_hdspm_capture_release(struct snd_pcm_substream *substream)
6190{
6191 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6192
6193 spin_lock_irq(&hdspm->lock);
6194
6195 hdspm->capture_pid = -1;
6196 hdspm->capture_substream = NULL;
6197
6198 spin_unlock_irq(&hdspm->lock); 6138 spin_unlock_irq(&hdspm->lock);
6139
6199 return 0; 6140 return 0;
6200} 6141}
6201 6142
@@ -6413,21 +6354,9 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
6413 return 0; 6354 return 0;
6414} 6355}
6415 6356
6416static struct snd_pcm_ops snd_hdspm_playback_ops = { 6357static struct snd_pcm_ops snd_hdspm_ops = {
6417 .open = snd_hdspm_playback_open, 6358 .open = snd_hdspm_open,
6418 .close = snd_hdspm_playback_release, 6359 .close = snd_hdspm_release,
6419 .ioctl = snd_hdspm_ioctl,
6420 .hw_params = snd_hdspm_hw_params,
6421 .hw_free = snd_hdspm_hw_free,
6422 .prepare = snd_hdspm_prepare,
6423 .trigger = snd_hdspm_trigger,
6424 .pointer = snd_hdspm_hw_pointer,
6425 .page = snd_pcm_sgbuf_ops_page,
6426};
6427
6428static struct snd_pcm_ops snd_hdspm_capture_ops = {
6429 .open = snd_hdspm_capture_open,
6430 .close = snd_hdspm_capture_release,
6431 .ioctl = snd_hdspm_ioctl, 6360 .ioctl = snd_hdspm_ioctl,
6432 .hw_params = snd_hdspm_hw_params, 6361 .hw_params = snd_hdspm_hw_params,
6433 .hw_free = snd_hdspm_hw_free, 6362 .hw_free = snd_hdspm_hw_free,
@@ -6521,9 +6450,9 @@ static int snd_hdspm_create_pcm(struct snd_card *card,
6521 strcpy(pcm->name, hdspm->card_name); 6450 strcpy(pcm->name, hdspm->card_name);
6522 6451
6523 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, 6452 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
6524 &snd_hdspm_playback_ops); 6453 &snd_hdspm_ops);
6525 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, 6454 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
6526 &snd_hdspm_capture_ops); 6455 &snd_hdspm_ops);
6527 6456
6528 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; 6457 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
6529 6458
diff --git a/sound/soc/atmel/atmel_ssc_dai.c b/sound/soc/atmel/atmel_ssc_dai.c
index fb0b7e8b08ff..841d05946b88 100644
--- a/sound/soc/atmel/atmel_ssc_dai.c
+++ b/sound/soc/atmel/atmel_ssc_dai.c
@@ -187,6 +187,94 @@ static irqreturn_t atmel_ssc_interrupt(int irq, void *dev_id)
187 return IRQ_HANDLED; 187 return IRQ_HANDLED;
188} 188}
189 189
190/*
191 * When the bit clock is input, limit the maximum rate according to the
192 * Serial Clock Ratio Considerations section from the SSC documentation:
193 *
194 * The Transmitter and the Receiver can be programmed to operate
195 * with the clock signals provided on either the TK or RK pins.
196 * This allows the SSC to support many slave-mode data transfers.
197 * In this case, the maximum clock speed allowed on the RK pin is:
198 * - Peripheral clock divided by 2 if Receiver Frame Synchro is input
199 * - Peripheral clock divided by 3 if Receiver Frame Synchro is output
200 * In addition, the maximum clock speed allowed on the TK pin is:
201 * - Peripheral clock divided by 6 if Transmit Frame Synchro is input
202 * - Peripheral clock divided by 2 if Transmit Frame Synchro is output
203 *
204 * When the bit clock is output, limit the rate according to the
205 * SSC divider restrictions.
206 */
207static int atmel_ssc_hw_rule_rate(struct snd_pcm_hw_params *params,
208 struct snd_pcm_hw_rule *rule)
209{
210 struct atmel_ssc_info *ssc_p = rule->private;
211 struct ssc_device *ssc = ssc_p->ssc;
212 struct snd_interval *i = hw_param_interval(params, rule->var);
213 struct snd_interval t;
214 struct snd_ratnum r = {
215 .den_min = 1,
216 .den_max = 4095,
217 .den_step = 1,
218 };
219 unsigned int num = 0, den = 0;
220 int frame_size;
221 int mck_div = 2;
222 int ret;
223
224 frame_size = snd_soc_params_to_frame_size(params);
225 if (frame_size < 0)
226 return frame_size;
227
228 switch (ssc_p->daifmt & SND_SOC_DAIFMT_MASTER_MASK) {
229 case SND_SOC_DAIFMT_CBM_CFS:
230 if ((ssc_p->dir_mask & SSC_DIR_MASK_CAPTURE)
231 && ssc->clk_from_rk_pin)
232 /* Receiver Frame Synchro (i.e. capture)
233 * is output (format is _CFS) and the RK pin
234 * is used for input (format is _CBM_).
235 */
236 mck_div = 3;
237 break;
238
239 case SND_SOC_DAIFMT_CBM_CFM:
240 if ((ssc_p->dir_mask & SSC_DIR_MASK_PLAYBACK)
241 && !ssc->clk_from_rk_pin)
242 /* Transmit Frame Synchro (i.e. playback)
243 * is input (format is _CFM) and the TK pin
244 * is used for input (format _CBM_ but not
245 * using the RK pin).
246 */
247 mck_div = 6;
248 break;
249 }
250
251 switch (ssc_p->daifmt & SND_SOC_DAIFMT_MASTER_MASK) {
252 case SND_SOC_DAIFMT_CBS_CFS:
253 r.num = ssc_p->mck_rate / mck_div / frame_size;
254
255 ret = snd_interval_ratnum(i, 1, &r, &num, &den);
256 if (ret >= 0 && den && rule->var == SNDRV_PCM_HW_PARAM_RATE) {
257 params->rate_num = num;
258 params->rate_den = den;
259 }
260 break;
261
262 case SND_SOC_DAIFMT_CBM_CFS:
263 case SND_SOC_DAIFMT_CBM_CFM:
264 t.min = 8000;
265 t.max = ssc_p->mck_rate / mck_div / frame_size;
266 t.openmin = t.openmax = 0;
267 t.integer = 0;
268 ret = snd_interval_refine(i, &t);
269 break;
270
271 default:
272 ret = -EINVAL;
273 break;
274 }
275
276 return ret;
277}
190 278
191/*-------------------------------------------------------------------------*\ 279/*-------------------------------------------------------------------------*\
192 * DAI functions 280 * DAI functions
@@ -200,6 +288,7 @@ static int atmel_ssc_startup(struct snd_pcm_substream *substream,
200 struct atmel_ssc_info *ssc_p = &ssc_info[dai->id]; 288 struct atmel_ssc_info *ssc_p = &ssc_info[dai->id];
201 struct atmel_pcm_dma_params *dma_params; 289 struct atmel_pcm_dma_params *dma_params;
202 int dir, dir_mask; 290 int dir, dir_mask;
291 int ret;
203 292
204 pr_debug("atmel_ssc_startup: SSC_SR=0x%u\n", 293 pr_debug("atmel_ssc_startup: SSC_SR=0x%u\n",
205 ssc_readl(ssc_p->ssc->regs, SR)); 294 ssc_readl(ssc_p->ssc->regs, SR));
@@ -207,6 +296,7 @@ static int atmel_ssc_startup(struct snd_pcm_substream *substream,
207 /* Enable PMC peripheral clock for this SSC */ 296 /* Enable PMC peripheral clock for this SSC */
208 pr_debug("atmel_ssc_dai: Starting clock\n"); 297 pr_debug("atmel_ssc_dai: Starting clock\n");
209 clk_enable(ssc_p->ssc->clk); 298 clk_enable(ssc_p->ssc->clk);
299 ssc_p->mck_rate = clk_get_rate(ssc_p->ssc->clk);
210 300
211 /* Reset the SSC to keep it at a clean status */ 301 /* Reset the SSC to keep it at a clean status */
212 ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_SWRST)); 302 ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_SWRST));
@@ -219,6 +309,17 @@ static int atmel_ssc_startup(struct snd_pcm_substream *substream,
219 dir_mask = SSC_DIR_MASK_CAPTURE; 309 dir_mask = SSC_DIR_MASK_CAPTURE;
220 } 310 }
221 311
312 ret = snd_pcm_hw_rule_add(substream->runtime, 0,
313 SNDRV_PCM_HW_PARAM_RATE,
314 atmel_ssc_hw_rule_rate,
315 ssc_p,
316 SNDRV_PCM_HW_PARAM_FRAME_BITS,
317 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
318 if (ret < 0) {
319 dev_err(dai->dev, "Failed to specify rate rule: %d\n", ret);
320 return ret;
321 }
322
222 dma_params = &ssc_dma_params[dai->id][dir]; 323 dma_params = &ssc_dma_params[dai->id][dir];
223 dma_params->ssc = ssc_p->ssc; 324 dma_params->ssc = ssc_p->ssc;
224 dma_params->substream = substream; 325 dma_params->substream = substream;
@@ -783,8 +884,6 @@ static int atmel_ssc_resume(struct snd_soc_dai *cpu_dai)
783# define atmel_ssc_resume NULL 884# define atmel_ssc_resume NULL
784#endif /* CONFIG_PM */ 885#endif /* CONFIG_PM */
785 886
786#define ATMEL_SSC_RATES (SNDRV_PCM_RATE_8000_96000)
787
788#define ATMEL_SSC_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\ 887#define ATMEL_SSC_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
789 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) 888 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
790 889
@@ -804,12 +903,16 @@ static struct snd_soc_dai_driver atmel_ssc_dai = {
804 .playback = { 903 .playback = {
805 .channels_min = 1, 904 .channels_min = 1,
806 .channels_max = 2, 905 .channels_max = 2,
807 .rates = ATMEL_SSC_RATES, 906 .rates = SNDRV_PCM_RATE_CONTINUOUS,
907 .rate_min = 8000,
908 .rate_max = 384000,
808 .formats = ATMEL_SSC_FORMATS,}, 909 .formats = ATMEL_SSC_FORMATS,},
809 .capture = { 910 .capture = {
810 .channels_min = 1, 911 .channels_min = 1,
811 .channels_max = 2, 912 .channels_max = 2,
812 .rates = ATMEL_SSC_RATES, 913 .rates = SNDRV_PCM_RATE_CONTINUOUS,
914 .rate_min = 8000,
915 .rate_max = 384000,
813 .formats = ATMEL_SSC_FORMATS,}, 916 .formats = ATMEL_SSC_FORMATS,},
814 .ops = &atmel_ssc_dai_ops, 917 .ops = &atmel_ssc_dai_ops,
815}; 918};
diff --git a/sound/soc/atmel/atmel_ssc_dai.h b/sound/soc/atmel/atmel_ssc_dai.h
index b1f08d511495..80b153857a88 100644
--- a/sound/soc/atmel/atmel_ssc_dai.h
+++ b/sound/soc/atmel/atmel_ssc_dai.h
@@ -115,6 +115,7 @@ struct atmel_ssc_info {
115 unsigned short rcmr_period; 115 unsigned short rcmr_period;
116 struct atmel_pcm_dma_params *dma_params[2]; 116 struct atmel_pcm_dma_params *dma_params[2];
117 struct atmel_ssc_state ssc_state; 117 struct atmel_ssc_state ssc_state;
118 unsigned long mck_rate;
118}; 119};
119 120
120int atmel_ssc_set_audio(int ssc_id); 121int atmel_ssc_set_audio(int ssc_id);
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index ea9f0e31f9d4..0bddd929837f 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -141,7 +141,8 @@ config SND_SOC_ALL_CODECS
141 select SND_SOC_WM8770 if SPI_MASTER 141 select SND_SOC_WM8770 if SPI_MASTER
142 select SND_SOC_WM8776 if SND_SOC_I2C_AND_SPI 142 select SND_SOC_WM8776 if SND_SOC_I2C_AND_SPI
143 select SND_SOC_WM8782 143 select SND_SOC_WM8782
144 select SND_SOC_WM8804 if SND_SOC_I2C_AND_SPI 144 select SND_SOC_WM8804_I2C if I2C
145 select SND_SOC_WM8804_SPI if SPI_MASTER
145 select SND_SOC_WM8900 if I2C 146 select SND_SOC_WM8900 if I2C
146 select SND_SOC_WM8903 if I2C 147 select SND_SOC_WM8903 if I2C
147 select SND_SOC_WM8904 if I2C 148 select SND_SOC_WM8904 if I2C
@@ -744,8 +745,19 @@ config SND_SOC_WM8782
744 tristate 745 tristate
745 746
746config SND_SOC_WM8804 747config SND_SOC_WM8804
747 tristate "Wolfson Microelectronics WM8804 S/PDIF transceiver" 748 tristate
748 depends on SND_SOC_I2C_AND_SPI 749
750config SND_SOC_WM8804_I2C
751 tristate "Wolfson Microelectronics WM8804 S/PDIF transceiver I2C"
752 depends on I2C
753 select SND_SOC_WM8804
754 select REGMAP_I2C
755
756config SND_SOC_WM8804_SPI
757 tristate "Wolfson Microelectronics WM8804 S/PDIF transceiver SPI"
758 depends on SPI_MASTER
759 select SND_SOC_WM8804
760 select REGMAP_SPI
749 761
750config SND_SOC_WM8900 762config SND_SOC_WM8900
751 tristate 763 tristate
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 69b8666d187a..7acb6c174cb4 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -145,6 +145,8 @@ snd-soc-wm8770-objs := wm8770.o
145snd-soc-wm8776-objs := wm8776.o 145snd-soc-wm8776-objs := wm8776.o
146snd-soc-wm8782-objs := wm8782.o 146snd-soc-wm8782-objs := wm8782.o
147snd-soc-wm8804-objs := wm8804.o 147snd-soc-wm8804-objs := wm8804.o
148snd-soc-wm8804-i2c-objs := wm8804-i2c.o
149snd-soc-wm8804-spi-objs := wm8804-spi.o
148snd-soc-wm8900-objs := wm8900.o 150snd-soc-wm8900-objs := wm8900.o
149snd-soc-wm8903-objs := wm8903.o 151snd-soc-wm8903-objs := wm8903.o
150snd-soc-wm8904-objs := wm8904.o 152snd-soc-wm8904-objs := wm8904.o
@@ -323,6 +325,8 @@ obj-$(CONFIG_SND_SOC_WM8770) += snd-soc-wm8770.o
323obj-$(CONFIG_SND_SOC_WM8776) += snd-soc-wm8776.o 325obj-$(CONFIG_SND_SOC_WM8776) += snd-soc-wm8776.o
324obj-$(CONFIG_SND_SOC_WM8782) += snd-soc-wm8782.o 326obj-$(CONFIG_SND_SOC_WM8782) += snd-soc-wm8782.o
325obj-$(CONFIG_SND_SOC_WM8804) += snd-soc-wm8804.o 327obj-$(CONFIG_SND_SOC_WM8804) += snd-soc-wm8804.o
328obj-$(CONFIG_SND_SOC_WM8804_I2C) += snd-soc-wm8804-i2c.o
329obj-$(CONFIG_SND_SOC_WM8804_SPI) += snd-soc-wm8804-spi.o
326obj-$(CONFIG_SND_SOC_WM8900) += snd-soc-wm8900.o 330obj-$(CONFIG_SND_SOC_WM8900) += snd-soc-wm8900.o
327obj-$(CONFIG_SND_SOC_WM8903) += snd-soc-wm8903.o 331obj-$(CONFIG_SND_SOC_WM8903) += snd-soc-wm8903.o
328obj-$(CONFIG_SND_SOC_WM8904) += snd-soc-wm8904.o 332obj-$(CONFIG_SND_SOC_WM8904) += snd-soc-wm8904.o
diff --git a/sound/soc/codecs/adau1977.c b/sound/soc/codecs/adau1977.c
index 70ab35744aba..7ad8e156e2df 100644
--- a/sound/soc/codecs/adau1977.c
+++ b/sound/soc/codecs/adau1977.c
@@ -938,22 +938,15 @@ int adau1977_probe(struct device *dev, struct regmap *regmap,
938 adau1977->dvdd_reg = NULL; 938 adau1977->dvdd_reg = NULL;
939 } 939 }
940 940
941 adau1977->reset_gpio = devm_gpiod_get(dev, "reset"); 941 adau1977->reset_gpio = devm_gpiod_get_optional(dev, "reset",
942 if (IS_ERR(adau1977->reset_gpio)) { 942 GPIOD_OUT_LOW);
943 ret = PTR_ERR(adau1977->reset_gpio); 943 if (IS_ERR(adau1977->reset_gpio))
944 if (ret != -ENOENT && ret != -ENOSYS) 944 return PTR_ERR(adau1977->reset_gpio);
945 return PTR_ERR(adau1977->reset_gpio);
946 adau1977->reset_gpio = NULL;
947 }
948 945
949 dev_set_drvdata(dev, adau1977); 946 dev_set_drvdata(dev, adau1977);
950 947
951 if (adau1977->reset_gpio) { 948 if (adau1977->reset_gpio)
952 ret = gpiod_direction_output(adau1977->reset_gpio, 0);
953 if (ret)
954 return ret;
955 ndelay(100); 949 ndelay(100);
956 }
957 950
958 ret = adau1977_power_enable(adau1977); 951 ret = adau1977_power_enable(adau1977);
959 if (ret) 952 if (ret)
diff --git a/sound/soc/codecs/cs35l32.c b/sound/soc/codecs/cs35l32.c
index f2b8aad21274..60598b230341 100644
--- a/sound/soc/codecs/cs35l32.c
+++ b/sound/soc/codecs/cs35l32.c
@@ -437,20 +437,13 @@ static int cs35l32_i2c_probe(struct i2c_client *i2c_client,
437 } 437 }
438 438
439 /* Reset the Device */ 439 /* Reset the Device */
440 cs35l32->reset_gpio = devm_gpiod_get(&i2c_client->dev, 440 cs35l32->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev,
441 "reset-gpios"); 441 "reset", GPIOD_OUT_LOW);
442 if (IS_ERR(cs35l32->reset_gpio)) { 442 if (IS_ERR(cs35l32->reset_gpio))
443 ret = PTR_ERR(cs35l32->reset_gpio); 443 return PTR_ERR(cs35l32->reset_gpio);
444 if (ret != -ENOENT && ret != -ENOSYS) 444
445 return ret; 445 if (cs35l32->reset_gpio)
446
447 cs35l32->reset_gpio = NULL;
448 } else {
449 ret = gpiod_direction_output(cs35l32->reset_gpio, 0);
450 if (ret)
451 return ret;
452 gpiod_set_value_cansleep(cs35l32->reset_gpio, 1); 446 gpiod_set_value_cansleep(cs35l32->reset_gpio, 1);
453 }
454 447
455 /* initialize codec */ 448 /* initialize codec */
456 ret = regmap_read(cs35l32->regmap, CS35L32_DEVID_AB, &reg); 449 ret = regmap_read(cs35l32->regmap, CS35L32_DEVID_AB, &reg);
diff --git a/sound/soc/codecs/cs4265.c b/sound/soc/codecs/cs4265.c
index ce6086835ebd..cac48ddf3ba6 100644
--- a/sound/soc/codecs/cs4265.c
+++ b/sound/soc/codecs/cs4265.c
@@ -605,21 +605,14 @@ static int cs4265_i2c_probe(struct i2c_client *i2c_client,
605 return ret; 605 return ret;
606 } 606 }
607 607
608 cs4265->reset_gpio = devm_gpiod_get(&i2c_client->dev, 608 cs4265->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev,
609 "reset-gpios"); 609 "reset", GPIOD_OUT_LOW);
610 if (IS_ERR(cs4265->reset_gpio)) { 610 if (IS_ERR(cs4265->reset_gpio))
611 ret = PTR_ERR(cs4265->reset_gpio); 611 return PTR_ERR(cs4265->reset_gpio);
612 if (ret != -ENOENT && ret != -ENOSYS) 612
613 return ret; 613 if (cs4265->reset_gpio) {
614
615 cs4265->reset_gpio = NULL;
616 } else {
617 ret = gpiod_direction_output(cs4265->reset_gpio, 0);
618 if (ret)
619 return ret;
620 mdelay(1); 614 mdelay(1);
621 gpiod_set_value_cansleep(cs4265->reset_gpio, 1); 615 gpiod_set_value_cansleep(cs4265->reset_gpio, 1);
622
623 } 616 }
624 617
625 i2c_set_clientdata(i2c_client, cs4265); 618 i2c_set_clientdata(i2c_client, cs4265);
diff --git a/sound/soc/codecs/max98357a.c b/sound/soc/codecs/max98357a.c
index e9e6efbc21dd..bf3e933ee895 100644
--- a/sound/soc/codecs/max98357a.c
+++ b/sound/soc/codecs/max98357a.c
@@ -26,8 +26,6 @@
26#include <sound/soc-dai.h> 26#include <sound/soc-dai.h>
27#include <sound/soc-dapm.h> 27#include <sound/soc-dapm.h>
28 28
29#define DRV_NAME "max98357a"
30
31static int max98357a_daiops_trigger(struct snd_pcm_substream *substream, 29static int max98357a_daiops_trigger(struct snd_pcm_substream *substream,
32 int cmd, struct snd_soc_dai *dai) 30 int cmd, struct snd_soc_dai *dai)
33{ 31{
@@ -87,9 +85,9 @@ static struct snd_soc_dai_ops max98357a_dai_ops = {
87}; 85};
88 86
89static struct snd_soc_dai_driver max98357a_dai_driver = { 87static struct snd_soc_dai_driver max98357a_dai_driver = {
90 .name = DRV_NAME, 88 .name = "HiFi",
91 .playback = { 89 .playback = {
92 .stream_name = DRV_NAME "-playback", 90 .stream_name = "HiFi Playback",
93 .formats = SNDRV_PCM_FMTBIT_S16 | 91 .formats = SNDRV_PCM_FMTBIT_S16 |
94 SNDRV_PCM_FMTBIT_S24 | 92 SNDRV_PCM_FMTBIT_S24 |
95 SNDRV_PCM_FMTBIT_S32, 93 SNDRV_PCM_FMTBIT_S32,
@@ -127,7 +125,7 @@ static int max98357a_platform_remove(struct platform_device *pdev)
127 125
128#ifdef CONFIG_OF 126#ifdef CONFIG_OF
129static const struct of_device_id max98357a_device_id[] = { 127static const struct of_device_id max98357a_device_id[] = {
130 { .compatible = "maxim," DRV_NAME, }, 128 { .compatible = "maxim,max98357a" },
131 {} 129 {}
132}; 130};
133MODULE_DEVICE_TABLE(of, max98357a_device_id); 131MODULE_DEVICE_TABLE(of, max98357a_device_id);
@@ -135,7 +133,7 @@ MODULE_DEVICE_TABLE(of, max98357a_device_id);
135 133
136static struct platform_driver max98357a_platform_driver = { 134static struct platform_driver max98357a_platform_driver = {
137 .driver = { 135 .driver = {
138 .name = DRV_NAME, 136 .name = "max98357a",
139 .of_match_table = of_match_ptr(max98357a_device_id), 137 .of_match_table = of_match_ptr(max98357a_device_id),
140 }, 138 },
141 .probe = max98357a_platform_probe, 139 .probe = max98357a_platform_probe,
@@ -145,4 +143,3 @@ module_platform_driver(max98357a_platform_driver);
145 143
146MODULE_DESCRIPTION("Maxim MAX98357A Codec Driver"); 144MODULE_DESCRIPTION("Maxim MAX98357A Codec Driver");
147MODULE_LICENSE("GPL v2"); 145MODULE_LICENSE("GPL v2");
148MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c
index 9974f201a08f..4b5f1fe9be97 100644
--- a/sound/soc/codecs/pcm512x.c
+++ b/sound/soc/codecs/pcm512x.c
@@ -54,6 +54,9 @@ struct pcm512x_priv {
54 int pll_d; 54 int pll_d;
55 int pll_p; 55 int pll_p;
56 unsigned long real_pll; 56 unsigned long real_pll;
57 unsigned long overclock_pll;
58 unsigned long overclock_dac;
59 unsigned long overclock_dsp;
57}; 60};
58 61
59/* 62/*
@@ -224,6 +227,90 @@ static bool pcm512x_volatile(struct device *dev, unsigned int reg)
224 } 227 }
225} 228}
226 229
230static int pcm512x_overclock_pll_get(struct snd_kcontrol *kcontrol,
231 struct snd_ctl_elem_value *ucontrol)
232{
233 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
234 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
235
236 ucontrol->value.integer.value[0] = pcm512x->overclock_pll;
237 return 0;
238}
239
240static int pcm512x_overclock_pll_put(struct snd_kcontrol *kcontrol,
241 struct snd_ctl_elem_value *ucontrol)
242{
243 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
244 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
245
246 switch (codec->dapm.bias_level) {
247 case SND_SOC_BIAS_OFF:
248 case SND_SOC_BIAS_STANDBY:
249 break;
250 default:
251 return -EBUSY;
252 }
253
254 pcm512x->overclock_pll = ucontrol->value.integer.value[0];
255 return 0;
256}
257
258static int pcm512x_overclock_dsp_get(struct snd_kcontrol *kcontrol,
259 struct snd_ctl_elem_value *ucontrol)
260{
261 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
262 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
263
264 ucontrol->value.integer.value[0] = pcm512x->overclock_dsp;
265 return 0;
266}
267
268static int pcm512x_overclock_dsp_put(struct snd_kcontrol *kcontrol,
269 struct snd_ctl_elem_value *ucontrol)
270{
271 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
272 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
273
274 switch (codec->dapm.bias_level) {
275 case SND_SOC_BIAS_OFF:
276 case SND_SOC_BIAS_STANDBY:
277 break;
278 default:
279 return -EBUSY;
280 }
281
282 pcm512x->overclock_dsp = ucontrol->value.integer.value[0];
283 return 0;
284}
285
286static int pcm512x_overclock_dac_get(struct snd_kcontrol *kcontrol,
287 struct snd_ctl_elem_value *ucontrol)
288{
289 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
290 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
291
292 ucontrol->value.integer.value[0] = pcm512x->overclock_dac;
293 return 0;
294}
295
296static int pcm512x_overclock_dac_put(struct snd_kcontrol *kcontrol,
297 struct snd_ctl_elem_value *ucontrol)
298{
299 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
300 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
301
302 switch (codec->dapm.bias_level) {
303 case SND_SOC_BIAS_OFF:
304 case SND_SOC_BIAS_STANDBY:
305 break;
306 default:
307 return -EBUSY;
308 }
309
310 pcm512x->overclock_dac = ucontrol->value.integer.value[0];
311 return 0;
312}
313
227static const DECLARE_TLV_DB_SCALE(digital_tlv, -10350, 50, 1); 314static const DECLARE_TLV_DB_SCALE(digital_tlv, -10350, 50, 1);
228static const DECLARE_TLV_DB_SCALE(analog_tlv, -600, 600, 0); 315static const DECLARE_TLV_DB_SCALE(analog_tlv, -600, 600, 0);
229static const DECLARE_TLV_DB_SCALE(boost_tlv, 0, 80, 0); 316static const DECLARE_TLV_DB_SCALE(boost_tlv, 0, 80, 0);
@@ -328,6 +415,13 @@ SOC_ENUM("Volume Ramp Up Rate", pcm512x_vnuf),
328SOC_ENUM("Volume Ramp Up Step", pcm512x_vnus), 415SOC_ENUM("Volume Ramp Up Step", pcm512x_vnus),
329SOC_ENUM("Volume Ramp Down Emergency Rate", pcm512x_vedf), 416SOC_ENUM("Volume Ramp Down Emergency Rate", pcm512x_vedf),
330SOC_ENUM("Volume Ramp Down Emergency Step", pcm512x_veds), 417SOC_ENUM("Volume Ramp Down Emergency Step", pcm512x_veds),
418
419SOC_SINGLE_EXT("Max Overclock PLL", SND_SOC_NOPM, 0, 20, 0,
420 pcm512x_overclock_pll_get, pcm512x_overclock_pll_put),
421SOC_SINGLE_EXT("Max Overclock DSP", SND_SOC_NOPM, 0, 40, 0,
422 pcm512x_overclock_dsp_get, pcm512x_overclock_dsp_put),
423SOC_SINGLE_EXT("Max Overclock DAC", SND_SOC_NOPM, 0, 40, 0,
424 pcm512x_overclock_dac_get, pcm512x_overclock_dac_put),
331}; 425};
332 426
333static const struct snd_soc_dapm_widget pcm512x_dapm_widgets[] = { 427static const struct snd_soc_dapm_widget pcm512x_dapm_widgets[] = {
@@ -346,6 +440,45 @@ static const struct snd_soc_dapm_route pcm512x_dapm_routes[] = {
346 { "OUTR", NULL, "DACR" }, 440 { "OUTR", NULL, "DACR" },
347}; 441};
348 442
443static unsigned long pcm512x_pll_max(struct pcm512x_priv *pcm512x)
444{
445 return 25000000 + 25000000 * pcm512x->overclock_pll / 100;
446}
447
448static unsigned long pcm512x_dsp_max(struct pcm512x_priv *pcm512x)
449{
450 return 50000000 + 50000000 * pcm512x->overclock_dsp / 100;
451}
452
453static unsigned long pcm512x_dac_max(struct pcm512x_priv *pcm512x,
454 unsigned long rate)
455{
456 return rate + rate * pcm512x->overclock_dac / 100;
457}
458
459static unsigned long pcm512x_sck_max(struct pcm512x_priv *pcm512x)
460{
461 if (!pcm512x->pll_out)
462 return 25000000;
463 return pcm512x_pll_max(pcm512x);
464}
465
466static unsigned long pcm512x_ncp_target(struct pcm512x_priv *pcm512x,
467 unsigned long dac_rate)
468{
469 /*
470 * If the DAC is not actually overclocked, use the good old
471 * NCP target rate...
472 */
473 if (dac_rate <= 6144000)
474 return 1536000;
475 /*
476 * ...but if the DAC is in fact overclocked, bump the NCP target
477 * rate to get the recommended dividers even when overclocking.
478 */
479 return pcm512x_dac_max(pcm512x, 1536000);
480}
481
349static const u32 pcm512x_dai_rates[] = { 482static const u32 pcm512x_dai_rates[] = {
350 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 483 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000,
351 88200, 96000, 176400, 192000, 384000, 484 88200, 96000, 176400, 192000, 384000,
@@ -359,6 +492,7 @@ static const struct snd_pcm_hw_constraint_list constraints_slave = {
359static int pcm512x_hw_rule_rate(struct snd_pcm_hw_params *params, 492static int pcm512x_hw_rule_rate(struct snd_pcm_hw_params *params,
360 struct snd_pcm_hw_rule *rule) 493 struct snd_pcm_hw_rule *rule)
361{ 494{
495 struct pcm512x_priv *pcm512x = rule->private;
362 struct snd_interval ranges[2]; 496 struct snd_interval ranges[2];
363 int frame_size; 497 int frame_size;
364 498
@@ -377,7 +511,7 @@ static int pcm512x_hw_rule_rate(struct snd_pcm_hw_params *params,
377 */ 511 */
378 memset(ranges, 0, sizeof(ranges)); 512 memset(ranges, 0, sizeof(ranges));
379 ranges[0].min = 8000; 513 ranges[0].min = 8000;
380 ranges[0].max = 25000000 / frame_size / 2; 514 ranges[0].max = pcm512x_sck_max(pcm512x) / frame_size / 2;
381 ranges[1].min = DIV_ROUND_UP(16000000, frame_size); 515 ranges[1].min = DIV_ROUND_UP(16000000, frame_size);
382 ranges[1].max = 384000; 516 ranges[1].max = 384000;
383 break; 517 break;
@@ -408,7 +542,7 @@ static int pcm512x_dai_startup_master(struct snd_pcm_substream *substream,
408 return snd_pcm_hw_rule_add(substream->runtime, 0, 542 return snd_pcm_hw_rule_add(substream->runtime, 0,
409 SNDRV_PCM_HW_PARAM_RATE, 543 SNDRV_PCM_HW_PARAM_RATE,
410 pcm512x_hw_rule_rate, 544 pcm512x_hw_rule_rate,
411 NULL, 545 pcm512x,
412 SNDRV_PCM_HW_PARAM_FRAME_BITS, 546 SNDRV_PCM_HW_PARAM_FRAME_BITS,
413 SNDRV_PCM_HW_PARAM_CHANNELS, -1); 547 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
414 548
@@ -517,6 +651,8 @@ static unsigned long pcm512x_find_sck(struct snd_soc_dai *dai,
517 unsigned long bclk_rate) 651 unsigned long bclk_rate)
518{ 652{
519 struct device *dev = dai->dev; 653 struct device *dev = dai->dev;
654 struct snd_soc_codec *codec = dai->codec;
655 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
520 unsigned long sck_rate; 656 unsigned long sck_rate;
521 int pow2; 657 int pow2;
522 658
@@ -527,9 +663,10 @@ static unsigned long pcm512x_find_sck(struct snd_soc_dai *dai,
527 * as many factors of 2 as possible, as that makes it easier 663 * as many factors of 2 as possible, as that makes it easier
528 * to find a fast DAC rate 664 * to find a fast DAC rate
529 */ 665 */
530 pow2 = 1 << fls((25000000 - 16000000) / bclk_rate); 666 pow2 = 1 << fls((pcm512x_pll_max(pcm512x) - 16000000) / bclk_rate);
531 for (; pow2; pow2 >>= 1) { 667 for (; pow2; pow2 >>= 1) {
532 sck_rate = rounddown(25000000, bclk_rate * pow2); 668 sck_rate = rounddown(pcm512x_pll_max(pcm512x),
669 bclk_rate * pow2);
533 if (sck_rate >= 16000000) 670 if (sck_rate >= 16000000)
534 break; 671 break;
535 } 672 }
@@ -678,7 +815,7 @@ static unsigned long pcm512x_pllin_dac_rate(struct snd_soc_dai *dai,
678 return 0; /* futile, quit early */ 815 return 0; /* futile, quit early */
679 816
680 /* run DAC no faster than 6144000 Hz */ 817 /* run DAC no faster than 6144000 Hz */
681 for (dac_rate = rounddown(6144000, osr_rate); 818 for (dac_rate = rounddown(pcm512x_dac_max(pcm512x, 6144000), osr_rate);
682 dac_rate; 819 dac_rate;
683 dac_rate -= osr_rate) { 820 dac_rate -= osr_rate) {
684 821
@@ -805,7 +942,7 @@ static int pcm512x_set_dividers(struct snd_soc_dai *dai,
805 osr_rate = 16 * sample_rate; 942 osr_rate = 16 * sample_rate;
806 943
807 /* run DSP no faster than 50 MHz */ 944 /* run DSP no faster than 50 MHz */
808 dsp_div = mck_rate > 50000000 ? 2 : 1; 945 dsp_div = mck_rate > pcm512x_dsp_max(pcm512x) ? 2 : 1;
809 946
810 dac_rate = pcm512x_pllin_dac_rate(dai, osr_rate, pllin_rate); 947 dac_rate = pcm512x_pllin_dac_rate(dai, osr_rate, pllin_rate);
811 if (dac_rate) { 948 if (dac_rate) {
@@ -836,7 +973,8 @@ static int pcm512x_set_dividers(struct snd_soc_dai *dai,
836 dacsrc_rate = pllin_rate; 973 dacsrc_rate = pllin_rate;
837 } else { 974 } else {
838 /* run DAC no faster than 6144000 Hz */ 975 /* run DAC no faster than 6144000 Hz */
839 unsigned long dac_mul = 6144000 / osr_rate; 976 unsigned long dac_mul = pcm512x_dac_max(pcm512x, 6144000)
977 / osr_rate;
840 unsigned long sck_mul = sck_rate / osr_rate; 978 unsigned long sck_mul = sck_rate / osr_rate;
841 979
842 for (; dac_mul; dac_mul--) { 980 for (; dac_mul; dac_mul--) {
@@ -863,28 +1001,30 @@ static int pcm512x_set_dividers(struct snd_soc_dai *dai,
863 dacsrc_rate = sck_rate; 1001 dacsrc_rate = sck_rate;
864 } 1002 }
865 1003
1004 osr_div = DIV_ROUND_CLOSEST(dac_rate, osr_rate);
1005 if (osr_div > 128) {
1006 dev_err(dev, "Failed to find OSR divider\n");
1007 return -EINVAL;
1008 }
1009
866 dac_div = DIV_ROUND_CLOSEST(dacsrc_rate, dac_rate); 1010 dac_div = DIV_ROUND_CLOSEST(dacsrc_rate, dac_rate);
867 if (dac_div > 128) { 1011 if (dac_div > 128) {
868 dev_err(dev, "Failed to find DAC divider\n"); 1012 dev_err(dev, "Failed to find DAC divider\n");
869 return -EINVAL; 1013 return -EINVAL;
870 } 1014 }
1015 dac_rate = dacsrc_rate / dac_div;
871 1016
872 ncp_div = DIV_ROUND_CLOSEST(dacsrc_rate / dac_div, 1536000); 1017 ncp_div = DIV_ROUND_CLOSEST(dac_rate,
873 if (ncp_div > 128 || dacsrc_rate / dac_div / ncp_div > 2048000) { 1018 pcm512x_ncp_target(pcm512x, dac_rate));
1019 if (ncp_div > 128 || dac_rate / ncp_div > 2048000) {
874 /* run NCP no faster than 2048000 Hz, but why? */ 1020 /* run NCP no faster than 2048000 Hz, but why? */
875 ncp_div = DIV_ROUND_UP(dacsrc_rate / dac_div, 2048000); 1021 ncp_div = DIV_ROUND_UP(dac_rate, 2048000);
876 if (ncp_div > 128) { 1022 if (ncp_div > 128) {
877 dev_err(dev, "Failed to find NCP divider\n"); 1023 dev_err(dev, "Failed to find NCP divider\n");
878 return -EINVAL; 1024 return -EINVAL;
879 } 1025 }
880 } 1026 }
881 1027
882 osr_div = DIV_ROUND_CLOSEST(dac_rate, osr_rate);
883 if (osr_div > 128) {
884 dev_err(dev, "Failed to find OSR divider\n");
885 return -EINVAL;
886 }
887
888 idac = mck_rate / (dsp_div * sample_rate); 1028 idac = mck_rate / (dsp_div * sample_rate);
889 1029
890 ret = regmap_write(pcm512x->regmap, PCM512x_DSP_CLKDIV, dsp_div - 1); 1030 ret = regmap_write(pcm512x->regmap, PCM512x_DSP_CLKDIV, dsp_div - 1);
@@ -937,11 +1077,11 @@ static int pcm512x_set_dividers(struct snd_soc_dai *dai,
937 return ret; 1077 return ret;
938 } 1078 }
939 1079
940 if (sample_rate <= 48000) 1080 if (sample_rate <= pcm512x_dac_max(pcm512x, 48000))
941 fssp = PCM512x_FSSP_48KHZ; 1081 fssp = PCM512x_FSSP_48KHZ;
942 else if (sample_rate <= 96000) 1082 else if (sample_rate <= pcm512x_dac_max(pcm512x, 96000))
943 fssp = PCM512x_FSSP_96KHZ; 1083 fssp = PCM512x_FSSP_96KHZ;
944 else if (sample_rate <= 192000) 1084 else if (sample_rate <= pcm512x_dac_max(pcm512x, 192000))
945 fssp = PCM512x_FSSP_192KHZ; 1085 fssp = PCM512x_FSSP_192KHZ;
946 else 1086 else
947 fssp = PCM512x_FSSP_384KHZ; 1087 fssp = PCM512x_FSSP_384KHZ;
diff --git a/sound/soc/codecs/rt286.c b/sound/soc/codecs/rt286.c
index 9b541e52da8c..826037090c83 100644
--- a/sound/soc/codecs/rt286.c
+++ b/sound/soc/codecs/rt286.c
@@ -395,9 +395,20 @@ int rt286_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack)
395 395
396 rt286->jack = jack; 396 rt286->jack = jack;
397 397
398 /* Send an initial empty report */ 398 if (jack) {
399 snd_soc_jack_report(rt286->jack, 0, 399 /* enable IRQ */
400 SND_JACK_MICROPHONE | SND_JACK_HEADPHONE); 400 if (rt286->jack->status | SND_JACK_HEADPHONE)
401 snd_soc_dapm_force_enable_pin(&codec->dapm, "LDO1");
402 regmap_update_bits(rt286->regmap, RT286_IRQ_CTRL, 0x2, 0x2);
403 /* Send an initial empty report */
404 snd_soc_jack_report(rt286->jack, rt286->jack->status,
405 SND_JACK_MICROPHONE | SND_JACK_HEADPHONE);
406 } else {
407 /* disable IRQ */
408 regmap_update_bits(rt286->regmap, RT286_IRQ_CTRL, 0x2, 0x0);
409 snd_soc_dapm_disable_pin(&codec->dapm, "LDO1");
410 }
411 snd_soc_dapm_sync(&codec->dapm);
401 412
402 return 0; 413 return 0;
403} 414}
diff --git a/sound/soc/codecs/rt5670.h b/sound/soc/codecs/rt5670.h
index 21f8e18c13c4..0a67adbcfbc3 100644
--- a/sound/soc/codecs/rt5670.h
+++ b/sound/soc/codecs/rt5670.h
@@ -1950,17 +1950,20 @@ enum {
1950}; 1950};
1951 1951
1952enum { 1952enum {
1953 RT5670_DMIC1_DISABLED,
1953 RT5670_DMIC_DATA_GPIO6, 1954 RT5670_DMIC_DATA_GPIO6,
1954 RT5670_DMIC_DATA_IN2P, 1955 RT5670_DMIC_DATA_IN2P,
1955 RT5670_DMIC_DATA_GPIO7, 1956 RT5670_DMIC_DATA_GPIO7,
1956}; 1957};
1957 1958
1958enum { 1959enum {
1960 RT5670_DMIC2_DISABLED,
1959 RT5670_DMIC_DATA_GPIO8, 1961 RT5670_DMIC_DATA_GPIO8,
1960 RT5670_DMIC_DATA_IN3N, 1962 RT5670_DMIC_DATA_IN3N,
1961}; 1963};
1962 1964
1963enum { 1965enum {
1966 RT5670_DMIC3_DISABLED,
1964 RT5670_DMIC_DATA_GPIO9, 1967 RT5670_DMIC_DATA_GPIO9,
1965 RT5670_DMIC_DATA_GPIO10, 1968 RT5670_DMIC_DATA_GPIO10,
1966 RT5670_DMIC_DATA_GPIO5, 1969 RT5670_DMIC_DATA_GPIO5,
diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c
index fb9c20eace3f..c2a6e4091357 100644
--- a/sound/soc/codecs/rt5677.c
+++ b/sound/soc/codecs/rt5677.c
@@ -718,11 +718,24 @@ static int rt5677_set_dsp_vad(struct snd_soc_codec *codec, bool on)
718 RT5677_LDO1_SEL_MASK, 0x0); 718 RT5677_LDO1_SEL_MASK, 0x0);
719 regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG2, 719 regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG2,
720 RT5677_PWR_LDO1, RT5677_PWR_LDO1); 720 RT5677_PWR_LDO1, RT5677_PWR_LDO1);
721 regmap_update_bits(rt5677->regmap, RT5677_GLB_CLK1, 721 switch (rt5677->type) {
722 RT5677_MCLK_SRC_MASK, RT5677_MCLK2_SRC); 722 case RT5677:
723 regmap_update_bits(rt5677->regmap, RT5677_GLB_CLK2, 723 regmap_update_bits(rt5677->regmap, RT5677_GLB_CLK1,
724 RT5677_PLL2_PR_SRC_MASK | RT5677_DSP_CLK_SRC_MASK, 724 RT5677_MCLK_SRC_MASK, RT5677_MCLK2_SRC);
725 RT5677_PLL2_PR_SRC_MCLK2 | RT5677_DSP_CLK_SRC_BYPASS); 725 regmap_update_bits(rt5677->regmap, RT5677_GLB_CLK2,
726 RT5677_PLL2_PR_SRC_MASK |
727 RT5677_DSP_CLK_SRC_MASK,
728 RT5677_PLL2_PR_SRC_MCLK2 |
729 RT5677_DSP_CLK_SRC_BYPASS);
730 break;
731 case RT5676:
732 regmap_update_bits(rt5677->regmap, RT5677_GLB_CLK2,
733 RT5677_DSP_CLK_SRC_MASK,
734 RT5677_DSP_CLK_SRC_BYPASS);
735 break;
736 default:
737 break;
738 }
726 regmap_write(rt5677->regmap, RT5677_PWR_DSP2, 0x07ff); 739 regmap_write(rt5677->regmap, RT5677_PWR_DSP2, 0x07ff);
727 regmap_write(rt5677->regmap, RT5677_PWR_DSP1, 0x07fd); 740 regmap_write(rt5677->regmap, RT5677_PWR_DSP1, 0x07fd);
728 rt5677_set_dsp_mode(codec, true); 741 rt5677_set_dsp_mode(codec, true);
@@ -4500,10 +4513,10 @@ static int rt5677_suspend(struct snd_soc_codec *codec)
4500 if (!rt5677->dsp_vad_en) { 4513 if (!rt5677->dsp_vad_en) {
4501 regcache_cache_only(rt5677->regmap, true); 4514 regcache_cache_only(rt5677->regmap, true);
4502 regcache_mark_dirty(rt5677->regmap); 4515 regcache_mark_dirty(rt5677->regmap);
4503 }
4504 4516
4505 if (gpio_is_valid(rt5677->pow_ldo2)) 4517 if (gpio_is_valid(rt5677->pow_ldo2))
4506 gpio_set_value_cansleep(rt5677->pow_ldo2, 0); 4518 gpio_set_value_cansleep(rt5677->pow_ldo2, 0);
4519 }
4507 4520
4508 return 0; 4521 return 0;
4509} 4522}
@@ -4512,12 +4525,12 @@ static int rt5677_resume(struct snd_soc_codec *codec)
4512{ 4525{
4513 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 4526 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
4514 4527
4515 if (gpio_is_valid(rt5677->pow_ldo2)) {
4516 gpio_set_value_cansleep(rt5677->pow_ldo2, 1);
4517 msleep(10);
4518 }
4519
4520 if (!rt5677->dsp_vad_en) { 4528 if (!rt5677->dsp_vad_en) {
4529 if (gpio_is_valid(rt5677->pow_ldo2)) {
4530 gpio_set_value_cansleep(rt5677->pow_ldo2, 1);
4531 msleep(10);
4532 }
4533
4521 regcache_cache_only(rt5677->regmap, false); 4534 regcache_cache_only(rt5677->regmap, false);
4522 regcache_sync(rt5677->regmap); 4535 regcache_sync(rt5677->regmap);
4523 } 4536 }
@@ -4733,7 +4746,8 @@ static const struct regmap_config rt5677_regmap = {
4733}; 4746};
4734 4747
4735static const struct i2c_device_id rt5677_i2c_id[] = { 4748static const struct i2c_device_id rt5677_i2c_id[] = {
4736 { "rt5677", 0 }, 4749 { "rt5677", RT5677 },
4750 { "rt5676", RT5676 },
4737 { } 4751 { }
4738}; 4752};
4739MODULE_DEVICE_TABLE(i2c, rt5677_i2c_id); 4753MODULE_DEVICE_TABLE(i2c, rt5677_i2c_id);
@@ -4850,6 +4864,8 @@ static int rt5677_i2c_probe(struct i2c_client *i2c,
4850 4864
4851 i2c_set_clientdata(i2c, rt5677); 4865 i2c_set_clientdata(i2c, rt5677);
4852 4866
4867 rt5677->type = id->driver_data;
4868
4853 if (pdata) 4869 if (pdata)
4854 rt5677->pdata = *pdata; 4870 rt5677->pdata = *pdata;
4855 4871
diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h
index c0a625f290cc..07df96b43f59 100644
--- a/sound/soc/codecs/rt5677.h
+++ b/sound/soc/codecs/rt5677.h
@@ -1665,6 +1665,11 @@ enum {
1665 RT5677_IRQ_JD3, 1665 RT5677_IRQ_JD3,
1666}; 1666};
1667 1667
1668enum rt5677_type {
1669 RT5677,
1670 RT5676,
1671};
1672
1668struct rt5677_priv { 1673struct rt5677_priv {
1669 struct snd_soc_codec *codec; 1674 struct snd_soc_codec *codec;
1670 struct rt5677_platform_data pdata; 1675 struct rt5677_platform_data pdata;
@@ -1681,6 +1686,7 @@ struct rt5677_priv {
1681 int pll_in; 1686 int pll_in;
1682 int pll_out; 1687 int pll_out;
1683 int pow_ldo2; /* POW_LDO2 pin */ 1688 int pow_ldo2; /* POW_LDO2 pin */
1689 enum rt5677_type type;
1684#ifdef CONFIG_GPIOLIB 1690#ifdef CONFIG_GPIOLIB
1685 struct gpio_chip gpio_chip; 1691 struct gpio_chip gpio_chip;
1686#endif 1692#endif
diff --git a/sound/soc/codecs/sn95031.c b/sound/soc/codecs/sn95031.c
index 82095d6cd070..7947c0ebb1ed 100644
--- a/sound/soc/codecs/sn95031.c
+++ b/sound/soc/codecs/sn95031.c
@@ -783,19 +783,21 @@ static inline void sn95031_enable_jack_btn(struct snd_soc_codec *codec)
783 snd_soc_write(codec, SN95031_BTNCTRL2, 0x01); 783 snd_soc_write(codec, SN95031_BTNCTRL2, 0x01);
784} 784}
785 785
786static int sn95031_get_headset_state(struct snd_soc_jack *mfld_jack) 786static int sn95031_get_headset_state(struct snd_soc_codec *codec,
787 struct snd_soc_jack *mfld_jack)
787{ 788{
788 int micbias = sn95031_get_mic_bias(mfld_jack->codec); 789 int micbias = sn95031_get_mic_bias(codec);
789 790
790 int jack_type = snd_soc_jack_get_type(mfld_jack, micbias); 791 int jack_type = snd_soc_jack_get_type(mfld_jack, micbias);
791 792
792 pr_debug("jack type detected = %d\n", jack_type); 793 pr_debug("jack type detected = %d\n", jack_type);
793 if (jack_type == SND_JACK_HEADSET) 794 if (jack_type == SND_JACK_HEADSET)
794 sn95031_enable_jack_btn(mfld_jack->codec); 795 sn95031_enable_jack_btn(codec);
795 return jack_type; 796 return jack_type;
796} 797}
797 798
798void sn95031_jack_detection(struct mfld_jack_data *jack_data) 799void sn95031_jack_detection(struct snd_soc_codec *codec,
800 struct mfld_jack_data *jack_data)
799{ 801{
800 unsigned int status; 802 unsigned int status;
801 unsigned int mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_HEADSET; 803 unsigned int mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_HEADSET;
@@ -809,11 +811,11 @@ void sn95031_jack_detection(struct mfld_jack_data *jack_data)
809 status = SND_JACK_HEADSET | SND_JACK_BTN_1; 811 status = SND_JACK_HEADSET | SND_JACK_BTN_1;
810 } else if (jack_data->intr_id & 0x4) { 812 } else if (jack_data->intr_id & 0x4) {
811 pr_debug("headset or headphones inserted\n"); 813 pr_debug("headset or headphones inserted\n");
812 status = sn95031_get_headset_state(jack_data->mfld_jack); 814 status = sn95031_get_headset_state(codec, jack_data->mfld_jack);
813 } else if (jack_data->intr_id & 0x8) { 815 } else if (jack_data->intr_id & 0x8) {
814 pr_debug("headset or headphones removed\n"); 816 pr_debug("headset or headphones removed\n");
815 status = 0; 817 status = 0;
816 sn95031_disable_jack_btn(jack_data->mfld_jack->codec); 818 sn95031_disable_jack_btn(codec);
817 } else { 819 } else {
818 pr_err("unidentified interrupt\n"); 820 pr_err("unidentified interrupt\n");
819 return; 821 return;
diff --git a/sound/soc/codecs/sn95031.h b/sound/soc/codecs/sn95031.h
index 20376d234fb8..7651fe4e6a45 100644
--- a/sound/soc/codecs/sn95031.h
+++ b/sound/soc/codecs/sn95031.h
@@ -127,6 +127,7 @@ struct mfld_jack_data {
127 struct snd_soc_jack *mfld_jack; 127 struct snd_soc_jack *mfld_jack;
128}; 128};
129 129
130extern void sn95031_jack_detection(struct mfld_jack_data *jack_data); 130extern void sn95031_jack_detection(struct snd_soc_codec *codec,
131 struct mfld_jack_data *jack_data);
131 132
132#endif 133#endif
diff --git a/sound/soc/codecs/sta350.c b/sound/soc/codecs/sta350.c
index bda2ee18769e..669e3228241e 100644
--- a/sound/soc/codecs/sta350.c
+++ b/sound/soc/codecs/sta350.c
@@ -1213,27 +1213,15 @@ static int sta350_i2c_probe(struct i2c_client *i2c,
1213#endif 1213#endif
1214 1214
1215 /* GPIOs */ 1215 /* GPIOs */
1216 sta350->gpiod_nreset = devm_gpiod_get(dev, "reset"); 1216 sta350->gpiod_nreset = devm_gpiod_get_optional(dev, "reset",
1217 if (IS_ERR(sta350->gpiod_nreset)) { 1217 GPIOD_OUT_LOW);
1218 ret = PTR_ERR(sta350->gpiod_nreset); 1218 if (IS_ERR(sta350->gpiod_nreset))
1219 if (ret != -ENOENT && ret != -ENOSYS) 1219 return PTR_ERR(sta350->gpiod_nreset);
1220 return ret; 1220
1221 1221 sta350->gpiod_power_down = devm_gpiod_get(dev, "power-down",
1222 sta350->gpiod_nreset = NULL; 1222 GPIOD_OUT_LOW);
1223 } else { 1223 if (IS_ERR(sta350->gpiod_power_down))
1224 gpiod_direction_output(sta350->gpiod_nreset, 0); 1224 return PTR_ERR(sta350->gpiod_power_down);
1225 }
1226
1227 sta350->gpiod_power_down = devm_gpiod_get(dev, "power-down");
1228 if (IS_ERR(sta350->gpiod_power_down)) {
1229 ret = PTR_ERR(sta350->gpiod_power_down);
1230 if (ret != -ENOENT && ret != -ENOSYS)
1231 return ret;
1232
1233 sta350->gpiod_power_down = NULL;
1234 } else {
1235 gpiod_direction_output(sta350->gpiod_power_down, 0);
1236 }
1237 1225
1238 /* regulators */ 1226 /* regulators */
1239 for (i = 0; i < ARRAY_SIZE(sta350->supplies); i++) 1227 for (i = 0; i < ARRAY_SIZE(sta350->supplies); i++)
diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index ae23acdd2708..dfb4ff5cc9ea 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -485,16 +485,9 @@ static int tas2552_probe(struct i2c_client *client,
485 if (data == NULL) 485 if (data == NULL)
486 return -ENOMEM; 486 return -ENOMEM;
487 487
488 data->enable_gpio = devm_gpiod_get(dev, "enable"); 488 data->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW);
489 if (IS_ERR(data->enable_gpio)) { 489 if (IS_ERR(data->enable_gpio))
490 ret = PTR_ERR(data->enable_gpio); 490 return PTR_ERR(data->enable_gpio);
491 if (ret != -ENOENT && ret != -ENOSYS)
492 return ret;
493
494 data->enable_gpio = NULL;
495 } else {
496 gpiod_direction_output(data->enable_gpio, 0);
497 }
498 491
499 data->tas2552_client = client; 492 data->tas2552_client = client;
500 data->regmap = devm_regmap_init_i2c(client, &tas2552_regmap_config); 493 data->regmap = devm_regmap_init_i2c(client, &tas2552_regmap_config);
diff --git a/sound/soc/codecs/wm8804-i2c.c b/sound/soc/codecs/wm8804-i2c.c
new file mode 100644
index 000000000000..5bd4af2b4059
--- /dev/null
+++ b/sound/soc/codecs/wm8804-i2c.c
@@ -0,0 +1,64 @@
1/*
2 * wm8804-i2c.c -- WM8804 S/PDIF transceiver driver - I2C
3 *
4 * Copyright 2015 Cirrus Logic Inc
5 *
6 * Author: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/i2c.h>
16
17#include "wm8804.h"
18
19static int wm8804_i2c_probe(struct i2c_client *i2c,
20 const struct i2c_device_id *id)
21{
22 struct regmap *regmap;
23
24 regmap = devm_regmap_init_i2c(i2c, &wm8804_regmap_config);
25 if (IS_ERR(regmap))
26 return PTR_ERR(regmap);
27
28 return wm8804_probe(&i2c->dev, regmap);
29}
30
31static int wm8804_i2c_remove(struct i2c_client *i2c)
32{
33 wm8804_remove(&i2c->dev);
34 return 0;
35}
36
37static const struct i2c_device_id wm8804_i2c_id[] = {
38 { "wm8804", 0 },
39 { }
40};
41MODULE_DEVICE_TABLE(i2c, wm8804_i2c_id);
42
43static const struct of_device_id wm8804_of_match[] = {
44 { .compatible = "wlf,wm8804", },
45 { }
46};
47MODULE_DEVICE_TABLE(of, wm8804_of_match);
48
49static struct i2c_driver wm8804_i2c_driver = {
50 .driver = {
51 .name = "wm8804",
52 .owner = THIS_MODULE,
53 .of_match_table = wm8804_of_match,
54 },
55 .probe = wm8804_i2c_probe,
56 .remove = wm8804_i2c_remove,
57 .id_table = wm8804_i2c_id
58};
59
60module_i2c_driver(wm8804_i2c_driver);
61
62MODULE_DESCRIPTION("ASoC WM8804 driver - I2C");
63MODULE_AUTHOR("Charles Keepax <ckeepax@opensource.wolfsonmicro.com>");
64MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm8804-spi.c b/sound/soc/codecs/wm8804-spi.c
new file mode 100644
index 000000000000..287e11e90794
--- /dev/null
+++ b/sound/soc/codecs/wm8804-spi.c
@@ -0,0 +1,56 @@
1/*
2 * wm8804-spi.c -- WM8804 S/PDIF transceiver driver - SPI
3 *
4 * Copyright 2015 Cirrus Logic Inc
5 *
6 * Author: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/spi/spi.h>
16
17#include "wm8804.h"
18
19static int wm8804_spi_probe(struct spi_device *spi)
20{
21 struct regmap *regmap;
22
23 regmap = devm_regmap_init_spi(spi, &wm8804_regmap_config);
24 if (IS_ERR(regmap))
25 return PTR_ERR(regmap);
26
27 return wm8804_probe(&spi->dev, regmap);
28}
29
30static int wm8804_spi_remove(struct spi_device *spi)
31{
32 wm8804_remove(&spi->dev);
33 return 0;
34}
35
36static const struct of_device_id wm8804_of_match[] = {
37 { .compatible = "wlf,wm8804", },
38 { }
39};
40MODULE_DEVICE_TABLE(of, wm8804_of_match);
41
42static struct spi_driver wm8804_spi_driver = {
43 .driver = {
44 .name = "wm8804",
45 .owner = THIS_MODULE,
46 .of_match_table = wm8804_of_match,
47 },
48 .probe = wm8804_spi_probe,
49 .remove = wm8804_spi_remove
50};
51
52module_spi_driver(wm8804_spi_driver);
53
54MODULE_DESCRIPTION("ASoC WM8804 driver - SPI");
55MODULE_AUTHOR("Charles Keepax <ckeepax@opensource.wolfsonmicro.com>");
56MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm8804.c b/sound/soc/codecs/wm8804.c
index b2b0e68f707e..1bd4ace29594 100644
--- a/sound/soc/codecs/wm8804.c
+++ b/sound/soc/codecs/wm8804.c
@@ -15,10 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/pm.h> 17#include <linux/pm.h>
18#include <linux/i2c.h>
19#include <linux/of_device.h> 18#include <linux/of_device.h>
20#include <linux/spi/spi.h>
21#include <linux/regmap.h>
22#include <linux/regulator/consumer.h> 19#include <linux/regulator/consumer.h>
23#include <linux/slab.h> 20#include <linux/slab.h>
24#include <sound/core.h> 21#include <sound/core.h>
@@ -185,9 +182,9 @@ static bool wm8804_volatile(struct device *dev, unsigned int reg)
185 } 182 }
186} 183}
187 184
188static int wm8804_reset(struct snd_soc_codec *codec) 185static int wm8804_reset(struct wm8804_priv *wm8804)
189{ 186{
190 return snd_soc_write(codec, WM8804_RST_DEVID1, 0x0); 187 return regmap_write(wm8804->regmap, WM8804_RST_DEVID1, 0x0);
191} 188}
192 189
193static int wm8804_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) 190static int wm8804_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
@@ -518,100 +515,6 @@ static int wm8804_set_bias_level(struct snd_soc_codec *codec,
518 return 0; 515 return 0;
519} 516}
520 517
521static int wm8804_remove(struct snd_soc_codec *codec)
522{
523 struct wm8804_priv *wm8804;
524 int i;
525
526 wm8804 = snd_soc_codec_get_drvdata(codec);
527
528 for (i = 0; i < ARRAY_SIZE(wm8804->supplies); ++i)
529 regulator_unregister_notifier(wm8804->supplies[i].consumer,
530 &wm8804->disable_nb[i]);
531 return 0;
532}
533
534static int wm8804_probe(struct snd_soc_codec *codec)
535{
536 struct wm8804_priv *wm8804;
537 int i, id1, id2, ret;
538
539 wm8804 = snd_soc_codec_get_drvdata(codec);
540
541 for (i = 0; i < ARRAY_SIZE(wm8804->supplies); i++)
542 wm8804->supplies[i].supply = wm8804_supply_names[i];
543
544 ret = devm_regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8804->supplies),
545 wm8804->supplies);
546 if (ret) {
547 dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
548 return ret;
549 }
550
551 wm8804->disable_nb[0].notifier_call = wm8804_regulator_event_0;
552 wm8804->disable_nb[1].notifier_call = wm8804_regulator_event_1;
553
554 /* This should really be moved into the regulator core */
555 for (i = 0; i < ARRAY_SIZE(wm8804->supplies); i++) {
556 ret = regulator_register_notifier(wm8804->supplies[i].consumer,
557 &wm8804->disable_nb[i]);
558 if (ret != 0) {
559 dev_err(codec->dev,
560 "Failed to register regulator notifier: %d\n",
561 ret);
562 }
563 }
564
565 ret = regulator_bulk_enable(ARRAY_SIZE(wm8804->supplies),
566 wm8804->supplies);
567 if (ret) {
568 dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
569 return ret;
570 }
571
572 id1 = snd_soc_read(codec, WM8804_RST_DEVID1);
573 if (id1 < 0) {
574 dev_err(codec->dev, "Failed to read device ID: %d\n", id1);
575 ret = id1;
576 goto err_reg_enable;
577 }
578
579 id2 = snd_soc_read(codec, WM8804_DEVID2);
580 if (id2 < 0) {
581 dev_err(codec->dev, "Failed to read device ID: %d\n", id2);
582 ret = id2;
583 goto err_reg_enable;
584 }
585
586 id2 = (id2 << 8) | id1;
587
588 if (id2 != 0x8805) {
589 dev_err(codec->dev, "Invalid device ID: %#x\n", id2);
590 ret = -EINVAL;
591 goto err_reg_enable;
592 }
593
594 ret = snd_soc_read(codec, WM8804_DEVREV);
595 if (ret < 0) {
596 dev_err(codec->dev, "Failed to read device revision: %d\n",
597 ret);
598 goto err_reg_enable;
599 }
600 dev_info(codec->dev, "revision %c\n", ret + 'A');
601
602 ret = wm8804_reset(codec);
603 if (ret < 0) {
604 dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
605 goto err_reg_enable;
606 }
607
608 return 0;
609
610err_reg_enable:
611 regulator_bulk_disable(ARRAY_SIZE(wm8804->supplies), wm8804->supplies);
612 return ret;
613}
614
615static const struct snd_soc_dai_ops wm8804_dai_ops = { 518static const struct snd_soc_dai_ops wm8804_dai_ops = {
616 .hw_params = wm8804_hw_params, 519 .hw_params = wm8804_hw_params,
617 .set_fmt = wm8804_set_fmt, 520 .set_fmt = wm8804_set_fmt,
@@ -649,8 +552,6 @@ static struct snd_soc_dai_driver wm8804_dai = {
649}; 552};
650 553
651static const struct snd_soc_codec_driver soc_codec_dev_wm8804 = { 554static const struct snd_soc_codec_driver soc_codec_dev_wm8804 = {
652 .probe = wm8804_probe,
653 .remove = wm8804_remove,
654 .set_bias_level = wm8804_set_bias_level, 555 .set_bias_level = wm8804_set_bias_level,
655 .idle_bias_off = true, 556 .idle_bias_off = true,
656 557
@@ -658,13 +559,7 @@ static const struct snd_soc_codec_driver soc_codec_dev_wm8804 = {
658 .num_controls = ARRAY_SIZE(wm8804_snd_controls), 559 .num_controls = ARRAY_SIZE(wm8804_snd_controls),
659}; 560};
660 561
661static const struct of_device_id wm8804_of_match[] = { 562const struct regmap_config wm8804_regmap_config = {
662 { .compatible = "wlf,wm8804", },
663 { }
664};
665MODULE_DEVICE_TABLE(of, wm8804_of_match);
666
667static const struct regmap_config wm8804_regmap_config = {
668 .reg_bits = 8, 563 .reg_bits = 8,
669 .val_bits = 8, 564 .val_bits = 8,
670 565
@@ -675,128 +570,110 @@ static const struct regmap_config wm8804_regmap_config = {
675 .reg_defaults = wm8804_reg_defaults, 570 .reg_defaults = wm8804_reg_defaults,
676 .num_reg_defaults = ARRAY_SIZE(wm8804_reg_defaults), 571 .num_reg_defaults = ARRAY_SIZE(wm8804_reg_defaults),
677}; 572};
573EXPORT_SYMBOL_GPL(wm8804_regmap_config);
678 574
679#if defined(CONFIG_SPI_MASTER) 575int wm8804_probe(struct device *dev, struct regmap *regmap)
680static int wm8804_spi_probe(struct spi_device *spi)
681{ 576{
682 struct wm8804_priv *wm8804; 577 struct wm8804_priv *wm8804;
683 int ret; 578 unsigned int id1, id2;
579 int i, ret;
684 580
685 wm8804 = devm_kzalloc(&spi->dev, sizeof *wm8804, GFP_KERNEL); 581 wm8804 = devm_kzalloc(dev, sizeof(*wm8804), GFP_KERNEL);
686 if (!wm8804) 582 if (!wm8804)
687 return -ENOMEM; 583 return -ENOMEM;
688 584
689 wm8804->regmap = devm_regmap_init_spi(spi, &wm8804_regmap_config); 585 dev_set_drvdata(dev, wm8804);
690 if (IS_ERR(wm8804->regmap)) { 586
691 ret = PTR_ERR(wm8804->regmap); 587 wm8804->regmap = regmap;
588
589 for (i = 0; i < ARRAY_SIZE(wm8804->supplies); i++)
590 wm8804->supplies[i].supply = wm8804_supply_names[i];
591
592 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(wm8804->supplies),
593 wm8804->supplies);
594 if (ret) {
595 dev_err(dev, "Failed to request supplies: %d\n", ret);
692 return ret; 596 return ret;
693 } 597 }
694 598
695 spi_set_drvdata(spi, wm8804); 599 wm8804->disable_nb[0].notifier_call = wm8804_regulator_event_0;
600 wm8804->disable_nb[1].notifier_call = wm8804_regulator_event_1;
696 601
697 ret = snd_soc_register_codec(&spi->dev, 602 /* This should really be moved into the regulator core */
698 &soc_codec_dev_wm8804, &wm8804_dai, 1); 603 for (i = 0; i < ARRAY_SIZE(wm8804->supplies); i++) {
604 ret = regulator_register_notifier(wm8804->supplies[i].consumer,
605 &wm8804->disable_nb[i]);
606 if (ret != 0) {
607 dev_err(dev,
608 "Failed to register regulator notifier: %d\n",
609 ret);
610 }
611 }
699 612
700 return ret; 613 ret = regulator_bulk_enable(ARRAY_SIZE(wm8804->supplies),
701} 614 wm8804->supplies);
615 if (ret) {
616 dev_err(dev, "Failed to enable supplies: %d\n", ret);
617 goto err_reg_enable;
618 }
702 619
703static int wm8804_spi_remove(struct spi_device *spi) 620 ret = regmap_read(regmap, WM8804_RST_DEVID1, &id1);
704{ 621 if (ret < 0) {
705 snd_soc_unregister_codec(&spi->dev); 622 dev_err(dev, "Failed to read device ID: %d\n", ret);
706 return 0; 623 goto err_reg_enable;
707} 624 }
708 625
709static struct spi_driver wm8804_spi_driver = { 626 ret = regmap_read(regmap, WM8804_DEVID2, &id2);
710 .driver = { 627 if (ret < 0) {
711 .name = "wm8804", 628 dev_err(dev, "Failed to read device ID: %d\n", ret);
712 .owner = THIS_MODULE, 629 goto err_reg_enable;
713 .of_match_table = wm8804_of_match, 630 }
714 },
715 .probe = wm8804_spi_probe,
716 .remove = wm8804_spi_remove
717};
718#endif
719 631
720#if IS_ENABLED(CONFIG_I2C) 632 id2 = (id2 << 8) | id1;
721static int wm8804_i2c_probe(struct i2c_client *i2c,
722 const struct i2c_device_id *id)
723{
724 struct wm8804_priv *wm8804;
725 int ret;
726 633
727 wm8804 = devm_kzalloc(&i2c->dev, sizeof *wm8804, GFP_KERNEL); 634 if (id2 != 0x8805) {
728 if (!wm8804) 635 dev_err(dev, "Invalid device ID: %#x\n", id2);
729 return -ENOMEM; 636 ret = -EINVAL;
637 goto err_reg_enable;
638 }
730 639
731 wm8804->regmap = devm_regmap_init_i2c(i2c, &wm8804_regmap_config); 640 ret = regmap_read(regmap, WM8804_DEVREV, &id1);
732 if (IS_ERR(wm8804->regmap)) { 641 if (ret < 0) {
733 ret = PTR_ERR(wm8804->regmap); 642 dev_err(dev, "Failed to read device revision: %d\n",
734 return ret; 643 ret);
644 goto err_reg_enable;
735 } 645 }
646 dev_info(dev, "revision %c\n", id1 + 'A');
736 647
737 i2c_set_clientdata(i2c, wm8804); 648 ret = wm8804_reset(wm8804);
649 if (ret < 0) {
650 dev_err(dev, "Failed to issue reset: %d\n", ret);
651 goto err_reg_enable;
652 }
738 653
739 ret = snd_soc_register_codec(&i2c->dev, 654 return snd_soc_register_codec(dev, &soc_codec_dev_wm8804,
740 &soc_codec_dev_wm8804, &wm8804_dai, 1); 655 &wm8804_dai, 1);
656
657err_reg_enable:
658 regulator_bulk_disable(ARRAY_SIZE(wm8804->supplies), wm8804->supplies);
741 return ret; 659 return ret;
742} 660}
661EXPORT_SYMBOL_GPL(wm8804_probe);
743 662
744static int wm8804_i2c_remove(struct i2c_client *i2c) 663void wm8804_remove(struct device *dev)
745{ 664{
746 snd_soc_unregister_codec(&i2c->dev); 665 struct wm8804_priv *wm8804;
747 return 0; 666 int i;
748}
749
750static const struct i2c_device_id wm8804_i2c_id[] = {
751 { "wm8804", 0 },
752 { }
753};
754MODULE_DEVICE_TABLE(i2c, wm8804_i2c_id);
755
756static struct i2c_driver wm8804_i2c_driver = {
757 .driver = {
758 .name = "wm8804",
759 .owner = THIS_MODULE,
760 .of_match_table = wm8804_of_match,
761 },
762 .probe = wm8804_i2c_probe,
763 .remove = wm8804_i2c_remove,
764 .id_table = wm8804_i2c_id
765};
766#endif
767 667
768static int __init wm8804_modinit(void) 668 wm8804 = dev_get_drvdata(dev);
769{
770 int ret = 0;
771 669
772#if IS_ENABLED(CONFIG_I2C) 670 for (i = 0; i < ARRAY_SIZE(wm8804->supplies); ++i)
773 ret = i2c_add_driver(&wm8804_i2c_driver); 671 regulator_unregister_notifier(wm8804->supplies[i].consumer,
774 if (ret) { 672 &wm8804->disable_nb[i]);
775 printk(KERN_ERR "Failed to register wm8804 I2C driver: %d\n",
776 ret);
777 }
778#endif
779#if defined(CONFIG_SPI_MASTER)
780 ret = spi_register_driver(&wm8804_spi_driver);
781 if (ret != 0) {
782 printk(KERN_ERR "Failed to register wm8804 SPI driver: %d\n",
783 ret);
784 }
785#endif
786 return ret;
787}
788module_init(wm8804_modinit);
789 673
790static void __exit wm8804_exit(void) 674 snd_soc_unregister_codec(dev);
791{
792#if IS_ENABLED(CONFIG_I2C)
793 i2c_del_driver(&wm8804_i2c_driver);
794#endif
795#if defined(CONFIG_SPI_MASTER)
796 spi_unregister_driver(&wm8804_spi_driver);
797#endif
798} 675}
799module_exit(wm8804_exit); 676EXPORT_SYMBOL_GPL(wm8804_remove);
800 677
801MODULE_DESCRIPTION("ASoC WM8804 driver"); 678MODULE_DESCRIPTION("ASoC WM8804 driver");
802MODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>"); 679MODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>");
diff --git a/sound/soc/codecs/wm8804.h b/sound/soc/codecs/wm8804.h
index e72d4f4ba6b1..a39a2563dc67 100644
--- a/sound/soc/codecs/wm8804.h
+++ b/sound/soc/codecs/wm8804.h
@@ -13,6 +13,8 @@
13#ifndef _WM8804_H 13#ifndef _WM8804_H
14#define _WM8804_H 14#define _WM8804_H
15 15
16#include <linux/regmap.h>
17
16/* 18/*
17 * Register values. 19 * Register values.
18 */ 20 */
@@ -62,4 +64,9 @@
62#define WM8804_MCLKDIV_256FS 0 64#define WM8804_MCLKDIV_256FS 0
63#define WM8804_MCLKDIV_128FS 1 65#define WM8804_MCLKDIV_128FS 1
64 66
67extern const struct regmap_config wm8804_regmap_config;
68
69int wm8804_probe(struct device *dev, struct regmap *regmap);
70void wm8804_remove(struct device *dev);
71
65#endif /* _WM8804_H */ 72#endif /* _WM8804_H */
diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c
index ff67b334065b..d01c2095452f 100644
--- a/sound/soc/codecs/wm_adsp.c
+++ b/sound/soc/codecs/wm_adsp.c
@@ -420,10 +420,9 @@ static int wm_coeff_put(struct snd_kcontrol *kcontrol,
420 420
421 memcpy(ctl->cache, p, ctl->len); 421 memcpy(ctl->cache, p, ctl->len);
422 422
423 if (!ctl->enabled) { 423 ctl->set = 1;
424 ctl->set = 1; 424 if (!ctl->enabled)
425 return 0; 425 return 0;
426 }
427 426
428 return wm_coeff_write_control(kcontrol, p, ctl->len); 427 return wm_coeff_write_control(kcontrol, p, ctl->len);
429} 428}
@@ -1185,7 +1184,6 @@ static int wm_adsp_load_coeff(struct wm_adsp *dsp)
1185 int ret, pos, blocks, type, offset, reg; 1184 int ret, pos, blocks, type, offset, reg;
1186 char *file; 1185 char *file;
1187 struct wm_adsp_buf *buf; 1186 struct wm_adsp_buf *buf;
1188 int tmp;
1189 1187
1190 file = kzalloc(PAGE_SIZE, GFP_KERNEL); 1188 file = kzalloc(PAGE_SIZE, GFP_KERNEL);
1191 if (file == NULL) 1189 if (file == NULL)
@@ -1335,12 +1333,7 @@ static int wm_adsp_load_coeff(struct wm_adsp *dsp)
1335 } 1333 }
1336 } 1334 }
1337 1335
1338 tmp = le32_to_cpu(blk->len) % 4; 1336 pos += (le32_to_cpu(blk->len) + sizeof(*blk) + 3) & ~0x03;
1339 if (tmp)
1340 pos += le32_to_cpu(blk->len) + (4 - tmp) + sizeof(*blk);
1341 else
1342 pos += le32_to_cpu(blk->len) + sizeof(*blk);
1343
1344 blocks++; 1337 blocks++;
1345 } 1338 }
1346 1339
diff --git a/sound/soc/davinci/Kconfig b/sound/soc/davinci/Kconfig
index 2b81ca418d2a..3736d9aabc56 100644
--- a/sound/soc/davinci/Kconfig
+++ b/sound/soc/davinci/Kconfig
@@ -1,14 +1,16 @@
1config SND_DAVINCI_SOC 1config SND_DAVINCI_SOC
2 tristate "SoC Audio for TI DAVINCI" 2 tristate
3 depends on ARCH_DAVINCI 3 depends on ARCH_DAVINCI
4 select SND_EDMA_SOC
4 5
5config SND_EDMA_SOC 6config SND_EDMA_SOC
6 tristate "SoC Audio for Texas Instruments chips using eDMA (AM33XX/43XX)" 7 tristate "SoC Audio for Texas Instruments chips using eDMA"
7 depends on SOC_AM33XX || SOC_AM43XX 8 depends on SOC_AM33XX || SOC_AM43XX || ARCH_DAVINCI
8 select SND_SOC_GENERIC_DMAENGINE_PCM 9 select SND_SOC_GENERIC_DMAENGINE_PCM
9 help 10 help
10 Say Y or M here if you want audio support for TI SoC which uses eDMA. 11 Say Y or M here if you want audio support for TI SoC which uses eDMA.
11 The following line of SoCs are supported by this platform driver: 12 The following line of SoCs are supported by this platform driver:
13 - daVinci devices
12 - AM335x 14 - AM335x
13 - AM437x/AM438x 15 - AM437x/AM438x
14 16
@@ -17,7 +19,7 @@ config SND_DAVINCI_SOC_I2S
17 19
18config SND_DAVINCI_SOC_MCASP 20config SND_DAVINCI_SOC_MCASP
19 tristate "Multichannel Audio Serial Port (McASP) support" 21 tristate "Multichannel Audio Serial Port (McASP) support"
20 depends on SND_DAVINCI_SOC || SND_OMAP_SOC || SND_EDMA_SOC 22 depends on SND_OMAP_SOC || SND_EDMA_SOC
21 help 23 help
22 Say Y or M here if you want to have support for McASP IP found in 24 Say Y or M here if you want to have support for McASP IP found in
23 various Texas Instruments SoCs like: 25 various Texas Instruments SoCs like:
@@ -45,7 +47,7 @@ config SND_AM33XX_SOC_EVM
45 47
46config SND_DAVINCI_SOC_EVM 48config SND_DAVINCI_SOC_EVM
47 tristate "SoC Audio support for DaVinci DM6446, DM355 or DM365 EVM" 49 tristate "SoC Audio support for DaVinci DM6446, DM355 or DM365 EVM"
48 depends on SND_DAVINCI_SOC && I2C 50 depends on SND_EDMA_SOC && I2C
49 depends on MACH_DAVINCI_EVM || MACH_DAVINCI_DM355_EVM || MACH_DAVINCI_DM365_EVM 51 depends on MACH_DAVINCI_EVM || MACH_DAVINCI_DM355_EVM || MACH_DAVINCI_DM365_EVM
50 select SND_DAVINCI_SOC_GENERIC_EVM 52 select SND_DAVINCI_SOC_GENERIC_EVM
51 help 53 help
@@ -73,7 +75,7 @@ endchoice
73 75
74config SND_DM6467_SOC_EVM 76config SND_DM6467_SOC_EVM
75 tristate "SoC Audio support for DaVinci DM6467 EVM" 77 tristate "SoC Audio support for DaVinci DM6467 EVM"
76 depends on SND_DAVINCI_SOC && MACH_DAVINCI_DM6467_EVM && I2C 78 depends on SND_EDMA_SOC && MACH_DAVINCI_DM6467_EVM && I2C
77 select SND_DAVINCI_SOC_GENERIC_EVM 79 select SND_DAVINCI_SOC_GENERIC_EVM
78 select SND_SOC_SPDIF 80 select SND_SOC_SPDIF
79 81
@@ -82,7 +84,7 @@ config SND_DM6467_SOC_EVM
82 84
83config SND_DA830_SOC_EVM 85config SND_DA830_SOC_EVM
84 tristate "SoC Audio support for DA830/OMAP-L137 EVM" 86 tristate "SoC Audio support for DA830/OMAP-L137 EVM"
85 depends on SND_DAVINCI_SOC && MACH_DAVINCI_DA830_EVM && I2C 87 depends on SND_EDMA_SOC && MACH_DAVINCI_DA830_EVM && I2C
86 select SND_DAVINCI_SOC_GENERIC_EVM 88 select SND_DAVINCI_SOC_GENERIC_EVM
87 89
88 help 90 help
@@ -91,7 +93,7 @@ config SND_DA830_SOC_EVM
91 93
92config SND_DA850_SOC_EVM 94config SND_DA850_SOC_EVM
93 tristate "SoC Audio support for DA850/OMAP-L138 EVM" 95 tristate "SoC Audio support for DA850/OMAP-L138 EVM"
94 depends on SND_DAVINCI_SOC && MACH_DAVINCI_DA850_EVM && I2C 96 depends on SND_EDMA_SOC && MACH_DAVINCI_DA850_EVM && I2C
95 select SND_DAVINCI_SOC_GENERIC_EVM 97 select SND_DAVINCI_SOC_GENERIC_EVM
96 help 98 help
97 Say Y if you want to add support for SoC audio on TI 99 Say Y if you want to add support for SoC audio on TI
diff --git a/sound/soc/davinci/Makefile b/sound/soc/davinci/Makefile
index 09bf2ba92d38..f883933c1a19 100644
--- a/sound/soc/davinci/Makefile
+++ b/sound/soc/davinci/Makefile
@@ -1,11 +1,9 @@
1# DAVINCI Platform Support 1# DAVINCI Platform Support
2snd-soc-davinci-objs := davinci-pcm.o
3snd-soc-edma-objs := edma-pcm.o 2snd-soc-edma-objs := edma-pcm.o
4snd-soc-davinci-i2s-objs := davinci-i2s.o 3snd-soc-davinci-i2s-objs := davinci-i2s.o
5snd-soc-davinci-mcasp-objs:= davinci-mcasp.o 4snd-soc-davinci-mcasp-objs:= davinci-mcasp.o
6snd-soc-davinci-vcif-objs:= davinci-vcif.o 5snd-soc-davinci-vcif-objs:= davinci-vcif.o
7 6
8obj-$(CONFIG_SND_DAVINCI_SOC) += snd-soc-davinci.o
9obj-$(CONFIG_SND_EDMA_SOC) += snd-soc-edma.o 7obj-$(CONFIG_SND_EDMA_SOC) += snd-soc-edma.o
10obj-$(CONFIG_SND_DAVINCI_SOC_I2S) += snd-soc-davinci-i2s.o 8obj-$(CONFIG_SND_DAVINCI_SOC_I2S) += snd-soc-davinci-i2s.o
11obj-$(CONFIG_SND_DAVINCI_SOC_MCASP) += snd-soc-davinci-mcasp.o 9obj-$(CONFIG_SND_DAVINCI_SOC_MCASP) += snd-soc-davinci-mcasp.o
diff --git a/sound/soc/davinci/davinci-i2s.c b/sound/soc/davinci/davinci-i2s.c
index 15fb28fc8e1b..56cb4d95637d 100644
--- a/sound/soc/davinci/davinci-i2s.c
+++ b/sound/soc/davinci/davinci-i2s.c
@@ -23,8 +23,9 @@
23#include <sound/pcm_params.h> 23#include <sound/pcm_params.h>
24#include <sound/initval.h> 24#include <sound/initval.h>
25#include <sound/soc.h> 25#include <sound/soc.h>
26#include <sound/dmaengine_pcm.h>
26 27
27#include "davinci-pcm.h" 28#include "edma-pcm.h"
28#include "davinci-i2s.h" 29#include "davinci-i2s.h"
29 30
30 31
@@ -122,7 +123,8 @@ static const unsigned char double_fmt[SNDRV_PCM_FORMAT_S32_LE + 1] = {
122 123
123struct davinci_mcbsp_dev { 124struct davinci_mcbsp_dev {
124 struct device *dev; 125 struct device *dev;
125 struct davinci_pcm_dma_params dma_params[2]; 126 struct snd_dmaengine_dai_dma_data dma_data[2];
127 int dma_request[2];
126 void __iomem *base; 128 void __iomem *base;
127#define MOD_DSP_A 0 129#define MOD_DSP_A 0
128#define MOD_DSP_B 1 130#define MOD_DSP_B 1
@@ -419,8 +421,6 @@ static int davinci_i2s_hw_params(struct snd_pcm_substream *substream,
419 struct snd_soc_dai *dai) 421 struct snd_soc_dai *dai)
420{ 422{
421 struct davinci_mcbsp_dev *dev = snd_soc_dai_get_drvdata(dai); 423 struct davinci_mcbsp_dev *dev = snd_soc_dai_get_drvdata(dai);
422 struct davinci_pcm_dma_params *dma_params =
423 &dev->dma_params[substream->stream];
424 struct snd_interval *i = NULL; 424 struct snd_interval *i = NULL;
425 int mcbsp_word_length, master; 425 int mcbsp_word_length, master;
426 unsigned int rcr, xcr, srgr, clk_div, freq, framesize; 426 unsigned int rcr, xcr, srgr, clk_div, freq, framesize;
@@ -532,8 +532,6 @@ static int davinci_i2s_hw_params(struct snd_pcm_substream *substream,
532 return -EINVAL; 532 return -EINVAL;
533 } 533 }
534 } 534 }
535 dma_params->acnt = dma_params->data_type = data_type[fmt];
536 dma_params->fifo_level = 0;
537 mcbsp_word_length = asp_word_length[fmt]; 535 mcbsp_word_length = asp_word_length[fmt];
538 536
539 switch (master) { 537 switch (master) {
@@ -600,15 +598,6 @@ static int davinci_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
600 return ret; 598 return ret;
601} 599}
602 600
603static int davinci_i2s_startup(struct snd_pcm_substream *substream,
604 struct snd_soc_dai *dai)
605{
606 struct davinci_mcbsp_dev *dev = snd_soc_dai_get_drvdata(dai);
607
608 snd_soc_dai_set_dma_data(dai, substream, dev->dma_params);
609 return 0;
610}
611
612static void davinci_i2s_shutdown(struct snd_pcm_substream *substream, 601static void davinci_i2s_shutdown(struct snd_pcm_substream *substream,
613 struct snd_soc_dai *dai) 602 struct snd_soc_dai *dai)
614{ 603{
@@ -620,7 +609,6 @@ static void davinci_i2s_shutdown(struct snd_pcm_substream *substream,
620#define DAVINCI_I2S_RATES SNDRV_PCM_RATE_8000_96000 609#define DAVINCI_I2S_RATES SNDRV_PCM_RATE_8000_96000
621 610
622static const struct snd_soc_dai_ops davinci_i2s_dai_ops = { 611static const struct snd_soc_dai_ops davinci_i2s_dai_ops = {
623 .startup = davinci_i2s_startup,
624 .shutdown = davinci_i2s_shutdown, 612 .shutdown = davinci_i2s_shutdown,
625 .prepare = davinci_i2s_prepare, 613 .prepare = davinci_i2s_prepare,
626 .trigger = davinci_i2s_trigger, 614 .trigger = davinci_i2s_trigger,
@@ -630,7 +618,18 @@ static const struct snd_soc_dai_ops davinci_i2s_dai_ops = {
630 618
631}; 619};
632 620
621static int davinci_i2s_dai_probe(struct snd_soc_dai *dai)
622{
623 struct davinci_mcbsp_dev *dev = snd_soc_dai_get_drvdata(dai);
624
625 dai->playback_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
626 dai->capture_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_CAPTURE];
627
628 return 0;
629}
630
633static struct snd_soc_dai_driver davinci_i2s_dai = { 631static struct snd_soc_dai_driver davinci_i2s_dai = {
632 .probe = davinci_i2s_dai_probe,
634 .playback = { 633 .playback = {
635 .channels_min = 2, 634 .channels_min = 2,
636 .channels_max = 2, 635 .channels_max = 2,
@@ -651,11 +650,9 @@ static const struct snd_soc_component_driver davinci_i2s_component = {
651 650
652static int davinci_i2s_probe(struct platform_device *pdev) 651static int davinci_i2s_probe(struct platform_device *pdev)
653{ 652{
654 struct snd_platform_data *pdata = pdev->dev.platform_data;
655 struct davinci_mcbsp_dev *dev; 653 struct davinci_mcbsp_dev *dev;
656 struct resource *mem, *ioarea, *res; 654 struct resource *mem, *ioarea, *res;
657 enum dma_event_q asp_chan_q = EVENTQ_0; 655 int *dma;
658 enum dma_event_q ram_chan_q = EVENTQ_1;
659 int ret; 656 int ret;
660 657
661 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 658 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -676,22 +673,6 @@ static int davinci_i2s_probe(struct platform_device *pdev)
676 GFP_KERNEL); 673 GFP_KERNEL);
677 if (!dev) 674 if (!dev)
678 return -ENOMEM; 675 return -ENOMEM;
679 if (pdata) {
680 dev->enable_channel_combine = pdata->enable_channel_combine;
681 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].sram_size =
682 pdata->sram_size_playback;
683 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].sram_size =
684 pdata->sram_size_capture;
685 dev->clk_input_pin = pdata->clk_input_pin;
686 dev->i2s_accurate_sck = pdata->i2s_accurate_sck;
687 asp_chan_q = pdata->asp_chan_q;
688 ram_chan_q = pdata->ram_chan_q;
689 }
690
691 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].asp_chan_q = asp_chan_q;
692 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].ram_chan_q = ram_chan_q;
693 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].asp_chan_q = asp_chan_q;
694 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].ram_chan_q = ram_chan_q;
695 676
696 dev->clk = clk_get(&pdev->dev, NULL); 677 dev->clk = clk_get(&pdev->dev, NULL);
697 if (IS_ERR(dev->clk)) 678 if (IS_ERR(dev->clk))
@@ -705,10 +686,10 @@ static int davinci_i2s_probe(struct platform_device *pdev)
705 goto err_release_clk; 686 goto err_release_clk;
706 } 687 }
707 688
708 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].dma_addr = 689 dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
709 (dma_addr_t)(mem->start + DAVINCI_MCBSP_DXR_REG); 690 (dma_addr_t)(mem->start + DAVINCI_MCBSP_DXR_REG);
710 691
711 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].dma_addr = 692 dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
712 (dma_addr_t)(mem->start + DAVINCI_MCBSP_DRR_REG); 693 (dma_addr_t)(mem->start + DAVINCI_MCBSP_DRR_REG);
713 694
714 /* first TX, then RX */ 695 /* first TX, then RX */
@@ -718,7 +699,9 @@ static int davinci_i2s_probe(struct platform_device *pdev)
718 ret = -ENXIO; 699 ret = -ENXIO;
719 goto err_release_clk; 700 goto err_release_clk;
720 } 701 }
721 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].channel = res->start; 702 dma = &dev->dma_request[SNDRV_PCM_STREAM_PLAYBACK];
703 *dma = res->start;
704 dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].filter_data = dma;
722 705
723 res = platform_get_resource(pdev, IORESOURCE_DMA, 1); 706 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
724 if (!res) { 707 if (!res) {
@@ -726,9 +709,11 @@ static int davinci_i2s_probe(struct platform_device *pdev)
726 ret = -ENXIO; 709 ret = -ENXIO;
727 goto err_release_clk; 710 goto err_release_clk;
728 } 711 }
729 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].channel = res->start; 712 dma = &dev->dma_request[SNDRV_PCM_STREAM_CAPTURE];
730 dev->dev = &pdev->dev; 713 *dma = res->start;
714 dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].filter_data = dma;
731 715
716 dev->dev = &pdev->dev;
732 dev_set_drvdata(&pdev->dev, dev); 717 dev_set_drvdata(&pdev->dev, dev);
733 718
734 ret = snd_soc_register_component(&pdev->dev, &davinci_i2s_component, 719 ret = snd_soc_register_component(&pdev->dev, &davinci_i2s_component,
@@ -736,7 +721,7 @@ static int davinci_i2s_probe(struct platform_device *pdev)
736 if (ret != 0) 721 if (ret != 0)
737 goto err_release_clk; 722 goto err_release_clk;
738 723
739 ret = davinci_soc_platform_register(&pdev->dev); 724 ret = edma_pcm_platform_register(&pdev->dev);
740 if (ret) { 725 if (ret) {
741 dev_err(&pdev->dev, "register PCM failed: %d\n", ret); 726 dev_err(&pdev->dev, "register PCM failed: %d\n", ret);
742 goto err_unregister_component; 727 goto err_unregister_component;
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index de3b155a5011..0c882995a357 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -26,6 +26,7 @@
26#include <linux/of.h> 26#include <linux/of.h>
27#include <linux/of_platform.h> 27#include <linux/of_platform.h>
28#include <linux/of_device.h> 28#include <linux/of_device.h>
29#include <linux/platform_data/davinci_asp.h>
29 30
30#include <sound/asoundef.h> 31#include <sound/asoundef.h>
31#include <sound/core.h> 32#include <sound/core.h>
@@ -36,7 +37,6 @@
36#include <sound/dmaengine_pcm.h> 37#include <sound/dmaengine_pcm.h>
37#include <sound/omap-pcm.h> 38#include <sound/omap-pcm.h>
38 39
39#include "davinci-pcm.h"
40#include "edma-pcm.h" 40#include "edma-pcm.h"
41#include "davinci-mcasp.h" 41#include "davinci-mcasp.h"
42 42
@@ -65,7 +65,6 @@ struct davinci_mcasp_context {
65}; 65};
66 66
67struct davinci_mcasp { 67struct davinci_mcasp {
68 struct davinci_pcm_dma_params dma_params[2];
69 struct snd_dmaengine_dai_dma_data dma_data[2]; 68 struct snd_dmaengine_dai_dma_data dma_data[2];
70 void __iomem *base; 69 void __iomem *base;
71 u32 fifo_base; 70 u32 fifo_base;
@@ -82,6 +81,7 @@ struct davinci_mcasp {
82 u16 bclk_lrclk_ratio; 81 u16 bclk_lrclk_ratio;
83 int streams; 82 int streams;
84 u32 irq_request[2]; 83 u32 irq_request[2];
84 int dma_request[2];
85 85
86 int sysclk_freq; 86 int sysclk_freq;
87 bool bclk_master; 87 bool bclk_master;
@@ -441,6 +441,18 @@ static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
441 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AFSX | AFSR); 441 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AFSX | AFSR);
442 mcasp->bclk_master = 1; 442 mcasp->bclk_master = 1;
443 break; 443 break;
444 case SND_SOC_DAIFMT_CBS_CFM:
445 /* codec is clock slave and frame master */
446 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
447 mcasp_clr_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, AFSXE);
448
449 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
450 mcasp_clr_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
451
452 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, ACLKX | ACLKR);
453 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AFSX | AFSR);
454 mcasp->bclk_master = 1;
455 break;
444 case SND_SOC_DAIFMT_CBM_CFS: 456 case SND_SOC_DAIFMT_CBM_CFS:
445 /* codec is clock master and frame slave */ 457 /* codec is clock master and frame slave */
446 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE); 458 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
@@ -631,7 +643,6 @@ static int davinci_config_channel_size(struct davinci_mcasp *mcasp,
631static int mcasp_common_hw_param(struct davinci_mcasp *mcasp, int stream, 643static int mcasp_common_hw_param(struct davinci_mcasp *mcasp, int stream,
632 int period_words, int channels) 644 int period_words, int channels)
633{ 645{
634 struct davinci_pcm_dma_params *dma_params = &mcasp->dma_params[stream];
635 struct snd_dmaengine_dai_dma_data *dma_data = &mcasp->dma_data[stream]; 646 struct snd_dmaengine_dai_dma_data *dma_data = &mcasp->dma_data[stream];
636 int i; 647 int i;
637 u8 tx_ser = 0; 648 u8 tx_ser = 0;
@@ -699,10 +710,8 @@ static int mcasp_common_hw_param(struct davinci_mcasp *mcasp, int stream,
699 * For example if three serializers are enabled the DMA 710 * For example if three serializers are enabled the DMA
700 * need to transfer three words per DMA request. 711 * need to transfer three words per DMA request.
701 */ 712 */
702 dma_params->fifo_level = active_serializers;
703 dma_data->maxburst = active_serializers; 713 dma_data->maxburst = active_serializers;
704 } else { 714 } else {
705 dma_params->fifo_level = 0;
706 dma_data->maxburst = 0; 715 dma_data->maxburst = 0;
707 } 716 }
708 return 0; 717 return 0;
@@ -734,7 +743,6 @@ static int mcasp_common_hw_param(struct davinci_mcasp *mcasp, int stream,
734 /* Configure the burst size for platform drivers */ 743 /* Configure the burst size for platform drivers */
735 if (numevt == 1) 744 if (numevt == 1)
736 numevt = 0; 745 numevt = 0;
737 dma_params->fifo_level = numevt;
738 dma_data->maxburst = numevt; 746 dma_data->maxburst = numevt;
739 747
740 return 0; 748 return 0;
@@ -860,8 +868,6 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
860 struct snd_soc_dai *cpu_dai) 868 struct snd_soc_dai *cpu_dai)
861{ 869{
862 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai); 870 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
863 struct davinci_pcm_dma_params *dma_params =
864 &mcasp->dma_params[substream->stream];
865 int word_length; 871 int word_length;
866 int channels = params_channels(params); 872 int channels = params_channels(params);
867 int period_size = params_period_size(params); 873 int period_size = params_period_size(params);
@@ -902,31 +908,26 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
902 switch (params_format(params)) { 908 switch (params_format(params)) {
903 case SNDRV_PCM_FORMAT_U8: 909 case SNDRV_PCM_FORMAT_U8:
904 case SNDRV_PCM_FORMAT_S8: 910 case SNDRV_PCM_FORMAT_S8:
905 dma_params->data_type = 1;
906 word_length = 8; 911 word_length = 8;
907 break; 912 break;
908 913
909 case SNDRV_PCM_FORMAT_U16_LE: 914 case SNDRV_PCM_FORMAT_U16_LE:
910 case SNDRV_PCM_FORMAT_S16_LE: 915 case SNDRV_PCM_FORMAT_S16_LE:
911 dma_params->data_type = 2;
912 word_length = 16; 916 word_length = 16;
913 break; 917 break;
914 918
915 case SNDRV_PCM_FORMAT_U24_3LE: 919 case SNDRV_PCM_FORMAT_U24_3LE:
916 case SNDRV_PCM_FORMAT_S24_3LE: 920 case SNDRV_PCM_FORMAT_S24_3LE:
917 dma_params->data_type = 3;
918 word_length = 24; 921 word_length = 24;
919 break; 922 break;
920 923
921 case SNDRV_PCM_FORMAT_U24_LE: 924 case SNDRV_PCM_FORMAT_U24_LE:
922 case SNDRV_PCM_FORMAT_S24_LE: 925 case SNDRV_PCM_FORMAT_S24_LE:
923 dma_params->data_type = 4;
924 word_length = 24; 926 word_length = 24;
925 break; 927 break;
926 928
927 case SNDRV_PCM_FORMAT_U32_LE: 929 case SNDRV_PCM_FORMAT_U32_LE:
928 case SNDRV_PCM_FORMAT_S32_LE: 930 case SNDRV_PCM_FORMAT_S32_LE:
929 dma_params->data_type = 4;
930 word_length = 32; 931 word_length = 32;
931 break; 932 break;
932 933
@@ -935,11 +936,6 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
935 return -EINVAL; 936 return -EINVAL;
936 } 937 }
937 938
938 if (mcasp->version == MCASP_VERSION_2 && !dma_params->fifo_level)
939 dma_params->acnt = 4;
940 else
941 dma_params->acnt = dma_params->data_type;
942
943 davinci_config_channel_size(mcasp, word_length); 939 davinci_config_channel_size(mcasp, word_length);
944 940
945 if (mcasp->op_mode == DAVINCI_MCASP_IIS_MODE) 941 if (mcasp->op_mode == DAVINCI_MCASP_IIS_MODE)
@@ -1043,17 +1039,8 @@ static int davinci_mcasp_dai_probe(struct snd_soc_dai *dai)
1043{ 1039{
1044 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai); 1040 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
1045 1041
1046 if (mcasp->version >= MCASP_VERSION_3) { 1042 dai->playback_dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
1047 /* Using dmaengine PCM */ 1043 dai->capture_dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE];
1048 dai->playback_dma_data =
1049 &mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
1050 dai->capture_dma_data =
1051 &mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE];
1052 } else {
1053 /* Using davinci-pcm */
1054 dai->playback_dma_data = mcasp->dma_params;
1055 dai->capture_dma_data = mcasp->dma_params;
1056 }
1057 1044
1058 return 0; 1045 return 0;
1059} 1046}
@@ -1172,28 +1159,24 @@ static const struct snd_soc_component_driver davinci_mcasp_component = {
1172static struct davinci_mcasp_pdata dm646x_mcasp_pdata = { 1159static struct davinci_mcasp_pdata dm646x_mcasp_pdata = {
1173 .tx_dma_offset = 0x400, 1160 .tx_dma_offset = 0x400,
1174 .rx_dma_offset = 0x400, 1161 .rx_dma_offset = 0x400,
1175 .asp_chan_q = EVENTQ_0,
1176 .version = MCASP_VERSION_1, 1162 .version = MCASP_VERSION_1,
1177}; 1163};
1178 1164
1179static struct davinci_mcasp_pdata da830_mcasp_pdata = { 1165static struct davinci_mcasp_pdata da830_mcasp_pdata = {
1180 .tx_dma_offset = 0x2000, 1166 .tx_dma_offset = 0x2000,
1181 .rx_dma_offset = 0x2000, 1167 .rx_dma_offset = 0x2000,
1182 .asp_chan_q = EVENTQ_0,
1183 .version = MCASP_VERSION_2, 1168 .version = MCASP_VERSION_2,
1184}; 1169};
1185 1170
1186static struct davinci_mcasp_pdata am33xx_mcasp_pdata = { 1171static struct davinci_mcasp_pdata am33xx_mcasp_pdata = {
1187 .tx_dma_offset = 0, 1172 .tx_dma_offset = 0,
1188 .rx_dma_offset = 0, 1173 .rx_dma_offset = 0,
1189 .asp_chan_q = EVENTQ_0,
1190 .version = MCASP_VERSION_3, 1174 .version = MCASP_VERSION_3,
1191}; 1175};
1192 1176
1193static struct davinci_mcasp_pdata dra7_mcasp_pdata = { 1177static struct davinci_mcasp_pdata dra7_mcasp_pdata = {
1194 .tx_dma_offset = 0x200, 1178 .tx_dma_offset = 0x200,
1195 .rx_dma_offset = 0x284, 1179 .rx_dma_offset = 0x284,
1196 .asp_chan_q = EVENTQ_0,
1197 .version = MCASP_VERSION_4, 1180 .version = MCASP_VERSION_4,
1198}; 1181};
1199 1182
@@ -1370,12 +1353,12 @@ nodata:
1370 1353
1371static int davinci_mcasp_probe(struct platform_device *pdev) 1354static int davinci_mcasp_probe(struct platform_device *pdev)
1372{ 1355{
1373 struct davinci_pcm_dma_params *dma_params;
1374 struct snd_dmaengine_dai_dma_data *dma_data; 1356 struct snd_dmaengine_dai_dma_data *dma_data;
1375 struct resource *mem, *ioarea, *res, *dat; 1357 struct resource *mem, *ioarea, *res, *dat;
1376 struct davinci_mcasp_pdata *pdata; 1358 struct davinci_mcasp_pdata *pdata;
1377 struct davinci_mcasp *mcasp; 1359 struct davinci_mcasp *mcasp;
1378 char *irq_name; 1360 char *irq_name;
1361 int *dma;
1379 int irq; 1362 int irq;
1380 int ret; 1363 int ret;
1381 1364
@@ -1509,59 +1492,45 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1509 if (dat) 1492 if (dat)
1510 mcasp->dat_port = true; 1493 mcasp->dat_port = true;
1511 1494
1512 dma_params = &mcasp->dma_params[SNDRV_PCM_STREAM_PLAYBACK];
1513 dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK]; 1495 dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
1514 dma_params->asp_chan_q = pdata->asp_chan_q;
1515 dma_params->ram_chan_q = pdata->ram_chan_q;
1516 dma_params->sram_pool = pdata->sram_pool;
1517 dma_params->sram_size = pdata->sram_size_playback;
1518 if (dat) 1496 if (dat)
1519 dma_params->dma_addr = dat->start; 1497 dma_data->addr = dat->start;
1520 else 1498 else
1521 dma_params->dma_addr = mem->start + pdata->tx_dma_offset; 1499 dma_data->addr = mem->start + pdata->tx_dma_offset;
1522
1523 /* Unconditional dmaengine stuff */
1524 dma_data->addr = dma_params->dma_addr;
1525 1500
1501 dma = &mcasp->dma_request[SNDRV_PCM_STREAM_PLAYBACK];
1526 res = platform_get_resource(pdev, IORESOURCE_DMA, 0); 1502 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1527 if (res) 1503 if (res)
1528 dma_params->channel = res->start; 1504 *dma = res->start;
1529 else 1505 else
1530 dma_params->channel = pdata->tx_dma_channel; 1506 *dma = pdata->tx_dma_channel;
1531 1507
1532 /* dmaengine filter data for DT and non-DT boot */ 1508 /* dmaengine filter data for DT and non-DT boot */
1533 if (pdev->dev.of_node) 1509 if (pdev->dev.of_node)
1534 dma_data->filter_data = "tx"; 1510 dma_data->filter_data = "tx";
1535 else 1511 else
1536 dma_data->filter_data = &dma_params->channel; 1512 dma_data->filter_data = dma;
1537 1513
1538 /* RX is not valid in DIT mode */ 1514 /* RX is not valid in DIT mode */
1539 if (mcasp->op_mode != DAVINCI_MCASP_DIT_MODE) { 1515 if (mcasp->op_mode != DAVINCI_MCASP_DIT_MODE) {
1540 dma_params = &mcasp->dma_params[SNDRV_PCM_STREAM_CAPTURE];
1541 dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE]; 1516 dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE];
1542 dma_params->asp_chan_q = pdata->asp_chan_q;
1543 dma_params->ram_chan_q = pdata->ram_chan_q;
1544 dma_params->sram_pool = pdata->sram_pool;
1545 dma_params->sram_size = pdata->sram_size_capture;
1546 if (dat) 1517 if (dat)
1547 dma_params->dma_addr = dat->start; 1518 dma_data->addr = dat->start;
1548 else 1519 else
1549 dma_params->dma_addr = mem->start + pdata->rx_dma_offset; 1520 dma_data->addr = mem->start + pdata->rx_dma_offset;
1550
1551 /* Unconditional dmaengine stuff */
1552 dma_data->addr = dma_params->dma_addr;
1553 1521
1522 dma = &mcasp->dma_request[SNDRV_PCM_STREAM_CAPTURE];
1554 res = platform_get_resource(pdev, IORESOURCE_DMA, 1); 1523 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
1555 if (res) 1524 if (res)
1556 dma_params->channel = res->start; 1525 *dma = res->start;
1557 else 1526 else
1558 dma_params->channel = pdata->rx_dma_channel; 1527 *dma = pdata->rx_dma_channel;
1559 1528
1560 /* dmaengine filter data for DT and non-DT boot */ 1529 /* dmaengine filter data for DT and non-DT boot */
1561 if (pdev->dev.of_node) 1530 if (pdev->dev.of_node)
1562 dma_data->filter_data = "rx"; 1531 dma_data->filter_data = "rx";
1563 else 1532 else
1564 dma_data->filter_data = &dma_params->channel; 1533 dma_data->filter_data = dma;
1565 } 1534 }
1566 1535
1567 if (mcasp->version < MCASP_VERSION_3) { 1536 if (mcasp->version < MCASP_VERSION_3) {
@@ -1584,17 +1553,11 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1584 goto err; 1553 goto err;
1585 1554
1586 switch (mcasp->version) { 1555 switch (mcasp->version) {
1587#if IS_BUILTIN(CONFIG_SND_DAVINCI_SOC) || \
1588 (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \
1589 IS_MODULE(CONFIG_SND_DAVINCI_SOC))
1590 case MCASP_VERSION_1:
1591 case MCASP_VERSION_2:
1592 ret = davinci_soc_platform_register(&pdev->dev);
1593 break;
1594#endif
1595#if IS_BUILTIN(CONFIG_SND_EDMA_SOC) || \ 1556#if IS_BUILTIN(CONFIG_SND_EDMA_SOC) || \
1596 (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \ 1557 (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \
1597 IS_MODULE(CONFIG_SND_EDMA_SOC)) 1558 IS_MODULE(CONFIG_SND_EDMA_SOC))
1559 case MCASP_VERSION_1:
1560 case MCASP_VERSION_2:
1598 case MCASP_VERSION_3: 1561 case MCASP_VERSION_3:
1599 ret = edma_pcm_platform_register(&pdev->dev); 1562 ret = edma_pcm_platform_register(&pdev->dev);
1600 break; 1563 break;
diff --git a/sound/soc/davinci/davinci-pcm.c b/sound/soc/davinci/davinci-pcm.c
deleted file mode 100644
index 7809e9d935fc..000000000000
--- a/sound/soc/davinci/davinci-pcm.c
+++ /dev/null
@@ -1,861 +0,0 @@
1/*
2 * ALSA PCM interface for the TI DAVINCI processor
3 *
4 * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 * added SRAM ping/pong (C) 2008 Troy Kisky <troy.kisky@boundarydevices.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/platform_device.h>
16#include <linux/slab.h>
17#include <linux/dma-mapping.h>
18#include <linux/kernel.h>
19#include <linux/genalloc.h>
20#include <linux/platform_data/edma.h>
21
22#include <sound/core.h>
23#include <sound/pcm.h>
24#include <sound/pcm_params.h>
25#include <sound/soc.h>
26
27#include <asm/dma.h>
28
29#include "davinci-pcm.h"
30
31#ifdef DEBUG
32static void print_buf_info(int slot, char *name)
33{
34 struct edmacc_param p;
35 if (slot < 0)
36 return;
37 edma_read_slot(slot, &p);
38 printk(KERN_DEBUG "%s: 0x%x, opt=%x, src=%x, a_b_cnt=%x dst=%x\n",
39 name, slot, p.opt, p.src, p.a_b_cnt, p.dst);
40 printk(KERN_DEBUG " src_dst_bidx=%x link_bcntrld=%x src_dst_cidx=%x ccnt=%x\n",
41 p.src_dst_bidx, p.link_bcntrld, p.src_dst_cidx, p.ccnt);
42}
43#else
44static void print_buf_info(int slot, char *name)
45{
46}
47#endif
48
49static struct snd_pcm_hardware pcm_hardware_playback = {
50 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
51 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
52 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME|
53 SNDRV_PCM_INFO_BATCH),
54 .buffer_bytes_max = 128 * 1024,
55 .period_bytes_min = 32,
56 .period_bytes_max = 8 * 1024,
57 .periods_min = 16,
58 .periods_max = 255,
59 .fifo_size = 0,
60};
61
62static struct snd_pcm_hardware pcm_hardware_capture = {
63 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
64 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
65 SNDRV_PCM_INFO_PAUSE |
66 SNDRV_PCM_INFO_BATCH),
67 .buffer_bytes_max = 128 * 1024,
68 .period_bytes_min = 32,
69 .period_bytes_max = 8 * 1024,
70 .periods_min = 16,
71 .periods_max = 255,
72 .fifo_size = 0,
73};
74
75/*
76 * How ping/pong works....
77 *
78 * Playback:
79 * ram_params - copys 2*ping_size from start of SDRAM to iram,
80 * links to ram_link2
81 * ram_link2 - copys rest of SDRAM to iram in ping_size units,
82 * links to ram_link
83 * ram_link - copys entire SDRAM to iram in ping_size uints,
84 * links to self
85 *
86 * asp_params - same as asp_link[0]
87 * asp_link[0] - copys from lower half of iram to asp port
88 * links to asp_link[1], triggers iram copy event on completion
89 * asp_link[1] - copys from upper half of iram to asp port
90 * links to asp_link[0], triggers iram copy event on completion
91 * triggers interrupt only needed to let upper SOC levels update position
92 * in stream on completion
93 *
94 * When playback is started:
95 * ram_params started
96 * asp_params started
97 *
98 * Capture:
99 * ram_params - same as ram_link,
100 * links to ram_link
101 * ram_link - same as playback
102 * links to self
103 *
104 * asp_params - same as playback
105 * asp_link[0] - same as playback
106 * asp_link[1] - same as playback
107 *
108 * When capture is started:
109 * asp_params started
110 */
111struct davinci_runtime_data {
112 spinlock_t lock;
113 int period; /* current DMA period */
114 int asp_channel; /* Master DMA channel */
115 int asp_link[2]; /* asp parameter link channel, ping/pong */
116 struct davinci_pcm_dma_params *params; /* DMA params */
117 int ram_channel;
118 int ram_link;
119 int ram_link2;
120 struct edmacc_param asp_params;
121 struct edmacc_param ram_params;
122};
123
124static void davinci_pcm_period_elapsed(struct snd_pcm_substream *substream)
125{
126 struct davinci_runtime_data *prtd = substream->runtime->private_data;
127 struct snd_pcm_runtime *runtime = substream->runtime;
128
129 prtd->period++;
130 if (unlikely(prtd->period >= runtime->periods))
131 prtd->period = 0;
132}
133
134static void davinci_pcm_period_reset(struct snd_pcm_substream *substream)
135{
136 struct davinci_runtime_data *prtd = substream->runtime->private_data;
137
138 prtd->period = 0;
139}
140/*
141 * Not used with ping/pong
142 */
143static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream)
144{
145 struct davinci_runtime_data *prtd = substream->runtime->private_data;
146 struct snd_pcm_runtime *runtime = substream->runtime;
147 unsigned int period_size;
148 unsigned int dma_offset;
149 dma_addr_t dma_pos;
150 dma_addr_t src, dst;
151 unsigned short src_bidx, dst_bidx;
152 unsigned short src_cidx, dst_cidx;
153 unsigned int data_type;
154 unsigned short acnt;
155 unsigned int count;
156 unsigned int fifo_level;
157
158 period_size = snd_pcm_lib_period_bytes(substream);
159 dma_offset = prtd->period * period_size;
160 dma_pos = runtime->dma_addr + dma_offset;
161 fifo_level = prtd->params->fifo_level;
162
163 pr_debug("davinci_pcm: audio_set_dma_params_play channel = %d "
164 "dma_ptr = %x period_size=%x\n", prtd->asp_link[0], dma_pos,
165 period_size);
166
167 data_type = prtd->params->data_type;
168 count = period_size / data_type;
169 if (fifo_level)
170 count /= fifo_level;
171
172 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
173 src = dma_pos;
174 dst = prtd->params->dma_addr;
175 src_bidx = data_type;
176 dst_bidx = 4;
177 src_cidx = data_type * fifo_level;
178 dst_cidx = 0;
179 } else {
180 src = prtd->params->dma_addr;
181 dst = dma_pos;
182 src_bidx = 0;
183 dst_bidx = data_type;
184 src_cidx = 0;
185 dst_cidx = data_type * fifo_level;
186 }
187
188 acnt = prtd->params->acnt;
189 edma_set_src(prtd->asp_link[0], src, INCR, W8BIT);
190 edma_set_dest(prtd->asp_link[0], dst, INCR, W8BIT);
191
192 edma_set_src_index(prtd->asp_link[0], src_bidx, src_cidx);
193 edma_set_dest_index(prtd->asp_link[0], dst_bidx, dst_cidx);
194
195 if (!fifo_level)
196 edma_set_transfer_params(prtd->asp_link[0], acnt, count, 1, 0,
197 ASYNC);
198 else
199 edma_set_transfer_params(prtd->asp_link[0], acnt,
200 fifo_level,
201 count, fifo_level,
202 ABSYNC);
203}
204
205static void davinci_pcm_dma_irq(unsigned link, u16 ch_status, void *data)
206{
207 struct snd_pcm_substream *substream = data;
208 struct davinci_runtime_data *prtd = substream->runtime->private_data;
209
210 print_buf_info(prtd->ram_channel, "i ram_channel");
211 pr_debug("davinci_pcm: link=%d, status=0x%x\n", link, ch_status);
212
213 if (unlikely(ch_status != EDMA_DMA_COMPLETE))
214 return;
215
216 if (snd_pcm_running(substream)) {
217 spin_lock(&prtd->lock);
218 if (prtd->ram_channel < 0) {
219 /* No ping/pong must fix up link dma data*/
220 davinci_pcm_enqueue_dma(substream);
221 }
222 davinci_pcm_period_elapsed(substream);
223 spin_unlock(&prtd->lock);
224 snd_pcm_period_elapsed(substream);
225 }
226}
227
228#ifdef CONFIG_GENERIC_ALLOCATOR
229static int allocate_sram(struct snd_pcm_substream *substream,
230 struct gen_pool *sram_pool, unsigned size,
231 struct snd_pcm_hardware *ppcm)
232{
233 struct snd_dma_buffer *buf = &substream->dma_buffer;
234 struct snd_dma_buffer *iram_dma = NULL;
235 dma_addr_t iram_phys = 0;
236 void *iram_virt = NULL;
237
238 if (buf->private_data || !size)
239 return 0;
240
241 ppcm->period_bytes_max = size;
242 iram_virt = gen_pool_dma_alloc(sram_pool, size, &iram_phys);
243 if (!iram_virt)
244 goto exit1;
245 iram_dma = kzalloc(sizeof(*iram_dma), GFP_KERNEL);
246 if (!iram_dma)
247 goto exit2;
248 iram_dma->area = iram_virt;
249 iram_dma->addr = iram_phys;
250 memset(iram_dma->area, 0, size);
251 iram_dma->bytes = size;
252 buf->private_data = iram_dma;
253 return 0;
254exit2:
255 if (iram_virt)
256 gen_pool_free(sram_pool, (unsigned)iram_virt, size);
257exit1:
258 return -ENOMEM;
259}
260
261static void davinci_free_sram(struct snd_pcm_substream *substream,
262 struct snd_dma_buffer *iram_dma)
263{
264 struct davinci_runtime_data *prtd = substream->runtime->private_data;
265 struct gen_pool *sram_pool = prtd->params->sram_pool;
266
267 gen_pool_free(sram_pool, (unsigned) iram_dma->area, iram_dma->bytes);
268}
269#else
270static int allocate_sram(struct snd_pcm_substream *substream,
271 struct gen_pool *sram_pool, unsigned size,
272 struct snd_pcm_hardware *ppcm)
273{
274 return 0;
275}
276
277static void davinci_free_sram(struct snd_pcm_substream *substream,
278 struct snd_dma_buffer *iram_dma)
279{
280}
281#endif
282
283/*
284 * Only used with ping/pong.
285 * This is called after runtime->dma_addr, period_bytes and data_type are valid
286 */
287static int ping_pong_dma_setup(struct snd_pcm_substream *substream)
288{
289 unsigned short ram_src_cidx, ram_dst_cidx;
290 struct snd_pcm_runtime *runtime = substream->runtime;
291 struct davinci_runtime_data *prtd = runtime->private_data;
292 struct snd_dma_buffer *iram_dma =
293 (struct snd_dma_buffer *)substream->dma_buffer.private_data;
294 struct davinci_pcm_dma_params *params = prtd->params;
295 unsigned int data_type = params->data_type;
296 unsigned int acnt = params->acnt;
297 /* divide by 2 for ping/pong */
298 unsigned int ping_size = snd_pcm_lib_period_bytes(substream) >> 1;
299 unsigned int fifo_level = prtd->params->fifo_level;
300 unsigned int count;
301 if ((data_type == 0) || (data_type > 4)) {
302 printk(KERN_ERR "%s: data_type=%i\n", __func__, data_type);
303 return -EINVAL;
304 }
305 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
306 dma_addr_t asp_src_pong = iram_dma->addr + ping_size;
307 ram_src_cidx = ping_size;
308 ram_dst_cidx = -ping_size;
309 edma_set_src(prtd->asp_link[1], asp_src_pong, INCR, W8BIT);
310
311 edma_set_src_index(prtd->asp_link[0], data_type,
312 data_type * fifo_level);
313 edma_set_src_index(prtd->asp_link[1], data_type,
314 data_type * fifo_level);
315
316 edma_set_src(prtd->ram_link, runtime->dma_addr, INCR, W32BIT);
317 } else {
318 dma_addr_t asp_dst_pong = iram_dma->addr + ping_size;
319 ram_src_cidx = -ping_size;
320 ram_dst_cidx = ping_size;
321 edma_set_dest(prtd->asp_link[1], asp_dst_pong, INCR, W8BIT);
322
323 edma_set_dest_index(prtd->asp_link[0], data_type,
324 data_type * fifo_level);
325 edma_set_dest_index(prtd->asp_link[1], data_type,
326 data_type * fifo_level);
327
328 edma_set_dest(prtd->ram_link, runtime->dma_addr, INCR, W32BIT);
329 }
330
331 if (!fifo_level) {
332 count = ping_size / data_type;
333 edma_set_transfer_params(prtd->asp_link[0], acnt, count,
334 1, 0, ASYNC);
335 edma_set_transfer_params(prtd->asp_link[1], acnt, count,
336 1, 0, ASYNC);
337 } else {
338 count = ping_size / (data_type * fifo_level);
339 edma_set_transfer_params(prtd->asp_link[0], acnt, fifo_level,
340 count, fifo_level, ABSYNC);
341 edma_set_transfer_params(prtd->asp_link[1], acnt, fifo_level,
342 count, fifo_level, ABSYNC);
343 }
344
345 edma_set_src_index(prtd->ram_link, ping_size, ram_src_cidx);
346 edma_set_dest_index(prtd->ram_link, ping_size, ram_dst_cidx);
347 edma_set_transfer_params(prtd->ram_link, ping_size, 2,
348 runtime->periods, 2, ASYNC);
349
350 /* init master params */
351 edma_read_slot(prtd->asp_link[0], &prtd->asp_params);
352 edma_read_slot(prtd->ram_link, &prtd->ram_params);
353 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
354 struct edmacc_param p_ram;
355 /* Copy entire iram buffer before playback started */
356 prtd->ram_params.a_b_cnt = (1 << 16) | (ping_size << 1);
357 /* 0 dst_bidx */
358 prtd->ram_params.src_dst_bidx = (ping_size << 1);
359 /* 0 dst_cidx */
360 prtd->ram_params.src_dst_cidx = (ping_size << 1);
361 prtd->ram_params.ccnt = 1;
362
363 /* Skip 1st period */
364 edma_read_slot(prtd->ram_link, &p_ram);
365 p_ram.src += (ping_size << 1);
366 p_ram.ccnt -= 1;
367 edma_write_slot(prtd->ram_link2, &p_ram);
368 /*
369 * When 1st started, ram -> iram dma channel will fill the
370 * entire iram. Then, whenever a ping/pong asp buffer finishes,
371 * 1/2 iram will be filled.
372 */
373 prtd->ram_params.link_bcntrld =
374 EDMA_CHAN_SLOT(prtd->ram_link2) << 5;
375 }
376 return 0;
377}
378
379/* 1 asp tx or rx channel using 2 parameter channels
380 * 1 ram to/from iram channel using 1 parameter channel
381 *
382 * Playback
383 * ram copy channel kicks off first,
384 * 1st ram copy of entire iram buffer completion kicks off asp channel
385 * asp tcc always kicks off ram copy of 1/2 iram buffer
386 *
387 * Record
388 * asp channel starts, tcc kicks off ram copy
389 */
390static int request_ping_pong(struct snd_pcm_substream *substream,
391 struct davinci_runtime_data *prtd,
392 struct snd_dma_buffer *iram_dma)
393{
394 dma_addr_t asp_src_ping;
395 dma_addr_t asp_dst_ping;
396 int ret;
397 struct davinci_pcm_dma_params *params = prtd->params;
398
399 /* Request ram master channel */
400 ret = prtd->ram_channel = edma_alloc_channel(EDMA_CHANNEL_ANY,
401 davinci_pcm_dma_irq, substream,
402 prtd->params->ram_chan_q);
403 if (ret < 0)
404 goto exit1;
405
406 /* Request ram link channel */
407 ret = prtd->ram_link = edma_alloc_slot(
408 EDMA_CTLR(prtd->ram_channel), EDMA_SLOT_ANY);
409 if (ret < 0)
410 goto exit2;
411
412 ret = prtd->asp_link[1] = edma_alloc_slot(
413 EDMA_CTLR(prtd->asp_channel), EDMA_SLOT_ANY);
414 if (ret < 0)
415 goto exit3;
416
417 prtd->ram_link2 = -1;
418 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
419 ret = prtd->ram_link2 = edma_alloc_slot(
420 EDMA_CTLR(prtd->ram_channel), EDMA_SLOT_ANY);
421 if (ret < 0)
422 goto exit4;
423 }
424 /* circle ping-pong buffers */
425 edma_link(prtd->asp_link[0], prtd->asp_link[1]);
426 edma_link(prtd->asp_link[1], prtd->asp_link[0]);
427 /* circle ram buffers */
428 edma_link(prtd->ram_link, prtd->ram_link);
429
430 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
431 asp_src_ping = iram_dma->addr;
432 asp_dst_ping = params->dma_addr; /* fifo */
433 } else {
434 asp_src_ping = params->dma_addr; /* fifo */
435 asp_dst_ping = iram_dma->addr;
436 }
437 /* ping */
438 edma_set_src(prtd->asp_link[0], asp_src_ping, INCR, W16BIT);
439 edma_set_dest(prtd->asp_link[0], asp_dst_ping, INCR, W16BIT);
440 edma_set_src_index(prtd->asp_link[0], 0, 0);
441 edma_set_dest_index(prtd->asp_link[0], 0, 0);
442
443 edma_read_slot(prtd->asp_link[0], &prtd->asp_params);
444 prtd->asp_params.opt &= ~(TCCMODE | EDMA_TCC(0x3f) | TCINTEN);
445 prtd->asp_params.opt |= TCCHEN |
446 EDMA_TCC(prtd->ram_channel & 0x3f);
447 edma_write_slot(prtd->asp_link[0], &prtd->asp_params);
448
449 /* pong */
450 edma_set_src(prtd->asp_link[1], asp_src_ping, INCR, W16BIT);
451 edma_set_dest(prtd->asp_link[1], asp_dst_ping, INCR, W16BIT);
452 edma_set_src_index(prtd->asp_link[1], 0, 0);
453 edma_set_dest_index(prtd->asp_link[1], 0, 0);
454
455 edma_read_slot(prtd->asp_link[1], &prtd->asp_params);
456 prtd->asp_params.opt &= ~(TCCMODE | EDMA_TCC(0x3f));
457 /* interrupt after every pong completion */
458 prtd->asp_params.opt |= TCINTEN | TCCHEN |
459 EDMA_TCC(prtd->ram_channel & 0x3f);
460 edma_write_slot(prtd->asp_link[1], &prtd->asp_params);
461
462 /* ram */
463 edma_set_src(prtd->ram_link, iram_dma->addr, INCR, W32BIT);
464 edma_set_dest(prtd->ram_link, iram_dma->addr, INCR, W32BIT);
465 pr_debug("%s: audio dma channels/slots in use for ram:%u %u %u,"
466 "for asp:%u %u %u\n", __func__,
467 prtd->ram_channel, prtd->ram_link, prtd->ram_link2,
468 prtd->asp_channel, prtd->asp_link[0],
469 prtd->asp_link[1]);
470 return 0;
471exit4:
472 edma_free_channel(prtd->asp_link[1]);
473 prtd->asp_link[1] = -1;
474exit3:
475 edma_free_channel(prtd->ram_link);
476 prtd->ram_link = -1;
477exit2:
478 edma_free_channel(prtd->ram_channel);
479 prtd->ram_channel = -1;
480exit1:
481 return ret;
482}
483
484static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
485{
486 struct snd_dma_buffer *iram_dma;
487 struct davinci_runtime_data *prtd = substream->runtime->private_data;
488 struct davinci_pcm_dma_params *params = prtd->params;
489 int ret;
490
491 if (!params)
492 return -ENODEV;
493
494 /* Request asp master DMA channel */
495 ret = prtd->asp_channel = edma_alloc_channel(params->channel,
496 davinci_pcm_dma_irq, substream,
497 prtd->params->asp_chan_q);
498 if (ret < 0)
499 goto exit1;
500
501 /* Request asp link channels */
502 ret = prtd->asp_link[0] = edma_alloc_slot(
503 EDMA_CTLR(prtd->asp_channel), EDMA_SLOT_ANY);
504 if (ret < 0)
505 goto exit2;
506
507 iram_dma = (struct snd_dma_buffer *)substream->dma_buffer.private_data;
508 if (iram_dma) {
509 if (request_ping_pong(substream, prtd, iram_dma) == 0)
510 return 0;
511 printk(KERN_WARNING "%s: dma channel allocation failed,"
512 "not using sram\n", __func__);
513 }
514
515 /* Issue transfer completion IRQ when the channel completes a
516 * transfer, then always reload from the same slot (by a kind
517 * of loopback link). The completion IRQ handler will update
518 * the reload slot with a new buffer.
519 *
520 * REVISIT save p_ram here after setting up everything except
521 * the buffer and its length (ccnt) ... use it as a template
522 * so davinci_pcm_enqueue_dma() takes less time in IRQ.
523 */
524 edma_read_slot(prtd->asp_link[0], &prtd->asp_params);
525 prtd->asp_params.opt |= TCINTEN |
526 EDMA_TCC(EDMA_CHAN_SLOT(prtd->asp_channel));
527 prtd->asp_params.link_bcntrld = EDMA_CHAN_SLOT(prtd->asp_link[0]) << 5;
528 edma_write_slot(prtd->asp_link[0], &prtd->asp_params);
529 return 0;
530exit2:
531 edma_free_channel(prtd->asp_channel);
532 prtd->asp_channel = -1;
533exit1:
534 return ret;
535}
536
537static int davinci_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
538{
539 struct davinci_runtime_data *prtd = substream->runtime->private_data;
540 int ret = 0;
541
542 spin_lock(&prtd->lock);
543
544 switch (cmd) {
545 case SNDRV_PCM_TRIGGER_START:
546 edma_start(prtd->asp_channel);
547 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
548 prtd->ram_channel >= 0) {
549 /* copy 1st iram buffer */
550 edma_start(prtd->ram_channel);
551 }
552 break;
553 case SNDRV_PCM_TRIGGER_RESUME:
554 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
555 edma_resume(prtd->asp_channel);
556 break;
557 case SNDRV_PCM_TRIGGER_STOP:
558 case SNDRV_PCM_TRIGGER_SUSPEND:
559 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
560 edma_pause(prtd->asp_channel);
561 break;
562 default:
563 ret = -EINVAL;
564 break;
565 }
566
567 spin_unlock(&prtd->lock);
568
569 return ret;
570}
571
572static int davinci_pcm_prepare(struct snd_pcm_substream *substream)
573{
574 struct davinci_runtime_data *prtd = substream->runtime->private_data;
575
576 davinci_pcm_period_reset(substream);
577 if (prtd->ram_channel >= 0) {
578 int ret = ping_pong_dma_setup(substream);
579 if (ret < 0)
580 return ret;
581
582 edma_write_slot(prtd->ram_channel, &prtd->ram_params);
583 edma_write_slot(prtd->asp_channel, &prtd->asp_params);
584
585 print_buf_info(prtd->ram_channel, "ram_channel");
586 print_buf_info(prtd->ram_link, "ram_link");
587 print_buf_info(prtd->ram_link2, "ram_link2");
588 print_buf_info(prtd->asp_channel, "asp_channel");
589 print_buf_info(prtd->asp_link[0], "asp_link[0]");
590 print_buf_info(prtd->asp_link[1], "asp_link[1]");
591
592 /*
593 * There is a phase offset of 2 periods between the position
594 * used by dma setup and the position reported in the pointer
595 * function.
596 *
597 * The phase offset, when not using ping-pong buffers, is due to
598 * the two consecutive calls to davinci_pcm_enqueue_dma() below.
599 *
600 * Whereas here, with ping-pong buffers, the phase is due to
601 * there being an entire buffer transfer complete before the
602 * first dma completion event triggers davinci_pcm_dma_irq().
603 */
604 davinci_pcm_period_elapsed(substream);
605 davinci_pcm_period_elapsed(substream);
606
607 return 0;
608 }
609 davinci_pcm_enqueue_dma(substream);
610 davinci_pcm_period_elapsed(substream);
611
612 /* Copy self-linked parameter RAM entry into master channel */
613 edma_read_slot(prtd->asp_link[0], &prtd->asp_params);
614 edma_write_slot(prtd->asp_channel, &prtd->asp_params);
615 davinci_pcm_enqueue_dma(substream);
616 davinci_pcm_period_elapsed(substream);
617
618 return 0;
619}
620
621static snd_pcm_uframes_t
622davinci_pcm_pointer(struct snd_pcm_substream *substream)
623{
624 struct snd_pcm_runtime *runtime = substream->runtime;
625 struct davinci_runtime_data *prtd = runtime->private_data;
626 unsigned int offset;
627 int asp_count;
628 unsigned int period_size = snd_pcm_lib_period_bytes(substream);
629
630 /*
631 * There is a phase offset of 2 periods between the position used by dma
632 * setup and the position reported in the pointer function. Either +2 in
633 * the dma setup or -2 here in the pointer function (with wrapping,
634 * both) accounts for this offset -- choose the latter since it makes
635 * the first-time setup clearer.
636 */
637 spin_lock(&prtd->lock);
638 asp_count = prtd->period - 2;
639 spin_unlock(&prtd->lock);
640
641 if (asp_count < 0)
642 asp_count += runtime->periods;
643 asp_count *= period_size;
644
645 offset = bytes_to_frames(runtime, asp_count);
646 if (offset >= runtime->buffer_size)
647 offset = 0;
648
649 return offset;
650}
651
652static int davinci_pcm_open(struct snd_pcm_substream *substream)
653{
654 struct snd_pcm_runtime *runtime = substream->runtime;
655 struct davinci_runtime_data *prtd;
656 struct snd_pcm_hardware *ppcm;
657 int ret = 0;
658 struct snd_soc_pcm_runtime *rtd = substream->private_data;
659 struct davinci_pcm_dma_params *pa;
660 struct davinci_pcm_dma_params *params;
661
662 pa = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
663 if (!pa)
664 return -ENODEV;
665 params = &pa[substream->stream];
666
667 ppcm = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
668 &pcm_hardware_playback : &pcm_hardware_capture;
669 allocate_sram(substream, params->sram_pool, params->sram_size, ppcm);
670 snd_soc_set_runtime_hwparams(substream, ppcm);
671 /* ensure that buffer size is a multiple of period size */
672 ret = snd_pcm_hw_constraint_integer(runtime,
673 SNDRV_PCM_HW_PARAM_PERIODS);
674 if (ret < 0)
675 return ret;
676
677 prtd = kzalloc(sizeof(struct davinci_runtime_data), GFP_KERNEL);
678 if (prtd == NULL)
679 return -ENOMEM;
680
681 spin_lock_init(&prtd->lock);
682 prtd->params = params;
683 prtd->asp_channel = -1;
684 prtd->asp_link[0] = prtd->asp_link[1] = -1;
685 prtd->ram_channel = -1;
686 prtd->ram_link = -1;
687 prtd->ram_link2 = -1;
688
689 runtime->private_data = prtd;
690
691 ret = davinci_pcm_dma_request(substream);
692 if (ret) {
693 printk(KERN_ERR "davinci_pcm: Failed to get dma channels\n");
694 kfree(prtd);
695 }
696
697 return ret;
698}
699
700static int davinci_pcm_close(struct snd_pcm_substream *substream)
701{
702 struct snd_pcm_runtime *runtime = substream->runtime;
703 struct davinci_runtime_data *prtd = runtime->private_data;
704
705 if (prtd->ram_channel >= 0)
706 edma_stop(prtd->ram_channel);
707 if (prtd->asp_channel >= 0)
708 edma_stop(prtd->asp_channel);
709 if (prtd->asp_link[0] >= 0)
710 edma_unlink(prtd->asp_link[0]);
711 if (prtd->asp_link[1] >= 0)
712 edma_unlink(prtd->asp_link[1]);
713 if (prtd->ram_link >= 0)
714 edma_unlink(prtd->ram_link);
715
716 if (prtd->asp_link[0] >= 0)
717 edma_free_slot(prtd->asp_link[0]);
718 if (prtd->asp_link[1] >= 0)
719 edma_free_slot(prtd->asp_link[1]);
720 if (prtd->asp_channel >= 0)
721 edma_free_channel(prtd->asp_channel);
722 if (prtd->ram_link >= 0)
723 edma_free_slot(prtd->ram_link);
724 if (prtd->ram_link2 >= 0)
725 edma_free_slot(prtd->ram_link2);
726 if (prtd->ram_channel >= 0)
727 edma_free_channel(prtd->ram_channel);
728
729 kfree(prtd);
730
731 return 0;
732}
733
734static int davinci_pcm_hw_params(struct snd_pcm_substream *substream,
735 struct snd_pcm_hw_params *hw_params)
736{
737 return snd_pcm_lib_malloc_pages(substream,
738 params_buffer_bytes(hw_params));
739}
740
741static int davinci_pcm_hw_free(struct snd_pcm_substream *substream)
742{
743 return snd_pcm_lib_free_pages(substream);
744}
745
746static int davinci_pcm_mmap(struct snd_pcm_substream *substream,
747 struct vm_area_struct *vma)
748{
749 struct snd_pcm_runtime *runtime = substream->runtime;
750
751 return dma_mmap_writecombine(substream->pcm->card->dev, vma,
752 runtime->dma_area,
753 runtime->dma_addr,
754 runtime->dma_bytes);
755}
756
757static struct snd_pcm_ops davinci_pcm_ops = {
758 .open = davinci_pcm_open,
759 .close = davinci_pcm_close,
760 .ioctl = snd_pcm_lib_ioctl,
761 .hw_params = davinci_pcm_hw_params,
762 .hw_free = davinci_pcm_hw_free,
763 .prepare = davinci_pcm_prepare,
764 .trigger = davinci_pcm_trigger,
765 .pointer = davinci_pcm_pointer,
766 .mmap = davinci_pcm_mmap,
767};
768
769static int davinci_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream,
770 size_t size)
771{
772 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
773 struct snd_dma_buffer *buf = &substream->dma_buffer;
774
775 buf->dev.type = SNDRV_DMA_TYPE_DEV;
776 buf->dev.dev = pcm->card->dev;
777 buf->private_data = NULL;
778 buf->area = dma_alloc_writecombine(pcm->card->dev, size,
779 &buf->addr, GFP_KERNEL);
780
781 pr_debug("davinci_pcm: preallocate_dma_buffer: area=%p, addr=%p, "
782 "size=%d\n", (void *) buf->area, (void *) buf->addr, size);
783
784 if (!buf->area)
785 return -ENOMEM;
786
787 buf->bytes = size;
788 return 0;
789}
790
791static void davinci_pcm_free(struct snd_pcm *pcm)
792{
793 struct snd_pcm_substream *substream;
794 struct snd_dma_buffer *buf;
795 int stream;
796
797 for (stream = 0; stream < 2; stream++) {
798 struct snd_dma_buffer *iram_dma;
799 substream = pcm->streams[stream].substream;
800 if (!substream)
801 continue;
802
803 buf = &substream->dma_buffer;
804 if (!buf->area)
805 continue;
806
807 dma_free_writecombine(pcm->card->dev, buf->bytes,
808 buf->area, buf->addr);
809 buf->area = NULL;
810 iram_dma = buf->private_data;
811 if (iram_dma) {
812 davinci_free_sram(substream, iram_dma);
813 kfree(iram_dma);
814 }
815 }
816}
817
818static int davinci_pcm_new(struct snd_soc_pcm_runtime *rtd)
819{
820 struct snd_card *card = rtd->card->snd_card;
821 struct snd_pcm *pcm = rtd->pcm;
822 int ret;
823
824 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
825 if (ret)
826 return ret;
827
828 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
829 ret = davinci_pcm_preallocate_dma_buffer(pcm,
830 SNDRV_PCM_STREAM_PLAYBACK,
831 pcm_hardware_playback.buffer_bytes_max);
832 if (ret)
833 return ret;
834 }
835
836 if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
837 ret = davinci_pcm_preallocate_dma_buffer(pcm,
838 SNDRV_PCM_STREAM_CAPTURE,
839 pcm_hardware_capture.buffer_bytes_max);
840 if (ret)
841 return ret;
842 }
843
844 return 0;
845}
846
847static struct snd_soc_platform_driver davinci_soc_platform = {
848 .ops = &davinci_pcm_ops,
849 .pcm_new = davinci_pcm_new,
850 .pcm_free = davinci_pcm_free,
851};
852
853int davinci_soc_platform_register(struct device *dev)
854{
855 return devm_snd_soc_register_platform(dev, &davinci_soc_platform);
856}
857EXPORT_SYMBOL_GPL(davinci_soc_platform_register);
858
859MODULE_AUTHOR("Vladimir Barinov");
860MODULE_DESCRIPTION("TI DAVINCI PCM DMA module");
861MODULE_LICENSE("GPL");
diff --git a/sound/soc/davinci/davinci-pcm.h b/sound/soc/davinci/davinci-pcm.h
deleted file mode 100644
index 0fe2346a9aa2..000000000000
--- a/sound/soc/davinci/davinci-pcm.h
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 * ALSA PCM interface for the TI DAVINCI processor
3 *
4 * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _DAVINCI_PCM_H
13#define _DAVINCI_PCM_H
14
15#include <linux/genalloc.h>
16#include <linux/platform_data/davinci_asp.h>
17#include <linux/platform_data/edma.h>
18
19struct davinci_pcm_dma_params {
20 int channel; /* sync dma channel ID */
21 unsigned short acnt;
22 dma_addr_t dma_addr; /* device physical address for DMA */
23 unsigned sram_size;
24 struct gen_pool *sram_pool; /* SRAM gen_pool for ping pong */
25 enum dma_event_q asp_chan_q; /* event queue number for ASP channel */
26 enum dma_event_q ram_chan_q; /* event queue number for RAM channel */
27 unsigned char data_type; /* xfer data type */
28 unsigned char convert_mono_stereo;
29 unsigned int fifo_level;
30};
31
32#if IS_ENABLED(CONFIG_SND_DAVINCI_SOC)
33int davinci_soc_platform_register(struct device *dev);
34#else
35static inline int davinci_soc_platform_register(struct device *dev)
36{
37 return 0;
38}
39#endif /* CONFIG_SND_DAVINCI_SOC */
40
41#endif
diff --git a/sound/soc/davinci/davinci-vcif.c b/sound/soc/davinci/davinci-vcif.c
index 5bee04279ebe..fabd05f24aeb 100644
--- a/sound/soc/davinci/davinci-vcif.c
+++ b/sound/soc/davinci/davinci-vcif.c
@@ -33,8 +33,9 @@
33#include <sound/pcm_params.h> 33#include <sound/pcm_params.h>
34#include <sound/initval.h> 34#include <sound/initval.h>
35#include <sound/soc.h> 35#include <sound/soc.h>
36#include <sound/dmaengine_pcm.h>
36 37
37#include "davinci-pcm.h" 38#include "edma-pcm.h"
38#include "davinci-i2s.h" 39#include "davinci-i2s.h"
39 40
40#define MOD_REG_BIT(val, mask, set) do { \ 41#define MOD_REG_BIT(val, mask, set) do { \
@@ -47,7 +48,8 @@
47 48
48struct davinci_vcif_dev { 49struct davinci_vcif_dev {
49 struct davinci_vc *davinci_vc; 50 struct davinci_vc *davinci_vc;
50 struct davinci_pcm_dma_params dma_params[2]; 51 struct snd_dmaengine_dai_dma_data dma_data[2];
52 int dma_request[2];
51}; 53};
52 54
53static void davinci_vcif_start(struct snd_pcm_substream *substream) 55static void davinci_vcif_start(struct snd_pcm_substream *substream)
@@ -93,8 +95,6 @@ static int davinci_vcif_hw_params(struct snd_pcm_substream *substream,
93{ 95{
94 struct davinci_vcif_dev *davinci_vcif_dev = snd_soc_dai_get_drvdata(dai); 96 struct davinci_vcif_dev *davinci_vcif_dev = snd_soc_dai_get_drvdata(dai);
95 struct davinci_vc *davinci_vc = davinci_vcif_dev->davinci_vc; 97 struct davinci_vc *davinci_vc = davinci_vcif_dev->davinci_vc;
96 struct davinci_pcm_dma_params *dma_params =
97 &davinci_vcif_dev->dma_params[substream->stream];
98 u32 w; 98 u32 w;
99 99
100 /* Restart the codec before setup */ 100 /* Restart the codec before setup */
@@ -113,16 +113,12 @@ static int davinci_vcif_hw_params(struct snd_pcm_substream *substream,
113 /* Determine xfer data type */ 113 /* Determine xfer data type */
114 switch (params_format(params)) { 114 switch (params_format(params)) {
115 case SNDRV_PCM_FORMAT_U8: 115 case SNDRV_PCM_FORMAT_U8:
116 dma_params->data_type = 0;
117
118 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_BITS_8 | 116 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_BITS_8 |
119 DAVINCI_VC_CTRL_RD_UNSIGNED | 117 DAVINCI_VC_CTRL_RD_UNSIGNED |
120 DAVINCI_VC_CTRL_WD_BITS_8 | 118 DAVINCI_VC_CTRL_WD_BITS_8 |
121 DAVINCI_VC_CTRL_WD_UNSIGNED, 1); 119 DAVINCI_VC_CTRL_WD_UNSIGNED, 1);
122 break; 120 break;
123 case SNDRV_PCM_FORMAT_S8: 121 case SNDRV_PCM_FORMAT_S8:
124 dma_params->data_type = 1;
125
126 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_BITS_8 | 122 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_BITS_8 |
127 DAVINCI_VC_CTRL_WD_BITS_8, 1); 123 DAVINCI_VC_CTRL_WD_BITS_8, 1);
128 124
@@ -130,8 +126,6 @@ static int davinci_vcif_hw_params(struct snd_pcm_substream *substream,
130 DAVINCI_VC_CTRL_WD_UNSIGNED, 0); 126 DAVINCI_VC_CTRL_WD_UNSIGNED, 0);
131 break; 127 break;
132 case SNDRV_PCM_FORMAT_S16_LE: 128 case SNDRV_PCM_FORMAT_S16_LE:
133 dma_params->data_type = 2;
134
135 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_BITS_8 | 129 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_BITS_8 |
136 DAVINCI_VC_CTRL_RD_UNSIGNED | 130 DAVINCI_VC_CTRL_RD_UNSIGNED |
137 DAVINCI_VC_CTRL_WD_BITS_8 | 131 DAVINCI_VC_CTRL_WD_BITS_8 |
@@ -142,8 +136,6 @@ static int davinci_vcif_hw_params(struct snd_pcm_substream *substream,
142 return -EINVAL; 136 return -EINVAL;
143 } 137 }
144 138
145 dma_params->acnt = dma_params->data_type;
146
147 writel(w, davinci_vc->base + DAVINCI_VC_CTRL); 139 writel(w, davinci_vc->base + DAVINCI_VC_CTRL);
148 140
149 return 0; 141 return 0;
@@ -172,24 +164,25 @@ static int davinci_vcif_trigger(struct snd_pcm_substream *substream, int cmd,
172 return ret; 164 return ret;
173} 165}
174 166
175static int davinci_vcif_startup(struct snd_pcm_substream *substream,
176 struct snd_soc_dai *dai)
177{
178 struct davinci_vcif_dev *dev = snd_soc_dai_get_drvdata(dai);
179
180 snd_soc_dai_set_dma_data(dai, substream, dev->dma_params);
181 return 0;
182}
183
184#define DAVINCI_VCIF_RATES SNDRV_PCM_RATE_8000_48000 167#define DAVINCI_VCIF_RATES SNDRV_PCM_RATE_8000_48000
185 168
186static const struct snd_soc_dai_ops davinci_vcif_dai_ops = { 169static const struct snd_soc_dai_ops davinci_vcif_dai_ops = {
187 .startup = davinci_vcif_startup,
188 .trigger = davinci_vcif_trigger, 170 .trigger = davinci_vcif_trigger,
189 .hw_params = davinci_vcif_hw_params, 171 .hw_params = davinci_vcif_hw_params,
190}; 172};
191 173
174static int davinci_vcif_dai_probe(struct snd_soc_dai *dai)
175{
176 struct davinci_vcif_dev *dev = snd_soc_dai_get_drvdata(dai);
177
178 dai->playback_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
179 dai->capture_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_CAPTURE];
180
181 return 0;
182}
183
192static struct snd_soc_dai_driver davinci_vcif_dai = { 184static struct snd_soc_dai_driver davinci_vcif_dai = {
185 .probe = davinci_vcif_dai_probe,
193 .playback = { 186 .playback = {
194 .channels_min = 1, 187 .channels_min = 1,
195 .channels_max = 2, 188 .channels_max = 2,
@@ -225,16 +218,16 @@ static int davinci_vcif_probe(struct platform_device *pdev)
225 218
226 /* DMA tx params */ 219 /* DMA tx params */
227 davinci_vcif_dev->davinci_vc = davinci_vc; 220 davinci_vcif_dev->davinci_vc = davinci_vc;
228 davinci_vcif_dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].channel = 221 davinci_vcif_dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].filter_data =
229 davinci_vc->davinci_vcif.dma_tx_channel; 222 &davinci_vc->davinci_vcif.dma_tx_channel;
230 davinci_vcif_dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].dma_addr = 223 davinci_vcif_dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
231 davinci_vc->davinci_vcif.dma_tx_addr; 224 davinci_vc->davinci_vcif.dma_tx_addr;
232 225
233 /* DMA rx params */ 226 /* DMA rx params */
234 davinci_vcif_dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].channel = 227 davinci_vcif_dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].filter_data =
235 davinci_vc->davinci_vcif.dma_rx_channel; 228 &davinci_vc->davinci_vcif.dma_rx_channel;
236 davinci_vcif_dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].dma_addr = 229 davinci_vcif_dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
237 davinci_vc->davinci_vcif.dma_rx_addr; 230 davinci_vc->davinci_vcif.dma_rx_addr;
238 231
239 dev_set_drvdata(&pdev->dev, davinci_vcif_dev); 232 dev_set_drvdata(&pdev->dev, davinci_vcif_dev);
240 233
@@ -245,7 +238,7 @@ static int davinci_vcif_probe(struct platform_device *pdev)
245 return ret; 238 return ret;
246 } 239 }
247 240
248 ret = davinci_soc_platform_register(&pdev->dev); 241 ret = edma_pcm_platform_register(&pdev->dev);
249 if (ret) { 242 if (ret) {
250 dev_err(&pdev->dev, "register PCM failed: %d\n", ret); 243 dev_err(&pdev->dev, "register PCM failed: %d\n", ret);
251 snd_soc_unregister_component(&pdev->dev); 244 snd_soc_unregister_component(&pdev->dev);
diff --git a/sound/soc/fsl/fsl-asoc-card.c b/sound/soc/fsl/fsl-asoc-card.c
index 3f6959c8e2f7..de438871040b 100644
--- a/sound/soc/fsl/fsl-asoc-card.c
+++ b/sound/soc/fsl/fsl-asoc-card.c
@@ -512,6 +512,12 @@ static int fsl_asoc_card_probe(struct platform_device *pdev)
512 memcpy(priv->dai_link, fsl_asoc_card_dai, 512 memcpy(priv->dai_link, fsl_asoc_card_dai,
513 sizeof(struct snd_soc_dai_link) * ARRAY_SIZE(priv->dai_link)); 513 sizeof(struct snd_soc_dai_link) * ARRAY_SIZE(priv->dai_link));
514 514
515 ret = snd_soc_of_parse_audio_routing(&priv->card, "audio-routing");
516 if (ret) {
517 dev_err(&pdev->dev, "failed to parse audio-routing: %d\n", ret);
518 goto asrc_fail;
519 }
520
515 /* Normal DAI Link */ 521 /* Normal DAI Link */
516 priv->dai_link[0].cpu_of_node = cpu_np; 522 priv->dai_link[0].cpu_of_node = cpu_np;
517 priv->dai_link[0].codec_of_node = codec_np; 523 priv->dai_link[0].codec_of_node = codec_np;
diff --git a/sound/soc/fsl/imx-es8328.c b/sound/soc/fsl/imx-es8328.c
index f8cf10e16ce9..20e7400e2611 100644
--- a/sound/soc/fsl/imx-es8328.c
+++ b/sound/soc/fsl/imx-es8328.c
@@ -53,9 +53,9 @@ static int imx_es8328_dai_init(struct snd_soc_pcm_runtime *rtd)
53 53
54 /* Headphone jack detection */ 54 /* Headphone jack detection */
55 if (gpio_is_valid(data->jack_gpio)) { 55 if (gpio_is_valid(data->jack_gpio)) {
56 ret = snd_soc_jack_new(rtd->codec, "Headphone", 56 ret = snd_soc_card_jack_new(rtd->card, "Headphone",
57 SND_JACK_HEADPHONE | SND_JACK_BTN_0, 57 SND_JACK_HEADPHONE | SND_JACK_BTN_0,
58 &headset_jack); 58 &headset_jack, NULL, 0);
59 if (ret) 59 if (ret)
60 return ret; 60 return ret;
61 61
diff --git a/sound/soc/fsl/wm1133-ev1.c b/sound/soc/fsl/wm1133-ev1.c
index a958937ab405..0653aa83c927 100644
--- a/sound/soc/fsl/wm1133-ev1.c
+++ b/sound/soc/fsl/wm1133-ev1.c
@@ -205,16 +205,14 @@ static int wm1133_ev1_init(struct snd_soc_pcm_runtime *rtd)
205 struct snd_soc_dapm_context *dapm = &codec->dapm; 205 struct snd_soc_dapm_context *dapm = &codec->dapm;
206 206
207 /* Headphone jack detection */ 207 /* Headphone jack detection */
208 snd_soc_jack_new(codec, "Headphone", SND_JACK_HEADPHONE, &hp_jack); 208 snd_soc_card_jack_new(rtd->card, "Headphone", SND_JACK_HEADPHONE,
209 snd_soc_jack_add_pins(&hp_jack, ARRAY_SIZE(hp_jack_pins), 209 &hp_jack, hp_jack_pins, ARRAY_SIZE(hp_jack_pins));
210 hp_jack_pins);
211 wm8350_hp_jack_detect(codec, WM8350_JDR, &hp_jack, SND_JACK_HEADPHONE); 210 wm8350_hp_jack_detect(codec, WM8350_JDR, &hp_jack, SND_JACK_HEADPHONE);
212 211
213 /* Microphone jack detection */ 212 /* Microphone jack detection */
214 snd_soc_jack_new(codec, "Microphone", 213 snd_soc_card_jack_new(rtd->card, "Microphone",
215 SND_JACK_MICROPHONE | SND_JACK_BTN_0, &mic_jack); 214 SND_JACK_MICROPHONE | SND_JACK_BTN_0, &mic_jack,
216 snd_soc_jack_add_pins(&mic_jack, ARRAY_SIZE(mic_jack_pins), 215 mic_jack_pins, ARRAY_SIZE(mic_jack_pins));
217 mic_jack_pins);
218 wm8350_mic_jack_detect(codec, &mic_jack, SND_JACK_MICROPHONE, 216 wm8350_mic_jack_detect(codec, &mic_jack, SND_JACK_MICROPHONE,
219 SND_JACK_BTN_0); 217 SND_JACK_BTN_0);
220 218
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index fb550b5869d2..c49a408fc7a6 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -176,11 +176,11 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
176 return ret; 176 return ret;
177 177
178 if (gpio_is_valid(priv->gpio_hp_det)) { 178 if (gpio_is_valid(priv->gpio_hp_det)) {
179 snd_soc_jack_new(codec->codec, "Headphones", SND_JACK_HEADPHONE, 179 snd_soc_card_jack_new(rtd->card, "Headphones",
180 &simple_card_hp_jack); 180 SND_JACK_HEADPHONE,
181 snd_soc_jack_add_pins(&simple_card_hp_jack, 181 &simple_card_hp_jack,
182 ARRAY_SIZE(simple_card_hp_jack_pins), 182 simple_card_hp_jack_pins,
183 simple_card_hp_jack_pins); 183 ARRAY_SIZE(simple_card_hp_jack_pins));
184 184
185 simple_card_hp_jack_gpio.gpio = priv->gpio_hp_det; 185 simple_card_hp_jack_gpio.gpio = priv->gpio_hp_det;
186 simple_card_hp_jack_gpio.invert = priv->gpio_hp_det_invert; 186 simple_card_hp_jack_gpio.invert = priv->gpio_hp_det_invert;
@@ -189,11 +189,11 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
189 } 189 }
190 190
191 if (gpio_is_valid(priv->gpio_mic_det)) { 191 if (gpio_is_valid(priv->gpio_mic_det)) {
192 snd_soc_jack_new(codec->codec, "Mic Jack", SND_JACK_MICROPHONE, 192 snd_soc_card_jack_new(rtd->card, "Mic Jack",
193 &simple_card_mic_jack); 193 SND_JACK_MICROPHONE,
194 snd_soc_jack_add_pins(&simple_card_mic_jack, 194 &simple_card_mic_jack,
195 ARRAY_SIZE(simple_card_mic_jack_pins), 195 simple_card_mic_jack_pins,
196 simple_card_mic_jack_pins); 196 ARRAY_SIZE(simple_card_mic_jack_pins));
197 simple_card_mic_jack_gpio.gpio = priv->gpio_mic_det; 197 simple_card_mic_jack_gpio.gpio = priv->gpio_mic_det;
198 simple_card_mic_jack_gpio.invert = priv->gpio_mic_det_invert; 198 simple_card_mic_jack_gpio.invert = priv->gpio_mic_det_invert;
199 snd_soc_jack_add_gpios(&simple_card_mic_jack, 1, 199 snd_soc_jack_add_gpios(&simple_card_mic_jack, 1,
diff --git a/sound/soc/intel/broadwell.c b/sound/soc/intel/broadwell.c
index 9cf7d01479ad..fc5542034b9b 100644
--- a/sound/soc/intel/broadwell.c
+++ b/sound/soc/intel/broadwell.c
@@ -80,15 +80,9 @@ static int broadwell_rt286_codec_init(struct snd_soc_pcm_runtime *rtd)
80{ 80{
81 struct snd_soc_codec *codec = rtd->codec; 81 struct snd_soc_codec *codec = rtd->codec;
82 int ret = 0; 82 int ret = 0;
83 ret = snd_soc_jack_new(codec, "Headset", 83 ret = snd_soc_card_jack_new(rtd->card, "Headset",
84 SND_JACK_HEADSET | SND_JACK_BTN_0, &broadwell_headset); 84 SND_JACK_HEADSET | SND_JACK_BTN_0, &broadwell_headset,
85 85 broadwell_headset_pins, ARRAY_SIZE(broadwell_headset_pins));
86 if (ret)
87 return ret;
88
89 ret = snd_soc_jack_add_pins(&broadwell_headset,
90 ARRAY_SIZE(broadwell_headset_pins),
91 broadwell_headset_pins);
92 if (ret) 86 if (ret)
93 return ret; 87 return ret;
94 88
@@ -110,9 +104,7 @@ static int broadwell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
110 channels->min = channels->max = 2; 104 channels->min = channels->max = 2;
111 105
112 /* set SSP0 to 16 bit */ 106 /* set SSP0 to 16 bit */
113 snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT - 107 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
114 SNDRV_PCM_HW_PARAM_FIRST_MASK],
115 SNDRV_PCM_FORMAT_S16_LE);
116 return 0; 108 return 0;
117} 109}
118 110
diff --git a/sound/soc/intel/byt-max98090.c b/sound/soc/intel/byt-max98090.c
index 9832afe7d22c..d8b1f038da1c 100644
--- a/sound/soc/intel/byt-max98090.c
+++ b/sound/soc/intel/byt-max98090.c
@@ -84,7 +84,6 @@ static struct snd_soc_jack_gpio hs_jack_gpios[] = {
84static int byt_max98090_init(struct snd_soc_pcm_runtime *runtime) 84static int byt_max98090_init(struct snd_soc_pcm_runtime *runtime)
85{ 85{
86 int ret; 86 int ret;
87 struct snd_soc_codec *codec = runtime->codec;
88 struct snd_soc_card *card = runtime->card; 87 struct snd_soc_card *card = runtime->card;
89 struct byt_max98090_private *drv = snd_soc_card_get_drvdata(card); 88 struct byt_max98090_private *drv = snd_soc_card_get_drvdata(card);
90 struct snd_soc_jack *jack = &drv->jack; 89 struct snd_soc_jack *jack = &drv->jack;
@@ -100,13 +99,9 @@ static int byt_max98090_init(struct snd_soc_pcm_runtime *runtime)
100 } 99 }
101 100
102 /* Enable jack detection */ 101 /* Enable jack detection */
103 ret = snd_soc_jack_new(codec, "Headset", 102 ret = snd_soc_card_jack_new(runtime->card, "Headset",
104 SND_JACK_LINEOUT | SND_JACK_HEADSET, jack); 103 SND_JACK_LINEOUT | SND_JACK_HEADSET, jack,
105 if (ret) 104 hs_jack_pins, ARRAY_SIZE(hs_jack_pins));
106 return ret;
107
108 ret = snd_soc_jack_add_pins(jack, ARRAY_SIZE(hs_jack_pins),
109 hs_jack_pins);
110 if (ret) 105 if (ret)
111 return ret; 106 return ret;
112 107
diff --git a/sound/soc/intel/bytcr_dpcm_rt5640.c b/sound/soc/intel/bytcr_dpcm_rt5640.c
index 59308629043e..3b262d01c1b3 100644
--- a/sound/soc/intel/bytcr_dpcm_rt5640.c
+++ b/sound/soc/intel/bytcr_dpcm_rt5640.c
@@ -113,9 +113,7 @@ static int byt_codec_fixup(struct snd_soc_pcm_runtime *rtd,
113 channels->min = channels->max = 2; 113 channels->min = channels->max = 2;
114 114
115 /* set SSP2 to 24-bit */ 115 /* set SSP2 to 24-bit */
116 snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT - 116 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
117 SNDRV_PCM_HW_PARAM_FIRST_MASK],
118 SNDRV_PCM_FORMAT_S24_LE);
119 return 0; 117 return 0;
120} 118}
121 119
diff --git a/sound/soc/intel/cht_bsw_rt5645.c b/sound/soc/intel/cht_bsw_rt5645.c
index bd29617a9ab9..012227997ed9 100644
--- a/sound/soc/intel/cht_bsw_rt5645.c
+++ b/sound/soc/intel/cht_bsw_rt5645.c
@@ -169,17 +169,17 @@ static int cht_codec_init(struct snd_soc_pcm_runtime *runtime)
169 return ret; 169 return ret;
170 } 170 }
171 171
172 ret = snd_soc_jack_new(codec, "Headphone Jack", 172 ret = snd_soc_card_jack_new(runtime->card, "Headphone Jack",
173 SND_JACK_HEADPHONE, 173 SND_JACK_HEADPHONE, &ctx->hp_jack,
174 &ctx->hp_jack); 174 NULL, 0);
175 if (ret) { 175 if (ret) {
176 dev_err(runtime->dev, "HP jack creation failed %d\n", ret); 176 dev_err(runtime->dev, "HP jack creation failed %d\n", ret);
177 return ret; 177 return ret;
178 } 178 }
179 179
180 ret = snd_soc_jack_new(codec, "Mic Jack", 180 ret = snd_soc_card_jack_new(runtime->card, "Mic Jack",
181 SND_JACK_MICROPHONE, 181 SND_JACK_MICROPHONE, &ctx->mic_jack,
182 &ctx->mic_jack); 182 NULL, 0);
183 if (ret) { 183 if (ret) {
184 dev_err(runtime->dev, "Mic jack creation failed %d\n", ret); 184 dev_err(runtime->dev, "Mic jack creation failed %d\n", ret);
185 return ret; 185 return ret;
@@ -203,9 +203,7 @@ static int cht_codec_fixup(struct snd_soc_pcm_runtime *rtd,
203 channels->min = channels->max = 2; 203 channels->min = channels->max = 2;
204 204
205 /* set SSP2 to 24-bit */ 205 /* set SSP2 to 24-bit */
206 snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT - 206 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
207 SNDRV_PCM_HW_PARAM_FIRST_MASK],
208 SNDRV_PCM_FORMAT_S24_LE);
209 return 0; 207 return 0;
210} 208}
211 209
diff --git a/sound/soc/intel/cht_bsw_rt5672.c b/sound/soc/intel/cht_bsw_rt5672.c
index ff016621583a..bc8dcacd5e6a 100644
--- a/sound/soc/intel/cht_bsw_rt5672.c
+++ b/sound/soc/intel/cht_bsw_rt5672.c
@@ -178,9 +178,7 @@ static int cht_codec_fixup(struct snd_soc_pcm_runtime *rtd,
178 channels->min = channels->max = 2; 178 channels->min = channels->max = 2;
179 179
180 /* set SSP2 to 24-bit */ 180 /* set SSP2 to 24-bit */
181 snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT - 181 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
182 SNDRV_PCM_HW_PARAM_FIRST_MASK],
183 SNDRV_PCM_FORMAT_S24_LE);
184 return 0; 182 return 0;
185} 183}
186 184
@@ -217,7 +215,7 @@ static struct snd_soc_dai_link cht_dailink[] = {
217 .codec_dai_name = "snd-soc-dummy-dai", 215 .codec_dai_name = "snd-soc-dummy-dai",
218 .codec_name = "snd-soc-dummy", 216 .codec_name = "snd-soc-dummy",
219 .platform_name = "sst-mfld-platform", 217 .platform_name = "sst-mfld-platform",
220 .ignore_suspend = 1, 218 .nonatomic = true,
221 .dynamic = 1, 219 .dynamic = 1,
222 .dpcm_playback = 1, 220 .dpcm_playback = 1,
223 .dpcm_capture = 1, 221 .dpcm_capture = 1,
@@ -240,13 +238,13 @@ static struct snd_soc_dai_link cht_dailink[] = {
240 .cpu_dai_name = "ssp2-port", 238 .cpu_dai_name = "ssp2-port",
241 .platform_name = "sst-mfld-platform", 239 .platform_name = "sst-mfld-platform",
242 .no_pcm = 1, 240 .no_pcm = 1,
241 .nonatomic = true,
243 .codec_dai_name = "rt5670-aif1", 242 .codec_dai_name = "rt5670-aif1",
244 .codec_name = "i2c-10EC5670:00", 243 .codec_name = "i2c-10EC5670:00",
245 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF 244 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF
246 | SND_SOC_DAIFMT_CBS_CFS, 245 | SND_SOC_DAIFMT_CBS_CFS,
247 .init = cht_codec_init, 246 .init = cht_codec_init,
248 .be_hw_params_fixup = cht_codec_fixup, 247 .be_hw_params_fixup = cht_codec_fixup,
249 .ignore_suspend = 1,
250 .dpcm_playback = 1, 248 .dpcm_playback = 1,
251 .dpcm_capture = 1, 249 .dpcm_capture = 1,
252 .ops = &cht_be_ssp2_ops, 250 .ops = &cht_be_ssp2_ops,
@@ -285,7 +283,6 @@ static int snd_cht_mc_probe(struct platform_device *pdev)
285static struct platform_driver snd_cht_mc_driver = { 283static struct platform_driver snd_cht_mc_driver = {
286 .driver = { 284 .driver = {
287 .name = "cht-bsw-rt5672", 285 .name = "cht-bsw-rt5672",
288 .pm = &snd_soc_pm_ops,
289 }, 286 },
290 .probe = snd_cht_mc_probe, 287 .probe = snd_cht_mc_probe,
291}; 288};
diff --git a/sound/soc/intel/haswell.c b/sound/soc/intel/haswell.c
index 35edf51a52aa..00fddd3f5dfb 100644
--- a/sound/soc/intel/haswell.c
+++ b/sound/soc/intel/haswell.c
@@ -56,9 +56,7 @@ static int haswell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
56 channels->min = channels->max = 2; 56 channels->min = channels->max = 2;
57 57
58 /* set SSP0 to 16 bit */ 58 /* set SSP0 to 16 bit */
59 snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT - 59 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
60 SNDRV_PCM_HW_PARAM_FIRST_MASK],
61 SNDRV_PCM_FORMAT_S16_LE);
62 return 0; 60 return 0;
63} 61}
64 62
diff --git a/sound/soc/intel/mfld_machine.c b/sound/soc/intel/mfld_machine.c
index 90b7a57713a0..49c09a0add79 100644
--- a/sound/soc/intel/mfld_machine.c
+++ b/sound/soc/intel/mfld_machine.c
@@ -228,10 +228,13 @@ static void mfld_jack_check(unsigned int intr_status)
228{ 228{
229 struct mfld_jack_data jack_data; 229 struct mfld_jack_data jack_data;
230 230
231 if (!mfld_codec)
232 return;
233
231 jack_data.mfld_jack = &mfld_jack; 234 jack_data.mfld_jack = &mfld_jack;
232 jack_data.intr_id = intr_status; 235 jack_data.intr_id = intr_status;
233 236
234 sn95031_jack_detection(&jack_data); 237 sn95031_jack_detection(mfld_codec, &jack_data);
235 /* TODO: add american headset detection post gpiolib support */ 238 /* TODO: add american headset detection post gpiolib support */
236} 239}
237 240
@@ -240,8 +243,6 @@ static int mfld_init(struct snd_soc_pcm_runtime *runtime)
240 struct snd_soc_dapm_context *dapm = &runtime->card->dapm; 243 struct snd_soc_dapm_context *dapm = &runtime->card->dapm;
241 int ret_val; 244 int ret_val;
242 245
243 mfld_codec = runtime->codec;
244
245 /* default is earpiece pin, userspace sets it explcitly */ 246 /* default is earpiece pin, userspace sets it explcitly */
246 snd_soc_dapm_disable_pin(dapm, "Headphones"); 247 snd_soc_dapm_disable_pin(dapm, "Headphones");
247 /* default is lineout NC, userspace sets it explcitly */ 248 /* default is lineout NC, userspace sets it explcitly */
@@ -254,20 +255,15 @@ static int mfld_init(struct snd_soc_pcm_runtime *runtime)
254 snd_soc_dapm_disable_pin(dapm, "LINEINR"); 255 snd_soc_dapm_disable_pin(dapm, "LINEINR");
255 256
256 /* Headset and button jack detection */ 257 /* Headset and button jack detection */
257 ret_val = snd_soc_jack_new(mfld_codec, "Intel(R) MID Audio Jack", 258 ret_val = snd_soc_card_jack_new(runtime->card,
258 SND_JACK_HEADSET | SND_JACK_BTN_0 | 259 "Intel(R) MID Audio Jack", SND_JACK_HEADSET |
259 SND_JACK_BTN_1, &mfld_jack); 260 SND_JACK_BTN_0 | SND_JACK_BTN_1, &mfld_jack,
261 mfld_jack_pins, ARRAY_SIZE(mfld_jack_pins));
260 if (ret_val) { 262 if (ret_val) {
261 pr_err("jack creation failed\n"); 263 pr_err("jack creation failed\n");
262 return ret_val; 264 return ret_val;
263 } 265 }
264 266
265 ret_val = snd_soc_jack_add_pins(&mfld_jack,
266 ARRAY_SIZE(mfld_jack_pins), mfld_jack_pins);
267 if (ret_val) {
268 pr_err("adding jack pins failed\n");
269 return ret_val;
270 }
271 ret_val = snd_soc_jack_add_zones(&mfld_jack, 267 ret_val = snd_soc_jack_add_zones(&mfld_jack,
272 ARRAY_SIZE(mfld_zones), mfld_zones); 268 ARRAY_SIZE(mfld_zones), mfld_zones);
273 if (ret_val) { 269 if (ret_val) {
@@ -275,6 +271,8 @@ static int mfld_init(struct snd_soc_pcm_runtime *runtime)
275 return ret_val; 271 return ret_val;
276 } 272 }
277 273
274 mfld_codec = runtime->codec;
275
278 /* we want to check if anything is inserted at boot, 276 /* we want to check if anything is inserted at boot,
279 * so send a fake event to codec and it will read adc 277 * so send a fake event to codec and it will read adc
280 * to find if anything is there or not */ 278 * to find if anything is there or not */
@@ -359,8 +357,6 @@ static irqreturn_t snd_mfld_jack_detection(int irq, void *data)
359{ 357{
360 struct mfld_mc_private *mc_drv_ctx = (struct mfld_mc_private *) data; 358 struct mfld_mc_private *mc_drv_ctx = (struct mfld_mc_private *) data;
361 359
362 if (mfld_jack.codec == NULL)
363 return IRQ_HANDLED;
364 mfld_jack_check(mc_drv_ctx->interrupt_status); 360 mfld_jack_check(mc_drv_ctx->interrupt_status);
365 361
366 return IRQ_HANDLED; 362 return IRQ_HANDLED;
diff --git a/sound/soc/intel/sst-mfld-platform-pcm.c b/sound/soc/intel/sst-mfld-platform-pcm.c
index 7523cbef8780..2fbaf2c75d17 100644
--- a/sound/soc/intel/sst-mfld-platform-pcm.c
+++ b/sound/soc/intel/sst-mfld-platform-pcm.c
@@ -594,11 +594,13 @@ static int sst_platform_pcm_trigger(struct snd_pcm_substream *substream,
594 ret_val = stream->ops->stream_drop(sst->dev, str_id); 594 ret_val = stream->ops->stream_drop(sst->dev, str_id);
595 break; 595 break;
596 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 596 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
597 case SNDRV_PCM_TRIGGER_SUSPEND:
597 dev_dbg(rtd->dev, "sst: in pause\n"); 598 dev_dbg(rtd->dev, "sst: in pause\n");
598 status = SST_PLATFORM_PAUSED; 599 status = SST_PLATFORM_PAUSED;
599 ret_val = stream->ops->stream_pause(sst->dev, str_id); 600 ret_val = stream->ops->stream_pause(sst->dev, str_id);
600 break; 601 break;
601 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 602 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
603 case SNDRV_PCM_TRIGGER_RESUME:
602 dev_dbg(rtd->dev, "sst: in pause release\n"); 604 dev_dbg(rtd->dev, "sst: in pause release\n");
603 status = SST_PLATFORM_RUNNING; 605 status = SST_PLATFORM_RUNNING;
604 ret_val = stream->ops->stream_pause_release(sst->dev, str_id); 606 ret_val = stream->ops->stream_pause_release(sst->dev, str_id);
@@ -665,6 +667,9 @@ static int sst_pcm_new(struct snd_soc_pcm_runtime *rtd)
665 667
666static int sst_soc_probe(struct snd_soc_platform *platform) 668static int sst_soc_probe(struct snd_soc_platform *platform)
667{ 669{
670 struct sst_data *drv = dev_get_drvdata(platform->dev);
671
672 drv->soc_card = platform->component.card;
668 return sst_dsp_init_v2_dpcm(platform); 673 return sst_dsp_init_v2_dpcm(platform);
669} 674}
670 675
@@ -727,9 +732,64 @@ static int sst_platform_remove(struct platform_device *pdev)
727 return 0; 732 return 0;
728} 733}
729 734
735#ifdef CONFIG_PM_SLEEP
736
737static int sst_soc_prepare(struct device *dev)
738{
739 struct sst_data *drv = dev_get_drvdata(dev);
740 int i;
741
742 /* suspend all pcms first */
743 snd_soc_suspend(drv->soc_card->dev);
744 snd_soc_poweroff(drv->soc_card->dev);
745
746 /* set the SSPs to idle */
747 for (i = 0; i < drv->soc_card->num_rtd; i++) {
748 struct snd_soc_dai *dai = drv->soc_card->rtd[i].cpu_dai;
749
750 if (dai->active) {
751 send_ssp_cmd(dai, dai->name, 0);
752 sst_handle_vb_timer(dai, false);
753 }
754 }
755
756 return 0;
757}
758
759static void sst_soc_complete(struct device *dev)
760{
761 struct sst_data *drv = dev_get_drvdata(dev);
762 int i;
763
764 /* restart SSPs */
765 for (i = 0; i < drv->soc_card->num_rtd; i++) {
766 struct snd_soc_dai *dai = drv->soc_card->rtd[i].cpu_dai;
767
768 if (dai->active) {
769 sst_handle_vb_timer(dai, true);
770 send_ssp_cmd(dai, dai->name, 1);
771 }
772 }
773 snd_soc_resume(drv->soc_card->dev);
774}
775
776#else
777
778#define sst_soc_prepare NULL
779#define sst_soc_complete NULL
780
781#endif
782
783
784static const struct dev_pm_ops sst_platform_pm = {
785 .prepare = sst_soc_prepare,
786 .complete = sst_soc_complete,
787};
788
730static struct platform_driver sst_platform_driver = { 789static struct platform_driver sst_platform_driver = {
731 .driver = { 790 .driver = {
732 .name = "sst-mfld-platform", 791 .name = "sst-mfld-platform",
792 .pm = &sst_platform_pm,
733 }, 793 },
734 .probe = sst_platform_probe, 794 .probe = sst_platform_probe,
735 .remove = sst_platform_remove, 795 .remove = sst_platform_remove,
diff --git a/sound/soc/intel/sst-mfld-platform.h b/sound/soc/intel/sst-mfld-platform.h
index 79c8d1246a8f..9094314be2b0 100644
--- a/sound/soc/intel/sst-mfld-platform.h
+++ b/sound/soc/intel/sst-mfld-platform.h
@@ -174,6 +174,7 @@ struct sst_data {
174 struct sst_platform_data *pdata; 174 struct sst_platform_data *pdata;
175 struct snd_sst_bytes_v2 *byte_stream; 175 struct snd_sst_bytes_v2 *byte_stream;
176 struct mutex lock; 176 struct mutex lock;
177 struct snd_soc_card *soc_card;
177}; 178};
178int sst_register_dsp(struct sst_device *sst); 179int sst_register_dsp(struct sst_device *sst);
179int sst_unregister_dsp(struct sst_device *sst); 180int sst_unregister_dsp(struct sst_device *sst);
diff --git a/sound/soc/intel/sst/sst.c b/sound/soc/intel/sst/sst.c
index 11c578651c1c..1a7eeec444b1 100644
--- a/sound/soc/intel/sst/sst.c
+++ b/sound/soc/intel/sst/sst.c
@@ -423,23 +423,135 @@ static int intel_sst_runtime_suspend(struct device *dev)
423 return ret; 423 return ret;
424} 424}
425 425
426static int intel_sst_runtime_resume(struct device *dev) 426static int intel_sst_suspend(struct device *dev)
427{ 427{
428 int ret = 0;
429 struct intel_sst_drv *ctx = dev_get_drvdata(dev); 428 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
429 struct sst_fw_save *fw_save;
430 int i, ret = 0;
430 431
431 if (ctx->sst_state == SST_RESET) { 432 /* check first if we are already in SW reset */
432 ret = sst_load_fw(ctx); 433 if (ctx->sst_state == SST_RESET)
433 if (ret) { 434 return 0;
434 dev_err(dev, "FW download fail %d\n", ret); 435
435 sst_set_fw_state_locked(ctx, SST_RESET); 436 /*
437 * check if any stream is active and running
438 * they should already by suspend by soc_suspend
439 */
440 for (i = 1; i <= ctx->info.max_streams; i++) {
441 struct stream_info *stream = &ctx->streams[i];
442
443 if (stream->status == STREAM_RUNNING) {
444 dev_err(dev, "stream %d is running, cant susupend, abort\n", i);
445 return -EBUSY;
436 } 446 }
437 } 447 }
448 synchronize_irq(ctx->irq_num);
449 flush_workqueue(ctx->post_msg_wq);
450
451 /* Move the SST state to Reset */
452 sst_set_fw_state_locked(ctx, SST_RESET);
453
454 /* tell DSP we are suspending */
455 if (ctx->ops->save_dsp_context(ctx))
456 return -EBUSY;
457
458 /* save the memories */
459 fw_save = kzalloc(sizeof(*fw_save), GFP_KERNEL);
460 if (!fw_save)
461 return -ENOMEM;
462 fw_save->iram = kzalloc(ctx->iram_end - ctx->iram_base, GFP_KERNEL);
463 if (!fw_save->iram) {
464 ret = -ENOMEM;
465 goto iram;
466 }
467 fw_save->dram = kzalloc(ctx->dram_end - ctx->dram_base, GFP_KERNEL);
468 if (!fw_save->dram) {
469 ret = -ENOMEM;
470 goto dram;
471 }
472 fw_save->sram = kzalloc(SST_MAILBOX_SIZE, GFP_KERNEL);
473 if (!fw_save->sram) {
474 ret = -ENOMEM;
475 goto sram;
476 }
477
478 fw_save->ddr = kzalloc(ctx->ddr_end - ctx->ddr_base, GFP_KERNEL);
479 if (!fw_save->ddr) {
480 ret = -ENOMEM;
481 goto ddr;
482 }
483
484 memcpy32_fromio(fw_save->iram, ctx->iram, ctx->iram_end - ctx->iram_base);
485 memcpy32_fromio(fw_save->dram, ctx->dram, ctx->dram_end - ctx->dram_base);
486 memcpy32_fromio(fw_save->sram, ctx->mailbox, SST_MAILBOX_SIZE);
487 memcpy32_fromio(fw_save->ddr, ctx->ddr, ctx->ddr_end - ctx->ddr_base);
488
489 ctx->fw_save = fw_save;
490 ctx->ops->reset(ctx);
491 return 0;
492ddr:
493 kfree(fw_save->sram);
494sram:
495 kfree(fw_save->dram);
496dram:
497 kfree(fw_save->iram);
498iram:
499 kfree(fw_save);
500 return ret;
501}
502
503static int intel_sst_resume(struct device *dev)
504{
505 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
506 struct sst_fw_save *fw_save = ctx->fw_save;
507 int ret = 0;
508 struct sst_block *block;
509
510 if (!fw_save)
511 return 0;
512
513 sst_set_fw_state_locked(ctx, SST_FW_LOADING);
514
515 /* we have to restore the memory saved */
516 ctx->ops->reset(ctx);
517
518 ctx->fw_save = NULL;
519
520 memcpy32_toio(ctx->iram, fw_save->iram, ctx->iram_end - ctx->iram_base);
521 memcpy32_toio(ctx->dram, fw_save->dram, ctx->dram_end - ctx->dram_base);
522 memcpy32_toio(ctx->mailbox, fw_save->sram, SST_MAILBOX_SIZE);
523 memcpy32_toio(ctx->ddr, fw_save->ddr, ctx->ddr_end - ctx->ddr_base);
524
525 kfree(fw_save->sram);
526 kfree(fw_save->dram);
527 kfree(fw_save->iram);
528 kfree(fw_save->ddr);
529 kfree(fw_save);
530
531 block = sst_create_block(ctx, 0, FW_DWNL_ID);
532 if (block == NULL)
533 return -ENOMEM;
534
535
536 /* start and wait for ack */
537 ctx->ops->start(ctx);
538 ret = sst_wait_timeout(ctx, block);
539 if (ret) {
540 dev_err(ctx->dev, "fw download failed %d\n", ret);
541 /* FW download failed due to timeout */
542 ret = -EBUSY;
543
544 } else {
545 sst_set_fw_state_locked(ctx, SST_FW_RUNNING);
546 }
547
548 sst_free_block(ctx, block);
438 return ret; 549 return ret;
439} 550}
440 551
441const struct dev_pm_ops intel_sst_pm = { 552const struct dev_pm_ops intel_sst_pm = {
553 .suspend = intel_sst_suspend,
554 .resume = intel_sst_resume,
442 .runtime_suspend = intel_sst_runtime_suspend, 555 .runtime_suspend = intel_sst_runtime_suspend,
443 .runtime_resume = intel_sst_runtime_resume,
444}; 556};
445EXPORT_SYMBOL_GPL(intel_sst_pm); 557EXPORT_SYMBOL_GPL(intel_sst_pm);
diff --git a/sound/soc/intel/sst/sst.h b/sound/soc/intel/sst/sst.h
index 562bc483d6b7..3f493862e98d 100644
--- a/sound/soc/intel/sst/sst.h
+++ b/sound/soc/intel/sst/sst.h
@@ -337,6 +337,13 @@ struct sst_shim_regs64 {
337 u64 csr2; 337 u64 csr2;
338}; 338};
339 339
340struct sst_fw_save {
341 void *iram;
342 void *dram;
343 void *sram;
344 void *ddr;
345};
346
340/** 347/**
341 * struct intel_sst_drv - driver ops 348 * struct intel_sst_drv - driver ops
342 * 349 *
@@ -428,6 +435,8 @@ struct intel_sst_drv {
428 * persistent till worker thread gets called 435 * persistent till worker thread gets called
429 */ 436 */
430 char firmware_name[FW_NAME_SIZE]; 437 char firmware_name[FW_NAME_SIZE];
438
439 struct sst_fw_save *fw_save;
431}; 440};
432 441
433/* misc definitions */ 442/* misc definitions */
@@ -544,4 +553,7 @@ int sst_alloc_drv_context(struct intel_sst_drv **ctx,
544int sst_context_init(struct intel_sst_drv *ctx); 553int sst_context_init(struct intel_sst_drv *ctx);
545void sst_context_cleanup(struct intel_sst_drv *ctx); 554void sst_context_cleanup(struct intel_sst_drv *ctx);
546void sst_configure_runtime_pm(struct intel_sst_drv *ctx); 555void sst_configure_runtime_pm(struct intel_sst_drv *ctx);
556void memcpy32_toio(void __iomem *dst, const void *src, int count);
557void memcpy32_fromio(void *dst, const void __iomem *src, int count);
558
547#endif 559#endif
diff --git a/sound/soc/intel/sst/sst_drv_interface.c b/sound/soc/intel/sst/sst_drv_interface.c
index 5f75ef3cdd22..f0e4b99b3aeb 100644
--- a/sound/soc/intel/sst/sst_drv_interface.c
+++ b/sound/soc/intel/sst/sst_drv_interface.c
@@ -138,12 +138,36 @@ int sst_get_stream(struct intel_sst_drv *ctx,
138static int sst_power_control(struct device *dev, bool state) 138static int sst_power_control(struct device *dev, bool state)
139{ 139{
140 struct intel_sst_drv *ctx = dev_get_drvdata(dev); 140 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
141 141 int ret = 0;
142 dev_dbg(ctx->dev, "state:%d", state); 142 int usage_count = 0;
143 if (state == true) 143
144 return pm_runtime_get_sync(dev); 144#ifdef CONFIG_PM
145 else 145 usage_count = atomic_read(&dev->power.usage_count);
146#else
147 usage_count = 1;
148#endif
149
150 if (state == true) {
151 ret = pm_runtime_get_sync(dev);
152
153 dev_dbg(ctx->dev, "Enable: pm usage count: %d\n", usage_count);
154 if (ret < 0) {
155 dev_err(ctx->dev, "Runtime get failed with err: %d\n", ret);
156 return ret;
157 }
158 if ((ctx->sst_state == SST_RESET) && (usage_count == 1)) {
159 ret = sst_load_fw(ctx);
160 if (ret) {
161 dev_err(dev, "FW download fail %d\n", ret);
162 sst_set_fw_state_locked(ctx, SST_RESET);
163 ret = sst_pm_runtime_put(ctx);
164 }
165 }
166 } else {
167 dev_dbg(ctx->dev, "Disable: pm usage count: %d\n", usage_count);
146 return sst_pm_runtime_put(ctx); 168 return sst_pm_runtime_put(ctx);
169 }
170 return ret;
147} 171}
148 172
149/* 173/*
@@ -572,6 +596,35 @@ static int sst_stream_drop(struct device *dev, int str_id)
572 return sst_drop_stream(ctx, str_id); 596 return sst_drop_stream(ctx, str_id);
573} 597}
574 598
599static int sst_stream_pause(struct device *dev, int str_id)
600{
601 struct stream_info *str_info;
602 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
603
604 if (ctx->sst_state != SST_FW_RUNNING)
605 return 0;
606
607 str_info = get_stream_info(ctx, str_id);
608 if (!str_info)
609 return -EINVAL;
610
611 return sst_pause_stream(ctx, str_id);
612}
613
614static int sst_stream_resume(struct device *dev, int str_id)
615{
616 struct stream_info *str_info;
617 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
618
619 if (ctx->sst_state != SST_FW_RUNNING)
620 return 0;
621
622 str_info = get_stream_info(ctx, str_id);
623 if (!str_info)
624 return -EINVAL;
625 return sst_resume_stream(ctx, str_id);
626}
627
575static int sst_stream_init(struct device *dev, struct pcm_stream_info *str_info) 628static int sst_stream_init(struct device *dev, struct pcm_stream_info *str_info)
576{ 629{
577 int str_id = 0; 630 int str_id = 0;
@@ -633,6 +686,8 @@ static struct sst_ops pcm_ops = {
633 .stream_init = sst_stream_init, 686 .stream_init = sst_stream_init,
634 .stream_start = sst_stream_start, 687 .stream_start = sst_stream_start,
635 .stream_drop = sst_stream_drop, 688 .stream_drop = sst_stream_drop,
689 .stream_pause = sst_stream_pause,
690 .stream_pause_release = sst_stream_resume,
636 .stream_read_tstamp = sst_read_timestamp, 691 .stream_read_tstamp = sst_read_timestamp,
637 .send_byte_stream = sst_send_byte_stream, 692 .send_byte_stream = sst_send_byte_stream,
638 .close = sst_close_pcm_stream, 693 .close = sst_close_pcm_stream,
diff --git a/sound/soc/intel/sst/sst_loader.c b/sound/soc/intel/sst/sst_loader.c
index 7888cd707853..e88907ae8b15 100644
--- a/sound/soc/intel/sst/sst_loader.c
+++ b/sound/soc/intel/sst/sst_loader.c
@@ -39,7 +39,15 @@
39#include "sst.h" 39#include "sst.h"
40#include "../sst-dsp.h" 40#include "../sst-dsp.h"
41 41
42static inline void memcpy32_toio(void __iomem *dst, const void *src, int count) 42void memcpy32_toio(void __iomem *dst, const void *src, int count)
43{
44 /* __iowrite32_copy uses 32-bit count values so divide by 4 for
45 * right count in words
46 */
47 __iowrite32_copy(dst, src, count/4);
48}
49
50void memcpy32_fromio(void *dst, const void __iomem *src, int count)
43{ 51{
44 /* __iowrite32_copy uses 32-bit count values so divide by 4 for 52 /* __iowrite32_copy uses 32-bit count values so divide by 4 for
45 * right count in words 53 * right count in words
diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig
index a2cd3486ac55..e7c78b0406b5 100644
--- a/sound/soc/omap/Kconfig
+++ b/sound/soc/omap/Kconfig
@@ -100,17 +100,19 @@ config SND_OMAP_SOC_OMAP_TWL4030
100 100
101config SND_OMAP_SOC_OMAP_ABE_TWL6040 101config SND_OMAP_SOC_OMAP_ABE_TWL6040
102 tristate "SoC Audio support for OMAP boards using ABE and twl6040 codec" 102 tristate "SoC Audio support for OMAP boards using ABE and twl6040 codec"
103 depends on TWL6040_CORE && SND_OMAP_SOC && (ARCH_OMAP4 || COMPILE_TEST) 103 depends on TWL6040_CORE && SND_OMAP_SOC && (ARCH_OMAP4 || SOC_OMAP5 || COMPILE_TEST)
104 select SND_OMAP_SOC_DMIC 104 select SND_OMAP_SOC_DMIC
105 select SND_OMAP_SOC_MCPDM 105 select SND_OMAP_SOC_MCPDM
106 select SND_SOC_TWL6040 106 select SND_SOC_TWL6040
107 select SND_SOC_DMIC 107 select SND_SOC_DMIC
108 select COMMON_CLK_PALMAS if SOC_OMAP5
108 help 109 help
109 Say Y if you want to add support for SoC audio on OMAP boards using 110 Say Y if you want to add support for SoC audio on OMAP boards using
110 ABE and twl6040 codec. This driver currently supports: 111 ABE and twl6040 codec. This driver currently supports:
111 - SDP4430/Blaze boards 112 - SDP4430/Blaze boards
112 - PandaBoard (4430) 113 - PandaBoard (4430)
113 - PandaBoardES (4460) 114 - PandaBoardES (4460)
115 - omap5-uevm (5432)
114 116
115config SND_OMAP_SOC_OMAP3_PANDORA 117config SND_OMAP_SOC_OMAP3_PANDORA
116 tristate "SoC Audio support for OMAP3 Pandora" 118 tristate "SoC Audio support for OMAP3 Pandora"
diff --git a/sound/soc/omap/ams-delta.c b/sound/soc/omap/ams-delta.c
index 706613077c15..16cc95fa4573 100644
--- a/sound/soc/omap/ams-delta.c
+++ b/sound/soc/omap/ams-delta.c
@@ -479,8 +479,8 @@ static int ams_delta_cx20442_init(struct snd_soc_pcm_runtime *rtd)
479 479
480 /* Add hook switch - can be used to control the codec from userspace 480 /* Add hook switch - can be used to control the codec from userspace
481 * even if line discipline fails */ 481 * even if line discipline fails */
482 ret = snd_soc_jack_new(rtd->codec, "hook_switch", 482 ret = snd_soc_card_jack_new(card, "hook_switch", SND_JACK_HEADSET,
483 SND_JACK_HEADSET, &ams_delta_hook_switch); 483 &ams_delta_hook_switch, NULL, 0);
484 if (ret) 484 if (ret)
485 dev_warn(card->dev, 485 dev_warn(card->dev,
486 "Failed to allocate resources for hook switch, " 486 "Failed to allocate resources for hook switch, "
diff --git a/sound/soc/omap/omap-abe-twl6040.c b/sound/soc/omap/omap-abe-twl6040.c
index b9c65f1ad5a8..0843a68f277c 100644
--- a/sound/soc/omap/omap-abe-twl6040.c
+++ b/sound/soc/omap/omap-abe-twl6040.c
@@ -182,17 +182,17 @@ static int omap_abe_twl6040_init(struct snd_soc_pcm_runtime *rtd)
182 182
183 /* Headset jack detection only if it is supported */ 183 /* Headset jack detection only if it is supported */
184 if (priv->jack_detection) { 184 if (priv->jack_detection) {
185 ret = snd_soc_jack_new(codec, "Headset Jack", 185 ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
186 SND_JACK_HEADSET, &hs_jack); 186 SND_JACK_HEADSET, &hs_jack,
187 hs_jack_pins,
188 ARRAY_SIZE(hs_jack_pins));
187 if (ret) 189 if (ret)
188 return ret; 190 return ret;
189 191
190 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
191 hs_jack_pins);
192 twl6040_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADSET); 192 twl6040_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADSET);
193 } 193 }
194 194
195 return ret; 195 return 0;
196} 196}
197 197
198static const struct snd_soc_dapm_route dmic_audio_map[] = { 198static const struct snd_soc_dapm_route dmic_audio_map[] = {
diff --git a/sound/soc/omap/omap-pcm.c b/sound/soc/omap/omap-pcm.c
index 1343ecbf0bd5..6bb623a2a4df 100644
--- a/sound/soc/omap/omap-pcm.c
+++ b/sound/soc/omap/omap-pcm.c
@@ -39,7 +39,7 @@
39#define pcm_omap1510() 0 39#define pcm_omap1510() 0
40#endif 40#endif
41 41
42static const struct snd_pcm_hardware omap_pcm_hardware = { 42static struct snd_pcm_hardware omap_pcm_hardware = {
43 .info = SNDRV_PCM_INFO_MMAP | 43 .info = SNDRV_PCM_INFO_MMAP |
44 SNDRV_PCM_INFO_MMAP_VALID | 44 SNDRV_PCM_INFO_MMAP_VALID |
45 SNDRV_PCM_INFO_INTERLEAVED | 45 SNDRV_PCM_INFO_INTERLEAVED |
@@ -53,6 +53,24 @@ static const struct snd_pcm_hardware omap_pcm_hardware = {
53 .buffer_bytes_max = 128 * 1024, 53 .buffer_bytes_max = 128 * 1024,
54}; 54};
55 55
56/* sDMA supports only 1, 2, and 4 byte transfer elements. */
57static void omap_pcm_limit_supported_formats(void)
58{
59 int i;
60
61 for (i = 0; i < SNDRV_PCM_FORMAT_LAST; i++) {
62 switch (snd_pcm_format_physical_width(i)) {
63 case 8:
64 case 16:
65 case 32:
66 omap_pcm_hardware.formats |= (1LL << i);
67 break;
68 default:
69 break;
70 }
71 }
72}
73
56/* this may get called several times by oss emulation */ 74/* this may get called several times by oss emulation */
57static int omap_pcm_hw_params(struct snd_pcm_substream *substream, 75static int omap_pcm_hw_params(struct snd_pcm_substream *substream,
58 struct snd_pcm_hw_params *params) 76 struct snd_pcm_hw_params *params)
@@ -235,6 +253,7 @@ static struct snd_soc_platform_driver omap_soc_platform = {
235 253
236int omap_pcm_platform_register(struct device *dev) 254int omap_pcm_platform_register(struct device *dev)
237{ 255{
256 omap_pcm_limit_supported_formats();
238 return devm_snd_soc_register_platform(dev, &omap_soc_platform); 257 return devm_snd_soc_register_platform(dev, &omap_soc_platform);
239} 258}
240EXPORT_SYMBOL_GPL(omap_pcm_platform_register); 259EXPORT_SYMBOL_GPL(omap_pcm_platform_register);
diff --git a/sound/soc/omap/omap-twl4030.c b/sound/soc/omap/omap-twl4030.c
index fb1f6bb87cd4..3673ada43bfb 100644
--- a/sound/soc/omap/omap-twl4030.c
+++ b/sound/soc/omap/omap-twl4030.c
@@ -170,14 +170,10 @@ static int omap_twl4030_init(struct snd_soc_pcm_runtime *rtd)
170 if (priv->jack_detect > 0) { 170 if (priv->jack_detect > 0) {
171 hs_jack_gpios[0].gpio = priv->jack_detect; 171 hs_jack_gpios[0].gpio = priv->jack_detect;
172 172
173 ret = snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET, 173 ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
174 &priv->hs_jack); 174 SND_JACK_HEADSET, &priv->hs_jack,
175 if (ret) 175 hs_jack_pins,
176 return ret; 176 ARRAY_SIZE(hs_jack_pins));
177
178 ret = snd_soc_jack_add_pins(&priv->hs_jack,
179 ARRAY_SIZE(hs_jack_pins),
180 hs_jack_pins);
181 if (ret) 177 if (ret)
182 return ret; 178 return ret;
183 179
diff --git a/sound/soc/omap/rx51.c b/sound/soc/omap/rx51.c
index 7f299357c2d2..c2ddf0fbfa28 100644
--- a/sound/soc/omap/rx51.c
+++ b/sound/soc/omap/rx51.c
@@ -311,9 +311,9 @@ static int rx51_aic34_init(struct snd_soc_pcm_runtime *rtd)
311 } 311 }
312 312
313 /* AV jack detection */ 313 /* AV jack detection */
314 err = snd_soc_jack_new(codec, "AV Jack", 314 err = snd_soc_card_jack_new(rtd->card, "AV Jack",
315 SND_JACK_HEADSET | SND_JACK_VIDEOOUT, 315 SND_JACK_HEADSET | SND_JACK_VIDEOOUT,
316 &rx51_av_jack); 316 &rx51_av_jack, NULL, 0);
317 if (err) { 317 if (err) {
318 dev_err(card->dev, "Failed to add AV Jack\n"); 318 dev_err(card->dev, "Failed to add AV Jack\n");
319 return err; 319 return err;
diff --git a/sound/soc/pxa/hx4700.c b/sound/soc/pxa/hx4700.c
index 73eb5ddf9753..9f8be7cd567e 100644
--- a/sound/soc/pxa/hx4700.c
+++ b/sound/soc/pxa/hx4700.c
@@ -126,17 +126,12 @@ static const struct snd_soc_dapm_route hx4700_audio_map[] = {
126 */ 126 */
127static int hx4700_ak4641_init(struct snd_soc_pcm_runtime *rtd) 127static int hx4700_ak4641_init(struct snd_soc_pcm_runtime *rtd)
128{ 128{
129 struct snd_soc_codec *codec = rtd->codec;
130 int err; 129 int err;
131 130
132 /* Jack detection API stuff */ 131 /* Jack detection API stuff */
133 err = snd_soc_jack_new(codec, "Headphone Jack", 132 err = snd_soc_card_jack_new(rtd->card, "Headphone Jack",
134 SND_JACK_HEADPHONE, &hs_jack); 133 SND_JACK_HEADPHONE, &hs_jack, hs_jack_pin,
135 if (err) 134 ARRAY_SIZE(hs_jack_pin));
136 return err;
137
138 err = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pin),
139 hs_jack_pin);
140 if (err) 135 if (err)
141 return err; 136 return err;
142 137
diff --git a/sound/soc/pxa/palm27x.c b/sound/soc/pxa/palm27x.c
index 910336c5ebeb..c20bbc042425 100644
--- a/sound/soc/pxa/palm27x.c
+++ b/sound/soc/pxa/palm27x.c
@@ -75,17 +75,12 @@ static struct snd_soc_card palm27x_asoc;
75 75
76static int palm27x_ac97_init(struct snd_soc_pcm_runtime *rtd) 76static int palm27x_ac97_init(struct snd_soc_pcm_runtime *rtd)
77{ 77{
78 struct snd_soc_codec *codec = rtd->codec;
79 int err; 78 int err;
80 79
81 /* Jack detection API stuff */ 80 /* Jack detection API stuff */
82 err = snd_soc_jack_new(codec, "Headphone Jack", 81 err = snd_soc_card_jack_new(rtd->card, "Headphone Jack",
83 SND_JACK_HEADPHONE, &hs_jack); 82 SND_JACK_HEADPHONE, &hs_jack, hs_jack_pins,
84 if (err) 83 ARRAY_SIZE(hs_jack_pins));
85 return err;
86
87 err = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
88 hs_jack_pins);
89 if (err) 84 if (err)
90 return err; 85 return err;
91 86
diff --git a/sound/soc/pxa/ttc-dkb.c b/sound/soc/pxa/ttc-dkb.c
index 5001dbb9b257..1753c7d9e760 100644
--- a/sound/soc/pxa/ttc-dkb.c
+++ b/sound/soc/pxa/ttc-dkb.c
@@ -78,15 +78,12 @@ static int ttc_pm860x_init(struct snd_soc_pcm_runtime *rtd)
78 struct snd_soc_codec *codec = rtd->codec; 78 struct snd_soc_codec *codec = rtd->codec;
79 79
80 /* Headset jack detection */ 80 /* Headset jack detection */
81 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE 81 snd_soc_card_jack_new(rtd->card, "Headphone Jack", SND_JACK_HEADPHONE |
82 | SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2, 82 SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2,
83 &hs_jack); 83 &hs_jack, hs_jack_pins, ARRAY_SIZE(hs_jack_pins));
84 snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins), 84 snd_soc_card_jack_new(rtd->card, "Microphone Jack", SND_JACK_MICROPHONE,
85 hs_jack_pins); 85 &mic_jack, mic_jack_pins,
86 snd_soc_jack_new(codec, "Microphone Jack", SND_JACK_MICROPHONE, 86 ARRAY_SIZE(mic_jack_pins));
87 &mic_jack);
88 snd_soc_jack_add_pins(&mic_jack, ARRAY_SIZE(mic_jack_pins),
89 mic_jack_pins);
90 87
91 /* headphone, microphone detection & headset short detection */ 88 /* headphone, microphone detection & headset short detection */
92 pm860x_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADPHONE, 89 pm860x_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADPHONE,
diff --git a/sound/soc/pxa/z2.c b/sound/soc/pxa/z2.c
index 76ccb172d0a7..bcbfbe8303f7 100644
--- a/sound/soc/pxa/z2.c
+++ b/sound/soc/pxa/z2.c
@@ -143,13 +143,9 @@ static int z2_wm8750_init(struct snd_soc_pcm_runtime *rtd)
143 snd_soc_dapm_disable_pin(dapm, "MONO1"); 143 snd_soc_dapm_disable_pin(dapm, "MONO1");
144 144
145 /* Jack detection API stuff */ 145 /* Jack detection API stuff */
146 ret = snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET, 146 ret = snd_soc_card_jack_new(rtd->card, "Headset Jack", SND_JACK_HEADSET,
147 &hs_jack); 147 &hs_jack, hs_jack_pins,
148 if (ret) 148 ARRAY_SIZE(hs_jack_pins));
149 goto err;
150
151 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
152 hs_jack_pins);
153 if (ret) 149 if (ret)
154 goto err; 150 goto err;
155 151
diff --git a/sound/soc/samsung/h1940_uda1380.c b/sound/soc/samsung/h1940_uda1380.c
index 59b044255b78..c72e9fb26658 100644
--- a/sound/soc/samsung/h1940_uda1380.c
+++ b/sound/soc/samsung/h1940_uda1380.c
@@ -162,13 +162,8 @@ static struct platform_device *s3c24xx_snd_device;
162 162
163static int h1940_uda1380_init(struct snd_soc_pcm_runtime *rtd) 163static int h1940_uda1380_init(struct snd_soc_pcm_runtime *rtd)
164{ 164{
165 struct snd_soc_codec *codec = rtd->codec; 165 snd_soc_card_jack_new(rtd->card, "Headphone Jack", SND_JACK_HEADPHONE,
166 166 &hp_jack, hp_jack_pins, ARRAY_SIZE(hp_jack_pins));
167 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
168 &hp_jack);
169
170 snd_soc_jack_add_pins(&hp_jack, ARRAY_SIZE(hp_jack_pins),
171 hp_jack_pins);
172 167
173 snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios), 168 snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
174 hp_jack_gpios); 169 hp_jack_gpios);
diff --git a/sound/soc/samsung/littlemill.c b/sound/soc/samsung/littlemill.c
index 141519c21e21..31a820eb0ac3 100644
--- a/sound/soc/samsung/littlemill.c
+++ b/sound/soc/samsung/littlemill.c
@@ -260,12 +260,12 @@ static int littlemill_late_probe(struct snd_soc_card *card)
260 if (ret < 0) 260 if (ret < 0)
261 return ret; 261 return ret;
262 262
263 ret = snd_soc_jack_new(codec, "Headset", 263 ret = snd_soc_card_jack_new(card, "Headset",
264 SND_JACK_HEADSET | SND_JACK_MECHANICAL | 264 SND_JACK_HEADSET | SND_JACK_MECHANICAL |
265 SND_JACK_BTN_0 | SND_JACK_BTN_1 | 265 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
266 SND_JACK_BTN_2 | SND_JACK_BTN_3 | 266 SND_JACK_BTN_2 | SND_JACK_BTN_3 |
267 SND_JACK_BTN_4 | SND_JACK_BTN_5, 267 SND_JACK_BTN_4 | SND_JACK_BTN_5,
268 &littlemill_headset); 268 &littlemill_headset, NULL, 0);
269 if (ret) 269 if (ret)
270 return ret; 270 return ret;
271 271
diff --git a/sound/soc/samsung/lowland.c b/sound/soc/samsung/lowland.c
index 243dea7ba38f..5f156093101e 100644
--- a/sound/soc/samsung/lowland.c
+++ b/sound/soc/samsung/lowland.c
@@ -56,16 +56,10 @@ static int lowland_wm5100_init(struct snd_soc_pcm_runtime *rtd)
56 return ret; 56 return ret;
57 } 57 }
58 58
59 ret = snd_soc_jack_new(codec, "Headset", 59 ret = snd_soc_card_jack_new(rtd->card, "Headset", SND_JACK_LINEOUT |
60 SND_JACK_LINEOUT | SND_JACK_HEADSET | 60 SND_JACK_HEADSET | SND_JACK_BTN_0,
61 SND_JACK_BTN_0, 61 &lowland_headset, lowland_headset_pins,
62 &lowland_headset); 62 ARRAY_SIZE(lowland_headset_pins));
63 if (ret)
64 return ret;
65
66 ret = snd_soc_jack_add_pins(&lowland_headset,
67 ARRAY_SIZE(lowland_headset_pins),
68 lowland_headset_pins);
69 if (ret) 63 if (ret)
70 return ret; 64 return ret;
71 65
diff --git a/sound/soc/samsung/rx1950_uda1380.c b/sound/soc/samsung/rx1950_uda1380.c
index 873f2cb4bebe..35e37c457f1f 100644
--- a/sound/soc/samsung/rx1950_uda1380.c
+++ b/sound/soc/samsung/rx1950_uda1380.c
@@ -211,13 +211,8 @@ static int rx1950_hw_params(struct snd_pcm_substream *substream,
211 211
212static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd) 212static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd)
213{ 213{
214 struct snd_soc_codec *codec = rtd->codec; 214 snd_soc_card_jack_new(rtd->card, "Headphone Jack", SND_JACK_HEADPHONE,
215 215 &hp_jack, hp_jack_pins, ARRAY_SIZE(hp_jack_pins));
216 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
217 &hp_jack);
218
219 snd_soc_jack_add_pins(&hp_jack, ARRAY_SIZE(hp_jack_pins),
220 hp_jack_pins);
221 216
222 snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios), 217 snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
223 hp_jack_gpios); 218 hp_jack_gpios);
diff --git a/sound/soc/samsung/smartq_wm8987.c b/sound/soc/samsung/smartq_wm8987.c
index 8291d2a5f152..dfbe2db1c407 100644
--- a/sound/soc/samsung/smartq_wm8987.c
+++ b/sound/soc/samsung/smartq_wm8987.c
@@ -151,13 +151,10 @@ static int smartq_wm8987_init(struct snd_soc_pcm_runtime *rtd)
151 snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); 151 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
152 152
153 /* Headphone jack detection */ 153 /* Headphone jack detection */
154 err = snd_soc_jack_new(codec, "Headphone Jack", 154 err = snd_soc_card_jack_new(rtd->card, "Headphone Jack",
155 SND_JACK_HEADPHONE, &smartq_jack); 155 SND_JACK_HEADPHONE, &smartq_jack,
156 if (err) 156 smartq_jack_pins,
157 return err; 157 ARRAY_SIZE(smartq_jack_pins));
158
159 err = snd_soc_jack_add_pins(&smartq_jack, ARRAY_SIZE(smartq_jack_pins),
160 smartq_jack_pins);
161 if (err) 158 if (err)
162 return err; 159 return err;
163 160
diff --git a/sound/soc/samsung/speyside.c b/sound/soc/samsung/speyside.c
index 5ec7c52282f2..2dcb988bdff2 100644
--- a/sound/soc/samsung/speyside.c
+++ b/sound/soc/samsung/speyside.c
@@ -153,16 +153,10 @@ static int speyside_wm8996_init(struct snd_soc_pcm_runtime *rtd)
153 pr_err("Failed to request HP_SEL GPIO: %d\n", ret); 153 pr_err("Failed to request HP_SEL GPIO: %d\n", ret);
154 gpio_direction_output(WM8996_HPSEL_GPIO, speyside_jack_polarity); 154 gpio_direction_output(WM8996_HPSEL_GPIO, speyside_jack_polarity);
155 155
156 ret = snd_soc_jack_new(codec, "Headset", 156 ret = snd_soc_card_jack_new(rtd->card, "Headset", SND_JACK_LINEOUT |
157 SND_JACK_LINEOUT | SND_JACK_HEADSET | 157 SND_JACK_HEADSET | SND_JACK_BTN_0,
158 SND_JACK_BTN_0, 158 &speyside_headset, speyside_headset_pins,
159 &speyside_headset); 159 ARRAY_SIZE(speyside_headset_pins));
160 if (ret)
161 return ret;
162
163 ret = snd_soc_jack_add_pins(&speyside_headset,
164 ARRAY_SIZE(speyside_headset_pins),
165 speyside_headset_pins);
166 if (ret) 160 if (ret)
167 return ret; 161 return ret;
168 162
diff --git a/sound/soc/samsung/tobermory.c b/sound/soc/samsung/tobermory.c
index 9c80506527c4..85ccfb7188cb 100644
--- a/sound/soc/samsung/tobermory.c
+++ b/sound/soc/samsung/tobermory.c
@@ -179,15 +179,10 @@ static int tobermory_late_probe(struct snd_soc_card *card)
179 if (ret < 0) 179 if (ret < 0)
180 return ret; 180 return ret;
181 181
182 ret = snd_soc_jack_new(codec, "Headset", 182 ret = snd_soc_card_jack_new(card, "Headset", SND_JACK_HEADSET |
183 SND_JACK_HEADSET | SND_JACK_BTN_0, 183 SND_JACK_BTN_0, &tobermory_headset,
184 &tobermory_headset); 184 tobermory_headset_pins,
185 if (ret) 185 ARRAY_SIZE(tobermory_headset_pins));
186 return ret;
187
188 ret = snd_soc_jack_add_pins(&tobermory_headset,
189 ARRAY_SIZE(tobermory_headset_pins),
190 tobermory_headset_pins);
191 if (ret) 186 if (ret)
192 return ret; 187 return ret;
193 188
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index e5c990889dcc..07aa54385ae0 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1578,6 +1578,10 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
1578 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, 1578 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
1579 card->num_dapm_widgets); 1579 card->num_dapm_widgets);
1580 1580
1581 if (card->of_dapm_widgets)
1582 snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets,
1583 card->num_of_dapm_widgets);
1584
1581 /* initialise the sound card only once */ 1585 /* initialise the sound card only once */
1582 if (card->probe) { 1586 if (card->probe) {
1583 ret = card->probe(card); 1587 ret = card->probe(card);
@@ -1633,6 +1637,10 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
1633 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, 1637 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1634 card->num_dapm_routes); 1638 card->num_dapm_routes);
1635 1639
1640 if (card->of_dapm_routes)
1641 snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes,
1642 card->num_of_dapm_routes);
1643
1636 for (i = 0; i < card->num_links; i++) { 1644 for (i = 0; i < card->num_links; i++) {
1637 if (card->dai_link[i].dai_fmt) 1645 if (card->dai_link[i].dai_fmt)
1638 snd_soc_runtime_set_dai_fmt(&card->rtd[i], 1646 snd_soc_runtime_set_dai_fmt(&card->rtd[i],
@@ -3242,8 +3250,8 @@ int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
3242 widgets[i].name = wname; 3250 widgets[i].name = wname;
3243 } 3251 }
3244 3252
3245 card->dapm_widgets = widgets; 3253 card->of_dapm_widgets = widgets;
3246 card->num_dapm_widgets = num_widgets; 3254 card->num_of_dapm_widgets = num_widgets;
3247 3255
3248 return 0; 3256 return 0;
3249} 3257}
@@ -3327,8 +3335,8 @@ int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
3327 } 3335 }
3328 } 3336 }
3329 3337
3330 card->num_dapm_routes = num_routes; 3338 card->num_of_dapm_routes = num_routes;
3331 card->dapm_routes = routes; 3339 card->of_dapm_routes = routes;
3332 3340
3333 return 0; 3341 return 0;
3334} 3342}
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c
index 4380dcc064a5..9f60c25c4568 100644
--- a/sound/soc/soc-jack.c
+++ b/sound/soc/soc-jack.c
@@ -22,30 +22,42 @@
22#include <trace/events/asoc.h> 22#include <trace/events/asoc.h>
23 23
24/** 24/**
25 * snd_soc_jack_new - Create a new jack 25 * snd_soc_card_jack_new - Create a new jack
26 * @codec: ASoC codec 26 * @card: ASoC card
27 * @id: an identifying string for this jack 27 * @id: an identifying string for this jack
28 * @type: a bitmask of enum snd_jack_type values that can be detected by 28 * @type: a bitmask of enum snd_jack_type values that can be detected by
29 * this jack 29 * this jack
30 * @jack: structure to use for the jack 30 * @jack: structure to use for the jack
31 * @pins: Array of jack pins to be added to the jack or NULL
32 * @num_pins: Number of elements in the @pins array
31 * 33 *
32 * Creates a new jack object. 34 * Creates a new jack object.
33 * 35 *
34 * Returns zero if successful, or a negative error code on failure. 36 * Returns zero if successful, or a negative error code on failure.
35 * On success jack will be initialised. 37 * On success jack will be initialised.
36 */ 38 */
37int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type, 39int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type,
38 struct snd_soc_jack *jack) 40 struct snd_soc_jack *jack, struct snd_soc_jack_pin *pins,
41 unsigned int num_pins)
39{ 42{
43 int ret;
44
40 mutex_init(&jack->mutex); 45 mutex_init(&jack->mutex);
41 jack->codec = codec; 46 jack->card = card;
42 INIT_LIST_HEAD(&jack->pins); 47 INIT_LIST_HEAD(&jack->pins);
43 INIT_LIST_HEAD(&jack->jack_zones); 48 INIT_LIST_HEAD(&jack->jack_zones);
44 BLOCKING_INIT_NOTIFIER_HEAD(&jack->notifier); 49 BLOCKING_INIT_NOTIFIER_HEAD(&jack->notifier);
45 50
46 return snd_jack_new(codec->component.card->snd_card, id, type, &jack->jack); 51 ret = snd_jack_new(card->snd_card, id, type, &jack->jack);
52 if (ret)
53 return ret;
54
55 if (num_pins)
56 return snd_soc_jack_add_pins(jack, num_pins, pins);
57
58 return 0;
47} 59}
48EXPORT_SYMBOL_GPL(snd_soc_jack_new); 60EXPORT_SYMBOL_GPL(snd_soc_card_jack_new);
49 61
50/** 62/**
51 * snd_soc_jack_report - Report the current status for a jack 63 * snd_soc_jack_report - Report the current status for a jack
@@ -63,7 +75,6 @@ EXPORT_SYMBOL_GPL(snd_soc_jack_new);
63 */ 75 */
64void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask) 76void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask)
65{ 77{
66 struct snd_soc_codec *codec;
67 struct snd_soc_dapm_context *dapm; 78 struct snd_soc_dapm_context *dapm;
68 struct snd_soc_jack_pin *pin; 79 struct snd_soc_jack_pin *pin;
69 unsigned int sync = 0; 80 unsigned int sync = 0;
@@ -74,8 +85,7 @@ void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask)
74 if (!jack) 85 if (!jack)
75 return; 86 return;
76 87
77 codec = jack->codec; 88 dapm = &jack->card->dapm;
78 dapm = &codec->dapm;
79 89
80 mutex_lock(&jack->mutex); 90 mutex_lock(&jack->mutex);
81 91
@@ -175,12 +185,12 @@ int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
175 185
176 for (i = 0; i < count; i++) { 186 for (i = 0; i < count; i++) {
177 if (!pins[i].pin) { 187 if (!pins[i].pin) {
178 dev_err(jack->codec->dev, "ASoC: No name for pin %d\n", 188 dev_err(jack->card->dev, "ASoC: No name for pin %d\n",
179 i); 189 i);
180 return -EINVAL; 190 return -EINVAL;
181 } 191 }
182 if (!pins[i].mask) { 192 if (!pins[i].mask) {
183 dev_err(jack->codec->dev, "ASoC: No mask for pin %d" 193 dev_err(jack->card->dev, "ASoC: No mask for pin %d"
184 " (%s)\n", i, pins[i].pin); 194 " (%s)\n", i, pins[i].pin);
185 return -EINVAL; 195 return -EINVAL;
186 } 196 }
@@ -260,7 +270,7 @@ static void snd_soc_jack_gpio_detect(struct snd_soc_jack_gpio *gpio)
260static irqreturn_t gpio_handler(int irq, void *data) 270static irqreturn_t gpio_handler(int irq, void *data)
261{ 271{
262 struct snd_soc_jack_gpio *gpio = data; 272 struct snd_soc_jack_gpio *gpio = data;
263 struct device *dev = gpio->jack->codec->component.card->dev; 273 struct device *dev = gpio->jack->card->dev;
264 274
265 trace_snd_soc_jack_irq(gpio->name); 275 trace_snd_soc_jack_irq(gpio->name);
266 276
@@ -299,7 +309,7 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
299 309
300 for (i = 0; i < count; i++) { 310 for (i = 0; i < count; i++) {
301 if (!gpios[i].name) { 311 if (!gpios[i].name) {
302 dev_err(jack->codec->dev, 312 dev_err(jack->card->dev,
303 "ASoC: No name for gpio at index %d\n", i); 313 "ASoC: No name for gpio at index %d\n", i);
304 ret = -EINVAL; 314 ret = -EINVAL;
305 goto undo; 315 goto undo;
@@ -320,7 +330,7 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
320 } else { 330 } else {
321 /* legacy GPIO number */ 331 /* legacy GPIO number */
322 if (!gpio_is_valid(gpios[i].gpio)) { 332 if (!gpio_is_valid(gpios[i].gpio)) {
323 dev_err(jack->codec->dev, 333 dev_err(jack->card->dev,
324 "ASoC: Invalid gpio %d\n", 334 "ASoC: Invalid gpio %d\n",
325 gpios[i].gpio); 335 gpios[i].gpio);
326 ret = -EINVAL; 336 ret = -EINVAL;
@@ -350,7 +360,7 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
350 if (gpios[i].wake) { 360 if (gpios[i].wake) {
351 ret = irq_set_irq_wake(gpiod_to_irq(gpios[i].desc), 1); 361 ret = irq_set_irq_wake(gpiod_to_irq(gpios[i].desc), 1);
352 if (ret != 0) 362 if (ret != 0)
353 dev_err(jack->codec->dev, 363 dev_err(jack->card->dev,
354 "ASoC: Failed to mark GPIO at index %d as wake source: %d\n", 364 "ASoC: Failed to mark GPIO at index %d as wake source: %d\n",
355 i, ret); 365 i, ret);
356 } 366 }
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 6b0136e7cb88..6e3781e88f9a 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -2511,6 +2511,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
2511 /* DAPM dai link stream work */ 2511 /* DAPM dai link stream work */
2512 INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work); 2512 INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
2513 2513
2514 pcm->nonatomic = rtd->dai_link->nonatomic;
2514 rtd->pcm = pcm; 2515 rtd->pcm = pcm;
2515 pcm->private_data = rtd; 2516 pcm->private_data = rtd;
2516 2517
diff --git a/sound/soc/tegra/tegra_alc5632.c b/sound/soc/tegra/tegra_alc5632.c
index 769aca2fc5f5..6dcd06a966c7 100644
--- a/sound/soc/tegra/tegra_alc5632.c
+++ b/sound/soc/tegra/tegra_alc5632.c
@@ -106,11 +106,10 @@ static int tegra_alc5632_asoc_init(struct snd_soc_pcm_runtime *rtd)
106 struct snd_soc_dapm_context *dapm = &codec->dapm; 106 struct snd_soc_dapm_context *dapm = &codec->dapm;
107 struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(rtd->card); 107 struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(rtd->card);
108 108
109 snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET, 109 snd_soc_card_jack_new(rtd->card, "Headset Jack", SND_JACK_HEADSET,
110 &tegra_alc5632_hs_jack); 110 &tegra_alc5632_hs_jack,
111 snd_soc_jack_add_pins(&tegra_alc5632_hs_jack, 111 tegra_alc5632_hs_jack_pins,
112 ARRAY_SIZE(tegra_alc5632_hs_jack_pins), 112 ARRAY_SIZE(tegra_alc5632_hs_jack_pins));
113 tegra_alc5632_hs_jack_pins);
114 113
115 if (gpio_is_valid(machine->gpio_hp_det)) { 114 if (gpio_is_valid(machine->gpio_hp_det)) {
116 tegra_alc5632_hp_jack_gpio.gpio = machine->gpio_hp_det; 115 tegra_alc5632_hp_jack_gpio.gpio = machine->gpio_hp_det;
diff --git a/sound/soc/tegra/tegra_max98090.c b/sound/soc/tegra/tegra_max98090.c
index af3fb997b752..902da36581d1 100644
--- a/sound/soc/tegra/tegra_max98090.c
+++ b/sound/soc/tegra/tegra_max98090.c
@@ -133,24 +133,26 @@ static const struct snd_soc_dapm_widget tegra_max98090_dapm_widgets[] = {
133 SND_SOC_DAPM_HP("Headphones", NULL), 133 SND_SOC_DAPM_HP("Headphones", NULL),
134 SND_SOC_DAPM_SPK("Speakers", NULL), 134 SND_SOC_DAPM_SPK("Speakers", NULL),
135 SND_SOC_DAPM_MIC("Mic Jack", NULL), 135 SND_SOC_DAPM_MIC("Mic Jack", NULL),
136 SND_SOC_DAPM_MIC("Int Mic", NULL),
136}; 137};
137 138
138static const struct snd_kcontrol_new tegra_max98090_controls[] = { 139static const struct snd_kcontrol_new tegra_max98090_controls[] = {
140 SOC_DAPM_PIN_SWITCH("Headphones"),
139 SOC_DAPM_PIN_SWITCH("Speakers"), 141 SOC_DAPM_PIN_SWITCH("Speakers"),
142 SOC_DAPM_PIN_SWITCH("Mic Jack"),
143 SOC_DAPM_PIN_SWITCH("Int Mic"),
140}; 144};
141 145
142static int tegra_max98090_asoc_init(struct snd_soc_pcm_runtime *rtd) 146static int tegra_max98090_asoc_init(struct snd_soc_pcm_runtime *rtd)
143{ 147{
144 struct snd_soc_dai *codec_dai = rtd->codec_dai;
145 struct snd_soc_codec *codec = codec_dai->codec;
146 struct tegra_max98090 *machine = snd_soc_card_get_drvdata(rtd->card); 148 struct tegra_max98090 *machine = snd_soc_card_get_drvdata(rtd->card);
147 149
148 if (gpio_is_valid(machine->gpio_hp_det)) { 150 if (gpio_is_valid(machine->gpio_hp_det)) {
149 snd_soc_jack_new(codec, "Headphones", SND_JACK_HEADPHONE, 151 snd_soc_card_jack_new(rtd->card, "Headphones",
150 &tegra_max98090_hp_jack); 152 SND_JACK_HEADPHONE,
151 snd_soc_jack_add_pins(&tegra_max98090_hp_jack, 153 &tegra_max98090_hp_jack,
152 ARRAY_SIZE(tegra_max98090_hp_jack_pins), 154 tegra_max98090_hp_jack_pins,
153 tegra_max98090_hp_jack_pins); 155 ARRAY_SIZE(tegra_max98090_hp_jack_pins));
154 156
155 tegra_max98090_hp_jack_gpio.gpio = machine->gpio_hp_det; 157 tegra_max98090_hp_jack_gpio.gpio = machine->gpio_hp_det;
156 snd_soc_jack_add_gpios(&tegra_max98090_hp_jack, 158 snd_soc_jack_add_gpios(&tegra_max98090_hp_jack,
@@ -159,11 +161,11 @@ static int tegra_max98090_asoc_init(struct snd_soc_pcm_runtime *rtd)
159 } 161 }
160 162
161 if (gpio_is_valid(machine->gpio_mic_det)) { 163 if (gpio_is_valid(machine->gpio_mic_det)) {
162 snd_soc_jack_new(codec, "Mic Jack", SND_JACK_MICROPHONE, 164 snd_soc_card_jack_new(rtd->card, "Mic Jack",
163 &tegra_max98090_mic_jack); 165 SND_JACK_MICROPHONE,
164 snd_soc_jack_add_pins(&tegra_max98090_mic_jack, 166 &tegra_max98090_mic_jack,
165 ARRAY_SIZE(tegra_max98090_mic_jack_pins), 167 tegra_max98090_mic_jack_pins,
166 tegra_max98090_mic_jack_pins); 168 ARRAY_SIZE(tegra_max98090_mic_jack_pins));
167 169
168 tegra_max98090_mic_jack_gpio.gpio = machine->gpio_mic_det; 170 tegra_max98090_mic_jack_gpio.gpio = machine->gpio_mic_det;
169 snd_soc_jack_add_gpios(&tegra_max98090_mic_jack, 171 snd_soc_jack_add_gpios(&tegra_max98090_mic_jack,
diff --git a/sound/soc/tegra/tegra_rt5640.c b/sound/soc/tegra/tegra_rt5640.c
index ed759a3076b8..773daecaa5e8 100644
--- a/sound/soc/tegra/tegra_rt5640.c
+++ b/sound/soc/tegra/tegra_rt5640.c
@@ -108,15 +108,11 @@ static const struct snd_kcontrol_new tegra_rt5640_controls[] = {
108 108
109static int tegra_rt5640_asoc_init(struct snd_soc_pcm_runtime *rtd) 109static int tegra_rt5640_asoc_init(struct snd_soc_pcm_runtime *rtd)
110{ 110{
111 struct snd_soc_dai *codec_dai = rtd->codec_dai;
112 struct snd_soc_codec *codec = codec_dai->codec;
113 struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(rtd->card); 111 struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(rtd->card);
114 112
115 snd_soc_jack_new(codec, "Headphones", SND_JACK_HEADPHONE, 113 snd_soc_card_jack_new(rtd->card, "Headphones", SND_JACK_HEADPHONE,
116 &tegra_rt5640_hp_jack); 114 &tegra_rt5640_hp_jack, tegra_rt5640_hp_jack_pins,
117 snd_soc_jack_add_pins(&tegra_rt5640_hp_jack, 115 ARRAY_SIZE(tegra_rt5640_hp_jack_pins));
118 ARRAY_SIZE(tegra_rt5640_hp_jack_pins),
119 tegra_rt5640_hp_jack_pins);
120 116
121 if (gpio_is_valid(machine->gpio_hp_det)) { 117 if (gpio_is_valid(machine->gpio_hp_det)) {
122 tegra_rt5640_hp_jack_gpio.gpio = machine->gpio_hp_det; 118 tegra_rt5640_hp_jack_gpio.gpio = machine->gpio_hp_det;
diff --git a/sound/soc/tegra/tegra_rt5677.c b/sound/soc/tegra/tegra_rt5677.c
index e4cf978a6e3a..68d8b67e79c1 100644
--- a/sound/soc/tegra/tegra_rt5677.c
+++ b/sound/soc/tegra/tegra_rt5677.c
@@ -146,10 +146,9 @@ static int tegra_rt5677_asoc_init(struct snd_soc_pcm_runtime *rtd)
146 struct snd_soc_dapm_context *dapm = &codec->dapm; 146 struct snd_soc_dapm_context *dapm = &codec->dapm;
147 struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(rtd->card); 147 struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(rtd->card);
148 148
149 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE, 149 snd_soc_card_jack_new(rtd->card, "Headphone Jack", SND_JACK_HEADPHONE,
150 &tegra_rt5677_hp_jack); 150 &tegra_rt5677_hp_jack,
151 snd_soc_jack_add_pins(&tegra_rt5677_hp_jack, 1, 151 &tegra_rt5677_hp_jack_pins, 1);
152 &tegra_rt5677_hp_jack_pins);
153 152
154 if (gpio_is_valid(machine->gpio_hp_det)) { 153 if (gpio_is_valid(machine->gpio_hp_det)) {
155 tegra_rt5677_hp_jack_gpio.gpio = machine->gpio_hp_det; 154 tegra_rt5677_hp_jack_gpio.gpio = machine->gpio_hp_det;
@@ -158,10 +157,9 @@ static int tegra_rt5677_asoc_init(struct snd_soc_pcm_runtime *rtd)
158 } 157 }
159 158
160 159
161 snd_soc_jack_new(codec, "Mic Jack", SND_JACK_MICROPHONE, 160 snd_soc_card_jack_new(rtd->card, "Mic Jack", SND_JACK_MICROPHONE,
162 &tegra_rt5677_mic_jack); 161 &tegra_rt5677_mic_jack,
163 snd_soc_jack_add_pins(&tegra_rt5677_mic_jack, 1, 162 &tegra_rt5677_mic_jack_pins, 1);
164 &tegra_rt5677_mic_jack_pins);
165 163
166 if (gpio_is_valid(machine->gpio_mic_present)) { 164 if (gpio_is_valid(machine->gpio_mic_present)) {
167 tegra_rt5677_mic_jack_gpio.gpio = machine->gpio_mic_present; 165 tegra_rt5677_mic_jack_gpio.gpio = machine->gpio_mic_present;
diff --git a/sound/soc/tegra/tegra_wm8903.c b/sound/soc/tegra/tegra_wm8903.c
index e52420dae2b4..4a95b70f0cf0 100644
--- a/sound/soc/tegra/tegra_wm8903.c
+++ b/sound/soc/tegra/tegra_wm8903.c
@@ -177,21 +177,19 @@ static int tegra_wm8903_init(struct snd_soc_pcm_runtime *rtd)
177 177
178 if (gpio_is_valid(machine->gpio_hp_det)) { 178 if (gpio_is_valid(machine->gpio_hp_det)) {
179 tegra_wm8903_hp_jack_gpio.gpio = machine->gpio_hp_det; 179 tegra_wm8903_hp_jack_gpio.gpio = machine->gpio_hp_det;
180 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE, 180 snd_soc_card_jack_new(rtd->card, "Headphone Jack",
181 &tegra_wm8903_hp_jack); 181 SND_JACK_HEADPHONE, &tegra_wm8903_hp_jack,
182 snd_soc_jack_add_pins(&tegra_wm8903_hp_jack, 182 tegra_wm8903_hp_jack_pins,
183 ARRAY_SIZE(tegra_wm8903_hp_jack_pins), 183 ARRAY_SIZE(tegra_wm8903_hp_jack_pins));
184 tegra_wm8903_hp_jack_pins);
185 snd_soc_jack_add_gpios(&tegra_wm8903_hp_jack, 184 snd_soc_jack_add_gpios(&tegra_wm8903_hp_jack,
186 1, 185 1,
187 &tegra_wm8903_hp_jack_gpio); 186 &tegra_wm8903_hp_jack_gpio);
188 } 187 }
189 188
190 snd_soc_jack_new(codec, "Mic Jack", SND_JACK_MICROPHONE, 189 snd_soc_card_jack_new(rtd->card, "Mic Jack", SND_JACK_MICROPHONE,
191 &tegra_wm8903_mic_jack); 190 &tegra_wm8903_mic_jack,
192 snd_soc_jack_add_pins(&tegra_wm8903_mic_jack, 191 tegra_wm8903_mic_jack_pins,
193 ARRAY_SIZE(tegra_wm8903_mic_jack_pins), 192 ARRAY_SIZE(tegra_wm8903_mic_jack_pins));
194 tegra_wm8903_mic_jack_pins);
195 wm8903_mic_detect(codec, &tegra_wm8903_mic_jack, SND_JACK_MICROPHONE, 193 wm8903_mic_detect(codec, &tegra_wm8903_mic_jack, SND_JACK_MICROPHONE,
196 0); 194 0);
197 195
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 753a47de8459..353532b8aee4 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -1120,17 +1120,24 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip)
1120/* Marantz/Denon USB DACs need a vendor cmd to switch 1120/* Marantz/Denon USB DACs need a vendor cmd to switch
1121 * between PCM and native DSD mode 1121 * between PCM and native DSD mode
1122 */ 1122 */
1123static bool is_marantz_denon_dac(unsigned int id)
1124{
1125 switch (id) {
1126 case USB_ID(0x154e, 0x1003): /* Denon DA-300USB */
1127 case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */
1128 case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */
1129 return true;
1130 }
1131 return false;
1132}
1133
1123int snd_usb_select_mode_quirk(struct snd_usb_substream *subs, 1134int snd_usb_select_mode_quirk(struct snd_usb_substream *subs,
1124 struct audioformat *fmt) 1135 struct audioformat *fmt)
1125{ 1136{
1126 struct usb_device *dev = subs->dev; 1137 struct usb_device *dev = subs->dev;
1127 int err; 1138 int err;
1128 1139
1129 switch (subs->stream->chip->usb_id) { 1140 if (is_marantz_denon_dac(subs->stream->chip->usb_id)) {
1130 case USB_ID(0x154e, 0x1003): /* Denon DA-300USB */
1131 case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */
1132 case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */
1133
1134 /* First switch to alt set 0, otherwise the mode switch cmd 1141 /* First switch to alt set 0, otherwise the mode switch cmd
1135 * will not be accepted by the DAC 1142 * will not be accepted by the DAC
1136 */ 1143 */
@@ -1203,17 +1210,10 @@ void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
1203 /* Marantz/Denon devices with USB DAC functionality need a delay 1210 /* Marantz/Denon devices with USB DAC functionality need a delay
1204 * after each class compliant request 1211 * after each class compliant request
1205 */ 1212 */
1206 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x154e) && 1213 if (is_marantz_denon_dac(USB_ID(le16_to_cpu(dev->descriptor.idVendor),
1207 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS) { 1214 le16_to_cpu(dev->descriptor.idProduct)))
1208 1215 && (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
1209 switch (le16_to_cpu(dev->descriptor.idProduct)) { 1216 mdelay(20);
1210 case 0x1003: /* Denon DA300-USB */
1211 case 0x3005: /* Marantz HD-DAC1 */
1212 case 0x3006: /* Marantz SA-14S1 */
1213 mdelay(20);
1214 break;
1215 }
1216 }
1217 1217
1218 /* Zoom R16/24 needs a tiny delay here, otherwise requests like 1218 /* Zoom R16/24 needs a tiny delay here, otherwise requests like
1219 * get/set frequency return as failed despite actually succeeding. 1219 * get/set frequency return as failed despite actually succeeding.
@@ -1268,15 +1268,9 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
1268 } 1268 }
1269 1269
1270 /* Denon/Marantz devices with USB DAC functionality */ 1270 /* Denon/Marantz devices with USB DAC functionality */
1271 switch (chip->usb_id) { 1271 if (is_marantz_denon_dac(chip->usb_id)) {
1272 case USB_ID(0x154e, 0x1003): /* Denon DA300-USB */
1273 case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */
1274 case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */
1275 if (fp->altsetting == 2) 1272 if (fp->altsetting == 2)
1276 return SNDRV_PCM_FMTBIT_DSD_U32_BE; 1273 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
1277 break;
1278 default:
1279 break;
1280 } 1274 }
1281 1275
1282 return 0; 1276 return 0;