Skip to contentSkip to conversation

ASoC: Make register_card API available to drivers

PATCH In review Koul, Vinod 2 participants 9 messages Jan 13, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: Make register_card API available to drivers

From: Vinod Koul <[email protected]>

The register_card is an internal API which soc_probe uses to register the card. In order to create multiple cards we need to create multiple instances of soc-audio device. If we exposes the register card API for drivers to use, then machine driver can register their cards directly

This patch makes register_card and unregister_card API available to machine drivers. This also maintains compatibility with older method of registration which can be marked depreciated and removed eventually.

---
 include/sound/soc.h  |    2 +
 sound/soc/soc-core.c |   90 +++++++++++++++++++++++++++----------------------
 2 files changed, 52 insertions(+), 40 deletions(-)
include/sound/soc.h +2 -0
index d609232..b515eb6 100644
@@ -258,6 +258,8 @@ enum snd_soc_compress_type {
 	SND_SOC_RBTREE_COMPRESSION
 };
 
+int snd_soc_register_card(struct snd_soc_card *card);
+int snd_soc_unregister_card(struct snd_soc_card *card);
 int snd_soc_register_platform(struct device *dev,
 		struct snd_soc_platform_driver *platform_drv);
 void snd_soc_unregister_platform(struct device *dev);
sound/soc/soc-core.c +50 -40

153 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#1 lore raw
Quoted 8 lines · Vinod

The register_card is an internal API which soc_probe uses to register the card. In order to create multiple cards we need to create multiple instances of soc-audio device. If we exposes the register card API for drivers to use, then machine driver can register their cards directly

This patch makes register_card and unregister_card API available to machine drivers. This also maintains compatibility with older method of registration which can be marked depreciated and removed eventually.

This is probably mostly OK but it'd be good if you could break it down into a small patch series. At present it does a bunch of refactoring and also adds the API - it'd be better if there were a sequence of patches, each doing a single refactor, followed by a final patch which exports the API.

Splitting it up like this will allow bisection if there's a problem introduced by the change and makes review very much easier as there's only one change to think about in a given patch.

sound/soc/soc-core.c static int soc_probe(struct platform_device *pdev) · line 1874

Quoted 8 lines
sound/soc/soc-core.c +4 -0
@@ -1870,16 +1868,12 @@ static int soc_probe(struct platform_device *pdev)
 	struct snd_soc_card *card = platform_get_drvdata(pdev);
 	int ret = 0;
 
+	/* no card, so machine driver will register explictly */
+	if (!card)
+		return 0;
+

Hrm, this looks a bit surprising. When we're registering directly from the machine drivers I'd not expect us to end up going through soc-probe at all and...

sound/soc/soc-core.c static int soc_probe(struct platform_device *pdev) · line 1876

Quoted 2 lines
sound/soc/soc-core.c +0 -0
 	/* Bodge while we unpick instantiation */
 	card->dev = &pdev->dev;

...that the card device would be something passed in from the machine driver (probably something that the architecture code registered in order to allow the machine driver to probe, but possibly something else).

#2 lore raw
Quoted 9 lines
Quoted 3 lines

This patch makes register_card and unregister_card API available to machine drivers. This also maintains compatibility with older method of registration which can be marked depreciated and removed eventually.

This is probably mostly OK but it'd be good if you could break it down into a small patch series. At present it does a bunch of refactoring and also adds the API - it'd be better if there were a sequence of patches, each doing a single refactor, followed by a final patch which exports the API.

Sure will do that...

Quoted 13 lines

sound/soc/soc-core.c static int soc_probe(struct platform_device *pdev) · line 1874

Quoted 8 lines
sound/soc/soc-core.c +4 -0
@@ -1870,16 +1868,12 @@ static int soc_probe(struct platform_device *pdev)
 	struct snd_soc_card *card = platform_get_drvdata(pdev);
 	int ret = 0;
 
+	/* no card, so machine driver will register explictly */
+	if (!card)
+		return 0;
+

Hrm, this looks a bit surprising. When we're registering directly from the machine drivers I'd not expect us to end up going through soc-probe at all and...

Quoted 7 lines

sound/soc/soc-core.c static int soc_probe(struct platform_device *pdev) · line 1876

Quoted 2 lines
sound/soc/soc-core.c +0 -0
 	/* Bodge while we unpick instantiation */
 	card->dev = &pdev->dev;

...that the card device would be something passed in from the machine driver (probably something that the architecture code registered in order to allow the machine driver to probe, but possibly something else).

