Linux-GPIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v1 1/3] pinctrl: intel: Extract intel_pinctrl_get_soc_data() helper for wider use
@ 2020-07-29 11:57 Andy Shevchenko
  2020-07-29 11:57 ` [PATCH v1 2/3] pinctrl: baytrail: Switch to use intel_pinctrl_get_soc_data() Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Andy Shevchenko @ 2020-07-29 11:57 UTC (permalink / raw)
  To: Mika Westerberg, linux-gpio, Linus Walleij; +Cc: Andy Shevchenko

intel_pinctrl_get_soc_data() helper can be used in few driver instead of
open-coded variants. Thus, extract it as a standalone API.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pinctrl/intel/pinctrl-intel.c | 24 ++++++++++++++++++------
 drivers/pinctrl/intel/pinctrl-intel.h |  2 ++
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
index 5a39e6ce6786..6e11d16a8684 100644
--- a/drivers/pinctrl/intel/pinctrl-intel.c
+++ b/drivers/pinctrl/intel/pinctrl-intel.c
@@ -1424,9 +1424,6 @@ static int intel_pinctrl_probe(struct platform_device *pdev,
 	struct intel_pinctrl *pctrl;
 	int i, ret, irq;
 
-	if (!soc_data)
-		return -EINVAL;
-
 	pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL);
 	if (!pctrl)
 		return -ENOMEM;
@@ -1534,11 +1531,26 @@ int intel_pinctrl_probe_by_hid(struct platform_device *pdev)
 	const struct intel_pinctrl_soc_data *data;
 
 	data = device_get_match_data(&pdev->dev);
+	if (!data)
+		return -ENODATA;
+
 	return intel_pinctrl_probe(pdev, data);
 }
 EXPORT_SYMBOL_GPL(intel_pinctrl_probe_by_hid);
 
 int intel_pinctrl_probe_by_uid(struct platform_device *pdev)
+{
+	const struct intel_pinctrl_soc_data *data;
+
+	data = intel_pinctrl_get_soc_data(pdev);
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	return intel_pinctrl_probe(pdev, data);
+}
+EXPORT_SYMBOL_GPL(intel_pinctrl_probe_by_uid);
+
+const struct intel_pinctrl_soc_data *intel_pinctrl_get_soc_data(struct platform_device *pdev)
 {
 	const struct intel_pinctrl_soc_data *data = NULL;
 	const struct intel_pinctrl_soc_data **table;
@@ -1561,15 +1573,15 @@ int intel_pinctrl_probe_by_uid(struct platform_device *pdev)
 
 		id = platform_get_device_id(pdev);
 		if (!id)
-			return -ENODEV;
+			return ERR_PTR(-ENODEV);
 
 		table = (const struct intel_pinctrl_soc_data **)id->driver_data;
 		data = table[pdev->id];
 	}
 
-	return intel_pinctrl_probe(pdev, data);
+	return data ?: ERR_PTR(-ENODATA);
 }
-EXPORT_SYMBOL_GPL(intel_pinctrl_probe_by_uid);
+EXPORT_SYMBOL_GPL(intel_pinctrl_get_soc_data);
 
 #ifdef CONFIG_PM_SLEEP
 static bool intel_pinctrl_should_save(struct intel_pinctrl *pctrl, unsigned int pin)
diff --git a/drivers/pinctrl/intel/pinctrl-intel.h b/drivers/pinctrl/intel/pinctrl-intel.h
index 2e283247f3ba..38a1d6af7427 100644
--- a/drivers/pinctrl/intel/pinctrl-intel.h
+++ b/drivers/pinctrl/intel/pinctrl-intel.h
@@ -198,6 +198,8 @@ struct intel_pinctrl_soc_data {
 	size_t ncommunities;
 };
 
+const struct intel_pinctrl_soc_data *intel_pinctrl_get_soc_data(struct platform_device *pdev);
+
 struct intel_pad_context;
 struct intel_community_context;
 
-- 
2.27.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v1 2/3] pinctrl: baytrail: Switch to use intel_pinctrl_get_soc_data()
  2020-07-29 11:57 [PATCH v1 1/3] pinctrl: intel: Extract intel_pinctrl_get_soc_data() helper for wider use Andy Shevchenko
@ 2020-07-29 11:57 ` Andy Shevchenko
  2020-07-29 11:57 ` [PATCH v1 3/3] pinctrl: cherryview: " Andy Shevchenko
  2020-08-03 12:33 ` [PATCH v1 1/3] pinctrl: intel: Extract intel_pinctrl_get_soc_data() helper for wider use Mika Westerberg
  2 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2020-07-29 11:57 UTC (permalink / raw)
  To: Mika Westerberg, linux-gpio, Linus Walleij; +Cc: Andy Shevchenko

