1
1
// SPDX-License-Identifier: GPL-2.0
2
2
//
3
- // cs35l41.c -- CS35l41 ALSA HDA audio driver
3
+ // CS35l41 ALSA HDA audio driver
4
4
//
5
5
// Copyright 2021 Cirrus Logic, Inc.
6
6
//
17
17
#include "cs35l41_hda.h"
18
18
19
19
static const struct reg_sequence cs35l41_hda_config [] = {
20
- { CS35L41_PLL_CLK_CTRL , 0x00000430 }, //3200000Hz, BCLK Input, PLL_REFCLK_EN = 1
21
- { CS35L41_GLOBAL_CLK_CTRL , 0x00000003 }, //GLOBAL_FS = 48 kHz
22
- { CS35L41_SP_ENABLES , 0x00010000 }, //ASP_RX1_EN = 1
23
- { CS35L41_SP_RATE_CTRL , 0x00000021 }, //ASP_BCLK_FREQ = 3.072 MHz
24
- { CS35L41_SP_FORMAT , 0x20200200 }, //24 bits, I2S, BCLK Slave, FSYNC Slave
25
- { CS35L41_DAC_PCM1_SRC , 0x00000008 }, //DACPCM1_SRC = ASPRX1
26
- { CS35L41_AMP_DIG_VOL_CTRL , 0x00000000 }, //AMP_VOL_PCM 0.0 dB
27
- { CS35L41_AMP_GAIN_CTRL , 0x00000084 }, //AMP_GAIN_PCM 4.5 dB
28
- { CS35L41_PWR_CTRL2 , 0x00000001 }, //AMP_EN = 1
20
+ { CS35L41_PLL_CLK_CTRL , 0x00000430 }, // 3200000Hz, BCLK Input, PLL_REFCLK_EN = 1
21
+ { CS35L41_GLOBAL_CLK_CTRL , 0x00000003 }, // GLOBAL_FS = 48 kHz
22
+ { CS35L41_SP_ENABLES , 0x00010000 }, // ASP_RX1_EN = 1
23
+ { CS35L41_SP_RATE_CTRL , 0x00000021 }, // ASP_BCLK_FREQ = 3.072 MHz
24
+ { CS35L41_SP_FORMAT , 0x20200200 }, // 24 bits, I2S, BCLK Slave, FSYNC Slave
25
+ { CS35L41_DAC_PCM1_SRC , 0x00000008 }, // DACPCM1_SRC = ASPRX1
26
+ { CS35L41_AMP_DIG_VOL_CTRL , 0x00000000 }, // AMP_VOL_PCM 0.0 dB
27
+ { CS35L41_AMP_GAIN_CTRL , 0x00000084 }, // AMP_GAIN_PCM 4.5 dB
28
+ { CS35L41_PWR_CTRL2 , 0x00000001 }, // AMP_EN = 1
29
29
};
30
30
31
31
static const struct reg_sequence cs35l41_hda_start_bst [] = {
32
- { CS35L41_PWR_CTRL2 , 0x00000021 }, //BST_EN = 10, AMP_EN = 1
32
+ { CS35L41_PWR_CTRL2 , 0x00000021 }, // BST_EN = 10, AMP_EN = 1
33
33
{ CS35L41_PWR_CTRL1 , 0x00000001 , 3000 }, // set GLOBAL_EN = 1
34
34
};
35
35
@@ -60,7 +60,7 @@ static const struct reg_sequence cs35l41_stop_ext_vspk[] = {
60
60
{ 0x00000040 , 0x00000055 },
61
61
{ 0x00000040 , 0x000000AA },
62
62
{ 0x00007438 , 0x00585941 },
63
- { 0x00002014 , 0x00000000 , 3000 }, //set GLOBAL_EN = 0
63
+ { 0x00002014 , 0x00000000 , 3000 }, // set GLOBAL_EN = 0
64
64
{ 0x0000742C , 0x00000009 },
65
65
{ 0x00007438 , 0x00580941 },
66
66
{ 0x00011008 , 0x00000001 },
@@ -78,7 +78,7 @@ static const struct reg_sequence cs35l41_safe_to_active[] = {
78
78
{ 0x0000742C , 0x0000000F },
79
79
{ 0x0000742C , 0x00000079 },
80
80
{ 0x00007438 , 0x00585941 },
81
- { CS35L41_PWR_CTRL1 , 0x00000001 , 2000 }, //GLOBAL_EN = 1
81
+ { CS35L41_PWR_CTRL1 , 0x00000001 , 2000 }, // GLOBAL_EN = 1
82
82
{ 0x0000742C , 0x000000F9 },
83
83
{ 0x00007438 , 0x00580941 },
84
84
{ 0x00000040 , 0x000000CC },
@@ -89,8 +89,8 @@ static const struct reg_sequence cs35l41_active_to_safe[] = {
89
89
{ 0x00000040 , 0x00000055 },
90
90
{ 0x00000040 , 0x000000AA },
91
91
{ 0x00007438 , 0x00585941 },
92
- { CS35L41_AMP_DIG_VOL_CTRL , 0x0000A678 }, //AMP_VOL_PCM Mute
93
- { CS35L41_PWR_CTRL2 , 0x00000000 }, //AMP_EN = 0
92
+ { CS35L41_AMP_DIG_VOL_CTRL , 0x0000A678 }, // AMP_VOL_PCM Mute
93
+ { CS35L41_PWR_CTRL2 , 0x00000000 }, // AMP_EN = 0
94
94
{ CS35L41_PWR_CTRL1 , 0x00000000 },
95
95
{ 0x0000742C , 0x00000009 , 2000 },
96
96
{ 0x00007438 , 0x00580941 },
@@ -161,11 +161,13 @@ static void cs35l41_hda_playback_hook(struct device *dev, int action)
161
161
if (reg_seq -> close )
162
162
ret = regmap_multi_reg_write (reg , reg_seq -> close , reg_seq -> num_close );
163
163
break ;
164
+ default :
165
+ ret = - EINVAL ;
166
+ break ;
164
167
}
165
168
166
169
if (ret )
167
170
dev_warn (cs35l41 -> dev , "Failed to apply multi reg write: %d\n" , ret );
168
-
169
171
}
170
172
171
173
static int cs35l41_hda_channel_map (struct device * dev , unsigned int tx_num , unsigned int * tx_slot ,
@@ -182,20 +184,19 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
182
184
struct cs35l41_hda * cs35l41 = dev_get_drvdata (dev );
183
185
struct hda_component * comps = master_data ;
184
186
185
- if (comps && cs35l41 -> index >= 0 && cs35l41 -> index < HDA_MAX_COMPONENTS )
186
- comps = & comps [cs35l41 -> index ];
187
- else
187
+ if (!comps || cs35l41 -> index < 0 || cs35l41 -> index >= HDA_MAX_COMPONENTS )
188
188
return - EINVAL ;
189
189
190
- if (!comps -> dev ) {
191
- comps -> dev = dev ;
192
- strscpy (comps -> name , dev_name (dev ), sizeof (comps -> name ));
193
- comps -> playback_hook = cs35l41_hda_playback_hook ;
194
- comps -> set_channel_map = cs35l41_hda_channel_map ;
195
- return 0 ;
196
- }
190
+ comps = & comps [cs35l41 -> index ];
191
+ if (comps -> dev )
192
+ return - EBUSY ;
193
+
194
+ comps -> dev = dev ;
195
+ strscpy (comps -> name , dev_name (dev ), sizeof (comps -> name ));
196
+ comps -> playback_hook = cs35l41_hda_playback_hook ;
197
+ comps -> set_channel_map = cs35l41_hda_channel_map ;
197
198
198
- return - EBUSY ;
199
+ return 0 ;
199
200
}
200
201
201
202
static void cs35l41_hda_unbind (struct device * dev , struct device * master , void * master_data )
@@ -227,6 +228,8 @@ static int cs35l41_hda_apply_properties(struct cs35l41_hda *cs35l41,
227
228
internal_boost = true;
228
229
229
230
switch (hw_cfg -> gpio1_func ) {
231
+ case CS35L41_NOT_USED :
232
+ break ;
230
233
case CS35l41_VSPK_SWITCH :
231
234
regmap_update_bits (cs35l41 -> regmap , CS35L41_GPIO_PAD_CONTROL ,
232
235
CS35L41_GPIO1_CTRL_MASK , 1 << CS35L41_GPIO1_CTRL_SHIFT );
@@ -235,13 +238,21 @@ static int cs35l41_hda_apply_properties(struct cs35l41_hda *cs35l41,
235
238
regmap_update_bits (cs35l41 -> regmap , CS35L41_GPIO_PAD_CONTROL ,
236
239
CS35L41_GPIO1_CTRL_MASK , 2 << CS35L41_GPIO1_CTRL_SHIFT );
237
240
break ;
241
+ default :
242
+ dev_err (cs35l41 -> dev , "Invalid function %d for GPIO1\n" , hw_cfg -> gpio1_func );
243
+ return - EINVAL ;
238
244
}
239
245
240
246
switch (hw_cfg -> gpio2_func ) {
247
+ case CS35L41_NOT_USED :
248
+ break ;
241
249
case CS35L41_INTERRUPT :
242
250
regmap_update_bits (cs35l41 -> regmap , CS35L41_GPIO_PAD_CONTROL ,
243
251
CS35L41_GPIO2_CTRL_MASK , 2 << CS35L41_GPIO2_CTRL_SHIFT );
244
252
break ;
253
+ default :
254
+ dev_err (cs35l41 -> dev , "Invalid function %d for GPIO2\n" , hw_cfg -> gpio2_func );
255
+ return - EINVAL ;
245
256
}
246
257
247
258
if (internal_boost ) {
@@ -256,11 +267,7 @@ static int cs35l41_hda_apply_properties(struct cs35l41_hda *cs35l41,
256
267
cs35l41 -> reg_seq = & cs35l41_hda_reg_seq_ext_bst ;
257
268
}
258
269
259
- ret = cs35l41_hda_channel_map (cs35l41 -> dev , 0 , NULL , 1 , (unsigned int * )& hw_cfg -> spk_pos );
260
- if (ret )
261
- return ret ;
262
-
263
- return 0 ;
270
+ return cs35l41_hda_channel_map (cs35l41 -> dev , 0 , NULL , 1 , (unsigned int * )& hw_cfg -> spk_pos );
264
271
}
265
272
266
273
static struct cs35l41_hda_hw_config * cs35l41_hda_read_acpi (struct cs35l41_hda * cs35l41 ,
@@ -269,7 +276,7 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
269
276
struct cs35l41_hda_hw_config * hw_cfg ;
270
277
u32 values [HDA_MAX_COMPONENTS ];
271
278
struct acpi_device * adev ;
272
- struct device * acpi_dev ;
279
+ struct device * physdev ;
273
280
char * property ;
274
281
size_t nval ;
275
282
int i , ret ;
@@ -280,11 +287,11 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
280
287
return ERR_PTR (- ENODEV );
281
288
}
282
289
283
- acpi_dev = get_device (acpi_get_first_physical_node (adev ));
290
+ physdev = get_device (acpi_get_first_physical_node (adev ));
284
291
acpi_dev_put (adev );
285
292
286
293
property = "cirrus,dev-index" ;
287
- ret = device_property_count_u32 (acpi_dev , property );
294
+ ret = device_property_count_u32 (physdev , property );
288
295
if (ret <= 0 )
289
296
goto no_acpi_dsd ;
290
297
@@ -294,7 +301,7 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
294
301
}
295
302
nval = ret ;
296
303
297
- ret = device_property_read_u32_array (acpi_dev , property , values , nval );
304
+ ret = device_property_read_u32_array (physdev , property , values , nval );
298
305
if (ret )
299
306
goto err ;
300
307
@@ -311,7 +318,9 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
311
318
goto err ;
312
319
}
313
320
314
- /* No devm_ version as CLSA0100, in no_acpi_dsd case, can't use devm version */
321
+ /* To use the same release code for all laptop variants we can't use devm_ version of
322
+ * gpiod_get here, as CLSA010* don't have a fully functional bios with an _DSD node
323
+ */
315
324
cs35l41 -> reset_gpio = fwnode_gpiod_get_index (& adev -> fwnode , "reset" , cs35l41 -> index ,
316
325
GPIOD_OUT_LOW , "cs35l41-reset" );
317
326
@@ -322,46 +331,46 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
322
331
}
323
332
324
333
property = "cirrus,speaker-position" ;
325
- ret = device_property_read_u32_array (acpi_dev , property , values , nval );
334
+ ret = device_property_read_u32_array (physdev , property , values , nval );
326
335
if (ret )
327
336
goto err_free ;
328
337
hw_cfg -> spk_pos = values [cs35l41 -> index ];
329
338
330
339
property = "cirrus,gpio1-func" ;
331
- ret = device_property_read_u32_array (acpi_dev , property , values , nval );
340
+ ret = device_property_read_u32_array (physdev , property , values , nval );
332
341
if (ret )
333
342
goto err_free ;
334
343
hw_cfg -> gpio1_func = values [cs35l41 -> index ];
335
344
336
345
property = "cirrus,gpio2-func" ;
337
- ret = device_property_read_u32_array (acpi_dev , property , values , nval );
346
+ ret = device_property_read_u32_array (physdev , property , values , nval );
338
347
if (ret )
339
348
goto err_free ;
340
349
hw_cfg -> gpio2_func = values [cs35l41 -> index ];
341
350
342
351
property = "cirrus,boost-peak-milliamp" ;
343
- ret = device_property_read_u32_array (acpi_dev , property , values , nval );
352
+ ret = device_property_read_u32_array (physdev , property , values , nval );
344
353
if (ret == 0 )
345
354
hw_cfg -> bst_ipk = values [cs35l41 -> index ];
346
355
347
356
property = "cirrus,boost-ind-nanohenry" ;
348
- ret = device_property_read_u32_array (acpi_dev , property , values , nval );
357
+ ret = device_property_read_u32_array (physdev , property , values , nval );
349
358
if (ret == 0 )
350
359
hw_cfg -> bst_ind = values [cs35l41 -> index ];
351
360
352
361
property = "cirrus,boost-cap-microfarad" ;
353
- ret = device_property_read_u32_array (acpi_dev , property , values , nval );
362
+ ret = device_property_read_u32_array (physdev , property , values , nval );
354
363
if (ret == 0 )
355
364
hw_cfg -> bst_cap = values [cs35l41 -> index ];
356
365
357
- put_device (acpi_dev );
366
+ put_device (physdev );
358
367
359
368
return hw_cfg ;
360
369
361
370
err_free :
362
371
kfree (hw_cfg );
363
372
err :
364
- put_device (acpi_dev );
373
+ put_device (physdev );
365
374
dev_err (cs35l41 -> dev , "Failed property %s: %d\n" , property , ret );
366
375
367
376
return ERR_PTR (ret );
@@ -370,18 +379,18 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
370
379
/*
371
380
* Device CLSA0100 doesn't have _DSD so a gpiod_get by the label reset won't work.
372
381
* And devices created by i2c-multi-instantiate don't have their device struct pointing to
373
- * the correct fwnode, so acpi_dev must be used here
382
+ * the correct fwnode, so acpi_dev must be used here.
374
383
* And devm functions expect that the device requesting the resource has the correct
375
- * fwnode
384
+ * fwnode.
376
385
*/
377
386
if (strncmp (hid , "CLSA0100" , 8 ) != 0 )
378
387
return ERR_PTR (- EINVAL );
379
388
380
389
/* check I2C address to assign the index */
381
390
cs35l41 -> index = id == 0x40 ? 0 : 1 ;
382
- cs35l41 -> reset_gpio = gpiod_get_index (acpi_dev , NULL , 0 , GPIOD_OUT_HIGH );
391
+ cs35l41 -> reset_gpio = gpiod_get_index (physdev , NULL , 0 , GPIOD_OUT_HIGH );
383
392
cs35l41 -> vspk_always_on = true;
384
- put_device (acpi_dev );
393
+ put_device (physdev );
385
394
386
395
return NULL ;
387
396
}
@@ -416,8 +425,7 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
416
425
if (ret == - EBUSY ) {
417
426
dev_info (cs35l41 -> dev , "Reset line busy, assuming shared reset\n" );
418
427
} else {
419
- if (ret != - EPROBE_DEFER )
420
- dev_err (cs35l41 -> dev , "Failed to get reset GPIO: %d\n" , ret );
428
+ dev_err_probe (cs35l41 -> dev , ret , "Failed to get reset GPIO: %d\n" , ret );
421
429
goto err ;
422
430
}
423
431
}
@@ -437,7 +445,8 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
437
445
438
446
ret = regmap_read (cs35l41 -> regmap , CS35L41_IRQ1_STATUS3 , & int_sts );
439
447
if (ret || (int_sts & CS35L41_OTP_BOOT_ERR )) {
440
- dev_err (cs35l41 -> dev , "OTP Boot error\n" );
448
+ dev_err (cs35l41 -> dev , "OTP Boot status %x error: %d\n" ,
449
+ int_sts & CS35L41_OTP_BOOT_ERR , ret );
441
450
ret = - EIO ;
442
451
goto err ;
443
452
}
@@ -463,6 +472,10 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
463
472
goto err ;
464
473
}
465
474
475
+ ret = cs35l41_test_key_unlock (cs35l41 -> dev , cs35l41 -> regmap );
476
+ if (ret )
477
+ goto err ;
478
+
466
479
ret = cs35l41_register_errata_patch (cs35l41 -> dev , cs35l41 -> regmap , reg_revid );
467
480
if (ret )
468
481
goto err ;
@@ -473,15 +486,19 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
473
486
goto err ;
474
487
}
475
488
489
+ ret = cs35l41_test_key_lock (cs35l41 -> dev , cs35l41 -> regmap );
490
+ if (ret )
491
+ goto err ;
492
+
476
493
ret = cs35l41_hda_apply_properties (cs35l41 , acpi_hw_cfg );
477
494
if (ret )
478
495
goto err ;
479
496
kfree (acpi_hw_cfg );
480
497
acpi_hw_cfg = NULL ;
481
498
482
499
if (cs35l41 -> reg_seq -> probe ) {
483
- ret = regmap_register_patch (cs35l41 -> regmap , cs35l41 -> reg_seq -> probe ,
484
- cs35l41 -> reg_seq -> num_probe );
500
+ ret = regmap_multi_reg_write (cs35l41 -> regmap , cs35l41 -> reg_seq -> probe ,
501
+ cs35l41 -> reg_seq -> num_probe );
485
502
if (ret ) {
486
503
dev_err (cs35l41 -> dev , "Fail to apply probe reg patch: %d\n" , ret );
487
504
goto err ;
@@ -506,9 +523,9 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
506
523
507
524
return ret ;
508
525
}
509
- EXPORT_SYMBOL_GPL (cs35l41_hda_probe );
526
+ EXPORT_SYMBOL_NS_GPL (cs35l41_hda_probe , SND_HDA_SCODEC_CS35L41 );
510
527
511
- int cs35l41_hda_remove (struct device * dev )
528
+ void cs35l41_hda_remove (struct device * dev )
512
529
{
513
530
struct cs35l41_hda * cs35l41 = dev_get_drvdata (dev );
514
531
@@ -517,11 +534,8 @@ int cs35l41_hda_remove(struct device *dev)
517
534
if (!cs35l41 -> vspk_always_on )
518
535
gpiod_set_value_cansleep (cs35l41 -> reset_gpio , 0 );
519
536
gpiod_put (cs35l41 -> reset_gpio );
520
-
521
- return 0 ;
522
537
}
523
- EXPORT_SYMBOL_GPL (cs35l41_hda_remove );
524
-
538
+ EXPORT_SYMBOL_NS_GPL (cs35l41_hda_remove , SND_HDA_SCODEC_CS35L41 );
525
539
526
540
MODULE_DESCRIPTION ("CS35L41 HDA Driver" );
527
541
MODULE_AUTHOR ("Lucas Tanure, Cirrus Logic Inc, <tanureal@opensource.cirrus.com>" );
0 commit comments