Yes on both of these, but I didn't want to break current method. So I kept these to ensure both methods work fine.

One we have converted all driver to use register then we can remove these. Would have made sense to put a comment for that

~Vinod

#3 lore raw
Quoted 5 lines · Vinod

Yes on both of these, but I didn't want to break current method. So I kept these to ensure both methods work fine.

One we have converted all driver to use register then we can remove these. Would have made sense to put a comment for that

My plan for this when I originally wrote the comment had been to make the contents of the soc-audio device probe and removal look exactly like what you'd write directly in a machine driver so no code except for the code doing the soc-audio device had any idea it was there. This would keep backwards compatiblity without special casing, making things more maintainable.

#4 lore raw
Quoted 6 lines
Quoted 5 lines

Yes on both of these, but I didn't want to break current method. So I kept these to ensure both methods work fine.

One we have converted all driver to use register then we can remove these. Would have made sense to put a comment for that

Quoted 6 lines

My plan for this when I originally wrote the comment had been to make the contents of the soc-audio device probe and removal look exactly like what you'd write directly in a machine driver so no code except for the code doing the soc-audio device had any idea it was there. This would keep backwards compatiblity without special casing, making things more maintainable.

Hmmmm, I didn't want to change the current machine drivers yet, hence tried to move the code of soc_probe into card_register.
So that works neatly (doesn't matter who is doing, machine or core) Only thing which I kept is to check for card pointer and if valid then call register (assuming someone is still using old method) which we should mark deprecated

Quoted 1 line

card->dev = &pdev->dev;

This would be required only for current method hence kept it there. For anyone who uses register, the machine should set this up properly

And I agree that these things should be done by machine. But wanted to split the change to avoid any issues

So what I propose is keep it as is, I will resend the split patch series, and then after machine drivers are changed we remove these.

Btw this make me wonder what will soc_probe be used (it is not doing anything) Do we still need this and creating soc-audio device?

~Vinod

#5 lore raw
Quoted 7 lines · Vinod
Quoted 6 lines

My plan for this when I originally wrote the comment had been to make the contents of the soc-audio device probe and removal look exactly like what you'd write directly in a machine driver so no code except for the code doing the soc-audio device had any idea it was there. This would keep backwards compatiblity without special casing, making things more maintainable.

Quoted 6 lines

Hmmmm, I didn't want to change the current machine drivers yet, hence tried to move the code of soc_probe into card_register.
So that works neatly (doesn't matter who is doing, machine or core) Only thing which I kept is to check for card pointer and if valid then call register (assuming someone is still using old method) which we should mark deprecated

The above doesn't require any change in existing machine drivers - they still pass the card data structure into the soc-audio device which then registers with the core. This the whole point, move the soc-audio device over to using an API that can also be used externally then convert the machine drivers to stop using the soc-audio device.

Quoted 2 lines

Btw this make me wonder what will soc_probe be used (it is not doing anything) Do we still need this and creating soc-audio device?

That's the point I'm making above. It shouldn't be involved at all except as part of the soc-audio device code, anything registering a card directly should never call it.

#6 lore raw
Quoted 6 lines

The above doesn't require any change in existing machine drivers - they still pass the card data structure into the soc-audio device which then registers with the core. This the whole point, move the soc-audio device over to using an API that can also be used externally then convert the machine drivers to stop using the soc-audio device.

Quoted 6 lines
Quoted 2 lines

Btw this make me wonder what will soc_probe be used (it is not doing anything) Do we still need this and creating soc-audio device?

That's the point I'm making above. It shouldn't be involved at all except as part of the soc-audio device code, anything registering a card directly should never call it.

Agreed :)
Knowing the context helps...

Above works well for probe, but not sure if that is intention for remove(). Do you expect the machine driver to call codec and platform remove before it unregisters the card.
The code inside:

	if (card->instantiated)

~Vinod

#7 lore raw
Quoted 5 lines · Vinod

Above works well for probe, but not sure if that is intention for remove(). Do you expect the machine driver to call codec and platform remove before it unregisters the card.
The code inside:

	if (card->instantiated)

No, the core code needs to do that as part of removing the card.

#8 lore raw
Quoted 8 lines
Quoted 6 lines

Above works well for probe, but not sure if that is intention for remove(). Do you expect the machine driver to call codec and platform remove before it unregisters the card.
The code inside:

	if (card->instantiated)

No, the core code needs to do that as part of removing the card.

Agreed, sending you're the split patchset, code is almost same

~Vinod