Since we have common helper to retrieve SoC data from driver data
we may switch to use it.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pinctrl/intel/pinctrl-baytrail.c | 24 +++++-------------------
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/pinctrl/intel/pinctrl-baytrail.c b/drivers/pinctrl/intel/pinctrl-baytrail.c
index d6e35cba3065..d49aab3cfbaa 100644
--- a/drivers/pinctrl/intel/pinctrl-baytrail.c
+++ b/drivers/pinctrl/intel/pinctrl-baytrail.c
@@ -1635,28 +1635,14 @@ static const struct acpi_device_id byt_gpio_acpi_match[] = {
 
 static int byt_pinctrl_probe(struct platform_device *pdev)
 {
-	const struct intel_pinctrl_soc_data *soc_data = NULL;
-	const struct intel_pinctrl_soc_data **soc_table;
+	const struct intel_pinctrl_soc_data *soc_data;
 	struct device *dev = &pdev->dev;
-	struct acpi_device *acpi_dev;
 	struct intel_pinctrl *vg;
-	int i, ret;
-
-	acpi_dev = ACPI_COMPANION(dev);
-	if (!acpi_dev)
-		return -ENODEV;
-
-	soc_table = (const struct intel_pinctrl_soc_data **)device_get_match_data(dev);
-
-	for (i = 0; soc_table[i]; i++) {
-		if (!strcmp(acpi_dev->pnp.unique_id, soc_table[i]->uid)) {
-			soc_data = soc_table[i];
-			break;
-		}
-	}
+	int ret;
 
-	if (!soc_data)
-		return -ENODEV;
+	soc_data = intel_pinctrl_get_soc_data(pdev);
+	if (IS_ERR(soc_data))
+		return PTR_ERR(soc_data);
 
 	vg = devm_kzalloc(dev, sizeof(*vg), GFP_KERNEL);
 	if (!vg)
-- 
2.27.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v1 3/3] pinctrl: cherryview: Switch to use intel_pinctrl_get_soc_data()
  2020-07-29 11:57 [PATCH v1 1/3] pinctrl: intel: Extract intel_pinctrl_get_soc_data() helper for wider use Andy Shevchenko
  2020-07-29 11:57 ` [PATCH v1 2/3] pinctrl: baytrail: Switch to use intel_pinctrl_get_soc_data() Andy Shevchenko
@ 2020-07-29 11:57 ` Andy Shevchenko
  2020-08-03 12:33 ` [PATCH v1 1/3] pinctrl: intel: Extract intel_pinctrl_get_soc_data() helper for wider use Mika Westerberg
  2 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2020-07-29 11:57 UTC (permalink / raw)
  To: Mika Westerberg, linux-gpio, Linus Walleij; +Cc: Andy Shevchenko

Since we have common helper to retrieve SoC data from driver data
we may switch to use it.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pinctrl/intel/pinctrl-cherryview.c | 23 ++++++----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/drivers/pinctrl/intel/pinctrl-cherryview.c b/drivers/pinctrl/intel/pinctrl-cherryview.c
index c18abc1a0d04..595686e6a238 100644
--- a/drivers/pinctrl/intel/pinctrl-cherryview.c
+++ b/drivers/pinctrl/intel/pinctrl-cherryview.c
@@ -1605,28 +1605,17 @@ static acpi_status chv_pinctrl_mmio_access_handler(u32 function,
 
 static int chv_pinctrl_probe(struct platform_device *pdev)
 {
-	const struct intel_pinctrl_soc_data *soc_data = NULL;
-	const struct intel_pinctrl_soc_data **soc_table;
+	const struct intel_pinctrl_soc_data *soc_data;
 	struct intel_community *community;
 	struct device *dev = &pdev->dev;
+	struct acpi_device *adev = ACPI_COMPANION(dev);
 	struct intel_pinctrl *pctrl;
-	struct acpi_device *adev;
 	acpi_status status;
-	int ret, irq, i;
+	int ret, irq;
 
-	adev = ACPI_COMPANION(&pdev->dev);
-	if (!adev)
-		return -ENODEV;
-
-	soc_table = (const struct intel_pinctrl_soc_data **)device_get_match_data(dev);
-	for (i = 0; soc_table[i]; i++) {
-		if (!strcmp(adev->pnp.unique_id, soc_table[i]->uid)) {
-			soc_data = soc_table[i];
-			break;
-		}
-	}
-	if (!soc_data)
-		return -ENODEV;
+	soc_data = intel_pinctrl_get_soc_data(pdev);
+	if (IS_ERR(soc_data))
+		return PTR_ERR(soc_data);
 
 	pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL);
 	if (!pctrl)
-- 
2.27.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/3] pinctrl: intel: Extract intel_pinctrl_get_soc_data() helper for wider use
  2020-07-29 11:57 [PATCH v1 1/3] pinctrl: intel: Extract intel_pinctrl_get_soc_data() helper for wider use Andy Shevchenko
  2020-07-29 11:57 ` [PATCH v1 2/3] pinctrl: baytrail: Switch to use intel_pinctrl_get_soc_data() Andy Shevchenko
  2020-07-29 11:57 ` [PATCH v1 3/3] pinctrl: cherryview: " Andy Shevchenko
@ 2020-08-03 12:33 ` Mika Westerberg
  2020-08-03 13:50   ` Andy Shevchenko
  2 siblings, 1 reply; 6+ messages in thread
From: Mika Westerberg @ 2020-08-03 12:33 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-gpio, Linus Walleij

On Wed, Jul 29, 2020 at 02:57:06PM +0300, Andy Shevchenko wrote:
> intel_pinctrl_get_soc_data() helper can be used in few driver instead of
> open-coded variants. Thus, extract it as a standalone API.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/pinctrl/intel/pinctrl-intel.c | 24 ++++++++++++++++++------
>  drivers/pinctrl/intel/pinctrl-intel.h |  2 ++
>  2 files changed, 20 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
> index 5a39e6ce6786..6e11d16a8684 100644
> --- a/drivers/pinctrl/intel/pinctrl-intel.c
> +++ b/drivers/pinctrl/intel/pinctrl-intel.c
> @@ -1424,9 +1424,6 @@ static int intel_pinctrl_probe(struct platform_device *pdev,
>  	struct intel_pinctrl *pctrl;
>  	int i, ret, irq;
>  
> -	if (!soc_data)
> -		return -EINVAL;
> -
>  	pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL);
>  	if (!pctrl)
>  		return -ENOMEM;
> @@ -1534,11 +1531,26 @@ int intel_pinctrl_probe_by_hid(struct platform_device *pdev)
>  	const struct intel_pinctrl_soc_data *data;
>  
>  	data = device_get_match_data(&pdev->dev);
> +	if (!data)
> +		return -ENODATA;
> +
>  	return intel_pinctrl_probe(pdev, data);
>  }
>  EXPORT_SYMBOL_GPL(intel_pinctrl_probe_by_hid);
>  
>  int intel_pinctrl_probe_by_uid(struct platform_device *pdev)
> +{
> +	const struct intel_pinctrl_soc_data *data;
> +
> +	data = intel_pinctrl_get_soc_data(pdev);
> +	if (IS_ERR(data))
> +		return PTR_ERR(data);
> +
> +	return intel_pinctrl_probe(pdev, data);
> +}
> +EXPORT_SYMBOL_GPL(intel_pinctrl_probe_by_uid);
> +
> +const struct intel_pinctrl_soc_data *intel_pinctrl_get_soc_data(struct platform_device *pdev)

Can we make this take const parameter as well?

>  {
>  	const struct intel_pinctrl_soc_data *data = NULL;
>  	const struct intel_pinctrl_soc_data **table;
> @@ -1561,15 +1573,15 @@ int intel_pinctrl_probe_by_uid(struct platform_device *pdev)
>  
>  		id = platform_get_device_id(pdev);
>  		if (!id)
> -			return -ENODEV;
> +			return ERR_PTR(-ENODEV);
>  
>  		table = (const struct intel_pinctrl_soc_data **)id->driver_data;
>  		data = table[pdev->id];
>  	}
>  
> -	return intel_pinctrl_probe(pdev, data);
> +	return data ?: ERR_PTR(-ENODATA);
>  }
> -EXPORT_SYMBOL_GPL(intel_pinctrl_probe_by_uid);
> +EXPORT_SYMBOL_GPL(intel_pinctrl_get_soc_data);
>  
>  #ifdef CONFIG_PM_SLEEP
>  static bool intel_pinctrl_should_save(struct intel_pinctrl *pctrl, unsigned int pin)
> diff --git a/drivers/pinctrl/intel/pinctrl-intel.h b/drivers/pinctrl/intel/pinctrl-intel.h
> index 2e283247f3ba..38a1d6af7427 100644
> --- a/drivers/pinctrl/intel/pinctrl-intel.h
> +++ b/drivers/pinctrl/intel/pinctrl-intel.h
> @@ -198,6 +198,8 @@ struct intel_pinctrl_soc_data {
>  	size_t ncommunities;
>  };
>  
> +const struct intel_pinctrl_soc_data *intel_pinctrl_get_soc_data(struct platform_device *pdev);
> +
>  struct intel_pad_context;
>  struct intel_community_context;
>  
> -- 
> 2.27.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/3] pinctrl: intel: Extract intel_pinctrl_get_soc_data() helper for wider use
  2020-08-03 12:33 ` [PATCH v1 1/3] pinctrl: intel: Extract intel_pinctrl_get_soc_data() helper for wider use Mika Westerberg
@ 2020-08-03 13:50   ` Andy Shevchenko
  2020-08-03 14:22     ` Mika Westerberg
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2020-08-03 13:50 UTC (permalink / raw)
  To: Mika Westerberg; +Cc: linux-gpio, Linus Walleij

On Mon, Aug 03, 2020 at 03:33:18PM +0300, Mika Westerberg wrote:
> On Wed, Jul 29, 2020 at 02:57:06PM +0300, Andy Shevchenko wrote:
> > intel_pinctrl_get_soc_data() helper can be used in few driver instead of
> > open-coded variants. Thus, extract it as a standalone API.

...

> > +const struct intel_pinctrl_soc_data *intel_pinctrl_get_soc_data(struct platform_device *pdev)
> 
> Can we make this take const parameter as well?

You mean

const struct intel_pinctrl_soc_data *
intel_pinctrl_get_soc_data(const struct platform_device *pdev)

?

Sure, I can do it for v2.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/3] pinctrl: intel: Extract intel_pinctrl_get_soc_data() helper for wider use
  2020-08-03 13:50   ` Andy Shevchenko
@ 2020-08-03 14:22     ` Mika Westerberg
  0 siblings, 0 replies; 6+ messages in thread
