Linux-i2c Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] i2c: npcm7xx: Support changing bus speed using debugfs.
@ 2020-10-13 10:03 Tali Perry
  2020-10-13 11:50 ` Andy Shevchenko
  2020-10-14  5:30 ` Joel Stanley
  0 siblings, 2 replies; 4+ messages in thread
From: Tali Perry @ 2020-10-13 10:03 UTC (permalink / raw)
  To: wsa, andriy.shevchenko, xqiu, kunyi, benjaminfair, avifishman70,
	joel, tmaimon77
  Cc: linux-i2c, openbmc, linux-kernel, Tali Perry

Systems that can dynamically add and remove slave devices
often need to change the bus speed in runtime.
This patch expose the bus frequency to the user.
This feature can also be used for test automation.

--
v2 -> v1:
	- Fix typos.
	- Remove casting to u64.
	
v1: initial version

Fixes: 56a1485b102e (i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver)
Signed-off-by: Tali Perry <tali.perry1@gmail.com>
---
 drivers/i2c/busses/i2c-npcm7xx.c | 35 ++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c
index 2ad166355ec9..633ac67153e2 100644
--- a/drivers/i2c/busses/i2c-npcm7xx.c
+++ b/drivers/i2c/busses/i2c-npcm7xx.c
@@ -2208,6 +2208,40 @@ static const struct i2c_algorithm npcm_i2c_algo = {
 /* i2c debugfs directory: used to keep health monitor of i2c devices */
 static struct dentry *npcm_i2c_debugfs_dir;
 
+static int i2c_speed_get(void *data, u64 *val)
+{
+	struct npcm_i2c *bus = data;
+
+	*val = bus->bus_freq;
+	return 0;
+}
+
+static int i2c_speed_set(void *data, u64 val)
+{
+	struct npcm_i2c *bus = data;
+	int ret;
+
+	if (val < I2C_FREQ_MIN_HZ || val > I2C_FREQ_MAX_HZ)
+		return -EINVAL;
+
+	if (val == bus->bus_freq)
+		return 0;
+
+	i2c_lock_bus(&bus->adap, I2C_LOCK_ROOT_ADAPTER);
+
+	npcm_i2c_int_enable(bus, false);
+
+	ret = npcm_i2c_init_module(bus, I2C_MASTER, (u32)val);
+
+	i2c_unlock_bus(&bus->adap, I2C_LOCK_ROOT_ADAPTER);
+
+	if (ret)
+		return -EAGAIN;
+
+	return 0;
+}
+DEFINE_DEBUGFS_ATTRIBUTE(i2c_clock_ops, i2c_speed_get, i2c_speed_set, "%llu\n");
+
 static void npcm_i2c_init_debugfs(struct platform_device *pdev,
 				  struct npcm_i2c *bus)
 {
@@ -2223,6 +2257,7 @@ static void npcm_i2c_init_debugfs(struct platform_device *pdev,
 	debugfs_create_u64("rec_succ_cnt", 0444, d, &bus->rec_succ_cnt);
 	debugfs_create_u64("rec_fail_cnt", 0444, d, &bus->rec_fail_cnt);
 	debugfs_create_u64("timeout_cnt", 0444, d, &bus->timeout_cnt);
+	debugfs_create_file("i2c_speed", 0644, d, bus, &i2c_clock_ops);
 
 	bus->debugfs = d;
 }

base-commit: 865c50e1d279671728c2936cb7680eb89355eeea
-- 
2.22.0


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

* Re: [PATCH v2] i2c: npcm7xx: Support changing bus speed using debugfs.
  2020-10-13 10:03 [PATCH v2] i2c: npcm7xx: Support changing bus speed using debugfs Tali Perry
@ 2020-10-13 11:50 ` Andy Shevchenko
  2020-10-13 21:29   ` Alex Qiu
  2020-10-14  5:30 ` Joel Stanley
  1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2020-10-13 11:50 UTC (permalink / raw)
  To: Tali Perry
  Cc: wsa, xqiu, kunyi, benjaminfair, avifishman70, joel, tmaimon77,
	linux-i2c, openbmc, linux-kernel

On Tue, Oct 13, 2020 at 01:03:14PM +0300, Tali Perry wrote:
> Systems that can dynamically add and remove slave devices
> often need to change the bus speed in runtime.
> This patch expose the bus frequency to the user.
> This feature can also be used for test automation.

> --
> v2 -> v1:
> 	- Fix typos.
> 	- Remove casting to u64.
> 	
> v1: initial version

Above block should go after cutter '---' (see below) line...

> Fixes: 56a1485b102e (i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver)
> Signed-off-by: Tali Perry <tali.perry1@gmail.com>
> ---

...here.

>  drivers/i2c/busses/i2c-npcm7xx.c | 35 ++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)

As we discussed previously I'm not a fan of the functionality this gives and a
way it's done, but this is debugfs and not anyhow an ABI. Also it's localized
inside one driver. In the future we may come up with better approach.

That said, no objections from me.

> diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c
> index 2ad166355ec9..633ac67153e2 100644
> --- a/drivers/i2c/busses/i2c-npcm7xx.c
> +++ b/drivers/i2c/busses/i2c-npcm7xx.c
> @@ -2208,6 +2208,40 @@ static const struct i2c_algorithm npcm_i2c_algo = {
>  /* i2c debugfs directory: used to keep health monitor of i2c devices */
>  static struct dentry *npcm_i2c_debugfs_dir;
>  
> +static int i2c_speed_get(void *data, u64 *val)
> +{
> +	struct npcm_i2c *bus = data;
> +
> +	*val = bus->bus_freq;
> +	return 0;
> +}
> +
> +static int i2c_speed_set(void *data, u64 val)
> +{
> +	struct npcm_i2c *bus = data;
> +	int ret;
> +
> +	if (val < I2C_FREQ_MIN_HZ || val > I2C_FREQ_MAX_HZ)
> +		return -EINVAL;
> +
> +	if (val == bus->bus_freq)
> +		return 0;
> +
> +	i2c_lock_bus(&bus->adap, I2C_LOCK_ROOT_ADAPTER);
> +
> +	npcm_i2c_int_enable(bus, false);
> +
> +	ret = npcm_i2c_init_module(bus, I2C_MASTER, (u32)val);
> +
> +	i2c_unlock_bus(&bus->adap, I2C_LOCK_ROOT_ADAPTER);
> +
> +	if (ret)
> +		return -EAGAIN;
> +
> +	return 0;
> +}
> +DEFINE_DEBUGFS_ATTRIBUTE(i2c_clock_ops, i2c_speed_get, i2c_speed_set, "%llu\n");
> +
>  static void npcm_i2c_init_debugfs(struct platform_device *pdev,
>  				  struct npcm_i2c *bus)
>  {
> @@ -2223,6 +2257,7 @@ static void npcm_i2c_init_debugfs(struct platform_device *pdev,
>  	debugfs_create_u64("rec_succ_cnt", 0444, d, &bus->rec_succ_cnt);
>  	debugfs_create_u64("rec_fail_cnt", 0444, d, &bus->rec_fail_cnt);
>  	debugfs_create_u64("timeout_cnt", 0444, d, &bus->timeout_cnt);
> +	debugfs_create_file("i2c_speed", 0644, d, bus, &i2c_clock_ops);
>  
>  	bus->debugfs = d;
>  }
> 
> base-commit: 865c50e1d279671728c2936cb7680eb89355eeea
> -- 
> 2.22.0
> 

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2] i2c: npcm7xx: Support changing bus speed using debugfs.
  2020-10-13 11:50 ` Andy Shevchenko
@ 2020-10-13 21:29   ` Alex Qiu
  0 siblings, 0 replies; 4+ messages in thread
From: Alex Qiu @ 2020-10-13 21:29 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Tali Perry, Wolfram Sang, Kun Yi, Benjamin Fair, Avi Fishman,
	Joel Stanley, Tomer Maimon, Linux I2C, OpenBMC Maillist,
	Linux Kernel Mailing List

Tested again, and the updated patch is still working.

On Tue, Oct 13, 2020 at 4:49 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Tue, Oct 13, 2020 at 01:03:14PM +0300, Tali Perry wrote:
> > Systems that can dynamically add and remove slave devices
> > often need to change the bus speed in runtime.
> > This patch expose the bus frequency to the user.
> > This feature can also be used for test automation.
>
> > --
> > v2 -> v1:
> >       - Fix typos.
> >       - Remove casting to u64.
> >
> > v1: initial version
>
> Above block should go after cutter '---' (see below) line...
>
> > Fixes: 56a1485b102e (i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver)
> > Signed-off-by: Tali Perry <tali.perry1@gmail.com>
Reviewed-by: Alex Qiu <xqiu@google.com>
Tested-by: Alex Qiu <xqiu@google.com>

> > ---
>
> ...here.
>
> >  drivers/i2c/busses/i2c-npcm7xx.c | 35 ++++++++++++++++++++++++++++++++
> >  1 file changed, 35 insertions(+)
>
> As we discussed previously I'm not a fan of the functionality this gives and a
> way it's done, but this is debugfs and not anyhow an ABI. Also it's localized
> inside one driver. In the future we may come up with better approach.
>
> That said, no objections from me.
>
> > diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c
> > index 2ad166355ec9..633ac67153e2 100644
> > --- a/drivers/i2c/busses/i2c-npcm7xx.c
> > +++ b/drivers/i2c/busses/i2c-npcm7xx.c
> > @@ -2208,6 +2208,40 @@ static const struct i2c_algorithm npcm_i2c_algo = {
> >  /* i2c debugfs directory: used to keep health monitor of i2c devices */
> >  static struct dentry *npcm_i2c_debugfs_dir;
> >
> > +static int i2c_speed_get(void *data, u64 *val)
> > +{
> > +     struct npcm_i2c *bus = data;
> > +
> > +     *val = bus->bus_freq;
> > +     return 0;
> > +}
> > +
> > +static int i2c_speed_set(void *data, u64 val)
> > +{
> > +     struct npcm_i2c *bus = data;
> > +     int ret;
> > +
> > +     if (val < I2C_FREQ_MIN_HZ || val > I2C_FREQ_MAX_HZ)
> > +             return -EINVAL;
> > +
> > +     if (val == bus->bus_freq)
> > +             return 0;
> > +
> > +     i2c_lock_bus(&bus->adap, I2C_LOCK_ROOT_ADAPTER);
> > +
> > +     npcm_i2c_int_enable(bus, false);
> > +
> > +     ret = npcm_i2c_init_module(bus, I2C_MASTER, (u32)val);
> > +
> > +     i2c_unlock_bus(&bus->adap, I2C_LOCK_ROOT_ADAPTER);
> > +
> > +     if (ret)
> > +             return -EAGAIN;
> > +
> > +     return 0;
> > +}
> > +DEFINE_DEBUGFS_ATTRIBUTE(i2c_clock_ops, i2c_speed_get, i2c_speed_set, "%llu\n");
> > +
> >  static void npcm_i2c_init_debugfs(struct platform_device *pdev,
> >                                 struct npcm_i2c *bus)
> >  {
> > @@ -2223,6 +2257,7 @@ static void npcm_i2c_init_debugfs(struct platform_device *pdev,
> >       debugfs_create_u64("rec_succ_cnt", 0444, d, &bus->rec_succ_cnt);
> >       debugfs_create_u64("rec_fail_cnt", 0444, d, &bus->rec_fail_cnt);
> >       debugfs_create_u64("timeout_cnt", 0444, d, &bus->timeout_cnt);
> > +     debugfs_create_file("i2c_speed", 0644, d, bus, &i2c_clock_ops);
> >
> >       bus->debugfs = d;
> >  }
> >
> > base-commit: 865c50e1d279671728c2936cb7680eb89355eeea
> > --
> > 2.22.0
> >
>
> --
> With Best Regards,
> Andy Shevchenko
>
>

- Alex Qiu

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

* Re: [PATCH v2] i2c: npcm7xx: Support changing bus speed using debugfs.
  2020-10-13 10:03 [PATCH v2] i2c: npcm7xx: Support changing bus speed using debugfs Tali Perry
  2020-10-13 11:50 ` Andy Shevchenko
@ 2020-10-14  5:30 ` Joel Stanley
  1 sibling, 0 replies; 4+ messages in thread
From: Joel Stanley @ 2020-10-14  5:30 UTC (permalink / raw)
  To: Tali Perry
  Cc: wsa, andriy.shevchenko, xqiu, Kun Yi, Benjamin Fair, Avi Fishman,
	Tomer Maimon, linux-i2c, OpenBMC Maillist,
	Linux Kernel Mailing List

On Tue, 13 Oct 2020 at 10:03, Tali Perry <tali.perry1@gmail.com> wrote:
>
> Systems that can dynamically add and remove slave devices
> often need to change the bus speed in runtime.
> This patch expose the bus frequency to the user.
> This feature can also be used for test automation.
>
> --
> v2 -> v1:
>         - Fix typos.
>         - Remove casting to u64.
>
> v1: initial version
>
> Fixes: 56a1485b102e (i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver)
> Signed-off-by: Tali Perry <tali.perry1@gmail.com>

Reviewed-by: Joel Stanley <joel@jms.id.au>

I'm not sure that the Fixes tag is quite correct, but it's no biggie.


> ---
>  drivers/i2c/busses/i2c-npcm7xx.c | 35 ++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
>
> diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c
> index 2ad166355ec9..633ac67153e2 100644
> --- a/drivers/i2c/busses/i2c-npcm7xx.c
> +++ b/drivers/i2c/busses/i2c-npcm7xx.c
> @@ -2208,6 +2208,40 @@ static const struct i2c_algorithm npcm_i2c_algo = {
>  /* i2c debugfs directory: used to keep health monitor of i2c devices */
>  static struct dentry *npcm_i2c_debugfs_dir;
>
> +static int i2c_speed_get(void *data, u64 *val)
> +{
> +       struct npcm_i2c *bus = data;
> +
> +       *val = bus->bus_freq;
> +       return 0;
> +}
> +
> +static int i2c_speed_set(void *data, u64 val)
> +{
> +       struct npcm_i2c *bus = data;
> +       int ret;
> +
> +       if (val < I2C_FREQ_MIN_HZ || val > I2C_FREQ_MAX_HZ)
> +               return -EINVAL;
> +
> +       if (val == bus->bus_freq)
> +               return 0;
> +
> +       i2c_lock_bus(&bus->adap, I2C_LOCK_ROOT_ADAPTER);
> +
> +       npcm_i2c_int_enable(bus, false);
> +
> +       ret = npcm_i2c_init_module(bus, I2C_MASTER, (u32)val);
> +
> +       i2c_unlock_bus(&bus->adap, I2C_LOCK_ROOT_ADAPTER);
> +
> +       if (ret)
> +               return -EAGAIN;
> +
> +       return 0;
> +}
> +DEFINE_DEBUGFS_ATTRIBUTE(i2c_clock_ops, i2c_speed_get, i2c_speed_set, "%llu\n");
> +
>  static void npcm_i2c_init_debugfs(struct platform_device *pdev,
>                                   struct npcm_i2c *bus)
>  {
> @@ -2223,6 +2257,7 @@ static void npcm_i2c_init_debugfs(struct platform_device *pdev,
>         debugfs_create_u64("rec_succ_cnt", 0444, d, &bus->rec_succ_cnt);
>         debugfs_create_u64("rec_fail_cnt", 0444, d, &bus->rec_fail_cnt);
>         debugfs_create_u64("timeout_cnt", 0444, d, &bus->timeout_cnt);
> +       debugfs_create_file("i2c_speed", 0644, d, bus, &i2c_clock_ops);
>
>         bus->debugfs = d;
>  }
>
> base-commit: 865c50e1d279671728c2936cb7680eb89355eeea
> --
> 2.22.0
>

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-13 10:03 [PATCH v2] i2c: npcm7xx: Support changing bus speed using debugfs Tali Perry
2020-10-13 11:50 ` Andy Shevchenko
2020-10-13 21:29   ` Alex Qiu
2020-10-14  5:30 ` Joel Stanley

Linux-i2c Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-i2c/0 linux-i2c/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-i2c linux-i2c/ https://lore.kernel.org/linux-i2c \
		linux-i2c@vger.kernel.org
	public-inbox-index linux-i2c

Example config snippet for mirrors

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


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