diff mbox series

[v4,1/5] spi: pxa2xx: Respect Intel SSP type given by a property

Message ID 20221020194500.10225-2-andriy.shevchenko@linux.intel.com
State New
Headers show
Series spi: pxa2xx: Pass the SSP type via device property | expand

Commit Message

Andy Shevchenko Oct. 20, 2022, 7:44 p.m. UTC
Allow to set the Intel SSP type by reading the property.
Only apply this to the known MFD enumerated devices.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/spi/spi-pxa2xx.c   | 12 ++++++++++++
 include/linux/pxa2xx_ssp.h |  1 +
 2 files changed, 13 insertions(+)

Comments

Mark Brown Oct. 21, 2022, 12:16 p.m. UTC | #1
On Thu, Oct 20, 2022 at 10:44:56PM +0300, Andy Shevchenko wrote:

> Allow to set the Intel SSP type by reading the property.
> Only apply this to the known MFD enumerated devices.

> +	/* For MFD enumerated devices always ask for a property */
> +	mfd_enumerated = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lpss_priv");
> +	if (mfd_enumerated) {
> +		status = device_property_read_u32(dev, "intel,spi-pxa2xx-type", &value);
> +		if (status)
> +			return ERR_PTR(status);
> +	}
> +
>  	if (pcidev)
>  		pcidev_id = pci_match_id(pxa2xx_spi_pci_compound_match, pcidev);
>  
>  	match = device_get_match_data(&pdev->dev);
>  	if (match)
>  		type = (enum pxa_ssp_type)match;
> +	else if (value > SSP_UNDEFINED && value < SSP_MAX)
> +		type = (enum pxa_ssp_type)value;

This is quite hard to follow, partly because value isn't exactly a clear
variable name and partly because the initialisation to SSP_UNDEFINED,
the attempt to read via device property and this if/else chain are split
up and not clearly joined up with each other.  This is partly an issue
with the existing code but the extra layer of spreading things
throughout the function being added amplifies things a bit.
Andy Shevchenko Oct. 21, 2022, 12:26 p.m. UTC | #2
On Fri, Oct 21, 2022 at 01:16:01PM +0100, Mark Brown wrote:
> On Thu, Oct 20, 2022 at 10:44:56PM +0300, Andy Shevchenko wrote:
> 
> > Allow to set the Intel SSP type by reading the property.
> > Only apply this to the known MFD enumerated devices.
> 
> > +	/* For MFD enumerated devices always ask for a property */
> > +	mfd_enumerated = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lpss_priv");
> > +	if (mfd_enumerated) {
> > +		status = device_property_read_u32(dev, "intel,spi-pxa2xx-type", &value);
> > +		if (status)
> > +			return ERR_PTR(status);
> > +	}
> > +
> >  	if (pcidev)
> >  		pcidev_id = pci_match_id(pxa2xx_spi_pci_compound_match, pcidev);
> >  
> >  	match = device_get_match_data(&pdev->dev);
> >  	if (match)
> >  		type = (enum pxa_ssp_type)match;
> > +	else if (value > SSP_UNDEFINED && value < SSP_MAX)
> > +		type = (enum pxa_ssp_type)value;
> 
> This is quite hard to follow, partly because value isn't exactly a clear
> variable name and partly because the initialisation to SSP_UNDEFINED,
> the attempt to read via device property and this if/else chain are split
> up and not clearly joined up with each other.  This is partly an issue
> with the existing code but the extra layer of spreading things
> throughout the function being added amplifies things a bit.

The next patch removes the PCI part in this equation, at the end there is
no "new" complexity on top of the existing one. But I'm all ears on how
to simplify the existing code.
diff mbox series

Patch

diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
index 03ed6d4a14cd..f3ba1b0588fb 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -1460,17 +1460,29 @@  pxa2xx_spi_init_pdata(struct platform_device *pdev)
 	struct resource *res;
 	struct pci_dev *pcidev = dev_is_pci(parent) ? to_pci_dev(parent) : NULL;
 	const struct pci_device_id *pcidev_id = NULL;
+	u32 value = SSP_UNDEFINED;
 	enum pxa_ssp_type type;
+	bool mfd_enumerated;
 	const void *match;
 	int status;
 	u64 uid;
 
+	/* For MFD enumerated devices always ask for a property */
+	mfd_enumerated = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lpss_priv");
+	if (mfd_enumerated) {
+		status = device_property_read_u32(dev, "intel,spi-pxa2xx-type", &value);
+		if (status)
+			return ERR_PTR(status);
+	}
+
 	if (pcidev)
 		pcidev_id = pci_match_id(pxa2xx_spi_pci_compound_match, pcidev);
 
 	match = device_get_match_data(&pdev->dev);
 	if (match)
 		type = (enum pxa_ssp_type)match;
+	else if (value > SSP_UNDEFINED && value < SSP_MAX)
+		type = (enum pxa_ssp_type)value;
 	else if (pcidev_id)
 		type = (enum pxa_ssp_type)pcidev_id->driver_data;
 	else
diff --git a/include/linux/pxa2xx_ssp.h b/include/linux/pxa2xx_ssp.h
index a3fec2de512f..cd1973e6ac4b 100644
--- a/include/linux/pxa2xx_ssp.h
+++ b/include/linux/pxa2xx_ssp.h
@@ -229,6 +229,7 @@  enum pxa_ssp_type {
 	LPSS_SPT_SSP,
 	LPSS_BXT_SSP,
 	LPSS_CNL_SSP,
+	SSP_MAX
 };
 
 struct ssp_device {