pinctrl: intel: Replace ifdeffery by pm_sleep_ptr() macro Andy Shevchenko
Subsystems (3)
v2 cover pinctrl: intel: Replace ifdeffery by pm_sleep_ptr() macro Andy Shevchenko
There are two benefits of this series:
1) no more ugly ifdeffery in the code;
2) the PM callbacks are all being synchronised via using the same macro, i.e. pm_sleep_ptr() everywhere.
v2:
- made the code readable again (Mika)
Andy Shevchenko (3):
pinctrl: intel: Replace ifdeffery by pm_sleep_ptr() macro
pinctrl: baytrail: Replace ifdeffery by pm_sleep_ptr() macro
pinctrl: cherryview: Replace ifdeffery by pm_sleep_ptr() macro
drivers/pinctrl/intel/pinctrl-baytrail.c | 21 ++++++++++++++------- drivers/pinctrl/intel/pinctrl-cherryview.c | 20 +++++++++++++------- drivers/pinctrl/intel/pinctrl-intel.c | 5 +---- drivers/pinctrl/intel/pinctrl-intel.h | 14 ++++++++++++++ 4 files changed, 42 insertions(+), 18 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v2 1/3 pinctrl: intel: Replace ifdeffery by pm_sleep_ptr() macro
Explicit ifdeffery is ugly and theoretically might be not synchronised with the rest of functions that are assigned via pm_sleep_ptr() macro. Replace ifdeffery by pm_sleep_ptr() macro to improve this.
--- drivers/pinctrl/intel/pinctrl-intel.c | 5 +---- drivers/pinctrl/intel/pinctrl-intel.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-)
drivers/pinctrl/intel/pinctrl-intel.c +1 -4
@@ -1482,7 +1482,6 @@ static int intel_pinctrl_add_padgroups_by_size(struct intel_pinctrl *pctrl,static int intel_pinctrl_pm_init (struct intel_pinctrl *pctrl) { -#ifdef CONFIG_PM_SLEEP const struct intel_pinctrl_soc_data *soc = pctrl->soc;struct intel_community_context *communities;struct intel_pad_context *pads;
@@ -1497,7 +1496,6 @@ static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl)if (!communities)return -ENOMEM ; -for (i =0 ; i < pctrl->ncommunities; i++) {struct intel_community *community = &pctrl->communities[i];u32 *intmask, *hostown;
@@ -1519,7 +1517,6 @@ static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl) pctrl->context.pads = pads; pctrl->context.communities = communities; -#endif return 0 ; }
@@ -1649,7 +1646,7 @@ int intel_pinctrl_probe(struct platform_device *pdev,if (irq <0 )return irq; - ret =intel_pinctrl_pm_init (pctrl); + ret =intel_pinctrl_context_alloc (pctrl, intel_pinctrl_pm_init);if (ret)return ret;
drivers/pinctrl/intel/pinctrl-intel.h +14 -0
@@ -256,6 +256,20 @@ struct intel_pinctrl {int irq; }; +typedef int (*intel_pinctrl_context_alloc_fn )(struct intel_pinctrl *pctrl); + +static inline int intel_pinctrl_context_alloc (struct intel_pinctrl *pctrl, +intel_pinctrl_context_alloc_fn alloc_fn) +{ +intel_pinctrl_context_alloc_fn fn; + + fn =pm_sleep_ptr (alloc_fn); +if (fn) +return fn (pctrl); + +return 0 ; +} +int intel_pinctrl_probe (struct platform_device *pdev,const struct intel_pinctrl_soc_data *soc_data);
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Mika Westerberg
maintainerRe: [PATCH v2 1/3] pinctrl: intel: Replace ifdeffery by pm_sleep_ptr() macro
Quoted 58 lines · Andy Shevchenko
Explicit ifdeffery is ugly and theoretically might be not synchronised with the rest of functions that are assigned via
pm_sleep_ptr()macro. Replace ifdeffery bypm_sleep_ptr()macro to improve this.Signed-off-by Andy Shevchenko <[email protected]>--- drivers/pinctrl/intel/pinctrl-intel.c | 5 +---- drivers/pinctrl/intel/pinctrl-intel.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-)drivers/pinctrl/intel/pinctrl-intel.c +1
-4@@ -1482,7 +1482,6 @@ static int intel_pinctrl_add_padgroups_by_size(struct intel_pinctrl *pctrl,static int intel_pinctrl_pm_init (struct intel_pinctrl *pctrl) { -#ifdef CONFIG_PM_SLEEP const struct intel_pinctrl_soc_data *soc = pctrl->soc;struct intel_community_context *communities;struct intel_pad_context *pads;@@ -1497,7 +1496,6 @@ static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl)if (!communities)return -ENOMEM ; -for (i =0 ; i < pctrl->ncommunities; i++) {struct intel_community *community = &pctrl->communities[i];u32 *intmask, *hostown;@@ -1519,7 +1517,6 @@ static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl) pctrl->context.pads = pads; pctrl->context.communities = communities; -#endif return 0 ; }@@ -1649,7 +1646,7 @@ int intel_pinctrl_probe(struct platform_device *pdev,if (irq <0 )return irq; - ret =intel_pinctrl_pm_init (pctrl); + ret =intel_pinctrl_context_alloc (pctrl, intel_pinctrl_pm_init);if (ret)return ret;drivers/pinctrl/intel/pinctrl-intel.h +3
-0@@ -256,6 +256,20 @@ struct intel_pinctrl {int irq; }; +typedef int (*intel_pinctrl_context_alloc_fn )(struct intel_pinctrl *pctrl); + +static inline int intel_pinctrl_context_alloc(struct intel_pinctrl *pctrl,
drivers/pinctrl/intel/pinctrl-intel.h struct intel_pinctrl { · line 271
Quoted 10 lines
drivers/pinctrl/intel/pinctrl-intel.h +10
-0+ intel_pinctrl_context_alloc_fn alloc_fn) +{ +intel_pinctrl_context_alloc_fn fn; + + fn =pm_sleep_ptr (alloc_fn); +if (fn) +return fn (pctrl); + +return 0 ; +}
No way, this looks even worse :(
Let's not do this change please.
PATCH v2 2/3 pinctrl: baytrail: Replace ifdeffery by pm_sleep_ptr() macro
In reply to Andy ShevchenkoExplicit ifdeffery is ugly and theoretically might be not synchronised with the rest of functions that are assigned via pm_sleep_ptr() macro. Replace ifdeffery by pm_sleep_ptr() macro to improve this.
--- drivers/pinctrl/intel/pinctrl-baytrail.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/pinctrl/intel/pinctrl-baytrail.c +14 -7
@@ -1514,13 +1514,6 @@ static int byt_gpio_probe(struct intel_pinctrl *vg) gc->parent = vg->dev; gc->ngpio = vg->soc->npins; -#ifdef CONFIG_PM_SLEEP - vg->context.pads =devm_kcalloc (vg->dev, gc->ngpio,sizeof (*vg->context.pads), -GFP_KERNEL ); -if (!vg->context.pads) -return -ENOMEM ; -#endif -/* set up interrupts */ irq =platform_get_irq_optional (pdev,0 );if (irq >0 ) {
@@ -1581,6 +1574,16 @@ static const struct acpi_device_id byt_gpio_acpi_match[] = { { } }; +static int byt_pinctrl_pm_init (struct intel_pinctrl *vg) +{ + vg->context.pads =devm_kcalloc (vg->dev, vg->soc->npins, +sizeof (*vg->context.pads),GFP_KERNEL ); +if (!vg->context.pads) +return -ENOMEM ; + +return 0 ; +} +static int byt_pinctrl_probe (struct platform_device *pdev) {const struct intel_pinctrl_soc_data *soc_data;
@@ -1603,6 +1606,10 @@ static int byt_pinctrl_probe(struct platform_device *pdev)return ret; } + ret =intel_pinctrl_context_alloc (vg, byt_pinctrl_pm_init); +if (ret) +return ret; + vg->pctldesc = byt_pinctrl_desc; vg->pctldesc.name =dev_name (dev); vg->pctldesc.pins = vg->soc->pins;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v2 3/3 pinctrl: cherryview: Replace ifdeffery by pm_sleep_ptr() macro
In reply to Andy ShevchenkoExplicit ifdeffery is ugly and theoretically might be not synchronised with the rest of functions that are assigned via pm_sleep_ptr() macro. Replace ifdeffery by pm_sleep_ptr() macro to improve this.
--- drivers/pinctrl/intel/pinctrl-cherryview.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/pinctrl/intel/pinctrl-cherryview.c +13 -7
@@ -1608,6 +1608,16 @@ static acpi_status chv_pinctrl_mmio_access_handler(u32 function,return AE_OK ; } +static int chv_pinctrl_pm_init (struct intel_pinctrl *pctrl) +{ + pctrl->context.pads =devm_kcalloc (pctrl->dev, pctrl->soc->npins, +sizeof (*pctrl->context.pads),GFP_KERNEL ); +if (!pctrl->context.pads) +return -ENOMEM ; + +return 0 ; +} +static int chv_pinctrl_probe (struct platform_device *pdev) {const struct intel_pinctrl_soc_data *soc_data;
@@ -1648,13 +1658,9 @@ static int chv_pinctrl_probe(struct platform_device *pdev) community->pad_regs = community->regs +FAMILY_PAD_REGS_OFF ; -#ifdef CONFIG_PM_SLEEP - pctrl->context.pads =devm_kcalloc (dev, pctrl->soc->npins, -sizeof (*pctrl->context.pads), -GFP_KERNEL ); -if (!pctrl->context.pads) -return -ENOMEM ; -#endif + ret =intel_pinctrl_context_alloc (pctrl, chv_pinctrl_pm_init); +if (ret) +return ret; pctrl->context.communities = devm_kcalloc(dev, pctrl->soc->ncommunities, sizeof(*pctrl->context.communities),
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac