diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-15 18:41:41 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-15 18:41:41 -0400 |
commit | d0a3997c0c3f9351e24029349dee65dd1d9e8d84 (patch) | |
tree | 7a04fe282b0c7b329cd87cdb891f0f3879dc71a6 | |
parent | 6d50ff91d9780263160262daeb6adfdda8ddbc6c (diff) | |
parent | d6eb9e3ec78c98324097bab8eea266c3bb0d0ac7 (diff) |
Merge tag 'sound-4.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
Pull sound updates from Takashi Iwai:
"There have been major modernization with the standard bus: in ALSA
sequencer core and HD-audio. Also, HD-audio receives the regmap
support replacing the in-house cache register cache code. These
changes shouldn't impact the existing behavior, but rather
refactoring.
In addition, HD-audio got the code split to a core library part and
the "legacy" driver parts. This is a preliminary work for adapting
the upcoming ASoC HD-audio driver, and the whole transition is still
work in progress, likely finished in 4.1.
Along with them, there are many updates in ASoC area as usual, too:
lots of cleanups, Intel code shuffling, etc.
Here are some highlights:
ALSA core:
- PCM: the audio timestamp / wallclock enhancement
- PCM: fixes in DPCM management
- Fixes / cleanups of user-space control element management
- Sequencer: modernization using the standard bus
HD-audio:
- Modernization using the standard bus
- Regmap support
- Use standard runtime PM for codec power saving
- Widget-path based power-saving for IDT, VIA and Realtek codecs
- Reorganized sysfs entries for each codec object
- More Dell headset support
ASoC:
- Move of jack registration to the card level
- Lots of ASoC cleanups, mainly moving things from the CODEC level to
the card level
- Support for DAPM routes specified by both the machine driver and DT
- Continuing improvements to rcar
- pcm512x enhacements
- Intel platforms updates
- rt5670 updates / fixes
- New platforms / devices: some non-DSP Qualcomm platforms, Google's
Storm platform, Maxmim MAX98925 CODECs and the Ingenic JZ4780 SoC
Misc:
- ice1724: Improved ESI W192M support
- emu10k1: Emu 1010 fixes/enhancement"
* tag 'sound-4.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound: (411 commits)
ALSA: hda - set GET bit when adding a vendor verb to the codec regmap
ALSA: hda/realtek - Enable the ALC292 dock fixup on the Thinkpad T450
ALSA: hda - Fix another race in runtime PM refcounting
ALSA: hda - Expose codec type sysfs
ALSA: ctl: fix to handle several elements added by one operation for userspace element
ASoC: Intel: fix array_size.cocci warnings
ASoC: n810: Automatically disconnect non-connected pins
ASoC: n810: Consistently pass the card DAPM context to n810_ext_control()
ASoC: davinci-evm: Use card DAPM context to access widgets
ASoC: mop500_ab8500: Use card DAPM context to access widgets
ASoC: wm1133-ev1: Use card DAPM context to access widgets
ASoC: atmel: Improve machine driver compile test coverage
ASoC: atmel: Add dependency to SND_SOC_I2C_AND_SPI where necessary
ALSA: control: Fix a typo of SNDRV_CTL_ELEM_ACCESS_TLV_* with SNDRV_CTL_TLV_OP_*
ALSA: usb-audio: Don't attempt to get Microsoft Lifecam Cinema sample rate
ASoC: rnsd: fix build regression without CONFIG_OF
ALSA: emu10k1: add toggles for E-mu 1010 optical ports
ALSA: ctl: fill identical information to return value when adding userspace elements
ALSA: ctl: fix a bug to return no identical information in info operation for userspace controls
ALSA: ctl: confirm to return all identical information in 'activate' event
...
315 files changed, 15172 insertions, 9019 deletions
diff --git a/Documentation/devicetree/bindings/sound/ingenic,jz4740-i2s.txt b/Documentation/devicetree/bindings/sound/ingenic,jz4740-i2s.txt index b41433386e2f..b623d50004fb 100644 --- a/Documentation/devicetree/bindings/sound/ingenic,jz4740-i2s.txt +++ b/Documentation/devicetree/bindings/sound/ingenic,jz4740-i2s.txt | |||
@@ -1,7 +1,7 @@ | |||
1 | Ingenic JZ4740 I2S controller | 1 | Ingenic JZ4740 I2S controller |
2 | 2 | ||
3 | Required properties: | 3 | Required properties: |
4 | - compatible : "ingenic,jz4740-i2s" | 4 | - compatible : "ingenic,jz4740-i2s" or "ingenic,jz4780-i2s" |
5 | - reg : I2S registers location and length | 5 | - reg : I2S registers location and length |
6 | - clocks : AIC and I2S PLL clock specifiers. | 6 | - clocks : AIC and I2S PLL clock specifiers. |
7 | - clock-names: "aic" and "i2s" | 7 | - clock-names: "aic" and "i2s" |
diff --git a/Documentation/devicetree/bindings/sound/max98925.txt b/Documentation/devicetree/bindings/sound/max98925.txt new file mode 100644 index 000000000000..27be63e2aa0d --- /dev/null +++ b/Documentation/devicetree/bindings/sound/max98925.txt | |||
@@ -0,0 +1,22 @@ | |||
1 | max98925 audio CODEC | ||
2 | |||
3 | This device supports I2C. | ||
4 | |||
5 | Required properties: | ||
6 | |||
7 | - compatible : "maxim,max98925" | ||
8 | |||
9 | - vmon-slot-no : slot number used to send voltage information | ||
10 | |||
11 | - imon-slot-no : slot number used to send current information | ||
12 | |||
13 | - reg : the I2C address of the device for I2C | ||
14 | |||
15 | Example: | ||
16 | |||
17 | codec: max98925@1a { | ||
18 | compatible = "maxim,max98925"; | ||
19 | vmon-slot-no = <0>; | ||
20 | imon-slot-no = <2>; | ||
21 | reg = <0x1a>; | ||
22 | }; | ||
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/devicetree/bindings/sound/qcom,lpass-cpu.txt b/Documentation/devicetree/bindings/sound/qcom,lpass-cpu.txt new file mode 100644 index 000000000000..e00732dac939 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/qcom,lpass-cpu.txt | |||
@@ -0,0 +1,43 @@ | |||
1 | * Qualcomm Technologies LPASS CPU DAI | ||
2 | |||
3 | This node models the Qualcomm Technologies Low-Power Audio SubSystem (LPASS). | ||
4 | |||
5 | Required properties: | ||
6 | |||
7 | - compatible : "qcom,lpass-cpu" | ||
8 | - clocks : Must contain an entry for each entry in clock-names. | ||
9 | - clock-names : A list which must include the following entries: | ||
10 | * "ahbix-clk" | ||
11 | * "mi2s-osr-clk" | ||
12 | * "mi2s-bit-clk" | ||
13 | - interrupts : Must contain an entry for each entry in | ||
14 | interrupt-names. | ||
15 | - interrupt-names : A list which must include the following entries: | ||
16 | * "lpass-irq-lpaif" | ||
17 | - pinctrl-N : One property must exist for each entry in | ||
18 | pinctrl-names. See ../pinctrl/pinctrl-bindings.txt | ||
19 | for details of the property values. | ||
20 | - pinctrl-names : Must contain a "default" entry. | ||
21 | - reg : Must contain an address for each entry in reg-names. | ||
22 | - reg-names : A list which must include the following entries: | ||
23 | * "lpass-lpaif" | ||
24 | |||
25 | Optional properties: | ||
26 | |||
27 | - qcom,adsp : Phandle for the audio DSP node | ||
28 | |||
29 | Example: | ||
30 | |||
31 | lpass@28100000 { | ||
32 | compatible = "qcom,lpass-cpu"; | ||
33 | clocks = <&lcc AHBIX_CLK>, <&lcc MI2S_OSR_CLK>, <&lcc MI2S_BIT_CLK>; | ||
34 | clock-names = "ahbix-clk", "mi2s-osr-clk", "mi2s-bit-clk"; | ||
35 | interrupts = <0 85 1>; | ||
36 | interrupt-names = "lpass-irq-lpaif"; | ||
37 | pinctrl-names = "default", "idle"; | ||
38 | pinctrl-0 = <&mi2s_default>; | ||
39 | pinctrl-1 = <&mi2s_idle>; | ||
40 | reg = <0x28100000 0x10000>; | ||
41 | reg-names = "lpass-lpaif"; | ||
42 | qcom,adsp = <&adsp>; | ||
43 | }; | ||
diff --git a/Documentation/devicetree/bindings/sound/renesas,rsnd.txt b/Documentation/devicetree/bindings/sound/renesas,rsnd.txt index 2dd690bc19cc..f316ce1f214a 100644 --- a/Documentation/devicetree/bindings/sound/renesas,rsnd.txt +++ b/Documentation/devicetree/bindings/sound/renesas,rsnd.txt | |||
@@ -29,9 +29,17 @@ SSI subnode properties: | |||
29 | - shared-pin : if shared clock pin | 29 | - shared-pin : if shared clock pin |
30 | - pio-transfer : use PIO transfer mode | 30 | - pio-transfer : use PIO transfer mode |
31 | - no-busif : BUSIF is not ussed when [mem -> SSI] via DMA case | 31 | - no-busif : BUSIF is not ussed when [mem -> SSI] via DMA case |
32 | - dma : Should contain Audio DMAC entry | ||
33 | - dma-names : SSI case "rx" (=playback), "tx" (=capture) | ||
34 | SSIU case "rxu" (=playback), "txu" (=capture) | ||
32 | 35 | ||
33 | SRC subnode properties: | 36 | SRC subnode properties: |
34 | no properties at this point | 37 | - dma : Should contain Audio DMAC entry |
38 | - dma-names : "rx" (=playback), "tx" (=capture) | ||
39 | |||
40 | DVC subnode properties: | ||
41 | - dma : Should contain Audio DMAC entry | ||
42 | - dma-names : "tx" (=playback/capture) | ||
35 | 43 | ||
36 | DAI subnode properties: | 44 | DAI subnode properties: |
37 | - playback : list of playback modules | 45 | - playback : list of playback modules |
@@ -45,56 +53,145 @@ rcar_sound: rcar_sound@ec500000 { | |||
45 | reg = <0 0xec500000 0 0x1000>, /* SCU */ | 53 | reg = <0 0xec500000 0 0x1000>, /* SCU */ |
46 | <0 0xec5a0000 0 0x100>, /* ADG */ | 54 | <0 0xec5a0000 0 0x100>, /* ADG */ |
47 | <0 0xec540000 0 0x1000>, /* SSIU */ | 55 | <0 0xec540000 0 0x1000>, /* SSIU */ |
48 | <0 0xec541000 0 0x1280>; /* SSI */ | 56 | <0 0xec541000 0 0x1280>, /* SSI */ |
57 | <0 0xec740000 0 0x200>; /* Audio DMAC peri peri*/ | ||
58 | reg-names = "scu", "adg", "ssiu", "ssi", "audmapp"; | ||
59 | |||
60 | clocks = <&mstp10_clks R8A7790_CLK_SSI_ALL>, | ||
61 | <&mstp10_clks R8A7790_CLK_SSI9>, <&mstp10_clks R8A7790_CLK_SSI8>, | ||
62 | <&mstp10_clks R8A7790_CLK_SSI7>, <&mstp10_clks R8A7790_CLK_SSI6>, | ||
63 | <&mstp10_clks R8A7790_CLK_SSI5>, <&mstp10_clks R8A7790_CLK_SSI4>, | ||
64 | <&mstp10_clks R8A7790_CLK_SSI3>, <&mstp10_clks R8A7790_CLK_SSI2>, | ||
65 | <&mstp10_clks R8A7790_CLK_SSI1>, <&mstp10_clks R8A7790_CLK_SSI0>, | ||
66 | <&mstp10_clks R8A7790_CLK_SCU_SRC9>, <&mstp10_clks R8A7790_CLK_SCU_SRC8>, | ||
67 | <&mstp10_clks R8A7790_CLK_SCU_SRC7>, <&mstp10_clks R8A7790_CLK_SCU_SRC6>, | ||
68 | <&mstp10_clks R8A7790_CLK_SCU_SRC5>, <&mstp10_clks R8A7790_CLK_SCU_SRC4>, | ||
69 | <&mstp10_clks R8A7790_CLK_SCU_SRC3>, <&mstp10_clks R8A7790_CLK_SCU_SRC2>, | ||
70 | <&mstp10_clks R8A7790_CLK_SCU_SRC1>, <&mstp10_clks R8A7790_CLK_SCU_SRC0>, | ||
71 | <&mstp10_clks R8A7790_CLK_SCU_DVC0>, <&mstp10_clks R8A7790_CLK_SCU_DVC1>, | ||
72 | <&audio_clk_a>, <&audio_clk_b>, <&audio_clk_c>, <&m2_clk>; | ||
73 | clock-names = "ssi-all", | ||
74 | "ssi.9", "ssi.8", "ssi.7", "ssi.6", "ssi.5", | ||
75 | "ssi.4", "ssi.3", "ssi.2", "ssi.1", "ssi.0", | ||
76 | "src.9", "src.8", "src.7", "src.6", "src.5", | ||
77 | "src.4", "src.3", "src.2", "src.1", "src.0", | ||
78 | "dvc.0", "dvc.1", | ||
79 | "clk_a", "clk_b", "clk_c", "clk_i"; | ||
49 | 80 | ||
50 | rcar_sound,dvc { | 81 | rcar_sound,dvc { |
51 | dvc0: dvc@0 { }; | 82 | dvc0: dvc@0 { |
52 | dvc1: dvc@1 { }; | 83 | dmas = <&audma0 0xbc>; |
84 | dma-names = "tx"; | ||
85 | }; | ||
86 | dvc1: dvc@1 { | ||
87 | dmas = <&audma0 0xbe>; | ||
88 | dma-names = "tx"; | ||
89 | }; | ||
53 | }; | 90 | }; |
54 | 91 | ||
55 | rcar_sound,src { | 92 | rcar_sound,src { |
56 | src0: src@0 { }; | 93 | src0: src@0 { |
57 | src1: src@1 { }; | 94 | interrupts = <0 352 IRQ_TYPE_LEVEL_HIGH>; |
58 | src2: src@2 { }; | 95 | dmas = <&audma0 0x85>, <&audma1 0x9a>; |
59 | src3: src@3 { }; | 96 | dma-names = "rx", "tx"; |
60 | src4: src@4 { }; | 97 | }; |
61 | src5: src@5 { }; | 98 | src1: src@1 { |
62 | src6: src@6 { }; | 99 | interrupts = <0 353 IRQ_TYPE_LEVEL_HIGH>; |
63 | src7: src@7 { }; | 100 | dmas = <&audma0 0x87>, <&audma1 0x9c>; |
64 | src8: src@8 { }; | 101 | dma-names = "rx", "tx"; |
65 | src9: src@9 { }; | 102 | }; |
103 | src2: src@2 { | ||
104 | interrupts = <0 354 IRQ_TYPE_LEVEL_HIGH>; | ||
105 | dmas = <&audma0 0x89>, <&audma1 0x9e>; | ||
106 | dma-names = "rx", "tx"; | ||
107 | }; | ||
108 | src3: src@3 { | ||
109 | interrupts = <0 355 IRQ_TYPE_LEVEL_HIGH>; | ||
110 | dmas = <&audma0 0x8b>, <&audma1 0xa0>; | ||
111 | dma-names = "rx", "tx"; | ||
112 | }; | ||
113 | src4: src@4 { | ||
114 | interrupts = <0 356 IRQ_TYPE_LEVEL_HIGH>; | ||
115 | dmas = <&audma0 0x8d>, <&audma1 0xb0>; | ||
116 | dma-names = "rx", "tx"; | ||
117 | }; | ||
118 | src5: src@5 { | ||
119 | interrupts = <0 357 IRQ_TYPE_LEVEL_HIGH>; | ||
120 | dmas = <&audma0 0x8f>, <&audma1 0xb2>; | ||
121 | dma-names = "rx", "tx"; | ||
122 | }; | ||
123 | src6: src@6 { | ||
124 | interrupts = <0 358 IRQ_TYPE_LEVEL_HIGH>; | ||
125 | dmas = <&audma0 0x91>, <&audma1 0xb4>; | ||
126 | dma-names = "rx", "tx"; | ||
127 | }; | ||
128 | src7: src@7 { | ||
129 | interrupts = <0 359 IRQ_TYPE_LEVEL_HIGH>; | ||
130 | dmas = <&audma0 0x93>, <&audma1 0xb6>; | ||
131 | dma-names = "rx", "tx"; | ||
132 | }; | ||
133 | src8: src@8 { | ||
134 | interrupts = <0 360 IRQ_TYPE_LEVEL_HIGH>; | ||
135 | dmas = <&audma0 0x95>, <&audma1 0xb8>; | ||
136 | dma-names = "rx", "tx"; | ||
137 | }; | ||
138 | src9: src@9 { | ||
139 | interrupts = <0 361 IRQ_TYPE_LEVEL_HIGH>; | ||
140 | dmas = <&audma0 0x97>, <&audma1 0xba>; | ||
141 | dma-names = "rx", "tx"; | ||
142 | }; | ||
66 | }; | 143 | }; |
67 | 144 | ||
68 | rcar_sound,ssi { | 145 | rcar_sound,ssi { |
69 | ssi0: ssi@0 { | 146 | ssi0: ssi@0 { |
70 | interrupts = <0 370 IRQ_TYPE_LEVEL_HIGH>; | 147 | interrupts = <0 370 IRQ_TYPE_LEVEL_HIGH>; |
148 | dmas = <&audma0 0x01>, <&audma1 0x02>, <&audma0 0x15>, <&audma1 0x16>; | ||
149 | dma-names = "rx", "tx", "rxu", "txu"; | ||
71 | }; | 150 | }; |
72 | ssi1: ssi@1 { | 151 | ssi1: ssi@1 { |
73 | interrupts = <0 371 IRQ_TYPE_LEVEL_HIGH>; | 152 | interrupts = <0 371 IRQ_TYPE_LEVEL_HIGH>; |
153 | dmas = <&audma0 0x03>, <&audma1 0x04>, <&audma0 0x49>, <&audma1 0x4a>; | ||
154 | dma-names = "rx", "tx", "rxu", "txu"; | ||
74 | }; | 155 | }; |
75 | ssi2: ssi@2 { | 156 | ssi2: ssi@2 { |
76 | interrupts = <0 372 IRQ_TYPE_LEVEL_HIGH>; | 157 | interrupts = <0 372 IRQ_TYPE_LEVEL_HIGH>; |
158 | dmas = <&audma0 0x05>, <&audma1 0x06>, <&audma0 0x63>, <&audma1 0x64>; | ||
159 | dma-names = "rx", "tx", "rxu", "txu"; | ||
77 | }; | 160 | }; |
78 | ssi3: ssi@3 { | 161 | ssi3: ssi@3 { |
79 | interrupts = <0 373 IRQ_TYPE_LEVEL_HIGH>; | 162 | interrupts = <0 373 IRQ_TYPE_LEVEL_HIGH>; |
163 | dmas = <&audma0 0x07>, <&audma1 0x08>, <&audma0 0x6f>, <&audma1 0x70>; | ||
164 | dma-names = "rx", "tx", "rxu", "txu"; | ||
80 | }; | 165 | }; |
81 | ssi4: ssi@4 { | 166 | ssi4: ssi@4 { |
82 | interrupts = <0 374 IRQ_TYPE_LEVEL_HIGH>; | 167 | interrupts = <0 374 IRQ_TYPE_LEVEL_HIGH>; |
168 | dmas = <&audma0 0x09>, <&audma1 0x0a>, <&audma0 0x71>, <&audma1 0x72>; | ||
169 | dma-names = "rx", "tx", "rxu", "txu"; | ||
83 | }; | 170 | }; |
84 | ssi5: ssi@5 { | 171 | ssi5: ssi@5 { |
85 | interrupts = <0 375 IRQ_TYPE_LEVEL_HIGH>; | 172 | interrupts = <0 375 IRQ_TYPE_LEVEL_HIGH>; |
173 | dmas = <&audma0 0x0b>, <&audma1 0x0c>, <&audma0 0x73>, <&audma1 0x74>; | ||
174 | dma-names = "rx", "tx", "rxu", "txu"; | ||
86 | }; | 175 | }; |
87 | ssi6: ssi@6 { | 176 | ssi6: ssi@6 { |
88 | interrupts = <0 376 IRQ_TYPE_LEVEL_HIGH>; | 177 | interrupts = <0 376 IRQ_TYPE_LEVEL_HIGH>; |
178 | dmas = <&audma0 0x0d>, <&audma1 0x0e>, <&audma0 0x75>, <&audma1 0x76>; | ||
179 | dma-names = "rx", "tx", "rxu", "txu"; | ||
89 | }; | 180 | }; |
90 | ssi7: ssi@7 { | 181 | ssi7: ssi@7 { |
91 | interrupts = <0 377 IRQ_TYPE_LEVEL_HIGH>; | 182 | interrupts = <0 377 IRQ_TYPE_LEVEL_HIGH>; |
183 | dmas = <&audma0 0x0f>, <&audma1 0x10>, <&audma0 0x79>, <&audma1 0x7a>; | ||
184 | dma-names = "rx", "tx", "rxu", "txu"; | ||
92 | }; | 185 | }; |
93 | ssi8: ssi@8 { | 186 | ssi8: ssi@8 { |
94 | interrupts = <0 378 IRQ_TYPE_LEVEL_HIGH>; | 187 | interrupts = <0 378 IRQ_TYPE_LEVEL_HIGH>; |
188 | dmas = <&audma0 0x11>, <&audma1 0x12>, <&audma0 0x7b>, <&audma1 0x7c>; | ||
189 | dma-names = "rx", "tx", "rxu", "txu"; | ||
95 | }; | 190 | }; |
96 | ssi9: ssi@9 { | 191 | ssi9: ssi@9 { |
97 | interrupts = <0 379 IRQ_TYPE_LEVEL_HIGH>; | 192 | interrupts = <0 379 IRQ_TYPE_LEVEL_HIGH>; |
193 | dmas = <&audma0 0x13>, <&audma1 0x14>, <&audma0 0x7d>, <&audma1 0x7e>; | ||
194 | dma-names = "rx", "tx", "rxu", "txu"; | ||
98 | }; | 195 | }; |
99 | }; | 196 | }; |
100 | 197 | ||
diff --git a/Documentation/devicetree/bindings/sound/renesas,rsrc-card.txt b/Documentation/devicetree/bindings/sound/renesas,rsrc-card.txt new file mode 100644 index 000000000000..c64155027288 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/renesas,rsrc-card.txt | |||
@@ -0,0 +1,67 @@ | |||
1 | Renesas Sampling Rate Convert Sound Card: | ||
2 | |||
3 | Renesas Sampling Rate Convert Sound Card specifies audio DAI connections of SoC <-> codec. | ||
4 | |||
5 | Required properties: | ||
6 | |||
7 | - compatible : "renesas,rsrc-card,<board>" | ||
8 | Examples with soctypes are: | ||
9 | - "renesas,rsrc-card,lager" | ||
10 | - "renesas,rsrc-card,koelsch" | ||
11 | Optional properties: | ||
12 | |||
13 | - card_name : User specified audio sound card name, one string | ||
14 | property. | ||
15 | - cpu : CPU sub-node | ||
16 | - codec : CODEC sub-node | ||
17 | |||
18 | Optional subnode properties: | ||
19 | |||
20 | - format : CPU/CODEC common audio format. | ||
21 | "i2s", "right_j", "left_j" , "dsp_a" | ||
22 | "dsp_b", "ac97", "pdm", "msb", "lsb" | ||
23 | - frame-master : Indicates dai-link frame master. | ||
24 | phandle to a cpu or codec subnode. | ||
25 | - bitclock-master : Indicates dai-link bit clock master. | ||
26 | phandle to a cpu or codec subnode. | ||
27 | - bitclock-inversion : bool property. Add this if the | ||
28 | dai-link uses bit clock inversion. | ||
29 | - frame-inversion : bool property. Add this if the | ||
30 | dai-link uses frame clock inversion. | ||
31 | - convert-rate : platform specified sampling rate convert | ||
32 | |||
33 | Required CPU/CODEC subnodes properties: | ||
34 | |||
35 | - sound-dai : phandle and port of CPU/CODEC | ||
36 | |||
37 | Optional CPU/CODEC subnodes properties: | ||
38 | |||
39 | - clocks / system-clock-frequency : specify subnode's clock if needed. | ||
40 | it can be specified via "clocks" if system has | ||
41 | clock node (= common clock), or "system-clock-frequency" | ||
42 | (if system doens't support common clock) | ||
43 | If a clock is specified, it is | ||
44 | enabled with clk_prepare_enable() | ||
45 | in dai startup() and disabled with | ||
46 | clk_disable_unprepare() in dai | ||
47 | shutdown(). | ||
48 | |||
49 | Example | ||
50 | |||
51 | sound { | ||
52 | compatible = "renesas,rsrc-card,lager"; | ||
53 | |||
54 | card-name = "rsnd-ak4643"; | ||
55 | format = "left_j"; | ||
56 | bitclock-master = <&sndcodec>; | ||
57 | frame-master = <&sndcodec>; | ||
58 | |||
59 | sndcpu: cpu { | ||
60 | sound-dai = <&rcar_sound>; | ||
61 | }; | ||
62 | |||
63 | sndcodec: codec { | ||
64 | sound-dai = <&ak4643>; | ||
65 | system-clock-frequency = <11289600>; | ||
66 | }; | ||
67 | }; | ||
diff --git a/Documentation/devicetree/bindings/sound/storm.txt b/Documentation/devicetree/bindings/sound/storm.txt new file mode 100644 index 000000000000..062a4c185fa9 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/storm.txt | |||
@@ -0,0 +1,23 @@ | |||
1 | * Sound complex for Storm boards | ||
2 | |||
3 | Models a soundcard for Storm boards with the Qualcomm Technologies IPQ806x SOC | ||
4 | connected to a MAX98357A DAC via I2S. | ||
5 | |||
6 | Required properties: | ||
7 | |||
8 | - compatible : "google,storm-audio" | ||
9 | - cpu : Phandle of the CPU DAI | ||
10 | - codec : Phandle of the codec DAI | ||
11 | |||
12 | Optional properties: | ||
13 | |||
14 | - qcom,model : The user-visible name of this sound card. | ||
15 | |||
16 | Example: | ||
17 | |||
18 | sound { | ||
19 | compatible = "google,storm-audio"; | ||
20 | qcom,model = "ipq806x-storm"; | ||
21 | cpu = <&lpass_cpu>; | ||
22 | codec = <&max98357a>; | ||
23 | }; | ||
diff --git a/Documentation/devicetree/bindings/sound/wm8804.txt b/Documentation/devicetree/bindings/sound/wm8804.txt index 4d3a56f38adc..6fd124b16496 100644 --- a/Documentation/devicetree/bindings/sound/wm8804.txt +++ b/Documentation/devicetree/bindings/sound/wm8804.txt | |||
@@ -10,6 +10,13 @@ Required properties: | |||
10 | - reg : the I2C address of the device for I2C, the chip select | 10 | - reg : the I2C address of the device for I2C, the chip select |
11 | number for SPI. | 11 | number for SPI. |
12 | 12 | ||
13 | - PVDD-supply, DVDD-supply : Power supplies for the device, as covered | ||
14 | in Documentation/devicetree/bindings/regulator/regulator.txt | ||
15 | |||
16 | Optional properties: | ||
17 | |||
18 | - wlf,reset-gpio: A GPIO specifier for the GPIO controlling the reset pin | ||
19 | |||
13 | Example: | 20 | Example: |
14 | 21 | ||
15 | codec: wm8804@1a { | 22 | codec: wm8804@1a { |
diff --git a/Documentation/sound/alsa/ControlNames.txt b/Documentation/sound/alsa/ControlNames.txt index 79a6127863ca..3fc1cf50d28e 100644 --- a/Documentation/sound/alsa/ControlNames.txt +++ b/Documentation/sound/alsa/ControlNames.txt | |||
@@ -71,11 +71,11 @@ SOURCE: | |||
71 | HDMI/DP (either HDMI or DisplayPort) | 71 | HDMI/DP (either HDMI or DisplayPort) |
72 | 72 | ||
73 | Exceptions (deprecated): | 73 | Exceptions (deprecated): |
74 | [Digital] Capture Source | 74 | [Analogue|Digital] Capture Source |
75 | [Digital] Capture Switch (aka input gain switch) | 75 | [Analogue|Digital] Capture Switch (aka input gain switch) |
76 | [Digital] Capture Volume (aka input gain volume) | 76 | [Analogue|Digital] Capture Volume (aka input gain volume) |
77 | [Digital] Playback Switch (aka output gain switch) | 77 | [Analogue|Digital] Playback Switch (aka output gain switch) |
78 | [Digital] Playback Volume (aka output gain volume) | 78 | [Analogue|Digital] Playback Volume (aka output gain volume) |
79 | Tone Control - Switch | 79 | Tone Control - Switch |
80 | Tone Control - Bass | 80 | Tone Control - Bass |
81 | Tone Control - Treble | 81 | Tone Control - Treble |
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 @@ | |||
1 | The ALSA API can provide two different system timestamps: | ||
2 | |||
3 | - Trigger_tstamp is the system time snapshot taken when the .trigger | ||
4 | callback is invoked. This snapshot is taken by the ALSA core in the | ||
5 | general case, but specific hardware may have synchronization | ||
6 | capabilities or conversely may only be able to provide a correct | ||
7 | estimate with a delay. In the latter two cases, the low-level driver | ||
8 | is responsible for updating the trigger_tstamp at the most appropriate | ||
9 | and precise moment. Applications should not rely solely on the first | ||
10 | trigger_tstamp but update their internal calculations if the driver | ||
11 | provides a refined estimate with a delay. | ||
12 | |||
13 | - tstamp is the current system timestamp updated during the last | ||
14 | event or application query. | ||
15 | The difference (tstamp - trigger_tstamp) defines the elapsed time. | ||
16 | |||
17 | The ALSA API provides reports two basic pieces of information, avail | ||
18 | and delay, which combined with the trigger and current system | ||
19 | timestamps allow for applications to keep track of the 'fullness' of | ||
20 | the ring buffer and the amount of queued samples. | ||
21 | |||
22 | The use of these different pointers and time information depends on | ||
23 | the 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 | ||
27 | queued samples have been played out. | ||
28 | |||
29 | When timestamps are enabled, the avail/delay information is reported | ||
30 | along with a snapshot of system time. Applications can select from | ||
31 | CLOCK_REALTIME (NTP corrections including going backwards), | ||
32 | CLOCK_MONOTONIC (NTP corrections but never going backwards), | ||
33 | CLOCK_MONOTIC_RAW (without NTP corrections) and change the mode | ||
34 | dynamically with sw_params | ||
35 | |||
36 | |||
37 | The ALSA API also provide an audio_tstamp which reflects the passage | ||
38 | of time as measured by different components of audio hardware. In | ||
39 | ascii-art, this could be represented as follows (for the playback | ||
40 | case): | ||
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 | |||
53 | The analog time is taken at the last stage of the playback, as close | ||
54 | as possible to the actual transducer | ||
55 | |||
56 | The link time is taken at the output of the SOC/chipset as the samples | ||
57 | are pushed on a link. The link time can be directly measured if | ||
58 | supported in hardware by sample counters or wallclocks (e.g. with | ||
59 | HDAudio 24MHz or PTP clock for networked solutions) or indirectly | ||
60 | estimated (e.g. with the frame counter in USB). | ||
61 | |||
62 | The DMA time is measured using counters - typically the least reliable | ||
63 | of all measurements due to the bursty natured of DMA transfers. | ||
64 | |||
65 | The app time corresponds to the time tracked by an application after | ||
66 | writing in the ring buffer. | ||
67 | |||
68 | The application can query what the hardware supports, define which | ||
69 | audio time it wants reported by selecting the relevant settings in | ||
70 | audio_tstamp_config fields, get an estimate of the timestamp | ||
71 | accuracy. It can also request the delay-to-analog be included in the | ||
72 | measurement. Direct access to the link time is very interesting on | ||
73 | platforms that provide an embedded DSP; measuring directly the link | ||
74 | time with dedicated hardware, possibly synchronized with system time, | ||
75 | removes the need to keep track of internal DSP processing times and | ||
76 | latency. | ||
77 | |||
78 | In case the application requests an audio tstamp that is not supported | ||
79 | in hardware/low-level driver, the type is overridden as DEFAULT and the | ||
80 | timestamp will report the DMA time based on the hw_pointer value. | ||
81 | |||
82 | For backwards compatibility with previous implementations that did not | ||
83 | provide timestamp selection, with a zero-valued COMPAT timestamp type | ||
84 | the results will default to the HDAudio wall clock for playback | ||
85 | streams and to the DMA time (hw_ptr) in all other cases. | ||
86 | |||
87 | The audio timestamp accuracy can be returned to user-space, so that | ||
88 | appropriate 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 | |||
110 | The accuracy is reported in nanosecond units (using an unsigned 32-bit | ||
111 | word), which gives a max precision of 4.29s, more than enough for | ||
112 | audio applications... | ||
113 | |||
114 | Due to the varied nature of timestamping needs, even for a single | ||
115 | application, the audio_tstamp_config can be changed dynamically. In | ||
116 | the STATUS ioctl, the parameters are read-only and do not allow for | ||
117 | any application selection. To work around this limitation without | ||
118 | impacting legacy applications, a new STATUS_EXT ioctl is introduced | ||
119 | with read/write parameters. ALSA-lib will be modified to make use of | ||
120 | STATUS_EXT and effectively deprecate STATUS. | ||
121 | |||
122 | The ALSA API only allows for a single audio timestamp to be reported | ||
123 | at a time. This is a conscious design decision, reading the audio | ||
124 | timestamps from hardware registers or from IPC takes time, the more | ||
125 | timestamps are read the more imprecise the combined measurements | ||
126 | are. To avoid any interpretation issues, a single (system, audio) | ||
127 | timestamp is reported. Applications that need different timestamps | ||
128 | will be required to issue multiple queries and perform an | ||
129 | interpolation of the results | ||
130 | |||
131 | In some hardware-specific configuration, the system timestamp is | ||
132 | latched by a low-level audio subsytem, and the information provided | ||
133 | back to the driver. Due to potential delays in the communication with | ||
134 | the hardware, there is a risk of misalignment with the avail and delay | ||
135 | information. To make sure applications are not confused, a | ||
136 | driver_timestamp field is added in the snd_pcm_status structure; this | ||
137 | timestamp shows when the information is put together by the driver | ||
138 | before returning from the STATUS and STATUS_EXT ioctl. in most cases | ||
139 | this driver_timestamp will be identical to the regular system tstamp. | ||
140 | |||
141 | Examples of typestamping with HDaudio: | ||
142 | |||
143 | 1. DMA timestamp, no compensation for DMA+analog delay | ||
144 | $ ./audio_time -p --ts_type=1 | ||
145 | playback: systime: 341121338 nsec, audio time 342000000 nsec, systime delta -878662 | ||
146 | playback: systime: 426236663 nsec, audio time 427187500 nsec, systime delta -950837 | ||
147 | playback: systime: 597080580 nsec, audio time 598000000 nsec, systime delta -919420 | ||
148 | playback: systime: 682059782 nsec, audio time 683020833 nsec, systime delta -961051 | ||
149 | playback: systime: 852896415 nsec, audio time 853854166 nsec, systime delta -957751 | ||
150 | playback: systime: 937903344 nsec, audio time 938854166 nsec, systime delta -950822 | ||
151 | |||
152 | 2. DMA timestamp, compensation for DMA+analog delay | ||
153 | $ ./audio_time -p --ts_type=1 -d | ||
154 | playback: systime: 341053347 nsec, audio time 341062500 nsec, systime delta -9153 | ||
155 | playback: systime: 426072447 nsec, audio time 426062500 nsec, systime delta 9947 | ||
156 | playback: systime: 596899518 nsec, audio time 596895833 nsec, systime delta 3685 | ||
157 | playback: systime: 681915317 nsec, audio time 681916666 nsec, systime delta -1349 | ||
158 | playback: systime: 852741306 nsec, audio time 852750000 nsec, systime delta -8694 | ||
159 | |||
160 | 3. link timestamp, compensation for DMA+analog delay | ||
161 | $ ./audio_time -p --ts_type=2 -d | ||
162 | playback: systime: 341060004 nsec, audio time 341062791 nsec, systime delta -2787 | ||
163 | playback: systime: 426242074 nsec, audio time 426244875 nsec, systime delta -2801 | ||
164 | playback: systime: 597080992 nsec, audio time 597084583 nsec, systime delta -3591 | ||
165 | playback: systime: 682084512 nsec, audio time 682088291 nsec, systime delta -3779 | ||
166 | playback: systime: 852936229 nsec, audio time 852940916 nsec, systime delta -4687 | ||
167 | playback: systime: 938107562 nsec, audio time 938112708 nsec, systime delta -5146 | ||
168 | |||
169 | Example 1 shows that the timestamp at the DMA level is close to 1ms | ||
170 | ahead of the actual playback time (as a side time this sort of | ||
171 | measurement can help define rewind safeguards). Compensating for the | ||
172 | DMA-link delay in example 2 helps remove the hardware buffering abut | ||
173 | the information is still very jittery, with up to one sample of | ||
174 | error. In example 3 where the timestamps are measured with the link | ||
175 | wallclock, the timestamps show a monotonic behavior and a lower | ||
176 | dispersion. | ||
177 | |||
178 | Example 3 and 4 are with USB audio class. Example 3 shows a high | ||
179 | offset between audio time and system time due to buffering. Example 4 | ||
180 | shows how compensating for the delay exposes a 1ms accuracy (due to | ||
181 | the use of the frame counter by the driver) | ||
182 | |||
183 | Example 3: DMA timestamp, no compensation for delay, delta of ~5ms | ||
184 | $ ./audio_time -p -Dhw:1 -t1 | ||
185 | playback: systime: 120174019 nsec, audio time 125000000 nsec, systime delta -4825981 | ||
186 | playback: systime: 245041136 nsec, audio time 250000000 nsec, systime delta -4958864 | ||
187 | playback: systime: 370106088 nsec, audio time 375000000 nsec, systime delta -4893912 | ||
188 | playback: systime: 495040065 nsec, audio time 500000000 nsec, systime delta -4959935 | ||
189 | playback: systime: 620038179 nsec, audio time 625000000 nsec, systime delta -4961821 | ||
190 | playback: systime: 745087741 nsec, audio time 750000000 nsec, systime delta -4912259 | ||
191 | playback: systime: 870037336 nsec, audio time 875000000 nsec, systime delta -4962664 | ||
192 | |||
193 | Example 4: DMA timestamp, compensation for delay, delay of ~1ms | ||
194 | $ ./audio_time -p -Dhw:1 -t1 -d | ||
195 | playback: systime: 120190520 nsec, audio time 120000000 nsec, systime delta 190520 | ||
196 | playback: systime: 245036740 nsec, audio time 244000000 nsec, systime delta 1036740 | ||
197 | playback: systime: 370034081 nsec, audio time 369000000 nsec, systime delta 1034081 | ||
198 | playback: systime: 495159907 nsec, audio time 494000000 nsec, systime delta 1159907 | ||
199 | playback: systime: 620098824 nsec, audio time 619000000 nsec, systime delta 1098824 | ||
200 | playback: systime: 745031847 nsec, audio time 744000000 nsec, systime delta 1031847 | ||
diff --git a/MAINTAINERS b/MAINTAINERS index c72a7baec55c..d158405c75ff 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -1764,7 +1764,7 @@ S: Supported | |||
1764 | F: drivers/tty/serial/atmel_serial.c | 1764 | F: drivers/tty/serial/atmel_serial.c |
1765 | 1765 | ||
1766 | ATMEL Audio ALSA driver | 1766 | ATMEL Audio ALSA driver |
1767 | M: Bo Shen <voice.shen@atmel.com> | 1767 | M: Nicolas Ferre <nicolas.ferre@atmel.com> |
1768 | L: alsa-devel@alsa-project.org (moderated for non-subscribers) | 1768 | L: alsa-devel@alsa-project.org (moderated for non-subscribers) |
1769 | S: Supported | 1769 | S: Supported |
1770 | F: sound/soc/atmel | 1770 | F: sound/soc/atmel |
@@ -5301,6 +5301,13 @@ F: drivers/char/ipmi/ | |||
5301 | F: include/linux/ipmi* | 5301 | F: include/linux/ipmi* |
5302 | F: include/uapi/linux/ipmi* | 5302 | F: include/uapi/linux/ipmi* |
5303 | 5303 | ||
5304 | QCOM AUDIO (ASoC) DRIVERS | ||
5305 | M: Patrick Lai <plai@codeaurora.org> | ||
5306 | M: Banajit Goswami <bgoswami@codeaurora.org> | ||
5307 | L: alsa-devel@alsa-project.org (moderated for non-subscribers) | ||
5308 | S: Supported | ||
5309 | F: sound/soc/qcom/ | ||
5310 | |||
5304 | IPS SCSI RAID DRIVER | 5311 | IPS SCSI RAID DRIVER |
5305 | M: Adaptec OEM Raid Solutions <aacraid@adaptec.com> | 5312 | M: Adaptec OEM Raid Solutions <aacraid@adaptec.com> |
5306 | L: linux-scsi@vger.kernel.org | 5313 | L: linux-scsi@vger.kernel.org |
diff --git a/arch/arm/mach-shmobile/board-armadillo800eva.c b/arch/arm/mach-shmobile/board-armadillo800eva.c index 6d949f1c850b..36aaeb12e1a5 100644 --- a/arch/arm/mach-shmobile/board-armadillo800eva.c +++ b/arch/arm/mach-shmobile/board-armadillo800eva.c | |||
@@ -1015,7 +1015,6 @@ static struct asoc_simple_card_info fsi_wm8978_info = { | |||
1015 | .platform = "sh_fsi2", | 1015 | .platform = "sh_fsi2", |
1016 | .daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM, | 1016 | .daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM, |
1017 | .cpu_dai = { | 1017 | .cpu_dai = { |
1018 | .fmt = SND_SOC_DAIFMT_IB_NF, | ||
1019 | .name = "fsia-dai", | 1018 | .name = "fsia-dai", |
1020 | }, | 1019 | }, |
1021 | .codec_dai = { | 1020 | .codec_dai = { |
@@ -1040,9 +1039,9 @@ static struct asoc_simple_card_info fsi2_hdmi_info = { | |||
1040 | .card = "FSI2B-HDMI", | 1039 | .card = "FSI2B-HDMI", |
1041 | .codec = "sh-mobile-hdmi", | 1040 | .codec = "sh-mobile-hdmi", |
1042 | .platform = "sh_fsi2", | 1041 | .platform = "sh_fsi2", |
1042 | .daifmt = SND_SOC_DAIFMT_CBS_CFS, | ||
1043 | .cpu_dai = { | 1043 | .cpu_dai = { |
1044 | .name = "fsib-dai", | 1044 | .name = "fsib-dai", |
1045 | .fmt = SND_SOC_DAIFMT_CBS_CFS, | ||
1046 | }, | 1045 | }, |
1047 | .codec_dai = { | 1046 | .codec_dai = { |
1048 | .name = "sh_mobile_hdmi-hifi", | 1047 | .name = "sh_mobile_hdmi-hifi", |
diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c index ca31f1b45366..cbd4a8aff120 100644 --- a/drivers/dma/of-dma.c +++ b/drivers/dma/of-dma.c | |||
@@ -194,6 +194,7 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np, | |||
194 | 194 | ||
195 | return ERR_PTR(ret_no_channel); | 195 | return ERR_PTR(ret_no_channel); |
196 | } | 196 | } |
197 | EXPORT_SYMBOL_GPL(of_dma_request_slave_channel); | ||
197 | 198 | ||
198 | /** | 199 | /** |
199 | * of_dma_simple_xlate - Simple DMA engine translation function | 200 | * of_dma_simple_xlate - Simple DMA engine translation function |
diff --git a/include/sound/ac97_codec.h b/include/sound/ac97_codec.h index d315a08d6c6d..0e9d75b49bed 100644 --- a/include/sound/ac97_codec.h +++ b/include/sound/ac97_codec.h | |||
@@ -608,7 +608,9 @@ struct ac97_quirk { | |||
608 | int type; /* quirk type above */ | 608 | int type; /* quirk type above */ |
609 | }; | 609 | }; |
610 | 610 | ||
611 | int snd_ac97_tune_hardware(struct snd_ac97 *ac97, struct ac97_quirk *quirk, const char *override); | 611 | int snd_ac97_tune_hardware(struct snd_ac97 *ac97, |
612 | const struct ac97_quirk *quirk, | ||
613 | const char *override); | ||
612 | int snd_ac97_set_rate(struct snd_ac97 *ac97, int reg, unsigned int rate); | 614 | int snd_ac97_set_rate(struct snd_ac97 *ac97, int reg, unsigned int rate); |
613 | 615 | ||
614 | /* | 616 | /* |
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 | */ |
76 | struct snd_compr_stream { | 76 | struct 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); |
279 | int snd_device_register(struct snd_card *card, void *device_data); | 279 | int snd_device_register(struct snd_card *card, void *device_data); |
280 | int snd_device_register_all(struct snd_card *card); | 280 | int snd_device_register_all(struct snd_card *card); |
281 | int snd_device_disconnect_all(struct snd_card *card); | 281 | void snd_device_disconnect(struct snd_card *card, void *device_data); |
282 | void snd_device_disconnect_all(struct snd_card *card); | ||
282 | void snd_device_free(struct snd_card *card, void *device_data); | 283 | void snd_device_free(struct snd_card *card, void *device_data); |
283 | void snd_device_free_all(struct snd_card *card); | 284 | void snd_device_free_all(struct snd_card *card); |
284 | 285 | ||
diff --git a/include/sound/hda_regmap.h b/include/sound/hda_regmap.h new file mode 100644 index 000000000000..53a18b3635e2 --- /dev/null +++ b/include/sound/hda_regmap.h | |||
@@ -0,0 +1,217 @@ | |||
1 | /* | ||
2 | * HD-audio regmap helpers | ||
3 | */ | ||
4 | |||
5 | #ifndef __SOUND_HDA_REGMAP_H | ||
6 | #define __SOUND_HDA_REGMAP_H | ||
7 | |||
8 | #include <linux/regmap.h> | ||
9 | #include <sound/core.h> | ||
10 | #include <sound/hdaudio.h> | ||
11 | |||
12 | int snd_hdac_regmap_init(struct hdac_device *codec); | ||
13 | void snd_hdac_regmap_exit(struct hdac_device *codec); | ||
14 | int snd_hdac_regmap_add_vendor_verb(struct hdac_device *codec, | ||
15 | unsigned int verb); | ||
16 | int snd_hdac_regmap_read_raw(struct hdac_device *codec, unsigned int reg, | ||
17 | unsigned int *val); | ||
18 | int snd_hdac_regmap_write_raw(struct hdac_device *codec, unsigned int reg, | ||
19 | unsigned int val); | ||
20 | int snd_hdac_regmap_update_raw(struct hdac_device *codec, unsigned int reg, | ||
21 | unsigned int mask, unsigned int val); | ||
22 | |||
23 | /** | ||
24 | * snd_hdac_regmap_encode_verb - encode the verb to a pseudo register | ||
25 | * @nid: widget NID | ||
26 | * @verb: codec verb | ||
27 | * | ||
28 | * Returns an encoded pseudo register. | ||
29 | */ | ||
30 | #define snd_hdac_regmap_encode_verb(nid, verb) \ | ||
31 | (((verb) << 8) | 0x80000 | ((unsigned int)(nid) << 20)) | ||
32 | |||
33 | /** | ||
34 | * snd_hdac_regmap_encode_amp - encode the AMP verb to a pseudo register | ||
35 | * @nid: widget NID | ||
36 | * @ch: channel (left = 0, right = 1) | ||
37 | * @dir: direction (#HDA_INPUT, #HDA_OUTPUT) | ||
38 | * @idx: input index value | ||
39 | * | ||
40 | * Returns an encoded pseudo register. | ||
41 | */ | ||
42 | #define snd_hdac_regmap_encode_amp(nid, ch, dir, idx) \ | ||
43 | (snd_hdac_regmap_encode_verb(nid, AC_VERB_GET_AMP_GAIN_MUTE) | \ | ||
44 | ((ch) ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT) | \ | ||
45 | ((dir) == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT) | \ | ||
46 | (idx)) | ||
47 | |||
48 | /** | ||
49 | * snd_hdac_regmap_encode_amp_stereo - encode a pseudo register for stereo AMPs | ||
50 | * @nid: widget NID | ||
51 | * @dir: direction (#HDA_INPUT, #HDA_OUTPUT) | ||
52 | * @idx: input index value | ||
53 | * | ||
54 | * Returns an encoded pseudo register. | ||
55 | */ | ||
56 | #define snd_hdac_regmap_encode_amp_stereo(nid, dir, idx) \ | ||
57 | (snd_hdac_regmap_encode_verb(nid, AC_VERB_GET_AMP_GAIN_MUTE) | \ | ||
58 | AC_AMP_SET_LEFT | AC_AMP_SET_RIGHT | /* both bits set! */ \ | ||
59 | ((dir) == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT) | \ | ||
60 | (idx)) | ||
61 | |||
62 | /** | ||
63 | * snd_hdac_regmap_write - Write a verb with caching | ||
64 | * @nid: codec NID | ||
65 | * @reg: verb to write | ||
66 | * @val: value to write | ||
67 | * | ||
68 | * For writing an amp value, use snd_hda_regmap_amp_update(). | ||
69 | */ | ||
70 | static inline int | ||
71 | snd_hdac_regmap_write(struct hdac_device *codec, hda_nid_t nid, | ||
72 | unsigned int verb, unsigned int val) | ||
73 | { | ||
74 | unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb); | ||
75 | |||
76 | return snd_hdac_regmap_write_raw(codec, cmd, val); | ||
77 | } | ||
78 | |||
79 | /** | ||
80 | * snd_hda_regmap_update - Update a verb value with caching | ||
81 | * @nid: codec NID | ||
82 | * @verb: verb to update | ||
83 | * @mask: bit mask to update | ||
84 | * @val: value to update | ||
85 | * | ||
86 | * For updating an amp value, use snd_hda_regmap_amp_update(). | ||
87 | */ | ||
88 | static inline int | ||
89 | snd_hdac_regmap_update(struct hdac_device *codec, hda_nid_t nid, | ||
90 | unsigned int verb, unsigned int mask, | ||
91 | unsigned int val) | ||
92 | { | ||
93 | unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb); | ||
94 | |||
95 | return snd_hdac_regmap_update_raw(codec, cmd, mask, val); | ||
96 | } | ||
97 | |||
98 | /** | ||
99 | * snd_hda_regmap_read - Read a verb with caching | ||
100 | * @nid: codec NID | ||
101 | * @verb: verb to read | ||
102 | * @val: pointer to store the value | ||
103 | * | ||
104 | * For reading an amp value, use snd_hda_regmap_get_amp(). | ||
105 | */ | ||
106 | static inline int | ||
107 | snd_hdac_regmap_read(struct hdac_device *codec, hda_nid_t nid, | ||
108 | unsigned int verb, unsigned int *val) | ||
109 | { | ||
110 | unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb); | ||
111 | |||
112 | return snd_hdac_regmap_read_raw(codec, cmd, val); | ||
113 | } | ||
114 | |||
115 | /** | ||
116 | * snd_hdac_regmap_get_amp - Read AMP value | ||
117 | * @codec: HD-audio codec | ||
118 | * @nid: NID to read the AMP value | ||
119 | * @ch: channel (left=0 or right=1) | ||
120 | * @direction: #HDA_INPUT or #HDA_OUTPUT | ||
121 | * @index: the index value (only for input direction) | ||
122 | * @val: the pointer to store the value | ||
123 | * | ||
124 | * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit. | ||
125 | * Returns the value or a negative error. | ||
126 | */ | ||
127 | static inline int | ||
128 | snd_hdac_regmap_get_amp(struct hdac_device *codec, hda_nid_t nid, | ||
129 | int ch, int dir, int idx) | ||
130 | { | ||
131 | unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx); | ||
132 | int err, val; | ||
133 | |||
134 | err = snd_hdac_regmap_read_raw(codec, cmd, &val); | ||
135 | return err < 0 ? err : val; | ||
136 | } | ||
137 | |||
138 | /** | ||
139 | * snd_hdac_regmap_update_amp - update the AMP value | ||
140 | * @codec: HD-audio codec | ||
141 | * @nid: NID to read the AMP value | ||
142 | * @ch: channel (left=0 or right=1) | ||
143 | * @direction: #HDA_INPUT or #HDA_OUTPUT | ||
144 | * @idx: the index value (only for input direction) | ||
145 | * @mask: bit mask to set | ||
146 | * @val: the bits value to set | ||
147 | * | ||
148 | * Update the AMP value with a bit mask. | ||
149 | * Returns 0 if the value is unchanged, 1 if changed, or a negative error. | ||
150 | */ | ||
151 | static inline int | ||
152 | snd_hdac_regmap_update_amp(struct hdac_device *codec, hda_nid_t nid, | ||
153 | int ch, int dir, int idx, int mask, int val) | ||
154 | { | ||
155 | unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx); | ||
156 | |||
157 | return snd_hdac_regmap_update_raw(codec, cmd, mask, val); | ||
158 | } | ||
159 | |||
160 | /** | ||
161 | * snd_hdac_regmap_get_amp_stereo - Read stereo AMP values | ||
162 | * @codec: HD-audio codec | ||
163 | * @nid: NID to read the AMP value | ||
164 | * @ch: channel (left=0 or right=1) | ||
165 | * @direction: #HDA_INPUT or #HDA_OUTPUT | ||
166 | * @index: the index value (only for input direction) | ||
167 | * @val: the pointer to store the value | ||
168 | * | ||
169 | * Read stereo AMP values. The lower byte is left, the upper byte is right. | ||
170 | * Returns the value or a negative error. | ||
171 | */ | ||
172 | static inline int | ||
173 | snd_hdac_regmap_get_amp_stereo(struct hdac_device *codec, hda_nid_t nid, | ||
174 | int dir, int idx) | ||
175 | { | ||
176 | unsigned int cmd = snd_hdac_regmap_encode_amp_stereo(nid, dir, idx); | ||
177 | int err, val; | ||
178 | |||
179 | err = snd_hdac_regmap_read_raw(codec, cmd, &val); | ||
180 | return err < 0 ? err : val; | ||
181 | } | ||
182 | |||
183 | /** | ||
184 | * snd_hdac_regmap_update_amp_stereo - update the stereo AMP value | ||
185 | * @codec: HD-audio codec | ||
186 | * @nid: NID to read the AMP value | ||
187 | * @direction: #HDA_INPUT or #HDA_OUTPUT | ||
188 | * @idx: the index value (only for input direction) | ||
189 | * @mask: bit mask to set | ||
190 | * @val: the bits value to set | ||
191 | * | ||
192 | * Update the stereo AMP value with a bit mask. | ||
193 | * The lower byte is left, the upper byte is right. | ||
194 | * Returns 0 if the value is unchanged, 1 if changed, or a negative error. | ||
195 | */ | ||
196 | static inline int | ||
197 | snd_hdac_regmap_update_amp_stereo(struct hdac_device *codec, hda_nid_t nid, | ||
198 | int dir, int idx, int mask, int val) | ||
199 | { | ||
200 | unsigned int cmd = snd_hdac_regmap_encode_amp_stereo(nid, dir, idx); | ||
201 | |||
202 | return snd_hdac_regmap_update_raw(codec, cmd, mask, val); | ||
203 | } | ||
204 | |||
205 | /** | ||
206 | * snd_hdac_regmap_sync_node - sync the widget node attributes | ||
207 | * @codec: HD-audio codec | ||
208 | * @nid: NID to sync | ||
209 | */ | ||
210 | static inline void | ||
211 | snd_hdac_regmap_sync_node(struct hdac_device *codec, hda_nid_t nid) | ||
212 | { | ||
213 | regcache_mark_dirty(codec->regmap); | ||
214 | regcache_sync_region(codec->regmap, nid << 20, ((nid + 1) << 20) - 1); | ||
215 | } | ||
216 | |||
217 | #endif /* __SOUND_HDA_REGMAP_H */ | ||
diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h new file mode 100644 index 000000000000..2a8aa9dfb83d --- /dev/null +++ b/include/sound/hdaudio.h | |||
@@ -0,0 +1,247 @@ | |||
1 | /* | ||
2 | * HD-audio core stuff | ||
3 | */ | ||
4 | |||
5 | #ifndef __SOUND_HDAUDIO_H | ||
6 | #define __SOUND_HDAUDIO_H | ||
7 | |||
8 | #include <linux/device.h> | ||
9 | #include <sound/hda_verbs.h> | ||
10 | |||
11 | /* codec node id */ | ||
12 | typedef u16 hda_nid_t; | ||
13 | |||
14 | struct hdac_bus; | ||
15 | struct hdac_device; | ||
16 | struct hdac_driver; | ||
17 | struct hdac_widget_tree; | ||
18 | |||
19 | /* | ||
20 | * exported bus type | ||
21 | */ | ||
22 | extern struct bus_type snd_hda_bus_type; | ||
23 | |||
24 | /* | ||
25 | * generic arrays | ||
26 | */ | ||
27 | struct snd_array { | ||
28 | unsigned int used; | ||
29 | unsigned int alloced; | ||
30 | unsigned int elem_size; | ||
31 | unsigned int alloc_align; | ||
32 | void *list; | ||
33 | }; | ||
34 | |||
35 | /* | ||
36 | * HD-audio codec base device | ||
37 | */ | ||
38 | struct hdac_device { | ||
39 | struct device dev; | ||
40 | int type; | ||
41 | struct hdac_bus *bus; | ||
42 | unsigned int addr; /* codec address */ | ||
43 | struct list_head list; /* list point for bus codec_list */ | ||
44 | |||
45 | hda_nid_t afg; /* AFG node id */ | ||
46 | hda_nid_t mfg; /* MFG node id */ | ||
47 | |||
48 | /* ids */ | ||
49 | unsigned int vendor_id; | ||
50 | unsigned int subsystem_id; | ||
51 | unsigned int revision_id; | ||
52 | unsigned int afg_function_id; | ||
53 | unsigned int mfg_function_id; | ||
54 | unsigned int afg_unsol:1; | ||
55 | unsigned int mfg_unsol:1; | ||
56 | |||
57 | unsigned int power_caps; /* FG power caps */ | ||
58 | |||
59 | const char *vendor_name; /* codec vendor name */ | ||
60 | const char *chip_name; /* codec chip name */ | ||
61 | |||
62 | /* verb exec op override */ | ||
63 | int (*exec_verb)(struct hdac_device *dev, unsigned int cmd, | ||
64 | unsigned int flags, unsigned int *res); | ||
65 | |||
66 | /* widgets */ | ||
67 | unsigned int num_nodes; | ||
68 | hda_nid_t start_nid, end_nid; | ||
69 | |||
70 | /* misc flags */ | ||
71 | atomic_t in_pm; /* suspend/resume being performed */ | ||
72 | |||
73 | /* sysfs */ | ||
74 | struct hdac_widget_tree *widgets; | ||
75 | |||
76 | /* regmap */ | ||
77 | struct regmap *regmap; | ||
78 | struct snd_array vendor_verbs; | ||
79 | bool lazy_cache:1; /* don't wake up for writes */ | ||
80 | bool caps_overwriting:1; /* caps overwrite being in process */ | ||
81 | bool cache_coef:1; /* cache COEF read/write too */ | ||
82 | }; | ||
83 | |||
84 | /* device/driver type used for matching */ | ||
85 | enum { | ||
86 | HDA_DEV_CORE, | ||
87 | HDA_DEV_LEGACY, | ||
88 | }; | ||
89 | |||
90 | /* direction */ | ||
91 | enum { | ||
92 | HDA_INPUT, HDA_OUTPUT | ||
93 | }; | ||
94 | |||
95 | #define dev_to_hdac_dev(_dev) container_of(_dev, struct hdac_device, dev) | ||
96 | |||
97 | int snd_hdac_device_init(struct hdac_device *dev, struct hdac_bus *bus, | ||
98 | const char *name, unsigned int addr); | ||
99 | void snd_hdac_device_exit(struct hdac_device *dev); | ||
100 | int snd_hdac_device_register(struct hdac_device *codec); | ||
101 | void snd_hdac_device_unregister(struct hdac_device *codec); | ||
102 | |||
103 | int snd_hdac_refresh_widgets(struct hdac_device *codec); | ||
104 | |||
105 | unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid, | ||
106 | unsigned int verb, unsigned int parm); | ||
107 | int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd, | ||
108 | unsigned int flags, unsigned int *res); | ||
109 | int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid, | ||
110 | unsigned int verb, unsigned int parm, unsigned int *res); | ||
111 | int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm, | ||
112 | unsigned int *res); | ||
113 | int snd_hdac_read_parm_uncached(struct hdac_device *codec, hda_nid_t nid, | ||
114 | int parm); | ||
115 | int snd_hdac_override_parm(struct hdac_device *codec, hda_nid_t nid, | ||
116 | unsigned int parm, unsigned int val); | ||
117 | int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid, | ||
118 | hda_nid_t *conn_list, int max_conns); | ||
119 | int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid, | ||
120 | hda_nid_t *start_id); | ||
121 | |||
122 | /** | ||
123 | * snd_hdac_read_parm - read a codec parameter | ||
124 | * @codec: the codec object | ||
125 | * @nid: NID to read a parameter | ||
126 | * @parm: parameter to read | ||
127 | * | ||
128 | * Returns -1 for error. If you need to distinguish the error more | ||
129 | * strictly, use _snd_hdac_read_parm() directly. | ||
130 | */ | ||
131 | static inline int snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, | ||
132 | int parm) | ||
133 | { | ||
134 | unsigned int val; | ||
135 | |||
136 | return _snd_hdac_read_parm(codec, nid, parm, &val) < 0 ? -1 : val; | ||
137 | } | ||
138 | |||
139 | #ifdef CONFIG_PM | ||
140 | void snd_hdac_power_up(struct hdac_device *codec); | ||
141 | void snd_hdac_power_down(struct hdac_device *codec); | ||
142 | void snd_hdac_power_up_pm(struct hdac_device *codec); | ||
143 | void snd_hdac_power_down_pm(struct hdac_device *codec); | ||
144 | #else | ||
145 | static inline void snd_hdac_power_up(struct hdac_device *codec) {} | ||
146 | static inline void snd_hdac_power_down(struct hdac_device *codec) {} | ||
147 | static inline void snd_hdac_power_up_pm(struct hdac_device *codec) {} | ||
148 | static inline void snd_hdac_power_down_pm(struct hdac_device *codec) {} | ||
149 | #endif | ||
150 | |||
151 | /* | ||
152 | * HD-audio codec base driver | ||
153 | */ | ||
154 | struct hdac_driver { | ||
155 | struct device_driver driver; | ||
156 | int type; | ||
157 | int (*match)(struct hdac_device *dev, struct hdac_driver *drv); | ||
158 | void (*unsol_event)(struct hdac_device *dev, unsigned int event); | ||
159 | }; | ||
160 | |||
161 | #define drv_to_hdac_driver(_drv) container_of(_drv, struct hdac_driver, driver) | ||
162 | |||
163 | /* | ||
164 | * HD-audio bus base driver | ||
165 | */ | ||
166 | struct hdac_bus_ops { | ||
167 | /* send a single command */ | ||
168 | int (*command)(struct hdac_bus *bus, unsigned int cmd); | ||
169 | /* get a response from the last command */ | ||
170 | int (*get_response)(struct hdac_bus *bus, unsigned int addr, | ||
171 | unsigned int *res); | ||
172 | }; | ||
173 | |||
174 | #define HDA_UNSOL_QUEUE_SIZE 64 | ||
175 | |||
176 | struct hdac_bus { | ||
177 | struct device *dev; | ||
178 | const struct hdac_bus_ops *ops; | ||
179 | |||
180 | /* codec linked list */ | ||
181 | struct list_head codec_list; | ||
182 | unsigned int num_codecs; | ||
183 | |||
184 | /* link caddr -> codec */ | ||
185 | struct hdac_device *caddr_tbl[HDA_MAX_CODEC_ADDRESS + 1]; | ||
186 | |||
187 | /* unsolicited event queue */ | ||
188 | u32 unsol_queue[HDA_UNSOL_QUEUE_SIZE * 2]; /* ring buffer */ | ||
189 | unsigned int unsol_rp, unsol_wp; | ||
190 | struct work_struct unsol_work; | ||
191 | |||
192 | /* bit flags of powered codecs */ | ||
193 | unsigned long codec_powered; | ||
194 | |||
195 | /* flags */ | ||
196 | bool sync_write:1; /* sync after verb write */ | ||
197 | |||
198 | /* locks */ | ||
199 | struct mutex cmd_mutex; | ||
200 | }; | ||
201 | |||
202 | int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev, | ||
203 | const struct hdac_bus_ops *ops); | ||
204 | void snd_hdac_bus_exit(struct hdac_bus *bus); | ||
205 | int snd_hdac_bus_exec_verb(struct hdac_bus *bus, unsigned int addr, | ||
206 | unsigned int cmd, unsigned int *res); | ||
207 | int snd_hdac_bus_exec_verb_unlocked(struct hdac_bus *bus, unsigned int addr, | ||
208 | unsigned int cmd, unsigned int *res); | ||
209 | void snd_hdac_bus_queue_event(struct hdac_bus *bus, u32 res, u32 res_ex); | ||
210 | |||
211 | int snd_hdac_bus_add_device(struct hdac_bus *bus, struct hdac_device *codec); | ||
212 | void snd_hdac_bus_remove_device(struct hdac_bus *bus, | ||
213 | struct hdac_device *codec); | ||
214 | |||
215 | static inline void snd_hdac_codec_link_up(struct hdac_device *codec) | ||
216 | { | ||
217 | set_bit(codec->addr, &codec->bus->codec_powered); | ||
218 | } | ||
219 | |||
220 | static inline void snd_hdac_codec_link_down(struct hdac_device *codec) | ||
221 | { | ||
222 | clear_bit(codec->addr, &codec->bus->codec_powered); | ||
223 | } | ||
224 | |||
225 | /* | ||
226 | * generic array helpers | ||
227 | */ | ||
228 | void *snd_array_new(struct snd_array *array); | ||
229 | void snd_array_free(struct snd_array *array); | ||
230 | static inline void snd_array_init(struct snd_array *array, unsigned int size, | ||
231 | unsigned int align) | ||
232 | { | ||
233 | array->elem_size = size; | ||
234 | array->alloc_align = align; | ||
235 | } | ||
236 | |||
237 | static inline void *snd_array_elem(struct snd_array *array, unsigned int idx) | ||
238 | { | ||
239 | return array->list + idx * array->elem_size; | ||
240 | } | ||
241 | |||
242 | static inline unsigned int snd_array_index(struct snd_array *array, void *ptr) | ||
243 | { | ||
244 | return (unsigned long)(ptr - array->list) / array->elem_size; | ||
245 | } | ||
246 | |||
247 | #endif /* __SOUND_HDAUDIO_H */ | ||
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 | ||
61 | struct snd_pcm_substream; | 61 | struct snd_pcm_substream; |
62 | 62 | ||
63 | struct snd_pcm_audio_tstamp_config; /* definitions further down */ | ||
64 | struct snd_pcm_audio_tstamp_report; | ||
65 | |||
63 | struct snd_pcm_ops { | 66 | struct 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 | ||
282 | struct snd_pcm_hwptr_log; | 287 | struct 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 | */ | ||
293 | struct 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 | |||
299 | static 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 | */ | ||
310 | struct 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 | |||
324 | static 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 | |||
284 | struct snd_pcm_runtime { | 341 | struct 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 | ||
369 | static inline void | ||
370 | params_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/rt5670.h b/include/sound/rt5670.h index bd311197a3b5..b7d60510819b 100644 --- a/include/sound/rt5670.h +++ b/include/sound/rt5670.h | |||
@@ -14,6 +14,7 @@ | |||
14 | struct rt5670_platform_data { | 14 | struct rt5670_platform_data { |
15 | int jd_mode; | 15 | int jd_mode; |
16 | bool in2_diff; | 16 | bool in2_diff; |
17 | bool dev_gpio; | ||
17 | 18 | ||
18 | bool dmic_en; | 19 | bool dmic_en; |
19 | unsigned int dmic1_data_pin; | 20 | unsigned int dmic1_data_pin; |
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 | |||
34 | struct snd_seq_device { | 28 | struct 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 | */ |
62 | struct snd_seq_dev_ops { | 59 | struct 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 | ||
70 | void snd_seq_device_load_drivers(void); | 72 | void snd_seq_device_load_drivers(void); |
71 | int snd_seq_device_new(struct snd_card *card, int device, char *id, int argsize, struct snd_seq_device **result); | 73 | #else |
72 | int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry, int argsize); | 74 | #define snd_seq_device_load_drivers() |
73 | int snd_seq_device_unregister_driver(char *id); | 75 | #endif |
76 | int 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 | ||
81 | int __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) | ||
85 | void 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, | |||
99 | int snd_seq_event_port_detach(int client, int port); | 99 | int snd_seq_event_port_detach(int client, int port); |
100 | 100 | ||
101 | #ifdef CONFIG_MODULES | 101 | #ifdef CONFIG_MODULES |
102 | void snd_seq_autoload_lock(void); | ||
103 | void snd_seq_autoload_unlock(void); | ||
104 | void snd_seq_autoload_init(void); | 102 | void snd_seq_autoload_init(void); |
105 | #define snd_seq_autoload_exit() snd_seq_autoload_lock() | 103 | void 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/simple_card.h b/include/sound/simple_card.h index 1255ddb1d3e2..b9b4f289fe6b 100644 --- a/include/sound/simple_card.h +++ b/include/sound/simple_card.h | |||
@@ -16,7 +16,6 @@ | |||
16 | 16 | ||
17 | struct asoc_simple_dai { | 17 | struct asoc_simple_dai { |
18 | const char *name; | 18 | const char *name; |
19 | unsigned int fmt; | ||
20 | unsigned int sysclk; | 19 | unsigned int sysclk; |
21 | int slots; | 20 | int slots; |
22 | int slot_width; | 21 | int slot_width; |
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index 8d7416e46861..0bc83647d3fa 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h | |||
@@ -378,6 +378,7 @@ int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card); | |||
378 | void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card); | 378 | void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card); |
379 | int snd_soc_dapm_new_pcm(struct snd_soc_card *card, | 379 | int snd_soc_dapm_new_pcm(struct snd_soc_card *card, |
380 | const struct snd_soc_pcm_stream *params, | 380 | const struct snd_soc_pcm_stream *params, |
381 | unsigned int num_params, | ||
381 | struct snd_soc_dapm_widget *source, | 382 | struct snd_soc_dapm_widget *source, |
382 | struct snd_soc_dapm_widget *sink); | 383 | struct snd_soc_dapm_widget *sink); |
383 | 384 | ||
@@ -440,7 +441,6 @@ void dapm_mark_endpoints_dirty(struct snd_soc_card *card); | |||
440 | int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream, | 441 | int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream, |
441 | struct snd_soc_dapm_widget_list **list); | 442 | struct snd_soc_dapm_widget_list **list); |
442 | 443 | ||
443 | struct snd_soc_codec *snd_soc_dapm_kcontrol_codec(struct snd_kcontrol *kcontrol); | ||
444 | struct snd_soc_dapm_context *snd_soc_dapm_kcontrol_dapm( | 444 | struct snd_soc_dapm_context *snd_soc_dapm_kcontrol_dapm( |
445 | struct snd_kcontrol *kcontrol); | 445 | struct snd_kcontrol *kcontrol); |
446 | 446 | ||
@@ -531,6 +531,8 @@ struct snd_soc_dapm_widget { | |||
531 | void *priv; /* widget specific data */ | 531 | void *priv; /* widget specific data */ |
532 | struct regulator *regulator; /* attached regulator */ | 532 | struct regulator *regulator; /* attached regulator */ |
533 | const struct snd_soc_pcm_stream *params; /* params for dai links */ | 533 | const struct snd_soc_pcm_stream *params; /* params for dai links */ |
534 | unsigned int num_params; /* number of params for dai links */ | ||
535 | unsigned int params_select; /* currently selected param for dai link */ | ||
534 | 536 | ||
535 | /* dapm control */ | 537 | /* dapm control */ |
536 | int reg; /* negative reg = no direct dapm */ | 538 | int reg; /* negative reg = no direct dapm */ |
@@ -586,8 +588,6 @@ struct snd_soc_dapm_update { | |||
586 | /* DAPM context */ | 588 | /* DAPM context */ |
587 | struct snd_soc_dapm_context { | 589 | struct snd_soc_dapm_context { |
588 | enum snd_soc_bias_level bias_level; | 590 | enum snd_soc_bias_level bias_level; |
589 | enum snd_soc_bias_level suspend_bias_level; | ||
590 | struct delayed_work delayed_work; | ||
591 | unsigned int idle_bias_off:1; /* Use BIAS_OFF instead of STANDBY */ | 591 | unsigned int idle_bias_off:1; /* Use BIAS_OFF instead of STANDBY */ |
592 | /* Go to BIAS_OFF in suspend if the DAPM context is idle */ | 592 | /* Go to BIAS_OFF in suspend if the DAPM context is idle */ |
593 | unsigned int suspend_bias_off:1; | 593 | unsigned int suspend_bias_off:1; |
diff --git a/include/sound/soc-dpcm.h b/include/sound/soc-dpcm.h index 98f2ade0266e..806059052bfc 100644 --- a/include/sound/soc-dpcm.h +++ b/include/sound/soc-dpcm.h | |||
@@ -135,7 +135,7 @@ void snd_soc_dpcm_be_set_state(struct snd_soc_pcm_runtime *be, int stream, | |||
135 | 135 | ||
136 | /* internal use only */ | 136 | /* internal use only */ |
137 | int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute); | 137 | int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute); |
138 | int soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd); | 138 | void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd); |
139 | int soc_dpcm_runtime_update(struct snd_soc_card *); | 139 | int soc_dpcm_runtime_update(struct snd_soc_card *); |
140 | 140 | ||
141 | int dpcm_path_get(struct snd_soc_pcm_runtime *fe, | 141 | int dpcm_path_get(struct snd_soc_pcm_runtime *fe, |
diff --git a/include/sound/soc.h b/include/sound/soc.h index 0d1ade195628..fcb312b3f258 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 */ |
453 | int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type, | 453 | int 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 | |||
455 | void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask); | 457 | void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask); |
456 | int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count, | 458 | int 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 { | |||
659 | struct snd_soc_jack { | 661 | struct 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; |
@@ -941,6 +943,7 @@ struct snd_soc_dai_link { | |||
941 | int be_id; /* optional ID for machine driver BE identification */ | 943 | int be_id; /* optional ID for machine driver BE identification */ |
942 | 944 | ||
943 | const struct snd_soc_pcm_stream *params; | 945 | const struct snd_soc_pcm_stream *params; |
946 | unsigned int num_params; | ||
944 | 947 | ||
945 | unsigned int dai_fmt; /* format to set on init */ | 948 | unsigned int dai_fmt; /* format to set on init */ |
946 | 949 | ||
@@ -954,6 +957,9 @@ struct snd_soc_dai_link { | |||
954 | unsigned int symmetric_channels:1; | 957 | unsigned int symmetric_channels:1; |
955 | unsigned int symmetric_samplebits:1; | 958 | unsigned int symmetric_samplebits:1; |
956 | 959 | ||
960 | /* Mark this pcm with non atomic ops */ | ||
961 | bool nonatomic; | ||
962 | |||
957 | /* Do not create a PCM for this DAI link (Backend link) */ | 963 | /* Do not create a PCM for this DAI link (Backend link) */ |
958 | unsigned int no_pcm:1; | 964 | unsigned int no_pcm:1; |
959 | 965 | ||
@@ -1071,11 +1077,16 @@ struct snd_soc_card { | |||
1071 | 1077 | ||
1072 | /* | 1078 | /* |
1073 | * Card-specific routes and widgets. | 1079 | * Card-specific routes and widgets. |
1080 | * Note: of_dapm_xxx for Device Tree; Otherwise for driver build-in. | ||
1074 | */ | 1081 | */ |
1075 | const struct snd_soc_dapm_widget *dapm_widgets; | 1082 | const struct snd_soc_dapm_widget *dapm_widgets; |
1076 | int num_dapm_widgets; | 1083 | int num_dapm_widgets; |
1077 | const struct snd_soc_dapm_route *dapm_routes; | 1084 | const struct snd_soc_dapm_route *dapm_routes; |
1078 | int num_dapm_routes; | 1085 | int num_dapm_routes; |
1086 | const struct snd_soc_dapm_widget *of_dapm_widgets; | ||
1087 | int num_of_dapm_widgets; | ||
1088 | const struct snd_soc_dapm_route *of_dapm_routes; | ||
1089 | int num_of_dapm_routes; | ||
1079 | bool fully_routed; | 1090 | bool fully_routed; |
1080 | 1091 | ||
1081 | struct work_struct deferred_resume_work; | 1092 | struct work_struct deferred_resume_work; |
@@ -1258,6 +1269,19 @@ static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm( | |||
1258 | return component->dapm_ptr; | 1269 | return component->dapm_ptr; |
1259 | } | 1270 | } |
1260 | 1271 | ||
1272 | /** | ||
1273 | * snd_soc_dapm_kcontrol_codec() - Returns the codec associated to a kcontrol | ||
1274 | * @kcontrol: The kcontrol | ||
1275 | * | ||
1276 | * This function must only be used on DAPM contexts that are known to be part of | ||
1277 | * a CODEC (e.g. in a CODEC driver). Otherwise the behavior is undefined. | ||
1278 | */ | ||
1279 | static inline struct snd_soc_codec *snd_soc_dapm_kcontrol_codec( | ||
1280 | struct snd_kcontrol *kcontrol) | ||
1281 | { | ||
1282 | return snd_soc_dapm_to_codec(snd_soc_dapm_kcontrol_dapm(kcontrol)); | ||
1283 | } | ||
1284 | |||
1261 | /* codec IO */ | 1285 | /* codec IO */ |
1262 | unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg); | 1286 | unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg); |
1263 | int snd_soc_write(struct snd_soc_codec *codec, unsigned int reg, | 1287 | int snd_soc_write(struct snd_soc_codec *codec, unsigned int reg, |
@@ -1469,7 +1493,7 @@ static inline struct snd_soc_codec *snd_soc_kcontrol_codec( | |||
1469 | } | 1493 | } |
1470 | 1494 | ||
1471 | /** | 1495 | /** |
1472 | * snd_soc_kcontrol_platform() - Returns the platform that registerd the control | 1496 | * snd_soc_kcontrol_platform() - Returns the platform that registered the control |
1473 | * @kcontrol: The control for which to get the platform | 1497 | * @kcontrol: The control for which to get the platform |
1474 | * | 1498 | * |
1475 | * Note: This function will only work correctly if the control has been | 1499 | * 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 | ||
145 | typedef unsigned long snd_pcm_uframes_t; | 148 | typedef unsigned long snd_pcm_uframes_t; |
146 | typedef signed long snd_pcm_sframes_t; | 149 | typedef 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 | |||
274 | typedef int __bitwise snd_pcm_state_t; | 284 | typedef 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 | ||
421 | enum { | ||
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 | |||
411 | struct snd_pcm_status { | 437 | struct 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 | ||
427 | struct snd_pcm_mmap_status { | 455 | struct 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 | */ |
80 | struct snd_compr_avail { | 80 | struct 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/Kconfig b/sound/Kconfig index c710ce2c5c37..5a240e050ae6 100644 --- a/sound/Kconfig +++ b/sound/Kconfig | |||
@@ -76,6 +76,8 @@ source "sound/isa/Kconfig" | |||
76 | 76 | ||
77 | source "sound/pci/Kconfig" | 77 | source "sound/pci/Kconfig" |
78 | 78 | ||
79 | source "sound/hda/Kconfig" | ||
80 | |||
79 | source "sound/ppc/Kconfig" | 81 | source "sound/ppc/Kconfig" |
80 | 82 | ||
81 | source "sound/aoa/Kconfig" | 83 | source "sound/aoa/Kconfig" |
diff --git a/sound/Makefile b/sound/Makefile index ce9132b1c395..77320709fd26 100644 --- a/sound/Makefile +++ b/sound/Makefile | |||
@@ -6,7 +6,7 @@ obj-$(CONFIG_SOUND_PRIME) += sound_firmware.o | |||
6 | obj-$(CONFIG_SOUND_PRIME) += oss/ | 6 | obj-$(CONFIG_SOUND_PRIME) += oss/ |
7 | obj-$(CONFIG_DMASOUND) += oss/ | 7 | obj-$(CONFIG_DMASOUND) += oss/ |
8 | obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \ | 8 | obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \ |
9 | firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ | 9 | firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ hda/ |
10 | obj-$(CONFIG_SND_AOA) += aoa/ | 10 | obj-$(CONFIG_SND_AOA) += aoa/ |
11 | 11 | ||
12 | # This one must be compilable even if sound is configured out | 12 | # This one must be compilable even if sound is configured out |
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); | |||
31 | MODULE_PARM_DESC(force, "Force loading i2sbus even when" | 31 | MODULE_PARM_DESC(force, "Force loading i2sbus even when" |
32 | " no layout-id property is present"); | 32 | " no layout-id property is present"); |
33 | 33 | ||
34 | static struct of_device_id i2sbus_match[] = { | 34 | static 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..196a6fe100ca 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, | |||
192 | EXPORT_SYMBOL(snd_ctl_notify); | 192 | EXPORT_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 | */ |
204 | static struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control, | 207 | static 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, | |||
238 | struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol, | 243 | struct 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 | } |
273 | EXPORT_SYMBOL(snd_ctl_new1); | 294 | EXPORT_SYMBOL(snd_ctl_new1); |
274 | 295 | ||
@@ -557,6 +578,7 @@ error: | |||
557 | * | 578 | * |
558 | * Finds the control instance with the given id, and activate or | 579 | * Finds the control instance with the given id, and activate or |
559 | * inactivate the control together with notification, if changed. | 580 | * inactivate the control together with notification, if changed. |
581 | * The given ID data is filled with full information. | ||
560 | * | 582 | * |
561 | * Return: 0 if unchanged, 1 if changed, or a negative error code on failure. | 583 | * Return: 0 if unchanged, 1 if changed, or a negative error code on failure. |
562 | */ | 584 | */ |
@@ -586,6 +608,7 @@ int snd_ctl_activate_id(struct snd_card *card, struct snd_ctl_elem_id *id, | |||
586 | goto unlock; | 608 | goto unlock; |
587 | vd->access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; | 609 | vd->access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
588 | } | 610 | } |
611 | snd_ctl_build_ioff(id, kctl, index_offset); | ||
589 | ret = 1; | 612 | ret = 1; |
590 | unlock: | 613 | unlock: |
591 | up_write(&card->controls_rwsem); | 614 | up_write(&card->controls_rwsem); |
@@ -1006,7 +1029,7 @@ static int snd_ctl_elem_unlock(struct snd_ctl_file *file, | |||
1006 | struct user_element { | 1029 | struct user_element { |
1007 | struct snd_ctl_elem_info info; | 1030 | struct snd_ctl_elem_info info; |
1008 | struct snd_card *card; | 1031 | struct snd_card *card; |
1009 | void *elem_data; /* element data */ | 1032 | char *elem_data; /* element data */ |
1010 | unsigned long elem_data_size; /* size of element data in bytes */ | 1033 | unsigned long elem_data_size; /* size of element data in bytes */ |
1011 | void *tlv_data; /* TLV data */ | 1034 | void *tlv_data; /* TLV data */ |
1012 | unsigned long tlv_data_size; /* TLV data size */ | 1035 | unsigned long tlv_data_size; /* TLV data size */ |
@@ -1017,8 +1040,12 @@ static int snd_ctl_elem_user_info(struct snd_kcontrol *kcontrol, | |||
1017 | struct snd_ctl_elem_info *uinfo) | 1040 | struct snd_ctl_elem_info *uinfo) |
1018 | { | 1041 | { |
1019 | struct user_element *ue = kcontrol->private_data; | 1042 | struct user_element *ue = kcontrol->private_data; |
1043 | unsigned int offset; | ||
1020 | 1044 | ||
1045 | offset = snd_ctl_get_ioff(kcontrol, &uinfo->id); | ||
1021 | *uinfo = ue->info; | 1046 | *uinfo = ue->info; |
1047 | snd_ctl_build_ioff(&uinfo->id, kcontrol, offset); | ||
1048 | |||
1022 | return 0; | 1049 | return 0; |
1023 | } | 1050 | } |
1024 | 1051 | ||
@@ -1028,10 +1055,13 @@ static int snd_ctl_elem_user_enum_info(struct snd_kcontrol *kcontrol, | |||
1028 | struct user_element *ue = kcontrol->private_data; | 1055 | struct user_element *ue = kcontrol->private_data; |
1029 | const char *names; | 1056 | const char *names; |
1030 | unsigned int item; | 1057 | unsigned int item; |
1058 | unsigned int offset; | ||
1031 | 1059 | ||
1032 | item = uinfo->value.enumerated.item; | 1060 | item = uinfo->value.enumerated.item; |
1033 | 1061 | ||
1062 | offset = snd_ctl_get_ioff(kcontrol, &uinfo->id); | ||
1034 | *uinfo = ue->info; | 1063 | *uinfo = ue->info; |
1064 | snd_ctl_build_ioff(&uinfo->id, kcontrol, offset); | ||
1035 | 1065 | ||
1036 | item = min(item, uinfo->value.enumerated.items - 1); | 1066 | item = min(item, uinfo->value.enumerated.items - 1); |
1037 | uinfo->value.enumerated.item = item; | 1067 | uinfo->value.enumerated.item = item; |
@@ -1048,9 +1078,12 @@ static int snd_ctl_elem_user_get(struct snd_kcontrol *kcontrol, | |||
1048 | struct snd_ctl_elem_value *ucontrol) | 1078 | struct snd_ctl_elem_value *ucontrol) |
1049 | { | 1079 | { |
1050 | struct user_element *ue = kcontrol->private_data; | 1080 | struct user_element *ue = kcontrol->private_data; |
1081 | unsigned int size = ue->elem_data_size; | ||
1082 | char *src = ue->elem_data + | ||
1083 | snd_ctl_get_ioff(kcontrol, &ucontrol->id) * size; | ||
1051 | 1084 | ||
1052 | mutex_lock(&ue->card->user_ctl_lock); | 1085 | mutex_lock(&ue->card->user_ctl_lock); |
1053 | memcpy(&ucontrol->value, ue->elem_data, ue->elem_data_size); | 1086 | memcpy(&ucontrol->value, src, size); |
1054 | mutex_unlock(&ue->card->user_ctl_lock); | 1087 | mutex_unlock(&ue->card->user_ctl_lock); |
1055 | return 0; | 1088 | return 0; |
1056 | } | 1089 | } |
@@ -1060,11 +1093,14 @@ static int snd_ctl_elem_user_put(struct snd_kcontrol *kcontrol, | |||
1060 | { | 1093 | { |
1061 | int change; | 1094 | int change; |
1062 | struct user_element *ue = kcontrol->private_data; | 1095 | struct user_element *ue = kcontrol->private_data; |
1096 | unsigned int size = ue->elem_data_size; | ||
1097 | char *dst = ue->elem_data + | ||
1098 | snd_ctl_get_ioff(kcontrol, &ucontrol->id) * size; | ||
1063 | 1099 | ||
1064 | mutex_lock(&ue->card->user_ctl_lock); | 1100 | mutex_lock(&ue->card->user_ctl_lock); |
1065 | change = memcmp(&ucontrol->value, ue->elem_data, ue->elem_data_size) != 0; | 1101 | change = memcmp(&ucontrol->value, dst, size) != 0; |
1066 | if (change) | 1102 | if (change) |
1067 | memcpy(ue->elem_data, &ucontrol->value, ue->elem_data_size); | 1103 | memcpy(dst, &ucontrol->value, size); |
1068 | mutex_unlock(&ue->card->user_ctl_lock); | 1104 | mutex_unlock(&ue->card->user_ctl_lock); |
1069 | return change; | 1105 | return change; |
1070 | } | 1106 | } |
@@ -1078,7 +1114,7 @@ static int snd_ctl_elem_user_tlv(struct snd_kcontrol *kcontrol, | |||
1078 | int change = 0; | 1114 | int change = 0; |
1079 | void *new_data; | 1115 | void *new_data; |
1080 | 1116 | ||
1081 | if (op_flag > 0) { | 1117 | if (op_flag == SNDRV_CTL_TLV_OP_WRITE) { |
1082 | if (size > 1024 * 128) /* sane value */ | 1118 | if (size > 1024 * 128) /* sane value */ |
1083 | return -EINVAL; | 1119 | return -EINVAL; |
1084 | 1120 | ||
@@ -1161,84 +1197,103 @@ static void snd_ctl_elem_user_free(struct snd_kcontrol *kcontrol) | |||
1161 | static int snd_ctl_elem_add(struct snd_ctl_file *file, | 1197 | static int snd_ctl_elem_add(struct snd_ctl_file *file, |
1162 | struct snd_ctl_elem_info *info, int replace) | 1198 | struct snd_ctl_elem_info *info, int replace) |
1163 | { | 1199 | { |
1200 | /* The capacity of struct snd_ctl_elem_value.value.*/ | ||
1201 | static const unsigned int value_sizes[] = { | ||
1202 | [SNDRV_CTL_ELEM_TYPE_BOOLEAN] = sizeof(long), | ||
1203 | [SNDRV_CTL_ELEM_TYPE_INTEGER] = sizeof(long), | ||
1204 | [SNDRV_CTL_ELEM_TYPE_ENUMERATED] = sizeof(unsigned int), | ||
1205 | [SNDRV_CTL_ELEM_TYPE_BYTES] = sizeof(unsigned char), | ||
1206 | [SNDRV_CTL_ELEM_TYPE_IEC958] = sizeof(struct snd_aes_iec958), | ||
1207 | [SNDRV_CTL_ELEM_TYPE_INTEGER64] = sizeof(long long), | ||
1208 | }; | ||
1209 | static const unsigned int max_value_counts[] = { | ||
1210 | [SNDRV_CTL_ELEM_TYPE_BOOLEAN] = 128, | ||
1211 | [SNDRV_CTL_ELEM_TYPE_INTEGER] = 128, | ||
1212 | [SNDRV_CTL_ELEM_TYPE_ENUMERATED] = 128, | ||
1213 | [SNDRV_CTL_ELEM_TYPE_BYTES] = 512, | ||
1214 | [SNDRV_CTL_ELEM_TYPE_IEC958] = 1, | ||
1215 | [SNDRV_CTL_ELEM_TYPE_INTEGER64] = 64, | ||
1216 | }; | ||
1164 | struct snd_card *card = file->card; | 1217 | struct snd_card *card = file->card; |
1165 | struct snd_kcontrol kctl, *_kctl; | 1218 | struct snd_kcontrol *kctl; |
1219 | unsigned int count; | ||
1166 | unsigned int access; | 1220 | unsigned int access; |
1167 | long private_size; | 1221 | long private_size; |
1168 | struct user_element *ue; | 1222 | struct user_element *ue; |
1169 | int idx, err; | 1223 | unsigned int offset; |
1224 | int err; | ||
1170 | 1225 | ||
1171 | if (info->count < 1) | ||
1172 | return -EINVAL; | ||
1173 | if (!*info->id.name) | 1226 | if (!*info->id.name) |
1174 | return -EINVAL; | 1227 | return -EINVAL; |
1175 | if (strnlen(info->id.name, sizeof(info->id.name)) >= sizeof(info->id.name)) | 1228 | if (strnlen(info->id.name, sizeof(info->id.name)) >= sizeof(info->id.name)) |
1176 | return -EINVAL; | 1229 | 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 | 1230 | ||
1231 | /* Delete a control to replace them if needed. */ | ||
1184 | if (replace) { | 1232 | if (replace) { |
1233 | info->id.numid = 0; | ||
1185 | err = snd_ctl_remove_user_ctl(file, &info->id); | 1234 | err = snd_ctl_remove_user_ctl(file, &info->id); |
1186 | if (err) | 1235 | if (err) |
1187 | return err; | 1236 | return err; |
1188 | } | 1237 | } |
1189 | 1238 | ||
1190 | if (card->user_ctl_count >= MAX_USER_CONTROLS) | 1239 | /* |
1240 | * The number of userspace controls are counted control by control, | ||
1241 | * not element by element. | ||
1242 | */ | ||
1243 | if (card->user_ctl_count + 1 > MAX_USER_CONTROLS) | ||
1191 | return -ENOMEM; | 1244 | return -ENOMEM; |
1192 | 1245 | ||
1193 | memcpy(&kctl.id, &info->id, sizeof(info->id)); | 1246 | /* Check the number of elements for this userspace control. */ |
1194 | kctl.count = info->owner ? info->owner : 1; | 1247 | count = info->owner; |
1195 | access |= SNDRV_CTL_ELEM_ACCESS_USER; | 1248 | if (count == 0) |
1196 | if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) | 1249 | count = 1; |
1197 | kctl.info = snd_ctl_elem_user_enum_info; | 1250 | |
1198 | else | 1251 | /* Arrange access permissions if needed. */ |
1199 | kctl.info = snd_ctl_elem_user_info; | 1252 | access = info->access; |
1200 | if (access & SNDRV_CTL_ELEM_ACCESS_READ) | 1253 | if (access == 0) |
1201 | kctl.get = snd_ctl_elem_user_get; | 1254 | access = SNDRV_CTL_ELEM_ACCESS_READWRITE; |
1202 | if (access & SNDRV_CTL_ELEM_ACCESS_WRITE) | 1255 | access &= (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
1203 | kctl.put = snd_ctl_elem_user_put; | 1256 | SNDRV_CTL_ELEM_ACCESS_INACTIVE | |
1204 | if (access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) { | 1257 | SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE); |
1205 | kctl.tlv.c = snd_ctl_elem_user_tlv; | 1258 | if (access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) |
1206 | access |= SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; | 1259 | access |= SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; |
1207 | } | 1260 | access |= SNDRV_CTL_ELEM_ACCESS_USER; |
1208 | switch (info->type) { | 1261 | |
1209 | case SNDRV_CTL_ELEM_TYPE_BOOLEAN: | 1262 | /* |
1210 | case SNDRV_CTL_ELEM_TYPE_INTEGER: | 1263 | * Check information and calculate the size of data specific to |
1211 | private_size = sizeof(long); | 1264 | * this userspace control. |
1212 | if (info->count > 128) | 1265 | */ |
1213 | return -EINVAL; | 1266 | if (info->type < SNDRV_CTL_ELEM_TYPE_BOOLEAN || |
1214 | break; | 1267 | 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; | 1268 | return -EINVAL; |
1237 | } | 1269 | if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED && |
1238 | private_size *= info->count; | 1270 | info->value.enumerated.items == 0) |
1239 | ue = kzalloc(sizeof(struct user_element) + private_size, GFP_KERNEL); | 1271 | return -EINVAL; |
1240 | if (ue == NULL) | 1272 | if (info->count < 1 || |
1273 | info->count > max_value_counts[info->type]) | ||
1274 | return -EINVAL; | ||
1275 | private_size = value_sizes[info->type] * info->count; | ||
1276 | |||
1277 | /* | ||
1278 | * Keep memory object for this userspace control. After passing this | ||
1279 | * code block, the instance should be freed by snd_ctl_free_one(). | ||
1280 | * | ||
1281 | * Note that these elements in this control are locked. | ||
1282 | */ | ||
1283 | err = snd_ctl_new(&kctl, count, access, file); | ||
1284 | if (err < 0) | ||
1285 | return err; | ||
1286 | memcpy(&kctl->id, &info->id, sizeof(kctl->id)); | ||
1287 | kctl->private_data = kzalloc(sizeof(struct user_element) + private_size * count, | ||
1288 | GFP_KERNEL); | ||
1289 | if (kctl->private_data == NULL) { | ||
1290 | kfree(kctl); | ||
1241 | return -ENOMEM; | 1291 | return -ENOMEM; |
1292 | } | ||
1293 | kctl->private_free = snd_ctl_elem_user_free; | ||
1294 | |||
1295 | /* Set private data for this userspace control. */ | ||
1296 | ue = (struct user_element *)kctl->private_data; | ||
1242 | ue->card = card; | 1297 | ue->card = card; |
1243 | ue->info = *info; | 1298 | ue->info = *info; |
1244 | ue->info.access = 0; | 1299 | ue->info.access = 0; |
@@ -1247,23 +1302,36 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file, | |||
1247 | if (ue->info.type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) { | 1302 | if (ue->info.type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) { |
1248 | err = snd_ctl_elem_init_enum_names(ue); | 1303 | err = snd_ctl_elem_init_enum_names(ue); |
1249 | if (err < 0) { | 1304 | if (err < 0) { |
1250 | kfree(ue); | 1305 | snd_ctl_free_one(kctl); |
1251 | return err; | 1306 | return err; |
1252 | } | 1307 | } |
1253 | } | 1308 | } |
1254 | kctl.private_free = snd_ctl_elem_user_free; | 1309 | |
1255 | _kctl = snd_ctl_new(&kctl, access); | 1310 | /* Set callback functions. */ |
1256 | if (_kctl == NULL) { | 1311 | if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) |
1257 | kfree(ue->priv_data); | 1312 | kctl->info = snd_ctl_elem_user_enum_info; |
1258 | kfree(ue); | 1313 | else |
1259 | return -ENOMEM; | 1314 | kctl->info = snd_ctl_elem_user_info; |
1260 | } | 1315 | if (access & SNDRV_CTL_ELEM_ACCESS_READ) |
1261 | _kctl->private_data = ue; | 1316 | kctl->get = snd_ctl_elem_user_get; |
1262 | for (idx = 0; idx < _kctl->count; idx++) | 1317 | if (access & SNDRV_CTL_ELEM_ACCESS_WRITE) |
1263 | _kctl->vd[idx].owner = file; | 1318 | kctl->put = snd_ctl_elem_user_put; |
1264 | err = snd_ctl_add(card, _kctl); | 1319 | if (access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) |
1320 | kctl->tlv.c = snd_ctl_elem_user_tlv; | ||
1321 | |||
1322 | /* This function manage to free the instance on failure. */ | ||
1323 | err = snd_ctl_add(card, kctl); | ||
1265 | if (err < 0) | 1324 | if (err < 0) |
1266 | return err; | 1325 | return err; |
1326 | offset = snd_ctl_get_ioff(kctl, &info->id); | ||
1327 | snd_ctl_build_ioff(&info->id, kctl, offset); | ||
1328 | /* | ||
1329 | * Here we cannot fill any field for the number of elements added by | ||
1330 | * this operation because there're no specific fields. The usage of | ||
1331 | * 'owner' field for this purpose may cause any bugs to userspace | ||
1332 | * applications because the field originally means PID of a process | ||
1333 | * which locks the element. | ||
1334 | */ | ||
1267 | 1335 | ||
1268 | down_write(&card->controls_rwsem); | 1336 | down_write(&card->controls_rwsem); |
1269 | card->user_ctl_count++; | 1337 | card->user_ctl_count++; |
@@ -1276,9 +1344,19 @@ static int snd_ctl_elem_add_user(struct snd_ctl_file *file, | |||
1276 | struct snd_ctl_elem_info __user *_info, int replace) | 1344 | struct snd_ctl_elem_info __user *_info, int replace) |
1277 | { | 1345 | { |
1278 | struct snd_ctl_elem_info info; | 1346 | struct snd_ctl_elem_info info; |
1347 | int err; | ||
1348 | |||
1279 | if (copy_from_user(&info, _info, sizeof(info))) | 1349 | if (copy_from_user(&info, _info, sizeof(info))) |
1280 | return -EFAULT; | 1350 | return -EFAULT; |
1281 | return snd_ctl_elem_add(file, &info, replace); | 1351 | err = snd_ctl_elem_add(file, &info, replace); |
1352 | if (err < 0) | ||
1353 | return err; | ||
1354 | if (copy_to_user(_info, &info, sizeof(info))) { | ||
1355 | snd_ctl_remove_user_ctl(file, &info.id); | ||
1356 | return -EFAULT; | ||
1357 | } | ||
1358 | |||
1359 | return 0; | ||
1282 | } | 1360 | } |
1283 | 1361 | ||
1284 | static int snd_ctl_elem_remove(struct snd_ctl_file *file, | 1362 | static int snd_ctl_elem_remove(struct snd_ctl_file *file, |
@@ -1338,9 +1416,12 @@ static int snd_ctl_tlv_ioctl(struct snd_ctl_file *file, | |||
1338 | goto __kctl_end; | 1416 | goto __kctl_end; |
1339 | } | 1417 | } |
1340 | vd = &kctl->vd[tlv.numid - kctl->id.numid]; | 1418 | vd = &kctl->vd[tlv.numid - kctl->id.numid]; |
1341 | if ((op_flag == 0 && (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ) == 0) || | 1419 | if ((op_flag == SNDRV_CTL_TLV_OP_READ && |
1342 | (op_flag > 0 && (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) == 0) || | 1420 | (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ) == 0) || |
1343 | (op_flag < 0 && (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND) == 0)) { | 1421 | (op_flag == SNDRV_CTL_TLV_OP_WRITE && |
1422 | (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) == 0) || | ||
1423 | (op_flag == SNDRV_CTL_TLV_OP_CMD && | ||
1424 | (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND) == 0)) { | ||
1344 | err = -ENXIO; | 1425 | err = -ENXIO; |
1345 | goto __kctl_end; | 1426 | goto __kctl_end; |
1346 | } | 1427 | } |
@@ -1357,7 +1438,7 @@ static int snd_ctl_tlv_ioctl(struct snd_ctl_file *file, | |||
1357 | return 0; | 1438 | return 0; |
1358 | } | 1439 | } |
1359 | } else { | 1440 | } else { |
1360 | if (op_flag) { | 1441 | if (op_flag != SNDRV_CTL_TLV_OP_READ) { |
1361 | err = -ENXIO; | 1442 | err = -ENXIO; |
1362 | goto __kctl_end; | 1443 | goto __kctl_end; |
1363 | } | 1444 | } |
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 | } |
74 | EXPORT_SYMBOL(snd_device_new); | 72 | EXPORT_SYMBOL(snd_device_new); |
75 | 73 | ||
76 | static int __snd_device_disconnect(struct snd_device *dev) | 74 | static 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 | ||
87 | static void __snd_device_free(struct snd_device *dev) | 84 | static 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 | */ | ||
121 | void 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 | } | ||
134 | EXPORT_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 | */ |
198 | int snd_device_disconnect_all(struct snd_card *card) | 223 | void 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 = | |||
400 | int snd_card_disconnect(struct snd_card *card) | 400 | int 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(®ister_mutex); | 1075 | mutex_lock(®ister_mutex); |
1090 | err = snd_pcm_add(pcm); | 1076 | err = snd_pcm_add(pcm); |
1091 | if (err) { | 1077 | if (err) |
1092 | mutex_unlock(®ister_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(®ister_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(®ister_mutex); | 1108 | mutex_unlock(®ister_mutex); |
1125 | return 0; | 1109 | return err; |
1126 | } | 1110 | } |
1127 | 1111 | ||
1128 | static int snd_pcm_dev_disconnect(struct snd_device *device) | 1112 | static 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(®ister_mutex); | 1119 | mutex_lock(®ister_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(®ister_mutex); | 1147 | mutex_unlock(®ister_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 | ||
203 | static int snd_pcm_status_user_compat(struct snd_pcm_substream *substream, | 205 | static 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 | */ |
294 | int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream, | 294 | int 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 | */ |
333 | int snd_dmaengine_pcm_open_request_chan(struct snd_pcm_substream *substream, | 333 | int 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 | ||
235 | static 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 | |||
235 | static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream, | 278 | static 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 8e43610ec9b5..d126c03361ae 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 | ||
755 | static int snd_pcm_status_user(struct snd_pcm_substream *substream, | 779 | static 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 | ||
68 | static 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 | |||
68 | static int __init alsa_seq_oss_init(void) | 78 | static 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 | ||
105 | static void __exit alsa_seq_oss_exit(void) | 109 | static 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 | */ |
100 | int | 100 | int |
101 | snd_seq_oss_synth_register(struct snd_seq_device *dev) | 101 | snd_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 | ||
151 | int | 151 | int |
152 | snd_seq_oss_synth_unregister(struct snd_seq_device *dev) | 152 | snd_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 | ||
30 | void snd_seq_oss_synth_init(void); | 30 | void snd_seq_oss_synth_init(void); |
31 | int snd_seq_oss_synth_register(struct snd_seq_device *dev); | 31 | int snd_seq_oss_synth_probe(struct device *dev); |
32 | int snd_seq_oss_synth_unregister(struct snd_seq_device *dev); | 32 | int snd_seq_oss_synth_remove(struct device *dev); |
33 | void snd_seq_oss_synth_setup(struct seq_oss_devinfo *dp); | 33 | void snd_seq_oss_synth_setup(struct seq_oss_devinfo *dp); |
34 | void snd_seq_oss_synth_setup_midi(struct seq_oss_devinfo *dp); | 34 | void snd_seq_oss_synth_setup_midi(struct seq_oss_devinfo *dp); |
35 | void snd_seq_oss_synth_cleanup(struct seq_oss_devinfo *dp); | 35 | void snd_seq_oss_synth_cleanup(struct seq_oss_devinfo *dp); |
diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c index 48287651ac77..edbdab85fc02 100644 --- a/sound/core/seq/seq_clientmgr.c +++ b/sound/core/seq/seq_clientmgr.c | |||
@@ -1879,6 +1879,7 @@ static int snd_seq_ioctl_get_client_pool(struct snd_seq_client *client, | |||
1879 | if (cptr == NULL) | 1879 | if (cptr == NULL) |
1880 | return -ENOENT; | 1880 | return -ENOENT; |
1881 | memset(&info, 0, sizeof(info)); | 1881 | memset(&info, 0, sizeof(info)); |
1882 | info.client = cptr->number; | ||
1882 | info.output_pool = cptr->pool->size; | 1883 | info.output_pool = cptr->pool->size; |
1883 | info.output_room = cptr->pool->room; | 1884 | info.output_room = cptr->pool->room; |
1884 | info.output_free = info.output_pool; | 1885 | info.output_free = info.output_pool; |
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>"); | |||
51 | MODULE_DESCRIPTION("ALSA sequencer device management"); | 52 | MODULE_DESCRIPTION("ALSA sequencer device management"); |
52 | MODULE_LICENSE("GPL"); | 53 | MODULE_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) | 58 | static 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); | |
61 | struct 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 | ||
80 | static LIST_HEAD(opslist); | 67 | static struct bus_type snd_seq_bus_type = { |
81 | static int num_ops; | 68 | .name = "snd_seq", |
82 | static DEFINE_MUTEX(ops_mutex); | 69 | .match = snd_seq_bus_match, |
83 | #ifdef CONFIG_PROC_FS | 70 | }; |
84 | static struct snd_info_entry *info_entry; | ||
85 | #endif | ||
86 | 71 | ||
87 | /* | 72 | /* |
88 | * prototypes | 73 | * proc interface -- just for compatibility |
89 | */ | 74 | */ |
90 | static int snd_seq_device_free(struct snd_seq_device *dev); | 75 | #ifdef CONFIG_PROC_FS |
91 | static int snd_seq_device_dev_free(struct snd_device *device); | 76 | static struct snd_info_entry *info_entry; |
92 | static int snd_seq_device_dev_register(struct snd_device *device); | ||
93 | static int snd_seq_device_dev_disconnect(struct snd_device *device); | ||
94 | |||
95 | static int init_device(struct snd_seq_device *dev, struct ops_list *ops); | ||
96 | static int free_device(struct snd_seq_device *dev, struct ops_list *ops); | ||
97 | static struct ops_list *find_driver(char *id, int create_if_empty); | ||
98 | static struct ops_list *create_driver(char *id); | ||
99 | static void unlock_driver(struct ops_list *ops); | ||
100 | static void remove_drivers(void); | ||
101 | 77 | ||
102 | /* | 78 | static 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 | ||
107 | static void snd_seq_device_info(struct snd_info_entry *entry, | 89 | static 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 */ |
131 | static atomic_t snd_seq_in_init = ATOMIC_INIT(1); /* blocked as default */ | 102 | static atomic_t snd_seq_in_init = ATOMIC_INIT(1); /* blocked as default */ |
132 | void snd_seq_autoload_lock(void) | ||
133 | { | ||
134 | atomic_inc(&snd_seq_in_init); | ||
135 | } | ||
136 | 103 | ||
137 | void snd_seq_autoload_unlock(void) | 104 | static 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 | ||
142 | static void autoload_drivers(void) | 113 | static 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 | ||
165 | static void call_autoload(struct work_struct *work) | 122 | static DECLARE_WORK(autoload_work, autoload_drivers); |
166 | { | ||
167 | autoload_drivers(); | ||
168 | } | ||
169 | |||
170 | static DECLARE_WORK(autoload_work, call_autoload); | ||
171 | |||
172 | static 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 | ||
180 | static void queue_autoload_drivers(void) | 124 | static 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 | ||
190 | void snd_seq_autoload_init(void) | 129 | void 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 | 137 | EXPORT_SYMBOL(snd_seq_autoload_init); |
199 | #define try_autoload(ops) /* NOP */ | ||
200 | #endif | ||
201 | 138 | ||
202 | void snd_seq_device_load_drivers(void) | 139 | void 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 | } |
143 | EXPORT_SYMBOL(snd_seq_autoload_exit); | ||
209 | 144 | ||
210 | /* | 145 | void 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 | */ | ||
217 | int 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 | } |
150 | EXPORT_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 | */ |
275 | static 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 | |||
302 | static int snd_seq_device_dev_free(struct snd_device *device) | 158 | static 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 | */ | ||
311 | static int snd_seq_device_dev_register(struct snd_device *device) | 166 | static 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 | */ | ||
333 | static int snd_seq_device_dev_disconnect(struct snd_device *device) | 179 | static 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 | /* | 187 | static 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 | */ | ||
353 | int 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 | */ | ||
393 | static 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 | */ |
428 | int snd_seq_device_unregister_driver(char *id) | 203 | int 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; |
469 | static 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) { |
492 | static 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 | } |
248 | EXPORT_SYMBOL(snd_seq_device_new); | ||
513 | 249 | ||
514 | /* | 250 | /* |
515 | * release the device - call free_device operator | 251 | * driver registration |
516 | */ | 252 | */ |
517 | static int free_device(struct snd_seq_device *dev, struct ops_list *ops) | 253 | int __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 | } |
261 | EXPORT_SYMBOL_GPL(__snd_seq_driver_register); | ||
541 | 262 | ||
542 | /* | 263 | void snd_seq_driver_unregister(struct snd_seq_driver *drv) |
543 | * find the matching driver with given id | ||
544 | */ | ||
545 | static 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 | 267 | EXPORT_SYMBOL_GPL(snd_seq_driver_unregister); | |
563 | static 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 | ||
575 | static int __init alsa_seq_device_init(void) | 273 | static 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 | ||
290 | static 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 | |||
592 | static void __exit alsa_seq_device_exit(void) | 303 | static 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 | ||
605 | module_init(alsa_seq_device_init) | 314 | subsys_initcall(alsa_seq_device_init) |
606 | module_exit(alsa_seq_device_exit) | 315 | module_exit(alsa_seq_device_exit) |
607 | |||
608 | EXPORT_SYMBOL(snd_seq_device_load_drivers); | ||
609 | EXPORT_SYMBOL(snd_seq_device_new); | ||
610 | EXPORT_SYMBOL(snd_seq_device_register_driver); | ||
611 | EXPORT_SYMBOL(snd_seq_device_unregister_driver); | ||
612 | #ifdef CONFIG_MODULES | ||
613 | EXPORT_SYMBOL(snd_seq_autoload_init); | ||
614 | EXPORT_SYMBOL(snd_seq_autoload_lock); | ||
615 | EXPORT_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 | ||
215 | static int __init alsa_seq_dummy_init(void) | 215 | static 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 | ||
224 | static void __exit alsa_seq_dummy_exit(void) | 220 | static 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 */ |
275 | static int | 275 | static int |
276 | snd_seq_midisynth_register_port(struct snd_seq_device *dev) | 276 | snd_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 */ |
429 | static int | 430 | static int |
430 | snd_seq_midisynth_unregister_port(struct snd_seq_device *dev) | 431 | snd_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 | ||
462 | static 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 | ||
461 | static int __init alsa_seq_midi_init(void) | 472 | module_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 | |||
474 | static void __exit alsa_seq_midi_exit(void) | ||
475 | { | ||
476 | snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_MIDISYNTH); | ||
477 | } | ||
478 | |||
479 | module_init(alsa_seq_midi_init) | ||
480 | module_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 |
189 | static int snd_find_free_minor(int type) | 189 | static 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 |
212 | static int snd_kernel_minor(int type, struct snd_card *card, int dev) | 212 | static 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 | ||
219 | static int snd_opl3_seq_new_device(struct snd_seq_device *dev) | 219 | static 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 | ||
260 | static int snd_opl3_seq_delete_device(struct snd_seq_device *dev) | 261 | static 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 | ||
278 | static int __init alsa_opl3_seq_init(void) | 280 | static 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 | |||
290 | static void __exit alsa_opl3_seq_exit(void) | ||
291 | { | ||
292 | snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_OPL3); | ||
293 | } | ||
294 | 289 | ||
295 | module_init(alsa_opl3_seq_init) | 290 | module_snd_seq_driver(opl3_seq_driver); |
296 | module_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 | ||
127 | static int snd_opl4_seq_new_device(struct snd_seq_device *dev) | 127 | static 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 | ||
183 | static int snd_opl4_seq_delete_device(struct snd_seq_device *dev) | 184 | static 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 | ||
198 | static int __init alsa_opl4_synth_init(void) | 200 | static 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 | |||
209 | static void __exit alsa_opl4_synth_exit(void) | ||
210 | { | ||
211 | snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_OPL4); | ||
212 | } | ||
213 | 209 | ||
214 | module_init(alsa_opl4_synth_init) | 210 | module_snd_seq_driver(opl4_seq_driver); |
215 | module_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/hda/Kconfig b/sound/hda/Kconfig new file mode 100644 index 000000000000..001c6588a5ff --- /dev/null +++ b/sound/hda/Kconfig | |||
@@ -0,0 +1,3 @@ | |||
1 | config SND_HDA_CORE | ||
2 | tristate | ||
3 | select REGMAP | ||
diff --git a/sound/hda/Makefile b/sound/hda/Makefile new file mode 100644 index 000000000000..7a359f5b7e25 --- /dev/null +++ b/sound/hda/Makefile | |||
@@ -0,0 +1,7 @@ | |||
1 | snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o hdac_sysfs.o \ | ||
2 | hdac_regmap.o array.o | ||
3 | |||
4 | snd-hda-core-objs += trace.o | ||
5 | CFLAGS_trace.o := -I$(src) | ||
6 | |||
7 | obj-$(CONFIG_SND_HDA_CORE) += snd-hda-core.o | ||
diff --git a/sound/hda/array.c b/sound/hda/array.c new file mode 100644 index 000000000000..516795baa7db --- /dev/null +++ b/sound/hda/array.c | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | * generic arrays | ||
3 | */ | ||
4 | |||
5 | #include <linux/slab.h> | ||
6 | #include <sound/core.h> | ||
7 | #include <sound/hdaudio.h> | ||
8 | |||
9 | /** | ||
10 | * snd_array_new - get a new element from the given array | ||
11 | * @array: the array object | ||
12 | * | ||
13 | * Get a new element from the given array. If it exceeds the | ||
14 | * pre-allocated array size, re-allocate the array. | ||
15 | * | ||
16 | * Returns NULL if allocation failed. | ||
17 | */ | ||
18 | void *snd_array_new(struct snd_array *array) | ||
19 | { | ||
20 | if (snd_BUG_ON(!array->elem_size)) | ||
21 | return NULL; | ||
22 | if (array->used >= array->alloced) { | ||
23 | int num = array->alloced + array->alloc_align; | ||
24 | int size = (num + 1) * array->elem_size; | ||
25 | void *nlist; | ||
26 | if (snd_BUG_ON(num >= 4096)) | ||
27 | return NULL; | ||
28 | nlist = krealloc(array->list, size, GFP_KERNEL | __GFP_ZERO); | ||
29 | if (!nlist) | ||
30 | return NULL; | ||
31 | array->list = nlist; | ||
32 | array->alloced = num; | ||
33 | } | ||
34 | return snd_array_elem(array, array->used++); | ||
35 | } | ||
36 | EXPORT_SYMBOL_GPL(snd_array_new); | ||
37 | |||
38 | /** | ||
39 | * snd_array_free - free the given array elements | ||
40 | * @array: the array object | ||
41 | */ | ||
42 | void snd_array_free(struct snd_array *array) | ||
43 | { | ||
44 | kfree(array->list); | ||
45 | array->used = 0; | ||
46 | array->alloced = 0; | ||
47 | array->list = NULL; | ||
48 | } | ||
49 | EXPORT_SYMBOL_GPL(snd_array_free); | ||
diff --git a/sound/hda/hda_bus_type.c b/sound/hda/hda_bus_type.c new file mode 100644 index 000000000000..519914a12e8a --- /dev/null +++ b/sound/hda/hda_bus_type.c | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * HD-audio bus | ||
3 | */ | ||
4 | #include <linux/init.h> | ||
5 | #include <linux/device.h> | ||
6 | #include <linux/module.h> | ||
7 | #include <linux/export.h> | ||
8 | #include <sound/hdaudio.h> | ||
9 | |||
10 | MODULE_DESCRIPTION("HD-audio bus"); | ||
11 | MODULE_LICENSE("GPL"); | ||
12 | |||
13 | static int hda_bus_match(struct device *dev, struct device_driver *drv) | ||
14 | { | ||
15 | struct hdac_device *hdev = dev_to_hdac_dev(dev); | ||
16 | struct hdac_driver *hdrv = drv_to_hdac_driver(drv); | ||
17 | |||
18 | if (hdev->type != hdrv->type) | ||
19 | return 0; | ||
20 | if (hdrv->match) | ||
21 | return hdrv->match(hdev, hdrv); | ||
22 | return 1; | ||
23 | } | ||
24 | |||
25 | struct bus_type snd_hda_bus_type = { | ||
26 | .name = "hdaudio", | ||
27 | .match = hda_bus_match, | ||
28 | }; | ||
29 | EXPORT_SYMBOL_GPL(snd_hda_bus_type); | ||
30 | |||
31 | static int __init hda_bus_init(void) | ||
32 | { | ||
33 | return bus_register(&snd_hda_bus_type); | ||
34 | } | ||
35 | |||
36 | static void __exit hda_bus_exit(void) | ||
37 | { | ||
38 | bus_unregister(&snd_hda_bus_type); | ||
39 | } | ||
40 | |||
41 | subsys_initcall(hda_bus_init); | ||
42 | module_exit(hda_bus_exit); | ||
diff --git a/sound/hda/hdac_bus.c b/sound/hda/hdac_bus.c new file mode 100644 index 000000000000..8e262da74f6a --- /dev/null +++ b/sound/hda/hdac_bus.c | |||
@@ -0,0 +1,186 @@ | |||
1 | /* | ||
2 | * HD-audio core bus driver | ||
3 | */ | ||
4 | |||
5 | #include <linux/init.h> | ||
6 | #include <linux/device.h> | ||
7 | #include <linux/module.h> | ||
8 | #include <linux/export.h> | ||
9 | #include <sound/hdaudio.h> | ||
10 | #include "trace.h" | ||
11 | |||
12 | static void process_unsol_events(struct work_struct *work); | ||
13 | |||
14 | /** | ||
15 | * snd_hdac_bus_init - initialize a HD-audio bas bus | ||
16 | * @bus: the pointer to bus object | ||
17 | * | ||
18 | * Returns 0 if successful, or a negative error code. | ||
19 | */ | ||
20 | int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev, | ||
21 | const struct hdac_bus_ops *ops) | ||
22 | { | ||
23 | memset(bus, 0, sizeof(*bus)); | ||
24 | bus->dev = dev; | ||
25 | bus->ops = ops; | ||
26 | INIT_LIST_HEAD(&bus->codec_list); | ||
27 | INIT_WORK(&bus->unsol_work, process_unsol_events); | ||
28 | mutex_init(&bus->cmd_mutex); | ||
29 | return 0; | ||
30 | } | ||
31 | EXPORT_SYMBOL_GPL(snd_hdac_bus_init); | ||
32 | |||
33 | /** | ||
34 | * snd_hdac_bus_exit - clean up a HD-audio bas bus | ||
35 | * @bus: the pointer to bus object | ||
36 | */ | ||
37 | void snd_hdac_bus_exit(struct hdac_bus *bus) | ||
38 | { | ||
39 | WARN_ON(!list_empty(&bus->codec_list)); | ||
40 | cancel_work_sync(&bus->unsol_work); | ||
41 | } | ||
42 | EXPORT_SYMBOL_GPL(snd_hdac_bus_exit); | ||
43 | |||
44 | /** | ||
45 | * snd_hdac_bus_exec_verb - execute a HD-audio verb on the given bus | ||
46 | * @bus: bus object | ||
47 | * @cmd: HD-audio encoded verb | ||
48 | * @res: pointer to store the response, NULL if performing asynchronously | ||
49 | * | ||
50 | * Returns 0 if successful, or a negative error code. | ||
51 | */ | ||
52 | int snd_hdac_bus_exec_verb(struct hdac_bus *bus, unsigned int addr, | ||
53 | unsigned int cmd, unsigned int *res) | ||
54 | { | ||
55 | int err; | ||
56 | |||
57 | mutex_lock(&bus->cmd_mutex); | ||
58 | err = snd_hdac_bus_exec_verb_unlocked(bus, addr, cmd, res); | ||
59 | mutex_unlock(&bus->cmd_mutex); | ||
60 | return err; | ||
61 | } | ||
62 | EXPORT_SYMBOL_GPL(snd_hdac_bus_exec_verb); | ||
63 | |||
64 | /** | ||
65 | * snd_hdac_bus_exec_verb_unlocked - unlocked version | ||
66 | * @bus: bus object | ||
67 | * @cmd: HD-audio encoded verb | ||
68 | * @res: pointer to store the response, NULL if performing asynchronously | ||
69 | * | ||
70 | * Returns 0 if successful, or a negative error code. | ||
71 | */ | ||
72 | int snd_hdac_bus_exec_verb_unlocked(struct hdac_bus *bus, unsigned int addr, | ||
73 | unsigned int cmd, unsigned int *res) | ||
74 | { | ||
75 | unsigned int tmp; | ||
76 | int err; | ||
77 | |||
78 | if (cmd == ~0) | ||
79 | return -EINVAL; | ||
80 | |||
81 | if (res) | ||
82 | *res = -1; | ||
83 | else if (bus->sync_write) | ||
84 | res = &tmp; | ||
85 | for (;;) { | ||
86 | trace_hda_send_cmd(bus, cmd); | ||
87 | err = bus->ops->command(bus, cmd); | ||
88 | if (err != -EAGAIN) | ||
89 | break; | ||
90 | /* process pending verbs */ | ||
91 | err = bus->ops->get_response(bus, addr, &tmp); | ||
92 | if (err) | ||
93 | break; | ||
94 | } | ||
95 | if (!err && res) { | ||
96 | err = bus->ops->get_response(bus, addr, res); | ||
97 | trace_hda_get_response(bus, addr, *res); | ||
98 | } | ||
99 | return err; | ||
100 | } | ||
101 | EXPORT_SYMBOL_GPL(snd_hdac_bus_exec_verb_unlocked); | ||
102 | |||
103 | /** | ||
104 | * snd_hdac_bus_queue_event - add an unsolicited event to queue | ||
105 | * @bus: the BUS | ||
106 | * @res: unsolicited event (lower 32bit of RIRB entry) | ||
107 | * @res_ex: codec addr and flags (upper 32bit or RIRB entry) | ||
108 | * | ||
109 | * Adds the given event to the queue. The events are processed in | ||
110 | * the workqueue asynchronously. Call this function in the interrupt | ||
111 | * hanlder when RIRB receives an unsolicited event. | ||
112 | */ | ||
113 | void snd_hdac_bus_queue_event(struct hdac_bus *bus, u32 res, u32 res_ex) | ||
114 | { | ||
115 | unsigned int wp; | ||
116 | |||
117 | if (!bus) | ||
118 | return; | ||
119 | |||
120 | trace_hda_unsol_event(bus, res, res_ex); | ||
121 | wp = (bus->unsol_wp + 1) % HDA_UNSOL_QUEUE_SIZE; | ||
122 | bus->unsol_wp = wp; | ||
123 | |||
124 | wp <<= 1; | ||
125 | bus->unsol_queue[wp] = res; | ||
126 | bus->unsol_queue[wp + 1] = res_ex; | ||
127 | |||
128 | schedule_work(&bus->unsol_work); | ||
129 | } | ||
130 | EXPORT_SYMBOL_GPL(snd_hdac_bus_queue_event); | ||
131 | |||
132 | /* | ||
133 | * process queued unsolicited events | ||
134 | */ | ||
135 | static void process_unsol_events(struct work_struct *work) | ||
136 | { | ||
137 | struct hdac_bus *bus = container_of(work, struct hdac_bus, unsol_work); | ||
138 | struct hdac_device *codec; | ||
139 | struct hdac_driver *drv; | ||
140 | unsigned int rp, caddr, res; | ||
141 | |||
142 | while (bus->unsol_rp != bus->unsol_wp) { | ||
143 | rp = (bus->unsol_rp + 1) % HDA_UNSOL_QUEUE_SIZE; | ||
144 | bus->unsol_rp = rp; | ||
145 | rp <<= 1; | ||
146 | res = bus->unsol_queue[rp]; | ||
147 | caddr = bus->unsol_queue[rp + 1]; | ||
148 | if (!(caddr & (1 << 4))) /* no unsolicited event? */ | ||
149 | continue; | ||
150 | codec = bus->caddr_tbl[caddr & 0x0f]; | ||
151 | if (!codec || !codec->dev.driver) | ||
152 | continue; | ||
153 | drv = drv_to_hdac_driver(codec->dev.driver); | ||
154 | if (drv->unsol_event) | ||
155 | drv->unsol_event(codec, res); | ||
156 | } | ||
157 | } | ||
158 | |||
159 | int snd_hdac_bus_add_device(struct hdac_bus *bus, struct hdac_device *codec) | ||
160 | { | ||
161 | if (bus->caddr_tbl[codec->addr]) { | ||
162 | dev_err(bus->dev, "address 0x%x is already occupied\n", | ||
163 | codec->addr); | ||
164 | return -EBUSY; | ||
165 | } | ||
166 | |||
167 | list_add_tail(&codec->list, &bus->codec_list); | ||
168 | bus->caddr_tbl[codec->addr] = codec; | ||
169 | set_bit(codec->addr, &bus->codec_powered); | ||
170 | bus->num_codecs++; | ||
171 | return 0; | ||
172 | } | ||
173 | EXPORT_SYMBOL_GPL(snd_hdac_bus_add_device); | ||
174 | |||
175 | void snd_hdac_bus_remove_device(struct hdac_bus *bus, | ||
176 | struct hdac_device *codec) | ||
177 | { | ||
178 | WARN_ON(bus != codec->bus); | ||
179 | if (list_empty(&codec->list)) | ||
180 | return; | ||
181 | list_del_init(&codec->list); | ||
182 | bus->caddr_tbl[codec->addr] = NULL; | ||
183 | clear_bit(codec->addr, &bus->codec_powered); | ||
184 | bus->num_codecs--; | ||
185 | } | ||
186 | EXPORT_SYMBOL_GPL(snd_hdac_bus_remove_device); | ||
diff --git a/sound/hda/hdac_device.c b/sound/hda/hdac_device.c new file mode 100644 index 000000000000..f75bf5622687 --- /dev/null +++ b/sound/hda/hdac_device.c | |||
@@ -0,0 +1,599 @@ | |||
1 | /* | ||
2 | * HD-audio codec core device | ||
3 | */ | ||
4 | |||
5 | #include <linux/init.h> | ||
6 | #include <linux/device.h> | ||
7 | #include <linux/slab.h> | ||
8 | #include <linux/module.h> | ||
9 | #include <linux/export.h> | ||
10 | #include <linux/pm_runtime.h> | ||
11 | #include <sound/hdaudio.h> | ||
12 | #include <sound/hda_regmap.h> | ||
13 | #include "local.h" | ||
14 | |||
15 | static void setup_fg_nodes(struct hdac_device *codec); | ||
16 | static int get_codec_vendor_name(struct hdac_device *codec); | ||
17 | |||
18 | static void default_release(struct device *dev) | ||
19 | { | ||
20 | snd_hdac_device_exit(container_of(dev, struct hdac_device, dev)); | ||
21 | } | ||
22 | |||
23 | /** | ||
24 | * snd_hdac_device_init - initialize the HD-audio codec base device | ||
25 | * @codec: device to initialize | ||
26 | * @bus: but to attach | ||
27 | * @name: device name string | ||
28 | * @addr: codec address | ||
29 | * | ||
30 | * Returns zero for success or a negative error code. | ||
31 | * | ||
32 | * This function increments the runtime PM counter and marks it active. | ||
33 | * The caller needs to turn it off appropriately later. | ||
34 | * | ||
35 | * The caller needs to set the device's release op properly by itself. | ||
36 | */ | ||
37 | int snd_hdac_device_init(struct hdac_device *codec, struct hdac_bus *bus, | ||
38 | const char *name, unsigned int addr) | ||
39 | { | ||
40 | struct device *dev; | ||
41 | hda_nid_t fg; | ||
42 | int err; | ||
43 | |||
44 | dev = &codec->dev; | ||
45 | device_initialize(dev); | ||
46 | dev->parent = bus->dev; | ||
47 | dev->bus = &snd_hda_bus_type; | ||
48 | dev->release = default_release; | ||
49 | dev->groups = hdac_dev_attr_groups; | ||
50 | dev_set_name(dev, "%s", name); | ||
51 | device_enable_async_suspend(dev); | ||
52 | |||
53 | codec->bus = bus; | ||
54 | codec->addr = addr; | ||
55 | codec->type = HDA_DEV_CORE; | ||
56 | pm_runtime_set_active(&codec->dev); | ||
57 | pm_runtime_get_noresume(&codec->dev); | ||
58 | atomic_set(&codec->in_pm, 0); | ||
59 | |||
60 | err = snd_hdac_bus_add_device(bus, codec); | ||
61 | if (err < 0) | ||
62 | goto error; | ||
63 | |||
64 | /* fill parameters */ | ||
65 | codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, | ||
66 | AC_PAR_VENDOR_ID); | ||
67 | if (codec->vendor_id == -1) { | ||
68 | /* read again, hopefully the access method was corrected | ||
69 | * in the last read... | ||
70 | */ | ||
71 | codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, | ||
72 | AC_PAR_VENDOR_ID); | ||
73 | } | ||
74 | |||
75 | codec->subsystem_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, | ||
76 | AC_PAR_SUBSYSTEM_ID); | ||
77 | codec->revision_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, | ||
78 | AC_PAR_REV_ID); | ||
79 | |||
80 | setup_fg_nodes(codec); | ||
81 | if (!codec->afg && !codec->mfg) { | ||
82 | dev_err(dev, "no AFG or MFG node found\n"); | ||
83 | err = -ENODEV; | ||
84 | goto error; | ||
85 | } | ||
86 | |||
87 | fg = codec->afg ? codec->afg : codec->mfg; | ||
88 | |||
89 | err = snd_hdac_refresh_widgets(codec); | ||
90 | if (err < 0) | ||
91 | goto error; | ||
92 | |||
93 | codec->power_caps = snd_hdac_read_parm(codec, fg, AC_PAR_POWER_STATE); | ||
94 | /* reread ssid if not set by parameter */ | ||
95 | if (codec->subsystem_id == -1 || codec->subsystem_id == 0) | ||
96 | snd_hdac_read(codec, fg, AC_VERB_GET_SUBSYSTEM_ID, 0, | ||
97 | &codec->subsystem_id); | ||
98 | |||
99 | err = get_codec_vendor_name(codec); | ||
100 | if (err < 0) | ||
101 | goto error; | ||
102 | |||
103 | codec->chip_name = kasprintf(GFP_KERNEL, "ID %x", | ||
104 | codec->vendor_id & 0xffff); | ||
105 | if (!codec->chip_name) { | ||
106 | err = -ENOMEM; | ||
107 | goto error; | ||
108 | } | ||
109 | |||
110 | return 0; | ||
111 | |||
112 | error: | ||
113 | put_device(&codec->dev); | ||
114 | return err; | ||
115 | } | ||
116 | EXPORT_SYMBOL_GPL(snd_hdac_device_init); | ||
117 | |||
118 | /** | ||
119 | * snd_hdac_device_exit - clean up the HD-audio codec base device | ||
120 | * @codec: device to clean up | ||
121 | */ | ||
122 | void snd_hdac_device_exit(struct hdac_device *codec) | ||
123 | { | ||
124 | pm_runtime_put_noidle(&codec->dev); | ||
125 | snd_hdac_bus_remove_device(codec->bus, codec); | ||
126 | kfree(codec->vendor_name); | ||
127 | kfree(codec->chip_name); | ||
128 | } | ||
129 | EXPORT_SYMBOL_GPL(snd_hdac_device_exit); | ||
130 | |||
131 | /** | ||
132 | * snd_hdac_device_register - register the hd-audio codec base device | ||
133 | * codec: the device to register | ||
134 | */ | ||
135 | int snd_hdac_device_register(struct hdac_device *codec) | ||
136 | { | ||
137 | int err; | ||
138 | |||
139 | err = device_add(&codec->dev); | ||
140 | if (err < 0) | ||
141 | return err; | ||
142 | err = hda_widget_sysfs_init(codec); | ||
143 | if (err < 0) { | ||
144 | device_del(&codec->dev); | ||
145 | return err; | ||
146 | } | ||
147 | |||
148 | return 0; | ||
149 | } | ||
150 | EXPORT_SYMBOL_GPL(snd_hdac_device_register); | ||
151 | |||
152 | /** | ||
153 | * snd_hdac_device_unregister - unregister the hd-audio codec base device | ||
154 | * codec: the device to unregister | ||
155 | */ | ||
156 | void snd_hdac_device_unregister(struct hdac_device *codec) | ||
157 | { | ||
158 | if (device_is_registered(&codec->dev)) { | ||
159 | hda_widget_sysfs_exit(codec); | ||
160 | device_del(&codec->dev); | ||
161 | } | ||
162 | } | ||
163 | EXPORT_SYMBOL_GPL(snd_hdac_device_unregister); | ||
164 | |||
165 | /** | ||
166 | * snd_hdac_make_cmd - compose a 32bit command word to be sent to the | ||
167 | * HD-audio controller | ||
168 | * @codec: the codec object | ||
169 | * @nid: NID to encode | ||
170 | * @verb: verb to encode | ||
171 | * @parm: parameter to encode | ||
172 | * | ||
173 | * Return an encoded command verb or -1 for error. | ||
174 | */ | ||
175 | unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid, | ||
176 | unsigned int verb, unsigned int parm) | ||
177 | { | ||
178 | u32 val, addr; | ||
179 | |||
180 | addr = codec->addr; | ||
181 | if ((addr & ~0xf) || (nid & ~0x7f) || | ||
182 | (verb & ~0xfff) || (parm & ~0xffff)) { | ||
183 | dev_err(&codec->dev, "out of range cmd %x:%x:%x:%x\n", | ||
184 | addr, nid, verb, parm); | ||
185 | return -1; | ||
186 | } | ||
187 | |||
188 | val = addr << 28; | ||
189 | val |= (u32)nid << 20; | ||
190 | val |= verb << 8; | ||
191 | val |= parm; | ||
192 | return val; | ||
193 | } | ||
194 | EXPORT_SYMBOL_GPL(snd_hdac_make_cmd); | ||
195 | |||
196 | /** | ||
197 | * snd_hdac_exec_verb - execute an encoded verb | ||
198 | * @codec: the codec object | ||
199 | * @cmd: encoded verb to execute | ||
200 | * @flags: optional flags, pass zero for default | ||
201 | * @res: the pointer to store the result, NULL if running async | ||
202 | * | ||
203 | * Returns zero if successful, or a negative error code. | ||
204 | * | ||
205 | * This calls the exec_verb op when set in hdac_codec. If not, | ||
206 | * call the default snd_hdac_bus_exec_verb(). | ||
207 | */ | ||
208 | int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd, | ||
209 | unsigned int flags, unsigned int *res) | ||
210 | { | ||
211 | if (codec->exec_verb) | ||
212 | return codec->exec_verb(codec, cmd, flags, res); | ||
213 | return snd_hdac_bus_exec_verb(codec->bus, codec->addr, cmd, res); | ||
214 | } | ||
215 | EXPORT_SYMBOL_GPL(snd_hdac_exec_verb); | ||
216 | |||
217 | |||
218 | /** | ||
219 | * snd_hdac_read - execute a verb | ||
220 | * @codec: the codec object | ||
221 | * @nid: NID to execute a verb | ||
222 | * @verb: verb to execute | ||
223 | * @parm: parameter for a verb | ||
224 | * @res: the pointer to store the result, NULL if running async | ||
225 | * | ||
226 | * Returns zero if successful, or a negative error code. | ||
227 | */ | ||
228 | int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid, | ||
229 | unsigned int verb, unsigned int parm, unsigned int *res) | ||
230 | { | ||
231 | unsigned int cmd = snd_hdac_make_cmd(codec, nid, verb, parm); | ||
232 | |||
233 | return snd_hdac_exec_verb(codec, cmd, 0, res); | ||
234 | } | ||
235 | EXPORT_SYMBOL_GPL(snd_hdac_read); | ||
236 | |||
237 | /** | ||
238 | * _snd_hdac_read_parm - read a parmeter | ||
239 | * | ||
240 | * This function returns zero or an error unlike snd_hdac_read_parm(). | ||
241 | */ | ||
242 | int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm, | ||
243 | unsigned int *res) | ||
244 | { | ||
245 | unsigned int cmd; | ||
246 | |||
247 | cmd = snd_hdac_regmap_encode_verb(nid, AC_VERB_PARAMETERS) | parm; | ||
248 | return snd_hdac_regmap_read_raw(codec, cmd, res); | ||
249 | } | ||
250 | EXPORT_SYMBOL_GPL(_snd_hdac_read_parm); | ||
251 | |||
252 | /** | ||
253 | * snd_hdac_read_parm_uncached - read a codec parameter without caching | ||
254 | * @codec: the codec object | ||
255 | * @nid: NID to read a parameter | ||
256 | * @parm: parameter to read | ||
257 | * | ||
258 | * Returns -1 for error. If you need to distinguish the error more | ||
259 | * strictly, use snd_hdac_read() directly. | ||
260 | */ | ||
261 | int snd_hdac_read_parm_uncached(struct hdac_device *codec, hda_nid_t nid, | ||
262 | int parm) | ||
263 | { | ||
264 | int val; | ||
265 | |||
266 | if (codec->regmap) | ||
267 | regcache_cache_bypass(codec->regmap, true); | ||
268 | val = snd_hdac_read_parm(codec, nid, parm); | ||
269 | if (codec->regmap) | ||
270 | regcache_cache_bypass(codec->regmap, false); | ||
271 | return val; | ||
272 | } | ||
273 | EXPORT_SYMBOL_GPL(snd_hdac_read_parm_uncached); | ||
274 | |||
275 | /** | ||
276 | * snd_hdac_override_parm - override read-only parameters | ||
277 | * @codec: the codec object | ||
278 | * @nid: NID for the parameter | ||
279 | * @parm: the parameter to change | ||
280 | * @val: the parameter value to overwrite | ||
281 | */ | ||
282 | int snd_hdac_override_parm(struct hdac_device *codec, hda_nid_t nid, | ||
283 | unsigned int parm, unsigned int val) | ||
284 | { | ||
285 | unsigned int verb = (AC_VERB_PARAMETERS << 8) | (nid << 20) | parm; | ||
286 | int err; | ||
287 | |||
288 | if (!codec->regmap) | ||
289 | return -EINVAL; | ||
290 | |||
291 | codec->caps_overwriting = true; | ||
292 | err = snd_hdac_regmap_write_raw(codec, verb, val); | ||
293 | codec->caps_overwriting = false; | ||
294 | return err; | ||
295 | } | ||
296 | EXPORT_SYMBOL_GPL(snd_hdac_override_parm); | ||
297 | |||
298 | /** | ||
299 | * snd_hdac_get_sub_nodes - get start NID and number of subtree nodes | ||
300 | * @codec: the codec object | ||
301 | * @nid: NID to inspect | ||
302 | * @start_id: the pointer to store the starting NID | ||
303 | * | ||
304 | * Returns the number of subtree nodes or zero if not found. | ||
305 | * This function reads parameters always without caching. | ||
306 | */ | ||
307 | int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid, | ||
308 | hda_nid_t *start_id) | ||
309 | { | ||
310 | unsigned int parm; | ||
311 | |||
312 | parm = snd_hdac_read_parm_uncached(codec, nid, AC_PAR_NODE_COUNT); | ||
313 | if (parm == -1) { | ||
314 | *start_id = 0; | ||
315 | return 0; | ||
316 | } | ||
317 | *start_id = (parm >> 16) & 0x7fff; | ||
318 | return (int)(parm & 0x7fff); | ||
319 | } | ||
320 | EXPORT_SYMBOL_GPL(snd_hdac_get_sub_nodes); | ||
321 | |||
322 | /* | ||
323 | * look for an AFG and MFG nodes | ||
324 | */ | ||
325 | static void setup_fg_nodes(struct hdac_device *codec) | ||
326 | { | ||
327 | int i, total_nodes, function_id; | ||
328 | hda_nid_t nid; | ||
329 | |||
330 | total_nodes = snd_hdac_get_sub_nodes(codec, AC_NODE_ROOT, &nid); | ||
331 | for (i = 0; i < total_nodes; i++, nid++) { | ||
332 | function_id = snd_hdac_read_parm(codec, nid, | ||
333 | AC_PAR_FUNCTION_TYPE); | ||
334 | switch (function_id & 0xff) { | ||
335 | case AC_GRP_AUDIO_FUNCTION: | ||
336 | codec->afg = nid; | ||
337 | codec->afg_function_id = function_id & 0xff; | ||
338 | codec->afg_unsol = (function_id >> 8) & 1; | ||
339 | break; | ||
340 | case AC_GRP_MODEM_FUNCTION: | ||
341 | codec->mfg = nid; | ||
342 | codec->mfg_function_id = function_id & 0xff; | ||
343 | codec->mfg_unsol = (function_id >> 8) & 1; | ||
344 | break; | ||
345 | default: | ||
346 | break; | ||
347 | } | ||
348 | } | ||
349 | } | ||
350 | |||
351 | /** | ||
352 | * snd_hdac_refresh_widgets - Reset the widget start/end nodes | ||
353 | * @codec: the codec object | ||
354 | */ | ||
355 | int snd_hdac_refresh_widgets(struct hdac_device *codec) | ||
356 | { | ||
357 | hda_nid_t start_nid; | ||
358 | int nums; | ||
359 | |||
360 | nums = snd_hdac_get_sub_nodes(codec, codec->afg, &start_nid); | ||
361 | if (!start_nid || nums <= 0 || nums >= 0xff) { | ||
362 | dev_err(&codec->dev, "cannot read sub nodes for FG 0x%02x\n", | ||
363 | codec->afg); | ||
364 | return -EINVAL; | ||
365 | } | ||
366 | |||
367 | codec->num_nodes = nums; | ||
368 | codec->start_nid = start_nid; | ||
369 | codec->end_nid = start_nid + nums; | ||
370 | return 0; | ||
371 | } | ||
372 | EXPORT_SYMBOL_GPL(snd_hdac_refresh_widgets); | ||
373 | |||
374 | /* return CONNLIST_LEN parameter of the given widget */ | ||
375 | static unsigned int get_num_conns(struct hdac_device *codec, hda_nid_t nid) | ||
376 | { | ||
377 | unsigned int wcaps = get_wcaps(codec, nid); | ||
378 | unsigned int parm; | ||
379 | |||
380 | if (!(wcaps & AC_WCAP_CONN_LIST) && | ||
381 | get_wcaps_type(wcaps) != AC_WID_VOL_KNB) | ||
382 | return 0; | ||
383 | |||
384 | parm = snd_hdac_read_parm(codec, nid, AC_PAR_CONNLIST_LEN); | ||
385 | if (parm == -1) | ||
386 | parm = 0; | ||
387 | return parm; | ||
388 | } | ||
389 | |||
390 | /** | ||
391 | * snd_hdac_get_connections - get a widget connection list | ||
392 | * @codec: the codec object | ||
393 | * @nid: NID | ||
394 | * @conn_list: the array to store the results, can be NULL | ||
395 | * @max_conns: the max size of the given array | ||
396 | * | ||
397 | * Returns the number of connected widgets, zero for no connection, or a | ||
398 | * negative error code. When the number of elements don't fit with the | ||
399 | * given array size, it returns -ENOSPC. | ||
400 | * | ||
401 | * When @conn_list is NULL, it just checks the number of connections. | ||
402 | */ | ||
403 | int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid, | ||
404 | hda_nid_t *conn_list, int max_conns) | ||
405 | { | ||
406 | unsigned int parm; | ||
407 | int i, conn_len, conns, err; | ||
408 | unsigned int shift, num_elems, mask; | ||
409 | hda_nid_t prev_nid; | ||
410 | int null_count = 0; | ||
411 | |||
412 | parm = get_num_conns(codec, nid); | ||
413 | if (!parm) | ||
414 | return 0; | ||
415 | |||
416 | if (parm & AC_CLIST_LONG) { | ||
417 | /* long form */ | ||
418 | shift = 16; | ||
419 | num_elems = 2; | ||
420 | } else { | ||
421 | /* short form */ | ||
422 | shift = 8; | ||
423 | num_elems = 4; | ||
424 | } | ||
425 | conn_len = parm & AC_CLIST_LENGTH; | ||
426 | mask = (1 << (shift-1)) - 1; | ||
427 | |||
428 | if (!conn_len) | ||
429 | return 0; /* no connection */ | ||
430 | |||
431 | if (conn_len == 1) { | ||
432 | /* single connection */ | ||
433 | err = snd_hdac_read(codec, nid, AC_VERB_GET_CONNECT_LIST, 0, | ||
434 | &parm); | ||
435 | if (err < 0) | ||
436 | return err; | ||
437 | if (conn_list) | ||
438 | conn_list[0] = parm & mask; | ||
439 | return 1; | ||
440 | } | ||
441 | |||
442 | /* multi connection */ | ||
443 | conns = 0; | ||
444 | prev_nid = 0; | ||
445 | for (i = 0; i < conn_len; i++) { | ||
446 | int range_val; | ||
447 | hda_nid_t val, n; | ||
448 | |||
449 | if (i % num_elems == 0) { | ||
450 | err = snd_hdac_read(codec, nid, | ||
451 | AC_VERB_GET_CONNECT_LIST, i, | ||
452 | &parm); | ||
453 | if (err < 0) | ||
454 | return -EIO; | ||
455 | } | ||
456 | range_val = !!(parm & (1 << (shift-1))); /* ranges */ | ||
457 | val = parm & mask; | ||
458 | if (val == 0 && null_count++) { /* no second chance */ | ||
459 | dev_dbg(&codec->dev, | ||
460 | "invalid CONNECT_LIST verb %x[%i]:%x\n", | ||
461 | nid, i, parm); | ||
462 | return 0; | ||
463 | } | ||
464 | parm >>= shift; | ||
465 | if (range_val) { | ||
466 | /* ranges between the previous and this one */ | ||
467 | if (!prev_nid || prev_nid >= val) { | ||
468 | dev_warn(&codec->dev, | ||
469 | "invalid dep_range_val %x:%x\n", | ||
470 | prev_nid, val); | ||
471 | continue; | ||
472 | } | ||
473 | for (n = prev_nid + 1; n <= val; n++) { | ||
474 | if (conn_list) { | ||
475 | if (conns >= max_conns) | ||
476 | return -ENOSPC; | ||
477 | conn_list[conns] = n; | ||
478 | } | ||
479 | conns++; | ||
480 | } | ||
481 | } else { | ||
482 | if (conn_list) { | ||
483 | if (conns >= max_conns) | ||
484 | return -ENOSPC; | ||
485 | conn_list[conns] = val; | ||
486 | } | ||
487 | conns++; | ||
488 | } | ||
489 | prev_nid = val; | ||
490 | } | ||
491 | return conns; | ||
492 | } | ||
493 | EXPORT_SYMBOL_GPL(snd_hdac_get_connections); | ||
494 | |||
495 | #ifdef CONFIG_PM | ||
496 | /** | ||
497 | * snd_hdac_power_up - power up the codec | ||
498 | * @codec: the codec object | ||
499 | * | ||
500 | * This function calls the runtime PM helper to power up the given codec. | ||
501 | * Unlike snd_hdac_power_up_pm(), you should call this only for the code | ||
502 | * path that isn't included in PM path. Otherwise it gets stuck. | ||
503 | */ | ||
504 | void snd_hdac_power_up(struct hdac_device *codec) | ||
505 | { | ||
506 | pm_runtime_get_sync(&codec->dev); | ||
507 | } | ||
508 | EXPORT_SYMBOL_GPL(snd_hdac_power_up); | ||
509 | |||
510 | /** | ||
511 | * snd_hdac_power_down - power down the codec | ||
512 | * @codec: the codec object | ||
513 | */ | ||
514 | void snd_hdac_power_down(struct hdac_device *codec) | ||
515 | { | ||
516 | struct device *dev = &codec->dev; | ||
517 | |||
518 | pm_runtime_mark_last_busy(dev); | ||
519 | pm_runtime_put_autosuspend(dev); | ||
520 | } | ||
521 | EXPORT_SYMBOL_GPL(snd_hdac_power_down); | ||
522 | |||
523 | /** | ||
524 | * snd_hdac_power_up_pm - power up the codec | ||
525 | * @codec: the codec object | ||
526 | * | ||
527 | * This function can be called in a recursive code path like init code | ||
528 | * which may be called by PM suspend/resume again. OTOH, if a power-up | ||
529 | * call must wake up the sleeper (e.g. in a kctl callback), use | ||
530 | * snd_hdac_power_up() instead. | ||
531 | */ | ||
532 | void snd_hdac_power_up_pm(struct hdac_device *codec) | ||
533 | { | ||
534 | if (!atomic_inc_not_zero(&codec->in_pm)) | ||
535 | snd_hdac_power_up(codec); | ||
536 | } | ||
537 | EXPORT_SYMBOL_GPL(snd_hdac_power_up_pm); | ||
538 | |||
539 | /** | ||
540 | * snd_hdac_power_down_pm - power down the codec | ||
541 | * @codec: the codec object | ||
542 | * | ||
543 | * Like snd_hdac_power_up_pm(), this function is used in a recursive | ||
544 | * code path like init code which may be called by PM suspend/resume again. | ||
545 | */ | ||
546 | void snd_hdac_power_down_pm(struct hdac_device *codec) | ||
547 | { | ||
548 | if (atomic_dec_if_positive(&codec->in_pm) < 0) | ||
549 | snd_hdac_power_down(codec); | ||
550 | } | ||
551 | EXPORT_SYMBOL_GPL(snd_hdac_power_down_pm); | ||
552 | #endif | ||
553 | |||
554 | /* codec vendor labels */ | ||
555 | struct hda_vendor_id { | ||
556 | unsigned int id; | ||
557 | const char *name; | ||
558 | }; | ||
559 | |||
560 | static struct hda_vendor_id hda_vendor_ids[] = { | ||
561 | { 0x1002, "ATI" }, | ||
562 | { 0x1013, "Cirrus Logic" }, | ||
563 | { 0x1057, "Motorola" }, | ||
564 | { 0x1095, "Silicon Image" }, | ||
565 | { 0x10de, "Nvidia" }, | ||
566 | { 0x10ec, "Realtek" }, | ||
567 | { 0x1102, "Creative" }, | ||
568 | { 0x1106, "VIA" }, | ||
569 | { 0x111d, "IDT" }, | ||
570 | { 0x11c1, "LSI" }, | ||
571 | { 0x11d4, "Analog Devices" }, | ||
572 | { 0x13f6, "C-Media" }, | ||
573 | { 0x14f1, "Conexant" }, | ||
574 | { 0x17e8, "Chrontel" }, | ||
575 | { 0x1854, "LG" }, | ||
576 | { 0x1aec, "Wolfson Microelectronics" }, | ||
577 | { 0x1af4, "QEMU" }, | ||
578 | { 0x434d, "C-Media" }, | ||
579 | { 0x8086, "Intel" }, | ||
580 | { 0x8384, "SigmaTel" }, | ||
581 | {} /* terminator */ | ||
582 | }; | ||
583 | |||
584 | /* store the codec vendor name */ | ||
585 | static int get_codec_vendor_name(struct hdac_device *codec) | ||
586 | { | ||
587 | const struct hda_vendor_id *c; | ||
588 | u16 vendor_id = codec->vendor_id >> 16; | ||
589 | |||
590 | for (c = hda_vendor_ids; c->id; c++) { | ||
591 | if (c->id == vendor_id) { | ||
592 | codec->vendor_name = kstrdup(c->name, GFP_KERNEL); | ||
593 | return codec->vendor_name ? 0 : -ENOMEM; | ||
594 | } | ||
595 | } | ||
596 | |||
597 | codec->vendor_name = kasprintf(GFP_KERNEL, "Generic %04x", vendor_id); | ||
598 | return codec->vendor_name ? 0 : -ENOMEM; | ||
599 | } | ||
diff --git a/sound/hda/hdac_regmap.c b/sound/hda/hdac_regmap.c new file mode 100644 index 000000000000..7371e0c3926f --- /dev/null +++ b/sound/hda/hdac_regmap.c | |||
@@ -0,0 +1,472 @@ | |||
1 | /* | ||
2 | * Regmap support for HD-audio verbs | ||
3 | * | ||
4 | * A virtual register is translated to one or more hda verbs for write, | ||
5 | * vice versa for read. | ||
6 | * | ||
7 | * A few limitations: | ||
8 | * - Provided for not all verbs but only subset standard non-volatile verbs. | ||
9 | * - For reading, only AC_VERB_GET_* variants can be used. | ||
10 | * - For writing, mapped to the *corresponding* AC_VERB_SET_* variants, | ||
11 | * so can't handle asymmetric verbs for read and write | ||
12 | */ | ||
13 | |||
14 | #include <linux/slab.h> | ||
15 | #include <linux/device.h> | ||
16 | #include <linux/regmap.h> | ||
17 | #include <linux/export.h> | ||
18 | #include <linux/pm.h> | ||
19 | #include <linux/pm_runtime.h> | ||
20 | #include <sound/core.h> | ||
21 | #include <sound/hdaudio.h> | ||
22 | #include <sound/hda_regmap.h> | ||
23 | |||
24 | #ifdef CONFIG_PM | ||
25 | #define codec_is_running(codec) \ | ||
26 | (atomic_read(&(codec)->in_pm) || \ | ||
27 | !pm_runtime_suspended(&(codec)->dev)) | ||
28 | #else | ||
29 | #define codec_is_running(codec) true | ||
30 | #endif | ||
31 | |||
32 | #define get_verb(reg) (((reg) >> 8) & 0xfff) | ||
33 | |||
34 | static bool hda_volatile_reg(struct device *dev, unsigned int reg) | ||
35 | { | ||
36 | struct hdac_device *codec = dev_to_hdac_dev(dev); | ||
37 | unsigned int verb = get_verb(reg); | ||
38 | |||
39 | switch (verb) { | ||
40 | case AC_VERB_GET_PROC_COEF: | ||
41 | return !codec->cache_coef; | ||
42 | case AC_VERB_GET_COEF_INDEX: | ||
43 | case AC_VERB_GET_PROC_STATE: | ||
44 | case AC_VERB_GET_POWER_STATE: | ||
45 | case AC_VERB_GET_PIN_SENSE: | ||
46 | case AC_VERB_GET_HDMI_DIP_SIZE: | ||
47 | case AC_VERB_GET_HDMI_ELDD: | ||
48 | case AC_VERB_GET_HDMI_DIP_INDEX: | ||
49 | case AC_VERB_GET_HDMI_DIP_DATA: | ||
50 | case AC_VERB_GET_HDMI_DIP_XMIT: | ||
51 | case AC_VERB_GET_HDMI_CP_CTRL: | ||
52 | case AC_VERB_GET_HDMI_CHAN_SLOT: | ||
53 | case AC_VERB_GET_DEVICE_SEL: | ||
54 | case AC_VERB_GET_DEVICE_LIST: /* read-only volatile */ | ||
55 | return true; | ||
56 | } | ||
57 | |||
58 | return false; | ||
59 | } | ||
60 | |||
61 | static bool hda_writeable_reg(struct device *dev, unsigned int reg) | ||
62 | { | ||
63 | struct hdac_device *codec = dev_to_hdac_dev(dev); | ||
64 | unsigned int verb = get_verb(reg); | ||
65 | int i; | ||
66 | |||
67 | for (i = 0; i < codec->vendor_verbs.used; i++) { | ||
68 | unsigned int *v = snd_array_elem(&codec->vendor_verbs, i); | ||
69 | if (verb == *v) | ||
70 | return true; | ||
71 | } | ||
72 | |||
73 | if (codec->caps_overwriting) | ||
74 | return true; | ||
75 | |||
76 | switch (verb & 0xf00) { | ||
77 | case AC_VERB_GET_STREAM_FORMAT: | ||
78 | case AC_VERB_GET_AMP_GAIN_MUTE: | ||
79 | return true; | ||
80 | case AC_VERB_GET_PROC_COEF: | ||
81 | return codec->cache_coef; | ||
82 | case 0xf00: | ||
83 | break; | ||
84 | default: | ||
85 | return false; | ||
86 | } | ||
87 | |||
88 | switch (verb) { | ||
89 | case AC_VERB_GET_CONNECT_SEL: | ||
90 | case AC_VERB_GET_SDI_SELECT: | ||
91 | case AC_VERB_GET_PIN_WIDGET_CONTROL: | ||
92 | case AC_VERB_GET_UNSOLICITED_RESPONSE: /* only as SET_UNSOLICITED_ENABLE */ | ||
93 | case AC_VERB_GET_BEEP_CONTROL: | ||
94 | case AC_VERB_GET_EAPD_BTLENABLE: | ||
95 | case AC_VERB_GET_DIGI_CONVERT_1: | ||
96 | case AC_VERB_GET_DIGI_CONVERT_2: /* only for beep control */ | ||
97 | case AC_VERB_GET_VOLUME_KNOB_CONTROL: | ||
98 | case AC_VERB_GET_GPIO_MASK: | ||
99 | case AC_VERB_GET_GPIO_DIRECTION: | ||
100 | case AC_VERB_GET_GPIO_DATA: /* not for volatile read */ | ||
101 | case AC_VERB_GET_GPIO_WAKE_MASK: | ||
102 | case AC_VERB_GET_GPIO_UNSOLICITED_RSP_MASK: | ||
103 | case AC_VERB_GET_GPIO_STICKY_MASK: | ||
104 | return true; | ||
105 | } | ||
106 | |||
107 | return false; | ||
108 | } | ||
109 | |||
110 | static bool hda_readable_reg(struct device *dev, unsigned int reg) | ||
111 | { | ||
112 | struct hdac_device *codec = dev_to_hdac_dev(dev); | ||
113 | unsigned int verb = get_verb(reg); | ||
114 | |||
115 | if (codec->caps_overwriting) | ||
116 | return true; | ||
117 | |||
118 | switch (verb) { | ||
119 | case AC_VERB_PARAMETERS: | ||
120 | case AC_VERB_GET_CONNECT_LIST: | ||
121 | case AC_VERB_GET_SUBSYSTEM_ID: | ||
122 | return true; | ||
123 | /* below are basically writable, but disabled for reducing unnecessary | ||
124 | * writes at sync | ||
125 | */ | ||
126 | case AC_VERB_GET_CONFIG_DEFAULT: /* usually just read */ | ||
127 | case AC_VERB_GET_CONV: /* managed in PCM code */ | ||
128 | case AC_VERB_GET_CVT_CHAN_COUNT: /* managed in HDMI CA code */ | ||
129 | return true; | ||
130 | } | ||
131 | |||
132 | return hda_writeable_reg(dev, reg); | ||
133 | } | ||
134 | |||
135 | /* | ||
136 | * Stereo amp pseudo register: | ||
137 | * for making easier to handle the stereo volume control, we provide a | ||
138 | * fake register to deal both left and right channels by a single | ||
139 | * (pseudo) register access. A verb consisting of SET_AMP_GAIN with | ||
140 | * *both* SET_LEFT and SET_RIGHT bits takes a 16bit value, the lower 8bit | ||
141 | * for the left and the upper 8bit for the right channel. | ||
142 | */ | ||
143 | static bool is_stereo_amp_verb(unsigned int reg) | ||
144 | { | ||
145 | if (((reg >> 8) & 0x700) != AC_VERB_SET_AMP_GAIN_MUTE) | ||
146 | return false; | ||
147 | return (reg & (AC_AMP_SET_LEFT | AC_AMP_SET_RIGHT)) == | ||
148 | (AC_AMP_SET_LEFT | AC_AMP_SET_RIGHT); | ||
149 | } | ||
150 | |||
151 | /* read a pseudo stereo amp register (16bit left+right) */ | ||
152 | static int hda_reg_read_stereo_amp(struct hdac_device *codec, | ||
153 | unsigned int reg, unsigned int *val) | ||
154 | { | ||
155 | unsigned int left, right; | ||
156 | int err; | ||
157 | |||
158 | reg &= ~(AC_AMP_SET_LEFT | AC_AMP_SET_RIGHT); | ||
159 | err = snd_hdac_exec_verb(codec, reg | AC_AMP_GET_LEFT, 0, &left); | ||
160 | if (err < 0) | ||
161 | return err; | ||
162 | err = snd_hdac_exec_verb(codec, reg | AC_AMP_GET_RIGHT, 0, &right); | ||
163 | if (err < 0) | ||
164 | return err; | ||
165 | *val = left | (right << 8); | ||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | /* write a pseudo stereo amp register (16bit left+right) */ | ||
170 | static int hda_reg_write_stereo_amp(struct hdac_device *codec, | ||
171 | unsigned int reg, unsigned int val) | ||
172 | { | ||
173 | int err; | ||
174 | unsigned int verb, left, right; | ||
175 | |||
176 | verb = AC_VERB_SET_AMP_GAIN_MUTE << 8; | ||
177 | if (reg & AC_AMP_GET_OUTPUT) | ||
178 | verb |= AC_AMP_SET_OUTPUT; | ||
179 | else | ||
180 | verb |= AC_AMP_SET_INPUT | ((reg & 0xf) << 8); | ||
181 | reg = (reg & ~0xfffff) | verb; | ||
182 | |||
183 | left = val & 0xff; | ||
184 | right = (val >> 8) & 0xff; | ||
185 | if (left == right) { | ||
186 | reg |= AC_AMP_SET_LEFT | AC_AMP_SET_RIGHT; | ||
187 | return snd_hdac_exec_verb(codec, reg | left, 0, NULL); | ||
188 | } | ||
189 | |||
190 | err = snd_hdac_exec_verb(codec, reg | AC_AMP_SET_LEFT | left, 0, NULL); | ||
191 | if (err < 0) | ||
192 | return err; | ||
193 | err = snd_hdac_exec_verb(codec, reg | AC_AMP_SET_RIGHT | right, 0, NULL); | ||
194 | if (err < 0) | ||
195 | return err; | ||
196 | return 0; | ||
197 | } | ||
198 | |||
199 | /* read a pseudo coef register (16bit) */ | ||
200 | static int hda_reg_read_coef(struct hdac_device *codec, unsigned int reg, | ||
201 | unsigned int *val) | ||
202 | { | ||
203 | unsigned int verb; | ||
204 | int err; | ||
205 | |||
206 | if (!codec->cache_coef) | ||
207 | return -EINVAL; | ||
208 | /* LSB 8bit = coef index */ | ||
209 | verb = (reg & ~0xfff00) | (AC_VERB_SET_COEF_INDEX << 8); | ||
210 | err = snd_hdac_exec_verb(codec, verb, 0, NULL); | ||
211 | if (err < 0) | ||
212 | return err; | ||
213 | verb = (reg & ~0xfffff) | (AC_VERB_GET_COEF_INDEX << 8); | ||
214 | return snd_hdac_exec_verb(codec, verb, 0, val); | ||
215 | } | ||
216 | |||
217 | /* write a pseudo coef register (16bit) */ | ||
218 | static int hda_reg_write_coef(struct hdac_device *codec, unsigned int reg, | ||
219 | unsigned int val) | ||
220 | { | ||
221 | unsigned int verb; | ||
222 | int err; | ||
223 | |||
224 | if (!codec->cache_coef) | ||
225 | return -EINVAL; | ||
226 | /* LSB 8bit = coef index */ | ||
227 | verb = (reg & ~0xfff00) | (AC_VERB_SET_COEF_INDEX << 8); | ||
228 | err = snd_hdac_exec_verb(codec, verb, 0, NULL); | ||
229 | if (err < 0) | ||
230 | return err; | ||
231 | verb = (reg & ~0xfffff) | (AC_VERB_GET_COEF_INDEX << 8) | | ||
232 | (val & 0xffff); | ||
233 | return snd_hdac_exec_verb(codec, verb, 0, NULL); | ||
234 | } | ||
235 | |||
236 | static int hda_reg_read(void *context, unsigned int reg, unsigned int *val) | ||
237 | { | ||
238 | struct hdac_device *codec = context; | ||
239 | int verb = get_verb(reg); | ||
240 | int err; | ||
241 | |||
242 | if (!codec_is_running(codec) && verb != AC_VERB_GET_POWER_STATE) | ||
243 | return -EAGAIN; | ||
244 | reg |= (codec->addr << 28); | ||
245 | if (is_stereo_amp_verb(reg)) | ||
246 | return hda_reg_read_stereo_amp(codec, reg, val); | ||
247 | if (verb == AC_VERB_GET_PROC_COEF) | ||
248 | return hda_reg_read_coef(codec, reg, val); | ||
249 | err = snd_hdac_exec_verb(codec, reg, 0, val); | ||
250 | if (err < 0) | ||
251 | return err; | ||
252 | /* special handling for asymmetric reads */ | ||
253 | if (verb == AC_VERB_GET_POWER_STATE) { | ||
254 | if (*val & AC_PWRST_ERROR) | ||
255 | *val = -1; | ||
256 | else /* take only the actual state */ | ||
257 | *val = (*val >> 4) & 0x0f; | ||
258 | } | ||
259 | return 0; | ||
260 | } | ||
261 | |||
262 | static int hda_reg_write(void *context, unsigned int reg, unsigned int val) | ||
263 | { | ||
264 | struct hdac_device *codec = context; | ||
265 | unsigned int verb; | ||
266 | int i, bytes, err; | ||
267 | |||
268 | reg &= ~0x00080000U; /* drop GET bit */ | ||
269 | reg |= (codec->addr << 28); | ||
270 | verb = get_verb(reg); | ||
271 | |||
272 | if (!codec_is_running(codec) && verb != AC_VERB_SET_POWER_STATE) | ||
273 | return codec->lazy_cache ? 0 : -EAGAIN; | ||
274 | |||
275 | if (is_stereo_amp_verb(reg)) | ||
276 | return hda_reg_write_stereo_amp(codec, reg, val); | ||
277 | |||
278 | if (verb == AC_VERB_SET_PROC_COEF) | ||
279 | return hda_reg_write_coef(codec, reg, val); | ||
280 | |||
281 | switch (verb & 0xf00) { | ||
282 | case AC_VERB_SET_AMP_GAIN_MUTE: | ||
283 | verb = AC_VERB_SET_AMP_GAIN_MUTE; | ||
284 | if (reg & AC_AMP_GET_LEFT) | ||
285 | verb |= AC_AMP_SET_LEFT >> 8; | ||
286 | else | ||
287 | verb |= AC_AMP_SET_RIGHT >> 8; | ||
288 | if (reg & AC_AMP_GET_OUTPUT) { | ||
289 | verb |= AC_AMP_SET_OUTPUT >> 8; | ||
290 | } else { | ||
291 | verb |= AC_AMP_SET_INPUT >> 8; | ||
292 | verb |= reg & 0xf; | ||
293 | } | ||
294 | break; | ||
295 | } | ||
296 | |||
297 | switch (verb) { | ||
298 | case AC_VERB_SET_DIGI_CONVERT_1: | ||
299 | bytes = 2; | ||
300 | break; | ||
301 | case AC_VERB_SET_CONFIG_DEFAULT_BYTES_0: | ||
302 | bytes = 4; | ||
303 | break; | ||
304 | default: | ||
305 | bytes = 1; | ||
306 | break; | ||
307 | } | ||
308 | |||
309 | for (i = 0; i < bytes; i++) { | ||
310 | reg &= ~0xfffff; | ||
311 | reg |= (verb + i) << 8 | ((val >> (8 * i)) & 0xff); | ||
312 | err = snd_hdac_exec_verb(codec, reg, 0, NULL); | ||
313 | if (err < 0) | ||
314 | return err; | ||
315 | } | ||
316 | |||
317 | return 0; | ||
318 | } | ||
319 | |||
320 | static const struct regmap_config hda_regmap_cfg = { | ||
321 | .name = "hdaudio", | ||
322 | .reg_bits = 32, | ||
323 | .val_bits = 32, | ||
324 | .max_register = 0xfffffff, | ||
325 | .writeable_reg = hda_writeable_reg, | ||
326 | .readable_reg = hda_readable_reg, | ||
327 | .volatile_reg = hda_volatile_reg, | ||
328 | .cache_type = REGCACHE_RBTREE, | ||
329 | .reg_read = hda_reg_read, | ||
330 | .reg_write = hda_reg_write, | ||
331 | .use_single_rw = true, | ||
332 | }; | ||
333 | |||
334 | int snd_hdac_regmap_init(struct hdac_device *codec) | ||
335 | { | ||
336 | struct regmap *regmap; | ||
337 | |||
338 | regmap = regmap_init(&codec->dev, NULL, codec, &hda_regmap_cfg); | ||
339 | if (IS_ERR(regmap)) | ||
340 | return PTR_ERR(regmap); | ||
341 | codec->regmap = regmap; | ||
342 | snd_array_init(&codec->vendor_verbs, sizeof(unsigned int), 8); | ||
343 | return 0; | ||
344 | } | ||
345 | EXPORT_SYMBOL_GPL(snd_hdac_regmap_init); | ||
346 | |||
347 | void snd_hdac_regmap_exit(struct hdac_device *codec) | ||
348 | { | ||
349 | if (codec->regmap) { | ||
350 | regmap_exit(codec->regmap); | ||
351 | codec->regmap = NULL; | ||
352 | snd_array_free(&codec->vendor_verbs); | ||
353 | } | ||
354 | } | ||
355 | EXPORT_SYMBOL_GPL(snd_hdac_regmap_exit); | ||
356 | |||
357 | /** | ||
358 | * snd_hdac_regmap_add_vendor_verb - add a vendor-specific verb to regmap | ||
359 | * @codec: the codec object | ||
360 | * @verb: verb to allow accessing via regmap | ||
361 | * | ||
362 | * Returns zero for success or a negative error code. | ||
363 | */ | ||
364 | int snd_hdac_regmap_add_vendor_verb(struct hdac_device *codec, | ||
365 | unsigned int verb) | ||
366 | { | ||
367 | unsigned int *p = snd_array_new(&codec->vendor_verbs); | ||
368 | |||
369 | if (!p) | ||
370 | return -ENOMEM; | ||
371 | *p = verb | 0x800; /* set GET bit */ | ||
372 | return 0; | ||
373 | } | ||
374 | EXPORT_SYMBOL_GPL(snd_hdac_regmap_add_vendor_verb); | ||
375 | |||
376 | /* | ||
377 | * helper functions | ||
378 | */ | ||
379 | |||
380 | /* write a pseudo-register value (w/o power sequence) */ | ||
381 | static int reg_raw_write(struct hdac_device *codec, unsigned int reg, | ||
382 | unsigned int val) | ||
383 | { | ||
384 | if (!codec->regmap) | ||
385 | return hda_reg_write(codec, reg, val); | ||
386 | else | ||
387 | return regmap_write(codec->regmap, reg, val); | ||
388 | } | ||
389 | |||
390 | /** | ||
391 | * snd_hdac_regmap_write_raw - write a pseudo register with power mgmt | ||
392 | * @codec: the codec object | ||
393 | * @reg: pseudo register | ||
394 | * @val: value to write | ||
395 | * | ||
396 | * Returns zero if successful or a negative error code. | ||
397 | */ | ||
398 | int snd_hdac_regmap_write_raw(struct hdac_device *codec, unsigned int reg, | ||
399 | unsigned int val) | ||
400 | { | ||
401 | int err; | ||
402 | |||
403 | err = reg_raw_write(codec, reg, val); | ||
404 | if (err == -EAGAIN) { | ||
405 | snd_hdac_power_up_pm(codec); | ||
406 | err = reg_raw_write(codec, reg, val); | ||
407 | snd_hdac_power_down_pm(codec); | ||
408 | } | ||
409 | return err; | ||
410 | } | ||
411 | EXPORT_SYMBOL_GPL(snd_hdac_regmap_write_raw); | ||
412 | |||
413 | static int reg_raw_read(struct hdac_device *codec, unsigned int reg, | ||
414 | unsigned int *val) | ||
415 | { | ||
416 | if (!codec->regmap) | ||
417 | return hda_reg_read(codec, reg, val); | ||
418 | else | ||
419 | return regmap_read(codec->regmap, reg, val); | ||
420 | } | ||
421 | |||
422 | /** | ||
423 | * snd_hdac_regmap_read_raw - read a pseudo register with power mgmt | ||
424 | * @codec: the codec object | ||
425 | * @reg: pseudo register | ||
426 | * @val: pointer to store the read value | ||
427 | * | ||
428 | * Returns zero if successful or a negative error code. | ||
429 | */ | ||
430 | int snd_hdac_regmap_read_raw(struct hdac_device *codec, unsigned int reg, | ||
431 | unsigned int *val) | ||
432 | { | ||
433 | int err; | ||
434 | |||
435 | err = reg_raw_read(codec, reg, val); | ||
436 | if (err == -EAGAIN) { | ||
437 | snd_hdac_power_up_pm(codec); | ||
438 | err = reg_raw_read(codec, reg, val); | ||
439 | snd_hdac_power_down_pm(codec); | ||
440 | } | ||
441 | return err; | ||
442 | } | ||
443 | EXPORT_SYMBOL_GPL(snd_hdac_regmap_read_raw); | ||
444 | |||
445 | /** | ||
446 | * snd_hdac_regmap_update_raw - update a pseudo register with power mgmt | ||
447 | * @codec: the codec object | ||
448 | * @reg: pseudo register | ||
449 | * @mask: bit mask to udpate | ||
450 | * @val: value to update | ||
451 | * | ||
452 | * Returns zero if successful or a negative error code. | ||
453 | */ | ||
454 | int snd_hdac_regmap_update_raw(struct hdac_device *codec, unsigned int reg, | ||
455 | unsigned int mask, unsigned int val) | ||
456 | { | ||
457 | unsigned int orig; | ||
458 | int err; | ||
459 | |||
460 | val &= mask; | ||
461 | err = snd_hdac_regmap_read_raw(codec, reg, &orig); | ||
462 | if (err < 0) | ||
463 | return err; | ||
464 | val |= orig & ~mask; | ||
465 | if (val == orig) | ||
466 | return 0; | ||
467 | err = snd_hdac_regmap_write_raw(codec, reg, val); | ||
468 | if (err < 0) | ||
469 | return err; | ||
470 | return 1; | ||
471 | } | ||
472 | EXPORT_SYMBOL_GPL(snd_hdac_regmap_update_raw); | ||
diff --git a/sound/hda/hdac_sysfs.c b/sound/hda/hdac_sysfs.c new file mode 100644 index 000000000000..0a6ce3b84cc4 --- /dev/null +++ b/sound/hda/hdac_sysfs.c | |||
@@ -0,0 +1,406 @@ | |||
1 | /* | ||
2 | * sysfs support for HD-audio core device | ||
3 | */ | ||
4 | |||
5 | #include <linux/slab.h> | ||
6 | #include <linux/sysfs.h> | ||
7 | #include <linux/device.h> | ||
8 | #include <sound/core.h> | ||
9 | #include <sound/hdaudio.h> | ||
10 | #include "local.h" | ||
11 | |||
12 | struct hdac_widget_tree { | ||
13 | struct kobject *root; | ||
14 | struct kobject *afg; | ||
15 | struct kobject **nodes; | ||
16 | }; | ||
17 | |||
18 | #define CODEC_ATTR(type) \ | ||
19 | static ssize_t type##_show(struct device *dev, \ | ||
20 | struct device_attribute *attr, \ | ||
21 | char *buf) \ | ||
22 | { \ | ||
23 | struct hdac_device *codec = dev_to_hdac_dev(dev); \ | ||
24 | return sprintf(buf, "0x%x\n", codec->type); \ | ||
25 | } \ | ||
26 | static DEVICE_ATTR_RO(type) | ||
27 | |||
28 | #define CODEC_ATTR_STR(type) \ | ||
29 | static ssize_t type##_show(struct device *dev, \ | ||
30 | struct device_attribute *attr, \ | ||
31 | char *buf) \ | ||
32 | { \ | ||
33 | struct hdac_device *codec = dev_to_hdac_dev(dev); \ | ||
34 | return sprintf(buf, "%s\n", \ | ||
35 | codec->type ? codec->type : ""); \ | ||
36 | } \ | ||
37 | static DEVICE_ATTR_RO(type) | ||
38 | |||
39 | CODEC_ATTR(type); | ||
40 | CODEC_ATTR(vendor_id); | ||
41 | CODEC_ATTR(subsystem_id); | ||
42 | CODEC_ATTR(revision_id); | ||
43 | CODEC_ATTR(afg); | ||
44 | CODEC_ATTR(mfg); | ||
45 | CODEC_ATTR_STR(vendor_name); | ||
46 | CODEC_ATTR_STR(chip_name); | ||
47 | |||
48 | static struct attribute *hdac_dev_attrs[] = { | ||
49 | &dev_attr_type.attr, | ||
50 | &dev_attr_vendor_id.attr, | ||
51 | &dev_attr_subsystem_id.attr, | ||
52 | &dev_attr_revision_id.attr, | ||
53 | &dev_attr_afg.attr, | ||
54 | &dev_attr_mfg.attr, | ||
55 | &dev_attr_vendor_name.attr, | ||
56 | &dev_attr_chip_name.attr, | ||
57 | NULL | ||
58 | }; | ||
59 | |||
60 | static struct attribute_group hdac_dev_attr_group = { | ||
61 | .attrs = hdac_dev_attrs, | ||
62 | }; | ||
63 | |||
64 | const struct attribute_group *hdac_dev_attr_groups[] = { | ||
65 | &hdac_dev_attr_group, | ||
66 | NULL | ||
67 | }; | ||
68 | |||
69 | /* | ||
70 | * Widget tree sysfs | ||
71 | * | ||
72 | * This is a tree showing the attributes of each widget. It appears like | ||
73 | * /sys/bus/hdaudioC0D0/widgets/04/caps | ||
74 | */ | ||
75 | |||
76 | struct widget_attribute; | ||
77 | |||
78 | struct widget_attribute { | ||
79 | struct attribute attr; | ||
80 | ssize_t (*show)(struct hdac_device *codec, hda_nid_t nid, | ||
81 | struct widget_attribute *attr, char *buf); | ||
82 | ssize_t (*store)(struct hdac_device *codec, hda_nid_t nid, | ||
83 | struct widget_attribute *attr, | ||
84 | const char *buf, size_t count); | ||
85 | }; | ||
86 | |||
87 | static int get_codec_nid(struct kobject *kobj, struct hdac_device **codecp) | ||
88 | { | ||
89 | struct device *dev = kobj_to_dev(kobj->parent->parent); | ||
90 | int nid; | ||
91 | ssize_t ret; | ||
92 | |||
93 | ret = kstrtoint(kobj->name, 16, &nid); | ||
94 | if (ret < 0) | ||
95 | return ret; | ||
96 | *codecp = dev_to_hdac_dev(dev); | ||
97 | return nid; | ||
98 | } | ||
99 | |||
100 | static ssize_t widget_attr_show(struct kobject *kobj, struct attribute *attr, | ||
101 | char *buf) | ||
102 | { | ||
103 | struct widget_attribute *wid_attr = | ||
104 | container_of(attr, struct widget_attribute, attr); | ||
105 | struct hdac_device *codec; | ||
106 | int nid; | ||
107 | |||
108 | if (!wid_attr->show) | ||
109 | return -EIO; | ||
110 | nid = get_codec_nid(kobj, &codec); | ||
111 | if (nid < 0) | ||
112 | return nid; | ||
113 | return wid_attr->show(codec, nid, wid_attr, buf); | ||
114 | } | ||
115 | |||
116 | static ssize_t widget_attr_store(struct kobject *kobj, struct attribute *attr, | ||
117 | const char *buf, size_t count) | ||
118 | { | ||
119 | struct widget_attribute *wid_attr = | ||
120 | container_of(attr, struct widget_attribute, attr); | ||
121 | struct hdac_device *codec; | ||
122 | int nid; | ||
123 | |||
124 | if (!wid_attr->store) | ||
125 | return -EIO; | ||
126 | nid = get_codec_nid(kobj, &codec); | ||
127 | if (nid < 0) | ||
128 | return nid; | ||
129 | return wid_attr->store(codec, nid, wid_attr, buf, count); | ||
130 | } | ||
131 | |||
132 | static const struct sysfs_ops widget_sysfs_ops = { | ||
133 | .show = widget_attr_show, | ||
134 | .store = widget_attr_store, | ||
135 | }; | ||
136 | |||
137 | static void widget_release(struct kobject *kobj) | ||
138 | { | ||
139 | kfree(kobj); | ||
140 | } | ||
141 | |||
142 | static struct kobj_type widget_ktype = { | ||
143 | .release = widget_release, | ||
144 | .sysfs_ops = &widget_sysfs_ops, | ||
145 | }; | ||
146 | |||
147 | #define WIDGET_ATTR_RO(_name) \ | ||
148 | struct widget_attribute wid_attr_##_name = __ATTR_RO(_name) | ||
149 | #define WIDGET_ATTR_RW(_name) \ | ||
150 | struct widget_attribute wid_attr_##_name = __ATTR_RW(_name) | ||
151 | |||
152 | static ssize_t caps_show(struct hdac_device *codec, hda_nid_t nid, | ||
153 | struct widget_attribute *attr, char *buf) | ||
154 | { | ||
155 | return sprintf(buf, "0x%08x\n", get_wcaps(codec, nid)); | ||
156 | } | ||
157 | |||
158 | static ssize_t pin_caps_show(struct hdac_device *codec, hda_nid_t nid, | ||
159 | struct widget_attribute *attr, char *buf) | ||
160 | { | ||
161 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) | ||
162 | return 0; | ||
163 | return sprintf(buf, "0x%08x\n", | ||
164 | snd_hdac_read_parm(codec, nid, AC_PAR_PIN_CAP)); | ||
165 | } | ||
166 | |||
167 | static ssize_t pin_cfg_show(struct hdac_device *codec, hda_nid_t nid, | ||
168 | struct widget_attribute *attr, char *buf) | ||
169 | { | ||
170 | unsigned int val; | ||
171 | |||
172 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) | ||
173 | return 0; | ||
174 | if (snd_hdac_read(codec, nid, AC_VERB_GET_CONFIG_DEFAULT, 0, &val)) | ||
175 | return 0; | ||
176 | return sprintf(buf, "0x%08x\n", val); | ||
177 | } | ||
178 | |||
179 | static bool has_pcm_cap(struct hdac_device *codec, hda_nid_t nid) | ||
180 | { | ||
181 | if (nid == codec->afg || nid == codec->mfg) | ||
182 | return true; | ||
183 | switch (get_wcaps_type(get_wcaps(codec, nid))) { | ||
184 | case AC_WID_AUD_OUT: | ||
185 | case AC_WID_AUD_IN: | ||
186 | return true; | ||
187 | default: | ||
188 | return false; | ||
189 | } | ||
190 | } | ||
191 | |||
192 | static ssize_t pcm_caps_show(struct hdac_device *codec, hda_nid_t nid, | ||
193 | struct widget_attribute *attr, char *buf) | ||
194 | { | ||
195 | if (!has_pcm_cap(codec, nid)) | ||
196 | return 0; | ||
197 | return sprintf(buf, "0x%08x\n", | ||
198 | snd_hdac_read_parm(codec, nid, AC_PAR_PCM)); | ||
199 | } | ||
200 | |||
201 | static ssize_t pcm_formats_show(struct hdac_device *codec, hda_nid_t nid, | ||
202 | struct widget_attribute *attr, char *buf) | ||
203 | { | ||
204 | if (!has_pcm_cap(codec, nid)) | ||
205 | return 0; | ||
206 | return sprintf(buf, "0x%08x\n", | ||
207 | snd_hdac_read_parm(codec, nid, AC_PAR_STREAM)); | ||
208 | } | ||
209 | |||
210 | static ssize_t amp_in_caps_show(struct hdac_device *codec, hda_nid_t nid, | ||
211 | struct widget_attribute *attr, char *buf) | ||
212 | { | ||
213 | if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) | ||
214 | return 0; | ||
215 | return sprintf(buf, "0x%08x\n", | ||
216 | snd_hdac_read_parm(codec, nid, AC_PAR_AMP_IN_CAP)); | ||
217 | } | ||
218 | |||
219 | static ssize_t amp_out_caps_show(struct hdac_device *codec, hda_nid_t nid, | ||
220 | struct widget_attribute *attr, char *buf) | ||
221 | { | ||
222 | if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) | ||
223 | return 0; | ||
224 | return sprintf(buf, "0x%08x\n", | ||
225 | snd_hdac_read_parm(codec, nid, AC_PAR_AMP_OUT_CAP)); | ||
226 | } | ||
227 | |||
228 | static ssize_t power_caps_show(struct hdac_device *codec, hda_nid_t nid, | ||
229 | struct widget_attribute *attr, char *buf) | ||
230 | { | ||
231 | if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_POWER)) | ||
232 | return 0; | ||
233 | return sprintf(buf, "0x%08x\n", | ||
234 | snd_hdac_read_parm(codec, nid, AC_PAR_POWER_STATE)); | ||
235 | } | ||
236 | |||
237 | static ssize_t gpio_caps_show(struct hdac_device *codec, hda_nid_t nid, | ||
238 | struct widget_attribute *attr, char *buf) | ||
239 | { | ||
240 | return sprintf(buf, "0x%08x\n", | ||
241 | snd_hdac_read_parm(codec, nid, AC_PAR_GPIO_CAP)); | ||
242 | } | ||
243 | |||
244 | static ssize_t connections_show(struct hdac_device *codec, hda_nid_t nid, | ||
245 | struct widget_attribute *attr, char *buf) | ||
246 | { | ||
247 | hda_nid_t list[32]; | ||
248 | int i, nconns; | ||
249 | ssize_t ret = 0; | ||
250 | |||
251 | nconns = snd_hdac_get_connections(codec, nid, list, ARRAY_SIZE(list)); | ||
252 | if (nconns <= 0) | ||
253 | return nconns; | ||
254 | for (i = 0; i < nconns; i++) | ||
255 | ret += sprintf(buf + ret, "%s0x%02x", i ? " " : "", list[i]); | ||
256 | ret += sprintf(buf + ret, "\n"); | ||
257 | return ret; | ||
258 | } | ||
259 | |||
260 | static WIDGET_ATTR_RO(caps); | ||
261 | static WIDGET_ATTR_RO(pin_caps); | ||
262 | static WIDGET_ATTR_RO(pin_cfg); | ||
263 | static WIDGET_ATTR_RO(pcm_caps); | ||
264 | static WIDGET_ATTR_RO(pcm_formats); | ||
265 | static WIDGET_ATTR_RO(amp_in_caps); | ||
266 | static WIDGET_ATTR_RO(amp_out_caps); | ||
267 | static WIDGET_ATTR_RO(power_caps); | ||
268 | static WIDGET_ATTR_RO(gpio_caps); | ||
269 | static WIDGET_ATTR_RO(connections); | ||
270 | |||
271 | static struct attribute *widget_node_attrs[] = { | ||
272 | &wid_attr_caps.attr, | ||
273 | &wid_attr_pin_caps.attr, | ||
274 | &wid_attr_pin_cfg.attr, | ||
275 | &wid_attr_pcm_caps.attr, | ||
276 | &wid_attr_pcm_formats.attr, | ||
277 | &wid_attr_amp_in_caps.attr, | ||
278 | &wid_attr_amp_out_caps.attr, | ||
279 | &wid_attr_power_caps.attr, | ||
280 | &wid_attr_connections.attr, | ||
281 | NULL, | ||
282 | }; | ||
283 | |||
284 | static struct attribute *widget_afg_attrs[] = { | ||
285 | &wid_attr_pcm_caps.attr, | ||
286 | &wid_attr_pcm_formats.attr, | ||
287 | &wid_attr_amp_in_caps.attr, | ||
288 | &wid_attr_amp_out_caps.attr, | ||
289 | &wid_attr_power_caps.attr, | ||
290 | &wid_attr_gpio_caps.attr, | ||
291 | NULL, | ||
292 | }; | ||
293 | |||
294 | static const struct attribute_group widget_node_group = { | ||
295 | .attrs = widget_node_attrs, | ||
296 | }; | ||
297 | |||
298 | static const struct attribute_group widget_afg_group = { | ||
299 | .attrs = widget_afg_attrs, | ||
300 | }; | ||
301 | |||
302 | static void free_widget_node(struct kobject *kobj, | ||
303 | const struct attribute_group *group) | ||
304 | { | ||
305 | if (kobj) { | ||
306 | sysfs_remove_group(kobj, group); | ||
307 | kobject_put(kobj); | ||
308 | } | ||
309 | } | ||
310 | |||
311 | static void widget_tree_free(struct hdac_device *codec) | ||
312 | { | ||
313 | struct hdac_widget_tree *tree = codec->widgets; | ||
314 | struct kobject **p; | ||
315 | |||
316 | if (!tree) | ||
317 | return; | ||
318 | free_widget_node(tree->afg, &widget_afg_group); | ||
319 | if (tree->nodes) { | ||
320 | for (p = tree->nodes; *p; p++) | ||
321 | free_widget_node(*p, &widget_node_group); | ||
322 | kfree(tree->nodes); | ||
323 | } | ||
324 | if (tree->root) | ||
325 | kobject_put(tree->root); | ||
326 | kfree(tree); | ||
327 | codec->widgets = NULL; | ||
328 | } | ||
329 | |||
330 | static int add_widget_node(struct kobject *parent, hda_nid_t nid, | ||
331 | const struct attribute_group *group, | ||
332 | struct kobject **res) | ||
333 | { | ||
334 | struct kobject *kobj = kzalloc(sizeof(*kobj), GFP_KERNEL); | ||
335 | int err; | ||
336 | |||
337 | if (!kobj) | ||
338 | return -ENOMEM; | ||
339 | kobject_init(kobj, &widget_ktype); | ||
340 | err = kobject_add(kobj, parent, "%02x", nid); | ||
341 | if (err < 0) | ||
342 | return err; | ||
343 | err = sysfs_create_group(kobj, group); | ||
344 | if (err < 0) { | ||
345 | kobject_put(kobj); | ||
346 | return err; | ||
347 | } | ||
348 | |||
349 | *res = kobj; | ||
350 | return 0; | ||
351 | } | ||
352 | |||
353 | static int widget_tree_create(struct hdac_device *codec) | ||
354 | { | ||
355 | struct hdac_widget_tree *tree; | ||
356 | int i, err; | ||
357 | hda_nid_t nid; | ||
358 | |||
359 | tree = codec->widgets = kzalloc(sizeof(*tree), GFP_KERNEL); | ||
360 | if (!tree) | ||
361 | return -ENOMEM; | ||
362 | |||
363 | tree->root = kobject_create_and_add("widgets", &codec->dev.kobj); | ||
364 | if (!tree->root) | ||
365 | return -ENOMEM; | ||
366 | |||
367 | tree->nodes = kcalloc(codec->num_nodes + 1, sizeof(*tree->nodes), | ||
368 | GFP_KERNEL); | ||
369 | if (!tree->nodes) | ||
370 | return -ENOMEM; | ||
371 | |||
372 | for (i = 0, nid = codec->start_nid; i < codec->num_nodes; i++, nid++) { | ||
373 | err = add_widget_node(tree->root, nid, &widget_node_group, | ||
374 | &tree->nodes[i]); | ||
375 | if (err < 0) | ||
376 | return err; | ||
377 | } | ||
378 | |||
379 | if (codec->afg) { | ||
380 | err = add_widget_node(tree->root, codec->afg, | ||
381 | &widget_afg_group, &tree->afg); | ||
382 | if (err < 0) | ||
383 | return err; | ||
384 | } | ||
385 | |||
386 | kobject_uevent(tree->root, KOBJ_CHANGE); | ||
387 | return 0; | ||
388 | } | ||
389 | |||
390 | int hda_widget_sysfs_init(struct hdac_device *codec) | ||
391 | { | ||
392 | int err; | ||
393 | |||
394 | err = widget_tree_create(codec); | ||
395 | if (err < 0) { | ||
396 | widget_tree_free(codec); | ||
397 | return err; | ||
398 | } | ||
399 | |||
400 | return 0; | ||
401 | } | ||
402 | |||
403 | void hda_widget_sysfs_exit(struct hdac_device *codec) | ||
404 | { | ||
405 | widget_tree_free(codec); | ||
406 | } | ||
diff --git a/sound/hda/local.h b/sound/hda/local.h new file mode 100644 index 000000000000..d692f417ddc0 --- /dev/null +++ b/sound/hda/local.h | |||
@@ -0,0 +1,23 @@ | |||
1 | /* | ||
2 | * Local helper macros and functions for HD-audio core drivers | ||
3 | */ | ||
4 | |||
5 | #ifndef __HDAC_LOCAL_H | ||
6 | #define __HDAC_LOCAL_H | ||
7 | |||
8 | #define get_wcaps(codec, nid) \ | ||
9 | snd_hdac_read_parm(codec, nid, AC_PAR_AUDIO_WIDGET_CAP) | ||
10 | |||
11 | /* get the widget type from widget capability bits */ | ||
12 | static inline int get_wcaps_type(unsigned int wcaps) | ||
13 | { | ||
14 | if (!wcaps) | ||
15 | return -1; /* invalid type */ | ||
16 | return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; | ||
17 | } | ||
18 | |||
19 | extern const struct attribute_group *hdac_dev_attr_groups[]; | ||
20 | int hda_widget_sysfs_init(struct hdac_device *codec); | ||
21 | void hda_widget_sysfs_exit(struct hdac_device *codec); | ||
22 | |||
23 | #endif /* __HDAC_LOCAL_H */ | ||
diff --git a/sound/hda/trace.c b/sound/hda/trace.c new file mode 100644 index 000000000000..ca2d6bd94518 --- /dev/null +++ b/sound/hda/trace.c | |||
@@ -0,0 +1,6 @@ | |||
1 | /* | ||
2 | * tracepoint definitions for HD-audio core drivers | ||
3 | */ | ||
4 | |||
5 | #define CREATE_TRACE_POINTS | ||
6 | #include "trace.h" | ||
diff --git a/sound/hda/trace.h b/sound/hda/trace.h new file mode 100644 index 000000000000..33a7eb5573d4 --- /dev/null +++ b/sound/hda/trace.h | |||
@@ -0,0 +1,62 @@ | |||
1 | #undef TRACE_SYSTEM | ||
2 | #define TRACE_SYSTEM hda | ||
3 | |||
4 | #if !defined(__HDAC_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) | ||
5 | #define __HDAC_TRACE_H | ||
6 | |||
7 | #include <linux/tracepoint.h> | ||
8 | #include <linux/device.h> | ||
9 | #include <sound/hdaudio.h> | ||
10 | |||
11 | #ifndef HDAC_MSG_MAX | ||
12 | #define HDAC_MSG_MAX 500 | ||
13 | #endif | ||
14 | |||
15 | struct hdac_bus; | ||
16 | struct hdac_codec; | ||
17 | |||
18 | TRACE_EVENT(hda_send_cmd, | ||
19 | TP_PROTO(struct hdac_bus *bus, unsigned int cmd), | ||
20 | TP_ARGS(bus, cmd), | ||
21 | TP_STRUCT__entry(__dynamic_array(char, msg, HDAC_MSG_MAX)), | ||
22 | TP_fast_assign( | ||
23 | snprintf(__get_str(msg), HDAC_MSG_MAX, | ||
24 | "[%s:%d] val=0x%08x", | ||
25 | dev_name((bus)->dev), (cmd) >> 28, cmd); | ||
26 | ), | ||
27 | TP_printk("%s", __get_str(msg)) | ||
28 | ); | ||
29 | |||
30 | TRACE_EVENT(hda_get_response, | ||
31 | TP_PROTO(struct hdac_bus *bus, unsigned int addr, unsigned int res), | ||
32 | TP_ARGS(bus, addr, res), | ||
33 | TP_STRUCT__entry(__dynamic_array(char, msg, HDAC_MSG_MAX)), | ||
34 | TP_fast_assign( | ||
35 | snprintf(__get_str(msg), HDAC_MSG_MAX, | ||
36 | "[%s:%d] val=0x%08x", | ||
37 | dev_name((bus)->dev), addr, res); | ||
38 | ), | ||
39 | TP_printk("%s", __get_str(msg)) | ||
40 | ); | ||
41 | |||
42 | TRACE_EVENT(hda_unsol_event, | ||
43 | TP_PROTO(struct hdac_bus *bus, u32 res, u32 res_ex), | ||
44 | TP_ARGS(bus, res, res_ex), | ||
45 | TP_STRUCT__entry(__dynamic_array(char, msg, HDAC_MSG_MAX)), | ||
46 | TP_fast_assign( | ||
47 | snprintf(__get_str(msg), HDAC_MSG_MAX, | ||
48 | "[%s:%d] res=0x%08x, res_ex=0x%08x", | ||
49 | dev_name((bus)->dev), res_ex & 0x0f, res, res_ex); | ||
50 | ), | ||
51 | TP_printk("%s", __get_str(msg)) | ||
52 | ); | ||
53 | #endif /* __HDAC_TRACE_H */ | ||
54 | |||
55 | /* This part must be outside protection */ | ||
56 | #undef TRACE_INCLUDE_PATH | ||
57 | #define TRACE_INCLUDE_PATH . | ||
58 | |||
59 | #undef TRACE_INCLUDE_FILE | ||
60 | #define TRACE_INCLUDE_FILE trace | ||
61 | |||
62 | #include <trace/define_trace.h> | ||
diff --git a/sound/i2c/other/ak4113.c b/sound/i2c/other/ak4113.c index 88844881cbff..2183e9ebaa6d 100644 --- a/sound/i2c/other/ak4113.c +++ b/sound/i2c/other/ak4113.c | |||
@@ -73,7 +73,7 @@ int snd_ak4113_create(struct snd_card *card, ak4113_read_t *read, | |||
73 | void *private_data, struct ak4113 **r_ak4113) | 73 | void *private_data, struct ak4113 **r_ak4113) |
74 | { | 74 | { |
75 | struct ak4113 *chip; | 75 | struct ak4113 *chip; |
76 | int err = 0; | 76 | int err; |
77 | unsigned char reg; | 77 | unsigned char reg; |
78 | static struct snd_device_ops ops = { | 78 | static struct snd_device_ops ops = { |
79 | .dev_free = snd_ak4113_dev_free, | 79 | .dev_free = snd_ak4113_dev_free, |
@@ -109,7 +109,7 @@ int snd_ak4113_create(struct snd_card *card, ak4113_read_t *read, | |||
109 | 109 | ||
110 | __fail: | 110 | __fail: |
111 | snd_ak4113_free(chip); | 111 | snd_ak4113_free(chip); |
112 | return err < 0 ? err : -EIO; | 112 | return err; |
113 | } | 113 | } |
114 | EXPORT_SYMBOL_GPL(snd_ak4113_create); | 114 | EXPORT_SYMBOL_GPL(snd_ak4113_create); |
115 | 115 | ||
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 | */ |
37 | static int snd_emu8000_new_device(struct snd_seq_device *dev) | 37 | static 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 | */ |
96 | static int snd_emu8000_delete_device(struct snd_seq_device *dev) | 97 | static 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 | ||
117 | static int __init alsa_emu8000_init(void) | 119 | static 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 | 129 | module_snd_seq_driver(emu8000_driver); | |
128 | static void __exit alsa_emu8000_exit(void) | ||
129 | { | ||
130 | snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_EMU8000); | ||
131 | } | ||
132 | |||
133 | module_init(alsa_emu8000_init) | ||
134 | module_exit(alsa_emu8000_exit) | ||
diff --git a/sound/isa/wavefront/wavefront_fx.c b/sound/isa/wavefront/wavefront_fx.c index b5a19708473a..0608a5a4289d 100644 --- a/sound/isa/wavefront/wavefront_fx.c +++ b/sound/isa/wavefront/wavefront_fx.c | |||
@@ -79,13 +79,13 @@ wavefront_fx_memset (snd_wavefront_t *dev, | |||
79 | if (page < 0 || page > 7) { | 79 | if (page < 0 || page > 7) { |
80 | snd_printk ("FX memset: " | 80 | snd_printk ("FX memset: " |
81 | "page must be >= 0 and <= 7\n"); | 81 | "page must be >= 0 and <= 7\n"); |
82 | return -(EINVAL); | 82 | return -EINVAL; |
83 | } | 83 | } |
84 | 84 | ||
85 | if (addr < 0 || addr > 0x7f) { | 85 | if (addr < 0 || addr > 0x7f) { |
86 | snd_printk ("FX memset: " | 86 | snd_printk ("FX memset: " |
87 | "addr must be >= 0 and <= 7f\n"); | 87 | "addr must be >= 0 and <= 7f\n"); |
88 | return -(EINVAL); | 88 | return -EINVAL; |
89 | } | 89 | } |
90 | 90 | ||
91 | if (cnt == 1) { | 91 | if (cnt == 1) { |
@@ -118,7 +118,7 @@ wavefront_fx_memset (snd_wavefront_t *dev, | |||
118 | snd_printk ("FX memset " | 118 | snd_printk ("FX memset " |
119 | "(0x%x, 0x%x, 0x%lx, %d) incomplete\n", | 119 | "(0x%x, 0x%x, 0x%lx, %d) incomplete\n", |
120 | page, addr, (unsigned long) data, cnt); | 120 | page, addr, (unsigned long) data, cnt); |
121 | return -(EIO); | 121 | return -EIO; |
122 | } | 122 | } |
123 | } | 123 | } |
124 | 124 | ||
diff --git a/sound/isa/wavefront/wavefront_synth.c b/sound/isa/wavefront/wavefront_synth.c index 33f5ec14fcfa..69f76ff5693d 100644 --- a/sound/isa/wavefront/wavefront_synth.c +++ b/sound/isa/wavefront/wavefront_synth.c | |||
@@ -793,7 +793,7 @@ wavefront_send_patch (snd_wavefront_t *dev, wavefront_patch_info *header) | |||
793 | 793 | ||
794 | if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_PATCH, NULL, buf)) { | 794 | if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_PATCH, NULL, buf)) { |
795 | snd_printk ("download patch failed\n"); | 795 | snd_printk ("download patch failed\n"); |
796 | return -(EIO); | 796 | return -EIO; |
797 | } | 797 | } |
798 | 798 | ||
799 | return (0); | 799 | return (0); |
@@ -831,7 +831,7 @@ wavefront_send_program (snd_wavefront_t *dev, wavefront_patch_info *header) | |||
831 | 831 | ||
832 | if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_PROGRAM, NULL, buf)) { | 832 | if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_PROGRAM, NULL, buf)) { |
833 | snd_printk ("download patch failed\n"); | 833 | snd_printk ("download patch failed\n"); |
834 | return -(EIO); | 834 | return -EIO; |
835 | } | 835 | } |
836 | 836 | ||
837 | return (0); | 837 | return (0); |
@@ -952,7 +952,7 @@ wavefront_send_sample (snd_wavefront_t *dev, | |||
952 | if (skip > 0 && header->hdr.s.SampleResolution != LINEAR_16BIT) { | 952 | if (skip > 0 && header->hdr.s.SampleResolution != LINEAR_16BIT) { |
953 | snd_printk ("channel selection only " | 953 | snd_printk ("channel selection only " |
954 | "possible on 16-bit samples"); | 954 | "possible on 16-bit samples"); |
955 | return -(EINVAL); | 955 | return -EINVAL; |
956 | } | 956 | } |
957 | 957 | ||
958 | switch (skip) { | 958 | switch (skip) { |
@@ -1049,7 +1049,7 @@ wavefront_send_sample (snd_wavefront_t *dev, | |||
1049 | NULL, sample_hdr)) { | 1049 | NULL, sample_hdr)) { |
1050 | snd_printk ("sample %sdownload refused.\n", | 1050 | snd_printk ("sample %sdownload refused.\n", |
1051 | header->size ? "" : "header "); | 1051 | header->size ? "" : "header "); |
1052 | return -(EIO); | 1052 | return -EIO; |
1053 | } | 1053 | } |
1054 | 1054 | ||
1055 | if (header->size == 0) { | 1055 | if (header->size == 0) { |
@@ -1075,7 +1075,7 @@ wavefront_send_sample (snd_wavefront_t *dev, | |||
1075 | if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_BLOCK, NULL, NULL)) { | 1075 | if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_BLOCK, NULL, NULL)) { |
1076 | snd_printk ("download block " | 1076 | snd_printk ("download block " |
1077 | "request refused.\n"); | 1077 | "request refused.\n"); |
1078 | return -(EIO); | 1078 | return -EIO; |
1079 | } | 1079 | } |
1080 | 1080 | ||
1081 | for (i = 0; i < blocksize; i++) { | 1081 | for (i = 0; i < blocksize; i++) { |
@@ -1135,12 +1135,12 @@ wavefront_send_sample (snd_wavefront_t *dev, | |||
1135 | if (dma_ack == -1) { | 1135 | if (dma_ack == -1) { |
1136 | snd_printk ("upload sample " | 1136 | snd_printk ("upload sample " |
1137 | "DMA ack timeout\n"); | 1137 | "DMA ack timeout\n"); |
1138 | return -(EIO); | 1138 | return -EIO; |
1139 | } else { | 1139 | } else { |
1140 | snd_printk ("upload sample " | 1140 | snd_printk ("upload sample " |
1141 | "DMA ack error 0x%x\n", | 1141 | "DMA ack error 0x%x\n", |
1142 | dma_ack); | 1142 | dma_ack); |
1143 | return -(EIO); | 1143 | return -EIO; |
1144 | } | 1144 | } |
1145 | } | 1145 | } |
1146 | } | 1146 | } |
@@ -1181,7 +1181,7 @@ wavefront_send_alias (snd_wavefront_t *dev, wavefront_patch_info *header) | |||
1181 | 1181 | ||
1182 | if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_SAMPLE_ALIAS, NULL, alias_hdr)) { | 1182 | if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_SAMPLE_ALIAS, NULL, alias_hdr)) { |
1183 | snd_printk ("download alias failed.\n"); | 1183 | snd_printk ("download alias failed.\n"); |
1184 | return -(EIO); | 1184 | return -EIO; |
1185 | } | 1185 | } |
1186 | 1186 | ||
1187 | dev->sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_ALIAS); | 1187 | dev->sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_ALIAS); |
@@ -1232,7 +1232,7 @@ wavefront_send_multisample (snd_wavefront_t *dev, wavefront_patch_info *header) | |||
1232 | msample_hdr)) { | 1232 | msample_hdr)) { |
1233 | snd_printk ("download of multisample failed.\n"); | 1233 | snd_printk ("download of multisample failed.\n"); |
1234 | kfree(msample_hdr); | 1234 | kfree(msample_hdr); |
1235 | return -(EIO); | 1235 | return -EIO; |
1236 | } | 1236 | } |
1237 | 1237 | ||
1238 | dev->sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_MULTISAMPLE); | 1238 | dev->sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_MULTISAMPLE); |
@@ -1254,7 +1254,7 @@ wavefront_fetch_multisample (snd_wavefront_t *dev, | |||
1254 | 1254 | ||
1255 | if (snd_wavefront_cmd (dev, WFC_UPLOAD_MULTISAMPLE, log_ns, number)) { | 1255 | if (snd_wavefront_cmd (dev, WFC_UPLOAD_MULTISAMPLE, log_ns, number)) { |
1256 | snd_printk ("upload multisample failed.\n"); | 1256 | snd_printk ("upload multisample failed.\n"); |
1257 | return -(EIO); | 1257 | return -EIO; |
1258 | } | 1258 | } |
1259 | 1259 | ||
1260 | DPRINT (WF_DEBUG_DATA, "msample %d has %d samples\n", | 1260 | DPRINT (WF_DEBUG_DATA, "msample %d has %d samples\n", |
@@ -1273,14 +1273,14 @@ wavefront_fetch_multisample (snd_wavefront_t *dev, | |||
1273 | if ((val = wavefront_read (dev)) == -1) { | 1273 | if ((val = wavefront_read (dev)) == -1) { |
1274 | snd_printk ("upload multisample failed " | 1274 | snd_printk ("upload multisample failed " |
1275 | "during sample loop.\n"); | 1275 | "during sample loop.\n"); |
1276 | return -(EIO); | 1276 | return -EIO; |
1277 | } | 1277 | } |
1278 | d[0] = val; | 1278 | d[0] = val; |
1279 | 1279 | ||
1280 | if ((val = wavefront_read (dev)) == -1) { | 1280 | if ((val = wavefront_read (dev)) == -1) { |
1281 | snd_printk ("upload multisample failed " | 1281 | snd_printk ("upload multisample failed " |
1282 | "during sample loop.\n"); | 1282 | "during sample loop.\n"); |
1283 | return -(EIO); | 1283 | return -EIO; |
1284 | } | 1284 | } |
1285 | d[1] = val; | 1285 | d[1] = val; |
1286 | 1286 | ||
@@ -1315,7 +1315,7 @@ wavefront_send_drum (snd_wavefront_t *dev, wavefront_patch_info *header) | |||
1315 | 1315 | ||
1316 | if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_EDRUM_PROGRAM, NULL, drumbuf)) { | 1316 | if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_EDRUM_PROGRAM, NULL, drumbuf)) { |
1317 | snd_printk ("download drum failed.\n"); | 1317 | snd_printk ("download drum failed.\n"); |
1318 | return -(EIO); | 1318 | return -EIO; |
1319 | } | 1319 | } |
1320 | 1320 | ||
1321 | return (0); | 1321 | return (0); |
diff --git a/sound/mips/au1x00.c b/sound/mips/au1x00.c index fbcaa5434fd8..1e30e8475431 100644 --- a/sound/mips/au1x00.c +++ b/sound/mips/au1x00.c | |||
@@ -633,19 +633,25 @@ static int au1000_ac97_probe(struct platform_device *pdev) | |||
633 | 633 | ||
634 | au1000->stream[PLAYBACK] = kmalloc(sizeof(struct audio_stream), | 634 | au1000->stream[PLAYBACK] = kmalloc(sizeof(struct audio_stream), |
635 | GFP_KERNEL); | 635 | GFP_KERNEL); |
636 | if (!au1000->stream[PLAYBACK]) | 636 | if (!au1000->stream[PLAYBACK]) { |
637 | err = -ENOMEM; | ||
637 | goto out; | 638 | goto out; |
639 | } | ||
638 | au1000->stream[PLAYBACK]->dma = -1; | 640 | au1000->stream[PLAYBACK]->dma = -1; |
639 | 641 | ||
640 | au1000->stream[CAPTURE] = kmalloc(sizeof(struct audio_stream), | 642 | au1000->stream[CAPTURE] = kmalloc(sizeof(struct audio_stream), |
641 | GFP_KERNEL); | 643 | GFP_KERNEL); |
642 | if (!au1000->stream[CAPTURE]) | 644 | if (!au1000->stream[CAPTURE]) { |
645 | err = -ENOMEM; | ||
643 | goto out; | 646 | goto out; |
647 | } | ||
644 | au1000->stream[CAPTURE]->dma = -1; | 648 | au1000->stream[CAPTURE]->dma = -1; |
645 | 649 | ||
646 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 650 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
647 | if (!r) | 651 | if (!r) { |
652 | err = -ENODEV; | ||
648 | goto out; | 653 | goto out; |
654 | } | ||
649 | 655 | ||
650 | err = -EBUSY; | 656 | err = -EBUSY; |
651 | au1000->ac97_res_port = request_mem_region(r->start, resource_size(r), | 657 | au1000->ac97_res_port = request_mem_region(r->start, resource_size(r), |
diff --git a/sound/oss/dev_table.c b/sound/oss/dev_table.c index d8cf3e58dc76..6dad51596b70 100644 --- a/sound/oss/dev_table.c +++ b/sound/oss/dev_table.c | |||
@@ -58,13 +58,13 @@ int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver, | |||
58 | 58 | ||
59 | if (vers != AUDIO_DRIVER_VERSION || driver_size > sizeof(struct audio_driver)) { | 59 | if (vers != AUDIO_DRIVER_VERSION || driver_size > sizeof(struct audio_driver)) { |
60 | printk(KERN_ERR "Sound: Incompatible audio driver for %s\n", name); | 60 | printk(KERN_ERR "Sound: Incompatible audio driver for %s\n", name); |
61 | return -(EINVAL); | 61 | return -EINVAL; |
62 | } | 62 | } |
63 | num = sound_alloc_audiodev(); | 63 | num = sound_alloc_audiodev(); |
64 | 64 | ||
65 | if (num == -1) { | 65 | if (num == -1) { |
66 | printk(KERN_ERR "sound: Too many audio drivers\n"); | 66 | printk(KERN_ERR "sound: Too many audio drivers\n"); |
67 | return -(EBUSY); | 67 | return -EBUSY; |
68 | } | 68 | } |
69 | d = (struct audio_driver *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_driver))); | 69 | d = (struct audio_driver *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_driver))); |
70 | sound_nblocks++; | 70 | sound_nblocks++; |
@@ -79,7 +79,7 @@ int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver, | |||
79 | if (d == NULL || op == NULL) { | 79 | if (d == NULL || op == NULL) { |
80 | printk(KERN_ERR "Sound: Can't allocate driver for (%s)\n", name); | 80 | printk(KERN_ERR "Sound: Can't allocate driver for (%s)\n", name); |
81 | sound_unload_audiodev(num); | 81 | sound_unload_audiodev(num); |
82 | return -(ENOMEM); | 82 | return -ENOMEM; |
83 | } | 83 | } |
84 | init_waitqueue_head(&op->in_sleeper); | 84 | init_waitqueue_head(&op->in_sleeper); |
85 | init_waitqueue_head(&op->out_sleeper); | 85 | init_waitqueue_head(&op->out_sleeper); |
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 | ||
718 | static void opl3_command (int io_addr, unsigned int addr, unsigned int val) | 718 | static 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 | ||
610 | static void ess_audio_output_block | 610 | static 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) | |||
50 | static void | 50 | static void |
51 | poll_def_tmr(unsigned long dummy) | 51 | poll_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 | ||
78 | static void | 73 | static void |
diff --git a/sound/oss/v_midi.c b/sound/oss/v_midi.c index f0b4151d9b17..fc0ba276cc8f 100644 --- a/sound/oss/v_midi.c +++ b/sound/oss/v_midi.c | |||
@@ -49,13 +49,13 @@ static int v_midi_open (int dev, int mode, | |||
49 | unsigned long flags; | 49 | unsigned long flags; |
50 | 50 | ||
51 | if (devc == NULL) | 51 | if (devc == NULL) |
52 | return -(ENXIO); | 52 | return -ENXIO; |
53 | 53 | ||
54 | spin_lock_irqsave(&devc->lock,flags); | 54 | spin_lock_irqsave(&devc->lock,flags); |
55 | if (devc->opened) | 55 | if (devc->opened) |
56 | { | 56 | { |
57 | spin_unlock_irqrestore(&devc->lock,flags); | 57 | spin_unlock_irqrestore(&devc->lock,flags); |
58 | return -(EBUSY); | 58 | return -EBUSY; |
59 | } | 59 | } |
60 | devc->opened = 1; | 60 | devc->opened = 1; |
61 | spin_unlock_irqrestore(&devc->lock,flags); | 61 | spin_unlock_irqrestore(&devc->lock,flags); |
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c index 5ee2f17c287c..82259ca61e64 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 }, |
@@ -2901,7 +2902,8 @@ static int apply_quirk_str(struct snd_ac97 *ac97, const char *typestr) | |||
2901 | * Return: Zero if successful, or a negative error code on failure. | 2902 | * Return: Zero if successful, or a negative error code on failure. |
2902 | */ | 2903 | */ |
2903 | 2904 | ||
2904 | int snd_ac97_tune_hardware(struct snd_ac97 *ac97, struct ac97_quirk *quirk, const char *override) | 2905 | int snd_ac97_tune_hardware(struct snd_ac97 *ac97, |
2906 | const struct ac97_quirk *quirk, const char *override) | ||
2905 | { | 2907 | { |
2906 | int result; | 2908 | int result; |
2907 | 2909 | ||
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 | */ | ||
3357 | static const struct snd_kcontrol_new snd_ac97_controls_vt1613[] = { | ||
3358 | AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0), | ||
3359 | }; | ||
3360 | |||
3361 | static 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 | |||
3367 | static const struct snd_ac97_build_ops patch_vt1613_ops = { | ||
3368 | .build_specific = patch_vt1613_specific | ||
3369 | }; | ||
3370 | |||
3371 | static 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 | */ |
3357 | static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = { | 3384 | static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = { |
diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c index 850a8c984c25..66ddd981d1d5 100644 --- a/sound/pci/ad1889.c +++ b/sound/pci/ad1889.c | |||
@@ -747,7 +747,7 @@ snd_ad1889_proc_init(struct snd_ad1889 *chip) | |||
747 | snd_info_set_text_ops(entry, chip, snd_ad1889_proc_read); | 747 | snd_info_set_text_ops(entry, chip, snd_ad1889_proc_read); |
748 | } | 748 | } |
749 | 749 | ||
750 | static struct ac97_quirk ac97_quirks[] = { | 750 | static const struct ac97_quirk ac97_quirks[] = { |
751 | { | 751 | { |
752 | .subvendor = 0x11d4, /* AD */ | 752 | .subvendor = 0x11d4, /* AD */ |
753 | .subdevice = 0x1889, /* AD1889 */ | 753 | .subdevice = 0x1889, /* AD1889 */ |
diff --git a/sound/pci/asihpi/asihpi.c b/sound/pci/asihpi/asihpi.c index e5cd7be85355..1039eccbb895 100644 --- a/sound/pci/asihpi/asihpi.c +++ b/sound/pci/asihpi/asihpi.c | |||
@@ -2376,7 +2376,7 @@ static int snd_asihpi_cmode_add(struct snd_card_asihpi *asihpi, | |||
2376 | /*------------------------------------------------------------ | 2376 | /*------------------------------------------------------------ |
2377 | Sampleclock source controls | 2377 | Sampleclock source controls |
2378 | ------------------------------------------------------------*/ | 2378 | ------------------------------------------------------------*/ |
2379 | static const char const *sampleclock_sources[] = { | 2379 | static const char * const sampleclock_sources[] = { |
2380 | "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header", | 2380 | "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header", |
2381 | "SMPTE", "Digital1", "Auto", "Network", "Invalid", | 2381 | "SMPTE", "Digital1", "Auto", "Network", "Invalid", |
2382 | "Prev Module", "BLU-Link", | 2382 | "Prev Module", "BLU-Link", |
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c index d5f15c9bbeda..42a20c806b39 100644 --- a/sound/pci/atiixp.c +++ b/sound/pci/atiixp.c | |||
@@ -1390,7 +1390,7 @@ static irqreturn_t snd_atiixp_interrupt(int irq, void *dev_id) | |||
1390 | * ac97 mixer section | 1390 | * ac97 mixer section |
1391 | */ | 1391 | */ |
1392 | 1392 | ||
1393 | static struct ac97_quirk ac97_quirks[] = { | 1393 | static const struct ac97_quirk ac97_quirks[] = { |
1394 | { | 1394 | { |
1395 | .subvendor = 0x103c, | 1395 | .subvendor = 0x103c, |
1396 | .subdevice = 0x006b, | 1396 | .subdevice = 0x006b, |
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 = { | |||
2126 | static int | 2126 | static int |
2127 | snd_azf3328_pcm(struct snd_azf3328 *chip) | 2127 | snd_azf3328_pcm(struct snd_azf3328 *chip) |
2128 | { | 2128 | { |
2129 | enum { 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/cs5535audio/cs5535audio.c b/sound/pci/cs5535audio/cs5535audio.c index 802c33f1cc59..963b912550d4 100644 --- a/sound/pci/cs5535audio/cs5535audio.c +++ b/sound/pci/cs5535audio/cs5535audio.c | |||
@@ -43,7 +43,7 @@ static char *ac97_quirk; | |||
43 | module_param(ac97_quirk, charp, 0444); | 43 | module_param(ac97_quirk, charp, 0444); |
44 | MODULE_PARM_DESC(ac97_quirk, "AC'97 board specific workarounds."); | 44 | MODULE_PARM_DESC(ac97_quirk, "AC'97 board specific workarounds."); |
45 | 45 | ||
46 | static struct ac97_quirk ac97_quirks[] = { | 46 | static const struct ac97_quirk ac97_quirks[] = { |
47 | #if 0 /* Not yet confirmed if all 5536 boards are HP only */ | 47 | #if 0 /* Not yet confirmed if all 5536 boards are HP only */ |
48 | { | 48 | { |
49 | .subvendor = PCI_VENDOR_ID_AMD, | 49 | .subvendor = PCI_VENDOR_ID_AMD, |
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c index a962de03ebb6..862db9a0b041 100644 --- a/sound/pci/echoaudio/echoaudio.c +++ b/sound/pci/echoaudio/echoaudio.c | |||
@@ -1283,12 +1283,14 @@ static int snd_echo_mixer_info(struct snd_kcontrol *kcontrol, | |||
1283 | static int snd_echo_mixer_get(struct snd_kcontrol *kcontrol, | 1283 | static int snd_echo_mixer_get(struct snd_kcontrol *kcontrol, |
1284 | struct snd_ctl_elem_value *ucontrol) | 1284 | struct snd_ctl_elem_value *ucontrol) |
1285 | { | 1285 | { |
1286 | struct echoaudio *chip; | 1286 | struct echoaudio *chip = snd_kcontrol_chip(kcontrol); |
1287 | unsigned int out = ucontrol->id.index / num_busses_in(chip); | ||
1288 | unsigned int in = ucontrol->id.index % num_busses_in(chip); | ||
1287 | 1289 | ||
1288 | chip = snd_kcontrol_chip(kcontrol); | 1290 | if (out >= ECHO_MAXAUDIOOUTPUTS || in >= ECHO_MAXAUDIOINPUTS) |
1289 | ucontrol->value.integer.value[0] = | 1291 | return -EINVAL; |
1290 | chip->monitor_gain[ucontrol->id.index / num_busses_in(chip)] | 1292 | |
1291 | [ucontrol->id.index % num_busses_in(chip)]; | 1293 | ucontrol->value.integer.value[0] = chip->monitor_gain[out][in]; |
1292 | return 0; | 1294 | return 0; |
1293 | } | 1295 | } |
1294 | 1296 | ||
@@ -1297,12 +1299,14 @@ static int snd_echo_mixer_put(struct snd_kcontrol *kcontrol, | |||
1297 | { | 1299 | { |
1298 | struct echoaudio *chip; | 1300 | struct echoaudio *chip; |
1299 | int changed, gain; | 1301 | int changed, gain; |
1300 | short out, in; | 1302 | unsigned int out, in; |
1301 | 1303 | ||
1302 | changed = 0; | 1304 | changed = 0; |
1303 | chip = snd_kcontrol_chip(kcontrol); | 1305 | chip = snd_kcontrol_chip(kcontrol); |
1304 | out = ucontrol->id.index / num_busses_in(chip); | 1306 | out = ucontrol->id.index / num_busses_in(chip); |
1305 | in = ucontrol->id.index % num_busses_in(chip); | 1307 | in = ucontrol->id.index % num_busses_in(chip); |
1308 | if (out >= ECHO_MAXAUDIOOUTPUTS || in >= ECHO_MAXAUDIOINPUTS) | ||
1309 | return -EINVAL; | ||
1306 | gain = ucontrol->value.integer.value[0]; | 1310 | gain = ucontrol->value.integer.value[0]; |
1307 | if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT) | 1311 | if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT) |
1308 | return -EINVAL; | 1312 | return -EINVAL; |
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c index b4458a630a7c..54079f5d5673 100644 --- a/sound/pci/emu10k1/emu10k1_main.c +++ b/sound/pci/emu10k1/emu10k1_main.c | |||
@@ -707,6 +707,7 @@ static int emu1010_firmware_thread(void *data) | |||
707 | { | 707 | { |
708 | struct snd_emu10k1 *emu = data; | 708 | struct snd_emu10k1 *emu = data; |
709 | u32 tmp, tmp2, reg; | 709 | u32 tmp, tmp2, reg; |
710 | u32 last_reg = 0; | ||
710 | int err; | 711 | int err; |
711 | 712 | ||
712 | for (;;) { | 713 | for (;;) { |
@@ -782,7 +783,15 @@ static int emu1010_firmware_thread(void *data) | |||
782 | msleep(10); | 783 | msleep(10); |
783 | /* Unmute all. Default is muted after a firmware load */ | 784 | /* Unmute all. Default is muted after a firmware load */ |
784 | snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE); | 785 | snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE); |
786 | } else if (!reg && last_reg) { | ||
787 | /* Audio Dock removed */ | ||
788 | dev_info(emu->card->dev, | ||
789 | "emu1010: Audio Dock detached\n"); | ||
790 | /* Unmute all */ | ||
791 | snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE); | ||
785 | } | 792 | } |
793 | |||
794 | last_reg = reg; | ||
786 | } | 795 | } |
787 | dev_info(emu->card->dev, "emu1010: firmware thread stopping\n"); | 796 | dev_info(emu->card->dev, "emu1010: firmware thread stopping\n"); |
788 | return 0; | 797 | return 0; |
@@ -1325,6 +1334,22 @@ static int snd_emu10k1_dev_free(struct snd_device *device) | |||
1325 | } | 1334 | } |
1326 | 1335 | ||
1327 | static struct snd_emu_chip_details emu_chip_details[] = { | 1336 | static struct snd_emu_chip_details emu_chip_details[] = { |
1337 | /* Audigy 5/Rx SB1550 */ | ||
1338 | /* Tested by michael@gernoth.net 28 Mar 2015 */ | ||
1339 | /* DSP: CA10300-IAT LF | ||
1340 | * DAC: Cirrus Logic CS4382-KQZ | ||
1341 | * ADC: Philips 1361T | ||
1342 | * AC97: Sigmatel STAC9750 | ||
1343 | * CA0151: None | ||
1344 | */ | ||
1345 | {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10241102, | ||
1346 | .driver = "Audigy2", .name = "SB Audigy 5/Rx [SB1550]", | ||
1347 | .id = "Audigy2", | ||
1348 | .emu10k2_chip = 1, | ||
1349 | .ca0108_chip = 1, | ||
1350 | .spk71 = 1, | ||
1351 | .adc_1361t = 1, /* 24 bit capture instead of 16bit */ | ||
1352 | .ac97_chip = 1}, | ||
1328 | /* Audigy4 (Not PRO) SB0610 */ | 1353 | /* Audigy4 (Not PRO) SB0610 */ |
1329 | /* Tested by James@superbug.co.uk 4th April 2006 */ | 1354 | /* Tested by James@superbug.co.uk 4th April 2006 */ |
1330 | /* A_IOCFG bits | 1355 | /* A_IOCFG bits |
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 | */ |
32 | static int snd_emu10k1_synth_new_device(struct snd_seq_device *dev) | 32 | static 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 | ||
82 | static int snd_emu10k1_synth_delete_device(struct snd_seq_device *dev) | 83 | static 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 | ||
107 | static int __init alsa_emu10k1_synth_init(void) | 109 | static 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 | 119 | module_snd_seq_driver(emu10k1_synth_driver); | |
118 | static void __exit alsa_emu10k1_synth_exit(void) | ||
119 | { | ||
120 | snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH); | ||
121 | } | ||
122 | |||
123 | module_init(alsa_emu10k1_synth_init) | ||
124 | module_exit(alsa_emu10k1_synth_exit) | ||
diff --git a/sound/pci/emu10k1/emumixer.c b/sound/pci/emu10k1/emumixer.c index 1de33025669a..55e57166256e 100644 --- a/sound/pci/emu10k1/emumixer.c +++ b/sound/pci/emu10k1/emumixer.c | |||
@@ -806,6 +806,108 @@ static struct snd_kcontrol_new snd_emu1010_internal_clock = | |||
806 | .put = snd_emu1010_internal_clock_put | 806 | .put = snd_emu1010_internal_clock_put |
807 | }; | 807 | }; |
808 | 808 | ||
809 | static int snd_emu1010_optical_out_info(struct snd_kcontrol *kcontrol, | ||
810 | struct snd_ctl_elem_info *uinfo) | ||
811 | { | ||
812 | static const char * const texts[2] = { | ||
813 | "SPDIF", "ADAT" | ||
814 | }; | ||
815 | |||
816 | return snd_ctl_enum_info(uinfo, 1, 2, texts); | ||
817 | } | ||
818 | |||
819 | static int snd_emu1010_optical_out_get(struct snd_kcontrol *kcontrol, | ||
820 | struct snd_ctl_elem_value *ucontrol) | ||
821 | { | ||
822 | struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); | ||
823 | |||
824 | ucontrol->value.enumerated.item[0] = emu->emu1010.optical_out; | ||
825 | return 0; | ||
826 | } | ||
827 | |||
828 | static int snd_emu1010_optical_out_put(struct snd_kcontrol *kcontrol, | ||
829 | struct snd_ctl_elem_value *ucontrol) | ||
830 | { | ||
831 | struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); | ||
832 | unsigned int val; | ||
833 | u32 tmp; | ||
834 | int change = 0; | ||
835 | |||
836 | val = ucontrol->value.enumerated.item[0]; | ||
837 | /* Limit: uinfo->value.enumerated.items = 2; */ | ||
838 | if (val >= 2) | ||
839 | return -EINVAL; | ||
840 | change = (emu->emu1010.optical_out != val); | ||
841 | if (change) { | ||
842 | emu->emu1010.optical_out = val; | ||
843 | tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : 0) | | ||
844 | (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : 0); | ||
845 | snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp); | ||
846 | } | ||
847 | return change; | ||
848 | } | ||
849 | |||
850 | static struct snd_kcontrol_new snd_emu1010_optical_out = { | ||
851 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | ||
852 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
853 | .name = "Optical Output Mode", | ||
854 | .count = 1, | ||
855 | .info = snd_emu1010_optical_out_info, | ||
856 | .get = snd_emu1010_optical_out_get, | ||
857 | .put = snd_emu1010_optical_out_put | ||
858 | }; | ||
859 | |||
860 | static int snd_emu1010_optical_in_info(struct snd_kcontrol *kcontrol, | ||
861 | struct snd_ctl_elem_info *uinfo) | ||
862 | { | ||
863 | static const char * const texts[2] = { | ||
864 | "SPDIF", "ADAT" | ||
865 | }; | ||
866 | |||
867 | return snd_ctl_enum_info(uinfo, 1, 2, texts); | ||
868 | } | ||
869 | |||
870 | static int snd_emu1010_optical_in_get(struct snd_kcontrol *kcontrol, | ||
871 | struct snd_ctl_elem_value *ucontrol) | ||
872 | { | ||
873 | struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); | ||
874 | |||
875 | ucontrol->value.enumerated.item[0] = emu->emu1010.optical_in; | ||
876 | return 0; | ||
877 | } | ||
878 | |||
879 | static int snd_emu1010_optical_in_put(struct snd_kcontrol *kcontrol, | ||
880 | struct snd_ctl_elem_value *ucontrol) | ||
881 | { | ||
882 | struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); | ||
883 | unsigned int val; | ||
884 | u32 tmp; | ||
885 | int change = 0; | ||
886 | |||
887 | val = ucontrol->value.enumerated.item[0]; | ||
888 | /* Limit: uinfo->value.enumerated.items = 2; */ | ||
889 | if (val >= 2) | ||
890 | return -EINVAL; | ||
891 | change = (emu->emu1010.optical_in != val); | ||
892 | if (change) { | ||
893 | emu->emu1010.optical_in = val; | ||
894 | tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : 0) | | ||
895 | (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : 0); | ||
896 | snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp); | ||
897 | } | ||
898 | return change; | ||
899 | } | ||
900 | |||
901 | static struct snd_kcontrol_new snd_emu1010_optical_in = { | ||
902 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | ||
903 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
904 | .name = "Optical Input Mode", | ||
905 | .count = 1, | ||
906 | .info = snd_emu1010_optical_in_info, | ||
907 | .get = snd_emu1010_optical_in_get, | ||
908 | .put = snd_emu1010_optical_in_put | ||
909 | }; | ||
910 | |||
809 | static int snd_audigy_i2c_capture_source_info(struct snd_kcontrol *kcontrol, | 911 | static int snd_audigy_i2c_capture_source_info(struct snd_kcontrol *kcontrol, |
810 | struct snd_ctl_elem_info *uinfo) | 912 | struct snd_ctl_elem_info *uinfo) |
811 | { | 913 | { |
@@ -2051,6 +2153,14 @@ int snd_emu10k1_mixer(struct snd_emu10k1 *emu, | |||
2051 | snd_ctl_new1(&snd_emu1010_internal_clock, emu)); | 2153 | snd_ctl_new1(&snd_emu1010_internal_clock, emu)); |
2052 | if (err < 0) | 2154 | if (err < 0) |
2053 | return err; | 2155 | return err; |
2156 | err = snd_ctl_add(card, | ||
2157 | snd_ctl_new1(&snd_emu1010_optical_out, emu)); | ||
2158 | if (err < 0) | ||
2159 | return err; | ||
2160 | err = snd_ctl_add(card, | ||
2161 | snd_ctl_new1(&snd_emu1010_optical_in, emu)); | ||
2162 | if (err < 0) | ||
2163 | return err; | ||
2054 | 2164 | ||
2055 | } else if (emu->card_capabilities->emu_model) { | 2165 | } else if (emu->card_capabilities->emu_model) { |
2056 | /* all other e-mu cards for now */ | 2166 | /* all other e-mu cards for now */ |
@@ -2086,6 +2196,14 @@ int snd_emu10k1_mixer(struct snd_emu10k1 *emu, | |||
2086 | snd_ctl_new1(&snd_emu1010_internal_clock, emu)); | 2196 | snd_ctl_new1(&snd_emu1010_internal_clock, emu)); |
2087 | if (err < 0) | 2197 | if (err < 0) |
2088 | return err; | 2198 | return err; |
2199 | err = snd_ctl_add(card, | ||
2200 | snd_ctl_new1(&snd_emu1010_optical_out, emu)); | ||
2201 | if (err < 0) | ||
2202 | return err; | ||
2203 | err = snd_ctl_add(card, | ||
2204 | snd_ctl_new1(&snd_emu1010_optical_in, emu)); | ||
2205 | if (err < 0) | ||
2206 | return err; | ||
2089 | } | 2207 | } |
2090 | 2208 | ||
2091 | if ( emu->card_capabilities->i2c_adc) { | 2209 | if ( emu->card_capabilities->i2c_adc) { |
diff --git a/sound/pci/emu10k1/emuproc.c b/sound/pci/emu10k1/emuproc.c index 2ca9f2e93139..53745f4c2bf5 100644 --- a/sound/pci/emu10k1/emuproc.c +++ b/sound/pci/emu10k1/emuproc.c | |||
@@ -241,31 +241,22 @@ static void snd_emu10k1_proc_spdif_read(struct snd_info_entry *entry, | |||
241 | struct snd_emu10k1 *emu = entry->private_data; | 241 | struct snd_emu10k1 *emu = entry->private_data; |
242 | u32 value; | 242 | u32 value; |
243 | u32 value2; | 243 | u32 value2; |
244 | unsigned long flags; | ||
245 | u32 rate; | 244 | u32 rate; |
246 | 245 | ||
247 | if (emu->card_capabilities->emu_model) { | 246 | if (emu->card_capabilities->emu_model) { |
248 | spin_lock_irqsave(&emu->emu_lock, flags); | ||
249 | snd_emu1010_fpga_read(emu, 0x38, &value); | 247 | snd_emu1010_fpga_read(emu, 0x38, &value); |
250 | spin_unlock_irqrestore(&emu->emu_lock, flags); | ||
251 | if ((value & 0x1) == 0) { | 248 | if ((value & 0x1) == 0) { |
252 | spin_lock_irqsave(&emu->emu_lock, flags); | ||
253 | snd_emu1010_fpga_read(emu, 0x2a, &value); | 249 | snd_emu1010_fpga_read(emu, 0x2a, &value); |
254 | snd_emu1010_fpga_read(emu, 0x2b, &value2); | 250 | snd_emu1010_fpga_read(emu, 0x2b, &value2); |
255 | spin_unlock_irqrestore(&emu->emu_lock, flags); | ||
256 | rate = 0x1770000 / (((value << 5) | value2)+1); | 251 | rate = 0x1770000 / (((value << 5) | value2)+1); |
257 | snd_iprintf(buffer, "ADAT Locked : %u\n", rate); | 252 | snd_iprintf(buffer, "ADAT Locked : %u\n", rate); |
258 | } else { | 253 | } else { |
259 | snd_iprintf(buffer, "ADAT Unlocked\n"); | 254 | snd_iprintf(buffer, "ADAT Unlocked\n"); |
260 | } | 255 | } |
261 | spin_lock_irqsave(&emu->emu_lock, flags); | ||
262 | snd_emu1010_fpga_read(emu, 0x20, &value); | 256 | snd_emu1010_fpga_read(emu, 0x20, &value); |
263 | spin_unlock_irqrestore(&emu->emu_lock, flags); | ||
264 | if ((value & 0x4) == 0) { | 257 | if ((value & 0x4) == 0) { |
265 | spin_lock_irqsave(&emu->emu_lock, flags); | ||
266 | snd_emu1010_fpga_read(emu, 0x28, &value); | 258 | snd_emu1010_fpga_read(emu, 0x28, &value); |
267 | snd_emu1010_fpga_read(emu, 0x29, &value2); | 259 | snd_emu1010_fpga_read(emu, 0x29, &value2); |
268 | spin_unlock_irqrestore(&emu->emu_lock, flags); | ||
269 | rate = 0x1770000 / (((value << 5) | value2)+1); | 260 | rate = 0x1770000 / (((value << 5) | value2)+1); |
270 | snd_iprintf(buffer, "SPDIF Locked : %d\n", rate); | 261 | snd_iprintf(buffer, "SPDIF Locked : %d\n", rate); |
271 | } else { | 262 | } else { |
@@ -410,14 +401,11 @@ static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry, | |||
410 | { | 401 | { |
411 | struct snd_emu10k1 *emu = entry->private_data; | 402 | struct snd_emu10k1 *emu = entry->private_data; |
412 | u32 value; | 403 | u32 value; |
413 | unsigned long flags; | ||
414 | int i; | 404 | int i; |
415 | snd_iprintf(buffer, "EMU1010 Registers:\n\n"); | 405 | snd_iprintf(buffer, "EMU1010 Registers:\n\n"); |
416 | 406 | ||
417 | for(i = 0; i < 0x40; i+=1) { | 407 | for(i = 0; i < 0x40; i+=1) { |
418 | spin_lock_irqsave(&emu->emu_lock, flags); | ||
419 | snd_emu1010_fpga_read(emu, i, &value); | 408 | snd_emu1010_fpga_read(emu, i, &value); |
420 | spin_unlock_irqrestore(&emu->emu_lock, flags); | ||
421 | snd_iprintf(buffer, "%02X: %08X, %02X\n", i, value, (value >> 8) & 0x7f); | 409 | snd_iprintf(buffer, "%02X: %08X, %02X\n", i, value, (value >> 8) & 0x7f); |
422 | } | 410 | } |
423 | } | 411 | } |
diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig index 7f0f2c5a4e97..a5ed1c181784 100644 --- a/sound/pci/hda/Kconfig +++ b/sound/pci/hda/Kconfig | |||
@@ -5,6 +5,7 @@ config SND_HDA | |||
5 | select SND_PCM | 5 | select SND_PCM |
6 | select SND_VMASTER | 6 | select SND_VMASTER |
7 | select SND_KCTL_JACK | 7 | select SND_KCTL_JACK |
8 | select SND_HDA_CORE | ||
8 | 9 | ||
9 | config SND_HDA_INTEL | 10 | config SND_HDA_INTEL |
10 | tristate "HD Audio PCI" | 11 | tristate "HD Audio PCI" |
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile index 194f30935e77..af78fb33a4fd 100644 --- a/sound/pci/hda/Makefile +++ b/sound/pci/hda/Makefile | |||
@@ -4,13 +4,12 @@ snd-hda-tegra-objs := hda_tegra.o | |||
4 | # for haswell power well | 4 | # for haswell power well |
5 | snd-hda-intel-$(CONFIG_SND_HDA_I915) += hda_i915.o | 5 | snd-hda-intel-$(CONFIG_SND_HDA_I915) += hda_i915.o |
6 | 6 | ||
7 | snd-hda-codec-y := hda_codec.o hda_jack.o hda_auto_parser.o hda_sysfs.o | 7 | snd-hda-codec-y := hda_bind.o hda_codec.o hda_jack.o hda_auto_parser.o hda_sysfs.o |
8 | snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o | 8 | snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o |
9 | snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o | 9 | snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o |
10 | snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o | 10 | snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o |
11 | 11 | ||
12 | # for trace-points | 12 | # for trace-points |
13 | CFLAGS_hda_codec.o := -I$(src) | ||
14 | CFLAGS_hda_controller.o := -I$(src) | 13 | CFLAGS_hda_controller.o := -I$(src) |
15 | 14 | ||
16 | snd-hda-codec-generic-objs := hda_generic.o | 15 | snd-hda-codec-generic-objs := hda_generic.o |
diff --git a/sound/pci/hda/hda_auto_parser.c b/sound/pci/hda/hda_auto_parser.c index 3f8706bb3d16..03b7399bb7f0 100644 --- a/sound/pci/hda/hda_auto_parser.c +++ b/sound/pci/hda/hda_auto_parser.c | |||
@@ -172,7 +172,7 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec, | |||
172 | const hda_nid_t *ignore_nids, | 172 | const hda_nid_t *ignore_nids, |
173 | unsigned int cond_flags) | 173 | unsigned int cond_flags) |
174 | { | 174 | { |
175 | hda_nid_t nid, end_nid; | 175 | hda_nid_t nid; |
176 | short seq, assoc_line_out; | 176 | short seq, assoc_line_out; |
177 | struct auto_out_pin line_out[ARRAY_SIZE(cfg->line_out_pins)]; | 177 | struct auto_out_pin line_out[ARRAY_SIZE(cfg->line_out_pins)]; |
178 | struct auto_out_pin speaker_out[ARRAY_SIZE(cfg->speaker_pins)]; | 178 | struct auto_out_pin speaker_out[ARRAY_SIZE(cfg->speaker_pins)]; |
@@ -189,8 +189,7 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec, | |||
189 | memset(hp_out, 0, sizeof(hp_out)); | 189 | memset(hp_out, 0, sizeof(hp_out)); |
190 | assoc_line_out = 0; | 190 | assoc_line_out = 0; |
191 | 191 | ||
192 | end_nid = codec->start_nid + codec->num_nodes; | 192 | for_each_hda_codec_node(nid, codec) { |
193 | for (nid = codec->start_nid; nid < end_nid; nid++) { | ||
194 | unsigned int wid_caps = get_wcaps(codec, nid); | 193 | unsigned int wid_caps = get_wcaps(codec, nid); |
195 | unsigned int wid_type = get_wcaps_type(wid_caps); | 194 | unsigned int wid_type = get_wcaps_type(wid_caps); |
196 | unsigned int def_conf; | 195 | unsigned int def_conf; |
@@ -410,7 +409,7 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec, | |||
410 | * debug prints of the parsed results | 409 | * debug prints of the parsed results |
411 | */ | 410 | */ |
412 | codec_info(codec, "autoconfig for %s: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n", | 411 | codec_info(codec, "autoconfig for %s: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n", |
413 | codec->chip_name, cfg->line_outs, cfg->line_out_pins[0], | 412 | codec->core.chip_name, cfg->line_outs, cfg->line_out_pins[0], |
414 | cfg->line_out_pins[1], cfg->line_out_pins[2], | 413 | cfg->line_out_pins[1], cfg->line_out_pins[2], |
415 | cfg->line_out_pins[3], cfg->line_out_pins[4], | 414 | cfg->line_out_pins[3], cfg->line_out_pins[4], |
416 | cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" : | 415 | cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" : |
@@ -836,33 +835,33 @@ static void apply_fixup(struct hda_codec *codec, int id, int action, int depth) | |||
836 | if (action != HDA_FIXUP_ACT_PRE_PROBE || !fix->v.pins) | 835 | if (action != HDA_FIXUP_ACT_PRE_PROBE || !fix->v.pins) |
837 | break; | 836 | break; |
838 | codec_dbg(codec, "%s: Apply pincfg for %s\n", | 837 | codec_dbg(codec, "%s: Apply pincfg for %s\n", |
839 | codec->chip_name, modelname); | 838 | codec->core.chip_name, modelname); |
840 | snd_hda_apply_pincfgs(codec, fix->v.pins); | 839 | snd_hda_apply_pincfgs(codec, fix->v.pins); |
841 | break; | 840 | break; |
842 | case HDA_FIXUP_VERBS: | 841 | case HDA_FIXUP_VERBS: |
843 | if (action != HDA_FIXUP_ACT_PROBE || !fix->v.verbs) | 842 | if (action != HDA_FIXUP_ACT_PROBE || !fix->v.verbs) |
844 | break; | 843 | break; |
845 | codec_dbg(codec, "%s: Apply fix-verbs for %s\n", | 844 | codec_dbg(codec, "%s: Apply fix-verbs for %s\n", |
846 | codec->chip_name, modelname); | 845 | codec->core.chip_name, modelname); |
847 | snd_hda_add_verbs(codec, fix->v.verbs); | 846 | snd_hda_add_verbs(codec, fix->v.verbs); |
848 | break; | 847 | break; |
849 | case HDA_FIXUP_FUNC: | 848 | case HDA_FIXUP_FUNC: |
850 | if (!fix->v.func) | 849 | if (!fix->v.func) |
851 | break; | 850 | break; |
852 | codec_dbg(codec, "%s: Apply fix-func for %s\n", | 851 | codec_dbg(codec, "%s: Apply fix-func for %s\n", |
853 | codec->chip_name, modelname); | 852 | codec->core.chip_name, modelname); |
854 | fix->v.func(codec, fix, action); | 853 | fix->v.func(codec, fix, action); |
855 | break; | 854 | break; |
856 | case HDA_FIXUP_PINCTLS: | 855 | case HDA_FIXUP_PINCTLS: |
857 | if (action != HDA_FIXUP_ACT_PROBE || !fix->v.pins) | 856 | if (action != HDA_FIXUP_ACT_PROBE || !fix->v.pins) |
858 | break; | 857 | break; |
859 | codec_dbg(codec, "%s: Apply pinctl for %s\n", | 858 | codec_dbg(codec, "%s: Apply pinctl for %s\n", |
860 | codec->chip_name, modelname); | 859 | codec->core.chip_name, modelname); |
861 | set_pin_targets(codec, fix->v.pins); | 860 | set_pin_targets(codec, fix->v.pins); |
862 | break; | 861 | break; |
863 | default: | 862 | default: |
864 | codec_err(codec, "%s: Invalid fixup type %d\n", | 863 | codec_err(codec, "%s: Invalid fixup type %d\n", |
865 | codec->chip_name, fix->type); | 864 | codec->core.chip_name, fix->type); |
866 | break; | 865 | break; |
867 | } | 866 | } |
868 | if (!fix->chained || fix->chained_before) | 867 | if (!fix->chained || fix->chained_before) |
@@ -912,16 +911,16 @@ void snd_hda_pick_pin_fixup(struct hda_codec *codec, | |||
912 | return; | 911 | return; |
913 | 912 | ||
914 | for (pq = pin_quirk; pq->subvendor; pq++) { | 913 | for (pq = pin_quirk; pq->subvendor; pq++) { |
915 | if ((codec->subsystem_id & 0xffff0000) != (pq->subvendor << 16)) | 914 | if ((codec->core.subsystem_id & 0xffff0000) != (pq->subvendor << 16)) |
916 | continue; | 915 | continue; |
917 | if (codec->vendor_id != pq->codec) | 916 | if (codec->core.vendor_id != pq->codec) |
918 | continue; | 917 | continue; |
919 | if (pin_config_match(codec, pq->pins)) { | 918 | if (pin_config_match(codec, pq->pins)) { |
920 | codec->fixup_id = pq->value; | 919 | codec->fixup_id = pq->value; |
921 | #ifdef CONFIG_SND_DEBUG_VERBOSE | 920 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
922 | codec->fixup_name = pq->name; | 921 | codec->fixup_name = pq->name; |
923 | codec_dbg(codec, "%s: picked fixup %s (pin match)\n", | 922 | codec_dbg(codec, "%s: picked fixup %s (pin match)\n", |
924 | codec->chip_name, codec->fixup_name); | 923 | codec->core.chip_name, codec->fixup_name); |
925 | #endif | 924 | #endif |
926 | codec->fixup_list = fixlist; | 925 | codec->fixup_list = fixlist; |
927 | return; | 926 | return; |
@@ -963,7 +962,7 @@ void snd_hda_pick_fixup(struct hda_codec *codec, | |||
963 | codec->fixup_name = NULL; | 962 | codec->fixup_name = NULL; |
964 | codec->fixup_id = HDA_FIXUP_ID_NO_FIXUP; | 963 | codec->fixup_id = HDA_FIXUP_ID_NO_FIXUP; |
965 | codec_dbg(codec, "%s: picked no fixup (nofixup specified)\n", | 964 | codec_dbg(codec, "%s: picked no fixup (nofixup specified)\n", |
966 | codec->chip_name); | 965 | codec->core.chip_name); |
967 | return; | 966 | return; |
968 | } | 967 | } |
969 | 968 | ||
@@ -974,7 +973,7 @@ void snd_hda_pick_fixup(struct hda_codec *codec, | |||
974 | codec->fixup_name = models->name; | 973 | codec->fixup_name = models->name; |
975 | codec->fixup_list = fixlist; | 974 | codec->fixup_list = fixlist; |
976 | codec_dbg(codec, "%s: picked fixup %s (model specified)\n", | 975 | codec_dbg(codec, "%s: picked fixup %s (model specified)\n", |
977 | codec->chip_name, codec->fixup_name); | 976 | codec->core.chip_name, codec->fixup_name); |
978 | return; | 977 | return; |
979 | } | 978 | } |
980 | models++; | 979 | models++; |
@@ -987,7 +986,7 @@ void snd_hda_pick_fixup(struct hda_codec *codec, | |||
987 | #ifdef CONFIG_SND_DEBUG_VERBOSE | 986 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
988 | name = q->name; | 987 | name = q->name; |
989 | codec_dbg(codec, "%s: picked fixup %s (PCI SSID%s)\n", | 988 | codec_dbg(codec, "%s: picked fixup %s (PCI SSID%s)\n", |
990 | codec->chip_name, name, q->subdevice_mask ? "" : " - vendor generic"); | 989 | codec->core.chip_name, name, q->subdevice_mask ? "" : " - vendor generic"); |
991 | #endif | 990 | #endif |
992 | } | 991 | } |
993 | } | 992 | } |
@@ -996,12 +995,12 @@ void snd_hda_pick_fixup(struct hda_codec *codec, | |||
996 | unsigned int vendorid = | 995 | unsigned int vendorid = |
997 | q->subdevice | (q->subvendor << 16); | 996 | q->subdevice | (q->subvendor << 16); |
998 | unsigned int mask = 0xffff0000 | q->subdevice_mask; | 997 | unsigned int mask = 0xffff0000 | q->subdevice_mask; |
999 | if ((codec->subsystem_id & mask) == (vendorid & mask)) { | 998 | if ((codec->core.subsystem_id & mask) == (vendorid & mask)) { |
1000 | id = q->value; | 999 | id = q->value; |
1001 | #ifdef CONFIG_SND_DEBUG_VERBOSE | 1000 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
1002 | name = q->name; | 1001 | name = q->name; |
1003 | codec_dbg(codec, "%s: picked fixup %s (codec SSID)\n", | 1002 | codec_dbg(codec, "%s: picked fixup %s (codec SSID)\n", |
1004 | codec->chip_name, name); | 1003 | codec->core.chip_name, name); |
1005 | #endif | 1004 | #endif |
1006 | break; | 1005 | break; |
1007 | } | 1006 | } |
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c index 1e7de08e77cb..3364dc0fdeab 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 | ||
36 | static void snd_hda_generate_beep(struct work_struct *work) | 36 | /* generate or stop tone */ |
37 | static 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 | ||
57 | static 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,15 +163,15 @@ 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->core.vendor_id >> 16; |
165 | input_dev->id.product = codec->vendor_id & 0xffff; | 169 | input_dev->id.product = codec->core.vendor_id & 0xffff; |
166 | input_dev->id.version = 0x01; | 170 | input_dev->id.version = 0x01; |
167 | 171 | ||
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..00aa31c5f08e --- /dev/null +++ b/sound/pci/hda/hda_bind.c | |||
@@ -0,0 +1,273 @@ | |||
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 | /* | ||
18 | * find a matching codec preset | ||
19 | */ | ||
20 | static int hda_codec_match(struct hdac_device *dev, struct hdac_driver *drv) | ||
21 | { | ||
22 | struct hda_codec *codec = container_of(dev, struct hda_codec, core); | ||
23 | struct hda_codec_driver *driver = | ||
24 | container_of(drv, struct hda_codec_driver, core); | ||
25 | const struct hda_codec_preset *preset; | ||
26 | /* check probe_id instead of vendor_id if set */ | ||
27 | u32 id = codec->probe_id ? codec->probe_id : codec->core.vendor_id; | ||
28 | |||
29 | for (preset = driver->preset; preset->id; preset++) { | ||
30 | u32 mask = preset->mask; | ||
31 | |||
32 | if (preset->afg && preset->afg != codec->core.afg) | ||
33 | continue; | ||
34 | if (preset->mfg && preset->mfg != codec->core.mfg) | ||
35 | continue; | ||
36 | if (!mask) | ||
37 | mask = ~0; | ||
38 | if (preset->id == (id & mask) && | ||
39 | (!preset->rev || preset->rev == codec->core.revision_id)) { | ||
40 | codec->preset = preset; | ||
41 | return 1; | ||
42 | } | ||
43 | } | ||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | /* process an unsolicited event */ | ||
48 | static void hda_codec_unsol_event(struct hdac_device *dev, unsigned int ev) | ||
49 | { | ||
50 | struct hda_codec *codec = container_of(dev, struct hda_codec, core); | ||
51 | |||
52 | if (codec->patch_ops.unsol_event) | ||
53 | codec->patch_ops.unsol_event(codec, ev); | ||
54 | } | ||
55 | |||
56 | /* reset the codec name from the preset */ | ||
57 | static int codec_refresh_name(struct hda_codec *codec, const char *name) | ||
58 | { | ||
59 | if (name) { | ||
60 | kfree(codec->core.chip_name); | ||
61 | codec->core.chip_name = kstrdup(name, GFP_KERNEL); | ||
62 | } | ||
63 | return codec->core.chip_name ? 0 : -ENOMEM; | ||
64 | } | ||
65 | |||
66 | static int hda_codec_driver_probe(struct device *dev) | ||
67 | { | ||
68 | struct hda_codec *codec = dev_to_hda_codec(dev); | ||
69 | struct module *owner = dev->driver->owner; | ||
70 | int err; | ||
71 | |||
72 | if (WARN_ON(!codec->preset)) | ||
73 | return -EINVAL; | ||
74 | |||
75 | err = codec_refresh_name(codec, codec->preset->name); | ||
76 | if (err < 0) | ||
77 | goto error; | ||
78 | err = snd_hdac_regmap_init(&codec->core); | ||
79 | if (err < 0) | ||
80 | goto error; | ||
81 | |||
82 | if (!try_module_get(owner)) { | ||
83 | err = -EINVAL; | ||
84 | goto error; | ||
85 | } | ||
86 | |||
87 | err = codec->preset->patch(codec); | ||
88 | if (err < 0) | ||
89 | goto error_module; | ||
90 | |||
91 | err = snd_hda_codec_build_pcms(codec); | ||
92 | if (err < 0) | ||
93 | goto error_module; | ||
94 | err = snd_hda_codec_build_controls(codec); | ||
95 | if (err < 0) | ||
96 | goto error_module; | ||
97 | if (codec->card->registered) { | ||
98 | err = snd_card_register(codec->card); | ||
99 | if (err < 0) | ||
100 | goto error_module; | ||
101 | snd_hda_codec_register(codec); | ||
102 | } | ||
103 | |||
104 | codec->core.lazy_cache = true; | ||
105 | return 0; | ||
106 | |||
107 | error_module: | ||
108 | module_put(owner); | ||
109 | |||
110 | error: | ||
111 | snd_hda_codec_cleanup_for_unbind(codec); | ||
112 | return err; | ||
113 | } | ||
114 | |||
115 | static int hda_codec_driver_remove(struct device *dev) | ||
116 | { | ||
117 | struct hda_codec *codec = dev_to_hda_codec(dev); | ||
118 | |||
119 | if (codec->patch_ops.free) | ||
120 | codec->patch_ops.free(codec); | ||
121 | snd_hda_codec_cleanup_for_unbind(codec); | ||
122 | module_put(dev->driver->owner); | ||
123 | return 0; | ||
124 | } | ||
125 | |||
126 | static void hda_codec_driver_shutdown(struct device *dev) | ||
127 | { | ||
128 | struct hda_codec *codec = dev_to_hda_codec(dev); | ||
129 | |||
130 | if (!pm_runtime_suspended(dev) && codec->patch_ops.reboot_notify) | ||
131 | codec->patch_ops.reboot_notify(codec); | ||
132 | } | ||
133 | |||
134 | int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name, | ||
135 | struct module *owner) | ||
136 | { | ||
137 | drv->core.driver.name = name; | ||
138 | drv->core.driver.owner = owner; | ||
139 | drv->core.driver.bus = &snd_hda_bus_type; | ||
140 | drv->core.driver.probe = hda_codec_driver_probe; | ||
141 | drv->core.driver.remove = hda_codec_driver_remove; | ||
142 | drv->core.driver.shutdown = hda_codec_driver_shutdown; | ||
143 | drv->core.driver.pm = &hda_codec_driver_pm; | ||
144 | drv->core.type = HDA_DEV_LEGACY; | ||
145 | drv->core.match = hda_codec_match; | ||
146 | drv->core.unsol_event = hda_codec_unsol_event; | ||
147 | return driver_register(&drv->core.driver); | ||
148 | } | ||
149 | EXPORT_SYMBOL_GPL(__hda_codec_driver_register); | ||
150 | |||
151 | void hda_codec_driver_unregister(struct hda_codec_driver *drv) | ||
152 | { | ||
153 | driver_unregister(&drv->core.driver); | ||
154 | } | ||
155 | EXPORT_SYMBOL_GPL(hda_codec_driver_unregister); | ||
156 | |||
157 | static inline bool codec_probed(struct hda_codec *codec) | ||
158 | { | ||
159 | return device_attach(hda_codec_dev(codec)) > 0 && codec->preset; | ||
160 | } | ||
161 | |||
162 | /* try to auto-load and bind the codec module */ | ||
163 | static void codec_bind_module(struct hda_codec *codec) | ||
164 | { | ||
165 | #ifdef MODULE | ||
166 | request_module("snd-hda-codec-id:%08x", codec->core.vendor_id); | ||
167 | if (codec_probed(codec)) | ||
168 | return; | ||
169 | request_module("snd-hda-codec-id:%04x*", | ||
170 | (codec->core.vendor_id >> 16) & 0xffff); | ||
171 | if (codec_probed(codec)) | ||
172 | return; | ||
173 | #endif | ||
174 | } | ||
175 | |||
176 | #if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI) | ||
177 | /* if all audio out widgets are digital, let's assume the codec as a HDMI/DP */ | ||
178 | static bool is_likely_hdmi_codec(struct hda_codec *codec) | ||
179 | { | ||
180 | hda_nid_t nid; | ||
181 | |||
182 | for_each_hda_codec_node(nid, codec) { | ||
183 | unsigned int wcaps = get_wcaps(codec, nid); | ||
184 | switch (get_wcaps_type(wcaps)) { | ||
185 | case AC_WID_AUD_IN: | ||
186 | return false; /* HDMI parser supports only HDMI out */ | ||
187 | case AC_WID_AUD_OUT: | ||
188 | if (!(wcaps & AC_WCAP_DIGITAL)) | ||
189 | return false; | ||
190 | break; | ||
191 | } | ||
192 | } | ||
193 | return true; | ||
194 | } | ||
195 | #else | ||
196 | /* no HDMI codec parser support */ | ||
197 | #define is_likely_hdmi_codec(codec) false | ||
198 | #endif /* CONFIG_SND_HDA_CODEC_HDMI */ | ||
199 | |||
200 | static int codec_bind_generic(struct hda_codec *codec) | ||
201 | { | ||
202 | if (codec->probe_id) | ||
203 | return -ENODEV; | ||
204 | |||
205 | if (is_likely_hdmi_codec(codec)) { | ||
206 | codec->probe_id = HDA_CODEC_ID_GENERIC_HDMI; | ||
207 | #if IS_MODULE(CONFIG_SND_HDA_CODEC_HDMI) | ||
208 | request_module("snd-hda-codec-hdmi"); | ||
209 | #endif | ||
210 | if (codec_probed(codec)) | ||
211 | return 0; | ||
212 | } | ||
213 | |||
214 | codec->probe_id = HDA_CODEC_ID_GENERIC; | ||
215 | #if IS_MODULE(CONFIG_SND_HDA_GENERIC) | ||
216 | request_module("snd-hda-codec-generic"); | ||
217 | #endif | ||
218 | if (codec_probed(codec)) | ||
219 | return 0; | ||
220 | return -ENODEV; | ||
221 | } | ||
222 | |||
223 | #if IS_ENABLED(CONFIG_SND_HDA_GENERIC) | ||
224 | #define is_generic_config(codec) \ | ||
225 | (codec->modelname && !strcmp(codec->modelname, "generic")) | ||
226 | #else | ||
227 | #define is_generic_config(codec) 0 | ||
228 | #endif | ||
229 | |||
230 | /** | ||
231 | * snd_hda_codec_configure - (Re-)configure the HD-audio codec | ||
232 | * @codec: the HDA codec | ||
233 | * | ||
234 | * Start parsing of the given codec tree and (re-)initialize the whole | ||
235 | * patch instance. | ||
236 | * | ||
237 | * Returns 0 if successful or a negative error code. | ||
238 | */ | ||
239 | int snd_hda_codec_configure(struct hda_codec *codec) | ||
240 | { | ||
241 | int err; | ||
242 | |||
243 | if (is_generic_config(codec)) | ||
244 | codec->probe_id = HDA_CODEC_ID_GENERIC; | ||
245 | else | ||
246 | codec->probe_id = 0; | ||
247 | |||
248 | err = snd_hdac_device_register(&codec->core); | ||
249 | if (err < 0) | ||
250 | return err; | ||
251 | |||
252 | if (!codec->preset) | ||
253 | codec_bind_module(codec); | ||
254 | if (!codec->preset) { | ||
255 | err = codec_bind_generic(codec); | ||
256 | if (err < 0) { | ||
257 | codec_err(codec, "Unable to bind the codec\n"); | ||
258 | goto error; | ||
259 | } | ||
260 | } | ||
261 | |||
262 | /* audio codec should override the mixer name */ | ||
263 | if (codec->core.afg || !*codec->card->mixername) | ||
264 | snprintf(codec->card->mixername, | ||
265 | sizeof(codec->card->mixername), "%s %s", | ||
266 | codec->core.vendor_name, codec->core.chip_name); | ||
267 | return 0; | ||
268 | |||
269 | error: | ||
270 | snd_hdac_device_unregister(&codec->core); | ||
271 | return err; | ||
272 | } | ||
273 | EXPORT_SYMBOL_GPL(snd_hda_codec_configure); | ||
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 2fe86d2e1b09..e70a7fb393dd 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> |
@@ -37,97 +39,20 @@ | |||
37 | #include "hda_jack.h" | 39 | #include "hda_jack.h" |
38 | #include <sound/hda_hwdep.h> | 40 | #include <sound/hda_hwdep.h> |
39 | 41 | ||
40 | #define CREATE_TRACE_POINTS | ||
41 | #include "hda_trace.h" | ||
42 | |||
43 | /* | ||
44 | * vendor / preset table | ||
45 | */ | ||
46 | |||
47 | struct hda_vendor_id { | ||
48 | unsigned int id; | ||
49 | const char *name; | ||
50 | }; | ||
51 | |||
52 | /* codec vendor labels */ | ||
53 | static 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 | |||
77 | static DEFINE_MUTEX(preset_mutex); | ||
78 | static 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 | */ | ||
84 | int 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 | } | ||
91 | EXPORT_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 | */ | ||
97 | int 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 | } | ||
104 | EXPORT_SYMBOL_GPL(snd_hda_delete_codec_preset); | ||
105 | |||
106 | #ifdef CONFIG_PM | 42 | #ifdef CONFIG_PM |
107 | #define codec_in_pm(codec) ((codec)->in_pm) | 43 | #define codec_in_pm(codec) atomic_read(&(codec)->core.in_pm) |
108 | static void hda_power_work(struct work_struct *work); | 44 | #define hda_codec_is_power_on(codec) \ |
109 | static void hda_keep_power_on(struct hda_codec *codec); | 45 | (!pm_runtime_suspended(hda_codec_dev(codec))) |
110 | #define hda_codec_is_power_on(codec) ((codec)->power_on) | ||
111 | |||
112 | static 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 | 46 | #else |
125 | #define codec_in_pm(codec) 0 | 47 | #define codec_in_pm(codec) 0 |
126 | static inline void hda_keep_power_on(struct hda_codec *codec) {} | ||
127 | #define hda_codec_is_power_on(codec) 1 | 48 | #define hda_codec_is_power_on(codec) 1 |
128 | #define hda_call_pm_notify(codec, state) {} | ||
129 | #endif | 49 | #endif |
130 | 50 | ||
51 | #define codec_has_epss(codec) \ | ||
52 | ((codec)->core.power_caps & AC_PWRST_EPSS) | ||
53 | #define codec_has_clkstop(codec) \ | ||
54 | ((codec)->core.power_caps & AC_PWRST_CLKSTOP) | ||
55 | |||
131 | /** | 56 | /** |
132 | * snd_hda_get_jack_location - Give a location string of the jack | 57 | * snd_hda_get_jack_location - Give a location string of the jack |
133 | * @cfg: pin default config value | 58 | * @cfg: pin default config value |
@@ -199,67 +124,32 @@ const char *snd_hda_get_jack_type(u32 cfg) | |||
199 | EXPORT_SYMBOL_GPL(snd_hda_get_jack_type); | 124 | EXPORT_SYMBOL_GPL(snd_hda_get_jack_type); |
200 | 125 | ||
201 | /* | 126 | /* |
202 | * Compose a 32bit command word to be sent to the HD-audio controller | 127 | * Send and receive a verb - passed to exec_verb override for hdac_device |
203 | */ | ||
204 | static inline unsigned int | ||
205 | make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int flags, | ||
206 | unsigned int verb, unsigned int parm) | ||
207 | { | ||
208 | u32 val; | ||
209 | |||
210 | if ((codec->addr & ~0xf) || (nid & ~0x7f) || | ||
211 | (verb & ~0xfff) || (parm & ~0xffff)) { | ||
212 | codec_err(codec, "hda-codec: out of range cmd %x:%x:%x:%x\n", | ||
213 | codec->addr, nid, verb, parm); | ||
214 | return ~0; | ||
215 | } | ||
216 | |||
217 | val = (u32)codec->addr << 28; | ||
218 | val |= (u32)nid << 20; | ||
219 | val |= verb << 8; | ||
220 | val |= parm; | ||
221 | return val; | ||
222 | } | ||
223 | |||
224 | /* | ||
225 | * Send and receive a verb | ||
226 | */ | 128 | */ |
227 | static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd, | 129 | static int codec_exec_verb(struct hdac_device *dev, unsigned int cmd, |
228 | int flags, unsigned int *res) | 130 | unsigned int flags, unsigned int *res) |
229 | { | 131 | { |
132 | struct hda_codec *codec = container_of(dev, struct hda_codec, core); | ||
230 | struct hda_bus *bus = codec->bus; | 133 | struct hda_bus *bus = codec->bus; |
231 | int err; | 134 | int err; |
232 | 135 | ||
233 | if (cmd == ~0) | 136 | if (cmd == ~0) |
234 | return -1; | 137 | return -1; |
235 | 138 | ||
236 | if (res) | ||
237 | *res = -1; | ||
238 | again: | 139 | again: |
239 | snd_hda_power_up(codec); | 140 | snd_hda_power_up_pm(codec); |
240 | mutex_lock(&bus->cmd_mutex); | 141 | mutex_lock(&bus->core.cmd_mutex); |
241 | if (flags & HDA_RW_NO_RESPONSE_FALLBACK) | 142 | if (flags & HDA_RW_NO_RESPONSE_FALLBACK) |
242 | bus->no_response_fallback = 1; | 143 | bus->no_response_fallback = 1; |
243 | for (;;) { | 144 | err = snd_hdac_bus_exec_verb_unlocked(&bus->core, codec->core.addr, |
244 | trace_hda_send_cmd(codec, cmd); | 145 | cmd, res); |
245 | err = bus->ops.command(bus, cmd); | ||
246 | if (err != -EAGAIN) | ||
247 | break; | ||
248 | /* process pending verbs */ | ||
249 | bus->ops.get_response(bus, codec->addr); | ||
250 | } | ||
251 | if (!err && res) { | ||
252 | *res = bus->ops.get_response(bus, codec->addr); | ||
253 | trace_hda_get_response(codec, *res); | ||
254 | } | ||
255 | bus->no_response_fallback = 0; | 146 | bus->no_response_fallback = 0; |
256 | mutex_unlock(&bus->cmd_mutex); | 147 | mutex_unlock(&bus->core.cmd_mutex); |
257 | snd_hda_power_down(codec); | 148 | snd_hda_power_down_pm(codec); |
258 | if (!codec_in_pm(codec) && res && *res == -1 && bus->rirb_error) { | 149 | if (!codec_in_pm(codec) && res && err < 0 && bus->rirb_error) { |
259 | if (bus->response_reset) { | 150 | if (bus->response_reset) { |
260 | codec_dbg(codec, | 151 | codec_dbg(codec, |
261 | "resetting BUS due to fatal communication error\n"); | 152 | "resetting BUS due to fatal communication error\n"); |
262 | trace_hda_bus_reset(bus); | ||
263 | bus->ops.bus_reset(bus); | 153 | bus->ops.bus_reset(bus); |
264 | } | 154 | } |
265 | goto again; | 155 | goto again; |
@@ -286,9 +176,9 @@ unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid, | |||
286 | int flags, | 176 | int flags, |
287 | unsigned int verb, unsigned int parm) | 177 | unsigned int verb, unsigned int parm) |
288 | { | 178 | { |
289 | unsigned cmd = make_codec_cmd(codec, nid, flags, verb, parm); | 179 | unsigned int cmd = snd_hdac_make_cmd(&codec->core, nid, verb, parm); |
290 | unsigned int res; | 180 | unsigned int res; |
291 | if (codec_exec_verb(codec, cmd, flags, &res)) | 181 | if (snd_hdac_exec_verb(&codec->core, cmd, flags, &res)) |
292 | return -1; | 182 | return -1; |
293 | return res; | 183 | return res; |
294 | } | 184 | } |
@@ -309,10 +199,8 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_read); | |||
309 | int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags, | 199 | int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags, |
310 | unsigned int verb, unsigned int parm) | 200 | unsigned int verb, unsigned int parm) |
311 | { | 201 | { |
312 | unsigned int cmd = make_codec_cmd(codec, nid, flags, verb, parm); | 202 | unsigned int cmd = snd_hdac_make_cmd(&codec->core, nid, verb, parm); |
313 | unsigned int res; | 203 | return snd_hdac_exec_verb(&codec->core, cmd, flags, NULL); |
314 | return codec_exec_verb(codec, cmd, flags, | ||
315 | codec->bus->sync_write ? &res : NULL); | ||
316 | } | 204 | } |
317 | EXPORT_SYMBOL_GPL(snd_hda_codec_write); | 205 | EXPORT_SYMBOL_GPL(snd_hda_codec_write); |
318 | 206 | ||
@@ -331,30 +219,6 @@ void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq) | |||
331 | } | 219 | } |
332 | EXPORT_SYMBOL_GPL(snd_hda_sequence_write); | 220 | EXPORT_SYMBOL_GPL(snd_hda_sequence_write); |
333 | 221 | ||
334 | /** | ||
335 | * snd_hda_get_sub_nodes - get the range of sub nodes | ||
336 | * @codec: the HDA codec | ||
337 | * @nid: NID to parse | ||
338 | * @start_id: the pointer to store the start NID | ||
339 | * | ||
340 | * Parse the NID and store the start NID of its sub-nodes. | ||
341 | * Returns the number of sub-nodes. | ||
342 | */ | ||
343 | int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid, | ||
344 | hda_nid_t *start_id) | ||
345 | { | ||
346 | unsigned int parm; | ||
347 | |||
348 | parm = snd_hda_param_read(codec, nid, AC_PAR_NODE_COUNT); | ||
349 | if (parm == -1) { | ||
350 | *start_id = 0; | ||
351 | return 0; | ||
352 | } | ||
353 | *start_id = (parm >> 16) & 0x7fff; | ||
354 | return (int)(parm & 0x7fff); | ||
355 | } | ||
356 | EXPORT_SYMBOL_GPL(snd_hda_get_sub_nodes); | ||
357 | |||
358 | /* connection list element */ | 222 | /* connection list element */ |
359 | struct hda_conn_list { | 223 | struct hda_conn_list { |
360 | struct list_head list; | 224 | struct list_head list; |
@@ -495,128 +359,6 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, | |||
495 | } | 359 | } |
496 | EXPORT_SYMBOL_GPL(snd_hda_get_connections); | 360 | EXPORT_SYMBOL_GPL(snd_hda_get_connections); |
497 | 361 | ||
498 | /* return CONNLIST_LEN parameter of the given widget */ | ||
499 | static unsigned int get_num_conns(struct hda_codec *codec, hda_nid_t nid) | ||
500 | { | ||
501 | unsigned int wcaps = get_wcaps(codec, nid); | ||
502 | unsigned int parm; | ||
503 | |||
504 | if (!(wcaps & AC_WCAP_CONN_LIST) && | ||
505 | get_wcaps_type(wcaps) != AC_WID_VOL_KNB) | ||
506 | return 0; | ||
507 | |||
508 | parm = snd_hda_param_read(codec, nid, AC_PAR_CONNLIST_LEN); | ||
509 | if (parm == -1) | ||
510 | parm = 0; | ||
511 | return parm; | ||
512 | } | ||
513 | |||
514 | int snd_hda_get_num_raw_conns(struct hda_codec *codec, hda_nid_t nid) | ||
515 | { | ||
516 | return snd_hda_get_raw_connections(codec, nid, NULL, 0); | ||
517 | } | ||
518 | |||
519 | /** | ||
520 | * snd_hda_get_raw_connections - copy connection list without cache | ||
521 | * @codec: the HDA codec | ||
522 | * @nid: NID to parse | ||
523 | * @conn_list: connection list array | ||
524 | * @max_conns: max. number of connections to store | ||
525 | * | ||
526 | * Like snd_hda_get_connections(), copy the connection list but without | ||
527 | * checking through the connection-list cache. | ||
528 | * Currently called only from hda_proc.c, so not exported. | ||
529 | */ | ||
530 | int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid, | ||
531 | hda_nid_t *conn_list, int max_conns) | ||
532 | { | ||
533 | unsigned int parm; | ||
534 | int i, conn_len, conns; | ||
535 | unsigned int shift, num_elems, mask; | ||
536 | hda_nid_t prev_nid; | ||
537 | int null_count = 0; | ||
538 | |||
539 | parm = get_num_conns(codec, nid); | ||
540 | if (!parm) | ||
541 | return 0; | ||
542 | |||
543 | if (parm & AC_CLIST_LONG) { | ||
544 | /* long form */ | ||
545 | shift = 16; | ||
546 | num_elems = 2; | ||
547 | } else { | ||
548 | /* short form */ | ||
549 | shift = 8; | ||
550 | num_elems = 4; | ||
551 | } | ||
552 | conn_len = parm & AC_CLIST_LENGTH; | ||
553 | mask = (1 << (shift-1)) - 1; | ||
554 | |||
555 | if (!conn_len) | ||
556 | return 0; /* no connection */ | ||
557 | |||
558 | if (conn_len == 1) { | ||
559 | /* single connection */ | ||
560 | parm = snd_hda_codec_read(codec, nid, 0, | ||
561 | AC_VERB_GET_CONNECT_LIST, 0); | ||
562 | if (parm == -1 && codec->bus->rirb_error) | ||
563 | return -EIO; | ||
564 | if (conn_list) | ||
565 | conn_list[0] = parm & mask; | ||
566 | return 1; | ||
567 | } | ||
568 | |||
569 | /* multi connection */ | ||
570 | conns = 0; | ||
571 | prev_nid = 0; | ||
572 | for (i = 0; i < conn_len; i++) { | ||
573 | int range_val; | ||
574 | hda_nid_t val, n; | ||
575 | |||
576 | if (i % num_elems == 0) { | ||
577 | parm = snd_hda_codec_read(codec, nid, 0, | ||
578 | AC_VERB_GET_CONNECT_LIST, i); | ||
579 | if (parm == -1 && codec->bus->rirb_error) | ||
580 | return -EIO; | ||
581 | } | ||
582 | range_val = !!(parm & (1 << (shift-1))); /* ranges */ | ||
583 | val = parm & mask; | ||
584 | if (val == 0 && null_count++) { /* no second chance */ | ||
585 | codec_dbg(codec, | ||
586 | "invalid CONNECT_LIST verb %x[%i]:%x\n", | ||
587 | nid, i, parm); | ||
588 | return 0; | ||
589 | } | ||
590 | parm >>= shift; | ||
591 | if (range_val) { | ||
592 | /* ranges between the previous and this one */ | ||
593 | if (!prev_nid || prev_nid >= val) { | ||
594 | codec_warn(codec, | ||
595 | "invalid dep_range_val %x:%x\n", | ||
596 | prev_nid, val); | ||
597 | continue; | ||
598 | } | ||
599 | for (n = prev_nid + 1; n <= val; n++) { | ||
600 | if (conn_list) { | ||
601 | if (conns >= max_conns) | ||
602 | return -ENOSPC; | ||
603 | conn_list[conns] = n; | ||
604 | } | ||
605 | conns++; | ||
606 | } | ||
607 | } else { | ||
608 | if (conn_list) { | ||
609 | if (conns >= max_conns) | ||
610 | return -ENOSPC; | ||
611 | conn_list[conns] = val; | ||
612 | } | ||
613 | conns++; | ||
614 | } | ||
615 | prev_nid = val; | ||
616 | } | ||
617 | return conns; | ||
618 | } | ||
619 | |||
620 | /** | 362 | /** |
621 | * snd_hda_override_conn_list - add/modify the connection-list to cache | 363 | * snd_hda_override_conn_list - add/modify the connection-list to cache |
622 | * @codec: the HDA codec | 364 | * @codec: the HDA codec |
@@ -741,90 +483,6 @@ int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, | |||
741 | return devices; | 483 | return devices; |
742 | } | 484 | } |
743 | 485 | ||
744 | /** | ||
745 | * snd_hda_queue_unsol_event - add an unsolicited event to queue | ||
746 | * @bus: the BUS | ||
747 | * @res: unsolicited event (lower 32bit of RIRB entry) | ||
748 | * @res_ex: codec addr and flags (upper 32bit or RIRB entry) | ||
749 | * | ||
750 | * Adds the given event to the queue. The events are processed in | ||
751 | * the workqueue asynchronously. Call this function in the interrupt | ||
752 | * hanlder when RIRB receives an unsolicited event. | ||
753 | * | ||
754 | * Returns 0 if successful, or a negative error code. | ||
755 | */ | ||
756 | int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex) | ||
757 | { | ||
758 | struct hda_bus_unsolicited *unsol; | ||
759 | unsigned int wp; | ||
760 | |||
761 | if (!bus || !bus->workq) | ||
762 | return 0; | ||
763 | |||
764 | trace_hda_unsol_event(bus, res, res_ex); | ||
765 | unsol = bus->unsol; | ||
766 | if (!unsol) | ||
767 | return 0; | ||
768 | |||
769 | wp = (unsol->wp + 1) % HDA_UNSOL_QUEUE_SIZE; | ||
770 | unsol->wp = wp; | ||
771 | |||
772 | wp <<= 1; | ||
773 | unsol->queue[wp] = res; | ||
774 | unsol->queue[wp + 1] = res_ex; | ||
775 | |||
776 | queue_work(bus->workq, &unsol->work); | ||
777 | |||
778 | return 0; | ||
779 | } | ||
780 | EXPORT_SYMBOL_GPL(snd_hda_queue_unsol_event); | ||
781 | |||
782 | /* | ||
783 | * process queued unsolicited events | ||
784 | */ | ||
785 | static void process_unsol_events(struct work_struct *work) | ||
786 | { | ||
787 | struct hda_bus_unsolicited *unsol = | ||
788 | container_of(work, struct hda_bus_unsolicited, work); | ||
789 | struct hda_bus *bus = unsol->bus; | ||
790 | struct hda_codec *codec; | ||
791 | unsigned int rp, caddr, res; | ||
792 | |||
793 | while (unsol->rp != unsol->wp) { | ||
794 | rp = (unsol->rp + 1) % HDA_UNSOL_QUEUE_SIZE; | ||
795 | unsol->rp = rp; | ||
796 | rp <<= 1; | ||
797 | res = unsol->queue[rp]; | ||
798 | caddr = unsol->queue[rp + 1]; | ||
799 | if (!(caddr & (1 << 4))) /* no unsolicited event? */ | ||
800 | continue; | ||
801 | codec = bus->caddr_tbl[caddr & 0x0f]; | ||
802 | if (codec && codec->patch_ops.unsol_event) | ||
803 | codec->patch_ops.unsol_event(codec, res); | ||
804 | } | ||
805 | } | ||
806 | |||
807 | /* | ||
808 | * initialize unsolicited queue | ||
809 | */ | ||
810 | static 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 | /* | 486 | /* |
829 | * destructor | 487 | * destructor |
830 | */ | 488 | */ |
@@ -832,16 +490,9 @@ static void snd_hda_bus_free(struct hda_bus *bus) | |||
832 | { | 490 | { |
833 | if (!bus) | 491 | if (!bus) |
834 | return; | 492 | return; |
835 | |||
836 | WARN_ON(!list_empty(&bus->codec_list)); | ||
837 | if (bus->workq) | ||
838 | flush_workqueue(bus->workq); | ||
839 | kfree(bus->unsol); | ||
840 | if (bus->ops.private_free) | 493 | if (bus->ops.private_free) |
841 | bus->ops.private_free(bus); | 494 | bus->ops.private_free(bus); |
842 | if (bus->workq) | 495 | snd_hdac_bus_exit(&bus->core); |
843 | destroy_workqueue(bus->workq); | ||
844 | |||
845 | kfree(bus); | 496 | kfree(bus); |
846 | } | 497 | } |
847 | 498 | ||
@@ -858,17 +509,35 @@ static int snd_hda_bus_dev_disconnect(struct snd_device *device) | |||
858 | return 0; | 509 | return 0; |
859 | } | 510 | } |
860 | 511 | ||
512 | /* hdac_bus_ops translations */ | ||
513 | static int _hda_bus_command(struct hdac_bus *_bus, unsigned int cmd) | ||
514 | { | ||
515 | struct hda_bus *bus = container_of(_bus, struct hda_bus, core); | ||
516 | return bus->ops.command(bus, cmd); | ||
517 | } | ||
518 | |||
519 | static int _hda_bus_get_response(struct hdac_bus *_bus, unsigned int addr, | ||
520 | unsigned int *res) | ||
521 | { | ||
522 | struct hda_bus *bus = container_of(_bus, struct hda_bus, core); | ||
523 | *res = bus->ops.get_response(bus, addr); | ||
524 | return bus->rirb_error ? -EIO : 0; | ||
525 | } | ||
526 | |||
527 | static const struct hdac_bus_ops bus_ops = { | ||
528 | .command = _hda_bus_command, | ||
529 | .get_response = _hda_bus_get_response, | ||
530 | }; | ||
531 | |||
861 | /** | 532 | /** |
862 | * snd_hda_bus_new - create a HDA bus | 533 | * snd_hda_bus_new - create a HDA bus |
863 | * @card: the card entry | 534 | * @card: the card entry |
864 | * @temp: the template for hda_bus information | ||
865 | * @busp: the pointer to store the created bus instance | 535 | * @busp: the pointer to store the created bus instance |
866 | * | 536 | * |
867 | * Returns 0 if successful, or a negative error code. | 537 | * Returns 0 if successful, or a negative error code. |
868 | */ | 538 | */ |
869 | int snd_hda_bus_new(struct snd_card *card, | 539 | int snd_hda_bus_new(struct snd_card *card, |
870 | const struct hda_bus_template *temp, | 540 | struct hda_bus **busp) |
871 | struct hda_bus **busp) | ||
872 | { | 541 | { |
873 | struct hda_bus *bus; | 542 | struct hda_bus *bus; |
874 | int err; | 543 | int err; |
@@ -877,40 +546,21 @@ int snd_hda_bus_new(struct snd_card *card, | |||
877 | .dev_free = snd_hda_bus_dev_free, | 546 | .dev_free = snd_hda_bus_dev_free, |
878 | }; | 547 | }; |
879 | 548 | ||
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) | 549 | if (busp) |
886 | *busp = NULL; | 550 | *busp = NULL; |
887 | 551 | ||
888 | bus = kzalloc(sizeof(*bus), GFP_KERNEL); | 552 | bus = kzalloc(sizeof(*bus), GFP_KERNEL); |
889 | if (bus == NULL) { | 553 | if (!bus) |
890 | dev_err(card->dev, "can't allocate struct hda_bus\n"); | ||
891 | return -ENOMEM; | 554 | return -ENOMEM; |
555 | |||
556 | err = snd_hdac_bus_init(&bus->core, card->dev, &bus_ops); | ||
557 | if (err < 0) { | ||
558 | kfree(bus); | ||
559 | return err; | ||
892 | } | 560 | } |
893 | 561 | ||
894 | bus->card = card; | 562 | 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); | ||
902 | mutex_init(&bus->prepare_mutex); | 563 | mutex_init(&bus->prepare_mutex); |
903 | INIT_LIST_HEAD(&bus->codec_list); | ||
904 | |||
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 | 564 | ||
915 | err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops); | 565 | err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops); |
916 | if (err < 0) { | 566 | if (err < 0) { |
@@ -923,140 +573,6 @@ int snd_hda_bus_new(struct snd_card *card, | |||
923 | } | 573 | } |
924 | EXPORT_SYMBOL_GPL(snd_hda_bus_new); | 574 | EXPORT_SYMBOL_GPL(snd_hda_bus_new); |
925 | 575 | ||
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 | */ | ||
942 | static const struct hda_codec_preset * | ||
943 | find_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 | */ | ||
992 | static 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 | /* | ||
1032 | * look for an AFG and MFG nodes | ||
1033 | */ | ||
1034 | static void setup_fg_nodes(struct hda_codec *codec) | ||
1035 | { | ||
1036 | int i, total_nodes, function_id; | ||
1037 | hda_nid_t nid; | ||
1038 | |||
1039 | total_nodes = snd_hda_get_sub_nodes(codec, AC_NODE_ROOT, &nid); | ||
1040 | for (i = 0; i < total_nodes; i++, nid++) { | ||
1041 | function_id = snd_hda_param_read(codec, nid, | ||
1042 | AC_PAR_FUNCTION_TYPE); | ||
1043 | switch (function_id & 0xff) { | ||
1044 | case AC_GRP_AUDIO_FUNCTION: | ||
1045 | codec->afg = nid; | ||
1046 | codec->afg_function_id = function_id & 0xff; | ||
1047 | codec->afg_unsol = (function_id >> 8) & 1; | ||
1048 | break; | ||
1049 | case AC_GRP_MODEM_FUNCTION: | ||
1050 | codec->mfg = nid; | ||
1051 | codec->mfg_function_id = function_id & 0xff; | ||
1052 | codec->mfg_unsol = (function_id >> 8) & 1; | ||
1053 | break; | ||
1054 | default: | ||
1055 | break; | ||
1056 | } | ||
1057 | } | ||
1058 | } | ||
1059 | |||
1060 | /* | 576 | /* |
1061 | * read widget caps for each widget and store in cache | 577 | * read widget caps for each widget and store in cache |
1062 | */ | 578 | */ |
@@ -1065,25 +581,22 @@ static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node) | |||
1065 | int i; | 581 | int i; |
1066 | hda_nid_t nid; | 582 | hda_nid_t nid; |
1067 | 583 | ||
1068 | codec->num_nodes = snd_hda_get_sub_nodes(codec, fg_node, | 584 | codec->wcaps = kmalloc(codec->core.num_nodes * 4, GFP_KERNEL); |
1069 | &codec->start_nid); | ||
1070 | codec->wcaps = kmalloc(codec->num_nodes * 4, GFP_KERNEL); | ||
1071 | if (!codec->wcaps) | 585 | if (!codec->wcaps) |
1072 | return -ENOMEM; | 586 | return -ENOMEM; |
1073 | nid = codec->start_nid; | 587 | nid = codec->core.start_nid; |
1074 | for (i = 0; i < codec->num_nodes; i++, nid++) | 588 | for (i = 0; i < codec->core.num_nodes; i++, nid++) |
1075 | codec->wcaps[i] = snd_hda_param_read(codec, nid, | 589 | codec->wcaps[i] = snd_hdac_read_parm_uncached(&codec->core, |
1076 | AC_PAR_AUDIO_WIDGET_CAP); | 590 | nid, AC_PAR_AUDIO_WIDGET_CAP); |
1077 | return 0; | 591 | return 0; |
1078 | } | 592 | } |
1079 | 593 | ||
1080 | /* read all pin default configurations and save codec->init_pins */ | 594 | /* read all pin default configurations and save codec->init_pins */ |
1081 | static int read_pin_defaults(struct hda_codec *codec) | 595 | static int read_pin_defaults(struct hda_codec *codec) |
1082 | { | 596 | { |
1083 | int i; | 597 | hda_nid_t nid; |
1084 | hda_nid_t nid = codec->start_nid; | ||
1085 | 598 | ||
1086 | for (i = 0; i < codec->num_nodes; i++, nid++) { | 599 | for_each_hda_codec_node(nid, codec) { |
1087 | struct hda_pincfg *pin; | 600 | struct hda_pincfg *pin; |
1088 | unsigned int wcaps = get_wcaps(codec, nid); | 601 | unsigned int wcaps = get_wcaps(codec, nid); |
1089 | unsigned int wid_type = get_wcaps_type(wcaps); | 602 | unsigned int wid_type = get_wcaps_type(wcaps); |
@@ -1290,14 +803,10 @@ static void hda_jackpoll_work(struct work_struct *work) | |||
1290 | if (!codec->jackpoll_interval) | 803 | if (!codec->jackpoll_interval) |
1291 | return; | 804 | return; |
1292 | 805 | ||
1293 | queue_delayed_work(codec->bus->workq, &codec->jackpoll_work, | 806 | schedule_delayed_work(&codec->jackpoll_work, |
1294 | codec->jackpoll_interval); | 807 | codec->jackpoll_interval); |
1295 | } | 808 | } |
1296 | 809 | ||
1297 | static void init_hda_cache(struct hda_cache_rec *cache, | ||
1298 | unsigned int record_size); | ||
1299 | static void free_hda_cache(struct hda_cache_rec *cache); | ||
1300 | |||
1301 | /* release all pincfg lists */ | 810 | /* release all pincfg lists */ |
1302 | static void free_init_pincfgs(struct hda_codec *codec) | 811 | static void free_init_pincfgs(struct hda_codec *codec) |
1303 | { | 812 | { |
@@ -1339,70 +848,117 @@ get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid) | |||
1339 | } | 848 | } |
1340 | 849 | ||
1341 | /* | 850 | /* |
1342 | * Dynamic symbol binding for the codec parsers | 851 | * PCM device |
1343 | */ | 852 | */ |
853 | static void release_pcm(struct kref *kref) | ||
854 | { | ||
855 | struct hda_pcm *pcm = container_of(kref, struct hda_pcm, kref); | ||
856 | |||
857 | if (pcm->pcm) | ||
858 | snd_device_free(pcm->codec->card, pcm->pcm); | ||
859 | clear_bit(pcm->device, pcm->codec->bus->pcm_dev_bits); | ||
860 | kfree(pcm->name); | ||
861 | kfree(pcm); | ||
862 | } | ||
1344 | 863 | ||
1345 | #define load_parser(codec, sym) \ | 864 | void snd_hda_codec_pcm_put(struct hda_pcm *pcm) |
1346 | ((codec)->parser = (int (*)(struct hda_codec *))symbol_request(sym)) | 865 | { |
866 | kref_put(&pcm->kref, release_pcm); | ||
867 | } | ||
868 | EXPORT_SYMBOL_GPL(snd_hda_codec_pcm_put); | ||
1347 | 869 | ||
1348 | static void unload_parser(struct hda_codec *codec) | 870 | struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec, |
871 | const char *fmt, ...) | ||
1349 | { | 872 | { |
1350 | if (codec->parser) | 873 | struct hda_pcm *pcm; |
1351 | symbol_put_addr(codec->parser); | 874 | va_list args; |
1352 | codec->parser = NULL; | 875 | |
876 | va_start(args, fmt); | ||
877 | pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); | ||
878 | if (!pcm) | ||
879 | return NULL; | ||
880 | |||
881 | pcm->codec = codec; | ||
882 | kref_init(&pcm->kref); | ||
883 | pcm->name = kvasprintf(GFP_KERNEL, fmt, args); | ||
884 | if (!pcm->name) { | ||
885 | kfree(pcm); | ||
886 | return NULL; | ||
887 | } | ||
888 | |||
889 | list_add_tail(&pcm->list, &codec->pcm_list_head); | ||
890 | return pcm; | ||
1353 | } | 891 | } |
892 | EXPORT_SYMBOL_GPL(snd_hda_codec_pcm_new); | ||
1354 | 893 | ||
1355 | /* | 894 | /* |
1356 | * codec destructor | 895 | * codec destructor |
1357 | */ | 896 | */ |
1358 | static void snd_hda_codec_free(struct hda_codec *codec) | 897 | static void codec_release_pcms(struct hda_codec *codec) |
1359 | { | 898 | { |
1360 | if (!codec) | 899 | struct hda_pcm *pcm, *n; |
1361 | return; | 900 | |
901 | list_for_each_entry_safe(pcm, n, &codec->pcm_list_head, list) { | ||
902 | list_del_init(&pcm->list); | ||
903 | if (pcm->pcm) | ||
904 | snd_device_disconnect(codec->card, pcm->pcm); | ||
905 | snd_hda_codec_pcm_put(pcm); | ||
906 | } | ||
907 | } | ||
908 | |||
909 | void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) | ||
910 | { | ||
911 | if (codec->registered) { | ||
912 | /* pm_runtime_put() is called in snd_hdac_device_exit() */ | ||
913 | pm_runtime_get_noresume(hda_codec_dev(codec)); | ||
914 | pm_runtime_disable(hda_codec_dev(codec)); | ||
915 | codec->registered = 0; | ||
916 | } | ||
917 | |||
1362 | cancel_delayed_work_sync(&codec->jackpoll_work); | 918 | cancel_delayed_work_sync(&codec->jackpoll_work); |
919 | if (!codec->in_freeing) | ||
920 | snd_hda_ctls_clear(codec); | ||
921 | codec_release_pcms(codec); | ||
922 | snd_hda_detach_beep_device(codec); | ||
923 | memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); | ||
1363 | snd_hda_jack_tbl_clear(codec); | 924 | snd_hda_jack_tbl_clear(codec); |
1364 | free_init_pincfgs(codec); | 925 | codec->proc_widget_hook = NULL; |
1365 | #ifdef CONFIG_PM | 926 | codec->spec = NULL; |
1366 | cancel_delayed_work(&codec->power_work); | 927 | |
1367 | flush_workqueue(codec->bus->workq); | 928 | /* free only driver_pins so that init_pins + user_pins are restored */ |
1368 | #endif | 929 | snd_array_free(&codec->driver_pins); |
1369 | list_del(&codec->list); | ||
1370 | snd_array_free(&codec->mixers); | ||
1371 | snd_array_free(&codec->nids); | ||
1372 | snd_array_free(&codec->cvt_setups); | 930 | snd_array_free(&codec->cvt_setups); |
1373 | snd_array_free(&codec->spdif_out); | 931 | snd_array_free(&codec->spdif_out); |
932 | snd_array_free(&codec->verbs); | ||
933 | codec->preset = NULL; | ||
934 | codec->slave_dig_outs = NULL; | ||
935 | codec->spdif_status_reset = 0; | ||
936 | snd_array_free(&codec->mixers); | ||
937 | snd_array_free(&codec->nids); | ||
1374 | remove_conn_list(codec); | 938 | remove_conn_list(codec); |
1375 | codec->bus->caddr_tbl[codec->addr] = NULL; | 939 | snd_hdac_regmap_exit(&codec->core); |
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 | } | 940 | } |
1391 | 941 | ||
1392 | static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, | ||
1393 | hda_nid_t fg, unsigned int power_state); | ||
1394 | |||
1395 | static unsigned int hda_set_power_state(struct hda_codec *codec, | 942 | static unsigned int hda_set_power_state(struct hda_codec *codec, |
1396 | unsigned int power_state); | 943 | unsigned int power_state); |
1397 | 944 | ||
1398 | static int snd_hda_codec_dev_register(struct snd_device *device) | 945 | /* also called from hda_bind.c */ |
946 | void snd_hda_codec_register(struct hda_codec *codec) | ||
1399 | { | 947 | { |
1400 | struct hda_codec *codec = device->device_data; | 948 | if (codec->registered) |
1401 | int err = device_add(&codec->dev); | 949 | return; |
950 | if (device_is_registered(hda_codec_dev(codec))) { | ||
951 | snd_hda_register_beep_device(codec); | ||
952 | pm_runtime_enable(hda_codec_dev(codec)); | ||
953 | /* it was powered up in snd_hda_codec_new(), now all done */ | ||
954 | snd_hda_power_down(codec); | ||
955 | codec->registered = 1; | ||
956 | } | ||
957 | } | ||
1402 | 958 | ||
1403 | if (err < 0) | 959 | static int snd_hda_codec_dev_register(struct snd_device *device) |
1404 | return err; | 960 | { |
1405 | snd_hda_register_beep_device(codec); | 961 | snd_hda_codec_register(device->device_data); |
1406 | return 0; | 962 | return 0; |
1407 | } | 963 | } |
1408 | 964 | ||
@@ -1411,20 +967,29 @@ static int snd_hda_codec_dev_disconnect(struct snd_device *device) | |||
1411 | struct hda_codec *codec = device->device_data; | 967 | struct hda_codec *codec = device->device_data; |
1412 | 968 | ||
1413 | snd_hda_detach_beep_device(codec); | 969 | snd_hda_detach_beep_device(codec); |
1414 | device_del(&codec->dev); | ||
1415 | return 0; | 970 | return 0; |
1416 | } | 971 | } |
1417 | 972 | ||
1418 | static int snd_hda_codec_dev_free(struct snd_device *device) | 973 | static int snd_hda_codec_dev_free(struct snd_device *device) |
1419 | { | 974 | { |
1420 | snd_hda_codec_free(device->device_data); | 975 | struct hda_codec *codec = device->device_data; |
976 | |||
977 | codec->in_freeing = 1; | ||
978 | snd_hdac_device_unregister(&codec->core); | ||
979 | put_device(hda_codec_dev(codec)); | ||
1421 | return 0; | 980 | return 0; |
1422 | } | 981 | } |
1423 | 982 | ||
1424 | /* just free the container */ | ||
1425 | static void snd_hda_codec_dev_release(struct device *dev) | 983 | static void snd_hda_codec_dev_release(struct device *dev) |
1426 | { | 984 | { |
1427 | kfree(container_of(dev, struct hda_codec, dev)); | 985 | struct hda_codec *codec = dev_to_hda_codec(dev); |
986 | |||
987 | free_init_pincfgs(codec); | ||
988 | snd_hdac_device_exit(&codec->core); | ||
989 | snd_hda_sysfs_clear(codec); | ||
990 | kfree(codec->modelname); | ||
991 | kfree(codec->wcaps); | ||
992 | kfree(codec); | ||
1428 | } | 993 | } |
1429 | 994 | ||
1430 | /** | 995 | /** |
@@ -1435,9 +1000,8 @@ static void snd_hda_codec_dev_release(struct device *dev) | |||
1435 | * | 1000 | * |
1436 | * Returns 0 if successful, or a negative error code. | 1001 | * Returns 0 if successful, or a negative error code. |
1437 | */ | 1002 | */ |
1438 | int snd_hda_codec_new(struct hda_bus *bus, | 1003 | int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, |
1439 | unsigned int codec_addr, | 1004 | unsigned int codec_addr, struct hda_codec **codecp) |
1440 | struct hda_codec **codecp) | ||
1441 | { | 1005 | { |
1442 | struct hda_codec *codec; | 1006 | struct hda_codec *codec; |
1443 | char component[31]; | 1007 | char component[31]; |
@@ -1454,35 +1018,27 @@ int snd_hda_codec_new(struct hda_bus *bus, | |||
1454 | if (snd_BUG_ON(codec_addr > HDA_MAX_CODEC_ADDRESS)) | 1018 | if (snd_BUG_ON(codec_addr > HDA_MAX_CODEC_ADDRESS)) |
1455 | return -EINVAL; | 1019 | return -EINVAL; |
1456 | 1020 | ||
1457 | if (bus->caddr_tbl[codec_addr]) { | ||
1458 | dev_err(bus->card->dev, | ||
1459 | "address 0x%x is already occupied\n", | ||
1460 | codec_addr); | ||
1461 | return -EBUSY; | ||
1462 | } | ||
1463 | |||
1464 | codec = kzalloc(sizeof(*codec), GFP_KERNEL); | 1021 | codec = kzalloc(sizeof(*codec), GFP_KERNEL); |
1465 | if (codec == NULL) { | 1022 | if (!codec) |
1466 | dev_err(bus->card->dev, "can't allocate struct hda_codec\n"); | ||
1467 | return -ENOMEM; | 1023 | return -ENOMEM; |
1024 | |||
1025 | sprintf(component, "hdaudioC%dD%d", card->number, codec_addr); | ||
1026 | err = snd_hdac_device_init(&codec->core, &bus->core, component, | ||
1027 | codec_addr); | ||
1028 | if (err < 0) { | ||
1029 | kfree(codec); | ||
1030 | return err; | ||
1468 | } | 1031 | } |
1469 | 1032 | ||
1470 | device_initialize(&codec->dev); | 1033 | codec->core.dev.release = snd_hda_codec_dev_release; |
1471 | codec->dev.parent = &bus->card->card_dev; | 1034 | codec->core.type = HDA_DEV_LEGACY; |
1472 | codec->dev.class = sound_class; | 1035 | codec->core.exec_verb = codec_exec_verb; |
1473 | codec->dev.release = snd_hda_codec_dev_release; | ||
1474 | codec->dev.groups = snd_hda_dev_attr_groups; | ||
1475 | dev_set_name(&codec->dev, "hdaudioC%dD%d", bus->card->number, | ||
1476 | codec_addr); | ||
1477 | dev_set_drvdata(&codec->dev, codec); /* for sysfs */ | ||
1478 | 1036 | ||
1479 | codec->bus = bus; | 1037 | codec->bus = bus; |
1038 | codec->card = card; | ||
1480 | codec->addr = codec_addr; | 1039 | codec->addr = codec_addr; |
1481 | mutex_init(&codec->spdif_mutex); | 1040 | mutex_init(&codec->spdif_mutex); |
1482 | mutex_init(&codec->control_mutex); | 1041 | mutex_init(&codec->control_mutex); |
1483 | mutex_init(&codec->hash_mutex); | ||
1484 | init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); | ||
1485 | init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); | ||
1486 | snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); | 1042 | snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); |
1487 | snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32); | 1043 | snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32); |
1488 | snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); | 1044 | snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); |
@@ -1492,19 +1048,14 @@ int snd_hda_codec_new(struct hda_bus *bus, | |||
1492 | snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16); | 1048 | snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16); |
1493 | snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8); | 1049 | snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8); |
1494 | INIT_LIST_HEAD(&codec->conn_list); | 1050 | INIT_LIST_HEAD(&codec->conn_list); |
1051 | INIT_LIST_HEAD(&codec->pcm_list_head); | ||
1495 | 1052 | ||
1496 | INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work); | 1053 | INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work); |
1497 | codec->depop_delay = -1; | 1054 | codec->depop_delay = -1; |
1498 | codec->fixup_id = HDA_FIXUP_ID_NOT_SET; | 1055 | codec->fixup_id = HDA_FIXUP_ID_NOT_SET; |
1499 | 1056 | ||
1500 | #ifdef CONFIG_PM | 1057 | #ifdef CONFIG_PM |
1501 | spin_lock_init(&codec->power_lock); | 1058 | codec->power_jiffies = jiffies; |
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. | ||
1504 | * the caller has to power down appropriatley after initialization | ||
1505 | * phase. | ||
1506 | */ | ||
1507 | hda_keep_power_on(codec); | ||
1508 | #endif | 1059 | #endif |
1509 | 1060 | ||
1510 | snd_hda_sysfs_init(codec); | 1061 | snd_hda_sysfs_init(codec); |
@@ -1517,59 +1068,14 @@ int snd_hda_codec_new(struct hda_bus *bus, | |||
1517 | } | 1068 | } |
1518 | } | 1069 | } |
1519 | 1070 | ||
1520 | list_add_tail(&codec->list, &bus->codec_list); | 1071 | fg = codec->core.afg ? codec->core.afg : codec->core.mfg; |
1521 | bus->num_codecs++; | ||
1522 | |||
1523 | bus->caddr_tbl[codec_addr] = codec; | ||
1524 | |||
1525 | codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT, | ||
1526 | AC_PAR_VENDOR_ID); | ||
1527 | if (codec->vendor_id == -1) | ||
1528 | /* read again, hopefully the access method was corrected | ||
1529 | * in the last read... | ||
1530 | */ | ||
1531 | codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT, | ||
1532 | AC_PAR_VENDOR_ID); | ||
1533 | codec->subsystem_id = snd_hda_param_read(codec, AC_NODE_ROOT, | ||
1534 | AC_PAR_SUBSYSTEM_ID); | ||
1535 | codec->revision_id = snd_hda_param_read(codec, AC_NODE_ROOT, | ||
1536 | AC_PAR_REV_ID); | ||
1537 | |||
1538 | setup_fg_nodes(codec); | ||
1539 | if (!codec->afg && !codec->mfg) { | ||
1540 | dev_err(bus->card->dev, "no AFG or MFG node found\n"); | ||
1541 | err = -ENODEV; | ||
1542 | goto error; | ||
1543 | } | ||
1544 | |||
1545 | fg = codec->afg ? codec->afg : codec->mfg; | ||
1546 | err = read_widget_caps(codec, fg); | 1072 | err = read_widget_caps(codec, fg); |
1547 | if (err < 0) { | 1073 | if (err < 0) |
1548 | dev_err(bus->card->dev, "cannot malloc\n"); | ||
1549 | goto error; | 1074 | goto error; |
1550 | } | ||
1551 | err = read_pin_defaults(codec); | 1075 | err = read_pin_defaults(codec); |
1552 | if (err < 0) | 1076 | if (err < 0) |
1553 | goto error; | 1077 | goto error; |
1554 | 1078 | ||
1555 | if (!codec->subsystem_id) { | ||
1556 | codec->subsystem_id = | ||
1557 | snd_hda_codec_read(codec, fg, 0, | ||
1558 | AC_VERB_GET_SUBSYSTEM_ID, 0); | ||
1559 | } | ||
1560 | |||
1561 | #ifdef CONFIG_PM | ||
1562 | codec->d3_stop_clk = snd_hda_codec_get_supported_ps(codec, fg, | ||
1563 | AC_PWRST_CLKSTOP); | ||
1564 | #endif | ||
1565 | codec->epss = snd_hda_codec_get_supported_ps(codec, fg, | ||
1566 | 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 | |||
1573 | /* power-up all before initialization */ | 1079 | /* power-up all before initialization */ |
1574 | hda_set_power_state(codec, AC_PWRST_D0); | 1080 | hda_set_power_state(codec, AC_PWRST_D0); |
1575 | 1081 | ||
@@ -1577,11 +1083,11 @@ int snd_hda_codec_new(struct hda_bus *bus, | |||
1577 | 1083 | ||
1578 | snd_hda_create_hwdep(codec); | 1084 | snd_hda_create_hwdep(codec); |
1579 | 1085 | ||
1580 | sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id, | 1086 | sprintf(component, "HDA:%08x,%08x,%08x", codec->core.vendor_id, |
1581 | codec->subsystem_id, codec->revision_id); | 1087 | codec->core.subsystem_id, codec->core.revision_id); |
1582 | snd_component_add(codec->bus->card, component); | 1088 | snd_component_add(card, component); |
1583 | 1089 | ||
1584 | err = snd_device_new(bus->card, SNDRV_DEV_CODEC, codec, &dev_ops); | 1090 | err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops); |
1585 | if (err < 0) | 1091 | if (err < 0) |
1586 | goto error; | 1092 | goto error; |
1587 | 1093 | ||
@@ -1590,7 +1096,7 @@ int snd_hda_codec_new(struct hda_bus *bus, | |||
1590 | return 0; | 1096 | return 0; |
1591 | 1097 | ||
1592 | error: | 1098 | error: |
1593 | snd_hda_codec_free(codec); | 1099 | put_device(hda_codec_dev(codec)); |
1594 | return err; | 1100 | return err; |
1595 | } | 1101 | } |
1596 | EXPORT_SYMBOL_GPL(snd_hda_codec_new); | 1102 | EXPORT_SYMBOL_GPL(snd_hda_codec_new); |
@@ -1607,16 +1113,18 @@ int snd_hda_codec_update_widgets(struct hda_codec *codec) | |||
1607 | hda_nid_t fg; | 1113 | hda_nid_t fg; |
1608 | int err; | 1114 | int err; |
1609 | 1115 | ||
1116 | err = snd_hdac_refresh_widgets(&codec->core); | ||
1117 | if (err < 0) | ||
1118 | return err; | ||
1119 | |||
1610 | /* Assume the function group node does not change, | 1120 | /* Assume the function group node does not change, |
1611 | * only the widget nodes may change. | 1121 | * only the widget nodes may change. |
1612 | */ | 1122 | */ |
1613 | kfree(codec->wcaps); | 1123 | kfree(codec->wcaps); |
1614 | fg = codec->afg ? codec->afg : codec->mfg; | 1124 | fg = codec->core.afg ? codec->core.afg : codec->core.mfg; |
1615 | err = read_widget_caps(codec, fg); | 1125 | err = read_widget_caps(codec, fg); |
1616 | if (err < 0) { | 1126 | if (err < 0) |
1617 | codec_err(codec, "cannot malloc\n"); | ||
1618 | return err; | 1127 | return err; |
1619 | } | ||
1620 | 1128 | ||
1621 | snd_array_free(&codec->init_pins); | 1129 | snd_array_free(&codec->init_pins); |
1622 | err = read_pin_defaults(codec); | 1130 | err = read_pin_defaults(codec); |
@@ -1625,98 +1133,6 @@ int snd_hda_codec_update_widgets(struct hda_codec *codec) | |||
1625 | } | 1133 | } |
1626 | EXPORT_SYMBOL_GPL(snd_hda_codec_update_widgets); | 1134 | EXPORT_SYMBOL_GPL(snd_hda_codec_update_widgets); |
1627 | 1135 | ||
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 */ | ||
1631 | static 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 | */ | ||
1663 | int 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 | } | ||
1718 | EXPORT_SYMBOL_GPL(snd_hda_codec_configure); | ||
1719 | |||
1720 | /* update the stream-id if changed */ | 1136 | /* update the stream-id if changed */ |
1721 | static void update_pcm_stream_id(struct hda_codec *codec, | 1137 | static void update_pcm_stream_id(struct hda_codec *codec, |
1722 | struct hda_cvt_setup *p, hda_nid_t nid, | 1138 | struct hda_cvt_setup *p, hda_nid_t nid, |
@@ -1782,6 +1198,8 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, | |||
1782 | if (!p) | 1198 | if (!p) |
1783 | return; | 1199 | return; |
1784 | 1200 | ||
1201 | if (codec->patch_ops.stream_pm) | ||
1202 | codec->patch_ops.stream_pm(codec, nid, true); | ||
1785 | if (codec->pcm_format_first) | 1203 | if (codec->pcm_format_first) |
1786 | update_pcm_format(codec, p, nid, format); | 1204 | update_pcm_format(codec, p, nid, format); |
1787 | update_pcm_stream_id(codec, p, nid, stream_tag, channel_id); | 1205 | update_pcm_stream_id(codec, p, nid, stream_tag, channel_id); |
@@ -1793,7 +1211,7 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, | |||
1793 | 1211 | ||
1794 | /* make other inactive cvts with the same stream-tag dirty */ | 1212 | /* make other inactive cvts with the same stream-tag dirty */ |
1795 | type = get_wcaps_type(get_wcaps(codec, nid)); | 1213 | type = get_wcaps_type(get_wcaps(codec, nid)); |
1796 | list_for_each_entry(c, &codec->bus->codec_list, list) { | 1214 | list_for_each_codec(c, codec->bus) { |
1797 | for (i = 0; i < c->cvt_setups.used; i++) { | 1215 | for (i = 0; i < c->cvt_setups.used; i++) { |
1798 | p = snd_array_elem(&c->cvt_setups, i); | 1216 | p = snd_array_elem(&c->cvt_setups, i); |
1799 | if (!p->active && p->stream_tag == stream_tag && | 1217 | if (!p->active && p->stream_tag == stream_tag && |
@@ -1850,6 +1268,8 @@ static void really_cleanup_stream(struct hda_codec *codec, | |||
1850 | ); | 1268 | ); |
1851 | memset(q, 0, sizeof(*q)); | 1269 | memset(q, 0, sizeof(*q)); |
1852 | q->nid = nid; | 1270 | q->nid = nid; |
1271 | if (codec->patch_ops.stream_pm) | ||
1272 | codec->patch_ops.stream_pm(codec, nid, false); | ||
1853 | } | 1273 | } |
1854 | 1274 | ||
1855 | /* clean up the all conflicting obsolete streams */ | 1275 | /* clean up the all conflicting obsolete streams */ |
@@ -1858,7 +1278,7 @@ static void purify_inactive_streams(struct hda_codec *codec) | |||
1858 | struct hda_codec *c; | 1278 | struct hda_codec *c; |
1859 | int i; | 1279 | int i; |
1860 | 1280 | ||
1861 | list_for_each_entry(c, &codec->bus->codec_list, list) { | 1281 | list_for_each_codec(c, codec->bus) { |
1862 | for (i = 0; i < c->cvt_setups.used; i++) { | 1282 | for (i = 0; i < c->cvt_setups.used; i++) { |
1863 | struct hda_cvt_setup *p; | 1283 | struct hda_cvt_setup *p; |
1864 | p = snd_array_elem(&c->cvt_setups, i); | 1284 | p = snd_array_elem(&c->cvt_setups, i); |
@@ -1886,127 +1306,6 @@ static void hda_cleanup_all_streams(struct hda_codec *codec) | |||
1886 | * amp access functions | 1306 | * amp access functions |
1887 | */ | 1307 | */ |
1888 | 1308 | ||
1889 | /* FIXME: more better hash key? */ | ||
1890 | #define HDA_HASH_KEY(nid, dir, idx) (u32)((nid) + ((idx) << 16) + ((dir) << 24)) | ||
1891 | #define HDA_HASH_PINCAP_KEY(nid) (u32)((nid) + (0x02 << 24)) | ||
1892 | #define HDA_HASH_PARPCM_KEY(nid) (u32)((nid) + (0x03 << 24)) | ||
1893 | #define HDA_HASH_PARSTR_KEY(nid) (u32)((nid) + (0x04 << 24)) | ||
1894 | #define INFO_AMP_CAPS (1<<0) | ||
1895 | #define INFO_AMP_VOL(ch) (1 << (1 + (ch))) | ||
1896 | |||
1897 | /* initialize the hash table */ | ||
1898 | static void init_hda_cache(struct hda_cache_rec *cache, | ||
1899 | unsigned int record_size) | ||
1900 | { | ||
1901 | memset(cache, 0, sizeof(*cache)); | ||
1902 | memset(cache->hash, 0xff, sizeof(cache->hash)); | ||
1903 | snd_array_init(&cache->buf, record_size, 64); | ||
1904 | } | ||
1905 | |||
1906 | static void free_hda_cache(struct hda_cache_rec *cache) | ||
1907 | { | ||
1908 | snd_array_free(&cache->buf); | ||
1909 | } | ||
1910 | |||
1911 | /* query the hash. allocate an entry if not found. */ | ||
1912 | static struct hda_cache_head *get_hash(struct hda_cache_rec *cache, u32 key) | ||
1913 | { | ||
1914 | u16 idx = key % (u16)ARRAY_SIZE(cache->hash); | ||
1915 | u16 cur = cache->hash[idx]; | ||
1916 | struct hda_cache_head *info; | ||
1917 | |||
1918 | while (cur != 0xffff) { | ||
1919 | info = snd_array_elem(&cache->buf, cur); | ||
1920 | if (info->key == key) | ||
1921 | return info; | ||
1922 | cur = info->next; | ||
1923 | } | ||
1924 | return NULL; | ||
1925 | } | ||
1926 | |||
1927 | /* query the hash. allocate an entry if not found. */ | ||
1928 | static struct hda_cache_head *get_alloc_hash(struct hda_cache_rec *cache, | ||
1929 | u32 key) | ||
1930 | { | ||
1931 | struct hda_cache_head *info = get_hash(cache, key); | ||
1932 | if (!info) { | ||
1933 | u16 idx, cur; | ||
1934 | /* add a new hash entry */ | ||
1935 | info = snd_array_new(&cache->buf); | ||
1936 | if (!info) | ||
1937 | return NULL; | ||
1938 | cur = snd_array_index(&cache->buf, info); | ||
1939 | info->key = key; | ||
1940 | info->val = 0; | ||
1941 | info->dirty = 0; | ||
1942 | idx = key % (u16)ARRAY_SIZE(cache->hash); | ||
1943 | info->next = cache->hash[idx]; | ||
1944 | cache->hash[idx] = cur; | ||
1945 | } | ||
1946 | return info; | ||
1947 | } | ||
1948 | |||
1949 | /* query and allocate an amp hash entry */ | ||
1950 | static inline struct hda_amp_info * | ||
1951 | get_alloc_amp_hash(struct hda_codec *codec, u32 key) | ||
1952 | { | ||
1953 | return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key); | ||
1954 | } | ||
1955 | |||
1956 | /* overwrite the value with the key in the caps hash */ | ||
1957 | static int write_caps_hash(struct hda_codec *codec, u32 key, unsigned int val) | ||
1958 | { | ||
1959 | struct hda_amp_info *info; | ||
1960 | |||
1961 | mutex_lock(&codec->hash_mutex); | ||
1962 | info = get_alloc_amp_hash(codec, key); | ||
1963 | if (!info) { | ||
1964 | mutex_unlock(&codec->hash_mutex); | ||
1965 | return -EINVAL; | ||
1966 | } | ||
1967 | info->amp_caps = val; | ||
1968 | info->head.val |= INFO_AMP_CAPS; | ||
1969 | mutex_unlock(&codec->hash_mutex); | ||
1970 | return 0; | ||
1971 | } | ||
1972 | |||
1973 | /* query the value from the caps hash; if not found, fetch the current | ||
1974 | * value from the given function and store in the hash | ||
1975 | */ | ||
1976 | static unsigned int | ||
1977 | query_caps_hash(struct hda_codec *codec, hda_nid_t nid, int dir, u32 key, | ||
1978 | unsigned int (*func)(struct hda_codec *, hda_nid_t, int)) | ||
1979 | { | ||
1980 | struct hda_amp_info *info; | ||
1981 | unsigned int val; | ||
1982 | |||
1983 | mutex_lock(&codec->hash_mutex); | ||
1984 | info = get_alloc_amp_hash(codec, key); | ||
1985 | if (!info) { | ||
1986 | mutex_unlock(&codec->hash_mutex); | ||
1987 | return 0; | ||
1988 | } | ||
1989 | if (!(info->head.val & INFO_AMP_CAPS)) { | ||
1990 | mutex_unlock(&codec->hash_mutex); /* for reentrance */ | ||
1991 | val = func(codec, nid, dir); | ||
1992 | write_caps_hash(codec, key, val); | ||
1993 | } else { | ||
1994 | val = info->amp_caps; | ||
1995 | mutex_unlock(&codec->hash_mutex); | ||
1996 | } | ||
1997 | return val; | ||
1998 | } | ||
1999 | |||
2000 | static unsigned int read_amp_cap(struct hda_codec *codec, hda_nid_t nid, | ||
2001 | int direction) | ||
2002 | { | ||
2003 | if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) | ||
2004 | nid = codec->afg; | ||
2005 | return snd_hda_param_read(codec, nid, | ||
2006 | direction == HDA_OUTPUT ? | ||
2007 | AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP); | ||
2008 | } | ||
2009 | |||
2010 | /** | 1309 | /** |
2011 | * query_amp_caps - query AMP capabilities | 1310 | * query_amp_caps - query AMP capabilities |
2012 | * @codec: the HD-auio codec | 1311 | * @codec: the HD-auio codec |
@@ -2021,9 +1320,11 @@ static unsigned int read_amp_cap(struct hda_codec *codec, hda_nid_t nid, | |||
2021 | */ | 1320 | */ |
2022 | u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) | 1321 | u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) |
2023 | { | 1322 | { |
2024 | return query_caps_hash(codec, nid, direction, | 1323 | if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) |
2025 | HDA_HASH_KEY(nid, direction, 0), | 1324 | nid = codec->core.afg; |
2026 | read_amp_cap); | 1325 | return snd_hda_param_read(codec, nid, |
1326 | direction == HDA_OUTPUT ? | ||
1327 | AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP); | ||
2027 | } | 1328 | } |
2028 | EXPORT_SYMBOL_GPL(query_amp_caps); | 1329 | EXPORT_SYMBOL_GPL(query_amp_caps); |
2029 | 1330 | ||
@@ -2064,183 +1365,14 @@ EXPORT_SYMBOL_GPL(snd_hda_check_amp_caps); | |||
2064 | int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, | 1365 | int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, |
2065 | unsigned int caps) | 1366 | unsigned int caps) |
2066 | { | 1367 | { |
2067 | return write_caps_hash(codec, HDA_HASH_KEY(nid, dir, 0), caps); | 1368 | unsigned int parm; |
2068 | } | ||
2069 | EXPORT_SYMBOL_GPL(snd_hda_override_amp_caps); | ||
2070 | |||
2071 | static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid, | ||
2072 | int dir) | ||
2073 | { | ||
2074 | return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); | ||
2075 | } | ||
2076 | |||
2077 | /** | ||
2078 | * snd_hda_query_pin_caps - Query PIN capabilities | ||
2079 | * @codec: the HD-auio codec | ||
2080 | * @nid: the NID to query | ||
2081 | * | ||
2082 | * Query PIN capabilities for the given widget. | ||
2083 | * Returns the obtained capability bits. | ||
2084 | * | ||
2085 | * When cap bits have been already read, this doesn't read again but | ||
2086 | * returns the cached value. | ||
2087 | */ | ||
2088 | u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid) | ||
2089 | { | ||
2090 | return query_caps_hash(codec, nid, 0, HDA_HASH_PINCAP_KEY(nid), | ||
2091 | read_pin_cap); | ||
2092 | } | ||
2093 | EXPORT_SYMBOL_GPL(snd_hda_query_pin_caps); | ||
2094 | |||
2095 | /** | ||
2096 | * snd_hda_override_pin_caps - Override the pin capabilities | ||
2097 | * @codec: the CODEC | ||
2098 | * @nid: the NID to override | ||
2099 | * @caps: the capability bits to set | ||
2100 | * | ||
2101 | * Override the cached PIN capabilitiy bits value by the given one. | ||
2102 | * | ||
2103 | * Returns zero if successful or a negative error code. | ||
2104 | */ | ||
2105 | int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid, | ||
2106 | unsigned int caps) | ||
2107 | { | ||
2108 | return write_caps_hash(codec, HDA_HASH_PINCAP_KEY(nid), caps); | ||
2109 | } | ||
2110 | EXPORT_SYMBOL_GPL(snd_hda_override_pin_caps); | ||
2111 | |||
2112 | /* read or sync the hash value with the current value; | ||
2113 | * call within hash_mutex | ||
2114 | */ | ||
2115 | static struct hda_amp_info * | ||
2116 | update_amp_hash(struct hda_codec *codec, hda_nid_t nid, int ch, | ||
2117 | int direction, int index, bool init_only) | ||
2118 | { | ||
2119 | struct hda_amp_info *info; | ||
2120 | unsigned int parm, val = 0; | ||
2121 | bool val_read = false; | ||
2122 | |||
2123 | retry: | ||
2124 | info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index)); | ||
2125 | if (!info) | ||
2126 | return NULL; | ||
2127 | if (!(info->head.val & INFO_AMP_VOL(ch))) { | ||
2128 | if (!val_read) { | ||
2129 | mutex_unlock(&codec->hash_mutex); | ||
2130 | parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT; | ||
2131 | parm |= direction == HDA_OUTPUT ? | ||
2132 | AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT; | ||
2133 | parm |= index; | ||
2134 | val = snd_hda_codec_read(codec, nid, 0, | ||
2135 | AC_VERB_GET_AMP_GAIN_MUTE, parm); | ||
2136 | val &= 0xff; | ||
2137 | val_read = true; | ||
2138 | mutex_lock(&codec->hash_mutex); | ||
2139 | goto retry; | ||
2140 | } | ||
2141 | info->vol[ch] = val; | ||
2142 | info->head.val |= INFO_AMP_VOL(ch); | ||
2143 | } else if (init_only) | ||
2144 | return NULL; | ||
2145 | return info; | ||
2146 | } | ||
2147 | |||
2148 | /* | ||
2149 | * write the current volume in info to the h/w | ||
2150 | */ | ||
2151 | static void put_vol_mute(struct hda_codec *codec, unsigned int amp_caps, | ||
2152 | hda_nid_t nid, int ch, int direction, int index, | ||
2153 | int val) | ||
2154 | { | ||
2155 | u32 parm; | ||
2156 | |||
2157 | parm = ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT; | ||
2158 | parm |= direction == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT; | ||
2159 | parm |= index << AC_AMP_SET_INDEX_SHIFT; | ||
2160 | if ((val & HDA_AMP_MUTE) && !(amp_caps & AC_AMPCAP_MUTE) && | ||
2161 | (amp_caps & AC_AMPCAP_MIN_MUTE)) | ||
2162 | ; /* set the zero value as a fake mute */ | ||
2163 | else | ||
2164 | parm |= val; | ||
2165 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, parm); | ||
2166 | } | ||
2167 | |||
2168 | /** | ||
2169 | * snd_hda_codec_amp_read - Read AMP value | ||
2170 | * @codec: HD-audio codec | ||
2171 | * @nid: NID to read the AMP value | ||
2172 | * @ch: channel (left=0 or right=1) | ||
2173 | * @direction: #HDA_INPUT or #HDA_OUTPUT | ||
2174 | * @index: the index value (only for input direction) | ||
2175 | * | ||
2176 | * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit. | ||
2177 | */ | ||
2178 | int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, | ||
2179 | int direction, int index) | ||
2180 | { | ||
2181 | struct hda_amp_info *info; | ||
2182 | unsigned int val = 0; | ||
2183 | |||
2184 | mutex_lock(&codec->hash_mutex); | ||
2185 | info = update_amp_hash(codec, nid, ch, direction, index, false); | ||
2186 | if (info) | ||
2187 | val = info->vol[ch]; | ||
2188 | mutex_unlock(&codec->hash_mutex); | ||
2189 | return val; | ||
2190 | } | ||
2191 | EXPORT_SYMBOL_GPL(snd_hda_codec_amp_read); | ||
2192 | |||
2193 | static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, | ||
2194 | int direction, int idx, int mask, int val, | ||
2195 | bool init_only) | ||
2196 | { | ||
2197 | struct hda_amp_info *info; | ||
2198 | unsigned int caps; | ||
2199 | unsigned int cache_only; | ||
2200 | |||
2201 | if (snd_BUG_ON(mask & ~0xff)) | ||
2202 | mask &= 0xff; | ||
2203 | val &= mask; | ||
2204 | |||
2205 | mutex_lock(&codec->hash_mutex); | ||
2206 | info = update_amp_hash(codec, nid, ch, direction, idx, init_only); | ||
2207 | if (!info) { | ||
2208 | mutex_unlock(&codec->hash_mutex); | ||
2209 | return 0; | ||
2210 | } | ||
2211 | val |= info->vol[ch] & ~mask; | ||
2212 | if (info->vol[ch] == val) { | ||
2213 | mutex_unlock(&codec->hash_mutex); | ||
2214 | return 0; | ||
2215 | } | ||
2216 | info->vol[ch] = val; | ||
2217 | cache_only = info->head.dirty = codec->cached_write; | ||
2218 | caps = info->amp_caps; | ||
2219 | mutex_unlock(&codec->hash_mutex); | ||
2220 | if (!cache_only) | ||
2221 | put_vol_mute(codec, caps, nid, ch, direction, idx, val); | ||
2222 | return 1; | ||
2223 | } | ||
2224 | 1369 | ||
2225 | /** | 1370 | snd_hda_override_wcaps(codec, nid, |
2226 | * snd_hda_codec_amp_update - update the AMP value | 1371 | get_wcaps(codec, nid) | AC_WCAP_AMP_OVRD); |
2227 | * @codec: HD-audio codec | 1372 | parm = dir == HDA_OUTPUT ? AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP; |
2228 | * @nid: NID to read the AMP value | 1373 | return snd_hdac_override_parm(&codec->core, nid, parm, caps); |
2229 | * @ch: channel (left=0 or right=1) | ||
2230 | * @direction: #HDA_INPUT or #HDA_OUTPUT | ||
2231 | * @idx: the index value (only for input direction) | ||
2232 | * @mask: bit mask to set | ||
2233 | * @val: the bits value to set | ||
2234 | * | ||
2235 | * Update the AMP value with a bit mask. | ||
2236 | * Returns 0 if the value is unchanged, 1 if changed. | ||
2237 | */ | ||
2238 | int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, | ||
2239 | int direction, int idx, int mask, int val) | ||
2240 | { | ||
2241 | return codec_amp_update(codec, nid, ch, direction, idx, mask, val, false); | ||
2242 | } | 1374 | } |
2243 | EXPORT_SYMBOL_GPL(snd_hda_codec_amp_update); | 1375 | EXPORT_SYMBOL_GPL(snd_hda_override_amp_caps); |
2244 | 1376 | ||
2245 | /** | 1377 | /** |
2246 | * snd_hda_codec_amp_stereo - update the AMP stereo values | 1378 | * snd_hda_codec_amp_stereo - update the AMP stereo values |
@@ -2285,7 +1417,16 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_amp_stereo); | |||
2285 | int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, | 1417 | int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, |
2286 | int dir, int idx, int mask, int val) | 1418 | int dir, int idx, int mask, int val) |
2287 | { | 1419 | { |
2288 | return codec_amp_update(codec, nid, ch, dir, idx, mask, val, true); | 1420 | int orig; |
1421 | |||
1422 | if (!codec->core.regmap) | ||
1423 | return -EINVAL; | ||
1424 | regcache_cache_only(codec->core.regmap, true); | ||
1425 | orig = snd_hda_codec_amp_read(codec, nid, ch, dir, idx); | ||
1426 | regcache_cache_only(codec->core.regmap, false); | ||
1427 | if (orig >= 0) | ||
1428 | return 0; | ||
1429 | return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, mask, val); | ||
2289 | } | 1430 | } |
2290 | EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init); | 1431 | EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init); |
2291 | 1432 | ||
@@ -2314,49 +1455,6 @@ int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid, | |||
2314 | } | 1455 | } |
2315 | EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init_stereo); | 1456 | EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init_stereo); |
2316 | 1457 | ||
2317 | /** | ||
2318 | * snd_hda_codec_resume_amp - Resume all AMP commands from the cache | ||
2319 | * @codec: HD-audio codec | ||
2320 | * | ||
2321 | * Resume the all amp commands from the cache. | ||
2322 | */ | ||
2323 | void snd_hda_codec_resume_amp(struct hda_codec *codec) | ||
2324 | { | ||
2325 | int i; | ||
2326 | |||
2327 | mutex_lock(&codec->hash_mutex); | ||
2328 | codec->cached_write = 0; | ||
2329 | for (i = 0; i < codec->amp_cache.buf.used; i++) { | ||
2330 | struct hda_amp_info *buffer; | ||
2331 | u32 key; | ||
2332 | hda_nid_t nid; | ||
2333 | unsigned int idx, dir, ch; | ||
2334 | struct hda_amp_info info; | ||
2335 | |||
2336 | buffer = snd_array_elem(&codec->amp_cache.buf, i); | ||
2337 | if (!buffer->head.dirty) | ||
2338 | continue; | ||
2339 | buffer->head.dirty = 0; | ||
2340 | info = *buffer; | ||
2341 | key = info.head.key; | ||
2342 | if (!key) | ||
2343 | continue; | ||
2344 | nid = key & 0xff; | ||
2345 | idx = (key >> 16) & 0xff; | ||
2346 | dir = (key >> 24) & 0xff; | ||
2347 | for (ch = 0; ch < 2; ch++) { | ||
2348 | if (!(info.head.val & INFO_AMP_VOL(ch))) | ||
2349 | continue; | ||
2350 | mutex_unlock(&codec->hash_mutex); | ||
2351 | put_vol_mute(codec, info.amp_caps, nid, ch, dir, idx, | ||
2352 | info.vol[ch]); | ||
2353 | mutex_lock(&codec->hash_mutex); | ||
2354 | } | ||
2355 | } | ||
2356 | mutex_unlock(&codec->hash_mutex); | ||
2357 | } | ||
2358 | EXPORT_SYMBOL_GPL(snd_hda_codec_resume_amp); | ||
2359 | |||
2360 | static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir, | 1458 | static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir, |
2361 | unsigned int ofs) | 1459 | unsigned int ofs) |
2362 | { | 1460 | { |
@@ -2478,14 +1576,12 @@ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol, | |||
2478 | long *valp = ucontrol->value.integer.value; | 1576 | long *valp = ucontrol->value.integer.value; |
2479 | int change = 0; | 1577 | int change = 0; |
2480 | 1578 | ||
2481 | snd_hda_power_up(codec); | ||
2482 | if (chs & 1) { | 1579 | if (chs & 1) { |
2483 | change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp); | 1580 | change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp); |
2484 | valp++; | 1581 | valp++; |
2485 | } | 1582 | } |
2486 | if (chs & 2) | 1583 | if (chs & 2) |
2487 | change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp); | 1584 | change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp); |
2488 | snd_hda_power_down(codec); | ||
2489 | return change; | 1585 | return change; |
2490 | } | 1586 | } |
2491 | EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_put); | 1587 | EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_put); |
@@ -2572,7 +1668,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))) | 1668 | if (snd_BUG_ON(strlen(name) >= sizeof(id.name))) |
2573 | return NULL; | 1669 | return NULL; |
2574 | strcpy(id.name, name); | 1670 | strcpy(id.name, name); |
2575 | return snd_ctl_find_id(codec->bus->card, &id); | 1671 | return snd_ctl_find_id(codec->card, &id); |
2576 | } | 1672 | } |
2577 | 1673 | ||
2578 | /** | 1674 | /** |
@@ -2636,7 +1732,7 @@ int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid, | |||
2636 | nid = kctl->id.subdevice & 0xffff; | 1732 | nid = kctl->id.subdevice & 0xffff; |
2637 | if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG)) | 1733 | if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG)) |
2638 | kctl->id.subdevice = 0; | 1734 | kctl->id.subdevice = 0; |
2639 | err = snd_ctl_add(codec->bus->card, kctl); | 1735 | err = snd_ctl_add(codec->card, kctl); |
2640 | if (err < 0) | 1736 | if (err < 0) |
2641 | return err; | 1737 | return err; |
2642 | item = snd_array_new(&codec->mixers); | 1738 | item = snd_array_new(&codec->mixers); |
@@ -2689,7 +1785,7 @@ void snd_hda_ctls_clear(struct hda_codec *codec) | |||
2689 | int i; | 1785 | int i; |
2690 | struct hda_nid_item *items = codec->mixers.list; | 1786 | struct hda_nid_item *items = codec->mixers.list; |
2691 | for (i = 0; i < codec->mixers.used; i++) | 1787 | for (i = 0; i < codec->mixers.used; i++) |
2692 | snd_ctl_remove(codec->bus->card, items[i].kctl); | 1788 | snd_ctl_remove(codec->card, items[i].kctl); |
2693 | snd_array_free(&codec->mixers); | 1789 | snd_array_free(&codec->mixers); |
2694 | snd_array_free(&codec->nids); | 1790 | snd_array_free(&codec->nids); |
2695 | } | 1791 | } |
@@ -2712,10 +1808,9 @@ int snd_hda_lock_devices(struct hda_bus *bus) | |||
2712 | if (!list_empty(&card->ctl_files)) | 1808 | if (!list_empty(&card->ctl_files)) |
2713 | goto err_clear; | 1809 | goto err_clear; |
2714 | 1810 | ||
2715 | list_for_each_entry(codec, &bus->codec_list, list) { | 1811 | list_for_each_codec(codec, bus) { |
2716 | int pcm; | 1812 | struct hda_pcm *cpcm; |
2717 | for (pcm = 0; pcm < codec->num_pcms; pcm++) { | 1813 | list_for_each_entry(cpcm, &codec->pcm_list_head, list) { |
2718 | struct hda_pcm *cpcm = &codec->pcm_info[pcm]; | ||
2719 | if (!cpcm->pcm) | 1814 | if (!cpcm->pcm) |
2720 | continue; | 1815 | continue; |
2721 | if (cpcm->pcm->streams[0].substream_opened || | 1816 | if (cpcm->pcm->streams[0].substream_opened || |
@@ -2742,7 +1837,6 @@ void snd_hda_unlock_devices(struct hda_bus *bus) | |||
2742 | { | 1837 | { |
2743 | struct snd_card *card = bus->card; | 1838 | struct snd_card *card = bus->card; |
2744 | 1839 | ||
2745 | card = bus->card; | ||
2746 | spin_lock(&card->files_lock); | 1840 | spin_lock(&card->files_lock); |
2747 | card->shutdown = 0; | 1841 | card->shutdown = 0; |
2748 | spin_unlock(&card->files_lock); | 1842 | spin_unlock(&card->files_lock); |
@@ -2762,51 +1856,12 @@ EXPORT_SYMBOL_GPL(snd_hda_unlock_devices); | |||
2762 | int snd_hda_codec_reset(struct hda_codec *codec) | 1856 | int snd_hda_codec_reset(struct hda_codec *codec) |
2763 | { | 1857 | { |
2764 | struct hda_bus *bus = codec->bus; | 1858 | struct hda_bus *bus = codec->bus; |
2765 | struct snd_card *card = bus->card; | ||
2766 | int i; | ||
2767 | 1859 | ||
2768 | if (snd_hda_lock_devices(bus) < 0) | 1860 | if (snd_hda_lock_devices(bus) < 0) |
2769 | return -EBUSY; | 1861 | return -EBUSY; |
2770 | 1862 | ||
2771 | /* OK, let it free */ | 1863 | /* OK, let it free */ |
2772 | cancel_delayed_work_sync(&codec->jackpoll_work); | 1864 | snd_hdac_device_unregister(&codec->core); |
2773 | #ifdef CONFIG_PM | ||
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 | 1865 | ||
2811 | /* allow device access again */ | 1866 | /* allow device access again */ |
2812 | snd_hda_unlock_devices(bus); | 1867 | snd_hda_unlock_devices(bus); |
@@ -3153,7 +2208,6 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, | |||
3153 | long *valp = ucontrol->value.integer.value; | 2208 | long *valp = ucontrol->value.integer.value; |
3154 | int change = 0; | 2209 | int change = 0; |
3155 | 2210 | ||
3156 | snd_hda_power_up(codec); | ||
3157 | if (chs & 1) { | 2211 | if (chs & 1) { |
3158 | change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx, | 2212 | change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx, |
3159 | HDA_AMP_MUTE, | 2213 | HDA_AMP_MUTE, |
@@ -3165,7 +2219,6 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, | |||
3165 | HDA_AMP_MUTE, | 2219 | HDA_AMP_MUTE, |
3166 | *valp ? 0 : HDA_AMP_MUTE); | 2220 | *valp ? 0 : HDA_AMP_MUTE); |
3167 | hda_call_check_power_status(codec, nid); | 2221 | hda_call_check_power_status(codec, nid); |
3168 | snd_hda_power_down(codec); | ||
3169 | return change; | 2222 | return change; |
3170 | } | 2223 | } |
3171 | EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_put); | 2224 | EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_put); |
@@ -3466,25 +2519,35 @@ static unsigned int convert_to_spdif_status(unsigned short val) | |||
3466 | 2519 | ||
3467 | /* set digital convert verbs both for the given NID and its slaves */ | 2520 | /* set digital convert verbs both for the given NID and its slaves */ |
3468 | static void set_dig_out(struct hda_codec *codec, hda_nid_t nid, | 2521 | static void set_dig_out(struct hda_codec *codec, hda_nid_t nid, |
3469 | int verb, int val) | 2522 | int mask, int val) |
3470 | { | 2523 | { |
3471 | const hda_nid_t *d; | 2524 | const hda_nid_t *d; |
3472 | 2525 | ||
3473 | snd_hda_codec_write_cache(codec, nid, 0, verb, val); | 2526 | snd_hdac_regmap_update(&codec->core, nid, AC_VERB_SET_DIGI_CONVERT_1, |
2527 | mask, val); | ||
3474 | d = codec->slave_dig_outs; | 2528 | d = codec->slave_dig_outs; |
3475 | if (!d) | 2529 | if (!d) |
3476 | return; | 2530 | return; |
3477 | for (; *d; d++) | 2531 | for (; *d; d++) |
3478 | snd_hda_codec_write_cache(codec, *d, 0, verb, val); | 2532 | snd_hdac_regmap_update(&codec->core, nid, |
2533 | AC_VERB_SET_DIGI_CONVERT_1, mask, val); | ||
3479 | } | 2534 | } |
3480 | 2535 | ||
3481 | static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid, | 2536 | static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid, |
3482 | int dig1, int dig2) | 2537 | int dig1, int dig2) |
3483 | { | 2538 | { |
3484 | if (dig1 != -1) | 2539 | unsigned int mask = 0; |
3485 | set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_1, dig1); | 2540 | unsigned int val = 0; |
3486 | if (dig2 != -1) | 2541 | |
3487 | set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_2, dig2); | 2542 | if (dig1 != -1) { |
2543 | mask |= 0xff; | ||
2544 | val = dig1; | ||
2545 | } | ||
2546 | if (dig2 != -1) { | ||
2547 | mask |= 0xff00; | ||
2548 | val |= dig2 << 8; | ||
2549 | } | ||
2550 | set_dig_out(codec, nid, mask, val); | ||
3488 | } | 2551 | } |
3489 | 2552 | ||
3490 | static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol, | 2553 | static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol, |
@@ -3617,6 +2680,7 @@ int snd_hda_create_dig_out_ctls(struct hda_codec *codec, | |||
3617 | struct snd_kcontrol *kctl; | 2680 | struct snd_kcontrol *kctl; |
3618 | struct snd_kcontrol_new *dig_mix; | 2681 | struct snd_kcontrol_new *dig_mix; |
3619 | int idx = 0; | 2682 | int idx = 0; |
2683 | int val = 0; | ||
3620 | const int spdif_index = 16; | 2684 | const int spdif_index = 16; |
3621 | struct hda_spdif_out *spdif; | 2685 | struct hda_spdif_out *spdif; |
3622 | struct hda_bus *bus = codec->bus; | 2686 | struct hda_bus *bus = codec->bus; |
@@ -3657,8 +2721,9 @@ int snd_hda_create_dig_out_ctls(struct hda_codec *codec, | |||
3657 | return err; | 2721 | return err; |
3658 | } | 2722 | } |
3659 | spdif->nid = cvt_nid; | 2723 | spdif->nid = cvt_nid; |
3660 | spdif->ctls = snd_hda_codec_read(codec, cvt_nid, 0, | 2724 | snd_hdac_regmap_read(&codec->core, cvt_nid, |
3661 | AC_VERB_GET_DIGI_CONVERT_1, 0); | 2725 | AC_VERB_GET_DIGI_CONVERT_1, &val); |
2726 | spdif->ctls = val; | ||
3662 | spdif->status = convert_to_spdif_status(spdif->ctls); | 2727 | spdif->status = convert_to_spdif_status(spdif->ctls); |
3663 | return 0; | 2728 | return 0; |
3664 | } | 2729 | } |
@@ -3802,8 +2867,8 @@ static int snd_hda_spdif_in_switch_put(struct snd_kcontrol *kcontrol, | |||
3802 | change = codec->spdif_in_enable != val; | 2867 | change = codec->spdif_in_enable != val; |
3803 | if (change) { | 2868 | if (change) { |
3804 | codec->spdif_in_enable = val; | 2869 | codec->spdif_in_enable = val; |
3805 | snd_hda_codec_write_cache(codec, nid, 0, | 2870 | snd_hdac_regmap_write(&codec->core, nid, |
3806 | AC_VERB_SET_DIGI_CONVERT_1, val); | 2871 | AC_VERB_SET_DIGI_CONVERT_1, val); |
3807 | } | 2872 | } |
3808 | mutex_unlock(&codec->spdif_mutex); | 2873 | mutex_unlock(&codec->spdif_mutex); |
3809 | return change; | 2874 | return change; |
@@ -3814,10 +2879,11 @@ static int snd_hda_spdif_in_status_get(struct snd_kcontrol *kcontrol, | |||
3814 | { | 2879 | { |
3815 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 2880 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
3816 | hda_nid_t nid = kcontrol->private_value; | 2881 | hda_nid_t nid = kcontrol->private_value; |
3817 | unsigned short val; | 2882 | unsigned int val; |
3818 | unsigned int sbits; | 2883 | unsigned int sbits; |
3819 | 2884 | ||
3820 | val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DIGI_CONVERT_1, 0); | 2885 | snd_hdac_regmap_read(&codec->core, nid, |
2886 | AC_VERB_GET_DIGI_CONVERT_1, &val); | ||
3821 | sbits = convert_to_spdif_status(val); | 2887 | sbits = convert_to_spdif_status(val); |
3822 | ucontrol->value.iec958.status[0] = sbits; | 2888 | ucontrol->value.iec958.status[0] = sbits; |
3823 | ucontrol->value.iec958.status[1] = sbits >> 8; | 2889 | ucontrol->value.iec958.status[1] = sbits >> 8; |
@@ -3883,153 +2949,6 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid) | |||
3883 | } | 2949 | } |
3884 | EXPORT_SYMBOL_GPL(snd_hda_create_spdif_in_ctls); | 2950 | EXPORT_SYMBOL_GPL(snd_hda_create_spdif_in_ctls); |
3885 | 2951 | ||
3886 | /* | ||
3887 | * command cache | ||
3888 | */ | ||
3889 | |||
3890 | /* build a 31bit cache key with the widget id and the command parameter */ | ||
3891 | #define build_cmd_cache_key(nid, verb) ((verb << 8) | nid) | ||
3892 | #define get_cmd_cache_nid(key) ((key) & 0xff) | ||
3893 | #define get_cmd_cache_cmd(key) (((key) >> 8) & 0xffff) | ||
3894 | |||
3895 | /** | ||
3896 | * snd_hda_codec_write_cache - send a single command with caching | ||
3897 | * @codec: the HDA codec | ||
3898 | * @nid: NID to send the command | ||
3899 | * @flags: optional bit flags | ||
3900 | * @verb: the verb to send | ||
3901 | * @parm: the parameter for the verb | ||
3902 | * | ||
3903 | * Send a single command without waiting for response. | ||
3904 | * | ||
3905 | * Returns 0 if successful, or a negative error code. | ||
3906 | */ | ||
3907 | int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, | ||
3908 | int flags, unsigned int verb, unsigned int parm) | ||
3909 | { | ||
3910 | int err; | ||
3911 | struct hda_cache_head *c; | ||
3912 | u32 key; | ||
3913 | unsigned int cache_only; | ||
3914 | |||
3915 | cache_only = codec->cached_write; | ||
3916 | if (!cache_only) { | ||
3917 | err = snd_hda_codec_write(codec, nid, flags, verb, parm); | ||
3918 | if (err < 0) | ||
3919 | return err; | ||
3920 | } | ||
3921 | |||
3922 | /* parm may contain the verb stuff for get/set amp */ | ||
3923 | verb = verb | (parm >> 8); | ||
3924 | parm &= 0xff; | ||
3925 | key = build_cmd_cache_key(nid, verb); | ||
3926 | mutex_lock(&codec->bus->cmd_mutex); | ||
3927 | c = get_alloc_hash(&codec->cmd_cache, key); | ||
3928 | if (c) { | ||
3929 | c->val = parm; | ||
3930 | c->dirty = cache_only; | ||
3931 | } | ||
3932 | mutex_unlock(&codec->bus->cmd_mutex); | ||
3933 | return 0; | ||
3934 | } | ||
3935 | EXPORT_SYMBOL_GPL(snd_hda_codec_write_cache); | ||
3936 | |||
3937 | /** | ||
3938 | * snd_hda_codec_update_cache - check cache and write the cmd only when needed | ||
3939 | * @codec: the HDA codec | ||
3940 | * @nid: NID to send the command | ||
3941 | * @flags: optional bit flags | ||
3942 | * @verb: the verb to send | ||
3943 | * @parm: the parameter for the verb | ||
3944 | * | ||
3945 | * This function works like snd_hda_codec_write_cache(), but it doesn't send | ||
3946 | * command if the parameter is already identical with the cached value. | ||
3947 | * If not, it sends the command and refreshes the cache. | ||
3948 | * | ||
3949 | * Returns 0 if successful, or a negative error code. | ||
3950 | */ | ||
3951 | int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid, | ||
3952 | int flags, unsigned int verb, unsigned int parm) | ||
3953 | { | ||
3954 | struct hda_cache_head *c; | ||
3955 | u32 key; | ||
3956 | |||
3957 | /* parm may contain the verb stuff for get/set amp */ | ||
3958 | verb = verb | (parm >> 8); | ||
3959 | parm &= 0xff; | ||
3960 | key = build_cmd_cache_key(nid, verb); | ||
3961 | mutex_lock(&codec->bus->cmd_mutex); | ||
3962 | c = get_hash(&codec->cmd_cache, key); | ||
3963 | if (c && c->val == parm) { | ||
3964 | mutex_unlock(&codec->bus->cmd_mutex); | ||
3965 | return 0; | ||
3966 | } | ||
3967 | mutex_unlock(&codec->bus->cmd_mutex); | ||
3968 | return snd_hda_codec_write_cache(codec, nid, flags, verb, parm); | ||
3969 | } | ||
3970 | EXPORT_SYMBOL_GPL(snd_hda_codec_update_cache); | ||
3971 | |||
3972 | /** | ||
3973 | * snd_hda_codec_resume_cache - Resume the all commands from the cache | ||
3974 | * @codec: HD-audio codec | ||
3975 | * | ||
3976 | * Execute all verbs recorded in the command caches to resume. | ||
3977 | */ | ||
3978 | void snd_hda_codec_resume_cache(struct hda_codec *codec) | ||
3979 | { | ||
3980 | int i; | ||
3981 | |||
3982 | mutex_lock(&codec->hash_mutex); | ||
3983 | codec->cached_write = 0; | ||
3984 | for (i = 0; i < codec->cmd_cache.buf.used; i++) { | ||
3985 | struct hda_cache_head *buffer; | ||
3986 | u32 key; | ||
3987 | |||
3988 | buffer = snd_array_elem(&codec->cmd_cache.buf, i); | ||
3989 | key = buffer->key; | ||
3990 | if (!key) | ||
3991 | continue; | ||
3992 | if (!buffer->dirty) | ||
3993 | continue; | ||
3994 | buffer->dirty = 0; | ||
3995 | mutex_unlock(&codec->hash_mutex); | ||
3996 | snd_hda_codec_write(codec, get_cmd_cache_nid(key), 0, | ||
3997 | get_cmd_cache_cmd(key), buffer->val); | ||
3998 | mutex_lock(&codec->hash_mutex); | ||
3999 | } | ||
4000 | mutex_unlock(&codec->hash_mutex); | ||
4001 | } | ||
4002 | EXPORT_SYMBOL_GPL(snd_hda_codec_resume_cache); | ||
4003 | |||
4004 | /** | ||
4005 | * snd_hda_sequence_write_cache - sequence writes with caching | ||
4006 | * @codec: the HDA codec | ||
4007 | * @seq: VERB array to send | ||
4008 | * | ||
4009 | * Send the commands sequentially from the given array. | ||
4010 | * Thte commands are recorded on cache for power-save and resume. | ||
4011 | * The array must be terminated with NID=0. | ||
4012 | */ | ||
4013 | void snd_hda_sequence_write_cache(struct hda_codec *codec, | ||
4014 | const struct hda_verb *seq) | ||
4015 | { | ||
4016 | for (; seq->nid; seq++) | ||
4017 | snd_hda_codec_write_cache(codec, seq->nid, 0, seq->verb, | ||
4018 | seq->param); | ||
4019 | } | ||
4020 | EXPORT_SYMBOL_GPL(snd_hda_sequence_write_cache); | ||
4021 | |||
4022 | /** | ||
4023 | * snd_hda_codec_flush_cache - Execute all pending (cached) amps / verbs | ||
4024 | * @codec: HD-audio codec | ||
4025 | */ | ||
4026 | void snd_hda_codec_flush_cache(struct hda_codec *codec) | ||
4027 | { | ||
4028 | snd_hda_codec_resume_amp(codec); | ||
4029 | snd_hda_codec_resume_cache(codec); | ||
4030 | } | ||
4031 | EXPORT_SYMBOL_GPL(snd_hda_codec_flush_cache); | ||
4032 | |||
4033 | /** | 2952 | /** |
4034 | * snd_hda_codec_set_power_to_all - Set the power state to all widgets | 2953 | * snd_hda_codec_set_power_to_all - Set the power state to all widgets |
4035 | * @codec: the HDA codec | 2954 | * @codec: the HDA codec |
@@ -4043,10 +2962,9 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_flush_cache); | |||
4043 | void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, | 2962 | void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, |
4044 | unsigned int power_state) | 2963 | unsigned int power_state) |
4045 | { | 2964 | { |
4046 | hda_nid_t nid = codec->start_nid; | 2965 | hda_nid_t nid; |
4047 | int i; | ||
4048 | 2966 | ||
4049 | for (i = 0; i < codec->num_nodes; i++, nid++) { | 2967 | for_each_hda_codec_node(nid, codec) { |
4050 | unsigned int wcaps = get_wcaps(codec, nid); | 2968 | unsigned int wcaps = get_wcaps(codec, nid); |
4051 | unsigned int state = power_state; | 2969 | unsigned int state = power_state; |
4052 | if (!(wcaps & AC_WCAP_POWER)) | 2970 | if (!(wcaps & AC_WCAP_POWER)) |
@@ -4063,22 +2981,6 @@ void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, | |||
4063 | EXPORT_SYMBOL_GPL(snd_hda_codec_set_power_to_all); | 2981 | EXPORT_SYMBOL_GPL(snd_hda_codec_set_power_to_all); |
4064 | 2982 | ||
4065 | /* | 2983 | /* |
4066 | * supported power states check | ||
4067 | */ | ||
4068 | static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, hda_nid_t fg, | ||
4069 | unsigned int power_state) | ||
4070 | { | ||
4071 | int sup = snd_hda_param_read(codec, fg, AC_PAR_POWER_STATE); | ||
4072 | |||
4073 | if (sup == -1) | ||
4074 | return false; | ||
4075 | if (sup & power_state) | ||
4076 | return true; | ||
4077 | else | ||
4078 | return false; | ||
4079 | } | ||
4080 | |||
4081 | /* | ||
4082 | * wait until the state is reached, returns the current state | 2984 | * wait until the state is reached, returns the current state |
4083 | */ | 2985 | */ |
4084 | static unsigned int hda_sync_power_state(struct hda_codec *codec, | 2986 | static unsigned int hda_sync_power_state(struct hda_codec *codec, |
@@ -4117,7 +3019,7 @@ unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec, | |||
4117 | hda_nid_t nid, | 3019 | hda_nid_t nid, |
4118 | unsigned int power_state) | 3020 | unsigned int power_state) |
4119 | { | 3021 | { |
4120 | if (nid == codec->afg || nid == codec->mfg) | 3022 | if (nid == codec->core.afg || nid == codec->core.mfg) |
4121 | return power_state; | 3023 | return power_state; |
4122 | if (power_state == AC_PWRST_D3 && | 3024 | if (power_state == AC_PWRST_D3 && |
4123 | get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN && | 3025 | get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN && |
@@ -4137,7 +3039,7 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_eapd_power_filter); | |||
4137 | static unsigned int hda_set_power_state(struct hda_codec *codec, | 3039 | static unsigned int hda_set_power_state(struct hda_codec *codec, |
4138 | unsigned int power_state) | 3040 | unsigned int power_state) |
4139 | { | 3041 | { |
4140 | hda_nid_t fg = codec->afg ? codec->afg : codec->mfg; | 3042 | hda_nid_t fg = codec->core.afg ? codec->core.afg : codec->core.mfg; |
4141 | int count; | 3043 | int count; |
4142 | unsigned int state; | 3044 | unsigned int state; |
4143 | int flags = 0; | 3045 | int flags = 0; |
@@ -4145,7 +3047,7 @@ static unsigned int hda_set_power_state(struct hda_codec *codec, | |||
4145 | /* this delay seems necessary to avoid click noise at power-down */ | 3047 | /* this delay seems necessary to avoid click noise at power-down */ |
4146 | if (power_state == AC_PWRST_D3) { | 3048 | if (power_state == AC_PWRST_D3) { |
4147 | if (codec->depop_delay < 0) | 3049 | if (codec->depop_delay < 0) |
4148 | msleep(codec->epss ? 10 : 100); | 3050 | msleep(codec_has_epss(codec) ? 10 : 100); |
4149 | else if (codec->depop_delay > 0) | 3051 | else if (codec->depop_delay > 0) |
4150 | msleep(codec->depop_delay); | 3052 | msleep(codec->depop_delay); |
4151 | flags = HDA_RW_NO_RESPONSE_FALLBACK; | 3053 | flags = HDA_RW_NO_RESPONSE_FALLBACK; |
@@ -4179,14 +3081,13 @@ static unsigned int hda_set_power_state(struct hda_codec *codec, | |||
4179 | */ | 3081 | */ |
4180 | static void sync_power_up_states(struct hda_codec *codec) | 3082 | static void sync_power_up_states(struct hda_codec *codec) |
4181 | { | 3083 | { |
4182 | hda_nid_t nid = codec->start_nid; | 3084 | hda_nid_t nid; |
4183 | int i; | ||
4184 | 3085 | ||
4185 | /* don't care if no filter is used */ | 3086 | /* don't care if no filter is used */ |
4186 | if (!codec->power_filter) | 3087 | if (!codec->power_filter) |
4187 | return; | 3088 | return; |
4188 | 3089 | ||
4189 | for (i = 0; i < codec->num_nodes; i++, nid++) { | 3090 | for_each_hda_codec_node(nid, codec) { |
4190 | unsigned int wcaps = get_wcaps(codec, nid); | 3091 | unsigned int wcaps = get_wcaps(codec, nid); |
4191 | unsigned int target; | 3092 | unsigned int target; |
4192 | if (!(wcaps & AC_WCAP_POWER)) | 3093 | if (!(wcaps & AC_WCAP_POWER)) |
@@ -4212,63 +3113,54 @@ static inline void hda_exec_init_verbs(struct hda_codec *codec) {} | |||
4212 | #endif | 3113 | #endif |
4213 | 3114 | ||
4214 | #ifdef CONFIG_PM | 3115 | #ifdef CONFIG_PM |
3116 | /* update the power on/off account with the current jiffies */ | ||
3117 | static void update_power_acct(struct hda_codec *codec, bool on) | ||
3118 | { | ||
3119 | unsigned long delta = jiffies - codec->power_jiffies; | ||
3120 | |||
3121 | if (on) | ||
3122 | codec->power_on_acct += delta; | ||
3123 | else | ||
3124 | codec->power_off_acct += delta; | ||
3125 | codec->power_jiffies += delta; | ||
3126 | } | ||
3127 | |||
3128 | void snd_hda_update_power_acct(struct hda_codec *codec) | ||
3129 | { | ||
3130 | update_power_acct(codec, hda_codec_is_power_on(codec)); | ||
3131 | } | ||
3132 | |||
4215 | /* | 3133 | /* |
4216 | * call suspend and power-down; used both from PM and power-save | 3134 | * call suspend and power-down; used both from PM and power-save |
4217 | * this function returns the power state in the end | 3135 | * this function returns the power state in the end |
4218 | */ | 3136 | */ |
4219 | static unsigned int hda_call_codec_suspend(struct hda_codec *codec, bool in_wq) | 3137 | static unsigned int hda_call_codec_suspend(struct hda_codec *codec) |
4220 | { | 3138 | { |
4221 | unsigned int state; | 3139 | unsigned int state; |
4222 | 3140 | ||
4223 | codec->in_pm = 1; | 3141 | atomic_inc(&codec->core.in_pm); |
4224 | 3142 | ||
4225 | if (codec->patch_ops.suspend) | 3143 | if (codec->patch_ops.suspend) |
4226 | codec->patch_ops.suspend(codec); | 3144 | codec->patch_ops.suspend(codec); |
4227 | hda_cleanup_all_streams(codec); | 3145 | hda_cleanup_all_streams(codec); |
4228 | state = hda_set_power_state(codec, AC_PWRST_D3); | 3146 | state = hda_set_power_state(codec, AC_PWRST_D3); |
4229 | /* Cancel delayed work if we aren't currently running from it. */ | 3147 | update_power_acct(codec, true); |
4230 | if (!in_wq) | 3148 | atomic_dec(&codec->core.in_pm); |
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); | ||
4235 | codec->power_on = 0; | ||
4236 | codec->power_transition = 0; | ||
4237 | codec->power_jiffies = jiffies; | ||
4238 | spin_unlock(&codec->power_lock); | ||
4239 | codec->in_pm = 0; | ||
4240 | return state; | 3149 | return state; |
4241 | } | 3150 | } |
4242 | 3151 | ||
4243 | /* mark all entries of cmd and amp caches dirty */ | ||
4244 | static void hda_mark_cmd_cache_dirty(struct hda_codec *codec) | ||
4245 | { | ||
4246 | int i; | ||
4247 | for (i = 0; i < codec->cmd_cache.buf.used; i++) { | ||
4248 | struct hda_cache_head *cmd; | ||
4249 | cmd = snd_array_elem(&codec->cmd_cache.buf, i); | ||
4250 | cmd->dirty = 1; | ||
4251 | } | ||
4252 | for (i = 0; i < codec->amp_cache.buf.used; i++) { | ||
4253 | struct hda_amp_info *amp; | ||
4254 | amp = snd_array_elem(&codec->amp_cache.buf, i); | ||
4255 | amp->head.dirty = 1; | ||
4256 | } | ||
4257 | } | ||
4258 | |||
4259 | /* | 3152 | /* |
4260 | * kick up codec; used both from PM and power-save | 3153 | * kick up codec; used both from PM and power-save |
4261 | */ | 3154 | */ |
4262 | static void hda_call_codec_resume(struct hda_codec *codec) | 3155 | static void hda_call_codec_resume(struct hda_codec *codec) |
4263 | { | 3156 | { |
4264 | codec->in_pm = 1; | 3157 | atomic_inc(&codec->core.in_pm); |
4265 | 3158 | ||
4266 | hda_mark_cmd_cache_dirty(codec); | 3159 | if (codec->core.regmap) |
3160 | regcache_mark_dirty(codec->core.regmap); | ||
3161 | |||
3162 | codec->power_jiffies = jiffies; | ||
4267 | 3163 | ||
4268 | /* set as if powered on for avoiding re-entering the resume | ||
4269 | * in the resume / power-save sequence | ||
4270 | */ | ||
4271 | hda_keep_power_on(codec); | ||
4272 | hda_set_power_state(codec, AC_PWRST_D0); | 3164 | hda_set_power_state(codec, AC_PWRST_D0); |
4273 | restore_shutup_pins(codec); | 3165 | restore_shutup_pins(codec); |
4274 | hda_exec_init_verbs(codec); | 3166 | hda_exec_init_verbs(codec); |
@@ -4278,72 +3170,71 @@ static void hda_call_codec_resume(struct hda_codec *codec) | |||
4278 | else { | 3170 | else { |
4279 | if (codec->patch_ops.init) | 3171 | if (codec->patch_ops.init) |
4280 | codec->patch_ops.init(codec); | 3172 | codec->patch_ops.init(codec); |
4281 | snd_hda_codec_resume_amp(codec); | 3173 | if (codec->core.regmap) |
4282 | snd_hda_codec_resume_cache(codec); | 3174 | regcache_sync(codec->core.regmap); |
4283 | } | 3175 | } |
4284 | 3176 | ||
4285 | if (codec->jackpoll_interval) | 3177 | if (codec->jackpoll_interval) |
4286 | hda_jackpoll_work(&codec->jackpoll_work.work); | 3178 | hda_jackpoll_work(&codec->jackpoll_work.work); |
4287 | else | 3179 | else |
4288 | snd_hda_jack_report_sync(codec); | 3180 | snd_hda_jack_report_sync(codec); |
4289 | 3181 | atomic_dec(&codec->core.in_pm); | |
4290 | codec->in_pm = 0; | ||
4291 | snd_hda_power_down(codec); /* flag down before returning */ | ||
4292 | } | 3182 | } |
4293 | #endif /* CONFIG_PM */ | ||
4294 | 3183 | ||
3184 | static int hda_codec_runtime_suspend(struct device *dev) | ||
3185 | { | ||
3186 | struct hda_codec *codec = dev_to_hda_codec(dev); | ||
3187 | struct hda_pcm *pcm; | ||
3188 | unsigned int state; | ||
4295 | 3189 | ||
4296 | /** | 3190 | cancel_delayed_work_sync(&codec->jackpoll_work); |
4297 | * snd_hda_build_controls - build mixer controls | 3191 | list_for_each_entry(pcm, &codec->pcm_list_head, list) |
4298 | * @bus: the BUS | 3192 | snd_pcm_suspend_all(pcm->pcm); |
4299 | * | 3193 | state = hda_call_codec_suspend(codec); |
4300 | * Creates mixer controls for each codec included in the bus. | 3194 | if (codec_has_clkstop(codec) && codec_has_epss(codec) && |
4301 | * | 3195 | (state & AC_PWRST_CLK_STOP_OK)) |
4302 | * Returns 0 if successful, otherwise a negative error code. | 3196 | snd_hdac_codec_link_down(&codec->core); |
4303 | */ | 3197 | return 0; |
4304 | int snd_hda_build_controls(struct hda_bus *bus) | 3198 | } |
3199 | |||
3200 | static int hda_codec_runtime_resume(struct device *dev) | ||
4305 | { | 3201 | { |
4306 | struct hda_codec *codec; | 3202 | struct hda_codec *codec = dev_to_hda_codec(dev); |
4307 | 3203 | ||
4308 | list_for_each_entry(codec, &bus->codec_list, list) { | 3204 | snd_hdac_codec_link_up(&codec->core); |
4309 | int err = snd_hda_codec_build_controls(codec); | 3205 | hda_call_codec_resume(codec); |
4310 | if (err < 0) { | 3206 | 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; | 3207 | return 0; |
4323 | } | 3208 | } |
4324 | EXPORT_SYMBOL_GPL(snd_hda_build_controls); | 3209 | #endif /* CONFIG_PM */ |
3210 | |||
3211 | /* referred in hda_bind.c */ | ||
3212 | const struct dev_pm_ops hda_codec_driver_pm = { | ||
3213 | SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, | ||
3214 | pm_runtime_force_resume) | ||
3215 | SET_RUNTIME_PM_OPS(hda_codec_runtime_suspend, hda_codec_runtime_resume, | ||
3216 | NULL) | ||
3217 | }; | ||
4325 | 3218 | ||
4326 | /* | 3219 | /* |
4327 | * add standard channel maps if not specified | 3220 | * add standard channel maps if not specified |
4328 | */ | 3221 | */ |
4329 | static int add_std_chmaps(struct hda_codec *codec) | 3222 | static int add_std_chmaps(struct hda_codec *codec) |
4330 | { | 3223 | { |
4331 | int i, str, err; | 3224 | struct hda_pcm *pcm; |
3225 | int str, err; | ||
4332 | 3226 | ||
4333 | for (i = 0; i < codec->num_pcms; i++) { | 3227 | list_for_each_entry(pcm, &codec->pcm_list_head, list) { |
4334 | for (str = 0; str < 2; str++) { | 3228 | for (str = 0; str < 2; str++) { |
4335 | struct snd_pcm *pcm = codec->pcm_info[i].pcm; | 3229 | 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; | 3230 | struct snd_pcm_chmap *chmap; |
4339 | const struct snd_pcm_chmap_elem *elem; | 3231 | const struct snd_pcm_chmap_elem *elem; |
4340 | 3232 | ||
4341 | if (codec->pcm_info[i].own_chmap) | 3233 | if (!pcm || pcm->own_chmap || |
4342 | continue; | 3234 | !hinfo->substreams) |
4343 | if (!pcm || !hinfo->substreams) | ||
4344 | continue; | 3235 | continue; |
4345 | elem = hinfo->chmap ? hinfo->chmap : snd_pcm_std_chmaps; | 3236 | elem = hinfo->chmap ? hinfo->chmap : snd_pcm_std_chmaps; |
4346 | err = snd_pcm_add_chmap_ctls(pcm, str, elem, | 3237 | err = snd_pcm_add_chmap_ctls(pcm->pcm, str, elem, |
4347 | hinfo->channels_max, | 3238 | hinfo->channels_max, |
4348 | 0, &chmap); | 3239 | 0, &chmap); |
4349 | if (err < 0) | 3240 | if (err < 0) |
@@ -4499,43 +3390,29 @@ unsigned int snd_hda_calc_stream_format(struct hda_codec *codec, | |||
4499 | } | 3390 | } |
4500 | EXPORT_SYMBOL_GPL(snd_hda_calc_stream_format); | 3391 | EXPORT_SYMBOL_GPL(snd_hda_calc_stream_format); |
4501 | 3392 | ||
4502 | static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid, | 3393 | static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid) |
4503 | int dir) | ||
4504 | { | 3394 | { |
4505 | unsigned int val = 0; | 3395 | unsigned int val = 0; |
4506 | if (nid != codec->afg && | 3396 | if (nid != codec->core.afg && |
4507 | (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) | 3397 | (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) |
4508 | val = snd_hda_param_read(codec, nid, AC_PAR_PCM); | 3398 | val = snd_hda_param_read(codec, nid, AC_PAR_PCM); |
4509 | if (!val || val == -1) | 3399 | if (!val || val == -1) |
4510 | val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM); | 3400 | val = snd_hda_param_read(codec, codec->core.afg, AC_PAR_PCM); |
4511 | if (!val || val == -1) | 3401 | if (!val || val == -1) |
4512 | return 0; | 3402 | return 0; |
4513 | return val; | 3403 | return val; |
4514 | } | 3404 | } |
4515 | 3405 | ||
4516 | static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid) | 3406 | static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid) |
4517 | { | ||
4518 | return query_caps_hash(codec, nid, 0, HDA_HASH_PARPCM_KEY(nid), | ||
4519 | get_pcm_param); | ||
4520 | } | ||
4521 | |||
4522 | static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid, | ||
4523 | int dir) | ||
4524 | { | 3407 | { |
4525 | unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM); | 3408 | unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM); |
4526 | if (!streams || streams == -1) | 3409 | if (!streams || streams == -1) |
4527 | streams = snd_hda_param_read(codec, codec->afg, AC_PAR_STREAM); | 3410 | streams = snd_hda_param_read(codec, codec->core.afg, AC_PAR_STREAM); |
4528 | if (!streams || streams == -1) | 3411 | if (!streams || streams == -1) |
4529 | return 0; | 3412 | return 0; |
4530 | return streams; | 3413 | return streams; |
4531 | } | 3414 | } |
4532 | 3415 | ||
4533 | static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid) | ||
4534 | { | ||
4535 | return query_caps_hash(codec, nid, 0, HDA_HASH_PARSTR_KEY(nid), | ||
4536 | get_stream_param); | ||
4537 | } | ||
4538 | |||
4539 | /** | 3416 | /** |
4540 | * snd_hda_query_supported_pcm - query the supported PCM rates and formats | 3417 | * snd_hda_query_supported_pcm - query the supported PCM rates and formats |
4541 | * @codec: the HDA codec | 3418 | * @codec: the HDA codec |
@@ -4792,7 +3669,11 @@ int snd_hda_codec_prepare(struct hda_codec *codec, | |||
4792 | { | 3669 | { |
4793 | int ret; | 3670 | int ret; |
4794 | mutex_lock(&codec->bus->prepare_mutex); | 3671 | mutex_lock(&codec->bus->prepare_mutex); |
4795 | ret = hinfo->ops.prepare(hinfo, codec, stream, format, substream); | 3672 | if (hinfo->ops.prepare) |
3673 | ret = hinfo->ops.prepare(hinfo, codec, stream, format, | ||
3674 | substream); | ||
3675 | else | ||
3676 | ret = -ENODEV; | ||
4796 | if (ret >= 0) | 3677 | if (ret >= 0) |
4797 | purify_inactive_streams(codec); | 3678 | purify_inactive_streams(codec); |
4798 | mutex_unlock(&codec->bus->prepare_mutex); | 3679 | mutex_unlock(&codec->bus->prepare_mutex); |
@@ -4813,7 +3694,8 @@ void snd_hda_codec_cleanup(struct hda_codec *codec, | |||
4813 | struct snd_pcm_substream *substream) | 3694 | struct snd_pcm_substream *substream) |
4814 | { | 3695 | { |
4815 | mutex_lock(&codec->bus->prepare_mutex); | 3696 | mutex_lock(&codec->bus->prepare_mutex); |
4816 | hinfo->ops.cleanup(hinfo, codec, substream); | 3697 | if (hinfo->ops.cleanup) |
3698 | hinfo->ops.cleanup(hinfo, codec, substream); | ||
4817 | mutex_unlock(&codec->bus->prepare_mutex); | 3699 | mutex_unlock(&codec->bus->prepare_mutex); |
4818 | } | 3700 | } |
4819 | EXPORT_SYMBOL_GPL(snd_hda_codec_cleanup); | 3701 | EXPORT_SYMBOL_GPL(snd_hda_codec_cleanup); |
@@ -4871,112 +3753,84 @@ static int get_empty_pcm_device(struct hda_bus *bus, unsigned int type) | |||
4871 | return -EAGAIN; | 3753 | return -EAGAIN; |
4872 | } | 3754 | } |
4873 | 3755 | ||
4874 | /* | 3756 | /* call build_pcms ops of the given codec and set up the default parameters */ |
4875 | * attach a new PCM stream | 3757 | int snd_hda_codec_parse_pcms(struct hda_codec *codec) |
4876 | */ | ||
4877 | static int snd_hda_attach_pcm(struct hda_codec *codec, struct hda_pcm *pcm) | ||
4878 | { | 3758 | { |
4879 | struct hda_bus *bus = codec->bus; | 3759 | struct hda_pcm *cpcm; |
4880 | struct hda_pcm_stream *info; | 3760 | int err; |
4881 | int stream, err; | ||
4882 | 3761 | ||
4883 | if (snd_BUG_ON(!pcm->name)) | 3762 | if (!list_empty(&codec->pcm_list_head)) |
4884 | return -EINVAL; | 3763 | return 0; /* already parsed */ |
4885 | for (stream = 0; stream < 2; stream++) { | 3764 | |
4886 | info = &pcm->stream[stream]; | 3765 | if (!codec->patch_ops.build_pcms) |
4887 | if (info->substreams) { | 3766 | return 0; |
3767 | |||
3768 | err = codec->patch_ops.build_pcms(codec); | ||
3769 | if (err < 0) { | ||
3770 | codec_err(codec, "cannot build PCMs for #%d (error %d)\n", | ||
3771 | codec->core.addr, err); | ||
3772 | return err; | ||
3773 | } | ||
3774 | |||
3775 | list_for_each_entry(cpcm, &codec->pcm_list_head, list) { | ||
3776 | int stream; | ||
3777 | |||
3778 | for (stream = 0; stream < 2; stream++) { | ||
3779 | struct hda_pcm_stream *info = &cpcm->stream[stream]; | ||
3780 | |||
3781 | if (!info->substreams) | ||
3782 | continue; | ||
4888 | err = set_pcm_default_values(codec, info); | 3783 | err = set_pcm_default_values(codec, info); |
4889 | if (err < 0) | 3784 | if (err < 0) { |
3785 | codec_warn(codec, | ||
3786 | "fail to setup default for PCM %s\n", | ||
3787 | cpcm->name); | ||
4890 | return err; | 3788 | return err; |
3789 | } | ||
4891 | } | 3790 | } |
4892 | } | 3791 | } |
4893 | return bus->ops.attach_pcm(bus, codec, pcm); | 3792 | |
3793 | return 0; | ||
4894 | } | 3794 | } |
4895 | 3795 | ||
4896 | /* assign all PCMs of the given codec */ | 3796 | /* assign all PCMs of the given codec */ |
4897 | int snd_hda_codec_build_pcms(struct hda_codec *codec) | 3797 | int snd_hda_codec_build_pcms(struct hda_codec *codec) |
4898 | { | 3798 | { |
4899 | unsigned int pcm; | 3799 | struct hda_bus *bus = codec->bus; |
4900 | int err; | 3800 | struct hda_pcm *cpcm; |
3801 | int dev, err; | ||
4901 | 3802 | ||
4902 | if (!codec->num_pcms) { | 3803 | if (snd_BUG_ON(!bus->ops.attach_pcm)) |
4903 | if (!codec->patch_ops.build_pcms) | 3804 | return -EINVAL; |
4904 | return 0; | 3805 | |
4905 | err = codec->patch_ops.build_pcms(codec); | 3806 | err = snd_hda_codec_parse_pcms(codec); |
4906 | if (err < 0) { | 3807 | if (err < 0) { |
4907 | codec_err(codec, | 3808 | snd_hda_codec_reset(codec); |
4908 | "cannot build PCMs for #%d (error %d)\n", | 3809 | 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 | } | 3810 | } |
4918 | for (pcm = 0; pcm < codec->num_pcms; pcm++) { | ||
4919 | struct hda_pcm *cpcm = &codec->pcm_info[pcm]; | ||
4920 | int dev; | ||
4921 | 3811 | ||
3812 | /* attach a new PCM streams */ | ||
3813 | list_for_each_entry(cpcm, &codec->pcm_list_head, list) { | ||
3814 | if (cpcm->pcm) | ||
3815 | continue; /* already attached */ | ||
4922 | if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams) | 3816 | if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams) |
4923 | continue; /* no substreams assigned */ | 3817 | continue; /* no substreams assigned */ |
4924 | 3818 | ||
4925 | if (!cpcm->pcm) { | 3819 | dev = get_empty_pcm_device(bus, cpcm->pcm_type); |
4926 | dev = get_empty_pcm_device(codec->bus, cpcm->pcm_type); | 3820 | if (dev < 0) |
4927 | if (dev < 0) | 3821 | continue; /* no fatal error */ |
4928 | continue; /* no fatal error */ | 3822 | cpcm->device = dev; |
4929 | cpcm->device = dev; | 3823 | err = bus->ops.attach_pcm(bus, codec, cpcm); |
4930 | err = snd_hda_attach_pcm(codec, cpcm); | 3824 | if (err < 0) { |
4931 | if (err < 0) { | 3825 | codec_err(codec, |
4932 | codec_err(codec, | 3826 | "cannot attach PCM stream %d for codec #%d\n", |
4933 | "cannot attach PCM stream %d for codec #%d\n", | 3827 | dev, codec->core.addr); |
4934 | dev, codec->addr); | 3828 | continue; /* no fatal error */ |
4935 | continue; /* no fatal error */ | ||
4936 | } | ||
4937 | } | 3829 | } |
4938 | } | 3830 | } |
4939 | return 0; | ||
4940 | } | ||
4941 | 3831 | ||
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 | */ | ||
4968 | int 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; | 3832 | return 0; |
4978 | } | 3833 | } |
4979 | EXPORT_SYMBOL_GPL(snd_hda_build_pcms); | ||
4980 | 3834 | ||
4981 | /** | 3835 | /** |
4982 | * snd_hda_add_new_ctls - create controls from the array | 3836 | * snd_hda_add_new_ctls - create controls from the array |
@@ -5013,8 +3867,8 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, | |||
5013 | * the codec addr; if it still fails (or it's the | 3867 | * the codec addr; if it still fails (or it's the |
5014 | * primary codec), then try another control index | 3868 | * primary codec), then try another control index |
5015 | */ | 3869 | */ |
5016 | if (!addr && codec->addr) | 3870 | if (!addr && codec->core.addr) |
5017 | addr = codec->addr; | 3871 | addr = codec->core.addr; |
5018 | else if (!idx && !knew->index) { | 3872 | else if (!idx && !knew->index) { |
5019 | idx = find_empty_mixer_ctl_idx(codec, | 3873 | idx = find_empty_mixer_ctl_idx(codec, |
5020 | knew->name, 0); | 3874 | knew->name, 0); |
@@ -5029,127 +3883,37 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, | |||
5029 | EXPORT_SYMBOL_GPL(snd_hda_add_new_ctls); | 3883 | EXPORT_SYMBOL_GPL(snd_hda_add_new_ctls); |
5030 | 3884 | ||
5031 | #ifdef CONFIG_PM | 3885 | #ifdef CONFIG_PM |
5032 | static void hda_power_work(struct work_struct *work) | 3886 | static void codec_set_power_save(struct hda_codec *codec, int delay) |
5033 | { | ||
5034 | struct hda_codec *codec = | ||
5035 | container_of(work, struct hda_codec, power_work.work); | ||
5036 | struct hda_bus *bus = codec->bus; | ||
5037 | unsigned int state; | ||
5038 | |||
5039 | spin_lock(&codec->power_lock); | ||
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; | ||
5048 | } | ||
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 | } | ||
5055 | |||
5056 | static void hda_keep_power_on(struct hda_codec *codec) | ||
5057 | { | ||
5058 | spin_lock(&codec->power_lock); | ||
5059 | codec->power_count++; | ||
5060 | codec->power_on = 1; | ||
5061 | codec->power_jiffies = jiffies; | ||
5062 | spin_unlock(&codec->power_lock); | ||
5063 | hda_call_pm_notify(codec, true); | ||
5064 | } | ||
5065 | |||
5066 | /* update the power on/off account with the current jiffies */ | ||
5067 | void 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! */ | ||
5081 | static void __snd_hda_power_up(struct hda_codec *codec, bool wait_power_down) | ||
5082 | { | ||
5083 | /* Return if power_on or transitioning to power_on, unless currently | ||
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 | |||
5092 | spin_lock(&codec->power_lock); | ||
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; | ||
5100 | } | ||
5101 | |||
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 | } | ||
5114 | |||
5115 | #define power_save(codec) \ | ||
5116 | ((codec)->bus->power_save ? *(codec)->bus->power_save : 0) | ||
5117 | |||
5118 | /* Transition to powered down */ | ||
5119 | static void __snd_hda_power_down(struct hda_codec *codec) | ||
5120 | { | 3887 | { |
5121 | if (!codec->power_on || codec->power_count || codec->power_transition) | 3888 | struct device *dev = hda_codec_dev(codec); |
5122 | return; | ||
5123 | 3889 | ||
5124 | if (power_save(codec)) { | 3890 | if (delay > 0) { |
5125 | codec->power_transition = -1; /* avoid reentrance */ | 3891 | pm_runtime_set_autosuspend_delay(dev, delay); |
5126 | queue_delayed_work(codec->bus->workq, &codec->power_work, | 3892 | pm_runtime_use_autosuspend(dev); |
5127 | msecs_to_jiffies(power_save(codec) * 1000)); | 3893 | pm_runtime_allow(dev); |
3894 | if (!pm_runtime_suspended(dev)) | ||
3895 | pm_runtime_mark_last_busy(dev); | ||
3896 | } else { | ||
3897 | pm_runtime_dont_use_autosuspend(dev); | ||
3898 | pm_runtime_forbid(dev); | ||
5128 | } | 3899 | } |
5129 | } | 3900 | } |
5130 | 3901 | ||
5131 | /** | 3902 | /** |
5132 | * snd_hda_power_save - Power-up/down/sync the codec | 3903 | * snd_hda_set_power_save - reprogram autosuspend for the given delay |
5133 | * @codec: HD-audio codec | 3904 | * @bus: HD-audio bus |
5134 | * @delta: the counter delta to change | 3905 | * @delay: autosuspend delay in msec, 0 = off |
5135 | * @d3wait: sync for D3 transition complete | ||
5136 | * | 3906 | * |
5137 | * Change the power-up counter via @delta, and power up or down the hardware | 3907 | * 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 | */ | 3908 | */ |
5141 | void snd_hda_power_save(struct hda_codec *codec, int delta, bool d3wait) | 3909 | void snd_hda_set_power_save(struct hda_bus *bus, int delay) |
5142 | { | 3910 | { |
5143 | spin_lock(&codec->power_lock); | 3911 | struct hda_codec *c; |
5144 | codec->power_count += delta; | 3912 | |
5145 | trace_hda_power_count(codec); | 3913 | list_for_each_codec(c, bus) |
5146 | if (delta > 0) | 3914 | 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 | } | 3915 | } |
5152 | EXPORT_SYMBOL_GPL(snd_hda_power_save); | 3916 | EXPORT_SYMBOL_GPL(snd_hda_set_power_save); |
5153 | 3917 | ||
5154 | /** | 3918 | /** |
5155 | * snd_hda_check_amp_list_power - Check the amp list and update the power | 3919 | * snd_hda_check_amp_list_power - Check the amp list and update the power |
@@ -5187,7 +3951,7 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec, | |||
5187 | if (!(v & HDA_AMP_MUTE) && v > 0) { | 3951 | if (!(v & HDA_AMP_MUTE) && v > 0) { |
5188 | if (!check->power_on) { | 3952 | if (!check->power_on) { |
5189 | check->power_on = 1; | 3953 | check->power_on = 1; |
5190 | snd_hda_power_up(codec); | 3954 | snd_hda_power_up_pm(codec); |
5191 | } | 3955 | } |
5192 | return 1; | 3956 | return 1; |
5193 | } | 3957 | } |
@@ -5195,7 +3959,7 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec, | |||
5195 | } | 3959 | } |
5196 | if (check->power_on) { | 3960 | if (check->power_on) { |
5197 | check->power_on = 0; | 3961 | check->power_on = 0; |
5198 | snd_hda_power_down(codec); | 3962 | snd_hda_power_down_pm(codec); |
5199 | } | 3963 | } |
5200 | return 0; | 3964 | return 0; |
5201 | } | 3965 | } |
@@ -5203,88 +3967,6 @@ EXPORT_SYMBOL_GPL(snd_hda_check_amp_list_power); | |||
5203 | #endif | 3967 | #endif |
5204 | 3968 | ||
5205 | /* | 3969 | /* |
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 | */ | ||
5216 | int 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 | } | ||
5230 | EXPORT_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 | */ | ||
5240 | int 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 | } | ||
5256 | EXPORT_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 | */ | ||
5266 | int 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 | } | ||
5285 | EXPORT_SYMBOL_GPL(snd_hda_ch_mode_put); | ||
5286 | |||
5287 | /* | ||
5288 | * input MUX helper | 3970 | * input MUX helper |
5289 | */ | 3971 | */ |
5290 | 3972 | ||
@@ -5418,24 +4100,6 @@ static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid) | |||
5418 | } | 4100 | } |
5419 | 4101 | ||
5420 | /** | 4102 | /** |
5421 | * snd_hda_bus_reboot_notify - call the reboot notifier of each codec | ||
5422 | * @bus: HD-audio bus | ||
5423 | */ | ||
5424 | void 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 | } | ||
5436 | EXPORT_SYMBOL_GPL(snd_hda_bus_reboot_notify); | ||
5437 | |||
5438 | /** | ||
5439 | * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode | 4103 | * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode |
5440 | * @codec: the HDA codec | 4104 | * @codec: the HDA codec |
5441 | * @mout: hda_multi_out object | 4105 | * @mout: hda_multi_out object |
@@ -5825,123 +4489,26 @@ int snd_hda_add_imux_item(struct hda_codec *codec, | |||
5825 | } | 4489 | } |
5826 | EXPORT_SYMBOL_GPL(snd_hda_add_imux_item); | 4490 | EXPORT_SYMBOL_GPL(snd_hda_add_imux_item); |
5827 | 4491 | ||
5828 | |||
5829 | #ifdef CONFIG_PM | ||
5830 | /* | ||
5831 | * power management | ||
5832 | */ | ||
5833 | |||
5834 | |||
5835 | static void hda_async_suspend(void *data, async_cookie_t cookie) | ||
5836 | { | ||
5837 | hda_call_codec_suspend(data, false); | ||
5838 | } | ||
5839 | |||
5840 | static void hda_async_resume(void *data, async_cookie_t cookie) | ||
5841 | { | ||
5842 | hda_call_codec_resume(data); | ||
5843 | } | ||
5844 | |||
5845 | /** | 4492 | /** |
5846 | * snd_hda_suspend - suspend the codecs | 4493 | * snd_hda_bus_reset - Reset the bus |
5847 | * @bus: the HDA bus | 4494 | * @bus: HD-audio bus |
5848 | * | ||
5849 | * Returns 0 if successful. | ||
5850 | */ | 4495 | */ |
5851 | int snd_hda_suspend(struct hda_bus *bus) | 4496 | void snd_hda_bus_reset(struct hda_bus *bus) |
5852 | { | 4497 | { |
5853 | struct hda_codec *codec; | 4498 | struct hda_codec *codec; |
5854 | ASYNC_DOMAIN_EXCLUSIVE(domain); | ||
5855 | 4499 | ||
5856 | list_for_each_entry(codec, &bus->codec_list, list) { | 4500 | list_for_each_codec(codec, bus) { |
4501 | /* FIXME: maybe a better way needed for forced reset */ | ||
5857 | cancel_delayed_work_sync(&codec->jackpoll_work); | 4502 | cancel_delayed_work_sync(&codec->jackpoll_work); |
4503 | #ifdef CONFIG_PM | ||
5858 | if (hda_codec_is_power_on(codec)) { | 4504 | if (hda_codec_is_power_on(codec)) { |
5859 | if (bus->num_codecs > 1) | 4505 | 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 | } | ||
5872 | EXPORT_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 | */ | ||
5880 | int 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); | 4506 | hda_call_codec_resume(codec); |
4507 | } | ||
4508 | #endif | ||
5890 | } | 4509 | } |
5891 | |||
5892 | if (bus->num_codecs > 1) | ||
5893 | async_synchronize_full_domain(&domain); | ||
5894 | |||
5895 | return 0; | ||
5896 | } | ||
5897 | EXPORT_SYMBOL_GPL(snd_hda_resume); | ||
5898 | #endif /* CONFIG_PM */ | ||
5899 | |||
5900 | /* | ||
5901 | * generic arrays | ||
5902 | */ | ||
5903 | |||
5904 | /** | ||
5905 | * snd_array_new - get a new element from the given array | ||
5906 | * @array: the array object | ||
5907 | * | ||
5908 | * Get a new element from the given array. If it exceeds the | ||
5909 | * pre-allocated array size, re-allocate the array. | ||
5910 | * | ||
5911 | * Returns NULL if allocation failed. | ||
5912 | */ | ||
5913 | void *snd_array_new(struct snd_array *array) | ||
5914 | { | ||
5915 | if (snd_BUG_ON(!array->elem_size)) | ||
5916 | return NULL; | ||
5917 | if (array->used >= array->alloced) { | ||
5918 | int num = array->alloced + array->alloc_align; | ||
5919 | int size = (num + 1) * array->elem_size; | ||
5920 | void *nlist; | ||
5921 | if (snd_BUG_ON(num >= 4096)) | ||
5922 | return NULL; | ||
5923 | nlist = krealloc(array->list, size, GFP_KERNEL | __GFP_ZERO); | ||
5924 | if (!nlist) | ||
5925 | return NULL; | ||
5926 | array->list = nlist; | ||
5927 | array->alloced = num; | ||
5928 | } | ||
5929 | return snd_array_elem(array, array->used++); | ||
5930 | } | ||
5931 | EXPORT_SYMBOL_GPL(snd_array_new); | ||
5932 | |||
5933 | /** | ||
5934 | * snd_array_free - free the given array elements | ||
5935 | * @array: the array object | ||
5936 | */ | ||
5937 | void snd_array_free(struct snd_array *array) | ||
5938 | { | ||
5939 | kfree(array->list); | ||
5940 | array->used = 0; | ||
5941 | array->alloced = 0; | ||
5942 | array->list = NULL; | ||
5943 | } | 4510 | } |
5944 | EXPORT_SYMBOL_GPL(snd_array_free); | 4511 | EXPORT_SYMBOL_GPL(snd_hda_bus_reset); |
5945 | 4512 | ||
5946 | /** | 4513 | /** |
5947 | * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer | 4514 | * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer |
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 9c8820f21f94..9075ac28dc4b 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h | |||
@@ -21,41 +21,14 @@ | |||
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> |
27 | #include <sound/hwdep.h> | 28 | #include <sound/hwdep.h> |
29 | #include <sound/hdaudio.h> | ||
28 | #include <sound/hda_verbs.h> | 30 | #include <sound/hda_verbs.h> |
29 | 31 | #include <sound/hda_regmap.h> | |
30 | /* | ||
31 | * generic arrays | ||
32 | */ | ||
33 | struct snd_array { | ||
34 | unsigned int used; | ||
35 | unsigned int alloced; | ||
36 | unsigned int elem_size; | ||
37 | unsigned int alloc_align; | ||
38 | void *list; | ||
39 | }; | ||
40 | |||
41 | void *snd_array_new(struct snd_array *array); | ||
42 | void snd_array_free(struct snd_array *array); | ||
43 | static inline void snd_array_init(struct snd_array *array, unsigned int size, | ||
44 | unsigned int align) | ||
45 | { | ||
46 | array->elem_size = size; | ||
47 | array->alloc_align = align; | ||
48 | } | ||
49 | |||
50 | static inline void *snd_array_elem(struct snd_array *array, unsigned int idx) | ||
51 | { | ||
52 | return array->list + idx * array->elem_size; | ||
53 | } | ||
54 | |||
55 | static inline unsigned int snd_array_index(struct snd_array *array, void *ptr) | ||
56 | { | ||
57 | return (unsigned long)(ptr - array->list) / array->elem_size; | ||
58 | } | ||
59 | 32 | ||
60 | /* | 33 | /* |
61 | * Structures | 34 | * Structures |
@@ -66,10 +39,6 @@ struct hda_beep; | |||
66 | struct hda_codec; | 39 | struct hda_codec; |
67 | struct hda_pcm; | 40 | struct hda_pcm; |
68 | struct hda_pcm_stream; | 41 | struct hda_pcm_stream; |
69 | struct hda_bus_unsolicited; | ||
70 | |||
71 | /* NID type */ | ||
72 | typedef u16 hda_nid_t; | ||
73 | 42 | ||
74 | /* bus operators */ | 43 | /* bus operators */ |
75 | struct hda_bus_ops { | 44 | struct hda_bus_ops { |
@@ -84,10 +53,6 @@ struct hda_bus_ops { | |||
84 | struct hda_pcm *pcm); | 53 | struct hda_pcm *pcm); |
85 | /* reset bus for retry verb */ | 54 | /* reset bus for retry verb */ |
86 | void (*bus_reset)(struct hda_bus *bus); | 55 | 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 | 56 | #ifdef CONFIG_SND_HDA_DSP_LOADER |
92 | /* prepare DSP transfer */ | 57 | /* prepare DSP transfer */ |
93 | int (*load_dsp_prepare)(struct hda_bus *bus, unsigned int format, | 58 | int (*load_dsp_prepare)(struct hda_bus *bus, unsigned int format, |
@@ -101,15 +66,6 @@ struct hda_bus_ops { | |||
101 | #endif | 66 | #endif |
102 | }; | 67 | }; |
103 | 68 | ||
104 | /* template to pass to the bus constructor */ | ||
105 | struct hda_bus_template { | ||
106 | void *private_data; | ||
107 | struct pci_dev *pci; | ||
108 | const char *modelname; | ||
109 | int *power_save; | ||
110 | struct hda_bus_ops ops; | ||
111 | }; | ||
112 | |||
113 | /* | 69 | /* |
114 | * codec bus | 70 | * codec bus |
115 | * | 71 | * |
@@ -117,42 +73,28 @@ struct hda_bus_template { | |||
117 | * A hda_bus contains several codecs in the list codec_list. | 73 | * A hda_bus contains several codecs in the list codec_list. |
118 | */ | 74 | */ |
119 | struct hda_bus { | 75 | struct hda_bus { |
76 | struct hdac_bus core; | ||
77 | |||
120 | struct snd_card *card; | 78 | struct snd_card *card; |
121 | 79 | ||
122 | /* copied from template */ | ||
123 | void *private_data; | 80 | void *private_data; |
124 | struct pci_dev *pci; | 81 | struct pci_dev *pci; |
125 | const char *modelname; | 82 | const char *modelname; |
126 | int *power_save; | ||
127 | struct hda_bus_ops ops; | 83 | struct hda_bus_ops ops; |
128 | 84 | ||
129 | /* codec linked list */ | ||
130 | struct list_head codec_list; | ||
131 | unsigned int num_codecs; | ||
132 | /* link caddr -> codec */ | ||
133 | struct hda_codec *caddr_tbl[HDA_MAX_CODEC_ADDRESS + 1]; | ||
134 | |||
135 | struct mutex cmd_mutex; | ||
136 | struct mutex prepare_mutex; | 85 | struct mutex prepare_mutex; |
137 | 86 | ||
138 | /* unsolicited event queue */ | ||
139 | struct hda_bus_unsolicited *unsol; | ||
140 | char workq_name[16]; | ||
141 | struct workqueue_struct *workq; /* common workqueue for codecs */ | ||
142 | |||
143 | /* assigned PCMs */ | 87 | /* assigned PCMs */ |
144 | DECLARE_BITMAP(pcm_dev_bits, SNDRV_PCM_DEVICES); | 88 | DECLARE_BITMAP(pcm_dev_bits, SNDRV_PCM_DEVICES); |
145 | 89 | ||
146 | /* misc op flags */ | 90 | /* misc op flags */ |
147 | unsigned int needs_damn_long_delay :1; | 91 | unsigned int needs_damn_long_delay :1; |
148 | unsigned int allow_bus_reset:1; /* allow bus reset at fatal error */ | 92 | unsigned int allow_bus_reset:1; /* allow bus reset at fatal error */ |
149 | unsigned int sync_write:1; /* sync after verb write */ | ||
150 | /* status for codec/controller */ | 93 | /* status for codec/controller */ |
151 | unsigned int shutdown :1; /* being unloaded */ | 94 | unsigned int shutdown :1; /* being unloaded */ |
152 | unsigned int rirb_error:1; /* error in codec communication */ | 95 | unsigned int rirb_error:1; /* error in codec communication */ |
153 | unsigned int response_reset:1; /* controller was reset */ | 96 | unsigned int response_reset:1; /* controller was reset */ |
154 | unsigned int in_reset:1; /* during reset operation */ | 97 | 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 */ | 98 | unsigned int no_response_fallback:1; /* don't fallback at RIRB error */ |
157 | 99 | ||
158 | int primary_dig_out_type; /* primary digital out PCM type */ | 100 | int primary_dig_out_type; /* primary digital out PCM type */ |
@@ -175,15 +117,22 @@ struct hda_codec_preset { | |||
175 | int (*patch)(struct hda_codec *codec); | 117 | int (*patch)(struct hda_codec *codec); |
176 | }; | 118 | }; |
177 | 119 | ||
178 | struct hda_codec_preset_list { | 120 | #define HDA_CODEC_ID_GENERIC_HDMI 0x00000101 |
121 | #define HDA_CODEC_ID_GENERIC 0x00000201 | ||
122 | |||
123 | struct hda_codec_driver { | ||
124 | struct hdac_driver core; | ||
179 | const struct hda_codec_preset *preset; | 125 | const struct hda_codec_preset *preset; |
180 | struct module *owner; | ||
181 | struct list_head list; | ||
182 | }; | 126 | }; |
183 | 127 | ||
184 | /* initial hook */ | 128 | int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name, |
185 | int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset); | 129 | struct module *owner); |
186 | int snd_hda_delete_codec_preset(struct hda_codec_preset_list *preset); | 130 | #define hda_codec_driver_register(drv) \ |
131 | __hda_codec_driver_register(drv, KBUILD_MODNAME, THIS_MODULE) | ||
132 | void hda_codec_driver_unregister(struct hda_codec_driver *drv); | ||
133 | #define module_hda_codec_driver(drv) \ | ||
134 | module_driver(drv, hda_codec_driver_register, \ | ||
135 | hda_codec_driver_unregister) | ||
187 | 136 | ||
188 | /* ops set by the preset patch */ | 137 | /* ops set by the preset patch */ |
189 | struct hda_codec_ops { | 138 | struct hda_codec_ops { |
@@ -200,25 +149,7 @@ struct hda_codec_ops { | |||
200 | int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid); | 149 | int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid); |
201 | #endif | 150 | #endif |
202 | void (*reboot_notify)(struct hda_codec *codec); | 151 | void (*reboot_notify)(struct hda_codec *codec); |
203 | }; | 152 | void (*stream_pm)(struct hda_codec *codec, hda_nid_t nid, bool on); |
204 | |||
205 | /* record for amp information cache */ | ||
206 | struct hda_cache_head { | ||
207 | u32 key:31; /* hash key */ | ||
208 | u32 dirty:1; | ||
209 | u16 val; /* assigned value */ | ||
210 | u16 next; | ||
211 | }; | ||
212 | |||
213 | struct hda_amp_info { | ||
214 | struct hda_cache_head head; | ||
215 | u32 amp_caps; /* amp capabilities */ | ||
216 | u16 vol[2]; /* current volume & mute */ | ||
217 | }; | ||
218 | |||
219 | struct hda_cache_rec { | ||
220 | u16 hash[64]; /* hash table for index */ | ||
221 | struct snd_array buf; /* record entries */ | ||
222 | }; | 153 | }; |
223 | 154 | ||
224 | /* PCM callbacks */ | 155 | /* PCM callbacks */ |
@@ -267,41 +198,29 @@ struct hda_pcm { | |||
267 | int device; /* device number to assign */ | 198 | int device; /* device number to assign */ |
268 | struct snd_pcm *pcm; /* assigned PCM instance */ | 199 | struct snd_pcm *pcm; /* assigned PCM instance */ |
269 | bool own_chmap; /* codec driver provides own channel maps */ | 200 | bool own_chmap; /* codec driver provides own channel maps */ |
201 | /* private: */ | ||
202 | struct hda_codec *codec; | ||
203 | struct kref kref; | ||
204 | struct list_head list; | ||
270 | }; | 205 | }; |
271 | 206 | ||
272 | /* codec information */ | 207 | /* codec information */ |
273 | struct hda_codec { | 208 | struct hda_codec { |
274 | struct device dev; | 209 | struct hdac_device core; |
275 | struct hda_bus *bus; | 210 | struct hda_bus *bus; |
211 | struct snd_card *card; | ||
276 | unsigned int addr; /* codec addr*/ | 212 | unsigned int addr; /* codec addr*/ |
277 | struct list_head list; /* list point */ | 213 | u32 probe_id; /* overridden id for probing */ |
278 | |||
279 | hda_nid_t afg; /* AFG node id */ | ||
280 | hda_nid_t mfg; /* MFG node id */ | ||
281 | |||
282 | /* ids */ | ||
283 | u8 afg_function_id; | ||
284 | u8 mfg_function_id; | ||
285 | u8 afg_unsol; | ||
286 | u8 mfg_unsol; | ||
287 | u32 vendor_id; | ||
288 | u32 subsystem_id; | ||
289 | u32 revision_id; | ||
290 | 214 | ||
291 | /* detected preset */ | 215 | /* detected preset */ |
292 | const struct hda_codec_preset *preset; | 216 | 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 */ | ||
296 | const char *chip_name; /* codec chip name */ | ||
297 | const char *modelname; /* model name for preset */ | 217 | const char *modelname; /* model name for preset */ |
298 | 218 | ||
299 | /* set by patch */ | 219 | /* set by patch */ |
300 | struct hda_codec_ops patch_ops; | 220 | struct hda_codec_ops patch_ops; |
301 | 221 | ||
302 | /* PCM to create, set by patch_ops.build_pcms callback */ | 222 | /* PCM to create, set by patch_ops.build_pcms callback */ |
303 | unsigned int num_pcms; | 223 | struct list_head pcm_list_head; |
304 | struct hda_pcm *pcm_info; | ||
305 | 224 | ||
306 | /* codec specific info */ | 225 | /* codec specific info */ |
307 | void *spec; | 226 | void *spec; |
@@ -311,21 +230,15 @@ struct hda_codec { | |||
311 | unsigned int beep_mode; | 230 | unsigned int beep_mode; |
312 | 231 | ||
313 | /* widget capabilities cache */ | 232 | /* widget capabilities cache */ |
314 | unsigned int num_nodes; | ||
315 | hda_nid_t start_nid; | ||
316 | u32 *wcaps; | 233 | u32 *wcaps; |
317 | 234 | ||
318 | struct snd_array mixers; /* list of assigned mixer elements */ | 235 | struct snd_array mixers; /* list of assigned mixer elements */ |
319 | struct snd_array nids; /* list of mapped mixer elements */ | 236 | struct snd_array nids; /* list of mapped mixer elements */ |
320 | 237 | ||
321 | struct hda_cache_rec amp_cache; /* cache for amp access */ | ||
322 | struct hda_cache_rec cmd_cache; /* cache for other commands */ | ||
323 | |||
324 | struct list_head conn_list; /* linked-list of connection-list */ | 238 | struct list_head conn_list; /* linked-list of connection-list */ |
325 | 239 | ||
326 | struct mutex spdif_mutex; | 240 | struct mutex spdif_mutex; |
327 | struct mutex control_mutex; | 241 | struct mutex control_mutex; |
328 | struct mutex hash_mutex; | ||
329 | struct snd_array spdif_out; | 242 | struct snd_array spdif_out; |
330 | unsigned int spdif_in_enable; /* SPDIF input enable? */ | 243 | unsigned int spdif_in_enable; /* SPDIF input enable? */ |
331 | const hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */ | 244 | const hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */ |
@@ -345,6 +258,8 @@ struct hda_codec { | |||
345 | #endif | 258 | #endif |
346 | 259 | ||
347 | /* misc flags */ | 260 | /* misc flags */ |
261 | unsigned int in_freeing:1; /* being released */ | ||
262 | unsigned int registered:1; /* codec was registered */ | ||
348 | unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each | 263 | unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each |
349 | * status change | 264 | * status change |
350 | * (e.g. Realtek codecs) | 265 | * (e.g. Realtek codecs) |
@@ -362,22 +277,14 @@ struct hda_codec { | |||
362 | unsigned int inv_eapd:1; /* broken h/w: inverted EAPD control */ | 277 | unsigned int inv_eapd:1; /* broken h/w: inverted EAPD control */ |
363 | unsigned int inv_jack_detect:1; /* broken h/w: inverted detection bit */ | 278 | unsigned int inv_jack_detect:1; /* broken h/w: inverted detection bit */ |
364 | unsigned int pcm_format_first:1; /* PCM format must be set first */ | 279 | unsigned int pcm_format_first:1; /* PCM format must be set first */ |
365 | unsigned int epss:1; /* supporting EPSS? */ | ||
366 | unsigned int cached_write:1; /* write only to caches */ | 280 | unsigned int cached_write:1; /* write only to caches */ |
367 | unsigned int dp_mst:1; /* support DP1.2 Multi-stream transport */ | 281 | unsigned int dp_mst:1; /* support DP1.2 Multi-stream transport */ |
368 | unsigned int dump_coef:1; /* dump processing coefs in codec proc file */ | 282 | unsigned int dump_coef:1; /* dump processing coefs in codec proc file */ |
283 | unsigned int power_save_node:1; /* advanced PM for each widget */ | ||
369 | #ifdef CONFIG_PM | 284 | #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 */ | ||
372 | unsigned int pm_up_notified:1; /* PM notified to controller */ | ||
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; | 285 | unsigned long power_on_acct; |
378 | unsigned long power_off_acct; | 286 | unsigned long power_off_acct; |
379 | unsigned long power_jiffies; | 287 | unsigned long power_jiffies; |
380 | spinlock_t power_lock; | ||
381 | #endif | 288 | #endif |
382 | 289 | ||
383 | /* filter the requested power state per nid */ | 290 | /* filter the requested power state per nid */ |
@@ -409,10 +316,11 @@ struct hda_codec { | |||
409 | struct snd_array verbs; | 316 | struct snd_array verbs; |
410 | }; | 317 | }; |
411 | 318 | ||
412 | /* direction */ | 319 | #define dev_to_hda_codec(_dev) container_of(_dev, struct hda_codec, core.dev) |
413 | enum { | 320 | #define hda_codec_dev(_dev) (&(_dev)->core.dev) |
414 | HDA_INPUT, HDA_OUTPUT | 321 | |
415 | }; | 322 | #define list_for_each_codec(c, bus) \ |
323 | list_for_each_entry(c, &(bus)->core.codec_list, core.list) | ||
416 | 324 | ||
417 | /* snd_hda_codec_read/write optional flags */ | 325 | /* snd_hda_codec_read/write optional flags */ |
418 | #define HDA_RW_NO_RESPONSE_FALLBACK (1 << 0) | 326 | #define HDA_RW_NO_RESPONSE_FALLBACK (1 << 0) |
@@ -420,10 +328,9 @@ enum { | |||
420 | /* | 328 | /* |
421 | * constructors | 329 | * constructors |
422 | */ | 330 | */ |
423 | int snd_hda_bus_new(struct snd_card *card, const struct hda_bus_template *temp, | 331 | int snd_hda_bus_new(struct snd_card *card, struct hda_bus **busp); |
424 | struct hda_bus **busp); | 332 | int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, |
425 | int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr, | 333 | unsigned int codec_addr, struct hda_codec **codecp); |
426 | struct hda_codec **codecp); | ||
427 | int snd_hda_codec_configure(struct hda_codec *codec); | 334 | int snd_hda_codec_configure(struct hda_codec *codec); |
428 | int snd_hda_codec_update_widgets(struct hda_codec *codec); | 335 | int snd_hda_codec_update_widgets(struct hda_codec *codec); |
429 | 336 | ||
@@ -436,9 +343,9 @@ unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid, | |||
436 | int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags, | 343 | int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags, |
437 | unsigned int verb, unsigned int parm); | 344 | unsigned int verb, unsigned int parm); |
438 | #define snd_hda_param_read(codec, nid, param) \ | 345 | #define snd_hda_param_read(codec, nid, param) \ |
439 | snd_hda_codec_read(codec, nid, 0, AC_VERB_PARAMETERS, param) | 346 | snd_hdac_read_parm(&(codec)->core, nid, param) |
440 | int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid, | 347 | #define snd_hda_get_sub_nodes(codec, nid, start_nid) \ |
441 | hda_nid_t *start_id); | 348 | snd_hdac_get_sub_nodes(&(codec)->core, nid, start_nid) |
442 | int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, | 349 | int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, |
443 | hda_nid_t *conn_list, int max_conns); | 350 | hda_nid_t *conn_list, int max_conns); |
444 | static inline int | 351 | static inline int |
@@ -446,9 +353,12 @@ snd_hda_get_num_conns(struct hda_codec *codec, hda_nid_t nid) | |||
446 | { | 353 | { |
447 | return snd_hda_get_connections(codec, nid, NULL, 0); | 354 | return snd_hda_get_connections(codec, nid, NULL, 0); |
448 | } | 355 | } |
449 | int snd_hda_get_num_raw_conns(struct hda_codec *codec, hda_nid_t nid); | 356 | |
450 | int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid, | 357 | #define snd_hda_get_raw_connections(codec, nid, list, max_conns) \ |
451 | hda_nid_t *conn_list, int max_conns); | 358 | snd_hdac_get_connections(&(codec)->core, nid, list, max_conns) |
359 | #define snd_hda_get_num_raw_conns(codec, nid) \ | ||
360 | snd_hdac_get_connections(&(codec)->core, nid, NULL, 0); | ||
361 | |||
452 | int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, | 362 | int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, |
453 | const hda_nid_t **listp); | 363 | const hda_nid_t **listp); |
454 | int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums, | 364 | int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums, |
@@ -470,18 +380,22 @@ void snd_hda_sequence_write(struct hda_codec *codec, | |||
470 | const struct hda_verb *seq); | 380 | const struct hda_verb *seq); |
471 | 381 | ||
472 | /* unsolicited event */ | 382 | /* unsolicited event */ |
473 | int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex); | 383 | static inline void |
384 | snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex) | ||
385 | { | ||
386 | snd_hdac_bus_queue_event(&bus->core, res, res_ex); | ||
387 | } | ||
474 | 388 | ||
475 | /* cached write */ | 389 | /* cached write */ |
476 | int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, | 390 | static inline int |
477 | int flags, unsigned int verb, unsigned int parm); | 391 | snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, |
478 | void snd_hda_sequence_write_cache(struct hda_codec *codec, | 392 | int flags, unsigned int verb, unsigned int parm) |
479 | const struct hda_verb *seq); | 393 | { |
480 | int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid, | 394 | return snd_hdac_regmap_write(&codec->core, nid, verb, parm); |
481 | int flags, unsigned int verb, unsigned int parm); | 395 | } |
482 | void snd_hda_codec_resume_cache(struct hda_codec *codec); | 396 | |
483 | /* both for cmd & amp caches */ | 397 | #define snd_hda_codec_update_cache(codec, nid, flags, verb, parm) \ |
484 | void snd_hda_codec_flush_cache(struct hda_codec *codec); | 398 | snd_hda_codec_write_cache(codec, nid, flags, verb, parm) |
485 | 399 | ||
486 | /* the struct for codec->pin_configs */ | 400 | /* the struct for codec->pin_configs */ |
487 | struct hda_pincfg { | 401 | struct hda_pincfg { |
@@ -512,15 +426,24 @@ void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid); | |||
512 | /* | 426 | /* |
513 | * Mixer | 427 | * Mixer |
514 | */ | 428 | */ |
515 | int snd_hda_build_controls(struct hda_bus *bus); | ||
516 | int snd_hda_codec_build_controls(struct hda_codec *codec); | 429 | int snd_hda_codec_build_controls(struct hda_codec *codec); |
517 | 430 | ||
518 | /* | 431 | /* |
519 | * PCM | 432 | * PCM |
520 | */ | 433 | */ |
521 | int snd_hda_build_pcms(struct hda_bus *bus); | 434 | int snd_hda_codec_parse_pcms(struct hda_codec *codec); |
522 | int snd_hda_codec_build_pcms(struct hda_codec *codec); | 435 | int snd_hda_codec_build_pcms(struct hda_codec *codec); |
523 | 436 | ||
437 | __printf(2, 3) | ||
438 | struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec, | ||
439 | const char *fmt, ...); | ||
440 | |||
441 | static inline void snd_hda_codec_pcm_get(struct hda_pcm *pcm) | ||
442 | { | ||
443 | kref_get(&pcm->kref); | ||
444 | } | ||
445 | void snd_hda_codec_pcm_put(struct hda_pcm *pcm); | ||
446 | |||
524 | int snd_hda_codec_prepare(struct hda_codec *codec, | 447 | int snd_hda_codec_prepare(struct hda_codec *codec, |
525 | struct hda_pcm_stream *hinfo, | 448 | struct hda_pcm_stream *hinfo, |
526 | unsigned int stream, | 449 | unsigned int stream, |
@@ -552,20 +475,17 @@ extern const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[]; | |||
552 | * Misc | 475 | * Misc |
553 | */ | 476 | */ |
554 | void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen); | 477 | void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen); |
555 | void snd_hda_bus_reboot_notify(struct hda_bus *bus); | ||
556 | void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, | 478 | void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, |
557 | unsigned int power_state); | 479 | unsigned int power_state); |
558 | 480 | ||
559 | int snd_hda_lock_devices(struct hda_bus *bus); | 481 | int snd_hda_lock_devices(struct hda_bus *bus); |
560 | void snd_hda_unlock_devices(struct hda_bus *bus); | 482 | void snd_hda_unlock_devices(struct hda_bus *bus); |
483 | void snd_hda_bus_reset(struct hda_bus *bus); | ||
561 | 484 | ||
562 | /* | 485 | /* |
563 | * power management | 486 | * power management |
564 | */ | 487 | */ |
565 | #ifdef CONFIG_PM | 488 | extern const struct dev_pm_ops hda_codec_driver_pm; |
566 | int snd_hda_suspend(struct hda_bus *bus); | ||
567 | int snd_hda_resume(struct hda_bus *bus); | ||
568 | #endif | ||
569 | 489 | ||
570 | static inline | 490 | static inline |
571 | int hda_call_check_power_status(struct hda_codec *codec, hda_nid_t nid) | 491 | int hda_call_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
@@ -587,65 +507,17 @@ const char *snd_hda_get_jack_location(u32 cfg); | |||
587 | /* | 507 | /* |
588 | * power saving | 508 | * power saving |
589 | */ | 509 | */ |
510 | #define snd_hda_power_up(codec) snd_hdac_power_up(&(codec)->core) | ||
511 | #define snd_hda_power_up_pm(codec) snd_hdac_power_up_pm(&(codec)->core) | ||
512 | #define snd_hda_power_down(codec) snd_hdac_power_down(&(codec)->core) | ||
513 | #define snd_hda_power_down_pm(codec) snd_hdac_power_down_pm(&(codec)->core) | ||
590 | #ifdef CONFIG_PM | 514 | #ifdef CONFIG_PM |
591 | void snd_hda_power_save(struct hda_codec *codec, int delta, bool d3wait); | 515 | void snd_hda_set_power_save(struct hda_bus *bus, int delay); |
592 | void snd_hda_update_power_acct(struct hda_codec *codec); | 516 | void snd_hda_update_power_acct(struct hda_codec *codec); |
593 | #else | 517 | #else |
594 | static inline void snd_hda_power_save(struct hda_codec *codec, int delta, | 518 | static inline void snd_hda_set_power_save(struct hda_bus *bus, int delay) {} |
595 | bool d3wait) {} | ||
596 | #endif | 519 | #endif |
597 | 520 | ||
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 | */ | ||
605 | static 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 | */ | ||
620 | static 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 | */ | ||
632 | static 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 | */ | ||
644 | static 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 | 521 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
650 | /* | 522 | /* |
651 | * patch firmware | 523 | * patch firmware |
diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index 17c2637d842c..26ce990592a0 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 | ||
260 | static inline struct hda_pcm_stream * | ||
261 | to_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 | |||
262 | static u64 azx_adjust_codec_delay(struct snd_pcm_substream *substream, | 267 | static 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, | |||
399 | static int azx_pcm_close(struct snd_pcm_substream *substream) | 404 | static 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 | ||
735 | static int azx_get_wallclock_tstamp(struct snd_pcm_substream *substream, | 742 | static 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 = { | |||
775 | static int azx_pcm_open(struct snd_pcm_substream *substream) | 798 | static 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 | ||
861 | static int azx_pcm_mmap(struct snd_pcm_substream *substream, | 895 | static 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 | */ |
953 | static int azx_alloc_cmd_io(struct azx *chip) | 985 | static 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 | ||
965 | static void azx_init_cmd_io(struct azx *chip) | 992 | static void azx_init_cmd_io(struct azx *chip) |
@@ -1445,7 +1472,6 @@ static void azx_load_dsp_cleanup(struct hda_bus *bus, | |||
1445 | int azx_alloc_stream_pages(struct azx *chip) | 1472 | int 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 |
@@ -1742,12 +1764,12 @@ static int probe_codec(struct azx *chip, int addr) | |||
1742 | (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID; | 1764 | (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID; |
1743 | unsigned int res; | 1765 | unsigned int res; |
1744 | 1766 | ||
1745 | mutex_lock(&chip->bus->cmd_mutex); | 1767 | mutex_lock(&chip->bus->core.cmd_mutex); |
1746 | chip->probing = 1; | 1768 | chip->probing = 1; |
1747 | azx_send_cmd(chip->bus, cmd); | 1769 | azx_send_cmd(chip->bus, cmd); |
1748 | res = azx_get_response(chip->bus, addr); | 1770 | res = azx_get_response(chip->bus, addr); |
1749 | chip->probing = 0; | 1771 | chip->probing = 0; |
1750 | mutex_unlock(&chip->bus->cmd_mutex); | 1772 | mutex_unlock(&chip->bus->core.cmd_mutex); |
1751 | if (res == -1) | 1773 | if (res == -1) |
1752 | return -EIO; | 1774 | return -EIO; |
1753 | dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr); | 1775 | dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr); |
@@ -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 */ | ||
1778 | static 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 | |||
1792 | static int get_jackpoll_interval(struct azx *chip) | 1791 | static 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 */ | 1812 | static struct hda_bus_ops bus_ops = { |
1814 | int 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 */ | ||
1825 | int 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->core.sync_write = 1; | ||
1852 | bus->allow_bus_reset = 1; | ||
1846 | } | 1853 | } |
1847 | 1854 | ||
1855 | return 0; | ||
1856 | } | ||
1857 | EXPORT_SYMBOL_GPL(azx_bus_create); | ||
1858 | |||
1859 | /* Probe codecs */ | ||
1860 | int 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,26 +1907,19 @@ int azx_codec_create(struct azx *chip, const char *model, | |||
1900 | } | 1907 | } |
1901 | return 0; | 1908 | return 0; |
1902 | } | 1909 | } |
1903 | EXPORT_SYMBOL_GPL(azx_codec_create); | 1910 | EXPORT_SYMBOL_GPL(azx_probe_codecs); |
1904 | 1911 | ||
1905 | /* configure each codec instance */ | 1912 | /* configure each codec instance */ |
1906 | int azx_codec_configure(struct azx *chip) | 1913 | int azx_codec_configure(struct azx *chip) |
1907 | { | 1914 | { |
1908 | struct hda_codec *codec; | 1915 | struct hda_codec *codec; |
1909 | list_for_each_entry(codec, &chip->bus->codec_list, list) { | 1916 | list_for_each_codec(codec, chip->bus) { |
1910 | snd_hda_codec_configure(codec); | 1917 | snd_hda_codec_configure(codec); |
1911 | } | 1918 | } |
1912 | return 0; | 1919 | return 0; |
1913 | } | 1920 | } |
1914 | EXPORT_SYMBOL_GPL(azx_codec_configure); | 1921 | EXPORT_SYMBOL_GPL(azx_codec_configure); |
1915 | 1922 | ||
1916 | /* mixer creation - all stuff is implemented in hda module */ | ||
1917 | int azx_mixer_create(struct azx *chip) | ||
1918 | { | ||
1919 | return snd_hda_build_controls(chip->bus); | ||
1920 | } | ||
1921 | EXPORT_SYMBOL_GPL(azx_mixer_create); | ||
1922 | |||
1923 | 1923 | ||
1924 | static bool is_input_stream(struct azx *chip, unsigned char index) | 1924 | static 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 | } |
1967 | EXPORT_SYMBOL_GPL(azx_init_stream); | 1967 | EXPORT_SYMBOL_GPL(azx_init_stream); |
1968 | 1968 | ||
1969 | /* | ||
1970 | * reboot notifier for hang-up problem at power-down | ||
1971 | */ | ||
1972 | static 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 | |||
1980 | void azx_notifier_register(struct azx *chip) | ||
1981 | { | ||
1982 | chip->reboot_notifier.notifier_call = azx_halt; | ||
1983 | register_reboot_notifier(&chip->reboot_notifier); | ||
1984 | } | ||
1985 | EXPORT_SYMBOL_GPL(azx_notifier_register); | ||
1986 | |||
1987 | void azx_notifier_unregister(struct azx *chip) | ||
1988 | { | ||
1989 | if (chip->reboot_notifier.notifier_call) | ||
1990 | unregister_reboot_notifier(&chip->reboot_notifier); | ||
1991 | } | ||
1992 | EXPORT_SYMBOL_GPL(azx_notifier_unregister); | ||
1993 | |||
1994 | MODULE_LICENSE("GPL"); | 1969 | MODULE_LICENSE("GPL"); |
1995 | MODULE_DESCRIPTION("Common HDA driver functions"); | 1970 | MODULE_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 */ | ||
88 | enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 }; | ||
89 | |||
90 | /* stream register offsets from stream base */ | ||
91 | #define AZX_REG_SD_CTL 0x00 | ||
92 | #define AZX_REG_SD_STS 0x03 | ||
93 | #define AZX_REG_SD_LPIB 0x04 | ||
94 | #define AZX_REG_SD_CBL 0x08 | ||
95 | #define AZX_REG_SD_LVI 0x0c | ||
96 | #define AZX_REG_SD_FIFOW 0x0e | ||
97 | #define AZX_REG_SD_FIFOSIZE 0x10 | ||
98 | #define AZX_REG_SD_FORMAT 0x12 | ||
99 | #define AZX_REG_SD_BDLPL 0x18 | ||
100 | #define AZX_REG_SD_BDLPU 0x1c | ||
101 | |||
102 | /* PCI space */ | ||
103 | #define AZX_PCIREG_TCSEL 0x44 | ||
104 | |||
105 | /* | ||
106 | * other constants | ||
107 | */ | ||
108 | |||
109 | /* max number of fragments - we may use more if allocating more pages for BDL */ | ||
110 | #define BDL_SIZE 4096 | ||
111 | #define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16) | ||
112 | #define AZX_MAX_FRAG 32 | ||
113 | /* max buffer size - no h/w limit, you can increase as you like */ | ||
114 | #define AZX_MAX_BUF_SIZE (1024*1024*1024) | ||
115 | |||
116 | /* RIRB int mask: overrun[2], response[0] */ | ||
117 | #define RIRB_INT_RESPONSE 0x01 | ||
118 | #define RIRB_INT_OVERRUN 0x04 | ||
119 | #define RIRB_INT_MASK 0x05 | ||
120 | |||
121 | /* STATESTS int mask: S3,SD2,SD1,SD0 */ | ||
122 | #define AZX_MAX_CODECS 8 | ||
123 | #define AZX_DEFAULT_CODECS 4 | ||
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 | |||
179 | enum { | ||
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 | |||
189 | struct 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 */ | ||
241 | struct 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 | |||
252 | struct azx; | ||
253 | |||
254 | /* Functions to read/write to hda registers. */ | ||
255 | struct hda_controller_ops { | ||
256 | /* Register Access */ | ||
257 | void (*reg_writel)(u32 value, u32 __iomem *addr); | ||
258 | u32 (*reg_readl)(u32 __iomem *addr); | ||
259 | void (*reg_writew)(u16 value, u16 __iomem *addr); | ||
260 | u16 (*reg_readw)(u16 __iomem *addr); | ||
261 | void (*reg_writeb)(u8 value, u8 __iomem *addr); | ||
262 | u8 (*reg_readb)(u8 __iomem *addr); | ||
263 | /* Disable msi if supported, PCI only */ | ||
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 | |||
282 | struct 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 | |||
290 | typedef unsigned int (*azx_get_pos_callback_t)(struct azx *, struct azx_dev *); | ||
291 | typedef int (*azx_get_delay_callback_t)(struct azx *, struct azx_dev *, unsigned int pos); | ||
292 | |||
293 | struct 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 */ |
24 | static inline struct azx_dev *get_azx_dev(struct snd_pcm_substream *substream) | 410 | static inline struct azx_dev *get_azx_dev(struct snd_pcm_substream *substream) |
@@ -43,14 +429,9 @@ void azx_enter_link_reset(struct azx *chip); | |||
43 | irqreturn_t azx_interrupt(int irq, void *dev_id); | 429 | irqreturn_t azx_interrupt(int irq, void *dev_id); |
44 | 430 | ||
45 | /* Codec interface */ | 431 | /* Codec interface */ |
46 | int azx_codec_create(struct azx *chip, const char *model, | 432 | int azx_bus_create(struct azx *chip, const char *model); |
47 | unsigned int max_slots, | 433 | int azx_probe_codecs(struct azx *chip, unsigned int max_slots); |
48 | int *power_save_to); | ||
49 | int azx_codec_configure(struct azx *chip); | 434 | int azx_codec_configure(struct azx *chip); |
50 | int azx_mixer_create(struct azx *chip); | ||
51 | int azx_init_stream(struct azx *chip); | 435 | int azx_init_stream(struct azx *chip); |
52 | 436 | ||
53 | void azx_notifier_register(struct azx *chip); | ||
54 | void 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..3d2597b7037b 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->core.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 */ | ||
826 | static 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 (!(get_wcaps(codec, nid) & AC_WCAP_POWER)) | ||
836 | continue; | ||
837 | if (nid == codec->core.afg) | ||
838 | continue; | ||
839 | if (!allow_powerdown || is_active_nid_for_any(codec, nid)) | ||
840 | state = AC_PWRST_D0; | ||
841 | else | ||
842 | state = AC_PWRST_D3; | ||
843 | if (!snd_hda_check_power_state(codec, nid, state)) { | ||
844 | snd_hda_codec_write(codec, nid, 0, | ||
845 | AC_VERB_SET_POWER_STATE, state); | ||
846 | changed = nid; | ||
847 | if (state == AC_PWRST_D0) | ||
848 | snd_hdac_regmap_sync_node(&codec->core, nid); | ||
849 | } | ||
850 | } | ||
851 | return changed; | ||
852 | } | ||
853 | |||
854 | /* do sync with the last power state change */ | ||
855 | static 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); | |||
853 | static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path) | 904 | static 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 | ||
@@ -1863,12 +1897,11 @@ static void debug_show_configs(struct hda_codec *codec, | |||
1863 | static void fill_all_dac_nids(struct hda_codec *codec) | 1897 | static void fill_all_dac_nids(struct hda_codec *codec) |
1864 | { | 1898 | { |
1865 | struct hda_gen_spec *spec = codec->spec; | 1899 | struct hda_gen_spec *spec = codec->spec; |
1866 | int i; | 1900 | hda_nid_t nid; |
1867 | hda_nid_t nid = codec->start_nid; | ||
1868 | 1901 | ||
1869 | spec->num_all_dacs = 0; | 1902 | spec->num_all_dacs = 0; |
1870 | memset(spec->all_dacs, 0, sizeof(spec->all_dacs)); | 1903 | memset(spec->all_dacs, 0, sizeof(spec->all_dacs)); |
1871 | for (i = 0; i < codec->num_nodes; i++, nid++) { | 1904 | for_each_hda_codec_node(nid, codec) { |
1872 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT) | 1905 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT) |
1873 | continue; | 1906 | continue; |
1874 | if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) { | 1907 | if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) { |
@@ -2998,6 +3031,7 @@ static int new_analog_input(struct hda_codec *codec, int input_idx, | |||
2998 | } | 3031 | } |
2999 | 3032 | ||
3000 | path->active = true; | 3033 | path->active = true; |
3034 | path->stream_enabled = true; /* no DAC/ADC involved */ | ||
3001 | err = add_loopback_list(spec, mix_nid, idx); | 3035 | err = add_loopback_list(spec, mix_nid, idx); |
3002 | if (err < 0) | 3036 | if (err < 0) |
3003 | return err; | 3037 | return err; |
@@ -3009,6 +3043,8 @@ static int new_analog_input(struct hda_codec *codec, int input_idx, | |||
3009 | if (path) { | 3043 | if (path) { |
3010 | print_nid_path(codec, "loopback-merge", path); | 3044 | print_nid_path(codec, "loopback-merge", path); |
3011 | path->active = true; | 3045 | path->active = true; |
3046 | path->pin_fixed = true; /* static route */ | ||
3047 | path->stream_enabled = true; /* no DAC/ADC involved */ | ||
3012 | spec->loopback_merge_path = | 3048 | spec->loopback_merge_path = |
3013 | snd_hda_get_path_idx(codec, path); | 3049 | snd_hda_get_path_idx(codec, path); |
3014 | } | 3050 | } |
@@ -3030,10 +3066,9 @@ static int fill_adc_nids(struct hda_codec *codec) | |||
3030 | hda_nid_t nid; | 3066 | hda_nid_t nid; |
3031 | hda_nid_t *adc_nids = spec->adc_nids; | 3067 | hda_nid_t *adc_nids = spec->adc_nids; |
3032 | int max_nums = ARRAY_SIZE(spec->adc_nids); | 3068 | int max_nums = ARRAY_SIZE(spec->adc_nids); |
3033 | int i, nums = 0; | 3069 | int nums = 0; |
3034 | 3070 | ||
3035 | nid = codec->start_nid; | 3071 | for_each_hda_codec_node(nid, codec) { |
3036 | for (i = 0; i < codec->num_nodes; i++, nid++) { | ||
3037 | unsigned int caps = get_wcaps(codec, nid); | 3072 | unsigned int caps = get_wcaps(codec, nid); |
3038 | int type = get_wcaps_type(caps); | 3073 | int type = get_wcaps_type(caps); |
3039 | 3074 | ||
@@ -3346,11 +3381,6 @@ static int cap_put_caller(struct snd_kcontrol *kcontrol, | |||
3346 | imux = &spec->input_mux; | 3381 | imux = &spec->input_mux; |
3347 | adc_idx = kcontrol->id.index; | 3382 | adc_idx = kcontrol->id.index; |
3348 | mutex_lock(&codec->control_mutex); | 3383 | mutex_lock(&codec->control_mutex); |
3349 | /* we use the cache-only update at first since multiple input paths | ||
3350 | * may shared the same amp; by updating only caches, the redundant | ||
3351 | * writes to hardware can be reduced. | ||
3352 | */ | ||
3353 | codec->cached_write = 1; | ||
3354 | for (i = 0; i < imux->num_items; i++) { | 3384 | for (i = 0; i < imux->num_items; i++) { |
3355 | path = get_input_path(codec, adc_idx, i); | 3385 | path = get_input_path(codec, adc_idx, i); |
3356 | if (!path || !path->ctls[type]) | 3386 | if (!path || !path->ctls[type]) |
@@ -3358,12 +3388,9 @@ static int cap_put_caller(struct snd_kcontrol *kcontrol, | |||
3358 | kcontrol->private_value = path->ctls[type]; | 3388 | kcontrol->private_value = path->ctls[type]; |
3359 | err = func(kcontrol, ucontrol); | 3389 | err = func(kcontrol, ucontrol); |
3360 | if (err < 0) | 3390 | if (err < 0) |
3361 | goto error; | 3391 | break; |
3362 | } | 3392 | } |
3363 | error: | ||
3364 | codec->cached_write = 0; | ||
3365 | mutex_unlock(&codec->control_mutex); | 3393 | mutex_unlock(&codec->control_mutex); |
3366 | snd_hda_codec_flush_cache(codec); /* flush the updates */ | ||
3367 | if (err >= 0 && spec->cap_sync_hook) | 3394 | if (err >= 0 && spec->cap_sync_hook) |
3368 | spec->cap_sync_hook(codec, kcontrol, ucontrol); | 3395 | spec->cap_sync_hook(codec, kcontrol, ucontrol); |
3369 | return err; | 3396 | return err; |
@@ -3810,6 +3837,7 @@ static void parse_digital(struct hda_codec *codec) | |||
3810 | continue; | 3837 | continue; |
3811 | print_nid_path(codec, "digout", path); | 3838 | print_nid_path(codec, "digout", path); |
3812 | path->active = true; | 3839 | path->active = true; |
3840 | path->pin_fixed = true; /* no jack detection */ | ||
3813 | spec->digout_paths[i] = snd_hda_get_path_idx(codec, path); | 3841 | spec->digout_paths[i] = snd_hda_get_path_idx(codec, path); |
3814 | set_pin_target(codec, pin, PIN_OUT, false); | 3842 | set_pin_target(codec, pin, PIN_OUT, false); |
3815 | if (!nums) { | 3843 | if (!nums) { |
@@ -3826,8 +3854,7 @@ static void parse_digital(struct hda_codec *codec) | |||
3826 | 3854 | ||
3827 | if (spec->autocfg.dig_in_pin) { | 3855 | if (spec->autocfg.dig_in_pin) { |
3828 | pin = spec->autocfg.dig_in_pin; | 3856 | pin = spec->autocfg.dig_in_pin; |
3829 | dig_nid = codec->start_nid; | 3857 | for_each_hda_codec_node(dig_nid, codec) { |
3830 | for (i = 0; i < codec->num_nodes; i++, dig_nid++) { | ||
3831 | unsigned int wcaps = get_wcaps(codec, dig_nid); | 3858 | unsigned int wcaps = get_wcaps(codec, dig_nid); |
3832 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) | 3859 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) |
3833 | continue; | 3860 | continue; |
@@ -3837,6 +3864,7 @@ static void parse_digital(struct hda_codec *codec) | |||
3837 | if (path) { | 3864 | if (path) { |
3838 | print_nid_path(codec, "digin", path); | 3865 | print_nid_path(codec, "digin", path); |
3839 | path->active = true; | 3866 | path->active = true; |
3867 | path->pin_fixed = true; /* no jack */ | ||
3840 | spec->dig_in_nid = dig_nid; | 3868 | spec->dig_in_nid = dig_nid; |
3841 | spec->digin_path = snd_hda_get_path_idx(codec, path); | 3869 | spec->digin_path = snd_hda_get_path_idx(codec, path); |
3842 | set_pin_target(codec, pin, PIN_IN, false); | 3870 | set_pin_target(codec, pin, PIN_IN, false); |
@@ -3896,6 +3924,238 @@ static int mux_select(struct hda_codec *codec, unsigned int adc_idx, | |||
3896 | return 1; | 3924 | return 1; |
3897 | } | 3925 | } |
3898 | 3926 | ||
3927 | /* power up/down widgets in the all paths that match with the given NID | ||
3928 | * as terminals (either start- or endpoint) | ||
3929 | * | ||
3930 | * returns the last changed NID, or zero if unchanged. | ||
3931 | */ | ||
3932 | static hda_nid_t set_path_power(struct hda_codec *codec, hda_nid_t nid, | ||
3933 | int pin_state, int stream_state) | ||
3934 | { | ||
3935 | struct hda_gen_spec *spec = codec->spec; | ||
3936 | hda_nid_t last, changed = 0; | ||
3937 | struct nid_path *path; | ||
3938 | int n; | ||
3939 | |||
3940 | for (n = 0; n < spec->paths.used; n++) { | ||
3941 | path = snd_array_elem(&spec->paths, n); | ||
3942 | if (path->path[0] == nid || | ||
3943 | path->path[path->depth - 1] == nid) { | ||
3944 | bool pin_old = path->pin_enabled; | ||
3945 | bool stream_old = path->stream_enabled; | ||
3946 | |||
3947 | if (pin_state >= 0) | ||
3948 | path->pin_enabled = pin_state; | ||
3949 | if (stream_state >= 0) | ||
3950 | path->stream_enabled = stream_state; | ||
3951 | if ((!path->pin_fixed && path->pin_enabled != pin_old) | ||
3952 | || path->stream_enabled != stream_old) { | ||
3953 | last = path_power_update(codec, path, true); | ||
3954 | if (last) | ||
3955 | changed = last; | ||
3956 | } | ||
3957 | } | ||
3958 | } | ||
3959 | return changed; | ||
3960 | } | ||
3961 | |||
3962 | /* check the jack status for power control */ | ||
3963 | static bool detect_pin_state(struct hda_codec *codec, hda_nid_t pin) | ||
3964 | { | ||
3965 | if (!is_jack_detectable(codec, pin)) | ||
3966 | return true; | ||
3967 | return snd_hda_jack_detect_state(codec, pin) != HDA_JACK_NOT_PRESENT; | ||
3968 | } | ||
3969 | |||
3970 | /* power up/down the paths of the given pin according to the jack state; | ||
3971 | * power = 0/1 : only power up/down if it matches with the jack state, | ||
3972 | * < 0 : force power up/down to follow the jack sate | ||
3973 | * | ||
3974 | * returns the last changed NID, or zero if unchanged. | ||
3975 | */ | ||
3976 | static hda_nid_t set_pin_power_jack(struct hda_codec *codec, hda_nid_t pin, | ||
3977 | int power) | ||
3978 | { | ||
3979 | bool on; | ||
3980 | |||
3981 | if (!codec->power_save_node) | ||
3982 | return 0; | ||
3983 | |||
3984 | on = detect_pin_state(codec, pin); | ||
3985 | |||
3986 | if (power >= 0 && on != power) | ||
3987 | return 0; | ||
3988 | return set_path_power(codec, pin, on, -1); | ||
3989 | } | ||
3990 | |||
3991 | static void pin_power_callback(struct hda_codec *codec, | ||
3992 | struct hda_jack_callback *jack, | ||
3993 | bool on) | ||
3994 | { | ||
3995 | if (jack && jack->tbl->nid) | ||
3996 | sync_power_state_change(codec, | ||
3997 | set_pin_power_jack(codec, jack->tbl->nid, on)); | ||
3998 | } | ||
3999 | |||
4000 | /* callback only doing power up -- called at first */ | ||
4001 | static void pin_power_up_callback(struct hda_codec *codec, | ||
4002 | struct hda_jack_callback *jack) | ||
4003 | { | ||
4004 | pin_power_callback(codec, jack, true); | ||
4005 | } | ||
4006 | |||
4007 | /* callback only doing power down -- called at last */ | ||
4008 | static void pin_power_down_callback(struct hda_codec *codec, | ||
4009 | struct hda_jack_callback *jack) | ||
4010 | { | ||
4011 | pin_power_callback(codec, jack, false); | ||
4012 | } | ||
4013 | |||
4014 | /* set up the power up/down callbacks */ | ||
4015 | static void add_pin_power_ctls(struct hda_codec *codec, int num_pins, | ||
4016 | const hda_nid_t *pins, bool on) | ||
4017 | { | ||
4018 | int i; | ||
4019 | hda_jack_callback_fn cb = | ||
4020 | on ? pin_power_up_callback : pin_power_down_callback; | ||
4021 | |||
4022 | for (i = 0; i < num_pins && pins[i]; i++) { | ||
4023 | if (is_jack_detectable(codec, pins[i])) | ||
4024 | snd_hda_jack_detect_enable_callback(codec, pins[i], cb); | ||
4025 | else | ||
4026 | set_path_power(codec, pins[i], true, -1); | ||
4027 | } | ||
4028 | } | ||
4029 | |||
4030 | /* enabled power callback to each available I/O pin with jack detections; | ||
4031 | * the digital I/O pins are excluded because of the unreliable detectsion | ||
4032 | */ | ||
4033 | static void add_all_pin_power_ctls(struct hda_codec *codec, bool on) | ||
4034 | { | ||
4035 | struct hda_gen_spec *spec = codec->spec; | ||
4036 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
4037 | int i; | ||
4038 | |||
4039 | if (!codec->power_save_node) | ||
4040 | return; | ||
4041 | add_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins, on); | ||
4042 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) | ||
4043 | add_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins, on); | ||
4044 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) | ||
4045 | add_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins, on); | ||
4046 | for (i = 0; i < cfg->num_inputs; i++) | ||
4047 | add_pin_power_ctls(codec, 1, &cfg->inputs[i].pin, on); | ||
4048 | } | ||
4049 | |||
4050 | /* sync path power up/down with the jack states of given pins */ | ||
4051 | static void sync_pin_power_ctls(struct hda_codec *codec, int num_pins, | ||
4052 | const hda_nid_t *pins) | ||
4053 | { | ||
4054 | int i; | ||
4055 | |||
4056 | for (i = 0; i < num_pins && pins[i]; i++) | ||
4057 | if (is_jack_detectable(codec, pins[i])) | ||
4058 | set_pin_power_jack(codec, pins[i], -1); | ||
4059 | } | ||
4060 | |||
4061 | /* sync path power up/down with pins; called at init and resume */ | ||
4062 | static void sync_all_pin_power_ctls(struct hda_codec *codec) | ||
4063 | { | ||
4064 | struct hda_gen_spec *spec = codec->spec; | ||
4065 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
4066 | int i; | ||
4067 | |||
4068 | if (!codec->power_save_node) | ||
4069 | return; | ||
4070 | sync_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins); | ||
4071 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) | ||
4072 | sync_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins); | ||
4073 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) | ||
4074 | sync_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins); | ||
4075 | for (i = 0; i < cfg->num_inputs; i++) | ||
4076 | sync_pin_power_ctls(codec, 1, &cfg->inputs[i].pin); | ||
4077 | } | ||
4078 | |||
4079 | /* add fake paths if not present yet */ | ||
4080 | static int add_fake_paths(struct hda_codec *codec, hda_nid_t nid, | ||
4081 | int num_pins, const hda_nid_t *pins) | ||
4082 | { | ||
4083 | struct hda_gen_spec *spec = codec->spec; | ||
4084 | struct nid_path *path; | ||
4085 | int i; | ||
4086 | |||
4087 | for (i = 0; i < num_pins; i++) { | ||
4088 | if (!pins[i]) | ||
4089 | break; | ||
4090 | if (get_nid_path(codec, nid, pins[i], 0)) | ||
4091 | continue; | ||
4092 | path = snd_array_new(&spec->paths); | ||
4093 | if (!path) | ||
4094 | return -ENOMEM; | ||
4095 | memset(path, 0, sizeof(*path)); | ||
4096 | path->depth = 2; | ||
4097 | path->path[0] = nid; | ||
4098 | path->path[1] = pins[i]; | ||
4099 | path->active = true; | ||
4100 | } | ||
4101 | return 0; | ||
4102 | } | ||
4103 | |||
4104 | /* create fake paths to all outputs from beep */ | ||
4105 | static int add_fake_beep_paths(struct hda_codec *codec) | ||
4106 | { | ||
4107 | struct hda_gen_spec *spec = codec->spec; | ||
4108 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
4109 | hda_nid_t nid = spec->beep_nid; | ||
4110 | int err; | ||
4111 | |||
4112 | if (!codec->power_save_node || !nid) | ||
4113 | return 0; | ||
4114 | err = add_fake_paths(codec, nid, cfg->line_outs, cfg->line_out_pins); | ||
4115 | if (err < 0) | ||
4116 | return err; | ||
4117 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) { | ||
4118 | err = add_fake_paths(codec, nid, cfg->hp_outs, cfg->hp_pins); | ||
4119 | if (err < 0) | ||
4120 | return err; | ||
4121 | } | ||
4122 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { | ||
4123 | err = add_fake_paths(codec, nid, cfg->speaker_outs, | ||
4124 | cfg->speaker_pins); | ||
4125 | if (err < 0) | ||
4126 | return err; | ||
4127 | } | ||
4128 | return 0; | ||
4129 | } | ||
4130 | |||
4131 | /* power up/down beep widget and its output paths */ | ||
4132 | static void beep_power_hook(struct hda_beep *beep, bool on) | ||
4133 | { | ||
4134 | set_path_power(beep->codec, beep->nid, -1, on); | ||
4135 | } | ||
4136 | |||
4137 | /** | ||
4138 | * snd_hda_gen_fix_pin_power - Fix the power of the given pin widget to D0 | ||
4139 | * @codec: the HDA codec | ||
4140 | * @pin: NID of pin to fix | ||
4141 | */ | ||
4142 | int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin) | ||
4143 | { | ||
4144 | struct hda_gen_spec *spec = codec->spec; | ||
4145 | struct nid_path *path; | ||
4146 | |||
4147 | path = snd_array_new(&spec->paths); | ||
4148 | if (!path) | ||
4149 | return -ENOMEM; | ||
4150 | memset(path, 0, sizeof(*path)); | ||
4151 | path->depth = 1; | ||
4152 | path->path[0] = pin; | ||
4153 | path->active = true; | ||
4154 | path->pin_fixed = true; | ||
4155 | path->stream_enabled = true; | ||
4156 | return 0; | ||
4157 | } | ||
4158 | EXPORT_SYMBOL_GPL(snd_hda_gen_fix_pin_power); | ||
3899 | 4159 | ||
3900 | /* | 4160 | /* |
3901 | * Jack detections for HP auto-mute and mic-switch | 4161 | * Jack detections for HP auto-mute and mic-switch |
@@ -3933,6 +4193,10 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins, | |||
3933 | if (!nid) | 4193 | if (!nid) |
3934 | break; | 4194 | break; |
3935 | 4195 | ||
4196 | oldval = snd_hda_codec_get_pin_target(codec, nid); | ||
4197 | if (oldval & PIN_IN) | ||
4198 | continue; /* no mute for inputs */ | ||
4199 | |||
3936 | if (spec->auto_mute_via_amp) { | 4200 | if (spec->auto_mute_via_amp) { |
3937 | struct nid_path *path; | 4201 | struct nid_path *path; |
3938 | hda_nid_t mute_nid; | 4202 | hda_nid_t mute_nid; |
@@ -3947,29 +4211,32 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins, | |||
3947 | spec->mute_bits |= (1ULL << mute_nid); | 4211 | spec->mute_bits |= (1ULL << mute_nid); |
3948 | else | 4212 | else |
3949 | spec->mute_bits &= ~(1ULL << mute_nid); | 4213 | spec->mute_bits &= ~(1ULL << mute_nid); |
3950 | set_pin_eapd(codec, nid, !mute); | ||
3951 | continue; | 4214 | continue; |
4215 | } else { | ||
4216 | /* don't reset VREF value in case it's controlling | ||
4217 | * the amp (see alc861_fixup_asus_amp_vref_0f()) | ||
4218 | */ | ||
4219 | if (spec->keep_vref_in_automute) | ||
4220 | val = oldval & ~PIN_HP; | ||
4221 | else | ||
4222 | val = 0; | ||
4223 | if (!mute) | ||
4224 | val |= oldval; | ||
4225 | /* here we call update_pin_ctl() so that the pinctl is | ||
4226 | * changed without changing the pinctl target value; | ||
4227 | * the original target value will be still referred at | ||
4228 | * the init / resume again | ||
4229 | */ | ||
4230 | update_pin_ctl(codec, nid, val); | ||
3952 | } | 4231 | } |
3953 | 4232 | ||
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); | 4233 | set_pin_eapd(codec, nid, !mute); |
4234 | if (codec->power_save_node) { | ||
4235 | bool on = !mute; | ||
4236 | if (on) | ||
4237 | on = detect_pin_state(codec, nid); | ||
4238 | set_path_power(codec, nid, on, -1); | ||
4239 | } | ||
3973 | } | 4240 | } |
3974 | } | 4241 | } |
3975 | 4242 | ||
@@ -4436,7 +4703,11 @@ unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec, | |||
4436 | hda_nid_t nid, | 4703 | hda_nid_t nid, |
4437 | unsigned int power_state) | 4704 | unsigned int power_state) |
4438 | { | 4705 | { |
4439 | if (power_state != AC_PWRST_D0 || nid == codec->afg) | 4706 | struct hda_gen_spec *spec = codec->spec; |
4707 | |||
4708 | if (!spec->power_down_unused && !codec->power_save_node) | ||
4709 | return power_state; | ||
4710 | if (power_state != AC_PWRST_D0 || nid == codec->core.afg) | ||
4440 | return power_state; | 4711 | return power_state; |
4441 | if (get_wcaps_type(get_wcaps(codec, nid)) >= AC_WID_POWER) | 4712 | if (get_wcaps_type(get_wcaps(codec, nid)) >= AC_WID_POWER) |
4442 | return power_state; | 4713 | return power_state; |
@@ -4466,6 +4737,21 @@ static void mute_all_mixer_nid(struct hda_codec *codec, hda_nid_t mix) | |||
4466 | } | 4737 | } |
4467 | 4738 | ||
4468 | /** | 4739 | /** |
4740 | * snd_hda_gen_stream_pm - Stream power management callback | ||
4741 | * @codec: the HDA codec | ||
4742 | * @nid: audio widget | ||
4743 | * @on: power on/off flag | ||
4744 | * | ||
4745 | * Set this in patch_ops.stream_pm. Only valid with power_save_node flag. | ||
4746 | */ | ||
4747 | void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on) | ||
4748 | { | ||
4749 | if (codec->power_save_node) | ||
4750 | set_path_power(codec, nid, -1, on); | ||
4751 | } | ||
4752 | EXPORT_SYMBOL_GPL(snd_hda_gen_stream_pm); | ||
4753 | |||
4754 | /** | ||
4469 | * snd_hda_gen_parse_auto_config - Parse the given BIOS configuration and | 4755 | * snd_hda_gen_parse_auto_config - Parse the given BIOS configuration and |
4470 | * set up the hda_gen_spec | 4756 | * set up the hda_gen_spec |
4471 | * @codec: the HDA codec | 4757 | * @codec: the HDA codec |
@@ -4549,6 +4835,9 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec, | |||
4549 | if (err < 0) | 4835 | if (err < 0) |
4550 | return err; | 4836 | return err; |
4551 | 4837 | ||
4838 | /* add power-down pin callbacks at first */ | ||
4839 | add_all_pin_power_ctls(codec, false); | ||
4840 | |||
4552 | spec->const_channel_count = spec->ext_channel_count; | 4841 | spec->const_channel_count = spec->ext_channel_count; |
4553 | /* check the multiple speaker and headphone pins */ | 4842 | /* check the multiple speaker and headphone pins */ |
4554 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) | 4843 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) |
@@ -4618,6 +4907,9 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec, | |||
4618 | } | 4907 | } |
4619 | } | 4908 | } |
4620 | 4909 | ||
4910 | /* add power-up pin callbacks at last */ | ||
4911 | add_all_pin_power_ctls(codec, true); | ||
4912 | |||
4621 | /* mute all aamix input initially */ | 4913 | /* mute all aamix input initially */ |
4622 | if (spec->mixer_nid) | 4914 | if (spec->mixer_nid) |
4623 | mute_all_mixer_nid(codec, spec->mixer_nid); | 4915 | mute_all_mixer_nid(codec, spec->mixer_nid); |
@@ -4625,13 +4917,20 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec, | |||
4625 | dig_only: | 4917 | dig_only: |
4626 | parse_digital(codec); | 4918 | parse_digital(codec); |
4627 | 4919 | ||
4628 | if (spec->power_down_unused) | 4920 | if (spec->power_down_unused || codec->power_save_node) |
4629 | codec->power_filter = snd_hda_gen_path_power_filter; | 4921 | if (!codec->power_filter) |
4922 | codec->power_filter = snd_hda_gen_path_power_filter; | ||
4630 | 4923 | ||
4631 | if (!spec->no_analog && spec->beep_nid) { | 4924 | if (!spec->no_analog && spec->beep_nid) { |
4632 | err = snd_hda_attach_beep_device(codec, spec->beep_nid); | 4925 | err = snd_hda_attach_beep_device(codec, spec->beep_nid); |
4633 | if (err < 0) | 4926 | if (err < 0) |
4634 | return err; | 4927 | return err; |
4928 | if (codec->beep && codec->power_save_node) { | ||
4929 | err = add_fake_beep_paths(codec); | ||
4930 | if (err < 0) | ||
4931 | return err; | ||
4932 | codec->beep->power_hook = beep_power_hook; | ||
4933 | } | ||
4635 | } | 4934 | } |
4636 | 4935 | ||
4637 | return 1; | 4936 | return 1; |
@@ -4675,7 +4974,7 @@ int snd_hda_gen_build_controls(struct hda_codec *codec) | |||
4675 | err = snd_hda_create_dig_out_ctls(codec, | 4974 | err = snd_hda_create_dig_out_ctls(codec, |
4676 | spec->multiout.dig_out_nid, | 4975 | spec->multiout.dig_out_nid, |
4677 | spec->multiout.dig_out_nid, | 4976 | spec->multiout.dig_out_nid, |
4678 | spec->pcm_rec[1].pcm_type); | 4977 | spec->pcm_rec[1]->pcm_type); |
4679 | if (err < 0) | 4978 | if (err < 0) |
4680 | return err; | 4979 | return err; |
4681 | if (!spec->no_analog) { | 4980 | if (!spec->no_analog) { |
@@ -5137,6 +5436,33 @@ static void fill_pcm_stream_name(char *str, size_t len, const char *sfx, | |||
5137 | strlcat(str, sfx, len); | 5436 | strlcat(str, sfx, len); |
5138 | } | 5437 | } |
5139 | 5438 | ||
5439 | /* copy PCM stream info from @default_str, and override non-NULL entries | ||
5440 | * from @spec_str and @nid | ||
5441 | */ | ||
5442 | static void setup_pcm_stream(struct hda_pcm_stream *str, | ||
5443 | const struct hda_pcm_stream *default_str, | ||
5444 | const struct hda_pcm_stream *spec_str, | ||
5445 | hda_nid_t nid) | ||
5446 | { | ||
5447 | *str = *default_str; | ||
5448 | if (nid) | ||
5449 | str->nid = nid; | ||
5450 | if (spec_str) { | ||
5451 | if (spec_str->substreams) | ||
5452 | str->substreams = spec_str->substreams; | ||
5453 | if (spec_str->channels_min) | ||
5454 | str->channels_min = spec_str->channels_min; | ||
5455 | if (spec_str->channels_max) | ||
5456 | str->channels_max = spec_str->channels_max; | ||
5457 | if (spec_str->rates) | ||
5458 | str->rates = spec_str->rates; | ||
5459 | if (spec_str->formats) | ||
5460 | str->formats = spec_str->formats; | ||
5461 | if (spec_str->maxbps) | ||
5462 | str->maxbps = spec_str->maxbps; | ||
5463 | } | ||
5464 | } | ||
5465 | |||
5140 | /** | 5466 | /** |
5141 | * snd_hda_gen_build_pcms - build PCM streams based on the parsed results | 5467 | * snd_hda_gen_build_pcms - build PCM streams based on the parsed results |
5142 | * @codec: the HDA codec | 5468 | * @codec: the HDA codec |
@@ -5146,27 +5472,25 @@ static void fill_pcm_stream_name(char *str, size_t len, const char *sfx, | |||
5146 | int snd_hda_gen_build_pcms(struct hda_codec *codec) | 5472 | int snd_hda_gen_build_pcms(struct hda_codec *codec) |
5147 | { | 5473 | { |
5148 | struct hda_gen_spec *spec = codec->spec; | 5474 | struct hda_gen_spec *spec = codec->spec; |
5149 | struct hda_pcm *info = spec->pcm_rec; | 5475 | struct hda_pcm *info; |
5150 | const struct hda_pcm_stream *p; | ||
5151 | bool have_multi_adcs; | 5476 | bool have_multi_adcs; |
5152 | 5477 | ||
5153 | codec->num_pcms = 1; | ||
5154 | codec->pcm_info = info; | ||
5155 | |||
5156 | if (spec->no_analog) | 5478 | if (spec->no_analog) |
5157 | goto skip_analog; | 5479 | goto skip_analog; |
5158 | 5480 | ||
5159 | fill_pcm_stream_name(spec->stream_name_analog, | 5481 | fill_pcm_stream_name(spec->stream_name_analog, |
5160 | sizeof(spec->stream_name_analog), | 5482 | sizeof(spec->stream_name_analog), |
5161 | " Analog", codec->chip_name); | 5483 | " Analog", codec->core.chip_name); |
5162 | info->name = spec->stream_name_analog; | 5484 | info = snd_hda_codec_pcm_new(codec, "%s", spec->stream_name_analog); |
5485 | if (!info) | ||
5486 | return -ENOMEM; | ||
5487 | spec->pcm_rec[0] = info; | ||
5163 | 5488 | ||
5164 | if (spec->multiout.num_dacs > 0) { | 5489 | if (spec->multiout.num_dacs > 0) { |
5165 | p = spec->stream_analog_playback; | 5490 | setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK], |
5166 | if (!p) | 5491 | &pcm_analog_playback, |
5167 | p = &pcm_analog_playback; | 5492 | spec->stream_analog_playback, |
5168 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; | 5493 | 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 = | 5494 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = |
5171 | spec->multiout.max_channels; | 5495 | spec->multiout.max_channels; |
5172 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT && | 5496 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT && |
@@ -5175,15 +5499,11 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) | |||
5175 | snd_pcm_2_1_chmaps; | 5499 | snd_pcm_2_1_chmaps; |
5176 | } | 5500 | } |
5177 | if (spec->num_adc_nids) { | 5501 | if (spec->num_adc_nids) { |
5178 | p = spec->stream_analog_capture; | 5502 | setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE], |
5179 | if (!p) { | 5503 | (spec->dyn_adc_switch ? |
5180 | if (spec->dyn_adc_switch) | 5504 | &dyn_adc_pcm_analog_capture : &pcm_analog_capture), |
5181 | p = &dyn_adc_pcm_analog_capture; | 5505 | spec->stream_analog_capture, |
5182 | else | 5506 | 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 | } | 5507 | } |
5188 | 5508 | ||
5189 | skip_analog: | 5509 | skip_analog: |
@@ -5191,29 +5511,27 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) | |||
5191 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { | 5511 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
5192 | fill_pcm_stream_name(spec->stream_name_digital, | 5512 | fill_pcm_stream_name(spec->stream_name_digital, |
5193 | sizeof(spec->stream_name_digital), | 5513 | sizeof(spec->stream_name_digital), |
5194 | " Digital", codec->chip_name); | 5514 | " Digital", codec->core.chip_name); |
5195 | codec->num_pcms = 2; | 5515 | info = snd_hda_codec_pcm_new(codec, "%s", |
5516 | spec->stream_name_digital); | ||
5517 | if (!info) | ||
5518 | return -ENOMEM; | ||
5196 | codec->slave_dig_outs = spec->multiout.slave_dig_outs; | 5519 | codec->slave_dig_outs = spec->multiout.slave_dig_outs; |
5197 | info = spec->pcm_rec + 1; | 5520 | spec->pcm_rec[1] = info; |
5198 | info->name = spec->stream_name_digital; | ||
5199 | if (spec->dig_out_type) | 5521 | if (spec->dig_out_type) |
5200 | info->pcm_type = spec->dig_out_type; | 5522 | info->pcm_type = spec->dig_out_type; |
5201 | else | 5523 | else |
5202 | info->pcm_type = HDA_PCM_TYPE_SPDIF; | 5524 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
5203 | if (spec->multiout.dig_out_nid) { | 5525 | if (spec->multiout.dig_out_nid) |
5204 | p = spec->stream_digital_playback; | 5526 | setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK], |
5205 | if (!p) | 5527 | &pcm_digital_playback, |
5206 | p = &pcm_digital_playback; | 5528 | spec->stream_digital_playback, |
5207 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; | 5529 | spec->multiout.dig_out_nid); |
5208 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; | 5530 | if (spec->dig_in_nid) |
5209 | } | 5531 | setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE], |
5210 | if (spec->dig_in_nid) { | 5532 | &pcm_digital_capture, |
5211 | p = spec->stream_digital_capture; | 5533 | spec->stream_digital_capture, |
5212 | if (!p) | 5534 | 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 | } | 5535 | } |
5218 | 5536 | ||
5219 | if (spec->no_analog) | 5537 | if (spec->no_analog) |
@@ -5228,35 +5546,30 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) | |||
5228 | if (spec->alt_dac_nid || have_multi_adcs) { | 5546 | if (spec->alt_dac_nid || have_multi_adcs) { |
5229 | fill_pcm_stream_name(spec->stream_name_alt_analog, | 5547 | fill_pcm_stream_name(spec->stream_name_alt_analog, |
5230 | sizeof(spec->stream_name_alt_analog), | 5548 | sizeof(spec->stream_name_alt_analog), |
5231 | " Alt Analog", codec->chip_name); | 5549 | " Alt Analog", codec->core.chip_name); |
5232 | codec->num_pcms = 3; | 5550 | info = snd_hda_codec_pcm_new(codec, "%s", |
5233 | info = spec->pcm_rec + 2; | 5551 | spec->stream_name_alt_analog); |
5234 | info->name = spec->stream_name_alt_analog; | 5552 | if (!info) |
5235 | if (spec->alt_dac_nid) { | 5553 | return -ENOMEM; |
5236 | p = spec->stream_analog_alt_playback; | 5554 | spec->pcm_rec[2] = info; |
5237 | if (!p) | 5555 | if (spec->alt_dac_nid) |
5238 | p = &pcm_analog_alt_playback; | 5556 | setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK], |
5239 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; | 5557 | &pcm_analog_alt_playback, |
5240 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | 5558 | spec->stream_analog_alt_playback, |
5241 | spec->alt_dac_nid; | 5559 | spec->alt_dac_nid); |
5242 | } else { | 5560 | else |
5243 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = | 5561 | setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK], |
5244 | pcm_null_stream; | 5562 | &pcm_null_stream, NULL, 0); |
5245 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0; | ||
5246 | } | ||
5247 | if (have_multi_adcs) { | 5563 | if (have_multi_adcs) { |
5248 | p = spec->stream_analog_alt_capture; | 5564 | setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE], |
5249 | if (!p) | 5565 | &pcm_analog_alt_capture, |
5250 | p = &pcm_analog_alt_capture; | 5566 | spec->stream_analog_alt_capture, |
5251 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; | 5567 | 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 = | 5568 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = |
5255 | spec->num_adc_nids - 1; | 5569 | spec->num_adc_nids - 1; |
5256 | } else { | 5570 | } else { |
5257 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | 5571 | setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE], |
5258 | pcm_null_stream; | 5572 | &pcm_null_stream, NULL, 0); |
5259 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0; | ||
5260 | } | 5573 | } |
5261 | } | 5574 | } |
5262 | 5575 | ||
@@ -5452,8 +5765,6 @@ int snd_hda_gen_init(struct hda_codec *codec) | |||
5452 | 5765 | ||
5453 | snd_hda_apply_verbs(codec); | 5766 | snd_hda_apply_verbs(codec); |
5454 | 5767 | ||
5455 | codec->cached_write = 1; | ||
5456 | |||
5457 | init_multi_out(codec); | 5768 | init_multi_out(codec); |
5458 | init_extra_out(codec); | 5769 | init_extra_out(codec); |
5459 | init_multi_io(codec); | 5770 | init_multi_io(codec); |
@@ -5464,10 +5775,12 @@ 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 | ||
5470 | snd_hda_codec_flush_cache(codec); | 5783 | regcache_sync(codec->core.regmap); |
5471 | 5784 | ||
5472 | if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook) | 5785 | if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook) |
5473 | snd_hda_sync_vmaster_hook(&spec->vmaster_mute); | 5786 | snd_hda_sync_vmaster_hook(&spec->vmaster_mute); |
@@ -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 | */ |
5533 | int snd_hda_parse_generic_codec(struct hda_codec *codec) | 5844 | static 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 | } |
5559 | EXPORT_SYMBOL_GPL(snd_hda_parse_generic_codec); | 5870 | |
5871 | static 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 | |||
5876 | static struct hda_codec_driver generic_driver = { | ||
5877 | .preset = snd_hda_preset_generic, | ||
5878 | }; | ||
5879 | |||
5880 | module_hda_codec_driver(generic_driver); | ||
5560 | 5881 | ||
5561 | MODULE_LICENSE("GPL"); | 5882 | MODULE_LICENSE("GPL"); |
5562 | MODULE_DESCRIPTION("Generic HD-audio codec parser"); | 5883 | MODULE_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); | |||
340 | unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec, | 343 | unsigned 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); |
346 | void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on); | ||
347 | int 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 a8a1e14272a1..e1c210515581 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 | ||
176 | static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT; | 175 | static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT; |
177 | static int *power_save_addr = &power_save; | ||
178 | module_param(power_save, xint, 0644); | 176 | module_param(power_save, xint, 0644); |
179 | MODULE_PARM_DESC(power_save, "Automatic power-saving timeout " | 177 | MODULE_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; | |||
187 | module_param(power_save_controller, bool, 0644); | 185 | module_param(power_save_controller, bool, 0644); |
188 | MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode."); | 186 | MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode."); |
189 | #else | 187 | #else |
190 | static int *power_save_addr; | 188 | #define power_save 0 |
191 | #endif /* CONFIG_PM */ | 189 | #endif /* CONFIG_PM */ |
192 | 190 | ||
193 | static int align_buffer_size = -1; | 191 | static int align_buffer_size = -1; |
@@ -299,8 +297,12 @@ enum { | |||
299 | AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_POWERWELL |\ | 297 | AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_POWERWELL |\ |
300 | AZX_DCAPS_SNOOP_TYPE(SCH)) | 298 | AZX_DCAPS_SNOOP_TYPE(SCH)) |
301 | 299 | ||
300 | #define AZX_DCAPS_INTEL_BRASWELL \ | ||
301 | (AZX_DCAPS_INTEL_PCH | AZX_DCAPS_I915_POWERWELL) | ||
302 | |||
302 | #define AZX_DCAPS_INTEL_SKYLAKE \ | 303 | #define AZX_DCAPS_INTEL_SKYLAKE \ |
303 | (AZX_DCAPS_INTEL_PCH | AZX_DCAPS_SEPARATE_STREAM_TAG) | 304 | (AZX_DCAPS_INTEL_PCH | AZX_DCAPS_SEPARATE_STREAM_TAG |\ |
305 | AZX_DCAPS_I915_POWERWELL) | ||
304 | 306 | ||
305 | /* quirks for ATI SB / AMD Hudson */ | 307 | /* quirks for ATI SB / AMD Hudson */ |
306 | #define AZX_DCAPS_PRESET_ATI_SB \ | 308 | #define AZX_DCAPS_PRESET_ATI_SB \ |
@@ -530,10 +532,10 @@ static int azx_position_check(struct azx *chip, struct azx_dev *azx_dev) | |||
530 | if (ok == 1) { | 532 | if (ok == 1) { |
531 | azx_dev->irq_pending = 0; | 533 | azx_dev->irq_pending = 0; |
532 | return ok; | 534 | return ok; |
533 | } else if (ok == 0 && chip->bus && chip->bus->workq) { | 535 | } else if (ok == 0) { |
534 | /* bogus IRQ, process it later */ | 536 | /* bogus IRQ, process it later */ |
535 | azx_dev->irq_pending = 1; | 537 | azx_dev->irq_pending = 1; |
536 | queue_work(chip->bus->workq, &hda->irq_pending_work); | 538 | schedule_work(&hda->irq_pending_work); |
537 | } | 539 | } |
538 | return 0; | 540 | return 0; |
539 | } | 541 | } |
@@ -741,7 +743,6 @@ static int param_set_xint(const char *val, const struct kernel_param *kp) | |||
741 | { | 743 | { |
742 | struct hda_intel *hda; | 744 | struct hda_intel *hda; |
743 | struct azx *chip; | 745 | struct azx *chip; |
744 | struct hda_codec *c; | ||
745 | int prev = power_save; | 746 | int prev = power_save; |
746 | int ret = param_set_int(val, kp); | 747 | int ret = param_set_int(val, kp); |
747 | 748 | ||
@@ -753,8 +754,7 @@ static int param_set_xint(const char *val, const struct kernel_param *kp) | |||
753 | chip = &hda->chip; | 754 | chip = &hda->chip; |
754 | if (!chip->bus || chip->disabled) | 755 | if (!chip->bus || chip->disabled) |
755 | continue; | 756 | continue; |
756 | list_for_each_entry(c, &chip->bus->codec_list, list) | 757 | snd_hda_set_power_save(chip->bus, power_save * 1000); |
757 | snd_hda_power_sync(c); | ||
758 | } | 758 | } |
759 | mutex_unlock(&card_list_lock); | 759 | mutex_unlock(&card_list_lock); |
760 | return 0; | 760 | return 0; |
@@ -773,7 +773,6 @@ static int azx_suspend(struct device *dev) | |||
773 | struct snd_card *card = dev_get_drvdata(dev); | 773 | struct snd_card *card = dev_get_drvdata(dev); |
774 | struct azx *chip; | 774 | struct azx *chip; |
775 | struct hda_intel *hda; | 775 | struct hda_intel *hda; |
776 | struct azx_pcm *p; | ||
777 | 776 | ||
778 | if (!card) | 777 | if (!card) |
779 | return 0; | 778 | return 0; |
@@ -785,10 +784,6 @@ static int azx_suspend(struct device *dev) | |||
785 | 784 | ||
786 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); | 785 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
787 | azx_clear_irq_pending(chip); | 786 | 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); | 787 | azx_stop_chip(chip); |
793 | azx_enter_link_reset(chip); | 788 | azx_enter_link_reset(chip); |
794 | if (chip->irq >= 0) { | 789 | if (chip->irq >= 0) { |
@@ -831,7 +826,6 @@ static int azx_resume(struct device *dev) | |||
831 | 826 | ||
832 | azx_init_chip(chip, true); | 827 | azx_init_chip(chip, true); |
833 | 828 | ||
834 | snd_hda_resume(chip->bus); | ||
835 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); | 829 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
836 | return 0; | 830 | return 0; |
837 | } | 831 | } |
@@ -852,7 +846,7 @@ static int azx_runtime_suspend(struct device *dev) | |||
852 | if (chip->disabled || hda->init_failed) | 846 | if (chip->disabled || hda->init_failed) |
853 | return 0; | 847 | return 0; |
854 | 848 | ||
855 | if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) | 849 | if (!azx_has_pm_runtime(chip)) |
856 | return 0; | 850 | return 0; |
857 | 851 | ||
858 | /* enable controller wake up event */ | 852 | /* enable controller wake up event */ |
@@ -885,7 +879,7 @@ static int azx_runtime_resume(struct device *dev) | |||
885 | if (chip->disabled || hda->init_failed) | 879 | if (chip->disabled || hda->init_failed) |
886 | return 0; | 880 | return 0; |
887 | 881 | ||
888 | if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) | 882 | if (!azx_has_pm_runtime(chip)) |
889 | return 0; | 883 | return 0; |
890 | 884 | ||
891 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { | 885 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { |
@@ -901,10 +895,10 @@ static int azx_runtime_resume(struct device *dev) | |||
901 | 895 | ||
902 | bus = chip->bus; | 896 | bus = chip->bus; |
903 | if (status && bus) { | 897 | if (status && bus) { |
904 | list_for_each_entry(codec, &bus->codec_list, list) | 898 | list_for_each_codec(codec, bus) |
905 | if (status & (1 << codec->addr)) | 899 | if (status & (1 << codec->addr)) |
906 | queue_delayed_work(codec->bus->workq, | 900 | schedule_delayed_work(&codec->jackpoll_work, |
907 | &codec->jackpoll_work, codec->jackpoll_interval); | 901 | codec->jackpoll_interval); |
908 | } | 902 | } |
909 | 903 | ||
910 | /* disable controller Wake Up event*/ | 904 | /* disable controller Wake Up event*/ |
@@ -928,8 +922,8 @@ static int azx_runtime_idle(struct device *dev) | |||
928 | if (chip->disabled || hda->init_failed) | 922 | if (chip->disabled || hda->init_failed) |
929 | return 0; | 923 | return 0; |
930 | 924 | ||
931 | if (!power_save_controller || | 925 | if (!power_save_controller || !azx_has_pm_runtime(chip) || |
932 | !(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) | 926 | chip->bus->core.codec_powered) |
933 | return -EBUSY; | 927 | return -EBUSY; |
934 | 928 | ||
935 | return 0; | 929 | return 0; |
@@ -1071,14 +1065,11 @@ static int azx_free(struct azx *chip) | |||
1071 | struct hda_intel *hda = container_of(chip, struct hda_intel, chip); | 1065 | struct hda_intel *hda = container_of(chip, struct hda_intel, chip); |
1072 | int i; | 1066 | int i; |
1073 | 1067 | ||
1074 | if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME) | 1068 | if (azx_has_pm_runtime(chip) && chip->running) |
1075 | && chip->running) | ||
1076 | pm_runtime_get_noresume(&pci->dev); | 1069 | pm_runtime_get_noresume(&pci->dev); |
1077 | 1070 | ||
1078 | azx_del_card_list(chip); | 1071 | azx_del_card_list(chip); |
1079 | 1072 | ||
1080 | azx_notifier_unregister(chip); | ||
1081 | |||
1082 | hda->init_failed = 1; /* to be sure */ | 1073 | hda->init_failed = 1; /* to be sure */ |
1083 | complete_all(&hda->probe_wait); | 1074 | complete_all(&hda->probe_wait); |
1084 | 1075 | ||
@@ -1394,7 +1385,6 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci, | |||
1394 | 1385 | ||
1395 | hda = kzalloc(sizeof(*hda), GFP_KERNEL); | 1386 | hda = kzalloc(sizeof(*hda), GFP_KERNEL); |
1396 | if (!hda) { | 1387 | if (!hda) { |
1397 | dev_err(card->dev, "Cannot allocate hda\n"); | ||
1398 | pci_disable_device(pci); | 1388 | pci_disable_device(pci); |
1399 | return -ENOMEM; | 1389 | return -ENOMEM; |
1400 | } | 1390 | } |
@@ -1575,10 +1565,8 @@ static int azx_first_init(struct azx *chip) | |||
1575 | chip->num_streams = chip->playback_streams + chip->capture_streams; | 1565 | chip->num_streams = chip->playback_streams + chip->capture_streams; |
1576 | chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev), | 1566 | chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev), |
1577 | GFP_KERNEL); | 1567 | GFP_KERNEL); |
1578 | if (!chip->azx_dev) { | 1568 | if (!chip->azx_dev) |
1579 | dev_err(card->dev, "cannot malloc azx_dev\n"); | ||
1580 | return -ENOMEM; | 1569 | return -ENOMEM; |
1581 | } | ||
1582 | 1570 | ||
1583 | err = azx_alloc_stream_pages(chip); | 1571 | err = azx_alloc_stream_pages(chip); |
1584 | if (err < 0) | 1572 | if (err < 0) |
@@ -1615,19 +1603,6 @@ static int azx_first_init(struct azx *chip) | |||
1615 | return 0; | 1603 | return 0; |
1616 | } | 1604 | } |
1617 | 1605 | ||
1618 | static 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 | 1606 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
1632 | /* callback from request_firmware_nowait() */ | 1607 | /* callback from request_firmware_nowait() */ |
1633 | static void azx_firmware_cb(const struct firmware *fw, void *context) | 1608 | static void azx_firmware_cb(const struct firmware *fw, void *context) |
@@ -1896,12 +1871,14 @@ static int azx_probe_continue(struct azx *chip) | |||
1896 | #endif | 1871 | #endif |
1897 | 1872 | ||
1898 | /* create codec instances */ | 1873 | /* create codec instances */ |
1899 | err = azx_codec_create(chip, model[dev], | 1874 | err = azx_bus_create(chip, model[dev]); |
1900 | azx_max_codecs[chip->driver_type], | 1875 | if (err < 0) |
1901 | power_save_addr); | 1876 | goto out_free; |
1902 | 1877 | ||
1878 | err = azx_probe_codecs(chip, azx_max_codecs[chip->driver_type]); | ||
1903 | if (err < 0) | 1879 | if (err < 0) |
1904 | goto out_free; | 1880 | goto out_free; |
1881 | |||
1905 | #ifdef CONFIG_SND_HDA_PATCH_LOADER | 1882 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
1906 | if (chip->fw) { | 1883 | if (chip->fw) { |
1907 | err = snd_hda_load_patch(chip->bus, chip->fw->size, | 1884 | err = snd_hda_load_patch(chip->bus, chip->fw->size, |
@@ -1920,25 +1897,14 @@ static int azx_probe_continue(struct azx *chip) | |||
1920 | goto out_free; | 1897 | goto out_free; |
1921 | } | 1898 | } |
1922 | 1899 | ||
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); | 1900 | err = snd_card_register(chip->card); |
1934 | if (err < 0) | 1901 | if (err < 0) |
1935 | goto out_free; | 1902 | goto out_free; |
1936 | 1903 | ||
1937 | chip->running = 1; | 1904 | chip->running = 1; |
1938 | power_down_all_codecs(chip); | ||
1939 | azx_notifier_register(chip); | ||
1940 | azx_add_card_list(chip); | 1905 | azx_add_card_list(chip); |
1941 | if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME) || hda->use_vga_switcheroo) | 1906 | snd_hda_set_power_save(chip->bus, power_save * 1000); |
1907 | if (azx_has_pm_runtime(chip) || hda->use_vga_switcheroo) | ||
1942 | pm_runtime_put_noidle(&pci->dev); | 1908 | pm_runtime_put_noidle(&pci->dev); |
1943 | 1909 | ||
1944 | out_free: | 1910 | out_free: |
@@ -1956,6 +1922,18 @@ static void azx_remove(struct pci_dev *pci) | |||
1956 | snd_card_free(card); | 1922 | snd_card_free(card); |
1957 | } | 1923 | } |
1958 | 1924 | ||
1925 | static void azx_shutdown(struct pci_dev *pci) | ||
1926 | { | ||
1927 | struct snd_card *card = pci_get_drvdata(pci); | ||
1928 | struct azx *chip; | ||
1929 | |||
1930 | if (!card) | ||
1931 | return; | ||
1932 | chip = card->private_data; | ||
1933 | if (chip && chip->running) | ||
1934 | azx_stop_chip(chip); | ||
1935 | } | ||
1936 | |||
1959 | /* PCI IDs */ | 1937 | /* PCI IDs */ |
1960 | static const struct pci_device_id azx_ids[] = { | 1938 | static const struct pci_device_id azx_ids[] = { |
1961 | /* CPT */ | 1939 | /* CPT */ |
@@ -2017,7 +1995,7 @@ static const struct pci_device_id azx_ids[] = { | |||
2017 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM }, | 1995 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM }, |
2018 | /* Braswell */ | 1996 | /* Braswell */ |
2019 | { PCI_DEVICE(0x8086, 0x2284), | 1997 | { PCI_DEVICE(0x8086, 0x2284), |
2020 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, | 1998 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BRASWELL }, |
2021 | /* ICH6 */ | 1999 | /* ICH6 */ |
2022 | { PCI_DEVICE(0x8086, 0x2668), | 2000 | { PCI_DEVICE(0x8086, 0x2668), |
2023 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH }, | 2001 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH }, |
@@ -2178,6 +2156,7 @@ static struct pci_driver azx_driver = { | |||
2178 | .id_table = azx_ids, | 2156 | .id_table = azx_ids, |
2179 | .probe = azx_probe, | 2157 | .probe = azx_probe, |
2180 | .remove = azx_remove, | 2158 | .remove = azx_remove, |
2159 | .shutdown = azx_shutdown, | ||
2181 | .driver = { | 2160 | .driver = { |
2182 | .pm = AZX_PM_OPS, | 2161 | .pm = AZX_PM_OPS, |
2183 | }, | 2162 | }, |
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 | ||
22 | struct hda_intel { | 22 | struct 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..3b567f42296b 100644 --- a/sound/pci/hda/hda_local.h +++ b/sound/pci/hda/hda_local.h | |||
@@ -127,18 +127,16 @@ int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol, | |||
127 | struct snd_ctl_elem_value *ucontrol); | 127 | struct snd_ctl_elem_value *ucontrol); |
128 | #endif | 128 | #endif |
129 | /* lowlevel accessor with caching; use carefully */ | 129 | /* lowlevel accessor with caching; use carefully */ |
130 | int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, | 130 | #define snd_hda_codec_amp_read(codec, nid, ch, dir, idx) \ |
131 | int direction, int index); | 131 | snd_hdac_regmap_get_amp(&(codec)->core, nid, ch, dir, idx) |
132 | int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, | 132 | #define snd_hda_codec_amp_update(codec, nid, ch, dir, idx, mask, val) \ |
133 | int direction, int idx, int mask, int val); | 133 | snd_hdac_regmap_update_amp(&(codec)->core, nid, ch, dir, idx, mask, val) |
134 | int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, | 134 | int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, |
135 | int dir, int idx, int mask, int val); | 135 | int dir, int idx, int mask, int val); |
136 | int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, | 136 | int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, |
137 | int direction, int idx, int mask, int val); | 137 | int direction, int idx, int mask, int val); |
138 | int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid, | 138 | int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid, |
139 | int dir, int idx, int mask, int val); | 139 | int dir, int idx, int mask, int val); |
140 | void snd_hda_codec_resume_amp(struct hda_codec *codec); | ||
141 | |||
142 | void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, | 140 | void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, |
143 | unsigned int *tlv); | 141 | unsigned int *tlv); |
144 | struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, | 142 | struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, |
@@ -150,6 +148,8 @@ int __snd_hda_add_vmaster(struct hda_codec *codec, char *name, | |||
150 | #define snd_hda_add_vmaster(codec, name, tlv, slaves, suffix) \ | 148 | #define snd_hda_add_vmaster(codec, name, tlv, slaves, suffix) \ |
151 | __snd_hda_add_vmaster(codec, name, tlv, slaves, suffix, true, NULL) | 149 | __snd_hda_add_vmaster(codec, name, tlv, slaves, suffix, true, NULL) |
152 | int snd_hda_codec_reset(struct hda_codec *codec); | 150 | int snd_hda_codec_reset(struct hda_codec *codec); |
151 | void snd_hda_codec_register(struct hda_codec *codec); | ||
152 | void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec); | ||
153 | 153 | ||
154 | enum { | 154 | enum { |
155 | HDA_VMUTE_OFF, | 155 | HDA_VMUTE_OFF, |
@@ -273,29 +273,6 @@ int snd_hda_add_imux_item(struct hda_codec *codec, | |||
273 | int index, int *type_index_ret); | 273 | int index, int *type_index_ret); |
274 | 274 | ||
275 | /* | 275 | /* |
276 | * Channel mode helper | ||
277 | */ | ||
278 | struct hda_channel_mode { | ||
279 | int channels; | ||
280 | const struct hda_verb *sequence; | ||
281 | }; | ||
282 | |||
283 | int 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); | ||
287 | int 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); | ||
292 | int 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 | 276 | * Multi-channel / digital-out PCM helper |
300 | */ | 277 | */ |
301 | 278 | ||
@@ -351,12 +328,6 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, | |||
351 | struct hda_multi_out *mout); | 328 | struct hda_multi_out *mout); |
352 | 329 | ||
353 | /* | 330 | /* |
354 | * generic codec parser | ||
355 | */ | ||
356 | int snd_hda_parse_generic_codec(struct hda_codec *codec); | ||
357 | int snd_hda_parse_hdmi_codec(struct hda_codec *codec); | ||
358 | |||
359 | /* | ||
360 | * generic proc interface | 331 | * generic proc interface |
361 | */ | 332 | */ |
362 | #ifdef CONFIG_PROC_FS | 333 | #ifdef CONFIG_PROC_FS |
@@ -466,23 +437,6 @@ void snd_hda_pick_pin_fixup(struct hda_codec *codec, | |||
466 | const struct snd_hda_pin_quirk *pin_quirk, | 437 | const struct snd_hda_pin_quirk *pin_quirk, |
467 | const struct hda_fixup *fixlist); | 438 | const struct hda_fixup *fixlist); |
468 | 439 | ||
469 | |||
470 | /* | ||
471 | * unsolicited event handler | ||
472 | */ | ||
473 | |||
474 | #define HDA_UNSOL_QUEUE_SIZE 64 | ||
475 | |||
476 | struct 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 */ | 440 | /* helper macros to retrieve pin default-config values */ |
487 | #define get_defcfg_connect(cfg) \ | 441 | #define get_defcfg_connect(cfg) \ |
488 | ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT) | 442 | ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT) |
@@ -560,15 +514,18 @@ int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid); | |||
560 | int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid, | 514 | int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid, |
561 | unsigned int val); | 515 | unsigned int val); |
562 | 516 | ||
517 | #define for_each_hda_codec_node(nid, codec) \ | ||
518 | for ((nid) = (codec)->core.start_nid; (nid) < (codec)->core.end_nid; (nid)++) | ||
519 | |||
563 | /* | 520 | /* |
564 | * get widget capabilities | 521 | * get widget capabilities |
565 | */ | 522 | */ |
566 | static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid) | 523 | static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid) |
567 | { | 524 | { |
568 | if (nid < codec->start_nid || | 525 | if (nid < codec->core.start_nid || |
569 | nid >= codec->start_nid + codec->num_nodes) | 526 | nid >= codec->core.start_nid + codec->core.num_nodes) |
570 | return 0; | 527 | return 0; |
571 | return codec->wcaps[nid - codec->start_nid]; | 528 | return codec->wcaps[nid - codec->core.start_nid]; |
572 | } | 529 | } |
573 | 530 | ||
574 | /* get the widget type from widget capability bits */ | 531 | /* get the widget type from widget capability bits */ |
@@ -592,17 +549,49 @@ static inline unsigned int get_wcaps_channels(u32 wcaps) | |||
592 | static inline void snd_hda_override_wcaps(struct hda_codec *codec, | 549 | static inline void snd_hda_override_wcaps(struct hda_codec *codec, |
593 | hda_nid_t nid, u32 val) | 550 | hda_nid_t nid, u32 val) |
594 | { | 551 | { |
595 | if (nid >= codec->start_nid && | 552 | if (nid >= codec->core.start_nid && |
596 | nid < codec->start_nid + codec->num_nodes) | 553 | nid < codec->core.start_nid + codec->core.num_nodes) |
597 | codec->wcaps[nid - codec->start_nid] = val; | 554 | codec->wcaps[nid - codec->core.start_nid] = val; |
598 | } | 555 | } |
599 | 556 | ||
600 | u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction); | 557 | u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction); |
601 | int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, | 558 | int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, |
602 | unsigned int caps); | 559 | unsigned int caps); |
603 | u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid); | 560 | /** |
604 | int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid, | 561 | * snd_hda_query_pin_caps - Query PIN capabilities |
605 | unsigned int caps); | 562 | * @codec: the HD-auio codec |
563 | * @nid: the NID to query | ||
564 | * | ||
565 | * Query PIN capabilities for the given widget. | ||
566 | * Returns the obtained capability bits. | ||
567 | * | ||
568 | * When cap bits have been already read, this doesn't read again but | ||
569 | * returns the cached value. | ||
570 | */ | ||
571 | static inline u32 | ||
572 | snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid) | ||
573 | { | ||
574 | return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); | ||
575 | |||
576 | } | ||
577 | |||
578 | /** | ||
579 | * snd_hda_override_pin_caps - Override the pin capabilities | ||
580 | * @codec: the CODEC | ||
581 | * @nid: the NID to override | ||
582 | * @caps: the capability bits to set | ||
583 | * | ||
584 | * Override the cached PIN capabilitiy bits value by the given one. | ||
585 | * | ||
586 | * Returns zero if successful or a negative error code. | ||
587 | */ | ||
588 | static inline int | ||
589 | snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid, | ||
590 | unsigned int caps) | ||
591 | { | ||
592 | return snd_hdac_override_parm(&codec->core, nid, AC_PAR_PIN_CAP, caps); | ||
593 | } | ||
594 | |||
606 | bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid, | 595 | bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid, |
607 | int dir, unsigned int bits); | 596 | int dir, unsigned int bits); |
608 | 597 | ||
@@ -800,9 +789,13 @@ void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen); | |||
800 | 789 | ||
801 | /* | 790 | /* |
802 | */ | 791 | */ |
803 | #define codec_err(codec, fmt, args...) dev_err(&(codec)->dev, fmt, ##args) | 792 | #define codec_err(codec, fmt, args...) \ |
804 | #define codec_warn(codec, fmt, args...) dev_warn(&(codec)->dev, fmt, ##args) | 793 | dev_err(hda_codec_dev(codec), fmt, ##args) |
805 | #define codec_info(codec, fmt, args...) dev_info(&(codec)->dev, fmt, ##args) | 794 | #define codec_warn(codec, fmt, args...) \ |
806 | #define codec_dbg(codec, fmt, args...) dev_dbg(&(codec)->dev, fmt, ##args) | 795 | dev_warn(hda_codec_dev(codec), fmt, ##args) |
796 | #define codec_info(codec, fmt, args...) \ | ||
797 | dev_info(hda_codec_dev(codec), fmt, ##args) | ||
798 | #define codec_dbg(codec, fmt, args...) \ | ||
799 | dev_dbg(hda_codec_dev(codec), fmt, ##args) | ||
807 | 800 | ||
808 | #endif /* __SOUND_HDA_LOCAL_H */ | 801 | #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 */ | ||
85 | enum { 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 | |||
176 | enum { | ||
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 | |||
186 | struct 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 */ | ||
238 | struct 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 | |||
249 | struct azx; | ||
250 | |||
251 | /* Functions to read/write to hda registers. */ | ||
252 | struct 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 | |||
279 | struct 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 | |||
287 | typedef unsigned int (*azx_get_pos_callback_t)(struct azx *, struct azx_dev *); | ||
288 | typedef int (*azx_get_delay_callback_t)(struct azx *, struct azx_dev *, unsigned int pos); | ||
289 | |||
290 | struct 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..ee6230767c64 100644 --- a/sound/pci/hda/hda_proc.c +++ b/sound/pci/hda/hda_proc.c | |||
@@ -32,6 +32,10 @@ static int dump_coef = -1; | |||
32 | module_param(dump_coef, int, 0644); | 32 | module_param(dump_coef, int, 0644); |
33 | MODULE_PARM_DESC(dump_coef, "Dump processing coefficients in codec proc file (-1=auto, 0=disable, 1=enable)"); | 33 | MODULE_PARM_DESC(dump_coef, "Dump processing coefficients in codec proc file (-1=auto, 0=disable, 1=enable)"); |
34 | 34 | ||
35 | /* always use noncached version */ | ||
36 | #define param_read(codec, nid, parm) \ | ||
37 | snd_hdac_read_parm_uncached(&(codec)->core, nid, parm) | ||
38 | |||
35 | static char *bits_names(unsigned int bits, char *names[], int size) | 39 | static char *bits_names(unsigned int bits, char *names[], int size) |
36 | { | 40 | { |
37 | int i, n; | 41 | int i, n; |
@@ -99,10 +103,10 @@ static void print_nid_array(struct snd_info_buffer *buffer, | |||
99 | static void print_nid_pcms(struct snd_info_buffer *buffer, | 103 | static void print_nid_pcms(struct snd_info_buffer *buffer, |
100 | struct hda_codec *codec, hda_nid_t nid) | 104 | struct hda_codec *codec, hda_nid_t nid) |
101 | { | 105 | { |
102 | int pcm, type; | 106 | int type; |
103 | struct hda_pcm *cpcm; | 107 | struct hda_pcm *cpcm; |
104 | for (pcm = 0; pcm < codec->num_pcms; pcm++) { | 108 | |
105 | cpcm = &codec->pcm_info[pcm]; | 109 | list_for_each_entry(cpcm, &codec->pcm_list_head, list) { |
106 | for (type = 0; type < 2; type++) { | 110 | for (type = 0; type < 2; type++) { |
107 | if (cpcm->stream[type].nid != nid || cpcm->pcm == NULL) | 111 | if (cpcm->stream[type].nid != nid || cpcm->pcm == NULL) |
108 | continue; | 112 | continue; |
@@ -119,9 +123,8 @@ static void print_amp_caps(struct snd_info_buffer *buffer, | |||
119 | struct hda_codec *codec, hda_nid_t nid, int dir) | 123 | struct hda_codec *codec, hda_nid_t nid, int dir) |
120 | { | 124 | { |
121 | unsigned int caps; | 125 | unsigned int caps; |
122 | caps = snd_hda_param_read(codec, nid, | 126 | caps = param_read(codec, nid, dir == HDA_OUTPUT ? |
123 | dir == HDA_OUTPUT ? | 127 | AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP); |
124 | AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP); | ||
125 | if (caps == -1 || caps == 0) { | 128 | if (caps == -1 || caps == 0) { |
126 | snd_iprintf(buffer, "N/A\n"); | 129 | snd_iprintf(buffer, "N/A\n"); |
127 | return; | 130 | return; |
@@ -225,8 +228,8 @@ static void print_pcm_formats(struct snd_info_buffer *buffer, | |||
225 | static void print_pcm_caps(struct snd_info_buffer *buffer, | 228 | static void print_pcm_caps(struct snd_info_buffer *buffer, |
226 | struct hda_codec *codec, hda_nid_t nid) | 229 | struct hda_codec *codec, hda_nid_t nid) |
227 | { | 230 | { |
228 | unsigned int pcm = snd_hda_param_read(codec, nid, AC_PAR_PCM); | 231 | unsigned int pcm = param_read(codec, nid, AC_PAR_PCM); |
229 | unsigned int stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM); | 232 | unsigned int stream = param_read(codec, nid, AC_PAR_STREAM); |
230 | if (pcm == -1 || stream == -1) { | 233 | if (pcm == -1 || stream == -1) { |
231 | snd_iprintf(buffer, "N/A\n"); | 234 | snd_iprintf(buffer, "N/A\n"); |
232 | return; | 235 | return; |
@@ -273,7 +276,7 @@ static void print_pin_caps(struct snd_info_buffer *buffer, | |||
273 | static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" }; | 276 | static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" }; |
274 | unsigned int caps, val; | 277 | unsigned int caps, val; |
275 | 278 | ||
276 | caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); | 279 | caps = param_read(codec, nid, AC_PAR_PIN_CAP); |
277 | snd_iprintf(buffer, " Pincap 0x%08x:", caps); | 280 | snd_iprintf(buffer, " Pincap 0x%08x:", caps); |
278 | if (caps & AC_PINCAP_IN) | 281 | if (caps & AC_PINCAP_IN) |
279 | snd_iprintf(buffer, " IN"); | 282 | snd_iprintf(buffer, " IN"); |
@@ -289,7 +292,7 @@ static void print_pin_caps(struct snd_info_buffer *buffer, | |||
289 | snd_iprintf(buffer, " Balanced"); | 292 | snd_iprintf(buffer, " Balanced"); |
290 | if (caps & AC_PINCAP_HDMI) { | 293 | if (caps & AC_PINCAP_HDMI) { |
291 | /* Realtek uses this bit as a different meaning */ | 294 | /* Realtek uses this bit as a different meaning */ |
292 | if ((codec->vendor_id >> 16) == 0x10ec) | 295 | if ((codec->core.vendor_id >> 16) == 0x10ec) |
293 | snd_iprintf(buffer, " R/L"); | 296 | snd_iprintf(buffer, " R/L"); |
294 | else { | 297 | else { |
295 | if (caps & AC_PINCAP_HBR) | 298 | if (caps & AC_PINCAP_HBR) |
@@ -401,8 +404,7 @@ static void print_pin_ctls(struct snd_info_buffer *buffer, | |||
401 | static void print_vol_knob(struct snd_info_buffer *buffer, | 404 | static void print_vol_knob(struct snd_info_buffer *buffer, |
402 | struct hda_codec *codec, hda_nid_t nid) | 405 | struct hda_codec *codec, hda_nid_t nid) |
403 | { | 406 | { |
404 | unsigned int cap = snd_hda_param_read(codec, nid, | 407 | unsigned int cap = param_read(codec, nid, AC_PAR_VOL_KNB_CAP); |
405 | AC_PAR_VOL_KNB_CAP); | ||
406 | snd_iprintf(buffer, " Volume-Knob: delta=%d, steps=%d, ", | 408 | snd_iprintf(buffer, " Volume-Knob: delta=%d, steps=%d, ", |
407 | (cap >> 7) & 1, cap & 0x7f); | 409 | (cap >> 7) & 1, cap & 0x7f); |
408 | cap = snd_hda_codec_read(codec, nid, 0, | 410 | cap = snd_hda_codec_read(codec, nid, 0, |
@@ -487,7 +489,7 @@ static void print_power_state(struct snd_info_buffer *buffer, | |||
487 | [ilog2(AC_PWRST_EPSS)] = "EPSS", | 489 | [ilog2(AC_PWRST_EPSS)] = "EPSS", |
488 | }; | 490 | }; |
489 | 491 | ||
490 | int sup = snd_hda_param_read(codec, nid, AC_PAR_POWER_STATE); | 492 | int sup = param_read(codec, nid, AC_PAR_POWER_STATE); |
491 | int pwr = snd_hda_codec_read(codec, nid, 0, | 493 | int pwr = snd_hda_codec_read(codec, nid, 0, |
492 | AC_VERB_GET_POWER_STATE, 0); | 494 | AC_VERB_GET_POWER_STATE, 0); |
493 | if (sup != -1) | 495 | if (sup != -1) |
@@ -531,8 +533,7 @@ static void print_proc_caps(struct snd_info_buffer *buffer, | |||
531 | struct hda_codec *codec, hda_nid_t nid) | 533 | struct hda_codec *codec, hda_nid_t nid) |
532 | { | 534 | { |
533 | unsigned int i, ncoeff, oldindex; | 535 | unsigned int i, ncoeff, oldindex; |
534 | unsigned int proc_caps = snd_hda_param_read(codec, nid, | 536 | unsigned int proc_caps = param_read(codec, nid, AC_PAR_PROC_CAP); |
535 | AC_PAR_PROC_CAP); | ||
536 | ncoeff = (proc_caps & AC_PCAP_NUM_COEF) >> AC_PCAP_NUM_COEF_SHIFT; | 537 | ncoeff = (proc_caps & AC_PCAP_NUM_COEF) >> AC_PCAP_NUM_COEF_SHIFT; |
537 | snd_iprintf(buffer, " Processing caps: benign=%d, ncoeff=%d\n", | 538 | snd_iprintf(buffer, " Processing caps: benign=%d, ncoeff=%d\n", |
538 | proc_caps & AC_PCAP_BENIGN, ncoeff); | 539 | proc_caps & AC_PCAP_BENIGN, ncoeff); |
@@ -597,7 +598,7 @@ static void print_gpio(struct snd_info_buffer *buffer, | |||
597 | struct hda_codec *codec, hda_nid_t nid) | 598 | struct hda_codec *codec, hda_nid_t nid) |
598 | { | 599 | { |
599 | unsigned int gpio = | 600 | unsigned int gpio = |
600 | snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP); | 601 | param_read(codec, codec->core.afg, AC_PAR_GPIO_CAP); |
601 | unsigned int enable, direction, wake, unsol, sticky, data; | 602 | unsigned int enable, direction, wake, unsol, sticky, data; |
602 | int i, max; | 603 | int i, max; |
603 | snd_iprintf(buffer, "GPIO: io=%d, o=%d, i=%d, " | 604 | snd_iprintf(buffer, "GPIO: io=%d, o=%d, i=%d, " |
@@ -667,13 +668,9 @@ static void print_device_list(struct snd_info_buffer *buffer, | |||
667 | } | 668 | } |
668 | } | 669 | } |
669 | 670 | ||
670 | static void print_codec_info(struct snd_info_entry *entry, | 671 | static void print_codec_core_info(struct hdac_device *codec, |
671 | struct snd_info_buffer *buffer) | 672 | struct snd_info_buffer *buffer) |
672 | { | 673 | { |
673 | struct hda_codec *codec = entry->private_data; | ||
674 | hda_nid_t nid; | ||
675 | int i, nodes; | ||
676 | |||
677 | snd_iprintf(buffer, "Codec: "); | 674 | snd_iprintf(buffer, "Codec: "); |
678 | if (codec->vendor_name && codec->chip_name) | 675 | if (codec->vendor_name && codec->chip_name) |
679 | snd_iprintf(buffer, "%s %s\n", | 676 | snd_iprintf(buffer, "%s %s\n", |
@@ -695,34 +692,43 @@ static void print_codec_info(struct snd_info_entry *entry, | |||
695 | snd_iprintf(buffer, "Modem Function Group: 0x%x\n", codec->mfg); | 692 | snd_iprintf(buffer, "Modem Function Group: 0x%x\n", codec->mfg); |
696 | else | 693 | else |
697 | snd_iprintf(buffer, "No Modem Function Group found\n"); | 694 | snd_iprintf(buffer, "No Modem Function Group found\n"); |
695 | } | ||
696 | |||
697 | static void print_codec_info(struct snd_info_entry *entry, | ||
698 | struct snd_info_buffer *buffer) | ||
699 | { | ||
700 | struct hda_codec *codec = entry->private_data; | ||
701 | hda_nid_t nid, fg; | ||
702 | int i, nodes; | ||
698 | 703 | ||
699 | if (! codec->afg) | 704 | print_codec_core_info(&codec->core, buffer); |
705 | fg = codec->core.afg; | ||
706 | if (!fg) | ||
700 | return; | 707 | return; |
701 | snd_hda_power_up(codec); | 708 | snd_hda_power_up(codec); |
702 | snd_iprintf(buffer, "Default PCM:\n"); | 709 | snd_iprintf(buffer, "Default PCM:\n"); |
703 | print_pcm_caps(buffer, codec, codec->afg); | 710 | print_pcm_caps(buffer, codec, fg); |
704 | snd_iprintf(buffer, "Default Amp-In caps: "); | 711 | snd_iprintf(buffer, "Default Amp-In caps: "); |
705 | print_amp_caps(buffer, codec, codec->afg, HDA_INPUT); | 712 | print_amp_caps(buffer, codec, fg, HDA_INPUT); |
706 | snd_iprintf(buffer, "Default Amp-Out caps: "); | 713 | snd_iprintf(buffer, "Default Amp-Out caps: "); |
707 | print_amp_caps(buffer, codec, codec->afg, HDA_OUTPUT); | 714 | print_amp_caps(buffer, codec, fg, HDA_OUTPUT); |
708 | snd_iprintf(buffer, "State of AFG node 0x%02x:\n", codec->afg); | 715 | snd_iprintf(buffer, "State of AFG node 0x%02x:\n", fg); |
709 | print_power_state(buffer, codec, codec->afg); | 716 | print_power_state(buffer, codec, fg); |
710 | 717 | ||
711 | nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid); | 718 | nodes = snd_hda_get_sub_nodes(codec, fg, &nid); |
712 | if (! nid || nodes < 0) { | 719 | if (! nid || nodes < 0) { |
713 | snd_iprintf(buffer, "Invalid AFG subtree\n"); | 720 | snd_iprintf(buffer, "Invalid AFG subtree\n"); |
714 | snd_hda_power_down(codec); | 721 | snd_hda_power_down(codec); |
715 | return; | 722 | return; |
716 | } | 723 | } |
717 | 724 | ||
718 | print_gpio(buffer, codec, codec->afg); | 725 | print_gpio(buffer, codec, fg); |
719 | if (codec->proc_widget_hook) | 726 | if (codec->proc_widget_hook) |
720 | codec->proc_widget_hook(buffer, codec, codec->afg); | 727 | codec->proc_widget_hook(buffer, codec, fg); |
721 | 728 | ||
722 | for (i = 0; i < nodes; i++, nid++) { | 729 | for (i = 0; i < nodes; i++, nid++) { |
723 | unsigned int wid_caps = | 730 | unsigned int wid_caps = |
724 | snd_hda_param_read(codec, nid, | 731 | param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP); |
725 | AC_PAR_AUDIO_WIDGET_CAP); | ||
726 | unsigned int wid_type = get_wcaps_type(wid_caps); | 732 | unsigned int wid_type = get_wcaps_type(wid_caps); |
727 | hda_nid_t *conn = NULL; | 733 | hda_nid_t *conn = NULL; |
728 | int conn_len = 0; | 734 | int conn_len = 0; |
@@ -860,8 +866,8 @@ int snd_hda_codec_proc_new(struct hda_codec *codec) | |||
860 | struct snd_info_entry *entry; | 866 | struct snd_info_entry *entry; |
861 | int err; | 867 | int err; |
862 | 868 | ||
863 | snprintf(name, sizeof(name), "codec#%d", codec->addr); | 869 | snprintf(name, sizeof(name), "codec#%d", codec->core.addr); |
864 | err = snd_card_proc_new(codec->bus->card, name, &entry); | 870 | err = snd_card_proc_new(codec->card, name, &entry); |
865 | if (err < 0) | 871 | if (err < 0) |
866 | return err; | 872 | return err; |
867 | 873 | ||
diff --git a/sound/pci/hda/hda_sysfs.c b/sound/pci/hda/hda_sysfs.c index ccc962a1699f..a6e3d9b511ab 100644 --- a/sound/pci/hda/hda_sysfs.c +++ b/sound/pci/hda/hda_sysfs.c | |||
@@ -48,33 +48,33 @@ static DEVICE_ATTR_RO(power_on_acct); | |||
48 | static DEVICE_ATTR_RO(power_off_acct); | 48 | static DEVICE_ATTR_RO(power_off_acct); |
49 | #endif /* CONFIG_PM */ | 49 | #endif /* CONFIG_PM */ |
50 | 50 | ||
51 | #define CODEC_INFO_SHOW(type) \ | 51 | #define CODEC_INFO_SHOW(type, field) \ |
52 | static ssize_t type##_show(struct device *dev, \ | 52 | static ssize_t type##_show(struct device *dev, \ |
53 | struct device_attribute *attr, \ | 53 | struct device_attribute *attr, \ |
54 | char *buf) \ | 54 | char *buf) \ |
55 | { \ | 55 | { \ |
56 | struct hda_codec *codec = dev_get_drvdata(dev); \ | 56 | struct hda_codec *codec = dev_get_drvdata(dev); \ |
57 | return sprintf(buf, "0x%x\n", codec->type); \ | 57 | return sprintf(buf, "0x%x\n", codec->field); \ |
58 | } | 58 | } |
59 | 59 | ||
60 | #define CODEC_INFO_STR_SHOW(type) \ | 60 | #define CODEC_INFO_STR_SHOW(type, field) \ |
61 | static ssize_t type##_show(struct device *dev, \ | 61 | static ssize_t type##_show(struct device *dev, \ |
62 | struct device_attribute *attr, \ | 62 | struct device_attribute *attr, \ |
63 | char *buf) \ | 63 | char *buf) \ |
64 | { \ | 64 | { \ |
65 | struct hda_codec *codec = dev_get_drvdata(dev); \ | 65 | struct hda_codec *codec = dev_get_drvdata(dev); \ |
66 | return sprintf(buf, "%s\n", \ | 66 | return sprintf(buf, "%s\n", \ |
67 | codec->type ? codec->type : ""); \ | 67 | codec->field ? codec->field : ""); \ |
68 | } | 68 | } |
69 | 69 | ||
70 | CODEC_INFO_SHOW(vendor_id); | 70 | CODEC_INFO_SHOW(vendor_id, core.vendor_id); |
71 | CODEC_INFO_SHOW(subsystem_id); | 71 | CODEC_INFO_SHOW(subsystem_id, core.subsystem_id); |
72 | CODEC_INFO_SHOW(revision_id); | 72 | CODEC_INFO_SHOW(revision_id, core.revision_id); |
73 | CODEC_INFO_SHOW(afg); | 73 | CODEC_INFO_SHOW(afg, core.afg); |
74 | CODEC_INFO_SHOW(mfg); | 74 | CODEC_INFO_SHOW(mfg, core.mfg); |
75 | CODEC_INFO_STR_SHOW(vendor_name); | 75 | CODEC_INFO_STR_SHOW(vendor_name, core.vendor_name); |
76 | CODEC_INFO_STR_SHOW(chip_name); | 76 | CODEC_INFO_STR_SHOW(chip_name, core.chip_name); |
77 | CODEC_INFO_STR_SHOW(modelname); | 77 | CODEC_INFO_STR_SHOW(modelname, modelname); |
78 | 78 | ||
79 | static ssize_t pin_configs_show(struct hda_codec *codec, | 79 | static ssize_t pin_configs_show(struct hda_codec *codec, |
80 | struct snd_array *list, | 80 | struct snd_array *list, |
@@ -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; |
@@ -170,7 +170,7 @@ static char *kstrndup_noeol(const char *src, size_t len) | |||
170 | return s; | 170 | return s; |
171 | } | 171 | } |
172 | 172 | ||
173 | #define CODEC_INFO_STORE(type) \ | 173 | #define CODEC_INFO_STORE(type, field) \ |
174 | static ssize_t type##_store(struct device *dev, \ | 174 | static ssize_t type##_store(struct device *dev, \ |
175 | struct device_attribute *attr, \ | 175 | struct device_attribute *attr, \ |
176 | const char *buf, size_t count) \ | 176 | const char *buf, size_t count) \ |
@@ -180,11 +180,11 @@ static ssize_t type##_store(struct device *dev, \ | |||
180 | int err = kstrtoul(buf, 0, &val); \ | 180 | int err = kstrtoul(buf, 0, &val); \ |
181 | if (err < 0) \ | 181 | if (err < 0) \ |
182 | return err; \ | 182 | return err; \ |
183 | codec->type = val; \ | 183 | codec->field = val; \ |
184 | return count; \ | 184 | return count; \ |
185 | } | 185 | } |
186 | 186 | ||
187 | #define CODEC_INFO_STR_STORE(type) \ | 187 | #define CODEC_INFO_STR_STORE(type, field) \ |
188 | static ssize_t type##_store(struct device *dev, \ | 188 | static ssize_t type##_store(struct device *dev, \ |
189 | struct device_attribute *attr, \ | 189 | struct device_attribute *attr, \ |
190 | const char *buf, size_t count) \ | 190 | const char *buf, size_t count) \ |
@@ -193,17 +193,17 @@ static ssize_t type##_store(struct device *dev, \ | |||
193 | char *s = kstrndup_noeol(buf, 64); \ | 193 | char *s = kstrndup_noeol(buf, 64); \ |
194 | if (!s) \ | 194 | if (!s) \ |
195 | return -ENOMEM; \ | 195 | return -ENOMEM; \ |
196 | kfree(codec->type); \ | 196 | kfree(codec->field); \ |
197 | codec->type = s; \ | 197 | codec->field = s; \ |
198 | return count; \ | 198 | return count; \ |
199 | } | 199 | } |
200 | 200 | ||
201 | CODEC_INFO_STORE(vendor_id); | 201 | CODEC_INFO_STORE(vendor_id, core.vendor_id); |
202 | CODEC_INFO_STORE(subsystem_id); | 202 | CODEC_INFO_STORE(subsystem_id, core.subsystem_id); |
203 | CODEC_INFO_STORE(revision_id); | 203 | CODEC_INFO_STORE(revision_id, core.revision_id); |
204 | CODEC_INFO_STR_STORE(vendor_name); | 204 | CODEC_INFO_STR_STORE(vendor_name, core.vendor_name); |
205 | CODEC_INFO_STR_STORE(chip_name); | 205 | CODEC_INFO_STR_STORE(chip_name, core.chip_name); |
206 | CODEC_INFO_STR_STORE(modelname); | 206 | CODEC_INFO_STR_STORE(modelname, modelname); |
207 | 207 | ||
208 | #define CODEC_ACTION_STORE(type) \ | 208 | #define CODEC_ACTION_STORE(type) \ |
209 | static ssize_t type##_store(struct device *dev, \ | 209 | static ssize_t type##_store(struct device *dev, \ |
@@ -552,10 +552,10 @@ static void parse_codec_mode(char *buf, struct hda_bus *bus, | |||
552 | 552 | ||
553 | *codecp = NULL; | 553 | *codecp = NULL; |
554 | if (sscanf(buf, "%i %i %i", &vendorid, &subid, &caddr) == 3) { | 554 | if (sscanf(buf, "%i %i %i", &vendorid, &subid, &caddr) == 3) { |
555 | list_for_each_entry(codec, &bus->codec_list, list) { | 555 | list_for_each_codec(codec, bus) { |
556 | if ((vendorid <= 0 || codec->vendor_id == vendorid) && | 556 | if ((vendorid <= 0 || codec->core.vendor_id == vendorid) && |
557 | (subid <= 0 || codec->subsystem_id == subid) && | 557 | (subid <= 0 || codec->core.subsystem_id == subid) && |
558 | codec->addr == caddr) { | 558 | codec->core.addr == caddr) { |
559 | *codecp = codec; | 559 | *codecp = codec; |
560 | break; | 560 | break; |
561 | } | 561 | } |
@@ -595,8 +595,8 @@ static void parse_model_mode(char *buf, struct hda_bus *bus, | |||
595 | static void parse_chip_name_mode(char *buf, struct hda_bus *bus, | 595 | static void parse_chip_name_mode(char *buf, struct hda_bus *bus, |
596 | struct hda_codec **codecp) | 596 | struct hda_codec **codecp) |
597 | { | 597 | { |
598 | kfree((*codecp)->chip_name); | 598 | kfree((*codecp)->core.chip_name); |
599 | (*codecp)->chip_name = kstrdup(buf, GFP_KERNEL); | 599 | (*codecp)->core.chip_name = kstrdup(buf, GFP_KERNEL); |
600 | } | 600 | } |
601 | 601 | ||
602 | #define DEFINE_PARSE_ID_MODE(name) \ | 602 | #define DEFINE_PARSE_ID_MODE(name) \ |
@@ -605,7 +605,7 @@ static void parse_##name##_mode(char *buf, struct hda_bus *bus, \ | |||
605 | { \ | 605 | { \ |
606 | unsigned long val; \ | 606 | unsigned long val; \ |
607 | if (!kstrtoul(buf, 0, &val)) \ | 607 | if (!kstrtoul(buf, 0, &val)) \ |
608 | (*codecp)->name = val; \ | 608 | (*codecp)->core.name = val; \ |
609 | } | 609 | } |
610 | 610 | ||
611 | DEFINE_PARSE_ID_MODE(vendor_id); | 611 | DEFINE_PARSE_ID_MODE(vendor_id); |
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); | |||
82 | MODULE_PARM_DESC(power_save, | 81 | MODULE_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 |
85 | static 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 | */ | ||
351 | static 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 | |||
358 | static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev) | 338 | static 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 | ||
517 | static 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 | |||
544 | static struct platform_driver tegra_platform_hda = { | 529 | static 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 | }; |
553 | module_platform_driver(tegra_platform_hda); | 539 | module_platform_driver(tegra_platform_hda); |
554 | 540 | ||
diff --git a/sound/pci/hda/hda_trace.h b/sound/pci/hda/hda_trace.h deleted file mode 100644 index 3a1c63161eb1..000000000000 --- a/sound/pci/hda/hda_trace.h +++ /dev/null | |||
@@ -1,143 +0,0 @@ | |||
1 | #undef TRACE_SYSTEM | ||
2 | #define TRACE_SYSTEM hda | ||
3 | #define TRACE_INCLUDE_FILE hda_trace | ||
4 | |||
5 | #if !defined(_TRACE_HDA_H) || defined(TRACE_HEADER_MULTI_READ) | ||
6 | #define _TRACE_HDA_H | ||
7 | |||
8 | #include <linux/tracepoint.h> | ||
9 | |||
10 | struct hda_bus; | ||
11 | struct hda_codec; | ||
12 | |||
13 | DECLARE_EVENT_CLASS(hda_cmd, | ||
14 | |||
15 | TP_PROTO(struct hda_codec *codec, unsigned int val), | ||
16 | |||
17 | TP_ARGS(codec, val), | ||
18 | |||
19 | TP_STRUCT__entry( | ||
20 | __field( unsigned int, card ) | ||
21 | __field( unsigned int, addr ) | ||
22 | __field( unsigned int, val ) | ||
23 | ), | ||
24 | |||
25 | TP_fast_assign( | ||
26 | __entry->card = (codec)->bus->card->number; | ||
27 | __entry->addr = (codec)->addr; | ||
28 | __entry->val = (val); | ||
29 | ), | ||
30 | |||
31 | TP_printk("[%d:%d] val=%x", __entry->card, __entry->addr, __entry->val) | ||
32 | ); | ||
33 | |||
34 | DEFINE_EVENT(hda_cmd, hda_send_cmd, | ||
35 | TP_PROTO(struct hda_codec *codec, unsigned int val), | ||
36 | TP_ARGS(codec, val) | ||
37 | ); | ||
38 | |||
39 | DEFINE_EVENT(hda_cmd, hda_get_response, | ||
40 | TP_PROTO(struct hda_codec *codec, unsigned int val), | ||
41 | TP_ARGS(codec, val) | ||
42 | ); | ||
43 | |||
44 | TRACE_EVENT(hda_bus_reset, | ||
45 | |||
46 | TP_PROTO(struct hda_bus *bus), | ||
47 | |||
48 | TP_ARGS(bus), | ||
49 | |||
50 | TP_STRUCT__entry( | ||
51 | __field( unsigned int, card ) | ||
52 | ), | ||
53 | |||
54 | TP_fast_assign( | ||
55 | __entry->card = (bus)->card->number; | ||
56 | ), | ||
57 | |||
58 | TP_printk("[%d]", __entry->card) | ||
59 | ); | ||
60 | |||
61 | #ifdef CONFIG_PM | ||
62 | DECLARE_EVENT_CLASS(hda_power, | ||
63 | |||
64 | TP_PROTO(struct hda_codec *codec), | ||
65 | |||
66 | TP_ARGS(codec), | ||
67 | |||
68 | TP_STRUCT__entry( | ||
69 | __field( unsigned int, card ) | ||
70 | __field( unsigned int, addr ) | ||
71 | ), | ||
72 | |||
73 | TP_fast_assign( | ||
74 | __entry->card = (codec)->bus->card->number; | ||
75 | __entry->addr = (codec)->addr; | ||
76 | ), | ||
77 | |||
78 | TP_printk("[%d:%d]", __entry->card, __entry->addr) | ||
79 | ); | ||
80 | |||
81 | DEFINE_EVENT(hda_power, hda_power_down, | ||
82 | TP_PROTO(struct hda_codec *codec), | ||
83 | TP_ARGS(codec) | ||
84 | ); | ||
85 | |||
86 | DEFINE_EVENT(hda_power, hda_power_up, | ||
87 | TP_PROTO(struct hda_codec *codec), | ||
88 | TP_ARGS(codec) | ||
89 | ); | ||
90 | |||
91 | TRACE_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 */ | ||
115 | |||
116 | TRACE_EVENT(hda_unsol_event, | ||
117 | |||
118 | TP_PROTO(struct hda_bus *bus, u32 res, u32 res_ex), | ||
119 | |||
120 | TP_ARGS(bus, res, res_ex), | ||
121 | |||
122 | TP_STRUCT__entry( | ||
123 | __field( unsigned int, card ) | ||
124 | __field( u32, res ) | ||
125 | __field( u32, res_ex ) | ||
126 | ), | ||
127 | |||
128 | TP_fast_assign( | ||
129 | __entry->card = (bus)->card->number; | ||
130 | __entry->res = res; | ||
131 | __entry->res_ex = res_ex; | ||
132 | ), | ||
133 | |||
134 | TP_printk("[%d] res=%x, res_ex=%x", __entry->card, | ||
135 | __entry->res, __entry->res_ex) | ||
136 | ); | ||
137 | |||
138 | #endif /* _TRACE_HDA_H */ | ||
139 | |||
140 | /* This part must be outside protection */ | ||
141 | #undef TRACE_INCLUDE_PATH | ||
142 | #define TRACE_INCLUDE_PATH . | ||
143 | #include <trace/define_trace.h> | ||
diff --git a/sound/pci/hda/local.h b/sound/pci/hda/local.h new file mode 100644 index 000000000000..28cb7f98982e --- /dev/null +++ b/sound/pci/hda/local.h | |||
@@ -0,0 +1,39 @@ | |||
1 | /* | ||
2 | */ | ||
3 | |||
4 | #ifndef __HDAC_LOCAL_H | ||
5 | #define __HDAC_LOCAL_H | ||
6 | |||
7 | int hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm); | ||
8 | |||
9 | #define get_wcaps(codec, nid) \ | ||
10 | hdac_read_parm(codec, nid, AC_PAR_AUDIO_WIDGET_CAP) | ||
11 | /* get the widget type from widget capability bits */ | ||
12 | static inline int get_wcaps_type(unsigned int wcaps) | ||
13 | { | ||
14 | if (!wcaps) | ||
15 | return -1; /* invalid type */ | ||
16 | return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; | ||
17 | } | ||
18 | |||
19 | #define get_pin_caps(codec, nid) \ | ||
20 | hdac_read_parm(codec, nid, AC_PAR_PIN_CAP) | ||
21 | |||
22 | static inline | ||
23 | unsigned int get_pin_cfg(struct hdac_device *codec, hda_nid_t nid) | ||
24 | { | ||
25 | unsigned int val; | ||
26 | |||
27 | if (snd_hdac_read(codec, nid, AC_VERB_GET_CONFIG_DEFAULT, 0, &val)) | ||
28 | return -1; | ||
29 | return val; | ||
30 | } | ||
31 | |||
32 | #define get_amp_caps(codec, nid, dir) \ | ||
33 | hdac_read_parm(codec, nid, (dir) == HDA_OUTPUT ? \ | ||
34 | AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP) | ||
35 | |||
36 | #define get_power_caps(codec, nid) \ | ||
37 | hdac_read_parm(codec, nid, AC_PAR_POWER_STATE) | ||
38 | |||
39 | #endif /* __HDAC_LOCAL_H */ | ||
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c index d285904cdb64..231f89029779 100644 --- a/sound/pci/hda/patch_analog.c +++ b/sound/pci/hda/patch_analog.c | |||
@@ -99,7 +99,7 @@ static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front, | |||
99 | static void ad198x_power_eapd(struct hda_codec *codec) | 99 | static void ad198x_power_eapd(struct hda_codec *codec) |
100 | { | 100 | { |
101 | /* We currently only handle front, HP */ | 101 | /* We currently only handle front, HP */ |
102 | switch (codec->vendor_id) { | 102 | switch (codec->core.vendor_id) { |
103 | case 0x11d41882: | 103 | case 0x11d41882: |
104 | case 0x11d4882a: | 104 | case 0x11d4882a: |
105 | case 0x11d41884: | 105 | case 0x11d41884: |
@@ -777,7 +777,6 @@ static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol, | |||
777 | return 0; | 777 | return 0; |
778 | 778 | ||
779 | mutex_lock(&codec->control_mutex); | 779 | mutex_lock(&codec->control_mutex); |
780 | codec->cached_write = 1; | ||
781 | path = snd_hda_get_path_from_idx(codec, | 780 | path = snd_hda_get_path_from_idx(codec, |
782 | spec->smux_paths[spec->cur_smux]); | 781 | spec->smux_paths[spec->cur_smux]); |
783 | if (path) | 782 | if (path) |
@@ -786,9 +785,7 @@ static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol, | |||
786 | if (path) | 785 | if (path) |
787 | snd_hda_activate_path(codec, path, true, true); | 786 | snd_hda_activate_path(codec, path, true, true); |
788 | spec->cur_smux = val; | 787 | spec->cur_smux = val; |
789 | codec->cached_write = 0; | ||
790 | mutex_unlock(&codec->control_mutex); | 788 | mutex_unlock(&codec->control_mutex); |
791 | snd_hda_codec_flush_cache(codec); /* flush the updates */ | ||
792 | return 1; | 789 | return 1; |
793 | } | 790 | } |
794 | 791 | ||
@@ -1004,18 +1001,17 @@ static void ad1884_fixup_hp_eapd(struct hda_codec *codec, | |||
1004 | const struct hda_fixup *fix, int action) | 1001 | const struct hda_fixup *fix, int action) |
1005 | { | 1002 | { |
1006 | struct ad198x_spec *spec = codec->spec; | 1003 | struct ad198x_spec *spec = codec->spec; |
1007 | static const struct hda_verb gpio_init_verbs[] = { | ||
1008 | {0x01, AC_VERB_SET_GPIO_MASK, 0x02}, | ||
1009 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02}, | ||
1010 | {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, | ||
1011 | {}, | ||
1012 | }; | ||
1013 | 1004 | ||
1014 | switch (action) { | 1005 | switch (action) { |
1015 | case HDA_FIXUP_ACT_PRE_PROBE: | 1006 | case HDA_FIXUP_ACT_PRE_PROBE: |
1016 | spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook; | 1007 | spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook; |
1017 | spec->gen.own_eapd_ctl = 1; | 1008 | spec->gen.own_eapd_ctl = 1; |
1018 | snd_hda_sequence_write_cache(codec, gpio_init_verbs); | 1009 | snd_hda_codec_write_cache(codec, 0x01, 0, |
1010 | AC_VERB_SET_GPIO_MASK, 0x02); | ||
1011 | snd_hda_codec_write_cache(codec, 0x01, 0, | ||
1012 | AC_VERB_SET_GPIO_DIRECTION, 0x02); | ||
1013 | snd_hda_codec_write_cache(codec, 0x01, 0, | ||
1014 | AC_VERB_SET_GPIO_DATA, 0x02); | ||
1019 | break; | 1015 | break; |
1020 | case HDA_FIXUP_ACT_PROBE: | 1016 | case HDA_FIXUP_ACT_PROBE: |
1021 | if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) | 1017 | if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) |
@@ -1194,20 +1190,8 @@ MODULE_ALIAS("snd-hda-codec-id:11d4*"); | |||
1194 | MODULE_LICENSE("GPL"); | 1190 | MODULE_LICENSE("GPL"); |
1195 | MODULE_DESCRIPTION("Analog Devices HD-audio codec"); | 1191 | MODULE_DESCRIPTION("Analog Devices HD-audio codec"); |
1196 | 1192 | ||
1197 | static struct hda_codec_preset_list analog_list = { | 1193 | static struct hda_codec_driver analog_driver = { |
1198 | .preset = snd_hda_preset_analog, | 1194 | .preset = snd_hda_preset_analog, |
1199 | .owner = THIS_MODULE, | ||
1200 | }; | 1195 | }; |
1201 | 1196 | ||
1202 | static int __init patch_analog_init(void) | 1197 | module_hda_codec_driver(analog_driver); |
1203 | { | ||
1204 | return snd_hda_add_codec_preset(&analog_list); | ||
1205 | } | ||
1206 | |||
1207 | static void __exit patch_analog_exit(void) | ||
1208 | { | ||
1209 | snd_hda_delete_codec_preset(&analog_list); | ||
1210 | } | ||
1211 | |||
1212 | module_init(patch_analog_init) | ||
1213 | module_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"); | |||
98 | MODULE_LICENSE("GPL"); | 98 | MODULE_LICENSE("GPL"); |
99 | MODULE_DESCRIPTION("Creative CA0110-IBG HD-audio codec"); | 99 | MODULE_DESCRIPTION("Creative CA0110-IBG HD-audio codec"); |
100 | 100 | ||
101 | static struct hda_codec_preset_list ca0110_list = { | 101 | static 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 | ||
106 | static int __init patch_ca0110_init(void) | 105 | module_hda_codec_driver(ca0110_driver); |
107 | { | ||
108 | return snd_hda_add_codec_preset(&ca0110_list); | ||
109 | } | ||
110 | |||
111 | static void __exit patch_ca0110_exit(void) | ||
112 | { | ||
113 | snd_hda_delete_codec_preset(&ca0110_list); | ||
114 | } | ||
115 | |||
116 | module_init(patch_ca0110_init) | ||
117 | module_exit(patch_ca0110_exit) | ||
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c index e0383eea9880..4a4e7b282e4f 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 */ |
@@ -3132,7 +3131,7 @@ static int ca0132_select_out(struct hda_codec *codec) | |||
3132 | 3131 | ||
3133 | codec_dbg(codec, "ca0132_select_out\n"); | 3132 | codec_dbg(codec, "ca0132_select_out\n"); |
3134 | 3133 | ||
3135 | snd_hda_power_up(codec); | 3134 | snd_hda_power_up_pm(codec); |
3136 | 3135 | ||
3137 | auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID]; | 3136 | auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID]; |
3138 | 3137 | ||
@@ -3216,7 +3215,7 @@ static int ca0132_select_out(struct hda_codec *codec) | |||
3216 | } | 3215 | } |
3217 | 3216 | ||
3218 | exit: | 3217 | exit: |
3219 | snd_hda_power_down(codec); | 3218 | snd_hda_power_down_pm(codec); |
3220 | 3219 | ||
3221 | return err < 0 ? err : 0; | 3220 | return err < 0 ? err : 0; |
3222 | } | 3221 | } |
@@ -3294,7 +3293,7 @@ static int ca0132_select_mic(struct hda_codec *codec) | |||
3294 | 3293 | ||
3295 | codec_dbg(codec, "ca0132_select_mic\n"); | 3294 | codec_dbg(codec, "ca0132_select_mic\n"); |
3296 | 3295 | ||
3297 | snd_hda_power_up(codec); | 3296 | snd_hda_power_up_pm(codec); |
3298 | 3297 | ||
3299 | auto_jack = spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID]; | 3298 | auto_jack = spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID]; |
3300 | 3299 | ||
@@ -3327,7 +3326,7 @@ static int ca0132_select_mic(struct hda_codec *codec) | |||
3327 | ca0132_effects_set(codec, VOICE_FOCUS, 0); | 3326 | ca0132_effects_set(codec, VOICE_FOCUS, 0); |
3328 | } | 3327 | } |
3329 | 3328 | ||
3330 | snd_hda_power_down(codec); | 3329 | snd_hda_power_down_pm(codec); |
3331 | 3330 | ||
3332 | return 0; | 3331 | return 0; |
3333 | } | 3332 | } |
@@ -4036,12 +4035,11 @@ static struct hda_pcm_stream ca0132_pcm_digital_capture = { | |||
4036 | static int ca0132_build_pcms(struct hda_codec *codec) | 4035 | static 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 | |||
4041 | codec->pcm_info = info; | ||
4042 | codec->num_pcms = 0; | ||
4043 | 4039 | ||
4044 | info->name = "CA0132 Analog"; | 4040 | info = snd_hda_codec_pcm_new(codec, "CA0132 Analog"); |
4041 | if (!info) | ||
4042 | return -ENOMEM; | ||
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 | } |
@@ -4246,13 +4243,9 @@ static void ca0132_refresh_widget_caps(struct hda_codec *codec) | |||
4246 | { | 4243 | { |
4247 | struct ca0132_spec *spec = codec->spec; | 4244 | struct ca0132_spec *spec = codec->spec; |
4248 | int i; | 4245 | int i; |
4249 | hda_nid_t nid; | ||
4250 | 4246 | ||
4251 | codec_dbg(codec, "ca0132_refresh_widget_caps.\n"); | 4247 | codec_dbg(codec, "ca0132_refresh_widget_caps.\n"); |
4252 | nid = codec->start_nid; | 4248 | snd_hda_codec_update_widgets(codec); |
4253 | for (i = 0; i < codec->num_nodes; i++, nid++) | ||
4254 | codec->wcaps[i] = snd_hda_param_read(codec, nid, | ||
4255 | AC_PAR_AUDIO_WIDGET_CAP); | ||
4256 | 4249 | ||
4257 | for (i = 0; i < spec->multiout.num_dacs; i++) | 4250 | for (i = 0; i < spec->multiout.num_dacs; i++) |
4258 | refresh_amp_caps(codec, spec->dacs[i], HDA_OUTPUT); | 4251 | refresh_amp_caps(codec, spec->dacs[i], HDA_OUTPUT); |
@@ -4352,7 +4345,7 @@ static bool ca0132_download_dsp_images(struct hda_codec *codec) | |||
4352 | const struct dsp_image_seg *dsp_os_image; | 4345 | const struct dsp_image_seg *dsp_os_image; |
4353 | const struct firmware *fw_entry; | 4346 | const struct firmware *fw_entry; |
4354 | 4347 | ||
4355 | if (request_firmware(&fw_entry, EFX_FILE, codec->bus->card->dev) != 0) | 4348 | if (request_firmware(&fw_entry, EFX_FILE, codec->card->dev) != 0) |
4356 | return false; | 4349 | return false; |
4357 | 4350 | ||
4358 | dsp_os_image = (struct dsp_image_seg *)(fw_entry->data); | 4351 | dsp_os_image = (struct dsp_image_seg *)(fw_entry->data); |
@@ -4413,8 +4406,7 @@ static void hp_callback(struct hda_codec *codec, struct hda_jack_callback *cb) | |||
4413 | * state machine run. | 4406 | * state machine run. |
4414 | */ | 4407 | */ |
4415 | cancel_delayed_work_sync(&spec->unsol_hp_work); | 4408 | cancel_delayed_work_sync(&spec->unsol_hp_work); |
4416 | queue_delayed_work(codec->bus->workq, &spec->unsol_hp_work, | 4409 | schedule_delayed_work(&spec->unsol_hp_work, msecs_to_jiffies(500)); |
4417 | msecs_to_jiffies(500)); | ||
4418 | cb->tbl->block_report = 1; | 4410 | cb->tbl->block_report = 1; |
4419 | } | 4411 | } |
4420 | 4412 | ||
@@ -4554,7 +4546,7 @@ static int ca0132_init(struct hda_codec *codec) | |||
4554 | spec->dsp_state = DSP_DOWNLOAD_INIT; | 4546 | spec->dsp_state = DSP_DOWNLOAD_INIT; |
4555 | spec->curr_chip_addx = INVALID_CHIP_ADDRESS; | 4547 | spec->curr_chip_addx = INVALID_CHIP_ADDRESS; |
4556 | 4548 | ||
4557 | snd_hda_power_up(codec); | 4549 | snd_hda_power_up_pm(codec); |
4558 | 4550 | ||
4559 | ca0132_init_unsol(codec); | 4551 | ca0132_init_unsol(codec); |
4560 | 4552 | ||
@@ -4585,7 +4577,7 @@ static int ca0132_init(struct hda_codec *codec) | |||
4585 | 4577 | ||
4586 | snd_hda_jack_report_sync(codec); | 4578 | snd_hda_jack_report_sync(codec); |
4587 | 4579 | ||
4588 | snd_hda_power_down(codec); | 4580 | snd_hda_power_down_pm(codec); |
4589 | 4581 | ||
4590 | return 0; | 4582 | return 0; |
4591 | } | 4583 | } |
@@ -4702,20 +4694,8 @@ MODULE_ALIAS("snd-hda-codec-id:11020011"); | |||
4702 | MODULE_LICENSE("GPL"); | 4694 | MODULE_LICENSE("GPL"); |
4703 | MODULE_DESCRIPTION("Creative Sound Core3D codec"); | 4695 | MODULE_DESCRIPTION("Creative Sound Core3D codec"); |
4704 | 4696 | ||
4705 | static struct hda_codec_preset_list ca0132_list = { | 4697 | static struct hda_codec_driver ca0132_driver = { |
4706 | .preset = snd_hda_preset_ca0132, | 4698 | .preset = snd_hda_preset_ca0132, |
4707 | .owner = THIS_MODULE, | ||
4708 | }; | 4699 | }; |
4709 | 4700 | ||
4710 | static int __init patch_ca0132_init(void) | 4701 | module_hda_codec_driver(ca0132_driver); |
4711 | { | ||
4712 | return snd_hda_add_codec_preset(&ca0132_list); | ||
4713 | } | ||
4714 | |||
4715 | static void __exit patch_ca0132_exit(void) | ||
4716 | { | ||
4717 | snd_hda_delete_codec_preset(&ca0132_list); | ||
4718 | } | ||
4719 | |||
4720 | module_init(patch_ca0132_init) | ||
4721 | module_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"); | |||
1221 | MODULE_LICENSE("GPL"); | 1221 | MODULE_LICENSE("GPL"); |
1222 | MODULE_DESCRIPTION("Cirrus Logic HD-audio codec"); | 1222 | MODULE_DESCRIPTION("Cirrus Logic HD-audio codec"); |
1223 | 1223 | ||
1224 | static struct hda_codec_preset_list cirrus_list = { | 1224 | static 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 | ||
1229 | static int __init patch_cirrus_init(void) | 1228 | module_hda_codec_driver(cirrus_driver); |
1230 | { | ||
1231 | return snd_hda_add_codec_preset(&cirrus_list); | ||
1232 | } | ||
1233 | |||
1234 | static void __exit patch_cirrus_exit(void) | ||
1235 | { | ||
1236 | snd_hda_delete_codec_preset(&cirrus_list); | ||
1237 | } | ||
1238 | |||
1239 | module_init(patch_cirrus_init) | ||
1240 | module_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"); | |||
137 | MODULE_LICENSE("GPL"); | 137 | MODULE_LICENSE("GPL"); |
138 | MODULE_DESCRIPTION("C-Media HD-audio codec"); | 138 | MODULE_DESCRIPTION("C-Media HD-audio codec"); |
139 | 139 | ||
140 | static struct hda_codec_preset_list cmedia_list = { | 140 | static 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 | ||
145 | static int __init patch_cmedia_init(void) | 144 | module_hda_codec_driver(cmedia_driver); |
146 | { | ||
147 | return snd_hda_add_codec_preset(&cmedia_list); | ||
148 | } | ||
149 | |||
150 | static void __exit patch_cmedia_exit(void) | ||
151 | { | ||
152 | snd_hda_delete_codec_preset(&cmedia_list); | ||
153 | } | ||
154 | |||
155 | module_init(patch_cmedia_init) | ||
156 | module_exit(patch_cmedia_exit) | ||
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c index da67ea8645a6..f8f0dfbef149 100644 --- a/sound/pci/hda/patch_conexant.c +++ b/sound/pci/hda/patch_conexant.c | |||
@@ -103,10 +103,9 @@ static int add_beep_ctls(struct hda_codec *codec) | |||
103 | static void cx_auto_parse_beep(struct hda_codec *codec) | 103 | static void cx_auto_parse_beep(struct hda_codec *codec) |
104 | { | 104 | { |
105 | struct conexant_spec *spec = codec->spec; | 105 | struct conexant_spec *spec = codec->spec; |
106 | hda_nid_t nid, end_nid; | 106 | hda_nid_t nid; |
107 | 107 | ||
108 | end_nid = codec->start_nid + codec->num_nodes; | 108 | for_each_hda_codec_node(nid, codec) |
109 | for (nid = codec->start_nid; nid < end_nid; nid++) | ||
110 | if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { | 109 | if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { |
111 | set_beep_amp(spec, nid, 0, HDA_OUTPUT); | 110 | set_beep_amp(spec, nid, 0, HDA_OUTPUT); |
112 | break; | 111 | break; |
@@ -120,10 +119,9 @@ static void cx_auto_parse_beep(struct hda_codec *codec) | |||
120 | static void cx_auto_parse_eapd(struct hda_codec *codec) | 119 | static void cx_auto_parse_eapd(struct hda_codec *codec) |
121 | { | 120 | { |
122 | struct conexant_spec *spec = codec->spec; | 121 | struct conexant_spec *spec = codec->spec; |
123 | hda_nid_t nid, end_nid; | 122 | hda_nid_t nid; |
124 | 123 | ||
125 | end_nid = codec->start_nid + codec->num_nodes; | 124 | for_each_hda_codec_node(nid, codec) { |
126 | for (nid = codec->start_nid; nid < end_nid; nid++) { | ||
127 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) | 125 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) |
128 | continue; | 126 | continue; |
129 | if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) | 127 | if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) |
@@ -304,6 +302,7 @@ static void cxt_fixup_headphone_mic(struct hda_codec *codec, | |||
304 | switch (action) { | 302 | switch (action) { |
305 | case HDA_FIXUP_ACT_PRE_PROBE: | 303 | case HDA_FIXUP_ACT_PRE_PROBE: |
306 | spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC; | 304 | spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC; |
305 | snd_hdac_regmap_add_vendor_verb(&codec->core, 0x410); | ||
307 | break; | 306 | break; |
308 | case HDA_FIXUP_ACT_PROBE: | 307 | case HDA_FIXUP_ACT_PROBE: |
309 | spec->gen.cap_sync_hook = cxt_update_headset_mode_hook; | 308 | spec->gen.cap_sync_hook = cxt_update_headset_mode_hook; |
@@ -411,15 +410,11 @@ static void olpc_xo_automic(struct hda_codec *codec, | |||
411 | struct hda_jack_callback *jack) | 410 | struct hda_jack_callback *jack) |
412 | { | 411 | { |
413 | struct conexant_spec *spec = codec->spec; | 412 | struct conexant_spec *spec = codec->spec; |
414 | int saved_cached_write = codec->cached_write; | ||
415 | 413 | ||
416 | codec->cached_write = 1; | ||
417 | /* in DC mode, we don't handle automic */ | 414 | /* in DC mode, we don't handle automic */ |
418 | if (!spec->dc_enable) | 415 | if (!spec->dc_enable) |
419 | snd_hda_gen_mic_autoswitch(codec, jack); | 416 | snd_hda_gen_mic_autoswitch(codec, jack); |
420 | olpc_xo_update_mic_pins(codec); | 417 | olpc_xo_update_mic_pins(codec); |
421 | snd_hda_codec_flush_cache(codec); | ||
422 | codec->cached_write = saved_cached_write; | ||
423 | if (spec->dc_enable) | 418 | if (spec->dc_enable) |
424 | olpc_xo_update_mic_boost(codec); | 419 | olpc_xo_update_mic_boost(codec); |
425 | } | 420 | } |
@@ -848,7 +843,7 @@ static int patch_conexant_auto(struct hda_codec *codec) | |||
848 | struct conexant_spec *spec; | 843 | struct conexant_spec *spec; |
849 | int err; | 844 | int err; |
850 | 845 | ||
851 | codec_info(codec, "%s: BIOS auto-probing.\n", codec->chip_name); | 846 | codec_info(codec, "%s: BIOS auto-probing.\n", codec->core.chip_name); |
852 | 847 | ||
853 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 848 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
854 | if (!spec) | 849 | if (!spec) |
@@ -862,7 +857,7 @@ static int patch_conexant_auto(struct hda_codec *codec) | |||
862 | if (spec->dynamic_eapd) | 857 | if (spec->dynamic_eapd) |
863 | spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook; | 858 | spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook; |
864 | 859 | ||
865 | switch (codec->vendor_id) { | 860 | switch (codec->core.vendor_id) { |
866 | case 0x14f15045: | 861 | case 0x14f15045: |
867 | codec->single_adc_amp = 1; | 862 | codec->single_adc_amp = 1; |
868 | spec->gen.mixer_nid = 0x17; | 863 | spec->gen.mixer_nid = 0x17; |
@@ -896,7 +891,7 @@ static int patch_conexant_auto(struct hda_codec *codec) | |||
896 | * others may use EAPD really as an amp switch, so it might be | 891 | * others may use EAPD really as an amp switch, so it might be |
897 | * not good to expose it blindly. | 892 | * not good to expose it blindly. |
898 | */ | 893 | */ |
899 | switch (codec->subsystem_id >> 16) { | 894 | switch (codec->core.subsystem_id >> 16) { |
900 | case 0x103c: | 895 | case 0x103c: |
901 | spec->gen.vmaster_mute_enum = 1; | 896 | spec->gen.vmaster_mute_enum = 1; |
902 | break; | 897 | break; |
@@ -919,10 +914,10 @@ static int patch_conexant_auto(struct hda_codec *codec) | |||
919 | * which falls into the single-cmd mode. | 914 | * which falls into the single-cmd mode. |
920 | * Better to make reset, then. | 915 | * Better to make reset, then. |
921 | */ | 916 | */ |
922 | if (!codec->bus->sync_write) { | 917 | if (!codec->bus->core.sync_write) { |
923 | codec_info(codec, | 918 | codec_info(codec, |
924 | "Enable sync_write for stable communication\n"); | 919 | "Enable sync_write for stable communication\n"); |
925 | codec->bus->sync_write = 1; | 920 | codec->bus->core.sync_write = 1; |
926 | codec->bus->allow_bus_reset = 1; | 921 | codec->bus->allow_bus_reset = 1; |
927 | } | 922 | } |
928 | 923 | ||
@@ -1018,20 +1013,8 @@ MODULE_ALIAS("snd-hda-codec-id:14f151d7"); | |||
1018 | MODULE_LICENSE("GPL"); | 1013 | MODULE_LICENSE("GPL"); |
1019 | MODULE_DESCRIPTION("Conexant HD-audio codec"); | 1014 | MODULE_DESCRIPTION("Conexant HD-audio codec"); |
1020 | 1015 | ||
1021 | static struct hda_codec_preset_list conexant_list = { | 1016 | static struct hda_codec_driver conexant_driver = { |
1022 | .preset = snd_hda_preset_conexant, | 1017 | .preset = snd_hda_preset_conexant, |
1023 | .owner = THIS_MODULE, | ||
1024 | }; | 1018 | }; |
1025 | 1019 | ||
1026 | static int __init patch_conexant_init(void) | 1020 | module_hda_codec_driver(conexant_driver); |
1027 | { | ||
1028 | return snd_hda_add_codec_preset(&conexant_list); | ||
1029 | } | ||
1030 | |||
1031 | static void __exit patch_conexant_exit(void) | ||
1032 | { | ||
1033 | snd_hda_delete_codec_preset(&conexant_list); | ||
1034 | } | ||
1035 | |||
1036 | module_init(patch_conexant_init) | ||
1037 | module_exit(patch_conexant_exit) | ||
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index b422e406a9cb..5f44f60a6389 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c | |||
@@ -45,14 +45,14 @@ static bool static_hdmi_pcm; | |||
45 | module_param(static_hdmi_pcm, bool, 0644); | 45 | module_param(static_hdmi_pcm, bool, 0644); |
46 | MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info"); | 46 | MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info"); |
47 | 47 | ||
48 | #define is_haswell(codec) ((codec)->vendor_id == 0x80862807) | 48 | #define is_haswell(codec) ((codec)->core.vendor_id == 0x80862807) |
49 | #define is_broadwell(codec) ((codec)->vendor_id == 0x80862808) | 49 | #define is_broadwell(codec) ((codec)->core.vendor_id == 0x80862808) |
50 | #define is_skylake(codec) ((codec)->vendor_id == 0x80862809) | 50 | #define is_skylake(codec) ((codec)->core.vendor_id == 0x80862809) |
51 | #define is_haswell_plus(codec) (is_haswell(codec) || is_broadwell(codec) \ | 51 | #define is_haswell_plus(codec) (is_haswell(codec) || is_broadwell(codec) \ |
52 | || is_skylake(codec)) | 52 | || is_skylake(codec)) |
53 | 53 | ||
54 | #define is_valleyview(codec) ((codec)->vendor_id == 0x80862882) | 54 | #define is_valleyview(codec) ((codec)->core.vendor_id == 0x80862882) |
55 | #define is_cherryview(codec) ((codec)->vendor_id == 0x80862883) | 55 | #define is_cherryview(codec) ((codec)->core.vendor_id == 0x80862883) |
56 | #define is_valleyview_plus(codec) (is_valleyview(codec) || is_cherryview(codec)) | 56 | #define is_valleyview_plus(codec) (is_valleyview(codec) || is_cherryview(codec)) |
57 | 57 | ||
58 | struct hdmi_spec_per_cvt { | 58 | struct hdmi_spec_per_cvt { |
@@ -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 | ||
361 | static int pin_nid_to_pin_index(struct hda_codec *codec, hda_nid_t pin_nid) | 359 | static 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) | |||
594 | static void eld_proc_free(struct hdmi_spec_per_pin *per_pin) | 592 | static void eld_proc_free(struct hdmi_spec_per_pin *per_pin) |
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 | } |
@@ -1393,13 +1391,12 @@ static void intel_not_share_assigned_cvt(struct hda_codec *codec, | |||
1393 | hda_nid_t pin_nid, int mux_idx) | 1391 | hda_nid_t pin_nid, int mux_idx) |
1394 | { | 1392 | { |
1395 | struct hdmi_spec *spec = codec->spec; | 1393 | struct hdmi_spec *spec = codec->spec; |
1396 | hda_nid_t nid, end_nid; | 1394 | hda_nid_t nid; |
1397 | int cvt_idx, curr; | 1395 | int cvt_idx, curr; |
1398 | struct hdmi_spec_per_cvt *per_cvt; | 1396 | struct hdmi_spec_per_cvt *per_cvt; |
1399 | 1397 | ||
1400 | /* configure all pins, including "no physical connection" ones */ | 1398 | /* configure all pins, including "no physical connection" ones */ |
1401 | end_nid = codec->start_nid + codec->num_nodes; | 1399 | for_each_hda_codec_node(nid, codec) { |
1402 | for (nid = codec->start_nid; nid < end_nid; nid++) { | ||
1403 | unsigned int wid_caps = get_wcaps(codec, nid); | 1400 | unsigned int wid_caps = get_wcaps(codec, nid); |
1404 | unsigned int wid_type = get_wcaps_type(wid_caps); | 1401 | unsigned int wid_type = get_wcaps_type(wid_caps); |
1405 | 1402 | ||
@@ -1548,7 +1545,7 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) | |||
1548 | bool eld_changed = false; | 1545 | bool eld_changed = false; |
1549 | bool ret; | 1546 | bool ret; |
1550 | 1547 | ||
1551 | snd_hda_power_up(codec); | 1548 | snd_hda_power_up_pm(codec); |
1552 | present = snd_hda_pin_sense(codec, pin_nid); | 1549 | present = snd_hda_pin_sense(codec, pin_nid); |
1553 | 1550 | ||
1554 | mutex_lock(&per_pin->lock); | 1551 | mutex_lock(&per_pin->lock); |
@@ -1578,9 +1575,8 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) | |||
1578 | update_eld = true; | 1575 | update_eld = true; |
1579 | } | 1576 | } |
1580 | else if (repoll) { | 1577 | else if (repoll) { |
1581 | queue_delayed_work(codec->bus->workq, | 1578 | schedule_delayed_work(&per_pin->work, |
1582 | &per_pin->work, | 1579 | msecs_to_jiffies(300)); |
1583 | msecs_to_jiffies(300)); | ||
1584 | goto unlock; | 1580 | goto unlock; |
1585 | } | 1581 | } |
1586 | } | 1582 | } |
@@ -1624,7 +1620,7 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) | |||
1624 | } | 1620 | } |
1625 | 1621 | ||
1626 | if (eld_changed) | 1622 | if (eld_changed) |
1627 | snd_ctl_notify(codec->bus->card, | 1623 | snd_ctl_notify(codec->card, |
1628 | SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, | 1624 | SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, |
1629 | &per_pin->eld_ctl->id); | 1625 | &per_pin->eld_ctl->id); |
1630 | unlock: | 1626 | unlock: |
@@ -1635,7 +1631,7 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) | |||
1635 | jack->block_report = !ret; | 1631 | jack->block_report = !ret; |
1636 | 1632 | ||
1637 | mutex_unlock(&per_pin->lock); | 1633 | mutex_unlock(&per_pin->lock); |
1638 | snd_hda_power_down(codec); | 1634 | snd_hda_power_down_pm(codec); |
1639 | return ret; | 1635 | return ret; |
1640 | } | 1636 | } |
1641 | 1637 | ||
@@ -1731,7 +1727,7 @@ static int hdmi_parse_codec(struct hda_codec *codec) | |||
1731 | hda_nid_t nid; | 1727 | hda_nid_t nid; |
1732 | int i, nodes; | 1728 | int i, nodes; |
1733 | 1729 | ||
1734 | nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid); | 1730 | nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &nid); |
1735 | if (!nid || nodes < 0) { | 1731 | if (!nid || nodes < 0) { |
1736 | codec_warn(codec, "HDMI: failed to get afg sub nodes\n"); | 1732 | codec_warn(codec, "HDMI: failed to get afg sub nodes\n"); |
1737 | return -EINVAL; | 1733 | return -EINVAL; |
@@ -2056,11 +2052,10 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec) | |||
2056 | struct hdmi_spec_per_pin *per_pin; | 2052 | struct hdmi_spec_per_pin *per_pin; |
2057 | 2053 | ||
2058 | per_pin = get_pin(spec, pin_idx); | 2054 | per_pin = get_pin(spec, pin_idx); |
2059 | sprintf(per_pin->pcm_name, "HDMI %d", pin_idx); | 2055 | info = snd_hda_codec_pcm_new(codec, "HDMI %d", pin_idx); |
2060 | info = snd_array_new(&spec->pcm_rec); | ||
2061 | if (!info) | 2056 | if (!info) |
2062 | return -ENOMEM; | 2057 | return -ENOMEM; |
2063 | info->name = per_pin->pcm_name; | 2058 | spec->pcm_rec[pin_idx] = info; |
2064 | info->pcm_type = HDA_PCM_TYPE_HDMI; | 2059 | info->pcm_type = HDA_PCM_TYPE_HDMI; |
2065 | info->own_chmap = true; | 2060 | info->own_chmap = true; |
2066 | 2061 | ||
@@ -2070,9 +2065,6 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec) | |||
2070 | /* other pstr fields are set in open */ | 2065 | /* other pstr fields are set in open */ |
2071 | } | 2066 | } |
2072 | 2067 | ||
2073 | codec->num_pcms = spec->num_pins; | ||
2074 | codec->pcm_info = spec->pcm_rec.list; | ||
2075 | |||
2076 | return 0; | 2068 | return 0; |
2077 | } | 2069 | } |
2078 | 2070 | ||
@@ -2125,13 +2117,15 @@ static int generic_hdmi_build_controls(struct hda_codec *codec) | |||
2125 | 2117 | ||
2126 | /* add channel maps */ | 2118 | /* add channel maps */ |
2127 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { | 2119 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
2120 | struct hda_pcm *pcm; | ||
2128 | struct snd_pcm_chmap *chmap; | 2121 | struct snd_pcm_chmap *chmap; |
2129 | struct snd_kcontrol *kctl; | 2122 | struct snd_kcontrol *kctl; |
2130 | int i; | 2123 | int i; |
2131 | 2124 | ||
2132 | if (!codec->pcm_info[pin_idx].pcm) | 2125 | pcm = spec->pcm_rec[pin_idx]; |
2126 | if (!pcm || !pcm->pcm) | ||
2133 | break; | 2127 | break; |
2134 | err = snd_pcm_add_chmap_ctls(codec->pcm_info[pin_idx].pcm, | 2128 | err = snd_pcm_add_chmap_ctls(pcm->pcm, |
2135 | SNDRV_PCM_STREAM_PLAYBACK, | 2129 | SNDRV_PCM_STREAM_PLAYBACK, |
2136 | NULL, 0, pin_idx, &chmap); | 2130 | NULL, 0, pin_idx, &chmap); |
2137 | if (err < 0) | 2131 | if (err < 0) |
@@ -2186,14 +2180,12 @@ static void hdmi_array_init(struct hdmi_spec *spec, int nums) | |||
2186 | { | 2180 | { |
2187 | snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums); | 2181 | 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); | 2182 | 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 | } | 2183 | } |
2191 | 2184 | ||
2192 | static void hdmi_array_free(struct hdmi_spec *spec) | 2185 | static void hdmi_array_free(struct hdmi_spec *spec) |
2193 | { | 2186 | { |
2194 | snd_array_free(&spec->pins); | 2187 | snd_array_free(&spec->pins); |
2195 | snd_array_free(&spec->cvts); | 2188 | snd_array_free(&spec->cvts); |
2196 | snd_array_free(&spec->pcm_rec); | ||
2197 | } | 2189 | } |
2198 | 2190 | ||
2199 | static void generic_hdmi_free(struct hda_codec *codec) | 2191 | static void generic_hdmi_free(struct hda_codec *codec) |
@@ -2204,11 +2196,10 @@ static void generic_hdmi_free(struct hda_codec *codec) | |||
2204 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { | 2196 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
2205 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); | 2197 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
2206 | 2198 | ||
2207 | cancel_delayed_work(&per_pin->work); | 2199 | cancel_delayed_work_sync(&per_pin->work); |
2208 | eld_proc_free(per_pin); | 2200 | eld_proc_free(per_pin); |
2209 | } | 2201 | } |
2210 | 2202 | ||
2211 | flush_workqueue(codec->bus->workq); | ||
2212 | hdmi_array_free(spec); | 2203 | hdmi_array_free(spec); |
2213 | kfree(spec); | 2204 | kfree(spec); |
2214 | } | 2205 | } |
@@ -2220,8 +2211,7 @@ static int generic_hdmi_resume(struct hda_codec *codec) | |||
2220 | int pin_idx; | 2211 | int pin_idx; |
2221 | 2212 | ||
2222 | codec->patch_ops.init(codec); | 2213 | codec->patch_ops.init(codec); |
2223 | snd_hda_codec_resume_amp(codec); | 2214 | regcache_sync(codec->core.regmap); |
2224 | snd_hda_codec_resume_cache(codec); | ||
2225 | 2215 | ||
2226 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { | 2216 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
2227 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); | 2217 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
@@ -2308,6 +2298,7 @@ static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec) | |||
2308 | 2298 | ||
2309 | /* enable DP1.2 mode */ | 2299 | /* enable DP1.2 mode */ |
2310 | vendor_param |= INTEL_EN_DP12; | 2300 | vendor_param |= INTEL_EN_DP12; |
2301 | snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB); | ||
2311 | snd_hda_codec_write_cache(codec, INTEL_VENDOR_NID, 0, | 2302 | snd_hda_codec_write_cache(codec, INTEL_VENDOR_NID, 0, |
2312 | INTEL_SET_VENDOR_VERB, vendor_param); | 2303 | INTEL_SET_VENDOR_VERB, vendor_param); |
2313 | } | 2304 | } |
@@ -2381,11 +2372,10 @@ static int simple_playback_build_pcms(struct hda_codec *codec) | |||
2381 | chans = get_wcaps(codec, per_cvt->cvt_nid); | 2372 | chans = get_wcaps(codec, per_cvt->cvt_nid); |
2382 | chans = get_wcaps_channels(chans); | 2373 | chans = get_wcaps_channels(chans); |
2383 | 2374 | ||
2384 | info = snd_array_new(&spec->pcm_rec); | 2375 | info = snd_hda_codec_pcm_new(codec, "HDMI 0"); |
2385 | if (!info) | 2376 | if (!info) |
2386 | return -ENOMEM; | 2377 | return -ENOMEM; |
2387 | info->name = get_pin(spec, 0)->pcm_name; | 2378 | spec->pcm_rec[0] = info; |
2388 | sprintf(info->name, "HDMI 0"); | ||
2389 | info->pcm_type = HDA_PCM_TYPE_HDMI; | 2379 | info->pcm_type = HDA_PCM_TYPE_HDMI; |
2390 | pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; | 2380 | pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; |
2391 | *pstr = spec->pcm_playback; | 2381 | *pstr = spec->pcm_playback; |
@@ -2393,9 +2383,6 @@ static int simple_playback_build_pcms(struct hda_codec *codec) | |||
2393 | if (pstr->channels_max <= 2 && chans && chans <= 16) | 2383 | if (pstr->channels_max <= 2 && chans && chans <= 16) |
2394 | pstr->channels_max = chans; | 2384 | pstr->channels_max = chans; |
2395 | 2385 | ||
2396 | codec->num_pcms = 1; | ||
2397 | codec->pcm_info = info; | ||
2398 | |||
2399 | return 0; | 2386 | return 0; |
2400 | } | 2387 | } |
2401 | 2388 | ||
@@ -2940,7 +2927,8 @@ static int patch_nvhdmi(struct hda_codec *codec) | |||
2940 | */ | 2927 | */ |
2941 | 2928 | ||
2942 | #define is_amdhdmi_rev3_or_later(codec) \ | 2929 | #define is_amdhdmi_rev3_or_later(codec) \ |
2943 | ((codec)->vendor_id == 0x1002aa01 && ((codec)->revision_id & 0xff00) >= 0x0300) | 2930 | ((codec)->core.vendor_id == 0x1002aa01 && \ |
2931 | ((codec)->core.revision_id & 0xff00) >= 0x0300) | ||
2944 | #define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec) | 2932 | #define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec) |
2945 | 2933 | ||
2946 | /* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */ | 2934 | /* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */ |
@@ -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 | */ | ||
3306 | int snd_hda_parse_hdmi_codec(struct hda_codec *codec) | ||
3307 | { | ||
3308 | return patch_generic_hdmi(codec); | ||
3309 | } | ||
3310 | EXPORT_SYMBOL_GPL(snd_hda_parse_hdmi_codec); | ||
3311 | |||
3312 | /* | ||
3313 | * patch entries | 3292 | * patch entries |
3314 | */ | 3293 | */ |
3315 | static const struct hda_codec_preset snd_hda_preset_hdmi[] = { | 3294 | static 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"); | |||
3442 | MODULE_ALIAS("snd-hda-codec-nvhdmi"); | 3423 | MODULE_ALIAS("snd-hda-codec-nvhdmi"); |
3443 | MODULE_ALIAS("snd-hda-codec-atihdmi"); | 3424 | MODULE_ALIAS("snd-hda-codec-atihdmi"); |
3444 | 3425 | ||
3445 | static struct hda_codec_preset_list intel_list = { | 3426 | static 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 | ||
3450 | static int __init patch_hdmi_init(void) | 3430 | module_hda_codec_driver(hdmi_driver); |
3451 | { | ||
3452 | return snd_hda_add_codec_preset(&intel_list); | ||
3453 | } | ||
3454 | |||
3455 | static void __exit patch_hdmi_exit(void) | ||
3456 | { | ||
3457 | snd_hda_delete_codec_preset(&intel_list); | ||
3458 | } | ||
3459 | |||
3460 | module_init(patch_hdmi_init) | ||
3461 | module_exit(patch_hdmi_exit) | ||
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index f9d12c0a7e5a..b18b9c67b262 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c | |||
@@ -299,7 +299,7 @@ static void alc_fill_eapd_coef(struct hda_codec *codec) | |||
299 | 299 | ||
300 | coef = alc_get_coef0(codec); | 300 | coef = alc_get_coef0(codec); |
301 | 301 | ||
302 | switch (codec->vendor_id) { | 302 | switch (codec->core.vendor_id) { |
303 | case 0x10ec0262: | 303 | case 0x10ec0262: |
304 | alc_update_coef_idx(codec, 0x7, 0, 1<<5); | 304 | alc_update_coef_idx(codec, 0x7, 0, 1<<5); |
305 | break; | 305 | break; |
@@ -432,7 +432,7 @@ static void alc_auto_init_amp(struct hda_codec *codec, int type) | |||
432 | snd_hda_sequence_write(codec, alc_gpio3_init_verbs); | 432 | snd_hda_sequence_write(codec, alc_gpio3_init_verbs); |
433 | break; | 433 | break; |
434 | case ALC_INIT_DEFAULT: | 434 | case ALC_INIT_DEFAULT: |
435 | switch (codec->vendor_id) { | 435 | switch (codec->core.vendor_id) { |
436 | case 0x10ec0260: | 436 | case 0x10ec0260: |
437 | alc_update_coefex_idx(codec, 0x1a, 7, 0, 0x2010); | 437 | alc_update_coefex_idx(codec, 0x1a, 7, 0, 0x2010); |
438 | break; | 438 | break; |
@@ -498,18 +498,18 @@ static int alc_auto_parse_customize_define(struct hda_codec *codec) | |||
498 | 498 | ||
499 | if (!codec->bus->pci) | 499 | if (!codec->bus->pci) |
500 | return -1; | 500 | return -1; |
501 | ass = codec->subsystem_id & 0xffff; | 501 | ass = codec->core.subsystem_id & 0xffff; |
502 | if (ass != codec->bus->pci->subsystem_device && (ass & 1)) | 502 | if (ass != codec->bus->pci->subsystem_device && (ass & 1)) |
503 | goto do_sku; | 503 | goto do_sku; |
504 | 504 | ||
505 | nid = 0x1d; | 505 | nid = 0x1d; |
506 | if (codec->vendor_id == 0x10ec0260) | 506 | if (codec->core.vendor_id == 0x10ec0260) |
507 | nid = 0x17; | 507 | nid = 0x17; |
508 | ass = snd_hda_codec_get_pincfg(codec, nid); | 508 | ass = snd_hda_codec_get_pincfg(codec, nid); |
509 | 509 | ||
510 | if (!(ass & 1)) { | 510 | if (!(ass & 1)) { |
511 | codec_info(codec, "%s: SKU not ready 0x%08x\n", | 511 | codec_info(codec, "%s: SKU not ready 0x%08x\n", |
512 | codec->chip_name, ass); | 512 | codec->core.chip_name, ass); |
513 | return -1; | 513 | return -1; |
514 | } | 514 | } |
515 | 515 | ||
@@ -585,7 +585,7 @@ static int alc_subsystem_id(struct hda_codec *codec, const hda_nid_t *ports) | |||
585 | goto do_sku; | 585 | goto do_sku; |
586 | } | 586 | } |
587 | 587 | ||
588 | ass = codec->subsystem_id & 0xffff; | 588 | ass = codec->core.subsystem_id & 0xffff; |
589 | if (codec->bus->pci && | 589 | if (codec->bus->pci && |
590 | ass != codec->bus->pci->subsystem_device && (ass & 1)) | 590 | ass != codec->bus->pci->subsystem_device && (ass & 1)) |
591 | goto do_sku; | 591 | goto do_sku; |
@@ -600,7 +600,7 @@ static int alc_subsystem_id(struct hda_codec *codec, const hda_nid_t *ports) | |||
600 | * 0 : override | 600 | * 0 : override |
601 | */ | 601 | */ |
602 | nid = 0x1d; | 602 | nid = 0x1d; |
603 | if (codec->vendor_id == 0x10ec0260) | 603 | if (codec->core.vendor_id == 0x10ec0260) |
604 | nid = 0x17; | 604 | nid = 0x17; |
605 | ass = snd_hda_codec_get_pincfg(codec, nid); | 605 | ass = snd_hda_codec_get_pincfg(codec, nid); |
606 | codec_dbg(codec, | 606 | codec_dbg(codec, |
@@ -621,7 +621,7 @@ static int alc_subsystem_id(struct hda_codec *codec, const hda_nid_t *ports) | |||
621 | return 0; | 621 | return 0; |
622 | do_sku: | 622 | do_sku: |
623 | codec_dbg(codec, "realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n", | 623 | codec_dbg(codec, "realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n", |
624 | ass & 0xffff, codec->vendor_id); | 624 | ass & 0xffff, codec->core.vendor_id); |
625 | /* | 625 | /* |
626 | * 0 : override | 626 | * 0 : override |
627 | * 1 : Swap Jack | 627 | * 1 : Swap Jack |
@@ -799,8 +799,7 @@ static int alc_resume(struct hda_codec *codec) | |||
799 | if (!spec->no_depop_delay) | 799 | if (!spec->no_depop_delay) |
800 | msleep(150); /* to avoid pop noise */ | 800 | msleep(150); /* to avoid pop noise */ |
801 | codec->patch_ops.init(codec); | 801 | codec->patch_ops.init(codec); |
802 | snd_hda_codec_resume_amp(codec); | 802 | regcache_sync(codec->core.regmap); |
803 | snd_hda_codec_resume_cache(codec); | ||
804 | hda_call_check_power_status(codec, 0x01); | 803 | hda_call_check_power_status(codec, 0x01); |
805 | return 0; | 804 | return 0; |
806 | } | 805 | } |
@@ -826,9 +825,9 @@ static const struct hda_codec_ops alc_patch_ops = { | |||
826 | /* replace the codec chip_name with the given string */ | 825 | /* replace the codec chip_name with the given string */ |
827 | static int alc_codec_rename(struct hda_codec *codec, const char *name) | 826 | static int alc_codec_rename(struct hda_codec *codec, const char *name) |
828 | { | 827 | { |
829 | kfree(codec->chip_name); | 828 | kfree(codec->core.chip_name); |
830 | codec->chip_name = kstrdup(name, GFP_KERNEL); | 829 | codec->core.chip_name = kstrdup(name, GFP_KERNEL); |
831 | if (!codec->chip_name) { | 830 | if (!codec->core.chip_name) { |
832 | alc_free(codec); | 831 | alc_free(codec); |
833 | return -ENOMEM; | 832 | return -ENOMEM; |
834 | } | 833 | } |
@@ -904,7 +903,7 @@ static int alc_codec_rename_from_preset(struct hda_codec *codec) | |||
904 | const struct alc_codec_rename_pci_table *q; | 903 | const struct alc_codec_rename_pci_table *q; |
905 | 904 | ||
906 | for (p = rename_tbl; p->vendor_id; p++) { | 905 | for (p = rename_tbl; p->vendor_id; p++) { |
907 | if (p->vendor_id != codec->vendor_id) | 906 | if (p->vendor_id != codec->core.vendor_id) |
908 | continue; | 907 | continue; |
909 | if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits) | 908 | if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits) |
910 | return alc_codec_rename(codec, p->name); | 909 | return alc_codec_rename(codec, p->name); |
@@ -913,7 +912,7 @@ static int alc_codec_rename_from_preset(struct hda_codec *codec) | |||
913 | if (!codec->bus->pci) | 912 | if (!codec->bus->pci) |
914 | return 0; | 913 | return 0; |
915 | for (q = rename_pci_tbl; q->codec_vendor_id; q++) { | 914 | for (q = rename_pci_tbl; q->codec_vendor_id; q++) { |
916 | if (q->codec_vendor_id != codec->vendor_id) | 915 | if (q->codec_vendor_id != codec->core.vendor_id) |
917 | continue; | 916 | continue; |
918 | if (q->pci_subvendor != codec->bus->pci->subsystem_vendor) | 917 | if (q->pci_subvendor != codec->bus->pci->subsystem_vendor) |
919 | continue; | 918 | continue; |
@@ -1785,7 +1784,7 @@ static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted) | |||
1785 | { | 1784 | { |
1786 | unsigned int gpiostate, gpiomask, gpiodir; | 1785 | unsigned int gpiostate, gpiomask, gpiodir; |
1787 | 1786 | ||
1788 | gpiostate = snd_hda_codec_read(codec, codec->afg, 0, | 1787 | gpiostate = snd_hda_codec_read(codec, codec->core.afg, 0, |
1789 | AC_VERB_GET_GPIO_DATA, 0); | 1788 | AC_VERB_GET_GPIO_DATA, 0); |
1790 | 1789 | ||
1791 | if (!muted) | 1790 | if (!muted) |
@@ -1793,23 +1792,23 @@ static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted) | |||
1793 | else | 1792 | else |
1794 | gpiostate &= ~(1 << pin); | 1793 | gpiostate &= ~(1 << pin); |
1795 | 1794 | ||
1796 | gpiomask = snd_hda_codec_read(codec, codec->afg, 0, | 1795 | gpiomask = snd_hda_codec_read(codec, codec->core.afg, 0, |
1797 | AC_VERB_GET_GPIO_MASK, 0); | 1796 | AC_VERB_GET_GPIO_MASK, 0); |
1798 | gpiomask |= (1 << pin); | 1797 | gpiomask |= (1 << pin); |
1799 | 1798 | ||
1800 | gpiodir = snd_hda_codec_read(codec, codec->afg, 0, | 1799 | gpiodir = snd_hda_codec_read(codec, codec->core.afg, 0, |
1801 | AC_VERB_GET_GPIO_DIRECTION, 0); | 1800 | AC_VERB_GET_GPIO_DIRECTION, 0); |
1802 | gpiodir |= (1 << pin); | 1801 | gpiodir |= (1 << pin); |
1803 | 1802 | ||
1804 | 1803 | ||
1805 | snd_hda_codec_write(codec, codec->afg, 0, | 1804 | snd_hda_codec_write(codec, codec->core.afg, 0, |
1806 | AC_VERB_SET_GPIO_MASK, gpiomask); | 1805 | AC_VERB_SET_GPIO_MASK, gpiomask); |
1807 | snd_hda_codec_write(codec, codec->afg, 0, | 1806 | snd_hda_codec_write(codec, codec->core.afg, 0, |
1808 | AC_VERB_SET_GPIO_DIRECTION, gpiodir); | 1807 | AC_VERB_SET_GPIO_DIRECTION, gpiodir); |
1809 | 1808 | ||
1810 | msleep(1); | 1809 | msleep(1); |
1811 | 1810 | ||
1812 | snd_hda_codec_write(codec, codec->afg, 0, | 1811 | snd_hda_codec_write(codec, codec->core.afg, 0, |
1813 | AC_VERB_SET_GPIO_DATA, gpiostate); | 1812 | AC_VERB_SET_GPIO_DATA, gpiostate); |
1814 | } | 1813 | } |
1815 | 1814 | ||
@@ -2269,7 +2268,7 @@ static int patch_alc882(struct hda_codec *codec) | |||
2269 | 2268 | ||
2270 | spec = codec->spec; | 2269 | spec = codec->spec; |
2271 | 2270 | ||
2272 | switch (codec->vendor_id) { | 2271 | switch (codec->core.vendor_id) { |
2273 | case 0x10ec0882: | 2272 | case 0x10ec0882: |
2274 | case 0x10ec0885: | 2273 | case 0x10ec0885: |
2275 | case 0x10ec0900: | 2274 | case 0x10ec0900: |
@@ -2602,53 +2601,12 @@ static int patch_alc268(struct hda_codec *codec) | |||
2602 | * ALC269 | 2601 | * ALC269 |
2603 | */ | 2602 | */ |
2604 | 2603 | ||
2605 | static 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 | |||
2614 | static 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 | |||
2625 | static 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 | |||
2633 | static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { | 2604 | static 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 */ | 2605 | .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 | }; | 2606 | }; |
2645 | 2607 | ||
2646 | static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = { | 2608 | static 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 */ | 2609 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ |
2651 | /* NID is set in alc_build_pcms */ | ||
2652 | }; | 2610 | }; |
2653 | 2611 | ||
2654 | /* different alc269-variants */ | 2612 | /* different alc269-variants */ |
@@ -3101,8 +3059,7 @@ static int alc269_resume(struct hda_codec *codec) | |||
3101 | msleep(200); | 3059 | msleep(200); |
3102 | } | 3060 | } |
3103 | 3061 | ||
3104 | snd_hda_codec_resume_amp(codec); | 3062 | regcache_sync(codec->core.regmap); |
3105 | snd_hda_codec_resume_cache(codec); | ||
3106 | hda_call_check_power_status(codec, 0x01); | 3063 | hda_call_check_power_status(codec, 0x01); |
3107 | 3064 | ||
3108 | /* on some machine, the BIOS will clear the codec gpio data when enter | 3065 | /* on some machine, the BIOS will clear the codec gpio data when enter |
@@ -3110,7 +3067,7 @@ static int alc269_resume(struct hda_codec *codec) | |||
3110 | * in the driver. | 3067 | * in the driver. |
3111 | */ | 3068 | */ |
3112 | if (spec->gpio_led) | 3069 | if (spec->gpio_led) |
3113 | snd_hda_codec_write(codec, codec->afg, 0, AC_VERB_SET_GPIO_DATA, | 3070 | snd_hda_codec_write(codec, codec->core.afg, 0, AC_VERB_SET_GPIO_DATA, |
3114 | spec->gpio_led); | 3071 | spec->gpio_led); |
3115 | 3072 | ||
3116 | if (spec->has_alc5505_dsp) | 3073 | if (spec->has_alc5505_dsp) |
@@ -3155,8 +3112,8 @@ static void alc271_fixup_dmic(struct hda_codec *codec, | |||
3155 | }; | 3112 | }; |
3156 | unsigned int cfg; | 3113 | unsigned int cfg; |
3157 | 3114 | ||
3158 | if (strcmp(codec->chip_name, "ALC271X") && | 3115 | if (strcmp(codec->core.chip_name, "ALC271X") && |
3159 | strcmp(codec->chip_name, "ALC269VB")) | 3116 | strcmp(codec->core.chip_name, "ALC269VB")) |
3160 | return; | 3117 | return; |
3161 | cfg = snd_hda_codec_get_pincfg(codec, 0x12); | 3118 | cfg = snd_hda_codec_get_pincfg(codec, 0x12); |
3162 | if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED) | 3119 | if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED) |
@@ -3266,7 +3223,7 @@ static unsigned int led_power_filter(struct hda_codec *codec, | |||
3266 | snd_hda_set_pin_ctl(codec, nid, | 3223 | snd_hda_set_pin_ctl(codec, nid, |
3267 | snd_hda_codec_get_pin_target(codec, nid)); | 3224 | snd_hda_codec_get_pin_target(codec, nid)); |
3268 | 3225 | ||
3269 | return AC_PWRST_D0; | 3226 | return snd_hda_gen_path_power_filter(codec, nid, power_state); |
3270 | } | 3227 | } |
3271 | 3228 | ||
3272 | static void alc269_fixup_hp_mute_led(struct hda_codec *codec, | 3229 | static void alc269_fixup_hp_mute_led(struct hda_codec *codec, |
@@ -3522,9 +3479,9 @@ static void alc280_fixup_hp_gpio2_mic_hotkey(struct hda_codec *codec, | |||
3522 | } | 3479 | } |
3523 | 3480 | ||
3524 | snd_hda_add_verbs(codec, gpio_init); | 3481 | snd_hda_add_verbs(codec, gpio_init); |
3525 | snd_hda_codec_write_cache(codec, codec->afg, 0, | 3482 | snd_hda_codec_write_cache(codec, codec->core.afg, 0, |
3526 | AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x04); | 3483 | AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x04); |
3527 | snd_hda_jack_detect_enable_callback(codec, codec->afg, | 3484 | snd_hda_jack_detect_enable_callback(codec, codec->core.afg, |
3528 | gpio2_mic_hotkey_event); | 3485 | gpio2_mic_hotkey_event); |
3529 | 3486 | ||
3530 | spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook; | 3487 | spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook; |
@@ -3585,6 +3542,14 @@ static void alc_headset_mode_unplugged(struct hda_codec *codec) | |||
3585 | WRITE_COEF(0x32, 0x42a3), | 3542 | WRITE_COEF(0x32, 0x42a3), |
3586 | {} | 3543 | {} |
3587 | }; | 3544 | }; |
3545 | static struct coef_fw coef0288[] = { | ||
3546 | UPDATE_COEF(0x4f, 0xfcc0, 0xc400), | ||
3547 | UPDATE_COEF(0x50, 0x2000, 0x2000), | ||
3548 | UPDATE_COEF(0x56, 0x0006, 0x0006), | ||
3549 | UPDATE_COEF(0x66, 0x0008, 0), | ||
3550 | UPDATE_COEF(0x67, 0x2000, 0), | ||
3551 | {} | ||
3552 | }; | ||
3588 | static struct coef_fw coef0292[] = { | 3553 | static struct coef_fw coef0292[] = { |
3589 | WRITE_COEF(0x76, 0x000e), | 3554 | WRITE_COEF(0x76, 0x000e), |
3590 | WRITE_COEF(0x6c, 0x2400), | 3555 | WRITE_COEF(0x6c, 0x2400), |
@@ -3607,7 +3572,7 @@ static void alc_headset_mode_unplugged(struct hda_codec *codec) | |||
3607 | {} | 3572 | {} |
3608 | }; | 3573 | }; |
3609 | 3574 | ||
3610 | switch (codec->vendor_id) { | 3575 | switch (codec->core.vendor_id) { |
3611 | case 0x10ec0255: | 3576 | case 0x10ec0255: |
3612 | case 0x10ec0256: | 3577 | case 0x10ec0256: |
3613 | alc_process_coef_fw(codec, coef0255); | 3578 | alc_process_coef_fw(codec, coef0255); |
@@ -3616,6 +3581,10 @@ static void alc_headset_mode_unplugged(struct hda_codec *codec) | |||
3616 | case 0x10ec0283: | 3581 | case 0x10ec0283: |
3617 | alc_process_coef_fw(codec, coef0233); | 3582 | alc_process_coef_fw(codec, coef0233); |
3618 | break; | 3583 | break; |
3584 | case 0x10ec0286: | ||
3585 | case 0x10ec0288: | ||
3586 | alc_process_coef_fw(codec, coef0288); | ||
3587 | break; | ||
3619 | case 0x10ec0292: | 3588 | case 0x10ec0292: |
3620 | alc_process_coef_fw(codec, coef0292); | 3589 | alc_process_coef_fw(codec, coef0292); |
3621 | break; | 3590 | break; |
@@ -3645,6 +3614,14 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin, | |||
3645 | WRITE_COEF(0x26, 0x008c), | 3614 | WRITE_COEF(0x26, 0x008c), |
3646 | {} | 3615 | {} |
3647 | }; | 3616 | }; |
3617 | static struct coef_fw coef0288[] = { | ||
3618 | UPDATE_COEF(0x50, 0x2000, 0), | ||
3619 | UPDATE_COEF(0x56, 0x0006, 0), | ||
3620 | UPDATE_COEF(0x4f, 0xfcc0, 0xc400), | ||
3621 | UPDATE_COEF(0x66, 0x0008, 0x0008), | ||
3622 | UPDATE_COEF(0x67, 0x2000, 0x2000), | ||
3623 | {} | ||
3624 | }; | ||
3648 | static struct coef_fw coef0292[] = { | 3625 | static struct coef_fw coef0292[] = { |
3649 | WRITE_COEF(0x19, 0xa208), | 3626 | WRITE_COEF(0x19, 0xa208), |
3650 | WRITE_COEF(0x2e, 0xacf0), | 3627 | WRITE_COEF(0x2e, 0xacf0), |
@@ -3663,7 +3640,7 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin, | |||
3663 | {} | 3640 | {} |
3664 | }; | 3641 | }; |
3665 | 3642 | ||
3666 | switch (codec->vendor_id) { | 3643 | switch (codec->core.vendor_id) { |
3667 | case 0x10ec0255: | 3644 | case 0x10ec0255: |
3668 | case 0x10ec0256: | 3645 | case 0x10ec0256: |
3669 | alc_write_coef_idx(codec, 0x45, 0xc489); | 3646 | alc_write_coef_idx(codec, 0x45, 0xc489); |
@@ -3678,6 +3655,13 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin, | |||
3678 | alc_process_coef_fw(codec, coef0233); | 3655 | alc_process_coef_fw(codec, coef0233); |
3679 | snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50); | 3656 | snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50); |
3680 | break; | 3657 | break; |
3658 | case 0x10ec0286: | ||
3659 | case 0x10ec0288: | ||
3660 | alc_update_coef_idx(codec, 0x4f, 0x000c, 0); | ||
3661 | snd_hda_set_pin_ctl_cache(codec, hp_pin, 0); | ||
3662 | alc_process_coef_fw(codec, coef0288); | ||
3663 | snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50); | ||
3664 | break; | ||
3681 | case 0x10ec0292: | 3665 | case 0x10ec0292: |
3682 | snd_hda_set_pin_ctl_cache(codec, hp_pin, 0); | 3666 | snd_hda_set_pin_ctl_cache(codec, hp_pin, 0); |
3683 | alc_process_coef_fw(codec, coef0292); | 3667 | alc_process_coef_fw(codec, coef0292); |
@@ -3713,6 +3697,14 @@ static void alc_headset_mode_default(struct hda_codec *codec) | |||
3713 | WRITE_COEF(0x32, 0x4ea3), | 3697 | WRITE_COEF(0x32, 0x4ea3), |
3714 | {} | 3698 | {} |
3715 | }; | 3699 | }; |
3700 | static struct coef_fw coef0288[] = { | ||
3701 | UPDATE_COEF(0x4f, 0xfcc0, 0xc400), /* Set to TRS type */ | ||
3702 | UPDATE_COEF(0x50, 0x2000, 0x2000), | ||
3703 | UPDATE_COEF(0x56, 0x0006, 0x0006), | ||
3704 | UPDATE_COEF(0x66, 0x0008, 0), | ||
3705 | UPDATE_COEF(0x67, 0x2000, 0), | ||
3706 | {} | ||
3707 | }; | ||
3716 | static struct coef_fw coef0292[] = { | 3708 | static struct coef_fw coef0292[] = { |
3717 | WRITE_COEF(0x76, 0x000e), | 3709 | WRITE_COEF(0x76, 0x000e), |
3718 | WRITE_COEF(0x6c, 0x2400), | 3710 | WRITE_COEF(0x6c, 0x2400), |
@@ -3733,7 +3725,7 @@ static void alc_headset_mode_default(struct hda_codec *codec) | |||
3733 | {} | 3725 | {} |
3734 | }; | 3726 | }; |
3735 | 3727 | ||
3736 | switch (codec->vendor_id) { | 3728 | switch (codec->core.vendor_id) { |
3737 | case 0x10ec0255: | 3729 | case 0x10ec0255: |
3738 | case 0x10ec0256: | 3730 | case 0x10ec0256: |
3739 | alc_process_coef_fw(codec, coef0255); | 3731 | alc_process_coef_fw(codec, coef0255); |
@@ -3742,6 +3734,11 @@ static void alc_headset_mode_default(struct hda_codec *codec) | |||
3742 | case 0x10ec0283: | 3734 | case 0x10ec0283: |
3743 | alc_process_coef_fw(codec, coef0233); | 3735 | alc_process_coef_fw(codec, coef0233); |
3744 | break; | 3736 | break; |
3737 | case 0x10ec0286: | ||
3738 | case 0x10ec0288: | ||
3739 | alc_process_coef_fw(codec, coef0288); | ||
3740 | break; | ||
3741 | break; | ||
3745 | case 0x10ec0292: | 3742 | case 0x10ec0292: |
3746 | alc_process_coef_fw(codec, coef0292); | 3743 | alc_process_coef_fw(codec, coef0292); |
3747 | break; | 3744 | break; |
@@ -3770,6 +3767,13 @@ static void alc_headset_mode_ctia(struct hda_codec *codec) | |||
3770 | WRITE_COEF(0x32, 0x4ea3), | 3767 | WRITE_COEF(0x32, 0x4ea3), |
3771 | {} | 3768 | {} |
3772 | }; | 3769 | }; |
3770 | static struct coef_fw coef0288[] = { | ||
3771 | UPDATE_COEF(0x50, 0x2000, 0x2000), | ||
3772 | UPDATE_COEF(0x56, 0x0006, 0x0006), | ||
3773 | UPDATE_COEF(0x66, 0x0008, 0), | ||
3774 | UPDATE_COEF(0x67, 0x2000, 0), | ||
3775 | {} | ||
3776 | }; | ||
3773 | static struct coef_fw coef0292[] = { | 3777 | static struct coef_fw coef0292[] = { |
3774 | WRITE_COEF(0x6b, 0xd429), | 3778 | WRITE_COEF(0x6b, 0xd429), |
3775 | WRITE_COEF(0x76, 0x0008), | 3779 | WRITE_COEF(0x76, 0x0008), |
@@ -3788,7 +3792,7 @@ static void alc_headset_mode_ctia(struct hda_codec *codec) | |||
3788 | {} | 3792 | {} |
3789 | }; | 3793 | }; |
3790 | 3794 | ||
3791 | switch (codec->vendor_id) { | 3795 | switch (codec->core.vendor_id) { |
3792 | case 0x10ec0255: | 3796 | case 0x10ec0255: |
3793 | case 0x10ec0256: | 3797 | case 0x10ec0256: |
3794 | alc_process_coef_fw(codec, coef0255); | 3798 | alc_process_coef_fw(codec, coef0255); |
@@ -3797,6 +3801,12 @@ static void alc_headset_mode_ctia(struct hda_codec *codec) | |||
3797 | case 0x10ec0283: | 3801 | case 0x10ec0283: |
3798 | alc_process_coef_fw(codec, coef0233); | 3802 | alc_process_coef_fw(codec, coef0233); |
3799 | break; | 3803 | break; |
3804 | case 0x10ec0286: | ||
3805 | case 0x10ec0288: | ||
3806 | alc_update_coef_idx(codec, 0x4f, 0xfcc0, 0xd400); | ||
3807 | msleep(300); | ||
3808 | alc_process_coef_fw(codec, coef0288); | ||
3809 | break; | ||
3800 | case 0x10ec0292: | 3810 | case 0x10ec0292: |
3801 | alc_process_coef_fw(codec, coef0292); | 3811 | alc_process_coef_fw(codec, coef0292); |
3802 | break; | 3812 | break; |
@@ -3825,6 +3835,13 @@ static void alc_headset_mode_omtp(struct hda_codec *codec) | |||
3825 | WRITE_COEF(0x32, 0x4ea3), | 3835 | WRITE_COEF(0x32, 0x4ea3), |
3826 | {} | 3836 | {} |
3827 | }; | 3837 | }; |
3838 | static struct coef_fw coef0288[] = { | ||
3839 | UPDATE_COEF(0x50, 0x2000, 0x2000), | ||
3840 | UPDATE_COEF(0x56, 0x0006, 0x0006), | ||
3841 | UPDATE_COEF(0x66, 0x0008, 0), | ||
3842 | UPDATE_COEF(0x67, 0x2000, 0), | ||
3843 | {} | ||
3844 | }; | ||
3828 | static struct coef_fw coef0292[] = { | 3845 | static struct coef_fw coef0292[] = { |
3829 | WRITE_COEF(0x6b, 0xe429), | 3846 | WRITE_COEF(0x6b, 0xe429), |
3830 | WRITE_COEF(0x76, 0x0008), | 3847 | WRITE_COEF(0x76, 0x0008), |
@@ -3843,7 +3860,7 @@ static void alc_headset_mode_omtp(struct hda_codec *codec) | |||
3843 | {} | 3860 | {} |
3844 | }; | 3861 | }; |
3845 | 3862 | ||
3846 | switch (codec->vendor_id) { | 3863 | switch (codec->core.vendor_id) { |
3847 | case 0x10ec0255: | 3864 | case 0x10ec0255: |
3848 | case 0x10ec0256: | 3865 | case 0x10ec0256: |
3849 | alc_process_coef_fw(codec, coef0255); | 3866 | alc_process_coef_fw(codec, coef0255); |
@@ -3852,6 +3869,12 @@ static void alc_headset_mode_omtp(struct hda_codec *codec) | |||
3852 | case 0x10ec0283: | 3869 | case 0x10ec0283: |
3853 | alc_process_coef_fw(codec, coef0233); | 3870 | alc_process_coef_fw(codec, coef0233); |
3854 | break; | 3871 | break; |
3872 | case 0x10ec0286: | ||
3873 | case 0x10ec0288: | ||
3874 | alc_update_coef_idx(codec, 0x4f, 0xfcc0, 0xe400); | ||
3875 | msleep(300); | ||
3876 | alc_process_coef_fw(codec, coef0288); | ||
3877 | break; | ||
3855 | case 0x10ec0292: | 3878 | case 0x10ec0292: |
3856 | alc_process_coef_fw(codec, coef0292); | 3879 | alc_process_coef_fw(codec, coef0292); |
3857 | break; | 3880 | break; |
@@ -3876,6 +3899,10 @@ static void alc_determine_headset_type(struct hda_codec *codec) | |||
3876 | conteol) */ | 3899 | conteol) */ |
3877 | {} | 3900 | {} |
3878 | }; | 3901 | }; |
3902 | static struct coef_fw coef0288[] = { | ||
3903 | UPDATE_COEF(0x4f, 0xfcc0, 0xd400), /* Check Type */ | ||
3904 | {} | ||
3905 | }; | ||
3879 | static struct coef_fw coef0293[] = { | 3906 | static struct coef_fw coef0293[] = { |
3880 | UPDATE_COEF(0x4a, 0x000f, 0x0008), /* Combo Jack auto detect */ | 3907 | UPDATE_COEF(0x4a, 0x000f, 0x0008), /* Combo Jack auto detect */ |
3881 | WRITE_COEF(0x45, 0xD429), /* Set to ctia type */ | 3908 | WRITE_COEF(0x45, 0xD429), /* Set to ctia type */ |
@@ -3889,7 +3916,7 @@ static void alc_determine_headset_type(struct hda_codec *codec) | |||
3889 | {} | 3916 | {} |
3890 | }; | 3917 | }; |
3891 | 3918 | ||
3892 | switch (codec->vendor_id) { | 3919 | switch (codec->core.vendor_id) { |
3893 | case 0x10ec0255: | 3920 | case 0x10ec0255: |
3894 | case 0x10ec0256: | 3921 | case 0x10ec0256: |
3895 | alc_process_coef_fw(codec, coef0255); | 3922 | alc_process_coef_fw(codec, coef0255); |
@@ -3904,6 +3931,13 @@ static void alc_determine_headset_type(struct hda_codec *codec) | |||
3904 | val = alc_read_coef_idx(codec, 0x46); | 3931 | val = alc_read_coef_idx(codec, 0x46); |
3905 | is_ctia = (val & 0x0070) == 0x0070; | 3932 | is_ctia = (val & 0x0070) == 0x0070; |
3906 | break; | 3933 | break; |
3934 | case 0x10ec0286: | ||
3935 | case 0x10ec0288: | ||
3936 | alc_process_coef_fw(codec, coef0288); | ||
3937 | msleep(350); | ||
3938 | val = alc_read_coef_idx(codec, 0x50); | ||
3939 | is_ctia = (val & 0x0070) == 0x0070; | ||
3940 | break; | ||
3907 | case 0x10ec0292: | 3941 | case 0x10ec0292: |
3908 | alc_write_coef_idx(codec, 0x6b, 0xd429); | 3942 | alc_write_coef_idx(codec, 0x6b, 0xd429); |
3909 | msleep(300); | 3943 | msleep(300); |
@@ -4087,6 +4121,29 @@ static void alc_fixup_headset_mode_alc255_no_hp_mic(struct hda_codec *codec, | |||
4087 | alc_fixup_headset_mode(codec, fix, action); | 4121 | alc_fixup_headset_mode(codec, fix, action); |
4088 | } | 4122 | } |
4089 | 4123 | ||
4124 | static void alc288_update_headset_jack_cb(struct hda_codec *codec, | ||
4125 | struct hda_jack_callback *jack) | ||
4126 | { | ||
4127 | struct alc_spec *spec = codec->spec; | ||
4128 | int present; | ||
4129 | |||
4130 | alc_update_headset_jack_cb(codec, jack); | ||
4131 | /* Headset Mic enable or disable, only for Dell Dino */ | ||
4132 | present = spec->gen.hp_jack_present ? 0x40 : 0; | ||
4133 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, | ||
4134 | present); | ||
4135 | } | ||
4136 | |||
4137 | static void alc_fixup_headset_mode_dell_alc288(struct hda_codec *codec, | ||
4138 | const struct hda_fixup *fix, int action) | ||
4139 | { | ||
4140 | alc_fixup_headset_mode(codec, fix, action); | ||
4141 | if (action == HDA_FIXUP_ACT_PROBE) { | ||
4142 | struct alc_spec *spec = codec->spec; | ||
4143 | spec->gen.hp_automute_hook = alc288_update_headset_jack_cb; | ||
4144 | } | ||
4145 | } | ||
4146 | |||
4090 | static void alc_fixup_auto_mute_via_amp(struct hda_codec *codec, | 4147 | static void alc_fixup_auto_mute_via_amp(struct hda_codec *codec, |
4091 | const struct hda_fixup *fix, int action) | 4148 | const struct hda_fixup *fix, int action) |
4092 | { | 4149 | { |
@@ -4127,9 +4184,9 @@ static unsigned int alc_power_filter_xps13(struct hda_codec *codec, | |||
4127 | 4184 | ||
4128 | /* Avoid pop noises when headphones are plugged in */ | 4185 | /* Avoid pop noises when headphones are plugged in */ |
4129 | if (spec->gen.hp_jack_present) | 4186 | if (spec->gen.hp_jack_present) |
4130 | if (nid == codec->afg || nid == 0x02 || nid == 0x15) | 4187 | if (nid == codec->core.afg || nid == 0x02 || nid == 0x15) |
4131 | return AC_PWRST_D0; | 4188 | return AC_PWRST_D0; |
4132 | return power_state; | 4189 | return snd_hda_gen_path_power_filter(codec, nid, power_state); |
4133 | } | 4190 | } |
4134 | 4191 | ||
4135 | static void alc_fixup_dell_xps13(struct hda_codec *codec, | 4192 | static void alc_fixup_dell_xps13(struct hda_codec *codec, |
@@ -4427,6 +4484,9 @@ enum { | |||
4427 | ALC286_FIXUP_HP_GPIO_LED, | 4484 | ALC286_FIXUP_HP_GPIO_LED, |
4428 | ALC280_FIXUP_HP_GPIO2_MIC_HOTKEY, | 4485 | ALC280_FIXUP_HP_GPIO2_MIC_HOTKEY, |
4429 | ALC280_FIXUP_HP_DOCK_PINS, | 4486 | ALC280_FIXUP_HP_DOCK_PINS, |
4487 | ALC288_FIXUP_DELL_HEADSET_MODE, | ||
4488 | ALC288_FIXUP_DELL1_MIC_NO_PRESENCE, | ||
4489 | ALC288_FIXUP_DELL_XPS_13_GPIO6, | ||
4430 | }; | 4490 | }; |
4431 | 4491 | ||
4432 | static const struct hda_fixup alc269_fixups[] = { | 4492 | static const struct hda_fixup alc269_fixups[] = { |
@@ -4922,6 +4982,33 @@ static const struct hda_fixup alc269_fixups[] = { | |||
4922 | .chained = true, | 4982 | .chained = true, |
4923 | .chain_id = ALC280_FIXUP_HP_GPIO4 | 4983 | .chain_id = ALC280_FIXUP_HP_GPIO4 |
4924 | }, | 4984 | }, |
4985 | [ALC288_FIXUP_DELL_HEADSET_MODE] = { | ||
4986 | .type = HDA_FIXUP_FUNC, | ||
4987 | .v.func = alc_fixup_headset_mode_dell_alc288, | ||
4988 | .chained = true, | ||
4989 | .chain_id = ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED | ||
4990 | }, | ||
4991 | [ALC288_FIXUP_DELL1_MIC_NO_PRESENCE] = { | ||
4992 | .type = HDA_FIXUP_PINS, | ||
4993 | .v.pins = (const struct hda_pintbl[]) { | ||
4994 | { 0x18, 0x01a1913c }, /* use as headset mic, without its own jack detect */ | ||
4995 | { 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */ | ||
4996 | { } | ||
4997 | }, | ||
4998 | .chained = true, | ||
4999 | .chain_id = ALC288_FIXUP_DELL_HEADSET_MODE | ||
5000 | }, | ||
5001 | [ALC288_FIXUP_DELL_XPS_13_GPIO6] = { | ||
5002 | .type = HDA_FIXUP_VERBS, | ||
5003 | .v.verbs = (const struct hda_verb[]) { | ||
5004 | {0x01, AC_VERB_SET_GPIO_MASK, 0x40}, | ||
5005 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x40}, | ||
5006 | {0x01, AC_VERB_SET_GPIO_DATA, 0x00}, | ||
5007 | { } | ||
5008 | }, | ||
5009 | .chained = true, | ||
5010 | .chain_id = ALC288_FIXUP_DELL1_MIC_NO_PRESENCE | ||
5011 | }, | ||
4925 | }; | 5012 | }; |
4926 | 5013 | ||
4927 | static const struct snd_pci_quirk alc269_fixup_tbl[] = { | 5014 | static const struct snd_pci_quirk alc269_fixup_tbl[] = { |
@@ -5047,12 +5134,14 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = { | |||
5047 | SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad T440", ALC292_FIXUP_TPT440_DOCK), | 5134 | SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad T440", ALC292_FIXUP_TPT440_DOCK), |
5048 | SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad X240", ALC292_FIXUP_TPT440_DOCK), | 5135 | SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad X240", ALC292_FIXUP_TPT440_DOCK), |
5049 | SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), | 5136 | SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), |
5137 | SND_PCI_QUIRK(0x17aa, 0x2226, "ThinkPad X250", ALC292_FIXUP_TPT440_DOCK), | ||
5050 | SND_PCI_QUIRK(0x17aa, 0x3977, "IdeaPad S210", ALC283_FIXUP_INT_MIC), | 5138 | SND_PCI_QUIRK(0x17aa, 0x3977, "IdeaPad S210", ALC283_FIXUP_INT_MIC), |
5051 | SND_PCI_QUIRK(0x17aa, 0x3978, "IdeaPad Y410P", ALC269_FIXUP_NO_SHUTUP), | 5139 | SND_PCI_QUIRK(0x17aa, 0x3978, "IdeaPad Y410P", ALC269_FIXUP_NO_SHUTUP), |
5052 | SND_PCI_QUIRK(0x17aa, 0x5013, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), | 5140 | SND_PCI_QUIRK(0x17aa, 0x5013, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), |
5053 | SND_PCI_QUIRK(0x17aa, 0x501a, "Thinkpad", ALC283_FIXUP_INT_MIC), | 5141 | SND_PCI_QUIRK(0x17aa, 0x501a, "Thinkpad", ALC283_FIXUP_INT_MIC), |
5054 | SND_PCI_QUIRK(0x17aa, 0x501e, "Thinkpad L440", ALC292_FIXUP_TPT440_DOCK), | 5142 | SND_PCI_QUIRK(0x17aa, 0x501e, "Thinkpad L440", ALC292_FIXUP_TPT440_DOCK), |
5055 | SND_PCI_QUIRK(0x17aa, 0x5026, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), | 5143 | SND_PCI_QUIRK(0x17aa, 0x5026, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), |
5144 | SND_PCI_QUIRK(0x17aa, 0x5034, "Thinkpad T450", ALC292_FIXUP_TPT440_DOCK), | ||
5056 | SND_PCI_QUIRK(0x17aa, 0x5036, "Thinkpad T450s", ALC292_FIXUP_TPT440_DOCK), | 5145 | SND_PCI_QUIRK(0x17aa, 0x5036, "Thinkpad T450s", ALC292_FIXUP_TPT440_DOCK), |
5057 | SND_PCI_QUIRK(0x17aa, 0x5109, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), | 5146 | SND_PCI_QUIRK(0x17aa, 0x5109, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), |
5058 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K), | 5147 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K), |
@@ -5149,6 +5238,13 @@ static const struct hda_model_fixup alc269_fixup_models[] = { | |||
5149 | {0x1b, 0x411111f0}, \ | 5238 | {0x1b, 0x411111f0}, \ |
5150 | {0x1e, 0x411111f0} | 5239 | {0x1e, 0x411111f0} |
5151 | 5240 | ||
5241 | #define ALC288_STANDARD_PINS \ | ||
5242 | {0x17, 0x411111f0}, \ | ||
5243 | {0x18, 0x411111f0}, \ | ||
5244 | {0x19, 0x411111f0}, \ | ||
5245 | {0x1a, 0x411111f0}, \ | ||
5246 | {0x1e, 0x411111f0} | ||
5247 | |||
5152 | #define ALC290_STANDARD_PINS \ | 5248 | #define ALC290_STANDARD_PINS \ |
5153 | {0x12, 0x99a30130}, \ | 5249 | {0x12, 0x99a30130}, \ |
5154 | {0x13, 0x40000000}, \ | 5250 | {0x13, 0x40000000}, \ |
@@ -5344,6 +5440,13 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = { | |||
5344 | {0x19, 0x03a11020}, | 5440 | {0x19, 0x03a11020}, |
5345 | {0x1d, 0x40e00001}, | 5441 | {0x1d, 0x40e00001}, |
5346 | {0x21, 0x0321101f}), | 5442 | {0x21, 0x0321101f}), |
5443 | SND_HDA_PIN_QUIRK(0x10ec0288, 0x1028, "Dell", ALC288_FIXUP_DELL_XPS_13_GPIO6, | ||
5444 | ALC288_STANDARD_PINS, | ||
5445 | {0x12, 0x90a60120}, | ||
5446 | {0x13, 0x40000000}, | ||
5447 | {0x14, 0x90170110}, | ||
5448 | {0x1d, 0x4076832d}, | ||
5449 | {0x21, 0x0321101f}), | ||
5347 | SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1, | 5450 | SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1, |
5348 | ALC290_STANDARD_PINS, | 5451 | ALC290_STANDARD_PINS, |
5349 | {0x14, 0x411111f0}, | 5452 | {0x14, 0x411111f0}, |
@@ -5484,6 +5587,7 @@ static int patch_alc269(struct hda_codec *codec) | |||
5484 | 5587 | ||
5485 | spec = codec->spec; | 5588 | spec = codec->spec; |
5486 | spec->gen.shared_mic_vref_pin = 0x18; | 5589 | spec->gen.shared_mic_vref_pin = 0x18; |
5590 | codec->power_save_node = 1; | ||
5487 | 5591 | ||
5488 | snd_hda_pick_fixup(codec, alc269_fixup_models, | 5592 | snd_hda_pick_fixup(codec, alc269_fixup_models, |
5489 | alc269_fixup_tbl, alc269_fixups); | 5593 | alc269_fixup_tbl, alc269_fixups); |
@@ -5497,7 +5601,7 @@ static int patch_alc269(struct hda_codec *codec) | |||
5497 | if (has_cdefine_beep(codec)) | 5601 | if (has_cdefine_beep(codec)) |
5498 | spec->gen.beep_nid = 0x01; | 5602 | spec->gen.beep_nid = 0x01; |
5499 | 5603 | ||
5500 | switch (codec->vendor_id) { | 5604 | switch (codec->core.vendor_id) { |
5501 | case 0x10ec0269: | 5605 | case 0x10ec0269: |
5502 | spec->codec_variant = ALC269_TYPE_ALC269VA; | 5606 | spec->codec_variant = ALC269_TYPE_ALC269VA; |
5503 | switch (alc_get_coef0(codec) & 0x00f0) { | 5607 | switch (alc_get_coef0(codec) & 0x00f0) { |
@@ -5580,6 +5684,7 @@ static int patch_alc269(struct hda_codec *codec) | |||
5580 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); | 5684 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); |
5581 | 5685 | ||
5582 | codec->patch_ops = alc_patch_ops; | 5686 | codec->patch_ops = alc_patch_ops; |
5687 | codec->patch_ops.stream_pm = snd_hda_gen_stream_pm; | ||
5583 | #ifdef CONFIG_PM | 5688 | #ifdef CONFIG_PM |
5584 | codec->patch_ops.suspend = alc269_suspend; | 5689 | codec->patch_ops.suspend = alc269_suspend; |
5585 | codec->patch_ops.resume = alc269_resume; | 5690 | codec->patch_ops.resume = alc269_resume; |
@@ -5841,9 +5946,9 @@ static int alc662_parse_auto_config(struct hda_codec *codec) | |||
5841 | static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 }; | 5946 | static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
5842 | const hda_nid_t *ssids; | 5947 | const hda_nid_t *ssids; |
5843 | 5948 | ||
5844 | if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 || | 5949 | if (codec->core.vendor_id == 0x10ec0272 || codec->core.vendor_id == 0x10ec0663 || |
5845 | codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670 || | 5950 | codec->core.vendor_id == 0x10ec0665 || codec->core.vendor_id == 0x10ec0670 || |
5846 | codec->vendor_id == 0x10ec0671) | 5951 | codec->core.vendor_id == 0x10ec0671) |
5847 | ssids = alc663_ssids; | 5952 | ssids = alc663_ssids; |
5848 | else | 5953 | else |
5849 | ssids = alc662_ssids; | 5954 | ssids = alc662_ssids; |
@@ -5878,7 +5983,7 @@ static void alc_fixup_bass_chmap(struct hda_codec *codec, | |||
5878 | { | 5983 | { |
5879 | if (action == HDA_FIXUP_ACT_BUILD) { | 5984 | if (action == HDA_FIXUP_ACT_BUILD) { |
5880 | struct alc_spec *spec = codec->spec; | 5985 | struct alc_spec *spec = codec->spec; |
5881 | spec->gen.pcm_rec[0].stream[0].chmap = asus_pcm_2_1_chmaps; | 5986 | spec->gen.pcm_rec[0]->stream[0].chmap = asus_pcm_2_1_chmaps; |
5882 | } | 5987 | } |
5883 | } | 5988 | } |
5884 | 5989 | ||
@@ -5888,7 +5993,7 @@ static unsigned int gpio_led_power_filter(struct hda_codec *codec, | |||
5888 | unsigned int power_state) | 5993 | unsigned int power_state) |
5889 | { | 5994 | { |
5890 | struct alc_spec *spec = codec->spec; | 5995 | struct alc_spec *spec = codec->spec; |
5891 | if (nid == codec->afg && power_state == AC_PWRST_D3 && spec->gpio_led) | 5996 | if (nid == codec->core.afg && power_state == AC_PWRST_D3 && spec->gpio_led) |
5892 | return AC_PWRST_D0; | 5997 | return AC_PWRST_D0; |
5893 | return power_state; | 5998 | return power_state; |
5894 | } | 5999 | } |
@@ -6386,7 +6491,7 @@ static int patch_alc662(struct hda_codec *codec) | |||
6386 | 6491 | ||
6387 | alc_fix_pll_init(codec, 0x20, 0x04, 15); | 6492 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
6388 | 6493 | ||
6389 | switch (codec->vendor_id) { | 6494 | switch (codec->core.vendor_id) { |
6390 | case 0x10ec0668: | 6495 | case 0x10ec0668: |
6391 | spec->init_hook = alc668_restore_default_value; | 6496 | spec->init_hook = alc668_restore_default_value; |
6392 | break; | 6497 | break; |
@@ -6416,7 +6521,7 @@ static int patch_alc662(struct hda_codec *codec) | |||
6416 | goto error; | 6521 | goto error; |
6417 | 6522 | ||
6418 | if (!spec->gen.no_analog && spec->gen.beep_nid) { | 6523 | if (!spec->gen.no_analog && spec->gen.beep_nid) { |
6419 | switch (codec->vendor_id) { | 6524 | switch (codec->core.vendor_id) { |
6420 | case 0x10ec0662: | 6525 | case 0x10ec0662: |
6421 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); | 6526 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
6422 | break; | 6527 | break; |
@@ -6549,20 +6654,8 @@ MODULE_ALIAS("snd-hda-codec-id:10ec*"); | |||
6549 | MODULE_LICENSE("GPL"); | 6654 | MODULE_LICENSE("GPL"); |
6550 | MODULE_DESCRIPTION("Realtek HD-audio codec"); | 6655 | MODULE_DESCRIPTION("Realtek HD-audio codec"); |
6551 | 6656 | ||
6552 | static struct hda_codec_preset_list realtek_list = { | 6657 | static struct hda_codec_driver realtek_driver = { |
6553 | .preset = snd_hda_preset_realtek, | 6658 | .preset = snd_hda_preset_realtek, |
6554 | .owner = THIS_MODULE, | ||
6555 | }; | 6659 | }; |
6556 | 6660 | ||
6557 | static int __init patch_realtek_init(void) | 6661 | module_hda_codec_driver(realtek_driver); |
6558 | { | ||
6559 | return snd_hda_add_codec_preset(&realtek_list); | ||
6560 | } | ||
6561 | |||
6562 | static void __exit patch_realtek_exit(void) | ||
6563 | { | ||
6564 | snd_hda_delete_codec_preset(&realtek_list); | ||
6565 | } | ||
6566 | |||
6567 | module_init(patch_realtek_init) | ||
6568 | module_exit(patch_realtek_exit) | ||
diff --git a/sound/pci/hda/patch_si3054.c b/sound/pci/hda/patch_si3054.c index 3208ad69583e..5104bebb2286 100644 --- a/sound/pci/hda/patch_si3054.c +++ b/sound/pci/hda/patch_si3054.c | |||
@@ -83,7 +83,6 @@ | |||
83 | 83 | ||
84 | struct si3054_spec { | 84 | struct si3054_spec { |
85 | unsigned international; | 85 | unsigned international; |
86 | struct hda_pcm pcm; | ||
87 | }; | 86 | }; |
88 | 87 | ||
89 | 88 | ||
@@ -199,15 +198,15 @@ static const struct hda_pcm_stream si3054_pcm = { | |||
199 | 198 | ||
200 | static int si3054_build_pcms(struct hda_codec *codec) | 199 | static 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->core.mfg; |
210 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = codec->mfg; | 209 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = codec->core.mfg; |
211 | info->pcm_type = HDA_PCM_TYPE_MODEM; | 210 | info->pcm_type = HDA_PCM_TYPE_MODEM; |
212 | return 0; | 211 | return 0; |
213 | } | 212 | } |
@@ -223,8 +222,12 @@ static int si3054_init(struct hda_codec *codec) | |||
223 | unsigned wait_count; | 222 | unsigned wait_count; |
224 | u16 val; | 223 | u16 val; |
225 | 224 | ||
225 | if (snd_hdac_regmap_add_vendor_verb(&codec->core, | ||
226 | SI3054_VERB_WRITE_NODE)) | ||
227 | return -ENOMEM; | ||
228 | |||
226 | snd_hda_codec_write(codec, AC_NODE_ROOT, 0, AC_VERB_SET_CODEC_RESET, 0); | 229 | snd_hda_codec_write(codec, AC_NODE_ROOT, 0, AC_VERB_SET_CODEC_RESET, 0); |
227 | snd_hda_codec_write(codec, codec->mfg, 0, AC_VERB_SET_STREAM_FORMAT, 0); | 230 | snd_hda_codec_write(codec, codec->core.mfg, 0, AC_VERB_SET_STREAM_FORMAT, 0); |
228 | SET_REG(codec, SI3054_LINE_RATE, 9600); | 231 | SET_REG(codec, SI3054_LINE_RATE, 9600); |
229 | SET_REG(codec, SI3054_LINE_LEVEL, SI3054_DTAG_MASK|SI3054_ATAG_MASK); | 232 | SET_REG(codec, SI3054_LINE_LEVEL, SI3054_DTAG_MASK|SI3054_ATAG_MASK); |
230 | SET_REG(codec, SI3054_EXTENDED_MID, 0); | 233 | SET_REG(codec, SI3054_EXTENDED_MID, 0); |
@@ -319,20 +322,8 @@ MODULE_ALIAS("snd-hda-codec-id:18540018"); | |||
319 | MODULE_LICENSE("GPL"); | 322 | MODULE_LICENSE("GPL"); |
320 | MODULE_DESCRIPTION("Si3054 HD-audio modem codec"); | 323 | MODULE_DESCRIPTION("Si3054 HD-audio modem codec"); |
321 | 324 | ||
322 | static struct hda_codec_preset_list si3054_list = { | 325 | static struct hda_codec_driver si3054_driver = { |
323 | .preset = snd_hda_preset_si3054, | 326 | .preset = snd_hda_preset_si3054, |
324 | .owner = THIS_MODULE, | ||
325 | }; | 327 | }; |
326 | 328 | ||
327 | static int __init patch_si3054_init(void) | 329 | module_hda_codec_driver(si3054_driver); |
328 | { | ||
329 | return snd_hda_add_codec_preset(&si3054_list); | ||
330 | } | ||
331 | |||
332 | static void __exit patch_si3054_exit(void) | ||
333 | { | ||
334 | snd_hda_delete_codec_preset(&si3054_list); | ||
335 | } | ||
336 | |||
337 | module_init(patch_si3054_init) | ||
338 | module_exit(patch_si3054_exit) | ||
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c index 87eff3173ce9..43c99ce4a520 100644 --- a/sound/pci/hda/patch_sigmatel.c +++ b/sound/pci/hda/patch_sigmatel.c | |||
@@ -299,32 +299,33 @@ static void stac_gpio_set(struct hda_codec *codec, unsigned int mask, | |||
299 | unsigned int dir_mask, unsigned int data) | 299 | unsigned int dir_mask, unsigned int data) |
300 | { | 300 | { |
301 | unsigned int gpiostate, gpiomask, gpiodir; | 301 | unsigned int gpiostate, gpiomask, gpiodir; |
302 | hda_nid_t fg = codec->core.afg; | ||
302 | 303 | ||
303 | codec_dbg(codec, "%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data); | 304 | codec_dbg(codec, "%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data); |
304 | 305 | ||
305 | gpiostate = snd_hda_codec_read(codec, codec->afg, 0, | 306 | gpiostate = snd_hda_codec_read(codec, fg, 0, |
306 | AC_VERB_GET_GPIO_DATA, 0); | 307 | AC_VERB_GET_GPIO_DATA, 0); |
307 | gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask); | 308 | gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask); |
308 | 309 | ||
309 | gpiomask = snd_hda_codec_read(codec, codec->afg, 0, | 310 | gpiomask = snd_hda_codec_read(codec, fg, 0, |
310 | AC_VERB_GET_GPIO_MASK, 0); | 311 | AC_VERB_GET_GPIO_MASK, 0); |
311 | gpiomask |= mask; | 312 | gpiomask |= mask; |
312 | 313 | ||
313 | gpiodir = snd_hda_codec_read(codec, codec->afg, 0, | 314 | gpiodir = snd_hda_codec_read(codec, fg, 0, |
314 | AC_VERB_GET_GPIO_DIRECTION, 0); | 315 | AC_VERB_GET_GPIO_DIRECTION, 0); |
315 | gpiodir |= dir_mask; | 316 | gpiodir |= dir_mask; |
316 | 317 | ||
317 | /* Configure GPIOx as CMOS */ | 318 | /* Configure GPIOx as CMOS */ |
318 | snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0); | 319 | snd_hda_codec_write(codec, fg, 0, 0x7e7, 0); |
319 | 320 | ||
320 | snd_hda_codec_write(codec, codec->afg, 0, | 321 | snd_hda_codec_write(codec, fg, 0, |
321 | AC_VERB_SET_GPIO_MASK, gpiomask); | 322 | AC_VERB_SET_GPIO_MASK, gpiomask); |
322 | snd_hda_codec_read(codec, codec->afg, 0, | 323 | snd_hda_codec_read(codec, fg, 0, |
323 | AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */ | 324 | AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */ |
324 | 325 | ||
325 | msleep(1); | 326 | msleep(1); |
326 | 327 | ||
327 | snd_hda_codec_read(codec, codec->afg, 0, | 328 | snd_hda_codec_read(codec, fg, 0, |
328 | AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */ | 329 | AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */ |
329 | } | 330 | } |
330 | 331 | ||
@@ -387,7 +388,7 @@ static unsigned int stac_vref_led_power_filter(struct hda_codec *codec, | |||
387 | hda_nid_t nid, | 388 | hda_nid_t nid, |
388 | unsigned int power_state) | 389 | unsigned int power_state) |
389 | { | 390 | { |
390 | if (nid == codec->afg && power_state == AC_PWRST_D3) | 391 | if (nid == codec->core.afg && power_state == AC_PWRST_D3) |
391 | return AC_PWRST_D1; | 392 | return AC_PWRST_D1; |
392 | return snd_hda_gen_path_power_filter(codec, nid, power_state); | 393 | return snd_hda_gen_path_power_filter(codec, nid, power_state); |
393 | } | 394 | } |
@@ -432,7 +433,7 @@ static void stac_update_outputs(struct hda_codec *codec) | |||
432 | 433 | ||
433 | if (spec->gpio_mute) | 434 | if (spec->gpio_mute) |
434 | spec->gen.master_mute = | 435 | spec->gen.master_mute = |
435 | !(snd_hda_codec_read(codec, codec->afg, 0, | 436 | !(snd_hda_codec_read(codec, codec->core.afg, 0, |
436 | AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute); | 437 | AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute); |
437 | 438 | ||
438 | snd_hda_gen_update_outputs(codec); | 439 | snd_hda_gen_update_outputs(codec); |
@@ -476,7 +477,7 @@ static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid, | |||
476 | if (val != spec->power_map_bits) { | 477 | if (val != spec->power_map_bits) { |
477 | spec->power_map_bits = val; | 478 | spec->power_map_bits = val; |
478 | if (do_write) | 479 | if (do_write) |
479 | snd_hda_codec_write(codec, codec->afg, 0, | 480 | snd_hda_codec_write(codec, codec->core.afg, 0, |
480 | AC_VERB_IDT_SET_POWER_MAP, val); | 481 | AC_VERB_IDT_SET_POWER_MAP, val); |
481 | } | 482 | } |
482 | } | 483 | } |
@@ -508,7 +509,8 @@ static void jack_update_power(struct hda_codec *codec, | |||
508 | false); | 509 | false); |
509 | } | 510 | } |
510 | 511 | ||
511 | snd_hda_codec_write(codec, codec->afg, 0, AC_VERB_IDT_SET_POWER_MAP, | 512 | snd_hda_codec_write(codec, codec->core.afg, 0, |
513 | AC_VERB_IDT_SET_POWER_MAP, | ||
512 | spec->power_map_bits); | 514 | spec->power_map_bits); |
513 | } | 515 | } |
514 | 516 | ||
@@ -517,10 +519,10 @@ static void stac_vref_event(struct hda_codec *codec, | |||
517 | { | 519 | { |
518 | unsigned int data; | 520 | unsigned int data; |
519 | 521 | ||
520 | data = snd_hda_codec_read(codec, codec->afg, 0, | 522 | data = snd_hda_codec_read(codec, codec->core.afg, 0, |
521 | AC_VERB_GET_GPIO_DATA, 0); | 523 | AC_VERB_GET_GPIO_DATA, 0); |
522 | /* toggle VREF state based on GPIOx status */ | 524 | /* toggle VREF state based on GPIOx status */ |
523 | snd_hda_codec_write(codec, codec->afg, 0, 0x7e0, | 525 | snd_hda_codec_write(codec, codec->core.afg, 0, 0x7e0, |
524 | !!(data & (1 << event->private_data))); | 526 | !!(data & (1 << event->private_data))); |
525 | } | 527 | } |
526 | 528 | ||
@@ -622,7 +624,7 @@ static int stac_aloopback_put(struct snd_kcontrol *kcontrol, | |||
622 | /* Only return the bits defined by the shift value of the | 624 | /* Only return the bits defined by the shift value of the |
623 | * first two bytes of the mask | 625 | * first two bytes of the mask |
624 | */ | 626 | */ |
625 | dac_mode = snd_hda_codec_read(codec, codec->afg, 0, | 627 | dac_mode = snd_hda_codec_read(codec, codec->core.afg, 0, |
626 | kcontrol->private_value & 0xFFFF, 0x0); | 628 | kcontrol->private_value & 0xFFFF, 0x0); |
627 | dac_mode >>= spec->aloopback_shift; | 629 | dac_mode >>= spec->aloopback_shift; |
628 | 630 | ||
@@ -634,7 +636,7 @@ static int stac_aloopback_put(struct snd_kcontrol *kcontrol, | |||
634 | dac_mode &= ~idx_val; | 636 | dac_mode &= ~idx_val; |
635 | } | 637 | } |
636 | 638 | ||
637 | snd_hda_codec_write_cache(codec, codec->afg, 0, | 639 | snd_hda_codec_write_cache(codec, codec->core.afg, 0, |
638 | kcontrol->private_value >> 16, dac_mode); | 640 | kcontrol->private_value >> 16, dac_mode); |
639 | 641 | ||
640 | return 1; | 642 | return 1; |
@@ -658,11 +660,11 @@ static int stac_aloopback_put(struct snd_kcontrol *kcontrol, | |||
658 | /* check whether it's a HP laptop with a docking port */ | 660 | /* check whether it's a HP laptop with a docking port */ |
659 | static bool hp_bnb2011_with_dock(struct hda_codec *codec) | 661 | static bool hp_bnb2011_with_dock(struct hda_codec *codec) |
660 | { | 662 | { |
661 | if (codec->vendor_id != 0x111d7605 && | 663 | if (codec->core.vendor_id != 0x111d7605 && |
662 | codec->vendor_id != 0x111d76d1) | 664 | codec->core.vendor_id != 0x111d76d1) |
663 | return false; | 665 | return false; |
664 | 666 | ||
665 | switch (codec->subsystem_id) { | 667 | switch (codec->core.subsystem_id) { |
666 | case 0x103c1618: | 668 | case 0x103c1618: |
667 | case 0x103c1619: | 669 | case 0x103c1619: |
668 | case 0x103c161a: | 670 | case 0x103c161a: |
@@ -733,7 +735,7 @@ static void set_hp_led_gpio(struct hda_codec *codec) | |||
733 | if (spec->gpio_led) | 735 | if (spec->gpio_led) |
734 | return; | 736 | return; |
735 | 737 | ||
736 | gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP); | 738 | gpio = snd_hda_param_read(codec, codec->core.afg, AC_PAR_GPIO_CAP); |
737 | gpio &= AC_GPIO_IO_COUNT; | 739 | gpio &= AC_GPIO_IO_COUNT; |
738 | if (gpio > 3) | 740 | if (gpio > 3) |
739 | spec->gpio_led = 0x08; /* GPIO 3 */ | 741 | spec->gpio_led = 0x08; /* GPIO 3 */ |
@@ -777,7 +779,7 @@ static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity) | |||
777 | &spec->gpio_led_polarity, | 779 | &spec->gpio_led_polarity, |
778 | &spec->gpio_led) == 2) { | 780 | &spec->gpio_led) == 2) { |
779 | unsigned int max_gpio; | 781 | unsigned int max_gpio; |
780 | max_gpio = snd_hda_param_read(codec, codec->afg, | 782 | max_gpio = snd_hda_param_read(codec, codec->core.afg, |
781 | AC_PAR_GPIO_CAP); | 783 | AC_PAR_GPIO_CAP); |
782 | max_gpio &= AC_GPIO_IO_COUNT; | 784 | max_gpio &= AC_GPIO_IO_COUNT; |
783 | if (spec->gpio_led < max_gpio) | 785 | if (spec->gpio_led < max_gpio) |
@@ -807,7 +809,7 @@ static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity) | |||
807 | * we statically set the GPIO - if not a B-series system | 809 | * we statically set the GPIO - if not a B-series system |
808 | * and default polarity is provided | 810 | * and default polarity is provided |
809 | */ | 811 | */ |
810 | if (!hp_blike_system(codec->subsystem_id) && | 812 | if (!hp_blike_system(codec->core.subsystem_id) && |
811 | (default_polarity == 0 || default_polarity == 1)) { | 813 | (default_polarity == 0 || default_polarity == 1)) { |
812 | set_hp_led_gpio(codec); | 814 | set_hp_led_gpio(codec); |
813 | spec->gpio_led_polarity = default_polarity; | 815 | spec->gpio_led_polarity = default_polarity; |
@@ -1048,12 +1050,9 @@ static const struct hda_verb stac92hd71bxx_core_init[] = { | |||
1048 | {} | 1050 | {} |
1049 | }; | 1051 | }; |
1050 | 1052 | ||
1051 | static const struct hda_verb stac92hd71bxx_unmute_core_init[] = { | 1053 | static const hda_nid_t stac92hd71bxx_unmute_nids[] = { |
1052 | /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */ | 1054 | /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */ |
1053 | { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | 1055 | 0x0f, 0x0a, 0x0d, 0 |
1054 | { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
1055 | { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
1056 | {} | ||
1057 | }; | 1056 | }; |
1058 | 1057 | ||
1059 | static const struct hda_verb stac925x_core_init[] = { | 1058 | static const struct hda_verb stac925x_core_init[] = { |
@@ -2132,8 +2131,10 @@ static void stac92hd83xxx_fixup_hp_mic_led(struct hda_codec *codec, | |||
2132 | 2131 | ||
2133 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { | 2132 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { |
2134 | spec->mic_mute_led_gpio = 0x08; /* GPIO3 */ | 2133 | spec->mic_mute_led_gpio = 0x08; /* GPIO3 */ |
2134 | #ifdef CONFIG_PM | ||
2135 | /* resetting controller clears GPIO, so we need to keep on */ | 2135 | /* resetting controller clears GPIO, so we need to keep on */ |
2136 | codec->bus->power_keep_link_on = 1; | 2136 | codec->core.power_caps &= ~AC_PWRST_CLKSTOP; |
2137 | #endif | ||
2137 | } | 2138 | } |
2138 | } | 2139 | } |
2139 | 2140 | ||
@@ -3029,9 +3030,9 @@ static void stac92hd71bxx_fixup_hp_m4(struct hda_codec *codec, | |||
3029 | return; | 3030 | return; |
3030 | 3031 | ||
3031 | /* Enable VREF power saving on GPIO1 detect */ | 3032 | /* Enable VREF power saving on GPIO1 detect */ |
3032 | snd_hda_codec_write_cache(codec, codec->afg, 0, | 3033 | snd_hda_codec_write_cache(codec, codec->core.afg, 0, |
3033 | AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02); | 3034 | AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02); |
3034 | jack = snd_hda_jack_detect_enable_callback(codec, codec->afg, | 3035 | jack = snd_hda_jack_detect_enable_callback(codec, codec->core.afg, |
3035 | stac_vref_event); | 3036 | stac_vref_event); |
3036 | if (!IS_ERR(jack)) | 3037 | if (!IS_ERR(jack)) |
3037 | jack->private_data = 0x02; | 3038 | jack->private_data = 0x02; |
@@ -3091,7 +3092,7 @@ static void stac92hd71bxx_fixup_hp(struct hda_codec *codec, | |||
3091 | if (action != HDA_FIXUP_ACT_PRE_PROBE) | 3092 | if (action != HDA_FIXUP_ACT_PRE_PROBE) |
3092 | return; | 3093 | return; |
3093 | 3094 | ||
3094 | if (hp_blike_system(codec->subsystem_id)) { | 3095 | if (hp_blike_system(codec->core.subsystem_id)) { |
3095 | unsigned int pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f); | 3096 | unsigned int pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f); |
3096 | if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT || | 3097 | if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT || |
3097 | get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER || | 3098 | get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER || |
@@ -3790,7 +3791,7 @@ static void stac927x_fixup_dell_dmic(struct hda_codec *codec, | |||
3790 | if (action != HDA_FIXUP_ACT_PRE_PROBE) | 3791 | if (action != HDA_FIXUP_ACT_PRE_PROBE) |
3791 | return; | 3792 | return; |
3792 | 3793 | ||
3793 | if (codec->subsystem_id != 0x1028022f) { | 3794 | if (codec->core.subsystem_id != 0x1028022f) { |
3794 | /* GPIO2 High = Enable EAPD */ | 3795 | /* GPIO2 High = Enable EAPD */ |
3795 | spec->eapd_mask = spec->gpio_mask = 0x04; | 3796 | spec->eapd_mask = spec->gpio_mask = 0x04; |
3796 | spec->gpio_dir = spec->gpio_data = 0x04; | 3797 | spec->gpio_dir = spec->gpio_data = 0x04; |
@@ -4051,9 +4052,9 @@ static void stac9205_fixup_dell_m43(struct hda_codec *codec, | |||
4051 | snd_hda_apply_pincfgs(codec, dell_9205_m43_pin_configs); | 4052 | snd_hda_apply_pincfgs(codec, dell_9205_m43_pin_configs); |
4052 | 4053 | ||
4053 | /* Enable unsol response for GPIO4/Dock HP connection */ | 4054 | /* Enable unsol response for GPIO4/Dock HP connection */ |
4054 | snd_hda_codec_write_cache(codec, codec->afg, 0, | 4055 | snd_hda_codec_write_cache(codec, codec->core.afg, 0, |
4055 | AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10); | 4056 | AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10); |
4056 | jack = snd_hda_jack_detect_enable_callback(codec, codec->afg, | 4057 | jack = snd_hda_jack_detect_enable_callback(codec, codec->core.afg, |
4057 | stac_vref_event); | 4058 | stac_vref_event); |
4058 | if (!IS_ERR(jack)) | 4059 | if (!IS_ERR(jack)) |
4059 | jack->private_data = 0x01; | 4060 | jack->private_data = 0x01; |
@@ -4223,6 +4224,12 @@ static int stac_parse_auto_config(struct hda_codec *codec) | |||
4223 | if (err < 0) | 4224 | if (err < 0) |
4224 | return err; | 4225 | return err; |
4225 | 4226 | ||
4227 | if (spec->vref_mute_led_nid) { | ||
4228 | err = snd_hda_gen_fix_pin_power(codec, spec->vref_mute_led_nid); | ||
4229 | if (err < 0) | ||
4230 | return err; | ||
4231 | } | ||
4232 | |||
4226 | /* setup analog beep controls */ | 4233 | /* setup analog beep controls */ |
4227 | if (spec->anabeep_nid > 0) { | 4234 | if (spec->anabeep_nid > 0) { |
4228 | err = stac_auto_create_beep_ctls(codec, | 4235 | err = stac_auto_create_beep_ctls(codec, |
@@ -4259,6 +4266,10 @@ static int stac_parse_auto_config(struct hda_codec *codec) | |||
4259 | 4266 | ||
4260 | if (spec->aloopback_ctl && | 4267 | if (spec->aloopback_ctl && |
4261 | snd_hda_get_bool_hint(codec, "loopback") == 1) { | 4268 | snd_hda_get_bool_hint(codec, "loopback") == 1) { |
4269 | unsigned int wr_verb = | ||
4270 | spec->aloopback_ctl->private_value >> 16; | ||
4271 | if (snd_hdac_regmap_add_vendor_verb(&codec->core, wr_verb)) | ||
4272 | return -ENOMEM; | ||
4262 | if (!snd_hda_gen_add_kctl(&spec->gen, NULL, spec->aloopback_ctl)) | 4273 | if (!snd_hda_gen_add_kctl(&spec->gen, NULL, spec->aloopback_ctl)) |
4263 | return -ENOMEM; | 4274 | return -ENOMEM; |
4264 | } | 4275 | } |
@@ -4294,7 +4305,7 @@ static int stac_init(struct hda_codec *codec) | |||
4294 | 4305 | ||
4295 | /* sync the power-map */ | 4306 | /* sync the power-map */ |
4296 | if (spec->num_pwrs) | 4307 | if (spec->num_pwrs) |
4297 | snd_hda_codec_write(codec, codec->afg, 0, | 4308 | snd_hda_codec_write(codec, codec->core.afg, 0, |
4298 | AC_VERB_IDT_SET_POWER_MAP, | 4309 | AC_VERB_IDT_SET_POWER_MAP, |
4299 | spec->power_map_bits); | 4310 | spec->power_map_bits); |
4300 | 4311 | ||
@@ -4330,7 +4341,7 @@ static void stac_shutup(struct hda_codec *codec) | |||
4330 | static void stac92hd_proc_hook(struct snd_info_buffer *buffer, | 4341 | static void stac92hd_proc_hook(struct snd_info_buffer *buffer, |
4331 | struct hda_codec *codec, hda_nid_t nid) | 4342 | struct hda_codec *codec, hda_nid_t nid) |
4332 | { | 4343 | { |
4333 | if (nid == codec->afg) | 4344 | if (nid == codec->core.afg) |
4334 | snd_iprintf(buffer, "Power-Map: 0x%02x\n", | 4345 | snd_iprintf(buffer, "Power-Map: 0x%02x\n", |
4335 | snd_hda_codec_read(codec, nid, 0, | 4346 | snd_hda_codec_read(codec, nid, 0, |
4336 | AC_VERB_IDT_GET_POWER_MAP, 0)); | 4347 | AC_VERB_IDT_GET_POWER_MAP, 0)); |
@@ -4341,7 +4352,7 @@ static void analog_loop_proc_hook(struct snd_info_buffer *buffer, | |||
4341 | unsigned int verb) | 4352 | unsigned int verb) |
4342 | { | 4353 | { |
4343 | snd_iprintf(buffer, "Analog Loopback: 0x%02x\n", | 4354 | snd_iprintf(buffer, "Analog Loopback: 0x%02x\n", |
4344 | snd_hda_codec_read(codec, codec->afg, 0, verb, 0)); | 4355 | snd_hda_codec_read(codec, codec->core.afg, 0, verb, 0)); |
4345 | } | 4356 | } |
4346 | 4357 | ||
4347 | /* stac92hd71bxx, stac92hd73xx */ | 4358 | /* stac92hd71bxx, stac92hd73xx */ |
@@ -4349,21 +4360,21 @@ static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer, | |||
4349 | struct hda_codec *codec, hda_nid_t nid) | 4360 | struct hda_codec *codec, hda_nid_t nid) |
4350 | { | 4361 | { |
4351 | stac92hd_proc_hook(buffer, codec, nid); | 4362 | stac92hd_proc_hook(buffer, codec, nid); |
4352 | if (nid == codec->afg) | 4363 | if (nid == codec->core.afg) |
4353 | analog_loop_proc_hook(buffer, codec, 0xfa0); | 4364 | analog_loop_proc_hook(buffer, codec, 0xfa0); |
4354 | } | 4365 | } |
4355 | 4366 | ||
4356 | static void stac9205_proc_hook(struct snd_info_buffer *buffer, | 4367 | static void stac9205_proc_hook(struct snd_info_buffer *buffer, |
4357 | struct hda_codec *codec, hda_nid_t nid) | 4368 | struct hda_codec *codec, hda_nid_t nid) |
4358 | { | 4369 | { |
4359 | if (nid == codec->afg) | 4370 | if (nid == codec->core.afg) |
4360 | analog_loop_proc_hook(buffer, codec, 0xfe0); | 4371 | analog_loop_proc_hook(buffer, codec, 0xfe0); |
4361 | } | 4372 | } |
4362 | 4373 | ||
4363 | static void stac927x_proc_hook(struct snd_info_buffer *buffer, | 4374 | static void stac927x_proc_hook(struct snd_info_buffer *buffer, |
4364 | struct hda_codec *codec, hda_nid_t nid) | 4375 | struct hda_codec *codec, hda_nid_t nid) |
4365 | { | 4376 | { |
4366 | if (nid == codec->afg) | 4377 | if (nid == codec->core.afg) |
4367 | analog_loop_proc_hook(buffer, codec, 0xfeb); | 4378 | analog_loop_proc_hook(buffer, codec, 0xfeb); |
4368 | } | 4379 | } |
4369 | #else | 4380 | #else |
@@ -4392,6 +4403,7 @@ static const struct hda_codec_ops stac_patch_ops = { | |||
4392 | #ifdef CONFIG_PM | 4403 | #ifdef CONFIG_PM |
4393 | .suspend = stac_suspend, | 4404 | .suspend = stac_suspend, |
4394 | #endif | 4405 | #endif |
4406 | .stream_pm = snd_hda_gen_stream_pm, | ||
4395 | .reboot_notify = stac_shutup, | 4407 | .reboot_notify = stac_shutup, |
4396 | }; | 4408 | }; |
4397 | 4409 | ||
@@ -4485,6 +4497,7 @@ static int patch_stac92hd73xx(struct hda_codec *codec) | |||
4485 | return err; | 4497 | return err; |
4486 | 4498 | ||
4487 | spec = codec->spec; | 4499 | spec = codec->spec; |
4500 | codec->power_save_node = 1; | ||
4488 | spec->linear_tone_beep = 0; | 4501 | spec->linear_tone_beep = 0; |
4489 | spec->gen.mixer_nid = 0x1d; | 4502 | spec->gen.mixer_nid = 0x1d; |
4490 | spec->have_spdif_mux = 1; | 4503 | spec->have_spdif_mux = 1; |
@@ -4587,9 +4600,11 @@ static int patch_stac92hd83xxx(struct hda_codec *codec) | |||
4587 | if (err < 0) | 4600 | if (err < 0) |
4588 | return err; | 4601 | return err; |
4589 | 4602 | ||
4590 | codec->epss = 0; /* longer delay needed for D3 */ | 4603 | /* longer delay needed for D3 */ |
4604 | codec->core.power_caps &= ~AC_PWRST_EPSS; | ||
4591 | 4605 | ||
4592 | spec = codec->spec; | 4606 | spec = codec->spec; |
4607 | codec->power_save_node = 1; | ||
4593 | spec->linear_tone_beep = 0; | 4608 | spec->linear_tone_beep = 0; |
4594 | spec->gen.own_eapd_ctl = 1; | 4609 | spec->gen.own_eapd_ctl = 1; |
4595 | spec->gen.power_down_unused = 1; | 4610 | spec->gen.power_down_unused = 1; |
@@ -4636,9 +4651,11 @@ static int patch_stac92hd95(struct hda_codec *codec) | |||
4636 | if (err < 0) | 4651 | if (err < 0) |
4637 | return err; | 4652 | return err; |
4638 | 4653 | ||
4639 | codec->epss = 0; /* longer delay needed for D3 */ | 4654 | /* longer delay needed for D3 */ |
4655 | codec->core.power_caps &= ~AC_PWRST_EPSS; | ||
4640 | 4656 | ||
4641 | spec = codec->spec; | 4657 | spec = codec->spec; |
4658 | codec->power_save_node = 1; | ||
4642 | spec->linear_tone_beep = 0; | 4659 | spec->linear_tone_beep = 0; |
4643 | spec->gen.own_eapd_ctl = 1; | 4660 | spec->gen.own_eapd_ctl = 1; |
4644 | spec->gen.power_down_unused = 1; | 4661 | spec->gen.power_down_unused = 1; |
@@ -4672,7 +4689,7 @@ static int patch_stac92hd95(struct hda_codec *codec) | |||
4672 | static int patch_stac92hd71bxx(struct hda_codec *codec) | 4689 | static int patch_stac92hd71bxx(struct hda_codec *codec) |
4673 | { | 4690 | { |
4674 | struct sigmatel_spec *spec; | 4691 | struct sigmatel_spec *spec; |
4675 | const struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init; | 4692 | const hda_nid_t *unmute_nids = stac92hd71bxx_unmute_nids; |
4676 | int err; | 4693 | int err; |
4677 | 4694 | ||
4678 | err = alloc_stac_spec(codec); | 4695 | err = alloc_stac_spec(codec); |
@@ -4680,6 +4697,7 @@ static int patch_stac92hd71bxx(struct hda_codec *codec) | |||
4680 | return err; | 4697 | return err; |
4681 | 4698 | ||
4682 | spec = codec->spec; | 4699 | spec = codec->spec; |
4700 | codec->power_save_node = 1; | ||
4683 | spec->linear_tone_beep = 0; | 4701 | spec->linear_tone_beep = 0; |
4684 | spec->gen.own_eapd_ctl = 1; | 4702 | spec->gen.own_eapd_ctl = 1; |
4685 | spec->gen.power_down_unused = 1; | 4703 | spec->gen.power_down_unused = 1; |
@@ -4693,23 +4711,23 @@ static int patch_stac92hd71bxx(struct hda_codec *codec) | |||
4693 | spec->gpio_dir = 0x01; | 4711 | spec->gpio_dir = 0x01; |
4694 | spec->gpio_data = 0x01; | 4712 | spec->gpio_data = 0x01; |
4695 | 4713 | ||
4696 | switch (codec->vendor_id) { | 4714 | switch (codec->core.vendor_id) { |
4697 | case 0x111d76b6: /* 4 Port without Analog Mixer */ | 4715 | case 0x111d76b6: /* 4 Port without Analog Mixer */ |
4698 | case 0x111d76b7: | 4716 | case 0x111d76b7: |
4699 | unmute_init++; | 4717 | unmute_nids++; |
4700 | break; | 4718 | break; |
4701 | case 0x111d7608: /* 5 Port with Analog Mixer */ | 4719 | case 0x111d7608: /* 5 Port with Analog Mixer */ |
4702 | if ((codec->revision_id & 0xf) == 0 || | 4720 | if ((codec->core.revision_id & 0xf) == 0 || |
4703 | (codec->revision_id & 0xf) == 1) | 4721 | (codec->core.revision_id & 0xf) == 1) |
4704 | spec->stream_delay = 40; /* 40 milliseconds */ | 4722 | spec->stream_delay = 40; /* 40 milliseconds */ |
4705 | 4723 | ||
4706 | /* disable VSW */ | 4724 | /* disable VSW */ |
4707 | unmute_init++; | 4725 | unmute_nids++; |
4708 | snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0); | 4726 | snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0); |
4709 | snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3); | 4727 | snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3); |
4710 | break; | 4728 | break; |
4711 | case 0x111d7603: /* 6 Port with Analog Mixer */ | 4729 | case 0x111d7603: /* 6 Port with Analog Mixer */ |
4712 | if ((codec->revision_id & 0xf) == 1) | 4730 | if ((codec->core.revision_id & 0xf) == 1) |
4713 | spec->stream_delay = 40; /* 40 milliseconds */ | 4731 | spec->stream_delay = 40; /* 40 milliseconds */ |
4714 | 4732 | ||
4715 | break; | 4733 | break; |
@@ -4718,8 +4736,12 @@ static int patch_stac92hd71bxx(struct hda_codec *codec) | |||
4718 | if (get_wcaps_type(get_wcaps(codec, 0x28)) == AC_WID_VOL_KNB) | 4736 | if (get_wcaps_type(get_wcaps(codec, 0x28)) == AC_WID_VOL_KNB) |
4719 | snd_hda_add_verbs(codec, stac92hd71bxx_core_init); | 4737 | snd_hda_add_verbs(codec, stac92hd71bxx_core_init); |
4720 | 4738 | ||
4721 | if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP) | 4739 | if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP) { |
4722 | snd_hda_sequence_write_cache(codec, unmute_init); | 4740 | const hda_nid_t *p; |
4741 | for (p = unmute_nids; *p; p++) | ||
4742 | snd_hda_codec_amp_init_stereo(codec, *p, HDA_INPUT, 0, | ||
4743 | 0xff, 0x00); | ||
4744 | } | ||
4723 | 4745 | ||
4724 | spec->aloopback_ctl = &stac92hd71bxx_loopback; | 4746 | spec->aloopback_ctl = &stac92hd71bxx_loopback; |
4725 | spec->aloopback_mask = 0x50; | 4747 | spec->aloopback_mask = 0x50; |
@@ -5091,20 +5113,8 @@ MODULE_ALIAS("snd-hda-codec-id:111d*"); | |||
5091 | MODULE_LICENSE("GPL"); | 5113 | MODULE_LICENSE("GPL"); |
5092 | MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec"); | 5114 | MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec"); |
5093 | 5115 | ||
5094 | static struct hda_codec_preset_list sigmatel_list = { | 5116 | static struct hda_codec_driver sigmatel_driver = { |
5095 | .preset = snd_hda_preset_sigmatel, | 5117 | .preset = snd_hda_preset_sigmatel, |
5096 | .owner = THIS_MODULE, | ||
5097 | }; | 5118 | }; |
5098 | 5119 | ||
5099 | static int __init patch_sigmatel_init(void) | 5120 | module_hda_codec_driver(sigmatel_driver); |
5100 | { | ||
5101 | return snd_hda_add_codec_preset(&sigmatel_list); | ||
5102 | } | ||
5103 | |||
5104 | static void __exit patch_sigmatel_exit(void) | ||
5105 | { | ||
5106 | snd_hda_delete_codec_preset(&sigmatel_list); | ||
5107 | } | ||
5108 | |||
5109 | module_init(patch_sigmatel_init) | ||
5110 | module_exit(patch_sigmatel_exit) | ||
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 3de6d3d779c9..31a95cca015d 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 */ |
@@ -109,8 +108,7 @@ struct via_spec { | |||
109 | int hp_work_active; | 108 | int hp_work_active; |
110 | int vt1708_jack_detect; | 109 | int vt1708_jack_detect; |
111 | 110 | ||
112 | void (*set_widgets_power_state)(struct hda_codec *codec); | 111 | unsigned int beep_amp; |
113 | unsigned int dac_stream_tag[4]; | ||
114 | }; | 112 | }; |
115 | 113 | ||
116 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); | 114 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); |
@@ -133,17 +131,18 @@ static struct via_spec *via_new_spec(struct hda_codec *codec) | |||
133 | /* VT1708BCE & VT1708S are almost same */ | 131 | /* VT1708BCE & VT1708S are almost same */ |
134 | if (spec->codec_type == VT1708BCE) | 132 | if (spec->codec_type == VT1708BCE) |
135 | spec->codec_type = VT1708S; | 133 | spec->codec_type = VT1708S; |
136 | spec->no_pin_power_ctl = 1; | ||
137 | spec->gen.indep_hp = 1; | 134 | spec->gen.indep_hp = 1; |
138 | spec->gen.keep_eapd_on = 1; | 135 | spec->gen.keep_eapd_on = 1; |
139 | spec->gen.pcm_playback_hook = via_playback_pcm_hook; | 136 | spec->gen.pcm_playback_hook = via_playback_pcm_hook; |
140 | spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO; | 137 | spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO; |
138 | codec->power_save_node = 1; | ||
139 | spec->gen.power_down_unused = 1; | ||
141 | return spec; | 140 | return spec; |
142 | } | 141 | } |
143 | 142 | ||
144 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec) | 143 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec) |
145 | { | 144 | { |
146 | u32 vendor_id = codec->vendor_id; | 145 | u32 vendor_id = codec->core.vendor_id; |
147 | u16 ven_id = vendor_id >> 16; | 146 | u16 ven_id = vendor_id >> 16; |
148 | u16 dev_id = vendor_id & 0xffff; | 147 | u16 dev_id = vendor_id & 0xffff; |
149 | enum VIA_HDA_CODEC codec_type; | 148 | enum VIA_HDA_CODEC codec_type; |
@@ -222,98 +221,13 @@ static void vt1708_update_hp_work(struct hda_codec *codec) | |||
222 | if (!spec->hp_work_active) { | 221 | if (!spec->hp_work_active) { |
223 | codec->jackpoll_interval = msecs_to_jiffies(100); | 222 | codec->jackpoll_interval = msecs_to_jiffies(100); |
224 | snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0); | 223 | snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0); |
225 | queue_delayed_work(codec->bus->workq, | 224 | schedule_delayed_work(&codec->jackpoll_work, 0); |
226 | &codec->jackpoll_work, 0); | ||
227 | spec->hp_work_active = true; | 225 | spec->hp_work_active = true; |
228 | } | 226 | } |
229 | } else if (!hp_detect_with_aa(codec)) | 227 | } else if (!hp_detect_with_aa(codec)) |
230 | vt1708_stop_hp_work(codec); | 228 | vt1708_stop_hp_work(codec); |
231 | } | 229 | } |
232 | 230 | ||
233 | static 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 | |||
245 | static 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 | |||
253 | static 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 | |||
275 | static 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 | |||
281 | static 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 | |||
292 | static 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 | |||
317 | static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, | 231 | static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, |
318 | struct snd_ctl_elem_info *uinfo) | 232 | struct snd_ctl_elem_info *uinfo) |
319 | { | 233 | { |
@@ -324,8 +238,7 @@ static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol, | |||
324 | struct snd_ctl_elem_value *ucontrol) | 238 | struct snd_ctl_elem_value *ucontrol) |
325 | { | 239 | { |
326 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 240 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
327 | struct via_spec *spec = codec->spec; | 241 | ucontrol->value.enumerated.item[0] = codec->power_save_node; |
328 | ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl; | ||
329 | return 0; | 242 | return 0; |
330 | } | 243 | } |
331 | 244 | ||
@@ -334,12 +247,12 @@ static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol, | |||
334 | { | 247 | { |
335 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 248 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
336 | struct via_spec *spec = codec->spec; | 249 | struct via_spec *spec = codec->spec; |
337 | unsigned int val = !ucontrol->value.enumerated.item[0]; | 250 | bool val = !!ucontrol->value.enumerated.item[0]; |
338 | 251 | ||
339 | if (val == spec->no_pin_power_ctl) | 252 | if (val == codec->power_save_node) |
340 | return 0; | 253 | return 0; |
341 | spec->no_pin_power_ctl = val; | 254 | codec->power_save_node = val; |
342 | set_widgets_power_state(codec); | 255 | spec->gen.power_down_unused = val; |
343 | analog_low_current_mode(codec); | 256 | analog_low_current_mode(codec); |
344 | return 1; | 257 | return 1; |
345 | } | 258 | } |
@@ -355,6 +268,59 @@ static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = { | |||
355 | {} /* terminator */ | 268 | {} /* terminator */ |
356 | }; | 269 | }; |
357 | 270 | ||
271 | #ifdef CONFIG_SND_HDA_INPUT_BEEP | ||
272 | static inline void set_beep_amp(struct via_spec *spec, hda_nid_t nid, | ||
273 | int idx, int dir) | ||
274 | { | ||
275 | spec->gen.beep_nid = nid; | ||
276 | spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir); | ||
277 | } | ||
278 | |||
279 | /* additional beep mixers; the actual parameters are overwritten at build */ | ||
280 | static const struct snd_kcontrol_new cxt_beep_mixer[] = { | ||
281 | HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), | ||
282 | HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), | ||
283 | { } /* end */ | ||
284 | }; | ||
285 | |||
286 | /* create beep controls if needed */ | ||
287 | static int add_beep_ctls(struct hda_codec *codec) | ||
288 | { | ||
289 | struct via_spec *spec = codec->spec; | ||
290 | int err; | ||
291 | |||
292 | if (spec->beep_amp) { | ||
293 | const struct snd_kcontrol_new *knew; | ||
294 | for (knew = cxt_beep_mixer; knew->name; knew++) { | ||
295 | struct snd_kcontrol *kctl; | ||
296 | kctl = snd_ctl_new1(knew, codec); | ||
297 | if (!kctl) | ||
298 | return -ENOMEM; | ||
299 | kctl->private_value = spec->beep_amp; | ||
300 | err = snd_hda_ctl_add(codec, 0, kctl); | ||
301 | if (err < 0) | ||
302 | return err; | ||
303 | } | ||
304 | } | ||
305 | return 0; | ||
306 | } | ||
307 | |||
308 | static void auto_parse_beep(struct hda_codec *codec) | ||
309 | { | ||
310 | struct via_spec *spec = codec->spec; | ||
311 | hda_nid_t nid; | ||
312 | |||
313 | for_each_hda_codec_node(nid, codec) | ||
314 | if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { | ||
315 | set_beep_amp(spec, nid, 0, HDA_OUTPUT); | ||
316 | break; | ||
317 | } | ||
318 | } | ||
319 | #else | ||
320 | #define set_beep_amp(spec, nid, idx, dir) /* NOP */ | ||
321 | #define add_beep_ctls(codec) 0 | ||
322 | #define auto_parse_beep(codec) | ||
323 | #endif | ||
358 | 324 | ||
359 | /* check AA path's mute status */ | 325 | /* check AA path's mute status */ |
360 | static bool is_aa_path_mute(struct hda_codec *codec) | 326 | static bool is_aa_path_mute(struct hda_codec *codec) |
@@ -384,7 +350,7 @@ static void __analog_low_current_mode(struct hda_codec *codec, bool force) | |||
384 | bool enable; | 350 | bool enable; |
385 | unsigned int verb, parm; | 351 | unsigned int verb, parm; |
386 | 352 | ||
387 | if (spec->no_pin_power_ctl) | 353 | if (!codec->power_save_node) |
388 | enable = false; | 354 | enable = false; |
389 | else | 355 | else |
390 | enable = is_aa_path_mute(codec) && !spec->gen.active_streams; | 356 | enable = is_aa_path_mute(codec) && !spec->gen.active_streams; |
@@ -424,7 +390,7 @@ static void __analog_low_current_mode(struct hda_codec *codec, bool force) | |||
424 | return; /* other codecs are not supported */ | 390 | return; /* other codecs are not supported */ |
425 | } | 391 | } |
426 | /* send verb */ | 392 | /* send verb */ |
427 | snd_hda_codec_write(codec, codec->afg, 0, verb, parm); | 393 | snd_hda_codec_write(codec, codec->core.afg, 0, verb, parm); |
428 | } | 394 | } |
429 | 395 | ||
430 | static void analog_low_current_mode(struct hda_codec *codec) | 396 | static void analog_low_current_mode(struct hda_codec *codec) |
@@ -441,8 +407,11 @@ static int via_build_controls(struct hda_codec *codec) | |||
441 | if (err < 0) | 407 | if (err < 0) |
442 | return err; | 408 | return err; |
443 | 409 | ||
444 | if (spec->set_widgets_power_state) | 410 | err = add_beep_ctls(codec); |
445 | spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum; | 411 | if (err < 0) |
412 | return err; | ||
413 | |||
414 | spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum; | ||
446 | 415 | ||
447 | for (i = 0; i < spec->num_mixers; i++) { | 416 | for (i = 0; i < spec->num_mixers; i++) { |
448 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); | 417 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
@@ -486,7 +455,6 @@ static int via_suspend(struct hda_codec *codec) | |||
486 | static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) | 455 | static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
487 | { | 456 | { |
488 | struct via_spec *spec = codec->spec; | 457 | struct via_spec *spec = codec->spec; |
489 | set_widgets_power_state(codec); | ||
490 | analog_low_current_mode(codec); | 458 | analog_low_current_mode(codec); |
491 | vt1708_update_hp_work(codec); | 459 | vt1708_update_hp_work(codec); |
492 | return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid); | 460 | return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid); |
@@ -504,6 +472,7 @@ static const struct hda_codec_ops via_patch_ops = { | |||
504 | .init = via_init, | 472 | .init = via_init, |
505 | .free = via_free, | 473 | .free = via_free, |
506 | .unsol_event = snd_hda_jack_unsol_event, | 474 | .unsol_event = snd_hda_jack_unsol_event, |
475 | .stream_pm = snd_hda_gen_stream_pm, | ||
507 | #ifdef CONFIG_PM | 476 | #ifdef CONFIG_PM |
508 | .suspend = via_suspend, | 477 | .suspend = via_suspend, |
509 | .check_power_status = via_check_power_status, | 478 | .check_power_status = via_check_power_status, |
@@ -574,34 +543,6 @@ static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = { | |||
574 | {} /* terminator */ | 543 | {} /* terminator */ |
575 | }; | 544 | }; |
576 | 545 | ||
577 | static void via_jack_powerstate_event(struct hda_codec *codec, | ||
578 | struct hda_jack_callback *tbl) | ||
579 | { | ||
580 | set_widgets_power_state(codec); | ||
581 | } | ||
582 | |||
583 | static 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 | |||
605 | static const struct badness_table via_main_out_badness = { | 546 | static const struct badness_table via_main_out_badness = { |
606 | .no_primary_dac = 0x10000, | 547 | .no_primary_dac = 0x10000, |
607 | .no_dac = 0x4000, | 548 | .no_dac = 0x4000, |
@@ -631,11 +572,15 @@ static int via_parse_auto_config(struct hda_codec *codec) | |||
631 | if (err < 0) | 572 | if (err < 0) |
632 | return err; | 573 | return err; |
633 | 574 | ||
575 | auto_parse_beep(codec); | ||
576 | |||
634 | err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); | 577 | err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); |
635 | if (err < 0) | 578 | if (err < 0) |
636 | return err; | 579 | return err; |
637 | 580 | ||
638 | via_set_jack_unsol_events(codec); | 581 | /* disable widget PM at start for compatibility */ |
582 | codec->power_save_node = 0; | ||
583 | spec->gen.power_down_unused = 0; | ||
639 | return 0; | 584 | return 0; |
640 | } | 585 | } |
641 | 586 | ||
@@ -648,7 +593,6 @@ static int via_init(struct hda_codec *codec) | |||
648 | snd_hda_sequence_write(codec, spec->init_verbs[i]); | 593 | snd_hda_sequence_write(codec, spec->init_verbs[i]); |
649 | 594 | ||
650 | /* init power states */ | 595 | /* init power states */ |
651 | set_widgets_power_state(codec); | ||
652 | __analog_low_current_mode(codec, true); | 596 | __analog_low_current_mode(codec, true); |
653 | 597 | ||
654 | snd_hda_gen_init(codec); | 598 | snd_hda_gen_init(codec); |
@@ -676,15 +620,17 @@ static int vt1708_build_pcms(struct hda_codec *codec) | |||
676 | int i, err; | 620 | int i, err; |
677 | 621 | ||
678 | err = snd_hda_gen_build_pcms(codec); | 622 | err = snd_hda_gen_build_pcms(codec); |
679 | if (err < 0 || codec->vendor_id != 0x11061708) | 623 | if (err < 0 || codec->core.vendor_id != 0x11061708) |
680 | return err; | 624 | return err; |
681 | 625 | ||
682 | /* We got noisy outputs on the right channel on VT1708 when | 626 | /* We got noisy outputs on the right channel on VT1708 when |
683 | * 24bit samples are used. Until any workaround is found, | 627 | * 24bit samples are used. Until any workaround is found, |
684 | * disable the 24bit format, so far. | 628 | * disable the 24bit format, so far. |
685 | */ | 629 | */ |
686 | for (i = 0; i < codec->num_pcms; i++) { | 630 | for (i = 0; i < ARRAY_SIZE(spec->gen.pcm_rec); i++) { |
687 | struct hda_pcm *info = &spec->gen.pcm_rec[i]; | 631 | struct hda_pcm *info = spec->gen.pcm_rec[i]; |
632 | if (!info) | ||
633 | continue; | ||
688 | if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams || | 634 | if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams || |
689 | info->pcm_type != HDA_PCM_TYPE_AUDIO) | 635 | info->pcm_type != HDA_PCM_TYPE_AUDIO) |
690 | continue; | 636 | continue; |
@@ -766,78 +712,6 @@ static int patch_vt1709(struct hda_codec *codec) | |||
766 | return 0; | 712 | return 0; |
767 | } | 713 | } |
768 | 714 | ||
769 | static 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 | |||
841 | static int patch_vt1708S(struct hda_codec *codec); | 715 | static int patch_vt1708S(struct hda_codec *codec); |
842 | static int patch_vt1708B(struct hda_codec *codec) | 716 | static int patch_vt1708B(struct hda_codec *codec) |
843 | { | 717 | { |
@@ -862,9 +736,6 @@ static int patch_vt1708B(struct hda_codec *codec) | |||
862 | } | 736 | } |
863 | 737 | ||
864 | codec->patch_ops = via_patch_ops; | 738 | codec->patch_ops = via_patch_ops; |
865 | |||
866 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; | ||
867 | |||
868 | return 0; | 739 | return 0; |
869 | } | 740 | } |
870 | 741 | ||
@@ -905,19 +776,19 @@ static int patch_vt1708S(struct hda_codec *codec) | |||
905 | 776 | ||
906 | /* correct names for VT1708BCE */ | 777 | /* correct names for VT1708BCE */ |
907 | if (get_codec_type(codec) == VT1708BCE) { | 778 | if (get_codec_type(codec) == VT1708BCE) { |
908 | kfree(codec->chip_name); | 779 | kfree(codec->core.chip_name); |
909 | codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); | 780 | codec->core.chip_name = kstrdup("VT1708BCE", GFP_KERNEL); |
910 | snprintf(codec->bus->card->mixername, | 781 | snprintf(codec->card->mixername, |
911 | sizeof(codec->bus->card->mixername), | 782 | sizeof(codec->card->mixername), |
912 | "%s %s", codec->vendor_name, codec->chip_name); | 783 | "%s %s", codec->core.vendor_name, codec->core.chip_name); |
913 | } | 784 | } |
914 | /* correct names for VT1705 */ | 785 | /* correct names for VT1705 */ |
915 | if (codec->vendor_id == 0x11064397) { | 786 | if (codec->core.vendor_id == 0x11064397) { |
916 | kfree(codec->chip_name); | 787 | kfree(codec->core.chip_name); |
917 | codec->chip_name = kstrdup("VT1705", GFP_KERNEL); | 788 | codec->core.chip_name = kstrdup("VT1705", GFP_KERNEL); |
918 | snprintf(codec->bus->card->mixername, | 789 | snprintf(codec->card->mixername, |
919 | sizeof(codec->bus->card->mixername), | 790 | sizeof(codec->card->mixername), |
920 | "%s %s", codec->vendor_name, codec->chip_name); | 791 | "%s %s", codec->core.vendor_name, codec->core.chip_name); |
921 | } | 792 | } |
922 | 793 | ||
923 | /* automatic parse from the BIOS config */ | 794 | /* automatic parse from the BIOS config */ |
@@ -930,8 +801,6 @@ static int patch_vt1708S(struct hda_codec *codec) | |||
930 | spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs; | 801 | spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs; |
931 | 802 | ||
932 | codec->patch_ops = via_patch_ops; | 803 | codec->patch_ops = via_patch_ops; |
933 | |||
934 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; | ||
935 | return 0; | 804 | return 0; |
936 | } | 805 | } |
937 | 806 | ||
@@ -945,36 +814,6 @@ static const struct hda_verb vt1702_init_verbs[] = { | |||
945 | { } | 814 | { } |
946 | }; | 815 | }; |
947 | 816 | ||
948 | static 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 | |||
978 | static int patch_vt1702(struct hda_codec *codec) | 817 | static int patch_vt1702(struct hda_codec *codec) |
979 | { | 818 | { |
980 | struct via_spec *spec; | 819 | struct via_spec *spec; |
@@ -1004,8 +843,6 @@ static int patch_vt1702(struct hda_codec *codec) | |||
1004 | spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs; | 843 | spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs; |
1005 | 844 | ||
1006 | codec->patch_ops = via_patch_ops; | 845 | codec->patch_ops = via_patch_ops; |
1007 | |||
1008 | spec->set_widgets_power_state = set_widgets_power_state_vt1702; | ||
1009 | return 0; | 846 | return 0; |
1010 | } | 847 | } |
1011 | 848 | ||
@@ -1020,71 +857,6 @@ static const struct hda_verb vt1718S_init_verbs[] = { | |||
1020 | { } | 857 | { } |
1021 | }; | 858 | }; |
1022 | 859 | ||
1023 | static 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 | 860 | /* 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. | 861 | * This isn't listed from the raw info, but the chip has a secret connection. |
1090 | */ | 862 | */ |
@@ -1105,8 +877,7 @@ static int add_secret_dac_path(struct hda_codec *codec) | |||
1105 | } | 877 | } |
1106 | 878 | ||
1107 | /* find the primary DAC and add to the connection list */ | 879 | /* find the primary DAC and add to the connection list */ |
1108 | nid = codec->start_nid; | 880 | for_each_hda_codec_node(nid, codec) { |
1109 | for (i = 0; i < codec->num_nodes; i++, nid++) { | ||
1110 | unsigned int caps = get_wcaps(codec, nid); | 881 | unsigned int caps = get_wcaps(codec, nid); |
1111 | if (get_wcaps_type(caps) == AC_WID_AUD_OUT && | 882 | if (get_wcaps_type(caps) == AC_WID_AUD_OUT && |
1112 | !(caps & AC_WCAP_DIGITAL)) { | 883 | !(caps & AC_WCAP_DIGITAL)) { |
@@ -1145,9 +916,6 @@ static int patch_vt1718S(struct hda_codec *codec) | |||
1145 | spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs; | 916 | spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs; |
1146 | 917 | ||
1147 | codec->patch_ops = via_patch_ops; | 918 | codec->patch_ops = via_patch_ops; |
1148 | |||
1149 | spec->set_widgets_power_state = set_widgets_power_state_vt1718S; | ||
1150 | |||
1151 | return 0; | 919 | return 0; |
1152 | } | 920 | } |
1153 | 921 | ||
@@ -1187,7 +955,6 @@ static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol, | |||
1187 | snd_hda_codec_write(codec, 0x26, 0, | 955 | snd_hda_codec_write(codec, 0x26, 0, |
1188 | AC_VERB_SET_CONNECT_SEL, index); | 956 | AC_VERB_SET_CONNECT_SEL, index); |
1189 | spec->dmic_enabled = index; | 957 | spec->dmic_enabled = index; |
1190 | set_widgets_power_state(codec); | ||
1191 | return 1; | 958 | return 1; |
1192 | } | 959 | } |
1193 | 960 | ||
@@ -1222,95 +989,6 @@ static const struct hda_verb vt1716S_init_verbs[] = { | |||
1222 | { } | 989 | { } |
1223 | }; | 990 | }; |
1224 | 991 | ||
1225 | static 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 | |||
1314 | static int patch_vt1716S(struct hda_codec *codec) | 992 | static int patch_vt1716S(struct hda_codec *codec) |
1315 | { | 993 | { |
1316 | struct via_spec *spec; | 994 | struct via_spec *spec; |
@@ -1338,8 +1016,6 @@ static int patch_vt1716S(struct hda_codec *codec) | |||
1338 | spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; | 1016 | spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; |
1339 | 1017 | ||
1340 | codec->patch_ops = via_patch_ops; | 1018 | codec->patch_ops = via_patch_ops; |
1341 | |||
1342 | spec->set_widgets_power_state = set_widgets_power_state_vt1716S; | ||
1343 | return 0; | 1019 | return 0; |
1344 | } | 1020 | } |
1345 | 1021 | ||
@@ -1365,98 +1041,6 @@ static const struct hda_verb vt1802_init_verbs[] = { | |||
1365 | { } | 1041 | { } |
1366 | }; | 1042 | }; |
1367 | 1043 | ||
1368 | static 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 | /* | 1044 | /* |
1461 | * pin fix-up | 1045 | * pin fix-up |
1462 | */ | 1046 | */ |
@@ -1540,8 +1124,6 @@ static int patch_vt2002P(struct hda_codec *codec) | |||
1540 | spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs; | 1124 | spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs; |
1541 | 1125 | ||
1542 | codec->patch_ops = via_patch_ops; | 1126 | codec->patch_ops = via_patch_ops; |
1543 | |||
1544 | spec->set_widgets_power_state = set_widgets_power_state_vt2002P; | ||
1545 | return 0; | 1127 | return 0; |
1546 | } | 1128 | } |
1547 | 1129 | ||
@@ -1555,81 +1137,6 @@ static const struct hda_verb vt1812_init_verbs[] = { | |||
1555 | { } | 1137 | { } |
1556 | }; | 1138 | }; |
1557 | 1139 | ||
1558 | static 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 */ | 1140 | /* patch for vt1812 */ |
1634 | static int patch_vt1812(struct hda_codec *codec) | 1141 | static int patch_vt1812(struct hda_codec *codec) |
1635 | { | 1142 | { |
@@ -1656,8 +1163,6 @@ static int patch_vt1812(struct hda_codec *codec) | |||
1656 | spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs; | 1163 | spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs; |
1657 | 1164 | ||
1658 | codec->patch_ops = via_patch_ops; | 1165 | codec->patch_ops = via_patch_ops; |
1659 | |||
1660 | spec->set_widgets_power_state = set_widgets_power_state_vt1812; | ||
1661 | return 0; | 1166 | return 0; |
1662 | } | 1167 | } |
1663 | 1168 | ||
@@ -1673,84 +1178,6 @@ static const struct hda_verb vt3476_init_verbs[] = { | |||
1673 | { } | 1178 | { } |
1674 | }; | 1179 | }; |
1675 | 1180 | ||
1676 | static 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 | |||
1754 | static int patch_vt3476(struct hda_codec *codec) | 1181 | static int patch_vt3476(struct hda_codec *codec) |
1755 | { | 1182 | { |
1756 | struct via_spec *spec; | 1183 | struct via_spec *spec; |
@@ -1774,9 +1201,6 @@ static int patch_vt3476(struct hda_codec *codec) | |||
1774 | spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs; | 1201 | spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs; |
1775 | 1202 | ||
1776 | codec->patch_ops = via_patch_ops; | 1203 | codec->patch_ops = via_patch_ops; |
1777 | |||
1778 | spec->set_widgets_power_state = set_widgets_power_state_vt3476; | ||
1779 | |||
1780 | return 0; | 1204 | return 0; |
1781 | } | 1205 | } |
1782 | 1206 | ||
@@ -1884,23 +1308,11 @@ static const struct hda_codec_preset snd_hda_preset_via[] = { | |||
1884 | 1308 | ||
1885 | MODULE_ALIAS("snd-hda-codec-id:1106*"); | 1309 | MODULE_ALIAS("snd-hda-codec-id:1106*"); |
1886 | 1310 | ||
1887 | static struct hda_codec_preset_list via_list = { | 1311 | static struct hda_codec_driver via_driver = { |
1888 | .preset = snd_hda_preset_via, | 1312 | .preset = snd_hda_preset_via, |
1889 | .owner = THIS_MODULE, | ||
1890 | }; | 1313 | }; |
1891 | 1314 | ||
1892 | MODULE_LICENSE("GPL"); | 1315 | MODULE_LICENSE("GPL"); |
1893 | MODULE_DESCRIPTION("VIA HD-audio codec"); | 1316 | MODULE_DESCRIPTION("VIA HD-audio codec"); |
1894 | 1317 | ||
1895 | static int __init patch_via_init(void) | 1318 | module_hda_codec_driver(via_driver); |
1896 | { | ||
1897 | return snd_hda_add_codec_preset(&via_list); | ||
1898 | } | ||
1899 | |||
1900 | static void __exit patch_via_exit(void) | ||
1901 | { | ||
1902 | snd_hda_delete_codec_preset(&via_list); | ||
1903 | } | ||
1904 | |||
1905 | module_init(patch_via_init) | ||
1906 | module_exit(patch_via_exit) | ||
diff --git a/sound/pci/hda/thinkpad_helper.c b/sound/pci/hda/thinkpad_helper.c index 6ba0b5517c40..0a4ad5feb82e 100644 --- a/sound/pci/hda/thinkpad_helper.c +++ b/sound/pci/hda/thinkpad_helper.c | |||
@@ -21,7 +21,7 @@ static acpi_status acpi_check_cb(acpi_handle handle, u32 lvl, void *context, | |||
21 | static bool is_thinkpad(struct hda_codec *codec) | 21 | static bool is_thinkpad(struct hda_codec *codec) |
22 | { | 22 | { |
23 | bool found = false; | 23 | bool found = false; |
24 | if (codec->subsystem_id >> 16 != 0x17aa) | 24 | if (codec->core.subsystem_id >> 16 != 0x17aa) |
25 | return false; | 25 | return false; |
26 | if (ACPI_SUCCESS(acpi_get_devices("LEN0068", acpi_check_cb, &found, NULL)) && found) | 26 | if (ACPI_SUCCESS(acpi_get_devices("LEN0068", acpi_check_cb, &found, NULL)) && found) |
27 | return true; | 27 | return true; |
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 | ||
40 | struct 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 | */ |
78 | static 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 | ||
73 | static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol, | 127 | static 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 | */ |
400 | static 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 | ||
344 | static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol, | 409 | static 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 | */ | ||
452 | static 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*/ | ||
488 | static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0); | ||
489 | static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0); | ||
490 | |||
383 | /* | 491 | /* |
384 | * Control tabs | 492 | * Control tabs |
385 | */ | 493 | */ |
386 | static struct snd_kcontrol_new stac9640_controls[] = { | 494 | static 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 | ||
464 | static int wtm_init(struct snd_ice1712 *ice) | 582 | static 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 | ||
487 | static unsigned char wtm_eeprom[] = { | 616 | static 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/intel8x0.c b/sound/pci/intel8x0.c index 2c5484eeb963..749069aa6997 100644 --- a/sound/pci/intel8x0.c +++ b/sound/pci/intel8x0.c | |||
@@ -1795,7 +1795,7 @@ static struct ac97_pcm ac97_pcm_defs[] = { | |||
1795 | }, | 1795 | }, |
1796 | }; | 1796 | }; |
1797 | 1797 | ||
1798 | static struct ac97_quirk ac97_quirks[] = { | 1798 | static const struct ac97_quirk ac97_quirks[] = { |
1799 | { | 1799 | { |
1800 | .subvendor = 0x0e11, | 1800 | .subvendor = 0x0e11, |
1801 | .subdevice = 0x000e, | 1801 | .subdevice = 0x000e, |
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 | ||
6046 | static int snd_hdspm_playback_open(struct snd_pcm_substream *substream) | 6046 | static 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 | ||
6112 | static int snd_hdspm_playback_release(struct snd_pcm_substream *substream) | 6123 | static 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 | |||
6127 | static 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 | |||
6189 | static 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 | ||
6416 | static struct snd_pcm_ops snd_hdspm_playback_ops = { | 6357 | static 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 | |||
6428 | static 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/pci/via82xx.c b/sound/pci/via82xx.c index 8622283e89f3..3dd038bdb204 100644 --- a/sound/pci/via82xx.c +++ b/sound/pci/via82xx.c | |||
@@ -1812,7 +1812,7 @@ static void snd_via82xx_mixer_free_ac97(struct snd_ac97 *ac97) | |||
1812 | chip->ac97 = NULL; | 1812 | chip->ac97 = NULL; |
1813 | } | 1813 | } |
1814 | 1814 | ||
1815 | static struct ac97_quirk ac97_quirks[] = { | 1815 | static const struct ac97_quirk ac97_quirks[] = { |
1816 | { | 1816 | { |
1817 | .subvendor = 0x1106, | 1817 | .subvendor = 0x1106, |
1818 | .subdevice = 0x4161, | 1818 | .subdevice = 0x4161, |
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig index dcc79aa0236b..3ba52da18bc6 100644 --- a/sound/soc/Kconfig +++ b/sound/soc/Kconfig | |||
@@ -47,6 +47,7 @@ source "sound/soc/kirkwood/Kconfig" | |||
47 | source "sound/soc/intel/Kconfig" | 47 | source "sound/soc/intel/Kconfig" |
48 | source "sound/soc/mxs/Kconfig" | 48 | source "sound/soc/mxs/Kconfig" |
49 | source "sound/soc/pxa/Kconfig" | 49 | source "sound/soc/pxa/Kconfig" |
50 | source "sound/soc/qcom/Kconfig" | ||
50 | source "sound/soc/rockchip/Kconfig" | 51 | source "sound/soc/rockchip/Kconfig" |
51 | source "sound/soc/samsung/Kconfig" | 52 | source "sound/soc/samsung/Kconfig" |
52 | source "sound/soc/sh/Kconfig" | 53 | source "sound/soc/sh/Kconfig" |
diff --git a/sound/soc/Makefile b/sound/soc/Makefile index 5b3c8f67c8db..974ba708b482 100644 --- a/sound/soc/Makefile +++ b/sound/soc/Makefile | |||
@@ -28,6 +28,7 @@ obj-$(CONFIG_SND_SOC) += nuc900/ | |||
28 | obj-$(CONFIG_SND_SOC) += omap/ | 28 | obj-$(CONFIG_SND_SOC) += omap/ |
29 | obj-$(CONFIG_SND_SOC) += kirkwood/ | 29 | obj-$(CONFIG_SND_SOC) += kirkwood/ |
30 | obj-$(CONFIG_SND_SOC) += pxa/ | 30 | obj-$(CONFIG_SND_SOC) += pxa/ |
31 | obj-$(CONFIG_SND_SOC) += qcom/ | ||
31 | obj-$(CONFIG_SND_SOC) += rockchip/ | 32 | obj-$(CONFIG_SND_SOC) += rockchip/ |
32 | obj-$(CONFIG_SND_SOC) += samsung/ | 33 | obj-$(CONFIG_SND_SOC) += samsung/ |
33 | obj-$(CONFIG_SND_SOC) += sh/ | 34 | obj-$(CONFIG_SND_SOC) += sh/ |
diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig index 1579e994acf8..e7d08806f3e9 100644 --- a/sound/soc/atmel/Kconfig +++ b/sound/soc/atmel/Kconfig | |||
@@ -25,7 +25,8 @@ config SND_ATMEL_SOC_SSC | |||
25 | 25 | ||
26 | config SND_AT91_SOC_SAM9G20_WM8731 | 26 | config SND_AT91_SOC_SAM9G20_WM8731 |
27 | tristate "SoC Audio support for WM8731-based At91sam9g20 evaluation board" | 27 | tristate "SoC Audio support for WM8731-based At91sam9g20 evaluation board" |
28 | depends on ARCH_AT91 && ATMEL_SSC && SND_ATMEL_SOC | 28 | depends on ARCH_AT91 || COMPILE_TEST |
29 | depends on ATMEL_SSC && SND_ATMEL_SOC && SND_SOC_I2C_AND_SPI | ||
29 | select SND_ATMEL_SOC_PDC | 30 | select SND_ATMEL_SOC_PDC |
30 | select SND_ATMEL_SOC_SSC | 31 | select SND_ATMEL_SOC_SSC |
31 | select SND_SOC_WM8731 | 32 | select SND_SOC_WM8731 |
@@ -35,7 +36,8 @@ config SND_AT91_SOC_SAM9G20_WM8731 | |||
35 | 36 | ||
36 | config SND_ATMEL_SOC_WM8904 | 37 | config SND_ATMEL_SOC_WM8904 |
37 | tristate "Atmel ASoC driver for boards using WM8904 codec" | 38 | tristate "Atmel ASoC driver for boards using WM8904 codec" |
38 | depends on ARCH_AT91 && ATMEL_SSC && SND_ATMEL_SOC && I2C | 39 | depends on ARCH_AT91 || COMPILE_TEST |
40 | depends on ATMEL_SSC && SND_ATMEL_SOC && I2C | ||
39 | select SND_ATMEL_SOC_SSC | 41 | select SND_ATMEL_SOC_SSC |
40 | select SND_ATMEL_SOC_DMA | 42 | select SND_ATMEL_SOC_DMA |
41 | select SND_SOC_WM8904 | 43 | select SND_SOC_WM8904 |
@@ -45,7 +47,8 @@ config SND_ATMEL_SOC_WM8904 | |||
45 | 47 | ||
46 | config SND_AT91_SOC_SAM9X5_WM8731 | 48 | config SND_AT91_SOC_SAM9X5_WM8731 |
47 | tristate "SoC Audio support for WM8731-based at91sam9x5 board" | 49 | tristate "SoC Audio support for WM8731-based at91sam9x5 board" |
48 | depends on ARCH_AT91 && ATMEL_SSC && SND_ATMEL_SOC | 50 | depends on ARCH_AT91 || COMPILE_TEST |
51 | depends on ATMEL_SSC && SND_ATMEL_SOC && SND_SOC_I2C_AND_SPI | ||
49 | select SND_ATMEL_SOC_SSC | 52 | select SND_ATMEL_SOC_SSC |
50 | select SND_ATMEL_SOC_DMA | 53 | select SND_ATMEL_SOC_DMA |
51 | select SND_SOC_WM8731 | 54 | select SND_SOC_WM8731 |
diff --git a/sound/soc/atmel/Makefile b/sound/soc/atmel/Makefile index 466a821da98c..b327e5cc8de3 100644 --- a/sound/soc/atmel/Makefile +++ b/sound/soc/atmel/Makefile | |||
@@ -1,10 +1,8 @@ | |||
1 | # AT91 Platform Support | 1 | # AT91 Platform Support |
2 | snd-soc-atmel-pcm-objs := atmel-pcm.o | ||
3 | snd-soc-atmel-pcm-pdc-objs := atmel-pcm-pdc.o | 2 | snd-soc-atmel-pcm-pdc-objs := atmel-pcm-pdc.o |
4 | snd-soc-atmel-pcm-dma-objs := atmel-pcm-dma.o | 3 | snd-soc-atmel-pcm-dma-objs := atmel-pcm-dma.o |
5 | snd-soc-atmel_ssc_dai-objs := atmel_ssc_dai.o | 4 | snd-soc-atmel_ssc_dai-objs := atmel_ssc_dai.o |
6 | 5 | ||
7 | obj-$(CONFIG_SND_ATMEL_SOC) += snd-soc-atmel-pcm.o | ||
8 | obj-$(CONFIG_SND_ATMEL_SOC_PDC) += snd-soc-atmel-pcm-pdc.o | 6 | obj-$(CONFIG_SND_ATMEL_SOC_PDC) += snd-soc-atmel-pcm-pdc.o |
9 | obj-$(CONFIG_SND_ATMEL_SOC_DMA) += snd-soc-atmel-pcm-dma.o | 7 | obj-$(CONFIG_SND_ATMEL_SOC_DMA) += snd-soc-atmel-pcm-dma.o |
10 | obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o | 8 | obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o |
diff --git a/sound/soc/atmel/atmel-pcm-dma.c b/sound/soc/atmel/atmel-pcm-dma.c index b8e7bad05eb1..b6625c8c411b 100644 --- a/sound/soc/atmel/atmel-pcm-dma.c +++ b/sound/soc/atmel/atmel-pcm-dma.c | |||
@@ -54,7 +54,7 @@ static const struct snd_pcm_hardware atmel_pcm_dma_hardware = { | |||
54 | .period_bytes_max = 2 * 0xffff, /* if 2 bytes format */ | 54 | .period_bytes_max = 2 * 0xffff, /* if 2 bytes format */ |
55 | .periods_min = 8, | 55 | .periods_min = 8, |
56 | .periods_max = 1024, /* no limit */ | 56 | .periods_max = 1024, /* no limit */ |
57 | .buffer_bytes_max = ATMEL_SSC_DMABUF_SIZE, | 57 | .buffer_bytes_max = 512 * 1024, |
58 | }; | 58 | }; |
59 | 59 | ||
60 | /** | 60 | /** |
@@ -119,7 +119,7 @@ static int atmel_pcm_configure_dma(struct snd_pcm_substream *substream, | |||
119 | static const struct snd_dmaengine_pcm_config atmel_dmaengine_pcm_config = { | 119 | static const struct snd_dmaengine_pcm_config atmel_dmaengine_pcm_config = { |
120 | .prepare_slave_config = atmel_pcm_configure_dma, | 120 | .prepare_slave_config = atmel_pcm_configure_dma, |
121 | .pcm_hardware = &atmel_pcm_dma_hardware, | 121 | .pcm_hardware = &atmel_pcm_dma_hardware, |
122 | .prealloc_buffer_size = ATMEL_SSC_DMABUF_SIZE, | 122 | .prealloc_buffer_size = 64 * 1024, |
123 | }; | 123 | }; |
124 | 124 | ||
125 | int atmel_pcm_dma_platform_register(struct device *dev) | 125 | int atmel_pcm_dma_platform_register(struct device *dev) |
diff --git a/sound/soc/atmel/atmel-pcm-pdc.c b/sound/soc/atmel/atmel-pcm-pdc.c index a366b3503c28..da861b44413f 100644 --- a/sound/soc/atmel/atmel-pcm-pdc.c +++ b/sound/soc/atmel/atmel-pcm-pdc.c | |||
@@ -47,6 +47,85 @@ | |||
47 | #include "atmel-pcm.h" | 47 | #include "atmel-pcm.h" |
48 | 48 | ||
49 | 49 | ||
50 | static int atmel_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, | ||
51 | int stream) | ||
52 | { | ||
53 | struct snd_pcm_substream *substream = pcm->streams[stream].substream; | ||
54 | struct snd_dma_buffer *buf = &substream->dma_buffer; | ||
55 | size_t size = ATMEL_SSC_DMABUF_SIZE; | ||
56 | |||
57 | buf->dev.type = SNDRV_DMA_TYPE_DEV; | ||
58 | buf->dev.dev = pcm->card->dev; | ||
59 | buf->private_data = NULL; | ||
60 | buf->area = dma_alloc_coherent(pcm->card->dev, size, | ||
61 | &buf->addr, GFP_KERNEL); | ||
62 | pr_debug("atmel-pcm: alloc dma buffer: area=%p, addr=%p, size=%zu\n", | ||
63 | (void *)buf->area, (void *)(long)buf->addr, size); | ||
64 | |||
65 | if (!buf->area) | ||
66 | return -ENOMEM; | ||
67 | |||
68 | buf->bytes = size; | ||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | static int atmel_pcm_mmap(struct snd_pcm_substream *substream, | ||
73 | struct vm_area_struct *vma) | ||
74 | { | ||
75 | return remap_pfn_range(vma, vma->vm_start, | ||
76 | substream->dma_buffer.addr >> PAGE_SHIFT, | ||
77 | vma->vm_end - vma->vm_start, vma->vm_page_prot); | ||
78 | } | ||
79 | |||
80 | static int atmel_pcm_new(struct snd_soc_pcm_runtime *rtd) | ||
81 | { | ||
82 | struct snd_card *card = rtd->card->snd_card; | ||
83 | struct snd_pcm *pcm = rtd->pcm; | ||
84 | int ret; | ||
85 | |||
86 | ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32)); | ||
87 | if (ret) | ||
88 | return ret; | ||
89 | |||
90 | if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { | ||
91 | pr_debug("atmel-pcm: allocating PCM playback DMA buffer\n"); | ||
92 | ret = atmel_pcm_preallocate_dma_buffer(pcm, | ||
93 | SNDRV_PCM_STREAM_PLAYBACK); | ||
94 | if (ret) | ||
95 | goto out; | ||
96 | } | ||
97 | |||
98 | if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) { | ||
99 | pr_debug("atmel-pcm: allocating PCM capture DMA buffer\n"); | ||
100 | ret = atmel_pcm_preallocate_dma_buffer(pcm, | ||
101 | SNDRV_PCM_STREAM_CAPTURE); | ||
102 | if (ret) | ||
103 | goto out; | ||
104 | } | ||
105 | out: | ||
106 | return ret; | ||
107 | } | ||
108 | |||
109 | static void atmel_pcm_free(struct snd_pcm *pcm) | ||
110 | { | ||
111 | struct snd_pcm_substream *substream; | ||
112 | struct snd_dma_buffer *buf; | ||
113 | int stream; | ||
114 | |||
115 | for (stream = 0; stream < 2; stream++) { | ||
116 | substream = pcm->streams[stream].substream; | ||
117 | if (!substream) | ||
118 | continue; | ||
119 | |||
120 | buf = &substream->dma_buffer; | ||
121 | if (!buf->area) | ||
122 | continue; | ||
123 | dma_free_coherent(pcm->card->dev, buf->bytes, | ||
124 | buf->area, buf->addr); | ||
125 | buf->area = NULL; | ||
126 | } | ||
127 | } | ||
128 | |||
50 | /*--------------------------------------------------------------------------*\ | 129 | /*--------------------------------------------------------------------------*\ |
51 | * Hardware definition | 130 | * Hardware definition |
52 | \*--------------------------------------------------------------------------*/ | 131 | \*--------------------------------------------------------------------------*/ |
diff --git a/sound/soc/atmel/atmel-pcm.c b/sound/soc/atmel/atmel-pcm.c deleted file mode 100644 index 8ae3fa5ac60a..000000000000 --- a/sound/soc/atmel/atmel-pcm.c +++ /dev/null | |||
@@ -1,121 +0,0 @@ | |||
1 | /* | ||
2 | * atmel-pcm.c -- ALSA PCM interface for the Atmel atmel SoC. | ||
3 | * | ||
4 | * Copyright (C) 2005 SAN People | ||
5 | * Copyright (C) 2008 Atmel | ||
6 | * | ||
7 | * Authors: Sedji Gaouaou <sedji.gaouaou@atmel.com> | ||
8 | * | ||
9 | * Based on at91-pcm. by: | ||
10 | * Frank Mandarino <fmandarino@endrelia.com> | ||
11 | * Copyright 2006 Endrelia Technologies Inc. | ||
12 | * | ||
13 | * Based on pxa2xx-pcm.c by: | ||
14 | * | ||
15 | * Author: Nicolas Pitre | ||
16 | * Created: Nov 30, 2004 | ||
17 | * Copyright: (C) 2004 MontaVista Software, Inc. | ||
18 | * | ||
19 | * This program is free software; you can redistribute it and/or modify | ||
20 | * it under the terms of the GNU General Public License as published by | ||
21 | * the Free Software Foundation; either version 2 of the License, or | ||
22 | * (at your option) any later version. | ||
23 | * | ||
24 | * This program is distributed in the hope that it will be useful, | ||
25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
27 | * GNU General Public License for more details. | ||
28 | * | ||
29 | * You should have received a copy of the GNU General Public License | ||
30 | * along with this program; if not, write to the Free Software | ||
31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
32 | */ | ||
33 | |||
34 | #include <linux/module.h> | ||
35 | #include <linux/dma-mapping.h> | ||
36 | #include <sound/pcm.h> | ||
37 | #include <sound/soc.h> | ||
38 | #include "atmel-pcm.h" | ||
39 | |||
40 | static int atmel_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, | ||
41 | int stream) | ||
42 | { | ||
43 | struct snd_pcm_substream *substream = pcm->streams[stream].substream; | ||
44 | struct snd_dma_buffer *buf = &substream->dma_buffer; | ||
45 | size_t size = ATMEL_SSC_DMABUF_SIZE; | ||
46 | |||
47 | buf->dev.type = SNDRV_DMA_TYPE_DEV; | ||
48 | buf->dev.dev = pcm->card->dev; | ||
49 | buf->private_data = NULL; | ||
50 | buf->area = dma_alloc_coherent(pcm->card->dev, size, | ||
51 | &buf->addr, GFP_KERNEL); | ||
52 | pr_debug("atmel-pcm: alloc dma buffer: area=%p, addr=%p, size=%zu\n", | ||
53 | (void *)buf->area, (void *)(long)buf->addr, size); | ||
54 | |||
55 | if (!buf->area) | ||
56 | return -ENOMEM; | ||
57 | |||
58 | buf->bytes = size; | ||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | int atmel_pcm_mmap(struct snd_pcm_substream *substream, | ||
63 | struct vm_area_struct *vma) | ||
64 | { | ||
65 | return remap_pfn_range(vma, vma->vm_start, | ||
66 | substream->dma_buffer.addr >> PAGE_SHIFT, | ||
67 | vma->vm_end - vma->vm_start, vma->vm_page_prot); | ||
68 | } | ||
69 | EXPORT_SYMBOL_GPL(atmel_pcm_mmap); | ||
70 | |||
71 | int atmel_pcm_new(struct snd_soc_pcm_runtime *rtd) | ||
72 | { | ||
73 | struct snd_card *card = rtd->card->snd_card; | ||
74 | struct snd_pcm *pcm = rtd->pcm; | ||
75 | int ret; | ||
76 | |||
77 | ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32)); | ||
78 | if (ret) | ||
79 | return ret; | ||
80 | |||
81 | if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { | ||
82 | pr_debug("atmel-pcm: allocating PCM playback DMA buffer\n"); | ||
83 | ret = atmel_pcm_preallocate_dma_buffer(pcm, | ||
84 | SNDRV_PCM_STREAM_PLAYBACK); | ||
85 | if (ret) | ||
86 | goto out; | ||
87 | } | ||
88 | |||
89 | if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) { | ||
90 | pr_debug("atmel-pcm: allocating PCM capture DMA buffer\n"); | ||
91 | ret = atmel_pcm_preallocate_dma_buffer(pcm, | ||
92 | SNDRV_PCM_STREAM_CAPTURE); | ||
93 | if (ret) | ||
94 | goto out; | ||
95 | } | ||
96 | out: | ||
97 | return ret; | ||
98 | } | ||
99 | EXPORT_SYMBOL_GPL(atmel_pcm_new); | ||
100 | |||
101 | void atmel_pcm_free(struct snd_pcm *pcm) | ||
102 | { | ||
103 | struct snd_pcm_substream *substream; | ||
104 | struct snd_dma_buffer *buf; | ||
105 | int stream; | ||
106 | |||
107 | for (stream = 0; stream < 2; stream++) { | ||
108 | substream = pcm->streams[stream].substream; | ||
109 | if (!substream) | ||
110 | continue; | ||
111 | |||
112 | buf = &substream->dma_buffer; | ||
113 | if (!buf->area) | ||
114 | continue; | ||
115 | dma_free_coherent(pcm->card->dev, buf->bytes, | ||
116 | buf->area, buf->addr); | ||
117 | buf->area = NULL; | ||
118 | } | ||
119 | } | ||
120 | EXPORT_SYMBOL_GPL(atmel_pcm_free); | ||
121 | |||
diff --git a/sound/soc/atmel/atmel-pcm.h b/sound/soc/atmel/atmel-pcm.h index 12ae814eff21..6eaf081cad50 100644 --- a/sound/soc/atmel/atmel-pcm.h +++ b/sound/soc/atmel/atmel-pcm.h | |||
@@ -83,11 +83,6 @@ struct atmel_pcm_dma_params { | |||
83 | #define ssc_readx(base, reg) (__raw_readl((base) + (reg))) | 83 | #define ssc_readx(base, reg) (__raw_readl((base) + (reg))) |
84 | #define ssc_writex(base, reg, value) __raw_writel((value), (base) + (reg)) | 84 | #define ssc_writex(base, reg, value) __raw_writel((value), (base) + (reg)) |
85 | 85 | ||
86 | int atmel_pcm_new(struct snd_soc_pcm_runtime *rtd); | ||
87 | void atmel_pcm_free(struct snd_pcm *pcm); | ||
88 | int atmel_pcm_mmap(struct snd_pcm_substream *substream, | ||
89 | struct vm_area_struct *vma); | ||
90 | |||
91 | #if defined(CONFIG_SND_ATMEL_SOC_PDC) || \ | 86 | #if defined(CONFIG_SND_ATMEL_SOC_PDC) || \ |
92 | defined(CONFIG_SND_ATMEL_SOC_PDC_MODULE) | 87 | defined(CONFIG_SND_ATMEL_SOC_PDC_MODULE) |
93 | int atmel_pcm_pdc_platform_register(struct device *dev); | 88 | int atmel_pcm_pdc_platform_register(struct device *dev); |
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 | */ | ||
207 | static 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 | ||
120 | int atmel_ssc_set_audio(int ssc_id); | 121 | int atmel_ssc_set_audio(int ssc_id); |
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index ea9f0e31f9d4..061c46587628 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig | |||
@@ -70,6 +70,7 @@ config SND_SOC_ALL_CODECS | |||
70 | select SND_SOC_MAX98090 if I2C | 70 | select SND_SOC_MAX98090 if I2C |
71 | select SND_SOC_MAX98095 if I2C | 71 | select SND_SOC_MAX98095 if I2C |
72 | select SND_SOC_MAX98357A if GPIOLIB | 72 | select SND_SOC_MAX98357A if GPIOLIB |
73 | select SND_SOC_MAX98925 if I2C | ||
73 | select SND_SOC_MAX9850 if I2C | 74 | select SND_SOC_MAX9850 if I2C |
74 | select SND_SOC_MAX9768 if I2C | 75 | select SND_SOC_MAX9768 if I2C |
75 | select SND_SOC_MAX9877 if I2C | 76 | select SND_SOC_MAX9877 if I2C |
@@ -141,7 +142,8 @@ config SND_SOC_ALL_CODECS | |||
141 | select SND_SOC_WM8770 if SPI_MASTER | 142 | select SND_SOC_WM8770 if SPI_MASTER |
142 | select SND_SOC_WM8776 if SND_SOC_I2C_AND_SPI | 143 | select SND_SOC_WM8776 if SND_SOC_I2C_AND_SPI |
143 | select SND_SOC_WM8782 | 144 | select SND_SOC_WM8782 |
144 | select SND_SOC_WM8804 if SND_SOC_I2C_AND_SPI | 145 | select SND_SOC_WM8804_I2C if I2C |
146 | select SND_SOC_WM8804_SPI if SPI_MASTER | ||
145 | select SND_SOC_WM8900 if I2C | 147 | select SND_SOC_WM8900 if I2C |
146 | select SND_SOC_WM8903 if I2C | 148 | select SND_SOC_WM8903 if I2C |
147 | select SND_SOC_WM8904 if I2C | 149 | select SND_SOC_WM8904 if I2C |
@@ -460,6 +462,9 @@ config SND_SOC_MAX98095 | |||
460 | config SND_SOC_MAX98357A | 462 | config SND_SOC_MAX98357A |
461 | tristate | 463 | tristate |
462 | 464 | ||
465 | config SND_SOC_MAX98925 | ||
466 | tristate | ||
467 | |||
463 | config SND_SOC_MAX9850 | 468 | config SND_SOC_MAX9850 |
464 | tristate | 469 | tristate |
465 | 470 | ||
@@ -744,8 +749,19 @@ config SND_SOC_WM8782 | |||
744 | tristate | 749 | tristate |
745 | 750 | ||
746 | config SND_SOC_WM8804 | 751 | config SND_SOC_WM8804 |
747 | tristate "Wolfson Microelectronics WM8804 S/PDIF transceiver" | 752 | tristate |
748 | depends on SND_SOC_I2C_AND_SPI | 753 | |
754 | config SND_SOC_WM8804_I2C | ||
755 | tristate "Wolfson Microelectronics WM8804 S/PDIF transceiver I2C" | ||
756 | depends on I2C | ||
757 | select SND_SOC_WM8804 | ||
758 | select REGMAP_I2C | ||
759 | |||
760 | config SND_SOC_WM8804_SPI | ||
761 | tristate "Wolfson Microelectronics WM8804 S/PDIF transceiver SPI" | ||
762 | depends on SPI_MASTER | ||
763 | select SND_SOC_WM8804 | ||
764 | select REGMAP_SPI | ||
749 | 765 | ||
750 | config SND_SOC_WM8900 | 766 | config SND_SOC_WM8900 |
751 | tristate | 767 | tristate |
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 69b8666d187a..abe2d7edf65c 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile | |||
@@ -65,6 +65,7 @@ snd-soc-max98088-objs := max98088.o | |||
65 | snd-soc-max98090-objs := max98090.o | 65 | snd-soc-max98090-objs := max98090.o |
66 | snd-soc-max98095-objs := max98095.o | 66 | snd-soc-max98095-objs := max98095.o |
67 | snd-soc-max98357a-objs := max98357a.o | 67 | snd-soc-max98357a-objs := max98357a.o |
68 | snd-soc-max98925-objs := max98925.o | ||
68 | snd-soc-max9850-objs := max9850.o | 69 | snd-soc-max9850-objs := max9850.o |
69 | snd-soc-mc13783-objs := mc13783.o | 70 | snd-soc-mc13783-objs := mc13783.o |
70 | snd-soc-ml26124-objs := ml26124.o | 71 | snd-soc-ml26124-objs := ml26124.o |
@@ -145,6 +146,8 @@ snd-soc-wm8770-objs := wm8770.o | |||
145 | snd-soc-wm8776-objs := wm8776.o | 146 | snd-soc-wm8776-objs := wm8776.o |
146 | snd-soc-wm8782-objs := wm8782.o | 147 | snd-soc-wm8782-objs := wm8782.o |
147 | snd-soc-wm8804-objs := wm8804.o | 148 | snd-soc-wm8804-objs := wm8804.o |
149 | snd-soc-wm8804-i2c-objs := wm8804-i2c.o | ||
150 | snd-soc-wm8804-spi-objs := wm8804-spi.o | ||
148 | snd-soc-wm8900-objs := wm8900.o | 151 | snd-soc-wm8900-objs := wm8900.o |
149 | snd-soc-wm8903-objs := wm8903.o | 152 | snd-soc-wm8903-objs := wm8903.o |
150 | snd-soc-wm8904-objs := wm8904.o | 153 | snd-soc-wm8904-objs := wm8904.o |
@@ -247,6 +250,7 @@ obj-$(CONFIG_SND_SOC_MAX98088) += snd-soc-max98088.o | |||
247 | obj-$(CONFIG_SND_SOC_MAX98090) += snd-soc-max98090.o | 250 | obj-$(CONFIG_SND_SOC_MAX98090) += snd-soc-max98090.o |
248 | obj-$(CONFIG_SND_SOC_MAX98095) += snd-soc-max98095.o | 251 | obj-$(CONFIG_SND_SOC_MAX98095) += snd-soc-max98095.o |
249 | obj-$(CONFIG_SND_SOC_MAX98357A) += snd-soc-max98357a.o | 252 | obj-$(CONFIG_SND_SOC_MAX98357A) += snd-soc-max98357a.o |
253 | obj-$(CONFIG_SND_SOC_MAX98925) += snd-soc-max98925.o | ||
250 | obj-$(CONFIG_SND_SOC_MAX9850) += snd-soc-max9850.o | 254 | obj-$(CONFIG_SND_SOC_MAX9850) += snd-soc-max9850.o |
251 | obj-$(CONFIG_SND_SOC_MC13783) += snd-soc-mc13783.o | 255 | obj-$(CONFIG_SND_SOC_MC13783) += snd-soc-mc13783.o |
252 | obj-$(CONFIG_SND_SOC_ML26124) += snd-soc-ml26124.o | 256 | obj-$(CONFIG_SND_SOC_ML26124) += snd-soc-ml26124.o |
@@ -323,6 +327,8 @@ obj-$(CONFIG_SND_SOC_WM8770) += snd-soc-wm8770.o | |||
323 | obj-$(CONFIG_SND_SOC_WM8776) += snd-soc-wm8776.o | 327 | obj-$(CONFIG_SND_SOC_WM8776) += snd-soc-wm8776.o |
324 | obj-$(CONFIG_SND_SOC_WM8782) += snd-soc-wm8782.o | 328 | obj-$(CONFIG_SND_SOC_WM8782) += snd-soc-wm8782.o |
325 | obj-$(CONFIG_SND_SOC_WM8804) += snd-soc-wm8804.o | 329 | obj-$(CONFIG_SND_SOC_WM8804) += snd-soc-wm8804.o |
330 | obj-$(CONFIG_SND_SOC_WM8804_I2C) += snd-soc-wm8804-i2c.o | ||
331 | obj-$(CONFIG_SND_SOC_WM8804_SPI) += snd-soc-wm8804-spi.o | ||
326 | obj-$(CONFIG_SND_SOC_WM8900) += snd-soc-wm8900.o | 332 | obj-$(CONFIG_SND_SOC_WM8900) += snd-soc-wm8900.o |
327 | obj-$(CONFIG_SND_SOC_WM8903) += snd-soc-wm8903.o | 333 | obj-$(CONFIG_SND_SOC_WM8903) += snd-soc-wm8903.o |
328 | obj-$(CONFIG_SND_SOC_WM8904) += snd-soc-wm8904.o | 334 | obj-$(CONFIG_SND_SOC_WM8904) += snd-soc-wm8904.o |
diff --git a/sound/soc/codecs/ab8500-codec.c b/sound/soc/codecs/ab8500-codec.c index 7895689588da..88ca9cb0ce79 100644 --- a/sound/soc/codecs/ab8500-codec.c +++ b/sound/soc/codecs/ab8500-codec.c | |||
@@ -2003,7 +2003,6 @@ static int ab8500_audio_setup_mics(struct snd_soc_codec *codec, | |||
2003 | 2003 | ||
2004 | return 0; | 2004 | return 0; |
2005 | } | 2005 | } |
2006 | EXPORT_SYMBOL_GPL(ab8500_audio_setup_mics); | ||
2007 | 2006 | ||
2008 | static int ab8500_audio_set_ear_cmv(struct snd_soc_codec *codec, | 2007 | static int ab8500_audio_set_ear_cmv(struct snd_soc_codec *codec, |
2009 | enum ear_cm_voltage ear_cmv) | 2008 | enum ear_cm_voltage ear_cmv) |
@@ -2036,7 +2035,6 @@ static int ab8500_audio_set_ear_cmv(struct snd_soc_codec *codec, | |||
2036 | 2035 | ||
2037 | return 0; | 2036 | return 0; |
2038 | } | 2037 | } |
2039 | EXPORT_SYMBOL_GPL(ab8500_audio_set_ear_cmv); | ||
2040 | 2038 | ||
2041 | static int ab8500_audio_set_bit_delay(struct snd_soc_dai *dai, | 2039 | static int ab8500_audio_set_bit_delay(struct snd_soc_dai *dai, |
2042 | unsigned int delay) | 2040 | unsigned int delay) |
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/ak4554.c b/sound/soc/codecs/ak4554.c index 16ce9f9fefa1..298dedc05140 100644 --- a/sound/soc/codecs/ak4554.c +++ b/sound/soc/codecs/ak4554.c | |||
@@ -84,7 +84,7 @@ static int ak4554_soc_remove(struct platform_device *pdev) | |||
84 | return 0; | 84 | return 0; |
85 | } | 85 | } |
86 | 86 | ||
87 | static struct of_device_id ak4554_of_match[] = { | 87 | static const struct of_device_id ak4554_of_match[] = { |
88 | { .compatible = "asahi-kasei,ak4554" }, | 88 | { .compatible = "asahi-kasei,ak4554" }, |
89 | {}, | 89 | {}, |
90 | }; | 90 | }; |
diff --git a/sound/soc/codecs/ak4642.c b/sound/soc/codecs/ak4642.c index dde8b49c19ad..13585e88f597 100644 --- a/sound/soc/codecs/ak4642.c +++ b/sound/soc/codecs/ak4642.c | |||
@@ -97,6 +97,9 @@ | |||
97 | #define PMMP (1 << 2) /* MPWR pin Power Management */ | 97 | #define PMMP (1 << 2) /* MPWR pin Power Management */ |
98 | #define MGAIN0 (1 << 0) /* MIC amp gain*/ | 98 | #define MGAIN0 (1 << 0) /* MIC amp gain*/ |
99 | 99 | ||
100 | /* SG_SL2 */ | ||
101 | #define LOPS (1 << 6) /* Stero Line-out Power Save Mode */ | ||
102 | |||
100 | /* TIMER */ | 103 | /* TIMER */ |
101 | #define ZTM(param) ((param & 0x3) << 4) /* ALC Zero Crossing TimeOut */ | 104 | #define ZTM(param) ((param & 0x3) << 4) /* ALC Zero Crossing TimeOut */ |
102 | #define WTM(param) (((param & 0x4) << 4) | ((param & 0x3) << 2)) | 105 | #define WTM(param) (((param & 0x4) << 4) | ((param & 0x3) << 2)) |
@@ -168,6 +171,29 @@ static const struct snd_kcontrol_new ak4642_lout_mixer_controls[] = { | |||
168 | SOC_DAPM_SINGLE("DACL", SG_SL1, 4, 1, 0), | 171 | SOC_DAPM_SINGLE("DACL", SG_SL1, 4, 1, 0), |
169 | }; | 172 | }; |
170 | 173 | ||
174 | /* event handlers */ | ||
175 | static int ak4642_lout_event(struct snd_soc_dapm_widget *w, | ||
176 | struct snd_kcontrol *kcontrol, int event) | ||
177 | { | ||
178 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); | ||
179 | |||
180 | switch (event) { | ||
181 | case SND_SOC_DAPM_PRE_PMD: | ||
182 | case SND_SOC_DAPM_PRE_PMU: | ||
183 | /* Power save mode ON */ | ||
184 | snd_soc_update_bits(codec, SG_SL2, LOPS, LOPS); | ||
185 | break; | ||
186 | case SND_SOC_DAPM_POST_PMU: | ||
187 | case SND_SOC_DAPM_POST_PMD: | ||
188 | /* Power save mode OFF */ | ||
189 | mdelay(300); | ||
190 | snd_soc_update_bits(codec, SG_SL2, LOPS, 0); | ||
191 | break; | ||
192 | } | ||
193 | |||
194 | return 0; | ||
195 | } | ||
196 | |||
171 | static const struct snd_soc_dapm_widget ak4642_dapm_widgets[] = { | 197 | static const struct snd_soc_dapm_widget ak4642_dapm_widgets[] = { |
172 | 198 | ||
173 | /* Outputs */ | 199 | /* Outputs */ |
@@ -182,12 +208,15 @@ static const struct snd_soc_dapm_widget ak4642_dapm_widgets[] = { | |||
182 | 208 | ||
183 | SND_SOC_DAPM_PGA("DACH", MD_CTL4, 0, 0, NULL, 0), | 209 | SND_SOC_DAPM_PGA("DACH", MD_CTL4, 0, 0, NULL, 0), |
184 | 210 | ||
185 | SND_SOC_DAPM_MIXER("LINEOUT Mixer", PW_MGMT1, 3, 0, | 211 | SND_SOC_DAPM_MIXER_E("LINEOUT Mixer", PW_MGMT1, 3, 0, |
186 | &ak4642_lout_mixer_controls[0], | 212 | &ak4642_lout_mixer_controls[0], |
187 | ARRAY_SIZE(ak4642_lout_mixer_controls)), | 213 | ARRAY_SIZE(ak4642_lout_mixer_controls), |
214 | ak4642_lout_event, | ||
215 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | | ||
216 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), | ||
188 | 217 | ||
189 | /* DAC */ | 218 | /* DAC */ |
190 | SND_SOC_DAPM_DAC("DAC", "HiFi Playback", PW_MGMT1, 2, 0), | 219 | SND_SOC_DAPM_DAC("DAC", NULL, PW_MGMT1, 2, 0), |
191 | }; | 220 | }; |
192 | 221 | ||
193 | static const struct snd_soc_dapm_route ak4642_intercon[] = { | 222 | static const struct snd_soc_dapm_route ak4642_intercon[] = { |
@@ -205,6 +234,8 @@ static const struct snd_soc_dapm_route ak4642_intercon[] = { | |||
205 | {"DACH", NULL, "DAC"}, | 234 | {"DACH", NULL, "DAC"}, |
206 | 235 | ||
207 | {"LINEOUT Mixer", "DACL", "DAC"}, | 236 | {"LINEOUT Mixer", "DACL", "DAC"}, |
237 | |||
238 | { "DAC", NULL, "Playback" }, | ||
208 | }; | 239 | }; |
209 | 240 | ||
210 | /* | 241 | /* |
@@ -468,13 +499,13 @@ static struct snd_soc_dai_driver ak4642_dai = { | |||
468 | .name = "ak4642-hifi", | 499 | .name = "ak4642-hifi", |
469 | .playback = { | 500 | .playback = { |
470 | .stream_name = "Playback", | 501 | .stream_name = "Playback", |
471 | .channels_min = 1, | 502 | .channels_min = 2, |
472 | .channels_max = 2, | 503 | .channels_max = 2, |
473 | .rates = SNDRV_PCM_RATE_8000_48000, | 504 | .rates = SNDRV_PCM_RATE_8000_48000, |
474 | .formats = SNDRV_PCM_FMTBIT_S16_LE }, | 505 | .formats = SNDRV_PCM_FMTBIT_S16_LE }, |
475 | .capture = { | 506 | .capture = { |
476 | .stream_name = "Capture", | 507 | .stream_name = "Capture", |
477 | .channels_min = 1, | 508 | .channels_min = 2, |
478 | .channels_max = 2, | 509 | .channels_max = 2, |
479 | .rates = SNDRV_PCM_RATE_8000_48000, | 510 | .rates = SNDRV_PCM_RATE_8000_48000, |
480 | .formats = SNDRV_PCM_FMTBIT_S16_LE }, | 511 | .formats = SNDRV_PCM_FMTBIT_S16_LE }, |
diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c index 95d31d6291ac..57da0ceda03f 100644 --- a/sound/soc/codecs/arizona.c +++ b/sound/soc/codecs/arizona.c | |||
@@ -1902,7 +1902,7 @@ static int arizona_is_enabled_fll(struct arizona_fll *fll) | |||
1902 | static int arizona_enable_fll(struct arizona_fll *fll) | 1902 | static int arizona_enable_fll(struct arizona_fll *fll) |
1903 | { | 1903 | { |
1904 | struct arizona *arizona = fll->arizona; | 1904 | struct arizona *arizona = fll->arizona; |
1905 | int ret; | 1905 | unsigned long time_left; |
1906 | bool use_sync = false; | 1906 | bool use_sync = false; |
1907 | int already_enabled = arizona_is_enabled_fll(fll); | 1907 | int already_enabled = arizona_is_enabled_fll(fll); |
1908 | struct arizona_fll_cfg cfg; | 1908 | struct arizona_fll_cfg cfg; |
@@ -1978,9 +1978,9 @@ static int arizona_enable_fll(struct arizona_fll *fll) | |||
1978 | regmap_update_bits_async(arizona->regmap, fll->base + 1, | 1978 | regmap_update_bits_async(arizona->regmap, fll->base + 1, |
1979 | ARIZONA_FLL1_FREERUN, 0); | 1979 | ARIZONA_FLL1_FREERUN, 0); |
1980 | 1980 | ||
1981 | ret = wait_for_completion_timeout(&fll->ok, | 1981 | time_left = wait_for_completion_timeout(&fll->ok, |
1982 | msecs_to_jiffies(250)); | 1982 | msecs_to_jiffies(250)); |
1983 | if (ret == 0) | 1983 | if (time_left == 0) |
1984 | arizona_fll_warn(fll, "Timed out waiting for lock\n"); | 1984 | arizona_fll_warn(fll, "Timed out waiting for lock\n"); |
1985 | 1985 | ||
1986 | return 0; | 1986 | return 0; |
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, ®); | 449 | ret = regmap_read(cs35l32->regmap, CS35L32_DEVID_AB, ®); |
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/cs4271.c b/sound/soc/codecs/cs4271.c index 7d3a6accaf9a..e770ee6f36da 100644 --- a/sound/soc/codecs/cs4271.c +++ b/sound/soc/codecs/cs4271.c | |||
@@ -561,10 +561,10 @@ static int cs4271_codec_probe(struct snd_soc_codec *codec) | |||
561 | if (gpio_is_valid(cs4271->gpio_nreset)) { | 561 | if (gpio_is_valid(cs4271->gpio_nreset)) { |
562 | /* Reset codec */ | 562 | /* Reset codec */ |
563 | gpio_direction_output(cs4271->gpio_nreset, 0); | 563 | gpio_direction_output(cs4271->gpio_nreset, 0); |
564 | udelay(1); | 564 | mdelay(1); |
565 | gpio_set_value(cs4271->gpio_nreset, 1); | 565 | gpio_set_value(cs4271->gpio_nreset, 1); |
566 | /* Give the codec time to wake up */ | 566 | /* Give the codec time to wake up */ |
567 | udelay(1); | 567 | mdelay(1); |
568 | } | 568 | } |
569 | 569 | ||
570 | ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2, | 570 | ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2, |
diff --git a/sound/soc/codecs/cx20442.c b/sound/soc/codecs/cx20442.c index 0b10979513c4..0f334bc1b63c 100644 --- a/sound/soc/codecs/cx20442.c +++ b/sound/soc/codecs/cx20442.c | |||
@@ -420,7 +420,7 @@ static int cx20442_platform_probe(struct platform_device *pdev) | |||
420 | &cx20442_codec_dev, &cx20442_dai, 1); | 420 | &cx20442_codec_dev, &cx20442_dai, 1); |
421 | } | 421 | } |
422 | 422 | ||
423 | static int __exit cx20442_platform_remove(struct platform_device *pdev) | 423 | static int cx20442_platform_remove(struct platform_device *pdev) |
424 | { | 424 | { |
425 | snd_soc_unregister_codec(&pdev->dev); | 425 | snd_soc_unregister_codec(&pdev->dev); |
426 | return 0; | 426 | return 0; |
@@ -431,7 +431,7 @@ static struct platform_driver cx20442_platform_driver = { | |||
431 | .name = "cx20442-codec", | 431 | .name = "cx20442-codec", |
432 | }, | 432 | }, |
433 | .probe = cx20442_platform_probe, | 433 | .probe = cx20442_platform_probe, |
434 | .remove = __exit_p(cx20442_platform_remove), | 434 | .remove = cx20442_platform_remove, |
435 | }; | 435 | }; |
436 | 436 | ||
437 | module_platform_driver(cx20442_platform_driver); | 437 | module_platform_driver(cx20442_platform_driver); |
diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c index b112b1c2c394..3e33ef2acf3c 100644 --- a/sound/soc/codecs/max98090.c +++ b/sound/soc/codecs/max98090.c | |||
@@ -2605,8 +2605,24 @@ err_enable: | |||
2605 | return ret; | 2605 | return ret; |
2606 | } | 2606 | } |
2607 | 2607 | ||
2608 | static void max98090_i2c_shutdown(struct i2c_client *i2c) | ||
2609 | { | ||
2610 | struct max98090_priv *max98090 = dev_get_drvdata(&i2c->dev); | ||
2611 | |||
2612 | /* | ||
2613 | * Enable volume smoothing, disable zero cross. This will cause | ||
2614 | * a quick 40ms ramp to mute on shutdown. | ||
2615 | */ | ||
2616 | regmap_write(max98090->regmap, | ||
2617 | M98090_REG_LEVEL_CONTROL, M98090_VSENN_MASK); | ||
2618 | regmap_write(max98090->regmap, | ||
2619 | M98090_REG_DEVICE_SHUTDOWN, 0x00); | ||
2620 | msleep(40); | ||
2621 | } | ||
2622 | |||
2608 | static int max98090_i2c_remove(struct i2c_client *client) | 2623 | static int max98090_i2c_remove(struct i2c_client *client) |
2609 | { | 2624 | { |
2625 | max98090_i2c_shutdown(client); | ||
2610 | snd_soc_unregister_codec(&client->dev); | 2626 | snd_soc_unregister_codec(&client->dev); |
2611 | return 0; | 2627 | return 0; |
2612 | } | 2628 | } |
@@ -2696,6 +2712,7 @@ static struct i2c_driver max98090_i2c_driver = { | |||
2696 | .acpi_match_table = ACPI_PTR(max98090_acpi_match), | 2712 | .acpi_match_table = ACPI_PTR(max98090_acpi_match), |
2697 | }, | 2713 | }, |
2698 | .probe = max98090_i2c_probe, | 2714 | .probe = max98090_i2c_probe, |
2715 | .shutdown = max98090_i2c_shutdown, | ||
2699 | .remove = max98090_i2c_remove, | 2716 | .remove = max98090_i2c_remove, |
2700 | .id_table = max98090_i2c_id, | 2717 | .id_table = max98090_i2c_id, |
2701 | }; | 2718 | }; |
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 | |||
31 | static int max98357a_daiops_trigger(struct snd_pcm_substream *substream, | 29 | static 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 | ||
89 | static struct snd_soc_dai_driver max98357a_dai_driver = { | 87 | static 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 |
129 | static const struct of_device_id max98357a_device_id[] = { | 127 | static const struct of_device_id max98357a_device_id[] = { |
130 | { .compatible = "maxim," DRV_NAME, }, | 128 | { .compatible = "maxim,max98357a" }, |
131 | {} | 129 | {} |
132 | }; | 130 | }; |
133 | MODULE_DEVICE_TABLE(of, max98357a_device_id); | 131 | MODULE_DEVICE_TABLE(of, max98357a_device_id); |
@@ -135,7 +133,7 @@ MODULE_DEVICE_TABLE(of, max98357a_device_id); | |||
135 | 133 | ||
136 | static struct platform_driver max98357a_platform_driver = { | 134 | static 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 | ||
146 | MODULE_DESCRIPTION("Maxim MAX98357A Codec Driver"); | 144 | MODULE_DESCRIPTION("Maxim MAX98357A Codec Driver"); |
147 | MODULE_LICENSE("GPL v2"); | 145 | MODULE_LICENSE("GPL v2"); |
148 | MODULE_ALIAS("platform:" DRV_NAME); | ||
diff --git a/sound/soc/codecs/max98925.c b/sound/soc/codecs/max98925.c new file mode 100644 index 000000000000..9b5a17de4690 --- /dev/null +++ b/sound/soc/codecs/max98925.c | |||
@@ -0,0 +1,655 @@ | |||
1 | /* | ||
2 | * max98925.c -- ALSA SoC Stereo MAX98925 driver | ||
3 | * Copyright 2013-15 Maxim Integrated Products | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | */ | ||
8 | #include <linux/delay.h> | ||
9 | #include <linux/i2c.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/regmap.h> | ||
12 | #include <linux/slab.h> | ||
13 | #include <linux/cdev.h> | ||
14 | #include <sound/pcm.h> | ||
15 | #include <sound/pcm_params.h> | ||
16 | #include <sound/soc.h> | ||
17 | #include <sound/tlv.h> | ||
18 | #include "max98925.h" | ||
19 | |||
20 | static const char *const dai_text[] = { | ||
21 | "Left", "Right", "LeftRight", "LeftRightDiv2", | ||
22 | }; | ||
23 | |||
24 | static const char * const max98925_boost_voltage_text[] = { | ||
25 | "8.5V", "8.25V", "8.0V", "7.75V", "7.5V", "7.25V", "7.0V", "6.75V", | ||
26 | "6.5V", "6.5V", "6.5V", "6.5V", "6.5V", "6.5V", "6.5V", "6.5V" | ||
27 | }; | ||
28 | |||
29 | static SOC_ENUM_SINGLE_DECL(max98925_boost_voltage, | ||
30 | MAX98925_CONFIGURATION, M98925_BST_VOUT_SHIFT, | ||
31 | max98925_boost_voltage_text); | ||
32 | |||
33 | static const char *const hpf_text[] = { | ||
34 | "Disable", "DC Block", "100Hz", "200Hz", "400Hz", "800Hz", | ||
35 | }; | ||
36 | |||
37 | static const struct reg_default max98925_reg[] = { | ||
38 | { 0x0B, 0x00 }, /* IRQ Enable0 */ | ||
39 | { 0x0C, 0x00 }, /* IRQ Enable1 */ | ||
40 | { 0x0D, 0x00 }, /* IRQ Enable2 */ | ||
41 | { 0x0E, 0x00 }, /* IRQ Clear0 */ | ||
42 | { 0x0F, 0x00 }, /* IRQ Clear1 */ | ||
43 | { 0x10, 0x00 }, /* IRQ Clear2 */ | ||
44 | { 0x11, 0xC0 }, /* Map0 */ | ||
45 | { 0x12, 0x00 }, /* Map1 */ | ||
46 | { 0x13, 0x00 }, /* Map2 */ | ||
47 | { 0x14, 0xF0 }, /* Map3 */ | ||
48 | { 0x15, 0x00 }, /* Map4 */ | ||
49 | { 0x16, 0xAB }, /* Map5 */ | ||
50 | { 0x17, 0x89 }, /* Map6 */ | ||
51 | { 0x18, 0x00 }, /* Map7 */ | ||
52 | { 0x19, 0x00 }, /* Map8 */ | ||
53 | { 0x1A, 0x06 }, /* DAI Clock Mode 1 */ | ||
54 | { 0x1B, 0xC0 }, /* DAI Clock Mode 2 */ | ||
55 | { 0x1C, 0x00 }, /* DAI Clock Divider Denominator MSBs */ | ||
56 | { 0x1D, 0x00 }, /* DAI Clock Divider Denominator LSBs */ | ||
57 | { 0x1E, 0xF0 }, /* DAI Clock Divider Numerator MSBs */ | ||
58 | { 0x1F, 0x00 }, /* DAI Clock Divider Numerator LSBs */ | ||
59 | { 0x20, 0x50 }, /* Format */ | ||
60 | { 0x21, 0x00 }, /* TDM Slot Select */ | ||
61 | { 0x22, 0x00 }, /* DOUT Configuration VMON */ | ||
62 | { 0x23, 0x00 }, /* DOUT Configuration IMON */ | ||
63 | { 0x24, 0x00 }, /* DOUT Configuration VBAT */ | ||
64 | { 0x25, 0x00 }, /* DOUT Configuration VBST */ | ||
65 | { 0x26, 0x00 }, /* DOUT Configuration FLAG */ | ||
66 | { 0x27, 0xFF }, /* DOUT HiZ Configuration 1 */ | ||
67 | { 0x28, 0xFF }, /* DOUT HiZ Configuration 2 */ | ||
68 | { 0x29, 0xFF }, /* DOUT HiZ Configuration 3 */ | ||
69 | { 0x2A, 0xFF }, /* DOUT HiZ Configuration 4 */ | ||
70 | { 0x2B, 0x02 }, /* DOUT Drive Strength */ | ||
71 | { 0x2C, 0x90 }, /* Filters */ | ||
72 | { 0x2D, 0x00 }, /* Gain */ | ||
73 | { 0x2E, 0x02 }, /* Gain Ramping */ | ||
74 | { 0x2F, 0x00 }, /* Speaker Amplifier */ | ||
75 | { 0x30, 0x0A }, /* Threshold */ | ||
76 | { 0x31, 0x00 }, /* ALC Attack */ | ||
77 | { 0x32, 0x80 }, /* ALC Atten and Release */ | ||
78 | { 0x33, 0x00 }, /* ALC Infinite Hold Release */ | ||
79 | { 0x34, 0x92 }, /* ALC Configuration */ | ||
80 | { 0x35, 0x01 }, /* Boost Converter */ | ||
81 | { 0x36, 0x00 }, /* Block Enable */ | ||
82 | { 0x37, 0x00 }, /* Configuration */ | ||
83 | { 0x38, 0x00 }, /* Global Enable */ | ||
84 | { 0x3A, 0x00 }, /* Boost Limiter */ | ||
85 | }; | ||
86 | |||
87 | static const struct soc_enum max98925_dai_enum = | ||
88 | SOC_ENUM_SINGLE(MAX98925_GAIN, 5, ARRAY_SIZE(dai_text), dai_text); | ||
89 | |||
90 | static const struct soc_enum max98925_hpf_enum = | ||
91 | SOC_ENUM_SINGLE(MAX98925_FILTERS, 0, ARRAY_SIZE(hpf_text), hpf_text); | ||
92 | |||
93 | static const struct snd_kcontrol_new max98925_hpf_sel_mux = | ||
94 | SOC_DAPM_ENUM("Rc Filter MUX Mux", max98925_hpf_enum); | ||
95 | |||
96 | static const struct snd_kcontrol_new max98925_dai_sel_mux = | ||
97 | SOC_DAPM_ENUM("DAI IN MUX Mux", max98925_dai_enum); | ||
98 | |||
99 | static int max98925_dac_event(struct snd_soc_dapm_widget *w, | ||
100 | struct snd_kcontrol *kcontrol, int event) | ||
101 | { | ||
102 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); | ||
103 | struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec); | ||
104 | |||
105 | switch (event) { | ||
106 | case SND_SOC_DAPM_PRE_PMU: | ||
107 | regmap_update_bits(max98925->regmap, | ||
108 | MAX98925_BLOCK_ENABLE, | ||
109 | M98925_BST_EN_MASK | | ||
110 | M98925_ADC_IMON_EN_MASK | M98925_ADC_VMON_EN_MASK, | ||
111 | M98925_BST_EN_MASK | | ||
112 | M98925_ADC_IMON_EN_MASK | M98925_ADC_VMON_EN_MASK); | ||
113 | break; | ||
114 | case SND_SOC_DAPM_POST_PMD: | ||
115 | regmap_update_bits(max98925->regmap, | ||
116 | MAX98925_BLOCK_ENABLE, M98925_BST_EN_MASK | | ||
117 | M98925_ADC_IMON_EN_MASK | M98925_ADC_VMON_EN_MASK, 0); | ||
118 | break; | ||
119 | default: | ||
120 | return 0; | ||
121 | } | ||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | static const struct snd_soc_dapm_widget max98925_dapm_widgets[] = { | ||
126 | SND_SOC_DAPM_AIF_IN("DAI_OUT", "HiFi Playback", 0, SND_SOC_NOPM, 0, 0), | ||
127 | SND_SOC_DAPM_MUX("DAI IN MUX", SND_SOC_NOPM, 0, 0, | ||
128 | &max98925_dai_sel_mux), | ||
129 | SND_SOC_DAPM_MUX("Rc Filter MUX", SND_SOC_NOPM, 0, 0, | ||
130 | &max98925_hpf_sel_mux), | ||
131 | SND_SOC_DAPM_DAC_E("Amp Enable", NULL, MAX98925_BLOCK_ENABLE, | ||
132 | M98925_SPK_EN_SHIFT, 0, max98925_dac_event, | ||
133 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), | ||
134 | SND_SOC_DAPM_SUPPLY("Global Enable", MAX98925_GLOBAL_ENABLE, | ||
135 | M98925_EN_SHIFT, 0, NULL, 0), | ||
136 | SND_SOC_DAPM_OUTPUT("BE_OUT"), | ||
137 | }; | ||
138 | |||
139 | static const struct snd_soc_dapm_route max98925_audio_map[] = { | ||
140 | {"DAI IN MUX", "Left", "DAI_OUT"}, | ||
141 | {"DAI IN MUX", "Right", "DAI_OUT"}, | ||
142 | {"DAI IN MUX", "LeftRight", "DAI_OUT"}, | ||
143 | {"DAI IN MUX", "LeftRightDiv2", "DAI_OUT"}, | ||
144 | {"Rc Filter MUX", "Disable", "DAI IN MUX"}, | ||
145 | {"Rc Filter MUX", "DC Block", "DAI IN MUX"}, | ||
146 | {"Rc Filter MUX", "100Hz", "DAI IN MUX"}, | ||
147 | {"Rc Filter MUX", "200Hz", "DAI IN MUX"}, | ||
148 | {"Rc Filter MUX", "400Hz", "DAI IN MUX"}, | ||
149 | {"Rc Filter MUX", "800Hz", "DAI IN MUX"}, | ||
150 | {"Amp Enable", NULL, "Rc Filter MUX"}, | ||
151 | {"BE_OUT", NULL, "Amp Enable"}, | ||
152 | {"BE_OUT", NULL, "Global Enable"}, | ||
153 | }; | ||
154 | |||
155 | static bool max98925_volatile_register(struct device *dev, unsigned int reg) | ||
156 | { | ||
157 | switch (reg) { | ||
158 | case MAX98925_VBAT_DATA: | ||
159 | case MAX98925_VBST_DATA: | ||
160 | case MAX98925_LIVE_STATUS0: | ||
161 | case MAX98925_LIVE_STATUS1: | ||
162 | case MAX98925_LIVE_STATUS2: | ||
163 | case MAX98925_STATE0: | ||
164 | case MAX98925_STATE1: | ||
165 | case MAX98925_STATE2: | ||
166 | case MAX98925_FLAG0: | ||
167 | case MAX98925_FLAG1: | ||
168 | case MAX98925_FLAG2: | ||
169 | case MAX98925_REV_VERSION: | ||
170 | return true; | ||
171 | default: | ||
172 | return false; | ||
173 | } | ||
174 | } | ||
175 | |||
176 | static bool max98925_readable_register(struct device *dev, unsigned int reg) | ||
177 | { | ||
178 | switch (reg) { | ||
179 | case MAX98925_IRQ_CLEAR0: | ||
180 | case MAX98925_IRQ_CLEAR1: | ||
181 | case MAX98925_IRQ_CLEAR2: | ||
182 | case MAX98925_ALC_HOLD_RLS: | ||
183 | return false; | ||
184 | default: | ||
185 | return true; | ||
186 | } | ||
187 | } | ||
188 | |||
189 | static DECLARE_TLV_DB_SCALE(max98925_spk_tlv, -600, 100, 0); | ||
190 | |||
191 | static const struct snd_kcontrol_new max98925_snd_controls[] = { | ||
192 | SOC_SINGLE_TLV("Speaker Volume", MAX98925_GAIN, | ||
193 | M98925_SPK_GAIN_SHIFT, (1<<M98925_SPK_GAIN_WIDTH)-1, 0, | ||
194 | max98925_spk_tlv), | ||
195 | SOC_SINGLE("Ramp Switch", MAX98925_GAIN_RAMPING, | ||
196 | M98925_SPK_RMP_EN_SHIFT, 1, 0), | ||
197 | SOC_SINGLE("ZCD Switch", MAX98925_GAIN_RAMPING, | ||
198 | M98925_SPK_ZCD_EN_SHIFT, 1, 0), | ||
199 | SOC_SINGLE("ALC Switch", MAX98925_THRESHOLD, | ||
200 | M98925_ALC_EN_SHIFT, 1, 0), | ||
201 | SOC_SINGLE("ALC Threshold", MAX98925_THRESHOLD, M98925_ALC_TH_SHIFT, | ||
202 | (1<<M98925_ALC_TH_WIDTH)-1, 0), | ||
203 | SOC_ENUM("Boost Output Voltage", max98925_boost_voltage), | ||
204 | }; | ||
205 | |||
206 | /* codec sample rate and n/m dividers parameter table */ | ||
207 | static const struct { | ||
208 | int rate; | ||
209 | int sr; | ||
210 | int divisors[3][2]; | ||
211 | } rate_table[] = { | ||
212 | { | ||
213 | .rate = 8000, | ||
214 | .sr = 0, | ||
215 | .divisors = { {1, 375}, {5, 1764}, {1, 384} } | ||
216 | }, | ||
217 | { | ||
218 | .rate = 11025, | ||
219 | .sr = 1, | ||
220 | .divisors = { {147, 40000}, {1, 256}, {147, 40960} } | ||
221 | }, | ||
222 | { | ||
223 | .rate = 12000, | ||
224 | .sr = 2, | ||
225 | .divisors = { {1, 250}, {5, 1176}, {1, 256} } | ||
226 | }, | ||
227 | { | ||
228 | .rate = 16000, | ||
229 | .sr = 3, | ||
230 | .divisors = { {2, 375}, {5, 882}, {1, 192} } | ||
231 | }, | ||
232 | { | ||
233 | .rate = 22050, | ||
234 | .sr = 4, | ||
235 | .divisors = { {147, 20000}, {1, 128}, {147, 20480} } | ||
236 | }, | ||
237 | { | ||
238 | .rate = 24000, | ||
239 | .sr = 5, | ||
240 | .divisors = { {1, 125}, {5, 588}, {1, 128} } | ||
241 | }, | ||
242 | { | ||
243 | .rate = 32000, | ||
244 | .sr = 6, | ||
245 | .divisors = { {4, 375}, {5, 441}, {1, 96} } | ||
246 | }, | ||
247 | { | ||
248 | .rate = 44100, | ||
249 | .sr = 7, | ||
250 | .divisors = { {147, 10000}, {1, 64}, {147, 10240} } | ||
251 | }, | ||
252 | { | ||
253 | .rate = 48000, | ||
254 | .sr = 8, | ||
255 | .divisors = { {2, 125}, {5, 294}, {1, 64} } | ||
256 | }, | ||
257 | }; | ||
258 | |||
259 | static inline int max98925_rate_value(struct snd_soc_codec *codec, | ||
260 | int rate, int clock, int *value, int *n, int *m) | ||
261 | { | ||
262 | int ret = -EINVAL; | ||
263 | int i; | ||
264 | |||
265 | for (i = 0; i < ARRAY_SIZE(rate_table); i++) { | ||
266 | if (rate_table[i].rate >= rate) { | ||
267 | *value = rate_table[i].sr; | ||
268 | *n = rate_table[i].divisors[clock][0]; | ||
269 | *m = rate_table[i].divisors[clock][1]; | ||
270 | ret = 0; | ||
271 | break; | ||
272 | } | ||
273 | } | ||
274 | dev_dbg(codec->dev, "%s: sample rate is %d, returning %d\n", | ||
275 | __func__, rate_table[i].rate, *value); | ||
276 | return ret; | ||
277 | } | ||
278 | |||
279 | static void max98925_set_sense_data(struct max98925_priv *max98925) | ||
280 | { | ||
281 | /* set VMON slots */ | ||
282 | regmap_update_bits(max98925->regmap, | ||
283 | MAX98925_DOUT_CFG_VMON, | ||
284 | M98925_DAI_VMON_EN_MASK, M98925_DAI_VMON_EN_MASK); | ||
285 | regmap_update_bits(max98925->regmap, | ||
286 | MAX98925_DOUT_CFG_VMON, | ||
287 | M98925_DAI_VMON_SLOT_MASK, | ||
288 | max98925->v_slot << M98925_DAI_VMON_SLOT_SHIFT); | ||
289 | /* set IMON slots */ | ||
290 | regmap_update_bits(max98925->regmap, | ||
291 | MAX98925_DOUT_CFG_IMON, | ||
292 | M98925_DAI_IMON_EN_MASK, M98925_DAI_IMON_EN_MASK); | ||
293 | regmap_update_bits(max98925->regmap, | ||
294 | MAX98925_DOUT_CFG_IMON, | ||
295 | M98925_DAI_IMON_SLOT_MASK, | ||
296 | max98925->i_slot << M98925_DAI_IMON_SLOT_SHIFT); | ||
297 | } | ||
298 | |||
299 | static int max98925_dai_set_fmt(struct snd_soc_dai *codec_dai, | ||
300 | unsigned int fmt) | ||
301 | { | ||
302 | struct snd_soc_codec *codec = codec_dai->codec; | ||
303 | struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec); | ||
304 | unsigned int invert = 0; | ||
305 | |||
306 | dev_dbg(codec->dev, "%s: fmt 0x%08X\n", __func__, fmt); | ||
307 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
308 | case SND_SOC_DAIFMT_CBS_CFS: | ||
309 | /* set DAI to slave mode */ | ||
310 | regmap_update_bits(max98925->regmap, | ||
311 | MAX98925_DAI_CLK_MODE2, | ||
312 | M98925_DAI_MAS_MASK, 0); | ||
313 | max98925_set_sense_data(max98925); | ||
314 | break; | ||
315 | case SND_SOC_DAIFMT_CBM_CFM: | ||
316 | /* | ||
317 | * set left channel DAI to master mode, | ||
318 | * right channel always slave | ||
319 | */ | ||
320 | regmap_update_bits(max98925->regmap, | ||
321 | MAX98925_DAI_CLK_MODE2, | ||
322 | M98925_DAI_MAS_MASK, M98925_DAI_MAS_MASK); | ||
323 | break; | ||
324 | case SND_SOC_DAIFMT_CBS_CFM: | ||
325 | case SND_SOC_DAIFMT_CBM_CFS: | ||
326 | default: | ||
327 | dev_err(codec->dev, "DAI clock mode unsupported"); | ||
328 | return -EINVAL; | ||
329 | } | ||
330 | |||
331 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
332 | case SND_SOC_DAIFMT_NB_NF: | ||
333 | break; | ||
334 | case SND_SOC_DAIFMT_NB_IF: | ||
335 | invert = M98925_DAI_WCI_MASK; | ||
336 | break; | ||
337 | case SND_SOC_DAIFMT_IB_NF: | ||
338 | invert = M98925_DAI_BCI_MASK; | ||
339 | break; | ||
340 | case SND_SOC_DAIFMT_IB_IF: | ||
341 | invert = M98925_DAI_BCI_MASK | M98925_DAI_WCI_MASK; | ||
342 | break; | ||
343 | default: | ||
344 | dev_err(codec->dev, "DAI invert mode unsupported"); | ||
345 | return -EINVAL; | ||
346 | } | ||
347 | |||
348 | regmap_update_bits(max98925->regmap, MAX98925_FORMAT, | ||
349 | M98925_DAI_BCI_MASK, invert); | ||
350 | return 0; | ||
351 | } | ||
352 | |||
353 | static int max98925_set_clock(struct max98925_priv *max98925, | ||
354 | struct snd_pcm_hw_params *params) | ||
355 | { | ||
356 | unsigned int dai_sr = 0, clock, mdll, n, m; | ||
357 | struct snd_soc_codec *codec = max98925->codec; | ||
358 | int rate = params_rate(params); | ||
359 | /* BCLK/LRCLK ratio calculation */ | ||
360 | int blr_clk_ratio = params_channels(params) * max98925->ch_size; | ||
361 | |||
362 | switch (blr_clk_ratio) { | ||
363 | case 32: | ||
364 | regmap_update_bits(max98925->regmap, | ||
365 | MAX98925_DAI_CLK_MODE2, | ||
366 | M98925_DAI_BSEL_MASK, M98925_DAI_BSEL_32); | ||
367 | break; | ||
368 | case 48: | ||
369 | regmap_update_bits(max98925->regmap, | ||
370 | MAX98925_DAI_CLK_MODE2, | ||
371 | M98925_DAI_BSEL_MASK, M98925_DAI_BSEL_48); | ||
372 | break; | ||
373 | case 64: | ||
374 | regmap_update_bits(max98925->regmap, | ||
375 | MAX98925_DAI_CLK_MODE2, | ||
376 | M98925_DAI_BSEL_MASK, M98925_DAI_BSEL_64); | ||
377 | break; | ||
378 | default: | ||
379 | return -EINVAL; | ||
380 | } | ||
381 | |||
382 | switch (max98925->sysclk) { | ||
383 | case 6000000: | ||
384 | clock = 0; | ||
385 | mdll = M98925_MDLL_MULT_MCLKx16; | ||
386 | break; | ||
387 | case 11289600: | ||
388 | clock = 1; | ||
389 | mdll = M98925_MDLL_MULT_MCLKx8; | ||
390 | break; | ||
391 | case 12000000: | ||
392 | clock = 0; | ||
393 | mdll = M98925_MDLL_MULT_MCLKx8; | ||
394 | break; | ||
395 | case 12288000: | ||
396 | clock = 2; | ||
397 | mdll = M98925_MDLL_MULT_MCLKx8; | ||
398 | break; | ||
399 | default: | ||
400 | dev_info(max98925->codec->dev, "unsupported sysclk %d\n", | ||
401 | max98925->sysclk); | ||
402 | return -EINVAL; | ||
403 | } | ||
404 | |||
405 | if (max98925_rate_value(codec, rate, clock, &dai_sr, &n, &m)) | ||
406 | return -EINVAL; | ||
407 | |||
408 | /* set DAI_SR to correct LRCLK frequency */ | ||
409 | regmap_update_bits(max98925->regmap, | ||
410 | MAX98925_DAI_CLK_MODE2, | ||
411 | M98925_DAI_SR_MASK, dai_sr << M98925_DAI_SR_SHIFT); | ||
412 | /* set DAI m divider */ | ||
413 | regmap_write(max98925->regmap, | ||
414 | MAX98925_DAI_CLK_DIV_M_MSBS, m >> 8); | ||
415 | regmap_write(max98925->regmap, | ||
416 | MAX98925_DAI_CLK_DIV_M_LSBS, m & 0xFF); | ||
417 | /* set DAI n divider */ | ||
418 | regmap_write(max98925->regmap, | ||
419 | MAX98925_DAI_CLK_DIV_N_MSBS, n >> 8); | ||
420 | regmap_write(max98925->regmap, | ||
421 | MAX98925_DAI_CLK_DIV_N_LSBS, n & 0xFF); | ||
422 | /* set MDLL */ | ||
423 | regmap_update_bits(max98925->regmap, MAX98925_DAI_CLK_MODE1, | ||
424 | M98925_MDLL_MULT_MASK, mdll << M98925_MDLL_MULT_SHIFT); | ||
425 | return 0; | ||
426 | } | ||
427 | |||
428 | static int max98925_dai_hw_params(struct snd_pcm_substream *substream, | ||
429 | struct snd_pcm_hw_params *params, | ||
430 | struct snd_soc_dai *dai) | ||
431 | { | ||
432 | struct snd_soc_codec *codec = dai->codec; | ||
433 | struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec); | ||
434 | |||
435 | switch (snd_pcm_format_width(params_format(params))) { | ||
436 | case 16: | ||
437 | regmap_update_bits(max98925->regmap, | ||
438 | MAX98925_FORMAT, | ||
439 | M98925_DAI_CHANSZ_MASK, M98925_DAI_CHANSZ_16); | ||
440 | max98925->ch_size = 16; | ||
441 | break; | ||
442 | case 24: | ||
443 | regmap_update_bits(max98925->regmap, | ||
444 | MAX98925_FORMAT, | ||
445 | M98925_DAI_CHANSZ_MASK, M98925_DAI_CHANSZ_24); | ||
446 | max98925->ch_size = 24; | ||
447 | break; | ||
448 | case 32: | ||
449 | regmap_update_bits(max98925->regmap, | ||
450 | MAX98925_FORMAT, | ||
451 | M98925_DAI_CHANSZ_MASK, M98925_DAI_CHANSZ_32); | ||
452 | max98925->ch_size = 32; | ||
453 | break; | ||
454 | default: | ||
455 | pr_err("%s: format unsupported %d", | ||
456 | __func__, params_format(params)); | ||
457 | return -EINVAL; | ||
458 | } | ||
459 | dev_dbg(codec->dev, "%s: format supported %d", | ||
460 | __func__, params_format(params)); | ||
461 | return max98925_set_clock(max98925, params); | ||
462 | } | ||
463 | |||
464 | static int max98925_dai_set_sysclk(struct snd_soc_dai *dai, | ||
465 | int clk_id, unsigned int freq, int dir) | ||
466 | { | ||
467 | struct snd_soc_codec *codec = dai->codec; | ||
468 | struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec); | ||
469 | |||
470 | switch (clk_id) { | ||
471 | case 0: | ||
472 | /* use MCLK for Left channel, right channel always BCLK */ | ||
473 | regmap_update_bits(max98925->regmap, | ||
474 | MAX98925_DAI_CLK_MODE1, | ||
475 | M98925_DAI_CLK_SOURCE_MASK, 0); | ||
476 | break; | ||
477 | case 1: | ||
478 | /* configure dai clock source to BCLK instead of MCLK */ | ||
479 | regmap_update_bits(max98925->regmap, | ||
480 | MAX98925_DAI_CLK_MODE1, | ||
481 | M98925_DAI_CLK_SOURCE_MASK, | ||
482 | M98925_DAI_CLK_SOURCE_MASK); | ||
483 | break; | ||
484 | default: | ||
485 | return -EINVAL; | ||
486 | } | ||
487 | max98925->sysclk = freq; | ||
488 | return 0; | ||
489 | } | ||
490 | |||
491 | #define MAX98925_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \ | ||
492 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) | ||
493 | |||
494 | static const struct snd_soc_dai_ops max98925_dai_ops = { | ||
495 | .set_sysclk = max98925_dai_set_sysclk, | ||
496 | .set_fmt = max98925_dai_set_fmt, | ||
497 | .hw_params = max98925_dai_hw_params, | ||
498 | }; | ||
499 | |||
500 | static struct snd_soc_dai_driver max98925_dai[] = { | ||
501 | { | ||
502 | .name = "max98925-aif1", | ||
503 | .playback = { | ||
504 | .stream_name = "HiFi Playback", | ||
505 | .channels_min = 1, | ||
506 | .channels_max = 2, | ||
507 | .rates = SNDRV_PCM_RATE_8000_48000, | ||
508 | .formats = MAX98925_FORMATS, | ||
509 | }, | ||
510 | .capture = { | ||
511 | .stream_name = "HiFi Capture", | ||
512 | .channels_min = 1, | ||
513 | .channels_max = 2, | ||
514 | .rates = SNDRV_PCM_RATE_8000_48000, | ||
515 | .formats = MAX98925_FORMATS, | ||
516 | }, | ||
517 | .ops = &max98925_dai_ops, | ||
518 | } | ||
519 | }; | ||
520 | |||
521 | static int max98925_probe(struct snd_soc_codec *codec) | ||
522 | { | ||
523 | struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec); | ||
524 | |||
525 | max98925->codec = codec; | ||
526 | codec->control_data = max98925->regmap; | ||
527 | regmap_write(max98925->regmap, MAX98925_GLOBAL_ENABLE, 0x00); | ||
528 | /* It's not the default but we need to set DAI_DLY */ | ||
529 | regmap_write(max98925->regmap, | ||
530 | MAX98925_FORMAT, M98925_DAI_DLY_MASK); | ||
531 | regmap_write(max98925->regmap, MAX98925_TDM_SLOT_SELECT, 0xC8); | ||
532 | regmap_write(max98925->regmap, MAX98925_DOUT_HIZ_CFG1, 0xFF); | ||
533 | regmap_write(max98925->regmap, MAX98925_DOUT_HIZ_CFG2, 0xFF); | ||
534 | regmap_write(max98925->regmap, MAX98925_DOUT_HIZ_CFG3, 0xFF); | ||
535 | regmap_write(max98925->regmap, MAX98925_DOUT_HIZ_CFG4, 0xF0); | ||
536 | regmap_write(max98925->regmap, MAX98925_FILTERS, 0xD8); | ||
537 | regmap_write(max98925->regmap, MAX98925_ALC_CONFIGURATION, 0xF8); | ||
538 | regmap_write(max98925->regmap, MAX98925_CONFIGURATION, 0xF0); | ||
539 | /* Disable ALC muting */ | ||
540 | regmap_write(max98925->regmap, MAX98925_BOOST_LIMITER, 0xF8); | ||
541 | return 0; | ||
542 | } | ||
543 | |||
544 | static const struct snd_soc_codec_driver soc_codec_dev_max98925 = { | ||
545 | .probe = max98925_probe, | ||
546 | .controls = max98925_snd_controls, | ||
547 | .num_controls = ARRAY_SIZE(max98925_snd_controls), | ||
548 | .dapm_routes = max98925_audio_map, | ||
549 | .num_dapm_routes = ARRAY_SIZE(max98925_audio_map), | ||
550 | .dapm_widgets = max98925_dapm_widgets, | ||
551 | .num_dapm_widgets = ARRAY_SIZE(max98925_dapm_widgets), | ||
552 | }; | ||
553 | |||
554 | static const struct regmap_config max98925_regmap = { | ||
555 | .reg_bits = 8, | ||
556 | .val_bits = 8, | ||
557 | .max_register = MAX98925_REV_VERSION, | ||
558 | .reg_defaults = max98925_reg, | ||
559 | .num_reg_defaults = ARRAY_SIZE(max98925_reg), | ||
560 | .volatile_reg = max98925_volatile_register, | ||
561 | .readable_reg = max98925_readable_register, | ||
562 | .cache_type = REGCACHE_RBTREE, | ||
563 | }; | ||
564 | |||
565 | static int max98925_i2c_probe(struct i2c_client *i2c, | ||
566 | const struct i2c_device_id *id) | ||
567 | { | ||
568 | int ret, reg; | ||
569 | u32 value; | ||
570 | struct max98925_priv *max98925; | ||
571 | |||
572 | max98925 = devm_kzalloc(&i2c->dev, | ||
573 | sizeof(*max98925), GFP_KERNEL); | ||
574 | if (!max98925) | ||
575 | return -ENOMEM; | ||
576 | |||
577 | i2c_set_clientdata(i2c, max98925); | ||
578 | max98925->regmap = devm_regmap_init_i2c(i2c, &max98925_regmap); | ||
579 | if (IS_ERR(max98925->regmap)) { | ||
580 | ret = PTR_ERR(max98925->regmap); | ||
581 | dev_err(&i2c->dev, | ||
582 | "Failed to allocate regmap: %d\n", ret); | ||
583 | goto err_out; | ||
584 | } | ||
585 | |||
586 | if (!of_property_read_u32(i2c->dev.of_node, "vmon-slot-no", &value)) { | ||
587 | if (value > M98925_DAI_VMON_SLOT_1E_1F) { | ||
588 | dev_err(&i2c->dev, "vmon slot number is wrong:\n"); | ||
589 | return -EINVAL; | ||
590 | } | ||
591 | max98925->v_slot = value; | ||
592 | } | ||
593 | if (!of_property_read_u32(i2c->dev.of_node, "imon-slot-no", &value)) { | ||
594 | if (value > M98925_DAI_IMON_SLOT_1E_1F) { | ||
595 | dev_err(&i2c->dev, "imon slot number is wrong:\n"); | ||
596 | return -EINVAL; | ||
597 | } | ||
598 | max98925->i_slot = value; | ||
599 | } | ||
600 | ret = regmap_read(max98925->regmap, | ||
601 | MAX98925_REV_VERSION, ®); | ||
602 | if ((ret < 0) || | ||
603 | ((reg != MAX98925_VERSION) && | ||
604 | (reg != MAX98925_VERSION1))) { | ||
605 | dev_err(&i2c->dev, | ||
606 | "device initialization error (%d 0x%02X)\n", | ||
607 | ret, reg); | ||
608 | goto err_out; | ||
609 | } | ||
610 | dev_info(&i2c->dev, "device version 0x%02X\n", reg); | ||
611 | |||
612 | ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_max98925, | ||
613 | max98925_dai, ARRAY_SIZE(max98925_dai)); | ||
614 | if (ret < 0) | ||
615 | dev_err(&i2c->dev, | ||
616 | "Failed to register codec: %d\n", ret); | ||
617 | err_out: | ||
618 | return ret; | ||
619 | } | ||
620 | |||
621 | static int max98925_i2c_remove(struct i2c_client *client) | ||
622 | { | ||
623 | snd_soc_unregister_codec(&client->dev); | ||
624 | return 0; | ||
625 | } | ||
626 | |||
627 | static const struct i2c_device_id max98925_i2c_id[] = { | ||
628 | { "max98925", 0 }, | ||
629 | { } | ||
630 | }; | ||
631 | MODULE_DEVICE_TABLE(i2c, max98925_i2c_id); | ||
632 | |||
633 | static const struct of_device_id max98925_of_match[] = { | ||
634 | { .compatible = "maxim,max98925", }, | ||
635 | { } | ||
636 | }; | ||
637 | MODULE_DEVICE_TABLE(of, max98925_of_match); | ||
638 | |||
639 | static struct i2c_driver max98925_i2c_driver = { | ||
640 | .driver = { | ||
641 | .name = "max98925", | ||
642 | .owner = THIS_MODULE, | ||
643 | .of_match_table = of_match_ptr(max98925_of_match), | ||
644 | .pm = NULL, | ||
645 | }, | ||
646 | .probe = max98925_i2c_probe, | ||
647 | .remove = max98925_i2c_remove, | ||
648 | .id_table = max98925_i2c_id, | ||
649 | }; | ||
650 | |||
651 | module_i2c_driver(max98925_i2c_driver) | ||
652 | |||
653 | MODULE_DESCRIPTION("ALSA SoC MAX98925 driver"); | ||
654 | MODULE_AUTHOR("Ralph Birt <rdbirt@gmail.com>, Anish kumar <anish.kumar@maximintegrated.com>"); | ||
655 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/codecs/max98925.h b/sound/soc/codecs/max98925.h new file mode 100644 index 000000000000..3783248f2780 --- /dev/null +++ b/sound/soc/codecs/max98925.h | |||
@@ -0,0 +1,832 @@ | |||
1 | /* | ||
2 | * max98925.h -- MAX98925 ALSA SoC Audio driver | ||
3 | * | ||
4 | * Copyright 2013-2015 Maxim Integrated Products | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | |||
11 | #ifndef _MAX98925_H | ||
12 | #define _MAX98925_H | ||
13 | |||
14 | #define MAX98925_VERSION 0x51 | ||
15 | #define MAX98925_VERSION1 0x80 | ||
16 | #define MAX98925_VBAT_DATA 0x00 | ||
17 | #define MAX98925_VBST_DATA 0x01 | ||
18 | #define MAX98925_LIVE_STATUS0 0x02 | ||
19 | #define MAX98925_LIVE_STATUS1 0x03 | ||
20 | #define MAX98925_LIVE_STATUS2 0x04 | ||
21 | #define MAX98925_STATE0 0x05 | ||
22 | #define MAX98925_STATE1 0x06 | ||
23 | #define MAX98925_STATE2 0x07 | ||
24 | #define MAX98925_FLAG0 0x08 | ||
25 | #define MAX98925_FLAG1 0x09 | ||
26 | #define MAX98925_FLAG2 0x0A | ||
27 | #define MAX98925_IRQ_ENABLE0 0x0B | ||
28 | #define MAX98925_IRQ_ENABLE1 0x0C | ||
29 | #define MAX98925_IRQ_ENABLE2 0x0D | ||
30 | #define MAX98925_IRQ_CLEAR0 0x0E | ||
31 | #define MAX98925_IRQ_CLEAR1 0x0F | ||
32 | #define MAX98925_IRQ_CLEAR2 0x10 | ||
33 | #define MAX98925_MAP0 0x11 | ||
34 | #define MAX98925_MAP1 0x12 | ||
35 | #define MAX98925_MAP2 0x13 | ||
36 | #define MAX98925_MAP3 0x14 | ||
37 | #define MAX98925_MAP4 0x15 | ||
38 | #define MAX98925_MAP5 0x16 | ||
39 | #define MAX98925_MAP6 0x17 | ||
40 | #define MAX98925_MAP7 0x18 | ||
41 | #define MAX98925_MAP8 0x19 | ||
42 | #define MAX98925_DAI_CLK_MODE1 0x1A | ||
43 | #define MAX98925_DAI_CLK_MODE2 0x1B | ||
44 | #define MAX98925_DAI_CLK_DIV_M_MSBS 0x1C | ||
45 | #define MAX98925_DAI_CLK_DIV_M_LSBS 0x1D | ||
46 | #define MAX98925_DAI_CLK_DIV_N_MSBS 0x1E | ||
47 | #define MAX98925_DAI_CLK_DIV_N_LSBS 0x1F | ||
48 | #define MAX98925_FORMAT 0x20 | ||
49 | #define MAX98925_TDM_SLOT_SELECT 0x21 | ||
50 | #define MAX98925_DOUT_CFG_VMON 0x22 | ||
51 | #define MAX98925_DOUT_CFG_IMON 0x23 | ||
52 | #define MAX98925_DOUT_CFG_VBAT 0x24 | ||
53 | #define MAX98925_DOUT_CFG_VBST 0x25 | ||
54 | #define MAX98925_DOUT_CFG_FLAG 0x26 | ||
55 | #define MAX98925_DOUT_HIZ_CFG1 0x27 | ||
56 | #define MAX98925_DOUT_HIZ_CFG2 0x28 | ||
57 | #define MAX98925_DOUT_HIZ_CFG3 0x29 | ||
58 | #define MAX98925_DOUT_HIZ_CFG4 0x2A | ||
59 | #define MAX98925_DOUT_DRV_STRENGTH 0x2B | ||
60 | #define MAX98925_FILTERS 0x2C | ||
61 | #define MAX98925_GAIN 0x2D | ||
62 | #define MAX98925_GAIN_RAMPING 0x2E | ||
63 | #define MAX98925_SPK_AMP 0x2F | ||
64 | #define MAX98925_THRESHOLD 0x30 | ||
65 | #define MAX98925_ALC_ATTACK 0x31 | ||
66 | #define MAX98925_ALC_ATTEN_RLS 0x32 | ||
67 | #define MAX98925_ALC_HOLD_RLS 0x33 | ||
68 | #define MAX98925_ALC_CONFIGURATION 0x34 | ||
69 | #define MAX98925_BOOST_CONVERTER 0x35 | ||
70 | #define MAX98925_BLOCK_ENABLE 0x36 | ||
71 | #define MAX98925_CONFIGURATION 0x37 | ||
72 | #define MAX98925_GLOBAL_ENABLE 0x38 | ||
73 | #define MAX98925_BOOST_LIMITER 0x3A | ||
74 | #define MAX98925_REV_VERSION 0xFF | ||
75 | |||
76 | #define MAX98925_REG_CNT (MAX98925_R03A_BOOST_LIMITER+1) | ||
77 | |||
78 | /* MAX98925 Register Bit Fields */ | ||
79 | |||
80 | /* MAX98925_R002_LIVE_STATUS0 */ | ||
81 | #define M98925_THERMWARN_STATUS_MASK (1<<3) | ||
82 | #define M98925_THERMWARN_STATUS_SHIFT 3 | ||
83 | #define M98925_THERMWARN_STATUS_WIDTH 1 | ||
84 | #define M98925_THERMSHDN_STATUS_MASK (1<<1) | ||
85 | #define M98925_THERMSHDN_STATUS_SHIFT 1 | ||
86 | #define M98925_THERMSHDN_STATUS_WIDTH 1 | ||
87 | |||
88 | /* MAX98925_R003_LIVE_STATUS1 */ | ||
89 | #define M98925_SPKCURNT_STATUS_MASK (1<<5) | ||
90 | #define M98925_SPKCURNT_STATUS_SHIFT 5 | ||
91 | #define M98925_SPKCURNT_STATUS_WIDTH 1 | ||
92 | #define M98925_WATCHFAIL_STATUS_MASK (1<<4) | ||
93 | #define M98925_WATCHFAIL_STATUS_SHIFT 4 | ||
94 | #define M98925_WATCHFAIL_STATUS_WIDTH 1 | ||
95 | #define M98925_ALCINFH_STATUS_MASK (1<<3) | ||
96 | #define M98925_ALCINFH_STATUS_SHIFT 3 | ||
97 | #define M98925_ALCINFH_STATUS_WIDTH 1 | ||
98 | #define M98925_ALCACT_STATUS_MASK (1<<2) | ||
99 | #define M98925_ALCACT_STATUS_SHIFT 2 | ||
100 | #define M98925_ALCACT_STATUS_WIDTH 1 | ||
101 | #define M98925_ALCMUT_STATUS_MASK (1<<1) | ||
102 | #define M98925_ALCMUT_STATUS_SHIFT 1 | ||
103 | #define M98925_ALCMUT_STATUS_WIDTH 1 | ||
104 | #define M98925_ACLP_STATUS_MASK (1<<0) | ||
105 | #define M98925_ACLP_STATUS_SHIFT 0 | ||
106 | #define M98925_ACLP_STATUS_WIDTH 1 | ||
107 | |||
108 | /* MAX98925_R004_LIVE_STATUS2 */ | ||
109 | #define M98925_SLOTOVRN_STATUS_MASK (1<<6) | ||
110 | #define M98925_SLOTOVRN_STATUS_SHIFT 6 | ||
111 | #define M98925_SLOTOVRN_STATUS_WIDTH 1 | ||
112 | #define M98925_INVALSLOT_STATUS_MASK (1<<5) | ||
113 | #define M98925_INVALSLOT_STATUS_SHIFT 5 | ||
114 | #define M98925_INVALSLOT_STATUS_WIDTH 1 | ||
115 | #define M98925_SLOTCNFLT_STATUS_MASK (1<<4) | ||
116 | #define M98925_SLOTCNFLT_STATUS_SHIFT 4 | ||
117 | #define M98925_SLOTCNFLT_STATUS_WIDTH 1 | ||
118 | #define M98925_VBSTOVFL_STATUS_MASK (1<<3) | ||
119 | #define M98925_VBSTOVFL_STATUS_SHIFT 3 | ||
120 | #define M98925_VBSTOVFL_STATUS_WIDTH 1 | ||
121 | #define M98925_VBATOVFL_STATUS_MASK (1<<2) | ||
122 | #define M98925_VBATOVFL_STATUS_SHIFT 2 | ||
123 | #define M98925_VBATOVFL_STATUS_WIDTH 1 | ||
124 | #define M98925_IMONOVFL_STATUS_MASK (1<<1) | ||
125 | #define M98925_IMONOVFL_STATUS_SHIFT 1 | ||
126 | #define M98925_IMONOVFL_STATUS_WIDTH 1 | ||
127 | #define M98925_VMONOVFL_STATUS_MASK (1<<0) | ||
128 | #define M98925_VMONOVFL_STATUS_SHIFT 0 | ||
129 | #define M98925_VMONOVFL_STATUS_WIDTH 1 | ||
130 | |||
131 | /* MAX98925_R005_STATE0 */ | ||
132 | #define M98925_THERMWARN_END_STATE_MASK (1<<3) | ||
133 | #define M98925_THERMWARN_END_STATE_SHIFT 3 | ||
134 | #define M98925_THERMWARN_END_STATE_WIDTH 1 | ||
135 | #define M98925_THERMWARN_BGN_STATE_MASK (1<<2) | ||
136 | #define M98925_THERMWARN_BGN_STATE_SHIFT 1 | ||
137 | #define M98925_THERMWARN_BGN_STATE_WIDTH 1 | ||
138 | #define M98925_THERMSHDN_END_STATE_MASK (1<<1) | ||
139 | #define M98925_THERMSHDN_END_STATE_SHIFT 1 | ||
140 | #define M98925_THERMSHDN_END_STATE_WIDTH 1 | ||
141 | #define M98925_THERMSHDN_BGN_STATE_MASK (1<<0) | ||
142 | #define M98925_THERMSHDN_BGN_STATE_SHIFT 0 | ||
143 | #define M98925_THERMSHDN_BGN_STATE_WIDTH 1 | ||
144 | |||
145 | /* MAX98925_R006_STATE1 */ | ||
146 | #define M98925_SPRCURNT_STATE_MASK (1<<5) | ||
147 | #define M98925_SPRCURNT_STATE_SHIFT 5 | ||
148 | #define M98925_SPRCURNT_STATE_WIDTH 1 | ||
149 | #define M98925_WATCHFAIL_STATE_MASK (1<<4) | ||
150 | #define M98925_WATCHFAIL_STATE_SHIFT 4 | ||
151 | #define M98925_WATCHFAIL_STATE_WIDTH 1 | ||
152 | #define M98925_ALCINFH_STATE_MASK (1<<3) | ||
153 | #define M98925_ALCINFH_STATE_SHIFT 3 | ||
154 | #define M98925_ALCINFH_STATE_WIDTH 1 | ||
155 | #define M98925_ALCACT_STATE_MASK (1<<2) | ||
156 | #define M98925_ALCACT_STATE_SHIFT 2 | ||
157 | #define M98925_ALCACT_STATE_WIDTH 1 | ||
158 | #define M98925_ALCMUT_STATE_MASK (1<<1) | ||
159 | #define M98925_ALCMUT_STATE_SHIFT 1 | ||
160 | #define M98925_ALCMUT_STATE_WIDTH 1 | ||
161 | #define M98925_ALCP_STATE_MASK (1<<0) | ||
162 | #define M98925_ALCP_STATE_SHIFT 0 | ||
163 | #define M98925_ALCP_STATE_WIDTH 1 | ||
164 | |||
165 | /* MAX98925_R007_STATE2 */ | ||
166 | #define M98925_SLOTOVRN_STATE_MASK (1<<6) | ||
167 | #define M98925_SLOTOVRN_STATE_SHIFT 6 | ||
168 | #define M98925_SLOTOVRN_STATE_WIDTH 1 | ||
169 | #define M98925_INVALSLOT_STATE_MASK (1<<5) | ||
170 | #define M98925_INVALSLOT_STATE_SHIFT 5 | ||
171 | #define M98925_INVALSLOT_STATE_WIDTH 1 | ||
172 | #define M98925_SLOTCNFLT_STATE_MASK (1<<4) | ||
173 | #define M98925_SLOTCNFLT_STATE_SHIFT 4 | ||
174 | #define M98925_SLOTCNFLT_STATE_WIDTH 1 | ||
175 | #define M98925_VBSTOVFL_STATE_MASK (1<<3) | ||
176 | #define M98925_VBSTOVFL_STATE_SHIFT 3 | ||
177 | #define M98925_VBSTOVFL_STATE_WIDTH 1 | ||
178 | #define M98925_VBATOVFL_STATE_MASK (1<<2) | ||
179 | #define M98925_VBATOVFL_STATE_SHIFT 2 | ||
180 | #define M98925_VBATOVFL_STATE_WIDTH 1 | ||
181 | #define M98925_IMONOVFL_STATE_MASK (1<<1) | ||
182 | #define M98925_IMONOVFL_STATE_SHIFT 1 | ||
183 | #define M98925_IMONOVFL_STATE_WIDTH 1 | ||
184 | #define M98925_VMONOVFL_STATE_MASK (1<<0) | ||
185 | #define M98925_VMONOVFL_STATE_SHIFT 0 | ||
186 | #define M98925_VMONOVFL_STATE_WIDTH 1 | ||
187 | |||
188 | /* MAX98925_R008_FLAG0 */ | ||
189 | #define M98925_THERMWARN_END_FLAG_MASK (1<<3) | ||
190 | #define M98925_THERMWARN_END_FLAG_SHIFT 3 | ||
191 | #define M98925_THERMWARN_END_FLAG_WIDTH 1 | ||
192 | #define M98925_THERMWARN_BGN_FLAG_MASK (1<<2) | ||
193 | #define M98925_THERMWARN_BGN_FLAG_SHIFT 2 | ||
194 | #define M98925_THERMWARN_BGN_FLAG_WIDTH 1 | ||
195 | #define M98925_THERMSHDN_END_FLAG_MASK (1<<1) | ||
196 | #define M98925_THERMSHDN_END_FLAG_SHIFT 1 | ||
197 | #define M98925_THERMSHDN_END_FLAG_WIDTH 1 | ||
198 | #define M98925_THERMSHDN_BGN_FLAG_MASK (1<<0) | ||
199 | #define M98925_THERMSHDN_BGN_FLAG_SHIFT 0 | ||
200 | #define M98925_THERMSHDN_BGN_FLAG_WIDTH 1 | ||
201 | |||
202 | /* MAX98925_R009_FLAG1 */ | ||
203 | #define M98925_SPKCURNT_FLAG_MASK (1<<5) | ||
204 | #define M98925_SPKCURNT_FLAG_SHIFT 5 | ||
205 | #define M98925_SPKCURNT_FLAG_WIDTH 1 | ||
206 | #define M98925_WATCHFAIL_FLAG_MASK (1<<4) | ||
207 | #define M98925_WATCHFAIL_FLAG_SHIFT 4 | ||
208 | #define M98925_WATCHFAIL_FLAG_WIDTH 1 | ||
209 | #define M98925_ALCINFH_FLAG_MASK (1<<3) | ||
210 | #define M98925_ALCINFH_FLAG_SHIFT 3 | ||
211 | #define M98925_ALCINFH_FLAG_WIDTH 1 | ||
212 | #define M98925_ALCACT_FLAG_MASK (1<<2) | ||
213 | #define M98925_ALCACT_FLAG_SHIFT 2 | ||
214 | #define M98925_ALCACT_FLAG_WIDTH 1 | ||
215 | #define M98925_ALCMUT_FLAG_MASK (1<<1) | ||
216 | #define M98925_ALCMUT_FLAG_SHIFT 1 | ||
217 | #define M98925_ALCMUT_FLAG_WIDTH 1 | ||
218 | #define M98925_ALCP_FLAG_MASK (1<<0) | ||
219 | #define M98925_ALCP_FLAG_SHIFT 0 | ||
220 | #define M98925_ALCP_FLAG_WIDTH 1 | ||
221 | |||
222 | /* MAX98925_R00A_FLAG2 */ | ||
223 | #define M98925_SLOTOVRN_FLAG_MASK (1<<6) | ||
224 | #define M98925_SLOTOVRN_FLAG_SHIFT 6 | ||
225 | #define M98925_SLOTOVRN_FLAG_WIDTH 1 | ||
226 | #define M98925_INVALSLOT_FLAG_MASK (1<<5) | ||
227 | #define M98925_INVALSLOT_FLAG_SHIFT 5 | ||
228 | #define M98925_INVALSLOT_FLAG_WIDTH 1 | ||
229 | #define M98925_SLOTCNFLT_FLAG_MASK (1<<4) | ||
230 | #define M98925_SLOTCNFLT_FLAG_SHIFT 4 | ||
231 | #define M98925_SLOTCNFLT_FLAG_WIDTH 1 | ||
232 | #define M98925_VBSTOVFL_FLAG_MASK (1<<3) | ||
233 | #define M98925_VBSTOVFL_FLAG_SHIFT 3 | ||
234 | #define M98925_VBSTOVFL_FLAG_WIDTH 1 | ||
235 | #define M98925_VBATOVFL_FLAG_MASK (1<<2) | ||
236 | #define M98925_VBATOVFL_FLAG_SHIFT 2 | ||
237 | #define M98925_VBATOVFL_FLAG_WIDTH 1 | ||
238 | #define M98925_IMONOVFL_FLAG_MASK (1<<1) | ||
239 | #define M98925_IMONOVFL_FLAG_SHIFT 1 | ||
240 | #define M98925_IMONOVFL_FLAG_WIDTH 1 | ||
241 | #define M98925_VMONOVFL_FLAG_MASK (1<<0) | ||
242 | #define M98925_VMONOVFL_FLAG_SHIFT 0 | ||
243 | #define M98925_VMONOVFL_FLAG_WIDTH 1 | ||
244 | |||
245 | /* MAX98925_R00B_IRQ_ENABLE0 */ | ||
246 | #define M98925_THERMWARN_END_EN_MASK (1<<3) | ||
247 | #define M98925_THERMWARN_END_EN_SHIFT 3 | ||
248 | #define M98925_THERMWARN_END_EN_WIDTH 1 | ||
249 | #define M98925_THERMWARN_BGN_EN_MASK (1<<2) | ||
250 | #define M98925_THERMWARN_BGN_EN_SHIFT 2 | ||
251 | #define M98925_THERMWARN_BGN_EN_WIDTH 1 | ||
252 | #define M98925_THERMSHDN_END_EN_MASK (1<<1) | ||
253 | #define M98925_THERMSHDN_END_EN_SHIFT 1 | ||
254 | #define M98925_THERMSHDN_END_EN_WIDTH 1 | ||
255 | #define M98925_THERMSHDN_BGN_EN_MASK (1<<0) | ||
256 | #define M98925_THERMSHDN_BGN_EN_SHIFT 0 | ||
257 | #define M98925_THERMSHDN_BGN_EN_WIDTH 1 | ||
258 | |||
259 | /* MAX98925_R00C_IRQ_ENABLE1 */ | ||
260 | #define M98925_SPKCURNT_EN_MASK (1<<5) | ||
261 | #define M98925_SPKCURNT_EN_SHIFT 5 | ||
262 | #define M98925_SPKCURNT_EN_WIDTH 1 | ||
263 | #define M98925_WATCHFAIL_EN_MASK (1<<4) | ||
264 | #define M98925_WATCHFAIL_EN_SHIFT 4 | ||
265 | #define M98925_WATCHFAIL_EN_WIDTH 1 | ||
266 | #define M98925_ALCINFH_EN_MASK (1<<3) | ||
267 | #define M98925_ALCINFH_EN_SHIFT 3 | ||
268 | #define M98925_ALCINFH_EN_WIDTH 1 | ||
269 | #define M98925_ALCACT_EN_MASK (1<<2) | ||
270 | #define M98925_ALCACT_EN_SHIFT 2 | ||
271 | #define M98925_ALCACT_EN_WIDTH 1 | ||
272 | #define M98925_ALCMUT_EN_MASK (1<<1) | ||
273 | #define M98925_ALCMUT_EN_SHIFT 1 | ||
274 | #define M98925_ALCMUT_EN_WIDTH 1 | ||
275 | #define M98925_ALCP_EN_MASK (1<<0) | ||
276 | #define M98925_ALCP_EN_SHIFT 0 | ||
277 | #define M98925_ALCP_EN_WIDTH 1 | ||
278 | |||
279 | /* MAX98925_R00D_IRQ_ENABLE2 */ | ||
280 | #define M98925_SLOTOVRN_EN_MASK (1<<6) | ||
281 | #define M98925_SLOTOVRN_EN_SHIFT 6 | ||
282 | #define M98925_SLOTOVRN_EN_WIDTH 1 | ||
283 | #define M98925_INVALSLOT_EN_MASK (1<<5) | ||
284 | #define M98925_INVALSLOT_EN_SHIFT 5 | ||
285 | #define M98925_INVALSLOT_EN_WIDTH 1 | ||
286 | #define M98925_SLOTCNFLT_EN_MASK (1<<4) | ||
287 | #define M98925_SLOTCNFLT_EN_SHIFT 4 | ||
288 | #define M98925_SLOTCNFLT_EN_WIDTH 1 | ||
289 | #define M98925_VBSTOVFL_EN_MASK (1<<3) | ||
290 | #define M98925_VBSTOVFL_EN_SHIFT 3 | ||
291 | #define M98925_VBSTOVFL_EN_WIDTH 1 | ||
292 | #define M98925_VBATOVFL_EN_MASK (1<<2) | ||
293 | #define M98925_VBATOVFL_EN_SHIFT 2 | ||
294 | #define M98925_VBATOVFL_EN_WIDTH 1 | ||
295 | #define M98925_IMONOVFL_EN_MASK (1<<1) | ||
296 | #define M98925_IMONOVFL_EN_SHIFT 1 | ||
297 | #define M98925_IMONOVFL_EN_WIDTH 1 | ||
298 | #define M98925_VMONOVFL_EN_MASK (1<<0) | ||
299 | #define M98925_VMONOVFL_EN_SHIFT 0 | ||
300 | #define M98925_VMONOVFL_EN_WIDTH 1 | ||
301 | |||
302 | /* MAX98925_R00E_IRQ_CLEAR0 */ | ||
303 | #define M98925_THERMWARN_END_CLR_MASK (1<<3) | ||
304 | #define M98925_THERMWARN_END_CLR_SHIFT 3 | ||
305 | #define M98925_THERMWARN_END_CLR_WIDTH 1 | ||
306 | #define M98925_THERMWARN_BGN_CLR_MASK (1<<2) | ||
307 | #define M98925_THERMWARN_BGN_CLR_SHIFT 2 | ||
308 | #define M98925_THERMWARN_BGN_CLR_WIDTH 1 | ||
309 | #define M98925_THERMSHDN_END_CLR_MASK (1<<1) | ||
310 | #define M98925_THERMSHDN_END_CLR_SHIFT 1 | ||
311 | #define M98925_THERMSHDN_END_CLR_WIDTH 1 | ||
312 | #define M98925_THERMSHDN_BGN_CLR_MASK (1<<0) | ||
313 | #define M98925_THERMSHDN_BGN_CLR_SHIFT 0 | ||
314 | #define M98925_THERMSHDN_BGN_CLR_WIDTH 1 | ||
315 | |||
316 | /* MAX98925_R00F_IRQ_CLEAR1 */ | ||
317 | #define M98925_SPKCURNT_CLR_MASK (1<<5) | ||
318 | #define M98925_SPKCURNT_CLR_SHIFT 5 | ||
319 | #define M98925_SPKCURNT_CLR_WIDTH 1 | ||
320 | #define M98925_WATCHFAIL_CLR_MASK (1<<4) | ||
321 | #define M98925_WATCHFAIL_CLR_SHIFT 4 | ||
322 | #define M98925_WATCHFAIL_CLR_WIDTH 1 | ||
323 | #define M98925_ALCINFH_CLR_MASK (1<<3) | ||
324 | #define M98925_ALCINFH_CLR_SHIFT 3 | ||
325 | #define M98925_ALCINFH_CLR_WIDTH 1 | ||
326 | #define M98925_ALCACT_CLR_MASK (1<<2) | ||
327 | #define M98925_ALCACT_CLR_SHIFT 2 | ||
328 | #define M98925_ALCACT_CLR_WIDTH 1 | ||
329 | #define M98925_ALCMUT_CLR_MASK (1<<1) | ||
330 | #define M98925_ALCMUT_CLR_SHIFT 1 | ||
331 | #define M98925_ALCMUT_CLR_WIDTH 1 | ||
332 | #define M98925_ALCP_CLR_MASK (1<<0) | ||
333 | #define M98925_ALCP_CLR_SHIFT 0 | ||
334 | #define M98925_ALCP_CLR_WIDTH 1 | ||
335 | |||
336 | /* MAX98925_R010_IRQ_CLEAR2 */ | ||
337 | #define M98925_SLOTOVRN_CLR_MASK (1<<6) | ||
338 | #define M98925_SLOTOVRN_CLR_SHIFT 6 | ||
339 | #define M98925_SLOTOVRN_CLR_WIDTH 1 | ||
340 | #define M98925_INVALSLOT_CLR_MASK (1<<5) | ||
341 | #define M98925_INVALSLOT_CLR_SHIFT 5 | ||
342 | #define M98925_INVALSLOT_CLR_WIDTH 1 | ||
343 | #define M98925_SLOTCNFLT_CLR_MASK (1<<4) | ||
344 | #define M98925_SLOTCNFLT_CLR_SHIFT 4 | ||
345 | #define M98925_SLOTCNFLT_CLR_WIDTH 1 | ||
346 | #define M98925_VBSTOVFL_CLR_MASK (1<<3) | ||
347 | #define M98925_VBSTOVFL_CLR_SHIFT 3 | ||
348 | #define M98925_VBSTOVFL_CLR_WIDTH 1 | ||
349 | #define M98925_VBATOVFL_CLR_MASK (1<<2) | ||
350 | #define M98925_VBATOVFL_CLR_SHIFT 2 | ||
351 | #define M98925_VBATOVFL_CLR_WIDTH 1 | ||
352 | #define M98925_IMONOVFL_CLR_MASK (1<<1) | ||
353 | #define M98925_IMONOVFL_CLR_SHIFT 1 | ||
354 | #define M98925_IMONOVFL_CLR_WIDTH 1 | ||
355 | #define M98925_VMONOVFL_CLR_MASK (1<<0) | ||
356 | #define M98925_VMONOVFL_CLR_SHIFT 0 | ||
357 | #define M98925_VMONOVFL_CLR_WIDTH 1 | ||
358 | |||
359 | /* MAX98925_R011_MAP0 */ | ||
360 | #define M98925_ER_THERMWARN_EN_MASK (1<<7) | ||
361 | #define M98925_ER_THERMWARN_EN_SHIFT 7 | ||
362 | #define M98925_ER_THERMWARN_EN_WIDTH 1 | ||
363 | #define M98925_ER_THERMWARN_MAP_MASK (0x07<<4) | ||
364 | #define M98925_ER_THERMWARN_MAP_SHIFT 4 | ||
365 | #define M98925_ER_THERMWARN_MAP_WIDTH 3 | ||
366 | |||
367 | /* MAX98925_R012_MAP1 */ | ||
368 | #define M98925_ER_ALCMUT_EN_MASK (1<<7) | ||
369 | #define M98925_ER_ALCMUT_EN_SHIFT 7 | ||
370 | #define M98925_ER_ALCMUT_EN_WIDTH 1 | ||
371 | #define M98925_ER_ALCMUT_MAP_MASK (0x07<<4) | ||
372 | #define M98925_ER_ALCMUT_MAP_SHIFT 4 | ||
373 | #define M98925_ER_ALCMUT_MAP_WIDTH 3 | ||
374 | #define M98925_ER_ALCP_EN_MASK (1<<3) | ||
375 | #define M98925_ER_ALCP_EN_SHIFT 3 | ||
376 | #define M98925_ER_ALCP_EN_WIDTH 1 | ||
377 | #define M98925_ER_ALCP_MAP_MASK (0x07<<0) | ||
378 | #define M98925_ER_ALCP_MAP_SHIFT 0 | ||
379 | #define M98925_ER_ALCP_MAP_WIDTH 3 | ||
380 | |||
381 | /* MAX98925_R013_MAP2 */ | ||
382 | #define M98925_ER_ALCINFH_EN_MASK (1<<7) | ||
383 | #define M98925_ER_ALCINFH_EN_SHIFT 7 | ||
384 | #define M98925_ER_ALCINFH_EN_WIDTH 1 | ||
385 | #define M98925_ER_ALCINFH_MAP_MASK (0x07<<4) | ||
386 | #define M98925_ER_ALCINFH_MAP_SHIFT 4 | ||
387 | #define M98925_ER_ALCINFH_MAP_WIDTH 3 | ||
388 | #define M98925_ER_ALCACT_EN_MASK (1<<3) | ||
389 | #define M98925_ER_ALCACT_EN_SHIFT 3 | ||
390 | #define M98925_ER_ALCACT_EN_WIDTH 1 | ||
391 | #define M98925_ER_ALCACT_MAP_MASK (0x07<<0) | ||
392 | #define M98925_ER_ALCACT_MAP_SHIFT 0 | ||
393 | #define M98925_ER_ALCACT_MAP_WIDTH 3 | ||
394 | |||
395 | /* MAX98925_R014_MAP3 */ | ||
396 | #define M98925_ER_SPKCURNT_EN_MASK (1<<7) | ||
397 | #define M98925_ER_SPKCURNT_EN_SHIFT 7 | ||
398 | #define M98925_ER_SPKCURNT_EN_WIDTH 1 | ||
399 | #define M98925_ER_SPKCURNT_MAP_MASK (0x07<<4) | ||
400 | #define M98925_ER_SPKCURNT_MAP_SHIFT 4 | ||
401 | #define M98925_ER_SPKCURNT_MAP_WIDTH 3 | ||
402 | |||
403 | /* MAX98925_R015_MAP4 */ | ||
404 | /* RESERVED */ | ||
405 | |||
406 | /* MAX98925_R016_MAP5 */ | ||
407 | #define M98925_ER_IMONOVFL_EN_MASK (1<<7) | ||
408 | #define M98925_ER_IMONOVFL_EN_SHIFT 7 | ||
409 | #define M98925_ER_IMONOVFL_EN_WIDTH 1 | ||
410 | #define M98925_ER_IMONOVFL_MAP_MASK (0x07<<4) | ||
411 | #define M98925_ER_IMONOVFL_MAP_SHIFT 4 | ||
412 | #define M98925_ER_IMONOVFL_MAP_WIDTH 3 | ||
413 | #define M98925_ER_VMONOVFL_EN_MASK (1<<3) | ||
414 | #define M98925_ER_VMONOVFL_EN_SHIFT 3 | ||
415 | #define M98925_ER_VMONOVFL_EN_WIDTH 1 | ||
416 | #define M98925_ER_VMONOVFL_MAP_MASK (0x07<<0) | ||
417 | #define M98925_ER_VMONOVFL_MAP_SHIFT 0 | ||
418 | #define M98925_ER_VMONOVFL_MAP_WIDTH 3 | ||
419 | |||
420 | /* MAX98925_R017_MAP6 */ | ||
421 | #define M98925_ER_VBSTOVFL_EN_MASK (1<<7) | ||
422 | #define M98925_ER_VBSTOVFL_EN_SHIFT 7 | ||
423 | #define M98925_ER_VBSTOVFL_EN_WIDTH 1 | ||
424 | #define M98925_ER_VBSTOVFL_MAP_MASK (0x07<<4) | ||
425 | #define M98925_ER_VBSTOVFL_MAP_SHIFT 4 | ||
426 | #define M98925_ER_VBSTOVFL_MAP_WIDTH 3 | ||
427 | #define M98925_ER_VBATOVFL_EN_MASK (1<<3) | ||
428 | #define M98925_ER_VBATOVFL_EN_SHIFT 3 | ||
429 | #define M98925_ER_VBATOVFL_EN_WIDTH 1 | ||
430 | #define M98925_ER_VBATOVFL_MAP_MASK (0x07<<0) | ||
431 | #define M98925_ER_VBATOVFL_MAP_SHIFT 0 | ||
432 | #define M98925_ER_VBATOVFL_MAP_WIDTH 3 | ||
433 | |||
434 | /* MAX98925_R018_MAP7 */ | ||
435 | #define M98925_ER_INVALSLOT_EN_MASK (1<<7) | ||
436 | #define M98925_ER_INVALSLOT_EN_SHIFT 7 | ||
437 | #define M98925_ER_INVALSLOT_EN_WIDTH 1 | ||
438 | #define M98925_ER_INVALSLOT_MAP_MASK (0x07<<4) | ||
439 | #define M98925_ER_INVALSLOT_MAP_SHIFT 4 | ||
440 | #define M98925_ER_INVALSLOT_MAP_WIDTH 3 | ||
441 | #define M98925_ER_SLOTCNFLT_EN_MASK (1<<3) | ||
442 | #define M98925_ER_SLOTCNFLT_EN_SHIFT 3 | ||
443 | #define M98925_ER_SLOTCNFLT_EN_WIDTH 1 | ||
444 | #define M98925_ER_SLOTCNFLT_MAP_MASK (0x07<<0) | ||
445 | #define M98925_ER_SLOTCNFLT_MAP_SHIFT 0 | ||
446 | #define M98925_ER_SLOTCNFLT_MAP_WIDTH 3 | ||
447 | |||
448 | /* MAX98925_R019_MAP8 */ | ||
449 | #define M98925_ER_SLOTOVRN_EN_MASK (1<<3) | ||
450 | #define M98925_ER_SLOTOVRN_EN_SHIFT 3 | ||
451 | #define M98925_ER_SLOTOVRN_EN_WIDTH 1 | ||
452 | #define M98925_ER_SLOTOVRN_MAP_MASK (0x07<<0) | ||
453 | #define M98925_ER_SLOTOVRN_MAP_SHIFT 0 | ||
454 | #define M98925_ER_SLOTOVRN_MAP_WIDTH 3 | ||
455 | |||
456 | /* MAX98925_R01A_DAI_CLK_MODE1 */ | ||
457 | #define M98925_DAI_CLK_SOURCE_MASK (1<<6) | ||
458 | #define M98925_DAI_CLK_SOURCE_SHIFT 6 | ||
459 | #define M98925_DAI_CLK_SOURCE_WIDTH 1 | ||
460 | #define M98925_MDLL_MULT_MASK (0x0F<<0) | ||
461 | #define M98925_MDLL_MULT_SHIFT 0 | ||
462 | #define M98925_MDLL_MULT_WIDTH 4 | ||
463 | |||
464 | #define M98925_MDLL_MULT_MCLKx8 6 | ||
465 | #define M98925_MDLL_MULT_MCLKx16 8 | ||
466 | |||
467 | /* MAX98925_R01B_DAI_CLK_MODE2 */ | ||
468 | #define M98925_DAI_SR_MASK (0x0F<<4) | ||
469 | #define M98925_DAI_SR_SHIFT 4 | ||
470 | #define M98925_DAI_SR_WIDTH 4 | ||
471 | #define M98925_DAI_MAS_MASK (1<<3) | ||
472 | #define M98925_DAI_MAS_SHIFT 3 | ||
473 | #define M98925_DAI_MAS_WIDTH 1 | ||
474 | #define M98925_DAI_BSEL_MASK (0x07<<0) | ||
475 | #define M98925_DAI_BSEL_SHIFT 0 | ||
476 | #define M98925_DAI_BSEL_WIDTH 3 | ||
477 | |||
478 | #define M98925_DAI_BSEL_32 (0 << M98925_DAI_BSEL_SHIFT) | ||
479 | #define M98925_DAI_BSEL_48 (1 << M98925_DAI_BSEL_SHIFT) | ||
480 | #define M98925_DAI_BSEL_64 (2 << M98925_DAI_BSEL_SHIFT) | ||
481 | #define M98925_DAI_BSEL_256 (6 << M98925_DAI_BSEL_SHIFT) | ||
482 | |||
483 | /* MAX98925_R01C_DAI_CLK_DIV_M_MSBS */ | ||
484 | #define M98925_DAI_M_MSBS_MASK (0xFF<<0) | ||
485 | #define M98925_DAI_M_MSBS_SHIFT 0 | ||
486 | #define M98925_DAI_M_MSBS_WIDTH 8 | ||
487 | |||
488 | /* MAX98925_R01D_DAI_CLK_DIV_M_LSBS */ | ||
489 | #define M98925_DAI_M_LSBS_MASK (0xFF<<0) | ||
490 | #define M98925_DAI_M_LSBS_SHIFT 0 | ||
491 | #define M98925_DAI_M_LSBS_WIDTH 8 | ||
492 | |||
493 | /* MAX98925_R01E_DAI_CLK_DIV_N_MSBS */ | ||
494 | #define M98925_DAI_N_MSBS_MASK (0x7F<<0) | ||
495 | #define M98925_DAI_N_MSBS_SHIFT 0 | ||
496 | #define M98925_DAI_N_MSBS_WIDTH 7 | ||
497 | |||
498 | /* MAX98925_R01F_DAI_CLK_DIV_N_LSBS */ | ||
499 | #define M98925_DAI_N_LSBS_MASK (0xFF<<0) | ||
500 | #define M98925_DAI_N_LSBS_SHIFT 0 | ||
501 | #define M98925_DAI_N_LSBS_WIDTH 8 | ||
502 | |||
503 | /* MAX98925_R020_FORMAT */ | ||
504 | #define M98925_DAI_CHANSZ_MASK (0x03<<6) | ||
505 | #define M98925_DAI_CHANSZ_SHIFT 6 | ||
506 | #define M98925_DAI_CHANSZ_WIDTH 2 | ||
507 | #define M98925_DAI_EXTBCLK_HIZ_MASK (1<<4) | ||
508 | #define M98925_DAI_EXTBCLK_HIZ_SHIFT 4 | ||
509 | #define M98925_DAI_EXTBCLK_HIZ_WIDTH 1 | ||
510 | #define M98925_DAI_WCI_MASK (1<<3) | ||
511 | #define M98925_DAI_WCI_SHIFT 3 | ||
512 | #define M98925_DAI_WCI_WIDTH 1 | ||
513 | #define M98925_DAI_BCI_MASK (1<<2) | ||
514 | #define M98925_DAI_BCI_SHIFT 2 | ||
515 | #define M98925_DAI_BCI_WIDTH 1 | ||
516 | #define M98925_DAI_DLY_MASK (1<<1) | ||
517 | #define M98925_DAI_DLY_SHIFT 1 | ||
518 | #define M98925_DAI_DLY_WIDTH 1 | ||
519 | #define M98925_DAI_TDM_MASK (1<<0) | ||
520 | #define M98925_DAI_TDM_SHIFT 0 | ||
521 | #define M98925_DAI_TDM_WIDTH 1 | ||
522 | |||
523 | #define M98925_DAI_CHANSZ_16 (1 << M98925_DAI_CHANSZ_SHIFT) | ||
524 | #define M98925_DAI_CHANSZ_24 (2 << M98925_DAI_CHANSZ_SHIFT) | ||
525 | #define M98925_DAI_CHANSZ_32 (3 << M98925_DAI_CHANSZ_SHIFT) | ||
526 | |||
527 | /* MAX98925_R021_TDM_SLOT_SELECT */ | ||
528 | #define M98925_DAI_DO_EN_MASK (1<<7) | ||
529 | #define M98925_DAI_DO_EN_SHIFT 7 | ||
530 | #define M98925_DAI_DO_EN_WIDTH 1 | ||
531 | #define M98925_DAI_DIN_EN_MASK (1<<6) | ||
532 | #define M98925_DAI_DIN_EN_SHIFT 6 | ||
533 | #define M98925_DAI_DIN_EN_WIDTH 1 | ||
534 | #define M98925_DAI_INR_SOURCE_MASK (0x07<<3) | ||
535 | #define M98925_DAI_INR_SOURCE_SHIFT 3 | ||
536 | #define M98925_DAI_INR_SOURCE_WIDTH 3 | ||
537 | #define M98925_DAI_INL_SOURCE_MASK (0x07<<0) | ||
538 | #define M98925_DAI_INL_SOURCE_SHIFT 0 | ||
539 | #define M98925_DAI_INL_SOURCE_WIDTH 3 | ||
540 | |||
541 | /* MAX98925_R022_DOUT_CFG_VMON */ | ||
542 | #define M98925_DAI_VMON_EN_MASK (1<<5) | ||
543 | #define M98925_DAI_VMON_EN_SHIFT 5 | ||
544 | #define M98925_DAI_VMON_EN_WIDTH 1 | ||
545 | #define M98925_DAI_VMON_SLOT_MASK (0x1F<<0) | ||
546 | #define M98925_DAI_VMON_SLOT_SHIFT 0 | ||
547 | #define M98925_DAI_VMON_SLOT_WIDTH 5 | ||
548 | |||
549 | #define M98925_DAI_VMON_SLOT_00_01 (0 << M98925_DAI_VMON_SLOT_SHIFT) | ||
550 | #define M98925_DAI_VMON_SLOT_01_02 (1 << M98925_DAI_VMON_SLOT_SHIFT) | ||
551 | #define M98925_DAI_VMON_SLOT_02_03 (2 << M98925_DAI_VMON_SLOT_SHIFT) | ||
552 | #define M98925_DAI_VMON_SLOT_03_04 (3 << M98925_DAI_VMON_SLOT_SHIFT) | ||
553 | #define M98925_DAI_VMON_SLOT_04_05 (4 << M98925_DAI_VMON_SLOT_SHIFT) | ||
554 | #define M98925_DAI_VMON_SLOT_05_06 (5 << M98925_DAI_VMON_SLOT_SHIFT) | ||
555 | #define M98925_DAI_VMON_SLOT_06_07 (6 << M98925_DAI_VMON_SLOT_SHIFT) | ||
556 | #define M98925_DAI_VMON_SLOT_07_08 (7 << M98925_DAI_VMON_SLOT_SHIFT) | ||
557 | #define M98925_DAI_VMON_SLOT_08_09 (8 << M98925_DAI_VMON_SLOT_SHIFT) | ||
558 | #define M98925_DAI_VMON_SLOT_09_0A (9 << M98925_DAI_VMON_SLOT_SHIFT) | ||
559 | #define M98925_DAI_VMON_SLOT_0A_0B (10 << M98925_DAI_VMON_SLOT_SHIFT) | ||
560 | #define M98925_DAI_VMON_SLOT_0B_0C (11 << M98925_DAI_VMON_SLOT_SHIFT) | ||
561 | #define M98925_DAI_VMON_SLOT_0C_0D (12 << M98925_DAI_VMON_SLOT_SHIFT) | ||
562 | #define M98925_DAI_VMON_SLOT_0D_0E (13 << M98925_DAI_VMON_SLOT_SHIFT) | ||
563 | #define M98925_DAI_VMON_SLOT_0E_0F (14 << M98925_DAI_VMON_SLOT_SHIFT) | ||
564 | #define M98925_DAI_VMON_SLOT_0F_10 (15 << M98925_DAI_VMON_SLOT_SHIFT) | ||
565 | #define M98925_DAI_VMON_SLOT_10_11 (16 << M98925_DAI_VMON_SLOT_SHIFT) | ||
566 | #define M98925_DAI_VMON_SLOT_11_12 (17 << M98925_DAI_VMON_SLOT_SHIFT) | ||
567 | #define M98925_DAI_VMON_SLOT_12_13 (18 << M98925_DAI_VMON_SLOT_SHIFT) | ||
568 | #define M98925_DAI_VMON_SLOT_13_14 (19 << M98925_DAI_VMON_SLOT_SHIFT) | ||
569 | #define M98925_DAI_VMON_SLOT_14_15 (20 << M98925_DAI_VMON_SLOT_SHIFT) | ||
570 | #define M98925_DAI_VMON_SLOT_15_16 (21 << M98925_DAI_VMON_SLOT_SHIFT) | ||
571 | #define M98925_DAI_VMON_SLOT_16_17 (22 << M98925_DAI_VMON_SLOT_SHIFT) | ||
572 | #define M98925_DAI_VMON_SLOT_17_18 (23 << M98925_DAI_VMON_SLOT_SHIFT) | ||
573 | #define M98925_DAI_VMON_SLOT_18_19 (24 << M98925_DAI_VMON_SLOT_SHIFT) | ||
574 | #define M98925_DAI_VMON_SLOT_19_1A (25 << M98925_DAI_VMON_SLOT_SHIFT) | ||
575 | #define M98925_DAI_VMON_SLOT_1A_1B (26 << M98925_DAI_VMON_SLOT_SHIFT) | ||
576 | #define M98925_DAI_VMON_SLOT_1B_1C (27 << M98925_DAI_VMON_SLOT_SHIFT) | ||
577 | #define M98925_DAI_VMON_SLOT_1C_1D (28 << M98925_DAI_VMON_SLOT_SHIFT) | ||
578 | #define M98925_DAI_VMON_SLOT_1D_1E (29 << M98925_DAI_VMON_SLOT_SHIFT) | ||
579 | #define M98925_DAI_VMON_SLOT_1E_1F (30 << M98925_DAI_VMON_SLOT_SHIFT) | ||
580 | |||
581 | /* MAX98925_R023_DOUT_CFG_IMON */ | ||
582 | #define M98925_DAI_IMON_EN_MASK (1<<5) | ||
583 | #define M98925_DAI_IMON_EN_SHIFT 5 | ||
584 | #define M98925_DAI_IMON_EN_WIDTH 1 | ||
585 | #define M98925_DAI_IMON_SLOT_MASK (0x1F<<0) | ||
586 | #define M98925_DAI_IMON_SLOT_SHIFT 0 | ||
587 | #define M98925_DAI_IMON_SLOT_WIDTH 5 | ||
588 | |||
589 | #define M98925_DAI_IMON_SLOT_00_01 (0 << M98925_DAI_IMON_SLOT_SHIFT) | ||
590 | #define M98925_DAI_IMON_SLOT_01_02 (1 << M98925_DAI_IMON_SLOT_SHIFT) | ||
591 | #define M98925_DAI_IMON_SLOT_02_03 (2 << M98925_DAI_IMON_SLOT_SHIFT) | ||
592 | #define M98925_DAI_IMON_SLOT_03_04 (3 << M98925_DAI_IMON_SLOT_SHIFT) | ||
593 | #define M98925_DAI_IMON_SLOT_04_05 (4 << M98925_DAI_IMON_SLOT_SHIFT) | ||
594 | #define M98925_DAI_IMON_SLOT_05_06 (5 << M98925_DAI_IMON_SLOT_SHIFT) | ||
595 | #define M98925_DAI_IMON_SLOT_06_07 (6 << M98925_DAI_IMON_SLOT_SHIFT) | ||
596 | #define M98925_DAI_IMON_SLOT_07_08 (7 << M98925_DAI_IMON_SLOT_SHIFT) | ||
597 | #define M98925_DAI_IMON_SLOT_08_09 (8 << M98925_DAI_IMON_SLOT_SHIFT) | ||
598 | #define M98925_DAI_IMON_SLOT_09_0A (9 << M98925_DAI_IMON_SLOT_SHIFT) | ||
599 | #define M98925_DAI_IMON_SLOT_0A_0B (10 << M98925_DAI_IMON_SLOT_SHIFT) | ||
600 | #define M98925_DAI_IMON_SLOT_0B_0C (11 << M98925_DAI_IMON_SLOT_SHIFT) | ||
601 | #define M98925_DAI_IMON_SLOT_0C_0D (12 << M98925_DAI_IMON_SLOT_SHIFT) | ||
602 | #define M98925_DAI_IMON_SLOT_0D_0E (13 << M98925_DAI_IMON_SLOT_SHIFT) | ||
603 | #define M98925_DAI_IMON_SLOT_0E_0F (14 << M98925_DAI_IMON_SLOT_SHIFT) | ||
604 | #define M98925_DAI_IMON_SLOT_0F_10 (15 << M98925_DAI_IMON_SLOT_SHIFT) | ||
605 | #define M98925_DAI_IMON_SLOT_10_11 (16 << M98925_DAI_IMON_SLOT_SHIFT) | ||
606 | #define M98925_DAI_IMON_SLOT_11_12 (17 << M98925_DAI_IMON_SLOT_SHIFT) | ||
607 | #define M98925_DAI_IMON_SLOT_12_13 (18 << M98925_DAI_IMON_SLOT_SHIFT) | ||
608 | #define M98925_DAI_IMON_SLOT_13_14 (19 << M98925_DAI_IMON_SLOT_SHIFT) | ||
609 | #define M98925_DAI_IMON_SLOT_14_15 (20 << M98925_DAI_IMON_SLOT_SHIFT) | ||
610 | #define M98925_DAI_IMON_SLOT_15_16 (21 << M98925_DAI_IMON_SLOT_SHIFT) | ||
611 | #define M98925_DAI_IMON_SLOT_16_17 (22 << M98925_DAI_IMON_SLOT_SHIFT) | ||
612 | #define M98925_DAI_IMON_SLOT_17_18 (23 << M98925_DAI_IMON_SLOT_SHIFT) | ||
613 | #define M98925_DAI_IMON_SLOT_18_19 (24 << M98925_DAI_IMON_SLOT_SHIFT) | ||
614 | #define M98925_DAI_IMON_SLOT_19_1A (25 << M98925_DAI_IMON_SLOT_SHIFT) | ||
615 | #define M98925_DAI_IMON_SLOT_1A_1B (26 << M98925_DAI_IMON_SLOT_SHIFT) | ||
616 | #define M98925_DAI_IMON_SLOT_1B_1C (27 << M98925_DAI_IMON_SLOT_SHIFT) | ||
617 | #define M98925_DAI_IMON_SLOT_1C_1D (28 << M98925_DAI_IMON_SLOT_SHIFT) | ||
618 | #define M98925_DAI_IMON_SLOT_1D_1E (29 << M98925_DAI_IMON_SLOT_SHIFT) | ||
619 | #define M98925_DAI_IMON_SLOT_1E_1F (30 << M98925_DAI_IMON_SLOT_SHIFT) | ||
620 | |||
621 | /* MAX98925_R024_DOUT_CFG_VBAT */ | ||
622 | #define M98925_DAI_VBAT_EN_MASK (1<<5) | ||
623 | #define M98925_DAI_VBAT_EN_SHIFT 5 | ||
624 | #define M98925_DAI_VBAT_EN_WIDTH 1 | ||
625 | #define M98925_DAI_VBAT_SLOT_MASK (0x1F<<0) | ||
626 | #define M98925_DAI_VBAT_SLOT_SHIFT 0 | ||
627 | #define M98925_DAI_VBAT_SLOT_WIDTH 5 | ||
628 | |||
629 | /* MAX98925_R025_DOUT_CFG_VBST */ | ||
630 | #define M98925_DAI_VBST_EN_MASK (1<<5) | ||
631 | #define M98925_DAI_VBST_EN_SHIFT 5 | ||
632 | #define M98925_DAI_VBST_EN_WIDTH 1 | ||
633 | #define M98925_DAI_VBST_SLOT_MASK (0x1F<<0) | ||
634 | #define M98925_DAI_VBST_SLOT_SHIFT 0 | ||
635 | #define M98925_DAI_VBST_SLOT_WIDTH 5 | ||
636 | |||
637 | /* MAX98925_R026_DOUT_CFG_FLAG */ | ||
638 | #define M98925_DAI_FLAG_EN_MASK (1<<5) | ||
639 | #define M98925_DAI_FLAG_EN_SHIFT 5 | ||
640 | #define M98925_DAI_FLAG_EN_WIDTH 1 | ||
641 | #define M98925_DAI_FLAG_SLOT_MASK (0x1F<<0) | ||
642 | #define M98925_DAI_FLAG_SLOT_SHIFT 0 | ||
643 | #define M98925_DAI_FLAG_SLOT_WIDTH 5 | ||
644 | |||
645 | /* MAX98925_R027_DOUT_HIZ_CFG1 */ | ||
646 | #define M98925_DAI_SLOT_HIZ_CFG1_MASK (0xFF<<0) | ||
647 | #define M98925_DAI_SLOT_HIZ_CFG1_SHIFT 0 | ||
648 | #define M98925_DAI_SLOT_HIZ_CFG1_WIDTH 8 | ||
649 | |||
650 | /* MAX98925_R028_DOUT_HIZ_CFG2 */ | ||
651 | #define M98925_DAI_SLOT_HIZ_CFG2_MASK (0xFF<<0) | ||
652 | #define M98925_DAI_SLOT_HIZ_CFG2_SHIFT 0 | ||
653 | #define M98925_DAI_SLOT_HIZ_CFG2_WIDTH 8 | ||
654 | |||
655 | /* MAX98925_R029_DOUT_HIZ_CFG3 */ | ||
656 | #define M98925_DAI_SLOT_HIZ_CFG3_MASK (0xFF<<0) | ||
657 | #define M98925_DAI_SLOT_HIZ_CFG3_SHIFT 0 | ||
658 | #define M98925_DAI_SLOT_HIZ_CFG3_WIDTH 8 | ||
659 | |||
660 | /* MAX98925_R02A_DOUT_HIZ_CFG4 */ | ||
661 | #define M98925_DAI_SLOT_HIZ_CFG4_MASK (0xFF<<0) | ||
662 | #define M98925_DAI_SLOT_HIZ_CFG4_SHIFT 0 | ||
663 | #define M98925_DAI_SLOT_HIZ_CFG4_WIDTH 8 | ||
664 | |||
665 | /* MAX98925_R02B_DOUT_DRV_STRENGTH */ | ||
666 | #define M98925_DAI_OUT_DRIVE_MASK (0x03<<0) | ||
667 | #define M98925_DAI_OUT_DRIVE_SHIFT 0 | ||
668 | #define M98925_DAI_OUT_DRIVE_WIDTH 2 | ||
669 | |||
670 | /* MAX98925_R02C_FILTERS */ | ||
671 | #define M98925_ADC_DITHER_EN_MASK (1<<7) | ||
672 | #define M98925_ADC_DITHER_EN_SHIFT 7 | ||
673 | #define M98925_ADC_DITHER_EN_WIDTH 1 | ||
674 | #define M98925_IV_DCB_EN_MASK (1<<6) | ||
675 | #define M98925_IV_DCB_EN_SHIFT 6 | ||
676 | #define M98925_IV_DCB_EN_WIDTH 1 | ||
677 | #define M98925_DAC_DITHER_EN_MASK (1<<4) | ||
678 | #define M98925_DAC_DITHER_EN_SHIFT 4 | ||
679 | #define M98925_DAC_DITHER_EN_WIDTH 1 | ||
680 | #define M98925_DAC_FILTER_MODE_MASK (1<<3) | ||
681 | #define M98925_DAC_FILTER_MODE_SHIFT 3 | ||
682 | #define M98925_DAC_FILTER_MODE_WIDTH 1 | ||
683 | #define M98925_DAC_HPF_MASK (0x07<<0) | ||
684 | #define M98925_DAC_HPF_SHIFT 0 | ||
685 | #define M98925_DAC_HPF_WIDTH 3 | ||
686 | #define M98925_DAC_HPF_DISABLE (0 << M98925_DAC_HPF_SHIFT) | ||
687 | #define M98925_DAC_HPF_DC_BLOCK (1 << M98925_DAC_HPF_SHIFT) | ||
688 | #define M98925_DAC_HPF_EN_100 (2 << M98925_DAC_HPF_SHIFT) | ||
689 | #define M98925_DAC_HPF_EN_200 (3 << M98925_DAC_HPF_SHIFT) | ||
690 | #define M98925_DAC_HPF_EN_400 (4 << M98925_DAC_HPF_SHIFT) | ||
691 | #define M98925_DAC_HPF_EN_800 (5 << M98925_DAC_HPF_SHIFT) | ||
692 | |||
693 | /* MAX98925_R02D_GAIN */ | ||
694 | #define M98925_DAC_IN_SEL_MASK (0x03<<5) | ||
695 | #define M98925_DAC_IN_SEL_SHIFT 5 | ||
696 | #define M98925_DAC_IN_SEL_WIDTH 2 | ||
697 | #define M98925_SPK_GAIN_MASK (0x1F<<0) | ||
698 | #define M98925_SPK_GAIN_SHIFT 0 | ||
699 | #define M98925_SPK_GAIN_WIDTH 5 | ||
700 | |||
701 | #define M98925_DAC_IN_SEL_LEFT_DAI (0 << M98925_DAC_IN_SEL_SHIFT) | ||
702 | #define M98925_DAC_IN_SEL_RIGHT_DAI (1 << M98925_DAC_IN_SEL_SHIFT) | ||
703 | #define M98925_DAC_IN_SEL_SUMMED_DAI (2 << M98925_DAC_IN_SEL_SHIFT) | ||
704 | #define M98925_DAC_IN_SEL_DIV2_SUMMED_DAI (3 << M98925_DAC_IN_SEL_SHIFT) | ||
705 | |||
706 | /* MAX98925_R02E_GAIN_RAMPING */ | ||
707 | #define M98925_SPK_RMP_EN_MASK (1<<1) | ||
708 | #define M98925_SPK_RMP_EN_SHIFT 1 | ||
709 | #define M98925_SPK_RMP_EN_WIDTH 1 | ||
710 | #define M98925_SPK_ZCD_EN_MASK (1<<0) | ||
711 | #define M98925_SPK_ZCD_EN_SHIFT 0 | ||
712 | #define M98925_SPK_ZCD_EN_WIDTH 1 | ||
713 | |||
714 | /* MAX98925_R02F_SPK_AMP */ | ||
715 | #define M98925_SPK_MODE_MASK (1<<0) | ||
716 | #define M98925_SPK_MODE_SHIFT 0 | ||
717 | #define M98925_SPK_MODE_WIDTH 1 | ||
718 | |||
719 | /* MAX98925_R030_THRESHOLD */ | ||
720 | #define M98925_ALC_EN_MASK (1<<5) | ||
721 | #define M98925_ALC_EN_SHIFT 5 | ||
722 | #define M98925_ALC_EN_WIDTH 1 | ||
723 | #define M98925_ALC_TH_MASK (0x1F<<0) | ||
724 | #define M98925_ALC_TH_SHIFT 0 | ||
725 | #define M98925_ALC_TH_WIDTH 5 | ||
726 | |||
727 | /* MAX98925_R031_ALC_ATTACK */ | ||
728 | #define M98925_ALC_ATK_STEP_MASK (0x0F<<4) | ||
729 | #define M98925_ALC_ATK_STEP_SHIFT 4 | ||
730 | #define M98925_ALC_ATK_STEP_WIDTH 4 | ||
731 | #define M98925_ALC_ATK_RATE_MASK (0x7<<0) | ||
732 | #define M98925_ALC_ATK_RATE_SHIFT 0 | ||
733 | #define M98925_ALC_ATK_RATE_WIDTH 3 | ||
734 | |||
735 | /* MAX98925_R032_ALC_ATTEN_RLS */ | ||
736 | #define M98925_ALC_MAX_ATTEN_MASK (0x0F<<4) | ||
737 | #define M98925_ALC_MAX_ATTEN_SHIFT 4 | ||
738 | #define M98925_ALC_MAX_ATTEN_WIDTH 4 | ||
739 | #define M98925_ALC_RLS_RATE_MASK (0x7<<0) | ||
740 | #define M98925_ALC_RLS_RATE_SHIFT 0 | ||
741 | #define M98925_ALC_RLS_RATE_WIDTH 3 | ||
742 | |||
743 | /* MAX98925_R033_ALC_HOLD_RLS */ | ||
744 | #define M98925_ALC_RLS_TGR_MASK (1<<0) | ||
745 | #define M98925_ALC_RLS_TGR_SHIFT 0 | ||
746 | #define M98925_ALC_RLS_TGR_WIDTH 1 | ||
747 | |||
748 | /* MAX98925_R034_ALC_CONFIGURATION */ | ||
749 | #define M98925_ALC_MUTE_EN_MASK (1<<7) | ||
750 | #define M98925_ALC_MUTE_EN_SHIFT 7 | ||
751 | #define M98925_ALC_MUTE_EN_WIDTH 1 | ||
752 | #define M98925_ALC_MUTE_DLY_MASK (0x07<<4) | ||
753 | #define M98925_ALC_MUTE_DLY_SHIFT 4 | ||
754 | #define M98925_ALC_MUTE_DLY_WIDTH 3 | ||
755 | #define M98925_ALC_RLS_DBT_MASK (0x07<<0) | ||
756 | #define M98925_ALC_RLS_DBT_SHIFT 0 | ||
757 | #define M98925_ALC_RLS_DBT_WIDTH 3 | ||
758 | |||
759 | /* MAX98925_R035_BOOST_CONVERTER */ | ||
760 | #define M98925_BST_SYNC_MASK (1<<7) | ||
761 | #define M98925_BST_SYNC_SHIFT 7 | ||
762 | #define M98925_BST_SYNC_WIDTH 1 | ||
763 | #define M98925_BST_PHASE_MASK (0x03<<4) | ||
764 | #define M98925_BST_PHASE_SHIFT 4 | ||
765 | #define M98925_BST_PHASE_WIDTH 2 | ||
766 | #define M98925_BST_SKIP_MODE_MASK (0x03<<0) | ||
767 | #define M98925_BST_SKIP_MODE_SHIFT 0 | ||
768 | #define M98925_BST_SKIP_MODE_WIDTH 2 | ||
769 | |||
770 | /* MAX98925_R036_BLOCK_ENABLE */ | ||
771 | #define M98925_BST_EN_MASK (1<<7) | ||
772 | #define M98925_BST_EN_SHIFT 7 | ||
773 | #define M98925_BST_EN_WIDTH 1 | ||
774 | #define M98925_WATCH_EN_MASK (1<<6) | ||
775 | #define M98925_WATCH_EN_SHIFT 6 | ||
776 | #define M98925_WATCH_EN_WIDTH 1 | ||
777 | #define M98925_CLKMON_EN_MASK (1<<5) | ||
778 | #define M98925_CLKMON_EN_SHIFT 5 | ||
779 | #define M98925_CLKMON_EN_WIDTH 1 | ||
780 | #define M98925_SPK_EN_MASK (1<<4) | ||
781 | #define M98925_SPK_EN_SHIFT 4 | ||
782 | #define M98925_SPK_EN_WIDTH 1 | ||
783 | #define M98925_ADC_VBST_EN_MASK (1<<3) | ||
784 | #define M98925_ADC_VBST_EN_SHIFT 3 | ||
785 | #define M98925_ADC_VBST_EN_WIDTH 1 | ||
786 | #define M98925_ADC_VBAT_EN_MASK (1<<2) | ||
787 | #define M98925_ADC_VBAT_EN_SHIFT 2 | ||
788 | #define M98925_ADC_VBAT_EN_WIDTH 1 | ||
789 | #define M98925_ADC_IMON_EN_MASK (1<<1) | ||
790 | #define M98925_ADC_IMON_EN_SHIFT 1 | ||
791 | #define M98925_ADC_IMON_EN_WIDTH 1 | ||
792 | #define M98925_ADC_VMON_EN_MASK (1<<0) | ||
793 | #define M98925_ADC_VMON_EN_SHIFT 0 | ||
794 | #define M98925_ADC_VMON_EN_WIDTH 1 | ||
795 | |||
796 | /* MAX98925_R037_CONFIGURATION */ | ||
797 | #define M98925_BST_VOUT_MASK (0x0F<<4) | ||
798 | #define M98925_BST_VOUT_SHIFT 4 | ||
799 | #define M98925_BST_VOUT_WIDTH 4 | ||
800 | #define M98925_THERMWARN_LEVEL_MASK (0x03<<2) | ||
801 | #define M98925_THERMWARN_LEVEL_SHIFT 2 | ||
802 | #define M98925_THERMWARN_LEVEL_WIDTH 2 | ||
803 | #define M98925_WATCH_TIME_MASK (0x03<<0) | ||
804 | #define M98925_WATCH_TIME_SHIFT 0 | ||
805 | #define M98925_WATCH_TIME_WIDTH 2 | ||
806 | |||
807 | /* MAX98925_R038_GLOBAL_ENABLE */ | ||
808 | #define M98925_EN_MASK (1<<7) | ||
809 | #define M98925_EN_SHIFT 7 | ||
810 | #define M98925_EN_WIDTH 1 | ||
811 | |||
812 | /* MAX98925_R03A_BOOST_LIMITER */ | ||
813 | #define M98925_BST_ILIM_MASK (0x1F<<3) | ||
814 | #define M98925_BST_ILIM_SHIFT 3 | ||
815 | #define M98925_BST_ILIM_WIDTH 5 | ||
816 | |||
817 | /* MAX98925_R0FF_VERSION */ | ||
818 | #define M98925_REV_ID_MASK (0xFF<<0) | ||
819 | #define M98925_REV_ID_SHIFT 0 | ||
820 | #define M98925_REV_ID_WIDTH 8 | ||
821 | |||
822 | struct max98925_priv { | ||
823 | struct regmap *regmap; | ||
824 | struct snd_soc_codec *codec; | ||
825 | struct max98925_pdata *pdata; | ||
826 | unsigned int sysclk; | ||
827 | unsigned int v_slot; | ||
828 | unsigned int i_slot; | ||
829 | unsigned int spk_gain; | ||
830 | unsigned int ch_size; | ||
831 | }; | ||
832 | #endif | ||
diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c index 474cae82a874..5a30fdd0da00 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 | ||
230 | static 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 | |||
240 | static 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 | |||
258 | static 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 | |||
268 | static 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 | |||
286 | static 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 | |||
296 | static 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 | |||
227 | static const DECLARE_TLV_DB_SCALE(digital_tlv, -10350, 50, 1); | 314 | static const DECLARE_TLV_DB_SCALE(digital_tlv, -10350, 50, 1); |
228 | static const DECLARE_TLV_DB_SCALE(analog_tlv, -600, 600, 0); | 315 | static const DECLARE_TLV_DB_SCALE(analog_tlv, -600, 600, 0); |
229 | static const DECLARE_TLV_DB_SCALE(boost_tlv, 0, 80, 0); | 316 | static const DECLARE_TLV_DB_SCALE(boost_tlv, 0, 80, 0); |
@@ -304,9 +391,9 @@ static const struct soc_enum pcm512x_veds = | |||
304 | static const struct snd_kcontrol_new pcm512x_controls[] = { | 391 | static const struct snd_kcontrol_new pcm512x_controls[] = { |
305 | SOC_DOUBLE_R_TLV("Digital Playback Volume", PCM512x_DIGITAL_VOLUME_2, | 392 | SOC_DOUBLE_R_TLV("Digital Playback Volume", PCM512x_DIGITAL_VOLUME_2, |
306 | PCM512x_DIGITAL_VOLUME_3, 0, 255, 1, digital_tlv), | 393 | PCM512x_DIGITAL_VOLUME_3, 0, 255, 1, digital_tlv), |
307 | SOC_DOUBLE_TLV("Playback Volume", PCM512x_ANALOG_GAIN_CTRL, | 394 | SOC_DOUBLE_TLV("Analogue Playback Volume", PCM512x_ANALOG_GAIN_CTRL, |
308 | PCM512x_LAGN_SHIFT, PCM512x_RAGN_SHIFT, 1, 1, analog_tlv), | 395 | PCM512x_LAGN_SHIFT, PCM512x_RAGN_SHIFT, 1, 1, analog_tlv), |
309 | SOC_DOUBLE_TLV("Playback Boost Volume", PCM512x_ANALOG_GAIN_BOOST, | 396 | SOC_DOUBLE_TLV("Analogue Playback Boost Volume", PCM512x_ANALOG_GAIN_BOOST, |
310 | PCM512x_AGBL_SHIFT, PCM512x_AGBR_SHIFT, 1, 0, boost_tlv), | 397 | PCM512x_AGBL_SHIFT, PCM512x_AGBR_SHIFT, 1, 0, boost_tlv), |
311 | SOC_DOUBLE("Digital Playback Switch", PCM512x_MUTE, PCM512x_RQML_SHIFT, | 398 | SOC_DOUBLE("Digital Playback Switch", PCM512x_MUTE, PCM512x_RQML_SHIFT, |
312 | PCM512x_RQMR_SHIFT, 1, 1), | 399 | PCM512x_RQMR_SHIFT, 1, 1), |
@@ -328,6 +415,13 @@ SOC_ENUM("Volume Ramp Up Rate", pcm512x_vnuf), | |||
328 | SOC_ENUM("Volume Ramp Up Step", pcm512x_vnus), | 415 | SOC_ENUM("Volume Ramp Up Step", pcm512x_vnus), |
329 | SOC_ENUM("Volume Ramp Down Emergency Rate", pcm512x_vedf), | 416 | SOC_ENUM("Volume Ramp Down Emergency Rate", pcm512x_vedf), |
330 | SOC_ENUM("Volume Ramp Down Emergency Step", pcm512x_veds), | 417 | SOC_ENUM("Volume Ramp Down Emergency Step", pcm512x_veds), |
418 | |||
419 | SOC_SINGLE_EXT("Max Overclock PLL", SND_SOC_NOPM, 0, 20, 0, | ||
420 | pcm512x_overclock_pll_get, pcm512x_overclock_pll_put), | ||
421 | SOC_SINGLE_EXT("Max Overclock DSP", SND_SOC_NOPM, 0, 40, 0, | ||
422 | pcm512x_overclock_dsp_get, pcm512x_overclock_dsp_put), | ||
423 | SOC_SINGLE_EXT("Max Overclock DAC", SND_SOC_NOPM, 0, 40, 0, | ||
424 | pcm512x_overclock_dac_get, pcm512x_overclock_dac_put), | ||
331 | }; | 425 | }; |
332 | 426 | ||
333 | static const struct snd_soc_dapm_widget pcm512x_dapm_widgets[] = { | 427 | static 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 | ||
443 | static unsigned long pcm512x_pll_max(struct pcm512x_priv *pcm512x) | ||
444 | { | ||
445 | return 25000000 + 25000000 * pcm512x->overclock_pll / 100; | ||
446 | } | ||
447 | |||
448 | static unsigned long pcm512x_dsp_max(struct pcm512x_priv *pcm512x) | ||
449 | { | ||
450 | return 50000000 + 50000000 * pcm512x->overclock_dsp / 100; | ||
451 | } | ||
452 | |||
453 | static unsigned long pcm512x_dac_max(struct pcm512x_priv *pcm512x, | ||
454 | unsigned long rate) | ||
455 | { | ||
456 | return rate + rate * pcm512x->overclock_dac / 100; | ||
457 | } | ||
458 | |||
459 | static 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 | |||
466 | static 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 | |||
349 | static const u32 pcm512x_dai_rates[] = { | 482 | static 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 = { | |||
359 | static int pcm512x_hw_rule_rate(struct snd_pcm_hw_params *params, | 492 | static 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 | } |
@@ -576,8 +713,8 @@ static int pcm512x_find_pll_coeff(struct snd_soc_dai *dai, | |||
576 | 713 | ||
577 | /* pllin_rate / P (or here, den) cannot be greater than 20 MHz */ | 714 | /* pllin_rate / P (or here, den) cannot be greater than 20 MHz */ |
578 | if (pllin_rate / den > 20000000 && num < 8) { | 715 | if (pllin_rate / den > 20000000 && num < 8) { |
579 | num *= 20000000 / (pllin_rate / den); | 716 | num *= DIV_ROUND_UP(pllin_rate / den, 20000000); |
580 | den *= 20000000 / (pllin_rate / den); | 717 | den *= DIV_ROUND_UP(pllin_rate / den, 20000000); |
581 | } | 718 | } |
582 | dev_dbg(dev, "num / den = %lu / %lu\n", num, den); | 719 | dev_dbg(dev, "num / den = %lu / %lu\n", num, den); |
583 | 720 | ||
@@ -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..0fcda35a3a93 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 | } |
@@ -1037,7 +1048,6 @@ static int rt286_probe(struct snd_soc_codec *codec) | |||
1037 | struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec); | 1048 | struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec); |
1038 | 1049 | ||
1039 | rt286->codec = codec; | 1050 | rt286->codec = codec; |
1040 | codec->dapm.bias_level = SND_SOC_BIAS_OFF; | ||
1041 | 1051 | ||
1042 | if (rt286->i2c->irq) { | 1052 | if (rt286->i2c->irq) { |
1043 | regmap_update_bits(rt286->regmap, | 1053 | regmap_update_bits(rt286->regmap, |
@@ -1209,7 +1219,7 @@ static int rt286_i2c_probe(struct i2c_client *i2c, | |||
1209 | { | 1219 | { |
1210 | struct rt286_platform_data *pdata = dev_get_platdata(&i2c->dev); | 1220 | struct rt286_platform_data *pdata = dev_get_platdata(&i2c->dev); |
1211 | struct rt286_priv *rt286; | 1221 | struct rt286_priv *rt286; |
1212 | int i, ret; | 1222 | int i, ret, val; |
1213 | 1223 | ||
1214 | rt286 = devm_kzalloc(&i2c->dev, sizeof(*rt286), | 1224 | rt286 = devm_kzalloc(&i2c->dev, sizeof(*rt286), |
1215 | GFP_KERNEL); | 1225 | GFP_KERNEL); |
@@ -1224,11 +1234,15 @@ static int rt286_i2c_probe(struct i2c_client *i2c, | |||
1224 | return ret; | 1234 | return ret; |
1225 | } | 1235 | } |
1226 | 1236 | ||
1227 | regmap_read(rt286->regmap, | 1237 | ret = regmap_read(rt286->regmap, |
1228 | RT286_GET_PARAM(AC_NODE_ROOT, AC_PAR_VENDOR_ID), &ret); | 1238 | RT286_GET_PARAM(AC_NODE_ROOT, AC_PAR_VENDOR_ID), &val); |
1229 | if (ret != RT286_VENDOR_ID && ret != RT288_VENDOR_ID) { | 1239 | if (ret != 0) { |
1240 | dev_err(&i2c->dev, "I2C error %d\n", ret); | ||
1241 | return ret; | ||
1242 | } | ||
1243 | if (val != RT286_VENDOR_ID && val != RT288_VENDOR_ID) { | ||
1230 | dev_err(&i2c->dev, | 1244 | dev_err(&i2c->dev, |
1231 | "Device with ID register %x is not rt286\n", ret); | 1245 | "Device with ID register %x is not rt286\n", val); |
1232 | return -ENODEV; | 1246 | return -ENODEV; |
1233 | } | 1247 | } |
1234 | 1248 | ||
@@ -1236,6 +1250,14 @@ static int rt286_i2c_probe(struct i2c_client *i2c, | |||
1236 | rt286->i2c = i2c; | 1250 | rt286->i2c = i2c; |
1237 | i2c_set_clientdata(i2c, rt286); | 1251 | i2c_set_clientdata(i2c, rt286); |
1238 | 1252 | ||
1253 | /* restore codec default */ | ||
1254 | for (i = 0; i < INDEX_CACHE_SIZE; i++) | ||
1255 | regmap_write(rt286->regmap, rt286->index_cache[i].reg, | ||
1256 | rt286->index_cache[i].def); | ||
1257 | for (i = 0; i < ARRAY_SIZE(rt286_reg); i++) | ||
1258 | regmap_write(rt286->regmap, rt286_reg[i].reg, | ||
1259 | rt286_reg[i].def); | ||
1260 | |||
1239 | if (pdata) | 1261 | if (pdata) |
1240 | rt286->pdata = *pdata; | 1262 | rt286->pdata = *pdata; |
1241 | 1263 | ||
diff --git a/sound/soc/codecs/rt5631.c b/sound/soc/codecs/rt5631.c index c61852742ee3..2c10d77727af 100644 --- a/sound/soc/codecs/rt5631.c +++ b/sound/soc/codecs/rt5631.c | |||
@@ -1675,7 +1675,7 @@ static const struct i2c_device_id rt5631_i2c_id[] = { | |||
1675 | MODULE_DEVICE_TABLE(i2c, rt5631_i2c_id); | 1675 | MODULE_DEVICE_TABLE(i2c, rt5631_i2c_id); |
1676 | 1676 | ||
1677 | #ifdef CONFIG_OF | 1677 | #ifdef CONFIG_OF |
1678 | static struct of_device_id rt5631_i2c_dt_ids[] = { | 1678 | static const struct of_device_id rt5631_i2c_dt_ids[] = { |
1679 | { .compatible = "realtek,rt5631"}, | 1679 | { .compatible = "realtek,rt5631"}, |
1680 | { .compatible = "realtek,alc5631"}, | 1680 | { .compatible = "realtek,alc5631"}, |
1681 | { } | 1681 | { } |
diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c index c9a4c5be083b..69528ae5410c 100644 --- a/sound/soc/codecs/rt5645.c +++ b/sound/soc/codecs/rt5645.c | |||
@@ -1270,6 +1270,8 @@ static void hp_amp_power(struct snd_soc_codec *codec, int on) | |||
1270 | snd_soc_update_bits(codec, RT5645_PWR_ANLG1, | 1270 | snd_soc_update_bits(codec, RT5645_PWR_ANLG1, |
1271 | RT5645_PWR_HP_L | RT5645_PWR_HP_R | | 1271 | RT5645_PWR_HP_L | RT5645_PWR_HP_R | |
1272 | RT5645_PWR_HA, 0); | 1272 | RT5645_PWR_HA, 0); |
1273 | snd_soc_update_bits(codec, RT5645_DEPOP_M2, | ||
1274 | RT5645_DEPOP_MASK, 0); | ||
1273 | } | 1275 | } |
1274 | } | 1276 | } |
1275 | } | 1277 | } |
@@ -1538,8 +1540,6 @@ static const struct snd_soc_dapm_widget rt5645_dapm_widgets[] = { | |||
1538 | 1540 | ||
1539 | SND_SOC_DAPM_SUPPLY_S("adc stereo1 filter", 1, RT5645_PWR_DIG2, | 1541 | SND_SOC_DAPM_SUPPLY_S("adc stereo1 filter", 1, RT5645_PWR_DIG2, |
1540 | RT5645_PWR_ADC_S1F_BIT, 0, NULL, 0), | 1542 | RT5645_PWR_ADC_S1F_BIT, 0, NULL, 0), |
1541 | SND_SOC_DAPM_SUPPLY_S("adc stereo2 filter", 1, RT5645_PWR_DIG2, | ||
1542 | RT5645_PWR_ADC_S2F_BIT, 0, NULL, 0), | ||
1543 | SND_SOC_DAPM_MIXER_E("Sto1 ADC MIXL", SND_SOC_NOPM, 0, 0, | 1543 | SND_SOC_DAPM_MIXER_E("Sto1 ADC MIXL", SND_SOC_NOPM, 0, 0, |
1544 | rt5645_sto1_adc_l_mix, ARRAY_SIZE(rt5645_sto1_adc_l_mix), | 1544 | rt5645_sto1_adc_l_mix, ARRAY_SIZE(rt5645_sto1_adc_l_mix), |
1545 | NULL, 0), | 1545 | NULL, 0), |
@@ -1729,7 +1729,6 @@ static const struct snd_soc_dapm_widget rt5650_specific_dapm_widgets[] = { | |||
1729 | 1729 | ||
1730 | static const struct snd_soc_dapm_route rt5645_dapm_routes[] = { | 1730 | static const struct snd_soc_dapm_route rt5645_dapm_routes[] = { |
1731 | { "adc stereo1 filter", NULL, "ADC STO1 ASRC", is_using_asrc }, | 1731 | { "adc stereo1 filter", NULL, "ADC STO1 ASRC", is_using_asrc }, |
1732 | { "adc stereo2 filter", NULL, "ADC STO2 ASRC", is_using_asrc }, | ||
1733 | { "adc mono left filter", NULL, "ADC MONO L ASRC", is_using_asrc }, | 1732 | { "adc mono left filter", NULL, "ADC MONO L ASRC", is_using_asrc }, |
1734 | { "adc mono right filter", NULL, "ADC MONO R ASRC", is_using_asrc }, | 1733 | { "adc mono right filter", NULL, "ADC MONO R ASRC", is_using_asrc }, |
1735 | { "dac mono left filter", NULL, "DAC MONO L ASRC", is_using_asrc }, | 1734 | { "dac mono left filter", NULL, "DAC MONO L ASRC", is_using_asrc }, |
@@ -2052,7 +2051,7 @@ static int rt5645_hw_params(struct snd_pcm_substream *substream, | |||
2052 | { | 2051 | { |
2053 | struct snd_soc_codec *codec = dai->codec; | 2052 | struct snd_soc_codec *codec = dai->codec; |
2054 | struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); | 2053 | struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); |
2055 | unsigned int val_len = 0, val_clk, mask_clk; | 2054 | unsigned int val_len = 0, val_clk, mask_clk, dl_sft; |
2056 | int pre_div, bclk_ms, frame_size; | 2055 | int pre_div, bclk_ms, frame_size; |
2057 | 2056 | ||
2058 | rt5645->lrck[dai->id] = params_rate(params); | 2057 | rt5645->lrck[dai->id] = params_rate(params); |
@@ -2066,6 +2065,16 @@ static int rt5645_hw_params(struct snd_pcm_substream *substream, | |||
2066 | dev_err(codec->dev, "Unsupported frame size: %d\n", frame_size); | 2065 | dev_err(codec->dev, "Unsupported frame size: %d\n", frame_size); |
2067 | return -EINVAL; | 2066 | return -EINVAL; |
2068 | } | 2067 | } |
2068 | |||
2069 | switch (rt5645->codec_type) { | ||
2070 | case CODEC_TYPE_RT5650: | ||
2071 | dl_sft = 4; | ||
2072 | break; | ||
2073 | default: | ||
2074 | dl_sft = 2; | ||
2075 | break; | ||
2076 | } | ||
2077 | |||
2069 | bclk_ms = frame_size > 32; | 2078 | bclk_ms = frame_size > 32; |
2070 | rt5645->bclk[dai->id] = rt5645->lrck[dai->id] * (32 << bclk_ms); | 2079 | rt5645->bclk[dai->id] = rt5645->lrck[dai->id] * (32 << bclk_ms); |
2071 | 2080 | ||
@@ -2078,13 +2087,13 @@ static int rt5645_hw_params(struct snd_pcm_substream *substream, | |||
2078 | case 16: | 2087 | case 16: |
2079 | break; | 2088 | break; |
2080 | case 20: | 2089 | case 20: |
2081 | val_len |= RT5645_I2S_DL_20; | 2090 | val_len = 0x1; |
2082 | break; | 2091 | break; |
2083 | case 24: | 2092 | case 24: |
2084 | val_len |= RT5645_I2S_DL_24; | 2093 | val_len = 0x2; |
2085 | break; | 2094 | break; |
2086 | case 8: | 2095 | case 8: |
2087 | val_len |= RT5645_I2S_DL_8; | 2096 | val_len = 0x3; |
2088 | break; | 2097 | break; |
2089 | default: | 2098 | default: |
2090 | return -EINVAL; | 2099 | return -EINVAL; |
@@ -2096,7 +2105,7 @@ static int rt5645_hw_params(struct snd_pcm_substream *substream, | |||
2096 | val_clk = bclk_ms << RT5645_I2S_BCLK_MS1_SFT | | 2105 | val_clk = bclk_ms << RT5645_I2S_BCLK_MS1_SFT | |
2097 | pre_div << RT5645_I2S_PD1_SFT; | 2106 | pre_div << RT5645_I2S_PD1_SFT; |
2098 | snd_soc_update_bits(codec, RT5645_I2S1_SDP, | 2107 | snd_soc_update_bits(codec, RT5645_I2S1_SDP, |
2099 | RT5645_I2S_DL_MASK, val_len); | 2108 | (0x3 << dl_sft), (val_len << dl_sft)); |
2100 | snd_soc_update_bits(codec, RT5645_ADDA_CLK1, mask_clk, val_clk); | 2109 | snd_soc_update_bits(codec, RT5645_ADDA_CLK1, mask_clk, val_clk); |
2101 | break; | 2110 | break; |
2102 | case RT5645_AIF2: | 2111 | case RT5645_AIF2: |
@@ -2104,7 +2113,7 @@ static int rt5645_hw_params(struct snd_pcm_substream *substream, | |||
2104 | val_clk = bclk_ms << RT5645_I2S_BCLK_MS2_SFT | | 2113 | val_clk = bclk_ms << RT5645_I2S_BCLK_MS2_SFT | |
2105 | pre_div << RT5645_I2S_PD2_SFT; | 2114 | pre_div << RT5645_I2S_PD2_SFT; |
2106 | snd_soc_update_bits(codec, RT5645_I2S2_SDP, | 2115 | snd_soc_update_bits(codec, RT5645_I2S2_SDP, |
2107 | RT5645_I2S_DL_MASK, val_len); | 2116 | (0x3 << dl_sft), (val_len << dl_sft)); |
2108 | snd_soc_update_bits(codec, RT5645_ADDA_CLK1, mask_clk, val_clk); | 2117 | snd_soc_update_bits(codec, RT5645_ADDA_CLK1, mask_clk, val_clk); |
2109 | break; | 2118 | break; |
2110 | default: | 2119 | default: |
@@ -2119,7 +2128,16 @@ static int rt5645_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) | |||
2119 | { | 2128 | { |
2120 | struct snd_soc_codec *codec = dai->codec; | 2129 | struct snd_soc_codec *codec = dai->codec; |
2121 | struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); | 2130 | struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); |
2122 | unsigned int reg_val = 0; | 2131 | unsigned int reg_val = 0, pol_sft; |
2132 | |||
2133 | switch (rt5645->codec_type) { | ||
2134 | case CODEC_TYPE_RT5650: | ||
2135 | pol_sft = 8; | ||
2136 | break; | ||
2137 | default: | ||
2138 | pol_sft = 7; | ||
2139 | break; | ||
2140 | } | ||
2123 | 2141 | ||
2124 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | 2142 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
2125 | case SND_SOC_DAIFMT_CBM_CFM: | 2143 | case SND_SOC_DAIFMT_CBM_CFM: |
@@ -2137,7 +2155,7 @@ static int rt5645_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) | |||
2137 | case SND_SOC_DAIFMT_NB_NF: | 2155 | case SND_SOC_DAIFMT_NB_NF: |
2138 | break; | 2156 | break; |
2139 | case SND_SOC_DAIFMT_IB_NF: | 2157 | case SND_SOC_DAIFMT_IB_NF: |
2140 | reg_val |= RT5645_I2S_BP_INV; | 2158 | reg_val |= (1 << pol_sft); |
2141 | break; | 2159 | break; |
2142 | default: | 2160 | default: |
2143 | return -EINVAL; | 2161 | return -EINVAL; |
@@ -2161,12 +2179,12 @@ static int rt5645_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) | |||
2161 | switch (dai->id) { | 2179 | switch (dai->id) { |
2162 | case RT5645_AIF1: | 2180 | case RT5645_AIF1: |
2163 | snd_soc_update_bits(codec, RT5645_I2S1_SDP, | 2181 | snd_soc_update_bits(codec, RT5645_I2S1_SDP, |
2164 | RT5645_I2S_MS_MASK | RT5645_I2S_BP_MASK | | 2182 | RT5645_I2S_MS_MASK | (1 << pol_sft) | |
2165 | RT5645_I2S_DF_MASK, reg_val); | 2183 | RT5645_I2S_DF_MASK, reg_val); |
2166 | break; | 2184 | break; |
2167 | case RT5645_AIF2: | 2185 | case RT5645_AIF2: |
2168 | snd_soc_update_bits(codec, RT5645_I2S2_SDP, | 2186 | snd_soc_update_bits(codec, RT5645_I2S2_SDP, |
2169 | RT5645_I2S_MS_MASK | RT5645_I2S_BP_MASK | | 2187 | RT5645_I2S_MS_MASK | (1 << pol_sft) | |
2170 | RT5645_I2S_DF_MASK, reg_val); | 2188 | RT5645_I2S_DF_MASK, reg_val); |
2171 | break; | 2189 | break; |
2172 | default: | 2190 | default: |
@@ -2285,23 +2303,42 @@ static int rt5645_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, | |||
2285 | unsigned int rx_mask, int slots, int slot_width) | 2303 | unsigned int rx_mask, int slots, int slot_width) |
2286 | { | 2304 | { |
2287 | struct snd_soc_codec *codec = dai->codec; | 2305 | struct snd_soc_codec *codec = dai->codec; |
2288 | unsigned int val = 0; | 2306 | struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); |
2307 | unsigned int i_slot_sft, o_slot_sft, i_width_sht, o_width_sht, en_sft; | ||
2308 | unsigned int mask, val = 0; | ||
2289 | 2309 | ||
2310 | switch (rt5645->codec_type) { | ||
2311 | case CODEC_TYPE_RT5650: | ||
2312 | en_sft = 15; | ||
2313 | i_slot_sft = 10; | ||
2314 | o_slot_sft = 8; | ||
2315 | i_width_sht = 6; | ||
2316 | o_width_sht = 4; | ||
2317 | mask = 0x8ff0; | ||
2318 | break; | ||
2319 | default: | ||
2320 | en_sft = 14; | ||
2321 | i_slot_sft = o_slot_sft = 12; | ||
2322 | i_width_sht = o_width_sht = 10; | ||
2323 | mask = 0x7c00; | ||
2324 | break; | ||
2325 | } | ||
2290 | if (rx_mask || tx_mask) { | 2326 | if (rx_mask || tx_mask) { |
2291 | val |= (1 << 14); | 2327 | val |= (1 << en_sft); |
2292 | snd_soc_update_bits(codec, RT5645_BASS_BACK, | 2328 | if (rt5645->codec_type == CODEC_TYPE_RT5645) |
2293 | RT5645_G_BB_BST_MASK, RT5645_G_BB_BST_25DB); | 2329 | snd_soc_update_bits(codec, RT5645_BASS_BACK, |
2330 | RT5645_G_BB_BST_MASK, RT5645_G_BB_BST_25DB); | ||
2294 | } | 2331 | } |
2295 | 2332 | ||
2296 | switch (slots) { | 2333 | switch (slots) { |
2297 | case 4: | 2334 | case 4: |
2298 | val |= (1 << 12); | 2335 | val |= (1 << i_slot_sft) | (1 << o_slot_sft); |
2299 | break; | 2336 | break; |
2300 | case 6: | 2337 | case 6: |
2301 | val |= (2 << 12); | 2338 | val |= (2 << i_slot_sft) | (2 << o_slot_sft); |
2302 | break; | 2339 | break; |
2303 | case 8: | 2340 | case 8: |
2304 | val |= (3 << 12); | 2341 | val |= (3 << i_slot_sft) | (3 << o_slot_sft); |
2305 | break; | 2342 | break; |
2306 | case 2: | 2343 | case 2: |
2307 | default: | 2344 | default: |
@@ -2310,20 +2347,20 @@ static int rt5645_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, | |||
2310 | 2347 | ||
2311 | switch (slot_width) { | 2348 | switch (slot_width) { |
2312 | case 20: | 2349 | case 20: |
2313 | val |= (1 << 10); | 2350 | val |= (1 << i_width_sht) | (1 << o_width_sht); |
2314 | break; | 2351 | break; |
2315 | case 24: | 2352 | case 24: |
2316 | val |= (2 << 10); | 2353 | val |= (2 << i_width_sht) | (2 << o_width_sht); |
2317 | break; | 2354 | break; |
2318 | case 32: | 2355 | case 32: |
2319 | val |= (3 << 10); | 2356 | val |= (3 << i_width_sht) | (3 << o_width_sht); |
2320 | break; | 2357 | break; |
2321 | case 16: | 2358 | case 16: |
2322 | default: | 2359 | default: |
2323 | break; | 2360 | break; |
2324 | } | 2361 | } |
2325 | 2362 | ||
2326 | snd_soc_update_bits(codec, RT5645_TDM_CTRL_1, 0x7c00, val); | 2363 | snd_soc_update_bits(codec, RT5645_TDM_CTRL_1, mask, val); |
2327 | 2364 | ||
2328 | return 0; | 2365 | return 0; |
2329 | } | 2366 | } |
@@ -2361,7 +2398,8 @@ static int rt5645_set_bias_level(struct snd_soc_codec *codec, | |||
2361 | 2398 | ||
2362 | case SND_SOC_BIAS_OFF: | 2399 | case SND_SOC_BIAS_OFF: |
2363 | snd_soc_write(codec, RT5645_DEPOP_M2, 0x1100); | 2400 | snd_soc_write(codec, RT5645_DEPOP_M2, 0x1100); |
2364 | snd_soc_write(codec, RT5645_GEN_CTRL1, 0x0128); | 2401 | snd_soc_update_bits(codec, RT5645_GEN_CTRL1, |
2402 | RT5645_DIG_GATE_CTRL, 0); | ||
2365 | snd_soc_update_bits(codec, RT5645_PWR_ANLG1, | 2403 | snd_soc_update_bits(codec, RT5645_PWR_ANLG1, |
2366 | RT5645_PWR_VREF1 | RT5645_PWR_MB | | 2404 | RT5645_PWR_VREF1 | RT5645_PWR_MB | |
2367 | RT5645_PWR_BG | RT5645_PWR_VREF2 | | 2405 | RT5645_PWR_BG | RT5645_PWR_VREF2 | |
@@ -2598,7 +2636,7 @@ static struct snd_soc_codec_driver soc_codec_dev_rt5645 = { | |||
2598 | static const struct regmap_config rt5645_regmap = { | 2636 | static const struct regmap_config rt5645_regmap = { |
2599 | .reg_bits = 8, | 2637 | .reg_bits = 8, |
2600 | .val_bits = 16, | 2638 | .val_bits = 16, |
2601 | 2639 | .use_single_rw = true, | |
2602 | .max_register = RT5645_VENDOR_ID2 + 1 + (ARRAY_SIZE(rt5645_ranges) * | 2640 | .max_register = RT5645_VENDOR_ID2 + 1 + (ARRAY_SIZE(rt5645_ranges) * |
2603 | RT5645_PR_SPACING), | 2641 | RT5645_PR_SPACING), |
2604 | .volatile_reg = rt5645_volatile_register, | 2642 | .volatile_reg = rt5645_volatile_register, |
diff --git a/sound/soc/codecs/rt5645.h b/sound/soc/codecs/rt5645.h index dbfd98c22f4d..db78e9462876 100644 --- a/sound/soc/codecs/rt5645.h +++ b/sound/soc/codecs/rt5645.h | |||
@@ -804,8 +804,6 @@ | |||
804 | #define RT5645_PWR_DAC_MF_L_BIT 10 | 804 | #define RT5645_PWR_DAC_MF_L_BIT 10 |
805 | #define RT5645_PWR_DAC_MF_R (0x1 << 9) | 805 | #define RT5645_PWR_DAC_MF_R (0x1 << 9) |
806 | #define RT5645_PWR_DAC_MF_R_BIT 9 | 806 | #define RT5645_PWR_DAC_MF_R_BIT 9 |
807 | #define RT5645_PWR_ADC_S2F (0x1 << 8) | ||
808 | #define RT5645_PWR_ADC_S2F_BIT 8 | ||
809 | #define RT5645_PWR_PDM1 (0x1 << 7) | 807 | #define RT5645_PWR_PDM1 (0x1 << 7) |
810 | #define RT5645_PWR_PDM1_BIT 7 | 808 | #define RT5645_PWR_PDM1_BIT 7 |
811 | #define RT5645_PWR_PDM2 (0x1 << 6) | 809 | #define RT5645_PWR_PDM2 (0x1 << 6) |
diff --git a/sound/soc/codecs/rt5670.c b/sound/soc/codecs/rt5670.c index fd102613d20d..cc7f84a150a7 100644 --- a/sound/soc/codecs/rt5670.c +++ b/sound/soc/codecs/rt5670.c | |||
@@ -403,6 +403,189 @@ static bool rt5670_readable_register(struct device *dev, unsigned int reg) | |||
403 | } | 403 | } |
404 | } | 404 | } |
405 | 405 | ||
406 | /** | ||
407 | * rt5670_headset_detect - Detect headset. | ||
408 | * @codec: SoC audio codec device. | ||
409 | * @jack_insert: Jack insert or not. | ||
410 | * | ||
411 | * Detect whether is headset or not when jack inserted. | ||
412 | * | ||
413 | * Returns detect status. | ||
414 | */ | ||
415 | |||
416 | static int rt5670_headset_detect(struct snd_soc_codec *codec, int jack_insert) | ||
417 | { | ||
418 | int val; | ||
419 | struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); | ||
420 | |||
421 | if (jack_insert) { | ||
422 | snd_soc_dapm_force_enable_pin(&codec->dapm, | ||
423 | "Mic Det Power"); | ||
424 | snd_soc_dapm_sync(&codec->dapm); | ||
425 | snd_soc_update_bits(codec, RT5670_GEN_CTRL3, 0x4, 0x0); | ||
426 | snd_soc_update_bits(codec, RT5670_CJ_CTRL2, | ||
427 | RT5670_CBJ_DET_MODE | RT5670_CBJ_MN_JD, | ||
428 | RT5670_CBJ_MN_JD); | ||
429 | snd_soc_write(codec, RT5670_GPIO_CTRL2, 0x0004); | ||
430 | snd_soc_update_bits(codec, RT5670_GPIO_CTRL1, | ||
431 | RT5670_GP1_PIN_MASK, RT5670_GP1_PIN_IRQ); | ||
432 | snd_soc_update_bits(codec, RT5670_CJ_CTRL1, | ||
433 | RT5670_CBJ_BST1_EN, RT5670_CBJ_BST1_EN); | ||
434 | snd_soc_write(codec, RT5670_JD_CTRL3, 0x00f0); | ||
435 | snd_soc_update_bits(codec, RT5670_CJ_CTRL2, | ||
436 | RT5670_CBJ_MN_JD, RT5670_CBJ_MN_JD); | ||
437 | snd_soc_update_bits(codec, RT5670_CJ_CTRL2, | ||
438 | RT5670_CBJ_MN_JD, 0); | ||
439 | msleep(300); | ||
440 | val = snd_soc_read(codec, RT5670_CJ_CTRL3) & 0x7; | ||
441 | if (val == 0x1 || val == 0x2) { | ||
442 | rt5670->jack_type = SND_JACK_HEADSET; | ||
443 | /* for push button */ | ||
444 | snd_soc_update_bits(codec, RT5670_INT_IRQ_ST, 0x8, 0x8); | ||
445 | snd_soc_update_bits(codec, RT5670_IL_CMD, 0x40, 0x40); | ||
446 | snd_soc_read(codec, RT5670_IL_CMD); | ||
447 | } else { | ||
448 | snd_soc_update_bits(codec, RT5670_GEN_CTRL3, 0x4, 0x4); | ||
449 | rt5670->jack_type = SND_JACK_HEADPHONE; | ||
450 | snd_soc_dapm_disable_pin(&codec->dapm, "Mic Det Power"); | ||
451 | snd_soc_dapm_sync(&codec->dapm); | ||
452 | } | ||
453 | } else { | ||
454 | snd_soc_update_bits(codec, RT5670_INT_IRQ_ST, 0x8, 0x0); | ||
455 | snd_soc_update_bits(codec, RT5670_GEN_CTRL3, 0x4, 0x4); | ||
456 | rt5670->jack_type = 0; | ||
457 | snd_soc_dapm_disable_pin(&codec->dapm, "Mic Det Power"); | ||
458 | snd_soc_dapm_sync(&codec->dapm); | ||
459 | } | ||
460 | |||
461 | return rt5670->jack_type; | ||
462 | } | ||
463 | |||
464 | void rt5670_jack_suspend(struct snd_soc_codec *codec) | ||
465 | { | ||
466 | struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); | ||
467 | |||
468 | rt5670->jack_type_saved = rt5670->jack_type; | ||
469 | rt5670_headset_detect(codec, 0); | ||
470 | } | ||
471 | EXPORT_SYMBOL_GPL(rt5670_jack_suspend); | ||
472 | |||
473 | void rt5670_jack_resume(struct snd_soc_codec *codec) | ||
474 | { | ||
475 | struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); | ||
476 | |||
477 | if (rt5670->jack_type_saved) | ||
478 | rt5670_headset_detect(codec, 1); | ||
479 | } | ||
480 | EXPORT_SYMBOL_GPL(rt5670_jack_resume); | ||
481 | |||
482 | static int rt5670_button_detect(struct snd_soc_codec *codec) | ||
483 | { | ||
484 | int btn_type, val; | ||
485 | |||
486 | val = snd_soc_read(codec, RT5670_IL_CMD); | ||
487 | btn_type = val & 0xff80; | ||
488 | snd_soc_write(codec, RT5670_IL_CMD, val); | ||
489 | if (btn_type != 0) { | ||
490 | msleep(20); | ||
491 | val = snd_soc_read(codec, RT5670_IL_CMD); | ||
492 | snd_soc_write(codec, RT5670_IL_CMD, val); | ||
493 | } | ||
494 | |||
495 | return btn_type; | ||
496 | } | ||
497 | |||
498 | static int rt5670_irq_detection(void *data) | ||
499 | { | ||
500 | struct rt5670_priv *rt5670 = (struct rt5670_priv *)data; | ||
501 | struct snd_soc_jack_gpio *gpio = &rt5670->hp_gpio; | ||
502 | struct snd_soc_jack *jack = rt5670->jack; | ||
503 | int val, btn_type, report = jack->status; | ||
504 | |||
505 | if (rt5670->pdata.jd_mode == 1) /* 2 port */ | ||
506 | val = snd_soc_read(rt5670->codec, RT5670_A_JD_CTRL1) & 0x0070; | ||
507 | else | ||
508 | val = snd_soc_read(rt5670->codec, RT5670_A_JD_CTRL1) & 0x0020; | ||
509 | |||
510 | switch (val) { | ||
511 | /* jack in */ | ||
512 | case 0x30: /* 2 port */ | ||
513 | case 0x0: /* 1 port or 2 port */ | ||
514 | if (rt5670->jack_type == 0) { | ||
515 | report = rt5670_headset_detect(rt5670->codec, 1); | ||
516 | /* for push button and jack out */ | ||
517 | gpio->debounce_time = 25; | ||
518 | break; | ||
519 | } | ||
520 | btn_type = 0; | ||
521 | if (snd_soc_read(rt5670->codec, RT5670_INT_IRQ_ST) & 0x4) { | ||
522 | /* button pressed */ | ||
523 | report = SND_JACK_HEADSET; | ||
524 | btn_type = rt5670_button_detect(rt5670->codec); | ||
525 | switch (btn_type) { | ||
526 | case 0x2000: /* up */ | ||
527 | report |= SND_JACK_BTN_1; | ||
528 | break; | ||
529 | case 0x0400: /* center */ | ||
530 | report |= SND_JACK_BTN_0; | ||
531 | break; | ||
532 | case 0x0080: /* down */ | ||
533 | report |= SND_JACK_BTN_2; | ||
534 | break; | ||
535 | default: | ||
536 | dev_err(rt5670->codec->dev, | ||
537 | "Unexpected button code 0x%04x\n", | ||
538 | btn_type); | ||
539 | break; | ||
540 | } | ||
541 | } | ||
542 | if (btn_type == 0)/* button release */ | ||
543 | report = rt5670->jack_type; | ||
544 | |||
545 | break; | ||
546 | /* jack out */ | ||
547 | case 0x70: /* 2 port */ | ||
548 | case 0x10: /* 2 port */ | ||
549 | case 0x20: /* 1 port */ | ||
550 | report = 0; | ||
551 | snd_soc_update_bits(rt5670->codec, RT5670_INT_IRQ_ST, 0x1, 0x0); | ||
552 | rt5670_headset_detect(rt5670->codec, 0); | ||
553 | gpio->debounce_time = 150; /* for jack in */ | ||
554 | break; | ||
555 | default: | ||
556 | break; | ||
557 | } | ||
558 | |||
559 | return report; | ||
560 | } | ||
561 | |||
562 | int rt5670_set_jack_detect(struct snd_soc_codec *codec, | ||
563 | struct snd_soc_jack *jack) | ||
564 | { | ||
565 | struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); | ||
566 | int ret; | ||
567 | |||
568 | rt5670->jack = jack; | ||
569 | rt5670->hp_gpio.gpiod_dev = codec->dev; | ||
570 | rt5670->hp_gpio.name = "headphone detect"; | ||
571 | rt5670->hp_gpio.report = SND_JACK_HEADSET | | ||
572 | SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2; | ||
573 | rt5670->hp_gpio.debounce_time = 150; | ||
574 | rt5670->hp_gpio.wake = true; | ||
575 | rt5670->hp_gpio.data = (struct rt5670_priv *)rt5670; | ||
576 | rt5670->hp_gpio.jack_status_check = rt5670_irq_detection; | ||
577 | |||
578 | ret = snd_soc_jack_add_gpios(rt5670->jack, 1, | ||
579 | &rt5670->hp_gpio); | ||
580 | if (ret) { | ||
581 | dev_err(codec->dev, "Adding jack GPIO failed\n"); | ||
582 | return ret; | ||
583 | } | ||
584 | |||
585 | return 0; | ||
586 | } | ||
587 | EXPORT_SYMBOL_GPL(rt5670_set_jack_detect); | ||
588 | |||
406 | static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0); | 589 | static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0); |
407 | static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -65625, 375, 0); | 590 | static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -65625, 375, 0); |
408 | static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0); | 591 | static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0); |
@@ -517,11 +700,9 @@ static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *source, | |||
517 | struct snd_soc_dapm_widget *sink) | 700 | struct snd_soc_dapm_widget *sink) |
518 | { | 701 | { |
519 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm); | 702 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm); |
520 | unsigned int val; | 703 | struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); |
521 | 704 | ||
522 | val = snd_soc_read(codec, RT5670_GLB_CLK); | 705 | if (rt5670->sysclk_src == RT5670_SCLK_S_PLL1) |
523 | val &= RT5670_SCLK_SRC_MASK; | ||
524 | if (val == RT5670_SCLK_SRC_PLL1) | ||
525 | return 1; | 706 | return 1; |
526 | else | 707 | else |
527 | return 0; | 708 | return 0; |
@@ -2271,16 +2452,6 @@ static int rt5670_set_dai_sysclk(struct snd_soc_dai *dai, | |||
2271 | struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); | 2452 | struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); |
2272 | unsigned int reg_val = 0; | 2453 | unsigned int reg_val = 0; |
2273 | 2454 | ||
2274 | if (freq == rt5670->sysclk && clk_id == rt5670->sysclk_src) | ||
2275 | return 0; | ||
2276 | |||
2277 | if (rt5670->pdata.jd_mode) { | ||
2278 | if (clk_id == RT5670_SCLK_S_PLL1) | ||
2279 | snd_soc_dapm_force_enable_pin(&codec->dapm, "PLL1"); | ||
2280 | else | ||
2281 | snd_soc_dapm_disable_pin(&codec->dapm, "PLL1"); | ||
2282 | snd_soc_dapm_sync(&codec->dapm); | ||
2283 | } | ||
2284 | switch (clk_id) { | 2455 | switch (clk_id) { |
2285 | case RT5670_SCLK_S_MCLK: | 2456 | case RT5670_SCLK_S_MCLK: |
2286 | reg_val |= RT5670_SCLK_SRC_MCLK; | 2457 | reg_val |= RT5670_SCLK_SRC_MCLK; |
@@ -2298,7 +2469,8 @@ static int rt5670_set_dai_sysclk(struct snd_soc_dai *dai, | |||
2298 | snd_soc_update_bits(codec, RT5670_GLB_CLK, | 2469 | snd_soc_update_bits(codec, RT5670_GLB_CLK, |
2299 | RT5670_SCLK_SRC_MASK, reg_val); | 2470 | RT5670_SCLK_SRC_MASK, reg_val); |
2300 | rt5670->sysclk = freq; | 2471 | rt5670->sysclk = freq; |
2301 | rt5670->sysclk_src = clk_id; | 2472 | if (clk_id != RT5670_SCLK_S_RCCLK) |
2473 | rt5670->sysclk_src = clk_id; | ||
2302 | 2474 | ||
2303 | dev_dbg(dai->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id); | 2475 | dev_dbg(dai->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id); |
2304 | 2476 | ||
@@ -2517,6 +2689,7 @@ static int rt5670_remove(struct snd_soc_codec *codec) | |||
2517 | struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); | 2689 | struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); |
2518 | 2690 | ||
2519 | regmap_write(rt5670->regmap, RT5670_RESET, 0); | 2691 | regmap_write(rt5670->regmap, RT5670_RESET, 0); |
2692 | snd_soc_jack_free_gpios(rt5670->jack, 1, &rt5670->hp_gpio); | ||
2520 | return 0; | 2693 | return 0; |
2521 | } | 2694 | } |
2522 | 2695 | ||
@@ -2676,6 +2849,7 @@ static int rt5670_i2c_probe(struct i2c_client *i2c, | |||
2676 | if (dmi_check_system(dmi_platform_intel_braswell)) { | 2849 | if (dmi_check_system(dmi_platform_intel_braswell)) { |
2677 | rt5670->pdata.dmic_en = true; | 2850 | rt5670->pdata.dmic_en = true; |
2678 | rt5670->pdata.dmic1_data_pin = RT5670_DMIC_DATA_IN2P; | 2851 | rt5670->pdata.dmic1_data_pin = RT5670_DMIC_DATA_IN2P; |
2852 | rt5670->pdata.dev_gpio = true; | ||
2679 | rt5670->pdata.jd_mode = 1; | 2853 | rt5670->pdata.jd_mode = 1; |
2680 | } | 2854 | } |
2681 | 2855 | ||
@@ -2717,12 +2891,17 @@ static int rt5670_i2c_probe(struct i2c_client *i2c, | |||
2717 | regmap_update_bits(rt5670->regmap, RT5670_IN2, | 2891 | regmap_update_bits(rt5670->regmap, RT5670_IN2, |
2718 | RT5670_IN_DF2, RT5670_IN_DF2); | 2892 | RT5670_IN_DF2, RT5670_IN_DF2); |
2719 | 2893 | ||
2720 | if (i2c->irq) { | 2894 | if (rt5670->pdata.dev_gpio) { |
2895 | /* for push button */ | ||
2896 | regmap_write(rt5670->regmap, RT5670_IL_CMD, 0x0000); | ||
2897 | regmap_write(rt5670->regmap, RT5670_IL_CMD2, 0x0010); | ||
2898 | regmap_write(rt5670->regmap, RT5670_IL_CMD3, 0x0014); | ||
2899 | /* for irq */ | ||
2721 | regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL1, | 2900 | regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL1, |
2722 | RT5670_GP1_PIN_MASK, RT5670_GP1_PIN_IRQ); | 2901 | RT5670_GP1_PIN_MASK, RT5670_GP1_PIN_IRQ); |
2723 | regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL2, | 2902 | regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL2, |
2724 | RT5670_GP1_PF_MASK, RT5670_GP1_PF_OUT); | 2903 | RT5670_GP1_PF_MASK, RT5670_GP1_PF_OUT); |
2725 | 2904 | regmap_update_bits(rt5670->regmap, RT5670_DIG_MISC, 0x8, 0x8); | |
2726 | } | 2905 | } |
2727 | 2906 | ||
2728 | if (rt5670->pdata.jd_mode) { | 2907 | if (rt5670->pdata.jd_mode) { |
diff --git a/sound/soc/codecs/rt5670.h b/sound/soc/codecs/rt5670.h index 21f8e18c13c4..dc2b46236c5c 100644 --- a/sound/soc/codecs/rt5670.h +++ b/sound/soc/codecs/rt5670.h | |||
@@ -1950,17 +1950,20 @@ enum { | |||
1950 | }; | 1950 | }; |
1951 | 1951 | ||
1952 | enum { | 1952 | enum { |
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 | ||
1958 | enum { | 1959 | enum { |
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 | ||
1963 | enum { | 1965 | enum { |
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, |
@@ -1985,6 +1988,8 @@ struct rt5670_priv { | |||
1985 | struct snd_soc_codec *codec; | 1988 | struct snd_soc_codec *codec; |
1986 | struct rt5670_platform_data pdata; | 1989 | struct rt5670_platform_data pdata; |
1987 | struct regmap *regmap; | 1990 | struct regmap *regmap; |
1991 | struct snd_soc_jack *jack; | ||
1992 | struct snd_soc_jack_gpio hp_gpio; | ||
1988 | 1993 | ||
1989 | int sysclk; | 1994 | int sysclk; |
1990 | int sysclk_src; | 1995 | int sysclk_src; |
@@ -1999,6 +2004,11 @@ struct rt5670_priv { | |||
1999 | int dsp_sw; /* expected parameter setting */ | 2004 | int dsp_sw; /* expected parameter setting */ |
2000 | int dsp_rate; | 2005 | int dsp_rate; |
2001 | int jack_type; | 2006 | int jack_type; |
2007 | int jack_type_saved; | ||
2002 | }; | 2008 | }; |
2003 | 2009 | ||
2010 | void rt5670_jack_suspend(struct snd_soc_codec *codec); | ||
2011 | void rt5670_jack_resume(struct snd_soc_codec *codec); | ||
2012 | int rt5670_set_jack_detect(struct snd_soc_codec *codec, | ||
2013 | struct snd_soc_jack *jack); | ||
2004 | #endif /* __RT5670_H__ */ | 2014 | #endif /* __RT5670_H__ */ |
diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index fb9c20eace3f..af182586712d 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); |
@@ -1021,6 +1034,169 @@ static int can_use_asrc(struct snd_soc_dapm_widget *source, | |||
1021 | return 0; | 1034 | return 0; |
1022 | } | 1035 | } |
1023 | 1036 | ||
1037 | /** | ||
1038 | * rt5677_sel_asrc_clk_src - select ASRC clock source for a set of filters | ||
1039 | * @codec: SoC audio codec device. | ||
1040 | * @filter_mask: mask of filters. | ||
1041 | * @clk_src: clock source | ||
1042 | * | ||
1043 | * The ASRC function is for asynchronous MCLK and LRCK. Also, since RT5677 can | ||
1044 | * only support standard 32fs or 64fs i2s format, ASRC should be enabled to | ||
1045 | * support special i2s clock format such as Intel's 100fs(100 * sampling rate). | ||
1046 | * ASRC function will track i2s clock and generate a corresponding system clock | ||
1047 | * for codec. This function provides an API to select the clock source for a | ||
1048 | * set of filters specified by the mask. And the codec driver will turn on ASRC | ||
1049 | * for these filters if ASRC is selected as their clock source. | ||
1050 | */ | ||
1051 | int rt5677_sel_asrc_clk_src(struct snd_soc_codec *codec, | ||
1052 | unsigned int filter_mask, unsigned int clk_src) | ||
1053 | { | ||
1054 | struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); | ||
1055 | unsigned int asrc3_mask = 0, asrc3_value = 0; | ||
1056 | unsigned int asrc4_mask = 0, asrc4_value = 0; | ||
1057 | unsigned int asrc5_mask = 0, asrc5_value = 0; | ||
1058 | unsigned int asrc6_mask = 0, asrc6_value = 0; | ||
1059 | unsigned int asrc7_mask = 0, asrc7_value = 0; | ||
1060 | |||
1061 | switch (clk_src) { | ||
1062 | case RT5677_CLK_SEL_SYS: | ||
1063 | case RT5677_CLK_SEL_I2S1_ASRC: | ||
1064 | case RT5677_CLK_SEL_I2S2_ASRC: | ||
1065 | case RT5677_CLK_SEL_I2S3_ASRC: | ||
1066 | case RT5677_CLK_SEL_I2S4_ASRC: | ||
1067 | case RT5677_CLK_SEL_I2S5_ASRC: | ||
1068 | case RT5677_CLK_SEL_I2S6_ASRC: | ||
1069 | case RT5677_CLK_SEL_SYS2: | ||
1070 | case RT5677_CLK_SEL_SYS3: | ||
1071 | case RT5677_CLK_SEL_SYS4: | ||
1072 | case RT5677_CLK_SEL_SYS5: | ||
1073 | case RT5677_CLK_SEL_SYS6: | ||
1074 | case RT5677_CLK_SEL_SYS7: | ||
1075 | break; | ||
1076 | |||
1077 | default: | ||
1078 | return -EINVAL; | ||
1079 | } | ||
1080 | |||
1081 | /* ASRC 3 */ | ||
1082 | if (filter_mask & RT5677_DA_STEREO_FILTER) { | ||
1083 | asrc3_mask |= RT5677_DA_STO_CLK_SEL_MASK; | ||
1084 | asrc3_value = (asrc3_value & ~RT5677_DA_STO_CLK_SEL_MASK) | ||
1085 | | (clk_src << RT5677_DA_STO_CLK_SEL_SFT); | ||
1086 | } | ||
1087 | |||
1088 | if (filter_mask & RT5677_DA_MONO2_L_FILTER) { | ||
1089 | asrc3_mask |= RT5677_DA_MONO2L_CLK_SEL_MASK; | ||
1090 | asrc3_value = (asrc3_value & ~RT5677_DA_MONO2L_CLK_SEL_MASK) | ||
1091 | | (clk_src << RT5677_DA_MONO2L_CLK_SEL_SFT); | ||
1092 | } | ||
1093 | |||
1094 | if (filter_mask & RT5677_DA_MONO2_R_FILTER) { | ||
1095 | asrc3_mask |= RT5677_DA_MONO2R_CLK_SEL_MASK; | ||
1096 | asrc3_value = (asrc3_value & ~RT5677_DA_MONO2R_CLK_SEL_MASK) | ||
1097 | | (clk_src << RT5677_DA_MONO2R_CLK_SEL_SFT); | ||
1098 | } | ||
1099 | |||
1100 | if (asrc3_mask) | ||
1101 | regmap_update_bits(rt5677->regmap, RT5677_ASRC_3, asrc3_mask, | ||
1102 | asrc3_value); | ||
1103 | |||
1104 | /* ASRC 4 */ | ||
1105 | if (filter_mask & RT5677_DA_MONO3_L_FILTER) { | ||
1106 | asrc4_mask |= RT5677_DA_MONO3L_CLK_SEL_MASK; | ||
1107 | asrc4_value = (asrc4_value & ~RT5677_DA_MONO3L_CLK_SEL_MASK) | ||
1108 | | (clk_src << RT5677_DA_MONO3L_CLK_SEL_SFT); | ||
1109 | } | ||
1110 | |||
1111 | if (filter_mask & RT5677_DA_MONO3_R_FILTER) { | ||
1112 | asrc4_mask |= RT5677_DA_MONO3R_CLK_SEL_MASK; | ||
1113 | asrc4_value = (asrc4_value & ~RT5677_DA_MONO3R_CLK_SEL_MASK) | ||
1114 | | (clk_src << RT5677_DA_MONO3R_CLK_SEL_SFT); | ||
1115 | } | ||
1116 | |||
1117 | if (filter_mask & RT5677_DA_MONO4_L_FILTER) { | ||
1118 | asrc4_mask |= RT5677_DA_MONO4L_CLK_SEL_MASK; | ||
1119 | asrc4_value = (asrc4_value & ~RT5677_DA_MONO4L_CLK_SEL_MASK) | ||
1120 | | (clk_src << RT5677_DA_MONO4L_CLK_SEL_SFT); | ||
1121 | } | ||
1122 | |||
1123 | if (filter_mask & RT5677_DA_MONO4_R_FILTER) { | ||
1124 | asrc4_mask |= RT5677_DA_MONO4R_CLK_SEL_MASK; | ||
1125 | asrc4_value = (asrc4_value & ~RT5677_DA_MONO4R_CLK_SEL_MASK) | ||
1126 | | (clk_src << RT5677_DA_MONO4R_CLK_SEL_SFT); | ||
1127 | } | ||
1128 | |||
1129 | if (asrc4_mask) | ||
1130 | regmap_update_bits(rt5677->regmap, RT5677_ASRC_4, asrc4_mask, | ||
1131 | asrc4_value); | ||
1132 | |||
1133 | /* ASRC 5 */ | ||
1134 | if (filter_mask & RT5677_AD_STEREO1_FILTER) { | ||
1135 | asrc5_mask |= RT5677_AD_STO1_CLK_SEL_MASK; | ||
1136 | asrc5_value = (asrc5_value & ~RT5677_AD_STO1_CLK_SEL_MASK) | ||
1137 | | (clk_src << RT5677_AD_STO1_CLK_SEL_SFT); | ||
1138 | } | ||
1139 | |||
1140 | if (filter_mask & RT5677_AD_STEREO2_FILTER) { | ||
1141 | asrc5_mask |= RT5677_AD_STO2_CLK_SEL_MASK; | ||
1142 | asrc5_value = (asrc5_value & ~RT5677_AD_STO2_CLK_SEL_MASK) | ||
1143 | | (clk_src << RT5677_AD_STO2_CLK_SEL_SFT); | ||
1144 | } | ||
1145 | |||
1146 | if (filter_mask & RT5677_AD_STEREO3_FILTER) { | ||
1147 | asrc5_mask |= RT5677_AD_STO3_CLK_SEL_MASK; | ||
1148 | asrc5_value = (asrc5_value & ~RT5677_AD_STO3_CLK_SEL_MASK) | ||
1149 | | (clk_src << RT5677_AD_STO3_CLK_SEL_SFT); | ||
1150 | } | ||
1151 | |||
1152 | if (filter_mask & RT5677_AD_STEREO4_FILTER) { | ||
1153 | asrc5_mask |= RT5677_AD_STO4_CLK_SEL_MASK; | ||
1154 | asrc5_value = (asrc5_value & ~RT5677_AD_STO4_CLK_SEL_MASK) | ||
1155 | | (clk_src << RT5677_AD_STO4_CLK_SEL_SFT); | ||
1156 | } | ||
1157 | |||
1158 | if (asrc5_mask) | ||
1159 | regmap_update_bits(rt5677->regmap, RT5677_ASRC_5, asrc5_mask, | ||
1160 | asrc5_value); | ||
1161 | |||
1162 | /* ASRC 6 */ | ||
1163 | if (filter_mask & RT5677_AD_MONO_L_FILTER) { | ||
1164 | asrc6_mask |= RT5677_AD_MONOL_CLK_SEL_MASK; | ||
1165 | asrc6_value = (asrc6_value & ~RT5677_AD_MONOL_CLK_SEL_MASK) | ||
1166 | | (clk_src << RT5677_AD_MONOL_CLK_SEL_SFT); | ||
1167 | } | ||
1168 | |||
1169 | if (filter_mask & RT5677_AD_MONO_R_FILTER) { | ||
1170 | asrc6_mask |= RT5677_AD_MONOR_CLK_SEL_MASK; | ||
1171 | asrc6_value = (asrc6_value & ~RT5677_AD_MONOR_CLK_SEL_MASK) | ||
1172 | | (clk_src << RT5677_AD_MONOR_CLK_SEL_SFT); | ||
1173 | } | ||
1174 | |||
1175 | if (asrc6_mask) | ||
1176 | regmap_update_bits(rt5677->regmap, RT5677_ASRC_6, asrc6_mask, | ||
1177 | asrc6_value); | ||
1178 | |||
1179 | /* ASRC 7 */ | ||
1180 | if (filter_mask & RT5677_DSP_OB_0_3_FILTER) { | ||
1181 | asrc7_mask |= RT5677_DSP_OB_0_3_CLK_SEL_MASK; | ||
1182 | asrc7_value = (asrc7_value & ~RT5677_DSP_OB_0_3_CLK_SEL_MASK) | ||
1183 | | (clk_src << RT5677_DSP_OB_0_3_CLK_SEL_SFT); | ||
1184 | } | ||
1185 | |||
1186 | if (filter_mask & RT5677_DSP_OB_4_7_FILTER) { | ||
1187 | asrc7_mask |= RT5677_DSP_OB_4_7_CLK_SEL_MASK; | ||
1188 | asrc7_value = (asrc7_value & ~RT5677_DSP_OB_4_7_CLK_SEL_MASK) | ||
1189 | | (clk_src << RT5677_DSP_OB_4_7_CLK_SEL_SFT); | ||
1190 | } | ||
1191 | |||
1192 | if (asrc7_mask) | ||
1193 | regmap_update_bits(rt5677->regmap, RT5677_ASRC_7, asrc7_mask, | ||
1194 | asrc7_value); | ||
1195 | |||
1196 | return 0; | ||
1197 | } | ||
1198 | EXPORT_SYMBOL_GPL(rt5677_sel_asrc_clk_src); | ||
1199 | |||
1024 | /* Digital Mixer */ | 1200 | /* Digital Mixer */ |
1025 | static const struct snd_kcontrol_new rt5677_sto1_adc_l_mix[] = { | 1201 | static const struct snd_kcontrol_new rt5677_sto1_adc_l_mix[] = { |
1026 | SOC_DAPM_SINGLE("ADC1 Switch", RT5677_STO1_ADC_MIXER, | 1202 | SOC_DAPM_SINGLE("ADC1 Switch", RT5677_STO1_ADC_MIXER, |
@@ -4500,10 +4676,10 @@ static int rt5677_suspend(struct snd_soc_codec *codec) | |||
4500 | if (!rt5677->dsp_vad_en) { | 4676 | if (!rt5677->dsp_vad_en) { |
4501 | regcache_cache_only(rt5677->regmap, true); | 4677 | regcache_cache_only(rt5677->regmap, true); |
4502 | regcache_mark_dirty(rt5677->regmap); | 4678 | regcache_mark_dirty(rt5677->regmap); |
4503 | } | ||
4504 | 4679 | ||
4505 | if (gpio_is_valid(rt5677->pow_ldo2)) | 4680 | if (gpio_is_valid(rt5677->pow_ldo2)) |
4506 | gpio_set_value_cansleep(rt5677->pow_ldo2, 0); | 4681 | gpio_set_value_cansleep(rt5677->pow_ldo2, 0); |
4682 | } | ||
4507 | 4683 | ||
4508 | return 0; | 4684 | return 0; |
4509 | } | 4685 | } |
@@ -4512,12 +4688,12 @@ static int rt5677_resume(struct snd_soc_codec *codec) | |||
4512 | { | 4688 | { |
4513 | struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); | 4689 | struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); |
4514 | 4690 | ||
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) { | 4691 | if (!rt5677->dsp_vad_en) { |
4692 | if (gpio_is_valid(rt5677->pow_ldo2)) { | ||
4693 | gpio_set_value_cansleep(rt5677->pow_ldo2, 1); | ||
4694 | msleep(10); | ||
4695 | } | ||
4696 | |||
4521 | regcache_cache_only(rt5677->regmap, false); | 4697 | regcache_cache_only(rt5677->regmap, false); |
4522 | regcache_sync(rt5677->regmap); | 4698 | regcache_sync(rt5677->regmap); |
4523 | } | 4699 | } |
@@ -4733,7 +4909,8 @@ static const struct regmap_config rt5677_regmap = { | |||
4733 | }; | 4909 | }; |
4734 | 4910 | ||
4735 | static const struct i2c_device_id rt5677_i2c_id[] = { | 4911 | static const struct i2c_device_id rt5677_i2c_id[] = { |
4736 | { "rt5677", 0 }, | 4912 | { "rt5677", RT5677 }, |
4913 | { "rt5676", RT5676 }, | ||
4737 | { } | 4914 | { } |
4738 | }; | 4915 | }; |
4739 | MODULE_DEVICE_TABLE(i2c, rt5677_i2c_id); | 4916 | MODULE_DEVICE_TABLE(i2c, rt5677_i2c_id); |
@@ -4850,6 +5027,8 @@ static int rt5677_i2c_probe(struct i2c_client *i2c, | |||
4850 | 5027 | ||
4851 | i2c_set_clientdata(i2c, rt5677); | 5028 | i2c_set_clientdata(i2c, rt5677); |
4852 | 5029 | ||
5030 | rt5677->type = id->driver_data; | ||
5031 | |||
4853 | if (pdata) | 5032 | if (pdata) |
4854 | rt5677->pdata = *pdata; | 5033 | rt5677->pdata = *pdata; |
4855 | 5034 | ||
diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h index c0a625f290cc..9dceb41d18ea 100644 --- a/sound/soc/codecs/rt5677.h +++ b/sound/soc/codecs/rt5677.h | |||
@@ -1406,6 +1406,46 @@ | |||
1406 | #define RT5677_DSP_CLK_SRC_PLL2 (0x0 << 7) | 1406 | #define RT5677_DSP_CLK_SRC_PLL2 (0x0 << 7) |
1407 | #define RT5677_DSP_CLK_SRC_BYPASS (0x1 << 7) | 1407 | #define RT5677_DSP_CLK_SRC_BYPASS (0x1 << 7) |
1408 | 1408 | ||
1409 | /* ASRC Control 3 (0x85) */ | ||
1410 | #define RT5677_DA_STO_CLK_SEL_MASK (0xf << 12) | ||
1411 | #define RT5677_DA_STO_CLK_SEL_SFT 12 | ||
1412 | #define RT5677_DA_MONO2L_CLK_SEL_MASK (0xf << 4) | ||
1413 | #define RT5677_DA_MONO2L_CLK_SEL_SFT 4 | ||
1414 | #define RT5677_DA_MONO2R_CLK_SEL_MASK (0xf << 0) | ||
1415 | #define RT5677_DA_MONO2R_CLK_SEL_SFT 0 | ||
1416 | |||
1417 | /* ASRC Control 4 (0x86) */ | ||
1418 | #define RT5677_DA_MONO3L_CLK_SEL_MASK (0xf << 12) | ||
1419 | #define RT5677_DA_MONO3L_CLK_SEL_SFT 12 | ||
1420 | #define RT5677_DA_MONO3R_CLK_SEL_MASK (0xf << 8) | ||
1421 | #define RT5677_DA_MONO3R_CLK_SEL_SFT 8 | ||
1422 | #define RT5677_DA_MONO4L_CLK_SEL_MASK (0xf << 4) | ||
1423 | #define RT5677_DA_MONO4L_CLK_SEL_SFT 4 | ||
1424 | #define RT5677_DA_MONO4R_CLK_SEL_MASK (0xf << 0) | ||
1425 | #define RT5677_DA_MONO4R_CLK_SEL_SFT 0 | ||
1426 | |||
1427 | /* ASRC Control 5 (0x87) */ | ||
1428 | #define RT5677_AD_STO1_CLK_SEL_MASK (0xf << 12) | ||
1429 | #define RT5677_AD_STO1_CLK_SEL_SFT 12 | ||
1430 | #define RT5677_AD_STO2_CLK_SEL_MASK (0xf << 8) | ||
1431 | #define RT5677_AD_STO2_CLK_SEL_SFT 8 | ||
1432 | #define RT5677_AD_STO3_CLK_SEL_MASK (0xf << 4) | ||
1433 | #define RT5677_AD_STO3_CLK_SEL_SFT 4 | ||
1434 | #define RT5677_AD_STO4_CLK_SEL_MASK (0xf << 0) | ||
1435 | #define RT5677_AD_STO4_CLK_SEL_SFT 0 | ||
1436 | |||
1437 | /* ASRC Control 6 (0x88) */ | ||
1438 | #define RT5677_AD_MONOL_CLK_SEL_MASK (0xf << 12) | ||
1439 | #define RT5677_AD_MONOL_CLK_SEL_SFT 12 | ||
1440 | #define RT5677_AD_MONOR_CLK_SEL_MASK (0xf << 8) | ||
1441 | #define RT5677_AD_MONOR_CLK_SEL_SFT 8 | ||
1442 | |||
1443 | /* ASRC Control 7 (0x89) */ | ||
1444 | #define RT5677_DSP_OB_0_3_CLK_SEL_MASK (0xf << 12) | ||
1445 | #define RT5677_DSP_OB_0_3_CLK_SEL_SFT 12 | ||
1446 | #define RT5677_DSP_OB_4_7_CLK_SEL_MASK (0xf << 8) | ||
1447 | #define RT5677_DSP_OB_4_7_CLK_SEL_SFT 8 | ||
1448 | |||
1409 | /* VAD Function Control 4 (0x9f) */ | 1449 | /* VAD Function Control 4 (0x9f) */ |
1410 | #define RT5677_VAD_SRC_MASK (0x7 << 8) | 1450 | #define RT5677_VAD_SRC_MASK (0x7 << 8) |
1411 | #define RT5677_VAD_SRC_SFT 8 | 1451 | #define RT5677_VAD_SRC_SFT 8 |
@@ -1665,6 +1705,47 @@ enum { | |||
1665 | RT5677_IRQ_JD3, | 1705 | RT5677_IRQ_JD3, |
1666 | }; | 1706 | }; |
1667 | 1707 | ||
1708 | enum rt5677_type { | ||
1709 | RT5677, | ||
1710 | RT5676, | ||
1711 | }; | ||
1712 | |||
1713 | /* ASRC clock source selection */ | ||
1714 | enum { | ||
1715 | RT5677_CLK_SEL_SYS, | ||
1716 | RT5677_CLK_SEL_I2S1_ASRC, | ||
1717 | RT5677_CLK_SEL_I2S2_ASRC, | ||
1718 | RT5677_CLK_SEL_I2S3_ASRC, | ||
1719 | RT5677_CLK_SEL_I2S4_ASRC, | ||
1720 | RT5677_CLK_SEL_I2S5_ASRC, | ||
1721 | RT5677_CLK_SEL_I2S6_ASRC, | ||
1722 | RT5677_CLK_SEL_SYS2, | ||
1723 | RT5677_CLK_SEL_SYS3, | ||
1724 | RT5677_CLK_SEL_SYS4, | ||
1725 | RT5677_CLK_SEL_SYS5, | ||
1726 | RT5677_CLK_SEL_SYS6, | ||
1727 | RT5677_CLK_SEL_SYS7, | ||
1728 | }; | ||
1729 | |||
1730 | /* filter mask */ | ||
1731 | enum { | ||
1732 | RT5677_DA_STEREO_FILTER = 0x1, | ||
1733 | RT5677_DA_MONO2_L_FILTER = (0x1 << 1), | ||
1734 | RT5677_DA_MONO2_R_FILTER = (0x1 << 2), | ||
1735 | RT5677_DA_MONO3_L_FILTER = (0x1 << 3), | ||
1736 | RT5677_DA_MONO3_R_FILTER = (0x1 << 4), | ||
1737 | RT5677_DA_MONO4_L_FILTER = (0x1 << 5), | ||
1738 | RT5677_DA_MONO4_R_FILTER = (0x1 << 6), | ||
1739 | RT5677_AD_STEREO1_FILTER = (0x1 << 7), | ||
1740 | RT5677_AD_STEREO2_FILTER = (0x1 << 8), | ||
1741 | RT5677_AD_STEREO3_FILTER = (0x1 << 9), | ||
1742 | RT5677_AD_STEREO4_FILTER = (0x1 << 10), | ||
1743 | RT5677_AD_MONO_L_FILTER = (0x1 << 11), | ||
1744 | RT5677_AD_MONO_R_FILTER = (0x1 << 12), | ||
1745 | RT5677_DSP_OB_0_3_FILTER = (0x1 << 13), | ||
1746 | RT5677_DSP_OB_4_7_FILTER = (0x1 << 14), | ||
1747 | }; | ||
1748 | |||
1668 | struct rt5677_priv { | 1749 | struct rt5677_priv { |
1669 | struct snd_soc_codec *codec; | 1750 | struct snd_soc_codec *codec; |
1670 | struct rt5677_platform_data pdata; | 1751 | struct rt5677_platform_data pdata; |
@@ -1681,6 +1762,7 @@ struct rt5677_priv { | |||
1681 | int pll_in; | 1762 | int pll_in; |
1682 | int pll_out; | 1763 | int pll_out; |
1683 | int pow_ldo2; /* POW_LDO2 pin */ | 1764 | int pow_ldo2; /* POW_LDO2 pin */ |
1765 | enum rt5677_type type; | ||
1684 | #ifdef CONFIG_GPIOLIB | 1766 | #ifdef CONFIG_GPIOLIB |
1685 | struct gpio_chip gpio_chip; | 1767 | struct gpio_chip gpio_chip; |
1686 | #endif | 1768 | #endif |
@@ -1690,4 +1772,7 @@ struct rt5677_priv { | |||
1690 | bool is_vref_slow; | 1772 | bool is_vref_slow; |
1691 | }; | 1773 | }; |
1692 | 1774 | ||
1775 | int rt5677_sel_asrc_clk_src(struct snd_soc_codec *codec, | ||
1776 | unsigned int filter_mask, unsigned int clk_src); | ||
1777 | |||
1693 | #endif /* __RT5677_H__ */ | 1778 | #endif /* __RT5677_H__ */ |
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 | ||
786 | static int sn95031_get_headset_state(struct snd_soc_jack *mfld_jack) | 786 | static 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 | ||
798 | void sn95031_jack_detection(struct mfld_jack_data *jack_data) | 799 | void 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 | ||
130 | extern void sn95031_jack_detection(struct mfld_jack_data *jack_data); | 130 | extern 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/tlv320aic23-i2c.c b/sound/soc/codecs/tlv320aic23-i2c.c index f13701995482..78a94af65518 100644 --- a/sound/soc/codecs/tlv320aic23-i2c.c +++ b/sound/soc/codecs/tlv320aic23-i2c.c | |||
@@ -31,7 +31,7 @@ static int tlv320aic23_i2c_probe(struct i2c_client *i2c, | |||
31 | return tlv320aic23_probe(&i2c->dev, regmap); | 31 | return tlv320aic23_probe(&i2c->dev, regmap); |
32 | } | 32 | } |
33 | 33 | ||
34 | static int __exit tlv320aic23_i2c_remove(struct i2c_client *i2c) | 34 | static int tlv320aic23_i2c_remove(struct i2c_client *i2c) |
35 | { | 35 | { |
36 | snd_soc_unregister_codec(&i2c->dev); | 36 | snd_soc_unregister_codec(&i2c->dev); |
37 | return 0; | 37 | return 0; |
@@ -56,7 +56,7 @@ static struct i2c_driver tlv320aic23_i2c_driver = { | |||
56 | .of_match_table = of_match_ptr(tlv320aic23_of_match), | 56 | .of_match_table = of_match_ptr(tlv320aic23_of_match), |
57 | }, | 57 | }, |
58 | .probe = tlv320aic23_i2c_probe, | 58 | .probe = tlv320aic23_i2c_probe, |
59 | .remove = __exit_p(tlv320aic23_i2c_remove), | 59 | .remove = tlv320aic23_i2c_remove, |
60 | .id_table = tlv320aic23_id, | 60 | .id_table = tlv320aic23_id, |
61 | }; | 61 | }; |
62 | 62 | ||
diff --git a/sound/soc/codecs/wm2200.c b/sound/soc/codecs/wm2200.c index 15599845a660..5a9da28f4f33 100644 --- a/sound/soc/codecs/wm2200.c +++ b/sound/soc/codecs/wm2200.c | |||
@@ -1554,7 +1554,6 @@ static int wm2200_probe(struct snd_soc_codec *codec) | |||
1554 | int ret; | 1554 | int ret; |
1555 | 1555 | ||
1556 | wm2200->codec = codec; | 1556 | wm2200->codec = codec; |
1557 | codec->dapm.bias_level = SND_SOC_BIAS_OFF; | ||
1558 | 1557 | ||
1559 | ret = snd_soc_add_codec_controls(codec, wm_adsp1_fw_controls, 2); | 1558 | ret = snd_soc_add_codec_controls(codec, wm_adsp1_fw_controls, 2); |
1560 | if (ret != 0) | 1559 | if (ret != 0) |
@@ -1942,6 +1941,7 @@ static int wm2200_set_fll(struct snd_soc_codec *codec, int fll_id, int source, | |||
1942 | struct wm2200_priv *wm2200 = snd_soc_codec_get_drvdata(codec); | 1941 | struct wm2200_priv *wm2200 = snd_soc_codec_get_drvdata(codec); |
1943 | struct _fll_div factors; | 1942 | struct _fll_div factors; |
1944 | int ret, i, timeout; | 1943 | int ret, i, timeout; |
1944 | unsigned long time_left; | ||
1945 | 1945 | ||
1946 | if (!Fout) { | 1946 | if (!Fout) { |
1947 | dev_dbg(codec->dev, "FLL disabled"); | 1947 | dev_dbg(codec->dev, "FLL disabled"); |
@@ -2021,9 +2021,10 @@ static int wm2200_set_fll(struct snd_soc_codec *codec, int fll_id, int source, | |||
2021 | /* Poll for the lock; will use the interrupt to exit quickly */ | 2021 | /* Poll for the lock; will use the interrupt to exit quickly */ |
2022 | for (i = 0; i < timeout; i++) { | 2022 | for (i = 0; i < timeout; i++) { |
2023 | if (i2c->irq) { | 2023 | if (i2c->irq) { |
2024 | ret = wait_for_completion_timeout(&wm2200->fll_lock, | 2024 | time_left = wait_for_completion_timeout( |
2025 | msecs_to_jiffies(25)); | 2025 | &wm2200->fll_lock, |
2026 | if (ret > 0) | 2026 | msecs_to_jiffies(25)); |
2027 | if (time_left > 0) | ||
2027 | break; | 2028 | break; |
2028 | } else { | 2029 | } else { |
2029 | msleep(1); | 2030 | msleep(1); |
diff --git a/sound/soc/codecs/wm5100.c b/sound/soc/codecs/wm5100.c index ea09db585aa1..96740379b711 100644 --- a/sound/soc/codecs/wm5100.c +++ b/sound/soc/codecs/wm5100.c | |||
@@ -1762,6 +1762,7 @@ static int wm5100_set_fll(struct snd_soc_codec *codec, int fll_id, int source, | |||
1762 | struct _fll_div factors; | 1762 | struct _fll_div factors; |
1763 | struct wm5100_fll *fll; | 1763 | struct wm5100_fll *fll; |
1764 | int ret, base, lock, i, timeout; | 1764 | int ret, base, lock, i, timeout; |
1765 | unsigned long time_left; | ||
1765 | 1766 | ||
1766 | switch (fll_id) { | 1767 | switch (fll_id) { |
1767 | case WM5100_FLL1: | 1768 | case WM5100_FLL1: |
@@ -1842,9 +1843,9 @@ static int wm5100_set_fll(struct snd_soc_codec *codec, int fll_id, int source, | |||
1842 | /* Poll for the lock; will use interrupt when we can test */ | 1843 | /* Poll for the lock; will use interrupt when we can test */ |
1843 | for (i = 0; i < timeout; i++) { | 1844 | for (i = 0; i < timeout; i++) { |
1844 | if (i2c->irq) { | 1845 | if (i2c->irq) { |
1845 | ret = wait_for_completion_timeout(&fll->lock, | 1846 | time_left = wait_for_completion_timeout(&fll->lock, |
1846 | msecs_to_jiffies(25)); | 1847 | msecs_to_jiffies(25)); |
1847 | if (ret > 0) | 1848 | if (time_left > 0) |
1848 | break; | 1849 | break; |
1849 | } else { | 1850 | } else { |
1850 | msleep(1); | 1851 | msleep(1); |
diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c index 6d0fe0ac95a3..0c6d1bc0526e 100644 --- a/sound/soc/codecs/wm5102.c +++ b/sound/soc/codecs/wm5102.c | |||
@@ -1861,7 +1861,6 @@ static unsigned int wm5102_digital_vu[] = { | |||
1861 | ARIZONA_DAC_DIGITAL_VOLUME_2L, | 1861 | ARIZONA_DAC_DIGITAL_VOLUME_2L, |
1862 | ARIZONA_DAC_DIGITAL_VOLUME_2R, | 1862 | ARIZONA_DAC_DIGITAL_VOLUME_2R, |
1863 | ARIZONA_DAC_DIGITAL_VOLUME_3L, | 1863 | ARIZONA_DAC_DIGITAL_VOLUME_3L, |
1864 | ARIZONA_DAC_DIGITAL_VOLUME_3R, | ||
1865 | ARIZONA_DAC_DIGITAL_VOLUME_4L, | 1864 | ARIZONA_DAC_DIGITAL_VOLUME_4L, |
1866 | ARIZONA_DAC_DIGITAL_VOLUME_4R, | 1865 | ARIZONA_DAC_DIGITAL_VOLUME_4R, |
1867 | ARIZONA_DAC_DIGITAL_VOLUME_5L, | 1866 | ARIZONA_DAC_DIGITAL_VOLUME_5L, |
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c index c81a9eab3e3e..c65e5a75fc1a 100644 --- a/sound/soc/codecs/wm8350.c +++ b/sound/soc/codecs/wm8350.c | |||
@@ -69,14 +69,14 @@ struct wm8350_data { | |||
69 | struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; | 69 | struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; |
70 | int fll_freq_out; | 70 | int fll_freq_out; |
71 | int fll_freq_in; | 71 | int fll_freq_in; |
72 | struct delayed_work pga_work; | ||
72 | }; | 73 | }; |
73 | 74 | ||
74 | /* | 75 | /* |
75 | * Ramp OUT1 PGA volume to minimise pops at stream startup and shutdown. | 76 | * Ramp OUT1 PGA volume to minimise pops at stream startup and shutdown. |
76 | */ | 77 | */ |
77 | static inline int wm8350_out1_ramp_step(struct snd_soc_codec *codec) | 78 | static inline int wm8350_out1_ramp_step(struct wm8350_data *wm8350_data) |
78 | { | 79 | { |
79 | struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec); | ||
80 | struct wm8350_output *out1 = &wm8350_data->out1; | 80 | struct wm8350_output *out1 = &wm8350_data->out1; |
81 | struct wm8350 *wm8350 = wm8350_data->wm8350; | 81 | struct wm8350 *wm8350 = wm8350_data->wm8350; |
82 | int left_complete = 0, right_complete = 0; | 82 | int left_complete = 0, right_complete = 0; |
@@ -140,9 +140,8 @@ static inline int wm8350_out1_ramp_step(struct snd_soc_codec *codec) | |||
140 | /* | 140 | /* |
141 | * Ramp OUT2 PGA volume to minimise pops at stream startup and shutdown. | 141 | * Ramp OUT2 PGA volume to minimise pops at stream startup and shutdown. |
142 | */ | 142 | */ |
143 | static inline int wm8350_out2_ramp_step(struct snd_soc_codec *codec) | 143 | static inline int wm8350_out2_ramp_step(struct wm8350_data *wm8350_data) |
144 | { | 144 | { |
145 | struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec); | ||
146 | struct wm8350_output *out2 = &wm8350_data->out2; | 145 | struct wm8350_output *out2 = &wm8350_data->out2; |
147 | struct wm8350 *wm8350 = wm8350_data->wm8350; | 146 | struct wm8350 *wm8350 = wm8350_data->wm8350; |
148 | int left_complete = 0, right_complete = 0; | 147 | int left_complete = 0, right_complete = 0; |
@@ -210,10 +209,8 @@ static inline int wm8350_out2_ramp_step(struct snd_soc_codec *codec) | |||
210 | */ | 209 | */ |
211 | static void wm8350_pga_work(struct work_struct *work) | 210 | static void wm8350_pga_work(struct work_struct *work) |
212 | { | 211 | { |
213 | struct snd_soc_dapm_context *dapm = | 212 | struct wm8350_data *wm8350_data = |
214 | container_of(work, struct snd_soc_dapm_context, delayed_work.work); | 213 | container_of(work, struct wm8350_data, pga_work.work); |
215 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm); | ||
216 | struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec); | ||
217 | struct wm8350_output *out1 = &wm8350_data->out1, | 214 | struct wm8350_output *out1 = &wm8350_data->out1, |
218 | *out2 = &wm8350_data->out2; | 215 | *out2 = &wm8350_data->out2; |
219 | int i, out1_complete, out2_complete; | 216 | int i, out1_complete, out2_complete; |
@@ -226,9 +223,9 @@ static void wm8350_pga_work(struct work_struct *work) | |||
226 | for (i = 0; i <= 63; i++) { | 223 | for (i = 0; i <= 63; i++) { |
227 | out1_complete = 1, out2_complete = 1; | 224 | out1_complete = 1, out2_complete = 1; |
228 | if (out1->ramp != WM8350_RAMP_NONE) | 225 | if (out1->ramp != WM8350_RAMP_NONE) |
229 | out1_complete = wm8350_out1_ramp_step(codec); | 226 | out1_complete = wm8350_out1_ramp_step(wm8350_data); |
230 | if (out2->ramp != WM8350_RAMP_NONE) | 227 | if (out2->ramp != WM8350_RAMP_NONE) |
231 | out2_complete = wm8350_out2_ramp_step(codec); | 228 | out2_complete = wm8350_out2_ramp_step(wm8350_data); |
232 | 229 | ||
233 | /* ramp finished ? */ | 230 | /* ramp finished ? */ |
234 | if (out1_complete && out2_complete) | 231 | if (out1_complete && out2_complete) |
@@ -283,7 +280,7 @@ static int pga_event(struct snd_soc_dapm_widget *w, | |||
283 | out->ramp = WM8350_RAMP_UP; | 280 | out->ramp = WM8350_RAMP_UP; |
284 | out->active = 1; | 281 | out->active = 1; |
285 | 282 | ||
286 | schedule_delayed_work(&codec->dapm.delayed_work, | 283 | schedule_delayed_work(&wm8350_data->pga_work, |
287 | msecs_to_jiffies(1)); | 284 | msecs_to_jiffies(1)); |
288 | break; | 285 | break; |
289 | 286 | ||
@@ -291,7 +288,7 @@ static int pga_event(struct snd_soc_dapm_widget *w, | |||
291 | out->ramp = WM8350_RAMP_DOWN; | 288 | out->ramp = WM8350_RAMP_DOWN; |
292 | out->active = 0; | 289 | out->active = 0; |
293 | 290 | ||
294 | schedule_delayed_work(&codec->dapm.delayed_work, | 291 | schedule_delayed_work(&wm8350_data->pga_work, |
295 | msecs_to_jiffies(1)); | 292 | msecs_to_jiffies(1)); |
296 | break; | 293 | break; |
297 | } | 294 | } |
@@ -1492,7 +1489,7 @@ static int wm8350_codec_probe(struct snd_soc_codec *codec) | |||
1492 | /* Put the codec into reset if it wasn't already */ | 1489 | /* Put the codec into reset if it wasn't already */ |
1493 | wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA); | 1490 | wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA); |
1494 | 1491 | ||
1495 | INIT_DELAYED_WORK(&codec->dapm.delayed_work, wm8350_pga_work); | 1492 | INIT_DELAYED_WORK(&priv->pga_work, wm8350_pga_work); |
1496 | INIT_DELAYED_WORK(&priv->hpl.work, wm8350_hpl_work); | 1493 | INIT_DELAYED_WORK(&priv->hpl.work, wm8350_hpl_work); |
1497 | INIT_DELAYED_WORK(&priv->hpr.work, wm8350_hpr_work); | 1494 | INIT_DELAYED_WORK(&priv->hpr.work, wm8350_hpr_work); |
1498 | 1495 | ||
@@ -1578,7 +1575,7 @@ static int wm8350_codec_remove(struct snd_soc_codec *codec) | |||
1578 | 1575 | ||
1579 | /* if there was any work waiting then we run it now and | 1576 | /* if there was any work waiting then we run it now and |
1580 | * wait for its completion */ | 1577 | * wait for its completion */ |
1581 | flush_delayed_work(&codec->dapm.delayed_work); | 1578 | flush_delayed_work(&priv->pga_work); |
1582 | 1579 | ||
1583 | wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA); | 1580 | wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA); |
1584 | 1581 | ||
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c index c6d10533e2bd..2245b6a32f3d 100644 --- a/sound/soc/codecs/wm8731.c +++ b/sound/soc/codecs/wm8731.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/spi/spi.h> | 25 | #include <linux/spi/spi.h> |
26 | #include <linux/of_device.h> | 26 | #include <linux/of_device.h> |
27 | #include <linux/mutex.h> | 27 | #include <linux/mutex.h> |
28 | #include <linux/clk.h> | ||
28 | #include <sound/core.h> | 29 | #include <sound/core.h> |
29 | #include <sound/pcm.h> | 30 | #include <sound/pcm.h> |
30 | #include <sound/pcm_params.h> | 31 | #include <sound/pcm_params.h> |
@@ -45,6 +46,7 @@ static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = { | |||
45 | /* codec private data */ | 46 | /* codec private data */ |
46 | struct wm8731_priv { | 47 | struct wm8731_priv { |
47 | struct regmap *regmap; | 48 | struct regmap *regmap; |
49 | struct clk *mclk; | ||
48 | struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES]; | 50 | struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES]; |
49 | const struct snd_pcm_hw_constraint_list *constraints; | 51 | const struct snd_pcm_hw_constraint_list *constraints; |
50 | unsigned int sysclk; | 52 | unsigned int sysclk; |
@@ -390,6 +392,8 @@ static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai, | |||
390 | switch (clk_id) { | 392 | switch (clk_id) { |
391 | case WM8731_SYSCLK_XTAL: | 393 | case WM8731_SYSCLK_XTAL: |
392 | case WM8731_SYSCLK_MCLK: | 394 | case WM8731_SYSCLK_MCLK: |
395 | if (wm8731->mclk && clk_set_rate(wm8731->mclk, freq)) | ||
396 | return -EINVAL; | ||
393 | wm8731->sysclk_type = clk_id; | 397 | wm8731->sysclk_type = clk_id; |
394 | break; | 398 | break; |
395 | default: | 399 | default: |
@@ -491,6 +495,8 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec, | |||
491 | 495 | ||
492 | switch (level) { | 496 | switch (level) { |
493 | case SND_SOC_BIAS_ON: | 497 | case SND_SOC_BIAS_ON: |
498 | if (wm8731->mclk) | ||
499 | clk_prepare_enable(wm8731->mclk); | ||
494 | break; | 500 | break; |
495 | case SND_SOC_BIAS_PREPARE: | 501 | case SND_SOC_BIAS_PREPARE: |
496 | break; | 502 | break; |
@@ -509,6 +515,8 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec, | |||
509 | snd_soc_write(codec, WM8731_PWR, reg | 0x0040); | 515 | snd_soc_write(codec, WM8731_PWR, reg | 0x0040); |
510 | break; | 516 | break; |
511 | case SND_SOC_BIAS_OFF: | 517 | case SND_SOC_BIAS_OFF: |
518 | if (wm8731->mclk) | ||
519 | clk_disable_unprepare(wm8731->mclk); | ||
512 | snd_soc_write(codec, WM8731_PWR, 0xffff); | 520 | snd_soc_write(codec, WM8731_PWR, 0xffff); |
513 | regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), | 521 | regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), |
514 | wm8731->supplies); | 522 | wm8731->supplies); |
@@ -667,6 +675,19 @@ static int wm8731_spi_probe(struct spi_device *spi) | |||
667 | if (wm8731 == NULL) | 675 | if (wm8731 == NULL) |
668 | return -ENOMEM; | 676 | return -ENOMEM; |
669 | 677 | ||
678 | wm8731->mclk = devm_clk_get(&spi->dev, "mclk"); | ||
679 | if (IS_ERR(wm8731->mclk)) { | ||
680 | ret = PTR_ERR(wm8731->mclk); | ||
681 | if (ret == -ENOENT) { | ||
682 | wm8731->mclk = NULL; | ||
683 | dev_warn(&spi->dev, "Assuming static MCLK\n"); | ||
684 | } else { | ||
685 | dev_err(&spi->dev, "Failed to get MCLK: %d\n", | ||
686 | ret); | ||
687 | return ret; | ||
688 | } | ||
689 | } | ||
690 | |||
670 | mutex_init(&wm8731->lock); | 691 | mutex_init(&wm8731->lock); |
671 | 692 | ||
672 | wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap); | 693 | wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap); |
@@ -718,6 +739,19 @@ static int wm8731_i2c_probe(struct i2c_client *i2c, | |||
718 | if (wm8731 == NULL) | 739 | if (wm8731 == NULL) |
719 | return -ENOMEM; | 740 | return -ENOMEM; |
720 | 741 | ||
742 | wm8731->mclk = devm_clk_get(&i2c->dev, "mclk"); | ||
743 | if (IS_ERR(wm8731->mclk)) { | ||
744 | ret = PTR_ERR(wm8731->mclk); | ||
745 | if (ret == -ENOENT) { | ||
746 | wm8731->mclk = NULL; | ||
747 | dev_warn(&i2c->dev, "Assuming static MCLK\n"); | ||
748 | } else { | ||
749 | dev_err(&i2c->dev, "Failed to get MCLK: %d\n", | ||
750 | ret); | ||
751 | return ret; | ||
752 | } | ||
753 | } | ||
754 | |||
721 | mutex_init(&wm8731->lock); | 755 | mutex_init(&wm8731->lock); |
722 | 756 | ||
723 | wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap); | 757 | wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap); |
diff --git a/sound/soc/codecs/wm8741.c b/sound/soc/codecs/wm8741.c index 31bb4801a005..9e71c768966f 100644 --- a/sound/soc/codecs/wm8741.c +++ b/sound/soc/codecs/wm8741.c | |||
@@ -123,7 +123,7 @@ static struct { | |||
123 | }; | 123 | }; |
124 | 124 | ||
125 | static const unsigned int rates_11289[] = { | 125 | static const unsigned int rates_11289[] = { |
126 | 44100, 88235, | 126 | 44100, 88200, |
127 | }; | 127 | }; |
128 | 128 | ||
129 | static const struct snd_pcm_hw_constraint_list constraints_11289 = { | 129 | static const struct snd_pcm_hw_constraint_list constraints_11289 = { |
@@ -150,7 +150,7 @@ static const struct snd_pcm_hw_constraint_list constraints_16384 = { | |||
150 | }; | 150 | }; |
151 | 151 | ||
152 | static const unsigned int rates_16934[] = { | 152 | static const unsigned int rates_16934[] = { |
153 | 44100, 88235, | 153 | 44100, 88200, |
154 | }; | 154 | }; |
155 | 155 | ||
156 | static const struct snd_pcm_hw_constraint_list constraints_16934 = { | 156 | static const struct snd_pcm_hw_constraint_list constraints_16934 = { |
@@ -168,7 +168,7 @@ static const struct snd_pcm_hw_constraint_list constraints_18432 = { | |||
168 | }; | 168 | }; |
169 | 169 | ||
170 | static const unsigned int rates_22579[] = { | 170 | static const unsigned int rates_22579[] = { |
171 | 44100, 88235, 1764000 | 171 | 44100, 88200, 176400 |
172 | }; | 172 | }; |
173 | 173 | ||
174 | static const struct snd_pcm_hw_constraint_list constraints_22579 = { | 174 | static const struct snd_pcm_hw_constraint_list constraints_22579 = { |
@@ -186,7 +186,7 @@ static const struct snd_pcm_hw_constraint_list constraints_24576 = { | |||
186 | }; | 186 | }; |
187 | 187 | ||
188 | static const unsigned int rates_36864[] = { | 188 | static const unsigned int rates_36864[] = { |
189 | 48000, 96000, 19200 | 189 | 48000, 96000, 192000 |
190 | }; | 190 | }; |
191 | 191 | ||
192 | static const struct snd_pcm_hw_constraint_list constraints_36864 = { | 192 | static const struct snd_pcm_hw_constraint_list constraints_36864 = { |
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c index 21ca3a94fc96..c50a5959345f 100644 --- a/sound/soc/codecs/wm8753.c +++ b/sound/soc/codecs/wm8753.c | |||
@@ -153,6 +153,7 @@ struct wm8753_priv { | |||
153 | unsigned int hifi_fmt; | 153 | unsigned int hifi_fmt; |
154 | 154 | ||
155 | int dai_func; | 155 | int dai_func; |
156 | struct delayed_work charge_work; | ||
156 | }; | 157 | }; |
157 | 158 | ||
158 | #define wm8753_reset(c) snd_soc_write(c, WM8753_RESET, 0) | 159 | #define wm8753_reset(c) snd_soc_write(c, WM8753_RESET, 0) |
@@ -1326,9 +1327,19 @@ static int wm8753_mute(struct snd_soc_dai *dai, int mute) | |||
1326 | return 0; | 1327 | return 0; |
1327 | } | 1328 | } |
1328 | 1329 | ||
1330 | static void wm8753_charge_work(struct work_struct *work) | ||
1331 | { | ||
1332 | struct wm8753_priv *wm8753 = | ||
1333 | container_of(work, struct wm8753_priv, charge_work.work); | ||
1334 | |||
1335 | /* Set to 500k */ | ||
1336 | regmap_update_bits(wm8753->regmap, WM8753_PWR1, 0x0180, 0x0100); | ||
1337 | } | ||
1338 | |||
1329 | static int wm8753_set_bias_level(struct snd_soc_codec *codec, | 1339 | static int wm8753_set_bias_level(struct snd_soc_codec *codec, |
1330 | enum snd_soc_bias_level level) | 1340 | enum snd_soc_bias_level level) |
1331 | { | 1341 | { |
1342 | struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); | ||
1332 | u16 pwr_reg = snd_soc_read(codec, WM8753_PWR1) & 0xfe3e; | 1343 | u16 pwr_reg = snd_soc_read(codec, WM8753_PWR1) & 0xfe3e; |
1333 | 1344 | ||
1334 | switch (level) { | 1345 | switch (level) { |
@@ -1337,14 +1348,22 @@ static int wm8753_set_bias_level(struct snd_soc_codec *codec, | |||
1337 | snd_soc_write(codec, WM8753_PWR1, pwr_reg | 0x00c0); | 1348 | snd_soc_write(codec, WM8753_PWR1, pwr_reg | 0x00c0); |
1338 | break; | 1349 | break; |
1339 | case SND_SOC_BIAS_PREPARE: | 1350 | case SND_SOC_BIAS_PREPARE: |
1340 | /* set vmid to 5k for quick power up */ | 1351 | /* Wait until fully charged */ |
1341 | snd_soc_write(codec, WM8753_PWR1, pwr_reg | 0x01c1); | 1352 | flush_delayed_work(&wm8753->charge_work); |
1342 | break; | 1353 | break; |
1343 | case SND_SOC_BIAS_STANDBY: | 1354 | case SND_SOC_BIAS_STANDBY: |
1344 | /* mute dac and set vmid to 500k, enable VREF */ | 1355 | if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { |
1345 | snd_soc_write(codec, WM8753_PWR1, pwr_reg | 0x0141); | 1356 | /* set vmid to 5k for quick power up */ |
1357 | snd_soc_write(codec, WM8753_PWR1, pwr_reg | 0x01c1); | ||
1358 | schedule_delayed_work(&wm8753->charge_work, | ||
1359 | msecs_to_jiffies(caps_charge)); | ||
1360 | } else { | ||
1361 | /* mute dac and set vmid to 500k, enable VREF */ | ||
1362 | snd_soc_write(codec, WM8753_PWR1, pwr_reg | 0x0141); | ||
1363 | } | ||
1346 | break; | 1364 | break; |
1347 | case SND_SOC_BIAS_OFF: | 1365 | case SND_SOC_BIAS_OFF: |
1366 | cancel_delayed_work_sync(&wm8753->charge_work); | ||
1348 | snd_soc_write(codec, WM8753_PWR1, 0x0001); | 1367 | snd_soc_write(codec, WM8753_PWR1, 0x0001); |
1349 | break; | 1368 | break; |
1350 | } | 1369 | } |
@@ -1428,38 +1447,12 @@ static struct snd_soc_dai_driver wm8753_dai[] = { | |||
1428 | }, | 1447 | }, |
1429 | }; | 1448 | }; |
1430 | 1449 | ||
1431 | static void wm8753_work(struct work_struct *work) | ||
1432 | { | ||
1433 | struct snd_soc_dapm_context *dapm = | ||
1434 | container_of(work, struct snd_soc_dapm_context, | ||
1435 | delayed_work.work); | ||
1436 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm); | ||
1437 | wm8753_set_bias_level(codec, dapm->bias_level); | ||
1438 | } | ||
1439 | |||
1440 | static int wm8753_suspend(struct snd_soc_codec *codec) | ||
1441 | { | ||
1442 | wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
1443 | return 0; | ||
1444 | } | ||
1445 | |||
1446 | static int wm8753_resume(struct snd_soc_codec *codec) | 1450 | static int wm8753_resume(struct snd_soc_codec *codec) |
1447 | { | 1451 | { |
1448 | struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); | 1452 | struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); |
1449 | 1453 | ||
1450 | regcache_sync(wm8753->regmap); | 1454 | regcache_sync(wm8753->regmap); |
1451 | 1455 | ||
1452 | wm8753_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
1453 | |||
1454 | /* charge wm8753 caps */ | ||
1455 | if (codec->dapm.suspend_bias_level == SND_SOC_BIAS_ON) { | ||
1456 | wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE); | ||
1457 | codec->dapm.bias_level = SND_SOC_BIAS_ON; | ||
1458 | queue_delayed_work(system_power_efficient_wq, | ||
1459 | &codec->dapm.delayed_work, | ||
1460 | msecs_to_jiffies(caps_charge)); | ||
1461 | } | ||
1462 | |||
1463 | return 0; | 1456 | return 0; |
1464 | } | 1457 | } |
1465 | 1458 | ||
@@ -1468,7 +1461,7 @@ static int wm8753_probe(struct snd_soc_codec *codec) | |||
1468 | struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); | 1461 | struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); |
1469 | int ret; | 1462 | int ret; |
1470 | 1463 | ||
1471 | INIT_DELAYED_WORK(&codec->dapm.delayed_work, wm8753_work); | 1464 | INIT_DELAYED_WORK(&wm8753->charge_work, wm8753_charge_work); |
1472 | 1465 | ||
1473 | ret = wm8753_reset(codec); | 1466 | ret = wm8753_reset(codec); |
1474 | if (ret < 0) { | 1467 | if (ret < 0) { |
@@ -1476,14 +1469,8 @@ static int wm8753_probe(struct snd_soc_codec *codec) | |||
1476 | return ret; | 1469 | return ret; |
1477 | } | 1470 | } |
1478 | 1471 | ||
1479 | wm8753_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
1480 | wm8753->dai_func = 0; | 1472 | wm8753->dai_func = 0; |
1481 | 1473 | ||
1482 | /* charge output caps */ | ||
1483 | wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE); | ||
1484 | schedule_delayed_work(&codec->dapm.delayed_work, | ||
1485 | msecs_to_jiffies(caps_charge)); | ||
1486 | |||
1487 | /* set the update bits */ | 1474 | /* set the update bits */ |
1488 | snd_soc_update_bits(codec, WM8753_LDAC, 0x0100, 0x0100); | 1475 | snd_soc_update_bits(codec, WM8753_LDAC, 0x0100, 0x0100); |
1489 | snd_soc_update_bits(codec, WM8753_RDAC, 0x0100, 0x0100); | 1476 | snd_soc_update_bits(codec, WM8753_RDAC, 0x0100, 0x0100); |
@@ -1499,21 +1486,11 @@ static int wm8753_probe(struct snd_soc_codec *codec) | |||
1499 | return 0; | 1486 | return 0; |
1500 | } | 1487 | } |
1501 | 1488 | ||
1502 | /* power down chip */ | ||
1503 | static int wm8753_remove(struct snd_soc_codec *codec) | ||
1504 | { | ||
1505 | flush_delayed_work(&codec->dapm.delayed_work); | ||
1506 | wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
1507 | |||
1508 | return 0; | ||
1509 | } | ||
1510 | |||
1511 | static struct snd_soc_codec_driver soc_codec_dev_wm8753 = { | 1489 | static struct snd_soc_codec_driver soc_codec_dev_wm8753 = { |
1512 | .probe = wm8753_probe, | 1490 | .probe = wm8753_probe, |
1513 | .remove = wm8753_remove, | ||
1514 | .suspend = wm8753_suspend, | ||
1515 | .resume = wm8753_resume, | 1491 | .resume = wm8753_resume, |
1516 | .set_bias_level = wm8753_set_bias_level, | 1492 | .set_bias_level = wm8753_set_bias_level, |
1493 | .suspend_bias_off = true, | ||
1517 | 1494 | ||
1518 | .controls = wm8753_snd_controls, | 1495 | .controls = wm8753_snd_controls, |
1519 | .num_controls = ARRAY_SIZE(wm8753_snd_controls), | 1496 | .num_controls = ARRAY_SIZE(wm8753_snd_controls), |
diff --git a/sound/soc/codecs/wm8804-i2c.c b/sound/soc/codecs/wm8804-i2c.c new file mode 100644 index 000000000000..6596f5f3a0c3 --- /dev/null +++ b/sound/soc/codecs/wm8804-i2c.c | |||
@@ -0,0 +1,65 @@ | |||
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 | |||
19 | static 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 | |||
31 | static int wm8804_i2c_remove(struct i2c_client *i2c) | ||
32 | { | ||
33 | wm8804_remove(&i2c->dev); | ||
34 | return 0; | ||
35 | } | ||
36 | |||
37 | static const struct i2c_device_id wm8804_i2c_id[] = { | ||
38 | { "wm8804", 0 }, | ||
39 | { } | ||
40 | }; | ||
41 | MODULE_DEVICE_TABLE(i2c, wm8804_i2c_id); | ||
42 | |||
43 | static const struct of_device_id wm8804_of_match[] = { | ||
44 | { .compatible = "wlf,wm8804", }, | ||
45 | { } | ||
46 | }; | ||
47 | MODULE_DEVICE_TABLE(of, wm8804_of_match); | ||
48 | |||
49 | static struct i2c_driver wm8804_i2c_driver = { | ||
50 | .driver = { | ||
51 | .name = "wm8804", | ||
52 | .owner = THIS_MODULE, | ||
53 | .pm = &wm8804_pm, | ||
54 | .of_match_table = wm8804_of_match, | ||
55 | }, | ||
56 | .probe = wm8804_i2c_probe, | ||
57 | .remove = wm8804_i2c_remove, | ||
58 | .id_table = wm8804_i2c_id | ||
59 | }; | ||
60 | |||
61 | module_i2c_driver(wm8804_i2c_driver); | ||
62 | |||
63 | MODULE_DESCRIPTION("ASoC WM8804 driver - I2C"); | ||
64 | MODULE_AUTHOR("Charles Keepax <ckeepax@opensource.wolfsonmicro.com>"); | ||
65 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/codecs/wm8804-spi.c b/sound/soc/codecs/wm8804-spi.c new file mode 100644 index 000000000000..407a3cf391e5 --- /dev/null +++ b/sound/soc/codecs/wm8804-spi.c | |||
@@ -0,0 +1,57 @@ | |||
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 | |||
19 | static 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 | |||
30 | static int wm8804_spi_remove(struct spi_device *spi) | ||
31 | { | ||
32 | wm8804_remove(&spi->dev); | ||
33 | return 0; | ||
34 | } | ||
35 | |||
36 | static const struct of_device_id wm8804_of_match[] = { | ||
37 | { .compatible = "wlf,wm8804", }, | ||
38 | { } | ||
39 | }; | ||
40 | MODULE_DEVICE_TABLE(of, wm8804_of_match); | ||
41 | |||
42 | static struct spi_driver wm8804_spi_driver = { | ||
43 | .driver = { | ||
44 | .name = "wm8804", | ||
45 | .owner = THIS_MODULE, | ||
46 | .pm = &wm8804_pm, | ||
47 | .of_match_table = wm8804_of_match, | ||
48 | }, | ||
49 | .probe = wm8804_spi_probe, | ||
50 | .remove = wm8804_spi_remove | ||
51 | }; | ||
52 | |||
53 | module_spi_driver(wm8804_spi_driver); | ||
54 | |||
55 | MODULE_DESCRIPTION("ASoC WM8804 driver - SPI"); | ||
56 | MODULE_AUTHOR("Charles Keepax <ckeepax@opensource.wolfsonmicro.com>"); | ||
57 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/codecs/wm8804.c b/sound/soc/codecs/wm8804.c index b2b0e68f707e..1e403f67cf16 100644 --- a/sound/soc/codecs/wm8804.c +++ b/sound/soc/codecs/wm8804.c | |||
@@ -13,12 +13,11 @@ | |||
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/moduleparam.h> | 14 | #include <linux/moduleparam.h> |
15 | #include <linux/init.h> | 15 | #include <linux/init.h> |
16 | #include <linux/gpio/consumer.h> | ||
16 | #include <linux/delay.h> | 17 | #include <linux/delay.h> |
17 | #include <linux/pm.h> | 18 | #include <linux/pm.h> |
18 | #include <linux/i2c.h> | 19 | #include <linux/pm_runtime.h> |
19 | #include <linux/of_device.h> | 20 | #include <linux/of_device.h> |
20 | #include <linux/spi/spi.h> | ||
21 | #include <linux/regmap.h> | ||
22 | #include <linux/regulator/consumer.h> | 21 | #include <linux/regulator/consumer.h> |
23 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
24 | #include <sound/core.h> | 23 | #include <sound/core.h> |
@@ -27,6 +26,7 @@ | |||
27 | #include <sound/soc.h> | 26 | #include <sound/soc.h> |
28 | #include <sound/initval.h> | 27 | #include <sound/initval.h> |
29 | #include <sound/tlv.h> | 28 | #include <sound/tlv.h> |
29 | #include <sound/soc-dapm.h> | ||
30 | 30 | ||
31 | #include "wm8804.h" | 31 | #include "wm8804.h" |
32 | 32 | ||
@@ -60,18 +60,23 @@ static const struct reg_default wm8804_reg_defaults[] = { | |||
60 | }; | 60 | }; |
61 | 61 | ||
62 | struct wm8804_priv { | 62 | struct wm8804_priv { |
63 | struct device *dev; | ||
63 | struct regmap *regmap; | 64 | struct regmap *regmap; |
64 | struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES]; | 65 | struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES]; |
65 | struct notifier_block disable_nb[WM8804_NUM_SUPPLIES]; | 66 | struct notifier_block disable_nb[WM8804_NUM_SUPPLIES]; |
66 | int mclk_div; | 67 | int mclk_div; |
67 | }; | ||
68 | 68 | ||
69 | static int txsrc_get(struct snd_kcontrol *kcontrol, | 69 | struct gpio_desc *reset; |
70 | struct snd_ctl_elem_value *ucontrol); | 70 | |
71 | int aif_pwr; | ||
72 | }; | ||
71 | 73 | ||
72 | static int txsrc_put(struct snd_kcontrol *kcontrol, | 74 | static int txsrc_put(struct snd_kcontrol *kcontrol, |
73 | struct snd_ctl_elem_value *ucontrol); | 75 | struct snd_ctl_elem_value *ucontrol); |
74 | 76 | ||
77 | static int wm8804_aif_event(struct snd_soc_dapm_widget *w, | ||
78 | struct snd_kcontrol *kcontrol, int event); | ||
79 | |||
75 | /* | 80 | /* |
76 | * We can't use the same notifier block for more than one supply and | 81 | * We can't use the same notifier block for more than one supply and |
77 | * there's no way I can see to get from a callback to the caller | 82 | * there's no way I can see to get from a callback to the caller |
@@ -93,26 +98,62 @@ WM8804_REGULATOR_EVENT(0) | |||
93 | WM8804_REGULATOR_EVENT(1) | 98 | WM8804_REGULATOR_EVENT(1) |
94 | 99 | ||
95 | static const char *txsrc_text[] = { "S/PDIF RX", "AIF" }; | 100 | static const char *txsrc_text[] = { "S/PDIF RX", "AIF" }; |
96 | static SOC_ENUM_SINGLE_EXT_DECL(txsrc, txsrc_text); | 101 | static const SOC_ENUM_SINGLE_DECL(txsrc, WM8804_SPDTX4, 6, txsrc_text); |
97 | 102 | ||
98 | static const struct snd_kcontrol_new wm8804_snd_controls[] = { | 103 | static const struct snd_kcontrol_new wm8804_tx_source_mux[] = { |
99 | SOC_ENUM_EXT("Input Source", txsrc, txsrc_get, txsrc_put), | 104 | SOC_DAPM_ENUM_EXT("Input Source", txsrc, |
100 | SOC_SINGLE("TX Playback Switch", WM8804_PWRDN, 2, 1, 1), | 105 | snd_soc_dapm_get_enum_double, txsrc_put), |
101 | SOC_SINGLE("AIF Playback Switch", WM8804_PWRDN, 4, 1, 1) | ||
102 | }; | 106 | }; |
103 | 107 | ||
104 | static int txsrc_get(struct snd_kcontrol *kcontrol, | 108 | static const struct snd_soc_dapm_widget wm8804_dapm_widgets[] = { |
105 | struct snd_ctl_elem_value *ucontrol) | 109 | SND_SOC_DAPM_OUTPUT("SPDIF Out"), |
106 | { | 110 | SND_SOC_DAPM_INPUT("SPDIF In"), |
107 | struct snd_soc_codec *codec; | 111 | |
108 | unsigned int src; | 112 | SND_SOC_DAPM_PGA("SPDIFTX", WM8804_PWRDN, 2, 1, NULL, 0), |
113 | SND_SOC_DAPM_PGA("SPDIFRX", WM8804_PWRDN, 1, 1, NULL, 0), | ||
114 | |||
115 | SND_SOC_DAPM_MUX("Tx Source", SND_SOC_NOPM, 6, 0, wm8804_tx_source_mux), | ||
116 | |||
117 | SND_SOC_DAPM_AIF_OUT_E("AIFTX", NULL, 0, SND_SOC_NOPM, 0, 0, wm8804_aif_event, | ||
118 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), | ||
119 | SND_SOC_DAPM_AIF_IN_E("AIFRX", NULL, 0, SND_SOC_NOPM, 0, 0, wm8804_aif_event, | ||
120 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), | ||
121 | }; | ||
122 | |||
123 | static const struct snd_soc_dapm_route wm8804_dapm_routes[] = { | ||
124 | { "AIFRX", NULL, "Playback" }, | ||
125 | { "Tx Source", "AIF", "AIFRX" }, | ||
109 | 126 | ||
110 | codec = snd_soc_kcontrol_codec(kcontrol); | 127 | { "SPDIFRX", NULL, "SPDIF In" }, |
111 | src = snd_soc_read(codec, WM8804_SPDTX4); | 128 | { "Tx Source", "S/PDIF RX", "SPDIFRX" }, |
112 | if (src & 0x40) | 129 | |
113 | ucontrol->value.integer.value[0] = 1; | 130 | { "SPDIFTX", NULL, "Tx Source" }, |
114 | else | 131 | { "SPDIF Out", NULL, "SPDIFTX" }, |
115 | ucontrol->value.integer.value[0] = 0; | 132 | |
133 | { "AIFTX", NULL, "SPDIFRX" }, | ||
134 | { "Capture", NULL, "AIFTX" }, | ||
135 | }; | ||
136 | |||
137 | static int wm8804_aif_event(struct snd_soc_dapm_widget *w, | ||
138 | struct snd_kcontrol *kcontrol, int event) | ||
139 | { | ||
140 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); | ||
141 | struct wm8804_priv *wm8804 = snd_soc_codec_get_drvdata(codec); | ||
142 | |||
143 | switch (event) { | ||
144 | case SND_SOC_DAPM_POST_PMU: | ||
145 | /* power up the aif */ | ||
146 | if (!wm8804->aif_pwr) | ||
147 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x10, 0x0); | ||
148 | wm8804->aif_pwr++; | ||
149 | break; | ||
150 | case SND_SOC_DAPM_POST_PMD: | ||
151 | /* power down only both paths are disabled */ | ||
152 | wm8804->aif_pwr--; | ||
153 | if (!wm8804->aif_pwr) | ||
154 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x10, 0x10); | ||
155 | break; | ||
156 | } | ||
116 | 157 | ||
117 | return 0; | 158 | return 0; |
118 | } | 159 | } |
@@ -120,48 +161,33 @@ static int txsrc_get(struct snd_kcontrol *kcontrol, | |||
120 | static int txsrc_put(struct snd_kcontrol *kcontrol, | 161 | static int txsrc_put(struct snd_kcontrol *kcontrol, |
121 | struct snd_ctl_elem_value *ucontrol) | 162 | struct snd_ctl_elem_value *ucontrol) |
122 | { | 163 | { |
123 | struct snd_soc_codec *codec; | 164 | struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); |
124 | unsigned int src, txpwr; | 165 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
166 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; | ||
167 | unsigned int val = ucontrol->value.enumerated.item[0] << e->shift_l; | ||
168 | unsigned int mask = 1 << e->shift_l; | ||
169 | unsigned int txpwr; | ||
170 | |||
171 | if (val != 0 && val != mask) | ||
172 | return -EINVAL; | ||
125 | 173 | ||
126 | codec = snd_soc_kcontrol_codec(kcontrol); | 174 | snd_soc_dapm_mutex_lock(dapm); |
127 | 175 | ||
128 | if (ucontrol->value.integer.value[0] != 0 | 176 | if (snd_soc_test_bits(codec, e->reg, mask, val)) { |
129 | && ucontrol->value.integer.value[0] != 1) | 177 | /* save the current power state of the transmitter */ |
130 | return -EINVAL; | 178 | txpwr = snd_soc_read(codec, WM8804_PWRDN) & 0x4; |
131 | 179 | ||
132 | src = snd_soc_read(codec, WM8804_SPDTX4); | 180 | /* power down the transmitter */ |
133 | switch ((src & 0x40) >> 6) { | 181 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x4); |
134 | case 0: | ||
135 | if (!ucontrol->value.integer.value[0]) | ||
136 | return 0; | ||
137 | break; | ||
138 | case 1: | ||
139 | if (ucontrol->value.integer.value[1]) | ||
140 | return 0; | ||
141 | break; | ||
142 | } | ||
143 | 182 | ||
144 | /* save the current power state of the transmitter */ | 183 | /* set the tx source */ |
145 | txpwr = snd_soc_read(codec, WM8804_PWRDN) & 0x4; | 184 | snd_soc_update_bits(codec, e->reg, mask, val); |
146 | /* power down the transmitter */ | 185 | |
147 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x4); | 186 | /* restore the transmitter's configuration */ |
148 | /* set the tx source */ | 187 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, txpwr); |
149 | snd_soc_update_bits(codec, WM8804_SPDTX4, 0x40, | ||
150 | ucontrol->value.integer.value[0] << 6); | ||
151 | |||
152 | if (ucontrol->value.integer.value[0]) { | ||
153 | /* power down the receiver */ | ||
154 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x2, 0x2); | ||
155 | /* power up the AIF */ | ||
156 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x10, 0); | ||
157 | } else { | ||
158 | /* don't power down the AIF -- may be used as an output */ | ||
159 | /* power up the receiver */ | ||
160 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x2, 0); | ||
161 | } | 188 | } |
162 | 189 | ||
163 | /* restore the transmitter's configuration */ | 190 | snd_soc_dapm_mutex_unlock(dapm); |
164 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, txpwr); | ||
165 | 191 | ||
166 | return 0; | 192 | return 0; |
167 | } | 193 | } |
@@ -185,9 +211,9 @@ static bool wm8804_volatile(struct device *dev, unsigned int reg) | |||
185 | } | 211 | } |
186 | } | 212 | } |
187 | 213 | ||
188 | static int wm8804_reset(struct snd_soc_codec *codec) | 214 | static int wm8804_soft_reset(struct wm8804_priv *wm8804) |
189 | { | 215 | { |
190 | return snd_soc_write(codec, WM8804_RST_DEVID1, 0x0); | 216 | return regmap_write(wm8804->regmap, WM8804_RST_DEVID1, 0x0); |
191 | } | 217 | } |
192 | 218 | ||
193 | static int wm8804_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) | 219 | static int wm8804_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
@@ -379,19 +405,19 @@ static int wm8804_set_pll(struct snd_soc_dai *dai, int pll_id, | |||
379 | int source, unsigned int freq_in, | 405 | int source, unsigned int freq_in, |
380 | unsigned int freq_out) | 406 | unsigned int freq_out) |
381 | { | 407 | { |
382 | struct snd_soc_codec *codec; | 408 | struct snd_soc_codec *codec = dai->codec; |
409 | struct wm8804_priv *wm8804 = snd_soc_codec_get_drvdata(codec); | ||
410 | bool change; | ||
383 | 411 | ||
384 | codec = dai->codec; | ||
385 | if (!freq_in || !freq_out) { | 412 | if (!freq_in || !freq_out) { |
386 | /* disable the PLL */ | 413 | /* disable the PLL */ |
387 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x1, 0x1); | 414 | regmap_update_bits_check(wm8804->regmap, WM8804_PWRDN, |
388 | return 0; | 415 | 0x1, 0x1, &change); |
416 | if (change) | ||
417 | pm_runtime_put(wm8804->dev); | ||
389 | } else { | 418 | } else { |
390 | int ret; | 419 | int ret; |
391 | struct pll_div pll_div; | 420 | struct pll_div pll_div; |
392 | struct wm8804_priv *wm8804; | ||
393 | |||
394 | wm8804 = snd_soc_codec_get_drvdata(codec); | ||
395 | 421 | ||
396 | ret = pll_factors(&pll_div, freq_out, freq_in, | 422 | ret = pll_factors(&pll_div, freq_out, freq_in, |
397 | wm8804->mclk_div); | 423 | wm8804->mclk_div); |
@@ -399,7 +425,10 @@ static int wm8804_set_pll(struct snd_soc_dai *dai, int pll_id, | |||
399 | return ret; | 425 | return ret; |
400 | 426 | ||
401 | /* power down the PLL before reprogramming it */ | 427 | /* power down the PLL before reprogramming it */ |
402 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x1, 0x1); | 428 | regmap_update_bits_check(wm8804->regmap, WM8804_PWRDN, |
429 | 0x1, 0x1, &change); | ||
430 | if (!change) | ||
431 | pm_runtime_get_sync(wm8804->dev); | ||
403 | 432 | ||
404 | /* set PLLN and PRESCALE */ | 433 | /* set PLLN and PRESCALE */ |
405 | snd_soc_update_bits(codec, WM8804_PLL4, 0xf | 0x10, | 434 | snd_soc_update_bits(codec, WM8804_PLL4, 0xf | 0x10, |
@@ -477,141 +506,6 @@ static int wm8804_set_clkdiv(struct snd_soc_dai *dai, | |||
477 | return 0; | 506 | return 0; |
478 | } | 507 | } |
479 | 508 | ||
480 | static int wm8804_set_bias_level(struct snd_soc_codec *codec, | ||
481 | enum snd_soc_bias_level level) | ||
482 | { | ||
483 | int ret; | ||
484 | struct wm8804_priv *wm8804; | ||
485 | |||
486 | wm8804 = snd_soc_codec_get_drvdata(codec); | ||
487 | switch (level) { | ||
488 | case SND_SOC_BIAS_ON: | ||
489 | break; | ||
490 | case SND_SOC_BIAS_PREPARE: | ||
491 | /* power up the OSC and the PLL */ | ||
492 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0); | ||
493 | break; | ||
494 | case SND_SOC_BIAS_STANDBY: | ||
495 | if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { | ||
496 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8804->supplies), | ||
497 | wm8804->supplies); | ||
498 | if (ret) { | ||
499 | dev_err(codec->dev, | ||
500 | "Failed to enable supplies: %d\n", | ||
501 | ret); | ||
502 | return ret; | ||
503 | } | ||
504 | regcache_sync(wm8804->regmap); | ||
505 | } | ||
506 | /* power down the OSC and the PLL */ | ||
507 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0x9); | ||
508 | break; | ||
509 | case SND_SOC_BIAS_OFF: | ||
510 | /* power down the OSC and the PLL */ | ||
511 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0x9); | ||
512 | regulator_bulk_disable(ARRAY_SIZE(wm8804->supplies), | ||
513 | wm8804->supplies); | ||
514 | break; | ||
515 | } | ||
516 | |||
517 | codec->dapm.bias_level = level; | ||
518 | return 0; | ||
519 | } | ||
520 | |||
521 | static 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 | |||
534 | static 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 | |||
610 | err_reg_enable: | ||
611 | regulator_bulk_disable(ARRAY_SIZE(wm8804->supplies), wm8804->supplies); | ||
612 | return ret; | ||
613 | } | ||
614 | |||
615 | static const struct snd_soc_dai_ops wm8804_dai_ops = { | 509 | static const struct snd_soc_dai_ops wm8804_dai_ops = { |
616 | .hw_params = wm8804_hw_params, | 510 | .hw_params = wm8804_hw_params, |
617 | .set_fmt = wm8804_set_fmt, | 511 | .set_fmt = wm8804_set_fmt, |
@@ -649,22 +543,15 @@ static struct snd_soc_dai_driver wm8804_dai = { | |||
649 | }; | 543 | }; |
650 | 544 | ||
651 | static const struct snd_soc_codec_driver soc_codec_dev_wm8804 = { | 545 | static 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, | ||
655 | .idle_bias_off = true, | 546 | .idle_bias_off = true, |
656 | 547 | ||
657 | .controls = wm8804_snd_controls, | 548 | .dapm_widgets = wm8804_dapm_widgets, |
658 | .num_controls = ARRAY_SIZE(wm8804_snd_controls), | 549 | .num_dapm_widgets = ARRAY_SIZE(wm8804_dapm_widgets), |
659 | }; | 550 | .dapm_routes = wm8804_dapm_routes, |
660 | 551 | .num_dapm_routes = ARRAY_SIZE(wm8804_dapm_routes), | |
661 | static const struct of_device_id wm8804_of_match[] = { | ||
662 | { .compatible = "wlf,wm8804", }, | ||
663 | { } | ||
664 | }; | 552 | }; |
665 | MODULE_DEVICE_TABLE(of, wm8804_of_match); | ||
666 | 553 | ||
667 | static const struct regmap_config wm8804_regmap_config = { | 554 | const struct regmap_config wm8804_regmap_config = { |
668 | .reg_bits = 8, | 555 | .reg_bits = 8, |
669 | .val_bits = 8, | 556 | .val_bits = 8, |
670 | 557 | ||
@@ -675,128 +562,169 @@ static const struct regmap_config wm8804_regmap_config = { | |||
675 | .reg_defaults = wm8804_reg_defaults, | 562 | .reg_defaults = wm8804_reg_defaults, |
676 | .num_reg_defaults = ARRAY_SIZE(wm8804_reg_defaults), | 563 | .num_reg_defaults = ARRAY_SIZE(wm8804_reg_defaults), |
677 | }; | 564 | }; |
565 | EXPORT_SYMBOL_GPL(wm8804_regmap_config); | ||
678 | 566 | ||
679 | #if defined(CONFIG_SPI_MASTER) | 567 | int wm8804_probe(struct device *dev, struct regmap *regmap) |
680 | static int wm8804_spi_probe(struct spi_device *spi) | ||
681 | { | 568 | { |
682 | struct wm8804_priv *wm8804; | 569 | struct wm8804_priv *wm8804; |
683 | int ret; | 570 | unsigned int id1, id2; |
571 | int i, ret; | ||
684 | 572 | ||
685 | wm8804 = devm_kzalloc(&spi->dev, sizeof *wm8804, GFP_KERNEL); | 573 | wm8804 = devm_kzalloc(dev, sizeof(*wm8804), GFP_KERNEL); |
686 | if (!wm8804) | 574 | if (!wm8804) |
687 | return -ENOMEM; | 575 | return -ENOMEM; |
688 | 576 | ||
689 | wm8804->regmap = devm_regmap_init_spi(spi, &wm8804_regmap_config); | 577 | dev_set_drvdata(dev, wm8804); |
690 | if (IS_ERR(wm8804->regmap)) { | 578 | |
691 | ret = PTR_ERR(wm8804->regmap); | 579 | wm8804->dev = dev; |
580 | wm8804->regmap = regmap; | ||
581 | |||
582 | wm8804->reset = devm_gpiod_get_optional(dev, "wlf,reset", | ||
583 | GPIOD_OUT_LOW); | ||
584 | if (IS_ERR(wm8804->reset)) { | ||
585 | ret = PTR_ERR(wm8804->reset); | ||
586 | dev_err(dev, "Failed to get reset line: %d\n", ret); | ||
692 | return ret; | 587 | return ret; |
693 | } | 588 | } |
694 | 589 | ||
695 | spi_set_drvdata(spi, wm8804); | 590 | for (i = 0; i < ARRAY_SIZE(wm8804->supplies); i++) |
591 | wm8804->supplies[i].supply = wm8804_supply_names[i]; | ||
696 | 592 | ||
697 | ret = snd_soc_register_codec(&spi->dev, | 593 | ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(wm8804->supplies), |
698 | &soc_codec_dev_wm8804, &wm8804_dai, 1); | 594 | wm8804->supplies); |
595 | if (ret) { | ||
596 | dev_err(dev, "Failed to request supplies: %d\n", ret); | ||
597 | return ret; | ||
598 | } | ||
699 | 599 | ||
700 | return ret; | 600 | wm8804->disable_nb[0].notifier_call = wm8804_regulator_event_0; |
701 | } | 601 | wm8804->disable_nb[1].notifier_call = wm8804_regulator_event_1; |
702 | 602 | ||
703 | static int wm8804_spi_remove(struct spi_device *spi) | 603 | /* This should really be moved into the regulator core */ |
704 | { | 604 | for (i = 0; i < ARRAY_SIZE(wm8804->supplies); i++) { |
705 | snd_soc_unregister_codec(&spi->dev); | 605 | struct regulator *regulator = wm8804->supplies[i].consumer; |
706 | return 0; | ||
707 | } | ||
708 | 606 | ||
709 | static struct spi_driver wm8804_spi_driver = { | 607 | ret = devm_regulator_register_notifier(regulator, |
710 | .driver = { | 608 | &wm8804->disable_nb[i]); |
711 | .name = "wm8804", | 609 | if (ret != 0) { |
712 | .owner = THIS_MODULE, | 610 | dev_err(dev, |
713 | .of_match_table = wm8804_of_match, | 611 | "Failed to register regulator notifier: %d\n", |
714 | }, | 612 | ret); |
715 | .probe = wm8804_spi_probe, | 613 | return ret; |
716 | .remove = wm8804_spi_remove | 614 | } |
717 | }; | 615 | } |
718 | #endif | ||
719 | 616 | ||
720 | #if IS_ENABLED(CONFIG_I2C) | 617 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8804->supplies), |
721 | static int wm8804_i2c_probe(struct i2c_client *i2c, | 618 | wm8804->supplies); |
722 | const struct i2c_device_id *id) | 619 | if (ret) { |
723 | { | 620 | dev_err(dev, "Failed to enable supplies: %d\n", ret); |
724 | struct wm8804_priv *wm8804; | 621 | return ret; |
725 | int ret; | 622 | } |
726 | 623 | ||
727 | wm8804 = devm_kzalloc(&i2c->dev, sizeof *wm8804, GFP_KERNEL); | 624 | if (wm8804->reset) |
728 | if (!wm8804) | 625 | gpiod_set_value_cansleep(wm8804->reset, 1); |
729 | return -ENOMEM; | ||
730 | 626 | ||
731 | wm8804->regmap = devm_regmap_init_i2c(i2c, &wm8804_regmap_config); | 627 | ret = regmap_read(regmap, WM8804_RST_DEVID1, &id1); |
732 | if (IS_ERR(wm8804->regmap)) { | 628 | if (ret < 0) { |
733 | ret = PTR_ERR(wm8804->regmap); | 629 | dev_err(dev, "Failed to read device ID: %d\n", ret); |
734 | return ret; | 630 | goto err_reg_enable; |
631 | } | ||
632 | |||
633 | ret = regmap_read(regmap, WM8804_DEVID2, &id2); | ||
634 | if (ret < 0) { | ||
635 | dev_err(dev, "Failed to read device ID: %d\n", ret); | ||
636 | goto err_reg_enable; | ||
637 | } | ||
638 | |||
639 | id2 = (id2 << 8) | id1; | ||
640 | |||
641 | if (id2 != 0x8805) { | ||
642 | dev_err(dev, "Invalid device ID: %#x\n", id2); | ||
643 | ret = -EINVAL; | ||
644 | goto err_reg_enable; | ||
645 | } | ||
646 | |||
647 | ret = regmap_read(regmap, WM8804_DEVREV, &id1); | ||
648 | if (ret < 0) { | ||
649 | dev_err(dev, "Failed to read device revision: %d\n", | ||
650 | ret); | ||
651 | goto err_reg_enable; | ||
735 | } | 652 | } |
653 | dev_info(dev, "revision %c\n", id1 + 'A'); | ||
736 | 654 | ||
737 | i2c_set_clientdata(i2c, wm8804); | 655 | if (!wm8804->reset) { |
656 | ret = wm8804_soft_reset(wm8804); | ||
657 | if (ret < 0) { | ||
658 | dev_err(dev, "Failed to issue reset: %d\n", ret); | ||
659 | goto err_reg_enable; | ||
660 | } | ||
661 | } | ||
662 | |||
663 | ret = snd_soc_register_codec(dev, &soc_codec_dev_wm8804, | ||
664 | &wm8804_dai, 1); | ||
665 | if (ret < 0) { | ||
666 | dev_err(dev, "Failed to register CODEC: %d\n", ret); | ||
667 | goto err_reg_enable; | ||
668 | } | ||
669 | |||
670 | pm_runtime_set_active(dev); | ||
671 | pm_runtime_enable(dev); | ||
672 | pm_runtime_idle(dev); | ||
738 | 673 | ||
739 | ret = snd_soc_register_codec(&i2c->dev, | 674 | return 0; |
740 | &soc_codec_dev_wm8804, &wm8804_dai, 1); | 675 | |
676 | err_reg_enable: | ||
677 | regulator_bulk_disable(ARRAY_SIZE(wm8804->supplies), wm8804->supplies); | ||
741 | return ret; | 678 | return ret; |
742 | } | 679 | } |
680 | EXPORT_SYMBOL_GPL(wm8804_probe); | ||
743 | 681 | ||
744 | static int wm8804_i2c_remove(struct i2c_client *i2c) | 682 | void wm8804_remove(struct device *dev) |
745 | { | 683 | { |
746 | snd_soc_unregister_codec(&i2c->dev); | 684 | pm_runtime_disable(dev); |
747 | return 0; | 685 | snd_soc_unregister_codec(dev); |
748 | } | 686 | } |
687 | EXPORT_SYMBOL_GPL(wm8804_remove); | ||
749 | 688 | ||
750 | static const struct i2c_device_id wm8804_i2c_id[] = { | 689 | #if IS_ENABLED(CONFIG_PM) |
751 | { "wm8804", 0 }, | 690 | static int wm8804_runtime_resume(struct device *dev) |
752 | { } | ||
753 | }; | ||
754 | MODULE_DEVICE_TABLE(i2c, wm8804_i2c_id); | ||
755 | |||
756 | static 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 | |||
768 | static int __init wm8804_modinit(void) | ||
769 | { | 691 | { |
770 | int ret = 0; | 692 | struct wm8804_priv *wm8804 = dev_get_drvdata(dev); |
693 | int ret; | ||
771 | 694 | ||
772 | #if IS_ENABLED(CONFIG_I2C) | 695 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8804->supplies), |
773 | ret = i2c_add_driver(&wm8804_i2c_driver); | 696 | wm8804->supplies); |
774 | if (ret) { | 697 | if (ret) { |
775 | printk(KERN_ERR "Failed to register wm8804 I2C driver: %d\n", | 698 | dev_err(wm8804->dev, "Failed to enable supplies: %d\n", ret); |
776 | ret); | 699 | return 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 | } | 700 | } |
785 | #endif | 701 | |
786 | return ret; | 702 | regcache_sync(wm8804->regmap); |
703 | |||
704 | /* Power up OSCCLK */ | ||
705 | regmap_update_bits(wm8804->regmap, WM8804_PWRDN, 0x8, 0x0); | ||
706 | |||
707 | return 0; | ||
787 | } | 708 | } |
788 | module_init(wm8804_modinit); | ||
789 | 709 | ||
790 | static void __exit wm8804_exit(void) | 710 | static int wm8804_runtime_suspend(struct device *dev) |
791 | { | 711 | { |
792 | #if IS_ENABLED(CONFIG_I2C) | 712 | struct wm8804_priv *wm8804 = dev_get_drvdata(dev); |
793 | i2c_del_driver(&wm8804_i2c_driver); | 713 | |
794 | #endif | 714 | /* Power down OSCCLK */ |
795 | #if defined(CONFIG_SPI_MASTER) | 715 | regmap_update_bits(wm8804->regmap, WM8804_PWRDN, 0x8, 0x8); |
796 | spi_unregister_driver(&wm8804_spi_driver); | 716 | |
797 | #endif | 717 | regulator_bulk_disable(ARRAY_SIZE(wm8804->supplies), |
718 | wm8804->supplies); | ||
719 | |||
720 | return 0; | ||
798 | } | 721 | } |
799 | module_exit(wm8804_exit); | 722 | #endif |
723 | |||
724 | const struct dev_pm_ops wm8804_pm = { | ||
725 | SET_RUNTIME_PM_OPS(wm8804_runtime_suspend, wm8804_runtime_resume, NULL) | ||
726 | }; | ||
727 | EXPORT_SYMBOL_GPL(wm8804_pm); | ||
800 | 728 | ||
801 | MODULE_DESCRIPTION("ASoC WM8804 driver"); | 729 | MODULE_DESCRIPTION("ASoC WM8804 driver"); |
802 | MODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>"); | 730 | MODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>"); |
diff --git a/sound/soc/codecs/wm8804.h b/sound/soc/codecs/wm8804.h index e72d4f4ba6b1..aa72fa66c932 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,10 @@ | |||
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 | ||
67 | extern const struct regmap_config wm8804_regmap_config; | ||
68 | extern const struct dev_pm_ops wm8804_pm; | ||
69 | |||
70 | int wm8804_probe(struct device *dev, struct regmap *regmap); | ||
71 | void wm8804_remove(struct device *dev); | ||
72 | |||
65 | #endif /* _WM8804_H */ | 73 | #endif /* _WM8804_H */ |
diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c index 39ddb9b8834c..f9cbabdc6238 100644 --- a/sound/soc/codecs/wm8971.c +++ b/sound/soc/codecs/wm8971.c | |||
@@ -31,11 +31,11 @@ | |||
31 | 31 | ||
32 | #define WM8971_REG_COUNT 43 | 32 | #define WM8971_REG_COUNT 43 |
33 | 33 | ||
34 | static struct workqueue_struct *wm8971_workq = NULL; | ||
35 | |||
36 | /* codec private data */ | 34 | /* codec private data */ |
37 | struct wm8971_priv { | 35 | struct wm8971_priv { |
38 | unsigned int sysclk; | 36 | unsigned int sysclk; |
37 | struct delayed_work charge_work; | ||
38 | struct regmap *regmap; | ||
39 | }; | 39 | }; |
40 | 40 | ||
41 | /* | 41 | /* |
@@ -552,9 +552,19 @@ static int wm8971_mute(struct snd_soc_dai *dai, int mute) | |||
552 | return 0; | 552 | return 0; |
553 | } | 553 | } |
554 | 554 | ||
555 | static void wm8971_charge_work(struct work_struct *work) | ||
556 | { | ||
557 | struct wm8971_priv *wm8971 = | ||
558 | container_of(work, struct wm8971_priv, charge_work.work); | ||
559 | |||
560 | /* Set to 500k */ | ||
561 | regmap_update_bits(wm8971->regmap, WM8971_PWR1, 0x0180, 0x0100); | ||
562 | } | ||
563 | |||
555 | static int wm8971_set_bias_level(struct snd_soc_codec *codec, | 564 | static int wm8971_set_bias_level(struct snd_soc_codec *codec, |
556 | enum snd_soc_bias_level level) | 565 | enum snd_soc_bias_level level) |
557 | { | 566 | { |
567 | struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec); | ||
558 | u16 pwr_reg = snd_soc_read(codec, WM8971_PWR1) & 0xfe3e; | 568 | u16 pwr_reg = snd_soc_read(codec, WM8971_PWR1) & 0xfe3e; |
559 | 569 | ||
560 | switch (level) { | 570 | switch (level) { |
@@ -563,15 +573,24 @@ static int wm8971_set_bias_level(struct snd_soc_codec *codec, | |||
563 | snd_soc_write(codec, WM8971_PWR1, pwr_reg | 0x00c1); | 573 | snd_soc_write(codec, WM8971_PWR1, pwr_reg | 0x00c1); |
564 | break; | 574 | break; |
565 | case SND_SOC_BIAS_PREPARE: | 575 | case SND_SOC_BIAS_PREPARE: |
576 | /* Wait until fully charged */ | ||
577 | flush_delayed_work(&wm8971->charge_work); | ||
566 | break; | 578 | break; |
567 | case SND_SOC_BIAS_STANDBY: | 579 | case SND_SOC_BIAS_STANDBY: |
568 | if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) | 580 | if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { |
569 | snd_soc_cache_sync(codec); | 581 | snd_soc_cache_sync(codec); |
582 | /* charge output caps - set vmid to 5k for quick power up */ | ||
583 | snd_soc_write(codec, WM8971_PWR1, pwr_reg | 0x01c0); | ||
584 | queue_delayed_work(system_power_efficient_wq, | ||
585 | &wm8971->charge_work, msecs_to_jiffies(1000)); | ||
586 | } else { | ||
587 | /* mute dac and set vmid to 500k, enable VREF */ | ||
588 | snd_soc_write(codec, WM8971_PWR1, pwr_reg | 0x0140); | ||
589 | } | ||
570 | 590 | ||
571 | /* mute dac and set vmid to 500k, enable VREF */ | ||
572 | snd_soc_write(codec, WM8971_PWR1, pwr_reg | 0x0140); | ||
573 | break; | 591 | break; |
574 | case SND_SOC_BIAS_OFF: | 592 | case SND_SOC_BIAS_OFF: |
593 | cancel_delayed_work_sync(&wm8971->charge_work); | ||
575 | snd_soc_write(codec, WM8971_PWR1, 0x0001); | 594 | snd_soc_write(codec, WM8971_PWR1, 0x0001); |
576 | break; | 595 | break; |
577 | } | 596 | } |
@@ -610,58 +629,14 @@ static struct snd_soc_dai_driver wm8971_dai = { | |||
610 | .ops = &wm8971_dai_ops, | 629 | .ops = &wm8971_dai_ops, |
611 | }; | 630 | }; |
612 | 631 | ||
613 | static void wm8971_work(struct work_struct *work) | ||
614 | { | ||
615 | struct snd_soc_dapm_context *dapm = | ||
616 | container_of(work, struct snd_soc_dapm_context, | ||
617 | delayed_work.work); | ||
618 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm); | ||
619 | wm8971_set_bias_level(codec, codec->dapm.bias_level); | ||
620 | } | ||
621 | |||
622 | static int wm8971_suspend(struct snd_soc_codec *codec) | ||
623 | { | ||
624 | wm8971_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
625 | return 0; | ||
626 | } | ||
627 | |||
628 | static int wm8971_resume(struct snd_soc_codec *codec) | ||
629 | { | ||
630 | u16 reg; | ||
631 | |||
632 | wm8971_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
633 | |||
634 | /* charge wm8971 caps */ | ||
635 | if (codec->dapm.suspend_bias_level == SND_SOC_BIAS_ON) { | ||
636 | reg = snd_soc_read(codec, WM8971_PWR1) & 0xfe3e; | ||
637 | snd_soc_write(codec, WM8971_PWR1, reg | 0x01c0); | ||
638 | codec->dapm.bias_level = SND_SOC_BIAS_ON; | ||
639 | queue_delayed_work(wm8971_workq, &codec->dapm.delayed_work, | ||
640 | msecs_to_jiffies(1000)); | ||
641 | } | ||
642 | |||
643 | return 0; | ||
644 | } | ||
645 | |||
646 | static int wm8971_probe(struct snd_soc_codec *codec) | 632 | static int wm8971_probe(struct snd_soc_codec *codec) |
647 | { | 633 | { |
648 | int ret = 0; | 634 | struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec); |
649 | u16 reg; | ||
650 | 635 | ||
651 | INIT_DELAYED_WORK(&codec->dapm.delayed_work, wm8971_work); | 636 | INIT_DELAYED_WORK(&wm8971->charge_work, wm8971_charge_work); |
652 | wm8971_workq = create_workqueue("wm8971"); | ||
653 | if (wm8971_workq == NULL) | ||
654 | return -ENOMEM; | ||
655 | 637 | ||
656 | wm8971_reset(codec); | 638 | wm8971_reset(codec); |
657 | 639 | ||
658 | /* charge output caps - set vmid to 5k for quick power up */ | ||
659 | reg = snd_soc_read(codec, WM8971_PWR1) & 0xfe3e; | ||
660 | snd_soc_write(codec, WM8971_PWR1, reg | 0x01c0); | ||
661 | codec->dapm.bias_level = SND_SOC_BIAS_STANDBY; | ||
662 | queue_delayed_work(wm8971_workq, &codec->dapm.delayed_work, | ||
663 | msecs_to_jiffies(1000)); | ||
664 | |||
665 | /* set the update bits */ | 640 | /* set the update bits */ |
666 | snd_soc_update_bits(codec, WM8971_LDAC, 0x0100, 0x0100); | 641 | snd_soc_update_bits(codec, WM8971_LDAC, 0x0100, 0x0100); |
667 | snd_soc_update_bits(codec, WM8971_RDAC, 0x0100, 0x0100); | 642 | snd_soc_update_bits(codec, WM8971_RDAC, 0x0100, 0x0100); |
@@ -672,26 +647,13 @@ static int wm8971_probe(struct snd_soc_codec *codec) | |||
672 | snd_soc_update_bits(codec, WM8971_LINVOL, 0x0100, 0x0100); | 647 | snd_soc_update_bits(codec, WM8971_LINVOL, 0x0100, 0x0100); |
673 | snd_soc_update_bits(codec, WM8971_RINVOL, 0x0100, 0x0100); | 648 | snd_soc_update_bits(codec, WM8971_RINVOL, 0x0100, 0x0100); |
674 | 649 | ||
675 | return ret; | ||
676 | } | ||
677 | |||
678 | |||
679 | /* power down chip */ | ||
680 | static int wm8971_remove(struct snd_soc_codec *codec) | ||
681 | { | ||
682 | wm8971_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
683 | |||
684 | if (wm8971_workq) | ||
685 | destroy_workqueue(wm8971_workq); | ||
686 | return 0; | 650 | return 0; |
687 | } | 651 | } |
688 | 652 | ||
689 | static struct snd_soc_codec_driver soc_codec_dev_wm8971 = { | 653 | static struct snd_soc_codec_driver soc_codec_dev_wm8971 = { |
690 | .probe = wm8971_probe, | 654 | .probe = wm8971_probe, |
691 | .remove = wm8971_remove, | ||
692 | .suspend = wm8971_suspend, | ||
693 | .resume = wm8971_resume, | ||
694 | .set_bias_level = wm8971_set_bias_level, | 655 | .set_bias_level = wm8971_set_bias_level, |
656 | .suspend_bias_off = true, | ||
695 | 657 | ||
696 | .controls = wm8971_snd_controls, | 658 | .controls = wm8971_snd_controls, |
697 | .num_controls = ARRAY_SIZE(wm8971_snd_controls), | 659 | .num_controls = ARRAY_SIZE(wm8971_snd_controls), |
@@ -715,7 +677,6 @@ static int wm8971_i2c_probe(struct i2c_client *i2c, | |||
715 | const struct i2c_device_id *id) | 677 | const struct i2c_device_id *id) |
716 | { | 678 | { |
717 | struct wm8971_priv *wm8971; | 679 | struct wm8971_priv *wm8971; |
718 | struct regmap *regmap; | ||
719 | int ret; | 680 | int ret; |
720 | 681 | ||
721 | wm8971 = devm_kzalloc(&i2c->dev, sizeof(struct wm8971_priv), | 682 | wm8971 = devm_kzalloc(&i2c->dev, sizeof(struct wm8971_priv), |
@@ -723,9 +684,9 @@ static int wm8971_i2c_probe(struct i2c_client *i2c, | |||
723 | if (wm8971 == NULL) | 684 | if (wm8971 == NULL) |
724 | return -ENOMEM; | 685 | return -ENOMEM; |
725 | 686 | ||
726 | regmap = devm_regmap_init_i2c(i2c, &wm8971_regmap); | 687 | wm8971->regmap = devm_regmap_init_i2c(i2c, &wm8971_regmap); |
727 | if (IS_ERR(regmap)) | 688 | if (IS_ERR(wm8971->regmap)) |
728 | return PTR_ERR(regmap); | 689 | return PTR_ERR(wm8971->regmap); |
729 | 690 | ||
730 | i2c_set_clientdata(i2c, wm8971); | 691 | i2c_set_clientdata(i2c, wm8971); |
731 | 692 | ||
diff --git a/sound/soc/codecs/wm8996.c b/sound/soc/codecs/wm8996.c index dc92d5e4e942..308748a022c5 100644 --- a/sound/soc/codecs/wm8996.c +++ b/sound/soc/codecs/wm8996.c | |||
@@ -2009,7 +2009,7 @@ static int wm8996_set_fll(struct snd_soc_codec *codec, int fll_id, int source, | |||
2009 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); | 2009 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
2010 | struct i2c_client *i2c = to_i2c_client(codec->dev); | 2010 | struct i2c_client *i2c = to_i2c_client(codec->dev); |
2011 | struct _fll_div fll_div; | 2011 | struct _fll_div fll_div; |
2012 | unsigned long timeout; | 2012 | unsigned long timeout, time_left; |
2013 | int ret, reg, retry; | 2013 | int ret, reg, retry; |
2014 | 2014 | ||
2015 | /* Any change? */ | 2015 | /* Any change? */ |
@@ -2110,13 +2110,15 @@ static int wm8996_set_fll(struct snd_soc_codec *codec, int fll_id, int source, | |||
2110 | if (i2c->irq) | 2110 | if (i2c->irq) |
2111 | timeout *= 10; | 2111 | timeout *= 10; |
2112 | else | 2112 | else |
2113 | timeout /= 2; | 2113 | /* ensure timeout of atleast 1 jiffies */ |
2114 | timeout = timeout/2 ? : 1; | ||
2114 | 2115 | ||
2115 | for (retry = 0; retry < 10; retry++) { | 2116 | for (retry = 0; retry < 10; retry++) { |
2116 | ret = wait_for_completion_timeout(&wm8996->fll_lock, | 2117 | time_left = wait_for_completion_timeout(&wm8996->fll_lock, |
2117 | timeout); | 2118 | timeout); |
2118 | if (ret != 0) { | 2119 | if (time_left != 0) { |
2119 | WARN_ON(!i2c->irq); | 2120 | WARN_ON(!i2c->irq); |
2121 | ret = 1; | ||
2120 | break; | 2122 | break; |
2121 | } | 2123 | } |
2122 | 2124 | ||
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 @@ | |||
1 | config SND_DAVINCI_SOC | 1 | config 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 | ||
5 | config SND_EDMA_SOC | 6 | config 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 | ||
18 | config SND_DAVINCI_SOC_MCASP | 20 | config 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 | ||
46 | config SND_DAVINCI_SOC_EVM | 48 | config 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 | ||
74 | config SND_DM6467_SOC_EVM | 76 | config 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 | ||
83 | config SND_DA830_SOC_EVM | 85 | config 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 | ||
92 | config SND_DA850_SOC_EVM | 94 | config 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 |
2 | snd-soc-davinci-objs := davinci-pcm.o | ||
3 | snd-soc-edma-objs := edma-pcm.o | 2 | snd-soc-edma-objs := edma-pcm.o |
4 | snd-soc-davinci-i2s-objs := davinci-i2s.o | 3 | snd-soc-davinci-i2s-objs := davinci-i2s.o |
5 | snd-soc-davinci-mcasp-objs:= davinci-mcasp.o | 4 | snd-soc-davinci-mcasp-objs:= davinci-mcasp.o |
6 | snd-soc-davinci-vcif-objs:= davinci-vcif.o | 5 | snd-soc-davinci-vcif-objs:= davinci-vcif.o |
7 | 6 | ||
8 | obj-$(CONFIG_SND_DAVINCI_SOC) += snd-soc-davinci.o | ||
9 | obj-$(CONFIG_SND_EDMA_SOC) += snd-soc-edma.o | 7 | obj-$(CONFIG_SND_EDMA_SOC) += snd-soc-edma.o |
10 | obj-$(CONFIG_SND_DAVINCI_SOC_I2S) += snd-soc-davinci-i2s.o | 8 | obj-$(CONFIG_SND_DAVINCI_SOC_I2S) += snd-soc-davinci-i2s.o |
11 | obj-$(CONFIG_SND_DAVINCI_SOC_MCASP) += snd-soc-davinci-mcasp.o | 9 | obj-$(CONFIG_SND_DAVINCI_SOC_MCASP) += snd-soc-davinci-mcasp.o |
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c index b6bb5947a8a8..731fb0d86c6a 100644 --- a/sound/soc/davinci/davinci-evm.c +++ b/sound/soc/davinci/davinci-evm.c | |||
@@ -117,7 +117,6 @@ static const struct snd_soc_dapm_route audio_map[] = { | |||
117 | static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd) | 117 | static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd) |
118 | { | 118 | { |
119 | struct snd_soc_card *card = rtd->card; | 119 | struct snd_soc_card *card = rtd->card; |
120 | struct snd_soc_codec *codec = rtd->codec; | ||
121 | struct device_node *np = card->dev->of_node; | 120 | struct device_node *np = card->dev->of_node; |
122 | int ret; | 121 | int ret; |
123 | 122 | ||
@@ -136,9 +135,9 @@ static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd) | |||
136 | } | 135 | } |
137 | 136 | ||
138 | /* not connected */ | 137 | /* not connected */ |
139 | snd_soc_dapm_nc_pin(&codec->dapm, "MONO_LOUT"); | 138 | snd_soc_dapm_nc_pin(&card->dapm, "MONO_LOUT"); |
140 | snd_soc_dapm_nc_pin(&codec->dapm, "HPLCOM"); | 139 | snd_soc_dapm_nc_pin(&card->dapm, "HPLCOM"); |
141 | snd_soc_dapm_nc_pin(&codec->dapm, "HPRCOM"); | 140 | snd_soc_dapm_nc_pin(&card->dapm, "HPRCOM"); |
142 | 141 | ||
143 | return 0; | 142 | return 0; |
144 | } | 143 | } |
@@ -425,18 +424,8 @@ static int davinci_evm_probe(struct platform_device *pdev) | |||
425 | return ret; | 424 | return ret; |
426 | } | 425 | } |
427 | 426 | ||
428 | static int davinci_evm_remove(struct platform_device *pdev) | ||
429 | { | ||
430 | struct snd_soc_card *card = platform_get_drvdata(pdev); | ||
431 | |||
432 | snd_soc_unregister_card(card); | ||
433 | |||
434 | return 0; | ||
435 | } | ||
436 | |||
437 | static struct platform_driver davinci_evm_driver = { | 427 | static struct platform_driver davinci_evm_driver = { |
438 | .probe = davinci_evm_probe, | 428 | .probe = davinci_evm_probe, |
439 | .remove = davinci_evm_remove, | ||
440 | .driver = { | 429 | .driver = { |
441 | .name = "davinci_evm", | 430 | .name = "davinci_evm", |
442 | .pm = &snd_soc_pm_ops, | 431 | .pm = &snd_soc_pm_ops, |
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 | ||
123 | struct davinci_mcbsp_dev { | 124 | struct 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 | ||
603 | static 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 | |||
612 | static void davinci_i2s_shutdown(struct snd_pcm_substream *substream, | 601 | static 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 | ||
622 | static const struct snd_soc_dai_ops davinci_i2s_dai_ops = { | 611 | static 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 | ||
621 | static 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 | |||
633 | static struct snd_soc_dai_driver davinci_i2s_dai = { | 631 | static 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 | ||
652 | static int davinci_i2s_probe(struct platform_device *pdev) | 651 | static 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..bb4b78eada58 100644 --- a/sound/soc/davinci/davinci-mcasp.c +++ b/sound/soc/davinci/davinci-mcasp.c | |||
@@ -26,6 +26,8 @@ | |||
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> | ||
30 | #include <linux/math64.h> | ||
29 | 31 | ||
30 | #include <sound/asoundef.h> | 32 | #include <sound/asoundef.h> |
31 | #include <sound/core.h> | 33 | #include <sound/core.h> |
@@ -36,7 +38,6 @@ | |||
36 | #include <sound/dmaengine_pcm.h> | 38 | #include <sound/dmaengine_pcm.h> |
37 | #include <sound/omap-pcm.h> | 39 | #include <sound/omap-pcm.h> |
38 | 40 | ||
39 | #include "davinci-pcm.h" | ||
40 | #include "edma-pcm.h" | 41 | #include "edma-pcm.h" |
41 | #include "davinci-mcasp.h" | 42 | #include "davinci-mcasp.h" |
42 | 43 | ||
@@ -62,10 +63,15 @@ struct davinci_mcasp_context { | |||
62 | u32 config_regs[ARRAY_SIZE(context_regs)]; | 63 | u32 config_regs[ARRAY_SIZE(context_regs)]; |
63 | u32 afifo_regs[2]; /* for read/write fifo control registers */ | 64 | u32 afifo_regs[2]; /* for read/write fifo control registers */ |
64 | u32 *xrsr_regs; /* for serializer configuration */ | 65 | u32 *xrsr_regs; /* for serializer configuration */ |
66 | bool pm_state; | ||
67 | }; | ||
68 | |||
69 | struct davinci_mcasp_ruledata { | ||
70 | struct davinci_mcasp *mcasp; | ||
71 | int serializers; | ||
65 | }; | 72 | }; |
66 | 73 | ||
67 | struct davinci_mcasp { | 74 | struct davinci_mcasp { |
68 | struct davinci_pcm_dma_params dma_params[2]; | ||
69 | struct snd_dmaengine_dai_dma_data dma_data[2]; | 75 | struct snd_dmaengine_dai_dma_data dma_data[2]; |
70 | void __iomem *base; | 76 | void __iomem *base; |
71 | u32 fifo_base; | 77 | u32 fifo_base; |
@@ -82,6 +88,7 @@ struct davinci_mcasp { | |||
82 | u16 bclk_lrclk_ratio; | 88 | u16 bclk_lrclk_ratio; |
83 | int streams; | 89 | int streams; |
84 | u32 irq_request[2]; | 90 | u32 irq_request[2]; |
91 | int dma_request[2]; | ||
85 | 92 | ||
86 | int sysclk_freq; | 93 | int sysclk_freq; |
87 | bool bclk_master; | 94 | bool bclk_master; |
@@ -98,6 +105,8 @@ struct davinci_mcasp { | |||
98 | #ifdef CONFIG_PM_SLEEP | 105 | #ifdef CONFIG_PM_SLEEP |
99 | struct davinci_mcasp_context context; | 106 | struct davinci_mcasp_context context; |
100 | #endif | 107 | #endif |
108 | |||
109 | struct davinci_mcasp_ruledata ruledata[2]; | ||
101 | }; | 110 | }; |
102 | 111 | ||
103 | static inline void mcasp_set_bits(struct davinci_mcasp *mcasp, u32 offset, | 112 | static inline void mcasp_set_bits(struct davinci_mcasp *mcasp, u32 offset, |
@@ -441,6 +450,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); | 450 | mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AFSX | AFSR); |
442 | mcasp->bclk_master = 1; | 451 | mcasp->bclk_master = 1; |
443 | break; | 452 | break; |
453 | case SND_SOC_DAIFMT_CBS_CFM: | ||
454 | /* codec is clock slave and frame master */ | ||
455 | mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE); | ||
456 | mcasp_clr_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, AFSXE); | ||
457 | |||
458 | mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE); | ||
459 | mcasp_clr_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, AFSRE); | ||
460 | |||
461 | mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, ACLKX | ACLKR); | ||
462 | mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AFSX | AFSR); | ||
463 | mcasp->bclk_master = 1; | ||
464 | break; | ||
444 | case SND_SOC_DAIFMT_CBM_CFS: | 465 | case SND_SOC_DAIFMT_CBM_CFS: |
445 | /* codec is clock master and frame slave */ | 466 | /* codec is clock master and frame slave */ |
446 | mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE); | 467 | mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE); |
@@ -507,7 +528,7 @@ static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai, | |||
507 | mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRPOL); | 528 | mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRPOL); |
508 | } | 529 | } |
509 | out: | 530 | out: |
510 | pm_runtime_put_sync(mcasp->dev); | 531 | pm_runtime_put(mcasp->dev); |
511 | return ret; | 532 | return ret; |
512 | } | 533 | } |
513 | 534 | ||
@@ -516,6 +537,7 @@ static int __davinci_mcasp_set_clkdiv(struct snd_soc_dai *dai, int div_id, | |||
516 | { | 537 | { |
517 | struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai); | 538 | struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai); |
518 | 539 | ||
540 | pm_runtime_get_sync(mcasp->dev); | ||
519 | switch (div_id) { | 541 | switch (div_id) { |
520 | case 0: /* MCLK divider */ | 542 | case 0: /* MCLK divider */ |
521 | mcasp_mod_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, | 543 | mcasp_mod_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, |
@@ -541,6 +563,7 @@ static int __davinci_mcasp_set_clkdiv(struct snd_soc_dai *dai, int div_id, | |||
541 | return -EINVAL; | 563 | return -EINVAL; |
542 | } | 564 | } |
543 | 565 | ||
566 | pm_runtime_put(mcasp->dev); | ||
544 | return 0; | 567 | return 0; |
545 | } | 568 | } |
546 | 569 | ||
@@ -555,6 +578,7 @@ static int davinci_mcasp_set_sysclk(struct snd_soc_dai *dai, int clk_id, | |||
555 | { | 578 | { |
556 | struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai); | 579 | struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai); |
557 | 580 | ||
581 | pm_runtime_get_sync(mcasp->dev); | ||
558 | if (dir == SND_SOC_CLOCK_OUT) { | 582 | if (dir == SND_SOC_CLOCK_OUT) { |
559 | mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE); | 583 | mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE); |
560 | mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE); | 584 | mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE); |
@@ -567,6 +591,7 @@ static int davinci_mcasp_set_sysclk(struct snd_soc_dai *dai, int clk_id, | |||
567 | 591 | ||
568 | mcasp->sysclk_freq = freq; | 592 | mcasp->sysclk_freq = freq; |
569 | 593 | ||
594 | pm_runtime_put(mcasp->dev); | ||
570 | return 0; | 595 | return 0; |
571 | } | 596 | } |
572 | 597 | ||
@@ -631,7 +656,6 @@ static int davinci_config_channel_size(struct davinci_mcasp *mcasp, | |||
631 | static int mcasp_common_hw_param(struct davinci_mcasp *mcasp, int stream, | 656 | static int mcasp_common_hw_param(struct davinci_mcasp *mcasp, int stream, |
632 | int period_words, int channels) | 657 | int period_words, int channels) |
633 | { | 658 | { |
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]; | 659 | struct snd_dmaengine_dai_dma_data *dma_data = &mcasp->dma_data[stream]; |
636 | int i; | 660 | int i; |
637 | u8 tx_ser = 0; | 661 | u8 tx_ser = 0; |
@@ -699,10 +723,8 @@ static int mcasp_common_hw_param(struct davinci_mcasp *mcasp, int stream, | |||
699 | * For example if three serializers are enabled the DMA | 723 | * For example if three serializers are enabled the DMA |
700 | * need to transfer three words per DMA request. | 724 | * need to transfer three words per DMA request. |
701 | */ | 725 | */ |
702 | dma_params->fifo_level = active_serializers; | ||
703 | dma_data->maxburst = active_serializers; | 726 | dma_data->maxburst = active_serializers; |
704 | } else { | 727 | } else { |
705 | dma_params->fifo_level = 0; | ||
706 | dma_data->maxburst = 0; | 728 | dma_data->maxburst = 0; |
707 | } | 729 | } |
708 | return 0; | 730 | return 0; |
@@ -734,7 +756,6 @@ static int mcasp_common_hw_param(struct davinci_mcasp *mcasp, int stream, | |||
734 | /* Configure the burst size for platform drivers */ | 756 | /* Configure the burst size for platform drivers */ |
735 | if (numevt == 1) | 757 | if (numevt == 1) |
736 | numevt = 0; | 758 | numevt = 0; |
737 | dma_params->fifo_level = numevt; | ||
738 | dma_data->maxburst = numevt; | 759 | dma_data->maxburst = numevt; |
739 | 760 | ||
740 | return 0; | 761 | return 0; |
@@ -855,13 +876,35 @@ static int mcasp_dit_hw_param(struct davinci_mcasp *mcasp, | |||
855 | return 0; | 876 | return 0; |
856 | } | 877 | } |
857 | 878 | ||
879 | static int davinci_mcasp_calc_clk_div(struct davinci_mcasp *mcasp, | ||
880 | unsigned int bclk_freq, | ||
881 | int *error_ppm) | ||
882 | { | ||
883 | int div = mcasp->sysclk_freq / bclk_freq; | ||
884 | int rem = mcasp->sysclk_freq % bclk_freq; | ||
885 | |||
886 | if (rem != 0) { | ||
887 | if (div == 0 || | ||
888 | ((mcasp->sysclk_freq / div) - bclk_freq) > | ||
889 | (bclk_freq - (mcasp->sysclk_freq / (div+1)))) { | ||
890 | div++; | ||
891 | rem = rem - bclk_freq; | ||
892 | } | ||
893 | } | ||
894 | if (error_ppm) | ||
895 | *error_ppm = | ||
896 | (div*1000000 + (int)div64_long(1000000LL*rem, | ||
897 | (int)bclk_freq)) | ||
898 | /div - 1000000; | ||
899 | |||
900 | return div; | ||
901 | } | ||
902 | |||
858 | static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream, | 903 | static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream, |
859 | struct snd_pcm_hw_params *params, | 904 | struct snd_pcm_hw_params *params, |
860 | struct snd_soc_dai *cpu_dai) | 905 | struct snd_soc_dai *cpu_dai) |
861 | { | 906 | { |
862 | struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai); | 907 | 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; | 908 | int word_length; |
866 | int channels = params_channels(params); | 909 | int channels = params_channels(params); |
867 | int period_size = params_period_size(params); | 910 | int period_size = params_period_size(params); |
@@ -872,16 +915,20 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream, | |||
872 | * the machine driver, we need to calculate the ratio. | 915 | * the machine driver, we need to calculate the ratio. |
873 | */ | 916 | */ |
874 | if (mcasp->bclk_master && mcasp->bclk_div == 0 && mcasp->sysclk_freq) { | 917 | if (mcasp->bclk_master && mcasp->bclk_div == 0 && mcasp->sysclk_freq) { |
875 | unsigned int bclk_freq = snd_soc_params_to_bclk(params); | 918 | int channels = params_channels(params); |
876 | unsigned int div = mcasp->sysclk_freq / bclk_freq; | 919 | int rate = params_rate(params); |
877 | if (mcasp->sysclk_freq % bclk_freq != 0) { | 920 | int sbits = params_width(params); |
878 | if (((mcasp->sysclk_freq / div) - bclk_freq) > | 921 | int ppm, div; |
879 | (bclk_freq - (mcasp->sysclk_freq / (div+1)))) | 922 | |
880 | div++; | 923 | if (channels > mcasp->tdm_slots) |
881 | dev_warn(mcasp->dev, | 924 | channels = mcasp->tdm_slots; |
882 | "Inaccurate BCLK: %u Hz / %u != %u Hz\n", | 925 | |
883 | mcasp->sysclk_freq, div, bclk_freq); | 926 | div = davinci_mcasp_calc_clk_div(mcasp, rate*sbits*channels, |
884 | } | 927 | &ppm); |
928 | if (ppm) | ||
929 | dev_info(mcasp->dev, "Sample-rate is off by %d PPM\n", | ||
930 | ppm); | ||
931 | |||
885 | __davinci_mcasp_set_clkdiv(cpu_dai, 1, div, 0); | 932 | __davinci_mcasp_set_clkdiv(cpu_dai, 1, div, 0); |
886 | } | 933 | } |
887 | 934 | ||
@@ -902,31 +949,26 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream, | |||
902 | switch (params_format(params)) { | 949 | switch (params_format(params)) { |
903 | case SNDRV_PCM_FORMAT_U8: | 950 | case SNDRV_PCM_FORMAT_U8: |
904 | case SNDRV_PCM_FORMAT_S8: | 951 | case SNDRV_PCM_FORMAT_S8: |
905 | dma_params->data_type = 1; | ||
906 | word_length = 8; | 952 | word_length = 8; |
907 | break; | 953 | break; |
908 | 954 | ||
909 | case SNDRV_PCM_FORMAT_U16_LE: | 955 | case SNDRV_PCM_FORMAT_U16_LE: |
910 | case SNDRV_PCM_FORMAT_S16_LE: | 956 | case SNDRV_PCM_FORMAT_S16_LE: |
911 | dma_params->data_type = 2; | ||
912 | word_length = 16; | 957 | word_length = 16; |
913 | break; | 958 | break; |
914 | 959 | ||
915 | case SNDRV_PCM_FORMAT_U24_3LE: | 960 | case SNDRV_PCM_FORMAT_U24_3LE: |
916 | case SNDRV_PCM_FORMAT_S24_3LE: | 961 | case SNDRV_PCM_FORMAT_S24_3LE: |
917 | dma_params->data_type = 3; | ||
918 | word_length = 24; | 962 | word_length = 24; |
919 | break; | 963 | break; |
920 | 964 | ||
921 | case SNDRV_PCM_FORMAT_U24_LE: | 965 | case SNDRV_PCM_FORMAT_U24_LE: |
922 | case SNDRV_PCM_FORMAT_S24_LE: | 966 | case SNDRV_PCM_FORMAT_S24_LE: |
923 | dma_params->data_type = 4; | ||
924 | word_length = 24; | 967 | word_length = 24; |
925 | break; | 968 | break; |
926 | 969 | ||
927 | case SNDRV_PCM_FORMAT_U32_LE: | 970 | case SNDRV_PCM_FORMAT_U32_LE: |
928 | case SNDRV_PCM_FORMAT_S32_LE: | 971 | case SNDRV_PCM_FORMAT_S32_LE: |
929 | dma_params->data_type = 4; | ||
930 | word_length = 32; | 972 | word_length = 32; |
931 | break; | 973 | break; |
932 | 974 | ||
@@ -935,11 +977,6 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream, | |||
935 | return -EINVAL; | 977 | return -EINVAL; |
936 | } | 978 | } |
937 | 979 | ||
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); | 980 | davinci_config_channel_size(mcasp, word_length); |
944 | 981 | ||
945 | if (mcasp->op_mode == DAVINCI_MCASP_IIS_MODE) | 982 | if (mcasp->op_mode == DAVINCI_MCASP_IIS_MODE) |
@@ -973,10 +1010,126 @@ static int davinci_mcasp_trigger(struct snd_pcm_substream *substream, | |||
973 | return ret; | 1010 | return ret; |
974 | } | 1011 | } |
975 | 1012 | ||
1013 | static const unsigned int davinci_mcasp_dai_rates[] = { | ||
1014 | 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, | ||
1015 | 88200, 96000, 176400, 192000, | ||
1016 | }; | ||
1017 | |||
1018 | #define DAVINCI_MAX_RATE_ERROR_PPM 1000 | ||
1019 | |||
1020 | static int davinci_mcasp_hw_rule_rate(struct snd_pcm_hw_params *params, | ||
1021 | struct snd_pcm_hw_rule *rule) | ||
1022 | { | ||
1023 | struct davinci_mcasp_ruledata *rd = rule->private; | ||
1024 | struct snd_interval *ri = | ||
1025 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); | ||
1026 | int sbits = params_width(params); | ||
1027 | int channels = params_channels(params); | ||
1028 | unsigned int list[ARRAY_SIZE(davinci_mcasp_dai_rates)]; | ||
1029 | int i, count = 0; | ||
1030 | |||
1031 | if (channels > rd->mcasp->tdm_slots) | ||
1032 | channels = rd->mcasp->tdm_slots; | ||
1033 | |||
1034 | for (i = 0; i < ARRAY_SIZE(davinci_mcasp_dai_rates); i++) { | ||
1035 | if (ri->min <= davinci_mcasp_dai_rates[i] && | ||
1036 | ri->max >= davinci_mcasp_dai_rates[i]) { | ||
1037 | uint bclk_freq = sbits*channels* | ||
1038 | davinci_mcasp_dai_rates[i]; | ||
1039 | int ppm; | ||
1040 | |||
1041 | davinci_mcasp_calc_clk_div(rd->mcasp, bclk_freq, &ppm); | ||
1042 | if (abs(ppm) < DAVINCI_MAX_RATE_ERROR_PPM) | ||
1043 | list[count++] = davinci_mcasp_dai_rates[i]; | ||
1044 | } | ||
1045 | } | ||
1046 | dev_dbg(rd->mcasp->dev, | ||
1047 | "%d frequencies (%d-%d) for %d sbits and %d channels\n", | ||
1048 | count, ri->min, ri->max, sbits, channels); | ||
1049 | |||
1050 | return snd_interval_list(hw_param_interval(params, rule->var), | ||
1051 | count, list, 0); | ||
1052 | } | ||
1053 | |||
1054 | static int davinci_mcasp_hw_rule_format(struct snd_pcm_hw_params *params, | ||
1055 | struct snd_pcm_hw_rule *rule) | ||
1056 | { | ||
1057 | struct davinci_mcasp_ruledata *rd = rule->private; | ||
1058 | struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); | ||
1059 | struct snd_mask nfmt; | ||
1060 | int rate = params_rate(params); | ||
1061 | int channels = params_channels(params); | ||
1062 | int i, count = 0; | ||
1063 | |||
1064 | snd_mask_none(&nfmt); | ||
1065 | |||
1066 | if (channels > rd->mcasp->tdm_slots) | ||
1067 | channels = rd->mcasp->tdm_slots; | ||
1068 | |||
1069 | for (i = 0; i < SNDRV_PCM_FORMAT_LAST; i++) { | ||
1070 | if (snd_mask_test(fmt, i)) { | ||
1071 | uint bclk_freq = snd_pcm_format_width(i)*channels*rate; | ||
1072 | int ppm; | ||
1073 | |||
1074 | davinci_mcasp_calc_clk_div(rd->mcasp, bclk_freq, &ppm); | ||
1075 | if (abs(ppm) < DAVINCI_MAX_RATE_ERROR_PPM) { | ||
1076 | snd_mask_set(&nfmt, i); | ||
1077 | count++; | ||
1078 | } | ||
1079 | } | ||
1080 | } | ||
1081 | dev_dbg(rd->mcasp->dev, | ||
1082 | "%d possible sample format for %d Hz and %d channels\n", | ||
1083 | count, rate, channels); | ||
1084 | |||
1085 | return snd_mask_refine(fmt, &nfmt); | ||
1086 | } | ||
1087 | |||
1088 | static int davinci_mcasp_hw_rule_channels(struct snd_pcm_hw_params *params, | ||
1089 | struct snd_pcm_hw_rule *rule) | ||
1090 | { | ||
1091 | struct davinci_mcasp_ruledata *rd = rule->private; | ||
1092 | struct snd_interval *ci = | ||
1093 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); | ||
1094 | int sbits = params_width(params); | ||
1095 | int rate = params_rate(params); | ||
1096 | int max_chan_per_wire = rd->mcasp->tdm_slots < ci->max ? | ||
1097 | rd->mcasp->tdm_slots : ci->max; | ||
1098 | unsigned int list[ci->max - ci->min + 1]; | ||
1099 | int c1, c, count = 0; | ||
1100 | |||
1101 | for (c1 = ci->min; c1 <= max_chan_per_wire; c1++) { | ||
1102 | uint bclk_freq = c1*sbits*rate; | ||
1103 | int ppm; | ||
1104 | |||
1105 | davinci_mcasp_calc_clk_div(rd->mcasp, bclk_freq, &ppm); | ||
1106 | if (abs(ppm) < DAVINCI_MAX_RATE_ERROR_PPM) { | ||
1107 | /* If we can use all tdm_slots, we can put any | ||
1108 | amount of channels to remaining wires as | ||
1109 | long as they fit in. */ | ||
1110 | if (c1 == rd->mcasp->tdm_slots) { | ||
1111 | for (c = c1; c <= rd->serializers*c1 && | ||
1112 | c <= ci->max; c++) | ||
1113 | list[count++] = c; | ||
1114 | } else { | ||
1115 | list[count++] = c1; | ||
1116 | } | ||
1117 | } | ||
1118 | } | ||
1119 | dev_dbg(rd->mcasp->dev, | ||
1120 | "%d possible channel counts (%d-%d) for %d Hz and %d sbits\n", | ||
1121 | count, ci->min, ci->max, rate, sbits); | ||
1122 | |||
1123 | return snd_interval_list(hw_param_interval(params, rule->var), | ||
1124 | count, list, 0); | ||
1125 | } | ||
1126 | |||
976 | static int davinci_mcasp_startup(struct snd_pcm_substream *substream, | 1127 | static int davinci_mcasp_startup(struct snd_pcm_substream *substream, |
977 | struct snd_soc_dai *cpu_dai) | 1128 | struct snd_soc_dai *cpu_dai) |
978 | { | 1129 | { |
979 | struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai); | 1130 | struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai); |
1131 | struct davinci_mcasp_ruledata *ruledata = | ||
1132 | &mcasp->ruledata[substream->stream]; | ||
980 | u32 max_channels = 0; | 1133 | u32 max_channels = 0; |
981 | int i, dir; | 1134 | int i, dir; |
982 | 1135 | ||
@@ -998,6 +1151,7 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream, | |||
998 | if (mcasp->serial_dir[i] == dir) | 1151 | if (mcasp->serial_dir[i] == dir) |
999 | max_channels++; | 1152 | max_channels++; |
1000 | } | 1153 | } |
1154 | ruledata->serializers = max_channels; | ||
1001 | max_channels *= mcasp->tdm_slots; | 1155 | max_channels *= mcasp->tdm_slots; |
1002 | /* | 1156 | /* |
1003 | * If the already active stream has less channels than the calculated | 1157 | * If the already active stream has less channels than the calculated |
@@ -1012,6 +1166,42 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream, | |||
1012 | snd_pcm_hw_constraint_minmax(substream->runtime, | 1166 | snd_pcm_hw_constraint_minmax(substream->runtime, |
1013 | SNDRV_PCM_HW_PARAM_CHANNELS, | 1167 | SNDRV_PCM_HW_PARAM_CHANNELS, |
1014 | 2, max_channels); | 1168 | 2, max_channels); |
1169 | |||
1170 | /* | ||
1171 | * If we rely on implicit BCLK divider setting we should | ||
1172 | * set constraints based on what we can provide. | ||
1173 | */ | ||
1174 | if (mcasp->bclk_master && mcasp->bclk_div == 0 && mcasp->sysclk_freq) { | ||
1175 | int ret; | ||
1176 | |||
1177 | ruledata->mcasp = mcasp; | ||
1178 | |||
1179 | ret = snd_pcm_hw_rule_add(substream->runtime, 0, | ||
1180 | SNDRV_PCM_HW_PARAM_RATE, | ||
1181 | davinci_mcasp_hw_rule_rate, | ||
1182 | ruledata, | ||
1183 | SNDRV_PCM_HW_PARAM_FORMAT, | ||
1184 | SNDRV_PCM_HW_PARAM_CHANNELS, -1); | ||
1185 | if (ret) | ||
1186 | return ret; | ||
1187 | ret = snd_pcm_hw_rule_add(substream->runtime, 0, | ||
1188 | SNDRV_PCM_HW_PARAM_FORMAT, | ||
1189 | davinci_mcasp_hw_rule_format, | ||
1190 | ruledata, | ||
1191 | SNDRV_PCM_HW_PARAM_RATE, | ||
1192 | SNDRV_PCM_HW_PARAM_CHANNELS, -1); | ||
1193 | if (ret) | ||
1194 | return ret; | ||
1195 | ret = snd_pcm_hw_rule_add(substream->runtime, 0, | ||
1196 | SNDRV_PCM_HW_PARAM_CHANNELS, | ||
1197 | davinci_mcasp_hw_rule_channels, | ||
1198 | ruledata, | ||
1199 | SNDRV_PCM_HW_PARAM_RATE, | ||
1200 | SNDRV_PCM_HW_PARAM_FORMAT, -1); | ||
1201 | if (ret) | ||
1202 | return ret; | ||
1203 | } | ||
1204 | |||
1015 | return 0; | 1205 | return 0; |
1016 | } | 1206 | } |
1017 | 1207 | ||
@@ -1043,17 +1233,8 @@ static int davinci_mcasp_dai_probe(struct snd_soc_dai *dai) | |||
1043 | { | 1233 | { |
1044 | struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai); | 1234 | struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai); |
1045 | 1235 | ||
1046 | if (mcasp->version >= MCASP_VERSION_3) { | 1236 | dai->playback_dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK]; |
1047 | /* Using dmaengine PCM */ | 1237 | 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 | 1238 | ||
1058 | return 0; | 1239 | return 0; |
1059 | } | 1240 | } |
@@ -1066,6 +1247,10 @@ static int davinci_mcasp_suspend(struct snd_soc_dai *dai) | |||
1066 | u32 reg; | 1247 | u32 reg; |
1067 | int i; | 1248 | int i; |
1068 | 1249 | ||
1250 | context->pm_state = pm_runtime_enabled(mcasp->dev); | ||
1251 | if (!context->pm_state) | ||
1252 | pm_runtime_get_sync(mcasp->dev); | ||
1253 | |||
1069 | for (i = 0; i < ARRAY_SIZE(context_regs); i++) | 1254 | for (i = 0; i < ARRAY_SIZE(context_regs); i++) |
1070 | context->config_regs[i] = mcasp_get_reg(mcasp, context_regs[i]); | 1255 | context->config_regs[i] = mcasp_get_reg(mcasp, context_regs[i]); |
1071 | 1256 | ||
@@ -1082,6 +1267,8 @@ static int davinci_mcasp_suspend(struct snd_soc_dai *dai) | |||
1082 | context->xrsr_regs[i] = mcasp_get_reg(mcasp, | 1267 | context->xrsr_regs[i] = mcasp_get_reg(mcasp, |
1083 | DAVINCI_MCASP_XRSRCTL_REG(i)); | 1268 | DAVINCI_MCASP_XRSRCTL_REG(i)); |
1084 | 1269 | ||
1270 | pm_runtime_put_sync(mcasp->dev); | ||
1271 | |||
1085 | return 0; | 1272 | return 0; |
1086 | } | 1273 | } |
1087 | 1274 | ||
@@ -1092,6 +1279,8 @@ static int davinci_mcasp_resume(struct snd_soc_dai *dai) | |||
1092 | u32 reg; | 1279 | u32 reg; |
1093 | int i; | 1280 | int i; |
1094 | 1281 | ||
1282 | pm_runtime_get_sync(mcasp->dev); | ||
1283 | |||
1095 | for (i = 0; i < ARRAY_SIZE(context_regs); i++) | 1284 | for (i = 0; i < ARRAY_SIZE(context_regs); i++) |
1096 | mcasp_set_reg(mcasp, context_regs[i], context->config_regs[i]); | 1285 | mcasp_set_reg(mcasp, context_regs[i], context->config_regs[i]); |
1097 | 1286 | ||
@@ -1108,6 +1297,9 @@ static int davinci_mcasp_resume(struct snd_soc_dai *dai) | |||
1108 | mcasp_set_reg(mcasp, DAVINCI_MCASP_XRSRCTL_REG(i), | 1297 | mcasp_set_reg(mcasp, DAVINCI_MCASP_XRSRCTL_REG(i), |
1109 | context->xrsr_regs[i]); | 1298 | context->xrsr_regs[i]); |
1110 | 1299 | ||
1300 | if (!context->pm_state) | ||
1301 | pm_runtime_put_sync(mcasp->dev); | ||
1302 | |||
1111 | return 0; | 1303 | return 0; |
1112 | } | 1304 | } |
1113 | #else | 1305 | #else |
@@ -1172,28 +1364,24 @@ static const struct snd_soc_component_driver davinci_mcasp_component = { | |||
1172 | static struct davinci_mcasp_pdata dm646x_mcasp_pdata = { | 1364 | static struct davinci_mcasp_pdata dm646x_mcasp_pdata = { |
1173 | .tx_dma_offset = 0x400, | 1365 | .tx_dma_offset = 0x400, |
1174 | .rx_dma_offset = 0x400, | 1366 | .rx_dma_offset = 0x400, |
1175 | .asp_chan_q = EVENTQ_0, | ||
1176 | .version = MCASP_VERSION_1, | 1367 | .version = MCASP_VERSION_1, |
1177 | }; | 1368 | }; |
1178 | 1369 | ||
1179 | static struct davinci_mcasp_pdata da830_mcasp_pdata = { | 1370 | static struct davinci_mcasp_pdata da830_mcasp_pdata = { |
1180 | .tx_dma_offset = 0x2000, | 1371 | .tx_dma_offset = 0x2000, |
1181 | .rx_dma_offset = 0x2000, | 1372 | .rx_dma_offset = 0x2000, |
1182 | .asp_chan_q = EVENTQ_0, | ||
1183 | .version = MCASP_VERSION_2, | 1373 | .version = MCASP_VERSION_2, |
1184 | }; | 1374 | }; |
1185 | 1375 | ||
1186 | static struct davinci_mcasp_pdata am33xx_mcasp_pdata = { | 1376 | static struct davinci_mcasp_pdata am33xx_mcasp_pdata = { |
1187 | .tx_dma_offset = 0, | 1377 | .tx_dma_offset = 0, |
1188 | .rx_dma_offset = 0, | 1378 | .rx_dma_offset = 0, |
1189 | .asp_chan_q = EVENTQ_0, | ||
1190 | .version = MCASP_VERSION_3, | 1379 | .version = MCASP_VERSION_3, |
1191 | }; | 1380 | }; |
1192 | 1381 | ||
1193 | static struct davinci_mcasp_pdata dra7_mcasp_pdata = { | 1382 | static struct davinci_mcasp_pdata dra7_mcasp_pdata = { |
1194 | .tx_dma_offset = 0x200, | 1383 | .tx_dma_offset = 0x200, |
1195 | .rx_dma_offset = 0x284, | 1384 | .rx_dma_offset = 0x284, |
1196 | .asp_chan_q = EVENTQ_0, | ||
1197 | .version = MCASP_VERSION_4, | 1385 | .version = MCASP_VERSION_4, |
1198 | }; | 1386 | }; |
1199 | 1387 | ||
@@ -1370,12 +1558,12 @@ nodata: | |||
1370 | 1558 | ||
1371 | static int davinci_mcasp_probe(struct platform_device *pdev) | 1559 | static int davinci_mcasp_probe(struct platform_device *pdev) |
1372 | { | 1560 | { |
1373 | struct davinci_pcm_dma_params *dma_params; | ||
1374 | struct snd_dmaengine_dai_dma_data *dma_data; | 1561 | struct snd_dmaengine_dai_dma_data *dma_data; |
1375 | struct resource *mem, *ioarea, *res, *dat; | 1562 | struct resource *mem, *ioarea, *res, *dat; |
1376 | struct davinci_mcasp_pdata *pdata; | 1563 | struct davinci_mcasp_pdata *pdata; |
1377 | struct davinci_mcasp *mcasp; | 1564 | struct davinci_mcasp *mcasp; |
1378 | char *irq_name; | 1565 | char *irq_name; |
1566 | int *dma; | ||
1379 | int irq; | 1567 | int irq; |
1380 | int ret; | 1568 | int ret; |
1381 | 1569 | ||
@@ -1415,13 +1603,6 @@ static int davinci_mcasp_probe(struct platform_device *pdev) | |||
1415 | 1603 | ||
1416 | pm_runtime_enable(&pdev->dev); | 1604 | pm_runtime_enable(&pdev->dev); |
1417 | 1605 | ||
1418 | ret = pm_runtime_get_sync(&pdev->dev); | ||
1419 | if (IS_ERR_VALUE(ret)) { | ||
1420 | dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n"); | ||
1421 | pm_runtime_disable(&pdev->dev); | ||
1422 | return ret; | ||
1423 | } | ||
1424 | |||
1425 | mcasp->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); | 1606 | mcasp->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); |
1426 | if (!mcasp->base) { | 1607 | if (!mcasp->base) { |
1427 | dev_err(&pdev->dev, "ioremap failed\n"); | 1608 | dev_err(&pdev->dev, "ioremap failed\n"); |
@@ -1509,59 +1690,45 @@ static int davinci_mcasp_probe(struct platform_device *pdev) | |||
1509 | if (dat) | 1690 | if (dat) |
1510 | mcasp->dat_port = true; | 1691 | mcasp->dat_port = true; |
1511 | 1692 | ||
1512 | dma_params = &mcasp->dma_params[SNDRV_PCM_STREAM_PLAYBACK]; | ||
1513 | dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK]; | 1693 | 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) | 1694 | if (dat) |
1519 | dma_params->dma_addr = dat->start; | 1695 | dma_data->addr = dat->start; |
1520 | else | 1696 | else |
1521 | dma_params->dma_addr = mem->start + pdata->tx_dma_offset; | 1697 | dma_data->addr = mem->start + pdata->tx_dma_offset; |
1522 | |||
1523 | /* Unconditional dmaengine stuff */ | ||
1524 | dma_data->addr = dma_params->dma_addr; | ||
1525 | 1698 | ||
1699 | dma = &mcasp->dma_request[SNDRV_PCM_STREAM_PLAYBACK]; | ||
1526 | res = platform_get_resource(pdev, IORESOURCE_DMA, 0); | 1700 | res = platform_get_resource(pdev, IORESOURCE_DMA, 0); |
1527 | if (res) | 1701 | if (res) |
1528 | dma_params->channel = res->start; | 1702 | *dma = res->start; |
1529 | else | 1703 | else |
1530 | dma_params->channel = pdata->tx_dma_channel; | 1704 | *dma = pdata->tx_dma_channel; |
1531 | 1705 | ||
1532 | /* dmaengine filter data for DT and non-DT boot */ | 1706 | /* dmaengine filter data for DT and non-DT boot */ |
1533 | if (pdev->dev.of_node) | 1707 | if (pdev->dev.of_node) |
1534 | dma_data->filter_data = "tx"; | 1708 | dma_data->filter_data = "tx"; |
1535 | else | 1709 | else |
1536 | dma_data->filter_data = &dma_params->channel; | 1710 | dma_data->filter_data = dma; |
1537 | 1711 | ||
1538 | /* RX is not valid in DIT mode */ | 1712 | /* RX is not valid in DIT mode */ |
1539 | if (mcasp->op_mode != DAVINCI_MCASP_DIT_MODE) { | 1713 | 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]; | 1714 | 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) | 1715 | if (dat) |
1547 | dma_params->dma_addr = dat->start; | 1716 | dma_data->addr = dat->start; |
1548 | else | 1717 | else |
1549 | dma_params->dma_addr = mem->start + pdata->rx_dma_offset; | 1718 | dma_data->addr = mem->start + pdata->rx_dma_offset; |
1550 | |||
1551 | /* Unconditional dmaengine stuff */ | ||
1552 | dma_data->addr = dma_params->dma_addr; | ||
1553 | 1719 | ||
1720 | dma = &mcasp->dma_request[SNDRV_PCM_STREAM_CAPTURE]; | ||
1554 | res = platform_get_resource(pdev, IORESOURCE_DMA, 1); | 1721 | res = platform_get_resource(pdev, IORESOURCE_DMA, 1); |
1555 | if (res) | 1722 | if (res) |
1556 | dma_params->channel = res->start; | 1723 | *dma = res->start; |
1557 | else | 1724 | else |
1558 | dma_params->channel = pdata->rx_dma_channel; | 1725 | *dma = pdata->rx_dma_channel; |
1559 | 1726 | ||
1560 | /* dmaengine filter data for DT and non-DT boot */ | 1727 | /* dmaengine filter data for DT and non-DT boot */ |
1561 | if (pdev->dev.of_node) | 1728 | if (pdev->dev.of_node) |
1562 | dma_data->filter_data = "rx"; | 1729 | dma_data->filter_data = "rx"; |
1563 | else | 1730 | else |
1564 | dma_data->filter_data = &dma_params->channel; | 1731 | dma_data->filter_data = dma; |
1565 | } | 1732 | } |
1566 | 1733 | ||
1567 | if (mcasp->version < MCASP_VERSION_3) { | 1734 | if (mcasp->version < MCASP_VERSION_3) { |
@@ -1584,17 +1751,11 @@ static int davinci_mcasp_probe(struct platform_device *pdev) | |||
1584 | goto err; | 1751 | goto err; |
1585 | 1752 | ||
1586 | switch (mcasp->version) { | 1753 | 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) || \ | 1754 | #if IS_BUILTIN(CONFIG_SND_EDMA_SOC) || \ |
1596 | (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \ | 1755 | (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \ |
1597 | IS_MODULE(CONFIG_SND_EDMA_SOC)) | 1756 | IS_MODULE(CONFIG_SND_EDMA_SOC)) |
1757 | case MCASP_VERSION_1: | ||
1758 | case MCASP_VERSION_2: | ||
1598 | case MCASP_VERSION_3: | 1759 | case MCASP_VERSION_3: |
1599 | ret = edma_pcm_platform_register(&pdev->dev); | 1760 | ret = edma_pcm_platform_register(&pdev->dev); |
1600 | break; | 1761 | break; |
@@ -1621,14 +1782,12 @@ static int davinci_mcasp_probe(struct platform_device *pdev) | |||
1621 | return 0; | 1782 | return 0; |
1622 | 1783 | ||
1623 | err: | 1784 | err: |
1624 | pm_runtime_put_sync(&pdev->dev); | ||
1625 | pm_runtime_disable(&pdev->dev); | 1785 | pm_runtime_disable(&pdev->dev); |
1626 | return ret; | 1786 | return ret; |
1627 | } | 1787 | } |
1628 | 1788 | ||
1629 | static int davinci_mcasp_remove(struct platform_device *pdev) | 1789 | static int davinci_mcasp_remove(struct platform_device *pdev) |
1630 | { | 1790 | { |
1631 | pm_runtime_put_sync(&pdev->dev); | ||
1632 | pm_runtime_disable(&pdev->dev); | 1791 | pm_runtime_disable(&pdev->dev); |
1633 | 1792 | ||
1634 | return 0; | 1793 | return 0; |
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 | ||
32 | static 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 | ||
44 | static void print_buf_info(int slot, char *name) | ||
45 | { | ||
46 | } | ||
47 | #endif | ||
48 | |||
49 | static 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 | |||
62 | static 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 | */ | ||
111 | struct 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 | |||
124 | static 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 | |||
134 | static 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 | */ | ||
143 | static 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 | |||
205 | static 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 | ||
229 | static 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; | ||
254 | exit2: | ||
255 | if (iram_virt) | ||
256 | gen_pool_free(sram_pool, (unsigned)iram_virt, size); | ||
257 | exit1: | ||
258 | return -ENOMEM; | ||
259 | } | ||
260 | |||
261 | static 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 | ||
270 | static 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 | |||
277 | static 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 | */ | ||
287 | static 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 | */ | ||
390 | static 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; | ||
471 | exit4: | ||
472 | edma_free_channel(prtd->asp_link[1]); | ||
473 | prtd->asp_link[1] = -1; | ||
474 | exit3: | ||
475 | edma_free_channel(prtd->ram_link); | ||
476 | prtd->ram_link = -1; | ||
477 | exit2: | ||
478 | edma_free_channel(prtd->ram_channel); | ||
479 | prtd->ram_channel = -1; | ||
480 | exit1: | ||
481 | return ret; | ||
482 | } | ||
483 | |||
484 | static 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; | ||
530 | exit2: | ||
531 | edma_free_channel(prtd->asp_channel); | ||
532 | prtd->asp_channel = -1; | ||
533 | exit1: | ||
534 | return ret; | ||
535 | } | ||
536 | |||
537 | static 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 | |||
572 | static 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 | |||
621 | static snd_pcm_uframes_t | ||
622 | davinci_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 | |||
652 | static 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 | |||
700 | static 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 | |||
734 | static 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 | |||
741 | static int davinci_pcm_hw_free(struct snd_pcm_substream *substream) | ||
742 | { | ||
743 | return snd_pcm_lib_free_pages(substream); | ||
744 | } | ||
745 | |||
746 | static 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 | |||
757 | static 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 | |||
769 | static 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 | |||
791 | static 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 | |||
818 | static 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 | |||
847 | static 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 | |||
853 | int davinci_soc_platform_register(struct device *dev) | ||
854 | { | ||
855 | return devm_snd_soc_register_platform(dev, &davinci_soc_platform); | ||
856 | } | ||
857 | EXPORT_SYMBOL_GPL(davinci_soc_platform_register); | ||
858 | |||
859 | MODULE_AUTHOR("Vladimir Barinov"); | ||
860 | MODULE_DESCRIPTION("TI DAVINCI PCM DMA module"); | ||
861 | MODULE_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 | |||
19 | struct 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) | ||
33 | int davinci_soc_platform_register(struct device *dev); | ||
34 | #else | ||
35 | static 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 | ||
48 | struct davinci_vcif_dev { | 49 | struct 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 | ||
53 | static void davinci_vcif_start(struct snd_pcm_substream *substream) | 55 | static 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 | ||
175 | static 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 | ||
186 | static const struct snd_soc_dai_ops davinci_vcif_dai_ops = { | 169 | static 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 | ||
174 | static 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 | |||
192 | static struct snd_soc_dai_driver davinci_vcif_dai = { | 184 | static 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/Kconfig b/sound/soc/fsl/Kconfig index 081e406b3713..19c302b0d763 100644 --- a/sound/soc/fsl/Kconfig +++ b/sound/soc/fsl/Kconfig | |||
@@ -24,7 +24,7 @@ config SND_SOC_FSL_SAI | |||
24 | in-tree drivers select it automatically. | 24 | in-tree drivers select it automatically. |
25 | 25 | ||
26 | config SND_SOC_FSL_SSI | 26 | config SND_SOC_FSL_SSI |
27 | tristate "Synchronous Serial Interface module support" | 27 | tristate "Synchronous Serial Interface module (SSI) support" |
28 | select SND_SOC_IMX_PCM_DMA if SND_IMX_SOC != n | 28 | select SND_SOC_IMX_PCM_DMA if SND_IMX_SOC != n |
29 | select SND_SOC_IMX_PCM_FIQ if SND_IMX_SOC != n && (MXC_TZIC || MXC_AVIC) | 29 | select SND_SOC_IMX_PCM_FIQ if SND_IMX_SOC != n && (MXC_TZIC || MXC_AVIC) |
30 | select REGMAP_MMIO | 30 | select REGMAP_MMIO |
@@ -35,7 +35,7 @@ config SND_SOC_FSL_SSI | |||
35 | in-tree drivers select it automatically. | 35 | in-tree drivers select it automatically. |
36 | 36 | ||
37 | config SND_SOC_FSL_SPDIF | 37 | config SND_SOC_FSL_SPDIF |
38 | tristate "Sony/Philips Digital Interface module support" | 38 | tristate "Sony/Philips Digital Interface (S/PDIF) module support" |
39 | select REGMAP_MMIO | 39 | select REGMAP_MMIO |
40 | select SND_SOC_IMX_PCM_DMA if SND_IMX_SOC != n | 40 | select SND_SOC_IMX_PCM_DMA if SND_IMX_SOC != n |
41 | select SND_SOC_IMX_PCM_FIQ if SND_IMX_SOC != n && (MXC_TZIC || MXC_AVIC) | 41 | select SND_SOC_IMX_PCM_FIQ if SND_IMX_SOC != n && (MXC_TZIC || MXC_AVIC) |
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/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c index 6b0c8f717ec2..e8bb8eef1d16 100644 --- a/sound/soc/fsl/fsl_ssi.c +++ b/sound/soc/fsl/fsl_ssi.c | |||
@@ -1288,7 +1288,7 @@ static int fsl_ssi_probe(struct platform_device *pdev) | |||
1288 | const struct of_device_id *of_id; | 1288 | const struct of_device_id *of_id; |
1289 | const char *p, *sprop; | 1289 | const char *p, *sprop; |
1290 | const uint32_t *iprop; | 1290 | const uint32_t *iprop; |
1291 | struct resource res; | 1291 | struct resource *res; |
1292 | void __iomem *iomem; | 1292 | void __iomem *iomem; |
1293 | char name[64]; | 1293 | char name[64]; |
1294 | 1294 | ||
@@ -1335,19 +1335,11 @@ static int fsl_ssi_probe(struct platform_device *pdev) | |||
1335 | } | 1335 | } |
1336 | ssi_private->cpu_dai_drv.name = dev_name(&pdev->dev); | 1336 | ssi_private->cpu_dai_drv.name = dev_name(&pdev->dev); |
1337 | 1337 | ||
1338 | /* Get the addresses and IRQ */ | 1338 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1339 | ret = of_address_to_resource(np, 0, &res); | 1339 | iomem = devm_ioremap_resource(&pdev->dev, res); |
1340 | if (ret) { | 1340 | if (IS_ERR(iomem)) |
1341 | dev_err(&pdev->dev, "could not determine device resources\n"); | 1341 | return PTR_ERR(iomem); |
1342 | return ret; | 1342 | ssi_private->ssi_phys = res->start; |
1343 | } | ||
1344 | ssi_private->ssi_phys = res.start; | ||
1345 | |||
1346 | iomem = devm_ioremap(&pdev->dev, res.start, resource_size(&res)); | ||
1347 | if (!iomem) { | ||
1348 | dev_err(&pdev->dev, "could not map device resources\n"); | ||
1349 | return -ENOMEM; | ||
1350 | } | ||
1351 | 1343 | ||
1352 | ret = of_property_match_string(np, "clock-names", "ipg"); | 1344 | ret = of_property_match_string(np, "clock-names", "ipg"); |
1353 | if (ret < 0) { | 1345 | if (ret < 0) { |
@@ -1393,8 +1385,8 @@ static int fsl_ssi_probe(struct platform_device *pdev) | |||
1393 | return ret; | 1385 | return ret; |
1394 | } | 1386 | } |
1395 | 1387 | ||
1396 | ret = snd_soc_register_component(&pdev->dev, &fsl_ssi_component, | 1388 | ret = devm_snd_soc_register_component(&pdev->dev, &fsl_ssi_component, |
1397 | &ssi_private->cpu_dai_drv, 1); | 1389 | &ssi_private->cpu_dai_drv, 1); |
1398 | if (ret) { | 1390 | if (ret) { |
1399 | dev_err(&pdev->dev, "failed to register DAI: %d\n", ret); | 1391 | dev_err(&pdev->dev, "failed to register DAI: %d\n", ret); |
1400 | goto error_asoc_register; | 1392 | goto error_asoc_register; |
@@ -1407,13 +1399,13 @@ static int fsl_ssi_probe(struct platform_device *pdev) | |||
1407 | if (ret < 0) { | 1399 | if (ret < 0) { |
1408 | dev_err(&pdev->dev, "could not claim irq %u\n", | 1400 | dev_err(&pdev->dev, "could not claim irq %u\n", |
1409 | ssi_private->irq); | 1401 | ssi_private->irq); |
1410 | goto error_irq; | 1402 | goto error_asoc_register; |
1411 | } | 1403 | } |
1412 | } | 1404 | } |
1413 | 1405 | ||
1414 | ret = fsl_ssi_debugfs_create(&ssi_private->dbg_stats, &pdev->dev); | 1406 | ret = fsl_ssi_debugfs_create(&ssi_private->dbg_stats, &pdev->dev); |
1415 | if (ret) | 1407 | if (ret) |
1416 | goto error_irq; | 1408 | goto error_asoc_register; |
1417 | 1409 | ||
1418 | /* | 1410 | /* |
1419 | * If codec-handle property is missing from SSI node, we assume | 1411 | * If codec-handle property is missing from SSI node, we assume |
@@ -1454,9 +1446,6 @@ done: | |||
1454 | error_sound_card: | 1446 | error_sound_card: |
1455 | fsl_ssi_debugfs_remove(&ssi_private->dbg_stats); | 1447 | fsl_ssi_debugfs_remove(&ssi_private->dbg_stats); |
1456 | 1448 | ||
1457 | error_irq: | ||
1458 | snd_soc_unregister_component(&pdev->dev); | ||
1459 | |||
1460 | error_asoc_register: | 1449 | error_asoc_register: |
1461 | if (ssi_private->soc->imx) | 1450 | if (ssi_private->soc->imx) |
1462 | fsl_ssi_imx_clean(pdev, ssi_private); | 1451 | fsl_ssi_imx_clean(pdev, ssi_private); |
@@ -1472,7 +1461,6 @@ static int fsl_ssi_remove(struct platform_device *pdev) | |||
1472 | 1461 | ||
1473 | if (ssi_private->pdev) | 1462 | if (ssi_private->pdev) |
1474 | platform_device_unregister(ssi_private->pdev); | 1463 | platform_device_unregister(ssi_private->pdev); |
1475 | snd_soc_unregister_component(&pdev->dev); | ||
1476 | 1464 | ||
1477 | if (ssi_private->soc->imx) | 1465 | if (ssi_private->soc->imx) |
1478 | fsl_ssi_imx_clean(pdev, ssi_private); | 1466 | fsl_ssi_imx_clean(pdev, ssi_private); |
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/mpc5200_psc_ac97.c b/sound/soc/fsl/mpc5200_psc_ac97.c index 08d2a8069b0a..0bab76051fd8 100644 --- a/sound/soc/fsl/mpc5200_psc_ac97.c +++ b/sound/soc/fsl/mpc5200_psc_ac97.c | |||
@@ -326,7 +326,7 @@ static int psc_ac97_of_remove(struct platform_device *op) | |||
326 | } | 326 | } |
327 | 327 | ||
328 | /* Match table for of_platform binding */ | 328 | /* Match table for of_platform binding */ |
329 | static struct of_device_id psc_ac97_match[] = { | 329 | static const struct of_device_id psc_ac97_match[] = { |
330 | { .compatible = "fsl,mpc5200-psc-ac97", }, | 330 | { .compatible = "fsl,mpc5200-psc-ac97", }, |
331 | { .compatible = "fsl,mpc5200b-psc-ac97", }, | 331 | { .compatible = "fsl,mpc5200b-psc-ac97", }, |
332 | {} | 332 | {} |
diff --git a/sound/soc/fsl/mpc5200_psc_i2s.c b/sound/soc/fsl/mpc5200_psc_i2s.c index 51fb0c00fe73..d8232943ccb6 100644 --- a/sound/soc/fsl/mpc5200_psc_i2s.c +++ b/sound/soc/fsl/mpc5200_psc_i2s.c | |||
@@ -217,7 +217,7 @@ static int psc_i2s_of_remove(struct platform_device *op) | |||
217 | } | 217 | } |
218 | 218 | ||
219 | /* Match table for of_platform binding */ | 219 | /* Match table for of_platform binding */ |
220 | static struct of_device_id psc_i2s_match[] = { | 220 | static const struct of_device_id psc_i2s_match[] = { |
221 | { .compatible = "fsl,mpc5200-psc-i2s", }, | 221 | { .compatible = "fsl,mpc5200-psc-i2s", }, |
222 | { .compatible = "fsl,mpc5200b-psc-i2s", }, | 222 | { .compatible = "fsl,mpc5200b-psc-i2s", }, |
223 | {} | 223 | {} |
diff --git a/sound/soc/fsl/pcm030-audio-fabric.c b/sound/soc/fsl/pcm030-audio-fabric.c index c44459d24c50..ec731223cab3 100644 --- a/sound/soc/fsl/pcm030-audio-fabric.c +++ b/sound/soc/fsl/pcm030-audio-fabric.c | |||
@@ -113,7 +113,7 @@ static int pcm030_fabric_remove(struct platform_device *op) | |||
113 | return ret; | 113 | return ret; |
114 | } | 114 | } |
115 | 115 | ||
116 | static struct of_device_id pcm030_audio_match[] = { | 116 | static const struct of_device_id pcm030_audio_match[] = { |
117 | { .compatible = "phytec,pcm030-audio-fabric", }, | 117 | { .compatible = "phytec,pcm030-audio-fabric", }, |
118 | {} | 118 | {} |
119 | }; | 119 | }; |
diff --git a/sound/soc/fsl/wm1133-ev1.c b/sound/soc/fsl/wm1133-ev1.c index a958937ab405..b454972dce35 100644 --- a/sound/soc/fsl/wm1133-ev1.c +++ b/sound/soc/fsl/wm1133-ev1.c | |||
@@ -202,23 +202,20 @@ static struct snd_soc_jack_pin mic_jack_pins[] = { | |||
202 | static int wm1133_ev1_init(struct snd_soc_pcm_runtime *rtd) | 202 | static int wm1133_ev1_init(struct snd_soc_pcm_runtime *rtd) |
203 | { | 203 | { |
204 | struct snd_soc_codec *codec = rtd->codec; | 204 | struct snd_soc_codec *codec = rtd->codec; |
205 | struct snd_soc_dapm_context *dapm = &codec->dapm; | ||
206 | 205 | ||
207 | /* Headphone jack detection */ | 206 | /* Headphone jack detection */ |
208 | snd_soc_jack_new(codec, "Headphone", SND_JACK_HEADPHONE, &hp_jack); | 207 | snd_soc_card_jack_new(rtd->card, "Headphone", SND_JACK_HEADPHONE, |
209 | snd_soc_jack_add_pins(&hp_jack, ARRAY_SIZE(hp_jack_pins), | 208 | &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); | 209 | wm8350_hp_jack_detect(codec, WM8350_JDR, &hp_jack, SND_JACK_HEADPHONE); |
212 | 210 | ||
213 | /* Microphone jack detection */ | 211 | /* Microphone jack detection */ |
214 | snd_soc_jack_new(codec, "Microphone", | 212 | snd_soc_card_jack_new(rtd->card, "Microphone", |
215 | SND_JACK_MICROPHONE | SND_JACK_BTN_0, &mic_jack); | 213 | SND_JACK_MICROPHONE | SND_JACK_BTN_0, &mic_jack, |
216 | snd_soc_jack_add_pins(&mic_jack, ARRAY_SIZE(mic_jack_pins), | 214 | mic_jack_pins, ARRAY_SIZE(mic_jack_pins)); |
217 | mic_jack_pins); | ||
218 | wm8350_mic_jack_detect(codec, &mic_jack, SND_JACK_MICROPHONE, | 215 | wm8350_mic_jack_detect(codec, &mic_jack, SND_JACK_MICROPHONE, |
219 | SND_JACK_BTN_0); | 216 | SND_JACK_BTN_0); |
220 | 217 | ||
221 | snd_soc_dapm_force_enable_pin(dapm, "Mic Bias"); | 218 | snd_soc_dapm_force_enable_pin(&rtd->card->dapm, "Mic Bias"); |
222 | 219 | ||
223 | return 0; | 220 | return 0; |
224 | } | 221 | } |
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index fb550b5869d2..33feee9ca8c3 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c | |||
@@ -125,14 +125,6 @@ static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai, | |||
125 | { | 125 | { |
126 | int ret; | 126 | int ret; |
127 | 127 | ||
128 | if (set->fmt) { | ||
129 | ret = snd_soc_dai_set_fmt(dai, set->fmt); | ||
130 | if (ret && ret != -ENOTSUPP) { | ||
131 | dev_err(dai->dev, "simple-card: set_fmt error\n"); | ||
132 | goto err; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | if (set->sysclk) { | 128 | if (set->sysclk) { |
137 | ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0); | 129 | ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0); |
138 | if (ret && ret != -ENOTSUPP) { | 130 | if (ret && ret != -ENOTSUPP) { |
@@ -176,11 +168,11 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) | |||
176 | return ret; | 168 | return ret; |
177 | 169 | ||
178 | if (gpio_is_valid(priv->gpio_hp_det)) { | 170 | if (gpio_is_valid(priv->gpio_hp_det)) { |
179 | snd_soc_jack_new(codec->codec, "Headphones", SND_JACK_HEADPHONE, | 171 | snd_soc_card_jack_new(rtd->card, "Headphones", |
180 | &simple_card_hp_jack); | 172 | SND_JACK_HEADPHONE, |
181 | snd_soc_jack_add_pins(&simple_card_hp_jack, | 173 | &simple_card_hp_jack, |
182 | ARRAY_SIZE(simple_card_hp_jack_pins), | 174 | simple_card_hp_jack_pins, |
183 | simple_card_hp_jack_pins); | 175 | ARRAY_SIZE(simple_card_hp_jack_pins)); |
184 | 176 | ||
185 | simple_card_hp_jack_gpio.gpio = priv->gpio_hp_det; | 177 | simple_card_hp_jack_gpio.gpio = priv->gpio_hp_det; |
186 | simple_card_hp_jack_gpio.invert = priv->gpio_hp_det_invert; | 178 | simple_card_hp_jack_gpio.invert = priv->gpio_hp_det_invert; |
@@ -189,11 +181,11 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) | |||
189 | } | 181 | } |
190 | 182 | ||
191 | if (gpio_is_valid(priv->gpio_mic_det)) { | 183 | if (gpio_is_valid(priv->gpio_mic_det)) { |
192 | snd_soc_jack_new(codec->codec, "Mic Jack", SND_JACK_MICROPHONE, | 184 | snd_soc_card_jack_new(rtd->card, "Mic Jack", |
193 | &simple_card_mic_jack); | 185 | SND_JACK_MICROPHONE, |
194 | snd_soc_jack_add_pins(&simple_card_mic_jack, | 186 | &simple_card_mic_jack, |
195 | ARRAY_SIZE(simple_card_mic_jack_pins), | 187 | simple_card_mic_jack_pins, |
196 | simple_card_mic_jack_pins); | 188 | ARRAY_SIZE(simple_card_mic_jack_pins)); |
197 | simple_card_mic_jack_gpio.gpio = priv->gpio_mic_det; | 189 | simple_card_mic_jack_gpio.gpio = priv->gpio_mic_det; |
198 | simple_card_mic_jack_gpio.invert = priv->gpio_mic_det_invert; | 190 | simple_card_mic_jack_gpio.invert = priv->gpio_mic_det_invert; |
199 | snd_soc_jack_add_gpios(&simple_card_mic_jack, 1, | 191 | snd_soc_jack_add_gpios(&simple_card_mic_jack, 1, |
@@ -269,12 +261,10 @@ static int asoc_simple_card_parse_daifmt(struct device_node *node, | |||
269 | struct device_node *codec, | 261 | struct device_node *codec, |
270 | char *prefix, int idx) | 262 | char *prefix, int idx) |
271 | { | 263 | { |
264 | struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, idx); | ||
272 | struct device *dev = simple_priv_to_dev(priv); | 265 | struct device *dev = simple_priv_to_dev(priv); |
273 | struct device_node *bitclkmaster = NULL; | 266 | struct device_node *bitclkmaster = NULL; |
274 | struct device_node *framemaster = NULL; | 267 | struct device_node *framemaster = NULL; |
275 | struct simple_dai_props *dai_props = simple_priv_to_props(priv, idx); | ||
276 | struct asoc_simple_dai *cpu_dai = &dai_props->cpu_dai; | ||
277 | struct asoc_simple_dai *codec_dai = &dai_props->codec_dai; | ||
278 | unsigned int daifmt; | 268 | unsigned int daifmt; |
279 | 269 | ||
280 | daifmt = snd_soc_of_parse_daifmt(node, prefix, | 270 | daifmt = snd_soc_of_parse_daifmt(node, prefix, |
@@ -289,8 +279,7 @@ static int asoc_simple_card_parse_daifmt(struct device_node *node, | |||
289 | */ | 279 | */ |
290 | dev_dbg(dev, "Revert to legacy daifmt parsing\n"); | 280 | dev_dbg(dev, "Revert to legacy daifmt parsing\n"); |
291 | 281 | ||
292 | cpu_dai->fmt = codec_dai->fmt = | 282 | daifmt = snd_soc_of_parse_daifmt(codec, NULL, NULL, NULL) | |
293 | snd_soc_of_parse_daifmt(codec, NULL, NULL, NULL) | | ||
294 | (daifmt & ~SND_SOC_DAIFMT_CLOCK_MASK); | 283 | (daifmt & ~SND_SOC_DAIFMT_CLOCK_MASK); |
295 | } else { | 284 | } else { |
296 | if (codec == bitclkmaster) | 285 | if (codec == bitclkmaster) |
@@ -299,11 +288,10 @@ static int asoc_simple_card_parse_daifmt(struct device_node *node, | |||
299 | else | 288 | else |
300 | daifmt |= (codec == framemaster) ? | 289 | daifmt |= (codec == framemaster) ? |
301 | SND_SOC_DAIFMT_CBS_CFM : SND_SOC_DAIFMT_CBS_CFS; | 290 | SND_SOC_DAIFMT_CBS_CFM : SND_SOC_DAIFMT_CBS_CFS; |
302 | |||
303 | cpu_dai->fmt = daifmt; | ||
304 | codec_dai->fmt = daifmt; | ||
305 | } | 291 | } |
306 | 292 | ||
293 | dai_link->dai_fmt = daifmt; | ||
294 | |||
307 | of_node_put(bitclkmaster); | 295 | of_node_put(bitclkmaster); |
308 | of_node_put(framemaster); | 296 | of_node_put(framemaster); |
309 | 297 | ||
@@ -384,13 +372,12 @@ static int asoc_simple_card_dai_link_of(struct device_node *node, | |||
384 | dai_link->init = asoc_simple_card_dai_init; | 372 | dai_link->init = asoc_simple_card_dai_init; |
385 | 373 | ||
386 | dev_dbg(dev, "\tname : %s\n", dai_link->stream_name); | 374 | dev_dbg(dev, "\tname : %s\n", dai_link->stream_name); |
387 | dev_dbg(dev, "\tcpu : %s / %04x / %d\n", | 375 | dev_dbg(dev, "\tformat : %04x\n", dai_link->dai_fmt); |
376 | dev_dbg(dev, "\tcpu : %s / %d\n", | ||
388 | dai_link->cpu_dai_name, | 377 | dai_link->cpu_dai_name, |
389 | dai_props->cpu_dai.fmt, | ||
390 | dai_props->cpu_dai.sysclk); | 378 | dai_props->cpu_dai.sysclk); |
391 | dev_dbg(dev, "\tcodec : %s / %04x / %d\n", | 379 | dev_dbg(dev, "\tcodec : %s / %d\n", |
392 | dai_link->codec_dai_name, | 380 | dai_link->codec_dai_name, |
393 | dai_props->codec_dai.fmt, | ||
394 | dai_props->codec_dai.sysclk); | 381 | dai_props->codec_dai.sysclk); |
395 | 382 | ||
396 | /* | 383 | /* |
@@ -577,14 +564,13 @@ static int asoc_simple_card_probe(struct platform_device *pdev) | |||
577 | dai_link->codec_name = cinfo->codec; | 564 | dai_link->codec_name = cinfo->codec; |
578 | dai_link->cpu_dai_name = cinfo->cpu_dai.name; | 565 | dai_link->cpu_dai_name = cinfo->cpu_dai.name; |
579 | dai_link->codec_dai_name = cinfo->codec_dai.name; | 566 | dai_link->codec_dai_name = cinfo->codec_dai.name; |
567 | dai_link->dai_fmt = cinfo->daifmt; | ||
580 | dai_link->init = asoc_simple_card_dai_init; | 568 | dai_link->init = asoc_simple_card_dai_init; |
581 | memcpy(&priv->dai_props->cpu_dai, &cinfo->cpu_dai, | 569 | memcpy(&priv->dai_props->cpu_dai, &cinfo->cpu_dai, |
582 | sizeof(priv->dai_props->cpu_dai)); | 570 | sizeof(priv->dai_props->cpu_dai)); |
583 | memcpy(&priv->dai_props->codec_dai, &cinfo->codec_dai, | 571 | memcpy(&priv->dai_props->codec_dai, &cinfo->codec_dai, |
584 | sizeof(priv->dai_props->codec_dai)); | 572 | sizeof(priv->dai_props->codec_dai)); |
585 | 573 | ||
586 | priv->dai_props->cpu_dai.fmt |= cinfo->daifmt; | ||
587 | priv->dai_props->codec_dai.fmt |= cinfo->daifmt; | ||
588 | } | 574 | } |
589 | 575 | ||
590 | snd_soc_card_set_drvdata(&priv->snd_card, priv); | 576 | snd_soc_card_set_drvdata(&priv->snd_card, priv); |
diff --git a/sound/soc/intel/Makefile b/sound/soc/intel/Makefile index a8e53c45c6b6..cd9aee9871a3 100644 --- a/sound/soc/intel/Makefile +++ b/sound/soc/intel/Makefile | |||
@@ -1,42 +1,10 @@ | |||
1 | # Core support | 1 | # Core support |
2 | snd-soc-sst-dsp-objs := sst-dsp.o sst-firmware.o | 2 | obj-$(CONFIG_SND_SOC_INTEL_SST) += common/ |
3 | snd-soc-sst-acpi-objs := sst-acpi.o | ||
4 | |||
5 | snd-soc-sst-mfld-platform-objs := sst-mfld-platform-pcm.o \ | ||
6 | sst-mfld-platform-compress.o sst-atom-controls.o | ||
7 | snd-soc-mfld-machine-objs := mfld_machine.o | ||
8 | |||
9 | obj-$(CONFIG_SND_SST_MFLD_PLATFORM) += snd-soc-sst-mfld-platform.o | ||
10 | obj-$(CONFIG_SND_MFLD_MACHINE) += snd-soc-mfld-machine.o | ||
11 | |||
12 | obj-$(CONFIG_SND_SOC_INTEL_SST) += snd-soc-sst-dsp.o | ||
13 | obj-$(CONFIG_SND_SOC_INTEL_SST_ACPI) += snd-soc-sst-acpi.o | ||
14 | 3 | ||
15 | # Platform Support | 4 | # Platform Support |
16 | snd-soc-sst-haswell-pcm-objs := \ | 5 | obj-$(CONFIG_SND_SOC_INTEL_HASWELL) += haswell/ |
17 | sst-haswell-ipc.o sst-haswell-pcm.o sst-haswell-dsp.o | 6 | obj-$(CONFIG_SND_SOC_INTEL_BAYTRAIL) += baytrail/ |
18 | snd-soc-sst-baytrail-pcm-objs := \ | 7 | obj-$(CONFIG_SND_SOC_INTEL_BAYTRAIL) += atom/ |
19 | sst-baytrail-ipc.o sst-baytrail-pcm.o sst-baytrail-dsp.o | ||
20 | |||
21 | obj-$(CONFIG_SND_SOC_INTEL_HASWELL) += snd-soc-sst-haswell-pcm.o | ||
22 | obj-$(CONFIG_SND_SOC_INTEL_BAYTRAIL) += snd-soc-sst-baytrail-pcm.o | ||
23 | 8 | ||
24 | # Machine support | 9 | # Machine support |
25 | snd-soc-sst-haswell-objs := haswell.o | 10 | obj-$(CONFIG_SND_SOC_INTEL_SST) += boards/ |
26 | snd-soc-sst-byt-rt5640-mach-objs := byt-rt5640.o | ||
27 | snd-soc-sst-byt-max98090-mach-objs := byt-max98090.o | ||
28 | snd-soc-sst-broadwell-objs := broadwell.o | ||
29 | snd-soc-sst-bytcr-dpcm-rt5640-objs := bytcr_dpcm_rt5640.o | ||
30 | snd-soc-sst-cht-bsw-rt5672-objs := cht_bsw_rt5672.o | ||
31 | snd-soc-sst-cht-bsw-rt5645-objs := cht_bsw_rt5645.o | ||
32 | |||
33 | obj-$(CONFIG_SND_SOC_INTEL_HASWELL_MACH) += snd-soc-sst-haswell.o | ||
34 | obj-$(CONFIG_SND_SOC_INTEL_BYT_RT5640_MACH) += snd-soc-sst-byt-rt5640-mach.o | ||
35 | obj-$(CONFIG_SND_SOC_INTEL_BYT_MAX98090_MACH) += snd-soc-sst-byt-max98090-mach.o | ||
36 | obj-$(CONFIG_SND_SOC_INTEL_BROADWELL_MACH) += snd-soc-sst-broadwell.o | ||
37 | obj-$(CONFIG_SND_SOC_INTEL_BYTCR_RT5640_MACH) += snd-soc-sst-bytcr-dpcm-rt5640.o | ||
38 | obj-$(CONFIG_SND_SOC_INTEL_CHT_BSW_RT5672_MACH) += snd-soc-sst-cht-bsw-rt5672.o | ||
39 | obj-$(CONFIG_SND_SOC_INTEL_CHT_BSW_RT5645_MACH) += snd-soc-sst-cht-bsw-rt5645.o | ||
40 | |||
41 | # DSP driver | ||
42 | obj-$(CONFIG_SND_SST_IPC) += sst/ | ||
diff --git a/sound/soc/intel/atom/Makefile b/sound/soc/intel/atom/Makefile new file mode 100644 index 000000000000..ce8074fa6d66 --- /dev/null +++ b/sound/soc/intel/atom/Makefile | |||
@@ -0,0 +1,7 @@ | |||
1 | snd-soc-sst-mfld-platform-objs := sst-mfld-platform-pcm.o \ | ||
2 | sst-mfld-platform-compress.o sst-atom-controls.o | ||
3 | |||
4 | obj-$(CONFIG_SND_SST_MFLD_PLATFORM) += snd-soc-sst-mfld-platform.o | ||
5 | |||
6 | # DSP driver | ||
7 | obj-$(CONFIG_SND_SST_IPC) += sst/ | ||
diff --git a/sound/soc/intel/sst-atom-controls.c b/sound/soc/intel/atom/sst-atom-controls.c index 90aa5c0476f3..90aa5c0476f3 100644 --- a/sound/soc/intel/sst-atom-controls.c +++ b/sound/soc/intel/atom/sst-atom-controls.c | |||
diff --git a/sound/soc/intel/sst-atom-controls.h b/sound/soc/intel/atom/sst-atom-controls.h index daecc58f28af..daecc58f28af 100644 --- a/sound/soc/intel/sst-atom-controls.h +++ b/sound/soc/intel/atom/sst-atom-controls.h | |||
diff --git a/sound/soc/intel/sst-mfld-dsp.h b/sound/soc/intel/atom/sst-mfld-dsp.h index 4257263157cd..4257263157cd 100644 --- a/sound/soc/intel/sst-mfld-dsp.h +++ b/sound/soc/intel/atom/sst-mfld-dsp.h | |||
diff --git a/sound/soc/intel/sst-mfld-platform-compress.c b/sound/soc/intel/atom/sst-mfld-platform-compress.c index 395168986462..395168986462 100644 --- a/sound/soc/intel/sst-mfld-platform-compress.c +++ b/sound/soc/intel/atom/sst-mfld-platform-compress.c | |||
diff --git a/sound/soc/intel/sst-mfld-platform-pcm.c b/sound/soc/intel/atom/sst-mfld-platform-pcm.c index 7523cbef8780..2fbaf2c75d17 100644 --- a/sound/soc/intel/sst-mfld-platform-pcm.c +++ b/sound/soc/intel/atom/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 | ||
666 | static int sst_soc_probe(struct snd_soc_platform *platform) | 668 | static 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 | |||
737 | static 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 | |||
759 | static 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 | |||
784 | static const struct dev_pm_ops sst_platform_pm = { | ||
785 | .prepare = sst_soc_prepare, | ||
786 | .complete = sst_soc_complete, | ||
787 | }; | ||
788 | |||
730 | static struct platform_driver sst_platform_driver = { | 789 | static 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/atom/sst-mfld-platform.h index 79c8d1246a8f..9094314be2b0 100644 --- a/sound/soc/intel/sst-mfld-platform.h +++ b/sound/soc/intel/atom/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 | }; |
178 | int sst_register_dsp(struct sst_device *sst); | 179 | int sst_register_dsp(struct sst_device *sst); |
179 | int sst_unregister_dsp(struct sst_device *sst); | 180 | int sst_unregister_dsp(struct sst_device *sst); |
diff --git a/sound/soc/intel/sst/Makefile b/sound/soc/intel/atom/sst/Makefile index fd21726361b5..fd21726361b5 100644 --- a/sound/soc/intel/sst/Makefile +++ b/sound/soc/intel/atom/sst/Makefile | |||
diff --git a/sound/soc/intel/sst/sst.c b/sound/soc/intel/atom/sst/sst.c index 11c578651c1c..96c2e420cce6 100644 --- a/sound/soc/intel/sst/sst.c +++ b/sound/soc/intel/atom/sst/sst.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include <asm/platform_sst_audio.h> | 32 | #include <asm/platform_sst_audio.h> |
33 | #include "../sst-mfld-platform.h" | 33 | #include "../sst-mfld-platform.h" |
34 | #include "sst.h" | 34 | #include "sst.h" |
35 | #include "../sst-dsp.h" | 35 | #include "../../common/sst-dsp.h" |
36 | 36 | ||
37 | MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>"); | 37 | MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>"); |
38 | MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>"); | 38 | MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>"); |
@@ -423,23 +423,135 @@ static int intel_sst_runtime_suspend(struct device *dev) | |||
423 | return ret; | 423 | return ret; |
424 | } | 424 | } |
425 | 425 | ||
426 | static int intel_sst_runtime_resume(struct device *dev) | 426 | static 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; | ||
492 | ddr: | ||
493 | kfree(fw_save->sram); | ||
494 | sram: | ||
495 | kfree(fw_save->dram); | ||
496 | dram: | ||
497 | kfree(fw_save->iram); | ||
498 | iram: | ||
499 | kfree(fw_save); | ||
500 | return ret; | ||
501 | } | ||
502 | |||
503 | static 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 | ||
441 | const struct dev_pm_ops intel_sst_pm = { | 552 | const 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 | }; |
445 | EXPORT_SYMBOL_GPL(intel_sst_pm); | 557 | EXPORT_SYMBOL_GPL(intel_sst_pm); |
diff --git a/sound/soc/intel/sst/sst.h b/sound/soc/intel/atom/sst/sst.h index 562bc483d6b7..3f493862e98d 100644 --- a/sound/soc/intel/sst/sst.h +++ b/sound/soc/intel/atom/sst/sst.h | |||
@@ -337,6 +337,13 @@ struct sst_shim_regs64 { | |||
337 | u64 csr2; | 337 | u64 csr2; |
338 | }; | 338 | }; |
339 | 339 | ||
340 | struct 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, | |||
544 | int sst_context_init(struct intel_sst_drv *ctx); | 553 | int sst_context_init(struct intel_sst_drv *ctx); |
545 | void sst_context_cleanup(struct intel_sst_drv *ctx); | 554 | void sst_context_cleanup(struct intel_sst_drv *ctx); |
546 | void sst_configure_runtime_pm(struct intel_sst_drv *ctx); | 555 | void sst_configure_runtime_pm(struct intel_sst_drv *ctx); |
556 | void memcpy32_toio(void __iomem *dst, const void *src, int count); | ||
557 | void memcpy32_fromio(void *dst, const void __iomem *src, int count); | ||
558 | |||
547 | #endif | 559 | #endif |
diff --git a/sound/soc/intel/sst/sst_acpi.c b/sound/soc/intel/atom/sst/sst_acpi.c index b782dfdcdbba..05f693083911 100644 --- a/sound/soc/intel/sst/sst_acpi.c +++ b/sound/soc/intel/atom/sst/sst_acpi.c | |||
@@ -39,7 +39,7 @@ | |||
39 | #include <acpi/actypes.h> | 39 | #include <acpi/actypes.h> |
40 | #include <acpi/acpi_bus.h> | 40 | #include <acpi/acpi_bus.h> |
41 | #include "../sst-mfld-platform.h" | 41 | #include "../sst-mfld-platform.h" |
42 | #include "../sst-dsp.h" | 42 | #include "../../common/sst-dsp.h" |
43 | #include "sst.h" | 43 | #include "sst.h" |
44 | 44 | ||
45 | struct sst_machines { | 45 | struct sst_machines { |
@@ -309,7 +309,7 @@ static int sst_acpi_probe(struct platform_device *pdev) | |||
309 | ctx->shim_regs64 = devm_kzalloc(ctx->dev, sizeof(*ctx->shim_regs64), | 309 | ctx->shim_regs64 = devm_kzalloc(ctx->dev, sizeof(*ctx->shim_regs64), |
310 | GFP_KERNEL); | 310 | GFP_KERNEL); |
311 | if (!ctx->shim_regs64) { | 311 | if (!ctx->shim_regs64) { |
312 | return -ENOMEM; | 312 | ret = -ENOMEM; |
313 | goto do_sst_cleanup; | 313 | goto do_sst_cleanup; |
314 | } | 314 | } |
315 | 315 | ||
diff --git a/sound/soc/intel/sst/sst_drv_interface.c b/sound/soc/intel/atom/sst/sst_drv_interface.c index 5f75ef3cdd22..7b50a9d17ec1 100644 --- a/sound/soc/intel/sst/sst_drv_interface.c +++ b/sound/soc/intel/atom/sst/sst_drv_interface.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include <asm/platform_sst_audio.h> | 32 | #include <asm/platform_sst_audio.h> |
33 | #include "../sst-mfld-platform.h" | 33 | #include "../sst-mfld-platform.h" |
34 | #include "sst.h" | 34 | #include "sst.h" |
35 | #include "../sst-dsp.h" | 35 | #include "../../common/sst-dsp.h" |
36 | 36 | ||
37 | 37 | ||
38 | 38 | ||
@@ -138,12 +138,36 @@ int sst_get_stream(struct intel_sst_drv *ctx, | |||
138 | static int sst_power_control(struct device *dev, bool state) | 138 | static 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 | /* |
@@ -357,7 +381,7 @@ static int sst_cdev_tstamp(struct device *dev, unsigned int str_id, | |||
357 | tstamp->copied_total = fw_tstamp.ring_buffer_counter; | 381 | tstamp->copied_total = fw_tstamp.ring_buffer_counter; |
358 | tstamp->pcm_frames = fw_tstamp.frames_decoded; | 382 | tstamp->pcm_frames = fw_tstamp.frames_decoded; |
359 | tstamp->pcm_io_frames = div_u64(fw_tstamp.hardware_counter, | 383 | tstamp->pcm_io_frames = div_u64(fw_tstamp.hardware_counter, |
360 | (u64)((stream->num_ch) * SST_GET_BYTES_PER_SAMPLE(24))); | 384 | (u64)stream->num_ch * SST_GET_BYTES_PER_SAMPLE(24)); |
361 | tstamp->sampling_rate = fw_tstamp.sampling_frequency; | 385 | tstamp->sampling_rate = fw_tstamp.sampling_frequency; |
362 | 386 | ||
363 | dev_dbg(dev, "PCM = %u\n", tstamp->pcm_io_frames); | 387 | dev_dbg(dev, "PCM = %u\n", tstamp->pcm_io_frames); |
@@ -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 | ||
599 | static 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 | |||
614 | static 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 | |||
575 | static int sst_stream_init(struct device *dev, struct pcm_stream_info *str_info) | 628 | static 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_ipc.c b/sound/soc/intel/atom/sst/sst_ipc.c index 484e60978477..5a278618466c 100644 --- a/sound/soc/intel/sst/sst_ipc.c +++ b/sound/soc/intel/atom/sst/sst_ipc.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include <asm/platform_sst_audio.h> | 32 | #include <asm/platform_sst_audio.h> |
33 | #include "../sst-mfld-platform.h" | 33 | #include "../sst-mfld-platform.h" |
34 | #include "sst.h" | 34 | #include "sst.h" |
35 | #include "../sst-dsp.h" | 35 | #include "../../common/sst-dsp.h" |
36 | 36 | ||
37 | struct sst_block *sst_create_block(struct intel_sst_drv *ctx, | 37 | struct sst_block *sst_create_block(struct intel_sst_drv *ctx, |
38 | u32 msg_id, u32 drv_id) | 38 | u32 msg_id, u32 drv_id) |
diff --git a/sound/soc/intel/sst/sst_loader.c b/sound/soc/intel/atom/sst/sst_loader.c index 7888cd707853..33917146d9c4 100644 --- a/sound/soc/intel/sst/sst_loader.c +++ b/sound/soc/intel/atom/sst/sst_loader.c | |||
@@ -37,9 +37,17 @@ | |||
37 | #include <asm/platform_sst_audio.h> | 37 | #include <asm/platform_sst_audio.h> |
38 | #include "../sst-mfld-platform.h" | 38 | #include "../sst-mfld-platform.h" |
39 | #include "sst.h" | 39 | #include "sst.h" |
40 | #include "../sst-dsp.h" | 40 | #include "../../common/sst-dsp.h" |
41 | 41 | ||
42 | static inline void memcpy32_toio(void __iomem *dst, const void *src, int count) | 42 | void 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 | |||
50 | void 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/intel/sst/sst_pci.c b/sound/soc/intel/atom/sst/sst_pci.c index 3a0b3bf0af97..3a0b3bf0af97 100644 --- a/sound/soc/intel/sst/sst_pci.c +++ b/sound/soc/intel/atom/sst/sst_pci.c | |||
diff --git a/sound/soc/intel/sst/sst_pvt.c b/sound/soc/intel/atom/sst/sst_pvt.c index 4b7720864492..adb32fefd693 100644 --- a/sound/soc/intel/sst/sst_pvt.c +++ b/sound/soc/intel/atom/sst/sst_pvt.c | |||
@@ -34,7 +34,7 @@ | |||
34 | #include <asm/platform_sst_audio.h> | 34 | #include <asm/platform_sst_audio.h> |
35 | #include "../sst-mfld-platform.h" | 35 | #include "../sst-mfld-platform.h" |
36 | #include "sst.h" | 36 | #include "sst.h" |
37 | #include "../sst-dsp.h" | 37 | #include "../../common/sst-dsp.h" |
38 | 38 | ||
39 | int sst_shim_write(void __iomem *addr, int offset, int value) | 39 | int sst_shim_write(void __iomem *addr, int offset, int value) |
40 | { | 40 | { |
@@ -111,30 +111,6 @@ int sst_wait_interruptible(struct intel_sst_drv *sst_drv_ctx, | |||
111 | 111 | ||
112 | } | 112 | } |
113 | 113 | ||
114 | unsigned long long read_shim_data(struct intel_sst_drv *sst, int addr) | ||
115 | { | ||
116 | unsigned long long val = 0; | ||
117 | |||
118 | switch (sst->dev_id) { | ||
119 | case SST_MRFLD_PCI_ID: | ||
120 | case SST_BYT_ACPI_ID: | ||
121 | val = sst_shim_read64(sst->shim, addr); | ||
122 | break; | ||
123 | } | ||
124 | return val; | ||
125 | } | ||
126 | |||
127 | void write_shim_data(struct intel_sst_drv *sst, int addr, | ||
128 | unsigned long long data) | ||
129 | { | ||
130 | switch (sst->dev_id) { | ||
131 | case SST_MRFLD_PCI_ID: | ||
132 | case SST_BYT_ACPI_ID: | ||
133 | sst_shim_write64(sst->shim, addr, (u64) data); | ||
134 | break; | ||
135 | } | ||
136 | } | ||
137 | |||
138 | /* | 114 | /* |
139 | * sst_wait_timeout - wait on event for timeout | 115 | * sst_wait_timeout - wait on event for timeout |
140 | * | 116 | * |
diff --git a/sound/soc/intel/sst/sst_stream.c b/sound/soc/intel/atom/sst/sst_stream.c index dae2a41997aa..a74c64c7053c 100644 --- a/sound/soc/intel/sst/sst_stream.c +++ b/sound/soc/intel/atom/sst/sst_stream.c | |||
@@ -31,7 +31,7 @@ | |||
31 | #include <asm/platform_sst_audio.h> | 31 | #include <asm/platform_sst_audio.h> |
32 | #include "../sst-mfld-platform.h" | 32 | #include "../sst-mfld-platform.h" |
33 | #include "sst.h" | 33 | #include "sst.h" |
34 | #include "../sst-dsp.h" | 34 | #include "../../common/sst-dsp.h" |
35 | 35 | ||
36 | int sst_alloc_stream_mrfld(struct intel_sst_drv *sst_drv_ctx, void *params) | 36 | int sst_alloc_stream_mrfld(struct intel_sst_drv *sst_drv_ctx, void *params) |
37 | { | 37 | { |
diff --git a/sound/soc/intel/baytrail/Makefile b/sound/soc/intel/baytrail/Makefile new file mode 100644 index 000000000000..488408cadf6d --- /dev/null +++ b/sound/soc/intel/baytrail/Makefile | |||
@@ -0,0 +1,4 @@ | |||
1 | snd-soc-sst-baytrail-pcm-objs := \ | ||
2 | sst-baytrail-ipc.o sst-baytrail-pcm.o sst-baytrail-dsp.o | ||
3 | |||
4 | obj-$(CONFIG_SND_SOC_INTEL_BAYTRAIL) += snd-soc-sst-baytrail-pcm.o | ||
diff --git a/sound/soc/intel/sst-baytrail-dsp.c b/sound/soc/intel/baytrail/sst-baytrail-dsp.c index 5a9e56700f31..01d023cc05dd 100644 --- a/sound/soc/intel/sst-baytrail-dsp.c +++ b/sound/soc/intel/baytrail/sst-baytrail-dsp.c | |||
@@ -22,8 +22,8 @@ | |||
22 | #include <linux/platform_device.h> | 22 | #include <linux/platform_device.h> |
23 | #include <linux/firmware.h> | 23 | #include <linux/firmware.h> |
24 | 24 | ||
25 | #include "sst-dsp.h" | 25 | #include "../common/sst-dsp.h" |
26 | #include "sst-dsp-priv.h" | 26 | #include "../common/sst-dsp-priv.h" |
27 | #include "sst-baytrail-ipc.h" | 27 | #include "sst-baytrail-ipc.h" |
28 | 28 | ||
29 | #define SST_BYT_FW_SIGNATURE_SIZE 4 | 29 | #define SST_BYT_FW_SIGNATURE_SIZE 4 |
diff --git a/sound/soc/intel/sst-baytrail-ipc.c b/sound/soc/intel/baytrail/sst-baytrail-ipc.c index b4ad98c43e5c..1efb33b36303 100644 --- a/sound/soc/intel/sst-baytrail-ipc.c +++ b/sound/soc/intel/baytrail/sst-baytrail-ipc.c | |||
@@ -29,8 +29,9 @@ | |||
29 | #include <asm/div64.h> | 29 | #include <asm/div64.h> |
30 | 30 | ||
31 | #include "sst-baytrail-ipc.h" | 31 | #include "sst-baytrail-ipc.h" |
32 | #include "sst-dsp.h" | 32 | #include "../common/sst-dsp.h" |
33 | #include "sst-dsp-priv.h" | 33 | #include "../common/sst-dsp-priv.h" |
34 | #include "../common/sst-ipc.h" | ||
34 | 35 | ||
35 | /* IPC message timeout */ | 36 | /* IPC message timeout */ |
36 | #define IPC_TIMEOUT_MSECS 300 | 37 | #define IPC_TIMEOUT_MSECS 300 |
@@ -142,23 +143,6 @@ struct sst_byt_fw_init { | |||
142 | u8 debug_info; | 143 | u8 debug_info; |
143 | } __packed; | 144 | } __packed; |
144 | 145 | ||
145 | /* driver internal IPC message structure */ | ||
146 | struct ipc_message { | ||
147 | struct list_head list; | ||
148 | u64 header; | ||
149 | |||
150 | /* direction wrt host CPU */ | ||
151 | char tx_data[SST_BYT_IPC_MAX_PAYLOAD_SIZE]; | ||
152 | size_t tx_size; | ||
153 | char rx_data[SST_BYT_IPC_MAX_PAYLOAD_SIZE]; | ||
154 | size_t rx_size; | ||
155 | |||
156 | wait_queue_head_t waitq; | ||
157 | bool complete; | ||
158 | bool wait; | ||
159 | int errno; | ||
160 | }; | ||
161 | |||
162 | struct sst_byt_stream; | 146 | struct sst_byt_stream; |
163 | struct sst_byt; | 147 | struct sst_byt; |
164 | 148 | ||
@@ -195,14 +179,7 @@ struct sst_byt { | |||
195 | struct sst_fw *fw; | 179 | struct sst_fw *fw; |
196 | 180 | ||
197 | /* IPC messaging */ | 181 | /* IPC messaging */ |
198 | struct list_head tx_list; | 182 | struct sst_generic_ipc ipc; |
199 | struct list_head rx_list; | ||
200 | struct list_head empty_list; | ||
201 | wait_queue_head_t wait_txq; | ||
202 | struct task_struct *tx_thread; | ||
203 | struct kthread_worker kworker; | ||
204 | struct kthread_work kwork; | ||
205 | struct ipc_message *msg; | ||
206 | }; | 183 | }; |
207 | 184 | ||
208 | static inline u64 sst_byt_header(int msg_id, int data, bool large, int str_id) | 185 | static inline u64 sst_byt_header(int msg_id, int data, bool large, int str_id) |
@@ -246,209 +223,6 @@ static struct sst_byt_stream *sst_byt_get_stream(struct sst_byt *byt, | |||
246 | return NULL; | 223 | return NULL; |
247 | } | 224 | } |
248 | 225 | ||
249 | static void sst_byt_ipc_shim_dbg(struct sst_byt *byt, const char *text) | ||
250 | { | ||
251 | struct sst_dsp *sst = byt->dsp; | ||
252 | u64 isr, ipcd, imrx, ipcx; | ||
253 | |||
254 | ipcx = sst_dsp_shim_read64_unlocked(sst, SST_IPCX); | ||
255 | isr = sst_dsp_shim_read64_unlocked(sst, SST_ISRX); | ||
256 | ipcd = sst_dsp_shim_read64_unlocked(sst, SST_IPCD); | ||
257 | imrx = sst_dsp_shim_read64_unlocked(sst, SST_IMRX); | ||
258 | |||
259 | dev_err(byt->dev, | ||
260 | "ipc: --%s-- ipcx 0x%llx isr 0x%llx ipcd 0x%llx imrx 0x%llx\n", | ||
261 | text, ipcx, isr, ipcd, imrx); | ||
262 | } | ||
263 | |||
264 | /* locks held by caller */ | ||
265 | static struct ipc_message *sst_byt_msg_get_empty(struct sst_byt *byt) | ||
266 | { | ||
267 | struct ipc_message *msg = NULL; | ||
268 | |||
269 | if (!list_empty(&byt->empty_list)) { | ||
270 | msg = list_first_entry(&byt->empty_list, | ||
271 | struct ipc_message, list); | ||
272 | list_del(&msg->list); | ||
273 | } | ||
274 | |||
275 | return msg; | ||
276 | } | ||
277 | |||
278 | static void sst_byt_ipc_tx_msgs(struct kthread_work *work) | ||
279 | { | ||
280 | struct sst_byt *byt = | ||
281 | container_of(work, struct sst_byt, kwork); | ||
282 | struct ipc_message *msg; | ||
283 | u64 ipcx; | ||
284 | unsigned long flags; | ||
285 | |||
286 | spin_lock_irqsave(&byt->dsp->spinlock, flags); | ||
287 | if (list_empty(&byt->tx_list)) { | ||
288 | spin_unlock_irqrestore(&byt->dsp->spinlock, flags); | ||
289 | return; | ||
290 | } | ||
291 | |||
292 | /* if the DSP is busy we will TX messages after IRQ */ | ||
293 | ipcx = sst_dsp_shim_read64_unlocked(byt->dsp, SST_IPCX); | ||
294 | if (ipcx & SST_BYT_IPCX_BUSY) { | ||
295 | spin_unlock_irqrestore(&byt->dsp->spinlock, flags); | ||
296 | return; | ||
297 | } | ||
298 | |||
299 | msg = list_first_entry(&byt->tx_list, struct ipc_message, list); | ||
300 | |||
301 | list_move(&msg->list, &byt->rx_list); | ||
302 | |||
303 | /* send the message */ | ||
304 | if (msg->header & IPC_HEADER_LARGE(true)) | ||
305 | sst_dsp_outbox_write(byt->dsp, msg->tx_data, msg->tx_size); | ||
306 | sst_dsp_shim_write64_unlocked(byt->dsp, SST_IPCX, msg->header); | ||
307 | |||
308 | spin_unlock_irqrestore(&byt->dsp->spinlock, flags); | ||
309 | } | ||
310 | |||
311 | static inline void sst_byt_tx_msg_reply_complete(struct sst_byt *byt, | ||
312 | struct ipc_message *msg) | ||
313 | { | ||
314 | msg->complete = true; | ||
315 | |||
316 | if (!msg->wait) | ||
317 | list_add_tail(&msg->list, &byt->empty_list); | ||
318 | else | ||
319 | wake_up(&msg->waitq); | ||
320 | } | ||
321 | |||
322 | static void sst_byt_drop_all(struct sst_byt *byt) | ||
323 | { | ||
324 | struct ipc_message *msg, *tmp; | ||
325 | unsigned long flags; | ||
326 | |||
327 | /* drop all TX and Rx messages before we stall + reset DSP */ | ||
328 | spin_lock_irqsave(&byt->dsp->spinlock, flags); | ||
329 | list_for_each_entry_safe(msg, tmp, &byt->tx_list, list) { | ||
330 | list_move(&msg->list, &byt->empty_list); | ||
331 | } | ||
332 | |||
333 | list_for_each_entry_safe(msg, tmp, &byt->rx_list, list) { | ||
334 | list_move(&msg->list, &byt->empty_list); | ||
335 | } | ||
336 | |||
337 | spin_unlock_irqrestore(&byt->dsp->spinlock, flags); | ||
338 | } | ||
339 | |||
340 | static int sst_byt_tx_wait_done(struct sst_byt *byt, struct ipc_message *msg, | ||
341 | void *rx_data) | ||
342 | { | ||
343 | unsigned long flags; | ||
344 | int ret; | ||
345 | |||
346 | /* wait for DSP completion */ | ||
347 | ret = wait_event_timeout(msg->waitq, msg->complete, | ||
348 | msecs_to_jiffies(IPC_TIMEOUT_MSECS)); | ||
349 | |||
350 | spin_lock_irqsave(&byt->dsp->spinlock, flags); | ||
351 | if (ret == 0) { | ||
352 | list_del(&msg->list); | ||
353 | sst_byt_ipc_shim_dbg(byt, "message timeout"); | ||
354 | |||
355 | ret = -ETIMEDOUT; | ||
356 | } else { | ||
357 | |||
358 | /* copy the data returned from DSP */ | ||
359 | if (msg->rx_size) | ||
360 | memcpy(rx_data, msg->rx_data, msg->rx_size); | ||
361 | ret = msg->errno; | ||
362 | } | ||
363 | |||
364 | list_add_tail(&msg->list, &byt->empty_list); | ||
365 | spin_unlock_irqrestore(&byt->dsp->spinlock, flags); | ||
366 | return ret; | ||
367 | } | ||
368 | |||
369 | static int sst_byt_ipc_tx_message(struct sst_byt *byt, u64 header, | ||
370 | void *tx_data, size_t tx_bytes, | ||
371 | void *rx_data, size_t rx_bytes, int wait) | ||
372 | { | ||
373 | unsigned long flags; | ||
374 | struct ipc_message *msg; | ||
375 | |||
376 | spin_lock_irqsave(&byt->dsp->spinlock, flags); | ||
377 | |||
378 | msg = sst_byt_msg_get_empty(byt); | ||
379 | if (msg == NULL) { | ||
380 | spin_unlock_irqrestore(&byt->dsp->spinlock, flags); | ||
381 | return -EBUSY; | ||
382 | } | ||
383 | |||
384 | msg->header = header; | ||
385 | msg->tx_size = tx_bytes; | ||
386 | msg->rx_size = rx_bytes; | ||
387 | msg->wait = wait; | ||
388 | msg->errno = 0; | ||
389 | msg->complete = false; | ||
390 | |||
391 | if (tx_bytes) { | ||
392 | /* msg content = lower 32-bit of the header + data */ | ||
393 | *(u32 *)msg->tx_data = (u32)(header & (u32)-1); | ||
394 | memcpy(msg->tx_data + sizeof(u32), tx_data, tx_bytes); | ||
395 | msg->tx_size += sizeof(u32); | ||
396 | } | ||
397 | |||
398 | list_add_tail(&msg->list, &byt->tx_list); | ||
399 | spin_unlock_irqrestore(&byt->dsp->spinlock, flags); | ||
400 | |||
401 | queue_kthread_work(&byt->kworker, &byt->kwork); | ||
402 | |||
403 | if (wait) | ||
404 | return sst_byt_tx_wait_done(byt, msg, rx_data); | ||
405 | else | ||
406 | return 0; | ||
407 | } | ||
408 | |||
409 | static inline int sst_byt_ipc_tx_msg_wait(struct sst_byt *byt, u64 header, | ||
410 | void *tx_data, size_t tx_bytes, | ||
411 | void *rx_data, size_t rx_bytes) | ||
412 | { | ||
413 | return sst_byt_ipc_tx_message(byt, header, tx_data, tx_bytes, | ||
414 | rx_data, rx_bytes, 1); | ||
415 | } | ||
416 | |||
417 | static inline int sst_byt_ipc_tx_msg_nowait(struct sst_byt *byt, u64 header, | ||
418 | void *tx_data, size_t tx_bytes) | ||
419 | { | ||
420 | return sst_byt_ipc_tx_message(byt, header, tx_data, tx_bytes, | ||
421 | NULL, 0, 0); | ||
422 | } | ||
423 | |||
424 | static struct ipc_message *sst_byt_reply_find_msg(struct sst_byt *byt, | ||
425 | u64 header) | ||
426 | { | ||
427 | struct ipc_message *msg = NULL, *_msg; | ||
428 | u64 mask; | ||
429 | |||
430 | /* match reply to message sent based on msg and stream IDs */ | ||
431 | mask = IPC_HEADER_MSG_ID_MASK | | ||
432 | IPC_HEADER_STR_ID_MASK << IPC_HEADER_STR_ID_SHIFT; | ||
433 | header &= mask; | ||
434 | |||
435 | if (list_empty(&byt->rx_list)) { | ||
436 | dev_err(byt->dev, | ||
437 | "ipc: rx list is empty but received 0x%llx\n", header); | ||
438 | goto out; | ||
439 | } | ||
440 | |||
441 | list_for_each_entry(_msg, &byt->rx_list, list) { | ||
442 | if ((_msg->header & mask) == header) { | ||
443 | msg = _msg; | ||
444 | break; | ||
445 | } | ||
446 | } | ||
447 | |||
448 | out: | ||
449 | return msg; | ||
450 | } | ||
451 | |||
452 | static void sst_byt_stream_update(struct sst_byt *byt, struct ipc_message *msg) | 226 | static void sst_byt_stream_update(struct sst_byt *byt, struct ipc_message *msg) |
453 | { | 227 | { |
454 | struct sst_byt_stream *stream; | 228 | struct sst_byt_stream *stream; |
@@ -477,7 +251,7 @@ static int sst_byt_process_reply(struct sst_byt *byt, u64 header) | |||
477 | { | 251 | { |
478 | struct ipc_message *msg; | 252 | struct ipc_message *msg; |
479 | 253 | ||
480 | msg = sst_byt_reply_find_msg(byt, header); | 254 | msg = sst_ipc_reply_find_msg(&byt->ipc, header); |
481 | if (msg == NULL) | 255 | if (msg == NULL) |
482 | return 1; | 256 | return 1; |
483 | 257 | ||
@@ -491,7 +265,7 @@ static int sst_byt_process_reply(struct sst_byt *byt, u64 header) | |||
491 | 265 | ||
492 | list_del(&msg->list); | 266 | list_del(&msg->list); |
493 | /* wake up */ | 267 | /* wake up */ |
494 | sst_byt_tx_msg_reply_complete(byt, msg); | 268 | sst_ipc_tx_msg_reply_complete(&byt->ipc, msg); |
495 | 269 | ||
496 | return 1; | 270 | return 1; |
497 | } | 271 | } |
@@ -538,6 +312,7 @@ static irqreturn_t sst_byt_irq_thread(int irq, void *context) | |||
538 | { | 312 | { |
539 | struct sst_dsp *sst = (struct sst_dsp *) context; | 313 | struct sst_dsp *sst = (struct sst_dsp *) context; |
540 | struct sst_byt *byt = sst_dsp_get_thread_context(sst); | 314 | struct sst_byt *byt = sst_dsp_get_thread_context(sst); |
315 | struct sst_generic_ipc *ipc = &byt->ipc; | ||
541 | u64 header; | 316 | u64 header; |
542 | unsigned long flags; | 317 | unsigned long flags; |
543 | 318 | ||
@@ -569,7 +344,7 @@ static irqreturn_t sst_byt_irq_thread(int irq, void *context) | |||
569 | spin_unlock_irqrestore(&sst->spinlock, flags); | 344 | spin_unlock_irqrestore(&sst->spinlock, flags); |
570 | 345 | ||
571 | /* continue to send any remaining messages... */ | 346 | /* continue to send any remaining messages... */ |
572 | queue_kthread_work(&byt->kworker, &byt->kwork); | 347 | queue_kthread_work(&ipc->kworker, &ipc->kwork); |
573 | 348 | ||
574 | return IRQ_HANDLED; | 349 | return IRQ_HANDLED; |
575 | } | 350 | } |
@@ -656,7 +431,8 @@ int sst_byt_stream_commit(struct sst_byt *byt, struct sst_byt_stream *stream) | |||
656 | header = sst_byt_header(IPC_IA_ALLOC_STREAM, | 431 | header = sst_byt_header(IPC_IA_ALLOC_STREAM, |
657 | sizeof(*str_req) + sizeof(u32), | 432 | sizeof(*str_req) + sizeof(u32), |
658 | true, stream->str_id); | 433 | true, stream->str_id); |
659 | ret = sst_byt_ipc_tx_msg_wait(byt, header, str_req, sizeof(*str_req), | 434 | ret = sst_ipc_tx_message_wait(&byt->ipc, header, str_req, |
435 | sizeof(*str_req), | ||
660 | reply, sizeof(*reply)); | 436 | reply, sizeof(*reply)); |
661 | if (ret < 0) { | 437 | if (ret < 0) { |
662 | dev_err(byt->dev, "ipc: error stream commit failed\n"); | 438 | dev_err(byt->dev, "ipc: error stream commit failed\n"); |
@@ -679,7 +455,7 @@ int sst_byt_stream_free(struct sst_byt *byt, struct sst_byt_stream *stream) | |||
679 | goto out; | 455 | goto out; |
680 | 456 | ||
681 | header = sst_byt_header(IPC_IA_FREE_STREAM, 0, false, stream->str_id); | 457 | header = sst_byt_header(IPC_IA_FREE_STREAM, 0, false, stream->str_id); |
682 | ret = sst_byt_ipc_tx_msg_wait(byt, header, NULL, 0, NULL, 0); | 458 | ret = sst_ipc_tx_message_wait(&byt->ipc, header, NULL, 0, NULL, 0); |
683 | if (ret < 0) { | 459 | if (ret < 0) { |
684 | dev_err(byt->dev, "ipc: free stream %d failed\n", | 460 | dev_err(byt->dev, "ipc: free stream %d failed\n", |
685 | stream->str_id); | 461 | stream->str_id); |
@@ -703,9 +479,11 @@ static int sst_byt_stream_operations(struct sst_byt *byt, int type, | |||
703 | 479 | ||
704 | header = sst_byt_header(type, 0, false, stream_id); | 480 | header = sst_byt_header(type, 0, false, stream_id); |
705 | if (wait) | 481 | if (wait) |
706 | return sst_byt_ipc_tx_msg_wait(byt, header, NULL, 0, NULL, 0); | 482 | return sst_ipc_tx_message_wait(&byt->ipc, header, NULL, |
483 | 0, NULL, 0); | ||
707 | else | 484 | else |
708 | return sst_byt_ipc_tx_msg_nowait(byt, header, NULL, 0); | 485 | return sst_ipc_tx_message_nowait(&byt->ipc, header, |
486 | NULL, 0); | ||
709 | } | 487 | } |
710 | 488 | ||
711 | /* stream ALSA trigger operations */ | 489 | /* stream ALSA trigger operations */ |
@@ -725,7 +503,7 @@ int sst_byt_stream_start(struct sst_byt *byt, struct sst_byt_stream *stream, | |||
725 | tx_msg = &start_stream; | 503 | tx_msg = &start_stream; |
726 | size = sizeof(start_stream); | 504 | size = sizeof(start_stream); |
727 | 505 | ||
728 | ret = sst_byt_ipc_tx_msg_nowait(byt, header, tx_msg, size); | 506 | ret = sst_ipc_tx_message_nowait(&byt->ipc, header, tx_msg, size); |
729 | if (ret < 0) | 507 | if (ret < 0) |
730 | dev_err(byt->dev, "ipc: error failed to start stream %d\n", | 508 | dev_err(byt->dev, "ipc: error failed to start stream %d\n", |
731 | stream->str_id); | 509 | stream->str_id); |
@@ -790,23 +568,6 @@ int sst_byt_get_dsp_position(struct sst_byt *byt, | |||
790 | return do_div(fw_tstamp.ring_buffer_counter, buffer_size); | 568 | return do_div(fw_tstamp.ring_buffer_counter, buffer_size); |
791 | } | 569 | } |
792 | 570 | ||
793 | static int msg_empty_list_init(struct sst_byt *byt) | ||
794 | { | ||
795 | struct ipc_message *msg; | ||
796 | int i; | ||
797 | |||
798 | byt->msg = kzalloc(sizeof(*msg) * IPC_EMPTY_LIST_SIZE, GFP_KERNEL); | ||
799 | if (byt->msg == NULL) | ||
800 | return -ENOMEM; | ||
801 | |||
802 | for (i = 0; i < IPC_EMPTY_LIST_SIZE; i++) { | ||
803 | init_waitqueue_head(&byt->msg[i].waitq); | ||
804 | list_add(&byt->msg[i].list, &byt->empty_list); | ||
805 | } | ||
806 | |||
807 | return 0; | ||
808 | } | ||
809 | |||
810 | struct sst_dsp *sst_byt_get_dsp(struct sst_byt *byt) | 571 | struct sst_dsp *sst_byt_get_dsp(struct sst_byt *byt) |
811 | { | 572 | { |
812 | return byt->dsp; | 573 | return byt->dsp; |
@@ -823,7 +584,7 @@ int sst_byt_dsp_suspend_late(struct device *dev, struct sst_pdata *pdata) | |||
823 | 584 | ||
824 | dev_dbg(byt->dev, "dsp reset\n"); | 585 | dev_dbg(byt->dev, "dsp reset\n"); |
825 | sst_dsp_reset(byt->dsp); | 586 | sst_dsp_reset(byt->dsp); |
826 | sst_byt_drop_all(byt); | 587 | sst_ipc_drop_all(&byt->ipc); |
827 | dev_dbg(byt->dev, "dsp in reset\n"); | 588 | dev_dbg(byt->dev, "dsp in reset\n"); |
828 | 589 | ||
829 | dev_dbg(byt->dev, "free all blocks and unload fw\n"); | 590 | dev_dbg(byt->dev, "free all blocks and unload fw\n"); |
@@ -876,9 +637,52 @@ int sst_byt_dsp_wait_for_ready(struct device *dev, struct sst_pdata *pdata) | |||
876 | } | 637 | } |
877 | EXPORT_SYMBOL_GPL(sst_byt_dsp_wait_for_ready); | 638 | EXPORT_SYMBOL_GPL(sst_byt_dsp_wait_for_ready); |
878 | 639 | ||
640 | static void byt_tx_msg(struct sst_generic_ipc *ipc, struct ipc_message *msg) | ||
641 | { | ||
642 | if (msg->header & IPC_HEADER_LARGE(true)) | ||
643 | sst_dsp_outbox_write(ipc->dsp, msg->tx_data, msg->tx_size); | ||
644 | |||
645 | sst_dsp_shim_write64_unlocked(ipc->dsp, SST_IPCX, msg->header); | ||
646 | } | ||
647 | |||
648 | static void byt_shim_dbg(struct sst_generic_ipc *ipc, const char *text) | ||
649 | { | ||
650 | struct sst_dsp *sst = ipc->dsp; | ||
651 | u64 isr, ipcd, imrx, ipcx; | ||
652 | |||
653 | ipcx = sst_dsp_shim_read64_unlocked(sst, SST_IPCX); | ||
654 | isr = sst_dsp_shim_read64_unlocked(sst, SST_ISRX); | ||
655 | ipcd = sst_dsp_shim_read64_unlocked(sst, SST_IPCD); | ||
656 | imrx = sst_dsp_shim_read64_unlocked(sst, SST_IMRX); | ||
657 | |||
658 | dev_err(ipc->dev, | ||
659 | "ipc: --%s-- ipcx 0x%llx isr 0x%llx ipcd 0x%llx imrx 0x%llx\n", | ||
660 | text, ipcx, isr, ipcd, imrx); | ||
661 | } | ||
662 | |||
663 | static void byt_tx_data_copy(struct ipc_message *msg, char *tx_data, | ||
664 | size_t tx_size) | ||
665 | { | ||
666 | /* msg content = lower 32-bit of the header + data */ | ||
667 | *(u32 *)msg->tx_data = (u32)(msg->header & (u32)-1); | ||
668 | memcpy(msg->tx_data + sizeof(u32), tx_data, tx_size); | ||
669 | msg->tx_size += sizeof(u32); | ||
670 | } | ||
671 | |||
672 | static u64 byt_reply_msg_match(u64 header, u64 *mask) | ||
673 | { | ||
674 | /* match reply to message sent based on msg and stream IDs */ | ||
675 | *mask = IPC_HEADER_MSG_ID_MASK | | ||
676 | IPC_HEADER_STR_ID_MASK << IPC_HEADER_STR_ID_SHIFT; | ||
677 | header &= *mask; | ||
678 | |||
679 | return header; | ||
680 | } | ||
681 | |||
879 | int sst_byt_dsp_init(struct device *dev, struct sst_pdata *pdata) | 682 | int sst_byt_dsp_init(struct device *dev, struct sst_pdata *pdata) |
880 | { | 683 | { |
881 | struct sst_byt *byt; | 684 | struct sst_byt *byt; |
685 | struct sst_generic_ipc *ipc; | ||
882 | struct sst_fw *byt_sst_fw; | 686 | struct sst_fw *byt_sst_fw; |
883 | struct sst_byt_fw_init init; | 687 | struct sst_byt_fw_init init; |
884 | int err; | 688 | int err; |
@@ -889,39 +693,30 @@ int sst_byt_dsp_init(struct device *dev, struct sst_pdata *pdata) | |||
889 | if (byt == NULL) | 693 | if (byt == NULL) |
890 | return -ENOMEM; | 694 | return -ENOMEM; |
891 | 695 | ||
892 | byt->dev = dev; | 696 | ipc = &byt->ipc; |
893 | INIT_LIST_HEAD(&byt->stream_list); | 697 | ipc->dev = dev; |
894 | INIT_LIST_HEAD(&byt->tx_list); | 698 | ipc->ops.tx_msg = byt_tx_msg; |
895 | INIT_LIST_HEAD(&byt->rx_list); | 699 | ipc->ops.shim_dbg = byt_shim_dbg; |
896 | INIT_LIST_HEAD(&byt->empty_list); | 700 | ipc->ops.tx_data_copy = byt_tx_data_copy; |
897 | init_waitqueue_head(&byt->boot_wait); | 701 | ipc->ops.reply_msg_match = byt_reply_msg_match; |
898 | init_waitqueue_head(&byt->wait_txq); | ||
899 | 702 | ||
900 | err = msg_empty_list_init(byt); | 703 | err = sst_ipc_init(ipc); |
901 | if (err < 0) | 704 | if (err != 0) |
902 | return -ENOMEM; | 705 | goto ipc_init_err; |
903 | |||
904 | /* start the IPC message thread */ | ||
905 | init_kthread_worker(&byt->kworker); | ||
906 | byt->tx_thread = kthread_run(kthread_worker_fn, | ||
907 | &byt->kworker, "%s", | ||
908 | dev_name(byt->dev)); | ||
909 | if (IS_ERR(byt->tx_thread)) { | ||
910 | err = PTR_ERR(byt->tx_thread); | ||
911 | dev_err(byt->dev, "error failed to create message TX task\n"); | ||
912 | goto err_free_msg; | ||
913 | } | ||
914 | init_kthread_work(&byt->kwork, sst_byt_ipc_tx_msgs); | ||
915 | 706 | ||
707 | INIT_LIST_HEAD(&byt->stream_list); | ||
708 | init_waitqueue_head(&byt->boot_wait); | ||
916 | byt_dev.thread_context = byt; | 709 | byt_dev.thread_context = byt; |
917 | 710 | ||
918 | /* init SST shim */ | 711 | /* init SST shim */ |
919 | byt->dsp = sst_dsp_new(dev, &byt_dev, pdata); | 712 | byt->dsp = sst_dsp_new(dev, &byt_dev, pdata); |
920 | if (byt->dsp == NULL) { | 713 | if (byt->dsp == NULL) { |
921 | err = -ENODEV; | 714 | err = -ENODEV; |
922 | goto dsp_err; | 715 | goto dsp_new_err; |
923 | } | 716 | } |
924 | 717 | ||
718 | ipc->dsp = byt->dsp; | ||
719 | |||
925 | /* keep the DSP in reset state for base FW loading */ | 720 | /* keep the DSP in reset state for base FW loading */ |
926 | sst_dsp_reset(byt->dsp); | 721 | sst_dsp_reset(byt->dsp); |
927 | 722 | ||
@@ -961,10 +756,10 @@ boot_err: | |||
961 | sst_fw_free(byt_sst_fw); | 756 | sst_fw_free(byt_sst_fw); |
962 | fw_err: | 757 | fw_err: |
963 | sst_dsp_free(byt->dsp); | 758 | sst_dsp_free(byt->dsp); |
964 | dsp_err: | 759 | dsp_new_err: |
965 | kthread_stop(byt->tx_thread); | 760 | sst_ipc_fini(ipc); |
966 | err_free_msg: | 761 | ipc_init_err: |
967 | kfree(byt->msg); | 762 | kfree(byt); |
968 | 763 | ||
969 | return err; | 764 | return err; |
970 | } | 765 | } |
@@ -977,7 +772,6 @@ void sst_byt_dsp_free(struct device *dev, struct sst_pdata *pdata) | |||
977 | sst_dsp_reset(byt->dsp); | 772 | sst_dsp_reset(byt->dsp); |
978 | sst_fw_free_all(byt->dsp); | 773 | sst_fw_free_all(byt->dsp); |
979 | sst_dsp_free(byt->dsp); | 774 | sst_dsp_free(byt->dsp); |
980 | kthread_stop(byt->tx_thread); | 775 | sst_ipc_fini(&byt->ipc); |
981 | kfree(byt->msg); | ||
982 | } | 776 | } |
983 | EXPORT_SYMBOL_GPL(sst_byt_dsp_free); | 777 | EXPORT_SYMBOL_GPL(sst_byt_dsp_free); |
diff --git a/sound/soc/intel/sst-baytrail-ipc.h b/sound/soc/intel/baytrail/sst-baytrail-ipc.h index 8faff6dcf25d..8faff6dcf25d 100644 --- a/sound/soc/intel/sst-baytrail-ipc.h +++ b/sound/soc/intel/baytrail/sst-baytrail-ipc.h | |||
diff --git a/sound/soc/intel/sst-baytrail-pcm.c b/sound/soc/intel/baytrail/sst-baytrail-pcm.c index 224c49c9f135..79547bec558b 100644 --- a/sound/soc/intel/sst-baytrail-pcm.c +++ b/sound/soc/intel/baytrail/sst-baytrail-pcm.c | |||
@@ -20,8 +20,8 @@ | |||
20 | #include <sound/pcm_params.h> | 20 | #include <sound/pcm_params.h> |
21 | #include <sound/soc.h> | 21 | #include <sound/soc.h> |
22 | #include "sst-baytrail-ipc.h" | 22 | #include "sst-baytrail-ipc.h" |
23 | #include "sst-dsp-priv.h" | 23 | #include "../common/sst-dsp-priv.h" |
24 | #include "sst-dsp.h" | 24 | #include "../common/sst-dsp.h" |
25 | 25 | ||
26 | #define BYT_PCM_COUNT 2 | 26 | #define BYT_PCM_COUNT 2 |
27 | 27 | ||
diff --git a/sound/soc/intel/boards/Makefile b/sound/soc/intel/boards/Makefile new file mode 100644 index 000000000000..f8237f0044eb --- /dev/null +++ b/sound/soc/intel/boards/Makefile | |||
@@ -0,0 +1,15 @@ | |||
1 | snd-soc-sst-haswell-objs := haswell.o | ||
2 | snd-soc-sst-byt-rt5640-mach-objs := byt-rt5640.o | ||
3 | snd-soc-sst-byt-max98090-mach-objs := byt-max98090.o | ||
4 | snd-soc-sst-broadwell-objs := broadwell.o | ||
5 | snd-soc-sst-bytcr-rt5640-objs := bytcr_rt5640.o | ||
6 | snd-soc-sst-cht-bsw-rt5672-objs := cht_bsw_rt5672.o | ||
7 | snd-soc-sst-cht-bsw-rt5645-objs := cht_bsw_rt5645.o | ||
8 | |||
9 | obj-$(CONFIG_SND_SOC_INTEL_HASWELL_MACH) += snd-soc-sst-haswell.o | ||
10 | obj-$(CONFIG_SND_SOC_INTEL_BYT_RT5640_MACH) += snd-soc-sst-byt-rt5640-mach.o | ||
11 | obj-$(CONFIG_SND_SOC_INTEL_BYT_MAX98090_MACH) += snd-soc-sst-byt-max98090-mach.o | ||
12 | obj-$(CONFIG_SND_SOC_INTEL_BROADWELL_MACH) += snd-soc-sst-broadwell.o | ||
13 | obj-$(CONFIG_SND_SOC_INTEL_BYTCR_RT5640_MACH) += snd-soc-sst-bytcr-rt5640.o | ||
14 | obj-$(CONFIG_SND_SOC_INTEL_CHT_BSW_RT5672_MACH) += snd-soc-sst-cht-bsw-rt5672.o | ||
15 | obj-$(CONFIG_SND_SOC_INTEL_CHT_BSW_RT5645_MACH) += snd-soc-sst-cht-bsw-rt5645.o | ||
diff --git a/sound/soc/intel/broadwell.c b/sound/soc/intel/boards/broadwell.c index 9cf7d01479ad..8bafaf6ceab1 100644 --- a/sound/soc/intel/broadwell.c +++ b/sound/soc/intel/boards/broadwell.c | |||
@@ -22,10 +22,10 @@ | |||
22 | #include <sound/jack.h> | 22 | #include <sound/jack.h> |
23 | #include <sound/pcm_params.h> | 23 | #include <sound/pcm_params.h> |
24 | 24 | ||
25 | #include "sst-dsp.h" | 25 | #include "../common/sst-dsp.h" |
26 | #include "sst-haswell-ipc.h" | 26 | #include "../haswell/sst-haswell-ipc.h" |
27 | 27 | ||
28 | #include "../codecs/rt286.h" | 28 | #include "../../codecs/rt286.h" |
29 | 29 | ||
30 | static struct snd_soc_jack broadwell_headset; | 30 | static struct snd_soc_jack broadwell_headset; |
31 | /* Headset jack detection DAPM pins */ | 31 | /* Headset jack detection DAPM pins */ |
@@ -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(¶ms->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 | ||
@@ -227,6 +219,32 @@ static struct snd_soc_dai_link broadwell_rt286_dais[] = { | |||
227 | }, | 219 | }, |
228 | }; | 220 | }; |
229 | 221 | ||
222 | static int broadwell_suspend(struct snd_soc_card *card){ | ||
223 | struct snd_soc_codec *codec; | ||
224 | |||
225 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { | ||
226 | if (!strcmp(codec->component.name, "i2c-INT343A:00")) { | ||
227 | dev_dbg(codec->dev, "disabling jack detect before going to suspend.\n"); | ||
228 | rt286_mic_detect(codec, NULL); | ||
229 | break; | ||
230 | } | ||
231 | } | ||
232 | return 0; | ||
233 | } | ||
234 | |||
235 | static int broadwell_resume(struct snd_soc_card *card){ | ||
236 | struct snd_soc_codec *codec; | ||
237 | |||
238 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { | ||
239 | if (!strcmp(codec->component.name, "i2c-INT343A:00")) { | ||
240 | dev_dbg(codec->dev, "enabling jack detect for resume.\n"); | ||
241 | rt286_mic_detect(codec, &broadwell_headset); | ||
242 | break; | ||
243 | } | ||
244 | } | ||
245 | return 0; | ||
246 | } | ||
247 | |||
230 | /* broadwell audio machine driver for WPT + RT286S */ | 248 | /* broadwell audio machine driver for WPT + RT286S */ |
231 | static struct snd_soc_card broadwell_rt286 = { | 249 | static struct snd_soc_card broadwell_rt286 = { |
232 | .name = "broadwell-rt286", | 250 | .name = "broadwell-rt286", |
@@ -240,6 +258,8 @@ static struct snd_soc_card broadwell_rt286 = { | |||
240 | .dapm_routes = broadwell_rt286_map, | 258 | .dapm_routes = broadwell_rt286_map, |
241 | .num_dapm_routes = ARRAY_SIZE(broadwell_rt286_map), | 259 | .num_dapm_routes = ARRAY_SIZE(broadwell_rt286_map), |
242 | .fully_routed = true, | 260 | .fully_routed = true, |
261 | .suspend_pre = broadwell_suspend, | ||
262 | .resume_post = broadwell_resume, | ||
243 | }; | 263 | }; |
244 | 264 | ||
245 | static int broadwell_audio_probe(struct platform_device *pdev) | 265 | static int broadwell_audio_probe(struct platform_device *pdev) |
diff --git a/sound/soc/intel/byt-max98090.c b/sound/soc/intel/boards/byt-max98090.c index 9832afe7d22c..7ab8cc9fbfd5 100644 --- a/sound/soc/intel/byt-max98090.c +++ b/sound/soc/intel/boards/byt-max98090.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include <sound/pcm_params.h> | 24 | #include <sound/pcm_params.h> |
25 | #include <sound/soc.h> | 25 | #include <sound/soc.h> |
26 | #include <sound/jack.h> | 26 | #include <sound/jack.h> |
27 | #include "../codecs/max98090.h" | 27 | #include "../../codecs/max98090.h" |
28 | 28 | ||
29 | struct byt_max98090_private { | 29 | struct byt_max98090_private { |
30 | struct snd_soc_jack jack; | 30 | struct snd_soc_jack jack; |
@@ -84,7 +84,6 @@ static struct snd_soc_jack_gpio hs_jack_gpios[] = { | |||
84 | static int byt_max98090_init(struct snd_soc_pcm_runtime *runtime) | 84 | static 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/byt-rt5640.c b/sound/soc/intel/boards/byt-rt5640.c index 354eaad886e1..ae89b9b966d9 100644 --- a/sound/soc/intel/byt-rt5640.c +++ b/sound/soc/intel/boards/byt-rt5640.c | |||
@@ -23,9 +23,9 @@ | |||
23 | #include <sound/pcm_params.h> | 23 | #include <sound/pcm_params.h> |
24 | #include <sound/soc.h> | 24 | #include <sound/soc.h> |
25 | #include <sound/jack.h> | 25 | #include <sound/jack.h> |
26 | #include "../codecs/rt5640.h" | 26 | #include "../../codecs/rt5640.h" |
27 | 27 | ||
28 | #include "sst-dsp.h" | 28 | #include "../common/sst-dsp.h" |
29 | 29 | ||
30 | static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = { | 30 | static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = { |
31 | SND_SOC_DAPM_HP("Headphone", NULL), | 31 | SND_SOC_DAPM_HP("Headphone", NULL), |
diff --git a/sound/soc/intel/bytcr_dpcm_rt5640.c b/sound/soc/intel/boards/bytcr_rt5640.c index 59308629043e..7f55d59024a8 100644 --- a/sound/soc/intel/bytcr_dpcm_rt5640.c +++ b/sound/soc/intel/boards/bytcr_rt5640.c | |||
@@ -26,8 +26,8 @@ | |||
26 | #include <sound/pcm.h> | 26 | #include <sound/pcm.h> |
27 | #include <sound/pcm_params.h> | 27 | #include <sound/pcm_params.h> |
28 | #include <sound/soc.h> | 28 | #include <sound/soc.h> |
29 | #include "../codecs/rt5640.h" | 29 | #include "../../codecs/rt5640.h" |
30 | #include "sst-atom-controls.h" | 30 | #include "../atom/sst-atom-controls.h" |
31 | 31 | ||
32 | static const struct snd_soc_dapm_widget byt_dapm_widgets[] = { | 32 | static const struct snd_soc_dapm_widget byt_dapm_widgets[] = { |
33 | SND_SOC_DAPM_HP("Headphone", NULL), | 33 | SND_SOC_DAPM_HP("Headphone", NULL), |
@@ -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(¶ms->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/boards/cht_bsw_rt5645.c index bd29617a9ab9..20a28b22e30f 100644 --- a/sound/soc/intel/cht_bsw_rt5645.c +++ b/sound/soc/intel/boards/cht_bsw_rt5645.c | |||
@@ -27,8 +27,8 @@ | |||
27 | #include <sound/pcm_params.h> | 27 | #include <sound/pcm_params.h> |
28 | #include <sound/soc.h> | 28 | #include <sound/soc.h> |
29 | #include <sound/jack.h> | 29 | #include <sound/jack.h> |
30 | #include "../codecs/rt5645.h" | 30 | #include "../../codecs/rt5645.h" |
31 | #include "sst-atom-controls.h" | 31 | #include "../atom/sst-atom-controls.h" |
32 | 32 | ||
33 | #define CHT_PLAT_CLK_3_HZ 19200000 | 33 | #define CHT_PLAT_CLK_3_HZ 19200000 |
34 | #define CHT_CODEC_DAI "rt5645-aif1" | 34 | #define CHT_CODEC_DAI "rt5645-aif1" |
@@ -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(¶ms->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/boards/cht_bsw_rt5672.c index ff016621583a..2c9cc5be439e 100644 --- a/sound/soc/intel/cht_bsw_rt5672.c +++ b/sound/soc/intel/boards/cht_bsw_rt5672.c | |||
@@ -22,13 +22,28 @@ | |||
22 | #include <sound/pcm.h> | 22 | #include <sound/pcm.h> |
23 | #include <sound/pcm_params.h> | 23 | #include <sound/pcm_params.h> |
24 | #include <sound/soc.h> | 24 | #include <sound/soc.h> |
25 | #include "../codecs/rt5670.h" | 25 | #include <sound/jack.h> |
26 | #include "sst-atom-controls.h" | 26 | #include "../../codecs/rt5670.h" |
27 | #include "../atom/sst-atom-controls.h" | ||
27 | 28 | ||
28 | /* The platform clock #3 outputs 19.2Mhz clock to codec as I2S MCLK */ | 29 | /* The platform clock #3 outputs 19.2Mhz clock to codec as I2S MCLK */ |
29 | #define CHT_PLAT_CLK_3_HZ 19200000 | 30 | #define CHT_PLAT_CLK_3_HZ 19200000 |
30 | #define CHT_CODEC_DAI "rt5670-aif1" | 31 | #define CHT_CODEC_DAI "rt5670-aif1" |
31 | 32 | ||
33 | static struct snd_soc_jack cht_bsw_headset; | ||
34 | |||
35 | /* Headset jack detection DAPM pins */ | ||
36 | static struct snd_soc_jack_pin cht_bsw_headset_pins[] = { | ||
37 | { | ||
38 | .pin = "Headset Mic", | ||
39 | .mask = SND_JACK_MICROPHONE, | ||
40 | }, | ||
41 | { | ||
42 | .pin = "Headphone", | ||
43 | .mask = SND_JACK_HEADPHONE, | ||
44 | }, | ||
45 | }; | ||
46 | |||
32 | static inline struct snd_soc_dai *cht_get_codec_dai(struct snd_soc_card *card) | 47 | static inline struct snd_soc_dai *cht_get_codec_dai(struct snd_soc_card *card) |
33 | { | 48 | { |
34 | int i; | 49 | int i; |
@@ -50,6 +65,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w, | |||
50 | struct snd_soc_dapm_context *dapm = w->dapm; | 65 | struct snd_soc_dapm_context *dapm = w->dapm; |
51 | struct snd_soc_card *card = dapm->card; | 66 | struct snd_soc_card *card = dapm->card; |
52 | struct snd_soc_dai *codec_dai; | 67 | struct snd_soc_dai *codec_dai; |
68 | int ret; | ||
53 | 69 | ||
54 | codec_dai = cht_get_codec_dai(card); | 70 | codec_dai = cht_get_codec_dai(card); |
55 | if (!codec_dai) { | 71 | if (!codec_dai) { |
@@ -57,17 +73,31 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w, | |||
57 | return -EIO; | 73 | return -EIO; |
58 | } | 74 | } |
59 | 75 | ||
60 | if (!SND_SOC_DAPM_EVENT_OFF(event)) | 76 | if (SND_SOC_DAPM_EVENT_ON(event)) { |
61 | return 0; | 77 | /* set codec PLL source to the 19.2MHz platform clock (MCLK) */ |
62 | 78 | ret = snd_soc_dai_set_pll(codec_dai, 0, RT5670_PLL1_S_MCLK, | |
63 | /* Set codec sysclk source to its internal clock because codec PLL will | 79 | CHT_PLAT_CLK_3_HZ, 48000 * 512); |
64 | * be off when idle and MCLK will also be off by ACPI when codec is | 80 | if (ret < 0) { |
65 | * runtime suspended. Codec needs clock for jack detection and button | 81 | dev_err(card->dev, "can't set codec pll: %d\n", ret); |
66 | * press. | 82 | return ret; |
67 | */ | 83 | } |
68 | snd_soc_dai_set_sysclk(codec_dai, RT5670_SCLK_S_RCCLK, | 84 | |
69 | 0, SND_SOC_CLOCK_IN); | 85 | /* set codec sysclk source to PLL */ |
70 | 86 | ret = snd_soc_dai_set_sysclk(codec_dai, RT5670_SCLK_S_PLL1, | |
87 | 48000 * 512, SND_SOC_CLOCK_IN); | ||
88 | if (ret < 0) { | ||
89 | dev_err(card->dev, "can't set codec sysclk: %d\n", ret); | ||
90 | return ret; | ||
91 | } | ||
92 | } else { | ||
93 | /* Set codec sysclk source to its internal clock because codec | ||
94 | * PLL will be off when idle and MCLK will also be off by ACPI | ||
95 | * when codec is runtime suspended. Codec needs clock for jack | ||
96 | * detection and button press. | ||
97 | */ | ||
98 | snd_soc_dai_set_sysclk(codec_dai, RT5670_SCLK_S_RCCLK, | ||
99 | 48000 * 512, SND_SOC_CLOCK_IN); | ||
100 | } | ||
71 | return 0; | 101 | return 0; |
72 | } | 102 | } |
73 | 103 | ||
@@ -77,7 +107,8 @@ static const struct snd_soc_dapm_widget cht_dapm_widgets[] = { | |||
77 | SND_SOC_DAPM_MIC("Int Mic", NULL), | 107 | SND_SOC_DAPM_MIC("Int Mic", NULL), |
78 | SND_SOC_DAPM_SPK("Ext Spk", NULL), | 108 | SND_SOC_DAPM_SPK("Ext Spk", NULL), |
79 | SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0, | 109 | SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0, |
80 | platform_clock_control, SND_SOC_DAPM_POST_PMD), | 110 | platform_clock_control, SND_SOC_DAPM_PRE_PMU | |
111 | SND_SOC_DAPM_POST_PMD), | ||
81 | }; | 112 | }; |
82 | 113 | ||
83 | static const struct snd_soc_dapm_route cht_audio_map[] = { | 114 | static const struct snd_soc_dapm_route cht_audio_map[] = { |
@@ -162,6 +193,15 @@ static int cht_codec_init(struct snd_soc_pcm_runtime *runtime) | |||
162 | | RT5670_AD_MONO_L_FILTER | 193 | | RT5670_AD_MONO_L_FILTER |
163 | | RT5670_AD_MONO_R_FILTER, | 194 | | RT5670_AD_MONO_R_FILTER, |
164 | RT5670_CLK_SEL_I2S1_ASRC); | 195 | RT5670_CLK_SEL_I2S1_ASRC); |
196 | |||
197 | ret = snd_soc_card_jack_new(runtime->card, "Headset", | ||
198 | SND_JACK_HEADSET | SND_JACK_BTN_0 | | ||
199 | SND_JACK_BTN_1 | SND_JACK_BTN_2, &cht_bsw_headset, | ||
200 | cht_bsw_headset_pins, ARRAY_SIZE(cht_bsw_headset_pins)); | ||
201 | if (ret) | ||
202 | return ret; | ||
203 | |||
204 | rt5670_set_jack_detect(codec, &cht_bsw_headset); | ||
165 | return 0; | 205 | return 0; |
166 | } | 206 | } |
167 | 207 | ||
@@ -178,9 +218,7 @@ static int cht_codec_fixup(struct snd_soc_pcm_runtime *rtd, | |||
178 | channels->min = channels->max = 2; | 218 | channels->min = channels->max = 2; |
179 | 219 | ||
180 | /* set SSP2 to 24-bit */ | 220 | /* set SSP2 to 24-bit */ |
181 | snd_mask_set(¶ms->masks[SNDRV_PCM_HW_PARAM_FORMAT - | 221 | 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; | 222 | return 0; |
185 | } | 223 | } |
186 | 224 | ||
@@ -217,7 +255,7 @@ static struct snd_soc_dai_link cht_dailink[] = { | |||
217 | .codec_dai_name = "snd-soc-dummy-dai", | 255 | .codec_dai_name = "snd-soc-dummy-dai", |
218 | .codec_name = "snd-soc-dummy", | 256 | .codec_name = "snd-soc-dummy", |
219 | .platform_name = "sst-mfld-platform", | 257 | .platform_name = "sst-mfld-platform", |
220 | .ignore_suspend = 1, | 258 | .nonatomic = true, |
221 | .dynamic = 1, | 259 | .dynamic = 1, |
222 | .dpcm_playback = 1, | 260 | .dpcm_playback = 1, |
223 | .dpcm_capture = 1, | 261 | .dpcm_capture = 1, |
@@ -240,19 +278,48 @@ static struct snd_soc_dai_link cht_dailink[] = { | |||
240 | .cpu_dai_name = "ssp2-port", | 278 | .cpu_dai_name = "ssp2-port", |
241 | .platform_name = "sst-mfld-platform", | 279 | .platform_name = "sst-mfld-platform", |
242 | .no_pcm = 1, | 280 | .no_pcm = 1, |
281 | .nonatomic = true, | ||
243 | .codec_dai_name = "rt5670-aif1", | 282 | .codec_dai_name = "rt5670-aif1", |
244 | .codec_name = "i2c-10EC5670:00", | 283 | .codec_name = "i2c-10EC5670:00", |
245 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF | 284 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF |
246 | | SND_SOC_DAIFMT_CBS_CFS, | 285 | | SND_SOC_DAIFMT_CBS_CFS, |
247 | .init = cht_codec_init, | 286 | .init = cht_codec_init, |
248 | .be_hw_params_fixup = cht_codec_fixup, | 287 | .be_hw_params_fixup = cht_codec_fixup, |
249 | .ignore_suspend = 1, | ||
250 | .dpcm_playback = 1, | 288 | .dpcm_playback = 1, |
251 | .dpcm_capture = 1, | 289 | .dpcm_capture = 1, |
252 | .ops = &cht_be_ssp2_ops, | 290 | .ops = &cht_be_ssp2_ops, |
253 | }, | 291 | }, |
254 | }; | 292 | }; |
255 | 293 | ||
294 | static int cht_suspend_pre(struct snd_soc_card *card) | ||
295 | { | ||
296 | struct snd_soc_codec *codec; | ||
297 | |||
298 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { | ||
299 | if (!strcmp(codec->component.name, "i2c-10EC5670:00")) { | ||
300 | dev_dbg(codec->dev, "disabling jack detect before going to suspend.\n"); | ||
301 | rt5670_jack_suspend(codec); | ||
302 | break; | ||
303 | } | ||
304 | } | ||
305 | return 0; | ||
306 | } | ||
307 | |||
308 | static int cht_resume_post(struct snd_soc_card *card) | ||
309 | { | ||
310 | struct snd_soc_codec *codec; | ||
311 | |||
312 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { | ||
313 | if (!strcmp(codec->component.name, "i2c-10EC5670:00")) { | ||
314 | dev_dbg(codec->dev, "enabling jack detect for resume.\n"); | ||
315 | rt5670_jack_resume(codec); | ||
316 | break; | ||
317 | } | ||
318 | } | ||
319 | |||
320 | return 0; | ||
321 | } | ||
322 | |||
256 | /* SoC card */ | 323 | /* SoC card */ |
257 | static struct snd_soc_card snd_soc_card_cht = { | 324 | static struct snd_soc_card snd_soc_card_cht = { |
258 | .name = "cherrytrailcraudio", | 325 | .name = "cherrytrailcraudio", |
@@ -264,6 +331,8 @@ static struct snd_soc_card snd_soc_card_cht = { | |||
264 | .num_dapm_routes = ARRAY_SIZE(cht_audio_map), | 331 | .num_dapm_routes = ARRAY_SIZE(cht_audio_map), |
265 | .controls = cht_mc_controls, | 332 | .controls = cht_mc_controls, |
266 | .num_controls = ARRAY_SIZE(cht_mc_controls), | 333 | .num_controls = ARRAY_SIZE(cht_mc_controls), |
334 | .suspend_pre = cht_suspend_pre, | ||
335 | .resume_post = cht_resume_post, | ||
267 | }; | 336 | }; |
268 | 337 | ||
269 | static int snd_cht_mc_probe(struct platform_device *pdev) | 338 | static int snd_cht_mc_probe(struct platform_device *pdev) |
@@ -285,7 +354,6 @@ static int snd_cht_mc_probe(struct platform_device *pdev) | |||
285 | static struct platform_driver snd_cht_mc_driver = { | 354 | static struct platform_driver snd_cht_mc_driver = { |
286 | .driver = { | 355 | .driver = { |
287 | .name = "cht-bsw-rt5672", | 356 | .name = "cht-bsw-rt5672", |
288 | .pm = &snd_soc_pm_ops, | ||
289 | }, | 357 | }, |
290 | .probe = snd_cht_mc_probe, | 358 | .probe = snd_cht_mc_probe, |
291 | }; | 359 | }; |
diff --git a/sound/soc/intel/haswell.c b/sound/soc/intel/boards/haswell.c index 35edf51a52aa..22558572cb9c 100644 --- a/sound/soc/intel/haswell.c +++ b/sound/soc/intel/boards/haswell.c | |||
@@ -21,10 +21,10 @@ | |||
21 | #include <sound/soc.h> | 21 | #include <sound/soc.h> |
22 | #include <sound/pcm_params.h> | 22 | #include <sound/pcm_params.h> |
23 | 23 | ||
24 | #include "sst-dsp.h" | 24 | #include "../common/sst-dsp.h" |
25 | #include "sst-haswell-ipc.h" | 25 | #include "../haswell/sst-haswell-ipc.h" |
26 | 26 | ||
27 | #include "../codecs/rt5640.h" | 27 | #include "../../codecs/rt5640.h" |
28 | 28 | ||
29 | /* Haswell ULT platforms have a Headphone and Mic jack */ | 29 | /* Haswell ULT platforms have a Headphone and Mic jack */ |
30 | static const struct snd_soc_dapm_widget haswell_widgets[] = { | 30 | static const struct snd_soc_dapm_widget haswell_widgets[] = { |
@@ -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(¶ms->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/boards/mfld_machine.c index 90b7a57713a0..49c09a0add79 100644 --- a/sound/soc/intel/mfld_machine.c +++ b/sound/soc/intel/boards/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/common/Makefile b/sound/soc/intel/common/Makefile new file mode 100644 index 000000000000..f24154ca4e98 --- /dev/null +++ b/sound/soc/intel/common/Makefile | |||
@@ -0,0 +1,7 @@ | |||
1 | snd-soc-sst-dsp-objs := sst-dsp.o sst-firmware.o | ||
2 | snd-soc-sst-acpi-objs := sst-acpi.o | ||
3 | snd-soc-sst-ipc-objs := sst-ipc.o | ||
4 | |||
5 | obj-$(CONFIG_SND_SOC_INTEL_SST) += snd-soc-sst-dsp.o snd-soc-sst-ipc.o | ||
6 | obj-$(CONFIG_SND_SOC_INTEL_SST_ACPI) += snd-soc-sst-acpi.o | ||
7 | |||
diff --git a/sound/soc/intel/sst-acpi.c b/sound/soc/intel/common/sst-acpi.c index b3d84560fbb5..42f293f9c6e2 100644 --- a/sound/soc/intel/sst-acpi.c +++ b/sound/soc/intel/common/sst-acpi.c | |||
@@ -142,6 +142,7 @@ static int sst_acpi_probe(struct platform_device *pdev) | |||
142 | sst_acpi->desc = desc; | 142 | sst_acpi->desc = desc; |
143 | sst_acpi->mach = mach; | 143 | sst_acpi->mach = mach; |
144 | 144 | ||
145 | sst_pdata->resindex_dma_base = desc->resindex_dma_base; | ||
145 | if (desc->resindex_dma_base >= 0) { | 146 | if (desc->resindex_dma_base >= 0) { |
146 | sst_pdata->dma_engine = desc->dma_engine; | 147 | sst_pdata->dma_engine = desc->dma_engine; |
147 | sst_pdata->dma_base = desc->resindex_dma_base; | 148 | sst_pdata->dma_base = desc->resindex_dma_base; |
diff --git a/sound/soc/intel/sst-dsp-priv.h b/sound/soc/intel/common/sst-dsp-priv.h index b9da030e312d..396d54510350 100644 --- a/sound/soc/intel/sst-dsp-priv.h +++ b/sound/soc/intel/common/sst-dsp-priv.h | |||
@@ -173,6 +173,16 @@ struct sst_module_runtime_context { | |||
173 | }; | 173 | }; |
174 | 174 | ||
175 | /* | 175 | /* |
176 | * Audio DSP Module State | ||
177 | */ | ||
178 | enum sst_module_state { | ||
179 | SST_MODULE_STATE_UNLOADED = 0, /* default state */ | ||
180 | SST_MODULE_STATE_LOADED, | ||
181 | SST_MODULE_STATE_INITIALIZED, /* and inactive */ | ||
182 | SST_MODULE_STATE_ACTIVE, | ||
183 | }; | ||
184 | |||
185 | /* | ||
176 | * Audio DSP Generic Module. | 186 | * Audio DSP Generic Module. |
177 | * | 187 | * |
178 | * Each Firmware file can consist of 1..N modules. A module can span multiple | 188 | * Each Firmware file can consist of 1..N modules. A module can span multiple |
@@ -203,6 +213,9 @@ struct sst_module { | |||
203 | struct list_head list; /* DSP list of modules */ | 213 | struct list_head list; /* DSP list of modules */ |
204 | struct list_head list_fw; /* FW list of modules */ | 214 | struct list_head list_fw; /* FW list of modules */ |
205 | struct list_head runtime_list; /* list of runtime module objects*/ | 215 | struct list_head runtime_list; /* list of runtime module objects*/ |
216 | |||
217 | /* state */ | ||
218 | enum sst_module_state state; | ||
206 | }; | 219 | }; |
207 | 220 | ||
208 | /* | 221 | /* |
diff --git a/sound/soc/intel/sst-dsp.c b/sound/soc/intel/common/sst-dsp.c index 64e94212d2d2..64e94212d2d2 100644 --- a/sound/soc/intel/sst-dsp.c +++ b/sound/soc/intel/common/sst-dsp.c | |||
diff --git a/sound/soc/intel/sst-dsp.h b/sound/soc/intel/common/sst-dsp.h index f291e32f0077..96aeb2556ad4 100644 --- a/sound/soc/intel/sst-dsp.h +++ b/sound/soc/intel/common/sst-dsp.h | |||
@@ -28,7 +28,6 @@ | |||
28 | 28 | ||
29 | /* Supported SST DMA Devices */ | 29 | /* Supported SST DMA Devices */ |
30 | #define SST_DMA_TYPE_DW 1 | 30 | #define SST_DMA_TYPE_DW 1 |
31 | #define SST_DMA_TYPE_MID 2 | ||
32 | 31 | ||
33 | /* autosuspend delay 5s*/ | 32 | /* autosuspend delay 5s*/ |
34 | #define SST_RUNTIME_SUSPEND_DELAY (5 * 1000) | 33 | #define SST_RUNTIME_SUSPEND_DELAY (5 * 1000) |
@@ -206,6 +205,7 @@ struct sst_pdata { | |||
206 | const struct firmware *fw; | 205 | const struct firmware *fw; |
207 | 206 | ||
208 | /* DMA */ | 207 | /* DMA */ |
208 | int resindex_dma_base; /* other fields invalid if equals to -1 */ | ||
209 | u32 dma_base; | 209 | u32 dma_base; |
210 | u32 dma_size; | 210 | u32 dma_size; |
211 | int dma_engine; | 211 | int dma_engine; |
diff --git a/sound/soc/intel/sst-firmware.c b/sound/soc/intel/common/sst-firmware.c index 5f71ef607a57..ebcca6dc48d1 100644 --- a/sound/soc/intel/sst-firmware.c +++ b/sound/soc/intel/common/sst-firmware.c | |||
@@ -221,8 +221,6 @@ int sst_dsp_dma_get_channel(struct sst_dsp *dsp, int chan_id) | |||
221 | dma_cap_mask_t mask; | 221 | dma_cap_mask_t mask; |
222 | int ret; | 222 | int ret; |
223 | 223 | ||
224 | /* The Intel MID DMA engine driver needs the slave config set but | ||
225 | * Synopsis DMA engine driver safely ignores the slave config */ | ||
226 | dma_cap_zero(mask); | 224 | dma_cap_zero(mask); |
227 | dma_cap_set(DMA_SLAVE, mask); | 225 | dma_cap_set(DMA_SLAVE, mask); |
228 | dma_cap_set(DMA_MEMCPY, mask); | 226 | dma_cap_set(DMA_MEMCPY, mask); |
@@ -271,15 +269,16 @@ int sst_dma_new(struct sst_dsp *sst) | |||
271 | const char *dma_dev_name; | 269 | const char *dma_dev_name; |
272 | int ret = 0; | 270 | int ret = 0; |
273 | 271 | ||
272 | if (sst->pdata->resindex_dma_base == -1) | ||
273 | /* DMA is not used, return and squelsh error messages */ | ||
274 | return 0; | ||
275 | |||
274 | /* configure the correct platform data for whatever DMA engine | 276 | /* configure the correct platform data for whatever DMA engine |
275 | * is attached to the ADSP IP. */ | 277 | * is attached to the ADSP IP. */ |
276 | switch (sst->pdata->dma_engine) { | 278 | switch (sst->pdata->dma_engine) { |
277 | case SST_DMA_TYPE_DW: | 279 | case SST_DMA_TYPE_DW: |
278 | dma_dev_name = "dw_dmac"; | 280 | dma_dev_name = "dw_dmac"; |
279 | break; | 281 | break; |
280 | case SST_DMA_TYPE_MID: | ||
281 | dma_dev_name = "Intel MID DMA"; | ||
282 | break; | ||
283 | default: | 282 | default: |
284 | dev_err(sst->dev, "error: invalid DMA engine %d\n", | 283 | dev_err(sst->dev, "error: invalid DMA engine %d\n", |
285 | sst->pdata->dma_engine); | 284 | sst->pdata->dma_engine); |
@@ -498,6 +497,7 @@ struct sst_module *sst_module_new(struct sst_fw *sst_fw, | |||
498 | sst_module->scratch_size = template->scratch_size; | 497 | sst_module->scratch_size = template->scratch_size; |
499 | sst_module->persistent_size = template->persistent_size; | 498 | sst_module->persistent_size = template->persistent_size; |
500 | sst_module->entry = template->entry; | 499 | sst_module->entry = template->entry; |
500 | sst_module->state = SST_MODULE_STATE_UNLOADED; | ||
501 | 501 | ||
502 | INIT_LIST_HEAD(&sst_module->block_list); | 502 | INIT_LIST_HEAD(&sst_module->block_list); |
503 | INIT_LIST_HEAD(&sst_module->runtime_list); | 503 | INIT_LIST_HEAD(&sst_module->runtime_list); |
diff --git a/sound/soc/intel/common/sst-ipc.c b/sound/soc/intel/common/sst-ipc.c new file mode 100644 index 000000000000..4b62a553823c --- /dev/null +++ b/sound/soc/intel/common/sst-ipc.c | |||
@@ -0,0 +1,294 @@ | |||
1 | /* | ||
2 | * Intel SST generic IPC Support | ||
3 | * | ||
4 | * Copyright (C) 2015, Intel Corporation. All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License version | ||
8 | * 2 as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | */ | ||
16 | |||
17 | #include <linux/types.h> | ||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/list.h> | ||
20 | #include <linux/wait.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/spinlock.h> | ||
23 | #include <linux/device.h> | ||
24 | #include <linux/slab.h> | ||
25 | #include <linux/workqueue.h> | ||
26 | #include <linux/sched.h> | ||
27 | #include <linux/delay.h> | ||
28 | #include <linux/platform_device.h> | ||
29 | #include <linux/kthread.h> | ||
30 | #include <sound/asound.h> | ||
31 | |||
32 | #include "sst-dsp.h" | ||
33 | #include "sst-dsp-priv.h" | ||
34 | #include "sst-ipc.h" | ||
35 | |||
36 | /* IPC message timeout (msecs) */ | ||
37 | #define IPC_TIMEOUT_MSECS 300 | ||
38 | |||
39 | #define IPC_EMPTY_LIST_SIZE 8 | ||
40 | |||
41 | /* locks held by caller */ | ||
42 | static struct ipc_message *msg_get_empty(struct sst_generic_ipc *ipc) | ||
43 | { | ||
44 | struct ipc_message *msg = NULL; | ||
45 | |||
46 | if (!list_empty(&ipc->empty_list)) { | ||
47 | msg = list_first_entry(&ipc->empty_list, struct ipc_message, | ||
48 | list); | ||
49 | list_del(&msg->list); | ||
50 | } | ||
51 | |||
52 | return msg; | ||
53 | } | ||
54 | |||
55 | static int tx_wait_done(struct sst_generic_ipc *ipc, | ||
56 | struct ipc_message *msg, void *rx_data) | ||
57 | { | ||
58 | unsigned long flags; | ||
59 | int ret; | ||
60 | |||
61 | /* wait for DSP completion (in all cases atm inc pending) */ | ||
62 | ret = wait_event_timeout(msg->waitq, msg->complete, | ||
63 | msecs_to_jiffies(IPC_TIMEOUT_MSECS)); | ||
64 | |||
65 | spin_lock_irqsave(&ipc->dsp->spinlock, flags); | ||
66 | if (ret == 0) { | ||
67 | if (ipc->ops.shim_dbg != NULL) | ||
68 | ipc->ops.shim_dbg(ipc, "message timeout"); | ||
69 | |||
70 | list_del(&msg->list); | ||
71 | ret = -ETIMEDOUT; | ||
72 | } else { | ||
73 | |||
74 | /* copy the data returned from DSP */ | ||
75 | if (msg->rx_size) | ||
76 | memcpy(rx_data, msg->rx_data, msg->rx_size); | ||
77 | ret = msg->errno; | ||
78 | } | ||
79 | |||
80 | list_add_tail(&msg->list, &ipc->empty_list); | ||
81 | spin_unlock_irqrestore(&ipc->dsp->spinlock, flags); | ||
82 | return ret; | ||
83 | } | ||
84 | |||
85 | static int ipc_tx_message(struct sst_generic_ipc *ipc, u64 header, | ||
86 | void *tx_data, size_t tx_bytes, void *rx_data, | ||
87 | size_t rx_bytes, int wait) | ||
88 | { | ||
89 | struct ipc_message *msg; | ||
90 | unsigned long flags; | ||
91 | |||
92 | spin_lock_irqsave(&ipc->dsp->spinlock, flags); | ||
93 | |||
94 | msg = msg_get_empty(ipc); | ||
95 | if (msg == NULL) { | ||
96 | spin_unlock_irqrestore(&ipc->dsp->spinlock, flags); | ||
97 | return -EBUSY; | ||
98 | } | ||
99 | |||
100 | msg->header = header; | ||
101 | msg->tx_size = tx_bytes; | ||
102 | msg->rx_size = rx_bytes; | ||
103 | msg->wait = wait; | ||
104 | msg->errno = 0; | ||
105 | msg->pending = false; | ||
106 | msg->complete = false; | ||
107 | |||
108 | if ((tx_bytes) && (ipc->ops.tx_data_copy != NULL)) | ||
109 | ipc->ops.tx_data_copy(msg, tx_data, tx_bytes); | ||
110 | |||
111 | list_add_tail(&msg->list, &ipc->tx_list); | ||
112 | spin_unlock_irqrestore(&ipc->dsp->spinlock, flags); | ||
113 | |||
114 | queue_kthread_work(&ipc->kworker, &ipc->kwork); | ||
115 | |||
116 | if (wait) | ||
117 | return tx_wait_done(ipc, msg, rx_data); | ||
118 | else | ||
119 | return 0; | ||
120 | } | ||
121 | |||
122 | static int msg_empty_list_init(struct sst_generic_ipc *ipc) | ||
123 | { | ||
124 | int i; | ||
125 | |||
126 | ipc->msg = kzalloc(sizeof(struct ipc_message) * | ||
127 | IPC_EMPTY_LIST_SIZE, GFP_KERNEL); | ||
128 | if (ipc->msg == NULL) | ||
129 | return -ENOMEM; | ||
130 | |||
131 | for (i = 0; i < IPC_EMPTY_LIST_SIZE; i++) { | ||
132 | init_waitqueue_head(&ipc->msg[i].waitq); | ||
133 | list_add(&ipc->msg[i].list, &ipc->empty_list); | ||
134 | } | ||
135 | |||
136 | return 0; | ||
137 | } | ||
138 | |||
139 | static void ipc_tx_msgs(struct kthread_work *work) | ||
140 | { | ||
141 | struct sst_generic_ipc *ipc = | ||
142 | container_of(work, struct sst_generic_ipc, kwork); | ||
143 | struct ipc_message *msg; | ||
144 | unsigned long flags; | ||
145 | u64 ipcx; | ||
146 | |||
147 | spin_lock_irqsave(&ipc->dsp->spinlock, flags); | ||
148 | |||
149 | if (list_empty(&ipc->tx_list) || ipc->pending) { | ||
150 | spin_unlock_irqrestore(&ipc->dsp->spinlock, flags); | ||
151 | return; | ||
152 | } | ||
153 | |||
154 | /* if the DSP is busy, we will TX messages after IRQ. | ||
155 | * also postpone if we are in the middle of procesing completion irq*/ | ||
156 | ipcx = sst_dsp_shim_read_unlocked(ipc->dsp, SST_IPCX); | ||
157 | if (ipcx & (SST_IPCX_BUSY | SST_IPCX_DONE)) { | ||
158 | spin_unlock_irqrestore(&ipc->dsp->spinlock, flags); | ||
159 | return; | ||
160 | } | ||
161 | |||
162 | msg = list_first_entry(&ipc->tx_list, struct ipc_message, list); | ||
163 | list_move(&msg->list, &ipc->rx_list); | ||
164 | |||
165 | if (ipc->ops.tx_msg != NULL) | ||
166 | ipc->ops.tx_msg(ipc, msg); | ||
167 | |||
168 | spin_unlock_irqrestore(&ipc->dsp->spinlock, flags); | ||
169 | } | ||
170 | |||
171 | int sst_ipc_tx_message_wait(struct sst_generic_ipc *ipc, u64 header, | ||
172 | void *tx_data, size_t tx_bytes, void *rx_data, size_t rx_bytes) | ||
173 | { | ||
174 | return ipc_tx_message(ipc, header, tx_data, tx_bytes, | ||
175 | rx_data, rx_bytes, 1); | ||
176 | } | ||
177 | EXPORT_SYMBOL_GPL(sst_ipc_tx_message_wait); | ||
178 | |||
179 | int sst_ipc_tx_message_nowait(struct sst_generic_ipc *ipc, u64 header, | ||
180 | void *tx_data, size_t tx_bytes) | ||
181 | { | ||
182 | return ipc_tx_message(ipc, header, tx_data, tx_bytes, | ||
183 | NULL, 0, 0); | ||
184 | } | ||
185 | EXPORT_SYMBOL_GPL(sst_ipc_tx_message_nowait); | ||
186 | |||
187 | struct ipc_message *sst_ipc_reply_find_msg(struct sst_generic_ipc *ipc, | ||
188 | u64 header) | ||
189 | { | ||
190 | struct ipc_message *msg; | ||
191 | u64 mask; | ||
192 | |||
193 | if (ipc->ops.reply_msg_match != NULL) | ||
194 | header = ipc->ops.reply_msg_match(header, &mask); | ||
195 | |||
196 | if (list_empty(&ipc->rx_list)) { | ||
197 | dev_err(ipc->dev, "error: rx list empty but received 0x%llx\n", | ||
198 | header); | ||
199 | return NULL; | ||
200 | } | ||
201 | |||
202 | list_for_each_entry(msg, &ipc->rx_list, list) { | ||
203 | if ((msg->header & mask) == header) | ||
204 | return msg; | ||
205 | } | ||
206 | |||
207 | return NULL; | ||
208 | } | ||
209 | EXPORT_SYMBOL_GPL(sst_ipc_reply_find_msg); | ||
210 | |||
211 | /* locks held by caller */ | ||
212 | void sst_ipc_tx_msg_reply_complete(struct sst_generic_ipc *ipc, | ||
213 | struct ipc_message *msg) | ||
214 | { | ||
215 | msg->complete = true; | ||
216 | |||
217 | if (!msg->wait) | ||
218 | list_add_tail(&msg->list, &ipc->empty_list); | ||
219 | else | ||
220 | wake_up(&msg->waitq); | ||
221 | } | ||
222 | EXPORT_SYMBOL_GPL(sst_ipc_tx_msg_reply_complete); | ||
223 | |||
224 | void sst_ipc_drop_all(struct sst_generic_ipc *ipc) | ||
225 | { | ||
226 | struct ipc_message *msg, *tmp; | ||
227 | unsigned long flags; | ||
228 | int tx_drop_cnt = 0, rx_drop_cnt = 0; | ||
229 | |||
230 | /* drop all TX and Rx messages before we stall + reset DSP */ | ||
231 | spin_lock_irqsave(&ipc->dsp->spinlock, flags); | ||
232 | |||
233 | list_for_each_entry_safe(msg, tmp, &ipc->tx_list, list) { | ||
234 | list_move(&msg->list, &ipc->empty_list); | ||
235 | tx_drop_cnt++; | ||
236 | } | ||
237 | |||
238 | list_for_each_entry_safe(msg, tmp, &ipc->rx_list, list) { | ||
239 | list_move(&msg->list, &ipc->empty_list); | ||
240 | rx_drop_cnt++; | ||
241 | } | ||
242 | |||
243 | spin_unlock_irqrestore(&ipc->dsp->spinlock, flags); | ||
244 | |||
245 | if (tx_drop_cnt || rx_drop_cnt) | ||
246 | dev_err(ipc->dev, "dropped IPC msg RX=%d, TX=%d\n", | ||
247 | tx_drop_cnt, rx_drop_cnt); | ||
248 | } | ||
249 | EXPORT_SYMBOL_GPL(sst_ipc_drop_all); | ||
250 | |||
251 | int sst_ipc_init(struct sst_generic_ipc *ipc) | ||
252 | { | ||
253 | int ret; | ||
254 | |||
255 | INIT_LIST_HEAD(&ipc->tx_list); | ||
256 | INIT_LIST_HEAD(&ipc->rx_list); | ||
257 | INIT_LIST_HEAD(&ipc->empty_list); | ||
258 | init_waitqueue_head(&ipc->wait_txq); | ||
259 | |||
260 | ret = msg_empty_list_init(ipc); | ||
261 | if (ret < 0) | ||
262 | return -ENOMEM; | ||
263 | |||
264 | /* start the IPC message thread */ | ||
265 | init_kthread_worker(&ipc->kworker); | ||
266 | ipc->tx_thread = kthread_run(kthread_worker_fn, | ||
267 | &ipc->kworker, "%s", | ||
268 | dev_name(ipc->dev)); | ||
269 | if (IS_ERR(ipc->tx_thread)) { | ||
270 | dev_err(ipc->dev, "error: failed to create message TX task\n"); | ||
271 | ret = PTR_ERR(ipc->tx_thread); | ||
272 | kfree(ipc->msg); | ||
273 | return ret; | ||
274 | } | ||
275 | |||
276 | init_kthread_work(&ipc->kwork, ipc_tx_msgs); | ||
277 | return 0; | ||
278 | } | ||
279 | EXPORT_SYMBOL_GPL(sst_ipc_init); | ||
280 | |||
281 | void sst_ipc_fini(struct sst_generic_ipc *ipc) | ||
282 | { | ||
283 | if (ipc->tx_thread) | ||
284 | kthread_stop(ipc->tx_thread); | ||
285 | |||
286 | if (ipc->msg) | ||
287 | kfree(ipc->msg); | ||
288 | } | ||
289 | EXPORT_SYMBOL_GPL(sst_ipc_fini); | ||
290 | |||
291 | /* Module information */ | ||
292 | MODULE_AUTHOR("Jin Yao"); | ||
293 | MODULE_DESCRIPTION("Intel SST IPC generic"); | ||
294 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/sound/soc/intel/common/sst-ipc.h b/sound/soc/intel/common/sst-ipc.h new file mode 100644 index 000000000000..125ea451a373 --- /dev/null +++ b/sound/soc/intel/common/sst-ipc.h | |||
@@ -0,0 +1,91 @@ | |||
1 | /* | ||
2 | * Intel SST generic IPC Support | ||
3 | * | ||
4 | * Copyright (C) 2015, Intel Corporation. All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License version | ||
8 | * 2 as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | */ | ||
16 | |||
17 | #ifndef __SST_GENERIC_IPC_H | ||
18 | #define __SST_GENERIC_IPC_H | ||
19 | |||
20 | #include <linux/types.h> | ||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/wait.h> | ||
23 | #include <linux/list.h> | ||
24 | #include <linux/workqueue.h> | ||
25 | #include <linux/sched.h> | ||
26 | #include <linux/kthread.h> | ||
27 | |||
28 | #define IPC_MAX_MAILBOX_BYTES 256 | ||
29 | |||
30 | struct ipc_message { | ||
31 | struct list_head list; | ||
32 | u64 header; | ||
33 | |||
34 | /* direction wrt host CPU */ | ||
35 | char tx_data[IPC_MAX_MAILBOX_BYTES]; | ||
36 | size_t tx_size; | ||
37 | char rx_data[IPC_MAX_MAILBOX_BYTES]; | ||
38 | size_t rx_size; | ||
39 | |||
40 | wait_queue_head_t waitq; | ||
41 | bool pending; | ||
42 | bool complete; | ||
43 | bool wait; | ||
44 | int errno; | ||
45 | }; | ||
46 | |||
47 | struct sst_generic_ipc; | ||
48 | |||
49 | struct sst_plat_ipc_ops { | ||
50 | void (*tx_msg)(struct sst_generic_ipc *, struct ipc_message *); | ||
51 | void (*shim_dbg)(struct sst_generic_ipc *, const char *); | ||
52 | void (*tx_data_copy)(struct ipc_message *, char *, size_t); | ||
53 | u64 (*reply_msg_match)(u64 header, u64 *mask); | ||
54 | }; | ||
55 | |||
56 | /* SST generic IPC data */ | ||
57 | struct sst_generic_ipc { | ||
58 | struct device *dev; | ||
59 | struct sst_dsp *dsp; | ||
60 | |||
61 | /* IPC messaging */ | ||
62 | struct list_head tx_list; | ||
63 | struct list_head rx_list; | ||
64 | struct list_head empty_list; | ||
65 | wait_queue_head_t wait_txq; | ||
66 | struct task_struct *tx_thread; | ||
67 | struct kthread_worker kworker; | ||
68 | struct kthread_work kwork; | ||
69 | bool pending; | ||
70 | struct ipc_message *msg; | ||
71 | |||
72 | struct sst_plat_ipc_ops ops; | ||
73 | }; | ||
74 | |||
75 | int sst_ipc_tx_message_wait(struct sst_generic_ipc *ipc, u64 header, | ||
76 | void *tx_data, size_t tx_bytes, void *rx_data, size_t rx_bytes); | ||
77 | |||
78 | int sst_ipc_tx_message_nowait(struct sst_generic_ipc *ipc, u64 header, | ||
79 | void *tx_data, size_t tx_bytes); | ||
80 | |||
81 | struct ipc_message *sst_ipc_reply_find_msg(struct sst_generic_ipc *ipc, | ||
82 | u64 header); | ||
83 | |||
84 | void sst_ipc_tx_msg_reply_complete(struct sst_generic_ipc *ipc, | ||
85 | struct ipc_message *msg); | ||
86 | |||
87 | void sst_ipc_drop_all(struct sst_generic_ipc *ipc); | ||
88 | int sst_ipc_init(struct sst_generic_ipc *ipc); | ||
89 | void sst_ipc_fini(struct sst_generic_ipc *ipc); | ||
90 | |||
91 | #endif | ||
diff --git a/sound/soc/intel/haswell/Makefile b/sound/soc/intel/haswell/Makefile new file mode 100644 index 000000000000..9c1723112d22 --- /dev/null +++ b/sound/soc/intel/haswell/Makefile | |||
@@ -0,0 +1,4 @@ | |||
1 | snd-soc-sst-haswell-pcm-objs := \ | ||
2 | sst-haswell-ipc.o sst-haswell-pcm.o sst-haswell-dsp.o | ||
3 | |||
4 | obj-$(CONFIG_SND_SOC_INTEL_HASWELL) += snd-soc-sst-haswell-pcm.o | ||
diff --git a/sound/soc/intel/sst-haswell-dsp.c b/sound/soc/intel/haswell/sst-haswell-dsp.c index 402b728c0a06..7f94920c8a4d 100644 --- a/sound/soc/intel/sst-haswell-dsp.c +++ b/sound/soc/intel/haswell/sst-haswell-dsp.c | |||
@@ -28,9 +28,9 @@ | |||
28 | #include <linux/firmware.h> | 28 | #include <linux/firmware.h> |
29 | #include <linux/pm_runtime.h> | 29 | #include <linux/pm_runtime.h> |
30 | 30 | ||
31 | #include "sst-dsp.h" | 31 | #include "../common/sst-dsp.h" |
32 | #include "sst-dsp-priv.h" | 32 | #include "../common/sst-dsp-priv.h" |
33 | #include "sst-haswell-ipc.h" | 33 | #include "../haswell/sst-haswell-ipc.h" |
34 | 34 | ||
35 | #include <trace/events/hswadsp.h> | 35 | #include <trace/events/hswadsp.h> |
36 | 36 | ||
@@ -100,6 +100,7 @@ static int hsw_parse_module(struct sst_dsp *dsp, struct sst_fw *fw, | |||
100 | && module->type != SST_HSW_MODULE_PCM | 100 | && module->type != SST_HSW_MODULE_PCM |
101 | && module->type != SST_HSW_MODULE_PCM_REFERENCE | 101 | && module->type != SST_HSW_MODULE_PCM_REFERENCE |
102 | && module->type != SST_HSW_MODULE_PCM_CAPTURE | 102 | && module->type != SST_HSW_MODULE_PCM_CAPTURE |
103 | && module->type != SST_HSW_MODULE_WAVES | ||
103 | && module->type != SST_HSW_MODULE_LPAL) | 104 | && module->type != SST_HSW_MODULE_LPAL) |
104 | return 0; | 105 | return 0; |
105 | 106 | ||
@@ -139,6 +140,7 @@ static int hsw_parse_module(struct sst_dsp *dsp, struct sst_fw *fw, | |||
139 | mod->type = SST_MEM_IRAM; | 140 | mod->type = SST_MEM_IRAM; |
140 | break; | 141 | break; |
141 | case SST_HSW_DRAM: | 142 | case SST_HSW_DRAM: |
143 | case SST_HSW_REGS: | ||
142 | ram = dsp->addr.lpe; | 144 | ram = dsp->addr.lpe; |
143 | mod->offset = block->ram_offset; | 145 | mod->offset = block->ram_offset; |
144 | mod->type = SST_MEM_DRAM; | 146 | mod->type = SST_MEM_DRAM; |
@@ -169,6 +171,7 @@ static int hsw_parse_module(struct sst_dsp *dsp, struct sst_fw *fw, | |||
169 | 171 | ||
170 | block = (void *)block + sizeof(*block) + block->size; | 172 | block = (void *)block + sizeof(*block) + block->size; |
171 | } | 173 | } |
174 | mod->state = SST_MODULE_STATE_LOADED; | ||
172 | 175 | ||
173 | return 0; | 176 | return 0; |
174 | } | 177 | } |
diff --git a/sound/soc/intel/sst-haswell-ipc.c b/sound/soc/intel/haswell/sst-haswell-ipc.c index 863a9ca34b8e..344a1e9bbce5 100644 --- a/sound/soc/intel/sst-haswell-ipc.c +++ b/sound/soc/intel/haswell/sst-haswell-ipc.c | |||
@@ -34,8 +34,9 @@ | |||
34 | #include <sound/asound.h> | 34 | #include <sound/asound.h> |
35 | 35 | ||
36 | #include "sst-haswell-ipc.h" | 36 | #include "sst-haswell-ipc.h" |
37 | #include "sst-dsp.h" | 37 | #include "../common/sst-dsp.h" |
38 | #include "sst-dsp-priv.h" | 38 | #include "../common/sst-dsp-priv.h" |
39 | #include "../common/sst-ipc.h" | ||
39 | 40 | ||
40 | /* Global Message - Generic */ | 41 | /* Global Message - Generic */ |
41 | #define IPC_GLB_TYPE_SHIFT 24 | 42 | #define IPC_GLB_TYPE_SHIFT 24 |
@@ -79,6 +80,15 @@ | |||
79 | #define IPC_LOG_ID_MASK (0xf << IPC_LOG_ID_SHIFT) | 80 | #define IPC_LOG_ID_MASK (0xf << IPC_LOG_ID_SHIFT) |
80 | #define IPC_LOG_ID(x) (x << IPC_LOG_ID_SHIFT) | 81 | #define IPC_LOG_ID(x) (x << IPC_LOG_ID_SHIFT) |
81 | 82 | ||
83 | /* Module Message */ | ||
84 | #define IPC_MODULE_OPERATION_SHIFT 20 | ||
85 | #define IPC_MODULE_OPERATION_MASK (0xf << IPC_MODULE_OPERATION_SHIFT) | ||
86 | #define IPC_MODULE_OPERATION(x) (x << IPC_MODULE_OPERATION_SHIFT) | ||
87 | |||
88 | #define IPC_MODULE_ID_SHIFT 16 | ||
89 | #define IPC_MODULE_ID_MASK (0xf << IPC_MODULE_ID_SHIFT) | ||
90 | #define IPC_MODULE_ID(x) (x << IPC_MODULE_ID_SHIFT) | ||
91 | |||
82 | /* IPC message timeout (msecs) */ | 92 | /* IPC message timeout (msecs) */ |
83 | #define IPC_TIMEOUT_MSECS 300 | 93 | #define IPC_TIMEOUT_MSECS 300 |
84 | #define IPC_BOOT_MSECS 200 | 94 | #define IPC_BOOT_MSECS 200 |
@@ -115,6 +125,7 @@ enum ipc_glb_type { | |||
115 | IPC_GLB_ENTER_DX_STATE = 12, | 125 | IPC_GLB_ENTER_DX_STATE = 12, |
116 | IPC_GLB_GET_MIXER_STREAM_INFO = 13, /* Request mixer stream params */ | 126 | IPC_GLB_GET_MIXER_STREAM_INFO = 13, /* Request mixer stream params */ |
117 | IPC_GLB_DEBUG_LOG_MESSAGE = 14, /* Message to or from the debug logger. */ | 127 | IPC_GLB_DEBUG_LOG_MESSAGE = 14, /* Message to or from the debug logger. */ |
128 | IPC_GLB_MODULE_OPERATION = 15, /* Message to loadable fw module */ | ||
118 | IPC_GLB_REQUEST_TRANSFER = 16, /* < Request Transfer for host */ | 129 | IPC_GLB_REQUEST_TRANSFER = 16, /* < Request Transfer for host */ |
119 | IPC_GLB_MAX_IPC_MESSAGE_TYPE = 17, /* Maximum message number */ | 130 | IPC_GLB_MAX_IPC_MESSAGE_TYPE = 17, /* Maximum message number */ |
120 | }; | 131 | }; |
@@ -133,6 +144,16 @@ enum ipc_glb_reply { | |||
133 | IPC_GLB_REPLY_SOURCE_NOT_STARTED = 10, /* Source was not started. */ | 144 | IPC_GLB_REPLY_SOURCE_NOT_STARTED = 10, /* Source was not started. */ |
134 | }; | 145 | }; |
135 | 146 | ||
147 | enum ipc_module_operation { | ||
148 | IPC_MODULE_NOTIFICATION = 0, | ||
149 | IPC_MODULE_ENABLE = 1, | ||
150 | IPC_MODULE_DISABLE = 2, | ||
151 | IPC_MODULE_GET_PARAMETER = 3, | ||
152 | IPC_MODULE_SET_PARAMETER = 4, | ||
153 | IPC_MODULE_GET_INFO = 5, | ||
154 | IPC_MODULE_MAX_MESSAGE | ||
155 | }; | ||
156 | |||
136 | /* Stream Message - Types */ | 157 | /* Stream Message - Types */ |
137 | enum ipc_str_operation { | 158 | enum ipc_str_operation { |
138 | IPC_STR_RESET = 0, | 159 | IPC_STR_RESET = 0, |
@@ -190,23 +211,6 @@ struct sst_hsw_ipc_fw_ready { | |||
190 | u8 fw_info[IPC_MAX_MAILBOX_BYTES - 5 * sizeof(u32)]; | 211 | u8 fw_info[IPC_MAX_MAILBOX_BYTES - 5 * sizeof(u32)]; |
191 | } __attribute__((packed)); | 212 | } __attribute__((packed)); |
192 | 213 | ||
193 | struct ipc_message { | ||
194 | struct list_head list; | ||
195 | u32 header; | ||
196 | |||
197 | /* direction wrt host CPU */ | ||
198 | char tx_data[IPC_MAX_MAILBOX_BYTES]; | ||
199 | size_t tx_size; | ||
200 | char rx_data[IPC_MAX_MAILBOX_BYTES]; | ||
201 | size_t rx_size; | ||
202 | |||
203 | wait_queue_head_t waitq; | ||
204 | bool pending; | ||
205 | bool complete; | ||
206 | bool wait; | ||
207 | int errno; | ||
208 | }; | ||
209 | |||
210 | struct sst_hsw_stream; | 214 | struct sst_hsw_stream; |
211 | struct sst_hsw; | 215 | struct sst_hsw; |
212 | 216 | ||
@@ -305,18 +309,19 @@ struct sst_hsw { | |||
305 | bool shutdown; | 309 | bool shutdown; |
306 | 310 | ||
307 | /* IPC messaging */ | 311 | /* IPC messaging */ |
308 | struct list_head tx_list; | 312 | struct sst_generic_ipc ipc; |
309 | struct list_head rx_list; | ||
310 | struct list_head empty_list; | ||
311 | wait_queue_head_t wait_txq; | ||
312 | struct task_struct *tx_thread; | ||
313 | struct kthread_worker kworker; | ||
314 | struct kthread_work kwork; | ||
315 | bool pending; | ||
316 | struct ipc_message *msg; | ||
317 | 313 | ||
318 | /* FW log stream */ | 314 | /* FW log stream */ |
319 | struct sst_hsw_log_stream log_stream; | 315 | struct sst_hsw_log_stream log_stream; |
316 | |||
317 | /* flags bit field to track module state when resume from RTD3, | ||
318 | * each bit represent state (enabled/disabled) of single module */ | ||
319 | u32 enabled_modules_rtd3; | ||
320 | |||
321 | /* buffer to store parameter lines */ | ||
322 | u32 param_idx_w; /* write index */ | ||
323 | u32 param_idx_r; /* read index */ | ||
324 | u8 param_buf[WAVES_PARAM_LINES][WAVES_PARAM_COUNT]; | ||
320 | }; | 325 | }; |
321 | 326 | ||
322 | #define CREATE_TRACE_POINTS | 327 | #define CREATE_TRACE_POINTS |
@@ -352,6 +357,16 @@ static inline u32 msg_get_notify_reason(u32 msg) | |||
352 | return (msg & IPC_STG_TYPE_MASK) >> IPC_STG_TYPE_SHIFT; | 357 | return (msg & IPC_STG_TYPE_MASK) >> IPC_STG_TYPE_SHIFT; |
353 | } | 358 | } |
354 | 359 | ||
360 | static inline u32 msg_get_module_operation(u32 msg) | ||
361 | { | ||
362 | return (msg & IPC_MODULE_OPERATION_MASK) >> IPC_MODULE_OPERATION_SHIFT; | ||
363 | } | ||
364 | |||
365 | static inline u32 msg_get_module_id(u32 msg) | ||
366 | { | ||
367 | return (msg & IPC_MODULE_ID_MASK) >> IPC_MODULE_ID_SHIFT; | ||
368 | } | ||
369 | |||
355 | u32 create_channel_map(enum sst_hsw_channel_config config) | 370 | u32 create_channel_map(enum sst_hsw_channel_config config) |
356 | { | 371 | { |
357 | switch (config) { | 372 | switch (config) { |
@@ -417,159 +432,6 @@ static struct sst_hsw_stream *get_stream_by_id(struct sst_hsw *hsw, | |||
417 | return NULL; | 432 | return NULL; |
418 | } | 433 | } |
419 | 434 | ||
420 | static void ipc_shim_dbg(struct sst_hsw *hsw, const char *text) | ||
421 | { | ||
422 | struct sst_dsp *sst = hsw->dsp; | ||
423 | u32 isr, ipcd, imrx, ipcx; | ||
424 | |||
425 | ipcx = sst_dsp_shim_read_unlocked(sst, SST_IPCX); | ||
426 | isr = sst_dsp_shim_read_unlocked(sst, SST_ISRX); | ||
427 | ipcd = sst_dsp_shim_read_unlocked(sst, SST_IPCD); | ||
428 | imrx = sst_dsp_shim_read_unlocked(sst, SST_IMRX); | ||
429 | |||
430 | dev_err(hsw->dev, "ipc: --%s-- ipcx 0x%8.8x isr 0x%8.8x ipcd 0x%8.8x imrx 0x%8.8x\n", | ||
431 | text, ipcx, isr, ipcd, imrx); | ||
432 | } | ||
433 | |||
434 | /* locks held by caller */ | ||
435 | static struct ipc_message *msg_get_empty(struct sst_hsw *hsw) | ||
436 | { | ||
437 | struct ipc_message *msg = NULL; | ||
438 | |||
439 | if (!list_empty(&hsw->empty_list)) { | ||
440 | msg = list_first_entry(&hsw->empty_list, struct ipc_message, | ||
441 | list); | ||
442 | list_del(&msg->list); | ||
443 | } | ||
444 | |||
445 | return msg; | ||
446 | } | ||
447 | |||
448 | static void ipc_tx_msgs(struct kthread_work *work) | ||
449 | { | ||
450 | struct sst_hsw *hsw = | ||
451 | container_of(work, struct sst_hsw, kwork); | ||
452 | struct ipc_message *msg; | ||
453 | unsigned long flags; | ||
454 | u32 ipcx; | ||
455 | |||
456 | spin_lock_irqsave(&hsw->dsp->spinlock, flags); | ||
457 | |||
458 | if (list_empty(&hsw->tx_list) || hsw->pending) { | ||
459 | spin_unlock_irqrestore(&hsw->dsp->spinlock, flags); | ||
460 | return; | ||
461 | } | ||
462 | |||
463 | /* if the DSP is busy, we will TX messages after IRQ. | ||
464 | * also postpone if we are in the middle of procesing completion irq*/ | ||
465 | ipcx = sst_dsp_shim_read_unlocked(hsw->dsp, SST_IPCX); | ||
466 | if (ipcx & (SST_IPCX_BUSY | SST_IPCX_DONE)) { | ||
467 | spin_unlock_irqrestore(&hsw->dsp->spinlock, flags); | ||
468 | return; | ||
469 | } | ||
470 | |||
471 | msg = list_first_entry(&hsw->tx_list, struct ipc_message, list); | ||
472 | |||
473 | list_move(&msg->list, &hsw->rx_list); | ||
474 | |||
475 | /* send the message */ | ||
476 | sst_dsp_outbox_write(hsw->dsp, msg->tx_data, msg->tx_size); | ||
477 | sst_dsp_ipc_msg_tx(hsw->dsp, msg->header | SST_IPCX_BUSY); | ||
478 | |||
479 | spin_unlock_irqrestore(&hsw->dsp->spinlock, flags); | ||
480 | } | ||
481 | |||
482 | /* locks held by caller */ | ||
483 | static void tx_msg_reply_complete(struct sst_hsw *hsw, struct ipc_message *msg) | ||
484 | { | ||
485 | msg->complete = true; | ||
486 | trace_ipc_reply("completed", msg->header); | ||
487 | |||
488 | if (!msg->wait) | ||
489 | list_add_tail(&msg->list, &hsw->empty_list); | ||
490 | else | ||
491 | wake_up(&msg->waitq); | ||
492 | } | ||
493 | |||
494 | static int tx_wait_done(struct sst_hsw *hsw, struct ipc_message *msg, | ||
495 | void *rx_data) | ||
496 | { | ||
497 | unsigned long flags; | ||
498 | int ret; | ||
499 | |||
500 | /* wait for DSP completion (in all cases atm inc pending) */ | ||
501 | ret = wait_event_timeout(msg->waitq, msg->complete, | ||
502 | msecs_to_jiffies(IPC_TIMEOUT_MSECS)); | ||
503 | |||
504 | spin_lock_irqsave(&hsw->dsp->spinlock, flags); | ||
505 | if (ret == 0) { | ||
506 | ipc_shim_dbg(hsw, "message timeout"); | ||
507 | |||
508 | trace_ipc_error("error message timeout for", msg->header); | ||
509 | list_del(&msg->list); | ||
510 | ret = -ETIMEDOUT; | ||
511 | } else { | ||
512 | |||
513 | /* copy the data returned from DSP */ | ||
514 | if (msg->rx_size) | ||
515 | memcpy(rx_data, msg->rx_data, msg->rx_size); | ||
516 | ret = msg->errno; | ||
517 | } | ||
518 | |||
519 | list_add_tail(&msg->list, &hsw->empty_list); | ||
520 | spin_unlock_irqrestore(&hsw->dsp->spinlock, flags); | ||
521 | return ret; | ||
522 | } | ||
523 | |||
524 | static int ipc_tx_message(struct sst_hsw *hsw, u32 header, void *tx_data, | ||
525 | size_t tx_bytes, void *rx_data, size_t rx_bytes, int wait) | ||
526 | { | ||
527 | struct ipc_message *msg; | ||
528 | unsigned long flags; | ||
529 | |||
530 | spin_lock_irqsave(&hsw->dsp->spinlock, flags); | ||
531 | |||
532 | msg = msg_get_empty(hsw); | ||
533 | if (msg == NULL) { | ||
534 | spin_unlock_irqrestore(&hsw->dsp->spinlock, flags); | ||
535 | return -EBUSY; | ||
536 | } | ||
537 | |||
538 | if (tx_bytes) | ||
539 | memcpy(msg->tx_data, tx_data, tx_bytes); | ||
540 | |||
541 | msg->header = header; | ||
542 | msg->tx_size = tx_bytes; | ||
543 | msg->rx_size = rx_bytes; | ||
544 | msg->wait = wait; | ||
545 | msg->errno = 0; | ||
546 | msg->pending = false; | ||
547 | msg->complete = false; | ||
548 | |||
549 | list_add_tail(&msg->list, &hsw->tx_list); | ||
550 | spin_unlock_irqrestore(&hsw->dsp->spinlock, flags); | ||
551 | |||
552 | queue_kthread_work(&hsw->kworker, &hsw->kwork); | ||
553 | |||
554 | if (wait) | ||
555 | return tx_wait_done(hsw, msg, rx_data); | ||
556 | else | ||
557 | return 0; | ||
558 | } | ||
559 | |||
560 | static inline int ipc_tx_message_wait(struct sst_hsw *hsw, u32 header, | ||
561 | void *tx_data, size_t tx_bytes, void *rx_data, size_t rx_bytes) | ||
562 | { | ||
563 | return ipc_tx_message(hsw, header, tx_data, tx_bytes, rx_data, | ||
564 | rx_bytes, 1); | ||
565 | } | ||
566 | |||
567 | static inline int ipc_tx_message_nowait(struct sst_hsw *hsw, u32 header, | ||
568 | void *tx_data, size_t tx_bytes) | ||
569 | { | ||
570 | return ipc_tx_message(hsw, header, tx_data, tx_bytes, NULL, 0, 0); | ||
571 | } | ||
572 | |||
573 | static void hsw_fw_ready(struct sst_hsw *hsw, u32 header) | 435 | static void hsw_fw_ready(struct sst_hsw *hsw, u32 header) |
574 | { | 436 | { |
575 | struct sst_hsw_ipc_fw_ready fw_ready; | 437 | struct sst_hsw_ipc_fw_ready fw_ready; |
@@ -604,7 +466,7 @@ static void hsw_fw_ready(struct sst_hsw *hsw, u32 header) | |||
604 | /* log the FW version info got from the mailbox here. */ | 466 | /* log the FW version info got from the mailbox here. */ |
605 | memcpy(fw_info, fw_ready.fw_info, fw_ready.fw_info_size); | 467 | memcpy(fw_info, fw_ready.fw_info, fw_ready.fw_info_size); |
606 | pinfo = &fw_info[0]; | 468 | pinfo = &fw_info[0]; |
607 | for (i = 0; i < sizeof(tmp) / sizeof(char *); i++) | 469 | for (i = 0; i < ARRAY_SIZE(tmp); i++) |
608 | tmp[i] = strsep(&pinfo, " "); | 470 | tmp[i] = strsep(&pinfo, " "); |
609 | dev_info(hsw->dev, "FW loaded, mailbox readback FW info: type %s, - " | 471 | dev_info(hsw->dev, "FW loaded, mailbox readback FW info: type %s, - " |
610 | "version: %s.%s, build %s, source commit id: %s\n", | 472 | "version: %s.%s, build %s, source commit id: %s\n", |
@@ -657,27 +519,6 @@ static void hsw_notification_work(struct work_struct *work) | |||
657 | sst_dsp_shim_update_bits(hsw->dsp, SST_IMRX, SST_IMRX_BUSY, 0); | 519 | sst_dsp_shim_update_bits(hsw->dsp, SST_IMRX, SST_IMRX_BUSY, 0); |
658 | } | 520 | } |
659 | 521 | ||
660 | static struct ipc_message *reply_find_msg(struct sst_hsw *hsw, u32 header) | ||
661 | { | ||
662 | struct ipc_message *msg; | ||
663 | |||
664 | /* clear reply bits & status bits */ | ||
665 | header &= ~(IPC_STATUS_MASK | IPC_GLB_REPLY_MASK); | ||
666 | |||
667 | if (list_empty(&hsw->rx_list)) { | ||
668 | dev_err(hsw->dev, "error: rx list empty but received 0x%x\n", | ||
669 | header); | ||
670 | return NULL; | ||
671 | } | ||
672 | |||
673 | list_for_each_entry(msg, &hsw->rx_list, list) { | ||
674 | if (msg->header == header) | ||
675 | return msg; | ||
676 | } | ||
677 | |||
678 | return NULL; | ||
679 | } | ||
680 | |||
681 | static void hsw_stream_update(struct sst_hsw *hsw, struct ipc_message *msg) | 522 | static void hsw_stream_update(struct sst_hsw *hsw, struct ipc_message *msg) |
682 | { | 523 | { |
683 | struct sst_hsw_stream *stream; | 524 | struct sst_hsw_stream *stream; |
@@ -716,7 +557,7 @@ static int hsw_process_reply(struct sst_hsw *hsw, u32 header) | |||
716 | 557 | ||
717 | trace_ipc_reply("processing -->", header); | 558 | trace_ipc_reply("processing -->", header); |
718 | 559 | ||
719 | msg = reply_find_msg(hsw, header); | 560 | msg = sst_ipc_reply_find_msg(&hsw->ipc, header); |
720 | if (msg == NULL) { | 561 | if (msg == NULL) { |
721 | trace_ipc_error("error: can't find message header", header); | 562 | trace_ipc_error("error: can't find message header", header); |
722 | return -EIO; | 563 | return -EIO; |
@@ -727,14 +568,14 @@ static int hsw_process_reply(struct sst_hsw *hsw, u32 header) | |||
727 | case IPC_GLB_REPLY_PENDING: | 568 | case IPC_GLB_REPLY_PENDING: |
728 | trace_ipc_pending_reply("received", header); | 569 | trace_ipc_pending_reply("received", header); |
729 | msg->pending = true; | 570 | msg->pending = true; |
730 | hsw->pending = true; | 571 | hsw->ipc.pending = true; |
731 | return 1; | 572 | return 1; |
732 | case IPC_GLB_REPLY_SUCCESS: | 573 | case IPC_GLB_REPLY_SUCCESS: |
733 | if (msg->pending) { | 574 | if (msg->pending) { |
734 | trace_ipc_pending_reply("completed", header); | 575 | trace_ipc_pending_reply("completed", header); |
735 | sst_dsp_inbox_read(hsw->dsp, msg->rx_data, | 576 | sst_dsp_inbox_read(hsw->dsp, msg->rx_data, |
736 | msg->rx_size); | 577 | msg->rx_size); |
737 | hsw->pending = false; | 578 | hsw->ipc.pending = false; |
738 | } else { | 579 | } else { |
739 | /* copy data from the DSP */ | 580 | /* copy data from the DSP */ |
740 | sst_dsp_outbox_read(hsw->dsp, msg->rx_data, | 581 | sst_dsp_outbox_read(hsw->dsp, msg->rx_data, |
@@ -790,11 +631,36 @@ static int hsw_process_reply(struct sst_hsw *hsw, u32 header) | |||
790 | 631 | ||
791 | /* wake up and return the error if we have waiters on this message ? */ | 632 | /* wake up and return the error if we have waiters on this message ? */ |
792 | list_del(&msg->list); | 633 | list_del(&msg->list); |
793 | tx_msg_reply_complete(hsw, msg); | 634 | sst_ipc_tx_msg_reply_complete(&hsw->ipc, msg); |
794 | 635 | ||
795 | return 1; | 636 | return 1; |
796 | } | 637 | } |
797 | 638 | ||
639 | static int hsw_module_message(struct sst_hsw *hsw, u32 header) | ||
640 | { | ||
641 | u32 operation, module_id; | ||
642 | int handled = 0; | ||
643 | |||
644 | operation = msg_get_module_operation(header); | ||
645 | module_id = msg_get_module_id(header); | ||
646 | dev_dbg(hsw->dev, "received module message header: 0x%8.8x\n", | ||
647 | header); | ||
648 | dev_dbg(hsw->dev, "operation: 0x%8.8x module_id: 0x%8.8x\n", | ||
649 | operation, module_id); | ||
650 | |||
651 | switch (operation) { | ||
652 | case IPC_MODULE_NOTIFICATION: | ||
653 | dev_dbg(hsw->dev, "module notification received"); | ||
654 | handled = 1; | ||
655 | break; | ||
656 | default: | ||
657 | handled = hsw_process_reply(hsw, header); | ||
658 | break; | ||
659 | } | ||
660 | |||
661 | return handled; | ||
662 | } | ||
663 | |||
798 | static int hsw_stream_message(struct sst_hsw *hsw, u32 header) | 664 | static int hsw_stream_message(struct sst_hsw *hsw, u32 header) |
799 | { | 665 | { |
800 | u32 stream_msg, stream_id, stage_type; | 666 | u32 stream_msg, stream_id, stage_type; |
@@ -890,6 +756,9 @@ static int hsw_process_notification(struct sst_hsw *hsw) | |||
890 | case IPC_GLB_DEBUG_LOG_MESSAGE: | 756 | case IPC_GLB_DEBUG_LOG_MESSAGE: |
891 | handled = hsw_log_message(hsw, header); | 757 | handled = hsw_log_message(hsw, header); |
892 | break; | 758 | break; |
759 | case IPC_GLB_MODULE_OPERATION: | ||
760 | handled = hsw_module_message(hsw, header); | ||
761 | break; | ||
893 | default: | 762 | default: |
894 | dev_err(hsw->dev, "error: unexpected type %d hdr 0x%8.8x\n", | 763 | dev_err(hsw->dev, "error: unexpected type %d hdr 0x%8.8x\n", |
895 | type, header); | 764 | type, header); |
@@ -903,6 +772,7 @@ static irqreturn_t hsw_irq_thread(int irq, void *context) | |||
903 | { | 772 | { |
904 | struct sst_dsp *sst = (struct sst_dsp *) context; | 773 | struct sst_dsp *sst = (struct sst_dsp *) context; |
905 | struct sst_hsw *hsw = sst_dsp_get_thread_context(sst); | 774 | struct sst_hsw *hsw = sst_dsp_get_thread_context(sst); |
775 | struct sst_generic_ipc *ipc = &hsw->ipc; | ||
906 | u32 ipcx, ipcd; | 776 | u32 ipcx, ipcd; |
907 | int handled; | 777 | int handled; |
908 | unsigned long flags; | 778 | unsigned long flags; |
@@ -949,7 +819,7 @@ static irqreturn_t hsw_irq_thread(int irq, void *context) | |||
949 | spin_unlock_irqrestore(&sst->spinlock, flags); | 819 | spin_unlock_irqrestore(&sst->spinlock, flags); |
950 | 820 | ||
951 | /* continue to send any remaining messages... */ | 821 | /* continue to send any remaining messages... */ |
952 | queue_kthread_work(&hsw->kworker, &hsw->kwork); | 822 | queue_kthread_work(&ipc->kworker, &ipc->kwork); |
953 | 823 | ||
954 | return IRQ_HANDLED; | 824 | return IRQ_HANDLED; |
955 | } | 825 | } |
@@ -959,7 +829,8 @@ int sst_hsw_fw_get_version(struct sst_hsw *hsw, | |||
959 | { | 829 | { |
960 | int ret; | 830 | int ret; |
961 | 831 | ||
962 | ret = ipc_tx_message_wait(hsw, IPC_GLB_TYPE(IPC_GLB_GET_FW_VERSION), | 832 | ret = sst_ipc_tx_message_wait(&hsw->ipc, |
833 | IPC_GLB_TYPE(IPC_GLB_GET_FW_VERSION), | ||
963 | NULL, 0, version, sizeof(*version)); | 834 | NULL, 0, version, sizeof(*version)); |
964 | if (ret < 0) | 835 | if (ret < 0) |
965 | dev_err(hsw->dev, "error: get version failed\n"); | 836 | dev_err(hsw->dev, "error: get version failed\n"); |
@@ -1023,7 +894,8 @@ int sst_hsw_stream_set_volume(struct sst_hsw *hsw, | |||
1023 | req->channel = channel; | 894 | req->channel = channel; |
1024 | } | 895 | } |
1025 | 896 | ||
1026 | ret = ipc_tx_message_wait(hsw, header, req, sizeof(*req), NULL, 0); | 897 | ret = sst_ipc_tx_message_wait(&hsw->ipc, header, req, |
898 | sizeof(*req), NULL, 0); | ||
1027 | if (ret < 0) { | 899 | if (ret < 0) { |
1028 | dev_err(hsw->dev, "error: set stream volume failed\n"); | 900 | dev_err(hsw->dev, "error: set stream volume failed\n"); |
1029 | return ret; | 901 | return ret; |
@@ -1088,7 +960,8 @@ int sst_hsw_mixer_set_volume(struct sst_hsw *hsw, u32 stage_id, u32 channel, | |||
1088 | req.curve_type = hsw->curve_type; | 960 | req.curve_type = hsw->curve_type; |
1089 | req.target_volume = volume; | 961 | req.target_volume = volume; |
1090 | 962 | ||
1091 | ret = ipc_tx_message_wait(hsw, header, &req, sizeof(req), NULL, 0); | 963 | ret = sst_ipc_tx_message_wait(&hsw->ipc, header, &req, |
964 | sizeof(req), NULL, 0); | ||
1092 | if (ret < 0) { | 965 | if (ret < 0) { |
1093 | dev_err(hsw->dev, "error: set mixer volume failed\n"); | 966 | dev_err(hsw->dev, "error: set mixer volume failed\n"); |
1094 | return ret; | 967 | return ret; |
@@ -1146,7 +1019,7 @@ int sst_hsw_stream_free(struct sst_hsw *hsw, struct sst_hsw_stream *stream) | |||
1146 | stream->free_req.stream_id = stream->reply.stream_hw_id; | 1019 | stream->free_req.stream_id = stream->reply.stream_hw_id; |
1147 | header = IPC_GLB_TYPE(IPC_GLB_FREE_STREAM); | 1020 | header = IPC_GLB_TYPE(IPC_GLB_FREE_STREAM); |
1148 | 1021 | ||
1149 | ret = ipc_tx_message_wait(hsw, header, &stream->free_req, | 1022 | ret = sst_ipc_tx_message_wait(&hsw->ipc, header, &stream->free_req, |
1150 | sizeof(stream->free_req), NULL, 0); | 1023 | sizeof(stream->free_req), NULL, 0); |
1151 | if (ret < 0) { | 1024 | if (ret < 0) { |
1152 | dev_err(hsw->dev, "error: free stream %d failed\n", | 1025 | dev_err(hsw->dev, "error: free stream %d failed\n", |
@@ -1338,8 +1211,8 @@ int sst_hsw_stream_commit(struct sst_hsw *hsw, struct sst_hsw_stream *stream) | |||
1338 | 1211 | ||
1339 | header = IPC_GLB_TYPE(IPC_GLB_ALLOCATE_STREAM); | 1212 | header = IPC_GLB_TYPE(IPC_GLB_ALLOCATE_STREAM); |
1340 | 1213 | ||
1341 | ret = ipc_tx_message_wait(hsw, header, str_req, sizeof(*str_req), | 1214 | ret = sst_ipc_tx_message_wait(&hsw->ipc, header, str_req, |
1342 | reply, sizeof(*reply)); | 1215 | sizeof(*str_req), reply, sizeof(*reply)); |
1343 | if (ret < 0) { | 1216 | if (ret < 0) { |
1344 | dev_err(hsw->dev, "error: stream commit failed\n"); | 1217 | dev_err(hsw->dev, "error: stream commit failed\n"); |
1345 | return ret; | 1218 | return ret; |
@@ -1388,7 +1261,8 @@ int sst_hsw_mixer_get_info(struct sst_hsw *hsw) | |||
1388 | 1261 | ||
1389 | trace_ipc_request("get global mixer info", 0); | 1262 | trace_ipc_request("get global mixer info", 0); |
1390 | 1263 | ||
1391 | ret = ipc_tx_message_wait(hsw, header, NULL, 0, reply, sizeof(*reply)); | 1264 | ret = sst_ipc_tx_message_wait(&hsw->ipc, header, NULL, 0, |
1265 | reply, sizeof(*reply)); | ||
1392 | if (ret < 0) { | 1266 | if (ret < 0) { |
1393 | dev_err(hsw->dev, "error: get stream info failed\n"); | 1267 | dev_err(hsw->dev, "error: get stream info failed\n"); |
1394 | return ret; | 1268 | return ret; |
@@ -1409,9 +1283,10 @@ static int sst_hsw_stream_operations(struct sst_hsw *hsw, int type, | |||
1409 | header |= (stream_id << IPC_STR_ID_SHIFT); | 1283 | header |= (stream_id << IPC_STR_ID_SHIFT); |
1410 | 1284 | ||
1411 | if (wait) | 1285 | if (wait) |
1412 | return ipc_tx_message_wait(hsw, header, NULL, 0, NULL, 0); | 1286 | return sst_ipc_tx_message_wait(&hsw->ipc, header, |
1287 | NULL, 0, NULL, 0); | ||
1413 | else | 1288 | else |
1414 | return ipc_tx_message_nowait(hsw, header, NULL, 0); | 1289 | return sst_ipc_tx_message_nowait(&hsw->ipc, header, NULL, 0); |
1415 | } | 1290 | } |
1416 | 1291 | ||
1417 | /* Stream ALSA trigger operations */ | 1292 | /* Stream ALSA trigger operations */ |
@@ -1538,8 +1413,8 @@ int sst_hsw_device_set_config(struct sst_hsw *hsw, | |||
1538 | 1413 | ||
1539 | header = IPC_GLB_TYPE(IPC_GLB_SET_DEVICE_FORMATS); | 1414 | header = IPC_GLB_TYPE(IPC_GLB_SET_DEVICE_FORMATS); |
1540 | 1415 | ||
1541 | ret = ipc_tx_message_wait(hsw, header, &config, sizeof(config), | 1416 | ret = sst_ipc_tx_message_wait(&hsw->ipc, header, &config, |
1542 | NULL, 0); | 1417 | sizeof(config), NULL, 0); |
1543 | if (ret < 0) | 1418 | if (ret < 0) |
1544 | dev_err(hsw->dev, "error: set device formats failed\n"); | 1419 | dev_err(hsw->dev, "error: set device formats failed\n"); |
1545 | 1420 | ||
@@ -1559,8 +1434,8 @@ int sst_hsw_dx_set_state(struct sst_hsw *hsw, | |||
1559 | 1434 | ||
1560 | trace_ipc_request("PM enter Dx state", state); | 1435 | trace_ipc_request("PM enter Dx state", state); |
1561 | 1436 | ||
1562 | ret = ipc_tx_message_wait(hsw, header, &state_, sizeof(state_), | 1437 | ret = sst_ipc_tx_message_wait(&hsw->ipc, header, &state_, |
1563 | dx, sizeof(*dx)); | 1438 | sizeof(state_), dx, sizeof(*dx)); |
1564 | if (ret < 0) { | 1439 | if (ret < 0) { |
1565 | dev_err(hsw->dev, "ipc: error set dx state %d failed\n", state); | 1440 | dev_err(hsw->dev, "ipc: error set dx state %d failed\n", state); |
1566 | return ret; | 1441 | return ret; |
@@ -1703,32 +1578,6 @@ static int sst_hsw_dx_state_restore(struct sst_hsw *hsw) | |||
1703 | return 0; | 1578 | return 0; |
1704 | } | 1579 | } |
1705 | 1580 | ||
1706 | static void sst_hsw_drop_all(struct sst_hsw *hsw) | ||
1707 | { | ||
1708 | struct ipc_message *msg, *tmp; | ||
1709 | unsigned long flags; | ||
1710 | int tx_drop_cnt = 0, rx_drop_cnt = 0; | ||
1711 | |||
1712 | /* drop all TX and Rx messages before we stall + reset DSP */ | ||
1713 | spin_lock_irqsave(&hsw->dsp->spinlock, flags); | ||
1714 | |||
1715 | list_for_each_entry_safe(msg, tmp, &hsw->tx_list, list) { | ||
1716 | list_move(&msg->list, &hsw->empty_list); | ||
1717 | tx_drop_cnt++; | ||
1718 | } | ||
1719 | |||
1720 | list_for_each_entry_safe(msg, tmp, &hsw->rx_list, list) { | ||
1721 | list_move(&msg->list, &hsw->empty_list); | ||
1722 | rx_drop_cnt++; | ||
1723 | } | ||
1724 | |||
1725 | spin_unlock_irqrestore(&hsw->dsp->spinlock, flags); | ||
1726 | |||
1727 | if (tx_drop_cnt || rx_drop_cnt) | ||
1728 | dev_err(hsw->dev, "dropped IPC msg RX=%d, TX=%d\n", | ||
1729 | tx_drop_cnt, rx_drop_cnt); | ||
1730 | } | ||
1731 | |||
1732 | int sst_hsw_dsp_load(struct sst_hsw *hsw) | 1581 | int sst_hsw_dsp_load(struct sst_hsw *hsw) |
1733 | { | 1582 | { |
1734 | struct sst_dsp *dsp = hsw->dsp; | 1583 | struct sst_dsp *dsp = hsw->dsp; |
@@ -1808,7 +1657,7 @@ int sst_hsw_dsp_runtime_suspend(struct sst_hsw *hsw) | |||
1808 | if (ret < 0) | 1657 | if (ret < 0) |
1809 | return ret; | 1658 | return ret; |
1810 | 1659 | ||
1811 | sst_hsw_drop_all(hsw); | 1660 | sst_ipc_drop_all(&hsw->ipc); |
1812 | 1661 | ||
1813 | return 0; | 1662 | return 0; |
1814 | } | 1663 | } |
@@ -1844,6 +1693,8 @@ int sst_hsw_dsp_runtime_resume(struct sst_hsw *hsw) | |||
1844 | if (ret < 0) | 1693 | if (ret < 0) |
1845 | dev_err(dev, "error: audio DSP boot failure\n"); | 1694 | dev_err(dev, "error: audio DSP boot failure\n"); |
1846 | 1695 | ||
1696 | sst_hsw_init_module_state(hsw); | ||
1697 | |||
1847 | ret = wait_event_timeout(hsw->boot_wait, hsw->boot_complete, | 1698 | ret = wait_event_timeout(hsw->boot_wait, hsw->boot_complete, |
1848 | msecs_to_jiffies(IPC_BOOT_MSECS)); | 1699 | msecs_to_jiffies(IPC_BOOT_MSECS)); |
1849 | if (ret == 0) { | 1700 | if (ret == 0) { |
@@ -1864,26 +1715,345 @@ int sst_hsw_dsp_runtime_resume(struct sst_hsw *hsw) | |||
1864 | } | 1715 | } |
1865 | #endif | 1716 | #endif |
1866 | 1717 | ||
1867 | static int msg_empty_list_init(struct sst_hsw *hsw) | 1718 | struct sst_dsp *sst_hsw_get_dsp(struct sst_hsw *hsw) |
1868 | { | 1719 | { |
1869 | int i; | 1720 | return hsw->dsp; |
1721 | } | ||
1870 | 1722 | ||
1871 | hsw->msg = kzalloc(sizeof(struct ipc_message) * | 1723 | void sst_hsw_init_module_state(struct sst_hsw *hsw) |
1872 | IPC_EMPTY_LIST_SIZE, GFP_KERNEL); | 1724 | { |
1873 | if (hsw->msg == NULL) | 1725 | struct sst_module *module; |
1874 | return -ENOMEM; | 1726 | enum sst_hsw_module_id id; |
1727 | |||
1728 | /* the base fw contains several modules */ | ||
1729 | for (id = SST_HSW_MODULE_BASE_FW; id < SST_HSW_MAX_MODULE_ID; id++) { | ||
1730 | module = sst_module_get_from_id(hsw->dsp, id); | ||
1731 | if (module) { | ||
1732 | /* module waves is active only after being enabled */ | ||
1733 | if (id == SST_HSW_MODULE_WAVES) | ||
1734 | module->state = SST_MODULE_STATE_INITIALIZED; | ||
1735 | else | ||
1736 | module->state = SST_MODULE_STATE_ACTIVE; | ||
1737 | } | ||
1738 | } | ||
1739 | } | ||
1740 | |||
1741 | bool sst_hsw_is_module_loaded(struct sst_hsw *hsw, u32 module_id) | ||
1742 | { | ||
1743 | struct sst_module *module; | ||
1744 | |||
1745 | module = sst_module_get_from_id(hsw->dsp, module_id); | ||
1746 | if (module == NULL || module->state == SST_MODULE_STATE_UNLOADED) | ||
1747 | return false; | ||
1748 | else | ||
1749 | return true; | ||
1750 | } | ||
1751 | |||
1752 | bool sst_hsw_is_module_active(struct sst_hsw *hsw, u32 module_id) | ||
1753 | { | ||
1754 | struct sst_module *module; | ||
1755 | |||
1756 | module = sst_module_get_from_id(hsw->dsp, module_id); | ||
1757 | if (module != NULL && module->state == SST_MODULE_STATE_ACTIVE) | ||
1758 | return true; | ||
1759 | else | ||
1760 | return false; | ||
1761 | } | ||
1875 | 1762 | ||
1876 | for (i = 0; i < IPC_EMPTY_LIST_SIZE; i++) { | 1763 | void sst_hsw_set_module_enabled_rtd3(struct sst_hsw *hsw, u32 module_id) |
1877 | init_waitqueue_head(&hsw->msg[i].waitq); | 1764 | { |
1878 | list_add(&hsw->msg[i].list, &hsw->empty_list); | 1765 | hsw->enabled_modules_rtd3 |= (1 << module_id); |
1766 | } | ||
1767 | |||
1768 | void sst_hsw_set_module_disabled_rtd3(struct sst_hsw *hsw, u32 module_id) | ||
1769 | { | ||
1770 | hsw->enabled_modules_rtd3 &= ~(1 << module_id); | ||
1771 | } | ||
1772 | |||
1773 | bool sst_hsw_is_module_enabled_rtd3(struct sst_hsw *hsw, u32 module_id) | ||
1774 | { | ||
1775 | return hsw->enabled_modules_rtd3 & (1 << module_id); | ||
1776 | } | ||
1777 | |||
1778 | void sst_hsw_reset_param_buf(struct sst_hsw *hsw) | ||
1779 | { | ||
1780 | hsw->param_idx_w = 0; | ||
1781 | hsw->param_idx_r = 0; | ||
1782 | memset((void *)hsw->param_buf, 0, sizeof(hsw->param_buf)); | ||
1783 | } | ||
1784 | |||
1785 | int sst_hsw_store_param_line(struct sst_hsw *hsw, u8 *buf) | ||
1786 | { | ||
1787 | /* save line to the first available position of param buffer */ | ||
1788 | if (hsw->param_idx_w > WAVES_PARAM_LINES - 1) { | ||
1789 | dev_warn(hsw->dev, "warning: param buffer overflow!\n"); | ||
1790 | return -EPERM; | ||
1791 | } | ||
1792 | memcpy(hsw->param_buf[hsw->param_idx_w], buf, WAVES_PARAM_COUNT); | ||
1793 | hsw->param_idx_w++; | ||
1794 | return 0; | ||
1795 | } | ||
1796 | |||
1797 | int sst_hsw_load_param_line(struct sst_hsw *hsw, u8 *buf) | ||
1798 | { | ||
1799 | u8 id = 0; | ||
1800 | |||
1801 | /* read the first matching line from param buffer */ | ||
1802 | while (hsw->param_idx_r < WAVES_PARAM_LINES) { | ||
1803 | id = hsw->param_buf[hsw->param_idx_r][0]; | ||
1804 | hsw->param_idx_r++; | ||
1805 | if (buf[0] == id) { | ||
1806 | memcpy(buf, hsw->param_buf[hsw->param_idx_r], | ||
1807 | WAVES_PARAM_COUNT); | ||
1808 | break; | ||
1809 | } | ||
1879 | } | 1810 | } |
1811 | if (hsw->param_idx_r > WAVES_PARAM_LINES - 1) { | ||
1812 | dev_dbg(hsw->dev, "end of buffer, roll to the beginning\n"); | ||
1813 | hsw->param_idx_r = 0; | ||
1814 | return 0; | ||
1815 | } | ||
1816 | return 0; | ||
1817 | } | ||
1818 | |||
1819 | int sst_hsw_launch_param_buf(struct sst_hsw *hsw) | ||
1820 | { | ||
1821 | int ret, idx; | ||
1880 | 1822 | ||
1823 | if (!sst_hsw_is_module_active(hsw, SST_HSW_MODULE_WAVES)) { | ||
1824 | dev_dbg(hsw->dev, "module waves is not active\n"); | ||
1825 | return 0; | ||
1826 | } | ||
1827 | |||
1828 | /* put all param lines to DSP through ipc */ | ||
1829 | for (idx = 0; idx < hsw->param_idx_w; idx++) { | ||
1830 | ret = sst_hsw_module_set_param(hsw, | ||
1831 | SST_HSW_MODULE_WAVES, 0, hsw->param_buf[idx][0], | ||
1832 | WAVES_PARAM_COUNT, hsw->param_buf[idx]); | ||
1833 | if (ret < 0) | ||
1834 | return ret; | ||
1835 | } | ||
1881 | return 0; | 1836 | return 0; |
1882 | } | 1837 | } |
1883 | 1838 | ||
1884 | struct sst_dsp *sst_hsw_get_dsp(struct sst_hsw *hsw) | 1839 | int sst_hsw_module_load(struct sst_hsw *hsw, |
1840 | u32 module_id, u32 instance_id, char *name) | ||
1885 | { | 1841 | { |
1886 | return hsw->dsp; | 1842 | int ret = 0; |
1843 | const struct firmware *fw = NULL; | ||
1844 | struct sst_fw *hsw_sst_fw; | ||
1845 | struct sst_module *module; | ||
1846 | struct device *dev = hsw->dev; | ||
1847 | struct sst_dsp *dsp = hsw->dsp; | ||
1848 | |||
1849 | dev_dbg(dev, "sst_hsw_module_load id=%d, name='%s'", module_id, name); | ||
1850 | |||
1851 | module = sst_module_get_from_id(dsp, module_id); | ||
1852 | if (module == NULL) { | ||
1853 | /* loading for the first time */ | ||
1854 | if (module_id == SST_HSW_MODULE_BASE_FW) { | ||
1855 | /* for base module: use fw requested in acpi probe */ | ||
1856 | fw = dsp->pdata->fw; | ||
1857 | if (!fw) { | ||
1858 | dev_err(dev, "request Base fw failed\n"); | ||
1859 | return -ENODEV; | ||
1860 | } | ||
1861 | } else { | ||
1862 | /* try and load any other optional modules if they are | ||
1863 | * available. Use dev_info instead of dev_err in case | ||
1864 | * request firmware failed */ | ||
1865 | ret = request_firmware(&fw, name, dev); | ||
1866 | if (ret) { | ||
1867 | dev_info(dev, "fw image %s not available(%d)\n", | ||
1868 | name, ret); | ||
1869 | return ret; | ||
1870 | } | ||
1871 | } | ||
1872 | hsw_sst_fw = sst_fw_new(dsp, fw, hsw); | ||
1873 | if (hsw_sst_fw == NULL) { | ||
1874 | dev_err(dev, "error: failed to load firmware\n"); | ||
1875 | ret = -ENOMEM; | ||
1876 | goto out; | ||
1877 | } | ||
1878 | module = sst_module_get_from_id(dsp, module_id); | ||
1879 | if (module == NULL) { | ||
1880 | dev_err(dev, "error: no module %d in firmware %s\n", | ||
1881 | module_id, name); | ||
1882 | } | ||
1883 | } else | ||
1884 | dev_info(dev, "module %d (%s) already loaded\n", | ||
1885 | module_id, name); | ||
1886 | out: | ||
1887 | /* release fw, but base fw should be released by acpi driver */ | ||
1888 | if (fw && module_id != SST_HSW_MODULE_BASE_FW) | ||
1889 | release_firmware(fw); | ||
1890 | |||
1891 | return ret; | ||
1892 | } | ||
1893 | |||
1894 | int sst_hsw_module_enable(struct sst_hsw *hsw, | ||
1895 | u32 module_id, u32 instance_id) | ||
1896 | { | ||
1897 | int ret; | ||
1898 | u32 header = 0; | ||
1899 | struct sst_hsw_ipc_module_config config; | ||
1900 | struct sst_module *module; | ||
1901 | struct sst_module_runtime *runtime; | ||
1902 | struct device *dev = hsw->dev; | ||
1903 | struct sst_dsp *dsp = hsw->dsp; | ||
1904 | |||
1905 | if (!sst_hsw_is_module_loaded(hsw, module_id)) { | ||
1906 | dev_dbg(dev, "module %d not loaded\n", module_id); | ||
1907 | return 0; | ||
1908 | } | ||
1909 | |||
1910 | if (sst_hsw_is_module_active(hsw, module_id)) { | ||
1911 | dev_info(dev, "module %d already enabled\n", module_id); | ||
1912 | return 0; | ||
1913 | } | ||
1914 | |||
1915 | module = sst_module_get_from_id(dsp, module_id); | ||
1916 | if (module == NULL) { | ||
1917 | dev_err(dev, "module %d not valid\n", module_id); | ||
1918 | return -ENXIO; | ||
1919 | } | ||
1920 | |||
1921 | runtime = sst_module_runtime_get_from_id(module, module_id); | ||
1922 | if (runtime == NULL) { | ||
1923 | dev_err(dev, "runtime %d not valid", module_id); | ||
1924 | return -ENXIO; | ||
1925 | } | ||
1926 | |||
1927 | header = IPC_GLB_TYPE(IPC_GLB_MODULE_OPERATION) | | ||
1928 | IPC_MODULE_OPERATION(IPC_MODULE_ENABLE) | | ||
1929 | IPC_MODULE_ID(module_id); | ||
1930 | dev_dbg(dev, "module enable header: %x\n", header); | ||
1931 | |||
1932 | config.map.module_entries_count = 1; | ||
1933 | config.map.module_entries[0].module_id = module->id; | ||
1934 | config.map.module_entries[0].entry_point = module->entry; | ||
1935 | |||
1936 | config.persistent_mem.offset = | ||
1937 | sst_dsp_get_offset(dsp, | ||
1938 | runtime->persistent_offset, SST_MEM_DRAM); | ||
1939 | config.persistent_mem.size = module->persistent_size; | ||
1940 | |||
1941 | config.scratch_mem.offset = | ||
1942 | sst_dsp_get_offset(dsp, | ||
1943 | dsp->scratch_offset, SST_MEM_DRAM); | ||
1944 | config.scratch_mem.size = module->scratch_size; | ||
1945 | dev_dbg(dev, "mod %d enable p:%d @ %x, s:%d @ %x, ep: %x", | ||
1946 | config.map.module_entries[0].module_id, | ||
1947 | config.persistent_mem.size, | ||
1948 | config.persistent_mem.offset, | ||
1949 | config.scratch_mem.size, config.scratch_mem.offset, | ||
1950 | config.map.module_entries[0].entry_point); | ||
1951 | |||
1952 | ret = sst_ipc_tx_message_wait(&hsw->ipc, header, | ||
1953 | &config, sizeof(config), NULL, 0); | ||
1954 | if (ret < 0) | ||
1955 | dev_err(dev, "ipc: module enable failed - %d\n", ret); | ||
1956 | else | ||
1957 | module->state = SST_MODULE_STATE_ACTIVE; | ||
1958 | |||
1959 | return ret; | ||
1960 | } | ||
1961 | |||
1962 | int sst_hsw_module_disable(struct sst_hsw *hsw, | ||
1963 | u32 module_id, u32 instance_id) | ||
1964 | { | ||
1965 | int ret; | ||
1966 | u32 header; | ||
1967 | struct sst_module *module; | ||
1968 | struct device *dev = hsw->dev; | ||
1969 | struct sst_dsp *dsp = hsw->dsp; | ||
1970 | |||
1971 | if (!sst_hsw_is_module_loaded(hsw, module_id)) { | ||
1972 | dev_dbg(dev, "module %d not loaded\n", module_id); | ||
1973 | return 0; | ||
1974 | } | ||
1975 | |||
1976 | if (!sst_hsw_is_module_active(hsw, module_id)) { | ||
1977 | dev_info(dev, "module %d already disabled\n", module_id); | ||
1978 | return 0; | ||
1979 | } | ||
1980 | |||
1981 | module = sst_module_get_from_id(dsp, module_id); | ||
1982 | if (module == NULL) { | ||
1983 | dev_err(dev, "module %d not valid\n", module_id); | ||
1984 | return -ENXIO; | ||
1985 | } | ||
1986 | |||
1987 | header = IPC_GLB_TYPE(IPC_GLB_MODULE_OPERATION) | | ||
1988 | IPC_MODULE_OPERATION(IPC_MODULE_DISABLE) | | ||
1989 | IPC_MODULE_ID(module_id); | ||
1990 | |||
1991 | ret = sst_ipc_tx_message_wait(&hsw->ipc, header, NULL, 0, NULL, 0); | ||
1992 | if (ret < 0) | ||
1993 | dev_err(dev, "module disable failed - %d\n", ret); | ||
1994 | else | ||
1995 | module->state = SST_MODULE_STATE_INITIALIZED; | ||
1996 | |||
1997 | return ret; | ||
1998 | } | ||
1999 | |||
2000 | int sst_hsw_module_set_param(struct sst_hsw *hsw, | ||
2001 | u32 module_id, u32 instance_id, u32 parameter_id, | ||
2002 | u32 param_size, char *param) | ||
2003 | { | ||
2004 | int ret; | ||
2005 | unsigned char *data = NULL; | ||
2006 | u32 header = 0; | ||
2007 | u32 payload_size = 0, transfer_parameter_size = 0; | ||
2008 | dma_addr_t dma_addr = 0; | ||
2009 | struct sst_hsw_transfer_parameter *parameter; | ||
2010 | struct device *dev = hsw->dev; | ||
2011 | |||
2012 | header = IPC_GLB_TYPE(IPC_GLB_MODULE_OPERATION) | | ||
2013 | IPC_MODULE_OPERATION(IPC_MODULE_SET_PARAMETER) | | ||
2014 | IPC_MODULE_ID(module_id); | ||
2015 | dev_dbg(dev, "sst_hsw_module_set_param header=%x\n", header); | ||
2016 | |||
2017 | payload_size = param_size + | ||
2018 | sizeof(struct sst_hsw_transfer_parameter) - | ||
2019 | sizeof(struct sst_hsw_transfer_list); | ||
2020 | dev_dbg(dev, "parameter size : %d\n", param_size); | ||
2021 | dev_dbg(dev, "payload size : %d\n", payload_size); | ||
2022 | |||
2023 | if (payload_size <= SST_HSW_IPC_MAX_SHORT_PARAMETER_SIZE) { | ||
2024 | /* short parameter, mailbox can contain data */ | ||
2025 | dev_dbg(dev, "transfer parameter size : %d\n", | ||
2026 | transfer_parameter_size); | ||
2027 | |||
2028 | transfer_parameter_size = ALIGN(payload_size, 4); | ||
2029 | dev_dbg(dev, "transfer parameter aligned size : %d\n", | ||
2030 | transfer_parameter_size); | ||
2031 | |||
2032 | parameter = kzalloc(transfer_parameter_size, GFP_KERNEL); | ||
2033 | if (parameter == NULL) | ||
2034 | return -ENOMEM; | ||
2035 | |||
2036 | memcpy(parameter->data, param, param_size); | ||
2037 | } else { | ||
2038 | dev_warn(dev, "transfer parameter size too large!"); | ||
2039 | return 0; | ||
2040 | } | ||
2041 | |||
2042 | parameter->parameter_id = parameter_id; | ||
2043 | parameter->data_size = param_size; | ||
2044 | |||
2045 | ret = sst_ipc_tx_message_wait(&hsw->ipc, header, | ||
2046 | parameter, transfer_parameter_size , NULL, 0); | ||
2047 | if (ret < 0) | ||
2048 | dev_err(dev, "ipc: module set parameter failed - %d\n", ret); | ||
2049 | |||
2050 | kfree(parameter); | ||
2051 | |||
2052 | if (data) | ||
2053 | dma_free_coherent(hsw->dsp->dma_dev, | ||
2054 | param_size, (void *)data, dma_addr); | ||
2055 | |||
2056 | return ret; | ||
1887 | } | 2057 | } |
1888 | 2058 | ||
1889 | static struct sst_dsp_device hsw_dev = { | 2059 | static struct sst_dsp_device hsw_dev = { |
@@ -1891,10 +2061,48 @@ static struct sst_dsp_device hsw_dev = { | |||
1891 | .ops = &haswell_ops, | 2061 | .ops = &haswell_ops, |
1892 | }; | 2062 | }; |
1893 | 2063 | ||
2064 | static void hsw_tx_msg(struct sst_generic_ipc *ipc, struct ipc_message *msg) | ||
2065 | { | ||
2066 | /* send the message */ | ||
2067 | sst_dsp_outbox_write(ipc->dsp, msg->tx_data, msg->tx_size); | ||
2068 | sst_dsp_ipc_msg_tx(ipc->dsp, msg->header); | ||
2069 | } | ||
2070 | |||
2071 | static void hsw_shim_dbg(struct sst_generic_ipc *ipc, const char *text) | ||
2072 | { | ||
2073 | struct sst_dsp *sst = ipc->dsp; | ||
2074 | u32 isr, ipcd, imrx, ipcx; | ||
2075 | |||
2076 | ipcx = sst_dsp_shim_read_unlocked(sst, SST_IPCX); | ||
2077 | isr = sst_dsp_shim_read_unlocked(sst, SST_ISRX); | ||
2078 | ipcd = sst_dsp_shim_read_unlocked(sst, SST_IPCD); | ||
2079 | imrx = sst_dsp_shim_read_unlocked(sst, SST_IMRX); | ||
2080 | |||
2081 | dev_err(ipc->dev, | ||
2082 | "ipc: --%s-- ipcx 0x%8.8x isr 0x%8.8x ipcd 0x%8.8x imrx 0x%8.8x\n", | ||
2083 | text, ipcx, isr, ipcd, imrx); | ||
2084 | } | ||
2085 | |||
2086 | static void hsw_tx_data_copy(struct ipc_message *msg, char *tx_data, | ||
2087 | size_t tx_size) | ||
2088 | { | ||
2089 | memcpy(msg->tx_data, tx_data, tx_size); | ||
2090 | } | ||
2091 | |||
2092 | static u64 hsw_reply_msg_match(u64 header, u64 *mask) | ||
2093 | { | ||
2094 | /* clear reply bits & status bits */ | ||
2095 | header &= ~(IPC_STATUS_MASK | IPC_GLB_REPLY_MASK); | ||
2096 | *mask = (u64)-1; | ||
2097 | |||
2098 | return header; | ||
2099 | } | ||
2100 | |||
1894 | int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata) | 2101 | int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata) |
1895 | { | 2102 | { |
1896 | struct sst_hsw_ipc_fw_version version; | 2103 | struct sst_hsw_ipc_fw_version version; |
1897 | struct sst_hsw *hsw; | 2104 | struct sst_hsw *hsw; |
2105 | struct sst_generic_ipc *ipc; | ||
1898 | int ret; | 2106 | int ret; |
1899 | 2107 | ||
1900 | dev_dbg(dev, "initialising Audio DSP IPC\n"); | 2108 | dev_dbg(dev, "initialising Audio DSP IPC\n"); |
@@ -1903,39 +2111,30 @@ int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata) | |||
1903 | if (hsw == NULL) | 2111 | if (hsw == NULL) |
1904 | return -ENOMEM; | 2112 | return -ENOMEM; |
1905 | 2113 | ||
1906 | hsw->dev = dev; | 2114 | ipc = &hsw->ipc; |
1907 | INIT_LIST_HEAD(&hsw->stream_list); | 2115 | ipc->dev = dev; |
1908 | INIT_LIST_HEAD(&hsw->tx_list); | 2116 | ipc->ops.tx_msg = hsw_tx_msg; |
1909 | INIT_LIST_HEAD(&hsw->rx_list); | 2117 | ipc->ops.shim_dbg = hsw_shim_dbg; |
1910 | INIT_LIST_HEAD(&hsw->empty_list); | 2118 | ipc->ops.tx_data_copy = hsw_tx_data_copy; |
1911 | init_waitqueue_head(&hsw->boot_wait); | 2119 | ipc->ops.reply_msg_match = hsw_reply_msg_match; |
1912 | init_waitqueue_head(&hsw->wait_txq); | ||
1913 | |||
1914 | ret = msg_empty_list_init(hsw); | ||
1915 | if (ret < 0) | ||
1916 | return -ENOMEM; | ||
1917 | 2120 | ||
1918 | /* start the IPC message thread */ | 2121 | ret = sst_ipc_init(ipc); |
1919 | init_kthread_worker(&hsw->kworker); | 2122 | if (ret != 0) |
1920 | hsw->tx_thread = kthread_run(kthread_worker_fn, | 2123 | goto ipc_init_err; |
1921 | &hsw->kworker, "%s", | ||
1922 | dev_name(hsw->dev)); | ||
1923 | if (IS_ERR(hsw->tx_thread)) { | ||
1924 | ret = PTR_ERR(hsw->tx_thread); | ||
1925 | dev_err(hsw->dev, "error: failed to create message TX task\n"); | ||
1926 | goto err_free_msg; | ||
1927 | } | ||
1928 | init_kthread_work(&hsw->kwork, ipc_tx_msgs); | ||
1929 | 2124 | ||
2125 | INIT_LIST_HEAD(&hsw->stream_list); | ||
2126 | init_waitqueue_head(&hsw->boot_wait); | ||
1930 | hsw_dev.thread_context = hsw; | 2127 | hsw_dev.thread_context = hsw; |
1931 | 2128 | ||
1932 | /* init SST shim */ | 2129 | /* init SST shim */ |
1933 | hsw->dsp = sst_dsp_new(dev, &hsw_dev, pdata); | 2130 | hsw->dsp = sst_dsp_new(dev, &hsw_dev, pdata); |
1934 | if (hsw->dsp == NULL) { | 2131 | if (hsw->dsp == NULL) { |
1935 | ret = -ENODEV; | 2132 | ret = -ENODEV; |
1936 | goto dsp_err; | 2133 | goto dsp_new_err; |
1937 | } | 2134 | } |
1938 | 2135 | ||
2136 | ipc->dsp = hsw->dsp; | ||
2137 | |||
1939 | /* allocate DMA buffer for context storage */ | 2138 | /* allocate DMA buffer for context storage */ |
1940 | hsw->dx_context = dma_alloc_coherent(hsw->dsp->dma_dev, | 2139 | hsw->dx_context = dma_alloc_coherent(hsw->dsp->dma_dev, |
1941 | SST_HSW_DX_CONTEXT_SIZE, &hsw->dx_context_paddr, GFP_KERNEL); | 2140 | SST_HSW_DX_CONTEXT_SIZE, &hsw->dx_context_paddr, GFP_KERNEL); |
@@ -1947,18 +2146,22 @@ int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata) | |||
1947 | /* keep the DSP in reset state for base FW loading */ | 2146 | /* keep the DSP in reset state for base FW loading */ |
1948 | sst_dsp_reset(hsw->dsp); | 2147 | sst_dsp_reset(hsw->dsp); |
1949 | 2148 | ||
1950 | hsw->sst_fw = sst_fw_new(hsw->dsp, pdata->fw, hsw); | 2149 | /* load base module and other modules in base firmware image */ |
1951 | if (hsw->sst_fw == NULL) { | 2150 | ret = sst_hsw_module_load(hsw, SST_HSW_MODULE_BASE_FW, 0, "Base"); |
1952 | ret = -ENODEV; | 2151 | if (ret < 0) |
1953 | dev_err(dev, "error: failed to load firmware\n"); | ||
1954 | goto fw_err; | 2152 | goto fw_err; |
1955 | } | 2153 | |
2154 | /* try to load module waves */ | ||
2155 | sst_hsw_module_load(hsw, SST_HSW_MODULE_WAVES, 0, "intel/IntcPP01.bin"); | ||
1956 | 2156 | ||
1957 | /* allocate scratch mem regions */ | 2157 | /* allocate scratch mem regions */ |
1958 | ret = sst_block_alloc_scratch(hsw->dsp); | 2158 | ret = sst_block_alloc_scratch(hsw->dsp); |
1959 | if (ret < 0) | 2159 | if (ret < 0) |
1960 | goto boot_err; | 2160 | goto boot_err; |
1961 | 2161 | ||
2162 | /* init param buffer */ | ||
2163 | sst_hsw_reset_param_buf(hsw); | ||
2164 | |||
1962 | /* wait for DSP boot completion */ | 2165 | /* wait for DSP boot completion */ |
1963 | sst_dsp_boot(hsw->dsp); | 2166 | sst_dsp_boot(hsw->dsp); |
1964 | ret = wait_event_timeout(hsw->boot_wait, hsw->boot_complete, | 2167 | ret = wait_event_timeout(hsw->boot_wait, hsw->boot_complete, |
@@ -1971,6 +2174,9 @@ int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata) | |||
1971 | goto boot_err; | 2174 | goto boot_err; |
1972 | } | 2175 | } |
1973 | 2176 | ||
2177 | /* init module state after boot */ | ||
2178 | sst_hsw_init_module_state(hsw); | ||
2179 | |||
1974 | /* get the FW version */ | 2180 | /* get the FW version */ |
1975 | sst_hsw_fw_get_version(hsw, &version); | 2181 | sst_hsw_fw_get_version(hsw, &version); |
1976 | 2182 | ||
@@ -1986,17 +2192,16 @@ int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata) | |||
1986 | 2192 | ||
1987 | boot_err: | 2193 | boot_err: |
1988 | sst_dsp_reset(hsw->dsp); | 2194 | sst_dsp_reset(hsw->dsp); |
1989 | sst_fw_free(hsw->sst_fw); | 2195 | sst_fw_free_all(hsw->dsp); |
1990 | fw_err: | 2196 | fw_err: |
1991 | dma_free_coherent(hsw->dsp->dma_dev, SST_HSW_DX_CONTEXT_SIZE, | 2197 | dma_free_coherent(hsw->dsp->dma_dev, SST_HSW_DX_CONTEXT_SIZE, |
1992 | hsw->dx_context, hsw->dx_context_paddr); | 2198 | hsw->dx_context, hsw->dx_context_paddr); |
1993 | dma_err: | 2199 | dma_err: |
1994 | sst_dsp_free(hsw->dsp); | 2200 | sst_dsp_free(hsw->dsp); |
1995 | dsp_err: | 2201 | dsp_new_err: |
1996 | kthread_stop(hsw->tx_thread); | 2202 | sst_ipc_fini(ipc); |
1997 | err_free_msg: | 2203 | ipc_init_err: |
1998 | kfree(hsw->msg); | 2204 | kfree(hsw); |
1999 | |||
2000 | return ret; | 2205 | return ret; |
2001 | } | 2206 | } |
2002 | EXPORT_SYMBOL_GPL(sst_hsw_dsp_init); | 2207 | EXPORT_SYMBOL_GPL(sst_hsw_dsp_init); |
@@ -2010,7 +2215,6 @@ void sst_hsw_dsp_free(struct device *dev, struct sst_pdata *pdata) | |||
2010 | dma_free_coherent(hsw->dsp->dma_dev, SST_HSW_DX_CONTEXT_SIZE, | 2215 | dma_free_coherent(hsw->dsp->dma_dev, SST_HSW_DX_CONTEXT_SIZE, |
2011 | hsw->dx_context, hsw->dx_context_paddr); | 2216 | hsw->dx_context, hsw->dx_context_paddr); |
2012 | sst_dsp_free(hsw->dsp); | 2217 | sst_dsp_free(hsw->dsp); |
2013 | kthread_stop(hsw->tx_thread); | 2218 | sst_ipc_fini(&hsw->ipc); |
2014 | kfree(hsw->msg); | ||
2015 | } | 2219 | } |
2016 | EXPORT_SYMBOL_GPL(sst_hsw_dsp_free); | 2220 | EXPORT_SYMBOL_GPL(sst_hsw_dsp_free); |
diff --git a/sound/soc/intel/sst-haswell-ipc.h b/sound/soc/intel/haswell/sst-haswell-ipc.h index 858096041cb1..06d71aefa1fe 100644 --- a/sound/soc/intel/sst-haswell-ipc.h +++ b/sound/soc/intel/haswell/sst-haswell-ipc.h | |||
@@ -37,6 +37,9 @@ | |||
37 | #define SST_HSW_IPC_MAX_PAYLOAD_SIZE 400 | 37 | #define SST_HSW_IPC_MAX_PAYLOAD_SIZE 400 |
38 | #define SST_HSW_MAX_INFO_SIZE 64 | 38 | #define SST_HSW_MAX_INFO_SIZE 64 |
39 | #define SST_HSW_BUILD_HASH_LENGTH 40 | 39 | #define SST_HSW_BUILD_HASH_LENGTH 40 |
40 | #define SST_HSW_IPC_MAX_SHORT_PARAMETER_SIZE 500 | ||
41 | #define WAVES_PARAM_COUNT 128 | ||
42 | #define WAVES_PARAM_LINES 160 | ||
40 | 43 | ||
41 | struct sst_hsw; | 44 | struct sst_hsw; |
42 | struct sst_hsw_stream; | 45 | struct sst_hsw_stream; |
@@ -187,6 +190,28 @@ enum sst_hsw_performance_action { | |||
187 | SST_HSW_PERF_STOP = 1, | 190 | SST_HSW_PERF_STOP = 1, |
188 | }; | 191 | }; |
189 | 192 | ||
193 | struct sst_hsw_transfer_info { | ||
194 | uint32_t destination; /* destination address */ | ||
195 | uint32_t reverse:1; /* if 1 data flows from destination */ | ||
196 | uint32_t size:31; /* transfer size in bytes.*/ | ||
197 | uint16_t first_page_offset; /* offset to data in the first page. */ | ||
198 | uint8_t packed_pages; /* page addresses. Each occupies 20 bits */ | ||
199 | } __attribute__((packed)); | ||
200 | |||
201 | struct sst_hsw_transfer_list { | ||
202 | uint32_t transfers_count; | ||
203 | struct sst_hsw_transfer_info transfers; | ||
204 | } __attribute__((packed)); | ||
205 | |||
206 | struct sst_hsw_transfer_parameter { | ||
207 | uint32_t parameter_id; | ||
208 | uint32_t data_size; | ||
209 | union { | ||
210 | uint8_t data[1]; | ||
211 | struct sst_hsw_transfer_list transfer_list; | ||
212 | }; | ||
213 | } __attribute__((packed)); | ||
214 | |||
190 | /* SST firmware module info */ | 215 | /* SST firmware module info */ |
191 | struct sst_hsw_module_info { | 216 | struct sst_hsw_module_info { |
192 | u8 name[SST_HSW_MAX_INFO_SIZE]; | 217 | u8 name[SST_HSW_MAX_INFO_SIZE]; |
@@ -215,6 +240,12 @@ struct sst_hsw_fx_enable { | |||
215 | struct sst_hsw_memory_info persistent_mem; | 240 | struct sst_hsw_memory_info persistent_mem; |
216 | } __attribute__((packed)); | 241 | } __attribute__((packed)); |
217 | 242 | ||
243 | struct sst_hsw_ipc_module_config { | ||
244 | struct sst_hsw_module_map map; | ||
245 | struct sst_hsw_memory_info persistent_mem; | ||
246 | struct sst_hsw_memory_info scratch_mem; | ||
247 | } __attribute__((packed)); | ||
248 | |||
218 | struct sst_hsw_get_fx_param { | 249 | struct sst_hsw_get_fx_param { |
219 | u32 parameter_id; | 250 | u32 parameter_id; |
220 | u32 param_size; | 251 | u32 param_size; |
@@ -467,6 +498,28 @@ int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata); | |||
467 | void sst_hsw_dsp_free(struct device *dev, struct sst_pdata *pdata); | 498 | void sst_hsw_dsp_free(struct device *dev, struct sst_pdata *pdata); |
468 | struct sst_dsp *sst_hsw_get_dsp(struct sst_hsw *hsw); | 499 | struct sst_dsp *sst_hsw_get_dsp(struct sst_hsw *hsw); |
469 | 500 | ||
501 | /* fw module function */ | ||
502 | void sst_hsw_init_module_state(struct sst_hsw *hsw); | ||
503 | bool sst_hsw_is_module_loaded(struct sst_hsw *hsw, u32 module_id); | ||
504 | bool sst_hsw_is_module_active(struct sst_hsw *hsw, u32 module_id); | ||
505 | void sst_hsw_set_module_enabled_rtd3(struct sst_hsw *hsw, u32 module_id); | ||
506 | void sst_hsw_set_module_disabled_rtd3(struct sst_hsw *hsw, u32 module_id); | ||
507 | bool sst_hsw_is_module_enabled_rtd3(struct sst_hsw *hsw, u32 module_id); | ||
508 | void sst_hsw_reset_param_buf(struct sst_hsw *hsw); | ||
509 | int sst_hsw_store_param_line(struct sst_hsw *hsw, u8 *buf); | ||
510 | int sst_hsw_load_param_line(struct sst_hsw *hsw, u8 *buf); | ||
511 | int sst_hsw_launch_param_buf(struct sst_hsw *hsw); | ||
512 | |||
513 | int sst_hsw_module_load(struct sst_hsw *hsw, | ||
514 | u32 module_id, u32 instance_id, char *name); | ||
515 | int sst_hsw_module_enable(struct sst_hsw *hsw, | ||
516 | u32 module_id, u32 instance_id); | ||
517 | int sst_hsw_module_disable(struct sst_hsw *hsw, | ||
518 | u32 module_id, u32 instance_id); | ||
519 | int sst_hsw_module_set_param(struct sst_hsw *hsw, | ||
520 | u32 module_id, u32 instance_id, u32 parameter_id, | ||
521 | u32 param_size, char *param); | ||
522 | |||
470 | /* runtime module management */ | 523 | /* runtime module management */ |
471 | struct sst_module_runtime *sst_hsw_runtime_module_create(struct sst_hsw *hsw, | 524 | struct sst_module_runtime *sst_hsw_runtime_module_create(struct sst_hsw *hsw, |
472 | int mod_id, int offset); | 525 | int mod_id, int offset); |
diff --git a/sound/soc/intel/sst-haswell-pcm.c b/sound/soc/intel/haswell/sst-haswell-pcm.c index 7e21e8f85885..23ae0400d6db 100644 --- a/sound/soc/intel/sst-haswell-pcm.c +++ b/sound/soc/intel/haswell/sst-haswell-pcm.c | |||
@@ -29,9 +29,9 @@ | |||
29 | #include <sound/tlv.h> | 29 | #include <sound/tlv.h> |
30 | #include <sound/compress_driver.h> | 30 | #include <sound/compress_driver.h> |
31 | 31 | ||
32 | #include "sst-haswell-ipc.h" | 32 | #include "../haswell/sst-haswell-ipc.h" |
33 | #include "sst-dsp-priv.h" | 33 | #include "../common/sst-dsp-priv.h" |
34 | #include "sst-dsp.h" | 34 | #include "../common/sst-dsp.h" |
35 | 35 | ||
36 | #define HSW_PCM_COUNT 6 | 36 | #define HSW_PCM_COUNT 6 |
37 | #define HSW_VOLUME_MAX 0x7FFFFFFF /* 0dB */ | 37 | #define HSW_VOLUME_MAX 0x7FFFFFFF /* 0dB */ |
@@ -137,6 +137,7 @@ struct hsw_priv_data { | |||
137 | struct device *dev; | 137 | struct device *dev; |
138 | enum hsw_pm_state pm_state; | 138 | enum hsw_pm_state pm_state; |
139 | struct snd_soc_card *soc_card; | 139 | struct snd_soc_card *soc_card; |
140 | struct sst_module_runtime *runtime_waves; /* sound effect module */ | ||
140 | 141 | ||
141 | /* page tables */ | 142 | /* page tables */ |
142 | struct snd_dma_buffer dmab[HSW_PCM_COUNT][2]; | 143 | struct snd_dma_buffer dmab[HSW_PCM_COUNT][2]; |
@@ -318,6 +319,93 @@ static int hsw_volume_get(struct snd_kcontrol *kcontrol, | |||
318 | return 0; | 319 | return 0; |
319 | } | 320 | } |
320 | 321 | ||
322 | static int hsw_waves_switch_get(struct snd_kcontrol *kcontrol, | ||
323 | struct snd_ctl_elem_value *ucontrol) | ||
324 | { | ||
325 | struct snd_soc_platform *platform = snd_soc_kcontrol_platform(kcontrol); | ||
326 | struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform); | ||
327 | struct sst_hsw *hsw = pdata->hsw; | ||
328 | enum sst_hsw_module_id id = SST_HSW_MODULE_WAVES; | ||
329 | |||
330 | ucontrol->value.integer.value[0] = | ||
331 | (sst_hsw_is_module_active(hsw, id) || | ||
332 | sst_hsw_is_module_enabled_rtd3(hsw, id)); | ||
333 | return 0; | ||
334 | } | ||
335 | |||
336 | static int hsw_waves_switch_put(struct snd_kcontrol *kcontrol, | ||
337 | struct snd_ctl_elem_value *ucontrol) | ||
338 | { | ||
339 | struct snd_soc_platform *platform = snd_soc_kcontrol_platform(kcontrol); | ||
340 | struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform); | ||
341 | struct sst_hsw *hsw = pdata->hsw; | ||
342 | int ret = 0; | ||
343 | enum sst_hsw_module_id id = SST_HSW_MODULE_WAVES; | ||
344 | bool switch_on = (bool)ucontrol->value.integer.value[0]; | ||
345 | |||
346 | /* if module is in RAM on the DSP, apply user settings to module through | ||
347 | * ipc. If module is not in RAM on the DSP, store user setting for | ||
348 | * track */ | ||
349 | if (sst_hsw_is_module_loaded(hsw, id)) { | ||
350 | if (switch_on == sst_hsw_is_module_active(hsw, id)) | ||
351 | return 0; | ||
352 | |||
353 | if (switch_on) | ||
354 | ret = sst_hsw_module_enable(hsw, id, 0); | ||
355 | else | ||
356 | ret = sst_hsw_module_disable(hsw, id, 0); | ||
357 | } else { | ||
358 | if (switch_on == sst_hsw_is_module_enabled_rtd3(hsw, id)) | ||
359 | return 0; | ||
360 | |||
361 | if (switch_on) | ||
362 | sst_hsw_set_module_enabled_rtd3(hsw, id); | ||
363 | else | ||
364 | sst_hsw_set_module_disabled_rtd3(hsw, id); | ||
365 | } | ||
366 | |||
367 | return ret; | ||
368 | } | ||
369 | |||
370 | static int hsw_waves_param_get(struct snd_kcontrol *kcontrol, | ||
371 | struct snd_ctl_elem_value *ucontrol) | ||
372 | { | ||
373 | struct snd_soc_platform *platform = snd_soc_kcontrol_platform(kcontrol); | ||
374 | struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform); | ||
375 | struct sst_hsw *hsw = pdata->hsw; | ||
376 | |||
377 | /* return a matching line from param buffer */ | ||
378 | return sst_hsw_load_param_line(hsw, ucontrol->value.bytes.data); | ||
379 | } | ||
380 | |||
381 | static int hsw_waves_param_put(struct snd_kcontrol *kcontrol, | ||
382 | struct snd_ctl_elem_value *ucontrol) | ||
383 | { | ||
384 | struct snd_soc_platform *platform = snd_soc_kcontrol_platform(kcontrol); | ||
385 | struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform); | ||
386 | struct sst_hsw *hsw = pdata->hsw; | ||
387 | int ret; | ||
388 | enum sst_hsw_module_id id = SST_HSW_MODULE_WAVES; | ||
389 | int param_id = ucontrol->value.bytes.data[0]; | ||
390 | int param_size = WAVES_PARAM_COUNT; | ||
391 | |||
392 | /* clear param buffer and reset buffer index */ | ||
393 | if (param_id == 0xFF) { | ||
394 | sst_hsw_reset_param_buf(hsw); | ||
395 | return 0; | ||
396 | } | ||
397 | |||
398 | /* store params into buffer */ | ||
399 | ret = sst_hsw_store_param_line(hsw, ucontrol->value.bytes.data); | ||
400 | if (ret < 0) | ||
401 | return ret; | ||
402 | |||
403 | if (sst_hsw_is_module_active(hsw, id)) | ||
404 | ret = sst_hsw_module_set_param(hsw, id, 0, param_id, | ||
405 | param_size, ucontrol->value.bytes.data); | ||
406 | return ret; | ||
407 | } | ||
408 | |||
321 | /* TLV used by both global and stream volumes */ | 409 | /* TLV used by both global and stream volumes */ |
322 | static const DECLARE_TLV_DB_SCALE(hsw_vol_tlv, -9000, 300, 1); | 410 | static const DECLARE_TLV_DB_SCALE(hsw_vol_tlv, -9000, 300, 1); |
323 | 411 | ||
@@ -339,6 +427,12 @@ static const struct snd_kcontrol_new hsw_volume_controls[] = { | |||
339 | SOC_DOUBLE_EXT_TLV("Mic Capture Volume", 4, 0, 8, | 427 | SOC_DOUBLE_EXT_TLV("Mic Capture Volume", 4, 0, 8, |
340 | ARRAY_SIZE(volume_map) - 1, 0, | 428 | ARRAY_SIZE(volume_map) - 1, 0, |
341 | hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv), | 429 | hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv), |
430 | /* enable/disable module waves */ | ||
431 | SOC_SINGLE_BOOL_EXT("Waves Switch", 0, | ||
432 | hsw_waves_switch_get, hsw_waves_switch_put), | ||
433 | /* set parameters to module waves */ | ||
434 | SND_SOC_BYTES_EXT("Waves Set Param", WAVES_PARAM_COUNT, | ||
435 | hsw_waves_param_get, hsw_waves_param_put), | ||
342 | }; | 436 | }; |
343 | 437 | ||
344 | /* Create DMA buffer page table for DSP */ | 438 | /* Create DMA buffer page table for DSP */ |
@@ -807,6 +901,14 @@ static int hsw_pcm_create_modules(struct hsw_priv_data *pdata) | |||
807 | pcm_data->runtime->persistent_offset; | 901 | pcm_data->runtime->persistent_offset; |
808 | } | 902 | } |
809 | 903 | ||
904 | /* create runtime blocks for module waves */ | ||
905 | if (sst_hsw_is_module_loaded(hsw, SST_HSW_MODULE_WAVES)) { | ||
906 | pdata->runtime_waves = sst_hsw_runtime_module_create(hsw, | ||
907 | SST_HSW_MODULE_WAVES, 0); | ||
908 | if (pdata->runtime_waves == NULL) | ||
909 | goto err; | ||
910 | } | ||
911 | |||
810 | return 0; | 912 | return 0; |
811 | 913 | ||
812 | err: | 914 | err: |
@@ -820,14 +922,17 @@ err: | |||
820 | 922 | ||
821 | static void hsw_pcm_free_modules(struct hsw_priv_data *pdata) | 923 | static void hsw_pcm_free_modules(struct hsw_priv_data *pdata) |
822 | { | 924 | { |
925 | struct sst_hsw *hsw = pdata->hsw; | ||
823 | struct hsw_pcm_data *pcm_data; | 926 | struct hsw_pcm_data *pcm_data; |
824 | int i; | 927 | int i; |
825 | 928 | ||
826 | for (i = 0; i < ARRAY_SIZE(mod_map); i++) { | 929 | for (i = 0; i < ARRAY_SIZE(mod_map); i++) { |
827 | pcm_data = &pdata->pcm[mod_map[i].dai_id][mod_map[i].stream]; | 930 | pcm_data = &pdata->pcm[mod_map[i].dai_id][mod_map[i].stream]; |
828 | |||
829 | sst_hsw_runtime_module_free(pcm_data->runtime); | 931 | sst_hsw_runtime_module_free(pcm_data->runtime); |
830 | } | 932 | } |
933 | if (sst_hsw_is_module_loaded(hsw, SST_HSW_MODULE_WAVES)) { | ||
934 | sst_hsw_runtime_module_free(pdata->runtime_waves); | ||
935 | } | ||
831 | } | 936 | } |
832 | 937 | ||
833 | static int hsw_pcm_new(struct snd_soc_pcm_runtime *rtd) | 938 | static int hsw_pcm_new(struct snd_soc_pcm_runtime *rtd) |
@@ -984,7 +1089,9 @@ static int hsw_pcm_probe(struct snd_soc_platform *platform) | |||
984 | } | 1089 | } |
985 | 1090 | ||
986 | /* allocate runtime modules */ | 1091 | /* allocate runtime modules */ |
987 | hsw_pcm_create_modules(priv_data); | 1092 | ret = hsw_pcm_create_modules(priv_data); |
1093 | if (ret < 0) | ||
1094 | goto err; | ||
988 | 1095 | ||
989 | /* enable runtime PM with auto suspend */ | 1096 | /* enable runtime PM with auto suspend */ |
990 | pm_runtime_set_autosuspend_delay(platform->dev, | 1097 | pm_runtime_set_autosuspend_delay(platform->dev, |
@@ -996,7 +1103,7 @@ static int hsw_pcm_probe(struct snd_soc_platform *platform) | |||
996 | return 0; | 1103 | return 0; |
997 | 1104 | ||
998 | err: | 1105 | err: |
999 | for (;i >= 0; i--) { | 1106 | for (--i; i >= 0; i--) { |
1000 | if (hsw_dais[i].playback.channels_min) | 1107 | if (hsw_dais[i].playback.channels_min) |
1001 | snd_dma_free_pages(&priv_data->dmab[i][0]); | 1108 | snd_dma_free_pages(&priv_data->dmab[i][0]); |
1002 | if (hsw_dais[i].capture.channels_min) | 1109 | if (hsw_dais[i].capture.channels_min) |
@@ -1101,10 +1208,18 @@ static int hsw_pcm_runtime_suspend(struct device *dev) | |||
1101 | { | 1208 | { |
1102 | struct hsw_priv_data *pdata = dev_get_drvdata(dev); | 1209 | struct hsw_priv_data *pdata = dev_get_drvdata(dev); |
1103 | struct sst_hsw *hsw = pdata->hsw; | 1210 | struct sst_hsw *hsw = pdata->hsw; |
1211 | int ret; | ||
1104 | 1212 | ||
1105 | if (pdata->pm_state >= HSW_PM_STATE_RTD3) | 1213 | if (pdata->pm_state >= HSW_PM_STATE_RTD3) |
1106 | return 0; | 1214 | return 0; |
1107 | 1215 | ||
1216 | /* fw modules will be unloaded on RTD3, set flag to track */ | ||
1217 | if (sst_hsw_is_module_active(hsw, SST_HSW_MODULE_WAVES)) { | ||
1218 | ret = sst_hsw_module_disable(hsw, SST_HSW_MODULE_WAVES, 0); | ||
1219 | if (ret < 0) | ||
1220 | return ret; | ||
1221 | sst_hsw_set_module_enabled_rtd3(hsw, SST_HSW_MODULE_WAVES); | ||
1222 | } | ||
1108 | sst_hsw_dsp_runtime_suspend(hsw); | 1223 | sst_hsw_dsp_runtime_suspend(hsw); |
1109 | sst_hsw_dsp_runtime_sleep(hsw); | 1224 | sst_hsw_dsp_runtime_sleep(hsw); |
1110 | pdata->pm_state = HSW_PM_STATE_RTD3; | 1225 | pdata->pm_state = HSW_PM_STATE_RTD3; |
@@ -1139,6 +1254,19 @@ static int hsw_pcm_runtime_resume(struct device *dev) | |||
1139 | else if (ret == 1) /* no action required */ | 1254 | else if (ret == 1) /* no action required */ |
1140 | return 0; | 1255 | return 0; |
1141 | 1256 | ||
1257 | /* check flag when resume */ | ||
1258 | if (sst_hsw_is_module_enabled_rtd3(hsw, SST_HSW_MODULE_WAVES)) { | ||
1259 | ret = sst_hsw_module_enable(hsw, SST_HSW_MODULE_WAVES, 0); | ||
1260 | if (ret < 0) | ||
1261 | return ret; | ||
1262 | /* put parameters from buffer to dsp */ | ||
1263 | ret = sst_hsw_launch_param_buf(hsw); | ||
1264 | if (ret < 0) | ||
1265 | return ret; | ||
1266 | /* unset flag */ | ||
1267 | sst_hsw_set_module_disabled_rtd3(hsw, SST_HSW_MODULE_WAVES); | ||
1268 | } | ||
1269 | |||
1142 | pdata->pm_state = HSW_PM_STATE_D0; | 1270 | pdata->pm_state = HSW_PM_STATE_D0; |
1143 | return ret; | 1271 | return ret; |
1144 | } | 1272 | } |
diff --git a/sound/soc/jz4740/jz4740-i2s.c b/sound/soc/jz4740/jz4740-i2s.c index 07f77815a586..b05fb1c1a848 100644 --- a/sound/soc/jz4740/jz4740-i2s.c +++ b/sound/soc/jz4740/jz4740-i2s.c | |||
@@ -58,6 +58,12 @@ | |||
58 | 58 | ||
59 | #define JZ_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET 12 | 59 | #define JZ_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET 12 |
60 | #define JZ_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET 8 | 60 | #define JZ_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET 8 |
61 | #define JZ4780_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET 24 | ||
62 | #define JZ4780_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET 16 | ||
63 | #define JZ4780_AIC_CONF_FIFO_RX_THRESHOLD_MASK \ | ||
64 | (0xf << JZ4780_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET) | ||
65 | #define JZ4780_AIC_CONF_FIFO_TX_THRESHOLD_MASK \ | ||
66 | (0x1f << JZ4780_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET) | ||
61 | 67 | ||
62 | #define JZ_AIC_CTRL_OUTPUT_SAMPLE_SIZE_MASK (0x7 << 19) | 68 | #define JZ_AIC_CTRL_OUTPUT_SAMPLE_SIZE_MASK (0x7 << 19) |
63 | #define JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_MASK (0x7 << 16) | 69 | #define JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_MASK (0x7 << 16) |
@@ -79,6 +85,7 @@ | |||
79 | #define JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_OFFSET 16 | 85 | #define JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_OFFSET 16 |
80 | 86 | ||
81 | #define JZ_AIC_I2S_FMT_DISABLE_BIT_CLK BIT(12) | 87 | #define JZ_AIC_I2S_FMT_DISABLE_BIT_CLK BIT(12) |
88 | #define JZ_AIC_I2S_FMT_DISABLE_BIT_ICLK BIT(13) | ||
82 | #define JZ_AIC_I2S_FMT_ENABLE_SYS_CLK BIT(4) | 89 | #define JZ_AIC_I2S_FMT_ENABLE_SYS_CLK BIT(4) |
83 | #define JZ_AIC_I2S_FMT_MSB BIT(0) | 90 | #define JZ_AIC_I2S_FMT_MSB BIT(0) |
84 | 91 | ||
@@ -87,6 +94,13 @@ | |||
87 | #define JZ_AIC_CLK_DIV_MASK 0xf | 94 | #define JZ_AIC_CLK_DIV_MASK 0xf |
88 | #define I2SDIV_DV_SHIFT 8 | 95 | #define I2SDIV_DV_SHIFT 8 |
89 | #define I2SDIV_DV_MASK (0xf << I2SDIV_DV_SHIFT) | 96 | #define I2SDIV_DV_MASK (0xf << I2SDIV_DV_SHIFT) |
97 | #define I2SDIV_IDV_SHIFT 8 | ||
98 | #define I2SDIV_IDV_MASK (0xf << I2SDIV_IDV_SHIFT) | ||
99 | |||
100 | enum jz47xx_i2s_version { | ||
101 | JZ_I2S_JZ4740, | ||
102 | JZ_I2S_JZ4780, | ||
103 | }; | ||
90 | 104 | ||
91 | struct jz4740_i2s { | 105 | struct jz4740_i2s { |
92 | struct resource *mem; | 106 | struct resource *mem; |
@@ -98,6 +112,8 @@ struct jz4740_i2s { | |||
98 | 112 | ||
99 | struct snd_dmaengine_dai_dma_data playback_dma_data; | 113 | struct snd_dmaengine_dai_dma_data playback_dma_data; |
100 | struct snd_dmaengine_dai_dma_data capture_dma_data; | 114 | struct snd_dmaengine_dai_dma_data capture_dma_data; |
115 | |||
116 | enum jz47xx_i2s_version version; | ||
101 | }; | 117 | }; |
102 | 118 | ||
103 | static inline uint32_t jz4740_i2s_read(const struct jz4740_i2s *i2s, | 119 | static inline uint32_t jz4740_i2s_read(const struct jz4740_i2s *i2s, |
@@ -267,13 +283,22 @@ static int jz4740_i2s_hw_params(struct snd_pcm_substream *substream, | |||
267 | ctrl |= JZ_AIC_CTRL_MONO_TO_STEREO; | 283 | ctrl |= JZ_AIC_CTRL_MONO_TO_STEREO; |
268 | else | 284 | else |
269 | ctrl &= ~JZ_AIC_CTRL_MONO_TO_STEREO; | 285 | ctrl &= ~JZ_AIC_CTRL_MONO_TO_STEREO; |
286 | |||
287 | div_reg &= ~I2SDIV_DV_MASK; | ||
288 | div_reg |= (div - 1) << I2SDIV_DV_SHIFT; | ||
270 | } else { | 289 | } else { |
271 | ctrl &= ~JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_MASK; | 290 | ctrl &= ~JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_MASK; |
272 | ctrl |= sample_size << JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_OFFSET; | 291 | ctrl |= sample_size << JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_OFFSET; |
292 | |||
293 | if (i2s->version >= JZ_I2S_JZ4780) { | ||
294 | div_reg &= ~I2SDIV_IDV_MASK; | ||
295 | div_reg |= (div - 1) << I2SDIV_IDV_SHIFT; | ||
296 | } else { | ||
297 | div_reg &= ~I2SDIV_DV_MASK; | ||
298 | div_reg |= (div - 1) << I2SDIV_DV_SHIFT; | ||
299 | } | ||
273 | } | 300 | } |
274 | 301 | ||
275 | div_reg &= ~I2SDIV_DV_MASK; | ||
276 | div_reg |= (div - 1) << I2SDIV_DV_SHIFT; | ||
277 | jz4740_i2s_write(i2s, JZ_REG_AIC_CTRL, ctrl); | 302 | jz4740_i2s_write(i2s, JZ_REG_AIC_CTRL, ctrl); |
278 | jz4740_i2s_write(i2s, JZ_REG_AIC_CLK_DIV, div_reg); | 303 | jz4740_i2s_write(i2s, JZ_REG_AIC_CLK_DIV, div_reg); |
279 | 304 | ||
@@ -369,11 +394,19 @@ static int jz4740_i2s_dai_probe(struct snd_soc_dai *dai) | |||
369 | snd_soc_dai_init_dma_data(dai, &i2s->playback_dma_data, | 394 | snd_soc_dai_init_dma_data(dai, &i2s->playback_dma_data, |
370 | &i2s->capture_dma_data); | 395 | &i2s->capture_dma_data); |
371 | 396 | ||
372 | conf = (7 << JZ_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET) | | 397 | if (i2s->version >= JZ_I2S_JZ4780) { |
373 | (8 << JZ_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET) | | 398 | conf = (7 << JZ4780_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET) | |
374 | JZ_AIC_CONF_OVERFLOW_PLAY_LAST | | 399 | (8 << JZ4780_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET) | |
375 | JZ_AIC_CONF_I2S | | 400 | JZ_AIC_CONF_OVERFLOW_PLAY_LAST | |
376 | JZ_AIC_CONF_INTERNAL_CODEC; | 401 | JZ_AIC_CONF_I2S | |
402 | JZ_AIC_CONF_INTERNAL_CODEC; | ||
403 | } else { | ||
404 | conf = (7 << JZ_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET) | | ||
405 | (8 << JZ_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET) | | ||
406 | JZ_AIC_CONF_OVERFLOW_PLAY_LAST | | ||
407 | JZ_AIC_CONF_I2S | | ||
408 | JZ_AIC_CONF_INTERNAL_CODEC; | ||
409 | } | ||
377 | 410 | ||
378 | jz4740_i2s_write(i2s, JZ_REG_AIC_CONF, JZ_AIC_CONF_RESET); | 411 | jz4740_i2s_write(i2s, JZ_REG_AIC_CONF, JZ_AIC_CONF_RESET); |
379 | jz4740_i2s_write(i2s, JZ_REG_AIC_CONF, conf); | 412 | jz4740_i2s_write(i2s, JZ_REG_AIC_CONF, conf); |
@@ -422,13 +455,34 @@ static struct snd_soc_dai_driver jz4740_i2s_dai = { | |||
422 | .resume = jz4740_i2s_resume, | 455 | .resume = jz4740_i2s_resume, |
423 | }; | 456 | }; |
424 | 457 | ||
458 | static struct snd_soc_dai_driver jz4780_i2s_dai = { | ||
459 | .probe = jz4740_i2s_dai_probe, | ||
460 | .remove = jz4740_i2s_dai_remove, | ||
461 | .playback = { | ||
462 | .channels_min = 1, | ||
463 | .channels_max = 2, | ||
464 | .rates = SNDRV_PCM_RATE_8000_48000, | ||
465 | .formats = JZ4740_I2S_FMTS, | ||
466 | }, | ||
467 | .capture = { | ||
468 | .channels_min = 2, | ||
469 | .channels_max = 2, | ||
470 | .rates = SNDRV_PCM_RATE_8000_48000, | ||
471 | .formats = JZ4740_I2S_FMTS, | ||
472 | }, | ||
473 | .ops = &jz4740_i2s_dai_ops, | ||
474 | .suspend = jz4740_i2s_suspend, | ||
475 | .resume = jz4740_i2s_resume, | ||
476 | }; | ||
477 | |||
425 | static const struct snd_soc_component_driver jz4740_i2s_component = { | 478 | static const struct snd_soc_component_driver jz4740_i2s_component = { |
426 | .name = "jz4740-i2s", | 479 | .name = "jz4740-i2s", |
427 | }; | 480 | }; |
428 | 481 | ||
429 | #ifdef CONFIG_OF | 482 | #ifdef CONFIG_OF |
430 | static const struct of_device_id jz4740_of_matches[] = { | 483 | static const struct of_device_id jz4740_of_matches[] = { |
431 | { .compatible = "ingenic,jz4740-i2s" }, | 484 | { .compatible = "ingenic,jz4740-i2s", .data = (void *)JZ_I2S_JZ4740 }, |
485 | { .compatible = "ingenic,jz4780-i2s", .data = (void *)JZ_I2S_JZ4780 }, | ||
432 | { /* sentinel */ } | 486 | { /* sentinel */ } |
433 | }; | 487 | }; |
434 | #endif | 488 | #endif |
@@ -438,11 +492,16 @@ static int jz4740_i2s_dev_probe(struct platform_device *pdev) | |||
438 | struct jz4740_i2s *i2s; | 492 | struct jz4740_i2s *i2s; |
439 | struct resource *mem; | 493 | struct resource *mem; |
440 | int ret; | 494 | int ret; |
495 | const struct of_device_id *match; | ||
441 | 496 | ||
442 | i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); | 497 | i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); |
443 | if (!i2s) | 498 | if (!i2s) |
444 | return -ENOMEM; | 499 | return -ENOMEM; |
445 | 500 | ||
501 | match = of_match_device(jz4740_of_matches, &pdev->dev); | ||
502 | if (match) | ||
503 | i2s->version = (enum jz47xx_i2s_version)match->data; | ||
504 | |||
446 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 505 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
447 | i2s->base = devm_ioremap_resource(&pdev->dev, mem); | 506 | i2s->base = devm_ioremap_resource(&pdev->dev, mem); |
448 | if (IS_ERR(i2s->base)) | 507 | if (IS_ERR(i2s->base)) |
@@ -460,8 +519,13 @@ static int jz4740_i2s_dev_probe(struct platform_device *pdev) | |||
460 | 519 | ||
461 | platform_set_drvdata(pdev, i2s); | 520 | platform_set_drvdata(pdev, i2s); |
462 | 521 | ||
463 | ret = devm_snd_soc_register_component(&pdev->dev, | 522 | if (i2s->version == JZ_I2S_JZ4780) |
464 | &jz4740_i2s_component, &jz4740_i2s_dai, 1); | 523 | ret = devm_snd_soc_register_component(&pdev->dev, |
524 | &jz4740_i2s_component, &jz4780_i2s_dai, 1); | ||
525 | else | ||
526 | ret = devm_snd_soc_register_component(&pdev->dev, | ||
527 | &jz4740_i2s_component, &jz4740_i2s_dai, 1); | ||
528 | |||
465 | if (ret) | 529 | if (ret) |
466 | return ret; | 530 | return ret; |
467 | 531 | ||
diff --git a/sound/soc/kirkwood/kirkwood-i2s.c b/sound/soc/kirkwood/kirkwood-i2s.c index d19483081f9b..3a36d60e1785 100644 --- a/sound/soc/kirkwood/kirkwood-i2s.c +++ b/sound/soc/kirkwood/kirkwood-i2s.c | |||
@@ -643,7 +643,7 @@ static int kirkwood_i2s_dev_remove(struct platform_device *pdev) | |||
643 | } | 643 | } |
644 | 644 | ||
645 | #ifdef CONFIG_OF | 645 | #ifdef CONFIG_OF |
646 | static struct of_device_id mvebu_audio_of_match[] = { | 646 | static const struct of_device_id mvebu_audio_of_match[] = { |
647 | { .compatible = "marvell,kirkwood-audio" }, | 647 | { .compatible = "marvell,kirkwood-audio" }, |
648 | { .compatible = "marvell,dove-audio" }, | 648 | { .compatible = "marvell,dove-audio" }, |
649 | { .compatible = "marvell,armada370-audio" }, | 649 | { .compatible = "marvell,armada370-audio" }, |
diff --git a/sound/soc/nuc900/nuc900-audio.h b/sound/soc/nuc900/nuc900-audio.h index 59f7e8ed1a68..d0b725705914 100644 --- a/sound/soc/nuc900/nuc900-audio.h +++ b/sound/soc/nuc900/nuc900-audio.h | |||
@@ -100,10 +100,7 @@ | |||
100 | struct nuc900_audio { | 100 | struct nuc900_audio { |
101 | void __iomem *mmio; | 101 | void __iomem *mmio; |
102 | spinlock_t lock; | 102 | spinlock_t lock; |
103 | dma_addr_t dma_addr[2]; | ||
104 | unsigned long buffersize[2]; | ||
105 | unsigned long irq_num; | 103 | unsigned long irq_num; |
106 | struct snd_pcm_substream *substream; | ||
107 | struct resource *res; | 104 | struct resource *res; |
108 | struct clk *clk; | 105 | struct clk *clk; |
109 | struct device *dev; | 106 | struct device *dev; |
diff --git a/sound/soc/nuc900/nuc900-pcm.c b/sound/soc/nuc900/nuc900-pcm.c index b809fa909e4d..5ae5ca15b6d6 100644 --- a/sound/soc/nuc900/nuc900-pcm.c +++ b/sound/soc/nuc900/nuc900-pcm.c | |||
@@ -42,29 +42,10 @@ static const struct snd_pcm_hardware nuc900_pcm_hardware = { | |||
42 | static int nuc900_dma_hw_params(struct snd_pcm_substream *substream, | 42 | static int nuc900_dma_hw_params(struct snd_pcm_substream *substream, |
43 | struct snd_pcm_hw_params *params) | 43 | struct snd_pcm_hw_params *params) |
44 | { | 44 | { |
45 | struct snd_pcm_runtime *runtime = substream->runtime; | 45 | return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); |
46 | struct nuc900_audio *nuc900_audio = runtime->private_data; | ||
47 | unsigned long flags; | ||
48 | int ret = 0; | ||
49 | |||
50 | ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); | ||
51 | if (ret < 0) | ||
52 | return ret; | ||
53 | |||
54 | spin_lock_irqsave(&nuc900_audio->lock, flags); | ||
55 | |||
56 | nuc900_audio->substream = substream; | ||
57 | nuc900_audio->dma_addr[substream->stream] = runtime->dma_addr; | ||
58 | nuc900_audio->buffersize[substream->stream] = | ||
59 | params_buffer_bytes(params); | ||
60 | |||
61 | spin_unlock_irqrestore(&nuc900_audio->lock, flags); | ||
62 | |||
63 | return ret; | ||
64 | } | 46 | } |
65 | 47 | ||
66 | static void nuc900_update_dma_register(struct snd_pcm_substream *substream, | 48 | static void nuc900_update_dma_register(struct snd_pcm_substream *substream) |
67 | dma_addr_t dma_addr, size_t count) | ||
68 | { | 49 | { |
69 | struct snd_pcm_runtime *runtime = substream->runtime; | 50 | struct snd_pcm_runtime *runtime = substream->runtime; |
70 | struct nuc900_audio *nuc900_audio = runtime->private_data; | 51 | struct nuc900_audio *nuc900_audio = runtime->private_data; |
@@ -78,8 +59,8 @@ static void nuc900_update_dma_register(struct snd_pcm_substream *substream, | |||
78 | mmio_len = nuc900_audio->mmio + ACTL_RDST_LENGTH; | 59 | mmio_len = nuc900_audio->mmio + ACTL_RDST_LENGTH; |
79 | } | 60 | } |
80 | 61 | ||
81 | AUDIO_WRITE(mmio_addr, dma_addr); | 62 | AUDIO_WRITE(mmio_addr, runtime->dma_addr); |
82 | AUDIO_WRITE(mmio_len, count); | 63 | AUDIO_WRITE(mmio_len, runtime->dma_bytes); |
83 | } | 64 | } |
84 | 65 | ||
85 | static void nuc900_dma_start(struct snd_pcm_substream *substream) | 66 | static void nuc900_dma_start(struct snd_pcm_substream *substream) |
@@ -170,9 +151,7 @@ static int nuc900_dma_prepare(struct snd_pcm_substream *substream) | |||
170 | 151 | ||
171 | spin_lock_irqsave(&nuc900_audio->lock, flags); | 152 | spin_lock_irqsave(&nuc900_audio->lock, flags); |
172 | 153 | ||
173 | nuc900_update_dma_register(substream, | 154 | nuc900_update_dma_register(substream); |
174 | nuc900_audio->dma_addr[substream->stream], | ||
175 | nuc900_audio->buffersize[substream->stream]); | ||
176 | 155 | ||
177 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_RESET); | 156 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_RESET); |
178 | 157 | ||
diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig index a2cd3486ac55..6768e4f7d7d0 100644 --- a/sound/soc/omap/Kconfig +++ b/sound/soc/omap/Kconfig | |||
@@ -100,17 +100,19 @@ config SND_OMAP_SOC_OMAP_TWL4030 | |||
100 | 100 | ||
101 | config SND_OMAP_SOC_OMAP_ABE_TWL6040 | 101 | config 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 MFD_PALMAS | ||
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 | ||
115 | config SND_OMAP_SOC_OMAP3_PANDORA | 117 | config 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/n810.c b/sound/soc/omap/n810.c index 5d7f9cebe041..dcb5336b5698 100644 --- a/sound/soc/omap/n810.c +++ b/sound/soc/omap/n810.c | |||
@@ -98,12 +98,11 @@ static int n810_startup(struct snd_pcm_substream *substream) | |||
98 | { | 98 | { |
99 | struct snd_pcm_runtime *runtime = substream->runtime; | 99 | struct snd_pcm_runtime *runtime = substream->runtime; |
100 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 100 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
101 | struct snd_soc_codec *codec = rtd->codec; | ||
102 | 101 | ||
103 | snd_pcm_hw_constraint_minmax(runtime, | 102 | snd_pcm_hw_constraint_minmax(runtime, |
104 | SNDRV_PCM_HW_PARAM_CHANNELS, 2, 2); | 103 | SNDRV_PCM_HW_PARAM_CHANNELS, 2, 2); |
105 | 104 | ||
106 | n810_ext_control(&codec->dapm); | 105 | n810_ext_control(&rtd->card->dapm); |
107 | return clk_prepare_enable(sys_clkout2); | 106 | return clk_prepare_enable(sys_clkout2); |
108 | } | 107 | } |
109 | 108 | ||
@@ -255,24 +254,6 @@ static const struct snd_kcontrol_new aic33_n810_controls[] = { | |||
255 | n810_get_input, n810_set_input), | 254 | n810_get_input, n810_set_input), |
256 | }; | 255 | }; |
257 | 256 | ||
258 | static int n810_aic33_init(struct snd_soc_pcm_runtime *rtd) | ||
259 | { | ||
260 | struct snd_soc_codec *codec = rtd->codec; | ||
261 | struct snd_soc_dapm_context *dapm = &codec->dapm; | ||
262 | |||
263 | /* Not connected */ | ||
264 | snd_soc_dapm_nc_pin(dapm, "MONO_LOUT"); | ||
265 | snd_soc_dapm_nc_pin(dapm, "HPLCOM"); | ||
266 | snd_soc_dapm_nc_pin(dapm, "HPRCOM"); | ||
267 | snd_soc_dapm_nc_pin(dapm, "MIC3L"); | ||
268 | snd_soc_dapm_nc_pin(dapm, "MIC3R"); | ||
269 | snd_soc_dapm_nc_pin(dapm, "LINE1R"); | ||
270 | snd_soc_dapm_nc_pin(dapm, "LINE2L"); | ||
271 | snd_soc_dapm_nc_pin(dapm, "LINE2R"); | ||
272 | |||
273 | return 0; | ||
274 | } | ||
275 | |||
276 | /* Digital audio interface glue - connects codec <--> CPU */ | 257 | /* Digital audio interface glue - connects codec <--> CPU */ |
277 | static struct snd_soc_dai_link n810_dai = { | 258 | static struct snd_soc_dai_link n810_dai = { |
278 | .name = "TLV320AIC33", | 259 | .name = "TLV320AIC33", |
@@ -283,7 +264,6 @@ static struct snd_soc_dai_link n810_dai = { | |||
283 | .codec_dai_name = "tlv320aic3x-hifi", | 264 | .codec_dai_name = "tlv320aic3x-hifi", |
284 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | | 265 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
285 | SND_SOC_DAIFMT_CBM_CFM, | 266 | SND_SOC_DAIFMT_CBM_CFM, |
286 | .init = n810_aic33_init, | ||
287 | .ops = &n810_ops, | 267 | .ops = &n810_ops, |
288 | }; | 268 | }; |
289 | 269 | ||
@@ -300,6 +280,7 @@ static struct snd_soc_card snd_soc_n810 = { | |||
300 | .num_dapm_widgets = ARRAY_SIZE(aic33_dapm_widgets), | 280 | .num_dapm_widgets = ARRAY_SIZE(aic33_dapm_widgets), |
301 | .dapm_routes = audio_map, | 281 | .dapm_routes = audio_map, |
302 | .num_dapm_routes = ARRAY_SIZE(audio_map), | 282 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
283 | .fully_routed = true, | ||
303 | }; | 284 | }; |
304 | 285 | ||
305 | static struct platform_device *n810_snd_device; | 286 | static struct platform_device *n810_snd_device; |
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 | ||
198 | static const struct snd_soc_dapm_route dmic_audio_map[] = { | 198 | static const struct snd_soc_dapm_route dmic_audio_map[] = { |
diff --git a/sound/soc/omap/omap-hdmi-audio.c b/sound/soc/omap/omap-hdmi-audio.c index f7eb42aa3f38..4775da4c4db5 100644 --- a/sound/soc/omap/omap-hdmi-audio.c +++ b/sound/soc/omap/omap-hdmi-audio.c | |||
@@ -142,8 +142,6 @@ static int hdmi_dai_hw_params(struct snd_pcm_substream *substream, | |||
142 | 142 | ||
143 | iec->status[0] |= IEC958_AES0_CON_EMPHASIS_NONE; | 143 | iec->status[0] |= IEC958_AES0_CON_EMPHASIS_NONE; |
144 | 144 | ||
145 | iec->status[0] |= IEC958_AES1_PRO_MODE_NOTID; | ||
146 | |||
147 | iec->status[1] = IEC958_AES1_CON_GENERAL; | 145 | iec->status[1] = IEC958_AES1_CON_GENERAL; |
148 | 146 | ||
149 | iec->status[2] |= IEC958_AES2_CON_SOURCE_UNSPEC; | 147 | iec->status[2] |= IEC958_AES2_CON_SOURCE_UNSPEC; |
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 | ||
42 | static const struct snd_pcm_hardware omap_pcm_hardware = { | 42 | static 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. */ | ||
57 | static 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 */ |
57 | static int omap_pcm_hw_params(struct snd_pcm_substream *substream, | 75 | static 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 | ||
236 | int omap_pcm_platform_register(struct device *dev) | 254 | int 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 | } |
240 | EXPORT_SYMBOL_GPL(omap_pcm_platform_register); | 259 | EXPORT_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 | */ |
127 | static int hx4700_ak4641_init(struct snd_soc_pcm_runtime *rtd) | 127 | static 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 | ||
76 | static int palm27x_ac97_init(struct snd_soc_pcm_runtime *rtd) | 76 | static 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/qcom/Kconfig b/sound/soc/qcom/Kconfig new file mode 100644 index 000000000000..5f58e4f1bca9 --- /dev/null +++ b/sound/soc/qcom/Kconfig | |||
@@ -0,0 +1,25 @@ | |||
1 | config SND_SOC_QCOM | ||
2 | tristate "ASoC support for QCOM platforms" | ||
3 | help | ||
4 | Say Y or M if you want to add support to use audio devices | ||
5 | in Qualcomm Technologies SOC-based platforms. | ||
6 | |||
7 | config SND_SOC_LPASS_CPU | ||
8 | tristate | ||
9 | depends on SND_SOC_QCOM | ||
10 | select REGMAP_MMIO | ||
11 | |||
12 | config SND_SOC_LPASS_PLATFORM | ||
13 | tristate | ||
14 | depends on SND_SOC_QCOM | ||
15 | select REGMAP_MMIO | ||
16 | |||
17 | config SND_SOC_STORM | ||
18 | tristate "ASoC I2S support for Storm boards" | ||
19 | depends on (ARCH_QCOM && SND_SOC_QCOM) || COMPILE_TEST | ||
20 | select SND_SOC_LPASS_CPU | ||
21 | select SND_SOC_LPASS_PLATFORM | ||
22 | select SND_SOC_MAX98357A | ||
23 | help | ||
24 | Say Y or M if you want add support for SoC audio on the | ||
25 | Qualcomm Technologies IPQ806X-based Storm board. | ||
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile new file mode 100644 index 000000000000..c5ce96c761c4 --- /dev/null +++ b/sound/soc/qcom/Makefile | |||
@@ -0,0 +1,11 @@ | |||
1 | # Platform | ||
2 | snd-soc-lpass-cpu-objs := lpass-cpu.o | ||
3 | snd-soc-lpass-platform-objs := lpass-platform.o | ||
4 | |||
5 | obj-$(CONFIG_SND_SOC_LPASS_CPU) += snd-soc-lpass-cpu.o | ||
6 | obj-$(CONFIG_SND_SOC_LPASS_PLATFORM) += snd-soc-lpass-platform.o | ||
7 | |||
8 | # Machine | ||
9 | snd-soc-storm-objs := storm.o | ||
10 | |||
11 | obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o | ||
diff --git a/sound/soc/qcom/lpass-cpu.c b/sound/soc/qcom/lpass-cpu.c new file mode 100644 index 000000000000..6698d058de29 --- /dev/null +++ b/sound/soc/qcom/lpass-cpu.c | |||
@@ -0,0 +1,491 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 and | ||
6 | * only version 2 as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * lpass-cpu.c -- ALSA SoC CPU DAI driver for QTi LPASS | ||
14 | */ | ||
15 | |||
16 | #include <linux/clk.h> | ||
17 | #include <linux/compiler.h> | ||
18 | #include <linux/device.h> | ||
19 | #include <linux/err.h> | ||
20 | #include <linux/ioport.h> | ||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/mod_devicetable.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/of.h> | ||
25 | #include <linux/platform_device.h> | ||
26 | #include <sound/pcm.h> | ||
27 | #include <sound/pcm_params.h> | ||
28 | #include <linux/regmap.h> | ||
29 | #include <sound/soc.h> | ||
30 | #include <sound/soc-dai.h> | ||
31 | #include "lpass-lpaif-ipq806x.h" | ||
32 | #include "lpass.h" | ||
33 | |||
34 | static int lpass_cpu_daiops_set_sysclk(struct snd_soc_dai *dai, int clk_id, | ||
35 | unsigned int freq, int dir) | ||
36 | { | ||
37 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); | ||
38 | int ret; | ||
39 | |||
40 | ret = clk_set_rate(drvdata->mi2s_osr_clk, freq); | ||
41 | if (ret) | ||
42 | dev_err(dai->dev, "%s() error setting mi2s osrclk to %u: %d\n", | ||
43 | __func__, freq, ret); | ||
44 | |||
45 | return ret; | ||
46 | } | ||
47 | |||
48 | static int lpass_cpu_daiops_startup(struct snd_pcm_substream *substream, | ||
49 | struct snd_soc_dai *dai) | ||
50 | { | ||
51 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); | ||
52 | int ret; | ||
53 | |||
54 | ret = clk_prepare_enable(drvdata->mi2s_osr_clk); | ||
55 | if (ret) { | ||
56 | dev_err(dai->dev, "%s() error in enabling mi2s osr clk: %d\n", | ||
57 | __func__, ret); | ||
58 | return ret; | ||
59 | } | ||
60 | |||
61 | ret = clk_prepare_enable(drvdata->mi2s_bit_clk); | ||
62 | if (ret) { | ||
63 | dev_err(dai->dev, "%s() error in enabling mi2s bit clk: %d\n", | ||
64 | __func__, ret); | ||
65 | clk_disable_unprepare(drvdata->mi2s_osr_clk); | ||
66 | return ret; | ||
67 | } | ||
68 | |||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | static void lpass_cpu_daiops_shutdown(struct snd_pcm_substream *substream, | ||
73 | struct snd_soc_dai *dai) | ||
74 | { | ||
75 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); | ||
76 | |||
77 | clk_disable_unprepare(drvdata->mi2s_bit_clk); | ||
78 | clk_disable_unprepare(drvdata->mi2s_osr_clk); | ||
79 | } | ||
80 | |||
81 | static int lpass_cpu_daiops_hw_params(struct snd_pcm_substream *substream, | ||
82 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) | ||
83 | { | ||
84 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); | ||
85 | snd_pcm_format_t format = params_format(params); | ||
86 | unsigned int channels = params_channels(params); | ||
87 | unsigned int rate = params_rate(params); | ||
88 | unsigned int regval; | ||
89 | int bitwidth, ret; | ||
90 | |||
91 | bitwidth = snd_pcm_format_width(format); | ||
92 | if (bitwidth < 0) { | ||
93 | dev_err(dai->dev, "%s() invalid bit width given: %d\n", | ||
94 | __func__, bitwidth); | ||
95 | return bitwidth; | ||
96 | } | ||
97 | |||
98 | regval = LPAIF_I2SCTL_LOOPBACK_DISABLE | | ||
99 | LPAIF_I2SCTL_WSSRC_INTERNAL; | ||
100 | |||
101 | switch (bitwidth) { | ||
102 | case 16: | ||
103 | regval |= LPAIF_I2SCTL_BITWIDTH_16; | ||
104 | break; | ||
105 | case 24: | ||
106 | regval |= LPAIF_I2SCTL_BITWIDTH_24; | ||
107 | break; | ||
108 | case 32: | ||
109 | regval |= LPAIF_I2SCTL_BITWIDTH_32; | ||
110 | break; | ||
111 | default: | ||
112 | dev_err(dai->dev, "%s() invalid bitwidth given: %d\n", | ||
113 | __func__, bitwidth); | ||
114 | return -EINVAL; | ||
115 | } | ||
116 | |||
117 | switch (channels) { | ||
118 | case 1: | ||
119 | regval |= LPAIF_I2SCTL_SPKMODE_SD0; | ||
120 | regval |= LPAIF_I2SCTL_SPKMONO_MONO; | ||
121 | break; | ||
122 | case 2: | ||
123 | regval |= LPAIF_I2SCTL_SPKMODE_SD0; | ||
124 | regval |= LPAIF_I2SCTL_SPKMONO_STEREO; | ||
125 | break; | ||
126 | case 4: | ||
127 | regval |= LPAIF_I2SCTL_SPKMODE_QUAD01; | ||
128 | regval |= LPAIF_I2SCTL_SPKMONO_STEREO; | ||
129 | break; | ||
130 | case 6: | ||
131 | regval |= LPAIF_I2SCTL_SPKMODE_6CH; | ||
132 | regval |= LPAIF_I2SCTL_SPKMONO_STEREO; | ||
133 | break; | ||
134 | case 8: | ||
135 | regval |= LPAIF_I2SCTL_SPKMODE_8CH; | ||
136 | regval |= LPAIF_I2SCTL_SPKMONO_STEREO; | ||
137 | break; | ||
138 | default: | ||
139 | dev_err(dai->dev, "%s() invalid channels given: %u\n", | ||
140 | __func__, channels); | ||
141 | return -EINVAL; | ||
142 | } | ||
143 | |||
144 | ret = regmap_write(drvdata->lpaif_map, | ||
145 | LPAIF_I2SCTL_REG(LPAIF_I2S_PORT_MI2S), regval); | ||
146 | if (ret) { | ||
147 | dev_err(dai->dev, "%s() error writing to i2sctl reg: %d\n", | ||
148 | __func__, ret); | ||
149 | return ret; | ||
150 | } | ||
151 | |||
152 | ret = clk_set_rate(drvdata->mi2s_bit_clk, rate * bitwidth * 2); | ||
153 | if (ret) { | ||
154 | dev_err(dai->dev, "%s() error setting mi2s bitclk to %u: %d\n", | ||
155 | __func__, rate * bitwidth * 2, ret); | ||
156 | return ret; | ||
157 | } | ||
158 | |||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | static int lpass_cpu_daiops_hw_free(struct snd_pcm_substream *substream, | ||
163 | struct snd_soc_dai *dai) | ||
164 | { | ||
165 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); | ||
166 | int ret; | ||
167 | |||
168 | ret = regmap_write(drvdata->lpaif_map, | ||
169 | LPAIF_I2SCTL_REG(LPAIF_I2S_PORT_MI2S), 0); | ||
170 | if (ret) | ||
171 | dev_err(dai->dev, "%s() error writing to i2sctl reg: %d\n", | ||
172 | __func__, ret); | ||
173 | |||
174 | return ret; | ||
175 | } | ||
176 | |||
177 | static int lpass_cpu_daiops_prepare(struct snd_pcm_substream *substream, | ||
178 | struct snd_soc_dai *dai) | ||
179 | { | ||
180 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); | ||
181 | int ret; | ||
182 | |||
183 | ret = regmap_update_bits(drvdata->lpaif_map, | ||
184 | LPAIF_I2SCTL_REG(LPAIF_I2S_PORT_MI2S), | ||
185 | LPAIF_I2SCTL_SPKEN_MASK, LPAIF_I2SCTL_SPKEN_ENABLE); | ||
186 | if (ret) | ||
187 | dev_err(dai->dev, "%s() error writing to i2sctl reg: %d\n", | ||
188 | __func__, ret); | ||
189 | |||
190 | return ret; | ||
191 | } | ||
192 | |||
193 | static int lpass_cpu_daiops_trigger(struct snd_pcm_substream *substream, | ||
194 | int cmd, struct snd_soc_dai *dai) | ||
195 | { | ||
196 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); | ||
197 | int ret; | ||
198 | |||
199 | switch (cmd) { | ||
200 | case SNDRV_PCM_TRIGGER_START: | ||
201 | case SNDRV_PCM_TRIGGER_RESUME: | ||
202 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
203 | ret = regmap_update_bits(drvdata->lpaif_map, | ||
204 | LPAIF_I2SCTL_REG(LPAIF_I2S_PORT_MI2S), | ||
205 | LPAIF_I2SCTL_SPKEN_MASK, | ||
206 | LPAIF_I2SCTL_SPKEN_ENABLE); | ||
207 | if (ret) | ||
208 | dev_err(dai->dev, "%s() error writing to i2sctl reg: %d\n", | ||
209 | __func__, ret); | ||
210 | break; | ||
211 | case SNDRV_PCM_TRIGGER_STOP: | ||
212 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
213 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
214 | ret = regmap_update_bits(drvdata->lpaif_map, | ||
215 | LPAIF_I2SCTL_REG(LPAIF_I2S_PORT_MI2S), | ||
216 | LPAIF_I2SCTL_SPKEN_MASK, | ||
217 | LPAIF_I2SCTL_SPKEN_DISABLE); | ||
218 | if (ret) | ||
219 | dev_err(dai->dev, "%s() error writing to i2sctl reg: %d\n", | ||
220 | __func__, ret); | ||
221 | break; | ||
222 | } | ||
223 | |||
224 | return ret; | ||
225 | } | ||
226 | |||
227 | static struct snd_soc_dai_ops lpass_cpu_dai_ops = { | ||
228 | .set_sysclk = lpass_cpu_daiops_set_sysclk, | ||
229 | .startup = lpass_cpu_daiops_startup, | ||
230 | .shutdown = lpass_cpu_daiops_shutdown, | ||
231 | .hw_params = lpass_cpu_daiops_hw_params, | ||
232 | .hw_free = lpass_cpu_daiops_hw_free, | ||
233 | .prepare = lpass_cpu_daiops_prepare, | ||
234 | .trigger = lpass_cpu_daiops_trigger, | ||
235 | }; | ||
236 | |||
237 | static int lpass_cpu_dai_probe(struct snd_soc_dai *dai) | ||
238 | { | ||
239 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); | ||
240 | int ret; | ||
241 | |||
242 | /* ensure audio hardware is disabled */ | ||
243 | ret = regmap_write(drvdata->lpaif_map, | ||
244 | LPAIF_I2SCTL_REG(LPAIF_I2S_PORT_MI2S), 0); | ||
245 | if (ret) | ||
246 | dev_err(dai->dev, "%s() error writing to i2sctl reg: %d\n", | ||
247 | __func__, ret); | ||
248 | |||
249 | return ret; | ||
250 | } | ||
251 | |||
252 | static struct snd_soc_dai_driver lpass_cpu_dai_driver = { | ||
253 | .playback = { | ||
254 | .stream_name = "lpass-cpu-playback", | ||
255 | .formats = SNDRV_PCM_FMTBIT_S16 | | ||
256 | SNDRV_PCM_FMTBIT_S24 | | ||
257 | SNDRV_PCM_FMTBIT_S32, | ||
258 | .rates = SNDRV_PCM_RATE_8000 | | ||
259 | SNDRV_PCM_RATE_16000 | | ||
260 | SNDRV_PCM_RATE_32000 | | ||
261 | SNDRV_PCM_RATE_48000 | | ||
262 | SNDRV_PCM_RATE_96000, | ||
263 | .rate_min = 8000, | ||
264 | .rate_max = 96000, | ||
265 | .channels_min = 1, | ||
266 | .channels_max = 8, | ||
267 | }, | ||
268 | .probe = &lpass_cpu_dai_probe, | ||
269 | .ops = &lpass_cpu_dai_ops, | ||
270 | }; | ||
271 | |||
272 | static const struct snd_soc_component_driver lpass_cpu_comp_driver = { | ||
273 | .name = "lpass-cpu", | ||
274 | }; | ||
275 | |||
276 | static bool lpass_cpu_regmap_writeable(struct device *dev, unsigned int reg) | ||
277 | { | ||
278 | int i; | ||
279 | |||
280 | for (i = 0; i < LPAIF_I2S_PORT_NUM; ++i) | ||
281 | if (reg == LPAIF_I2SCTL_REG(i)) | ||
282 | return true; | ||
283 | |||
284 | for (i = 0; i < LPAIF_IRQ_PORT_NUM; ++i) { | ||
285 | if (reg == LPAIF_IRQEN_REG(i)) | ||
286 | return true; | ||
287 | if (reg == LPAIF_IRQCLEAR_REG(i)) | ||
288 | return true; | ||
289 | } | ||
290 | |||
291 | for (i = 0; i < LPAIF_RDMA_CHAN_NUM; ++i) { | ||
292 | if (reg == LPAIF_RDMACTL_REG(i)) | ||
293 | return true; | ||
294 | if (reg == LPAIF_RDMABASE_REG(i)) | ||
295 | return true; | ||
296 | if (reg == LPAIF_RDMABUFF_REG(i)) | ||
297 | return true; | ||
298 | if (reg == LPAIF_RDMAPER_REG(i)) | ||
299 | return true; | ||
300 | } | ||
301 | |||
302 | return false; | ||
303 | } | ||
304 | |||
305 | static bool lpass_cpu_regmap_readable(struct device *dev, unsigned int reg) | ||
306 | { | ||
307 | int i; | ||
308 | |||
309 | for (i = 0; i < LPAIF_I2S_PORT_NUM; ++i) | ||
310 | if (reg == LPAIF_I2SCTL_REG(i)) | ||
311 | return true; | ||
312 | |||
313 | for (i = 0; i < LPAIF_IRQ_PORT_NUM; ++i) { | ||
314 | if (reg == LPAIF_IRQEN_REG(i)) | ||
315 | return true; | ||
316 | if (reg == LPAIF_IRQSTAT_REG(i)) | ||
317 | return true; | ||
318 | } | ||
319 | |||
320 | for (i = 0; i < LPAIF_RDMA_CHAN_NUM; ++i) { | ||
321 | if (reg == LPAIF_RDMACTL_REG(i)) | ||
322 | return true; | ||
323 | if (reg == LPAIF_RDMABASE_REG(i)) | ||
324 | return true; | ||
325 | if (reg == LPAIF_RDMABUFF_REG(i)) | ||
326 | return true; | ||
327 | if (reg == LPAIF_RDMACURR_REG(i)) | ||
328 | return true; | ||
329 | if (reg == LPAIF_RDMAPER_REG(i)) | ||
330 | return true; | ||
331 | } | ||
332 | |||
333 | return false; | ||
334 | } | ||
335 | |||
336 | static bool lpass_cpu_regmap_volatile(struct device *dev, unsigned int reg) | ||
337 | { | ||
338 | int i; | ||
339 | |||
340 | for (i = 0; i < LPAIF_IRQ_PORT_NUM; ++i) | ||
341 | if (reg == LPAIF_IRQSTAT_REG(i)) | ||
342 | return true; | ||
343 | |||
344 | for (i = 0; i < LPAIF_RDMA_CHAN_NUM; ++i) | ||
345 | if (reg == LPAIF_RDMACURR_REG(i)) | ||
346 | return true; | ||
347 | |||
348 | return false; | ||
349 | } | ||
350 | |||
351 | static const struct regmap_config lpass_cpu_regmap_config = { | ||
352 | .reg_bits = 32, | ||
353 | .reg_stride = 4, | ||
354 | .val_bits = 32, | ||
355 | .max_register = LPAIF_RDMAPER_REG(LPAIF_RDMA_CHAN_MAX), | ||
356 | .writeable_reg = lpass_cpu_regmap_writeable, | ||
357 | .readable_reg = lpass_cpu_regmap_readable, | ||
358 | .volatile_reg = lpass_cpu_regmap_volatile, | ||
359 | .cache_type = REGCACHE_FLAT, | ||
360 | }; | ||
361 | |||
362 | static int lpass_cpu_platform_probe(struct platform_device *pdev) | ||
363 | { | ||
364 | struct lpass_data *drvdata; | ||
365 | struct device_node *dsp_of_node; | ||
366 | struct resource *res; | ||
367 | int ret; | ||
368 | |||
369 | dsp_of_node = of_parse_phandle(pdev->dev.of_node, "qcom,adsp", 0); | ||
370 | if (dsp_of_node) { | ||
371 | dev_err(&pdev->dev, "%s() DSP exists and holds audio resources\n", | ||
372 | __func__); | ||
373 | return -EBUSY; | ||
374 | } | ||
375 | |||
376 | drvdata = devm_kzalloc(&pdev->dev, sizeof(struct lpass_data), | ||
377 | GFP_KERNEL); | ||
378 | if (!drvdata) | ||
379 | return -ENOMEM; | ||
380 | platform_set_drvdata(pdev, drvdata); | ||
381 | |||
382 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lpass-lpaif"); | ||
383 | if (!res) { | ||
384 | dev_err(&pdev->dev, "%s() error getting resource\n", __func__); | ||
385 | return -ENODEV; | ||
386 | } | ||
387 | |||
388 | drvdata->lpaif = devm_ioremap_resource(&pdev->dev, res); | ||
389 | if (IS_ERR((void const __force *)drvdata->lpaif)) { | ||
390 | dev_err(&pdev->dev, "%s() error mapping reg resource: %ld\n", | ||
391 | __func__, | ||
392 | PTR_ERR((void const __force *)drvdata->lpaif)); | ||
393 | return PTR_ERR((void const __force *)drvdata->lpaif); | ||
394 | } | ||
395 | |||
396 | drvdata->lpaif_map = devm_regmap_init_mmio(&pdev->dev, drvdata->lpaif, | ||
397 | &lpass_cpu_regmap_config); | ||
398 | if (IS_ERR(drvdata->lpaif_map)) { | ||
399 | dev_err(&pdev->dev, "%s() error initializing regmap: %ld\n", | ||
400 | __func__, PTR_ERR(drvdata->lpaif_map)); | ||
401 | return PTR_ERR(drvdata->lpaif_map); | ||
402 | } | ||
403 | |||
404 | drvdata->mi2s_osr_clk = devm_clk_get(&pdev->dev, "mi2s-osr-clk"); | ||
405 | if (IS_ERR(drvdata->mi2s_osr_clk)) { | ||
406 | dev_err(&pdev->dev, "%s() error getting mi2s-osr-clk: %ld\n", | ||
407 | __func__, PTR_ERR(drvdata->mi2s_osr_clk)); | ||
408 | return PTR_ERR(drvdata->mi2s_osr_clk); | ||
409 | } | ||
410 | |||
411 | drvdata->mi2s_bit_clk = devm_clk_get(&pdev->dev, "mi2s-bit-clk"); | ||
412 | if (IS_ERR(drvdata->mi2s_bit_clk)) { | ||
413 | dev_err(&pdev->dev, "%s() error getting mi2s-bit-clk: %ld\n", | ||
414 | __func__, PTR_ERR(drvdata->mi2s_bit_clk)); | ||
415 | return PTR_ERR(drvdata->mi2s_bit_clk); | ||
416 | } | ||
417 | |||
418 | drvdata->ahbix_clk = devm_clk_get(&pdev->dev, "ahbix-clk"); | ||
419 | if (IS_ERR(drvdata->ahbix_clk)) { | ||
420 | dev_err(&pdev->dev, "%s() error getting ahbix-clk: %ld\n", | ||
421 | __func__, PTR_ERR(drvdata->ahbix_clk)); | ||
422 | return PTR_ERR(drvdata->ahbix_clk); | ||
423 | } | ||
424 | |||
425 | ret = clk_set_rate(drvdata->ahbix_clk, LPASS_AHBIX_CLOCK_FREQUENCY); | ||
426 | if (ret) { | ||
427 | dev_err(&pdev->dev, "%s() error setting rate on ahbix_clk: %d\n", | ||
428 | __func__, ret); | ||
429 | return ret; | ||
430 | } | ||
431 | dev_dbg(&pdev->dev, "%s() set ahbix_clk rate to %lu\n", __func__, | ||
432 | clk_get_rate(drvdata->ahbix_clk)); | ||
433 | |||
434 | ret = clk_prepare_enable(drvdata->ahbix_clk); | ||
435 | if (ret) { | ||
436 | dev_err(&pdev->dev, "%s() error enabling ahbix_clk: %d\n", | ||
437 | __func__, ret); | ||
438 | return ret; | ||
439 | } | ||
440 | |||
441 | ret = devm_snd_soc_register_component(&pdev->dev, | ||
442 | &lpass_cpu_comp_driver, &lpass_cpu_dai_driver, 1); | ||
443 | if (ret) { | ||
444 | dev_err(&pdev->dev, "%s() error registering cpu driver: %d\n", | ||
445 | __func__, ret); | ||
446 | goto err_clk; | ||
447 | } | ||
448 | |||
449 | ret = asoc_qcom_lpass_platform_register(pdev); | ||
450 | if (ret) { | ||
451 | dev_err(&pdev->dev, "%s() error registering platform driver: %d\n", | ||
452 | __func__, ret); | ||
453 | goto err_clk; | ||
454 | } | ||
455 | |||
456 | return 0; | ||
457 | |||
458 | err_clk: | ||
459 | clk_disable_unprepare(drvdata->ahbix_clk); | ||
460 | return ret; | ||
461 | } | ||
462 | |||
463 | static int lpass_cpu_platform_remove(struct platform_device *pdev) | ||
464 | { | ||
465 | struct lpass_data *drvdata = platform_get_drvdata(pdev); | ||
466 | |||
467 | clk_disable_unprepare(drvdata->ahbix_clk); | ||
468 | |||
469 | return 0; | ||
470 | } | ||
471 | |||
472 | #ifdef CONFIG_OF | ||
473 | static const struct of_device_id lpass_cpu_device_id[] = { | ||
474 | { .compatible = "qcom,lpass-cpu" }, | ||
475 | {} | ||
476 | }; | ||
477 | MODULE_DEVICE_TABLE(of, lpass_cpu_device_id); | ||
478 | #endif | ||
479 | |||
480 | static struct platform_driver lpass_cpu_platform_driver = { | ||
481 | .driver = { | ||
482 | .name = "lpass-cpu", | ||
483 | .of_match_table = of_match_ptr(lpass_cpu_device_id), | ||
484 | }, | ||
485 | .probe = lpass_cpu_platform_probe, | ||
486 | .remove = lpass_cpu_platform_remove, | ||
487 | }; | ||
488 | module_platform_driver(lpass_cpu_platform_driver); | ||
489 | |||
490 | MODULE_DESCRIPTION("QTi LPASS CPU Driver"); | ||
491 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/sound/soc/qcom/lpass-lpaif-ipq806x.h b/sound/soc/qcom/lpass-lpaif-ipq806x.h new file mode 100644 index 000000000000..dc423b888842 --- /dev/null +++ b/sound/soc/qcom/lpass-lpaif-ipq806x.h | |||
@@ -0,0 +1,172 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 and | ||
6 | * only version 2 as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * lpass-lpaif-ipq806x.h -- Definitions for the QTi LPAIF in the ipq806x LPASS | ||
14 | */ | ||
15 | |||
16 | #ifndef __LPASS_LPAIF_H__ | ||
17 | #define __LPASS_LPAIF_H__ | ||
18 | |||
19 | #define LPAIF_BANK_OFFSET 0x1000 | ||
20 | |||
21 | /* LPAIF I2S */ | ||
22 | |||
23 | #define LPAIF_I2SCTL_REG_BASE 0x0010 | ||
24 | #define LPAIF_I2SCTL_REG_STRIDE 0x4 | ||
25 | #define LPAIF_I2SCTL_REG_ADDR(addr, port) \ | ||
26 | (LPAIF_I2SCTL_REG_BASE + (addr) + (LPAIF_I2SCTL_REG_STRIDE * (port))) | ||
27 | |||
28 | enum lpaif_i2s_ports { | ||
29 | LPAIF_I2S_PORT_MIN = 0, | ||
30 | |||
31 | LPAIF_I2S_PORT_CODEC_SPK = 0, | ||
32 | LPAIF_I2S_PORT_CODEC_MIC = 1, | ||
33 | LPAIF_I2S_PORT_SEC_SPK = 2, | ||
34 | LPAIF_I2S_PORT_SEC_MIC = 3, | ||
35 | LPAIF_I2S_PORT_MI2S = 4, | ||
36 | |||
37 | LPAIF_I2S_PORT_MAX = 4, | ||
38 | LPAIF_I2S_PORT_NUM = 5, | ||
39 | }; | ||
40 | |||
41 | #define LPAIF_I2SCTL_REG(port) LPAIF_I2SCTL_REG_ADDR(0x0, (port)) | ||
42 | |||
43 | #define LPAIF_I2SCTL_LOOPBACK_MASK 0x8000 | ||
44 | #define LPAIF_I2SCTL_LOOPBACK_SHIFT 15 | ||
45 | #define LPAIF_I2SCTL_LOOPBACK_DISABLE (0 << LPAIF_I2SCTL_LOOPBACK_SHIFT) | ||
46 | #define LPAIF_I2SCTL_LOOPBACK_ENABLE (1 << LPAIF_I2SCTL_LOOPBACK_SHIFT) | ||
47 | |||
48 | #define LPAIF_I2SCTL_SPKEN_MASK 0x4000 | ||
49 | #define LPAIF_I2SCTL_SPKEN_SHIFT 14 | ||
50 | #define LPAIF_I2SCTL_SPKEN_DISABLE (0 << LPAIF_I2SCTL_SPKEN_SHIFT) | ||
51 | #define LPAIF_I2SCTL_SPKEN_ENABLE (1 << LPAIF_I2SCTL_SPKEN_SHIFT) | ||
52 | |||
53 | #define LPAIF_I2SCTL_SPKMODE_MASK 0x3C00 | ||
54 | #define LPAIF_I2SCTL_SPKMODE_SHIFT 10 | ||
55 | #define LPAIF_I2SCTL_SPKMODE_NONE (0 << LPAIF_I2SCTL_SPKMODE_SHIFT) | ||
56 | #define LPAIF_I2SCTL_SPKMODE_SD0 (1 << LPAIF_I2SCTL_SPKMODE_SHIFT) | ||
57 | #define LPAIF_I2SCTL_SPKMODE_SD1 (2 << LPAIF_I2SCTL_SPKMODE_SHIFT) | ||
58 | #define LPAIF_I2SCTL_SPKMODE_SD2 (3 << LPAIF_I2SCTL_SPKMODE_SHIFT) | ||
59 | #define LPAIF_I2SCTL_SPKMODE_SD3 (4 << LPAIF_I2SCTL_SPKMODE_SHIFT) | ||
60 | #define LPAIF_I2SCTL_SPKMODE_QUAD01 (5 << LPAIF_I2SCTL_SPKMODE_SHIFT) | ||
61 | #define LPAIF_I2SCTL_SPKMODE_QUAD23 (6 << LPAIF_I2SCTL_SPKMODE_SHIFT) | ||
62 | #define LPAIF_I2SCTL_SPKMODE_6CH (7 << LPAIF_I2SCTL_SPKMODE_SHIFT) | ||
63 | #define LPAIF_I2SCTL_SPKMODE_8CH (8 << LPAIF_I2SCTL_SPKMODE_SHIFT) | ||
64 | |||
65 | #define LPAIF_I2SCTL_SPKMONO_MASK 0x0200 | ||
66 | #define LPAIF_I2SCTL_SPKMONO_SHIFT 9 | ||
67 | #define LPAIF_I2SCTL_SPKMONO_STEREO (0 << LPAIF_I2SCTL_SPKMONO_SHIFT) | ||
68 | #define LPAIF_I2SCTL_SPKMONO_MONO (1 << LPAIF_I2SCTL_SPKMONO_SHIFT) | ||
69 | |||
70 | #define LPAIF_I2SCTL_WSSRC_MASK 0x0004 | ||
71 | #define LPAIF_I2SCTL_WSSRC_SHIFT 2 | ||
72 | #define LPAIF_I2SCTL_WSSRC_INTERNAL (0 << LPAIF_I2SCTL_WSSRC_SHIFT) | ||
73 | #define LPAIF_I2SCTL_WSSRC_EXTERNAL (1 << LPAIF_I2SCTL_WSSRC_SHIFT) | ||
74 | |||
75 | #define LPAIF_I2SCTL_BITWIDTH_MASK 0x0003 | ||
76 | #define LPAIF_I2SCTL_BITWIDTH_SHIFT 0 | ||
77 | #define LPAIF_I2SCTL_BITWIDTH_16 (0 << LPAIF_I2SCTL_BITWIDTH_SHIFT) | ||
78 | #define LPAIF_I2SCTL_BITWIDTH_24 (1 << LPAIF_I2SCTL_BITWIDTH_SHIFT) | ||
79 | #define LPAIF_I2SCTL_BITWIDTH_32 (2 << LPAIF_I2SCTL_BITWIDTH_SHIFT) | ||
80 | |||
81 | /* LPAIF IRQ */ | ||
82 | |||
83 | #define LPAIF_IRQ_REG_BASE 0x3000 | ||
84 | #define LPAIF_IRQ_REG_STRIDE 0x1000 | ||
85 | #define LPAIF_IRQ_REG_ADDR(addr, port) \ | ||
86 | (LPAIF_IRQ_REG_BASE + (addr) + (LPAIF_IRQ_REG_STRIDE * (port))) | ||
87 | |||
88 | enum lpaif_irq_ports { | ||
89 | LPAIF_IRQ_PORT_MIN = 0, | ||
90 | |||
91 | LPAIF_IRQ_PORT_HOST = 0, | ||
92 | LPAIF_IRQ_PORT_ADSP = 1, | ||
93 | |||
94 | LPAIF_IRQ_PORT_MAX = 2, | ||
95 | LPAIF_IRQ_PORT_NUM = 3, | ||
96 | }; | ||
97 | |||
98 | #define LPAIF_IRQEN_REG(port) LPAIF_IRQ_REG_ADDR(0x0, (port)) | ||
99 | #define LPAIF_IRQSTAT_REG(port) LPAIF_IRQ_REG_ADDR(0x4, (port)) | ||
100 | #define LPAIF_IRQCLEAR_REG(port) LPAIF_IRQ_REG_ADDR(0xC, (port)) | ||
101 | |||
102 | #define LPAIF_IRQ_BITSTRIDE 3 | ||
103 | #define LPAIF_IRQ_PER(chan) (1 << (LPAIF_IRQ_BITSTRIDE * (chan))) | ||
104 | #define LPAIF_IRQ_XRUN(chan) (2 << (LPAIF_IRQ_BITSTRIDE * (chan))) | ||
105 | #define LPAIF_IRQ_ERR(chan) (4 << (LPAIF_IRQ_BITSTRIDE * (chan))) | ||
106 | #define LPAIF_IRQ_ALL(chan) (7 << (LPAIF_IRQ_BITSTRIDE * (chan))) | ||
107 | |||
108 | /* LPAIF DMA */ | ||
109 | |||
110 | #define LPAIF_RDMA_REG_BASE 0x6000 | ||
111 | #define LPAIF_RDMA_REG_STRIDE 0x1000 | ||
112 | #define LPAIF_RDMA_REG_ADDR(addr, chan) \ | ||
113 | (LPAIF_RDMA_REG_BASE + (addr) + (LPAIF_RDMA_REG_STRIDE * (chan))) | ||
114 | |||
115 | enum lpaif_dma_channels { | ||
116 | LPAIF_RDMA_CHAN_MIN = 0, | ||
117 | |||
118 | LPAIF_RDMA_CHAN_MI2S = 0, | ||
119 | LPAIF_RDMA_CHAN_PCM0 = 1, | ||
120 | LPAIF_RDMA_CHAN_PCM1 = 2, | ||
121 | |||
122 | LPAIF_RDMA_CHAN_MAX = 4, | ||
123 | LPAIF_RDMA_CHAN_NUM = 5, | ||
124 | }; | ||
125 | |||
126 | #define LPAIF_RDMACTL_REG(chan) LPAIF_RDMA_REG_ADDR(0x00, (chan)) | ||
127 | #define LPAIF_RDMABASE_REG(chan) LPAIF_RDMA_REG_ADDR(0x04, (chan)) | ||
128 | #define LPAIF_RDMABUFF_REG(chan) LPAIF_RDMA_REG_ADDR(0x08, (chan)) | ||
129 | #define LPAIF_RDMACURR_REG(chan) LPAIF_RDMA_REG_ADDR(0x0C, (chan)) | ||
130 | #define LPAIF_RDMAPER_REG(chan) LPAIF_RDMA_REG_ADDR(0x10, (chan)) | ||
131 | |||
132 | #define LPAIF_RDMACTL_BURSTEN_MASK 0x800 | ||
133 | #define LPAIF_RDMACTL_BURSTEN_SHIFT 11 | ||
134 | #define LPAIF_RDMACTL_BURSTEN_SINGLE (0 << LPAIF_RDMACTL_BURSTEN_SHIFT) | ||
135 | #define LPAIF_RDMACTL_BURSTEN_INCR4 (1 << LPAIF_RDMACTL_BURSTEN_SHIFT) | ||
136 | |||
137 | #define LPAIF_RDMACTL_WPSCNT_MASK 0x700 | ||
138 | #define LPAIF_RDMACTL_WPSCNT_SHIFT 8 | ||
139 | #define LPAIF_RDMACTL_WPSCNT_ONE (0 << LPAIF_RDMACTL_WPSCNT_SHIFT) | ||
140 | #define LPAIF_RDMACTL_WPSCNT_TWO (1 << LPAIF_RDMACTL_WPSCNT_SHIFT) | ||
141 | #define LPAIF_RDMACTL_WPSCNT_THREE (2 << LPAIF_RDMACTL_WPSCNT_SHIFT) | ||
142 | #define LPAIF_RDMACTL_WPSCNT_FOUR (3 << LPAIF_RDMACTL_WPSCNT_SHIFT) | ||
143 | #define LPAIF_RDMACTL_WPSCNT_SIX (5 << LPAIF_RDMACTL_WPSCNT_SHIFT) | ||
144 | #define LPAIF_RDMACTL_WPSCNT_EIGHT (7 << LPAIF_RDMACTL_WPSCNT_SHIFT) | ||
145 | |||
146 | #define LPAIF_RDMACTL_AUDINTF_MASK 0x0F0 | ||
147 | #define LPAIF_RDMACTL_AUDINTF_SHIFT 4 | ||
148 | #define LPAIF_RDMACTL_AUDINTF_NONE (0 << LPAIF_RDMACTL_AUDINTF_SHIFT) | ||
149 | #define LPAIF_RDMACTL_AUDINTF_CODEC (1 << LPAIF_RDMACTL_AUDINTF_SHIFT) | ||
150 | #define LPAIF_RDMACTL_AUDINTF_PCM (2 << LPAIF_RDMACTL_AUDINTF_SHIFT) | ||
151 | #define LPAIF_RDMACTL_AUDINTF_SEC_I2S (3 << LPAIF_RDMACTL_AUDINTF_SHIFT) | ||
152 | #define LPAIF_RDMACTL_AUDINTF_MI2S (4 << LPAIF_RDMACTL_AUDINTF_SHIFT) | ||
153 | #define LPAIF_RDMACTL_AUDINTF_HDMI (5 << LPAIF_RDMACTL_AUDINTF_SHIFT) | ||
154 | #define LPAIF_RDMACTL_AUDINTF_SEC_PCM (7 << LPAIF_RDMACTL_AUDINTF_SHIFT) | ||
155 | |||
156 | #define LPAIF_RDMACTL_FIFOWM_MASK 0x00E | ||
157 | #define LPAIF_RDMACTL_FIFOWM_SHIFT 1 | ||
158 | #define LPAIF_RDMACTL_FIFOWM_1 (0 << LPAIF_RDMACTL_FIFOWM_SHIFT) | ||
159 | #define LPAIF_RDMACTL_FIFOWM_2 (1 << LPAIF_RDMACTL_FIFOWM_SHIFT) | ||
160 | #define LPAIF_RDMACTL_FIFOWM_3 (2 << LPAIF_RDMACTL_FIFOWM_SHIFT) | ||
161 | #define LPAIF_RDMACTL_FIFOWM_4 (3 << LPAIF_RDMACTL_FIFOWM_SHIFT) | ||
162 | #define LPAIF_RDMACTL_FIFOWM_5 (4 << LPAIF_RDMACTL_FIFOWM_SHIFT) | ||
163 | #define LPAIF_RDMACTL_FIFOWM_6 (5 << LPAIF_RDMACTL_FIFOWM_SHIFT) | ||
164 | #define LPAIF_RDMACTL_FIFOWM_7 (6 << LPAIF_RDMACTL_FIFOWM_SHIFT) | ||
165 | #define LPAIF_RDMACTL_FIFOWM_8 (7 << LPAIF_RDMACTL_FIFOWM_SHIFT) | ||
166 | |||
167 | #define LPAIF_RDMACTL_ENABLE_MASK 0x1 | ||
168 | #define LPAIF_RDMACTL_ENABLE_SHIFT 0 | ||
169 | #define LPAIF_RDMACTL_ENABLE_OFF (0 << LPAIF_RDMACTL_ENABLE_SHIFT) | ||
170 | #define LPAIF_RDMACTL_ENABLE_ON (1 << LPAIF_RDMACTL_ENABLE_SHIFT) | ||
171 | |||
172 | #endif /* __LPASS_LPAIF_H__ */ | ||
diff --git a/sound/soc/qcom/lpass-platform.c b/sound/soc/qcom/lpass-platform.c new file mode 100644 index 000000000000..2fa6280dfb23 --- /dev/null +++ b/sound/soc/qcom/lpass-platform.c | |||
@@ -0,0 +1,526 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 and | ||
6 | * only version 2 as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * lpass-platform.c -- ALSA SoC platform driver for QTi LPASS | ||
14 | */ | ||
15 | |||
16 | #include <linux/compiler.h> | ||
17 | #include <linux/device.h> | ||
18 | #include <linux/dma-mapping.h> | ||
19 | #include <linux/err.h> | ||
20 | #include <linux/export.h> | ||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/io.h> | ||
24 | #include <linux/platform_device.h> | ||
25 | #include <sound/memalloc.h> | ||
26 | #include <sound/pcm.h> | ||
27 | #include <sound/pcm_params.h> | ||
28 | #include <linux/regmap.h> | ||
29 | #include <sound/soc.h> | ||
30 | #include "lpass-lpaif-ipq806x.h" | ||
31 | #include "lpass.h" | ||
32 | |||
33 | #define LPASS_PLATFORM_BUFFER_SIZE (16 * 1024) | ||
34 | #define LPASS_PLATFORM_PERIODS 2 | ||
35 | |||
36 | static struct snd_pcm_hardware lpass_platform_pcm_hardware = { | ||
37 | .info = SNDRV_PCM_INFO_MMAP | | ||
38 | SNDRV_PCM_INFO_MMAP_VALID | | ||
39 | SNDRV_PCM_INFO_INTERLEAVED | | ||
40 | SNDRV_PCM_INFO_PAUSE | | ||
41 | SNDRV_PCM_INFO_RESUME, | ||
42 | .formats = SNDRV_PCM_FMTBIT_S16 | | ||
43 | SNDRV_PCM_FMTBIT_S24 | | ||
44 | SNDRV_PCM_FMTBIT_S32, | ||
45 | .rates = SNDRV_PCM_RATE_8000_192000, | ||
46 | .rate_min = 8000, | ||
47 | .rate_max = 192000, | ||
48 | .channels_min = 1, | ||
49 | .channels_max = 8, | ||
50 | .buffer_bytes_max = LPASS_PLATFORM_BUFFER_SIZE, | ||
51 | .period_bytes_max = LPASS_PLATFORM_BUFFER_SIZE / | ||
52 | LPASS_PLATFORM_PERIODS, | ||
53 | .period_bytes_min = LPASS_PLATFORM_BUFFER_SIZE / | ||
54 | LPASS_PLATFORM_PERIODS, | ||
55 | .periods_min = LPASS_PLATFORM_PERIODS, | ||
56 | .periods_max = LPASS_PLATFORM_PERIODS, | ||
57 | .fifo_size = 0, | ||
58 | }; | ||
59 | |||
60 | static int lpass_platform_pcmops_open(struct snd_pcm_substream *substream) | ||
61 | { | ||
62 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
63 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
64 | int ret; | ||
65 | |||
66 | snd_soc_set_runtime_hwparams(substream, &lpass_platform_pcm_hardware); | ||
67 | |||
68 | runtime->dma_bytes = lpass_platform_pcm_hardware.buffer_bytes_max; | ||
69 | |||
70 | ret = snd_pcm_hw_constraint_integer(runtime, | ||
71 | SNDRV_PCM_HW_PARAM_PERIODS); | ||
72 | if (ret < 0) { | ||
73 | dev_err(soc_runtime->dev, "%s() setting constraints failed: %d\n", | ||
74 | __func__, ret); | ||
75 | return -EINVAL; | ||
76 | } | ||
77 | |||
78 | snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); | ||
79 | |||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | static int lpass_platform_pcmops_hw_params(struct snd_pcm_substream *substream, | ||
84 | struct snd_pcm_hw_params *params) | ||
85 | { | ||
86 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
87 | struct lpass_data *drvdata = | ||
88 | snd_soc_platform_get_drvdata(soc_runtime->platform); | ||
89 | snd_pcm_format_t format = params_format(params); | ||
90 | unsigned int channels = params_channels(params); | ||
91 | unsigned int regval; | ||
92 | int bitwidth; | ||
93 | int ret; | ||
94 | |||
95 | bitwidth = snd_pcm_format_width(format); | ||
96 | if (bitwidth < 0) { | ||
97 | dev_err(soc_runtime->dev, "%s() invalid bit width given: %d\n", | ||
98 | __func__, bitwidth); | ||
99 | return bitwidth; | ||
100 | } | ||
101 | |||
102 | regval = LPAIF_RDMACTL_BURSTEN_INCR4 | | ||
103 | LPAIF_RDMACTL_AUDINTF_MI2S | | ||
104 | LPAIF_RDMACTL_FIFOWM_8; | ||
105 | |||
106 | switch (bitwidth) { | ||
107 | case 16: | ||
108 | switch (channels) { | ||
109 | case 1: | ||
110 | case 2: | ||
111 | regval |= LPAIF_RDMACTL_WPSCNT_ONE; | ||
112 | break; | ||
113 | case 4: | ||
114 | regval |= LPAIF_RDMACTL_WPSCNT_TWO; | ||
115 | break; | ||
116 | case 6: | ||
117 | regval |= LPAIF_RDMACTL_WPSCNT_THREE; | ||
118 | break; | ||
119 | case 8: | ||
120 | regval |= LPAIF_RDMACTL_WPSCNT_FOUR; | ||
121 | break; | ||
122 | default: | ||
123 | dev_err(soc_runtime->dev, "%s() invalid PCM config given: bw=%d, ch=%u\n", | ||
124 | __func__, bitwidth, channels); | ||
125 | return -EINVAL; | ||
126 | } | ||
127 | break; | ||
128 | case 24: | ||
129 | case 32: | ||
130 | switch (channels) { | ||
131 | case 1: | ||
132 | regval |= LPAIF_RDMACTL_WPSCNT_ONE; | ||
133 | break; | ||
134 | case 2: | ||
135 | regval |= LPAIF_RDMACTL_WPSCNT_TWO; | ||
136 | break; | ||
137 | case 4: | ||
138 | regval |= LPAIF_RDMACTL_WPSCNT_FOUR; | ||
139 | break; | ||
140 | case 6: | ||
141 | regval |= LPAIF_RDMACTL_WPSCNT_SIX; | ||
142 | break; | ||
143 | case 8: | ||
144 | regval |= LPAIF_RDMACTL_WPSCNT_EIGHT; | ||
145 | break; | ||
146 | default: | ||
147 | dev_err(soc_runtime->dev, "%s() invalid PCM config given: bw=%d, ch=%u\n", | ||
148 | __func__, bitwidth, channels); | ||
149 | return -EINVAL; | ||
150 | } | ||
151 | break; | ||
152 | default: | ||
153 | dev_err(soc_runtime->dev, "%s() invalid PCM config given: bw=%d, ch=%u\n", | ||
154 | __func__, bitwidth, channels); | ||
155 | return -EINVAL; | ||
156 | } | ||
157 | |||
158 | ret = regmap_write(drvdata->lpaif_map, | ||
159 | LPAIF_RDMACTL_REG(LPAIF_RDMA_CHAN_MI2S), regval); | ||
160 | if (ret) { | ||
161 | dev_err(soc_runtime->dev, "%s() error writing to rdmactl reg: %d\n", | ||
162 | __func__, ret); | ||
163 | return ret; | ||
164 | } | ||
165 | |||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | static int lpass_platform_pcmops_hw_free(struct snd_pcm_substream *substream) | ||
170 | { | ||
171 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
172 | struct lpass_data *drvdata = | ||
173 | snd_soc_platform_get_drvdata(soc_runtime->platform); | ||
174 | int ret; | ||
175 | |||
176 | ret = regmap_write(drvdata->lpaif_map, | ||
177 | LPAIF_RDMACTL_REG(LPAIF_RDMA_CHAN_MI2S), 0); | ||
178 | if (ret) | ||
179 | dev_err(soc_runtime->dev, "%s() error writing to rdmactl reg: %d\n", | ||
180 | __func__, ret); | ||
181 | |||
182 | return ret; | ||
183 | } | ||
184 | |||
185 | static int lpass_platform_pcmops_prepare(struct snd_pcm_substream *substream) | ||
186 | { | ||
187 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
188 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
189 | struct lpass_data *drvdata = | ||
190 | snd_soc_platform_get_drvdata(soc_runtime->platform); | ||
191 | int ret; | ||
192 | |||
193 | ret = regmap_write(drvdata->lpaif_map, | ||
194 | LPAIF_RDMABASE_REG(LPAIF_RDMA_CHAN_MI2S), | ||
195 | runtime->dma_addr); | ||
196 | if (ret) { | ||
197 | dev_err(soc_runtime->dev, "%s() error writing to rdmabase reg: %d\n", | ||
198 | __func__, ret); | ||
199 | return ret; | ||
200 | } | ||
201 | |||
202 | ret = regmap_write(drvdata->lpaif_map, | ||
203 | LPAIF_RDMABUFF_REG(LPAIF_RDMA_CHAN_MI2S), | ||
204 | (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1); | ||
205 | if (ret) { | ||
206 | dev_err(soc_runtime->dev, "%s() error writing to rdmabuff reg: %d\n", | ||
207 | __func__, ret); | ||
208 | return ret; | ||
209 | } | ||
210 | |||
211 | ret = regmap_write(drvdata->lpaif_map, | ||
212 | LPAIF_RDMAPER_REG(LPAIF_RDMA_CHAN_MI2S), | ||
213 | (snd_pcm_lib_period_bytes(substream) >> 2) - 1); | ||
214 | if (ret) { | ||
215 | dev_err(soc_runtime->dev, "%s() error writing to rdmaper reg: %d\n", | ||
216 | __func__, ret); | ||
217 | return ret; | ||
218 | } | ||
219 | |||
220 | ret = regmap_update_bits(drvdata->lpaif_map, | ||
221 | LPAIF_RDMACTL_REG(LPAIF_RDMA_CHAN_MI2S), | ||
222 | LPAIF_RDMACTL_ENABLE_MASK, LPAIF_RDMACTL_ENABLE_ON); | ||
223 | if (ret) { | ||
224 | dev_err(soc_runtime->dev, "%s() error writing to rdmactl reg: %d\n", | ||
225 | __func__, ret); | ||
226 | return ret; | ||
227 | } | ||
228 | |||
229 | return 0; | ||
230 | } | ||
231 | |||
232 | static int lpass_platform_pcmops_trigger(struct snd_pcm_substream *substream, | ||
233 | int cmd) | ||
234 | { | ||
235 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
236 | struct lpass_data *drvdata = | ||
237 | snd_soc_platform_get_drvdata(soc_runtime->platform); | ||
238 | int ret; | ||
239 | |||
240 | switch (cmd) { | ||
241 | case SNDRV_PCM_TRIGGER_START: | ||
242 | case SNDRV_PCM_TRIGGER_RESUME: | ||
243 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
244 | /* clear status before enabling interrupts */ | ||
245 | ret = regmap_write(drvdata->lpaif_map, | ||
246 | LPAIF_IRQCLEAR_REG(LPAIF_IRQ_PORT_HOST), | ||
247 | LPAIF_IRQ_ALL(LPAIF_RDMA_CHAN_MI2S)); | ||
248 | if (ret) { | ||
249 | dev_err(soc_runtime->dev, "%s() error writing to irqclear reg: %d\n", | ||
250 | __func__, ret); | ||
251 | return ret; | ||
252 | } | ||
253 | |||
254 | ret = regmap_update_bits(drvdata->lpaif_map, | ||
255 | LPAIF_IRQEN_REG(LPAIF_IRQ_PORT_HOST), | ||
256 | LPAIF_IRQ_ALL(LPAIF_RDMA_CHAN_MI2S), | ||
257 | LPAIF_IRQ_ALL(LPAIF_RDMA_CHAN_MI2S)); | ||
258 | if (ret) { | ||
259 | dev_err(soc_runtime->dev, "%s() error writing to irqen reg: %d\n", | ||
260 | __func__, ret); | ||
261 | return ret; | ||
262 | } | ||
263 | |||
264 | ret = regmap_update_bits(drvdata->lpaif_map, | ||
265 | LPAIF_RDMACTL_REG(LPAIF_RDMA_CHAN_MI2S), | ||
266 | LPAIF_RDMACTL_ENABLE_MASK, | ||
267 | LPAIF_RDMACTL_ENABLE_ON); | ||
268 | if (ret) { | ||
269 | dev_err(soc_runtime->dev, "%s() error writing to rdmactl reg: %d\n", | ||
270 | __func__, ret); | ||
271 | return ret; | ||
272 | } | ||
273 | break; | ||
274 | case SNDRV_PCM_TRIGGER_STOP: | ||
275 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
276 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
277 | ret = regmap_update_bits(drvdata->lpaif_map, | ||
278 | LPAIF_RDMACTL_REG(LPAIF_RDMA_CHAN_MI2S), | ||
279 | LPAIF_RDMACTL_ENABLE_MASK, | ||
280 | LPAIF_RDMACTL_ENABLE_OFF); | ||
281 | if (ret) { | ||
282 | dev_err(soc_runtime->dev, "%s() error writing to rdmactl reg: %d\n", | ||
283 | __func__, ret); | ||
284 | return ret; | ||
285 | } | ||
286 | |||
287 | ret = regmap_update_bits(drvdata->lpaif_map, | ||
288 | LPAIF_IRQEN_REG(LPAIF_IRQ_PORT_HOST), | ||
289 | LPAIF_IRQ_ALL(LPAIF_RDMA_CHAN_MI2S), 0); | ||
290 | if (ret) { | ||
291 | dev_err(soc_runtime->dev, "%s() error writing to irqen reg: %d\n", | ||
292 | __func__, ret); | ||
293 | return ret; | ||
294 | } | ||
295 | break; | ||
296 | } | ||
297 | |||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | static snd_pcm_uframes_t lpass_platform_pcmops_pointer( | ||
302 | struct snd_pcm_substream *substream) | ||
303 | { | ||
304 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
305 | struct lpass_data *drvdata = | ||
306 | snd_soc_platform_get_drvdata(soc_runtime->platform); | ||
307 | unsigned int base_addr, curr_addr; | ||
308 | int ret; | ||
309 | |||
310 | ret = regmap_read(drvdata->lpaif_map, | ||
311 | LPAIF_RDMABASE_REG(LPAIF_RDMA_CHAN_MI2S), &base_addr); | ||
312 | if (ret) { | ||
313 | dev_err(soc_runtime->dev, "%s() error reading from rdmabase reg: %d\n", | ||
314 | __func__, ret); | ||
315 | return ret; | ||
316 | } | ||
317 | |||
318 | ret = regmap_read(drvdata->lpaif_map, | ||
319 | LPAIF_RDMACURR_REG(LPAIF_RDMA_CHAN_MI2S), &curr_addr); | ||
320 | if (ret) { | ||
321 | dev_err(soc_runtime->dev, "%s() error reading from rdmacurr reg: %d\n", | ||
322 | __func__, ret); | ||
323 | return ret; | ||
324 | } | ||
325 | |||
326 | return bytes_to_frames(substream->runtime, curr_addr - base_addr); | ||
327 | } | ||
328 | |||
329 | static int lpass_platform_pcmops_mmap(struct snd_pcm_substream *substream, | ||
330 | struct vm_area_struct *vma) | ||
331 | { | ||
332 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
333 | |||
334 | return dma_mmap_coherent(substream->pcm->card->dev, vma, | ||
335 | runtime->dma_area, runtime->dma_addr, | ||
336 | runtime->dma_bytes); | ||
337 | } | ||
338 | |||
339 | static struct snd_pcm_ops lpass_platform_pcm_ops = { | ||
340 | .open = lpass_platform_pcmops_open, | ||
341 | .ioctl = snd_pcm_lib_ioctl, | ||
342 | .hw_params = lpass_platform_pcmops_hw_params, | ||
343 | .hw_free = lpass_platform_pcmops_hw_free, | ||
344 | .prepare = lpass_platform_pcmops_prepare, | ||
345 | .trigger = lpass_platform_pcmops_trigger, | ||
346 | .pointer = lpass_platform_pcmops_pointer, | ||
347 | .mmap = lpass_platform_pcmops_mmap, | ||
348 | }; | ||
349 | |||
350 | static irqreturn_t lpass_platform_lpaif_irq(int irq, void *data) | ||
351 | { | ||
352 | struct snd_pcm_substream *substream = data; | ||
353 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
354 | struct lpass_data *drvdata = | ||
355 | snd_soc_platform_get_drvdata(soc_runtime->platform); | ||
356 | unsigned int interrupts; | ||
357 | irqreturn_t ret = IRQ_NONE; | ||
358 | int rv; | ||
359 | |||
360 | rv = regmap_read(drvdata->lpaif_map, | ||
361 | LPAIF_IRQSTAT_REG(LPAIF_IRQ_PORT_HOST), &interrupts); | ||
362 | if (rv) { | ||
363 | dev_err(soc_runtime->dev, "%s() error reading from irqstat reg: %d\n", | ||
364 | __func__, rv); | ||
365 | return IRQ_NONE; | ||
366 | } | ||
367 | interrupts &= LPAIF_IRQ_ALL(LPAIF_RDMA_CHAN_MI2S); | ||
368 | |||
369 | if (interrupts & LPAIF_IRQ_PER(LPAIF_RDMA_CHAN_MI2S)) { | ||
370 | rv = regmap_write(drvdata->lpaif_map, | ||
371 | LPAIF_IRQCLEAR_REG(LPAIF_IRQ_PORT_HOST), | ||
372 | LPAIF_IRQ_PER(LPAIF_RDMA_CHAN_MI2S)); | ||
373 | if (rv) { | ||
374 | dev_err(soc_runtime->dev, "%s() error writing to irqclear reg: %d\n", | ||
375 | __func__, rv); | ||
376 | return IRQ_NONE; | ||
377 | } | ||
378 | snd_pcm_period_elapsed(substream); | ||
379 | ret = IRQ_HANDLED; | ||
380 | } | ||
381 | |||
382 | if (interrupts & LPAIF_IRQ_XRUN(LPAIF_RDMA_CHAN_MI2S)) { | ||
383 | rv = regmap_write(drvdata->lpaif_map, | ||
384 | LPAIF_IRQCLEAR_REG(LPAIF_IRQ_PORT_HOST), | ||
385 | LPAIF_IRQ_XRUN(LPAIF_RDMA_CHAN_MI2S)); | ||
386 | if (rv) { | ||
387 | dev_err(soc_runtime->dev, "%s() error writing to irqclear reg: %d\n", | ||
388 | __func__, rv); | ||
389 | return IRQ_NONE; | ||
390 | } | ||
391 | dev_warn(soc_runtime->dev, "%s() xrun warning\n", __func__); | ||
392 | snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); | ||
393 | ret = IRQ_HANDLED; | ||
394 | } | ||
395 | |||
396 | if (interrupts & LPAIF_IRQ_ERR(LPAIF_RDMA_CHAN_MI2S)) { | ||
397 | rv = regmap_write(drvdata->lpaif_map, | ||
398 | LPAIF_IRQCLEAR_REG(LPAIF_IRQ_PORT_HOST), | ||
399 | LPAIF_IRQ_ERR(LPAIF_RDMA_CHAN_MI2S)); | ||
400 | if (rv) { | ||
401 | dev_err(soc_runtime->dev, "%s() error writing to irqclear reg: %d\n", | ||
402 | __func__, rv); | ||
403 | return IRQ_NONE; | ||
404 | } | ||
405 | dev_err(soc_runtime->dev, "%s() bus access error\n", __func__); | ||
406 | snd_pcm_stop(substream, SNDRV_PCM_STATE_DISCONNECTED); | ||
407 | ret = IRQ_HANDLED; | ||
408 | } | ||
409 | |||
410 | return ret; | ||
411 | } | ||
412 | |||
413 | static int lpass_platform_alloc_buffer(struct snd_pcm_substream *substream, | ||
414 | struct snd_soc_pcm_runtime *soc_runtime) | ||
415 | { | ||
416 | struct snd_dma_buffer *buf = &substream->dma_buffer; | ||
417 | size_t size = lpass_platform_pcm_hardware.buffer_bytes_max; | ||
418 | |||
419 | buf->dev.type = SNDRV_DMA_TYPE_DEV; | ||
420 | buf->dev.dev = soc_runtime->dev; | ||
421 | buf->private_data = NULL; | ||
422 | buf->area = dma_alloc_coherent(soc_runtime->dev, size, &buf->addr, | ||
423 | GFP_KERNEL); | ||
424 | if (!buf->area) { | ||
425 | dev_err(soc_runtime->dev, "%s: Could not allocate DMA buffer\n", | ||
426 | __func__); | ||
427 | return -ENOMEM; | ||
428 | } | ||
429 | buf->bytes = size; | ||
430 | |||
431 | return 0; | ||
432 | } | ||
433 | |||
434 | static void lpass_platform_free_buffer(struct snd_pcm_substream *substream, | ||
435 | struct snd_soc_pcm_runtime *soc_runtime) | ||
436 | { | ||
437 | struct snd_dma_buffer *buf = &substream->dma_buffer; | ||
438 | |||
439 | if (buf->area) { | ||
440 | dma_free_coherent(soc_runtime->dev, buf->bytes, buf->area, | ||
441 | buf->addr); | ||
442 | } | ||
443 | buf->area = NULL; | ||
444 | } | ||
445 | |||
446 | static int lpass_platform_pcm_new(struct snd_soc_pcm_runtime *soc_runtime) | ||
447 | { | ||
448 | struct snd_pcm *pcm = soc_runtime->pcm; | ||
449 | struct snd_pcm_substream *substream = | ||
450 | pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; | ||
451 | struct lpass_data *drvdata = | ||
452 | snd_soc_platform_get_drvdata(soc_runtime->platform); | ||
453 | int ret; | ||
454 | |||
455 | soc_runtime->dev->coherent_dma_mask = DMA_BIT_MASK(32); | ||
456 | soc_runtime->dev->dma_mask = &soc_runtime->dev->coherent_dma_mask; | ||
457 | |||
458 | ret = lpass_platform_alloc_buffer(substream, soc_runtime); | ||
459 | if (ret) | ||
460 | return ret; | ||
461 | |||
462 | ret = devm_request_irq(soc_runtime->dev, drvdata->lpaif_irq, | ||
463 | lpass_platform_lpaif_irq, IRQF_TRIGGER_RISING, | ||
464 | "lpass-irq-lpaif", substream); | ||
465 | if (ret) { | ||
466 | dev_err(soc_runtime->dev, "%s() irq request failed: %d\n", | ||
467 | __func__, ret); | ||
468 | goto err_buf; | ||
469 | } | ||
470 | |||
471 | /* ensure audio hardware is disabled */ | ||
472 | ret = regmap_write(drvdata->lpaif_map, | ||
473 | LPAIF_IRQEN_REG(LPAIF_IRQ_PORT_HOST), 0); | ||
474 | if (ret) { | ||
475 | dev_err(soc_runtime->dev, "%s() error writing to irqen reg: %d\n", | ||
476 | __func__, ret); | ||
477 | return ret; | ||
478 | } | ||
479 | ret = regmap_write(drvdata->lpaif_map, | ||
480 | LPAIF_RDMACTL_REG(LPAIF_RDMA_CHAN_MI2S), 0); | ||
481 | if (ret) { | ||
482 | dev_err(soc_runtime->dev, "%s() error writing to rdmactl reg: %d\n", | ||
483 | __func__, ret); | ||
484 | return ret; | ||
485 | } | ||
486 | |||
487 | return 0; | ||
488 | |||
489 | err_buf: | ||
490 | lpass_platform_free_buffer(substream, soc_runtime); | ||
491 | return ret; | ||
492 | } | ||
493 | |||
494 | static void lpass_platform_pcm_free(struct snd_pcm *pcm) | ||
495 | { | ||
496 | struct snd_pcm_substream *substream = | ||
497 | pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; | ||
498 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
499 | |||
500 | lpass_platform_free_buffer(substream, soc_runtime); | ||
501 | } | ||
502 | |||
503 | static struct snd_soc_platform_driver lpass_platform_driver = { | ||
504 | .pcm_new = lpass_platform_pcm_new, | ||
505 | .pcm_free = lpass_platform_pcm_free, | ||
506 | .ops = &lpass_platform_pcm_ops, | ||
507 | }; | ||
508 | |||
509 | int asoc_qcom_lpass_platform_register(struct platform_device *pdev) | ||
510 | { | ||
511 | struct lpass_data *drvdata = platform_get_drvdata(pdev); | ||
512 | |||
513 | drvdata->lpaif_irq = platform_get_irq_byname(pdev, "lpass-irq-lpaif"); | ||
514 | if (drvdata->lpaif_irq < 0) { | ||
515 | dev_err(&pdev->dev, "%s() error getting irq handle: %d\n", | ||
516 | __func__, drvdata->lpaif_irq); | ||
517 | return -ENODEV; | ||
518 | } | ||
519 | |||
520 | return devm_snd_soc_register_platform(&pdev->dev, | ||
521 | &lpass_platform_driver); | ||
522 | } | ||
523 | EXPORT_SYMBOL_GPL(asoc_qcom_lpass_platform_register); | ||
524 | |||
525 | MODULE_DESCRIPTION("QTi LPASS Platform Driver"); | ||
526 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/sound/soc/qcom/lpass.h b/sound/soc/qcom/lpass.h new file mode 100644 index 000000000000..5c99b3dace86 --- /dev/null +++ b/sound/soc/qcom/lpass.h | |||
@@ -0,0 +1,51 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 and | ||
6 | * only version 2 as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * lpass.h - Definitions for the QTi LPASS | ||
14 | */ | ||
15 | |||
16 | #ifndef __LPASS_H__ | ||
17 | #define __LPASS_H__ | ||
18 | |||
19 | #include <linux/clk.h> | ||
20 | #include <linux/compiler.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | #include <linux/regmap.h> | ||
23 | |||
24 | #define LPASS_AHBIX_CLOCK_FREQUENCY 131072000 | ||
25 | |||
26 | /* Both the CPU DAI and platform drivers will access this data */ | ||
27 | struct lpass_data { | ||
28 | |||
29 | /* AHB-I/X bus clocks inside the low-power audio subsystem (LPASS) */ | ||
30 | struct clk *ahbix_clk; | ||
31 | |||
32 | /* MI2S system clock */ | ||
33 | struct clk *mi2s_osr_clk; | ||
34 | |||
35 | /* MI2S bit clock (derived from system clock by a divider */ | ||
36 | struct clk *mi2s_bit_clk; | ||
37 | |||
38 | /* low-power audio interface (LPAIF) registers */ | ||
39 | void __iomem *lpaif; | ||
40 | |||
41 | /* regmap backed by the low-power audio interface (LPAIF) registers */ | ||
42 | struct regmap *lpaif_map; | ||
43 | |||
44 | /* interrupts from the low-power audio interface (LPAIF) */ | ||
45 | int lpaif_irq; | ||
46 | }; | ||
47 | |||
48 | /* register the platform driver from the CPU DAI driver */ | ||
49 | int asoc_qcom_lpass_platform_register(struct platform_device *); | ||
50 | |||
51 | #endif /* __LPASS_H__ */ | ||
diff --git a/sound/soc/qcom/storm.c b/sound/soc/qcom/storm.c new file mode 100644 index 000000000000..b8bd296190ad --- /dev/null +++ b/sound/soc/qcom/storm.c | |||
@@ -0,0 +1,162 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 and | ||
6 | * only version 2 as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * storm.c -- ALSA SoC machine driver for QTi ipq806x-based Storm board | ||
14 | */ | ||
15 | |||
16 | #include <linux/device.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/of.h> | ||
19 | #include <linux/mod_devicetable.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | #include <sound/pcm.h> | ||
22 | #include <sound/pcm_params.h> | ||
23 | #include <sound/soc.h> | ||
24 | |||
25 | #define STORM_SYSCLK_MULT 4 | ||
26 | |||
27 | static int storm_ops_hw_params(struct snd_pcm_substream *substream, | ||
28 | struct snd_pcm_hw_params *params) | ||
29 | { | ||
30 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
31 | struct snd_soc_card *card = soc_runtime->card; | ||
32 | snd_pcm_format_t format = params_format(params); | ||
33 | unsigned int rate = params_rate(params); | ||
34 | unsigned int sysclk_freq; | ||
35 | int bitwidth, ret; | ||
36 | |||
37 | bitwidth = snd_pcm_format_width(format); | ||
38 | if (bitwidth < 0) { | ||
39 | dev_err(card->dev, "%s() invalid bit width given: %d\n", | ||
40 | __func__, bitwidth); | ||
41 | return bitwidth; | ||
42 | } | ||
43 | |||
44 | /* | ||
45 | * as the CPU DAI is the I2S bus master and no system clock is needed by | ||
46 | * the MAX98357a DAC, simply set the system clock to be a constant | ||
47 | * multiple of the bit clock for the clock divider | ||
48 | */ | ||
49 | sysclk_freq = rate * bitwidth * 2 * STORM_SYSCLK_MULT; | ||
50 | |||
51 | ret = snd_soc_dai_set_sysclk(soc_runtime->cpu_dai, 0, sysclk_freq, 0); | ||
52 | if (ret) { | ||
53 | dev_err(card->dev, "%s() error setting sysclk to %u: %d\n", | ||
54 | __func__, sysclk_freq, ret); | ||
55 | return ret; | ||
56 | } | ||
57 | |||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | static struct snd_soc_ops storm_soc_ops = { | ||
62 | .hw_params = storm_ops_hw_params, | ||
63 | }; | ||
64 | |||
65 | static struct snd_soc_dai_link storm_dai_link = { | ||
66 | .name = "Primary", | ||
67 | .stream_name = "Primary", | ||
68 | .codec_dai_name = "HiFi", | ||
69 | .ops = &storm_soc_ops, | ||
70 | }; | ||
71 | |||
72 | static struct snd_soc_card storm_soc_card = { | ||
73 | .name = "ipq806x-storm", | ||
74 | .dev = NULL, | ||
75 | }; | ||
76 | |||
77 | static int storm_parse_of(struct snd_soc_card *card) | ||
78 | { | ||
79 | struct snd_soc_dai_link *dai_link = card->dai_link; | ||
80 | struct device_node *np = card->dev->of_node; | ||
81 | |||
82 | dai_link->cpu_of_node = of_parse_phandle(np, "cpu", 0); | ||
83 | if (!dai_link->cpu_of_node) { | ||
84 | dev_err(card->dev, "%s() error getting cpu phandle\n", | ||
85 | __func__); | ||
86 | return -EINVAL; | ||
87 | } | ||
88 | dai_link->platform_of_node = dai_link->cpu_of_node; | ||
89 | |||
90 | dai_link->codec_of_node = of_parse_phandle(np, "codec", 0); | ||
91 | if (!dai_link->codec_of_node) { | ||
92 | dev_err(card->dev, "%s() error getting codec phandle\n", | ||
93 | __func__); | ||
94 | return -EINVAL; | ||
95 | } | ||
96 | |||
97 | return 0; | ||
98 | } | ||
99 | |||
100 | static int storm_platform_probe(struct platform_device *pdev) | ||
101 | { | ||
102 | struct snd_soc_card *card = &storm_soc_card; | ||
103 | int ret; | ||
104 | |||
105 | if (card->dev) { | ||
106 | dev_err(&pdev->dev, "%s() error, existing soundcard\n", | ||
107 | __func__); | ||
108 | return -ENODEV; | ||
109 | } | ||
110 | card->dev = &pdev->dev; | ||
111 | platform_set_drvdata(pdev, card); | ||
112 | |||
113 | ret = snd_soc_of_parse_card_name(card, "qcom,model"); | ||
114 | if (ret) { | ||
115 | dev_err(&pdev->dev, "%s() error parsing card name: %d\n", | ||
116 | __func__, ret); | ||
117 | return ret; | ||
118 | } | ||
119 | |||
120 | card->dai_link = &storm_dai_link; | ||
121 | card->num_links = 1; | ||
122 | |||
123 | ret = storm_parse_of(card); | ||
124 | if (ret) { | ||
125 | dev_err(&pdev->dev, "%s() error resolving dai links: %d\n", | ||
126 | __func__, ret); | ||
127 | return ret; | ||
128 | } | ||
129 | |||
130 | ret = devm_snd_soc_register_card(&pdev->dev, card); | ||
131 | if (ret == -EPROBE_DEFER) { | ||
132 | card->dev = NULL; | ||
133 | return ret; | ||
134 | } else if (ret) { | ||
135 | dev_err(&pdev->dev, "%s() error registering soundcard: %d\n", | ||
136 | __func__, ret); | ||
137 | return ret; | ||
138 | } | ||
139 | |||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | #ifdef CONFIG_OF | ||
144 | static const struct of_device_id storm_device_id[] = { | ||
145 | { .compatible = "google,storm-audio" }, | ||
146 | {}, | ||
147 | }; | ||
148 | MODULE_DEVICE_TABLE(of, storm_device_id); | ||
149 | #endif | ||
150 | |||
151 | static struct platform_driver storm_platform_driver = { | ||
152 | .driver = { | ||
153 | .name = "storm-audio", | ||
154 | .of_match_table = | ||
155 | of_match_ptr(storm_device_id), | ||
156 | }, | ||
157 | .probe = storm_platform_probe, | ||
158 | }; | ||
159 | module_platform_driver(storm_platform_driver); | ||
160 | |||
161 | MODULE_DESCRIPTION("QTi IPQ806x-based Storm Machine Driver"); | ||
162 | MODULE_LICENSE("GPL v2"); | ||
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 | ||
163 | static int h1940_uda1380_init(struct snd_soc_pcm_runtime *rtd) | 163 | static 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 | ||
212 | static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd) | 212 | static 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/sh/Kconfig b/sound/soc/sh/Kconfig index 80245b6eebd6..07114b0b0dc1 100644 --- a/sound/soc/sh/Kconfig +++ b/sound/soc/sh/Kconfig | |||
@@ -36,11 +36,17 @@ config SND_SOC_SH4_SIU | |||
36 | 36 | ||
37 | config SND_SOC_RCAR | 37 | config SND_SOC_RCAR |
38 | tristate "R-Car series SRU/SCU/SSIU/SSI support" | 38 | tristate "R-Car series SRU/SCU/SSIU/SSI support" |
39 | depends on DMA_OF | ||
39 | select SND_SIMPLE_CARD | 40 | select SND_SIMPLE_CARD |
40 | select REGMAP_MMIO | 41 | select REGMAP_MMIO |
41 | help | 42 | help |
42 | This option enables R-Car SUR/SCU/SSIU/SSI sound support | 43 | This option enables R-Car SUR/SCU/SSIU/SSI sound support |
43 | 44 | ||
45 | config SND_SOC_RSRC_CARD | ||
46 | tristate "Renesas Sampling Rate Convert Sound Card" | ||
47 | help | ||
48 | This option enables simple sound if you need sampling rate convert | ||
49 | |||
44 | ## | 50 | ## |
45 | ## Boards | 51 | ## Boards |
46 | ## | 52 | ## |
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c index b87b22e88e43..0c2af21b0b82 100644 --- a/sound/soc/sh/fsi.c +++ b/sound/soc/sh/fsi.c | |||
@@ -1876,7 +1876,40 @@ static void fsi_handler_init(struct fsi_priv *fsi, | |||
1876 | } | 1876 | } |
1877 | } | 1877 | } |
1878 | 1878 | ||
1879 | static struct of_device_id fsi_of_match[]; | 1879 | static const struct fsi_core fsi1_core = { |
1880 | .ver = 1, | ||
1881 | |||
1882 | /* Interrupt */ | ||
1883 | .int_st = INT_ST, | ||
1884 | .iemsk = IEMSK, | ||
1885 | .imsk = IMSK, | ||
1886 | }; | ||
1887 | |||
1888 | static const struct fsi_core fsi2_core = { | ||
1889 | .ver = 2, | ||
1890 | |||
1891 | /* Interrupt */ | ||
1892 | .int_st = CPU_INT_ST, | ||
1893 | .iemsk = CPU_IEMSK, | ||
1894 | .imsk = CPU_IMSK, | ||
1895 | .a_mclk = A_MST_CTLR, | ||
1896 | .b_mclk = B_MST_CTLR, | ||
1897 | }; | ||
1898 | |||
1899 | static const struct of_device_id fsi_of_match[] = { | ||
1900 | { .compatible = "renesas,sh_fsi", .data = &fsi1_core}, | ||
1901 | { .compatible = "renesas,sh_fsi2", .data = &fsi2_core}, | ||
1902 | {}, | ||
1903 | }; | ||
1904 | MODULE_DEVICE_TABLE(of, fsi_of_match); | ||
1905 | |||
1906 | static const struct platform_device_id fsi_id_table[] = { | ||
1907 | { "sh_fsi", (kernel_ulong_t)&fsi1_core }, | ||
1908 | { "sh_fsi2", (kernel_ulong_t)&fsi2_core }, | ||
1909 | {}, | ||
1910 | }; | ||
1911 | MODULE_DEVICE_TABLE(platform, fsi_id_table); | ||
1912 | |||
1880 | static int fsi_probe(struct platform_device *pdev) | 1913 | static int fsi_probe(struct platform_device *pdev) |
1881 | { | 1914 | { |
1882 | struct fsi_master *master; | 1915 | struct fsi_master *master; |
@@ -2072,40 +2105,6 @@ static struct dev_pm_ops fsi_pm_ops = { | |||
2072 | .resume = fsi_resume, | 2105 | .resume = fsi_resume, |
2073 | }; | 2106 | }; |
2074 | 2107 | ||
2075 | static struct fsi_core fsi1_core = { | ||
2076 | .ver = 1, | ||
2077 | |||
2078 | /* Interrupt */ | ||
2079 | .int_st = INT_ST, | ||
2080 | .iemsk = IEMSK, | ||
2081 | .imsk = IMSK, | ||
2082 | }; | ||
2083 | |||
2084 | static struct fsi_core fsi2_core = { | ||
2085 | .ver = 2, | ||
2086 | |||
2087 | /* Interrupt */ | ||
2088 | .int_st = CPU_INT_ST, | ||
2089 | .iemsk = CPU_IEMSK, | ||
2090 | .imsk = CPU_IMSK, | ||
2091 | .a_mclk = A_MST_CTLR, | ||
2092 | .b_mclk = B_MST_CTLR, | ||
2093 | }; | ||
2094 | |||
2095 | static struct of_device_id fsi_of_match[] = { | ||
2096 | { .compatible = "renesas,sh_fsi", .data = &fsi1_core}, | ||
2097 | { .compatible = "renesas,sh_fsi2", .data = &fsi2_core}, | ||
2098 | {}, | ||
2099 | }; | ||
2100 | MODULE_DEVICE_TABLE(of, fsi_of_match); | ||
2101 | |||
2102 | static struct platform_device_id fsi_id_table[] = { | ||
2103 | { "sh_fsi", (kernel_ulong_t)&fsi1_core }, | ||
2104 | { "sh_fsi2", (kernel_ulong_t)&fsi2_core }, | ||
2105 | {}, | ||
2106 | }; | ||
2107 | MODULE_DEVICE_TABLE(platform, fsi_id_table); | ||
2108 | |||
2109 | static struct platform_driver fsi_driver = { | 2108 | static struct platform_driver fsi_driver = { |
2110 | .driver = { | 2109 | .driver = { |
2111 | .name = "fsi-pcm-audio", | 2110 | .name = "fsi-pcm-audio", |
@@ -2119,7 +2118,7 @@ static struct platform_driver fsi_driver = { | |||
2119 | 2118 | ||
2120 | module_platform_driver(fsi_driver); | 2119 | module_platform_driver(fsi_driver); |
2121 | 2120 | ||
2122 | MODULE_LICENSE("GPL"); | 2121 | MODULE_LICENSE("GPL v2"); |
2123 | MODULE_DESCRIPTION("SuperH onchip FSI audio driver"); | 2122 | MODULE_DESCRIPTION("SuperH onchip FSI audio driver"); |
2124 | MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>"); | 2123 | MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>"); |
2125 | MODULE_ALIAS("platform:fsi-pcm-audio"); | 2124 | MODULE_ALIAS("platform:fsi-pcm-audio"); |
diff --git a/sound/soc/sh/rcar/Makefile b/sound/soc/sh/rcar/Makefile index 9ac536429800..f1b445173fba 100644 --- a/sound/soc/sh/rcar/Makefile +++ b/sound/soc/sh/rcar/Makefile | |||
@@ -1,2 +1,5 @@ | |||
1 | snd-soc-rcar-objs := core.o gen.o src.o adg.o ssi.o dvc.o | 1 | snd-soc-rcar-objs := core.o gen.o dma.o src.o adg.o ssi.o dvc.o |
2 | obj-$(CONFIG_SND_SOC_RCAR) += snd-soc-rcar.o \ No newline at end of file | 2 | obj-$(CONFIG_SND_SOC_RCAR) += snd-soc-rcar.o |
3 | |||
4 | snd-soc-rsrc-card-objs := rsrc-card.o | ||
5 | obj-$(CONFIG_SND_SOC_RSRC_CARD) += snd-soc-rsrc-card.o | ||
diff --git a/sound/soc/sh/rcar/adg.c b/sound/soc/sh/rcar/adg.c index 7ac35c9d1cb8..fefc881dbac2 100644 --- a/sound/soc/sh/rcar/adg.c +++ b/sound/soc/sh/rcar/adg.c | |||
@@ -183,6 +183,8 @@ int rsnd_adg_set_convert_clk_gen2(struct rsnd_mod *mod, | |||
183 | 183 | ||
184 | rsnd_mod_bset(mod, DIV_EN, en, en); | 184 | rsnd_mod_bset(mod, DIV_EN, en, en); |
185 | 185 | ||
186 | dev_dbg(dev, "convert rate %d <-> %d\n", src_rate, dst_rate); | ||
187 | |||
186 | return 0; | 188 | return 0; |
187 | } | 189 | } |
188 | 190 | ||
@@ -432,7 +434,5 @@ int rsnd_adg_probe(struct platform_device *pdev, | |||
432 | 434 | ||
433 | priv->adg = adg; | 435 | priv->adg = adg; |
434 | 436 | ||
435 | dev_dbg(dev, "adg probed\n"); | ||
436 | |||
437 | return 0; | 437 | return 0; |
438 | } | 438 | } |
diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c index 110577c52317..9f48d75fa992 100644 --- a/sound/soc/sh/rcar/core.c +++ b/sound/soc/sh/rcar/core.c | |||
@@ -94,21 +94,20 @@ | |||
94 | * | 94 | * |
95 | */ | 95 | */ |
96 | #include <linux/pm_runtime.h> | 96 | #include <linux/pm_runtime.h> |
97 | #include <linux/shdma-base.h> | ||
98 | #include "rsnd.h" | 97 | #include "rsnd.h" |
99 | 98 | ||
100 | #define RSND_RATES SNDRV_PCM_RATE_8000_96000 | 99 | #define RSND_RATES SNDRV_PCM_RATE_8000_96000 |
101 | #define RSND_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE) | 100 | #define RSND_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE) |
102 | 101 | ||
103 | static struct rsnd_of_data rsnd_of_data_gen1 = { | 102 | static const struct rsnd_of_data rsnd_of_data_gen1 = { |
104 | .flags = RSND_GEN1, | 103 | .flags = RSND_GEN1, |
105 | }; | 104 | }; |
106 | 105 | ||
107 | static struct rsnd_of_data rsnd_of_data_gen2 = { | 106 | static const struct rsnd_of_data rsnd_of_data_gen2 = { |
108 | .flags = RSND_GEN2, | 107 | .flags = RSND_GEN2, |
109 | }; | 108 | }; |
110 | 109 | ||
111 | static struct of_device_id rsnd_of_match[] = { | 110 | static const struct of_device_id rsnd_of_match[] = { |
112 | { .compatible = "renesas,rcar_sound-gen1", .data = &rsnd_of_data_gen1 }, | 111 | { .compatible = "renesas,rcar_sound-gen1", .data = &rsnd_of_data_gen1 }, |
113 | { .compatible = "renesas,rcar_sound-gen2", .data = &rsnd_of_data_gen2 }, | 112 | { .compatible = "renesas,rcar_sound-gen2", .data = &rsnd_of_data_gen2 }, |
114 | {}, | 113 | {}, |
@@ -138,249 +137,37 @@ char *rsnd_mod_name(struct rsnd_mod *mod) | |||
138 | return mod->ops->name; | 137 | return mod->ops->name; |
139 | } | 138 | } |
140 | 139 | ||
141 | char *rsnd_mod_dma_name(struct rsnd_mod *mod) | 140 | struct dma_chan *rsnd_mod_dma_req(struct rsnd_mod *mod) |
142 | { | 141 | { |
143 | if (!mod || !mod->ops) | 142 | if (!mod || !mod->ops || !mod->ops->dma_req) |
144 | return "unknown"; | 143 | return NULL; |
145 | |||
146 | if (!mod->ops->dma_name) | ||
147 | return mod->ops->name; | ||
148 | 144 | ||
149 | return mod->ops->dma_name(mod); | 145 | return mod->ops->dma_req(mod); |
150 | } | 146 | } |
151 | 147 | ||
152 | void rsnd_mod_init(struct rsnd_mod *mod, | 148 | int rsnd_mod_init(struct rsnd_mod *mod, |
153 | struct rsnd_mod_ops *ops, | 149 | struct rsnd_mod_ops *ops, |
154 | struct clk *clk, | 150 | struct clk *clk, |
155 | enum rsnd_mod_type type, | 151 | enum rsnd_mod_type type, |
156 | int id) | 152 | int id) |
157 | { | 153 | { |
154 | int ret = clk_prepare(clk); | ||
155 | |||
156 | if (ret) | ||
157 | return ret; | ||
158 | |||
158 | mod->id = id; | 159 | mod->id = id; |
159 | mod->ops = ops; | 160 | mod->ops = ops; |
160 | mod->type = type; | 161 | mod->type = type; |
161 | mod->clk = clk; | 162 | mod->clk = clk; |
162 | } | ||
163 | |||
164 | /* | ||
165 | * rsnd_dma functions | ||
166 | */ | ||
167 | void rsnd_dma_stop(struct rsnd_dma *dma) | ||
168 | { | ||
169 | dmaengine_terminate_all(dma->chan); | ||
170 | } | ||
171 | |||
172 | static void rsnd_dma_complete(void *data) | ||
173 | { | ||
174 | struct rsnd_dma *dma = (struct rsnd_dma *)data; | ||
175 | struct rsnd_mod *mod = rsnd_dma_to_mod(dma); | ||
176 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); | ||
177 | |||
178 | /* | ||
179 | * Renesas sound Gen1 needs 1 DMAC, | ||
180 | * Gen2 needs 2 DMAC. | ||
181 | * In Gen2 case, it are Audio-DMAC, and Audio-DMAC-peri-peri. | ||
182 | * But, Audio-DMAC-peri-peri doesn't have interrupt, | ||
183 | * and this driver is assuming that here. | ||
184 | * | ||
185 | * If Audio-DMAC-peri-peri has interrpt, | ||
186 | * rsnd_dai_pointer_update() will be called twice, | ||
187 | * ant it will breaks io->byte_pos | ||
188 | */ | ||
189 | |||
190 | rsnd_dai_pointer_update(io, io->byte_per_period); | ||
191 | } | ||
192 | |||
193 | void rsnd_dma_start(struct rsnd_dma *dma) | ||
194 | { | ||
195 | struct rsnd_mod *mod = rsnd_dma_to_mod(dma); | ||
196 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | ||
197 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); | ||
198 | struct snd_pcm_substream *substream = io->substream; | ||
199 | struct device *dev = rsnd_priv_to_dev(priv); | ||
200 | struct dma_async_tx_descriptor *desc; | ||
201 | |||
202 | desc = dmaengine_prep_dma_cyclic(dma->chan, | ||
203 | (dma->addr) ? dma->addr : | ||
204 | substream->runtime->dma_addr, | ||
205 | snd_pcm_lib_buffer_bytes(substream), | ||
206 | snd_pcm_lib_period_bytes(substream), | ||
207 | dma->dir, | ||
208 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | ||
209 | |||
210 | if (!desc) { | ||
211 | dev_err(dev, "dmaengine_prep_slave_sg() fail\n"); | ||
212 | return; | ||
213 | } | ||
214 | |||
215 | desc->callback = rsnd_dma_complete; | ||
216 | desc->callback_param = dma; | ||
217 | |||
218 | if (dmaengine_submit(desc) < 0) { | ||
219 | dev_err(dev, "dmaengine_submit() fail\n"); | ||
220 | return; | ||
221 | } | ||
222 | |||
223 | dma_async_issue_pending(dma->chan); | ||
224 | } | ||
225 | |||
226 | int rsnd_dma_available(struct rsnd_dma *dma) | ||
227 | { | ||
228 | return !!dma->chan; | ||
229 | } | ||
230 | |||
231 | #define DMA_NAME_SIZE 16 | ||
232 | #define MOD_MAX 4 /* MEM/SSI/SRC/DVC */ | ||
233 | static int _rsnd_dma_of_name(char *dma_name, struct rsnd_mod *mod) | ||
234 | { | ||
235 | if (mod) | ||
236 | return snprintf(dma_name, DMA_NAME_SIZE / 2, "%s%d", | ||
237 | rsnd_mod_dma_name(mod), rsnd_mod_id(mod)); | ||
238 | else | ||
239 | return snprintf(dma_name, DMA_NAME_SIZE / 2, "mem"); | ||
240 | |||
241 | } | ||
242 | |||
243 | static void rsnd_dma_of_name(struct rsnd_mod *mod_from, | ||
244 | struct rsnd_mod *mod_to, | ||
245 | char *dma_name) | ||
246 | { | ||
247 | int index = 0; | ||
248 | |||
249 | index = _rsnd_dma_of_name(dma_name + index, mod_from); | ||
250 | *(dma_name + index++) = '_'; | ||
251 | index = _rsnd_dma_of_name(dma_name + index, mod_to); | ||
252 | } | ||
253 | |||
254 | static void rsnd_dma_of_path(struct rsnd_dma *dma, | ||
255 | int is_play, | ||
256 | struct rsnd_mod **mod_from, | ||
257 | struct rsnd_mod **mod_to) | ||
258 | { | ||
259 | struct rsnd_mod *this = rsnd_dma_to_mod(dma); | ||
260 | struct rsnd_dai_stream *io = rsnd_mod_to_io(this); | ||
261 | struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io); | ||
262 | struct rsnd_mod *src = rsnd_io_to_mod_src(io); | ||
263 | struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io); | ||
264 | struct rsnd_mod *mod[MOD_MAX]; | ||
265 | int i, index; | ||
266 | 163 | ||
267 | 164 | return ret; | |
268 | for (i = 0; i < MOD_MAX; i++) | ||
269 | mod[i] = NULL; | ||
270 | |||
271 | /* | ||
272 | * in play case... | ||
273 | * | ||
274 | * src -> dst | ||
275 | * | ||
276 | * mem -> SSI | ||
277 | * mem -> SRC -> SSI | ||
278 | * mem -> SRC -> DVC -> SSI | ||
279 | */ | ||
280 | mod[0] = NULL; /* for "mem" */ | ||
281 | index = 1; | ||
282 | for (i = 1; i < MOD_MAX; i++) { | ||
283 | if (!src) { | ||
284 | mod[i] = ssi; | ||
285 | } else if (!dvc) { | ||
286 | mod[i] = src; | ||
287 | src = NULL; | ||
288 | } else { | ||
289 | if ((!is_play) && (this == src)) | ||
290 | this = dvc; | ||
291 | |||
292 | mod[i] = (is_play) ? src : dvc; | ||
293 | i++; | ||
294 | mod[i] = (is_play) ? dvc : src; | ||
295 | src = NULL; | ||
296 | dvc = NULL; | ||
297 | } | ||
298 | |||
299 | if (mod[i] == this) | ||
300 | index = i; | ||
301 | |||
302 | if (mod[i] == ssi) | ||
303 | break; | ||
304 | } | ||
305 | |||
306 | if (is_play) { | ||
307 | *mod_from = mod[index - 1]; | ||
308 | *mod_to = mod[index]; | ||
309 | } else { | ||
310 | *mod_from = mod[index]; | ||
311 | *mod_to = mod[index - 1]; | ||
312 | } | ||
313 | } | ||
314 | |||
315 | int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, | ||
316 | int is_play, int id) | ||
317 | { | ||
318 | struct device *dev = rsnd_priv_to_dev(priv); | ||
319 | struct dma_slave_config cfg; | ||
320 | struct rsnd_mod *mod_from; | ||
321 | struct rsnd_mod *mod_to; | ||
322 | char dma_name[DMA_NAME_SIZE]; | ||
323 | dma_cap_mask_t mask; | ||
324 | int ret; | ||
325 | |||
326 | if (dma->chan) { | ||
327 | dev_err(dev, "it already has dma channel\n"); | ||
328 | return -EIO; | ||
329 | } | ||
330 | |||
331 | dma_cap_zero(mask); | ||
332 | dma_cap_set(DMA_SLAVE, mask); | ||
333 | |||
334 | rsnd_dma_of_path(dma, is_play, &mod_from, &mod_to); | ||
335 | rsnd_dma_of_name(mod_from, mod_to, dma_name); | ||
336 | |||
337 | cfg.slave_id = id; | ||
338 | cfg.direction = is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM; | ||
339 | cfg.src_addr = rsnd_gen_dma_addr(priv, mod_from, is_play, 1); | ||
340 | cfg.dst_addr = rsnd_gen_dma_addr(priv, mod_to, is_play, 0); | ||
341 | cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; | ||
342 | cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; | ||
343 | |||
344 | dev_dbg(dev, "dma : %s %pad -> %pad\n", | ||
345 | dma_name, &cfg.src_addr, &cfg.dst_addr); | ||
346 | |||
347 | dma->chan = dma_request_slave_channel_compat(mask, shdma_chan_filter, | ||
348 | (void *)id, dev, | ||
349 | dma_name); | ||
350 | if (!dma->chan) { | ||
351 | dev_err(dev, "can't get dma channel\n"); | ||
352 | goto rsnd_dma_channel_err; | ||
353 | } | ||
354 | |||
355 | ret = dmaengine_slave_config(dma->chan, &cfg); | ||
356 | if (ret < 0) | ||
357 | goto rsnd_dma_init_err; | ||
358 | |||
359 | dma->addr = is_play ? cfg.src_addr : cfg.dst_addr; | ||
360 | dma->dir = is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM; | ||
361 | |||
362 | return 0; | ||
363 | |||
364 | rsnd_dma_init_err: | ||
365 | rsnd_dma_quit(priv, dma); | ||
366 | rsnd_dma_channel_err: | ||
367 | |||
368 | /* | ||
369 | * DMA failed. try to PIO mode | ||
370 | * see | ||
371 | * rsnd_ssi_fallback() | ||
372 | * rsnd_rdai_continuance_probe() | ||
373 | */ | ||
374 | return -EAGAIN; | ||
375 | } | 165 | } |
376 | 166 | ||
377 | void rsnd_dma_quit(struct rsnd_priv *priv, | 167 | void rsnd_mod_quit(struct rsnd_mod *mod) |
378 | struct rsnd_dma *dma) | ||
379 | { | 168 | { |
380 | if (dma->chan) | 169 | if (mod->clk) |
381 | dma_release_channel(dma->chan); | 170 | clk_unprepare(mod->clk); |
382 | |||
383 | dma->chan = NULL; | ||
384 | } | 171 | } |
385 | 172 | ||
386 | /* | 173 | /* |
@@ -416,7 +203,7 @@ u32 rsnd_get_adinr(struct rsnd_mod *mod) | |||
416 | ({ \ | 203 | ({ \ |
417 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \ | 204 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \ |
418 | struct device *dev = rsnd_priv_to_dev(priv); \ | 205 | struct device *dev = rsnd_priv_to_dev(priv); \ |
419 | u32 mask = 1 << __rsnd_mod_shift_##func; \ | 206 | u32 mask = (1 << __rsnd_mod_shift_##func) & ~(1 << 31); \ |
420 | u32 call = __rsnd_mod_call_##func << __rsnd_mod_shift_##func; \ | 207 | u32 call = __rsnd_mod_call_##func << __rsnd_mod_shift_##func; \ |
421 | int ret = 0; \ | 208 | int ret = 0; \ |
422 | if ((mod->status & mask) == call) { \ | 209 | if ((mod->status & mask) == call) { \ |
@@ -458,7 +245,7 @@ static int rsnd_dai_connect(struct rsnd_mod *mod, | |||
458 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | 245 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
459 | struct device *dev = rsnd_priv_to_dev(priv); | 246 | struct device *dev = rsnd_priv_to_dev(priv); |
460 | 247 | ||
461 | dev_err(dev, "%s%d is not empty\n", | 248 | dev_err(dev, "%s[%d] is not empty\n", |
462 | rsnd_mod_name(mod), | 249 | rsnd_mod_name(mod), |
463 | rsnd_mod_id(mod)); | 250 | rsnd_mod_id(mod)); |
464 | return -EIO; | 251 | return -EIO; |
@@ -874,20 +661,28 @@ static int rsnd_dai_probe(struct platform_device *pdev, | |||
874 | drv[i].name = rdai[i].name; | 661 | drv[i].name = rdai[i].name; |
875 | drv[i].ops = &rsnd_soc_dai_ops; | 662 | drv[i].ops = &rsnd_soc_dai_ops; |
876 | if (pmod) { | 663 | if (pmod) { |
664 | snprintf(rdai[i].playback.name, RSND_DAI_NAME_SIZE, | ||
665 | "DAI%d Playback", i); | ||
666 | |||
877 | drv[i].playback.rates = RSND_RATES; | 667 | drv[i].playback.rates = RSND_RATES; |
878 | drv[i].playback.formats = RSND_FMTS; | 668 | drv[i].playback.formats = RSND_FMTS; |
879 | drv[i].playback.channels_min = 2; | 669 | drv[i].playback.channels_min = 2; |
880 | drv[i].playback.channels_max = 2; | 670 | drv[i].playback.channels_max = 2; |
671 | drv[i].playback.stream_name = rdai[i].playback.name; | ||
881 | 672 | ||
882 | rdai[i].playback.info = &info->dai_info[i].playback; | 673 | rdai[i].playback.info = &info->dai_info[i].playback; |
883 | rdai[i].playback.rdai = rdai + i; | 674 | rdai[i].playback.rdai = rdai + i; |
884 | rsnd_path_init(priv, &rdai[i], &rdai[i].playback); | 675 | rsnd_path_init(priv, &rdai[i], &rdai[i].playback); |
885 | } | 676 | } |
886 | if (cmod) { | 677 | if (cmod) { |
678 | snprintf(rdai[i].capture.name, RSND_DAI_NAME_SIZE, | ||
679 | "DAI%d Capture", i); | ||
680 | |||
887 | drv[i].capture.rates = RSND_RATES; | 681 | drv[i].capture.rates = RSND_RATES; |
888 | drv[i].capture.formats = RSND_FMTS; | 682 | drv[i].capture.formats = RSND_FMTS; |
889 | drv[i].capture.channels_min = 2; | 683 | drv[i].capture.channels_min = 2; |
890 | drv[i].capture.channels_max = 2; | 684 | drv[i].capture.channels_max = 2; |
685 | drv[i].capture.stream_name = rdai[i].capture.name; | ||
891 | 686 | ||
892 | rdai[i].capture.info = &info->dai_info[i].capture; | 687 | rdai[i].capture.info = &info->dai_info[i].capture; |
893 | rdai[i].capture.rdai = rdai + i; | 688 | rdai[i].capture.rdai = rdai + i; |
@@ -933,6 +728,15 @@ static int rsnd_pcm_open(struct snd_pcm_substream *substream) | |||
933 | static int rsnd_hw_params(struct snd_pcm_substream *substream, | 728 | static int rsnd_hw_params(struct snd_pcm_substream *substream, |
934 | struct snd_pcm_hw_params *hw_params) | 729 | struct snd_pcm_hw_params *hw_params) |
935 | { | 730 | { |
731 | struct snd_soc_dai *dai = rsnd_substream_to_dai(substream); | ||
732 | struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai); | ||
733 | struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream); | ||
734 | int ret; | ||
735 | |||
736 | ret = rsnd_dai_call(hw_params, io, substream, hw_params); | ||
737 | if (ret) | ||
738 | return ret; | ||
739 | |||
936 | return snd_pcm_lib_malloc_pages(substream, | 740 | return snd_pcm_lib_malloc_pages(substream, |
937 | params_buffer_bytes(hw_params)); | 741 | params_buffer_bytes(hw_params)); |
938 | } | 742 | } |
@@ -1197,6 +1001,7 @@ static int rsnd_probe(struct platform_device *pdev) | |||
1197 | const struct rsnd_of_data *of_data, | 1001 | const struct rsnd_of_data *of_data, |
1198 | struct rsnd_priv *priv) = { | 1002 | struct rsnd_priv *priv) = { |
1199 | rsnd_gen_probe, | 1003 | rsnd_gen_probe, |
1004 | rsnd_dma_probe, | ||
1200 | rsnd_ssi_probe, | 1005 | rsnd_ssi_probe, |
1201 | rsnd_src_probe, | 1006 | rsnd_src_probe, |
1202 | rsnd_dvc_probe, | 1007 | rsnd_dvc_probe, |
@@ -1290,6 +1095,12 @@ static int rsnd_remove(struct platform_device *pdev) | |||
1290 | { | 1095 | { |
1291 | struct rsnd_priv *priv = dev_get_drvdata(&pdev->dev); | 1096 | struct rsnd_priv *priv = dev_get_drvdata(&pdev->dev); |
1292 | struct rsnd_dai *rdai; | 1097 | struct rsnd_dai *rdai; |
1098 | void (*remove_func[])(struct platform_device *pdev, | ||
1099 | struct rsnd_priv *priv) = { | ||
1100 | rsnd_ssi_remove, | ||
1101 | rsnd_src_remove, | ||
1102 | rsnd_dvc_remove, | ||
1103 | }; | ||
1293 | int ret = 0, i; | 1104 | int ret = 0, i; |
1294 | 1105 | ||
1295 | pm_runtime_disable(&pdev->dev); | 1106 | pm_runtime_disable(&pdev->dev); |
@@ -1299,6 +1110,9 @@ static int rsnd_remove(struct platform_device *pdev) | |||
1299 | ret |= rsnd_dai_call(remove, &rdai->capture, priv); | 1110 | ret |= rsnd_dai_call(remove, &rdai->capture, priv); |
1300 | } | 1111 | } |
1301 | 1112 | ||
1113 | for (i = 0; i < ARRAY_SIZE(remove_func); i++) | ||
1114 | remove_func[i](pdev, priv); | ||
1115 | |||
1302 | snd_soc_unregister_component(&pdev->dev); | 1116 | snd_soc_unregister_component(&pdev->dev); |
1303 | snd_soc_unregister_platform(&pdev->dev); | 1117 | snd_soc_unregister_platform(&pdev->dev); |
1304 | 1118 | ||
diff --git a/sound/soc/sh/rcar/dma.c b/sound/soc/sh/rcar/dma.c new file mode 100644 index 000000000000..ac3756f6af60 --- /dev/null +++ b/sound/soc/sh/rcar/dma.c | |||
@@ -0,0 +1,616 @@ | |||
1 | /* | ||
2 | * Renesas R-Car Audio DMAC support | ||
3 | * | ||
4 | * Copyright (C) 2015 Renesas Electronics Corp. | ||
5 | * Copyright (c) 2015 Kuninori Morimoto <kuninori.morimoto.gx@renesas.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 | #include <linux/delay.h> | ||
12 | #include <linux/of_dma.h> | ||
13 | #include "rsnd.h" | ||
14 | |||
15 | /* | ||
16 | * Audio DMAC peri peri register | ||
17 | */ | ||
18 | #define PDMASAR 0x00 | ||
19 | #define PDMADAR 0x04 | ||
20 | #define PDMACHCR 0x0c | ||
21 | |||
22 | /* PDMACHCR */ | ||
23 | #define PDMACHCR_DE (1 << 0) | ||
24 | |||
25 | struct rsnd_dma_ctrl { | ||
26 | void __iomem *base; | ||
27 | int dmapp_num; | ||
28 | }; | ||
29 | |||
30 | #define rsnd_priv_to_dmac(p) ((struct rsnd_dma_ctrl *)(p)->dma) | ||
31 | |||
32 | /* | ||
33 | * Audio DMAC | ||
34 | */ | ||
35 | static void rsnd_dmaen_complete(void *data) | ||
36 | { | ||
37 | struct rsnd_dma *dma = (struct rsnd_dma *)data; | ||
38 | struct rsnd_mod *mod = rsnd_dma_to_mod(dma); | ||
39 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); | ||
40 | |||
41 | /* | ||
42 | * Renesas sound Gen1 needs 1 DMAC, | ||
43 | * Gen2 needs 2 DMAC. | ||
44 | * In Gen2 case, it are Audio-DMAC, and Audio-DMAC-peri-peri. | ||
45 | * But, Audio-DMAC-peri-peri doesn't have interrupt, | ||
46 | * and this driver is assuming that here. | ||
47 | * | ||
48 | * If Audio-DMAC-peri-peri has interrpt, | ||
49 | * rsnd_dai_pointer_update() will be called twice, | ||
50 | * ant it will breaks io->byte_pos | ||
51 | */ | ||
52 | |||
53 | rsnd_dai_pointer_update(io, io->byte_per_period); | ||
54 | } | ||
55 | |||
56 | static void rsnd_dmaen_stop(struct rsnd_dma *dma) | ||
57 | { | ||
58 | struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma); | ||
59 | |||
60 | dmaengine_terminate_all(dmaen->chan); | ||
61 | } | ||
62 | |||
63 | static void rsnd_dmaen_start(struct rsnd_dma *dma) | ||
64 | { | ||
65 | struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma); | ||
66 | struct rsnd_mod *mod = rsnd_dma_to_mod(dma); | ||
67 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | ||
68 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); | ||
69 | struct snd_pcm_substream *substream = io->substream; | ||
70 | struct device *dev = rsnd_priv_to_dev(priv); | ||
71 | struct dma_async_tx_descriptor *desc; | ||
72 | int is_play = rsnd_io_is_play(io); | ||
73 | |||
74 | desc = dmaengine_prep_dma_cyclic(dmaen->chan, | ||
75 | substream->runtime->dma_addr, | ||
76 | snd_pcm_lib_buffer_bytes(substream), | ||
77 | snd_pcm_lib_period_bytes(substream), | ||
78 | is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, | ||
79 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | ||
80 | |||
81 | if (!desc) { | ||
82 | dev_err(dev, "dmaengine_prep_slave_sg() fail\n"); | ||
83 | return; | ||
84 | } | ||
85 | |||
86 | desc->callback = rsnd_dmaen_complete; | ||
87 | desc->callback_param = dma; | ||
88 | |||
89 | if (dmaengine_submit(desc) < 0) { | ||
90 | dev_err(dev, "dmaengine_submit() fail\n"); | ||
91 | return; | ||
92 | } | ||
93 | |||
94 | dma_async_issue_pending(dmaen->chan); | ||
95 | } | ||
96 | |||
97 | struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, | ||
98 | struct rsnd_mod *mod, char *name) | ||
99 | { | ||
100 | struct dma_chan *chan; | ||
101 | struct device_node *np; | ||
102 | int i = 0; | ||
103 | |||
104 | for_each_child_of_node(of_node, np) { | ||
105 | if (i == rsnd_mod_id(mod)) | ||
106 | break; | ||
107 | i++; | ||
108 | } | ||
109 | |||
110 | chan = of_dma_request_slave_channel(np, name); | ||
111 | |||
112 | of_node_put(np); | ||
113 | of_node_put(of_node); | ||
114 | |||
115 | return chan; | ||
116 | } | ||
117 | |||
118 | static struct dma_chan *rsnd_dmaen_request_channel(struct rsnd_mod *mod_from, | ||
119 | struct rsnd_mod *mod_to) | ||
120 | { | ||
121 | if ((!mod_from && !mod_to) || | ||
122 | (mod_from && mod_to)) | ||
123 | return NULL; | ||
124 | |||
125 | if (mod_from) | ||
126 | return rsnd_mod_dma_req(mod_from); | ||
127 | else | ||
128 | return rsnd_mod_dma_req(mod_to); | ||
129 | } | ||
130 | |||
131 | static int rsnd_dmaen_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id, | ||
132 | struct rsnd_mod *mod_from, struct rsnd_mod *mod_to) | ||
133 | { | ||
134 | struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma); | ||
135 | struct device *dev = rsnd_priv_to_dev(priv); | ||
136 | struct dma_slave_config cfg = {}; | ||
137 | struct rsnd_mod *mod = rsnd_dma_to_mod(dma); | ||
138 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); | ||
139 | int is_play = rsnd_io_is_play(io); | ||
140 | int ret; | ||
141 | |||
142 | if (dmaen->chan) { | ||
143 | dev_err(dev, "it already has dma channel\n"); | ||
144 | return -EIO; | ||
145 | } | ||
146 | |||
147 | if (dev->of_node) { | ||
148 | dmaen->chan = rsnd_dmaen_request_channel(mod_from, mod_to); | ||
149 | } else { | ||
150 | dma_cap_mask_t mask; | ||
151 | |||
152 | dma_cap_zero(mask); | ||
153 | dma_cap_set(DMA_SLAVE, mask); | ||
154 | |||
155 | dmaen->chan = dma_request_channel(mask, shdma_chan_filter, | ||
156 | (void *)id); | ||
157 | } | ||
158 | if (IS_ERR_OR_NULL(dmaen->chan)) { | ||
159 | dev_err(dev, "can't get dma channel\n"); | ||
160 | goto rsnd_dma_channel_err; | ||
161 | } | ||
162 | |||
163 | cfg.direction = is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM; | ||
164 | cfg.src_addr = dma->src_addr; | ||
165 | cfg.dst_addr = dma->dst_addr; | ||
166 | cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; | ||
167 | cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; | ||
168 | |||
169 | dev_dbg(dev, "dma : %pad -> %pad\n", | ||
170 | &cfg.src_addr, &cfg.dst_addr); | ||
171 | |||
172 | ret = dmaengine_slave_config(dmaen->chan, &cfg); | ||
173 | if (ret < 0) | ||
174 | goto rsnd_dma_init_err; | ||
175 | |||
176 | return 0; | ||
177 | |||
178 | rsnd_dma_init_err: | ||
179 | rsnd_dma_quit(dma); | ||
180 | rsnd_dma_channel_err: | ||
181 | |||
182 | /* | ||
183 | * DMA failed. try to PIO mode | ||
184 | * see | ||
185 | * rsnd_ssi_fallback() | ||
186 | * rsnd_rdai_continuance_probe() | ||
187 | */ | ||
188 | return -EAGAIN; | ||
189 | } | ||
190 | |||
191 | static void rsnd_dmaen_quit(struct rsnd_dma *dma) | ||
192 | { | ||
193 | struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma); | ||
194 | |||
195 | if (dmaen->chan) | ||
196 | dma_release_channel(dmaen->chan); | ||
197 | |||
198 | dmaen->chan = NULL; | ||
199 | } | ||
200 | |||
201 | static struct rsnd_dma_ops rsnd_dmaen_ops = { | ||
202 | .start = rsnd_dmaen_start, | ||
203 | .stop = rsnd_dmaen_stop, | ||
204 | .init = rsnd_dmaen_init, | ||
205 | .quit = rsnd_dmaen_quit, | ||
206 | }; | ||
207 | |||
208 | /* | ||
209 | * Audio DMAC peri peri | ||
210 | */ | ||
211 | static const u8 gen2_id_table_ssiu[] = { | ||
212 | 0x00, /* SSI00 */ | ||
213 | 0x04, /* SSI10 */ | ||
214 | 0x08, /* SSI20 */ | ||
215 | 0x0c, /* SSI3 */ | ||
216 | 0x0d, /* SSI4 */ | ||
217 | 0x0e, /* SSI5 */ | ||
218 | 0x0f, /* SSI6 */ | ||
219 | 0x10, /* SSI7 */ | ||
220 | 0x11, /* SSI8 */ | ||
221 | 0x12, /* SSI90 */ | ||
222 | }; | ||
223 | static const u8 gen2_id_table_scu[] = { | ||
224 | 0x2d, /* SCU_SRCI0 */ | ||
225 | 0x2e, /* SCU_SRCI1 */ | ||
226 | 0x2f, /* SCU_SRCI2 */ | ||
227 | 0x30, /* SCU_SRCI3 */ | ||
228 | 0x31, /* SCU_SRCI4 */ | ||
229 | 0x32, /* SCU_SRCI5 */ | ||
230 | 0x33, /* SCU_SRCI6 */ | ||
231 | 0x34, /* SCU_SRCI7 */ | ||
232 | 0x35, /* SCU_SRCI8 */ | ||
233 | 0x36, /* SCU_SRCI9 */ | ||
234 | }; | ||
235 | static const u8 gen2_id_table_cmd[] = { | ||
236 | 0x37, /* SCU_CMD0 */ | ||
237 | 0x38, /* SCU_CMD1 */ | ||
238 | }; | ||
239 | |||
240 | static u32 rsnd_dmapp_get_id(struct rsnd_mod *mod) | ||
241 | { | ||
242 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); | ||
243 | struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io); | ||
244 | struct rsnd_mod *src = rsnd_io_to_mod_src(io); | ||
245 | struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io); | ||
246 | const u8 *entry = NULL; | ||
247 | int id = rsnd_mod_id(mod); | ||
248 | int size = 0; | ||
249 | |||
250 | if (mod == ssi) { | ||
251 | entry = gen2_id_table_ssiu; | ||
252 | size = ARRAY_SIZE(gen2_id_table_ssiu); | ||
253 | } else if (mod == src) { | ||
254 | entry = gen2_id_table_scu; | ||
255 | size = ARRAY_SIZE(gen2_id_table_scu); | ||
256 | } else if (mod == dvc) { | ||
257 | entry = gen2_id_table_cmd; | ||
258 | size = ARRAY_SIZE(gen2_id_table_cmd); | ||
259 | } | ||
260 | |||
261 | if (!entry) | ||
262 | return 0xFF; | ||
263 | |||
264 | if (size <= id) | ||
265 | return 0xFF; | ||
266 | |||
267 | return entry[id]; | ||
268 | } | ||
269 | |||
270 | static u32 rsnd_dmapp_get_chcr(struct rsnd_mod *mod_from, | ||
271 | struct rsnd_mod *mod_to) | ||
272 | { | ||
273 | return (rsnd_dmapp_get_id(mod_from) << 24) + | ||
274 | (rsnd_dmapp_get_id(mod_to) << 16); | ||
275 | } | ||
276 | |||
277 | #define rsnd_dmapp_addr(dmac, dma, reg) \ | ||
278 | (dmac->base + 0x20 + reg + \ | ||
279 | (0x10 * rsnd_dma_to_dmapp(dma)->dmapp_id)) | ||
280 | static void rsnd_dmapp_write(struct rsnd_dma *dma, u32 data, u32 reg) | ||
281 | { | ||
282 | struct rsnd_mod *mod = rsnd_dma_to_mod(dma); | ||
283 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | ||
284 | struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); | ||
285 | struct device *dev = rsnd_priv_to_dev(priv); | ||
286 | |||
287 | dev_dbg(dev, "w %p : %08x\n", rsnd_dmapp_addr(dmac, dma, reg), data); | ||
288 | |||
289 | iowrite32(data, rsnd_dmapp_addr(dmac, dma, reg)); | ||
290 | } | ||
291 | |||
292 | static u32 rsnd_dmapp_read(struct rsnd_dma *dma, u32 reg) | ||
293 | { | ||
294 | struct rsnd_mod *mod = rsnd_dma_to_mod(dma); | ||
295 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | ||
296 | struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); | ||
297 | |||
298 | return ioread32(rsnd_dmapp_addr(dmac, dma, reg)); | ||
299 | } | ||
300 | |||
301 | static void rsnd_dmapp_stop(struct rsnd_dma *dma) | ||
302 | { | ||
303 | int i; | ||
304 | |||
305 | rsnd_dmapp_write(dma, 0, PDMACHCR); | ||
306 | |||
307 | for (i = 0; i < 1024; i++) { | ||
308 | if (0 == rsnd_dmapp_read(dma, PDMACHCR)) | ||
309 | return; | ||
310 | udelay(1); | ||
311 | } | ||
312 | } | ||
313 | |||
314 | static void rsnd_dmapp_start(struct rsnd_dma *dma) | ||
315 | { | ||
316 | struct rsnd_dmapp *dmapp = rsnd_dma_to_dmapp(dma); | ||
317 | |||
318 | rsnd_dmapp_write(dma, dma->src_addr, PDMASAR); | ||
319 | rsnd_dmapp_write(dma, dma->dst_addr, PDMADAR); | ||
320 | rsnd_dmapp_write(dma, dmapp->chcr, PDMACHCR); | ||
321 | } | ||
322 | |||
323 | static int rsnd_dmapp_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id, | ||
324 | struct rsnd_mod *mod_from, struct rsnd_mod *mod_to) | ||
325 | { | ||
326 | struct rsnd_dmapp *dmapp = rsnd_dma_to_dmapp(dma); | ||
327 | struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); | ||
328 | struct device *dev = rsnd_priv_to_dev(priv); | ||
329 | |||
330 | dmapp->dmapp_id = dmac->dmapp_num; | ||
331 | dmapp->chcr = rsnd_dmapp_get_chcr(mod_from, mod_to) | PDMACHCR_DE; | ||
332 | |||
333 | dmac->dmapp_num++; | ||
334 | |||
335 | rsnd_dmapp_stop(dma); | ||
336 | |||
337 | dev_dbg(dev, "id/src/dst/chcr = %d/%pad/%pad/%08x\n", | ||
338 | dmapp->dmapp_id, &dma->src_addr, &dma->dst_addr, dmapp->chcr); | ||
339 | |||
340 | return 0; | ||
341 | } | ||
342 | |||
343 | static struct rsnd_dma_ops rsnd_dmapp_ops = { | ||
344 | .start = rsnd_dmapp_start, | ||
345 | .stop = rsnd_dmapp_stop, | ||
346 | .init = rsnd_dmapp_init, | ||
347 | .quit = rsnd_dmapp_stop, | ||
348 | }; | ||
349 | |||
350 | /* | ||
351 | * Common DMAC Interface | ||
352 | */ | ||
353 | |||
354 | /* | ||
355 | * DMA read/write register offset | ||
356 | * | ||
357 | * RSND_xxx_I_N for Audio DMAC input | ||
358 | * RSND_xxx_O_N for Audio DMAC output | ||
359 | * RSND_xxx_I_P for Audio DMAC peri peri input | ||
360 | * RSND_xxx_O_P for Audio DMAC peri peri output | ||
361 | * | ||
362 | * ex) R-Car H2 case | ||
363 | * mod / DMAC in / DMAC out / DMAC PP in / DMAC pp out | ||
364 | * SSI : 0xec541000 / 0xec241008 / 0xec24100c | ||
365 | * SSIU: 0xec541000 / 0xec100000 / 0xec100000 / 0xec400000 / 0xec400000 | ||
366 | * SCU : 0xec500000 / 0xec000000 / 0xec004000 / 0xec300000 / 0xec304000 | ||
367 | * CMD : 0xec500000 / / 0xec008000 0xec308000 | ||
368 | */ | ||
369 | #define RDMA_SSI_I_N(addr, i) (addr ##_reg - 0x00300000 + (0x40 * i) + 0x8) | ||
370 | #define RDMA_SSI_O_N(addr, i) (addr ##_reg - 0x00300000 + (0x40 * i) + 0xc) | ||
371 | |||
372 | #define RDMA_SSIU_I_N(addr, i) (addr ##_reg - 0x00441000 + (0x1000 * i)) | ||
373 | #define RDMA_SSIU_O_N(addr, i) (addr ##_reg - 0x00441000 + (0x1000 * i)) | ||
374 | |||
375 | #define RDMA_SSIU_I_P(addr, i) (addr ##_reg - 0x00141000 + (0x1000 * i)) | ||
376 | #define RDMA_SSIU_O_P(addr, i) (addr ##_reg - 0x00141000 + (0x1000 * i)) | ||
377 | |||
378 | #define RDMA_SRC_I_N(addr, i) (addr ##_reg - 0x00500000 + (0x400 * i)) | ||
379 | #define RDMA_SRC_O_N(addr, i) (addr ##_reg - 0x004fc000 + (0x400 * i)) | ||
380 | |||
381 | #define RDMA_SRC_I_P(addr, i) (addr ##_reg - 0x00200000 + (0x400 * i)) | ||
382 | #define RDMA_SRC_O_P(addr, i) (addr ##_reg - 0x001fc000 + (0x400 * i)) | ||
383 | |||
384 | #define RDMA_CMD_O_N(addr, i) (addr ##_reg - 0x004f8000 + (0x400 * i)) | ||
385 | #define RDMA_CMD_O_P(addr, i) (addr ##_reg - 0x001f8000 + (0x400 * i)) | ||
386 | |||
387 | static dma_addr_t | ||
388 | rsnd_gen2_dma_addr(struct rsnd_priv *priv, | ||
389 | struct rsnd_mod *mod, | ||
390 | int is_play, int is_from) | ||
391 | { | ||
392 | struct device *dev = rsnd_priv_to_dev(priv); | ||
393 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); | ||
394 | phys_addr_t ssi_reg = rsnd_gen_get_phy_addr(priv, RSND_GEN2_SSI); | ||
395 | phys_addr_t src_reg = rsnd_gen_get_phy_addr(priv, RSND_GEN2_SCU); | ||
396 | int is_ssi = !!(rsnd_io_to_mod_ssi(io) == mod); | ||
397 | int use_src = !!rsnd_io_to_mod_src(io); | ||
398 | int use_dvc = !!rsnd_io_to_mod_dvc(io); | ||
399 | int id = rsnd_mod_id(mod); | ||
400 | struct dma_addr { | ||
401 | dma_addr_t out_addr; | ||
402 | dma_addr_t in_addr; | ||
403 | } dma_addrs[3][2][3] = { | ||
404 | /* SRC */ | ||
405 | {{{ 0, 0 }, | ||
406 | /* Capture */ | ||
407 | { RDMA_SRC_O_N(src, id), RDMA_SRC_I_P(src, id) }, | ||
408 | { RDMA_CMD_O_N(src, id), RDMA_SRC_I_P(src, id) } }, | ||
409 | /* Playback */ | ||
410 | {{ 0, 0, }, | ||
411 | { RDMA_SRC_O_P(src, id), RDMA_SRC_I_N(src, id) }, | ||
412 | { RDMA_CMD_O_P(src, id), RDMA_SRC_I_N(src, id) } } | ||
413 | }, | ||
414 | /* SSI */ | ||
415 | /* Capture */ | ||
416 | {{{ RDMA_SSI_O_N(ssi, id), 0 }, | ||
417 | { RDMA_SSIU_O_P(ssi, id), 0 }, | ||
418 | { RDMA_SSIU_O_P(ssi, id), 0 } }, | ||
419 | /* Playback */ | ||
420 | {{ 0, RDMA_SSI_I_N(ssi, id) }, | ||
421 | { 0, RDMA_SSIU_I_P(ssi, id) }, | ||
422 | { 0, RDMA_SSIU_I_P(ssi, id) } } | ||
423 | }, | ||
424 | /* SSIU */ | ||
425 | /* Capture */ | ||
426 | {{{ RDMA_SSIU_O_N(ssi, id), 0 }, | ||
427 | { RDMA_SSIU_O_P(ssi, id), 0 }, | ||
428 | { RDMA_SSIU_O_P(ssi, id), 0 } }, | ||
429 | /* Playback */ | ||
430 | {{ 0, RDMA_SSIU_I_N(ssi, id) }, | ||
431 | { 0, RDMA_SSIU_I_P(ssi, id) }, | ||
432 | { 0, RDMA_SSIU_I_P(ssi, id) } } }, | ||
433 | }; | ||
434 | |||
435 | /* it shouldn't happen */ | ||
436 | if (use_dvc && !use_src) | ||
437 | dev_err(dev, "DVC is selected without SRC\n"); | ||
438 | |||
439 | /* use SSIU or SSI ? */ | ||
440 | if (is_ssi && rsnd_ssi_use_busif(mod)) | ||
441 | is_ssi++; | ||
442 | |||
443 | return (is_from) ? | ||
444 | dma_addrs[is_ssi][is_play][use_src + use_dvc].out_addr : | ||
445 | dma_addrs[is_ssi][is_play][use_src + use_dvc].in_addr; | ||
446 | } | ||
447 | |||
448 | static dma_addr_t rsnd_dma_addr(struct rsnd_priv *priv, | ||
449 | struct rsnd_mod *mod, | ||
450 | int is_play, int is_from) | ||
451 | { | ||
452 | /* | ||
453 | * gen1 uses default DMA addr | ||
454 | */ | ||
455 | if (rsnd_is_gen1(priv)) | ||
456 | return 0; | ||
457 | |||
458 | if (!mod) | ||
459 | return 0; | ||
460 | |||
461 | return rsnd_gen2_dma_addr(priv, mod, is_play, is_from); | ||
462 | } | ||
463 | |||
464 | #define MOD_MAX 4 /* MEM/SSI/SRC/DVC */ | ||
465 | static void rsnd_dma_of_path(struct rsnd_dma *dma, | ||
466 | int is_play, | ||
467 | struct rsnd_mod **mod_from, | ||
468 | struct rsnd_mod **mod_to) | ||
469 | { | ||
470 | struct rsnd_mod *this = rsnd_dma_to_mod(dma); | ||
471 | struct rsnd_dai_stream *io = rsnd_mod_to_io(this); | ||
472 | struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io); | ||
473 | struct rsnd_mod *src = rsnd_io_to_mod_src(io); | ||
474 | struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io); | ||
475 | struct rsnd_mod *mod[MOD_MAX]; | ||
476 | int i, index; | ||
477 | |||
478 | |||
479 | for (i = 0; i < MOD_MAX; i++) | ||
480 | mod[i] = NULL; | ||
481 | |||
482 | /* | ||
483 | * in play case... | ||
484 | * | ||
485 | * src -> dst | ||
486 | * | ||
487 | * mem -> SSI | ||
488 | * mem -> SRC -> SSI | ||
489 | * mem -> SRC -> DVC -> SSI | ||
490 | */ | ||
491 | mod[0] = NULL; /* for "mem" */ | ||
492 | index = 1; | ||
493 | for (i = 1; i < MOD_MAX; i++) { | ||
494 | if (!src) { | ||
495 | mod[i] = ssi; | ||
496 | } else if (!dvc) { | ||
497 | mod[i] = src; | ||
498 | src = NULL; | ||
499 | } else { | ||
500 | if ((!is_play) && (this == src)) | ||
501 | this = dvc; | ||
502 | |||
503 | mod[i] = (is_play) ? src : dvc; | ||
504 | i++; | ||
505 | mod[i] = (is_play) ? dvc : src; | ||
506 | src = NULL; | ||
507 | dvc = NULL; | ||
508 | } | ||
509 | |||
510 | if (mod[i] == this) | ||
511 | index = i; | ||
512 | |||
513 | if (mod[i] == ssi) | ||
514 | break; | ||
515 | } | ||
516 | |||
517 | if (is_play) { | ||
518 | *mod_from = mod[index - 1]; | ||
519 | *mod_to = mod[index]; | ||
520 | } else { | ||
521 | *mod_from = mod[index]; | ||
522 | *mod_to = mod[index - 1]; | ||
523 | } | ||
524 | } | ||
525 | |||
526 | void rsnd_dma_stop(struct rsnd_dma *dma) | ||
527 | { | ||
528 | dma->ops->stop(dma); | ||
529 | } | ||
530 | |||
531 | void rsnd_dma_start(struct rsnd_dma *dma) | ||
532 | { | ||
533 | dma->ops->start(dma); | ||
534 | } | ||
535 | |||
536 | void rsnd_dma_quit(struct rsnd_dma *dma) | ||
537 | { | ||
538 | struct rsnd_mod *mod = rsnd_dma_to_mod(dma); | ||
539 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | ||
540 | struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); | ||
541 | |||
542 | if (!dmac) | ||
543 | return; | ||
544 | |||
545 | dma->ops->quit(dma); | ||
546 | } | ||
547 | |||
548 | int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id) | ||
549 | { | ||
550 | struct rsnd_mod *mod = rsnd_dma_to_mod(dma); | ||
551 | struct rsnd_mod *mod_from; | ||
552 | struct rsnd_mod *mod_to; | ||
553 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); | ||
554 | struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); | ||
555 | int is_play = rsnd_io_is_play(io); | ||
556 | |||
557 | /* | ||
558 | * DMA failed. try to PIO mode | ||
559 | * see | ||
560 | * rsnd_ssi_fallback() | ||
561 | * rsnd_rdai_continuance_probe() | ||
562 | */ | ||
563 | if (!dmac) | ||
564 | return -EAGAIN; | ||
565 | |||
566 | rsnd_dma_of_path(dma, is_play, &mod_from, &mod_to); | ||
567 | |||
568 | dma->src_addr = rsnd_dma_addr(priv, mod_from, is_play, 1); | ||
569 | dma->dst_addr = rsnd_dma_addr(priv, mod_to, is_play, 0); | ||
570 | |||
571 | /* for Gen2 */ | ||
572 | if (mod_from && mod_to) | ||
573 | dma->ops = &rsnd_dmapp_ops; | ||
574 | else | ||
575 | dma->ops = &rsnd_dmaen_ops; | ||
576 | |||
577 | /* for Gen1, overwrite */ | ||
578 | if (rsnd_is_gen1(priv)) | ||
579 | dma->ops = &rsnd_dmaen_ops; | ||
580 | |||
581 | return dma->ops->init(priv, dma, id, mod_from, mod_to); | ||
582 | } | ||
583 | |||
584 | int rsnd_dma_probe(struct platform_device *pdev, | ||
585 | const struct rsnd_of_data *of_data, | ||
586 | struct rsnd_priv *priv) | ||
587 | { | ||
588 | struct device *dev = rsnd_priv_to_dev(priv); | ||
589 | struct rsnd_dma_ctrl *dmac; | ||
590 | struct resource *res; | ||
591 | |||
592 | /* | ||
593 | * for Gen1 | ||
594 | */ | ||
595 | if (rsnd_is_gen1(priv)) | ||
596 | return 0; | ||
597 | |||
598 | /* | ||
599 | * for Gen2 | ||
600 | */ | ||
601 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "audmapp"); | ||
602 | dmac = devm_kzalloc(dev, sizeof(*dmac), GFP_KERNEL); | ||
603 | if (!dmac || !res) { | ||
604 | dev_err(dev, "dma allocate failed\n"); | ||
605 | return 0; /* it will be PIO mode */ | ||
606 | } | ||
607 | |||
608 | dmac->dmapp_num = 0; | ||
609 | dmac->base = devm_ioremap_resource(dev, res); | ||
610 | if (IS_ERR(dmac->base)) | ||
611 | return PTR_ERR(dmac->base); | ||
612 | |||
613 | priv->dma = dmac; | ||
614 | |||
615 | return 0; | ||
616 | } | ||
diff --git a/sound/soc/sh/rcar/dvc.c b/sound/soc/sh/rcar/dvc.c index d7f9ed959c4e..e5fcb062ad77 100644 --- a/sound/soc/sh/rcar/dvc.c +++ b/sound/soc/sh/rcar/dvc.c | |||
@@ -24,6 +24,9 @@ struct rsnd_dvc { | |||
24 | struct rsnd_kctrl_cfg_s rdown; /* Ramp Rate Down */ | 24 | struct rsnd_kctrl_cfg_s rdown; /* Ramp Rate Down */ |
25 | }; | 25 | }; |
26 | 26 | ||
27 | #define rsnd_dvc_of_node(priv) \ | ||
28 | of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,dvc") | ||
29 | |||
27 | #define rsnd_mod_to_dvc(_mod) \ | 30 | #define rsnd_mod_to_dvc(_mod) \ |
28 | container_of((_mod), struct rsnd_dvc, mod) | 31 | container_of((_mod), struct rsnd_dvc, mod) |
29 | 32 | ||
@@ -33,7 +36,7 @@ struct rsnd_dvc { | |||
33 | ((pos) = (struct rsnd_dvc *)(priv)->dvc + i); \ | 36 | ((pos) = (struct rsnd_dvc *)(priv)->dvc + i); \ |
34 | i++) | 37 | i++) |
35 | 38 | ||
36 | static const char const *dvc_ramp_rate[] = { | 39 | static const char * const dvc_ramp_rate[] = { |
37 | "128 dB/1 step", /* 00000 */ | 40 | "128 dB/1 step", /* 00000 */ |
38 | "64 dB/1 step", /* 00001 */ | 41 | "64 dB/1 step", /* 00001 */ |
39 | "32 dB/1 step", /* 00010 */ | 42 | "32 dB/1 step", /* 00010 */ |
@@ -116,17 +119,6 @@ static void rsnd_dvc_volume_update(struct rsnd_mod *mod) | |||
116 | rsnd_mod_write(mod, DVC_DVUER, 1); | 119 | rsnd_mod_write(mod, DVC_DVUER, 1); |
117 | } | 120 | } |
118 | 121 | ||
119 | static int rsnd_dvc_probe_gen2(struct rsnd_mod *mod, | ||
120 | struct rsnd_priv *priv) | ||
121 | { | ||
122 | struct device *dev = rsnd_priv_to_dev(priv); | ||
123 | |||
124 | dev_dbg(dev, "%s[%d] (Gen2) is probed\n", | ||
125 | rsnd_mod_name(mod), rsnd_mod_id(mod)); | ||
126 | |||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | static int rsnd_dvc_remove_gen2(struct rsnd_mod *mod, | 122 | static int rsnd_dvc_remove_gen2(struct rsnd_mod *mod, |
131 | struct rsnd_priv *priv) | 123 | struct rsnd_priv *priv) |
132 | { | 124 | { |
@@ -269,9 +261,17 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod, | |||
269 | return 0; | 261 | return 0; |
270 | } | 262 | } |
271 | 263 | ||
264 | static struct dma_chan *rsnd_dvc_dma_req(struct rsnd_mod *mod) | ||
265 | { | ||
266 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | ||
267 | |||
268 | return rsnd_dma_request_channel(rsnd_dvc_of_node(priv), | ||
269 | mod, "tx"); | ||
270 | } | ||
271 | |||
272 | static struct rsnd_mod_ops rsnd_dvc_ops = { | 272 | static struct rsnd_mod_ops rsnd_dvc_ops = { |
273 | .name = DVC_NAME, | 273 | .name = DVC_NAME, |
274 | .probe = rsnd_dvc_probe_gen2, | 274 | .dma_req = rsnd_dvc_dma_req, |
275 | .remove = rsnd_dvc_remove_gen2, | 275 | .remove = rsnd_dvc_remove_gen2, |
276 | .init = rsnd_dvc_init, | 276 | .init = rsnd_dvc_init, |
277 | .quit = rsnd_dvc_quit, | 277 | .quit = rsnd_dvc_quit, |
@@ -333,7 +333,7 @@ int rsnd_dvc_probe(struct platform_device *pdev, | |||
333 | struct rsnd_dvc *dvc; | 333 | struct rsnd_dvc *dvc; |
334 | struct clk *clk; | 334 | struct clk *clk; |
335 | char name[RSND_DVC_NAME_SIZE]; | 335 | char name[RSND_DVC_NAME_SIZE]; |
336 | int i, nr; | 336 | int i, nr, ret; |
337 | 337 | ||
338 | rsnd_of_parse_dvc(pdev, of_data, priv); | 338 | rsnd_of_parse_dvc(pdev, of_data, priv); |
339 | 339 | ||
@@ -366,11 +366,22 @@ int rsnd_dvc_probe(struct platform_device *pdev, | |||
366 | 366 | ||
367 | dvc->info = &info->dvc_info[i]; | 367 | dvc->info = &info->dvc_info[i]; |
368 | 368 | ||
369 | rsnd_mod_init(&dvc->mod, &rsnd_dvc_ops, | 369 | ret = rsnd_mod_init(&dvc->mod, &rsnd_dvc_ops, |
370 | clk, RSND_MOD_DVC, i); | 370 | clk, RSND_MOD_DVC, i); |
371 | 371 | if (ret) | |
372 | dev_dbg(dev, "CMD%d probed\n", i); | 372 | return ret; |
373 | } | 373 | } |
374 | 374 | ||
375 | return 0; | 375 | return 0; |
376 | } | 376 | } |
377 | |||
378 | void rsnd_dvc_remove(struct platform_device *pdev, | ||
379 | struct rsnd_priv *priv) | ||
380 | { | ||
381 | struct rsnd_dvc *dvc; | ||
382 | int i; | ||
383 | |||
384 | for_each_rsnd_dvc(dvc, priv, i) { | ||
385 | rsnd_mod_quit(&dvc->mod); | ||
386 | } | ||
387 | } | ||
diff --git a/sound/soc/sh/rcar/gen.c b/sound/soc/sh/rcar/gen.c index de0685f2abae..8c7dc51b1c4f 100644 --- a/sound/soc/sh/rcar/gen.c +++ b/sound/soc/sh/rcar/gen.c | |||
@@ -28,6 +28,7 @@ struct rsnd_gen { | |||
28 | 28 | ||
29 | struct regmap *regmap[RSND_BASE_MAX]; | 29 | struct regmap *regmap[RSND_BASE_MAX]; |
30 | struct regmap_field *regs[RSND_REG_MAX]; | 30 | struct regmap_field *regs[RSND_REG_MAX]; |
31 | phys_addr_t res[RSND_REG_MAX]; | ||
31 | }; | 32 | }; |
32 | 33 | ||
33 | #define rsnd_priv_to_gen(p) ((struct rsnd_gen *)(p)->gen) | 34 | #define rsnd_priv_to_gen(p) ((struct rsnd_gen *)(p)->gen) |
@@ -118,11 +119,19 @@ void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, | |||
118 | mask, data); | 119 | mask, data); |
119 | } | 120 | } |
120 | 121 | ||
121 | #define rsnd_gen_regmap_init(priv, id_size, reg_id, conf) \ | 122 | phys_addr_t rsnd_gen_get_phy_addr(struct rsnd_priv *priv, int reg_id) |
122 | _rsnd_gen_regmap_init(priv, id_size, reg_id, conf, ARRAY_SIZE(conf)) | 123 | { |
124 | struct rsnd_gen *gen = rsnd_priv_to_gen(priv); | ||
125 | |||
126 | return gen->res[reg_id]; | ||
127 | } | ||
128 | |||
129 | #define rsnd_gen_regmap_init(priv, id_size, reg_id, name, conf) \ | ||
130 | _rsnd_gen_regmap_init(priv, id_size, reg_id, name, conf, ARRAY_SIZE(conf)) | ||
123 | static int _rsnd_gen_regmap_init(struct rsnd_priv *priv, | 131 | static int _rsnd_gen_regmap_init(struct rsnd_priv *priv, |
124 | int id_size, | 132 | int id_size, |
125 | int reg_id, | 133 | int reg_id, |
134 | const char *name, | ||
126 | struct rsnd_regmap_field_conf *conf, | 135 | struct rsnd_regmap_field_conf *conf, |
127 | int conf_size) | 136 | int conf_size) |
128 | { | 137 | { |
@@ -141,8 +150,11 @@ static int _rsnd_gen_regmap_init(struct rsnd_priv *priv, | |||
141 | regc.reg_bits = 32; | 150 | regc.reg_bits = 32; |
142 | regc.val_bits = 32; | 151 | regc.val_bits = 32; |
143 | regc.reg_stride = 4; | 152 | regc.reg_stride = 4; |
153 | regc.name = name; | ||
144 | 154 | ||
145 | res = platform_get_resource(pdev, IORESOURCE_MEM, reg_id); | 155 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name); |
156 | if (!res) | ||
157 | res = platform_get_resource(pdev, IORESOURCE_MEM, reg_id); | ||
146 | if (!res) | 158 | if (!res) |
147 | return -ENODEV; | 159 | return -ENODEV; |
148 | 160 | ||
@@ -156,6 +168,7 @@ static int _rsnd_gen_regmap_init(struct rsnd_priv *priv, | |||
156 | 168 | ||
157 | gen->base[reg_id] = base; | 169 | gen->base[reg_id] = base; |
158 | gen->regmap[reg_id] = regmap; | 170 | gen->regmap[reg_id] = regmap; |
171 | gen->res[reg_id] = res->start; | ||
159 | 172 | ||
160 | for (i = 0; i < conf_size; i++) { | 173 | for (i = 0; i < conf_size; i++) { |
161 | 174 | ||
@@ -176,125 +189,11 @@ static int _rsnd_gen_regmap_init(struct rsnd_priv *priv, | |||
176 | } | 189 | } |
177 | 190 | ||
178 | /* | 191 | /* |
179 | * DMA read/write register offset | ||
180 | * | ||
181 | * RSND_xxx_I_N for Audio DMAC input | ||
182 | * RSND_xxx_O_N for Audio DMAC output | ||
183 | * RSND_xxx_I_P for Audio DMAC peri peri input | ||
184 | * RSND_xxx_O_P for Audio DMAC peri peri output | ||
185 | * | ||
186 | * ex) R-Car H2 case | ||
187 | * mod / DMAC in / DMAC out / DMAC PP in / DMAC pp out | ||
188 | * SSI : 0xec541000 / 0xec241008 / 0xec24100c | ||
189 | * SSIU: 0xec541000 / 0xec100000 / 0xec100000 / 0xec400000 / 0xec400000 | ||
190 | * SCU : 0xec500000 / 0xec000000 / 0xec004000 / 0xec300000 / 0xec304000 | ||
191 | * CMD : 0xec500000 / / 0xec008000 0xec308000 | ||
192 | */ | ||
193 | #define RDMA_SSI_I_N(addr, i) (addr ##_reg - 0x00300000 + (0x40 * i) + 0x8) | ||
194 | #define RDMA_SSI_O_N(addr, i) (addr ##_reg - 0x00300000 + (0x40 * i) + 0xc) | ||
195 | |||
196 | #define RDMA_SSIU_I_N(addr, i) (addr ##_reg - 0x00441000 + (0x1000 * i)) | ||
197 | #define RDMA_SSIU_O_N(addr, i) (addr ##_reg - 0x00441000 + (0x1000 * i)) | ||
198 | |||
199 | #define RDMA_SSIU_I_P(addr, i) (addr ##_reg - 0x00141000 + (0x1000 * i)) | ||
200 | #define RDMA_SSIU_O_P(addr, i) (addr ##_reg - 0x00141000 + (0x1000 * i)) | ||
201 | |||
202 | #define RDMA_SRC_I_N(addr, i) (addr ##_reg - 0x00500000 + (0x400 * i)) | ||
203 | #define RDMA_SRC_O_N(addr, i) (addr ##_reg - 0x004fc000 + (0x400 * i)) | ||
204 | |||
205 | #define RDMA_SRC_I_P(addr, i) (addr ##_reg - 0x00200000 + (0x400 * i)) | ||
206 | #define RDMA_SRC_O_P(addr, i) (addr ##_reg - 0x001fc000 + (0x400 * i)) | ||
207 | |||
208 | #define RDMA_CMD_O_N(addr, i) (addr ##_reg - 0x004f8000 + (0x400 * i)) | ||
209 | #define RDMA_CMD_O_P(addr, i) (addr ##_reg - 0x001f8000 + (0x400 * i)) | ||
210 | |||
211 | static dma_addr_t | ||
212 | rsnd_gen2_dma_addr(struct rsnd_priv *priv, | ||
213 | struct rsnd_mod *mod, | ||
214 | int is_play, int is_from) | ||
215 | { | ||
216 | struct platform_device *pdev = rsnd_priv_to_pdev(priv); | ||
217 | struct device *dev = rsnd_priv_to_dev(priv); | ||
218 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); | ||
219 | dma_addr_t ssi_reg = platform_get_resource(pdev, | ||
220 | IORESOURCE_MEM, RSND_GEN2_SSI)->start; | ||
221 | dma_addr_t src_reg = platform_get_resource(pdev, | ||
222 | IORESOURCE_MEM, RSND_GEN2_SCU)->start; | ||
223 | int is_ssi = !!(rsnd_io_to_mod_ssi(io) == mod); | ||
224 | int use_src = !!rsnd_io_to_mod_src(io); | ||
225 | int use_dvc = !!rsnd_io_to_mod_dvc(io); | ||
226 | int id = rsnd_mod_id(mod); | ||
227 | struct dma_addr { | ||
228 | dma_addr_t out_addr; | ||
229 | dma_addr_t in_addr; | ||
230 | } dma_addrs[3][2][3] = { | ||
231 | /* SRC */ | ||
232 | {{{ 0, 0 }, | ||
233 | /* Capture */ | ||
234 | { RDMA_SRC_O_N(src, id), RDMA_SRC_I_P(src, id) }, | ||
235 | { RDMA_CMD_O_N(src, id), RDMA_SRC_I_P(src, id) } }, | ||
236 | /* Playback */ | ||
237 | {{ 0, 0, }, | ||
238 | { RDMA_SRC_O_P(src, id), RDMA_SRC_I_N(src, id) }, | ||
239 | { RDMA_CMD_O_P(src, id), RDMA_SRC_I_N(src, id) } } | ||
240 | }, | ||
241 | /* SSI */ | ||
242 | /* Capture */ | ||
243 | {{{ RDMA_SSI_O_N(ssi, id), 0 }, | ||
244 | { RDMA_SSIU_O_P(ssi, id), 0 }, | ||
245 | { RDMA_SSIU_O_P(ssi, id), 0 } }, | ||
246 | /* Playback */ | ||
247 | {{ 0, RDMA_SSI_I_N(ssi, id) }, | ||
248 | { 0, RDMA_SSIU_I_P(ssi, id) }, | ||
249 | { 0, RDMA_SSIU_I_P(ssi, id) } } | ||
250 | }, | ||
251 | /* SSIU */ | ||
252 | /* Capture */ | ||
253 | {{{ RDMA_SSIU_O_N(ssi, id), 0 }, | ||
254 | { RDMA_SSIU_O_P(ssi, id), 0 }, | ||
255 | { RDMA_SSIU_O_P(ssi, id), 0 } }, | ||
256 | /* Playback */ | ||
257 | {{ 0, RDMA_SSIU_I_N(ssi, id) }, | ||
258 | { 0, RDMA_SSIU_I_P(ssi, id) }, | ||
259 | { 0, RDMA_SSIU_I_P(ssi, id) } } }, | ||
260 | }; | ||
261 | |||
262 | /* it shouldn't happen */ | ||
263 | if (use_dvc && !use_src) | ||
264 | dev_err(dev, "DVC is selected without SRC\n"); | ||
265 | |||
266 | /* use SSIU or SSI ? */ | ||
267 | if (is_ssi && (0 == strcmp(rsnd_mod_dma_name(mod), "ssiu"))) | ||
268 | is_ssi++; | ||
269 | |||
270 | return (is_from) ? | ||
271 | dma_addrs[is_ssi][is_play][use_src + use_dvc].out_addr : | ||
272 | dma_addrs[is_ssi][is_play][use_src + use_dvc].in_addr; | ||
273 | } | ||
274 | |||
275 | dma_addr_t rsnd_gen_dma_addr(struct rsnd_priv *priv, | ||
276 | struct rsnd_mod *mod, | ||
277 | int is_play, int is_from) | ||
278 | { | ||
279 | /* | ||
280 | * gen1 uses default DMA addr | ||
281 | */ | ||
282 | if (rsnd_is_gen1(priv)) | ||
283 | return 0; | ||
284 | |||
285 | if (!mod) | ||
286 | return 0; | ||
287 | |||
288 | return rsnd_gen2_dma_addr(priv, mod, is_play, is_from); | ||
289 | } | ||
290 | |||
291 | /* | ||
292 | * Gen2 | 192 | * Gen2 |
293 | */ | 193 | */ |
294 | static int rsnd_gen2_probe(struct platform_device *pdev, | 194 | static int rsnd_gen2_probe(struct platform_device *pdev, |
295 | struct rsnd_priv *priv) | 195 | struct rsnd_priv *priv) |
296 | { | 196 | { |
297 | struct device *dev = rsnd_priv_to_dev(priv); | ||
298 | struct rsnd_regmap_field_conf conf_ssiu[] = { | 197 | struct rsnd_regmap_field_conf conf_ssiu[] = { |
299 | RSND_GEN_S_REG(SSI_MODE0, 0x800), | 198 | RSND_GEN_S_REG(SSI_MODE0, 0x800), |
300 | RSND_GEN_S_REG(SSI_MODE1, 0x804), | 199 | RSND_GEN_S_REG(SSI_MODE1, 0x804), |
@@ -368,18 +267,16 @@ static int rsnd_gen2_probe(struct platform_device *pdev, | |||
368 | int ret_adg; | 267 | int ret_adg; |
369 | int ret_ssi; | 268 | int ret_ssi; |
370 | 269 | ||
371 | ret_ssiu = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SSIU, conf_ssiu); | 270 | ret_ssiu = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SSIU, "ssiu", conf_ssiu); |
372 | ret_scu = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SCU, conf_scu); | 271 | ret_scu = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SCU, "scu", conf_scu); |
373 | ret_adg = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_ADG, conf_adg); | 272 | ret_adg = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_ADG, "adg", conf_adg); |
374 | ret_ssi = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SSI, conf_ssi); | 273 | ret_ssi = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SSI, "ssi", conf_ssi); |
375 | if (ret_ssiu < 0 || | 274 | if (ret_ssiu < 0 || |
376 | ret_scu < 0 || | 275 | ret_scu < 0 || |
377 | ret_adg < 0 || | 276 | ret_adg < 0 || |
378 | ret_ssi < 0) | 277 | ret_ssi < 0) |
379 | return ret_ssiu | ret_scu | ret_adg | ret_ssi; | 278 | return ret_ssiu | ret_scu | ret_adg | ret_ssi; |
380 | 279 | ||
381 | dev_dbg(dev, "Gen2 is probed\n"); | ||
382 | |||
383 | return 0; | 280 | return 0; |
384 | } | 281 | } |
385 | 282 | ||
@@ -390,7 +287,6 @@ static int rsnd_gen2_probe(struct platform_device *pdev, | |||
390 | static int rsnd_gen1_probe(struct platform_device *pdev, | 287 | static int rsnd_gen1_probe(struct platform_device *pdev, |
391 | struct rsnd_priv *priv) | 288 | struct rsnd_priv *priv) |
392 | { | 289 | { |
393 | struct device *dev = rsnd_priv_to_dev(priv); | ||
394 | struct rsnd_regmap_field_conf conf_sru[] = { | 290 | struct rsnd_regmap_field_conf conf_sru[] = { |
395 | RSND_GEN_S_REG(SRC_ROUTE_SEL, 0x00), | 291 | RSND_GEN_S_REG(SRC_ROUTE_SEL, 0x00), |
396 | RSND_GEN_S_REG(SRC_TMG_SEL0, 0x08), | 292 | RSND_GEN_S_REG(SRC_TMG_SEL0, 0x08), |
@@ -440,16 +336,14 @@ static int rsnd_gen1_probe(struct platform_device *pdev, | |||
440 | int ret_adg; | 336 | int ret_adg; |
441 | int ret_ssi; | 337 | int ret_ssi; |
442 | 338 | ||
443 | ret_sru = rsnd_gen_regmap_init(priv, 9, RSND_GEN1_SRU, conf_sru); | 339 | ret_sru = rsnd_gen_regmap_init(priv, 9, RSND_GEN1_SRU, "sru", conf_sru); |
444 | ret_adg = rsnd_gen_regmap_init(priv, 9, RSND_GEN1_ADG, conf_adg); | 340 | ret_adg = rsnd_gen_regmap_init(priv, 9, RSND_GEN1_ADG, "adg", conf_adg); |
445 | ret_ssi = rsnd_gen_regmap_init(priv, 9, RSND_GEN1_SSI, conf_ssi); | 341 | ret_ssi = rsnd_gen_regmap_init(priv, 9, RSND_GEN1_SSI, "ssi", conf_ssi); |
446 | if (ret_sru < 0 || | 342 | if (ret_sru < 0 || |
447 | ret_adg < 0 || | 343 | ret_adg < 0 || |
448 | ret_ssi < 0) | 344 | ret_ssi < 0) |
449 | return ret_sru | ret_adg | ret_ssi; | 345 | return ret_sru | ret_adg | ret_ssi; |
450 | 346 | ||
451 | dev_dbg(dev, "Gen1 is probed\n"); | ||
452 | |||
453 | return 0; | 347 | return 0; |
454 | } | 348 | } |
455 | 349 | ||
diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h index e7914bd610e2..4e6de6804cfb 100644 --- a/sound/soc/sh/rcar/rsnd.h +++ b/sound/soc/sh/rcar/rsnd.h | |||
@@ -170,21 +170,47 @@ u32 rsnd_get_adinr(struct rsnd_mod *mod); | |||
170 | /* | 170 | /* |
171 | * R-Car DMA | 171 | * R-Car DMA |
172 | */ | 172 | */ |
173 | struct rsnd_dma { | 173 | struct rsnd_dma; |
174 | struct sh_dmae_slave slave; | 174 | struct rsnd_dma_ops { |
175 | void (*start)(struct rsnd_dma *dma); | ||
176 | void (*stop)(struct rsnd_dma *dma); | ||
177 | int (*init)(struct rsnd_priv *priv, struct rsnd_dma *dma, int id, | ||
178 | struct rsnd_mod *mod_from, struct rsnd_mod *mod_to); | ||
179 | void (*quit)(struct rsnd_dma *dma); | ||
180 | }; | ||
181 | |||
182 | struct rsnd_dmaen { | ||
175 | struct dma_chan *chan; | 183 | struct dma_chan *chan; |
176 | enum dma_transfer_direction dir; | ||
177 | dma_addr_t addr; | ||
178 | }; | 184 | }; |
179 | 185 | ||
186 | struct rsnd_dmapp { | ||
187 | int dmapp_id; | ||
188 | u32 chcr; | ||
189 | }; | ||
190 | |||
191 | struct rsnd_dma { | ||
192 | struct rsnd_dma_ops *ops; | ||
193 | dma_addr_t src_addr; | ||
194 | dma_addr_t dst_addr; | ||
195 | union { | ||
196 | struct rsnd_dmaen en; | ||
197 | struct rsnd_dmapp pp; | ||
198 | } dma; | ||
199 | }; | ||
200 | #define rsnd_dma_to_dmaen(dma) (&(dma)->dma.en) | ||
201 | #define rsnd_dma_to_dmapp(dma) (&(dma)->dma.pp) | ||
202 | |||
180 | void rsnd_dma_start(struct rsnd_dma *dma); | 203 | void rsnd_dma_start(struct rsnd_dma *dma); |
181 | void rsnd_dma_stop(struct rsnd_dma *dma); | 204 | void rsnd_dma_stop(struct rsnd_dma *dma); |
182 | int rsnd_dma_available(struct rsnd_dma *dma); | 205 | int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id); |
183 | int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, | 206 | void rsnd_dma_quit(struct rsnd_dma *dma); |
184 | int is_play, int id); | 207 | int rsnd_dma_probe(struct platform_device *pdev, |
185 | void rsnd_dma_quit(struct rsnd_priv *priv, | 208 | const struct rsnd_of_data *of_data, |
186 | struct rsnd_dma *dma); | 209 | struct rsnd_priv *priv); |
210 | struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, | ||
211 | struct rsnd_mod *mod, char *name); | ||
187 | 212 | ||
213 | #define rsnd_dma_to_mod(_dma) container_of((_dma), struct rsnd_mod, dma) | ||
188 | 214 | ||
189 | /* | 215 | /* |
190 | * R-Car sound mod | 216 | * R-Car sound mod |
@@ -198,7 +224,7 @@ enum rsnd_mod_type { | |||
198 | 224 | ||
199 | struct rsnd_mod_ops { | 225 | struct rsnd_mod_ops { |
200 | char *name; | 226 | char *name; |
201 | char* (*dma_name)(struct rsnd_mod *mod); | 227 | struct dma_chan* (*dma_req)(struct rsnd_mod *mod); |
202 | int (*probe)(struct rsnd_mod *mod, | 228 | int (*probe)(struct rsnd_mod *mod, |
203 | struct rsnd_priv *priv); | 229 | struct rsnd_priv *priv); |
204 | int (*remove)(struct rsnd_mod *mod, | 230 | int (*remove)(struct rsnd_mod *mod, |
@@ -213,6 +239,9 @@ struct rsnd_mod_ops { | |||
213 | struct rsnd_priv *priv); | 239 | struct rsnd_priv *priv); |
214 | int (*pcm_new)(struct rsnd_mod *mod, | 240 | int (*pcm_new)(struct rsnd_mod *mod, |
215 | struct snd_soc_pcm_runtime *rtd); | 241 | struct snd_soc_pcm_runtime *rtd); |
242 | int (*hw_params)(struct rsnd_mod *mod, | ||
243 | struct snd_pcm_substream *substream, | ||
244 | struct snd_pcm_hw_params *hw_params); | ||
216 | int (*fallback)(struct rsnd_mod *mod, | 245 | int (*fallback)(struct rsnd_mod *mod, |
217 | struct rsnd_priv *priv); | 246 | struct rsnd_priv *priv); |
218 | }; | 247 | }; |
@@ -236,6 +265,9 @@ struct rsnd_mod { | |||
236 | * 2 0: start 1: stop | 265 | * 2 0: start 1: stop |
237 | * 3 0: pcm_new | 266 | * 3 0: pcm_new |
238 | * 4 0: fallback | 267 | * 4 0: fallback |
268 | * | ||
269 | * 31 bit is always called (see __rsnd_mod_call) | ||
270 | * 31 0: hw_params | ||
239 | */ | 271 | */ |
240 | #define __rsnd_mod_shift_probe 0 | 272 | #define __rsnd_mod_shift_probe 0 |
241 | #define __rsnd_mod_shift_remove 0 | 273 | #define __rsnd_mod_shift_remove 0 |
@@ -245,6 +277,7 @@ struct rsnd_mod { | |||
245 | #define __rsnd_mod_shift_stop 2 | 277 | #define __rsnd_mod_shift_stop 2 |
246 | #define __rsnd_mod_shift_pcm_new 3 | 278 | #define __rsnd_mod_shift_pcm_new 3 |
247 | #define __rsnd_mod_shift_fallback 4 | 279 | #define __rsnd_mod_shift_fallback 4 |
280 | #define __rsnd_mod_shift_hw_params 31 /* always called */ | ||
248 | 281 | ||
249 | #define __rsnd_mod_call_probe 0 | 282 | #define __rsnd_mod_call_probe 0 |
250 | #define __rsnd_mod_call_remove 1 | 283 | #define __rsnd_mod_call_remove 1 |
@@ -254,28 +287,30 @@ struct rsnd_mod { | |||
254 | #define __rsnd_mod_call_stop 1 | 287 | #define __rsnd_mod_call_stop 1 |
255 | #define __rsnd_mod_call_pcm_new 0 | 288 | #define __rsnd_mod_call_pcm_new 0 |
256 | #define __rsnd_mod_call_fallback 0 | 289 | #define __rsnd_mod_call_fallback 0 |
290 | #define __rsnd_mod_call_hw_params 0 | ||
257 | 291 | ||
258 | #define rsnd_mod_to_priv(mod) (rsnd_io_to_priv(rsnd_mod_to_io(mod))) | 292 | #define rsnd_mod_to_priv(mod) (rsnd_io_to_priv(rsnd_mod_to_io(mod))) |
259 | #define rsnd_mod_to_dma(mod) (&(mod)->dma) | 293 | #define rsnd_mod_to_dma(mod) (&(mod)->dma) |
260 | #define rsnd_dma_to_mod(_dma) container_of((_dma), struct rsnd_mod, dma) | ||
261 | #define rsnd_mod_to_io(mod) ((mod)->io) | 294 | #define rsnd_mod_to_io(mod) ((mod)->io) |
262 | #define rsnd_mod_id(mod) ((mod)->id) | 295 | #define rsnd_mod_id(mod) ((mod)->id) |
263 | #define rsnd_mod_hw_start(mod) clk_prepare_enable((mod)->clk) | 296 | #define rsnd_mod_hw_start(mod) clk_enable((mod)->clk) |
264 | #define rsnd_mod_hw_stop(mod) clk_disable_unprepare((mod)->clk) | 297 | #define rsnd_mod_hw_stop(mod) clk_disable((mod)->clk) |
265 | 298 | ||
266 | void rsnd_mod_init(struct rsnd_mod *mod, | 299 | int rsnd_mod_init(struct rsnd_mod *mod, |
267 | struct rsnd_mod_ops *ops, | 300 | struct rsnd_mod_ops *ops, |
268 | struct clk *clk, | 301 | struct clk *clk, |
269 | enum rsnd_mod_type type, | 302 | enum rsnd_mod_type type, |
270 | int id); | 303 | int id); |
304 | void rsnd_mod_quit(struct rsnd_mod *mod); | ||
271 | char *rsnd_mod_name(struct rsnd_mod *mod); | 305 | char *rsnd_mod_name(struct rsnd_mod *mod); |
272 | char *rsnd_mod_dma_name(struct rsnd_mod *mod); | 306 | struct dma_chan *rsnd_mod_dma_req(struct rsnd_mod *mod); |
273 | 307 | ||
274 | /* | 308 | /* |
275 | * R-Car sound DAI | 309 | * R-Car sound DAI |
276 | */ | 310 | */ |
277 | #define RSND_DAI_NAME_SIZE 16 | 311 | #define RSND_DAI_NAME_SIZE 16 |
278 | struct rsnd_dai_stream { | 312 | struct rsnd_dai_stream { |
313 | char name[RSND_DAI_NAME_SIZE]; | ||
279 | struct snd_pcm_substream *substream; | 314 | struct snd_pcm_substream *substream; |
280 | struct rsnd_mod *mod[RSND_MOD_MAX]; | 315 | struct rsnd_mod *mod[RSND_MOD_MAX]; |
281 | struct rsnd_dai_path_info *info; /* rcar_snd.h */ | 316 | struct rsnd_dai_path_info *info; /* rcar_snd.h */ |
@@ -331,9 +366,7 @@ int rsnd_gen_probe(struct platform_device *pdev, | |||
331 | void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv, | 366 | void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv, |
332 | struct rsnd_mod *mod, | 367 | struct rsnd_mod *mod, |
333 | enum rsnd_reg reg); | 368 | enum rsnd_reg reg); |
334 | dma_addr_t rsnd_gen_dma_addr(struct rsnd_priv *priv, | 369 | phys_addr_t rsnd_gen_get_phy_addr(struct rsnd_priv *priv, int reg_id); |
335 | struct rsnd_mod *mod, | ||
336 | int is_play, int is_from); | ||
337 | 370 | ||
338 | #define rsnd_is_gen1(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN1) | 371 | #define rsnd_is_gen1(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN1) |
339 | #define rsnd_is_gen2(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN2) | 372 | #define rsnd_is_gen2(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN2) |
@@ -389,6 +422,11 @@ struct rsnd_priv { | |||
389 | void *adg; | 422 | void *adg; |
390 | 423 | ||
391 | /* | 424 | /* |
425 | * below value will be filled on rsnd_dma_probe() | ||
426 | */ | ||
427 | void *dma; | ||
428 | |||
429 | /* | ||
392 | * below value will be filled on rsnd_ssi_probe() | 430 | * below value will be filled on rsnd_ssi_probe() |
393 | */ | 431 | */ |
394 | void *ssi; | 432 | void *ssi; |
@@ -414,19 +452,6 @@ struct rsnd_priv { | |||
414 | #define rsnd_lock(priv, flags) spin_lock_irqsave(&priv->lock, flags) | 452 | #define rsnd_lock(priv, flags) spin_lock_irqsave(&priv->lock, flags) |
415 | #define rsnd_unlock(priv, flags) spin_unlock_irqrestore(&priv->lock, flags) | 453 | #define rsnd_unlock(priv, flags) spin_unlock_irqrestore(&priv->lock, flags) |
416 | 454 | ||
417 | #define rsnd_info_is_playback(priv, type) \ | ||
418 | ({ \ | ||
419 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); \ | ||
420 | int i, is_play = 0; \ | ||
421 | for (i = 0; i < info->dai_info_nr; i++) { \ | ||
422 | if (info->dai_info[i].playback.type == (type)->info) { \ | ||
423 | is_play = 1; \ | ||
424 | break; \ | ||
425 | } \ | ||
426 | } \ | ||
427 | is_play; \ | ||
428 | }) | ||
429 | |||
430 | /* | 455 | /* |
431 | * rsnd_kctrl | 456 | * rsnd_kctrl |
432 | */ | 457 | */ |
@@ -480,6 +505,8 @@ int rsnd_kctrl_new_e(struct rsnd_mod *mod, | |||
480 | int rsnd_src_probe(struct platform_device *pdev, | 505 | int rsnd_src_probe(struct platform_device *pdev, |
481 | const struct rsnd_of_data *of_data, | 506 | const struct rsnd_of_data *of_data, |
482 | struct rsnd_priv *priv); | 507 | struct rsnd_priv *priv); |
508 | void rsnd_src_remove(struct platform_device *pdev, | ||
509 | struct rsnd_priv *priv); | ||
483 | struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id); | 510 | struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id); |
484 | unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv, | 511 | unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv, |
485 | struct rsnd_dai_stream *io, | 512 | struct rsnd_dai_stream *io, |
@@ -498,9 +525,12 @@ int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod); | |||
498 | int rsnd_ssi_probe(struct platform_device *pdev, | 525 | int rsnd_ssi_probe(struct platform_device *pdev, |
499 | const struct rsnd_of_data *of_data, | 526 | const struct rsnd_of_data *of_data, |
500 | struct rsnd_priv *priv); | 527 | struct rsnd_priv *priv); |
528 | void rsnd_ssi_remove(struct platform_device *pdev, | ||
529 | struct rsnd_priv *priv); | ||
501 | struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id); | 530 | struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id); |
502 | int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod); | 531 | int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod); |
503 | int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod); | 532 | int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod); |
533 | int rsnd_ssi_use_busif(struct rsnd_mod *mod); | ||
504 | 534 | ||
505 | /* | 535 | /* |
506 | * R-Car DVC | 536 | * R-Car DVC |
diff --git a/sound/soc/sh/rcar/rsrc-card.c b/sound/soc/sh/rcar/rsrc-card.c new file mode 100644 index 000000000000..a68517afe615 --- /dev/null +++ b/sound/soc/sh/rcar/rsrc-card.c | |||
@@ -0,0 +1,512 @@ | |||
1 | /* | ||
2 | * Renesas Sampling Rate Convert Sound Card for DPCM | ||
3 | * | ||
4 | * Copyright (C) 2015 Renesas Solutions Corp. | ||
5 | * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> | ||
6 | * | ||
7 | * based on ${LINUX}/sound/soc/generic/simple-card.c | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License version 2 as | ||
11 | * published by the Free Software Foundation. | ||
12 | */ | ||
13 | #include <linux/clk.h> | ||
14 | #include <linux/device.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/of.h> | ||
17 | #include <linux/of_device.h> | ||
18 | #include <linux/platform_device.h> | ||
19 | #include <linux/string.h> | ||
20 | #include <sound/jack.h> | ||
21 | #include <sound/soc.h> | ||
22 | #include <sound/soc-dai.h> | ||
23 | |||
24 | struct rsrc_card_of_data { | ||
25 | const char *prefix; | ||
26 | const struct snd_soc_dapm_route *routes; | ||
27 | int num_routes; | ||
28 | }; | ||
29 | |||
30 | static const struct snd_soc_dapm_route routes_ssi0_ak4642[] = { | ||
31 | {"ak4642 Playback", NULL, "DAI0 Playback"}, | ||
32 | {"DAI0 Capture", NULL, "ak4642 Capture"}, | ||
33 | }; | ||
34 | |||
35 | static const struct rsrc_card_of_data routes_of_ssi0_ak4642 = { | ||
36 | .prefix = "ak4642", | ||
37 | .routes = routes_ssi0_ak4642, | ||
38 | .num_routes = ARRAY_SIZE(routes_ssi0_ak4642), | ||
39 | }; | ||
40 | |||
41 | static const struct of_device_id rsrc_card_of_match[] = { | ||
42 | { .compatible = "renesas,rsrc-card,lager", .data = &routes_of_ssi0_ak4642 }, | ||
43 | { .compatible = "renesas,rsrc-card,koelsch", .data = &routes_of_ssi0_ak4642 }, | ||
44 | {}, | ||
45 | }; | ||
46 | MODULE_DEVICE_TABLE(of, rsrc_card_of_match); | ||
47 | |||
48 | struct rsrc_card_dai { | ||
49 | const char *name; | ||
50 | unsigned int fmt; | ||
51 | unsigned int sysclk; | ||
52 | struct clk *clk; | ||
53 | }; | ||
54 | |||
55 | #define RSRC_FB_NUM 2 /* FE/BE */ | ||
56 | #define IDX_CPU 0 | ||
57 | #define IDX_CODEC 1 | ||
58 | struct rsrc_card_priv { | ||
59 | struct snd_soc_card snd_card; | ||
60 | struct rsrc_card_dai_props { | ||
61 | struct rsrc_card_dai cpu_dai; | ||
62 | struct rsrc_card_dai codec_dai; | ||
63 | } dai_props[RSRC_FB_NUM]; | ||
64 | struct snd_soc_codec_conf codec_conf; | ||
65 | struct snd_soc_dai_link dai_link[RSRC_FB_NUM]; | ||
66 | u32 convert_rate; | ||
67 | }; | ||
68 | |||
69 | #define rsrc_priv_to_dev(priv) ((priv)->snd_card.dev) | ||
70 | #define rsrc_priv_to_link(priv, i) ((priv)->snd_card.dai_link + i) | ||
71 | #define rsrc_priv_to_props(priv, i) ((priv)->dai_props + i) | ||
72 | #define rsrc_dev_to_of_data(dev) (of_match_device(rsrc_card_of_match, (dev))->data) | ||
73 | |||
74 | static int rsrc_card_startup(struct snd_pcm_substream *substream) | ||
75 | { | ||
76 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
77 | struct rsrc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); | ||
78 | struct rsrc_card_dai_props *dai_props = | ||
79 | &priv->dai_props[rtd - rtd->card->rtd]; | ||
80 | int ret; | ||
81 | |||
82 | ret = clk_prepare_enable(dai_props->cpu_dai.clk); | ||
83 | if (ret) | ||
84 | return ret; | ||
85 | |||
86 | ret = clk_prepare_enable(dai_props->codec_dai.clk); | ||
87 | if (ret) | ||
88 | clk_disable_unprepare(dai_props->cpu_dai.clk); | ||
89 | |||
90 | return ret; | ||
91 | } | ||
92 | |||
93 | static void rsrc_card_shutdown(struct snd_pcm_substream *substream) | ||
94 | { | ||
95 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
96 | struct rsrc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); | ||
97 | struct rsrc_card_dai_props *dai_props = | ||
98 | &priv->dai_props[rtd - rtd->card->rtd]; | ||
99 | |||
100 | clk_disable_unprepare(dai_props->cpu_dai.clk); | ||
101 | |||
102 | clk_disable_unprepare(dai_props->codec_dai.clk); | ||
103 | } | ||
104 | |||
105 | static struct snd_soc_ops rsrc_card_ops = { | ||
106 | .startup = rsrc_card_startup, | ||
107 | .shutdown = rsrc_card_shutdown, | ||
108 | }; | ||
109 | |||
110 | static int __rsrc_card_dai_init(struct snd_soc_dai *dai, | ||
111 | struct rsrc_card_dai *set) | ||
112 | { | ||
113 | int ret; | ||
114 | |||
115 | if (set->fmt) { | ||
116 | ret = snd_soc_dai_set_fmt(dai, set->fmt); | ||
117 | if (ret && ret != -ENOTSUPP) { | ||
118 | dev_err(dai->dev, "set_fmt error\n"); | ||
119 | goto err; | ||
120 | } | ||
121 | } | ||
122 | |||
123 | if (set->sysclk) { | ||
124 | ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0); | ||
125 | if (ret && ret != -ENOTSUPP) { | ||
126 | dev_err(dai->dev, "set_sysclk error\n"); | ||
127 | goto err; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | ret = 0; | ||
132 | |||
133 | err: | ||
134 | return ret; | ||
135 | } | ||
136 | |||
137 | static int rsrc_card_dai_init(struct snd_soc_pcm_runtime *rtd) | ||
138 | { | ||
139 | struct rsrc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); | ||
140 | struct snd_soc_dai *codec = rtd->codec_dai; | ||
141 | struct snd_soc_dai *cpu = rtd->cpu_dai; | ||
142 | struct rsrc_card_dai_props *dai_props; | ||
143 | int num, ret; | ||
144 | |||
145 | num = rtd - rtd->card->rtd; | ||
146 | dai_props = &priv->dai_props[num]; | ||
147 | ret = __rsrc_card_dai_init(codec, &dai_props->codec_dai); | ||
148 | if (ret < 0) | ||
149 | return ret; | ||
150 | |||
151 | ret = __rsrc_card_dai_init(cpu, &dai_props->cpu_dai); | ||
152 | if (ret < 0) | ||
153 | return ret; | ||
154 | |||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | static int rsrc_card_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, | ||
159 | struct snd_pcm_hw_params *params) | ||
160 | { | ||
161 | struct rsrc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); | ||
162 | struct snd_interval *rate = hw_param_interval(params, | ||
163 | SNDRV_PCM_HW_PARAM_RATE); | ||
164 | |||
165 | if (!priv->convert_rate) | ||
166 | return 0; | ||
167 | |||
168 | rate->min = rate->max = priv->convert_rate; | ||
169 | |||
170 | return 0; | ||
171 | } | ||
172 | |||
173 | static int | ||
174 | rsrc_card_sub_parse_of(struct rsrc_card_priv *priv, | ||
175 | struct device_node *np, | ||
176 | struct rsrc_card_dai *dai, | ||
177 | struct snd_soc_dai_link *dai_link, | ||
178 | int *args_count) | ||
179 | { | ||
180 | struct device *dev = rsrc_priv_to_dev(priv); | ||
181 | const struct rsrc_card_of_data *of_data = rsrc_dev_to_of_data(dev); | ||
182 | struct of_phandle_args args; | ||
183 | struct device_node **p_node; | ||
184 | struct clk *clk; | ||
185 | const char **dai_name; | ||
186 | const char **name; | ||
187 | u32 val; | ||
188 | int ret; | ||
189 | |||
190 | if (args_count) { | ||
191 | p_node = &dai_link->cpu_of_node; | ||
192 | dai_name = &dai_link->cpu_dai_name; | ||
193 | name = &dai_link->cpu_name; | ||
194 | } else { | ||
195 | p_node = &dai_link->codec_of_node; | ||
196 | dai_name = &dai_link->codec_dai_name; | ||
197 | name = &dai_link->codec_name; | ||
198 | } | ||
199 | |||
200 | if (!np) { | ||
201 | /* use snd-soc-dummy */ | ||
202 | *p_node = NULL; | ||
203 | *dai_name = "snd-soc-dummy-dai"; | ||
204 | *name = "snd-soc-dummy"; | ||
205 | return 0; | ||
206 | } | ||
207 | |||
208 | /* | ||
209 | * Get node via "sound-dai = <&phandle port>" | ||
210 | * it will be used as xxx_of_node on soc_bind_dai_link() | ||
211 | */ | ||
212 | ret = of_parse_phandle_with_args(np, "sound-dai", | ||
213 | "#sound-dai-cells", 0, &args); | ||
214 | if (ret) | ||
215 | return ret; | ||
216 | |||
217 | *p_node = args.np; | ||
218 | |||
219 | /* Get dai->name */ | ||
220 | ret = snd_soc_of_get_dai_name(np, dai_name); | ||
221 | if (ret < 0) | ||
222 | return ret; | ||
223 | |||
224 | /* | ||
225 | * FIXME | ||
226 | * | ||
227 | * rsrc assumes DPCM playback/capture | ||
228 | */ | ||
229 | dai_link->dpcm_playback = 1; | ||
230 | dai_link->dpcm_capture = 1; | ||
231 | |||
232 | if (args_count) { | ||
233 | *args_count = args.args_count; | ||
234 | dai_link->dynamic = 1; | ||
235 | } else { | ||
236 | dai_link->no_pcm = 1; | ||
237 | priv->codec_conf.of_node = (*p_node); | ||
238 | priv->codec_conf.name_prefix = of_data->prefix; | ||
239 | } | ||
240 | |||
241 | /* | ||
242 | * Parse dai->sysclk come from "clocks = <&xxx>" | ||
243 | * (if system has common clock) | ||
244 | * or "system-clock-frequency = <xxx>" | ||
245 | * or device's module clock. | ||
246 | */ | ||
247 | if (of_property_read_bool(np, "clocks")) { | ||
248 | clk = of_clk_get(np, 0); | ||
249 | if (IS_ERR(clk)) { | ||
250 | ret = PTR_ERR(clk); | ||
251 | return ret; | ||
252 | } | ||
253 | |||
254 | dai->sysclk = clk_get_rate(clk); | ||
255 | dai->clk = clk; | ||
256 | } else if (!of_property_read_u32(np, "system-clock-frequency", &val)) { | ||
257 | dai->sysclk = val; | ||
258 | } else { | ||
259 | clk = of_clk_get(args.np, 0); | ||
260 | if (!IS_ERR(clk)) | ||
261 | dai->sysclk = clk_get_rate(clk); | ||
262 | } | ||
263 | |||
264 | return 0; | ||
265 | } | ||
266 | |||
267 | static int rsrc_card_parse_daifmt(struct device_node *node, | ||
268 | struct rsrc_card_priv *priv, | ||
269 | struct device_node *codec, | ||
270 | int idx) | ||
271 | { | ||
272 | struct device_node *bitclkmaster = NULL; | ||
273 | struct device_node *framemaster = NULL; | ||
274 | struct rsrc_card_dai_props *dai_props = rsrc_priv_to_props(priv, idx); | ||
275 | struct rsrc_card_dai *cpu_dai = &dai_props->cpu_dai; | ||
276 | struct rsrc_card_dai *codec_dai = &dai_props->codec_dai; | ||
277 | unsigned int daifmt; | ||
278 | |||
279 | daifmt = snd_soc_of_parse_daifmt(node, NULL, | ||
280 | &bitclkmaster, &framemaster); | ||
281 | daifmt &= ~SND_SOC_DAIFMT_MASTER_MASK; | ||
282 | |||
283 | if (!bitclkmaster && !framemaster) | ||
284 | return -EINVAL; | ||
285 | |||
286 | if (codec == bitclkmaster) | ||
287 | daifmt |= (codec == framemaster) ? | ||
288 | SND_SOC_DAIFMT_CBM_CFM : SND_SOC_DAIFMT_CBM_CFS; | ||
289 | else | ||
290 | daifmt |= (codec == framemaster) ? | ||
291 | SND_SOC_DAIFMT_CBS_CFM : SND_SOC_DAIFMT_CBS_CFS; | ||
292 | |||
293 | cpu_dai->fmt = daifmt; | ||
294 | codec_dai->fmt = daifmt; | ||
295 | |||
296 | of_node_put(bitclkmaster); | ||
297 | of_node_put(framemaster); | ||
298 | |||
299 | return 0; | ||
300 | } | ||
301 | |||
302 | static int rsrc_card_dai_link_of(struct device_node *node, | ||
303 | struct rsrc_card_priv *priv, | ||
304 | int idx) | ||
305 | { | ||
306 | struct device *dev = rsrc_priv_to_dev(priv); | ||
307 | struct snd_soc_dai_link *dai_link = rsrc_priv_to_link(priv, idx); | ||
308 | struct rsrc_card_dai_props *dai_props = rsrc_priv_to_props(priv, idx); | ||
309 | struct device_node *cpu = NULL; | ||
310 | struct device_node *codec = NULL; | ||
311 | char *name; | ||
312 | char prop[128]; | ||
313 | int ret, cpu_args; | ||
314 | |||
315 | cpu = of_get_child_by_name(node, "cpu"); | ||
316 | codec = of_get_child_by_name(node, "codec"); | ||
317 | |||
318 | if (!cpu || !codec) { | ||
319 | ret = -EINVAL; | ||
320 | dev_err(dev, "%s: Can't find %s DT node\n", __func__, prop); | ||
321 | goto dai_link_of_err; | ||
322 | } | ||
323 | |||
324 | ret = rsrc_card_parse_daifmt(node, priv, codec, idx); | ||
325 | if (ret < 0) | ||
326 | goto dai_link_of_err; | ||
327 | |||
328 | ret = rsrc_card_sub_parse_of(priv, (idx == IDX_CPU) ? cpu : NULL, | ||
329 | &dai_props->cpu_dai, | ||
330 | dai_link, | ||
331 | &cpu_args); | ||
332 | if (ret < 0) | ||
333 | goto dai_link_of_err; | ||
334 | |||
335 | ret = rsrc_card_sub_parse_of(priv, (idx == IDX_CODEC) ? codec : NULL, | ||
336 | &dai_props->codec_dai, | ||
337 | dai_link, | ||
338 | NULL); | ||
339 | if (ret < 0) | ||
340 | goto dai_link_of_err; | ||
341 | |||
342 | if (!dai_link->cpu_dai_name || !dai_link->codec_dai_name) { | ||
343 | ret = -EINVAL; | ||
344 | goto dai_link_of_err; | ||
345 | } | ||
346 | |||
347 | /* Simple Card assumes platform == cpu */ | ||
348 | dai_link->platform_of_node = dai_link->cpu_of_node; | ||
349 | |||
350 | /* DAI link name is created from CPU/CODEC dai name */ | ||
351 | name = devm_kzalloc(dev, | ||
352 | strlen(dai_link->cpu_dai_name) + | ||
353 | strlen(dai_link->codec_dai_name) + 2, | ||
354 | GFP_KERNEL); | ||
355 | if (!name) { | ||
356 | ret = -ENOMEM; | ||
357 | goto dai_link_of_err; | ||
358 | } | ||
359 | |||
360 | sprintf(name, "%s-%s", dai_link->cpu_dai_name, | ||
361 | dai_link->codec_dai_name); | ||
362 | dai_link->name = dai_link->stream_name = name; | ||
363 | dai_link->ops = &rsrc_card_ops; | ||
364 | dai_link->init = rsrc_card_dai_init; | ||
365 | |||
366 | if (idx == IDX_CODEC) | ||
367 | dai_link->be_hw_params_fixup = rsrc_card_be_hw_params_fixup; | ||
368 | |||
369 | dev_dbg(dev, "\tname : %s\n", dai_link->stream_name); | ||
370 | dev_dbg(dev, "\tcpu : %s / %04x / %d\n", | ||
371 | dai_link->cpu_dai_name, | ||
372 | dai_props->cpu_dai.fmt, | ||
373 | dai_props->cpu_dai.sysclk); | ||
374 | dev_dbg(dev, "\tcodec : %s / %04x / %d\n", | ||
375 | dai_link->codec_dai_name, | ||
376 | dai_props->codec_dai.fmt, | ||
377 | dai_props->codec_dai.sysclk); | ||
378 | |||
379 | /* | ||
380 | * In soc_bind_dai_link() will check cpu name after | ||
381 | * of_node matching if dai_link has cpu_dai_name. | ||
382 | * but, it will never match if name was created by | ||
383 | * fmt_single_name() remove cpu_dai_name if cpu_args | ||
384 | * was 0. See: | ||
385 | * fmt_single_name() | ||
386 | * fmt_multiple_name() | ||
387 | */ | ||
388 | if (!cpu_args) | ||
389 | dai_link->cpu_dai_name = NULL; | ||
390 | |||
391 | dai_link_of_err: | ||
392 | of_node_put(cpu); | ||
393 | of_node_put(codec); | ||
394 | |||
395 | return ret; | ||
396 | } | ||
397 | |||
398 | static int rsrc_card_parse_of(struct device_node *node, | ||
399 | struct rsrc_card_priv *priv) | ||
400 | { | ||
401 | struct device *dev = rsrc_priv_to_dev(priv); | ||
402 | const struct rsrc_card_of_data *of_data = rsrc_dev_to_of_data(dev); | ||
403 | int ret; | ||
404 | int i; | ||
405 | |||
406 | if (!node) | ||
407 | return -EINVAL; | ||
408 | |||
409 | /* Parse the card name from DT */ | ||
410 | snd_soc_of_parse_card_name(&priv->snd_card, "card-name"); | ||
411 | |||
412 | /* DAPM routes */ | ||
413 | priv->snd_card.of_dapm_routes = of_data->routes; | ||
414 | priv->snd_card.num_of_dapm_routes = of_data->num_routes; | ||
415 | |||
416 | /* sampling rate convert */ | ||
417 | of_property_read_u32(node, "convert-rate", &priv->convert_rate); | ||
418 | |||
419 | dev_dbg(dev, "New rsrc-audio-card: %s (%d)\n", | ||
420 | priv->snd_card.name ? priv->snd_card.name : "", | ||
421 | priv->convert_rate); | ||
422 | |||
423 | /* FE/BE */ | ||
424 | for (i = 0; i < RSRC_FB_NUM; i++) { | ||
425 | ret = rsrc_card_dai_link_of(node, priv, i); | ||
426 | if (ret < 0) | ||
427 | return ret; | ||
428 | } | ||
429 | |||
430 | if (!priv->snd_card.name) | ||
431 | priv->snd_card.name = priv->snd_card.dai_link->name; | ||
432 | |||
433 | return 0; | ||
434 | } | ||
435 | |||
436 | /* Decrease the reference count of the device nodes */ | ||
437 | static int rsrc_card_unref(struct snd_soc_card *card) | ||
438 | { | ||
439 | struct snd_soc_dai_link *dai_link; | ||
440 | int num_links; | ||
441 | |||
442 | for (num_links = 0, dai_link = card->dai_link; | ||
443 | num_links < card->num_links; | ||
444 | num_links++, dai_link++) { | ||
445 | of_node_put(dai_link->cpu_of_node); | ||
446 | of_node_put(dai_link->codec_of_node); | ||
447 | } | ||
448 | return 0; | ||
449 | } | ||
450 | |||
451 | static int rsrc_card_probe(struct platform_device *pdev) | ||
452 | { | ||
453 | struct rsrc_card_priv *priv; | ||
454 | struct snd_soc_dai_link *dai_link; | ||
455 | struct device_node *np = pdev->dev.of_node; | ||
456 | struct device *dev = &pdev->dev; | ||
457 | int ret; | ||
458 | |||
459 | /* Allocate the private data */ | ||
460 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | ||
461 | if (!priv) | ||
462 | return -ENOMEM; | ||
463 | |||
464 | /* Init snd_soc_card */ | ||
465 | priv->snd_card.owner = THIS_MODULE; | ||
466 | priv->snd_card.dev = dev; | ||
467 | dai_link = priv->dai_link; | ||
468 | priv->snd_card.dai_link = dai_link; | ||
469 | priv->snd_card.num_links = RSRC_FB_NUM; | ||
470 | priv->snd_card.codec_conf = &priv->codec_conf; | ||
471 | priv->snd_card.num_configs = 1; | ||
472 | |||
473 | ret = rsrc_card_parse_of(np, priv); | ||
474 | if (ret < 0) { | ||
475 | if (ret != -EPROBE_DEFER) | ||
476 | dev_err(dev, "parse error %d\n", ret); | ||
477 | goto err; | ||
478 | } | ||
479 | |||
480 | snd_soc_card_set_drvdata(&priv->snd_card, priv); | ||
481 | |||
482 | ret = devm_snd_soc_register_card(&pdev->dev, &priv->snd_card); | ||
483 | if (ret >= 0) | ||
484 | return ret; | ||
485 | err: | ||
486 | rsrc_card_unref(&priv->snd_card); | ||
487 | |||
488 | return ret; | ||
489 | } | ||
490 | |||
491 | static int rsrc_card_remove(struct platform_device *pdev) | ||
492 | { | ||
493 | struct snd_soc_card *card = platform_get_drvdata(pdev); | ||
494 | |||
495 | return rsrc_card_unref(card); | ||
496 | } | ||
497 | |||
498 | static struct platform_driver rsrc_card = { | ||
499 | .driver = { | ||
500 | .name = "renesas-src-audio-card", | ||
501 | .of_match_table = rsrc_card_of_match, | ||
502 | }, | ||
503 | .probe = rsrc_card_probe, | ||
504 | .remove = rsrc_card_remove, | ||
505 | }; | ||
506 | |||
507 | module_platform_driver(rsrc_card); | ||
508 | |||
509 | MODULE_ALIAS("platform:renesas-src-audio-card"); | ||
510 | MODULE_LICENSE("GPL"); | ||
511 | MODULE_DESCRIPTION("Renesas Sampling Rate Convert Sound Card"); | ||
512 | MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); | ||
diff --git a/sound/soc/sh/rcar/src.c b/sound/soc/sh/rcar/src.c index 81c182b4bad5..3beb32eb412a 100644 --- a/sound/soc/sh/rcar/src.c +++ b/sound/soc/sh/rcar/src.c | |||
@@ -22,16 +22,20 @@ | |||
22 | struct rsnd_src { | 22 | struct rsnd_src { |
23 | struct rsnd_src_platform_info *info; /* rcar_snd.h */ | 23 | struct rsnd_src_platform_info *info; /* rcar_snd.h */ |
24 | struct rsnd_mod mod; | 24 | struct rsnd_mod mod; |
25 | struct rsnd_kctrl_cfg_s sen; /* sync convert enable */ | ||
26 | struct rsnd_kctrl_cfg_s sync; /* sync convert */ | ||
27 | u32 convert_rate; /* sampling rate convert */ | ||
25 | int err; | 28 | int err; |
26 | }; | 29 | }; |
27 | 30 | ||
28 | #define RSND_SRC_NAME_SIZE 16 | 31 | #define RSND_SRC_NAME_SIZE 16 |
29 | 32 | ||
30 | #define rsnd_src_convert_rate(p) ((p)->info->convert_rate) | 33 | #define rsnd_enable_sync_convert(src) ((src)->sen.val) |
34 | #define rsnd_src_of_node(priv) \ | ||
35 | of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,src") | ||
36 | |||
31 | #define rsnd_mod_to_src(_mod) \ | 37 | #define rsnd_mod_to_src(_mod) \ |
32 | container_of((_mod), struct rsnd_src, mod) | 38 | container_of((_mod), struct rsnd_src, mod) |
33 | #define rsnd_src_dma_available(src) \ | ||
34 | rsnd_dma_available(rsnd_mod_to_dma(&(src)->mod)) | ||
35 | 39 | ||
36 | #define for_each_rsnd_src(pos, priv, i) \ | 40 | #define for_each_rsnd_src(pos, priv, i) \ |
37 | for ((i) = 0; \ | 41 | for ((i) = 0; \ |
@@ -113,6 +117,17 @@ struct rsnd_src { | |||
113 | /* | 117 | /* |
114 | * Gen1/Gen2 common functions | 118 | * Gen1/Gen2 common functions |
115 | */ | 119 | */ |
120 | static struct dma_chan *rsnd_src_dma_req(struct rsnd_mod *mod) | ||
121 | { | ||
122 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | ||
123 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); | ||
124 | int is_play = rsnd_io_is_play(io); | ||
125 | |||
126 | return rsnd_dma_request_channel(rsnd_src_of_node(priv), | ||
127 | mod, | ||
128 | is_play ? "rx" : "tx"); | ||
129 | } | ||
130 | |||
116 | int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod, | 131 | int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod, |
117 | int use_busif) | 132 | int use_busif) |
118 | { | 133 | { |
@@ -220,6 +235,30 @@ int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod) | |||
220 | return 0; | 235 | return 0; |
221 | } | 236 | } |
222 | 237 | ||
238 | static u32 rsnd_src_convert_rate(struct rsnd_src *src) | ||
239 | { | ||
240 | struct rsnd_mod *mod = &src->mod; | ||
241 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); | ||
242 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); | ||
243 | u32 convert_rate; | ||
244 | |||
245 | if (!runtime) | ||
246 | return 0; | ||
247 | |||
248 | if (!rsnd_enable_sync_convert(src)) | ||
249 | return src->convert_rate; | ||
250 | |||
251 | convert_rate = src->sync.val; | ||
252 | |||
253 | if (!convert_rate) | ||
254 | convert_rate = src->convert_rate; | ||
255 | |||
256 | if (!convert_rate) | ||
257 | convert_rate = runtime->rate; | ||
258 | |||
259 | return convert_rate; | ||
260 | } | ||
261 | |||
223 | unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv, | 262 | unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv, |
224 | struct rsnd_dai_stream *io, | 263 | struct rsnd_dai_stream *io, |
225 | struct snd_pcm_runtime *runtime) | 264 | struct snd_pcm_runtime *runtime) |
@@ -276,7 +315,43 @@ static int rsnd_src_set_convert_rate(struct rsnd_mod *mod) | |||
276 | return 0; | 315 | return 0; |
277 | } | 316 | } |
278 | 317 | ||
279 | static int rsnd_src_init(struct rsnd_mod *mod) | 318 | static int rsnd_src_hw_params(struct rsnd_mod *mod, |
319 | struct snd_pcm_substream *substream, | ||
320 | struct snd_pcm_hw_params *fe_params) | ||
321 | { | ||
322 | struct rsnd_src *src = rsnd_mod_to_src(mod); | ||
323 | struct snd_soc_pcm_runtime *fe = substream->private_data; | ||
324 | |||
325 | /* default value (mainly for non-DT) */ | ||
326 | src->convert_rate = src->info->convert_rate; | ||
327 | |||
328 | /* | ||
329 | * SRC assumes that it is used under DPCM if user want to use | ||
330 | * sampling rate convert. Then, SRC should be FE. | ||
331 | * And then, this function will be called *after* BE settings. | ||
332 | * this means, each BE already has fixuped hw_params. | ||
333 | * see | ||
334 | * dpcm_fe_dai_hw_params() | ||
335 | * dpcm_be_dai_hw_params() | ||
336 | */ | ||
337 | if (fe->dai_link->dynamic) { | ||
338 | int stream = substream->stream; | ||
339 | struct snd_soc_dpcm *dpcm; | ||
340 | struct snd_pcm_hw_params *be_params; | ||
341 | |||
342 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { | ||
343 | be_params = &dpcm->hw_params; | ||
344 | |||
345 | if (params_rate(fe_params) != params_rate(be_params)) | ||
346 | src->convert_rate = params_rate(be_params); | ||
347 | } | ||
348 | } | ||
349 | |||
350 | return 0; | ||
351 | } | ||
352 | |||
353 | static int rsnd_src_init(struct rsnd_mod *mod, | ||
354 | struct rsnd_priv *priv) | ||
280 | { | 355 | { |
281 | struct rsnd_src *src = rsnd_mod_to_src(mod); | 356 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
282 | 357 | ||
@@ -284,6 +359,9 @@ static int rsnd_src_init(struct rsnd_mod *mod) | |||
284 | 359 | ||
285 | src->err = 0; | 360 | src->err = 0; |
286 | 361 | ||
362 | /* reset sync convert_rate */ | ||
363 | src->sync.val = 0; | ||
364 | |||
287 | /* | 365 | /* |
288 | * Initialize the operation of the SRC internal circuits | 366 | * Initialize the operation of the SRC internal circuits |
289 | * see rsnd_src_start() | 367 | * see rsnd_src_start() |
@@ -305,6 +383,11 @@ static int rsnd_src_quit(struct rsnd_mod *mod, | |||
305 | dev_warn(dev, "%s[%d] under/over flow err = %d\n", | 383 | dev_warn(dev, "%s[%d] under/over flow err = %d\n", |
306 | rsnd_mod_name(mod), rsnd_mod_id(mod), src->err); | 384 | rsnd_mod_name(mod), rsnd_mod_id(mod), src->err); |
307 | 385 | ||
386 | src->convert_rate = 0; | ||
387 | |||
388 | /* reset sync convert_rate */ | ||
389 | src->sync.val = 0; | ||
390 | |||
308 | return 0; | 391 | return 0; |
309 | } | 392 | } |
310 | 393 | ||
@@ -448,23 +531,12 @@ static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod) | |||
448 | return 0; | 531 | return 0; |
449 | } | 532 | } |
450 | 533 | ||
451 | static int rsnd_src_probe_gen1(struct rsnd_mod *mod, | ||
452 | struct rsnd_priv *priv) | ||
453 | { | ||
454 | struct device *dev = rsnd_priv_to_dev(priv); | ||
455 | |||
456 | dev_dbg(dev, "%s[%d] (Gen1) is probed\n", | ||
457 | rsnd_mod_name(mod), rsnd_mod_id(mod)); | ||
458 | |||
459 | return 0; | ||
460 | } | ||
461 | |||
462 | static int rsnd_src_init_gen1(struct rsnd_mod *mod, | 534 | static int rsnd_src_init_gen1(struct rsnd_mod *mod, |
463 | struct rsnd_priv *priv) | 535 | struct rsnd_priv *priv) |
464 | { | 536 | { |
465 | int ret; | 537 | int ret; |
466 | 538 | ||
467 | ret = rsnd_src_init(mod); | 539 | ret = rsnd_src_init(mod, priv); |
468 | if (ret < 0) | 540 | if (ret < 0) |
469 | return ret; | 541 | return ret; |
470 | 542 | ||
@@ -505,11 +577,12 @@ static int rsnd_src_stop_gen1(struct rsnd_mod *mod, | |||
505 | 577 | ||
506 | static struct rsnd_mod_ops rsnd_src_gen1_ops = { | 578 | static struct rsnd_mod_ops rsnd_src_gen1_ops = { |
507 | .name = SRC_NAME, | 579 | .name = SRC_NAME, |
508 | .probe = rsnd_src_probe_gen1, | 580 | .dma_req = rsnd_src_dma_req, |
509 | .init = rsnd_src_init_gen1, | 581 | .init = rsnd_src_init_gen1, |
510 | .quit = rsnd_src_quit, | 582 | .quit = rsnd_src_quit, |
511 | .start = rsnd_src_start_gen1, | 583 | .start = rsnd_src_start_gen1, |
512 | .stop = rsnd_src_stop_gen1, | 584 | .stop = rsnd_src_stop_gen1, |
585 | .hw_params = rsnd_src_hw_params, | ||
513 | }; | 586 | }; |
514 | 587 | ||
515 | /* | 588 | /* |
@@ -607,13 +680,17 @@ static irqreturn_t rsnd_src_interrupt_gen2(int irq, void *data) | |||
607 | 680 | ||
608 | if (rsnd_src_error_record_gen2(mod)) { | 681 | if (rsnd_src_error_record_gen2(mod)) { |
609 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | 682 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
683 | struct rsnd_src *src = rsnd_mod_to_src(mod); | ||
610 | struct device *dev = rsnd_priv_to_dev(priv); | 684 | struct device *dev = rsnd_priv_to_dev(priv); |
611 | 685 | ||
612 | _rsnd_src_stop_gen2(mod); | ||
613 | _rsnd_src_start_gen2(mod); | ||
614 | |||
615 | dev_dbg(dev, "%s[%d] restart\n", | 686 | dev_dbg(dev, "%s[%d] restart\n", |
616 | rsnd_mod_name(mod), rsnd_mod_id(mod)); | 687 | rsnd_mod_name(mod), rsnd_mod_id(mod)); |
688 | |||
689 | _rsnd_src_stop_gen2(mod); | ||
690 | if (src->err < 1024) | ||
691 | _rsnd_src_start_gen2(mod); | ||
692 | else | ||
693 | dev_warn(dev, "no more SRC restart\n"); | ||
617 | } | 694 | } |
618 | 695 | ||
619 | return IRQ_HANDLED; | 696 | return IRQ_HANDLED; |
@@ -627,6 +704,7 @@ static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod) | |||
627 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); | 704 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
628 | struct rsnd_src *src = rsnd_mod_to_src(mod); | 705 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
629 | u32 convert_rate = rsnd_src_convert_rate(src); | 706 | u32 convert_rate = rsnd_src_convert_rate(src); |
707 | u32 cr, route; | ||
630 | uint ratio; | 708 | uint ratio; |
631 | int ret; | 709 | int ret; |
632 | 710 | ||
@@ -647,13 +725,21 @@ static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod) | |||
647 | if (ret < 0) | 725 | if (ret < 0) |
648 | return ret; | 726 | return ret; |
649 | 727 | ||
650 | rsnd_mod_write(mod, SRC_SRCCR, 0x00011110); | 728 | cr = 0x00011110; |
651 | 729 | route = 0x0; | |
652 | if (convert_rate) { | 730 | if (convert_rate) { |
653 | /* Gen1/Gen2 are not compatible */ | 731 | route = 0x1; |
654 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1); | 732 | |
733 | if (rsnd_enable_sync_convert(src)) { | ||
734 | cr |= 0x1; | ||
735 | route |= rsnd_io_is_play(io) ? | ||
736 | (0x1 << 24) : (0x1 << 25); | ||
737 | } | ||
655 | } | 738 | } |
656 | 739 | ||
740 | rsnd_mod_write(mod, SRC_SRCCR, cr); | ||
741 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, route); | ||
742 | |||
657 | switch (rsnd_mod_id(mod)) { | 743 | switch (rsnd_mod_id(mod)) { |
658 | case 5: | 744 | case 5: |
659 | case 6: | 745 | case 6: |
@@ -708,24 +794,12 @@ static int rsnd_src_probe_gen2(struct rsnd_mod *mod, | |||
708 | IRQF_SHARED, | 794 | IRQF_SHARED, |
709 | dev_name(dev), mod); | 795 | dev_name(dev), mod); |
710 | if (ret) | 796 | if (ret) |
711 | goto rsnd_src_probe_gen2_fail; | 797 | return ret; |
712 | } | 798 | } |
713 | 799 | ||
714 | ret = rsnd_dma_init(priv, | 800 | ret = rsnd_dma_init(priv, |
715 | rsnd_mod_to_dma(mod), | 801 | rsnd_mod_to_dma(mod), |
716 | rsnd_info_is_playback(priv, src), | ||
717 | src->info->dma_id); | 802 | src->info->dma_id); |
718 | if (ret) | ||
719 | goto rsnd_src_probe_gen2_fail; | ||
720 | |||
721 | dev_dbg(dev, "%s[%d] (Gen2) is probed\n", | ||
722 | rsnd_mod_name(mod), rsnd_mod_id(mod)); | ||
723 | |||
724 | return ret; | ||
725 | |||
726 | rsnd_src_probe_gen2_fail: | ||
727 | dev_err(dev, "%s[%d] (Gen2) failed\n", | ||
728 | rsnd_mod_name(mod), rsnd_mod_id(mod)); | ||
729 | 803 | ||
730 | return ret; | 804 | return ret; |
731 | } | 805 | } |
@@ -733,7 +807,7 @@ rsnd_src_probe_gen2_fail: | |||
733 | static int rsnd_src_remove_gen2(struct rsnd_mod *mod, | 807 | static int rsnd_src_remove_gen2(struct rsnd_mod *mod, |
734 | struct rsnd_priv *priv) | 808 | struct rsnd_priv *priv) |
735 | { | 809 | { |
736 | rsnd_dma_quit(priv, rsnd_mod_to_dma(mod)); | 810 | rsnd_dma_quit(rsnd_mod_to_dma(mod)); |
737 | 811 | ||
738 | return 0; | 812 | return 0; |
739 | } | 813 | } |
@@ -743,7 +817,7 @@ static int rsnd_src_init_gen2(struct rsnd_mod *mod, | |||
743 | { | 817 | { |
744 | int ret; | 818 | int ret; |
745 | 819 | ||
746 | ret = rsnd_src_init(mod); | 820 | ret = rsnd_src_init(mod, priv); |
747 | if (ret < 0) | 821 | if (ret < 0) |
748 | return ret; | 822 | return ret; |
749 | 823 | ||
@@ -778,14 +852,91 @@ static int rsnd_src_stop_gen2(struct rsnd_mod *mod, | |||
778 | return ret; | 852 | return ret; |
779 | } | 853 | } |
780 | 854 | ||
855 | static void rsnd_src_reconvert_update(struct rsnd_mod *mod) | ||
856 | { | ||
857 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); | ||
858 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); | ||
859 | struct rsnd_src *src = rsnd_mod_to_src(mod); | ||
860 | u32 convert_rate = rsnd_src_convert_rate(src); | ||
861 | u32 fsrate; | ||
862 | |||
863 | if (!runtime) | ||
864 | return; | ||
865 | |||
866 | if (!convert_rate) | ||
867 | convert_rate = runtime->rate; | ||
868 | |||
869 | fsrate = 0x0400000 / convert_rate * runtime->rate; | ||
870 | |||
871 | /* update IFS */ | ||
872 | rsnd_mod_write(mod, SRC_IFSVR, fsrate); | ||
873 | } | ||
874 | |||
875 | static int rsnd_src_pcm_new(struct rsnd_mod *mod, | ||
876 | struct snd_soc_pcm_runtime *rtd) | ||
877 | { | ||
878 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | ||
879 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); | ||
880 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); | ||
881 | struct rsnd_src *src = rsnd_mod_to_src(mod); | ||
882 | int ret; | ||
883 | |||
884 | /* | ||
885 | * enable SRC sync convert if possible | ||
886 | */ | ||
887 | |||
888 | /* | ||
889 | * Gen1 is not supported | ||
890 | */ | ||
891 | if (rsnd_is_gen1(priv)) | ||
892 | return 0; | ||
893 | |||
894 | /* | ||
895 | * SRC sync convert needs clock master | ||
896 | */ | ||
897 | if (!rsnd_rdai_is_clk_master(rdai)) | ||
898 | return 0; | ||
899 | |||
900 | /* | ||
901 | * We can't use SRC sync convert | ||
902 | * if it has DVC | ||
903 | */ | ||
904 | if (rsnd_io_to_mod_dvc(io)) | ||
905 | return 0; | ||
906 | |||
907 | /* | ||
908 | * enable sync convert | ||
909 | */ | ||
910 | ret = rsnd_kctrl_new_s(mod, rtd, | ||
911 | rsnd_io_is_play(io) ? | ||
912 | "SRC Out Rate Switch" : | ||
913 | "SRC In Rate Switch", | ||
914 | rsnd_src_reconvert_update, | ||
915 | &src->sen, 1); | ||
916 | if (ret < 0) | ||
917 | return ret; | ||
918 | |||
919 | ret = rsnd_kctrl_new_s(mod, rtd, | ||
920 | rsnd_io_is_play(io) ? | ||
921 | "SRC Out Rate" : | ||
922 | "SRC In Rate", | ||
923 | rsnd_src_reconvert_update, | ||
924 | &src->sync, 192000); | ||
925 | |||
926 | return ret; | ||
927 | } | ||
928 | |||
781 | static struct rsnd_mod_ops rsnd_src_gen2_ops = { | 929 | static struct rsnd_mod_ops rsnd_src_gen2_ops = { |
782 | .name = SRC_NAME, | 930 | .name = SRC_NAME, |
931 | .dma_req = rsnd_src_dma_req, | ||
783 | .probe = rsnd_src_probe_gen2, | 932 | .probe = rsnd_src_probe_gen2, |
784 | .remove = rsnd_src_remove_gen2, | 933 | .remove = rsnd_src_remove_gen2, |
785 | .init = rsnd_src_init_gen2, | 934 | .init = rsnd_src_init_gen2, |
786 | .quit = rsnd_src_quit, | 935 | .quit = rsnd_src_quit, |
787 | .start = rsnd_src_start_gen2, | 936 | .start = rsnd_src_start_gen2, |
788 | .stop = rsnd_src_stop_gen2, | 937 | .stop = rsnd_src_stop_gen2, |
938 | .hw_params = rsnd_src_hw_params, | ||
939 | .pcm_new = rsnd_src_pcm_new, | ||
789 | }; | 940 | }; |
790 | 941 | ||
791 | struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id) | 942 | struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id) |
@@ -810,7 +961,7 @@ static void rsnd_of_parse_src(struct platform_device *pdev, | |||
810 | if (!of_data) | 961 | if (!of_data) |
811 | return; | 962 | return; |
812 | 963 | ||
813 | src_node = of_get_child_by_name(dev->of_node, "rcar_sound,src"); | 964 | src_node = rsnd_src_of_node(priv); |
814 | if (!src_node) | 965 | if (!src_node) |
815 | return; | 966 | return; |
816 | 967 | ||
@@ -850,7 +1001,7 @@ int rsnd_src_probe(struct platform_device *pdev, | |||
850 | struct rsnd_mod_ops *ops; | 1001 | struct rsnd_mod_ops *ops; |
851 | struct clk *clk; | 1002 | struct clk *clk; |
852 | char name[RSND_SRC_NAME_SIZE]; | 1003 | char name[RSND_SRC_NAME_SIZE]; |
853 | int i, nr; | 1004 | int i, nr, ret; |
854 | 1005 | ||
855 | ops = NULL; | 1006 | ops = NULL; |
856 | if (rsnd_is_gen1(priv)) | 1007 | if (rsnd_is_gen1(priv)) |
@@ -890,10 +1041,21 @@ int rsnd_src_probe(struct platform_device *pdev, | |||
890 | 1041 | ||
891 | src->info = &info->src_info[i]; | 1042 | src->info = &info->src_info[i]; |
892 | 1043 | ||
893 | rsnd_mod_init(&src->mod, ops, clk, RSND_MOD_SRC, i); | 1044 | ret = rsnd_mod_init(&src->mod, ops, clk, RSND_MOD_SRC, i); |
894 | 1045 | if (ret) | |
895 | dev_dbg(dev, "SRC%d probed\n", i); | 1046 | return ret; |
896 | } | 1047 | } |
897 | 1048 | ||
898 | return 0; | 1049 | return 0; |
899 | } | 1050 | } |
1051 | |||
1052 | void rsnd_src_remove(struct platform_device *pdev, | ||
1053 | struct rsnd_priv *priv) | ||
1054 | { | ||
1055 | struct rsnd_src *src; | ||
1056 | int i; | ||
1057 | |||
1058 | for_each_rsnd_src(src, priv, i) { | ||
1059 | rsnd_mod_quit(&src->mod); | ||
1060 | } | ||
1061 | } | ||
diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c index 9e7b627c08e2..7bb9c087f3dc 100644 --- a/sound/soc/sh/rcar/ssi.c +++ b/sound/soc/sh/rcar/ssi.c | |||
@@ -80,13 +80,13 @@ struct rsnd_ssi { | |||
80 | #define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod) | 80 | #define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod) |
81 | #define rsnd_dma_to_ssi(dma) rsnd_mod_to_ssi(rsnd_dma_to_mod(dma)) | 81 | #define rsnd_dma_to_ssi(dma) rsnd_mod_to_ssi(rsnd_dma_to_mod(dma)) |
82 | #define rsnd_ssi_pio_available(ssi) ((ssi)->info->irq > 0) | 82 | #define rsnd_ssi_pio_available(ssi) ((ssi)->info->irq > 0) |
83 | #define rsnd_ssi_dma_available(ssi) \ | ||
84 | rsnd_dma_available(rsnd_mod_to_dma(&(ssi)->mod)) | ||
85 | #define rsnd_ssi_clk_from_parent(ssi) ((ssi)->parent) | 83 | #define rsnd_ssi_clk_from_parent(ssi) ((ssi)->parent) |
86 | #define rsnd_ssi_mode_flags(p) ((p)->info->flags) | 84 | #define rsnd_ssi_mode_flags(p) ((p)->info->flags) |
87 | #define rsnd_ssi_dai_id(ssi) ((ssi)->info->dai_id) | 85 | #define rsnd_ssi_dai_id(ssi) ((ssi)->info->dai_id) |
86 | #define rsnd_ssi_of_node(priv) \ | ||
87 | of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,ssi") | ||
88 | 88 | ||
89 | static int rsnd_ssi_use_busif(struct rsnd_mod *mod) | 89 | int rsnd_ssi_use_busif(struct rsnd_mod *mod) |
90 | { | 90 | { |
91 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); | 91 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
92 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); | 92 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); |
@@ -416,11 +416,14 @@ static irqreturn_t rsnd_ssi_interrupt(int irq, void *data) | |||
416 | /* | 416 | /* |
417 | * restart SSI | 417 | * restart SSI |
418 | */ | 418 | */ |
419 | rsnd_ssi_stop(mod, priv); | ||
420 | rsnd_ssi_start(mod, priv); | ||
421 | |||
422 | dev_dbg(dev, "%s[%d] restart\n", | 419 | dev_dbg(dev, "%s[%d] restart\n", |
423 | rsnd_mod_name(mod), rsnd_mod_id(mod)); | 420 | rsnd_mod_name(mod), rsnd_mod_id(mod)); |
421 | |||
422 | rsnd_ssi_stop(mod, priv); | ||
423 | if (ssi->err < 1024) | ||
424 | rsnd_ssi_start(mod, priv); | ||
425 | else | ||
426 | dev_warn(dev, "no more SSI restart\n"); | ||
424 | } | 427 | } |
425 | 428 | ||
426 | rsnd_ssi_record_error(ssi, status); | 429 | rsnd_ssi_record_error(ssi, status); |
@@ -442,12 +445,6 @@ static int rsnd_ssi_pio_probe(struct rsnd_mod *mod, | |||
442 | rsnd_ssi_interrupt, | 445 | rsnd_ssi_interrupt, |
443 | IRQF_SHARED, | 446 | IRQF_SHARED, |
444 | dev_name(dev), ssi); | 447 | dev_name(dev), ssi); |
445 | if (ret) | ||
446 | dev_err(dev, "%s[%d] (PIO) request interrupt failed\n", | ||
447 | rsnd_mod_name(mod), rsnd_mod_id(mod)); | ||
448 | else | ||
449 | dev_dbg(dev, "%s[%d] (PIO) is probed\n", | ||
450 | rsnd_mod_name(mod), rsnd_mod_id(mod)); | ||
451 | 448 | ||
452 | return ret; | 449 | return ret; |
453 | } | 450 | } |
@@ -474,23 +471,11 @@ static int rsnd_ssi_dma_probe(struct rsnd_mod *mod, | |||
474 | IRQF_SHARED, | 471 | IRQF_SHARED, |
475 | dev_name(dev), ssi); | 472 | dev_name(dev), ssi); |
476 | if (ret) | 473 | if (ret) |
477 | goto rsnd_ssi_dma_probe_fail; | 474 | return ret; |
478 | 475 | ||
479 | ret = rsnd_dma_init( | 476 | ret = rsnd_dma_init( |
480 | priv, rsnd_mod_to_dma(mod), | 477 | priv, rsnd_mod_to_dma(mod), |
481 | rsnd_info_is_playback(priv, ssi), | ||
482 | dma_id); | 478 | dma_id); |
483 | if (ret) | ||
484 | goto rsnd_ssi_dma_probe_fail; | ||
485 | |||
486 | dev_dbg(dev, "%s[%d] (DMA) is probed\n", | ||
487 | rsnd_mod_name(mod), rsnd_mod_id(mod)); | ||
488 | |||
489 | return ret; | ||
490 | |||
491 | rsnd_ssi_dma_probe_fail: | ||
492 | dev_err(dev, "%s[%d] (DMA) is failed\n", | ||
493 | rsnd_mod_name(mod), rsnd_mod_id(mod)); | ||
494 | 479 | ||
495 | return ret; | 480 | return ret; |
496 | } | 481 | } |
@@ -502,7 +487,7 @@ static int rsnd_ssi_dma_remove(struct rsnd_mod *mod, | |||
502 | struct device *dev = rsnd_priv_to_dev(priv); | 487 | struct device *dev = rsnd_priv_to_dev(priv); |
503 | int irq = ssi->info->irq; | 488 | int irq = ssi->info->irq; |
504 | 489 | ||
505 | rsnd_dma_quit(priv, rsnd_mod_to_dma(mod)); | 490 | rsnd_dma_quit(rsnd_mod_to_dma(mod)); |
506 | 491 | ||
507 | /* PIO will request IRQ again */ | 492 | /* PIO will request IRQ again */ |
508 | devm_free_irq(dev, irq, ssi); | 493 | devm_free_irq(dev, irq, ssi); |
@@ -554,14 +539,25 @@ static int rsnd_ssi_dma_stop(struct rsnd_mod *mod, | |||
554 | return 0; | 539 | return 0; |
555 | } | 540 | } |
556 | 541 | ||
557 | static char *rsnd_ssi_dma_name(struct rsnd_mod *mod) | 542 | static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_mod *mod) |
558 | { | 543 | { |
559 | return rsnd_ssi_use_busif(mod) ? "ssiu" : SSI_NAME; | 544 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
545 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); | ||
546 | int is_play = rsnd_io_is_play(io); | ||
547 | char *name; | ||
548 | |||
549 | if (rsnd_ssi_use_busif(mod)) | ||
550 | name = is_play ? "rxu" : "txu"; | ||
551 | else | ||
552 | name = is_play ? "rx" : "tx"; | ||
553 | |||
554 | return rsnd_dma_request_channel(rsnd_ssi_of_node(priv), | ||
555 | mod, name); | ||
560 | } | 556 | } |
561 | 557 | ||
562 | static struct rsnd_mod_ops rsnd_ssi_dma_ops = { | 558 | static struct rsnd_mod_ops rsnd_ssi_dma_ops = { |
563 | .name = SSI_NAME, | 559 | .name = SSI_NAME, |
564 | .dma_name = rsnd_ssi_dma_name, | 560 | .dma_req = rsnd_ssi_dma_req, |
565 | .probe = rsnd_ssi_dma_probe, | 561 | .probe = rsnd_ssi_dma_probe, |
566 | .remove = rsnd_ssi_dma_remove, | 562 | .remove = rsnd_ssi_dma_remove, |
567 | .init = rsnd_ssi_init, | 563 | .init = rsnd_ssi_init, |
@@ -636,7 +632,7 @@ static void rsnd_of_parse_ssi(struct platform_device *pdev, | |||
636 | if (!of_data) | 632 | if (!of_data) |
637 | return; | 633 | return; |
638 | 634 | ||
639 | node = of_get_child_by_name(dev->of_node, "rcar_sound,ssi"); | 635 | node = rsnd_ssi_of_node(priv); |
640 | if (!node) | 636 | if (!node) |
641 | return; | 637 | return; |
642 | 638 | ||
@@ -697,7 +693,7 @@ int rsnd_ssi_probe(struct platform_device *pdev, | |||
697 | struct clk *clk; | 693 | struct clk *clk; |
698 | struct rsnd_ssi *ssi; | 694 | struct rsnd_ssi *ssi; |
699 | char name[RSND_SSI_NAME_SIZE]; | 695 | char name[RSND_SSI_NAME_SIZE]; |
700 | int i, nr; | 696 | int i, nr, ret; |
701 | 697 | ||
702 | rsnd_of_parse_ssi(pdev, of_data, priv); | 698 | rsnd_of_parse_ssi(pdev, of_data, priv); |
703 | 699 | ||
@@ -732,10 +728,23 @@ int rsnd_ssi_probe(struct platform_device *pdev, | |||
732 | else if (rsnd_ssi_pio_available(ssi)) | 728 | else if (rsnd_ssi_pio_available(ssi)) |
733 | ops = &rsnd_ssi_pio_ops; | 729 | ops = &rsnd_ssi_pio_ops; |
734 | 730 | ||
735 | rsnd_mod_init(&ssi->mod, ops, clk, RSND_MOD_SSI, i); | 731 | ret = rsnd_mod_init(&ssi->mod, ops, clk, RSND_MOD_SSI, i); |
732 | if (ret) | ||
733 | return ret; | ||
736 | 734 | ||
737 | rsnd_ssi_parent_clk_setup(priv, ssi); | 735 | rsnd_ssi_parent_clk_setup(priv, ssi); |
738 | } | 736 | } |
739 | 737 | ||
740 | return 0; | 738 | return 0; |
741 | } | 739 | } |
740 | |||
741 | void rsnd_ssi_remove(struct platform_device *pdev, | ||
742 | struct rsnd_priv *priv) | ||
743 | { | ||
744 | struct rsnd_ssi *ssi; | ||
745 | int i; | ||
746 | |||
747 | for_each_rsnd_ssi(ssi, priv, i) { | ||
748 | rsnd_mod_quit(&ssi->mod); | ||
749 | } | ||
750 | } | ||
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 10f0886e78ec..23732523f87c 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c | |||
@@ -292,6 +292,9 @@ static const struct file_operations codec_reg_fops = { | |||
292 | 292 | ||
293 | static void soc_init_component_debugfs(struct snd_soc_component *component) | 293 | static void soc_init_component_debugfs(struct snd_soc_component *component) |
294 | { | 294 | { |
295 | if (!component->card->debugfs_card_root) | ||
296 | return; | ||
297 | |||
295 | if (component->debugfs_prefix) { | 298 | if (component->debugfs_prefix) { |
296 | char *name; | 299 | char *name; |
297 | 300 | ||
@@ -455,6 +458,9 @@ static const struct file_operations platform_list_fops = { | |||
455 | 458 | ||
456 | static void soc_init_card_debugfs(struct snd_soc_card *card) | 459 | static void soc_init_card_debugfs(struct snd_soc_card *card) |
457 | { | 460 | { |
461 | if (!snd_soc_debugfs_root) | ||
462 | return; | ||
463 | |||
458 | card->debugfs_card_root = debugfs_create_dir(card->name, | 464 | card->debugfs_card_root = debugfs_create_dir(card->name, |
459 | snd_soc_debugfs_root); | 465 | snd_soc_debugfs_root); |
460 | if (!card->debugfs_card_root) { | 466 | if (!card->debugfs_card_root) { |
@@ -476,6 +482,34 @@ static void soc_cleanup_card_debugfs(struct snd_soc_card *card) | |||
476 | debugfs_remove_recursive(card->debugfs_card_root); | 482 | debugfs_remove_recursive(card->debugfs_card_root); |
477 | } | 483 | } |
478 | 484 | ||
485 | |||
486 | static void snd_soc_debugfs_init(void) | ||
487 | { | ||
488 | snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL); | ||
489 | if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) { | ||
490 | pr_warn("ASoC: Failed to create debugfs directory\n"); | ||
491 | snd_soc_debugfs_root = NULL; | ||
492 | return; | ||
493 | } | ||
494 | |||
495 | if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL, | ||
496 | &codec_list_fops)) | ||
497 | pr_warn("ASoC: Failed to create CODEC list debugfs file\n"); | ||
498 | |||
499 | if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL, | ||
500 | &dai_list_fops)) | ||
501 | pr_warn("ASoC: Failed to create DAI list debugfs file\n"); | ||
502 | |||
503 | if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL, | ||
504 | &platform_list_fops)) | ||
505 | pr_warn("ASoC: Failed to create platform list debugfs file\n"); | ||
506 | } | ||
507 | |||
508 | static void snd_soc_debugfs_exit(void) | ||
509 | { | ||
510 | debugfs_remove_recursive(snd_soc_debugfs_root); | ||
511 | } | ||
512 | |||
479 | #else | 513 | #else |
480 | 514 | ||
481 | #define soc_init_codec_debugfs NULL | 515 | #define soc_init_codec_debugfs NULL |
@@ -497,6 +531,15 @@ static inline void soc_init_card_debugfs(struct snd_soc_card *card) | |||
497 | static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card) | 531 | static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card) |
498 | { | 532 | { |
499 | } | 533 | } |
534 | |||
535 | static inline void snd_soc_debugfs_init(void) | ||
536 | { | ||
537 | } | ||
538 | |||
539 | static inline void snd_soc_debugfs_exit(void) | ||
540 | { | ||
541 | } | ||
542 | |||
500 | #endif | 543 | #endif |
501 | 544 | ||
502 | struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card, | 545 | struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card, |
@@ -595,15 +638,9 @@ int snd_soc_suspend(struct device *dev) | |||
595 | cpu_dai->driver->suspend(cpu_dai); | 638 | cpu_dai->driver->suspend(cpu_dai); |
596 | } | 639 | } |
597 | 640 | ||
598 | /* close any waiting streams and save state */ | 641 | /* close any waiting streams */ |
599 | for (i = 0; i < card->num_rtd; i++) { | 642 | for (i = 0; i < card->num_rtd; i++) |
600 | struct snd_soc_dai **codec_dais = card->rtd[i].codec_dais; | ||
601 | flush_delayed_work(&card->rtd[i].delayed_work); | 643 | flush_delayed_work(&card->rtd[i].delayed_work); |
602 | for (j = 0; j < card->rtd[i].num_codecs; j++) { | ||
603 | codec_dais[j]->codec->dapm.suspend_bias_level = | ||
604 | codec_dais[j]->codec->dapm.bias_level; | ||
605 | } | ||
606 | } | ||
607 | 644 | ||
608 | for (i = 0; i < card->num_rtd; i++) { | 645 | for (i = 0; i < card->num_rtd; i++) { |
609 | 646 | ||
@@ -1261,7 +1298,8 @@ static int soc_link_dai_widgets(struct snd_soc_card *card, | |||
1261 | capture_w = cpu_dai->capture_widget; | 1298 | capture_w = cpu_dai->capture_widget; |
1262 | if (play_w && capture_w) { | 1299 | if (play_w && capture_w) { |
1263 | ret = snd_soc_dapm_new_pcm(card, dai_link->params, | 1300 | ret = snd_soc_dapm_new_pcm(card, dai_link->params, |
1264 | capture_w, play_w); | 1301 | dai_link->num_params, capture_w, |
1302 | play_w); | ||
1265 | if (ret != 0) { | 1303 | if (ret != 0) { |
1266 | dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n", | 1304 | dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n", |
1267 | play_w->name, capture_w->name, ret); | 1305 | play_w->name, capture_w->name, ret); |
@@ -1273,7 +1311,8 @@ static int soc_link_dai_widgets(struct snd_soc_card *card, | |||
1273 | capture_w = codec_dai->capture_widget; | 1311 | capture_w = codec_dai->capture_widget; |
1274 | if (play_w && capture_w) { | 1312 | if (play_w && capture_w) { |
1275 | ret = snd_soc_dapm_new_pcm(card, dai_link->params, | 1313 | ret = snd_soc_dapm_new_pcm(card, dai_link->params, |
1276 | capture_w, play_w); | 1314 | dai_link->num_params, capture_w, |
1315 | play_w); | ||
1277 | if (ret != 0) { | 1316 | if (ret != 0) { |
1278 | dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n", | 1317 | dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n", |
1279 | play_w->name, capture_w->name, ret); | 1318 | play_w->name, capture_w->name, ret); |
@@ -1322,21 +1361,17 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) | |||
1322 | } | 1361 | } |
1323 | } | 1362 | } |
1324 | 1363 | ||
1364 | if (dai_link->dai_fmt) | ||
1365 | snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt); | ||
1366 | |||
1325 | ret = soc_post_component_init(rtd, dai_link->name); | 1367 | ret = soc_post_component_init(rtd, dai_link->name); |
1326 | if (ret) | 1368 | if (ret) |
1327 | return ret; | 1369 | return ret; |
1328 | 1370 | ||
1329 | #ifdef CONFIG_DEBUG_FS | 1371 | #ifdef CONFIG_DEBUG_FS |
1330 | /* add DPCM sysfs entries */ | 1372 | /* add DPCM sysfs entries */ |
1331 | if (dai_link->dynamic) { | 1373 | if (dai_link->dynamic) |
1332 | ret = soc_dpcm_debugfs_add(rtd); | 1374 | soc_dpcm_debugfs_add(rtd); |
1333 | if (ret < 0) { | ||
1334 | dev_err(rtd->dev, | ||
1335 | "ASoC: failed to add dpcm sysfs entries: %d\n", | ||
1336 | ret); | ||
1337 | return ret; | ||
1338 | } | ||
1339 | } | ||
1340 | #endif | 1375 | #endif |
1341 | 1376 | ||
1342 | if (cpu_dai->driver->compress_dai) { | 1377 | if (cpu_dai->driver->compress_dai) { |
@@ -1426,7 +1461,6 @@ static void soc_remove_aux_dev(struct snd_soc_card *card, int num) | |||
1426 | 1461 | ||
1427 | /* unregister the rtd device */ | 1462 | /* unregister the rtd device */ |
1428 | if (rtd->dev_registered) { | 1463 | if (rtd->dev_registered) { |
1429 | device_remove_file(rtd->dev, &dev_attr_codec_reg); | ||
1430 | device_unregister(rtd->dev); | 1464 | device_unregister(rtd->dev); |
1431 | rtd->dev_registered = 0; | 1465 | rtd->dev_registered = 0; |
1432 | } | 1466 | } |
@@ -1560,6 +1594,8 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) | |||
1560 | goto base_error; | 1594 | goto base_error; |
1561 | } | 1595 | } |
1562 | 1596 | ||
1597 | soc_init_card_debugfs(card); | ||
1598 | |||
1563 | card->dapm.bias_level = SND_SOC_BIAS_OFF; | 1599 | card->dapm.bias_level = SND_SOC_BIAS_OFF; |
1564 | card->dapm.dev = card->dev; | 1600 | card->dapm.dev = card->dev; |
1565 | card->dapm.card = card; | 1601 | card->dapm.card = card; |
@@ -1578,6 +1614,10 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) | |||
1578 | snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, | 1614 | snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, |
1579 | card->num_dapm_widgets); | 1615 | card->num_dapm_widgets); |
1580 | 1616 | ||
1617 | if (card->of_dapm_widgets) | ||
1618 | snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets, | ||
1619 | card->num_of_dapm_widgets); | ||
1620 | |||
1581 | /* initialise the sound card only once */ | 1621 | /* initialise the sound card only once */ |
1582 | if (card->probe) { | 1622 | if (card->probe) { |
1583 | ret = card->probe(card); | 1623 | ret = card->probe(card); |
@@ -1633,11 +1673,9 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) | |||
1633 | snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, | 1673 | snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, |
1634 | card->num_dapm_routes); | 1674 | card->num_dapm_routes); |
1635 | 1675 | ||
1636 | for (i = 0; i < card->num_links; i++) { | 1676 | if (card->of_dapm_routes) |
1637 | if (card->dai_link[i].dai_fmt) | 1677 | snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes, |
1638 | snd_soc_runtime_set_dai_fmt(&card->rtd[i], | 1678 | card->num_of_dapm_routes); |
1639 | card->dai_link[i].dai_fmt); | ||
1640 | } | ||
1641 | 1679 | ||
1642 | snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname), | 1680 | snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname), |
1643 | "%s", card->name); | 1681 | "%s", card->name); |
@@ -1694,6 +1732,7 @@ card_probe_error: | |||
1694 | if (card->remove) | 1732 | if (card->remove) |
1695 | card->remove(card); | 1733 | card->remove(card); |
1696 | 1734 | ||
1735 | soc_cleanup_card_debugfs(card); | ||
1697 | snd_card_free(card->snd_card); | 1736 | snd_card_free(card->snd_card); |
1698 | 1737 | ||
1699 | base_error: | 1738 | base_error: |
@@ -2372,8 +2411,6 @@ int snd_soc_register_card(struct snd_soc_card *card) | |||
2372 | 2411 | ||
2373 | snd_soc_initialize_card_lists(card); | 2412 | snd_soc_initialize_card_lists(card); |
2374 | 2413 | ||
2375 | soc_init_card_debugfs(card); | ||
2376 | |||
2377 | card->rtd = devm_kzalloc(card->dev, | 2414 | card->rtd = devm_kzalloc(card->dev, |
2378 | sizeof(struct snd_soc_pcm_runtime) * | 2415 | sizeof(struct snd_soc_pcm_runtime) * |
2379 | (card->num_links + card->num_aux_devs), | 2416 | (card->num_links + card->num_aux_devs), |
@@ -2404,7 +2441,7 @@ int snd_soc_register_card(struct snd_soc_card *card) | |||
2404 | 2441 | ||
2405 | ret = snd_soc_instantiate_card(card); | 2442 | ret = snd_soc_instantiate_card(card); |
2406 | if (ret != 0) | 2443 | if (ret != 0) |
2407 | soc_cleanup_card_debugfs(card); | 2444 | return ret; |
2408 | 2445 | ||
2409 | /* deactivate pins to sleep state */ | 2446 | /* deactivate pins to sleep state */ |
2410 | for (i = 0; i < card->num_rtd; i++) { | 2447 | for (i = 0; i < card->num_rtd; i++) { |
@@ -3242,8 +3279,8 @@ int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card, | |||
3242 | widgets[i].name = wname; | 3279 | widgets[i].name = wname; |
3243 | } | 3280 | } |
3244 | 3281 | ||
3245 | card->dapm_widgets = widgets; | 3282 | card->of_dapm_widgets = widgets; |
3246 | card->num_dapm_widgets = num_widgets; | 3283 | card->num_of_dapm_widgets = num_widgets; |
3247 | 3284 | ||
3248 | return 0; | 3285 | return 0; |
3249 | } | 3286 | } |
@@ -3327,8 +3364,8 @@ int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, | |||
3327 | } | 3364 | } |
3328 | } | 3365 | } |
3329 | 3366 | ||
3330 | card->num_dapm_routes = num_routes; | 3367 | card->num_of_dapm_routes = num_routes; |
3331 | card->dapm_routes = routes; | 3368 | card->of_dapm_routes = routes; |
3332 | 3369 | ||
3333 | return 0; | 3370 | return 0; |
3334 | } | 3371 | } |
@@ -3587,26 +3624,7 @@ EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs); | |||
3587 | 3624 | ||
3588 | static int __init snd_soc_init(void) | 3625 | static int __init snd_soc_init(void) |
3589 | { | 3626 | { |
3590 | #ifdef CONFIG_DEBUG_FS | 3627 | snd_soc_debugfs_init(); |
3591 | snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL); | ||
3592 | if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) { | ||
3593 | pr_warn("ASoC: Failed to create debugfs directory\n"); | ||
3594 | snd_soc_debugfs_root = NULL; | ||
3595 | } | ||
3596 | |||
3597 | if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL, | ||
3598 | &codec_list_fops)) | ||
3599 | pr_warn("ASoC: Failed to create CODEC list debugfs file\n"); | ||
3600 | |||
3601 | if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL, | ||
3602 | &dai_list_fops)) | ||
3603 | pr_warn("ASoC: Failed to create DAI list debugfs file\n"); | ||
3604 | |||
3605 | if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL, | ||
3606 | &platform_list_fops)) | ||
3607 | pr_warn("ASoC: Failed to create platform list debugfs file\n"); | ||
3608 | #endif | ||
3609 | |||
3610 | snd_soc_util_init(); | 3628 | snd_soc_util_init(); |
3611 | 3629 | ||
3612 | return platform_driver_register(&soc_driver); | 3630 | return platform_driver_register(&soc_driver); |
@@ -3616,9 +3634,9 @@ module_init(snd_soc_init); | |||
3616 | static void __exit snd_soc_exit(void) | 3634 | static void __exit snd_soc_exit(void) |
3617 | { | 3635 | { |
3618 | snd_soc_util_exit(); | 3636 | snd_soc_util_exit(); |
3637 | snd_soc_debugfs_exit(); | ||
3619 | 3638 | ||
3620 | #ifdef CONFIG_DEBUG_FS | 3639 | #ifdef CONFIG_DEBUG_FS |
3621 | debugfs_remove_recursive(snd_soc_debugfs_root); | ||
3622 | #endif | 3640 | #endif |
3623 | platform_driver_unregister(&soc_driver); | 3641 | platform_driver_unregister(&soc_driver); |
3624 | } | 3642 | } |
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index b6f88202b8c9..defe0f0082b5 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c | |||
@@ -473,16 +473,6 @@ struct snd_soc_dapm_context *snd_soc_dapm_kcontrol_dapm( | |||
473 | } | 473 | } |
474 | EXPORT_SYMBOL_GPL(snd_soc_dapm_kcontrol_dapm); | 474 | EXPORT_SYMBOL_GPL(snd_soc_dapm_kcontrol_dapm); |
475 | 475 | ||
476 | /** | ||
477 | * snd_soc_dapm_kcontrol_codec() - Returns the codec associated to a kcontrol | ||
478 | * @kcontrol: The kcontrol | ||
479 | */ | ||
480 | struct snd_soc_codec *snd_soc_dapm_kcontrol_codec(struct snd_kcontrol *kcontrol) | ||
481 | { | ||
482 | return snd_soc_dapm_to_codec(snd_soc_dapm_kcontrol_dapm(kcontrol)); | ||
483 | } | ||
484 | EXPORT_SYMBOL_GPL(snd_soc_dapm_kcontrol_codec); | ||
485 | |||
486 | static void dapm_reset(struct snd_soc_card *card) | 476 | static void dapm_reset(struct snd_soc_card *card) |
487 | { | 477 | { |
488 | struct snd_soc_dapm_widget *w; | 478 | struct snd_soc_dapm_widget *w; |
@@ -853,6 +843,36 @@ static int dapm_new_pga(struct snd_soc_dapm_widget *w) | |||
853 | return 0; | 843 | return 0; |
854 | } | 844 | } |
855 | 845 | ||
846 | /* create new dapm dai link control */ | ||
847 | static int dapm_new_dai_link(struct snd_soc_dapm_widget *w) | ||
848 | { | ||
849 | int i, ret; | ||
850 | struct snd_kcontrol *kcontrol; | ||
851 | struct snd_soc_dapm_context *dapm = w->dapm; | ||
852 | struct snd_card *card = dapm->card->snd_card; | ||
853 | |||
854 | /* create control for links with > 1 config */ | ||
855 | if (w->num_params <= 1) | ||
856 | return 0; | ||
857 | |||
858 | /* add kcontrol */ | ||
859 | for (i = 0; i < w->num_kcontrols; i++) { | ||
860 | kcontrol = snd_soc_cnew(&w->kcontrol_news[i], w, | ||
861 | w->name, NULL); | ||
862 | ret = snd_ctl_add(card, kcontrol); | ||
863 | if (ret < 0) { | ||
864 | dev_err(dapm->dev, | ||
865 | "ASoC: failed to add widget %s dapm kcontrol %s: %d\n", | ||
866 | w->name, w->kcontrol_news[i].name, ret); | ||
867 | return ret; | ||
868 | } | ||
869 | kcontrol->private_data = w; | ||
870 | w->kcontrols[i] = kcontrol; | ||
871 | } | ||
872 | |||
873 | return 0; | ||
874 | } | ||
875 | |||
856 | /* We implement power down on suspend by checking the power state of | 876 | /* We implement power down on suspend by checking the power state of |
857 | * the ALSA card - when we are suspending the ALSA state for the card | 877 | * the ALSA card - when we are suspending the ALSA state for the card |
858 | * is set to D3. | 878 | * is set to D3. |
@@ -1898,6 +1918,9 @@ void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, | |||
1898 | { | 1918 | { |
1899 | struct dentry *d; | 1919 | struct dentry *d; |
1900 | 1920 | ||
1921 | if (!parent) | ||
1922 | return; | ||
1923 | |||
1901 | dapm->debugfs_dapm = debugfs_create_dir("dapm", parent); | 1924 | dapm->debugfs_dapm = debugfs_create_dir("dapm", parent); |
1902 | 1925 | ||
1903 | if (!dapm->debugfs_dapm) { | 1926 | if (!dapm->debugfs_dapm) { |
@@ -2719,6 +2742,9 @@ int snd_soc_dapm_new_widgets(struct snd_soc_card *card) | |||
2719 | case snd_soc_dapm_out_drv: | 2742 | case snd_soc_dapm_out_drv: |
2720 | dapm_new_pga(w); | 2743 | dapm_new_pga(w); |
2721 | break; | 2744 | break; |
2745 | case snd_soc_dapm_dai_link: | ||
2746 | dapm_new_dai_link(w); | ||
2747 | break; | ||
2722 | default: | 2748 | default: |
2723 | break; | 2749 | break; |
2724 | } | 2750 | } |
@@ -3193,7 +3219,7 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, | |||
3193 | { | 3219 | { |
3194 | struct snd_soc_dapm_path *source_p, *sink_p; | 3220 | struct snd_soc_dapm_path *source_p, *sink_p; |
3195 | struct snd_soc_dai *source, *sink; | 3221 | struct snd_soc_dai *source, *sink; |
3196 | const struct snd_soc_pcm_stream *config = w->params; | 3222 | const struct snd_soc_pcm_stream *config = w->params + w->params_select; |
3197 | struct snd_pcm_substream substream; | 3223 | struct snd_pcm_substream substream; |
3198 | struct snd_pcm_hw_params *params = NULL; | 3224 | struct snd_pcm_hw_params *params = NULL; |
3199 | u64 fmt; | 3225 | u64 fmt; |
@@ -3285,22 +3311,97 @@ out: | |||
3285 | return ret; | 3311 | return ret; |
3286 | } | 3312 | } |
3287 | 3313 | ||
3314 | static int snd_soc_dapm_dai_link_get(struct snd_kcontrol *kcontrol, | ||
3315 | struct snd_ctl_elem_value *ucontrol) | ||
3316 | { | ||
3317 | struct snd_soc_dapm_widget *w = snd_kcontrol_chip(kcontrol); | ||
3318 | |||
3319 | ucontrol->value.integer.value[0] = w->params_select; | ||
3320 | |||
3321 | return 0; | ||
3322 | } | ||
3323 | |||
3324 | static int snd_soc_dapm_dai_link_put(struct snd_kcontrol *kcontrol, | ||
3325 | struct snd_ctl_elem_value *ucontrol) | ||
3326 | { | ||
3327 | struct snd_soc_dapm_widget *w = snd_kcontrol_chip(kcontrol); | ||
3328 | |||
3329 | /* Can't change the config when widget is already powered */ | ||
3330 | if (w->power) | ||
3331 | return -EBUSY; | ||
3332 | |||
3333 | if (ucontrol->value.integer.value[0] == w->params_select) | ||
3334 | return 0; | ||
3335 | |||
3336 | if (ucontrol->value.integer.value[0] >= w->num_params) | ||
3337 | return -EINVAL; | ||
3338 | |||
3339 | w->params_select = ucontrol->value.integer.value[0]; | ||
3340 | |||
3341 | return 0; | ||
3342 | } | ||
3343 | |||
3288 | int snd_soc_dapm_new_pcm(struct snd_soc_card *card, | 3344 | int snd_soc_dapm_new_pcm(struct snd_soc_card *card, |
3289 | const struct snd_soc_pcm_stream *params, | 3345 | const struct snd_soc_pcm_stream *params, |
3346 | unsigned int num_params, | ||
3290 | struct snd_soc_dapm_widget *source, | 3347 | struct snd_soc_dapm_widget *source, |
3291 | struct snd_soc_dapm_widget *sink) | 3348 | struct snd_soc_dapm_widget *sink) |
3292 | { | 3349 | { |
3293 | struct snd_soc_dapm_widget template; | 3350 | struct snd_soc_dapm_widget template; |
3294 | struct snd_soc_dapm_widget *w; | 3351 | struct snd_soc_dapm_widget *w; |
3295 | size_t len; | ||
3296 | char *link_name; | 3352 | char *link_name; |
3297 | int ret; | 3353 | int ret, count; |
3298 | 3354 | unsigned long private_value; | |
3299 | len = strlen(source->name) + strlen(sink->name) + 2; | 3355 | const char **w_param_text; |
3300 | link_name = devm_kzalloc(card->dev, len, GFP_KERNEL); | 3356 | struct soc_enum w_param_enum[] = { |
3301 | if (!link_name) | 3357 | SOC_ENUM_SINGLE(0, 0, 0, NULL), |
3358 | }; | ||
3359 | struct snd_kcontrol_new kcontrol_dai_link[] = { | ||
3360 | SOC_ENUM_EXT(NULL, w_param_enum[0], | ||
3361 | snd_soc_dapm_dai_link_get, | ||
3362 | snd_soc_dapm_dai_link_put), | ||
3363 | }; | ||
3364 | const struct snd_soc_pcm_stream *config = params; | ||
3365 | |||
3366 | w_param_text = devm_kcalloc(card->dev, num_params, | ||
3367 | sizeof(char *), GFP_KERNEL); | ||
3368 | if (!w_param_text) | ||
3302 | return -ENOMEM; | 3369 | return -ENOMEM; |
3303 | snprintf(link_name, len, "%s-%s", source->name, sink->name); | 3370 | |
3371 | link_name = devm_kasprintf(card->dev, GFP_KERNEL, "%s-%s", | ||
3372 | source->name, sink->name); | ||
3373 | if (!link_name) { | ||
3374 | ret = -ENOMEM; | ||
3375 | goto outfree_w_param; | ||
3376 | } | ||
3377 | |||
3378 | for (count = 0 ; count < num_params; count++) { | ||
3379 | if (!config->stream_name) { | ||
3380 | dev_warn(card->dapm.dev, | ||
3381 | "ASoC: anonymous config %d for dai link %s\n", | ||
3382 | count, link_name); | ||
3383 | w_param_text[count] = | ||
3384 | devm_kasprintf(card->dev, GFP_KERNEL, | ||
3385 | "Anonymous Configuration %d", | ||
3386 | count); | ||
3387 | if (!w_param_text[count]) { | ||
3388 | ret = -ENOMEM; | ||
3389 | goto outfree_link_name; | ||
3390 | } | ||
3391 | } else { | ||
3392 | w_param_text[count] = devm_kmemdup(card->dev, | ||
3393 | config->stream_name, | ||
3394 | strlen(config->stream_name) + 1, | ||
3395 | GFP_KERNEL); | ||
3396 | if (!w_param_text[count]) { | ||
3397 | ret = -ENOMEM; | ||
3398 | goto outfree_link_name; | ||
3399 | } | ||
3400 | } | ||
3401 | config++; | ||
3402 | } | ||
3403 | w_param_enum[0].items = num_params; | ||
3404 | w_param_enum[0].texts = w_param_text; | ||
3304 | 3405 | ||
3305 | memset(&template, 0, sizeof(template)); | 3406 | memset(&template, 0, sizeof(template)); |
3306 | template.reg = SND_SOC_NOPM; | 3407 | template.reg = SND_SOC_NOPM; |
@@ -3309,6 +3410,30 @@ int snd_soc_dapm_new_pcm(struct snd_soc_card *card, | |||
3309 | template.event = snd_soc_dai_link_event; | 3410 | template.event = snd_soc_dai_link_event; |
3310 | template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | | 3411 | template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
3311 | SND_SOC_DAPM_PRE_PMD; | 3412 | SND_SOC_DAPM_PRE_PMD; |
3413 | template.num_kcontrols = 1; | ||
3414 | /* duplicate w_param_enum on heap so that memory persists */ | ||
3415 | private_value = | ||
3416 | (unsigned long) devm_kmemdup(card->dev, | ||
3417 | (void *)(kcontrol_dai_link[0].private_value), | ||
3418 | sizeof(struct soc_enum), GFP_KERNEL); | ||
3419 | if (!private_value) { | ||
3420 | dev_err(card->dev, "ASoC: Failed to create control for %s widget\n", | ||
3421 | link_name); | ||
3422 | ret = -ENOMEM; | ||
3423 | goto outfree_link_name; | ||
3424 | } | ||
3425 | kcontrol_dai_link[0].private_value = private_value; | ||
3426 | /* duplicate kcontrol_dai_link on heap so that memory persists */ | ||
3427 | template.kcontrol_news = | ||
3428 | devm_kmemdup(card->dev, &kcontrol_dai_link[0], | ||
3429 | sizeof(struct snd_kcontrol_new), | ||
3430 | GFP_KERNEL); | ||
3431 | if (!template.kcontrol_news) { | ||
3432 | dev_err(card->dev, "ASoC: Failed to create control for %s widget\n", | ||
3433 | link_name); | ||
3434 | ret = -ENOMEM; | ||
3435 | goto outfree_private_value; | ||
3436 | } | ||
3312 | 3437 | ||
3313 | dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name); | 3438 | dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name); |
3314 | 3439 | ||
@@ -3316,15 +3441,32 @@ int snd_soc_dapm_new_pcm(struct snd_soc_card *card, | |||
3316 | if (!w) { | 3441 | if (!w) { |
3317 | dev_err(card->dev, "ASoC: Failed to create %s widget\n", | 3442 | dev_err(card->dev, "ASoC: Failed to create %s widget\n", |
3318 | link_name); | 3443 | link_name); |
3319 | return -ENOMEM; | 3444 | ret = -ENOMEM; |
3445 | goto outfree_kcontrol_news; | ||
3320 | } | 3446 | } |
3321 | 3447 | ||
3322 | w->params = params; | 3448 | w->params = params; |
3449 | w->num_params = num_params; | ||
3323 | 3450 | ||
3324 | ret = snd_soc_dapm_add_path(&card->dapm, source, w, NULL, NULL); | 3451 | ret = snd_soc_dapm_add_path(&card->dapm, source, w, NULL, NULL); |
3325 | if (ret) | 3452 | if (ret) |
3326 | return ret; | 3453 | goto outfree_w; |
3327 | return snd_soc_dapm_add_path(&card->dapm, w, sink, NULL, NULL); | 3454 | return snd_soc_dapm_add_path(&card->dapm, w, sink, NULL, NULL); |
3455 | |||
3456 | outfree_w: | ||
3457 | devm_kfree(card->dev, w); | ||
3458 | outfree_kcontrol_news: | ||
3459 | devm_kfree(card->dev, (void *)template.kcontrol_news); | ||
3460 | outfree_private_value: | ||
3461 | devm_kfree(card->dev, (void *)private_value); | ||
3462 | outfree_link_name: | ||
3463 | devm_kfree(card->dev, link_name); | ||
3464 | outfree_w_param: | ||
3465 | for (count = 0 ; count < num_params; count++) | ||
3466 | devm_kfree(card->dev, (void *)w_param_text[count]); | ||
3467 | devm_kfree(card->dev, w_param_text); | ||
3468 | |||
3469 | return ret; | ||
3328 | } | 3470 | } |
3329 | 3471 | ||
3330 | int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm, | 3472 | int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm, |
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 | */ |
37 | int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type, | 39 | int 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 | } |
48 | EXPORT_SYMBOL_GPL(snd_soc_jack_new); | 60 | EXPORT_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 | */ |
64 | void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask) | 76 | void 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) | |||
260 | static irqreturn_t gpio_handler(int irq, void *data) | 270 | static 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..35fe58f4fa86 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c | |||
@@ -1097,8 +1097,9 @@ static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe, | |||
1097 | stream ? "<-" : "->", be->dai_link->name); | 1097 | stream ? "<-" : "->", be->dai_link->name); |
1098 | 1098 | ||
1099 | #ifdef CONFIG_DEBUG_FS | 1099 | #ifdef CONFIG_DEBUG_FS |
1100 | dpcm->debugfs_state = debugfs_create_u32(be->dai_link->name, 0644, | 1100 | if (fe->debugfs_dpcm_root) |
1101 | fe->debugfs_dpcm_root, &dpcm->state); | 1101 | dpcm->debugfs_state = debugfs_create_u32(be->dai_link->name, 0644, |
1102 | fe->debugfs_dpcm_root, &dpcm->state); | ||
1102 | #endif | 1103 | #endif |
1103 | return 1; | 1104 | return 1; |
1104 | } | 1105 | } |
@@ -2511,6 +2512,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) | |||
2511 | /* DAPM dai link stream work */ | 2512 | /* DAPM dai link stream work */ |
2512 | INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work); | 2513 | INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work); |
2513 | 2514 | ||
2515 | pcm->nonatomic = rtd->dai_link->nonatomic; | ||
2514 | rtd->pcm = pcm; | 2516 | rtd->pcm = pcm; |
2515 | pcm->private_data = rtd; | 2517 | pcm->private_data = rtd; |
2516 | 2518 | ||
@@ -2802,10 +2804,13 @@ static const struct file_operations dpcm_state_fops = { | |||
2802 | .llseek = default_llseek, | 2804 | .llseek = default_llseek, |
2803 | }; | 2805 | }; |
2804 | 2806 | ||
2805 | int soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd) | 2807 | void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd) |
2806 | { | 2808 | { |
2807 | if (!rtd->dai_link) | 2809 | if (!rtd->dai_link) |
2808 | return 0; | 2810 | return; |
2811 | |||
2812 | if (!rtd->card->debugfs_card_root) | ||
2813 | return; | ||
2809 | 2814 | ||
2810 | rtd->debugfs_dpcm_root = debugfs_create_dir(rtd->dai_link->name, | 2815 | rtd->debugfs_dpcm_root = debugfs_create_dir(rtd->dai_link->name, |
2811 | rtd->card->debugfs_card_root); | 2816 | rtd->card->debugfs_card_root); |
@@ -2813,13 +2818,11 @@ int soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd) | |||
2813 | dev_dbg(rtd->dev, | 2818 | dev_dbg(rtd->dev, |
2814 | "ASoC: Failed to create dpcm debugfs directory %s\n", | 2819 | "ASoC: Failed to create dpcm debugfs directory %s\n", |
2815 | rtd->dai_link->name); | 2820 | rtd->dai_link->name); |
2816 | return -EINVAL; | 2821 | return; |
2817 | } | 2822 | } |
2818 | 2823 | ||
2819 | rtd->debugfs_dpcm_state = debugfs_create_file("state", 0444, | 2824 | rtd->debugfs_dpcm_state = debugfs_create_file("state", 0444, |
2820 | rtd->debugfs_dpcm_root, | 2825 | rtd->debugfs_dpcm_root, |
2821 | rtd, &dpcm_state_fops); | 2826 | rtd, &dpcm_state_fops); |
2822 | |||
2823 | return 0; | ||
2824 | } | 2827 | } |
2825 | #endif | 2828 | #endif |
diff --git a/sound/soc/tegra/tegra_alc5632.c b/sound/soc/tegra/tegra_alc5632.c index 769aca2fc5f5..ba272e21a6fa 100644 --- a/sound/soc/tegra/tegra_alc5632.c +++ b/sound/soc/tegra/tegra_alc5632.c | |||
@@ -101,16 +101,12 @@ static const struct snd_kcontrol_new tegra_alc5632_controls[] = { | |||
101 | 101 | ||
102 | static int tegra_alc5632_asoc_init(struct snd_soc_pcm_runtime *rtd) | 102 | static int tegra_alc5632_asoc_init(struct snd_soc_pcm_runtime *rtd) |
103 | { | 103 | { |
104 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | ||
105 | struct snd_soc_codec *codec = codec_dai->codec; | ||
106 | struct snd_soc_dapm_context *dapm = &codec->dapm; | ||
107 | struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(rtd->card); | 104 | struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(rtd->card); |
108 | 105 | ||
109 | snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET, | 106 | snd_soc_card_jack_new(rtd->card, "Headset Jack", SND_JACK_HEADSET, |
110 | &tegra_alc5632_hs_jack); | 107 | &tegra_alc5632_hs_jack, |
111 | snd_soc_jack_add_pins(&tegra_alc5632_hs_jack, | 108 | tegra_alc5632_hs_jack_pins, |
112 | ARRAY_SIZE(tegra_alc5632_hs_jack_pins), | 109 | ARRAY_SIZE(tegra_alc5632_hs_jack_pins)); |
113 | tegra_alc5632_hs_jack_pins); | ||
114 | 110 | ||
115 | if (gpio_is_valid(machine->gpio_hp_det)) { | 111 | if (gpio_is_valid(machine->gpio_hp_det)) { |
116 | tegra_alc5632_hp_jack_gpio.gpio = machine->gpio_hp_det; | 112 | tegra_alc5632_hp_jack_gpio.gpio = machine->gpio_hp_det; |
@@ -119,7 +115,7 @@ static int tegra_alc5632_asoc_init(struct snd_soc_pcm_runtime *rtd) | |||
119 | &tegra_alc5632_hp_jack_gpio); | 115 | &tegra_alc5632_hp_jack_gpio); |
120 | } | 116 | } |
121 | 117 | ||
122 | snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1"); | 118 | snd_soc_dapm_force_enable_pin(&rtd->card->dapm, "MICBIAS1"); |
123 | 119 | ||
124 | return 0; | 120 | return 0; |
125 | } | 121 | } |
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 | ||
138 | static const struct snd_kcontrol_new tegra_max98090_controls[] = { | 139 | static 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 | ||
142 | static int tegra_max98090_asoc_init(struct snd_soc_pcm_runtime *rtd) | 146 | static 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 | ||
109 | static int tegra_rt5640_asoc_init(struct snd_soc_pcm_runtime *rtd) | 109 | static 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..1470873ecde6 100644 --- a/sound/soc/tegra/tegra_rt5677.c +++ b/sound/soc/tegra/tegra_rt5677.c | |||
@@ -141,15 +141,11 @@ static const struct snd_kcontrol_new tegra_rt5677_controls[] = { | |||
141 | 141 | ||
142 | static int tegra_rt5677_asoc_init(struct snd_soc_pcm_runtime *rtd) | 142 | static int tegra_rt5677_asoc_init(struct snd_soc_pcm_runtime *rtd) |
143 | { | 143 | { |
144 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | ||
145 | struct snd_soc_codec *codec = codec_dai->codec; | ||
146 | struct snd_soc_dapm_context *dapm = &codec->dapm; | ||
147 | struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(rtd->card); | 144 | struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(rtd->card); |
148 | 145 | ||
149 | snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE, | 146 | snd_soc_card_jack_new(rtd->card, "Headphone Jack", SND_JACK_HEADPHONE, |
150 | &tegra_rt5677_hp_jack); | 147 | &tegra_rt5677_hp_jack, |
151 | snd_soc_jack_add_pins(&tegra_rt5677_hp_jack, 1, | 148 | &tegra_rt5677_hp_jack_pins, 1); |
152 | &tegra_rt5677_hp_jack_pins); | ||
153 | 149 | ||
154 | if (gpio_is_valid(machine->gpio_hp_det)) { | 150 | if (gpio_is_valid(machine->gpio_hp_det)) { |
155 | tegra_rt5677_hp_jack_gpio.gpio = machine->gpio_hp_det; | 151 | tegra_rt5677_hp_jack_gpio.gpio = machine->gpio_hp_det; |
@@ -158,10 +154,9 @@ static int tegra_rt5677_asoc_init(struct snd_soc_pcm_runtime *rtd) | |||
158 | } | 154 | } |
159 | 155 | ||
160 | 156 | ||
161 | snd_soc_jack_new(codec, "Mic Jack", SND_JACK_MICROPHONE, | 157 | snd_soc_card_jack_new(rtd->card, "Mic Jack", SND_JACK_MICROPHONE, |
162 | &tegra_rt5677_mic_jack); | 158 | &tegra_rt5677_mic_jack, |
163 | snd_soc_jack_add_pins(&tegra_rt5677_mic_jack, 1, | 159 | &tegra_rt5677_mic_jack_pins, 1); |
164 | &tegra_rt5677_mic_jack_pins); | ||
165 | 160 | ||
166 | if (gpio_is_valid(machine->gpio_mic_present)) { | 161 | if (gpio_is_valid(machine->gpio_mic_present)) { |
167 | tegra_rt5677_mic_jack_gpio.gpio = machine->gpio_mic_present; | 162 | tegra_rt5677_mic_jack_gpio.gpio = machine->gpio_mic_present; |
@@ -169,7 +164,7 @@ static int tegra_rt5677_asoc_init(struct snd_soc_pcm_runtime *rtd) | |||
169 | &tegra_rt5677_mic_jack_gpio); | 164 | &tegra_rt5677_mic_jack_gpio); |
170 | } | 165 | } |
171 | 166 | ||
172 | snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1"); | 167 | snd_soc_dapm_force_enable_pin(&rtd->card->dapm, "MICBIAS1"); |
173 | 168 | ||
174 | return 0; | 169 | return 0; |
175 | } | 170 | } |
@@ -331,7 +326,6 @@ static const struct of_device_id tegra_rt5677_of_match[] = { | |||
331 | static struct platform_driver tegra_rt5677_driver = { | 326 | static struct platform_driver tegra_rt5677_driver = { |
332 | .driver = { | 327 | .driver = { |
333 | .name = DRV_NAME, | 328 | .name = DRV_NAME, |
334 | .owner = THIS_MODULE, | ||
335 | .pm = &snd_soc_pm_ops, | 329 | .pm = &snd_soc_pm_ops, |
336 | .of_match_table = tegra_rt5677_of_match, | 330 | .of_match_table = tegra_rt5677_of_match, |
337 | }, | 331 | }, |
diff --git a/sound/soc/tegra/tegra_wm8903.c b/sound/soc/tegra/tegra_wm8903.c index e52420dae2b4..21604009bc1a 100644 --- a/sound/soc/tegra/tegra_wm8903.c +++ b/sound/soc/tegra/tegra_wm8903.c | |||
@@ -171,31 +171,28 @@ static int tegra_wm8903_init(struct snd_soc_pcm_runtime *rtd) | |||
171 | { | 171 | { |
172 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | 172 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
173 | struct snd_soc_codec *codec = codec_dai->codec; | 173 | struct snd_soc_codec *codec = codec_dai->codec; |
174 | struct snd_soc_dapm_context *dapm = &codec->dapm; | ||
175 | struct snd_soc_card *card = rtd->card; | 174 | struct snd_soc_card *card = rtd->card; |
176 | struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card); | 175 | struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card); |
177 | 176 | ||
178 | if (gpio_is_valid(machine->gpio_hp_det)) { | 177 | if (gpio_is_valid(machine->gpio_hp_det)) { |
179 | tegra_wm8903_hp_jack_gpio.gpio = machine->gpio_hp_det; | 178 | tegra_wm8903_hp_jack_gpio.gpio = machine->gpio_hp_det; |
180 | snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE, | 179 | snd_soc_card_jack_new(rtd->card, "Headphone Jack", |
181 | &tegra_wm8903_hp_jack); | 180 | SND_JACK_HEADPHONE, &tegra_wm8903_hp_jack, |
182 | snd_soc_jack_add_pins(&tegra_wm8903_hp_jack, | 181 | tegra_wm8903_hp_jack_pins, |
183 | ARRAY_SIZE(tegra_wm8903_hp_jack_pins), | 182 | ARRAY_SIZE(tegra_wm8903_hp_jack_pins)); |
184 | tegra_wm8903_hp_jack_pins); | ||
185 | snd_soc_jack_add_gpios(&tegra_wm8903_hp_jack, | 183 | snd_soc_jack_add_gpios(&tegra_wm8903_hp_jack, |
186 | 1, | 184 | 1, |
187 | &tegra_wm8903_hp_jack_gpio); | 185 | &tegra_wm8903_hp_jack_gpio); |
188 | } | 186 | } |
189 | 187 | ||
190 | snd_soc_jack_new(codec, "Mic Jack", SND_JACK_MICROPHONE, | 188 | snd_soc_card_jack_new(rtd->card, "Mic Jack", SND_JACK_MICROPHONE, |
191 | &tegra_wm8903_mic_jack); | 189 | &tegra_wm8903_mic_jack, |
192 | snd_soc_jack_add_pins(&tegra_wm8903_mic_jack, | 190 | tegra_wm8903_mic_jack_pins, |
193 | ARRAY_SIZE(tegra_wm8903_mic_jack_pins), | 191 | 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, | 192 | wm8903_mic_detect(codec, &tegra_wm8903_mic_jack, SND_JACK_MICROPHONE, |
196 | 0); | 193 | 0); |
197 | 194 | ||
198 | snd_soc_dapm_force_enable_pin(dapm, "MICBIAS"); | 195 | snd_soc_dapm_force_enable_pin(&card->dapm, "MICBIAS"); |
199 | 196 | ||
200 | return 0; | 197 | return 0; |
201 | } | 198 | } |
diff --git a/sound/soc/tegra/tegra_wm9712.c b/sound/soc/tegra/tegra_wm9712.c index 2868b4839bc0..6492f8143ff1 100644 --- a/sound/soc/tegra/tegra_wm9712.c +++ b/sound/soc/tegra/tegra_wm9712.c | |||
@@ -46,11 +46,7 @@ static const struct snd_soc_dapm_widget tegra_wm9712_dapm_widgets[] = { | |||
46 | 46 | ||
47 | static int tegra_wm9712_init(struct snd_soc_pcm_runtime *rtd) | 47 | static int tegra_wm9712_init(struct snd_soc_pcm_runtime *rtd) |
48 | { | 48 | { |
49 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | 49 | return snd_soc_dapm_force_enable_pin(&rtd->card->dapm, "Mic Bias"); |
50 | struct snd_soc_codec *codec = codec_dai->codec; | ||
51 | struct snd_soc_dapm_context *dapm = &codec->dapm; | ||
52 | |||
53 | return snd_soc_dapm_force_enable_pin(dapm, "Mic Bias"); | ||
54 | } | 50 | } |
55 | 51 | ||
56 | static struct snd_soc_dai_link tegra_wm9712_dai = { | 52 | static struct snd_soc_dai_link tegra_wm9712_dai = { |
diff --git a/sound/soc/ux500/mop500_ab8500.c b/sound/soc/ux500/mop500_ab8500.c index aa65370db82a..b81a7a4c938b 100644 --- a/sound/soc/ux500/mop500_ab8500.c +++ b/sound/soc/ux500/mop500_ab8500.c | |||
@@ -362,7 +362,7 @@ struct snd_soc_ops mop500_ab8500_ops[] = { | |||
362 | 362 | ||
363 | int mop500_ab8500_machine_init(struct snd_soc_pcm_runtime *rtd) | 363 | int mop500_ab8500_machine_init(struct snd_soc_pcm_runtime *rtd) |
364 | { | 364 | { |
365 | struct snd_soc_codec *codec = rtd->codec; | 365 | struct snd_soc_dapm_context *dapm = &rtd->card->dapm; |
366 | struct device *dev = rtd->card->dev; | 366 | struct device *dev = rtd->card->dev; |
367 | struct mop500_ab8500_drvdata *drvdata; | 367 | struct mop500_ab8500_drvdata *drvdata; |
368 | int ret; | 368 | int ret; |
@@ -407,23 +407,23 @@ int mop500_ab8500_machine_init(struct snd_soc_pcm_runtime *rtd) | |||
407 | return ret; | 407 | return ret; |
408 | } | 408 | } |
409 | 409 | ||
410 | ret = snd_soc_dapm_disable_pin(&codec->dapm, "Earpiece"); | 410 | ret = snd_soc_dapm_disable_pin(dapm, "Earpiece"); |
411 | ret |= snd_soc_dapm_disable_pin(&codec->dapm, "Speaker Left"); | 411 | ret |= snd_soc_dapm_disable_pin(dapm, "Speaker Left"); |
412 | ret |= snd_soc_dapm_disable_pin(&codec->dapm, "Speaker Right"); | 412 | ret |= snd_soc_dapm_disable_pin(dapm, "Speaker Right"); |
413 | ret |= snd_soc_dapm_disable_pin(&codec->dapm, "LineOut Left"); | 413 | ret |= snd_soc_dapm_disable_pin(dapm, "LineOut Left"); |
414 | ret |= snd_soc_dapm_disable_pin(&codec->dapm, "LineOut Right"); | 414 | ret |= snd_soc_dapm_disable_pin(dapm, "LineOut Right"); |
415 | ret |= snd_soc_dapm_disable_pin(&codec->dapm, "Vibra 1"); | 415 | ret |= snd_soc_dapm_disable_pin(dapm, "Vibra 1"); |
416 | ret |= snd_soc_dapm_disable_pin(&codec->dapm, "Vibra 2"); | 416 | ret |= snd_soc_dapm_disable_pin(dapm, "Vibra 2"); |
417 | ret |= snd_soc_dapm_disable_pin(&codec->dapm, "Mic 1"); | 417 | ret |= snd_soc_dapm_disable_pin(dapm, "Mic 1"); |
418 | ret |= snd_soc_dapm_disable_pin(&codec->dapm, "Mic 2"); | 418 | ret |= snd_soc_dapm_disable_pin(dapm, "Mic 2"); |
419 | ret |= snd_soc_dapm_disable_pin(&codec->dapm, "LineIn Left"); | 419 | ret |= snd_soc_dapm_disable_pin(dapm, "LineIn Left"); |
420 | ret |= snd_soc_dapm_disable_pin(&codec->dapm, "LineIn Right"); | 420 | ret |= snd_soc_dapm_disable_pin(dapm, "LineIn Right"); |
421 | ret |= snd_soc_dapm_disable_pin(&codec->dapm, "DMic 1"); | 421 | ret |= snd_soc_dapm_disable_pin(dapm, "DMic 1"); |
422 | ret |= snd_soc_dapm_disable_pin(&codec->dapm, "DMic 2"); | 422 | ret |= snd_soc_dapm_disable_pin(dapm, "DMic 2"); |
423 | ret |= snd_soc_dapm_disable_pin(&codec->dapm, "DMic 3"); | 423 | ret |= snd_soc_dapm_disable_pin(dapm, "DMic 3"); |
424 | ret |= snd_soc_dapm_disable_pin(&codec->dapm, "DMic 4"); | 424 | ret |= snd_soc_dapm_disable_pin(dapm, "DMic 4"); |
425 | ret |= snd_soc_dapm_disable_pin(&codec->dapm, "DMic 5"); | 425 | ret |= snd_soc_dapm_disable_pin(dapm, "DMic 5"); |
426 | ret |= snd_soc_dapm_disable_pin(&codec->dapm, "DMic 6"); | 426 | ret |= snd_soc_dapm_disable_pin(dapm, "DMic 6"); |
427 | 427 | ||
428 | return ret; | 428 | return ret; |
429 | } | 429 | } |
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c index 9a28365126f9..7c5a70139278 100644 --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c | |||
@@ -1115,6 +1115,7 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip) | |||
1115 | { | 1115 | { |
1116 | /* devices which do not support reading the sample rate. */ | 1116 | /* devices which do not support reading the sample rate. */ |
1117 | switch (chip->usb_id) { | 1117 | switch (chip->usb_id) { |
1118 | case USB_ID(0x045E, 0x075D): /* MS Lifecam Cinema */ | ||
1118 | case USB_ID(0x045E, 0x076D): /* MS Lifecam HD-5000 */ | 1119 | case USB_ID(0x045E, 0x076D): /* MS Lifecam HD-5000 */ |
1119 | case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */ | 1120 | case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */ |
1120 | return true; | 1121 | return true; |
@@ -1125,17 +1126,24 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip) | |||
1125 | /* Marantz/Denon USB DACs need a vendor cmd to switch | 1126 | /* Marantz/Denon USB DACs need a vendor cmd to switch |
1126 | * between PCM and native DSD mode | 1127 | * between PCM and native DSD mode |
1127 | */ | 1128 | */ |
1129 | static bool is_marantz_denon_dac(unsigned int id) | ||
1130 | { | ||
1131 | switch (id) { | ||
1132 | case USB_ID(0x154e, 0x1003): /* Denon DA-300USB */ | ||
1133 | case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */ | ||
1134 | case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */ | ||
1135 | return true; | ||
1136 | } | ||
1137 | return false; | ||
1138 | } | ||
1139 | |||
1128 | int snd_usb_select_mode_quirk(struct snd_usb_substream *subs, | 1140 | int snd_usb_select_mode_quirk(struct snd_usb_substream *subs, |
1129 | struct audioformat *fmt) | 1141 | struct audioformat *fmt) |
1130 | { | 1142 | { |
1131 | struct usb_device *dev = subs->dev; | 1143 | struct usb_device *dev = subs->dev; |
1132 | int err; | 1144 | int err; |
1133 | 1145 | ||
1134 | switch (subs->stream->chip->usb_id) { | 1146 | if (is_marantz_denon_dac(subs->stream->chip->usb_id)) { |
1135 | case USB_ID(0x154e, 0x1003): /* Denon DA-300USB */ | ||
1136 | case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */ | ||
1137 | case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */ | ||
1138 | |||
1139 | /* First switch to alt set 0, otherwise the mode switch cmd | 1147 | /* First switch to alt set 0, otherwise the mode switch cmd |
1140 | * will not be accepted by the DAC | 1148 | * will not be accepted by the DAC |
1141 | */ | 1149 | */ |
@@ -1208,17 +1216,10 @@ void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe, | |||
1208 | /* Marantz/Denon devices with USB DAC functionality need a delay | 1216 | /* Marantz/Denon devices with USB DAC functionality need a delay |
1209 | * after each class compliant request | 1217 | * after each class compliant request |
1210 | */ | 1218 | */ |
1211 | if ((le16_to_cpu(dev->descriptor.idVendor) == 0x154e) && | 1219 | if (is_marantz_denon_dac(USB_ID(le16_to_cpu(dev->descriptor.idVendor), |
1212 | (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS) { | 1220 | le16_to_cpu(dev->descriptor.idProduct))) |
1213 | 1221 | && (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS) | |
1214 | switch (le16_to_cpu(dev->descriptor.idProduct)) { | 1222 | mdelay(20); |
1215 | case 0x1003: /* Denon DA300-USB */ | ||
1216 | case 0x3005: /* Marantz HD-DAC1 */ | ||
1217 | case 0x3006: /* Marantz SA-14S1 */ | ||
1218 | mdelay(20); | ||
1219 | break; | ||
1220 | } | ||
1221 | } | ||
1222 | 1223 | ||
1223 | /* Zoom R16/24 needs a tiny delay here, otherwise requests like | 1224 | /* Zoom R16/24 needs a tiny delay here, otherwise requests like |
1224 | * get/set frequency return as failed despite actually succeeding. | 1225 | * get/set frequency return as failed despite actually succeeding. |
@@ -1273,15 +1274,9 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip, | |||
1273 | } | 1274 | } |
1274 | 1275 | ||
1275 | /* Denon/Marantz devices with USB DAC functionality */ | 1276 | /* Denon/Marantz devices with USB DAC functionality */ |
1276 | switch (chip->usb_id) { | 1277 | if (is_marantz_denon_dac(chip->usb_id)) { |
1277 | case USB_ID(0x154e, 0x1003): /* Denon DA300-USB */ | ||
1278 | case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */ | ||
1279 | case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */ | ||
1280 | if (fp->altsetting == 2) | 1278 | if (fp->altsetting == 2) |
1281 | return SNDRV_PCM_FMTBIT_DSD_U32_BE; | 1279 | return SNDRV_PCM_FMTBIT_DSD_U32_BE; |
1282 | break; | ||
1283 | default: | ||
1284 | break; | ||
1285 | } | 1280 | } |
1286 | 1281 | ||
1287 | return 0; | 1282 | return 0; |