[alsa-devel] [PATCH v3 08/14] ASoC: SOF: Add DSP HW abstraction operations

Andy Shevchenko andriy.shevchenko at intel.com
Wed Dec 12 00:16:37 CET 2018


On Tue, Dec 11, 2018 at 03:23:12PM -0600, Pierre-Louis Bossart wrote:
> From: Liam Girdwood <liam.r.girdwood at linux.intel.com>
> 
> Add operation pointers that can be called by core to control a wide
> variety of DSP targets. The DSP HW drivers will fill in these
> operations.

> +int snd_sof_pci_update_bits_unlocked(struct snd_sof_dev *sdev, u32 offset,
> +				     u32 mask, u32 value)
> +{
> +	bool change;
> +	unsigned int old, new;
> +	u32 ret = ~0; /* explicit init to remove uninitialized use warnings */
> +
> +	pci_read_config_dword(sdev->pci, offset, &ret);
> +	dev_dbg(sdev->dev, "Debug PCIR: %8.8x at  %8.8x\n",
> +		pci_read_config_dword(sdev->pci, offset, &ret), offset);
> +
> +	old = ret;
> +	new = (old & (~mask)) | (value & mask);
> +

> +	change = (old != new);
> +	if (change) {
> +		pci_write_config_dword(sdev->pci, offset, new);
> +		dev_dbg(sdev->dev, "Debug PCIW: %8.8x at  %8.8x\n", value,
> +			offset);
> +	}
> +
> +	return change;

What about dropping change completely?

if (old == new)
	return false;

...
return true;


> +}
> +EXPORT_SYMBOL(snd_sof_pci_update_bits_unlocked);

> +int snd_sof_dsp_update_bits_unlocked(struct snd_sof_dev *sdev, u32 bar,
> +				     u32 offset, u32 mask, u32 value)
> +{
> +	bool change;
> +	unsigned int old, new;
> +	u32 ret;
> +
> +	ret = snd_sof_dsp_read(sdev, bar, offset);
> +
> +	old = ret;
> +	new = (old & (~mask)) | (value & mask);
> +
> +	change = (old != new);
> +	if (change)
> +		snd_sof_dsp_write(sdev, bar, offset, new);
> +
> +	return change;

Ditto.
Everywhere in similar places.

> +}
> +EXPORT_SYMBOL(snd_sof_dsp_update_bits_unlocked);

> +	/* check if set state successful */
> +	for (time = 5; time > 0; time--) {
> +		if ((snd_sof_dsp_read(sdev, bar, offset) & mask) == target)
> +			break;
> +		msleep(20);
> +	}
> +
> +	if (!time) {
> +		/* sleeping in 10ms steps so adjust timeout value */
> +		timeout /= 10;
> +
> +		for (time = timeout; time > 0; time--) {

> +			if ((snd_sof_dsp_read(sdev, bar, offset) & mask) ==
> +				target)

I would leave it on one line.

> +				break;
> +
> +			usleep_range(5000, 10000);
> +		}
> +	}
> +
> +	ret = time ? 0 : -ETIME;
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL(snd_sof_dsp_register_poll);

> +static inline void snd_sof_dsp_write64(struct snd_sof_dev *sdev, u32 bar,
> +				       u32 offset, u64 value)
> +{
> +	if (sdev->ops->write64)

> +		sdev->ops->write64(sdev,
> +			sdev->bar[bar] + offset, value);

Why not one line?

> +}


-- 
With Best Regards,
Andy Shevchenko




More information about the Alsa-devel mailing list