i2c: mpc: Use devm_clk_get_optional()
Subsystems (2)
PATCH 1/4 i2c: mpc: Use devm_clk_get_optional()
The peripheral clock is optional and we may get an -EPROBE_DEFER error code which would not be propagated correctly, fix this by using devm_clk_get_optional().
--- drivers/i2c/busses/i2c-mpc.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/i2c/busses/i2c-mpc.c +12 -13
@@ -690,17 +690,18 @@ static int fsl_i2c_probe(struct platform_device *op)* enable clock for the I2C peripheral (non fatal), * keep a reference upon successful allocation */ - clk =devm_clk_get (&op->dev,NULL ); -if (!IS_ERR (clk)) { - err =clk_prepare_enable (clk); -if (err) { -dev_err (&op->dev,"failed to enable clock\n" ); -return err; - }else { - i2c->clk_per = clk; - } + clk =devm_clk_get_optional (&op->dev,NULL ); +if (IS_ERR (clk)) +return PTR_ERR (clk); + + err =clk_prepare_enable (clk); +if (err) { +dev_err (&op->dev,"failed to enable clock\n" ); +return err; } + i2c->clk_per = clk; +if (of_property_read_bool (op->dev.of_node,"fsl,preserve-clocking" )) { clock =MPC_I2C_CLOCK_PRESERVE ; }else {
@@ -744,8 +745,7 @@ static int fsl_i2c_probe(struct platform_device *op)return 0 ; fail_add: -if (i2c->clk_per) -clk_disable_unprepare (i2c->clk_per); +clk_disable_unprepare (i2c->clk_per);return result; };
@@ -756,8 +756,7 @@ static int fsl_i2c_remove(struct platform_device *op)i2c_del_adapter (&i2c->adap); -if (i2c->clk_per) -clk_disable_unprepare (i2c->clk_per); +clk_disable_unprepare (i2c->clk_per);return 0 ; };
Signature · 1 line
2.30.2
PATCH 2/4 i2c: mpc: Remove CONFIG_PM_SLEEP ifdeffery
Use __maybe_unused for the suspend()/resume() hooks and get rid of the CONFIG_PM_SLEEP ifdeffery to improve the code.
--- drivers/i2c/busses/i2c-mpc.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/i2c/busses/i2c-mpc.c +2 -10
@@ -66,9 +66,7 @@ struct mpc_i2c {struct i2c_adapter adap;int irq;u32 real_clk; -#ifdef CONFIG_PM_SLEEP u8 fdr, dfsrr; -#endif struct clk *clk_per; };
@@ -761,8 +759,7 @@ static int fsl_i2c_remove(struct platform_device *op)return 0 ; }; -#ifdef CONFIG_PM_SLEEP -static int mpc_i2c_suspend (struct device *dev) +static int __maybe_unused mpc_i2c_suspend (struct device *dev) {struct mpc_i2c *i2c =dev_get_drvdata (dev);
@@ -772,7 +769,7 @@ static int mpc_i2c_suspend(struct device *dev)return 0 ; } -static int mpc_i2c_resume (struct device *dev) +static int __maybe_unused mpc_i2c_resume (struct device *dev) {struct mpc_i2c *i2c =dev_get_drvdata (dev);
@@ -781,12 +778,7 @@ static int mpc_i2c_resume(struct device *dev)return 0 ; } - static SIMPLE_DEV_PM_OPS(mpc_i2c_pm_ops, mpc_i2c_suspend, mpc_i2c_resume); -#define MPC_I2C_PM_OPS (&mpc_i2c_pm_ops) -#else -#define MPC_I2C_PM_OPS NULL -#endif static const struct mpc_i2c_data mpc_i2c_data_512x = { .setup = mpc_i2c_setup_512x,
Signature · 1 line
2.30.2
PATCH 3/4 i2c: mpc: Use device_get_match_data() helper
In reply to Andy ShevchenkoUse the device_get_match_data() helper instead of open coding.
--- drivers/i2c/busses/i2c-mpc.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/i2c/busses/i2c-mpc.c +4 -8
@@ -19,6 +19,7 @@#include <linux/of_address.h> #include <linux/of_irq.h> #include <linux/of_platform.h> +#include <linux/property.h> #include <linux/slab.h> #include <linux/clk.h>
@@ -643,10 +644,9 @@ static struct i2c_bus_recovery_info fsl_i2c_recovery_info = { .recover_bus = fsl_i2c_bus_recovery, }; -static const struct of_device_id mpc_i2c_of_match[];static int fsl_i2c_probe (struct platform_device *op) { -const struct of_device_id *match; +const struct mpc_i2c_data *data;struct mpc_i2c *i2c;const u32 *prop;u32 clock =MPC_I2C_CLOCK_LEGACY ;
@@ -655,10 +655,6 @@ static int fsl_i2c_probe(struct platform_device *op)struct clk *clk;int err; - match =of_match_device (mpc_i2c_of_match, &op->dev); -if (!match) -return -EINVAL ; - i2c =devm_kzalloc (&op->dev,sizeof (*i2c),GFP_KERNEL );if (!i2c)return -ENOMEM ;
@@ -709,8 +705,8 @@ static int fsl_i2c_probe(struct platform_device *op) clock = *prop; } -if (match->data) { -const struct mpc_i2c_data *data = match->data; + data =device_get_match_data (&op->dev); +if (data) { data->setup (op->dev.of_node, i2c, clock); }else {/* Backwards compatibility */
Signature · 1 line
2.30.2
PATCH 4/4 i2c: mpc: Drop duplicate message from devm_platform_ioremap_resource()
In reply to Andy Shevchenkodevm_platform_ioremap_resource() prints a message in case of error. Drop custom one.
--- drivers/i2c/busses/i2c-mpc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/i2c/busses/i2c-mpc.c +1 -3
@@ -664,10 +664,8 @@ static int fsl_i2c_probe(struct platform_device *op)init_waitqueue_head (&i2c->queue); i2c->base =devm_platform_ioremap_resource (op,0 ); -if (IS_ERR (i2c->base)) { -dev_err (i2c->dev,"failed to map controller\n" ); +if (IS_ERR (i2c->base))return PTR_ERR (i2c->base); - } i2c->irq =platform_get_irq (op,0 );if (i2c->irq <0 )
Signature · 1 line
2.30.2
kernel test robot
build botRe: [PATCH v1 2/4] i2c: mpc: Remove CONFIG_PM_SLEEP ifdeffery
In reply to Andy ShevchenkoI love your patch! Yet something to improve:
Hi Andy,
I love your patch! Yet something to improve:
[auto build test ERROR on wsa/i2c/for-next]
[also build test ERROR on next-20210413]
[cannot apply to linux/master linus/master v5.12-rc7]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Andy-Shevchenko/i2c-mpc-Use-devm_clk_get_optional/20210413-223941 base: https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next config: powerpc64-randconfig-r015-20210413 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 9829f5e6b1bca9b61efc629770d28bb9014dec45)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install powerpc64 cross compiling tool for clang build
# apt-get install binutils-powerpc64-linux-gnu
# https://github.com/0day-ci/linux/commit/31fed803b49f17742a0bfa9fb3940b5bc487e4dd
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Andy-Shevchenko/i2c-mpc-Use-devm_clk_get_optional/20210413-223941 git checkout 31fed803b49f17742a0bfa9fb3940b5bc487e4dd
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=powerpc64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> drivers/i2c/busses/i2c-mpc.c:824:9: error: use of undeclared identifier 'MPC_I2C_PM_OPS'
.pm = MPC_I2C_PM_OPS,
^1 error generated.
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for SND_SOC_MPC5200_AC97
Depends on SOUND && !UML && SND && SND_SOC && SND_POWERPC_SOC && PPC_MPC52xx && PPC_BESTCOMM Selected by
- SND_MPC52xx_SOC_EFIKA && SOUND && !UML && SND && SND_SOC && SND_POWERPC_SOC && PPC_EFIKA
vim +/MPC_I2C_PM_OPS +824 drivers/i2c/busses/i2c-mpc.c
0d1cde235874b0 Jon Smirl 2008-06-30 816
8c86cb127b2b76 Kumar Gala 2005-07-27 817 /* Structure for a device driver */
1c48a5c93da631 Grant Likely 2011-02-17 818 static struct platform_driver mpc_i2c_driver = {
8c86cb127b2b76 Kumar Gala 2005-07-27 819 .probe = fsl_i2c_probe,
0b255e927d47b5 Bill Pemberton 2012-11-27 820 .remove = fsl_i2c_remove,
3ae5eaec1d2d9c Russell King 2005-11-09 821 .driver = {
0d1cde235874b0 Jon Smirl 2008-06-30 822 .name = DRV_NAME,
4018294b53d1da Grant Likely 2010-04-13 823 .of_match_table = mpc_i2c_of_match,
0a488c49eac0ad Jingoo Han 2013-07-15 @824 .pm = MPC_I2C_PM_OPS,
3ae5eaec1d2d9c Russell King 2005-11-09 825 },
8c86cb127b2b76 Kumar Gala 2005-07-27 826 };
8c86cb127b2b76 Kumar Gala 2005-07-27 827 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Quoted 5 lines · Andy Shevchenko
The peripheral clock is optional and we may get an -EPROBE_DEFER error code which would not be propagated correctly, fix this by using
devm_clk_get_optional().Signed-off-by Andy Shevchenko <[email protected]>
None of the systems I have access to make use of the clocks property so I can't do much testing. I can say it still handles the absence of a clocks property correctly.
Quoted 56 lines
--- drivers/i2c/busses/i2c-mpc.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)drivers/i2c/busses/i2c-mpc.c +12
-13@@ -690,17 +690,18 @@ static int fsl_i2c_probe(struct platform_device *op)* enable clock for the I2C peripheral (non fatal), * keep a reference upon successful allocation */ - clk =devm_clk_get (&op->dev,NULL ); -if (!IS_ERR (clk)) { - err =clk_prepare_enable (clk); -if (err) { -dev_err (&op->dev,"failed to enable clock\n" ); -return err; - }else { - i2c->clk_per = clk; - } + clk =devm_clk_get_optional (&op->dev,NULL ); +if (IS_ERR (clk)) +return PTR_ERR (clk); + + err =clk_prepare_enable (clk); +if (err) { +dev_err (&op->dev,"failed to enable clock\n" ); +return err; } + i2c->clk_per = clk; +if (of_property_read_bool (op->dev.of_node,"fsl,preserve-clocking" )) { clock =MPC_I2C_CLOCK_PRESERVE ; }else {@@ -744,8 +745,7 @@ static int fsl_i2c_probe(struct platform_device *op)return 0 ; fail_add: -if (i2c->clk_per) -clk_disable_unprepare (i2c->clk_per); +clk_disable_unprepare (i2c->clk_per);return result; };@@ -756,8 +756,7 @@ static int fsl_i2c_remove(struct platform_device *op)i2c_del_adapter (&i2c->adap); -if (i2c->clk_per) -clk_disable_unprepare (i2c->clk_per); +clk_disable_unprepare (i2c->clk_per);return 0 ; };
Chris Packham
maintainerRe: [PATCH v1 2/4] i2c: mpc: Remove CONFIG_PM_SLEEP ifdeffery
In reply to Andy ShevchenkoQuoted 13 lines · Andy Shevchenko
Use
__maybe_unusedfor the suspend()/resume() hooks and get rid of theCONFIG_PM_SLEEPifdeffery to improve the code.Signed-off-by Andy Shevchenko <[email protected]>--- drivers/i2c/busses/i2c-mpc.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)drivers/i2c/busses/i2c-mpc.c +0
-0
drivers/i2c/busses/i2c-mpc.c struct mpc_i2c { · line 71
Quoted 8 lines
drivers/i2c/busses/i2c-mpc.c +0
-2@@ -66,9 +66,7 @@ struct mpc_i2c {struct i2c_adapter adap;int irq;u32 real_clk; -#ifdef CONFIG_PM_SLEEP u8 fdr, dfsrr; -#endif struct clk *clk_per; };
This has a trivial conflict with my series because I'm also touching struct mpc_i2c. git am -3 seems to deal with it but would it be easier if I picked up these 4 changes and included them with my next submission?
Quoted 22 lines
drivers/i2c/busses/i2c-mpc.c +2
-3@@ -761,8 +759,7 @@ static int fsl_i2c_remove(struct platform_device *op)return 0 ; }; -#ifdef CONFIG_PM_SLEEP -static int mpc_i2c_suspend (struct device *dev) +static int __maybe_unused mpc_i2c_suspend (struct device *dev) {struct mpc_i2c *i2c =dev_get_drvdata (dev);@@ -772,7 +769,7 @@ static int mpc_i2c_suspend(struct device *dev)return 0 ; } -static int mpc_i2c_resume (struct device *dev) +static int __maybe_unused mpc_i2c_resume (struct device *dev) {struct mpc_i2c *i2c =dev_get_drvdata (dev);@@ -781,12 +778,7 @@ static int mpc_i2c_resume(struct device *dev)return 0 ;
drivers/i2c/busses/i2c-mpc.c static int mpc_i2c_resume(struct device *dev) · line 784
Quoted 10 lines
drivers/i2c/busses/i2c-mpc.c +0
-5} - static SIMPLE_DEV_PM_OPS(mpc_i2c_pm_ops, mpc_i2c_suspend, mpc_i2c_resume); -#define MPC_I2C_PM_OPS (&mpc_i2c_pm_ops) -#else -#define MPC_I2C_PM_OPS NULL -#endif static const struct mpc_i2c_data mpc_i2c_data_512x = { .setup = mpc_i2c_setup_512x,
There's a reference to MPC_I2C_PM_OPS in mpc_i2c_driver which needs changing I think the following is needed
drivers/i2c/busses/i2c-mpc.c +1 -1
@@ -862,7 +862,7 @@ static struct platform_driver mpc_i2c_driver = { .driver = { .name = DRV_NAME, .of_match_table = mpc_i2c_of_match, - .pm = MPC_I2C_PM_OPS, + .pm = &mpc_i2c_pm_ops, }, };
Re: [PATCH v1 3/4] i2c: mpc: Use device_get_match_data() helper
In reply to Andy ShevchenkoQuoted 3 lines · Andy Shevchenko
Use the
device_get_match_data()helper instead of open coding.Signed-off-by Andy Shevchenko <[email protected]>
Quoted 50 lines
--- drivers/i2c/busses/i2c-mpc.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)drivers/i2c/busses/i2c-mpc.c +4
-8@@ -19,6 +19,7 @@#include <linux/of_address.h> #include <linux/of_irq.h> #include <linux/of_platform.h> +#include <linux/property.h> #include <linux/slab.h> #include <linux/clk.h> @@ -643,10 +644,9 @@ static struct i2c_bus_recovery_info fsl_i2c_recovery_info = { .recover_bus = fsl_i2c_bus_recovery, }; -static const struct of_device_id mpc_i2c_of_match[];static int fsl_i2c_probe (struct platform_device *op) { -const struct of_device_id *match; +const struct mpc_i2c_data *data;struct mpc_i2c *i2c;const u32 *prop;u32 clock =MPC_I2C_CLOCK_LEGACY ;@@ -655,10 +655,6 @@ static int fsl_i2c_probe(struct platform_device *op)struct clk *clk;int err; - match =of_match_device (mpc_i2c_of_match, &op->dev); -if (!match) -return -EINVAL ; - i2c =devm_kzalloc (&op->dev,sizeof (*i2c),GFP_KERNEL );if (!i2c)return -ENOMEM ;@@ -709,8 +705,8 @@ static int fsl_i2c_probe(struct platform_device *op) clock = *prop; } -if (match->data) { -const struct mpc_i2c_data *data = match->data; + data =device_get_match_data (&op->dev); +if (data) { data->setup (op->dev.of_node, i2c, clock); }else {/* Backwards compatibility */
Re: [PATCH v1 4/4] i2c: mpc: Drop duplicate message from devm_platform_ioremap_resource()
In reply to Andy ShevchenkoQuoted 4 lines · Andy Shevchenko
devm_platform_ioremap_resource()prints a message in case of error. Drop custom one.Signed-off-by Andy Shevchenko <[email protected]>
Quoted 20 lines
--- drivers/i2c/busses/i2c-mpc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/i2c/busses/i2c-mpc.c +1
-3@@ -664,10 +664,8 @@ static int fsl_i2c_probe(struct platform_device *op)init_waitqueue_head (&i2c->queue); i2c->base =devm_platform_ioremap_resource (op,0 ); -if (IS_ERR (i2c->base)) { -dev_err (i2c->dev,"failed to map controller\n" ); +if (IS_ERR (i2c->base))return PTR_ERR (i2c->base); - } i2c->irq =platform_get_irq (op,0 );if (i2c->irq <0 )
Re: [PATCH v1 2/4] i2c: mpc: Remove CONFIG_PM_SLEEP ifdeffery
In reply to Chris PackhamQuoted 7 lines · Chris Packham
Quoted 2 lines · Andy Shevchenko
Use
__maybe_unusedfor the suspend()/resume() hooks and get rid of theCONFIG_PM_SLEEPifdeffery to improve the code.This has a trivial conflict with my series because I'm also touching struct
mpc_i2c. git am -3 seems to deal with it but would it be easier if I picked up these 4 changes and included them with my next submission?
It would be ideal to me!
Quoted 10 lines
Review
Quoted 7 lines
(quoted diff) +0
-4-#define MPC_I2C_PM_OPS (&mpc_i2c_pm_ops) -#else -#define MPC_I2C_PM_OPS NULL -#endif static const struct mpc_i2c_data mpc_i2c_data_512x = { .setup = mpc_i2c_setup_512x,There's a reference to
MPC_I2C_PM_OPSinmpc_i2c_driverwhich needs changing I think the following is needed
True. sorry that my build test had been broken.
Tell me if you want v2 with this fixed or you may fold that change since the above agreement.
Quoted 14 lines
drivers/i2c/busses/i2c-mpc.c +1
-1@@ -862,7 +862,7 @@ static struct platform_driver mpc_i2c_driver = { .driver = { .name = DRV_NAME, .of_match_table = mpc_i2c_of_match, - .pm = MPC_I2C_PM_OPS, + .pm = &mpc_i2c_pm_ops, }, };
Signature · 2 lines
With Best Regards, Andy Shevchenko
Chris Packham
maintainerRe: [PATCH v1 2/4] i2c: mpc: Remove CONFIG_PM_SLEEP ifdeffery
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · Chris Packham
Quoted 2 lines · Andy Shevchenko
Use
__maybe_unusedfor the suspend()/resume() hooks and get rid of theCONFIG_PM_SLEEPifdeffery to improve the code.This has a trivial conflict with my series because I'm also touching struct
mpc_i2c. git am -3 seems to deal with it but would it be easier if I picked up these 4 changes and included them with my next submission?It would be ideal to me!
OK I've picked them up.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +0
-4-#define MPC_I2C_PM_OPS (&mpc_i2c_pm_ops) -#else -#define MPC_I2C_PM_OPS NULL -#endif
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
static const struct mpc_i2c_data mpc_i2c_data_512x = { .setup = mpc_i2c_setup_512x,There's a reference to
MPC_I2C_PM_OPSinmpc_i2c_driverwhich needs changing I think the following is neededTrue. sorry that my build test had been broken.
Tell me if you want v2 with this fixed or you may fold that change since the above agreement.
I can fold the fix below in. No need for a v2 from you.
Quoted 14 lines
Quoted 14 lines
drivers/i2c/busses/i2c-mpc.c +1
-1@@ -862,7 +862,7 @@ static struct platform_driver mpc_i2c_driver = { .driver = { .name = DRV_NAME, .of_match_table = mpc_i2c_of_match, - .pm = MPC_I2C_PM_OPS, + .pm = &mpc_i2c_pm_ops, }, };