[alsa-devel] [PATCH 2/7] ASoC: amd: Registering device endpoints using MFD framework

vishnu vravulap at amd.com
Tue Oct 1 12:00:45 CEST 2019


Hi Jones,

I am very Thankful to your review comments.

Actually The driver is not totally based on MFD. It just uses 
mfd_add_hotplug_devices() and mfd_remove_devices() for adding the 
devices automatically.

Remaining code has nothing to do with MFD framework.

So I thought It would not break the coding style and moved ahead by 
using the MFD API by adding its header file.

If it is any violation of coding standard then I can move it to 
drivers/mfd.

This patch could be a show stopper for us.Please suggest us how can we 
move ahead ASAP.

Thank you once again for your inputs.

Regards,
Vishnu

On 01/10/19 12:15 PM, Lee Jones wrote:
> On Tue, 01 Oct 2019, Ravulapati Vishnu vardhan rao wrote:
> 
>> Removed platform based endpoint registering in ACP-PCI driver.
>> Now Registering PCM DMA and multiple I2S instances: SP and  BT endpoint
>> devices automatically by using MFD framework.
> 
> This is a hack.
> 
> Why are you using the MFD framework outside of drivers/mfd?
> 
> If this driver is an MFD, then please create an MFD driver.
> 
> If it's not, please do not use the MFD API.
> 
>> Signed-off-by: Ravulapati Vishnu vardhan rao <Vishnuvardhanrao.Ravulapati at amd.com>
>> ---
>>   sound/soc/amd/raven/acp3x.h     |   8 +++
>>   sound/soc/amd/raven/pci-acp3x.c | 123 ++++++++++++++++++++++++++--------------
>>   2 files changed, 90 insertions(+), 41 deletions(-)
>>
>> diff --git a/sound/soc/amd/raven/acp3x.h b/sound/soc/amd/raven/acp3x.h
>> index 4f2cadd..c122dc6 100644
>> --- a/sound/soc/amd/raven/acp3x.h
>> +++ b/sound/soc/amd/raven/acp3x.h
>> @@ -7,13 +7,21 @@
>>   
>>   #include "chip_offset_byte.h"
>>   
>> +#define ACP3x_DEVS		3
>>   #define ACP3x_PHY_BASE_ADDRESS 0x1240000
>>   #define	ACP3x_I2S_MODE	0
>>   #define	ACP3x_REG_START	0x1240000
>>   #define	ACP3x_REG_END	0x1250200
>> +#define ACP3x_I2STDM_REG_START	0x1242400
>> +#define ACP3x_I2STDM_REG_END	0x1242410
>> +#define ACP3x_BT_TDM_REG_START	0x1242800
>> +#define ACP3x_BT_TDM_REG_END	0x1242810
>>   #define I2S_MODE	0x04
>> +#define	I2S_RX_THRESHOLD	27
>> +#define	I2S_TX_THRESHOLD	28
>>   #define	BT_TX_THRESHOLD 26
>>   #define	BT_RX_THRESHOLD 25
>> +#define ACP_ERR_INTR_MASK	29
>>   #define ACP3x_POWER_ON 0x00
>>   #define ACP3x_POWER_ON_IN_PROGRESS 0x01
>>   #define ACP3x_POWER_OFF 0x02
>> diff --git a/sound/soc/amd/raven/pci-acp3x.c b/sound/soc/amd/raven/pci-acp3x.c
>> index 8f6bf00..d9f5bc0 100644
>> --- a/sound/soc/amd/raven/pci-acp3x.c
>> +++ b/sound/soc/amd/raven/pci-acp3x.c
>> @@ -9,13 +9,21 @@
>>   #include <linux/io.h>
>>   #include <linux/platform_device.h>
>>   #include <linux/interrupt.h>
>> +#include <linux/mfd/core.h>
>>   
>>   #include "acp3x.h"
>>   
>> +struct i2s_platform_data {
>> +	unsigned int cap;
>> +	int channel;
>> +	u32 snd_rates;
>> +};
>>   struct acp3x_dev_data {
>> +	struct device *parent;
>> +	struct mfd_cell *cell;
>> +	struct resource *res;
>>   	void __iomem *acp3x_base;
>>   	bool acp3x_audio_mode;
>> -	struct resource *res;
>>   	struct platform_device *pdev;
>>   };
>>   
>> @@ -23,9 +31,11 @@ static int snd_acp3x_probe(struct pci_dev *pci,
>>   			   const struct pci_device_id *pci_id)
>>   {
>>   	int ret;
>> -	u32 addr, val;
>> +	resource_size_t addr;
>> +	int val, i, r;
>>   	struct acp3x_dev_data *adata;
>> -	struct platform_device_info pdevinfo;
>> +	struct device *dev;
>> +	struct i2s_platform_data *i2s_pdata;
>>   	unsigned int irqflags;
>>   
>>   	if (pci_enable_device(pci)) {
>> @@ -56,55 +66,87 @@ static int snd_acp3x_probe(struct pci_dev *pci,
>>   	}
>>   	pci_set_master(pci);
>>   	pci_set_drvdata(pci, adata);
>> -
>> +	adata->parent = &pci->dev;
>>   	val = rv_readl(adata->acp3x_base + mmACP_I2S_PIN_CONFIG);
>>   	switch (val) {
>>   	case I2S_MODE:
>>   		adata->res = devm_kzalloc(&pci->dev,
>> -					  sizeof(struct resource) * 2,
>> -					  GFP_KERNEL);
>> -		if (!adata->res) {
>> +				sizeof(struct resource) * 4,
>> +						GFP_KERNEL);
>> +		adata->cell = devm_kzalloc(&pci->dev,
>> +				sizeof(struct mfd_cell) * ACP3x_DEVS,
>> +						GFP_KERNEL);
>> +		if (!adata->cell) {
>>   			ret = -ENOMEM;
>>   			goto unmap_mmio;
>>   		}
>>   
>> -		adata->res[0].name = "acp3x_i2s_iomem";
>> -		adata->res[0].flags = IORESOURCE_MEM;
>> -		adata->res[0].start = addr;
>> -		adata->res[0].end = addr + (ACP3x_REG_END - ACP3x_REG_START);
>> -
>> -		adata->res[1].name = "acp3x_i2s_irq";
>> -		adata->res[1].flags = IORESOURCE_IRQ;
>> -		adata->res[1].start = pci->irq;
>> -		adata->res[1].end = pci->irq;
>> -
>> -		adata->acp3x_audio_mode = ACP3x_I2S_MODE;
>> -
>> -		memset(&pdevinfo, 0, sizeof(pdevinfo));
>> -		pdevinfo.name = "acp3x_rv_i2s";
>> -		pdevinfo.id = 0;
>> -		pdevinfo.parent = &pci->dev;
>> -		pdevinfo.num_res = 2;
>> -		pdevinfo.res = adata->res;
>> -		pdevinfo.data = &irqflags;
>> -		pdevinfo.size_data = sizeof(irqflags);
>> -
>> -		adata->pdev = platform_device_register_full(&pdevinfo);
>> -		if (IS_ERR(adata->pdev)) {
>> -			dev_err(&pci->dev, "cannot register %s device\n",
>> -				pdevinfo.name);
>> -			ret = PTR_ERR(adata->pdev);
>> -			goto unmap_mmio;
>> +		i2s_pdata = devm_kzalloc(&pci->dev,
>> +				sizeof(struct i2s_platform_data) * ACP3x_DEVS,
>> +						GFP_KERNEL);
>> +		if (i2s_pdata == NULL) {
>> +			kfree(adata->res);
>> +			kfree(adata->cell);
>> +			return -ENOMEM;
>>   		}
>> +		adata->res[0].name	= "acp3x_i2s_iomem";
>> +		adata->res[0].flags	= IORESOURCE_MEM;
>> +		adata->res[0].start	= addr;
>> +		adata->res[0].end	= addr +
>> +			(ACP3x_REG_END - ACP3x_REG_START);
>> +		i2s_pdata[0].cap	= 0;
>> +		i2s_pdata[0].snd_rates	= SNDRV_PCM_RATE_8000_96000;
>> +
>> +		adata->res[1].name	= "acp3x_i2s_sp_play_cap";
>> +		adata->res[1].flags	= IORESOURCE_MEM;
>> +		adata->res[1].start	= addr + ACP3x_I2STDM_REG_START;
>> +		adata->res[1].end	= addr + ACP3x_I2STDM_REG_END;
>> +		i2s_pdata[1].cap	= 0;
>> +		i2s_pdata[1].snd_rates	= SNDRV_PCM_RATE_8000_96000;
>> +
>> +		adata->res[2].name	= "acp3x_i2s_bt_play_cap";
>> +		adata->res[2].flags	= IORESOURCE_MEM;
>> +		adata->res[2].start	= addr + ACP3x_BT_TDM_REG_START;
>> +		adata->res[2].end	= addr + ACP3x_BT_TDM_REG_END;
>> +		i2s_pdata[2].cap	= 0;
>> +		i2s_pdata[2].snd_rates	= SNDRV_PCM_RATE_8000_96000;
>> +
>> +		adata->res[3].name	= "acp3x_i2s_irq";
>> +		adata->res[3].flags	= IORESOURCE_IRQ;
>> +		adata->res[3].start	= pci->irq;
>> +		adata->res[3].end	= adata->res[3].start;
>> +
>> +		adata->acp3x_audio_mode	= ACP3x_I2S_MODE;
>> +
>> +		adata->cell[0].name	=	"acp3x_rv_i2s_dma";
>> +		adata->cell[0].num_resources	= 4;
>> +		adata->cell[0].resources	= &adata->res[0];
>> +		adata->cell[0].platform_data	= &irqflags;
>> +		adata->cell[0].pdata_size	= sizeof(irqflags);
>> +
>> +		adata->cell[1].name		= "acp3x_i2s_playcap";
>> +		adata->cell[1].num_resources	= 1;
>> +		adata->cell[1].resources	= &adata->res[1];
>> +		adata->cell[1].platform_data	= &i2s_pdata[0];
>> +		adata->cell[1].pdata_size	=
>> +				sizeof(struct i2s_platform_data);
>> +
>> +		adata->cell[2].name		= "acp3x_i2s_playcap";
>> +		adata->cell[2].num_resources	= 1;
>> +		adata->cell[2].resources	= &adata->res[2];
>> +		adata->cell[2].platform_data	= &i2s_pdata[1];
>> +		adata->cell[2].pdata_size	=
>> +				sizeof(struct i2s_platform_data);
>> +		r = mfd_add_hotplug_devices(adata->parent,
>> +					adata->cell, ACP3x_DEVS);
>>   		break;
>> -	default:
>> -		dev_err(&pci->dev, "Invalid ACP audio mode : %d\n", val);
>> -		ret = -ENODEV;
>> -		goto unmap_mmio;
>>   	}
>>   	return 0;
>>   
>>   unmap_mmio:
>> +	mfd_remove_devices(adata->parent);
>> +	kfree(adata->res);
>> +	kfree(adata->cell);
>>   	iounmap(adata->acp3x_base);
>>   release_regions:
>>   	pci_release_regions(pci);
>> @@ -117,10 +159,8 @@ static int snd_acp3x_probe(struct pci_dev *pci,
>>   static void snd_acp3x_remove(struct pci_dev *pci)
>>   {
>>   	struct acp3x_dev_data *adata = pci_get_drvdata(pci);
>> -
>> -	platform_device_unregister(adata->pdev);
>> +	mfd_remove_devices(adata->parent);
>>   	iounmap(adata->acp3x_base);
>> -
>>   	pci_release_regions(pci);
>>   	pci_disable_device(pci);
>>   }
>> @@ -142,6 +182,7 @@ static struct pci_driver acp3x_driver  = {
>>   
>>   module_pci_driver(acp3x_driver);
>>   
>> +MODULE_AUTHOR("Vishnuvardhanrao.Ravulapati at amd.com");
>>   MODULE_AUTHOR("Maruthi.Bayyavarapu at amd.com");
>>   MODULE_DESCRIPTION("AMD ACP3x PCI driver");
>>   MODULE_LICENSE("GPL v2");
> 


More information about the Alsa-devel mailing list