diff mbox series

[2/2] ASoC: constify snd_soc_component_driver struct

Message ID 20240725-const_snd_soc_component_driver-v1-2-3d7ee08e129b@gmail.com (mailing list archive)
State New, archived
Headers show
Series {ASoC,media}: constify snd_soc_component_driver struct | expand

Commit Message

Javier Carrasco July 25, 2024, 10:31 a.m. UTC
The instances of the `snd_soc_component_driver` struct are not modified
after their declaration, and they are only passed to
`devm_snd_soc_register_component()`, which expects a constant
`snd_soc_component_driver`.

Move all instances of `snd_soc_component_driver` to read-only sections
by declaring them const.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 sound/soc/au1x/dbdma2.c              | 2 +-
 sound/soc/au1x/dma.c                 | 2 +-
 sound/soc/bcm/cygnus-pcm.c           | 2 +-
 sound/soc/codecs/cpcap.c             | 2 +-
 sound/soc/codecs/cs43130.c           | 2 +-
 sound/soc/codecs/pcm186x.c           | 4 ++--
 sound/soc/codecs/pcm5102a.c          | 2 +-
 sound/soc/codecs/spdif_receiver.c    | 2 +-
 sound/soc/codecs/spdif_transmitter.c | 2 +-
 sound/soc/codecs/sti-sas.c           | 2 +-
 sound/soc/codecs/tas6424.c           | 2 +-
 sound/soc/stm/stm32_adfsdm.c         | 2 +-
 sound/soc/uniphier/evea.c            | 2 +-
 13 files changed, 14 insertions(+), 14 deletions(-)

Comments

Charles Keepax July 26, 2024, 8:13 a.m. UTC | #1
On Thu, Jul 25, 2024 at 12:31:40PM +0200, Javier Carrasco wrote:
> The instances of the `snd_soc_component_driver` struct are not modified
> after their declaration, and they are only passed to
> `devm_snd_soc_register_component()`, which expects a constant
> `snd_soc_component_driver`.
> 
> Move all instances of `snd_soc_component_driver` to read-only sections
> by declaring them const.
> 
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> ---
>  sound/soc/codecs/cs43130.c           | 2 +-

