2021-04-19 08:26:00

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH 1/7] mfd: max8997: Simplify getting of_device_id match data

Use of_device_get_match_data() to make the code slightly smaller.

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/mfd/max8997.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c
index 68d8f2b95287..f89b1eb121c9 100644
--- a/drivers/mfd/max8997.c
+++ b/drivers/mfd/max8997.c
@@ -11,6 +11,7 @@
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/of.h>
+#include <linux/of_device.h>
#include <linux/of_irq.h>
#include <linux/interrupt.h>
#include <linux/pm_runtime.h>
@@ -145,11 +146,9 @@ static struct max8997_platform_data *max8997_i2c_parse_dt_pdata(
static inline unsigned long max8997_i2c_get_driver_data(struct i2c_client *i2c,
const struct i2c_device_id *id)
{
- if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) {
- const struct of_device_id *match;
- match = of_match_node(max8997_pmic_dt_match, i2c->dev.of_node);
- return (unsigned long)match->data;
- }
+ if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node)
+ return (unsigned long)of_device_get_match_data(&i2c->dev);
+
return id->driver_data;
}

--
2.25.1


2021-04-19 08:28:02

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH 3/7] mfd: da9052: Simplify getting of_device_id match data

Use of_device_get_match_data() to make the code slightly smaller.

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/mfd/da9052-i2c.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/mfd/da9052-i2c.c b/drivers/mfd/da9052-i2c.c
index 47556d2d9abe..5d8ce8dca3fc 100644
--- a/drivers/mfd/da9052-i2c.c
+++ b/drivers/mfd/da9052-i2c.c
@@ -154,13 +154,8 @@ static int da9052_i2c_probe(struct i2c_client *client,
return ret;

#ifdef CONFIG_OF
- if (!id) {
- struct device_node *np = client->dev.of_node;
- const struct of_device_id *deviceid;
-
- deviceid = of_match_node(dialog_dt_ids, np);
- id = deviceid->data;
- }
+ if (!id)
+ id = of_device_get_match_data(&client->dev);
#endif

if (!id) {
--
2.25.1

2021-04-19 09:28:55

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH 4/7] mfd: da9052: Simplify getting of_device_id match data

Use of_device_get_match_data() to make the code slightly smaller.

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/mfd/da9062-core.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/mfd/da9062-core.c b/drivers/mfd/da9062-core.c
index 8d913375152d..01f8e10dfa55 100644
--- a/drivers/mfd/da9062-core.c
+++ b/drivers/mfd/da9062-core.c
@@ -9,6 +9,7 @@
#include <linux/init.h>
#include <linux/device.h>
#include <linux/interrupt.h>
+#include <linux/of_device.h>
#include <linux/regmap.h>
#include <linux/irq.h>
#include <linux/mfd/core.h>
@@ -622,7 +623,6 @@ static int da9062_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
{
struct da9062 *chip;
- const struct of_device_id *match;
unsigned int irq_base;
const struct mfd_cell *cell;
const struct regmap_irq_chip *irq_chip;
@@ -635,15 +635,10 @@ static int da9062_i2c_probe(struct i2c_client *i2c,
if (!chip)
return -ENOMEM;

- if (i2c->dev.of_node) {
- match = of_match_node(da9062_dt_ids, i2c->dev.of_node);
- if (!match)
- return -EINVAL;
-
- chip->chip_type = (uintptr_t)match->data;
- } else {
+ if (i2c->dev.of_node)
+ chip->chip_type = (uintptr_t)of_device_get_match_data(&i2c->dev);
+ else
chip->chip_type = id->driver_data;
- }

i2c_set_clientdata(i2c, chip);
chip->dev = &i2c->dev;
--
2.25.1

2021-04-19 09:28:55

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH 7/7] mfd: twl: Correct kerneldoc

Correct kerneldoc function name to fix W=1 warning:

drivers/mfd/twl-core.c:496: warning:
expecting prototype for twl_regcache_bypass(). Prototype was for twl_set_regcache_bypass() instead

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/mfd/twl-core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
index 20cf8cfe4f3b..24b77b18b725 100644
--- a/drivers/mfd/twl-core.c
+++ b/drivers/mfd/twl-core.c
@@ -485,8 +485,8 @@ int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
EXPORT_SYMBOL(twl_i2c_read);

/**
- * twl_regcache_bypass - Configure the regcache bypass for the regmap associated
- * with the module
+ * twl_set_regcache_bypass - Configure the regcache bypass for the regmap
+ * associated with the module
* @mod_no: module number
* @enable: Regcache bypass state
*
--
2.25.1

2021-04-19 09:28:55

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH 5/7] mfd: sec: Simplify getting of_device_id match data

Use of_device_get_match_data() to make the code slightly smaller.

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/mfd/sec-core.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/sec-core.c b/drivers/mfd/sec-core.c
index 8d55992da19e..3126c39f3203 100644
--- a/drivers/mfd/sec-core.c
+++ b/drivers/mfd/sec-core.c
@@ -10,6 +10,7 @@
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/of.h>
+#include <linux/of_device.h>
#include <linux/of_irq.h>
#include <linux/interrupt.h>
#include <linux/pm_runtime.h>
@@ -324,12 +325,8 @@ static inline unsigned long sec_i2c_get_driver_data(struct i2c_client *i2c,
const struct i2c_device_id *id)
{
#ifdef CONFIG_OF
- if (i2c->dev.of_node) {
- const struct of_device_id *match;
-
- match = of_match_node(sec_dt_match, i2c->dev.of_node);
- return (unsigned long)match->data;
- }
+ if (i2c->dev.of_node)
+ return (unsigned long)of_device_get_match_data(&i2c->dev);
#endif
return id->driver_data;
}
--
2.25.1

2021-04-19 09:29:08

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH 2/7] mfd: max8998: Simplify getting of_device_id match data

Use of_device_get_match_data() to make the code slightly smaller.

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/mfd/max8998.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/mfd/max8998.c b/drivers/mfd/max8998.c
index 785f8e9841b7..42c60d4d97fb 100644
--- a/drivers/mfd/max8998.c
+++ b/drivers/mfd/max8998.c
@@ -12,6 +12,7 @@
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/of.h>
+#include <linux/of_device.h>
#include <linux/of_irq.h>
#include <linux/pm_runtime.h>
#include <linux/mutex.h>
@@ -155,11 +156,8 @@ static struct max8998_platform_data *max8998_i2c_parse_dt_pdata(
static inline unsigned long max8998_i2c_get_driver_data(struct i2c_client *i2c,
const struct i2c_device_id *id)
{
- if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) {
- const struct of_device_id *match;
- match = of_match_node(max8998_dt_match, i2c->dev.of_node);
- return (unsigned long)match->data;
- }
+ if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node)
+ return (unsigned long)of_device_get_match_data(&i2c->dev);

return id->driver_data;
}
--
2.25.1

2021-04-19 09:54:07

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH 6/7] mfd: wm831x: Correct kerneldoc

Correct kerneldoc function name to fix W=1 warning:

drivers/mfd/wm831x-core.c:121: warning:
expecting prototype for wm831x_reg_unlock(). Prototype was for wm831x_reg_lock() instead

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/mfd/wm831x-core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/wm831x-core.c b/drivers/mfd/wm831x-core.c
index bcef08f58fb3..c31809b17547 100644
--- a/drivers/mfd/wm831x-core.c
+++ b/drivers/mfd/wm831x-core.c
@@ -109,7 +109,7 @@ static int wm831x_reg_locked(struct wm831x *wm831x, unsigned short reg)
}

/**
- * wm831x_reg_unlock: Unlock user keyed registers
+ * wm831x_reg_lock: Unlock user keyed registers
*
* The WM831x has a user key preventing writes to particularly
* critical registers. This function locks those registers,
--
2.25.1

2021-04-19 11:03:13

by Adam Thomson

[permalink] [raw]
Subject: RE: [PATCH 4/7] mfd: da9052: Simplify getting of_device_id match data

On 19 April 2021 09:17, Krzysztof Kozlowski wrote:

> Use of_device_get_match_data() to make the code slightly smaller.
>
> Signed-off-by: Krzysztof Kozlowski <[email protected]>
> ---

Acked-by: Adam Thomson <[email protected]>

> drivers/mfd/da9062-core.c | 13 ++++---------
> 1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/mfd/da9062-core.c b/drivers/mfd/da9062-core.c
> index 8d913375152d..01f8e10dfa55 100644
> --- a/drivers/mfd/da9062-core.c
> +++ b/drivers/mfd/da9062-core.c
> @@ -9,6 +9,7 @@
> #include <linux/init.h>
> #include <linux/device.h>
> #include <linux/interrupt.h>
> +#include <linux/of_device.h>
> #include <linux/regmap.h>
> #include <linux/irq.h>
> #include <linux/mfd/core.h>
> @@ -622,7 +623,6 @@ static int da9062_i2c_probe(struct i2c_client *i2c,
> const struct i2c_device_id *id)
> {
> struct da9062 *chip;
> - const struct of_device_id *match;
> unsigned int irq_base;
> const struct mfd_cell *cell;
> const struct regmap_irq_chip *irq_chip;
> @@ -635,15 +635,10 @@ static int da9062_i2c_probe(struct i2c_client *i2c,
> if (!chip)
> return -ENOMEM;
>
> - if (i2c->dev.of_node) {
> - match = of_match_node(da9062_dt_ids, i2c->dev.of_node);
> - if (!match)
> - return -EINVAL;
> -
> - chip->chip_type = (uintptr_t)match->data;
> - } else {
> + if (i2c->dev.of_node)
> + chip->chip_type = (uintptr_t)of_device_get_match_data(&i2c-
> >dev);
> + else
> chip->chip_type = id->driver_data;
> - }
>
> i2c_set_clientdata(i2c, chip);
> chip->dev = &i2c->dev;
> --
> 2.25.1

2021-04-19 11:04:10

by Adam Thomson

[permalink] [raw]
Subject: RE: [PATCH 3/7] mfd: da9052: Simplify getting of_device_id match data

On 19 April 2021 09:17, Krzysztof Kozlowski wrote:

> Use of_device_get_match_data() to make the code slightly smaller.
>
> Signed-off-by: Krzysztof Kozlowski <[email protected]>
> ---

Acked-by: Adam Thomson <[email protected]>

> drivers/mfd/da9052-i2c.c | 9 ++-------
> 1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/mfd/da9052-i2c.c b/drivers/mfd/da9052-i2c.c
> index 47556d2d9abe..5d8ce8dca3fc 100644
> --- a/drivers/mfd/da9052-i2c.c
> +++ b/drivers/mfd/da9052-i2c.c
> @@ -154,13 +154,8 @@ static int da9052_i2c_probe(struct i2c_client *client,
> return ret;
>
> #ifdef CONFIG_OF
> - if (!id) {
> - struct device_node *np = client->dev.of_node;
> - const struct of_device_id *deviceid;
> -
> - deviceid = of_match_node(dialog_dt_ids, np);
> - id = deviceid->data;
> - }
> + if (!id)
> + id = of_device_get_match_data(&client->dev);
> #endif
>
> if (!id) {
> --
> 2.25.1

2021-04-19 11:06:36

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH 4/7] mfd: da9052: Simplify getting of_device_id match data

On 19/04/2021 10:17, Krzysztof Kozlowski wrote:
> Use of_device_get_match_data() to make the code slightly smaller.
>
> Signed-off-by: Krzysztof Kozlowski <[email protected]>
> ---
> drivers/mfd/da9062-core.c | 13 ++++---------
> 1 file changed, 4 insertions(+), 9 deletions(-)

Copy-paste error in the subject - the prefix should be:
mfd: da9062:


Best regards,
Krzysztof

2021-04-20 05:26:18

by Marek Szyprowski

[permalink] [raw]
Subject: Re: [PATCH 5/7] mfd: sec: Simplify getting of_device_id match data


On 19.04.2021 10:17, Krzysztof Kozlowski wrote:
> Use of_device_get_match_data() to make the code slightly smaller.
>
> Signed-off-by: Krzysztof Kozlowski <[email protected]>
> ---
> drivers/mfd/sec-core.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/mfd/sec-core.c b/drivers/mfd/sec-core.c
> index 8d55992da19e..3126c39f3203 100644
> --- a/drivers/mfd/sec-core.c
> +++ b/drivers/mfd/sec-core.c
> @@ -10,6 +10,7 @@
> #include <linux/slab.h>
> #include <linux/i2c.h>
> #include <linux/of.h>
> +#include <linux/of_device.h>
> #include <linux/of_irq.h>
> #include <linux/interrupt.h>
> #include <linux/pm_runtime.h>
> @@ -324,12 +325,8 @@ static inline unsigned long sec_i2c_get_driver_data(struct i2c_client *i2c,
> const struct i2c_device_id *id)
> {
> #ifdef CONFIG_OF
> - if (i2c->dev.of_node) {
> - const struct of_device_id *match;
> -
> - match = of_match_node(sec_dt_match, i2c->dev.of_node);
> - return (unsigned long)match->data;
> - }
> + if (i2c->dev.of_node)
> + return (unsigned long)of_device_get_match_data(&i2c->dev);
> #endif

Does it make any sense to keep the #ifdef CONFIG_OF after this change? I
would also skip (i2c->dev.of_node) check, because
of_device_get_match_data() already does that (although indirectly).

> return id->driver_data;
> }

Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland

2021-04-20 07:04:35

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH 5/7] mfd: sec: Simplify getting of_device_id match data

On 20/04/2021 07:25, Marek Szyprowski wrote:
>
> On 19.04.2021 10:17, Krzysztof Kozlowski wrote:
>> Use of_device_get_match_data() to make the code slightly smaller.
>>
>> Signed-off-by: Krzysztof Kozlowski <[email protected]>
>> ---
>> drivers/mfd/sec-core.c | 9 +++------
>> 1 file changed, 3 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/mfd/sec-core.c b/drivers/mfd/sec-core.c
>> index 8d55992da19e..3126c39f3203 100644
>> --- a/drivers/mfd/sec-core.c
>> +++ b/drivers/mfd/sec-core.c
>> @@ -10,6 +10,7 @@
>> #include <linux/slab.h>
>> #include <linux/i2c.h>
>> #include <linux/of.h>
>> +#include <linux/of_device.h>
>> #include <linux/of_irq.h>
>> #include <linux/interrupt.h>
>> #include <linux/pm_runtime.h>
>> @@ -324,12 +325,8 @@ static inline unsigned long sec_i2c_get_driver_data(struct i2c_client *i2c,
>> const struct i2c_device_id *id)
>> {
>> #ifdef CONFIG_OF
>> - if (i2c->dev.of_node) {
>> - const struct of_device_id *match;
>> -
>> - match = of_match_node(sec_dt_match, i2c->dev.of_node);
>> - return (unsigned long)match->data;
>> - }
>> + if (i2c->dev.of_node)
>> + return (unsigned long)of_device_get_match_data(&i2c->dev);
>> #endif
>
> Does it make any sense to keep the #ifdef CONFIG_OF after this change?

Good point, it was only to hide usage of of_device_id table.

> I would also skip (i2c->dev.of_node) check, because
> of_device_get_match_data() already does that (although indirectly).

First, the enum sec_device_type would need to be changed so it starts
from 1, not 0. It's because the value returned by this function is later
assigned to that enum and there is no way currently to differentiate
between NULL and S5M8767X.

Second, it wouldn't make the code smaller;

unsigned long data;
data = of_device_get_match_data(&i2c->dev);
if (data)
return data;

Best regards,
Krzysztof

2021-04-20 07:14:07

by Marek Szyprowski

[permalink] [raw]
Subject: Re: [PATCH 5/7] mfd: sec: Simplify getting of_device_id match data

On 20.04.2021 09:03, Krzysztof Kozlowski wrote:
> On 20/04/2021 07:25, Marek Szyprowski wrote:
>> On 19.04.2021 10:17, Krzysztof Kozlowski wrote:
>>> Use of_device_get_match_data() to make the code slightly smaller.
>>>
>>> Signed-off-by: Krzysztof Kozlowski <[email protected]>
>>> ---
>>> drivers/mfd/sec-core.c | 9 +++------
>>> 1 file changed, 3 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/mfd/sec-core.c b/drivers/mfd/sec-core.c
>>> index 8d55992da19e..3126c39f3203 100644
>>> --- a/drivers/mfd/sec-core.c
>>> +++ b/drivers/mfd/sec-core.c
>>> @@ -10,6 +10,7 @@
>>> #include <linux/slab.h>
>>> #include <linux/i2c.h>
>>> #include <linux/of.h>
>>> +#include <linux/of_device.h>
>>> #include <linux/of_irq.h>
>>> #include <linux/interrupt.h>
>>> #include <linux/pm_runtime.h>
>>> @@ -324,12 +325,8 @@ static inline unsigned long sec_i2c_get_driver_data(struct i2c_client *i2c,
>>> const struct i2c_device_id *id)
>>> {
>>> #ifdef CONFIG_OF
>>> - if (i2c->dev.of_node) {
>>> - const struct of_device_id *match;
>>> -
>>> - match = of_match_node(sec_dt_match, i2c->dev.of_node);
>>> - return (unsigned long)match->data;
>>> - }
>>> + if (i2c->dev.of_node)
>>> + return (unsigned long)of_device_get_match_data(&i2c->dev);
>>> #endif
>> Does it make any sense to keep the #ifdef CONFIG_OF after this change?
> Good point, it was only to hide usage of of_device_id table.
>
>> I would also skip (i2c->dev.of_node) check, because
>> of_device_get_match_data() already does that (although indirectly).
> First, the enum sec_device_type would need to be changed so it starts
> from 1, not 0. It's because the value returned by this function is later
> assigned to that enum and there is no way currently to differentiate
> between NULL and S5M8767X.
>
> Second, it wouldn't make the code smaller;
>
> unsigned long data;
> data = of_device_get_match_data(&i2c->dev);
> if (data)
> return data;

Then maybe one should go further and remove legacy, non-of based
initialization, because it is not used at all. This will simplify it
even more.

Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland

2021-04-20 07:28:20

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH 5/7] mfd: sec: Simplify getting of_device_id match data

On 20/04/2021 09:12, Marek Szyprowski wrote:
> On 20.04.2021 09:03, Krzysztof Kozlowski wrote:
>> On 20/04/2021 07:25, Marek Szyprowski wrote:
>>> On 19.04.2021 10:17, Krzysztof Kozlowski wrote:
>>>> Use of_device_get_match_data() to make the code slightly smaller.
>>>>
>>>> Signed-off-by: Krzysztof Kozlowski <[email protected]>
>>>> ---
>>>> drivers/mfd/sec-core.c | 9 +++------
>>>> 1 file changed, 3 insertions(+), 6 deletions(-)
>>>>
>>>> diff --git a/drivers/mfd/sec-core.c b/drivers/mfd/sec-core.c
>>>> index 8d55992da19e..3126c39f3203 100644
>>>> --- a/drivers/mfd/sec-core.c
>>>> +++ b/drivers/mfd/sec-core.c
>>>> @@ -10,6 +10,7 @@
>>>> #include <linux/slab.h>
>>>> #include <linux/i2c.h>
>>>> #include <linux/of.h>
>>>> +#include <linux/of_device.h>
>>>> #include <linux/of_irq.h>
>>>> #include <linux/interrupt.h>
>>>> #include <linux/pm_runtime.h>
>>>> @@ -324,12 +325,8 @@ static inline unsigned long sec_i2c_get_driver_data(struct i2c_client *i2c,
>>>> const struct i2c_device_id *id)
>>>> {
>>>> #ifdef CONFIG_OF
>>>> - if (i2c->dev.of_node) {
>>>> - const struct of_device_id *match;
>>>> -
>>>> - match = of_match_node(sec_dt_match, i2c->dev.of_node);
>>>> - return (unsigned long)match->data;
>>>> - }
>>>> + if (i2c->dev.of_node)
>>>> + return (unsigned long)of_device_get_match_data(&i2c->dev);
>>>> #endif
>>> Does it make any sense to keep the #ifdef CONFIG_OF after this change?
>> Good point, it was only to hide usage of of_device_id table.
>>
>>> I would also skip (i2c->dev.of_node) check, because
>>> of_device_get_match_data() already does that (although indirectly).
>> First, the enum sec_device_type would need to be changed so it starts
>> from 1, not 0. It's because the value returned by this function is later
>> assigned to that enum and there is no way currently to differentiate
>> between NULL and S5M8767X.
>>
>> Second, it wouldn't make the code smaller;
>>
>> unsigned long data;
>> data = of_device_get_match_data(&i2c->dev);
>> if (data)
>> return data;
>
> Then maybe one should go further and remove legacy, non-of based
> initialization, because it is not used at all. This will simplify it
> even more.

Indeed maybe it's the time to get rid of board-file support...

Thanks for the feedback!

Best regards,
Krzysztof