@@ -80,59 +80,6 @@ struct twl6040_data {
8080 struct mutex mutex ;
8181};
8282
83- /*
84- * twl6040 register cache & default register settings
85- */
86- static const u8 twl6040_reg [TWL6040_CACHEREGNUM ] = {
87- 0x00 , /* not used 0x00 */
88- 0x4B , /* REG_ASICID 0x01 (ro) */
89- 0x00 , /* REG_ASICREV 0x02 (ro) */
90- 0x00 , /* REG_INTID 0x03 */
91- 0x00 , /* REG_INTMR 0x04 */
92- 0x00 , /* REG_NCPCTRL 0x05 */
93- 0x00 , /* REG_LDOCTL 0x06 */
94- 0x60 , /* REG_HPPLLCTL 0x07 */
95- 0x00 , /* REG_LPPLLCTL 0x08 */
96- 0x4A , /* REG_LPPLLDIV 0x09 */
97- 0x00 , /* REG_AMICBCTL 0x0A */
98- 0x00 , /* REG_DMICBCTL 0x0B */
99- 0x00 , /* REG_MICLCTL 0x0C */
100- 0x00 , /* REG_MICRCTL 0x0D */
101- 0x00 , /* REG_MICGAIN 0x0E */
102- 0x1B , /* REG_LINEGAIN 0x0F */
103- 0x00 , /* REG_HSLCTL 0x10 */
104- 0x00 , /* REG_HSRCTL 0x11 */
105- 0x00 , /* REG_HSGAIN 0x12 */
106- 0x00 , /* REG_EARCTL 0x13 */
107- 0x00 , /* REG_HFLCTL 0x14 */
108- 0x00 , /* REG_HFLGAIN 0x15 */
109- 0x00 , /* REG_HFRCTL 0x16 */
110- 0x00 , /* REG_HFRGAIN 0x17 */
111- 0x00 , /* REG_VIBCTLL 0x18 */
112- 0x00 , /* REG_VIBDATL 0x19 */
113- 0x00 , /* REG_VIBCTLR 0x1A */
114- 0x00 , /* REG_VIBDATR 0x1B */
115- 0x00 , /* REG_HKCTL1 0x1C */
116- 0x00 , /* REG_HKCTL2 0x1D */
117- 0x00 , /* REG_GPOCTL 0x1E */
118- 0x00 , /* REG_ALB 0x1F */
119- 0x00 , /* REG_DLB 0x20 */
120- 0x00 , /* not used 0x21 */
121- 0x00 , /* not used 0x22 */
122- 0x00 , /* not used 0x23 */
123- 0x00 , /* not used 0x24 */
124- 0x00 , /* not used 0x25 */
125- 0x00 , /* not used 0x26 */
126- 0x00 , /* not used 0x27 */
127- 0x00 , /* REG_TRIM1 0x28 */
128- 0x00 , /* REG_TRIM2 0x29 */
129- 0x00 , /* REG_TRIM3 0x2A */
130- 0x00 , /* REG_HSOTRIM 0x2B */
131- 0x00 , /* REG_HFOTRIM 0x2C */
132- 0x09 , /* REG_ACCCTL 0x2D */
133- 0x00 , /* REG_STATUS 0x2E (ro) */
134- };
135-
13683/* set of rates for each pll: low-power and high-performance */
13784static unsigned int lp_rates [] = {
13885 8000 ,
@@ -159,119 +106,68 @@ static struct snd_pcm_hw_constraint_list sysclk_constraints[] = {
159106 { .count = ARRAY_SIZE (hp_rates ), .list = hp_rates , },
160107};
161108
162- static inline int twl6040_read_dl12_cache (struct snd_soc_codec * codec ,
163- u8 reg , u8 * value )
109+ static unsigned int twl6040_read (struct snd_soc_codec * codec , unsigned int reg )
164110{
165111 struct twl6040_data * priv = snd_soc_codec_get_drvdata (codec );
166- int ret = 0 ;
112+ struct twl6040 * twl6040 = codec -> control_data ;
113+ u8 value ;
114+
115+ if (reg >= TWL6040_CACHEREGNUM )
116+ return - EIO ;
167117
168118 switch (reg ) {
169119 case TWL6040_REG_HSLCTL :
170120 case TWL6040_REG_HSRCTL :
171121 case TWL6040_REG_EARCTL :
172122 case TWL6040_REG_HFLCTL :
173123 case TWL6040_REG_HFRCTL :
174- * value = priv -> dl12_cache [reg - TWL6040_REG_HSLCTL ];
124+ value = priv -> dl12_cache [reg - TWL6040_REG_HSLCTL ];
175125 break ;
176126 default :
177- ret = - EINVAL ;
127+ value = twl6040_reg_read ( twl6040 , reg ) ;
178128 break ;
179129 }
180130
181- return ret ;
182- }
183-
184- /*
185- * read twl6040 register cache
186- */
187- static inline unsigned int twl6040_read_reg_cache (struct snd_soc_codec * codec ,
188- unsigned int reg )
189- {
190- u8 * cache = codec -> reg_cache ;
191- u8 value ;
192-
193- if (reg >= TWL6040_CACHEREGNUM )
194- return - EIO ;
195-
196- if (twl6040_read_dl12_cache (codec , reg , & value ))
197- value = cache [reg ];
198-
199131 return value ;
200132}
201133
202- static inline void twl6040_update_dl12_cache (struct snd_soc_codec * codec ,
203- u8 reg , u8 value )
134+ static bool twl6040_can_write_to_chip (struct snd_soc_codec * codec ,
135+ unsigned int reg )
204136{
205137 struct twl6040_data * priv = snd_soc_codec_get_drvdata (codec );
206138
207139 switch (reg ) {
208140 case TWL6040_REG_HSLCTL :
209141 case TWL6040_REG_HSRCTL :
210142 case TWL6040_REG_EARCTL :
143+ /* DL1 path */
144+ return priv -> dl1_unmuted ;
211145 case TWL6040_REG_HFLCTL :
212146 case TWL6040_REG_HFRCTL :
213- priv -> dl12_cache [reg - TWL6040_REG_HSLCTL ] = value ;
214- break ;
147+ return priv -> dl2_unmuted ;
215148 default :
216- break ;
149+ return 1 ;
217150 }
218151}
219152
220- /*
221- * write twl6040 register cache
222- */
223- static inline void twl6040_write_reg_cache (struct snd_soc_codec * codec ,
224- u8 reg , u8 value )
225- {
226- u8 * cache = codec -> reg_cache ;
227-
228- if (reg >= TWL6040_CACHEREGNUM )
229- return ;
230- cache [reg ] = value ;
231-
232- twl6040_update_dl12_cache (codec , reg , value );
233- }
234-
235- /*
236- * read from twl6040 hardware register
237- */
238- static int twl6040_read_reg_volatile (struct snd_soc_codec * codec ,
239- unsigned int reg )
240- {
241- struct twl6040 * twl6040 = codec -> control_data ;
242- u8 value ;
243-
244- if (reg >= TWL6040_CACHEREGNUM )
245- return - EIO ;
246-
247- value = twl6040_reg_read (twl6040 , reg );
248- twl6040_write_reg_cache (codec , reg , value );
249-
250- return value ;
251- }
252-
253- static bool twl6040_can_write_to_chip (struct snd_soc_codec * codec ,
254- unsigned int reg )
153+ static inline void twl6040_update_dl12_cache (struct snd_soc_codec * codec ,
154+ u8 reg , u8 value )
255155{
256156 struct twl6040_data * priv = snd_soc_codec_get_drvdata (codec );
257157
258158 switch (reg ) {
259159 case TWL6040_REG_HSLCTL :
260160 case TWL6040_REG_HSRCTL :
261161 case TWL6040_REG_EARCTL :
262- /* DL1 path */
263- return priv -> dl1_unmuted ;
264162 case TWL6040_REG_HFLCTL :
265163 case TWL6040_REG_HFRCTL :
266- return priv -> dl2_unmuted ;
164+ priv -> dl12_cache [reg - TWL6040_REG_HSLCTL ] = value ;
165+ break ;
267166 default :
268- return 1 ;
167+ break ;
269168 }
270169}
271170
272- /*
273- * write to the twl6040 register space
274- */
275171static int twl6040_write (struct snd_soc_codec * codec ,
276172 unsigned int reg , unsigned int value )
277173{
@@ -280,7 +176,7 @@ static int twl6040_write(struct snd_soc_codec *codec,
280176 if (reg >= TWL6040_CACHEREGNUM )
281177 return - EIO ;
282178
283- twl6040_write_reg_cache (codec , reg , value );
179+ twl6040_update_dl12_cache (codec , reg , value );
284180 if (twl6040_can_write_to_chip (codec , reg ))
285181 return twl6040_reg_write (twl6040 , reg , value );
286182 else
@@ -289,34 +185,27 @@ static int twl6040_write(struct snd_soc_codec *codec,
289185
290186static void twl6040_init_chip (struct snd_soc_codec * codec )
291187{
292- struct twl6040 * twl6040 = codec -> control_data ;
293- u8 val ;
294-
295- /* Update reg_cache: ASICREV, and TRIM values */
296- val = twl6040_get_revid (twl6040 );
297- twl6040_write_reg_cache (codec , TWL6040_REG_ASICREV , val );
298-
299- twl6040_read_reg_volatile (codec , TWL6040_REG_TRIM1 );
300- twl6040_read_reg_volatile (codec , TWL6040_REG_TRIM2 );
301- twl6040_read_reg_volatile (codec , TWL6040_REG_TRIM3 );
302- twl6040_read_reg_volatile (codec , TWL6040_REG_HSOTRIM );
303- twl6040_read_reg_volatile (codec , TWL6040_REG_HFOTRIM );
188+ twl6040_read (codec , TWL6040_REG_TRIM1 );
189+ twl6040_read (codec , TWL6040_REG_TRIM2 );
190+ twl6040_read (codec , TWL6040_REG_TRIM3 );
191+ twl6040_read (codec , TWL6040_REG_HSOTRIM );
192+ twl6040_read (codec , TWL6040_REG_HFOTRIM );
304193
305194 /* Change chip defaults */
306195 /* No imput selected for microphone amplifiers */
307- twl6040_write_reg_cache (codec , TWL6040_REG_MICLCTL , 0x18 );
308- twl6040_write_reg_cache (codec , TWL6040_REG_MICRCTL , 0x18 );
196+ twl6040_write (codec , TWL6040_REG_MICLCTL , 0x18 );
197+ twl6040_write (codec , TWL6040_REG_MICRCTL , 0x18 );
309198
310199 /*
311200 * We need to lower the default gain values, so the ramp code
312201 * can work correctly for the first playback.
313202 * This reduces the pop noise heard at the first playback.
314203 */
315- twl6040_write_reg_cache (codec , TWL6040_REG_HSGAIN , 0xff );
316- twl6040_write_reg_cache (codec , TWL6040_REG_EARCTL , 0x1e );
317- twl6040_write_reg_cache (codec , TWL6040_REG_HFLGAIN , 0x1d );
318- twl6040_write_reg_cache (codec , TWL6040_REG_HFRGAIN , 0x1d );
319- twl6040_write_reg_cache (codec , TWL6040_REG_LINEGAIN , 0 );
204+ twl6040_write (codec , TWL6040_REG_HSGAIN , 0xff );
205+ twl6040_write (codec , TWL6040_REG_EARCTL , 0x1e );
206+ twl6040_write (codec , TWL6040_REG_HFLGAIN , 0x1d );
207+ twl6040_write (codec , TWL6040_REG_HFRGAIN , 0x1d );
208+ twl6040_write (codec , TWL6040_REG_LINEGAIN , 0 );
320209}
321210
322211/* set headset dac and driver power mode */
@@ -325,8 +214,8 @@ static int headset_power_mode(struct snd_soc_codec *codec, int high_perf)
325214 int hslctl , hsrctl ;
326215 int mask = TWL6040_HSDRVMODE | TWL6040_HSDACMODE ;
327216
328- hslctl = twl6040_read_reg_cache (codec , TWL6040_REG_HSLCTL );
329- hsrctl = twl6040_read_reg_cache (codec , TWL6040_REG_HSRCTL );
217+ hslctl = twl6040_read (codec , TWL6040_REG_HSLCTL );
218+ hsrctl = twl6040_read (codec , TWL6040_REG_HSRCTL );
330219
331220 if (high_perf ) {
332221 hslctl &= ~mask ;
@@ -353,8 +242,8 @@ static int twl6040_hs_dac_event(struct snd_soc_dapm_widget *w,
353242 * Both HS DAC need to be turned on (before the HS driver) and off at
354243 * the same time.
355244 */
356- hslctl = twl6040_read_reg_cache (codec , TWL6040_REG_HSLCTL );
357- hsrctl = twl6040_read_reg_cache (codec , TWL6040_REG_HSRCTL );
245+ hslctl = twl6040_read (codec , TWL6040_REG_HSLCTL );
246+ hsrctl = twl6040_read (codec , TWL6040_REG_HSRCTL );
358247 if (SND_SOC_DAPM_EVENT_ON (event )) {
359248 hslctl |= TWL6040_HSDACENA ;
360249 hsrctl |= TWL6040_HSDACENA ;
@@ -399,7 +288,7 @@ static void twl6040_hs_jack_report(struct snd_soc_codec *codec,
399288 mutex_lock (& priv -> mutex );
400289
401290 /* Sync status */
402- status = twl6040_read_reg_volatile (codec , TWL6040_REG_STATUS );
291+ status = twl6040_read (codec , TWL6040_REG_STATUS );
403292 if (status & TWL6040_PLUGCOMP )
404293 snd_soc_jack_report (jack , report , report );
405294 else
@@ -451,7 +340,7 @@ static int twl6040_soc_dapm_put_vibra_enum(struct snd_kcontrol *kcontrol,
451340 unsigned int val ;
452341
453342 /* Do not allow changes while Input/FF efect is running */
454- val = twl6040_read_reg_volatile (codec , e -> reg );
343+ val = twl6040_read (codec , e -> reg );
455344 if (val & TWL6040_VIBENA && !(val & TWL6040_VIBSEL ))
456345 return - EBUSY ;
457346
@@ -676,7 +565,7 @@ int twl6040_get_trim_value(struct snd_soc_codec *codec, enum twl6040_trim trim)
676565 if (unlikely (trim >= TWL6040_TRIM_INVAL ))
677566 return - EINVAL ;
678567
679- return twl6040_read_reg_cache (codec , TWL6040_REG_TRIM1 + trim );
568+ return twl6040_read (codec , TWL6040_REG_TRIM1 + trim );
680569}
681570EXPORT_SYMBOL_GPL (twl6040_get_trim_value );
682571
@@ -1071,9 +960,9 @@ static void twl6040_mute_path(struct snd_soc_codec *codec, enum twl6040_dai_id i
1071960
1072961 switch (id ) {
1073962 case TWL6040_DAI_DL1 :
1074- hslctl = twl6040_read_reg_cache (codec , TWL6040_REG_HSLCTL );
1075- hsrctl = twl6040_read_reg_cache (codec , TWL6040_REG_HSRCTL );
1076- earctl = twl6040_read_reg_cache (codec , TWL6040_REG_EARCTL );
963+ hslctl = twl6040_read (codec , TWL6040_REG_HSLCTL );
964+ hsrctl = twl6040_read (codec , TWL6040_REG_HSRCTL );
965+ earctl = twl6040_read (codec , TWL6040_REG_EARCTL );
1077966
1078967 if (mute ) {
1079968 /* Power down drivers and DACs */
@@ -1089,8 +978,8 @@ static void twl6040_mute_path(struct snd_soc_codec *codec, enum twl6040_dai_id i
1089978 priv -> dl1_unmuted = !mute ;
1090979 break ;
1091980 case TWL6040_DAI_DL2 :
1092- hflctl = twl6040_read_reg_cache (codec , TWL6040_REG_HFLCTL );
1093- hfrctl = twl6040_read_reg_cache (codec , TWL6040_REG_HFRCTL );
981+ hflctl = twl6040_read (codec , TWL6040_REG_HFLCTL );
982+ hfrctl = twl6040_read (codec , TWL6040_REG_HFRCTL );
1094983
1095984 if (mute ) {
1096985 /* Power down drivers and DACs */
@@ -1227,6 +1116,7 @@ static int twl6040_resume(struct snd_soc_codec *codec)
12271116static int twl6040_probe (struct snd_soc_codec * codec )
12281117{
12291118 struct twl6040_data * priv ;
1119+ struct twl6040 * twl6040 = dev_get_drvdata (codec -> dev -> parent );
12301120 struct platform_device * pdev = container_of (codec -> dev ,
12311121 struct platform_device , dev );
12321122 int ret = 0 ;
@@ -1238,7 +1128,7 @@ static int twl6040_probe(struct snd_soc_codec *codec)
12381128 snd_soc_codec_set_drvdata (codec , priv );
12391129
12401130 priv -> codec = codec ;
1241- codec -> control_data = dev_get_drvdata ( codec -> dev -> parent ) ;
1131+ codec -> control_data = twl6040 ;
12421132
12431133 priv -> plug_irq = platform_get_irq (pdev , 0 );
12441134 if (priv -> plug_irq < 0 ) {
@@ -1258,10 +1148,10 @@ static int twl6040_probe(struct snd_soc_codec *codec)
12581148 return ret ;
12591149 }
12601150
1151+ twl6040_set_bias_level (codec , SND_SOC_BIAS_STANDBY );
12611152 twl6040_init_chip (codec );
12621153
1263- /* power on device */
1264- return twl6040_set_bias_level (codec , SND_SOC_BIAS_STANDBY );
1154+ return 0 ;
12651155}
12661156
12671157static int twl6040_remove (struct snd_soc_codec * codec )
@@ -1279,12 +1169,9 @@ static struct snd_soc_codec_driver soc_codec_dev_twl6040 = {
12791169 .remove = twl6040_remove ,
12801170 .suspend = twl6040_suspend ,
12811171 .resume = twl6040_resume ,
1282- .read = twl6040_read_reg_cache ,
1172+ .read = twl6040_read ,
12831173 .write = twl6040_write ,
12841174 .set_bias_level = twl6040_set_bias_level ,
1285- .reg_cache_size = ARRAY_SIZE (twl6040_reg ),
1286- .reg_word_size = sizeof (u8 ),
1287- .reg_cache_default = twl6040_reg ,
12881175 .ignore_pmdown_time = true,
12891176
12901177 .controls = twl6040_snd_controls ,
0 commit comments