diff mbox series

[v1,1/3] pinctrl: intel: Extract intel_pinctrl_get_soc_data() helper for wider use

Message ID 20200729115708.38112-1-andriy.shevchenko@linux.intel.com
State New
Headers show
Series [v1,1/3] pinctrl: intel: Extract intel_pinctrl_get_soc_data() helper for wider use | expand

Commit Message

Andy Shevchenko July 29, 2020, 11:57 a.m. UTC
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(-)

Comments

Mika Westerberg Aug. 3, 2020, 12:33 p.m. UTC | #1
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
Andy Shevchenko Aug. 3, 2020, 1:50 p.m. UTC | #2
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.
Mika Westerberg Aug. 3, 2020, 2:22 p.m. UTC | #3
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!
Andy Shevchenko Aug. 18, 2020, 12:34 p.m. UTC | #4
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)
> 
> ?
> 
> Sure, I can do it for v2.

Actually I can't. device_match_data() requires struct device * pointer and
compiler is unable to compile with const qualifier.

Are you good with current version then?
Mika Westerberg Aug. 18, 2020, 12:36 p.m. UTC | #5
On Tue, Aug 18, 2020 at 03:34:59PM +0300, Andy Shevchenko wrote:
> 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)
> > 
> > ?
> > 
> > Sure, I can do it for v2.
> 
> Actually I can't. device_match_data() requires struct device * pointer and
> compiler is unable to compile with const qualifier.

OK

> Are you good with current version then?

Yes :)
Andy Shevchenko Aug. 18, 2020, 12:36 p.m. UTC | #6
On Tue, Aug 18, 2020 at 03:34:59PM +0300, Andy Shevchenko wrote:
> 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:

...

> > > > +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.
> 
> Actually I can't. device_match_data() requires struct device * pointer and
> compiler is unable to compile with const qualifier.

pinctrl-intel.c: In function ‘intel_pinctrl_get_soc_data’:
pinctrl-intel.c:1533:45: warning: passing argument 1 of ‘device_get_match_data’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]


> Are you good with current version then?
Andy Shevchenko Aug. 18, 2020, 1:47 p.m. UTC | #7
On Tue, Aug 18, 2020 at 03:36:02PM +0300, Mika Westerberg wrote:
> On Tue, Aug 18, 2020 at 03:34:59PM +0300, Andy Shevchenko wrote:
> > 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)
> > > 
> > > ?
> > > 
> > > Sure, I can do it for v2.
> > 
> > Actually I can't. device_match_data() requires struct device * pointer and
> > compiler is unable to compile with const qualifier.
> 
> OK
> 
> > Are you good with current version then?
> 
> Yes :)

Pushed to my review and testing queue, thanks!

P.S. I have added your Ack as discussed offline.
diff mbox series

Patch

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;