linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali.rohar@gmail.com>
To: "Jean Delvare" <jdelvare@suse.com>,
	"Wolfram Sang" <wsa@the-dreams.de>,
	"Michał Kępień" <kernel@kempniu.pl>,
	"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>
Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
	platform-driver-x86@vger.kernel.org,
	"Pali Rohár" <pali.rohar@gmail.com>
Subject: [PATCH v2] i2c: i801: Register optional lis3lv02d i2c device on Dell machines
Date: Sat, 27 Jan 2018 14:32:09 +0100	[thread overview]
Message-ID: <20180127133209.28995-1-pali.rohar@gmail.com> (raw)

Dell platform team told us that some (DMI whitelisted) Dell Latitude
machines have ST microelectronics accelerometer at i2c address 0x29.

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

This patch registers lis3lv02d device for selected Dell Latitude machines
at i2c address 0x29 after detection. And for Dell Vostro V131 machine at
i2c address 0x1d which was manually 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>
---
Changes since v1:
 * Added Dell Vostro V131 based on Michał Kępień testing
 * Changed DMI product structure to include also i2c address

I re-tested this patch against Debian's 4.9 kernel on E6440.
---
 drivers/i2c/busses/i2c-i801.c | 104 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 104 insertions(+)

diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 8eac00efadc1..502678e8b8c0 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -1136,6 +1136,107 @@ 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 that ACPI device SMO88xx exists and is enabled. That ACPI
+	 * device represent our ST microelectronics lis3lv02d accelerometer but
+	 * unfortunately without any other information (like i2c address).
+	 */
+	found = false;
+	status = acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL,
+				  (void **)&found);
+	if (!ACPI_SUCCESS(status) || !found)
+		return false;
+
+	return true;
+}
+
+/*
+ * Accelerometer's i2c address is not specified in DMI nor ACPI,
+ * so it is needed to define mapping table based on DMI product names.
+ */
+static struct {
+	const char *dmi_product_name;
+	unsigned short i2c_addr;
+} dell_lis3lv02d_devices[] = {
+	/*
+	 * Dell platform team told us that these Latitude devices have
+	 * ST microelectronics accelerometer at i2c address 0x29.
+	 */
+	{ "Latitude E5250",     0x29 },
+	{ "Latitude E5450",     0x29 },
+	{ "Latitude E5550",     0x29 },
+	{ "Latitude E6440",     0x29 },
+	{ "Latitude E6440 ATG", 0x29 },
+	{ "Latitude E6540",     0x29 },
+	/*
+	 * Additional individual entries were added after verification.
+	 */
+	{ "Vostro V131",        0x1d },
+};
+
+static void register_dell_lis3lv02d_i2c_device(struct i801_priv *priv)
+{
+	struct i2c_board_info info;
+	const char *dmi_product_name;
+	int i;
+
+	dmi_product_name = dmi_get_system_info(DMI_PRODUCT_NAME);
+	for (i = 0; i < ARRAY_SIZE(dell_lis3lv02d_devices); ++i) {
+		if (strcmp(dmi_product_name,
+			   dell_lis3lv02d_devices[i].dmi_product_name) == 0)
+			break;
+	}
+
+	if (i == ARRAY_SIZE(dell_lis3lv02d_devices)) {
+		dev_warn(&priv->pci_dev->dev,
+			 "Accelerometer lis3lv02d is present on i2c bus but its"
+			 " i2c address is unknown, skipping registration...\n");
+		return;
+	}
+
+	memset(&info, 0, sizeof(struct i2c_board_info));
+	info.addr = dell_lis3lv02d_devices[i].i2c_addr;
+	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)
 {
@@ -1154,6 +1255,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) {}
-- 
2.11.0

             reply	other threads:[~2018-01-27 13:32 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-27 13:32 Pali Rohár [this message]
2018-01-28 14:39 ` [PATCH v2] i2c: i801: Register optional lis3lv02d i2c device on Dell machines Andy Shevchenko
2018-01-28 14:45   ` Pali Rohár
2018-01-28 15:00     ` Andy Shevchenko
2018-01-31 12:03       ` Pali Rohár
2018-01-31 12:27         ` Andy Shevchenko
2018-02-12 15:30           ` Pali Rohár
2018-02-13 14:55             ` Andy Shevchenko
2018-02-13 15:00               ` Pali Rohár
2018-02-13 15:06                 ` Andy Shevchenko
2018-02-13 16:50                   ` Pali Rohár
2018-02-13 17:01                     ` Andy Shevchenko
2018-02-13 17:05                       ` Andy Shevchenko
2018-02-26 20:32                     ` Wolfram Sang
2018-03-08 22:53                       ` Pali Rohár
2018-04-18 11:46                         ` Pali Rohár
2019-04-27  6:48                           ` Pali Rohár
2019-05-28  9:19                       ` Jean Delvare
2019-05-28  9:41                         ` Pali Rohár
2019-05-28  9:50                           ` Jean Delvare
2019-05-28  9:54                             ` Pali Rohár
2019-05-28 10:00                               ` Jean Delvare
2018-02-11 22:03 ` Michał Kępień
2018-02-12 15:25   ` Andy Shevchenko
2019-06-02 13:20 ` [PATCH v3] " Pali Rohár
2019-06-04 14:57   ` Jean Delvare
2019-06-04 22:30     ` Pali Rohár

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=20180127133209.28995-1-pali.rohar@gmail.com \
    --to=pali.rohar@gmail.com \
    --cc=Mario_Limonciello@dell.com \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=alex.hung@canonical.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=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).