linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
To: "Pali Rohár" <pali.rohar@gmail.com>
Cc: "Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
	"Wolfram Sang" <wsa@the-dreams.de>,
	"Michał Kępień" <kernel@kempniu.pl>,
	"Jean Delvare" <jdelvare@suse.com>,
	"Steven Honeyman" <stevenhoneyman@gmail.com>,
	Valdis.Kletnieks@vt.edu,
	"Jochen Eisinger" <jochen@penguin-breeder.org>,
	"Gabriele Mazzotta" <gabriele.mzt@gmail.com>,
	"Andy Lutomirski" <luto@kernel.org>,
	Mario_Limonciello@dell.com, "Alex Hung" <alex.hung@canonical.com>,
	"Takashi Iwai" <tiwai@suse.de>,
	linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
	platform-driver-x86@vger.kernel.org
Subject: Re: [PATCH] i2c: i801: Register optional lis3lv02d i2c device on Dell machines
Date: Thu, 5 Jan 2017 10:26:54 +0100	[thread overview]
Message-ID: <20170105092654.GC15702@mail.corp.redhat.com> (raw)
In-Reply-To: <20170105085419.GB31083@pali>

On Jan 05 2017 or thereabouts, Pali Rohár wrote:
> On Wednesday 04 January 2017 09:54:56 Dmitry Torokhov wrote:
> > On Wed, Jan 04, 2017 at 06:46:19PM +0100, Wolfram Sang wrote:
> > > 
> > > > How about:
> > > > ---
> > > > From daa7571bbf337704332c0cfeec9b8fd5aeae596f Mon Sep 17 00:00:00 2001
> > > > From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
> > > > Date: Wed, 4 Jan 2017 18:26:54 +0100
> > > > Subject: [PATCH] I2C: add the source of the IRQ in struct i2c_client
> > > > 
> > > > With commit 4d5538f5882a ("i2c: use an IRQ to report Host Notify events,
> > > > not alert"), the IRQ provided in struct i2c_client might be assigned while
> > > > it has not been explicitly declared by either the platform information
> > > > or OF or ACPI.
> > > > Some drivers (lis3lv02d) rely on the fact that the IRQ gets assigned or
> > > > not to trigger a different behavior (exposing /dev/freefall in this case).
> > > > 
> > > > Provide a way for others to know who set the IRQ and so they can behave
> > > > accordingly.
> > > > 
> > > > Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
> > > > ---
> > > >  drivers/i2c/i2c-core.c |  7 +++++++
> > > >  include/linux/i2c.h    | 11 +++++++++++
> > > >  2 files changed, 18 insertions(+)
> > > > 
> > > > diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> > > > index cf9e396..226c75d 100644
> > > > --- a/drivers/i2c/i2c-core.c
> > > > +++ b/drivers/i2c/i2c-core.c
> > > > @@ -935,8 +935,12 @@ static int i2c_device_probe(struct device *dev)
> > > >  			irq = of_irq_get_byname(dev->of_node, "irq");
> > > >  			if (irq == -EINVAL || irq == -ENODATA)
> > > >  				irq = of_irq_get(dev->of_node, 0);
> > > > +			if (irq > 0)
> > > > +				client->irq_source = I2C_IRQ_SOURCE_OF;
> > > >  		} else if (ACPI_COMPANION(dev)) {
> > > >  			irq = acpi_dev_gpio_irq_get(ACPI_COMPANION(dev), 0);
> > > > +			if (irq > 0)
> > > > +				client->irq_source = I2C_IRQ_SOURCE_ACPI;
> > > >  		}
> > > >  		if (irq == -EPROBE_DEFER)
> > > >  			return irq;
> > > > @@ -947,6 +951,8 @@ static int i2c_device_probe(struct device *dev)
> > > >  		if (irq < 0) {
> > > >  			dev_dbg(dev, "Using Host Notify IRQ\n");
> > > >  			irq = i2c_smbus_host_notify_to_irq(client);
> > > > +			if (irq > 0)
> > > > +				client->irq_source = I2C_IRQ_SOURCE_HOST_NOTIFY;
> > > >  		}
> > > >  		if (irq < 0)
> > > >  			irq = 0;
> > > > @@ -1317,6 +1323,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
> > > >  	client->flags = info->flags;
> > > >  	client->addr = info->addr;
> > > >  	client->irq = info->irq;
> > > > +	client->irq_source = I2C_IRQ_SOURCE_PLATFORM;
> > > >  
> > > >  	strlcpy(client->name, info->type, sizeof(client->name));
> > > >  
> > > > diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> > > > index b2109c5..7d0368d 100644
> > > > --- a/include/linux/i2c.h
> > > > +++ b/include/linux/i2c.h
> > > > @@ -213,6 +213,13 @@ struct i2c_driver {
> > > >  };
> > > >  #define to_i2c_driver(d) container_of(d, struct i2c_driver, driver)
> > > >  
> > > > +enum i2c_irq_source {
> > > > +	I2C_IRQ_SOURCE_PLATFORM,
> > > > +	I2C_IRQ_SOURCE_OF,
> > > > +	I2C_IRQ_SOURCE_ACPI,
> > > > +	I2C_IRQ_SOURCE_HOST_NOTIFY,
> > > > +};
> > > > +
> > > >  /**
> > > >   * struct i2c_client - represent an I2C slave device
> > > >   * @flags: I2C_CLIENT_TEN indicates the device uses a ten bit chip address;
> > > > @@ -227,6 +234,9 @@ struct i2c_driver {
> > > >   *	userspace_devices list
> > > >   * @slave_cb: Callback when I2C slave mode of an adapter is used. The adapter
> > > >   *	calls it to pass on slave events to the slave driver.
> > > > + * @irq_source: Enum which provides the source of the IRQ. Useful to know
> > > > + * 	if the IRQ was issued from Host Notify or if it was provided by an other
> > > > + * 	component.
> > > 
> > > I'd think some documentation somewhere makes sense why we need to
> > > distinguish this in some cases?
> > 
> > I'd rather drivers be oblivious of the source of interrupt. If they need
> > to distinguish between them that means that our IRQ abstration failed.
> > 
> > > 
> > > >   *
> > > >   * An i2c_client identifies a single device (i.e. chip) connected to an
> > > >   * i2c bus. The behaviour exposed to Linux is defined by the driver
> > > > @@ -245,6 +255,7 @@ struct i2c_client {
> > > >  #if IS_ENABLED(CONFIG_I2C_SLAVE)
> > > >  	i2c_slave_cb_t slave_cb;	/* callback for slave mode	*/
> > > >  #endif
> > > > +	enum i2c_irq_source irq_source;	/* which component assigned the irq */
> > > >  };
> > > >  #define to_i2c_client(d) container_of(d, struct i2c_client, dev)
> > > > 
> > > > Dmitry, Wolfram, Jean, would this be acceptable for you?
> > > 
> > > Adding something to i2c_driver is not exactly cheap, but from what I
> > > glimpsed from this thread, this is one of the cleanest solution to this
> > > problem?
> > > 
> > 
> > As Benjamin said, it is really property of device [instance], not
> > driver. I.e. driver could handle both wired IRQ and HostNotify-based
> > scheme similarly, it is device (and board) that knows how stuff is
> > connected.
> > 
> > Maybe we could do something like this (untested):
> > 
> > 
> > From e362a0277fd1bd6112f258664d8831d9bc6b78da Mon Sep 17 00:00:00 2001
> > From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> > Date: Wed, 4 Jan 2017 09:33:43 -0800
> > Subject: [PATCH] i2c: do not enable fall back to Host Notify by default
> > 
> > Falling back unconditionally to HostNotify as primary client's interrupt
> > breaks some drivers which alter their functionality depending on whether
> > interrupt is present or not, so let's introduce a board flag telling I2C
> > core explicitly if we want wired interrupt or HostNotify-based one:
> > I2C_CLIENT_HOST_NOTIFY.
> > 
> > For DT-based systems we introduce "host-notofy" property that we convert
> > to I2C_CLIENT_HOST_NOTIFY board flag.
> > 
> > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> > ---
> >  Documentation/devicetree/bindings/i2c/i2c.txt |  8 ++++++++
> >  drivers/i2c/i2c-core.c                        | 17 ++++++++---------
> >  include/linux/i2c.h                           |  1 +
> >  3 files changed, 17 insertions(+), 9 deletions(-)
> > 
> > diff --git a/Documentation/devicetree/bindings/i2c/i2c.txt b/Documentation/devicetree/bindings/i2c/i2c.txt
> > index 5fa691e6f638..cee9d5055fa2 100644
> > --- a/Documentation/devicetree/bindings/i2c/i2c.txt
> > +++ b/Documentation/devicetree/bindings/i2c/i2c.txt
> > @@ -62,6 +62,9 @@ wants to support one of the below features, it should adapt the bindings below.
> >  	"irq" and "wakeup" names are recognized by I2C core, other names are
> >  	left to individual drivers.
> >  
> > +- host-notify
> > +	device uses SMBus host notify protocol instead of interrupt line.
> > +
> >  - multi-master
> >  	states that there is another master active on this bus. The OS can use
> >  	this information to adapt power management to keep the arbitration awake
> > @@ -81,6 +84,11 @@ Binding may contain optional "interrupts" property, describing interrupts
> >  used by the device. I2C core will assign "irq" interrupt (or the very first
> >  interrupt if not using interrupt names) as primary interrupt for the slave.
> >  
> > +Alternatively, devices supporting SMbus Host Notify, and connected to
> > +adapters that support this feature, may use "host-notify" property. I2C
> > +core will create a virtual interrupt for Host Notify and assign it as
> > +primary interrupt for the slave.
> > +
> >  Also, if device is marked as a wakeup source, I2C core will set up "wakeup"
> >  interrupt for the device. If "wakeup" interrupt name is not present in the
> >  binding, then primary interrupt will be used as wakeup interrupt.
> > diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> > index cf9e396d7702..250969fa7670 100644
> > --- a/drivers/i2c/i2c-core.c
> > +++ b/drivers/i2c/i2c-core.c
> > @@ -931,7 +931,10 @@ static int i2c_device_probe(struct device *dev)
> >  	if (!client->irq) {
> >  		int irq = -ENOENT;
> >  
> > -		if (dev->of_node) {
> > +		if (client->flags & I2C_CLIENT_HOST_HOTIFY) {
> > +			dev_dbg(dev, "Using Host Notify IRQ\n");
> > +			irq = i2c_smbus_host_notify_to_irq(client);
> > +		} else if (dev->of_node) {
> >  			irq = of_irq_get_byname(dev->of_node, "irq");
> >  			if (irq == -EINVAL || irq == -ENODATA)
> >  				irq = of_irq_get(dev->of_node, 0);
> > @@ -940,14 +943,7 @@ static int i2c_device_probe(struct device *dev)
> >  		}
> >  		if (irq == -EPROBE_DEFER)
> >  			return irq;
> > -		/*
> > -		 * ACPI and OF did not find any useful IRQ, try to see
> > -		 * if Host Notify can be used.
> > -		 */
> > -		if (irq < 0) {
> > -			dev_dbg(dev, "Using Host Notify IRQ\n");
> > -			irq = i2c_smbus_host_notify_to_irq(client);
> > -		}
> > +
> >  		if (irq < 0)
> >  			irq = 0;
> >  
> > @@ -1716,6 +1712,9 @@ static struct i2c_client *of_i2c_register_device(struct i2c_adapter *adap,
> >  	info.of_node = of_node_get(node);
> >  	info.archdata = &dev_ad;
> >  
> > +	if (of_read_property_bool(node, "host-notify"))
> > +		info.flags |= I2C_CLIENT_HOST_NOTIFY;
> > +
> >  	if (of_get_property(node, "wakeup-source", NULL))
> >  		info.flags |= I2C_CLIENT_WAKE;
> >  
> > diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> > index b2109c522dec..4b45ec46161f 100644
> > --- a/include/linux/i2c.h
> > +++ b/include/linux/i2c.h
> > @@ -665,6 +665,7 @@ i2c_unlock_adapter(struct i2c_adapter *adapter)
> >  #define I2C_CLIENT_TEN		0x10	/* we have a ten bit chip address */
> >  					/* Must equal I2C_M_TEN below */
> >  #define I2C_CLIENT_SLAVE	0x20	/* we are the slave */
> > +#define I2C_CLIENT_HOST_NOTIFY	0x40	/* We want to use I2C host notify */
> >  #define I2C_CLIENT_WAKE		0x80	/* for board_info; true iff can wake */
> >  #define I2C_CLIENT_SCCB		0x9000	/* Use Omnivision SCCB protocol */
> >  					/* Must match I2C_M_STOP|IGNORE_NAK */
> > -- 
> > 2.11.0.390.gc69c2f50cf-goog
> > 
> > 
> 
> Looks good, this seems to be elegant solution to our problem.
> 
> But then it is needed to patch those touchpad drivers to add that
> I2C_CLIENT_HOST_NOTIFY flag, right?
>

Yes, but currently the 2 drivers that are using Host Notify upstream are
rmi_smbus and elan_i2c. Both don't have an automatic binding (yet), so
there is nothing to worry about for now.

Cheers,
Benjamin

  reply	other threads:[~2017-01-05  9:27 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-27 12:52 [PATCH] i2c: i801: Register optional lis3lv02d i2c device on Dell machines Pali Rohár
2016-12-27 13:43 ` Wolfram Sang
2016-12-27 13:51   ` Pali Rohár
2016-12-27 22:15     ` Andy Shevchenko
2016-12-27 22:41       ` Valdis.Kletnieks
2016-12-28  7:55         ` Andy Shevchenko
2016-12-28  9:05           ` Pali Rohár
2016-12-28 14:03             ` Wolfram Sang
2016-12-29  4:37               ` Valdis.Kletnieks
2016-12-28  8:38       ` Pali Rohár
2016-12-28 14:02     ` Wolfram Sang
2017-01-04  9:45       ` Jean Delvare
2016-12-29  8:29 ` Michał Kępień
2016-12-29  9:00   ` Pali Rohár
2016-12-29 13:47     ` Michał Kępień
2016-12-29 14:17       ` Pali Rohár
2016-12-29 21:09         ` Michał Kępień
2016-12-29 21:28           ` Pali Rohár
2017-01-03  9:06             ` Benjamin Tissoires
2017-01-03  9:23               ` Pali Rohár
2017-01-03 18:38               ` Dmitry Torokhov
2017-01-03 18:50                 ` Pali Rohár
2017-01-03 18:58                   ` Mario.Limonciello
2017-01-03 19:48                   ` Dmitry Torokhov
2017-01-03 20:05                     ` Pali Rohár
2017-01-03 20:24                       ` Dmitry Torokhov
2017-01-03 20:39                         ` Pali Rohár
2017-01-03 20:59                           ` Dmitry Torokhov
2017-01-04  8:18                             ` Pali Rohár
2017-01-04  9:05                               ` Benjamin Tissoires
2017-01-04  9:18                                 ` Pali Rohár
2017-01-04 10:13                                   ` Benjamin Tissoires
2017-01-04 10:21                                     ` Pali Rohár
2017-01-04 10:32                                       ` Benjamin Tissoires
2017-01-04 11:22                                         ` Pali Rohár
2017-01-04 12:00                                           ` Pali Rohár
2017-01-04 13:02                                             ` Benjamin Tissoires
2017-01-04 16:06                                               ` Pali Rohár
2017-01-04 17:39                                                 ` Benjamin Tissoires
2017-01-04 17:46                                                   ` Wolfram Sang
2017-01-04 17:54                                                     ` Dmitry Torokhov
2017-01-04 21:49                                                       ` Benjamin Tissoires
2017-01-04 21:55                                                         ` Dmitry Torokhov
2017-01-04 21:55                                                       ` Wolfram Sang
2017-01-04 22:00                                                         ` Dmitry Torokhov
2017-01-04 22:03                                                           ` Dmitry Torokhov
2017-01-05  2:20                                                       ` [PATCH] i2c: do not enable fall back to Host Notify by default kbuild test robot
2017-01-05  2:21                                                       ` kbuild test robot
2017-01-05  8:54                                                       ` [PATCH] i2c: i801: Register optional lis3lv02d i2c device on Dell machines Pali Rohár
2017-01-05  9:26                                                         ` Benjamin Tissoires [this message]
2017-01-04 18:50                             ` Jean Delvare
2017-01-04  9:53                           ` Andy Shevchenko
2017-01-04 10:25                             ` Benjamin Tissoires
2017-01-04 11:35                               ` Pali Rohár
2017-01-04 12:33                                 ` Benjamin Tissoires
2017-01-03 21:29                     ` Benjamin Tissoires
2017-01-04  6:36                       ` Dmitry Torokhov
2017-01-04  9:13                         ` Benjamin Tissoires
2017-01-04  9:25                           ` Pali Rohár
2017-01-03 20:20                   ` Andy Shevchenko
2017-01-04 10:18               ` Jean Delvare
2017-01-07 12:49         ` Wolfram Sang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170105092654.GC15702@mail.corp.redhat.com \
    --to=benjamin.tissoires@redhat.com \
    --cc=Mario_Limonciello@dell.com \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=alex.hung@canonical.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gabriele.mzt@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=jochen@penguin-breeder.org \
    --cc=kernel@kempniu.pl \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=pali.rohar@gmail.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=stevenhoneyman@gmail.com \
    --cc=tiwai@suse.de \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).