iio: accel: bmc150: Check for a second ACPI device for BOSC0200
Some BOSC0200 acpi_device-s describe two accelerometers in a single ACPI device. Normally we would handle this by letting the special drivers/platform/x86/i2c-multi-instantiate.c driver handle the BOSC0200 ACPI id and let it instantiate 2 bmc150_accel type i2c_client-s for us. But doing so changes the modalias for the first accelerometer (which is already supported and used on many devices) from acpi:BOSC0200 to i2c:bmc150_accel. The modalias is not only used to load the driver, but is also used by hwdb matches in /lib/udev/hwdb.d/60-sensor.hwdb which provide a mountmatrix to userspace by setting the ACCEL_MOUNT_MATRIX udev property. Switching the handling of the BOSC0200 over to i2c-multi-instantiate.c will break the hwdb matches causing the ACCEL_MOUNT_MATRIX udev prop to no longer be set. So switching over to i2c-multi-instantiate.c is not an option. Changes by Hans de Goede: -Add explanation to the commit message why i2c-multi-instantiate.c cannot be used -Also set the dev_name, fwnode and irq i2c_board_info struct members for the 2nd client Signed-off-by: Jeremy Cline <jeremy@jcline.org> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20201130141954.339805-2-hdegoede@redhat.com BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=198671 Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
e488fed07f
commit
5bfb3a4bd8
3 changed files with 62 additions and 2 deletions
|
@ -206,6 +206,7 @@ struct bmc150_accel_data {
|
||||||
int ev_enable_state;
|
int ev_enable_state;
|
||||||
int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */
|
int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */
|
||||||
const struct bmc150_accel_chip_info *chip_info;
|
const struct bmc150_accel_chip_info *chip_info;
|
||||||
|
struct i2c_client *second_device;
|
||||||
struct iio_mount_matrix orientation;
|
struct iio_mount_matrix orientation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1701,6 +1702,26 @@ err_disable_regulators:
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(bmc150_accel_core_probe);
|
EXPORT_SYMBOL_GPL(bmc150_accel_core_probe);
|
||||||
|
|
||||||
|
struct i2c_client *bmc150_get_second_device(struct i2c_client *client)
|
||||||
|
{
|
||||||
|
struct bmc150_accel_data *data = i2c_get_clientdata(client);
|
||||||
|
|
||||||
|
if (!data)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return data->second_device;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(bmc150_get_second_device);
|
||||||
|
|
||||||
|
void bmc150_set_second_device(struct i2c_client *client)
|
||||||
|
{
|
||||||
|
struct bmc150_accel_data *data = i2c_get_clientdata(client);
|
||||||
|
|
||||||
|
if (data)
|
||||||
|
data->second_device = client;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(bmc150_set_second_device);
|
||||||
|
|
||||||
int bmc150_accel_core_remove(struct device *dev)
|
int bmc150_accel_core_remove(struct device *dev)
|
||||||
{
|
{
|
||||||
struct iio_dev *indio_dev = dev_get_drvdata(dev);
|
struct iio_dev *indio_dev = dev_get_drvdata(dev);
|
||||||
|
|
|
@ -30,6 +30,8 @@ static int bmc150_accel_probe(struct i2c_client *client,
|
||||||
i2c_check_functionality(client->adapter, I2C_FUNC_I2C) ||
|
i2c_check_functionality(client->adapter, I2C_FUNC_I2C) ||
|
||||||
i2c_check_functionality(client->adapter,
|
i2c_check_functionality(client->adapter,
|
||||||
I2C_FUNC_SMBUS_READ_I2C_BLOCK);
|
I2C_FUNC_SMBUS_READ_I2C_BLOCK);
|
||||||
|
struct acpi_device __maybe_unused *adev;
|
||||||
|
int ret;
|
||||||
|
|
||||||
regmap = devm_regmap_init_i2c(client, &bmc150_regmap_conf);
|
regmap = devm_regmap_init_i2c(client, &bmc150_regmap_conf);
|
||||||
if (IS_ERR(regmap)) {
|
if (IS_ERR(regmap)) {
|
||||||
|
@ -40,12 +42,47 @@ static int bmc150_accel_probe(struct i2c_client *client,
|
||||||
if (id)
|
if (id)
|
||||||
name = id->name;
|
name = id->name;
|
||||||
|
|
||||||
return bmc150_accel_core_probe(&client->dev, regmap, client->irq, name,
|
ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq, name, block_supported);
|
||||||
block_supported);
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Some BOSC0200 acpi_devices describe 2 accelerometers in a single ACPI
|
||||||
|
* device, try instantiating a second i2c_client for an I2cSerialBusV2
|
||||||
|
* ACPI resource with index 1. The !id check avoids recursion when
|
||||||
|
* bmc150_accel_probe() gets called for the second client.
|
||||||
|
*/
|
||||||
|
#ifdef CONFIG_ACPI
|
||||||
|
adev = ACPI_COMPANION(&client->dev);
|
||||||
|
if (!id && adev && strcmp(acpi_device_hid(adev), "BOSC0200") == 0) {
|
||||||
|
struct i2c_board_info board_info = {
|
||||||
|
.type = "bmc150_accel",
|
||||||
|
/*
|
||||||
|
* The 2nd accel sits in the base of 2-in-1s. Note this
|
||||||
|
* name is static, as there should never be more then 1
|
||||||
|
* BOSC0200 ACPI node with 2 accelerometers in it.
|
||||||
|
*/
|
||||||
|
.dev_name = "BOSC0200:base",
|
||||||
|
.fwnode = client->dev.fwnode,
|
||||||
|
.irq = -ENOENT,
|
||||||
|
};
|
||||||
|
struct i2c_client *second_dev;
|
||||||
|
|
||||||
|
second_dev = i2c_acpi_new_device(&client->dev, 1, &board_info);
|
||||||
|
if (!IS_ERR(second_dev))
|
||||||
|
bmc150_set_second_device(second_dev);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bmc150_accel_remove(struct i2c_client *client)
|
static int bmc150_accel_remove(struct i2c_client *client)
|
||||||
{
|
{
|
||||||
|
struct i2c_client *second_dev = bmc150_get_second_device(client);
|
||||||
|
|
||||||
|
i2c_unregister_device(second_dev);
|
||||||
|
|
||||||
return bmc150_accel_core_remove(&client->dev);
|
return bmc150_accel_core_remove(&client->dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ enum {
|
||||||
int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
|
int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
|
||||||
const char *name, bool block_supported);
|
const char *name, bool block_supported);
|
||||||
int bmc150_accel_core_remove(struct device *dev);
|
int bmc150_accel_core_remove(struct device *dev);
|
||||||
|
struct i2c_client *bmc150_get_second_device(struct i2c_client *second_device);
|
||||||
|
void bmc150_set_second_device(struct i2c_client *second_device);
|
||||||
extern const struct dev_pm_ops bmc150_accel_pm_ops;
|
extern const struct dev_pm_ops bmc150_accel_pm_ops;
|
||||||
extern const struct regmap_config bmc150_regmap_conf;
|
extern const struct regmap_config bmc150_regmap_conf;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue