Skip to content

Commit 65d03f1

Browse files
committed
platform/x86: dell-smo8800: Add support for probing for the accelerometer i2c address
JIRA: https://issues.redhat.com/browse/RHEL-47426 commit 1e4e3df Author: Hans de Goede <[email protected]> Date: Mon Jan 6 13:32:59 2025 +0100 platform/x86: dell-smo8800: Add support for probing for the accelerometer i2c address Unfortunately the SMOxxxx ACPI device does not contain the i2c-address of the accelerometer. So a DMI product-name to address mapping table is used. Add support to have the kernel probe for the i2c-address for models which are not on the list. The new probing code sits behind a new probe_i2c_addr module parameter, which is disabled by default because probing might be dangerous. Link: https://lore.kernel.org/linux-i2c/[email protected]/ Signed-off-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: David Arcari <[email protected]>
1 parent 29812b9 commit 65d03f1

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

drivers/platform/x86/dell/dell-lis3lv02d.c

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <linux/workqueue.h>
1616
#include "dell-smo8800-ids.h"
1717

18+
#define LIS3_WHO_AM_I 0x0f
19+
1820
#define DELL_LIS3LV02D_DMI_ENTRY(product_name, i2c_addr) \
1921
{ \
2022
.matches = { \
@@ -57,6 +59,42 @@ static u8 i2c_addr;
5759
static struct i2c_client *i2c_dev;
5860
static bool notifier_registered;
5961

62+
static bool probe_i2c_addr;
63+
module_param(probe_i2c_addr, bool, 0444);
64+
MODULE_PARM_DESC(probe_i2c_addr, "Probe the i801 I2C bus for the accelerometer on models where the address is unknown, this may be dangerous.");
65+
66+
static int detect_lis3lv02d(struct i2c_adapter *adap, unsigned short addr)
67+
{
68+
union i2c_smbus_data smbus_data;
69+
int err;
70+
71+
dev_info(&adap->dev, "Probing for lis3lv02d on address 0x%02x\n", addr);
72+
73+
err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, LIS3_WHO_AM_I,
74+
I2C_SMBUS_BYTE_DATA, &smbus_data);
75+
if (err < 0)
76+
return 0; /* Not found */
77+
78+
/* valid who-am-i values are from drivers/misc/lis3lv02d/lis3lv02d.c */
79+
switch (smbus_data.byte) {
80+
case 0x32:
81+
case 0x33:
82+
case 0x3a:
83+
case 0x3b:
84+
break;
85+
default:
86+
dev_warn(&adap->dev, "Unknown who-am-i register value 0x%02x\n",
87+
smbus_data.byte);
88+
return 0; /* Not found */
89+
}
90+
91+
dev_info(&adap->dev,
92+
"Detected lis3lv02d on address 0x%02x, please report this upstream to [email protected] so that a quirk can be added\n",
93+
addr);
94+
95+
return 1; /* Found */
96+
}
97+
6098
static bool i2c_adapter_is_main_i801(struct i2c_adapter *adap)
6199
{
62100
/*
@@ -97,10 +135,18 @@ static void instantiate_i2c_client(struct work_struct *work)
97135
if (!adap)
98136
return;
99137

100-
info.addr = i2c_addr;
101138
strscpy(info.type, "lis3lv02d", I2C_NAME_SIZE);
102139

103-
i2c_dev = i2c_new_client_device(adap, &info);
140+
if (i2c_addr) {
141+
info.addr = i2c_addr;
142+
i2c_dev = i2c_new_client_device(adap, &info);
143+
} else {
144+
/* First try address 0x29 (most used) and then try 0x1d */
145+
static const unsigned short addr_list[] = { 0x29, 0x1d, I2C_CLIENT_END };
146+
147+
i2c_dev = i2c_new_scanned_device(adap, &info, addr_list, detect_lis3lv02d);
148+
}
149+
104150
if (IS_ERR(i2c_dev)) {
105151
dev_err(&adap->dev, "error %ld registering i2c_client\n", PTR_ERR(i2c_dev));
106152
i2c_dev = NULL;
@@ -169,12 +215,14 @@ static int __init dell_lis3lv02d_init(void)
169215
put_device(dev);
170216

171217
lis3lv02d_dmi_id = dmi_first_match(lis3lv02d_devices);
172-
if (!lis3lv02d_dmi_id) {
218+
if (!lis3lv02d_dmi_id && !probe_i2c_addr) {
173219
pr_warn("accelerometer is present on SMBus but its address is unknown, skipping registration\n");
220+
pr_info("Pass dell_lis3lv02d.probe_i2c_addr=1 on the kernel command line to probe, this may be dangerous!\n");
174221
return 0;
175222
}
176223

177-
i2c_addr = (long)lis3lv02d_dmi_id->driver_data;
224+
if (lis3lv02d_dmi_id)
225+
i2c_addr = (long)lis3lv02d_dmi_id->driver_data;
178226

179227
/*
180228
* Register i2c-bus notifier + queue initial scan for lis3lv02d

0 commit comments

Comments
 (0)