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 },
@@ -168,7 +168,6 @@ static void cs35l41_hda_playback_hook(struct device *dev, int action)
168
168
169
169
if (ret )
170
170
dev_warn (cs35l41 -> dev , "Failed to apply multi reg write: %d\n" , ret );
171
-
172
171
}
173
172
174
173
static int cs35l41_hda_channel_map (struct device * dev , unsigned int tx_num , unsigned int * tx_slot ,
@@ -185,20 +184,19 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
185
184
struct cs35l41_hda * cs35l41 = dev_get_drvdata (dev );
186
185
struct hda_component * comps = master_data ;
187
186
188
- if (comps && cs35l41 -> index >= 0 && cs35l41 -> index < HDA_MAX_COMPONENTS )
189
- comps = & comps [cs35l41 -> index ];
190
- else
187
+ if (!comps || cs35l41 -> index < 0 || cs35l41 -> index >= HDA_MAX_COMPONENTS )
191
188
return - EINVAL ;
192
189
193
- if (!comps -> dev ) {
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 ;
198
- return 0 ;
199
- }
190
+ comps = & comps [cs35l41 -> index ];
191
+ if (comps -> dev )
192
+ return - EBUSY ;
200
193
201
- return - EBUSY ;
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 ;
198
+
199
+ return 0 ;
202
200
}
203
201
204
202
static void cs35l41_hda_unbind (struct device * dev , struct device * master , void * master_data )
@@ -269,11 +267,7 @@ static int cs35l41_hda_apply_properties(struct cs35l41_hda *cs35l41,
269
267
cs35l41 -> reg_seq = & cs35l41_hda_reg_seq_ext_bst ;
270
268
}
271
269
272
- ret = cs35l41_hda_channel_map (cs35l41 -> dev , 0 , NULL , 1 , (unsigned int * )& hw_cfg -> spk_pos );
273
- if (ret )
274
- return ret ;
275
-
276
- return 0 ;
270
+ return cs35l41_hda_channel_map (cs35l41 -> dev , 0 , NULL , 1 , (unsigned int * )& hw_cfg -> spk_pos );
277
271
}
278
272
279
273
static struct cs35l41_hda_hw_config * cs35l41_hda_read_acpi (struct cs35l41_hda * cs35l41 ,
@@ -282,7 +276,7 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
282
276
struct cs35l41_hda_hw_config * hw_cfg ;
283
277
u32 values [HDA_MAX_COMPONENTS ];
284
278
struct acpi_device * adev ;
285
- struct device * acpi_dev ;
279
+ struct device * physdev ;
286
280
char * property ;
287
281
size_t nval ;
288
282
int i , ret ;
@@ -293,11 +287,11 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
293
287
return ERR_PTR (- ENODEV );
294
288
}
295
289
296
- acpi_dev = get_device (acpi_get_first_physical_node (adev ));
290
+ physdev = get_device (acpi_get_first_physical_node (adev ));
297
291
acpi_dev_put (adev );
298
292
299
293
property = "cirrus,dev-index" ;
300
- ret = device_property_count_u32 (acpi_dev , property );
294
+ ret = device_property_count_u32 (physdev , property );
301
295
if (ret <= 0 )
302
296
goto no_acpi_dsd ;
303
297
@@ -307,7 +301,7 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
307
301
}
308
302
nval = ret ;
309
303
310
- ret = device_property_read_u32_array (acpi_dev , property , values , nval );
304
+ ret = device_property_read_u32_array (physdev , property , values , nval );
311
305
if (ret )
312
306
goto err ;
313
307
@@ -324,7 +318,9 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
324
318
goto err ;
325
319
}
326
320
327
- /* 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
+ */
328
324
cs35l41 -> reset_gpio = fwnode_gpiod_get_index (& adev -> fwnode , "reset" , cs35l41 -> index ,
329
325
GPIOD_OUT_LOW , "cs35l41-reset" );
330
326
@@ -335,46 +331,46 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
335
331
}
336
332
337
333
property = "cirrus,speaker-position" ;
338
- ret = device_property_read_u32_array (acpi_dev , property , values , nval );
334
+ ret = device_property_read_u32_array (physdev , property , values , nval );
339
335
if (ret )
340
336
goto err_free ;
341
337
hw_cfg -> spk_pos = values [cs35l41 -> index ];
342
338
343
339
property = "cirrus,gpio1-func" ;
344
- ret = device_property_read_u32_array (acpi_dev , property , values , nval );
340
+ ret = device_property_read_u32_array (physdev , property , values , nval );
345
341
if (ret )
346
342
goto err_free ;
347
343
hw_cfg -> gpio1_func = values [cs35l41 -> index ];
348
344
349
345
property = "cirrus,gpio2-func" ;
350
- ret = device_property_read_u32_array (acpi_dev , property , values , nval );
346
+ ret = device_property_read_u32_array (physdev , property , values , nval );
351
347
if (ret )
352
348
goto err_free ;
353
349
hw_cfg -> gpio2_func = values [cs35l41 -> index ];
354
350
355
351
property = "cirrus,boost-peak-milliamp" ;
356
- ret = device_property_read_u32_array (acpi_dev , property , values , nval );
352
+ ret = device_property_read_u32_array (physdev , property , values , nval );
357
353
if (ret == 0 )
358
354
hw_cfg -> bst_ipk = values [cs35l41 -> index ];
359
355
360
356
property = "cirrus,boost-ind-nanohenry" ;
361
- ret = device_property_read_u32_array (acpi_dev , property , values , nval );
357
+ ret = device_property_read_u32_array (physdev , property , values , nval );
362
358
if (ret == 0 )
363
359
hw_cfg -> bst_ind = values [cs35l41 -> index ];
364
360
365
361
property = "cirrus,boost-cap-microfarad" ;
366
- ret = device_property_read_u32_array (acpi_dev , property , values , nval );
362
+ ret = device_property_read_u32_array (physdev , property , values , nval );
367
363
if (ret == 0 )
368
364
hw_cfg -> bst_cap = values [cs35l41 -> index ];
369
365
370
- put_device (acpi_dev );
366
+ put_device (physdev );
371
367
372
368
return hw_cfg ;
373
369
374
370
err_free :
375
371
kfree (hw_cfg );
376
372
err :
377
- put_device (acpi_dev );
373
+ put_device (physdev );
378
374
dev_err (cs35l41 -> dev , "Failed property %s: %d\n" , property , ret );
379
375
380
376
return ERR_PTR (ret );
@@ -383,18 +379,18 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
383
379
/*
384
380
* Device CLSA0100 doesn't have _DSD so a gpiod_get by the label reset won't work.
385
381
* And devices created by i2c-multi-instantiate don't have their device struct pointing to
386
- * the correct fwnode, so acpi_dev must be used here
382
+ * the correct fwnode, so acpi_dev must be used here.
387
383
* And devm functions expect that the device requesting the resource has the correct
388
- * fwnode
384
+ * fwnode.
389
385
*/
390
386
if (strncmp (hid , "CLSA0100" , 8 ) != 0 )
391
387
return ERR_PTR (- EINVAL );
392
388
393
389
/* check I2C address to assign the index */
394
390
cs35l41 -> index = id == 0x40 ? 0 : 1 ;
395
- 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 );
396
392
cs35l41 -> vspk_always_on = true;
397
- put_device (acpi_dev );
393
+ put_device (physdev );
398
394
399
395
return NULL ;
400
396
}
@@ -449,7 +445,8 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
449
445
450
446
ret = regmap_read (cs35l41 -> regmap , CS35L41_IRQ1_STATUS3 , & int_sts );
451
447
if (ret || (int_sts & CS35L41_OTP_BOOT_ERR )) {
452
- 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 );
453
450
ret = - EIO ;
454
451
goto err ;
455
452
}
@@ -501,7 +498,7 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
501
498
502
499
if (cs35l41 -> reg_seq -> probe ) {
503
500
ret = regmap_multi_reg_write (cs35l41 -> regmap , cs35l41 -> reg_seq -> probe ,
504
- cs35l41 -> reg_seq -> num_probe );
501
+ cs35l41 -> reg_seq -> num_probe );
505
502
if (ret ) {
506
503
dev_err (cs35l41 -> dev , "Fail to apply probe reg patch: %d\n" , ret );
507
504
goto err ;
0 commit comments