From: Mika Westerberg @ 2020-08-03 14:22 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-gpio, Linus Walleij

On Mon, Aug 03, 2020 at 04:50:31PM +0300, Andy Shevchenko wrote:
> On Mon, Aug 03, 2020 at 03:33:18PM +0300, Mika Westerberg wrote:
> > On Wed, Jul 29, 2020 at 02:57:06PM +0300, Andy Shevchenko wrote:
> > > intel_pinctrl_get_soc_data() helper can be used in few driver instead of
> > > open-coded variants. Thus, extract it as a standalone API.
> 
> ...
> 
> > > +const struct intel_pinctrl_soc_data *intel_pinctrl_get_soc_data(struct platform_device *pdev)
> > 
> > Can we make this take const parameter as well?
> 
> You mean
> 
> const struct intel_pinctrl_soc_data *
> intel_pinctrl_get_soc_data(const struct platform_device *pdev)
> 
> ?

Yes, exactly.

> Sure, I can do it for v2.

Thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29 11:57 [PATCH v1 1/3] pinctrl: intel: Extract intel_pinctrl_get_soc_data() helper for wider use Andy Shevchenko
2020-07-29 11:57 ` [PATCH v1 2/3] pinctrl: baytrail: Switch to use intel_pinctrl_get_soc_data() Andy Shevchenko
2020-07-29 11:57 ` [PATCH v1 3/3] pinctrl: cherryview: " Andy Shevchenko
2020-08-03 12:33 ` [PATCH v1 1/3] pinctrl: intel: Extract intel_pinctrl_get_soc_data() helper for wider use Mika Westerberg
2020-08-03 13:50   ` Andy Shevchenko
2020-08-03 14:22     ` Mika Westerberg

Linux-GPIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-gpio/0 linux-gpio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-gpio linux-gpio/ https://lore.kernel.org/linux-gpio \
		linux-gpio@vger.kernel.org
	public-inbox-index linux-gpio

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-gpio


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git