2019-05-29 07:17:56 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2016-02-12 13:44:44 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Invensense, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/iio/iio.h>
|
2022-02-03 17:59:18 +02:00
|
|
|
#include <linux/mod_devicetable.h>
|
2016-02-12 13:44:44 +02:00
|
|
|
#include <linux/module.h>
|
2020-02-06 11:31:00 +01:00
|
|
|
#include <linux/property.h>
|
2022-02-03 17:59:20 +02:00
|
|
|
|
2016-02-12 13:44:44 +02:00
|
|
|
#include "inv_mpu_iio.h"
|
|
|
|
|
|
|
|
static const struct regmap_config inv_mpu_regmap_config = {
|
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 8,
|
|
|
|
};
|
|
|
|
|
2016-04-20 08:40:49 +02:00
|
|
|
static int inv_mpu6050_select_bypass(struct i2c_mux_core *muxc, u32 chan_id)
|
2016-02-12 13:44:44 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-16 09:41:58 +00:00
|
|
|
static bool inv_mpu_i2c_aux_bus(struct device *dev)
|
|
|
|
{
|
|
|
|
struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(dev));
|
|
|
|
|
|
|
|
switch (st->chip_type) {
|
|
|
|
case INV_ICM20608:
|
2022-03-23 13:15:50 +01:00
|
|
|
case INV_ICM20608D:
|
2020-02-06 11:31:01 +01:00
|
|
|
case INV_ICM20609:
|
|
|
|
case INV_ICM20689:
|
2023-05-05 13:48:53 +08:00
|
|
|
case INV_ICM20600:
|
2019-09-16 09:41:58 +00:00
|
|
|
case INV_ICM20602:
|
2024-11-15 17:37:23 -05:00
|
|
|
case INV_IAM20380:
|
2020-02-06 11:31:02 +01:00
|
|
|
case INV_IAM20680:
|
2019-09-16 09:41:58 +00:00
|
|
|
/* no i2c auxiliary bus on the chip */
|
|
|
|
return false;
|
2019-11-15 15:06:22 +01:00
|
|
|
case INV_MPU9150:
|
2019-09-16 09:41:58 +00:00
|
|
|
case INV_MPU9250:
|
|
|
|
case INV_MPU9255:
|
|
|
|
if (st->magn_disabled)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-19 15:39:46 +01:00
|
|
|
static int inv_mpu_i2c_aux_setup(struct iio_dev *indio_dev)
|
2019-09-16 09:41:58 +00:00
|
|
|
{
|
|
|
|
struct inv_mpu6050_state *st = iio_priv(indio_dev);
|
|
|
|
struct device *dev = indio_dev->dev.parent;
|
2022-02-03 17:59:20 +02:00
|
|
|
struct fwnode_handle *mux_node;
|
2020-02-19 15:39:46 +01:00
|
|
|
int ret;
|
2019-09-16 09:41:58 +00:00
|
|
|
|
2020-02-19 15:39:46 +01:00
|
|
|
/*
|
|
|
|
* MPU9xxx magnetometer support requires to disable i2c auxiliary bus.
|
|
|
|
* To ensure backward compatibility with existing setups, do not disable
|
|
|
|
* i2c auxiliary bus if it used.
|
|
|
|
* Check for i2c-gate node in devicetree and set magnetometer disabled.
|
|
|
|
* Only MPU6500 is supported by ACPI, no need to check.
|
|
|
|
*/
|
2019-09-16 09:41:58 +00:00
|
|
|
switch (st->chip_type) {
|
2019-11-15 15:06:22 +01:00
|
|
|
case INV_MPU9150:
|
2019-09-16 09:41:58 +00:00
|
|
|
case INV_MPU9250:
|
|
|
|
case INV_MPU9255:
|
2022-02-03 17:59:20 +02:00
|
|
|
mux_node = device_get_named_child_node(dev, "i2c-gate");
|
2019-09-16 09:41:58 +00:00
|
|
|
if (mux_node != NULL) {
|
|
|
|
st->magn_disabled = true;
|
|
|
|
dev_warn(dev, "disable internal use of magnetometer\n");
|
|
|
|
}
|
2022-02-03 17:59:20 +02:00
|
|
|
fwnode_handle_put(mux_node);
|
2019-09-16 09:41:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-02-19 15:39:46 +01:00
|
|
|
/* enable i2c bypass when using i2c auxiliary bus */
|
|
|
|
if (inv_mpu_i2c_aux_bus(dev)) {
|
|
|
|
ret = regmap_write(st->map, st->reg->int_pin_cfg,
|
|
|
|
st->irq_mask | INV_MPU6050_BIT_BYPASS_EN);
|
|
|
|
if (ret)
|
2020-02-19 15:39:48 +01:00
|
|
|
return ret;
|
2020-02-19 15:39:46 +01:00
|
|
|
}
|
|
|
|
|
2019-09-16 09:41:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-12 13:44:44 +02:00
|
|
|
/**
|
|
|
|
* inv_mpu_probe() - probe function.
|
|
|
|
* @client: i2c client.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, a negative error code otherwise.
|
|
|
|
*/
|
2022-11-18 23:37:23 +01:00
|
|
|
static int inv_mpu_probe(struct i2c_client *client)
|
2016-02-12 13:44:44 +02:00
|
|
|
{
|
2022-11-18 23:37:23 +01:00
|
|
|
const struct i2c_device_id *id = i2c_client_get_device_id(client);
|
2020-02-06 11:31:00 +01:00
|
|
|
const void *match;
|
2016-02-12 13:44:44 +02:00
|
|
|
struct inv_mpu6050_state *st;
|
2017-03-15 01:44:56 -03:00
|
|
|
int result;
|
|
|
|
enum inv_devices chip_type;
|
2016-02-12 13:44:44 +02:00
|
|
|
struct regmap *regmap;
|
2016-03-17 18:32:44 +02:00
|
|
|
const char *name;
|
2016-02-12 13:44:44 +02:00
|
|
|
|
|
|
|
if (!i2c_check_functionality(client->adapter,
|
|
|
|
I2C_FUNC_SMBUS_I2C_BLOCK))
|
2016-02-26 22:13:49 -08:00
|
|
|
return -EOPNOTSUPP;
|
2016-02-12 13:44:44 +02:00
|
|
|
|
2020-02-06 11:31:00 +01:00
|
|
|
match = device_get_match_data(&client->dev);
|
|
|
|
if (match) {
|
2021-11-28 17:24:41 +00:00
|
|
|
chip_type = (uintptr_t)match;
|
2017-03-15 01:44:56 -03:00
|
|
|
name = client->name;
|
|
|
|
} else if (id) {
|
|
|
|
chip_type = (enum inv_devices)
|
|
|
|
id->driver_data;
|
2016-03-17 18:32:44 +02:00
|
|
|
name = id->name;
|
|
|
|
} else {
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2016-02-12 13:44:44 +02:00
|
|
|
regmap = devm_regmap_init_i2c(client, &inv_mpu_regmap_config);
|
|
|
|
if (IS_ERR(regmap)) {
|
2020-03-22 22:53:11 +05:30
|
|
|
dev_err(&client->dev, "Failed to register i2c regmap: %pe\n",
|
|
|
|
regmap);
|
2016-02-12 13:44:44 +02:00
|
|
|
return PTR_ERR(regmap);
|
|
|
|
}
|
|
|
|
|
2016-02-22 13:39:11 -08:00
|
|
|
result = inv_mpu_core_probe(regmap, client->irq, name,
|
2020-02-19 15:39:46 +01:00
|
|
|
inv_mpu_i2c_aux_setup, chip_type);
|
2016-02-12 13:44:44 +02:00
|
|
|
if (result < 0)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
st = iio_priv(dev_get_drvdata(&client->dev));
|
2019-09-16 09:41:58 +00:00
|
|
|
if (inv_mpu_i2c_aux_bus(&client->dev)) {
|
2018-04-30 12:14:08 +02:00
|
|
|
/* declare i2c auxiliary bus */
|
|
|
|
st->muxc = i2c_mux_alloc(client->adapter, &client->dev,
|
|
|
|
1, 0, I2C_MUX_LOCKED | I2C_MUX_GATE,
|
2020-02-19 15:39:46 +01:00
|
|
|
inv_mpu6050_select_bypass, NULL);
|
2018-04-30 12:14:08 +02:00
|
|
|
if (!st->muxc)
|
|
|
|
return -ENOMEM;
|
|
|
|
st->muxc->priv = dev_get_drvdata(&client->dev);
|
2024-04-18 22:55:39 +02:00
|
|
|
result = i2c_mux_add_adapter(st->muxc, 0, 0);
|
2018-04-30 12:14:08 +02:00
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
result = inv_mpu_acpi_create_mux_client(client);
|
|
|
|
if (result)
|
|
|
|
goto out_del_mux;
|
|
|
|
}
|
2016-02-12 13:44:44 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_del_mux:
|
2016-04-20 08:40:49 +02:00
|
|
|
i2c_mux_del_adapters(st->muxc);
|
2016-02-12 13:44:44 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-08-15 10:02:30 +02:00
|
|
|
static void inv_mpu_remove(struct i2c_client *client)
|
2016-02-12 13:44:44 +02:00
|
|
|
{
|
|
|
|
struct iio_dev *indio_dev = i2c_get_clientdata(client);
|
|
|
|
struct inv_mpu6050_state *st = iio_priv(indio_dev);
|
|
|
|
|
2018-04-30 12:14:08 +02:00
|
|
|
if (st->muxc) {
|
|
|
|
inv_mpu_acpi_delete_mux_client(client);
|
|
|
|
i2c_mux_del_adapters(st->muxc);
|
|
|
|
}
|
2016-02-12 13:44:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* device id table is used to identify what device can be
|
|
|
|
* supported by this driver
|
|
|
|
*/
|
|
|
|
static const struct i2c_device_id inv_mpu_id[] = {
|
|
|
|
{"mpu6050", INV_MPU6050},
|
|
|
|
{"mpu6500", INV_MPU6500},
|
2018-07-10 21:09:30 -04:00
|
|
|
{"mpu6515", INV_MPU6515},
|
2020-12-02 11:46:56 +01:00
|
|
|
{"mpu6880", INV_MPU6880},
|
2016-04-20 16:15:13 +03:00
|
|
|
{"mpu9150", INV_MPU9150},
|
2017-03-26 12:11:00 +01:00
|
|
|
{"mpu9250", INV_MPU9250},
|
2018-04-02 18:42:00 -04:00
|
|
|
{"mpu9255", INV_MPU9255},
|
2016-06-30 19:06:34 +02:00
|
|
|
{"icm20608", INV_ICM20608},
|
2022-03-23 13:15:50 +01:00
|
|
|
{"icm20608d", INV_ICM20608D},
|
2020-02-06 11:31:01 +01:00
|
|
|
{"icm20609", INV_ICM20609},
|
|
|
|
{"icm20689", INV_ICM20689},
|
2023-05-05 13:48:53 +08:00
|
|
|
{"icm20600", INV_ICM20600},
|
2019-01-28 19:50:03 +01:00
|
|
|
{"icm20602", INV_ICM20602},
|
2020-02-06 11:31:03 +01:00
|
|
|
{"icm20690", INV_ICM20690},
|
2024-11-15 17:37:23 -05:00
|
|
|
{"iam20380", INV_IAM20380},
|
2020-02-06 11:31:02 +01:00
|
|
|
{"iam20680", INV_IAM20680},
|
2024-09-23 16:53:22 +02:00
|
|
|
{"iam20680hp", INV_IAM20680HP},
|
|
|
|
{"iam20680ht", INV_IAM20680HT},
|
2025-04-11 15:49:34 -05:00
|
|
|
{ }
|
2016-02-12 13:44:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(i2c, inv_mpu_id);
|
|
|
|
|
2017-03-15 01:44:56 -03:00
|
|
|
static const struct of_device_id inv_of_match[] = {
|
|
|
|
{
|
|
|
|
.compatible = "invensense,mpu6050",
|
|
|
|
.data = (void *)INV_MPU6050
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.compatible = "invensense,mpu6500",
|
|
|
|
.data = (void *)INV_MPU6500
|
|
|
|
},
|
2018-07-10 21:09:30 -04:00
|
|
|
{
|
|
|
|
.compatible = "invensense,mpu6515",
|
|
|
|
.data = (void *)INV_MPU6515
|
|
|
|
},
|
2020-12-02 11:46:56 +01:00
|
|
|
{
|
|
|
|
.compatible = "invensense,mpu6880",
|
|
|
|
.data = (void *)INV_MPU6880
|
|
|
|
},
|
2017-03-15 01:44:56 -03:00
|
|
|
{
|
|
|
|
.compatible = "invensense,mpu9150",
|
|
|
|
.data = (void *)INV_MPU9150
|
|
|
|
},
|
2017-03-26 12:11:00 +01:00
|
|
|
{
|
|
|
|
.compatible = "invensense,mpu9250",
|
|
|
|
.data = (void *)INV_MPU9250
|
|
|
|
},
|
2018-04-02 18:42:00 -04:00
|
|
|
{
|
|
|
|
.compatible = "invensense,mpu9255",
|
|
|
|
.data = (void *)INV_MPU9255
|
|
|
|
},
|
2017-03-15 01:44:56 -03:00
|
|
|
{
|
|
|
|
.compatible = "invensense,icm20608",
|
|
|
|
.data = (void *)INV_ICM20608
|
|
|
|
},
|
2022-03-23 13:15:50 +01:00
|
|
|
{
|
|
|
|
.compatible = "invensense,icm20608d",
|
|
|
|
.data = (void *)INV_ICM20608D
|
|
|
|
},
|
2020-02-06 11:31:01 +01:00
|
|
|
{
|
|
|
|
.compatible = "invensense,icm20609",
|
|
|
|
.data = (void *)INV_ICM20609
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.compatible = "invensense,icm20689",
|
|
|
|
.data = (void *)INV_ICM20689
|
|
|
|
},
|
2023-05-05 13:48:53 +08:00
|
|
|
{
|
|
|
|
.compatible = "invensense,icm20600",
|
|
|
|
.data = (void *)INV_ICM20600
|
|
|
|
},
|
2019-01-28 19:50:03 +01:00
|
|
|
{
|
|
|
|
.compatible = "invensense,icm20602",
|
|
|
|
.data = (void *)INV_ICM20602
|
|
|
|
},
|
2020-02-06 11:31:03 +01:00
|
|
|
{
|
|
|
|
.compatible = "invensense,icm20690",
|
|
|
|
.data = (void *)INV_ICM20690
|
|
|
|
},
|
2024-11-15 17:37:23 -05:00
|
|
|
{
|
|
|
|
.compatible = "invensense,iam20380",
|
|
|
|
.data = (void *)INV_IAM20380
|
|
|
|
},
|
2020-02-06 11:31:02 +01:00
|
|
|
{
|
|
|
|
.compatible = "invensense,iam20680",
|
|
|
|
.data = (void *)INV_IAM20680
|
|
|
|
},
|
2024-09-23 16:53:22 +02:00
|
|
|
{
|
|
|
|
.compatible = "invensense,iam20680hp",
|
|
|
|
.data = (void *)INV_IAM20680HP
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.compatible = "invensense,iam20680ht",
|
|
|
|
.data = (void *)INV_IAM20680HT
|
|
|
|
},
|
2017-03-15 01:44:56 -03:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, inv_of_match);
|
|
|
|
|
2022-02-03 17:59:18 +02:00
|
|
|
static const struct acpi_device_id inv_acpi_match[] = {
|
2016-04-20 16:15:09 +03:00
|
|
|
{"INVN6500", INV_MPU6500},
|
2025-04-11 15:49:34 -05:00
|
|
|
{ }
|
2016-02-12 13:44:44 +02:00
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(acpi, inv_acpi_match);
|
|
|
|
|
|
|
|
static struct i2c_driver inv_mpu_driver = {
|
2023-05-15 22:50:48 +02:00
|
|
|
.probe = inv_mpu_probe,
|
2016-02-12 13:44:44 +02:00
|
|
|
.remove = inv_mpu_remove,
|
|
|
|
.id_table = inv_mpu_id,
|
|
|
|
.driver = {
|
2017-03-15 01:44:56 -03:00
|
|
|
.of_match_table = inv_of_match,
|
2022-02-03 17:59:18 +02:00
|
|
|
.acpi_match_table = inv_acpi_match,
|
2016-02-12 13:44:44 +02:00
|
|
|
.name = "inv-mpu6050-i2c",
|
2022-09-25 16:57:19 +01:00
|
|
|
.pm = pm_ptr(&inv_mpu_pmops),
|
2016-02-12 13:44:44 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module_i2c_driver(inv_mpu_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Invensense Corporation");
|
|
|
|
MODULE_DESCRIPTION("Invensense device MPU6050 driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
module: Convert symbol namespace to string literal
Clean up the existing export namespace code along the same lines of
commit 33def8498fdd ("treewide: Convert macro and uses of __section(foo)
to __section("foo")") and for the same reason, it is not desired for the
namespace argument to be a macro expansion itself.
Scripted using
git grep -l -e MODULE_IMPORT_NS -e EXPORT_SYMBOL_NS | while read file;
do
awk -i inplace '
/^#define EXPORT_SYMBOL_NS/ {
gsub(/__stringify\(ns\)/, "ns");
print;
next;
}
/^#define MODULE_IMPORT_NS/ {
gsub(/__stringify\(ns\)/, "ns");
print;
next;
}
/MODULE_IMPORT_NS/ {
$0 = gensub(/MODULE_IMPORT_NS\(([^)]*)\)/, "MODULE_IMPORT_NS(\"\\1\")", "g");
}
/EXPORT_SYMBOL_NS/ {
if ($0 ~ /(EXPORT_SYMBOL_NS[^(]*)\(([^,]+),/) {
if ($0 !~ /(EXPORT_SYMBOL_NS[^(]*)\(([^,]+), ([^)]+)\)/ &&
$0 !~ /(EXPORT_SYMBOL_NS[^(]*)\(\)/ &&
$0 !~ /^my/) {
getline line;
gsub(/[[:space:]]*\\$/, "");
gsub(/[[:space:]]/, "", line);
$0 = $0 " " line;
}
$0 = gensub(/(EXPORT_SYMBOL_NS[^(]*)\(([^,]+), ([^)]+)\)/,
"\\1(\\2, \"\\3\")", "g");
}
}
{ print }' $file;
done
Requested-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://mail.google.com/mail/u/2/#inbox/FMfcgzQXKWgMmjdFwwdsfgxzKpVHWPlc
Acked-by: Greg KH <gregkh@linuxfoundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2024-12-02 15:59:47 +01:00
|
|
|
MODULE_IMPORT_NS("IIO_MPU6050");
|