> -static struct snd_soc_component_driver soc_component_dev_cs43130 = {
> +static const struct snd_soc_component_driver soc_component_dev_cs43130 = {
>  	.probe			= cs43130_probe,
>  	.controls		= cs43130_snd_controls,
>  	.num_controls		= ARRAY_SIZE(cs43130_snd_controls),

This won't work for cs43130, whilst what the driver does is
clearly slightly sketch it directly modifies this struct before
registering it with ASoC. That would need fixed first before this
change can be made.

Thanks,
Charles
Javier Carrasco July 26, 2024, 9:07 a.m. UTC | #2
On 26/07/2024 10:13, Charles Keepax wrote:
> On Thu, Jul 25, 2024 at 12:31:40PM +0200, Javier Carrasco wrote:
>> The instances of the `snd_soc_component_driver` struct are not modified
>> after their declaration, and they are only passed to
>> `devm_snd_soc_register_component()`, which expects a constant
>> `snd_soc_component_driver`.
>>
>> Move all instances of `snd_soc_component_driver` to read-only sections
>> by declaring them const.
>>
>> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
>> ---
>>  sound/soc/codecs/cs43130.c           | 2 +-
> 
>> -static struct snd_soc_component_driver soc_component_dev_cs43130 = {
>> +static const struct snd_soc_component_driver soc_component_dev_cs43130 = {
>>  	.probe			= cs43130_probe,
>>  	.controls		= cs43130_snd_controls,
>>  	.num_controls		= ARRAY_SIZE(cs43130_snd_controls),
> 
> This won't work for cs43130, whilst what the driver does is
> clearly slightly sketch it directly modifies this struct before
> registering it with ASoC. That would need fixed first before this
> change can be made.
> 
> Thanks,
> Charles

Hi Charles,

thanks a lot for pointing this out, somehow I failed to compile cs43130
and sti-sas, which are the only two cases in the kernel that do modify
snd_soc_component_driver after the declaration. The rest don't do that
and I just double checked that they compile cleanly.

Those two cases where modifications are required rely on values that are
not known until they are probed. I think it makes then sense that they
are left as they are, so I will drop both drivers for v2.

Best regards,
Javier Carrasco
kernel test robot July 26, 2024, 9:39 a.m. UTC | #3
Hi Javier,

kernel test robot noticed the following build errors:

[auto build test ERROR on 864b1099d16fc7e332c3ad7823058c65f890486c]

url:    https://github.com/intel-lab-lkp/linux/commits/Javier-Carrasco/media-i2c-tda1997x-constify-snd_soc_component_driver-struct/20240725-183542
base:   864b1099d16fc7e332c3ad7823058c65f890486c
patch link:    https://lore.kernel.org/r/20240725-const_snd_soc_component_driver-v1-2-3d7ee08e129b%40gmail.com
patch subject: [PATCH 2/2] ASoC: constify snd_soc_component_driver struct
config: i386-buildonly-randconfig-003-20240726 (https://download.01.org/0day-ci/archive/20240726/202407261707.8O24kg8R-lkp@intel.com/config)
compiler: gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240726/202407261707.8O24kg8R-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202407261707.8O24kg8R-lkp@intel.com/

All errors (new ones prefixed by >>):

   sound/soc/codecs/sti-sas.c: In function 'sti_sas_driver_probe':
>> sound/soc/codecs/sti-sas.c:450:37: error: assignment of member 'dapm_widgets' in read-only object
     450 |         sti_sas_driver.dapm_widgets = drvdata->dev_data->dapm_widgets;
         |                                     ^
>> sound/soc/codecs/sti-sas.c:451:41: error: assignment of member 'num_dapm_widgets' in read-only object
     451 |         sti_sas_driver.num_dapm_widgets = drvdata->dev_data->num_dapm_widgets;
         |                                         ^
>> sound/soc/codecs/sti-sas.c:453:36: error: assignment of member 'dapm_routes' in read-only object
     453 |         sti_sas_driver.dapm_routes = drvdata->dev_data->dapm_routes;
         |                                    ^
>> sound/soc/codecs/sti-sas.c:454:40: error: assignment of member 'num_dapm_routes' in read-only object
     454 |         sti_sas_driver.num_dapm_routes = drvdata->dev_data->num_dapm_routes;
         |                                        ^


vim +/dapm_widgets +450 sound/soc/codecs/sti-sas.c

32a726b2e089ec Arnaud Pouliquen  2015-06-22  405  
32a726b2e089ec Arnaud Pouliquen  2015-06-22  406  static int sti_sas_driver_probe(struct platform_device *pdev)
32a726b2e089ec Arnaud Pouliquen  2015-06-22  407  {
32a726b2e089ec Arnaud Pouliquen  2015-06-22  408  	struct device_node *pnode = pdev->dev.of_node;
32a726b2e089ec Arnaud Pouliquen  2015-06-22  409  	struct sti_sas_data *drvdata;
601b9d9c7bd04f Arnaud Pouliquen  2015-07-16  410  	const struct of_device_id *of_id;
32a726b2e089ec Arnaud Pouliquen  2015-06-22  411  
32a726b2e089ec Arnaud Pouliquen  2015-06-22  412  	/* Allocate device structure */
32a726b2e089ec Arnaud Pouliquen  2015-06-22  413  	drvdata = devm_kzalloc(&pdev->dev, sizeof(struct sti_sas_data),
32a726b2e089ec Arnaud Pouliquen  2015-06-22  414  			       GFP_KERNEL);
32a726b2e089ec Arnaud Pouliquen  2015-06-22  415  	if (!drvdata)
32a726b2e089ec Arnaud Pouliquen  2015-06-22  416  		return -ENOMEM;
32a726b2e089ec Arnaud Pouliquen  2015-06-22  417  
32a726b2e089ec Arnaud Pouliquen  2015-06-22  418  	/* Populate data structure depending on compatibility */
601b9d9c7bd04f Arnaud Pouliquen  2015-07-16  419  	of_id = of_match_node(sti_sas_dev_match, pnode);
601b9d9c7bd04f Arnaud Pouliquen  2015-07-16  420  	if (!of_id->data) {
92591efabc013f Arnaud Pouliquen  2016-10-24  421  		dev_err(&pdev->dev, "data associated to device is missing\n");
32a726b2e089ec Arnaud Pouliquen  2015-06-22  422  		return -EINVAL;
32a726b2e089ec Arnaud Pouliquen  2015-06-22  423  	}
32a726b2e089ec Arnaud Pouliquen  2015-06-22  424  
601b9d9c7bd04f Arnaud Pouliquen  2015-07-16  425  	drvdata->dev_data = (struct sti_sas_dev_data *)of_id->data;
32a726b2e089ec Arnaud Pouliquen  2015-06-22  426  
32a726b2e089ec Arnaud Pouliquen  2015-06-22  427  	/* Initialise device structure */
32a726b2e089ec Arnaud Pouliquen  2015-06-22  428  	drvdata->dev = &pdev->dev;
32a726b2e089ec Arnaud Pouliquen  2015-06-22  429  
32a726b2e089ec Arnaud Pouliquen  2015-06-22  430  	/* Request the DAC & SPDIF registers memory region */
32a726b2e089ec Arnaud Pouliquen  2015-06-22  431  	drvdata->dac.virt_regmap = devm_regmap_init(&pdev->dev, NULL, drvdata,
32a726b2e089ec Arnaud Pouliquen  2015-06-22  432  						    drvdata->dev_data->regmap);
e27d9ee6e709db Axel Lin          2015-07-13  433  	if (IS_ERR(drvdata->dac.virt_regmap)) {
32a726b2e089ec Arnaud Pouliquen  2015-06-22  434  		dev_err(&pdev->dev, "audio registers not enabled\n");
e27d9ee6e709db Axel Lin          2015-07-13  435  		return PTR_ERR(drvdata->dac.virt_regmap);
32a726b2e089ec Arnaud Pouliquen  2015-06-22  436  	}
32a726b2e089ec Arnaud Pouliquen  2015-06-22  437  
32a726b2e089ec Arnaud Pouliquen  2015-06-22  438  	/* Request the syscon region */
32a726b2e089ec Arnaud Pouliquen  2015-06-22  439  	drvdata->dac.regmap =
32a726b2e089ec Arnaud Pouliquen  2015-06-22  440  		syscon_regmap_lookup_by_phandle(pnode, "st,syscfg");
e27d9ee6e709db Axel Lin          2015-07-13  441  	if (IS_ERR(drvdata->dac.regmap)) {
32a726b2e089ec Arnaud Pouliquen  2015-06-22  442  		dev_err(&pdev->dev, "syscon registers not available\n");
e27d9ee6e709db Axel Lin          2015-07-13  443  		return PTR_ERR(drvdata->dac.regmap);
32a726b2e089ec Arnaud Pouliquen  2015-06-22  444  	}
32a726b2e089ec Arnaud Pouliquen  2015-06-22  445  	drvdata->spdif.regmap = drvdata->dac.regmap;
32a726b2e089ec Arnaud Pouliquen  2015-06-22  446  
32a726b2e089ec Arnaud Pouliquen  2015-06-22  447  	sti_sas_dai[STI_SAS_DAI_ANALOG_OUT].ops = drvdata->dev_data->dac_ops;
32a726b2e089ec Arnaud Pouliquen  2015-06-22  448  
32a726b2e089ec Arnaud Pouliquen  2015-06-22  449  	/* Set dapms*/
049c1bfc30f3a5 Kuninori Morimoto 2018-01-29 @450  	sti_sas_driver.dapm_widgets = drvdata->dev_data->dapm_widgets;
049c1bfc30f3a5 Kuninori Morimoto 2018-01-29 @451  	sti_sas_driver.num_dapm_widgets = drvdata->dev_data->num_dapm_widgets;
32a726b2e089ec Arnaud Pouliquen  2015-06-22  452  
049c1bfc30f3a5 Kuninori Morimoto 2018-01-29 @453  	sti_sas_driver.dapm_routes = drvdata->dev_data->dapm_routes;
049c1bfc30f3a5 Kuninori Morimoto 2018-01-29 @454  	sti_sas_driver.num_dapm_routes = drvdata->dev_data->num_dapm_routes;
32a726b2e089ec Arnaud Pouliquen  2015-06-22  455  
32a726b2e089ec Arnaud Pouliquen  2015-06-22  456  	/* Store context */
32a726b2e089ec Arnaud Pouliquen  2015-06-22  457  	dev_set_drvdata(&pdev->dev, drvdata);
32a726b2e089ec Arnaud Pouliquen  2015-06-22  458  
049c1bfc30f3a5 Kuninori Morimoto 2018-01-29  459  	return devm_snd_soc_register_component(&pdev->dev, &sti_sas_driver,
32a726b2e089ec Arnaud Pouliquen  2015-06-22  460  					sti_sas_dai,
32a726b2e089ec Arnaud Pouliquen  2015-06-22  461  					ARRAY_SIZE(sti_sas_dai));
32a726b2e089ec Arnaud Pouliquen  2015-06-22  462  }
32a726b2e089ec Arnaud Pouliquen  2015-06-22  463
kernel test robot July 26, 2024, 11:27 a.m. UTC | #4
Hi Javier,

kernel test robot noticed the following build errors:

[auto build test ERROR on 864b1099d16fc7e332c3ad7823058c65f890486c]

url:    https://github.com/intel-lab-lkp/linux/commits/Javier-Carrasco/media-i2c-tda1997x-constify-snd_soc_component_driver-struct/20240725-183542
base:   864b1099d16fc7e332c3ad7823058c65f890486c
patch link:    https://lore.kernel.org/r/20240725-const_snd_soc_component_driver-v1-2-3d7ee08e129b%40gmail.com
patch subject: [PATCH 2/2] ASoC: constify snd_soc_component_driver struct
config: i386-randconfig-012-20240726 (https://download.01.org/0day-ci/archive/20240726/202407261907.9WRDvix7-lkp@intel.com/config)
compiler: gcc-8 (Ubuntu 8.4.0-3ubuntu2) 8.4.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240726/202407261907.9WRDvix7-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202407261907.9WRDvix7-lkp@intel.com/

All errors (new ones prefixed by >>):

   sound/soc/codecs/cs43130.c: In function 'cs43130_i2c_probe':
>> sound/soc/codecs/cs43130.c:2608:42: error: assignment of member 'dapm_widgets' in read-only object
      soc_component_dev_cs43130.dapm_widgets =
                                             ^
>> sound/soc/codecs/cs43130.c:2610:46: error: assignment of member 'num_dapm_widgets' in read-only object
      soc_component_dev_cs43130.num_dapm_widgets =
                                                 ^
>> sound/soc/codecs/cs43130.c:2612:41: error: assignment of member 'dapm_routes' in read-only object
      soc_component_dev_cs43130.dapm_routes =
                                            ^
>> sound/soc/codecs/cs43130.c:2614:45: error: assignment of member 'num_dapm_routes' in read-only object
      soc_component_dev_cs43130.num_dapm_routes =
                                                ^
   sound/soc/codecs/cs43130.c:2619:42: error: assignment of member 'dapm_widgets' in read-only object
      soc_component_dev_cs43130.dapm_widgets =
                                             ^
   sound/soc/codecs/cs43130.c:2621:46: error: assignment of member 'num_dapm_widgets' in read-only object
      soc_component_dev_cs43130.num_dapm_widgets =
                                                 ^
   sound/soc/codecs/cs43130.c:2623:41: error: assignment of member 'dapm_routes' in read-only object
      soc_component_dev_cs43130.dapm_routes =
                                            ^
   sound/soc/codecs/cs43130.c:2625:45: error: assignment of member 'num_dapm_routes' in read-only object
      soc_component_dev_cs43130.num_dapm_routes =
                                                ^


vim +/dapm_widgets +2608 sound/soc/codecs/cs43130.c

8f1e5bf9b4408e Li Xu             2017-08-18  2479  
4a4043456cb82d Stephen Kitt      2022-03-25  2480  static int cs43130_i2c_probe(struct i2c_client *client)
8f1e5bf9b4408e Li Xu             2017-08-18  2481  {
8f1e5bf9b4408e Li Xu             2017-08-18  2482  	struct cs43130_private *cs43130;
8f1e5bf9b4408e Li Xu             2017-08-18  2483  	int ret;
8f1e5bf9b4408e Li Xu             2017-08-18  2484  	unsigned int reg;
e2bb1077cee4d1 Charles Keepax    2021-05-10  2485  	int i, devid;
8f1e5bf9b4408e Li Xu             2017-08-18  2486  
8f1e5bf9b4408e Li Xu             2017-08-18  2487  	cs43130 = devm_kzalloc(&client->dev, sizeof(*cs43130), GFP_KERNEL);
8f1e5bf9b4408e Li Xu             2017-08-18  2488  	if (!cs43130)
8f1e5bf9b4408e Li Xu             2017-08-18  2489  		return -ENOMEM;
8f1e5bf9b4408e Li Xu             2017-08-18  2490  
552206add94dd7 Maciej Strozek    2023-11-17  2491  	cs43130->dev = &client->dev;
552206add94dd7 Maciej Strozek    2023-11-17  2492  
8f1e5bf9b4408e Li Xu             2017-08-18  2493  	i2c_set_clientdata(client, cs43130);
8f1e5bf9b4408e Li Xu             2017-08-18  2494  
8f1e5bf9b4408e Li Xu             2017-08-18  2495  	cs43130->regmap = devm_regmap_init_i2c(client, &cs43130_regmap);
8f1e5bf9b4408e Li Xu             2017-08-18  2496  	if (IS_ERR(cs43130->regmap)) {
8f1e5bf9b4408e Li Xu             2017-08-18  2497  		ret = PTR_ERR(cs43130->regmap);
8f1e5bf9b4408e Li Xu             2017-08-18  2498  		return ret;
8f1e5bf9b4408e Li Xu             2017-08-18  2499  	}
8f1e5bf9b4408e Li Xu             2017-08-18  2500  
ce7944b73e7729 Maciej Strozek    2023-11-17  2501  	if (dev_fwnode(cs43130->dev)) {
ce7944b73e7729 Maciej Strozek    2023-11-17  2502  		ret = cs43130_handle_device_data(cs43130);
8f1e5bf9b4408e Li Xu             2017-08-18  2503  		if (ret != 0)
8f1e5bf9b4408e Li Xu             2017-08-18  2504  			return ret;
8f1e5bf9b4408e Li Xu             2017-08-18  2505  	}
ce7944b73e7729 Maciej Strozek    2023-11-17  2506  
8f1e5bf9b4408e Li Xu             2017-08-18  2507  	for (i = 0; i < ARRAY_SIZE(cs43130->supplies); i++)
8f1e5bf9b4408e Li Xu             2017-08-18  2508  		cs43130->supplies[i].supply = cs43130_supply_names[i];
8f1e5bf9b4408e Li Xu             2017-08-18  2509  
552206add94dd7 Maciej Strozek    2023-11-17  2510  	ret = devm_regulator_bulk_get(cs43130->dev,
8f1e5bf9b4408e Li Xu             2017-08-18  2511  				      ARRAY_SIZE(cs43130->supplies),
8f1e5bf9b4408e Li Xu             2017-08-18  2512  				      cs43130->supplies);
8f1e5bf9b4408e Li Xu             2017-08-18  2513  	if (ret != 0) {
552206add94dd7 Maciej Strozek    2023-11-17  2514  		dev_err(cs43130->dev, "Failed to request supplies: %d\n", ret);
8f1e5bf9b4408e Li Xu             2017-08-18  2515  		return ret;
8f1e5bf9b4408e Li Xu             2017-08-18  2516  	}
8f1e5bf9b4408e Li Xu             2017-08-18  2517  	ret = regulator_bulk_enable(ARRAY_SIZE(cs43130->supplies),
8f1e5bf9b4408e Li Xu             2017-08-18  2518  				    cs43130->supplies);
8f1e5bf9b4408e Li Xu             2017-08-18  2519  	if (ret != 0) {
552206add94dd7 Maciej Strozek    2023-11-17  2520  		dev_err(cs43130->dev, "Failed to enable supplies: %d\n", ret);
8f1e5bf9b4408e Li Xu             2017-08-18  2521  		return ret;
8f1e5bf9b4408e Li Xu             2017-08-18  2522  	}
8f1e5bf9b4408e Li Xu             2017-08-18  2523  
552206add94dd7 Maciej Strozek    2023-11-17  2524  	cs43130->reset_gpio = devm_gpiod_get_optional(cs43130->dev,
8f1e5bf9b4408e Li Xu             2017-08-18  2525  						      "reset", GPIOD_OUT_LOW);
e2bb1077cee4d1 Charles Keepax    2021-05-10  2526  	if (IS_ERR(cs43130->reset_gpio)) {
e2bb1077cee4d1 Charles Keepax    2021-05-10  2527  		ret = PTR_ERR(cs43130->reset_gpio);
e2bb1077cee4d1 Charles Keepax    2021-05-10  2528  		goto err_supplies;
e2bb1077cee4d1 Charles Keepax    2021-05-10  2529  	}
8f1e5bf9b4408e Li Xu             2017-08-18  2530  
8f1e5bf9b4408e Li Xu             2017-08-18  2531  	gpiod_set_value_cansleep(cs43130->reset_gpio, 1);
8f1e5bf9b4408e Li Xu             2017-08-18  2532  
8f1e5bf9b4408e Li Xu             2017-08-18  2533  	usleep_range(2000, 2050);
8f1e5bf9b4408e Li Xu             2017-08-18  2534  
e2bb1077cee4d1 Charles Keepax    2021-05-10  2535  	devid = cirrus_read_device_id(cs43130->regmap, CS43130_DEVID_AB);
e2bb1077cee4d1 Charles Keepax    2021-05-10  2536  	if (devid < 0) {
e2bb1077cee4d1 Charles Keepax    2021-05-10  2537  		ret = devid;
552206add94dd7 Maciej Strozek    2023-11-17  2538  		dev_err(cs43130->dev, "Failed to read device ID: %d\n", ret);
e2bb1077cee4d1 Charles Keepax    2021-05-10  2539  		goto err;
e2bb1077cee4d1 Charles Keepax    2021-05-10  2540  	}
8f1e5bf9b4408e Li Xu             2017-08-18  2541  
8f1e5bf9b4408e Li Xu             2017-08-18  2542  	switch (devid) {
8f1e5bf9b4408e Li Xu             2017-08-18  2543  	case CS43130_CHIP_ID:
8f1e5bf9b4408e Li Xu             2017-08-18  2544  	case CS4399_CHIP_ID:
8f1e5bf9b4408e Li Xu             2017-08-18  2545  	case CS43131_CHIP_ID:
8f1e5bf9b4408e Li Xu             2017-08-18  2546  	case CS43198_CHIP_ID:
8f1e5bf9b4408e Li Xu             2017-08-18  2547  		break;
8f1e5bf9b4408e Li Xu             2017-08-18  2548  	default:
552206add94dd7 Maciej Strozek    2023-11-17  2549  		dev_err(cs43130->dev,
8f1e5bf9b4408e Li Xu             2017-08-18  2550  			"CS43130 Device ID %X. Expected ID %X, %X, %X or %X\n",
8f1e5bf9b4408e Li Xu             2017-08-18  2551  			devid, CS43130_CHIP_ID, CS4399_CHIP_ID,
8f1e5bf9b4408e Li Xu             2017-08-18  2552  			CS43131_CHIP_ID, CS43198_CHIP_ID);
8f1e5bf9b4408e Li Xu             2017-08-18  2553  		ret = -ENODEV;
8f1e5bf9b4408e Li Xu             2017-08-18  2554  		goto err;
8f1e5bf9b4408e Li Xu             2017-08-18  2555  	}
8f1e5bf9b4408e Li Xu             2017-08-18  2556  
8f1e5bf9b4408e Li Xu             2017-08-18  2557  	cs43130->dev_id = devid;
8f1e5bf9b4408e Li Xu             2017-08-18  2558  	ret = regmap_read(cs43130->regmap, CS43130_REV_ID, &reg);
8f1e5bf9b4408e Li Xu             2017-08-18  2559  	if (ret < 0) {
552206add94dd7 Maciej Strozek    2023-11-17  2560  		dev_err(cs43130->dev, "Get Revision ID failed\n");
8f1e5bf9b4408e Li Xu             2017-08-18  2561  		goto err;
8f1e5bf9b4408e Li Xu             2017-08-18  2562  	}
8f1e5bf9b4408e Li Xu             2017-08-18  2563  
552206add94dd7 Maciej Strozek    2023-11-17  2564  	dev_info(cs43130->dev,
8f1e5bf9b4408e Li Xu             2017-08-18  2565  		 "Cirrus Logic CS43130 (%x), Revision: %02X\n", devid,
8f1e5bf9b4408e Li Xu             2017-08-18  2566  		 reg & 0xFF);
8f1e5bf9b4408e Li Xu             2017-08-18  2567  
8f1e5bf9b4408e Li Xu             2017-08-18  2568  	mutex_init(&cs43130->clk_mutex);
8f1e5bf9b4408e Li Xu             2017-08-18  2569  
8f1e5bf9b4408e Li Xu             2017-08-18  2570  	init_completion(&cs43130->xtal_rdy);
8f1e5bf9b4408e Li Xu             2017-08-18  2571  	init_completion(&cs43130->pll_rdy);
8f1e5bf9b4408e Li Xu             2017-08-18  2572  	init_completion(&cs43130->hpload_evt);
8f1e5bf9b4408e Li Xu             2017-08-18  2573  
fa91703dc2e010 Maciej Strozek    2023-11-23  2574  	if (!client->irq) {
fa91703dc2e010 Maciej Strozek    2023-11-23  2575  		dev_dbg(cs43130->dev, "IRQ not found, will poll instead\n");
fa91703dc2e010 Maciej Strozek    2023-11-23  2576  		cs43130->has_irq_line = 0;
fa91703dc2e010 Maciej Strozek    2023-11-23  2577  	} else {
552206add94dd7 Maciej Strozek    2023-11-17  2578  		ret = devm_request_threaded_irq(cs43130->dev, client->irq,
8f1e5bf9b4408e Li Xu             2017-08-18  2579  						NULL, cs43130_irq_thread,
8f1e5bf9b4408e Li Xu             2017-08-18  2580  						IRQF_ONESHOT | IRQF_TRIGGER_LOW,
8f1e5bf9b4408e Li Xu             2017-08-18  2581  						"cs43130", cs43130);
8f1e5bf9b4408e Li Xu             2017-08-18  2582  		if (ret != 0) {
552206add94dd7 Maciej Strozek    2023-11-17  2583  			dev_err(cs43130->dev, "Failed to request IRQ: %d\n", ret);
e2bb1077cee4d1 Charles Keepax    2021-05-10  2584  			goto err;
8f1e5bf9b4408e Li Xu             2017-08-18  2585  		}
fa91703dc2e010 Maciej Strozek    2023-11-23  2586  		cs43130->has_irq_line = 1;
fa91703dc2e010 Maciej Strozek    2023-11-23  2587  	}
8f1e5bf9b4408e Li Xu             2017-08-18  2588  
8f1e5bf9b4408e Li Xu             2017-08-18  2589  	cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO;
8f1e5bf9b4408e Li Xu             2017-08-18  2590  
552206add94dd7 Maciej Strozek    2023-11-17  2591  	pm_runtime_set_autosuspend_delay(cs43130->dev, 100);
552206add94dd7 Maciej Strozek    2023-11-17  2592  	pm_runtime_use_autosuspend(cs43130->dev);
552206add94dd7 Maciej Strozek    2023-11-17  2593  	pm_runtime_set_active(cs43130->dev);
552206add94dd7 Maciej Strozek    2023-11-17  2594  	pm_runtime_enable(cs43130->dev);
8f1e5bf9b4408e Li Xu             2017-08-18  2595  
8f1e5bf9b4408e Li Xu             2017-08-18  2596  	switch (cs43130->dev_id) {
8f1e5bf9b4408e Li Xu             2017-08-18  2597  	case CS43130_CHIP_ID:
8f1e5bf9b4408e Li Xu             2017-08-18  2598  	case CS43131_CHIP_ID:
8f1e5bf9b4408e Li Xu             2017-08-18  2599  		memcpy(all_hp_widgets, digital_hp_widgets,
8f1e5bf9b4408e Li Xu             2017-08-18  2600  		       sizeof(digital_hp_widgets));
8f1e5bf9b4408e Li Xu             2017-08-18  2601  		memcpy(all_hp_widgets + ARRAY_SIZE(digital_hp_widgets),
8f1e5bf9b4408e Li Xu             2017-08-18  2602  		       analog_hp_widgets, sizeof(analog_hp_widgets));
8f1e5bf9b4408e Li Xu             2017-08-18  2603  		memcpy(all_hp_routes, digital_hp_routes,
8f1e5bf9b4408e Li Xu             2017-08-18  2604  		       sizeof(digital_hp_routes));
8f1e5bf9b4408e Li Xu             2017-08-18  2605  		memcpy(all_hp_routes + ARRAY_SIZE(digital_hp_routes),
8f1e5bf9b4408e Li Xu             2017-08-18  2606  		       analog_hp_routes, sizeof(analog_hp_routes));
8f1e5bf9b4408e Li Xu             2017-08-18  2607  
97b566066ffc2f Kuninori Morimoto 2018-01-29 @2608  		soc_component_dev_cs43130.dapm_widgets =
8f1e5bf9b4408e Li Xu             2017-08-18  2609  			all_hp_widgets;
97b566066ffc2f Kuninori Morimoto 2018-01-29 @2610  		soc_component_dev_cs43130.num_dapm_widgets =
8f1e5bf9b4408e Li Xu             2017-08-18  2611  			ARRAY_SIZE(all_hp_widgets);
97b566066ffc2f Kuninori Morimoto 2018-01-29 @2612  		soc_component_dev_cs43130.dapm_routes =
8f1e5bf9b4408e Li Xu             2017-08-18  2613  			all_hp_routes;
97b566066ffc2f Kuninori Morimoto 2018-01-29 @2614  		soc_component_dev_cs43130.num_dapm_routes =
8f1e5bf9b4408e Li Xu             2017-08-18  2615  			ARRAY_SIZE(all_hp_routes);
8f1e5bf9b4408e Li Xu             2017-08-18  2616  		break;
8f1e5bf9b4408e Li Xu             2017-08-18  2617  	case CS43198_CHIP_ID:
8f1e5bf9b4408e Li Xu             2017-08-18  2618  	case CS4399_CHIP_ID:
97b566066ffc2f Kuninori Morimoto 2018-01-29  2619  		soc_component_dev_cs43130.dapm_widgets =
8f1e5bf9b4408e Li Xu             2017-08-18  2620  			digital_hp_widgets;
97b566066ffc2f Kuninori Morimoto 2018-01-29  2621  		soc_component_dev_cs43130.num_dapm_widgets =
8f1e5bf9b4408e Li Xu             2017-08-18  2622  			ARRAY_SIZE(digital_hp_widgets);
97b566066ffc2f Kuninori Morimoto 2018-01-29  2623  		soc_component_dev_cs43130.dapm_routes =
8f1e5bf9b4408e Li Xu             2017-08-18  2624  			digital_hp_routes;
97b566066ffc2f Kuninori Morimoto 2018-01-29  2625  		soc_component_dev_cs43130.num_dapm_routes =
8f1e5bf9b4408e Li Xu             2017-08-18  2626  			ARRAY_SIZE(digital_hp_routes);
574ff444b9fcc2 Li Xu             2017-09-05  2627  		break;
8f1e5bf9b4408e Li Xu             2017-08-18  2628  	}
8f1e5bf9b4408e Li Xu             2017-08-18  2629  
552206add94dd7 Maciej Strozek    2023-11-17  2630  	ret = devm_snd_soc_register_component(cs43130->dev,
97b566066ffc2f Kuninori Morimoto 2018-01-29  2631  				     &soc_component_dev_cs43130,
8f1e5bf9b4408e Li Xu             2017-08-18  2632  				     cs43130_dai, ARRAY_SIZE(cs43130_dai));
8f1e5bf9b4408e Li Xu             2017-08-18  2633  	if (ret < 0) {
552206add94dd7 Maciej Strozek    2023-11-17  2634  		dev_err(cs43130->dev,
97b566066ffc2f Kuninori Morimoto 2018-01-29  2635  			"snd_soc_register_component failed with ret = %d\n", ret);
8f1e5bf9b4408e Li Xu             2017-08-18  2636  		goto err;
8f1e5bf9b4408e Li Xu             2017-08-18  2637  	}
8f1e5bf9b4408e Li Xu             2017-08-18  2638  
8f1e5bf9b4408e Li Xu             2017-08-18  2639  	regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
8f1e5bf9b4408e Li Xu             2017-08-18  2640  			   CS43130_ASP_3ST_MASK, 0);
8f1e5bf9b4408e Li Xu             2017-08-18  2641  	regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
8f1e5bf9b4408e Li Xu             2017-08-18  2642  			   CS43130_XSP_3ST_MASK, 0);
8f1e5bf9b4408e Li Xu             2017-08-18  2643  
8f1e5bf9b4408e Li Xu             2017-08-18  2644  	return 0;
e2bb1077cee4d1 Charles Keepax    2021-05-10  2645  
8f1e5bf9b4408e Li Xu             2017-08-18  2646  err:
e2bb1077cee4d1 Charles Keepax    2021-05-10  2647  	gpiod_set_value_cansleep(cs43130->reset_gpio, 0);
e2bb1077cee4d1 Charles Keepax    2021-05-10  2648  err_supplies:
e2bb1077cee4d1 Charles Keepax    2021-05-10  2649  	regulator_bulk_disable(ARRAY_SIZE(cs43130->supplies),
e2bb1077cee4d1 Charles Keepax    2021-05-10  2650  			       cs43130->supplies);
e2bb1077cee4d1 Charles Keepax    2021-05-10  2651  
8f1e5bf9b4408e Li Xu             2017-08-18  2652  	return ret;
8f1e5bf9b4408e Li Xu             2017-08-18  2653  }
8f1e5bf9b4408e Li Xu             2017-08-18  2654
diff mbox series

Patch

diff --git a/sound/soc/au1x/dbdma2.c b/sound/soc/au1x/dbdma2.c
index ea01d6490cec..3392693faeb9 100644
--- a/sound/soc/au1x/dbdma2.c
+++ b/sound/soc/au1x/dbdma2.c
@@ -311,7 +311,7 @@  static int au1xpsc_pcm_new(struct snd_soc_component *component,
 }
 
 /* au1xpsc audio platform */
-static struct snd_soc_component_driver au1xpsc_soc_component = {
+static const struct snd_soc_component_driver au1xpsc_soc_component = {
 	.name		= DRV_NAME,
 	.open		= au1xpsc_pcm_open,
 	.close		= au1xpsc_pcm_close,
diff --git a/sound/soc/au1x/dma.c b/sound/soc/au1x/dma.c
index d2fdebd8881b..c9c2b1e71d55 100644
--- a/sound/soc/au1x/dma.c
+++ b/sound/soc/au1x/dma.c
@@ -289,7 +289,7 @@  static int alchemy_pcm_new(struct snd_soc_component *component,
 	return 0;
 }
 
-static struct snd_soc_component_driver alchemy_pcm_soc_component = {
+static const struct snd_soc_component_driver alchemy_pcm_soc_component = {
 	.name		= DRV_NAME,
 	.open		= alchemy_pcm_open,
 	.close		= alchemy_pcm_close,
diff --git a/sound/soc/bcm/cygnus-pcm.c b/sound/soc/bcm/cygnus-pcm.c
index 2d1e241d8367..4cb2fe10bcdc 100644
--- a/sound/soc/bcm/cygnus-pcm.c
+++ b/sound/soc/bcm/cygnus-pcm.c
@@ -707,7 +707,7 @@  static int cygnus_dma_new(struct snd_soc_component *component,
 	return 0;
 }
 
-static struct snd_soc_component_driver cygnus_soc_platform = {
+static const struct snd_soc_component_driver cygnus_soc_platform = {
 	.open		= cygnus_pcm_open,
 	.close		= cygnus_pcm_close,
 	.prepare	= cygnus_pcm_prepare,
diff --git a/sound/soc/codecs/cpcap.c b/sound/soc/codecs/cpcap.c
index 4f9dabd9d78a..04304a7ad915 100644
--- a/sound/soc/codecs/cpcap.c
+++ b/sound/soc/codecs/cpcap.c
@@ -1649,7 +1649,7 @@  static int cpcap_soc_probe(struct snd_soc_component *component)
 	return cpcap_audio_reset(component, false);
 }
 
-static struct snd_soc_component_driver soc_codec_dev_cpcap = {
+static const struct snd_soc_component_driver soc_codec_dev_cpcap = {
 	.probe			= cpcap_soc_probe,
 	.controls		= cpcap_snd_controls,
 	.num_controls		= ARRAY_SIZE(cpcap_snd_controls),
diff --git a/sound/soc/codecs/cs43130.c b/sound/soc/codecs/cs43130.c
index be4037890fdb..90909f452ba5 100644
--- a/sound/soc/codecs/cs43130.c
+++ b/sound/soc/codecs/cs43130.c
@@ -2398,7 +2398,7 @@  static int cs43130_probe(struct snd_soc_component *component)
 	return 0;
 }
 
-static struct snd_soc_component_driver soc_component_dev_cs43130 = {
+static const struct snd_soc_component_driver soc_component_dev_cs43130 = {
 	.probe			= cs43130_probe,
 	.controls		= cs43130_snd_controls,
 	.num_controls		= ARRAY_SIZE(cs43130_snd_controls),
diff --git a/sound/soc/codecs/pcm186x.c b/sound/soc/codecs/pcm186x.c
index 451a8fd8fac5..13443f569ddb 100644
--- a/sound/soc/codecs/pcm186x.c
+++ b/sound/soc/codecs/pcm186x.c
@@ -566,7 +566,7 @@  static int pcm186x_set_bias_level(struct snd_soc_component *component,
 	return 0;
 }
 
-static struct snd_soc_component_driver soc_codec_dev_pcm1863 = {
+static const struct snd_soc_component_driver soc_codec_dev_pcm1863 = {
 	.set_bias_level		= pcm186x_set_bias_level,
 	.controls		= pcm1863_snd_controls,
 	.num_controls		= ARRAY_SIZE(pcm1863_snd_controls),
@@ -579,7 +579,7 @@  static struct snd_soc_component_driver soc_codec_dev_pcm1863 = {
 	.endianness		= 1,
 };
 
-static struct snd_soc_component_driver soc_codec_dev_pcm1865 = {
+static const struct snd_soc_component_driver soc_codec_dev_pcm1865 = {
 	.set_bias_level		= pcm186x_set_bias_level,
 	.controls		= pcm1865_snd_controls,
 	.num_controls		= ARRAY_SIZE(pcm1865_snd_controls),
diff --git a/sound/soc/codecs/pcm5102a.c b/sound/soc/codecs/pcm5102a.c
index 3401a25341e6..9bca53de2475 100644
--- a/sound/soc/codecs/pcm5102a.c
+++ b/sound/soc/codecs/pcm5102a.c
@@ -24,7 +24,7 @@  static struct snd_soc_dai_driver pcm5102a_dai = {
 	},
 };
 
-static struct snd_soc_component_driver soc_component_dev_pcm5102a = {
+static const struct snd_soc_component_driver soc_component_dev_pcm5102a = {
 	.idle_bias_on		= 1,
 	.use_pmdown_time	= 1,
 	.endianness		= 1,
diff --git a/sound/soc/codecs/spdif_receiver.c b/sound/soc/codecs/spdif_receiver.c
index 862e0b654a1c..7043aa9a206e 100644
--- a/sound/soc/codecs/spdif_receiver.c
+++ b/sound/soc/codecs/spdif_receiver.c
@@ -35,7 +35,7 @@  static const struct snd_soc_dapm_route dir_routes[] = {
 			SNDRV_PCM_FMTBIT_S32_LE | \
 			SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE)
 
-static struct snd_soc_component_driver soc_codec_spdif_dir = {
+static const struct snd_soc_component_driver soc_codec_spdif_dir = {
 	.dapm_widgets		= dir_widgets,
 	.num_dapm_widgets	= ARRAY_SIZE(dir_widgets),
 	.dapm_routes		= dir_routes,
diff --git a/sound/soc/codecs/spdif_transmitter.c b/sound/soc/codecs/spdif_transmitter.c
index 736518921555..d997862767ec 100644
--- a/sound/soc/codecs/spdif_transmitter.c
+++ b/sound/soc/codecs/spdif_transmitter.c
@@ -35,7 +35,7 @@  static const struct snd_soc_dapm_route dit_routes[] = {
 	{ "spdif-out", NULL, "Playback" },
 };
 
-static struct snd_soc_component_driver soc_codec_spdif_dit = {
+static const struct snd_soc_component_driver soc_codec_spdif_dit = {
 	.dapm_widgets		= dit_widgets,
 	.num_dapm_widgets	= ARRAY_SIZE(dit_widgets),
 	.dapm_routes		= dit_routes,
diff --git a/sound/soc/codecs/sti-sas.c b/sound/soc/codecs/sti-sas.c
index c421906a0694..3a1cdb329f31 100644
--- a/sound/soc/codecs/sti-sas.c
+++ b/sound/soc/codecs/sti-sas.c
@@ -386,7 +386,7 @@  static int sti_sas_component_probe(struct snd_soc_component *component)
 	return sti_sas_init_sas_registers(component, drvdata);
 }
 
-static struct snd_soc_component_driver sti_sas_driver = {
+static const struct snd_soc_component_driver sti_sas_driver = {
 	.probe			= sti_sas_component_probe,
 	.resume			= sti_sas_resume,
 	.idle_bias_on		= 1,
diff --git a/sound/soc/codecs/tas6424.c b/sound/soc/codecs/tas6424.c
index bb0500e9d3ea..9be054837f68 100644
--- a/sound/soc/codecs/tas6424.c
+++ b/sound/soc/codecs/tas6424.c
@@ -364,7 +364,7 @@  static int tas6424_set_bias_level(struct snd_soc_component *component,
 	return 0;
 }
 
-static struct snd_soc_component_driver soc_codec_dev_tas6424 = {
+static const struct snd_soc_component_driver soc_codec_dev_tas6424 = {
 	.set_bias_level		= tas6424_set_bias_level,
 	.controls		= tas6424_snd_controls,
 	.num_controls		= ARRAY_SIZE(tas6424_snd_controls),
diff --git a/sound/soc/stm/stm32_adfsdm.c b/sound/soc/stm/stm32_adfsdm.c
index fb5dd9a68bea..b35c28b70265 100644
--- a/sound/soc/stm/stm32_adfsdm.c
+++ b/sound/soc/stm/stm32_adfsdm.c
@@ -309,7 +309,7 @@  static void stm32_adfsdm_cleanup(void *data)
 	iio_channel_release_all_cb(data);
 }
 
-static struct snd_soc_component_driver stm32_adfsdm_soc_platform = {
+static const struct snd_soc_component_driver stm32_adfsdm_soc_platform = {
 	.open		= stm32_adfsdm_pcm_open,
 	.close		= stm32_adfsdm_pcm_close,
 	.hw_params	= stm32_adfsdm_pcm_hw_params,
diff --git a/sound/soc/uniphier/evea.c b/sound/soc/uniphier/evea.c
index d90b3e4b0104..a4cf14462374 100644
--- a/sound/soc/uniphier/evea.c
+++ b/sound/soc/uniphier/evea.c
@@ -384,7 +384,7 @@  static int evea_codec_resume(struct snd_soc_component *component)
 	return ret;
 }
 
-static struct snd_soc_component_driver soc_codec_evea = {
+static const struct snd_soc_component_driver soc_codec_evea = {
 	.probe			= evea_codec_probe,
 	.suspend		= evea_codec_suspend,
 	.resume			= evea_codec_resume,