ASoC: fsl: use snd_soc_register_card to register the card
PATCH v2 1/2 ASoC: fsl: use snd_soc_register_card to register the card
Use snd_soc_register_card() instead of platform_device_alloc("soc-audio") to register the sound card from the machine drivers.
Although platform_device_alloc is officially deprecated, it is still used by several other drivers. Unfortunately, something is broken somewhere and the Freescale drivers don't register properly when using it. Since we need to transition to snd_soc_register_card() anyway, this fixes the problem and updates our code at the same time.
--- sound/soc/fsl/mpc8610_hpcd.c | 23 +++++------------------ sound/soc/fsl/p1022_ds.c | 22 ++++------------------ 2 files changed, 9 insertions(+), 36 deletions(-)
sound/soc/fsl/mpc8610_hpcd.c +5 -18
@@ -192,7 +192,6 @@ static int mpc8610_hpcd_probe(struct platform_device *pdev) container_of(dev, struct platform_device, dev);struct device_node *np = ssi_pdev->dev.of_node;struct device_node *codec_np =NULL ; -struct platform_device *sound_device =NULL ;struct mpc8610_hpcd_data *machine_data;int ret = -ENODEV ;const char *sprop;
@@ -341,34 +340,22 @@ static int mpc8610_hpcd_probe(struct platform_device *pdev) machine_data->card.probe = mpc8610_hpcd_machine_probe; machine_data->card.remove = mpc8610_hpcd_machine_remove; machine_data->card.name = pdev->name;/* The platform driver name */ + machine_data->card.owner =THIS_MODULE ; + machine_data->card.dev = &pdev->dev; machine_data->card.num_links =2 ; machine_data->card.dai_link = machine_data->dai; -/* Allocate a new audio platform device structure */ - sound_device =platform_device_alloc ("soc-audio" ,-1 ); -if (!sound_device) { -dev_err (&pdev->dev,"platform device alloc failed\n" ); - ret = -ENOMEM ; - goto error; - } - -/* Associate the card data with the sound device */ -platform_set_drvdata (sound_device, &machine_data->card); -/* Register with ASoC */ - ret =platform_device_add (sound_device); + ret =snd_soc_register_card (&machine_data->card);if (ret) { -dev_err (&pdev->dev,"platform device add failed\n" ); - goto error_sound; +dev_err (&pdev->dev,"could not register card\n" ); + goto error; } -dev_set_drvdata (&pdev->dev, sound_device);of_node_put (codec_np);return 0 ; -error_sound: -platform_device_put (sound_device); error:kfree (machine_data); error_alloc:
sound/soc/fsl/p1022_ds.c +4 -18
@@ -202,7 +202,6 @@ static int p1022_ds_probe(struct platform_device *pdev) container_of(dev, struct platform_device, dev);struct device_node *np = ssi_pdev->dev.of_node;struct device_node *codec_np =NULL ; -struct platform_device *sound_device =NULL ;struct machine_data *mdata;int ret = -ENODEV ;const char *sprop;
@@ -349,36 +348,23 @@ static int p1022_ds_probe(struct platform_device *pdev) mdata->card.probe = p1022_ds_machine_probe; mdata->card.remove = p1022_ds_machine_remove; mdata->card.name = pdev->name;/* The platform driver name */ + mdata->card.owner =THIS_MODULE ; + mdata->card.dev = &pdev->dev; mdata->card.num_links =2 ; mdata->card.dai_link = mdata->dai; -/* Allocate a new audio platform device structure */ - sound_device =platform_device_alloc ("soc-audio" ,-1 ); -if (!sound_device) { -dev_err (&pdev->dev,"platform device alloc failed\n" ); - ret = -ENOMEM ; - goto error; - } - -/* Associate the card data with the sound device */ -platform_set_drvdata (sound_device, &mdata->card); -/* Register with ASoC */ - ret =platform_device_add (sound_device); + ret =snd_soc_register_card (&mdata->card);if (ret) { -dev_err (&pdev->dev,"platform device add failed\n" ); +dev_err (&pdev->dev,"could not register card\n" ); goto error; } -dev_set_drvdata (&pdev->dev, sound_device);of_node_put (codec_np);return 0 ; error: -if (sound_device) -platform_device_put (sound_device); -kfree (mdata); error_put:of_node_put (codec_np);
Signature · 1 line
1.7.3.4
PATCH 2/2 ASoC: fsl: move machine drivers to late_initcall()
Transition the module initialization to late_initcall(), so that the machine driver loads last. Although this is technically not necessary, it does avoid this error message at boot time:
ALSA device list:
No soundcards found.
--- sound/soc/fsl/mpc8610_hpcd.c | 2 +- sound/soc/fsl/p1022_ds.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
sound/soc/fsl/mpc8610_hpcd.c +1 -1
@@ -430,7 +430,7 @@ static void __exit mpc8610_hpcd_exit(void)platform_driver_unregister (&mpc8610_hpcd_driver); } -module_init (mpc8610_hpcd_init); +late_initcall (mpc8610_hpcd_init);module_exit (mpc8610_hpcd_exit);MODULE_AUTHOR ("Timur Tabi <[email protected]>" );
sound/soc/fsl/p1022_ds.c +1 -1
@@ -439,7 +439,7 @@ static void __exit p1022_ds_exit(void)platform_driver_unregister (&p1022_ds_driver); } -module_init (p1022_ds_init); +late_initcall (p1022_ds_init);module_exit (p1022_ds_exit);MODULE_AUTHOR ("Timur Tabi <[email protected]>" );
Signature · 1 line
1.7.3.4
Quoted 10 lines · Timur Tabi
Use
snd_soc_register_card()instead ofplatform_device_alloc("soc-audio")to register the sound card from the machine drivers.Although
platform_device_allocis officially deprecated, it is still used by several other drivers. Unfortunately, something is broken somewhere and the Freescale drivers don't register properly when using it. Since we need to transition tosnd_soc_register_card()anyway, this fixes the problem and updates our code at the same time.Signed-off-by Timur Tabi <[email protected]>
Ugh, I forgot to update the _remove function. I'll post a v3 patch soon.
Sorry.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Quoted 8 lines · Timur Tabi
Use
snd_soc_register_card()instead ofplatform_device_alloc("soc-audio")to register the sound card from the machine drivers.Although
platform_device_allocis officially deprecated, it is still used by several other drivers. Unfortunately, something is broken somewhere and the Freescale drivers don't register properly when using it. Since we need to transition tosnd_soc_register_card()anyway, this fixes the problem and updates our code at the same time.
I did explain what's wrong here - it's the use of driver data.
Quoted 1 line · Mark Brown
I did explain what's wrong here - it's the use of driver data.
Sorry, I didn't think to update the description with your explanation.
Of course, now I need to figure out why my driver doesn't need driver data in order to work.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Quoted 8 lines · Timur Tabi
Quoted 1 line · Mark Brown
I did explain what's wrong here - it's the use of driver data.
Sorry, I didn't think to update the description with your explanation.
Of course, now I need to figure out why my driver doesn't need driver data in order to work.
The driver data is used by the soc-audio driver to get the card. Since your driver now calls snd_soc_register_card() directly it doens't need that.