linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: i801: Register optional lis3lv02d i2c device on Dell machines
@ 2016-12-27 12:52 Pali Rohár
  2016-12-27 13:43 ` Wolfram Sang
  2016-12-29  8:29 ` Michał Kępień
  0 siblings, 2 replies; 63+ messages in thread
From: Pali Rohár @ 2016-12-27 12:52 UTC (permalink / raw)
  To: Jean Delvare, Wolfram Sang, Steven Honeyman, Valdis.Kletnieks,
	Jochen Eisinger, Gabriele Mazzotta, Andy Lutomirski,
	Mario_Limonciello, Alex Hung, Michał Kępień,
	Takashi Iwai
  Cc: linux-i2c, linux-kernel, platform-driver-x86, Pali Rohár

Dell platform team told us that some (DMI whitelisted) Dell Latitude
machines have ST microelectronics accelerometer at i2c address 0x29. That
i2c address is not specified in DMI or ACPI, so runtime detection without
whitelist which is below is not possible.

Presence of that ST microelectronics accelerometer is verified by existence
of SMO88xx ACPI device which represent that accelerometer. Unfortunately
without i2c address.

This patch registers lis3lv02d device at i2c address 0x29 if is detected.

Finally commit a7ae81952cda ("i2c: i801: Allow ACPI SystemIO OpRegion to
conflict with PCI BAR") allowed to use i2c-i801 driver on Dell machines so
lis3lv02d correctly initialize accelerometer.

Tested on Dell Latitude E6440.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
---
 drivers/i2c/busses/i2c-i801.c |   98 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)

diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index eb3627f..188cfd4 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -1118,6 +1118,101 @@ static void dmi_check_onboard_devices(const struct dmi_header *dm, void *adap)
 	}
 }
 
+static acpi_status check_acpi_smo88xx_device(acpi_handle obj_handle,
+					     u32 nesting_level,
+					     void *context,
+					     void **return_value)
+{
+	struct acpi_device_info *info;
+	acpi_status status;
+	char *hid;
+
+	status = acpi_get_object_info(obj_handle, &info);
+	if (!ACPI_SUCCESS(status) || !(info->valid & ACPI_VALID_HID))
+		return AE_OK;
+
+	hid = info->hardware_id.string;
+	if (!hid)
+		return AE_OK;
+
+	if (strlen(hid) < 7)
+		return AE_OK;
+
+	if (memcmp(hid, "SMO88", 5) != 0)
+		return AE_OK;
+
+	*((bool *)return_value) = true;
+	return AE_CTRL_TERMINATE;
+}
+
+static bool is_dell_system_with_lis3lv02d(void)
+{
+	bool found;
+	acpi_status status;
+	const char *vendor;
+
+	vendor = dmi_get_system_info(DMI_SYS_VENDOR);
+	if (strcmp(vendor, "Dell Inc.") != 0)
+		return false;
+
+	/*
+	 * Check if ACPI device SMO88xx exists and if is enabled. That ACPI
+	 * device represent our ST microelectronics lis3lv02d accelerometer but
+	 * unfortunately without any other additional information.
+	 */
+	found = false;
+	status = acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL,
+				  (void **)&found);
+	if (!ACPI_SUCCESS(status) || !found)
+		return false;
+
+	return true;
+}
+
+/*
+ * Dell platform team told us that these Latitude devices have
+ * ST microelectronics accelerometer at i2c address 0x29.
+ * That i2c address is not specified in DMI or ACPI, so runtime
+ * detection without whitelist which is below is not possible.
+ */
+static const char * const dmi_dell_product_names[] = {
+	"Latitude E5250",
+	"Latitude E5450",
+	"Latitude E5550",
+	"Latitude E6440",
+	"Latitude E6440 ATG",
+	"Latitude E6540",
+};
+
+static void register_dell_lis3lv02d_i2c_device(struct i801_priv *priv)
+{
+	struct i2c_board_info info;
+	const char *product_name;
+	bool known_i2c_address;
+	int i;
+
+	known_i2c_address = false;
+	product_name = dmi_get_system_info(DMI_PRODUCT_NAME);
+	for (i = 0; i < ARRAY_SIZE(dmi_dell_product_names); ++i) {
+		if (strcmp(product_name, dmi_dell_product_names[i]) == 0) {
+			known_i2c_address = true;
+			break;
+		}
+	}
+
+	if (!known_i2c_address) {
+		dev_warn(&priv->pci_dev->dev,
+			 "Accelerometer lis3lv02d i2c device is present "
+			 "but its i2c address is unknown, skipping ...\n");
+		return;
+	}
+
+	memset(&info, 0, sizeof(struct i2c_board_info));
+	info.addr = 0x29;
+	strlcpy(info.type, "lis3lv02d", I2C_NAME_SIZE);
+	i2c_new_device(&priv->adapter, &info);
+}
+
 /* Register optional slaves */
 static void i801_probe_optional_slaves(struct i801_priv *priv)
 {
@@ -1136,6 +1231,9 @@ static void i801_probe_optional_slaves(struct i801_priv *priv)
 
 	if (dmi_name_in_vendors("FUJITSU"))
 		dmi_walk(dmi_check_onboard_devices, &priv->adapter);
+
+	if (is_dell_system_with_lis3lv02d())
+		register_dell_lis3lv02d_i2c_device(priv);
 }
 #else
 static void __init input_apanel_init(void) {}
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 63+ messages in thread
* [PATCH] i2c: do not enable fall back to Host Notify by default
@ 2017-01-04 21:58 Dmitry Torokhov
  0 siblings, 0 replies; 63+ messages in thread
From: Dmitry Torokhov @ 2017-01-04 21:58 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Rob Herring, Benjamin Tissoires, Pali Rohár,
	Michał Kępień,
	Jean Delvare, Takashi Iwai, linux-i2c, devicetree, linux-kernel

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-notify" property that we convert
to I2C_CLIENT_HOST_NOTIFY board flag.

Tested-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
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..fbd1db014768 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_NOTIFY) {
+			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


-- 
Dmitry

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

end of thread, other threads:[~2017-01-07 12:49 UTC | newest]

Thread overview: 63+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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
2017-01-04 21:58 [PATCH] i2c: do not enable fall back to Host Notify by default Dmitry Torokhov

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).