All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] i2c: core: helper function to detect slave mode
@ 2017-01-17 14:33 Luis Oliveira
  2017-01-25 20:45 ` Wolfram Sang
  0 siblings, 1 reply; 7+ messages in thread
From: Luis Oliveira @ 2017-01-17 14:33 UTC (permalink / raw)
  To: wsa, robh+dt, mark.rutland, jarkko.nikula, andriy.shevchenko,
	mika.westerberg, linux-i2c, devicetree, linux-kernel, vz
  Cc: Luis.Oliveira, Ramiro.Oliveira, Joao.Pinto, CARLOS.PALMINHA

This function has the purpose of mode detection by checking the
device nodes for a reg matching with the I2C_OWN_SLAVE_ADDREESS flag.
Currently only checks using OF functions (ACPI slave not supported yet).

Signed-off-by: Luis Oliveira <lolivei@synopsys.com>
Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
Changes V2->V3: (@Vladimir)
- Bug Fix: «of_node_put(child)» added.

 drivers/i2c/i2c-core.c | 30 ++++++++++++++++++++++++++++++
 include/linux/i2c.h    |  1 +
 2 files changed, 31 insertions(+)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 583e95042a21..30aa7b50b5bc 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -3690,6 +3690,36 @@ int i2c_slave_unregister(struct i2c_client *client)
 	return ret;
 }
 EXPORT_SYMBOL_GPL(i2c_slave_unregister);
+
+/**
+ * i2c_slave_mode_detect - detect operation mode
+ * @dev:  The device owning the bus
+ *
+ * This checks the device nodes for an I2C slave by checking the address
+ * used.
+ *
+ * Returns true if an I2C slave is detected, otherwise returns false.
+ */
+bool i2c_slave_mode_detect(struct device *dev)
+{
+	if (IS_BUILTIN(CONFIG_OF) && dev->of_node) {
+		struct device_node *child;
+		u32 reg;
+
+		for_each_child_of_node(dev->of_node, child) {
+			of_property_read_u32(child, "reg", &reg);
+			if (reg & I2C_OWN_SLAVE_ADDRESS) {
+				of_node_put(child);
+				return true;
+			}
+		}
+	} else if (IS_BUILTIN(CONFIG_ACPI) && ACPI_HANDLE(dev)) {
+		dev_dbg(dev, "ACPI slave is not supported yet\n");
+	}
+	return false;
+}
+EXPORT_SYMBOL_GPL(i2c_slave_mode_detect);
+
 #endif
 
 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 4b45ec46161f..2e72e157826c 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -282,6 +282,7 @@ enum i2c_slave_event {
 
 extern int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb);
 extern int i2c_slave_unregister(struct i2c_client *client);
+extern bool i2c_slave_mode_detect(struct device *dev);
 
 static inline int i2c_slave_event(struct i2c_client *client,
 				  enum i2c_slave_event event, u8 *val)
-- 
2.11.0

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

* Re: [PATCH v3] i2c: core: helper function to detect slave mode
  2017-01-17 14:33 [PATCH v3] i2c: core: helper function to detect slave mode Luis Oliveira
@ 2017-01-25 20:45 ` Wolfram Sang
  2017-01-25 20:50   ` Andy Shevchenko
  2017-01-26 11:49     ` Luis Oliveira
  0 siblings, 2 replies; 7+ messages in thread
From: Wolfram Sang @ 2017-01-25 20:45 UTC (permalink / raw)
  To: Luis Oliveira
  Cc: robh+dt, mark.rutland, jarkko.nikula, andriy.shevchenko,
	mika.westerberg, linux-i2c, devicetree, linux-kernel, vz,
	Ramiro.Oliveira, Joao.Pinto, CARLOS.PALMINHA

[-- Attachment #1: Type: text/plain, Size: 558 bytes --]


> + * i2c_slave_mode_detect - detect operation mode

I'd rather name it 'i2c_detect_slave_mode'

> + * @dev:  The device owning the bus
> + *
> + * This checks the device nodes for an I2C slave by checking the address
> + * used.
> + *
> + * Returns true if an I2C slave is detected, otherwise returns false.

Both paragraphs could be a little more explicit. It is not about
"slaves" or "clients" in general, but about those entries which make the
current master act as a slave, too.

The code looks good to me, so we are close to go!

Thanks,

   Wolfram


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v3] i2c: core: helper function to detect slave mode
  2017-01-25 20:45 ` Wolfram Sang
@ 2017-01-25 20:50   ` Andy Shevchenko
  2017-01-25 21:01     ` Wolfram Sang
  2017-01-26 11:49     ` Luis Oliveira
  1 sibling, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2017-01-25 20:50 UTC (permalink / raw)
  To: Wolfram Sang, Luis Oliveira
  Cc: robh+dt, mark.rutland, jarkko.nikula, mika.westerberg, linux-i2c,
	devicetree, linux-kernel, vz, Ramiro.Oliveira, Joao.Pinto,
	CARLOS.PALMINHA

On Wed, 2017-01-25 at 21:45 +0100, Wolfram Sang wrote:
> > + * i2c_slave_mode_detect - detect operation mode
> 
> I'd rather name it 'i2c_detect_slave_mode'

When I proposed that I kept in ming `git grep -n i2c_slave`.

> The code looks good to me, so we are close to go!

Thumb up!

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

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

* Re: [PATCH v3] i2c: core: helper function to detect slave mode
  2017-01-25 20:50   ` Andy Shevchenko
@ 2017-01-25 21:01     ` Wolfram Sang
  2017-01-25 21:29       ` Andy Shevchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Wolfram Sang @ 2017-01-25 21:01 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Luis Oliveira, robh+dt, mark.rutland, jarkko.nikula,
	mika.westerberg, linux-i2c, devicetree, linux-kernel, vz,
	Ramiro.Oliveira, Joao.Pinto, CARLOS.PALMINHA

[-- Attachment #1: Type: text/plain, Size: 485 bytes --]

On Wed, Jan 25, 2017 at 10:50:09PM +0200, Andy Shevchenko wrote:
> On Wed, 2017-01-25 at 21:45 +0100, Wolfram Sang wrote:
> > > + * i2c_slave_mode_detect - detect operation mode
> > 
> > I'd rather name it 'i2c_detect_slave_mode'
> 
> When I proposed that I kept in ming `git grep -n i2c_slave`.

"i2c.*slave"? :)

I think having the verb first makes function names more comprehensible.
i2c-core is not super consistent with that, but I'd say more follow this
than not.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v3] i2c: core: helper function to detect slave mode
  2017-01-25 21:01     ` Wolfram Sang
@ 2017-01-25 21:29       ` Andy Shevchenko
  0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2017-01-25 21:29 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Andy Shevchenko, Luis Oliveira, Rob Herring, Mark Rutland,
	Jarkko Nikula, Mika Westerberg, linux-i2c, devicetree,
	linux-kernel, Vladimir Zapolskiy, Ramiro.Oliveira, Joao Pinto,
	CARLOS.PALMINHA

On Wed, Jan 25, 2017 at 11:01 PM, Wolfram Sang <wsa@the-dreams.de> wrote:
> On Wed, Jan 25, 2017 at 10:50:09PM +0200, Andy Shevchenko wrote:
>> On Wed, 2017-01-25 at 21:45 +0100, Wolfram Sang wrote:
>> > > + * i2c_slave_mode_detect - detect operation mode
>> >
>> > I'd rather name it 'i2c_detect_slave_mode'
>>
>> When I proposed that I kept in ming `git grep -n i2c_slave`.
>
> "i2c.*slave"? :)

'i2c[a-z_]\+slave'

> I think having the verb first makes function names more comprehensible.
> i2c-core is not super consistent with that, but I'd say more follow this
> than not.

I'm okay with either.

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH v3] i2c: core: helper function to detect slave mode
  2017-01-25 20:45 ` Wolfram Sang
@ 2017-01-26 11:49     ` Luis Oliveira
  2017-01-26 11:49     ` Luis Oliveira
  1 sibling, 0 replies; 7+ messages in thread
From: Luis Oliveira @ 2017-01-26 11:49 UTC (permalink / raw)
  To: Wolfram Sang, Luis Oliveira
  Cc: robh+dt, mark.rutland, jarkko.nikula, andriy.shevchenko,
	mika.westerberg, linux-i2c, devicetree, linux-kernel, vz,
	Ramiro.Oliveira, Joao.Pinto, CARLOS.PALMINHA

On 25-Jan-17 20:45, Wolfram Sang wrote:
> 
>> + * i2c_slave_mode_detect - detect operation mode
> 
> I'd rather name it 'i2c_detect_slave_mode'

I will do a V4 with this change.

> 
>> + * @dev:  The device owning the bus
>> + *
>> + * This checks the device nodes for an I2C slave by checking the address
>> + * used.
>> + *
>> + * Returns true if an I2C slave is detected, otherwise returns false.
> 
> Both paragraphs could be a little more explicit. It is not about
> "slaves" or "clients" in general, but about those entries which make the
> current master act as a slave, too.
> 

Ok, I see your point of view. I will reword it also.

> The code looks good to me, so we are close to go!
> 
> Thanks,
> 
>    Wolfram
> 

Great! Thanks

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

* Re: [PATCH v3] i2c: core: helper function to detect slave mode
@ 2017-01-26 11:49     ` Luis Oliveira
  0 siblings, 0 replies; 7+ messages in thread
From: Luis Oliveira @ 2017-01-26 11:49 UTC (permalink / raw)
  To: Wolfram Sang, Luis Oliveira
  Cc: robh+dt, mark.rutland, jarkko.nikula, andriy.shevchenko,
	mika.westerberg, linux-i2c, devicetree, linux-kernel, vz,
	Ramiro.Oliveira, Joao.Pinto, CARLOS.PALMINHA

On 25-Jan-17 20:45, Wolfram Sang wrote:
> 
>> + * i2c_slave_mode_detect - detect operation mode
> 
> I'd rather name it 'i2c_detect_slave_mode'

I will do a V4 with this change.

> 
>> + * @dev:  The device owning the bus
>> + *
>> + * This checks the device nodes for an I2C slave by checking the address
>> + * used.
>> + *
>> + * Returns true if an I2C slave is detected, otherwise returns false.
> 
> Both paragraphs could be a little more explicit. It is not about
> "slaves" or "clients" in general, but about those entries which make the
> current master act as a slave, too.
> 

Ok, I see your point of view. I will reword it also.

> The code looks good to me, so we are close to go!
> 
> Thanks,
> 
>    Wolfram
> 

Great! Thanks

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

end of thread, other threads:[~2017-01-26 11:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-17 14:33 [PATCH v3] i2c: core: helper function to detect slave mode Luis Oliveira
2017-01-25 20:45 ` Wolfram Sang
2017-01-25 20:50   ` Andy Shevchenko
2017-01-25 21:01     ` Wolfram Sang
2017-01-25 21:29       ` Andy Shevchenko
2017-01-26 11:49   ` Luis Oliveira
2017-01-26 11:49     ` Luis Oliveira

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.