2019-05-29 00:57:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2013-01-26 07:44:00 +08:00
|
|
|
/*
|
|
|
|
* STMicroelectronics magnetometers driver
|
|
|
|
*
|
|
|
|
* Copyright 2012-2013 STMicroelectronics Inc.
|
|
|
|
*
|
|
|
|
* Denis Ciocca <denis.ciocca@st.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
2021-06-09 01:51:49 +08:00
|
|
|
#include <linux/mod_devicetable.h>
|
2013-01-26 07:44:00 +08:00
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/iio/iio.h>
|
|
|
|
|
|
|
|
#include <linux/iio/common/st_sensors.h>
|
|
|
|
#include <linux/iio/common/st_sensors_i2c.h>
|
|
|
|
#include "st_magn.h"
|
|
|
|
|
2014-08-07 15:16:00 +08:00
|
|
|
static const struct of_device_id st_magn_of_match[] = {
|
2015-04-30 21:15:50 +08:00
|
|
|
{
|
|
|
|
.compatible = "st,lsm303dlh-magn",
|
|
|
|
.data = LSM303DLH_MAGN_DEV_NAME,
|
|
|
|
},
|
2014-08-07 15:16:00 +08:00
|
|
|
{
|
|
|
|
.compatible = "st,lsm303dlhc-magn",
|
|
|
|
.data = LSM303DLHC_MAGN_DEV_NAME,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.compatible = "st,lsm303dlm-magn",
|
|
|
|
.data = LSM303DLM_MAGN_DEV_NAME,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.compatible = "st,lis3mdl-magn",
|
|
|
|
.data = LIS3MDL_MAGN_DEV_NAME,
|
|
|
|
},
|
2015-07-21 16:35:45 +08:00
|
|
|
{
|
|
|
|
.compatible = "st,lsm303agr-magn",
|
|
|
|
.data = LSM303AGR_MAGN_DEV_NAME,
|
|
|
|
},
|
2017-08-17 01:02:52 +08:00
|
|
|
{
|
|
|
|
.compatible = "st,lis2mdl",
|
|
|
|
.data = LIS2MDL_MAGN_DEV_NAME,
|
|
|
|
},
|
2018-10-26 10:38:10 +08:00
|
|
|
{
|
|
|
|
.compatible = "st,lsm9ds1-magn",
|
|
|
|
.data = LSM9DS1_MAGN_DEV_NAME,
|
|
|
|
},
|
2021-03-17 14:39:02 +08:00
|
|
|
{
|
|
|
|
.compatible = "st,iis2mdc",
|
|
|
|
.data = IIS2MDC_MAGN_DEV_NAME,
|
|
|
|
},
|
2023-01-06 18:22:39 +08:00
|
|
|
{
|
|
|
|
.compatible = "st,lsm303c-magn",
|
|
|
|
.data = LSM303C_MAGN_DEV_NAME,
|
|
|
|
},
|
2014-08-07 15:16:00 +08:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, st_magn_of_match);
|
|
|
|
|
2022-10-23 21:23:01 +08:00
|
|
|
static int st_magn_i2c_probe(struct i2c_client *client)
|
2013-01-26 07:44:00 +08:00
|
|
|
{
|
2019-07-19 06:53:50 +08:00
|
|
|
const struct st_sensor_settings *settings;
|
2013-01-26 07:44:00 +08:00
|
|
|
struct st_sensor_data *mdata;
|
2019-07-19 06:53:50 +08:00
|
|
|
struct iio_dev *indio_dev;
|
2013-01-26 07:44:00 +08:00
|
|
|
int err;
|
|
|
|
|
2019-12-17 01:38:52 +08:00
|
|
|
st_sensors_dev_name_probe(&client->dev, client->name, sizeof(client->name));
|
2019-07-19 06:53:50 +08:00
|
|
|
|
|
|
|
settings = st_magn_get_settings(client->name);
|
|
|
|
if (!settings) {
|
|
|
|
dev_err(&client->dev, "device name %s not recognized.\n",
|
|
|
|
client->name);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2013-08-02 18:08:00 +08:00
|
|
|
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*mdata));
|
|
|
|
if (!indio_dev)
|
|
|
|
return -ENOMEM;
|
2013-01-26 07:44:00 +08:00
|
|
|
|
|
|
|
mdata = iio_priv(indio_dev);
|
2019-07-19 06:53:50 +08:00
|
|
|
mdata->sensor_settings = (struct st_sensor_settings *)settings;
|
2013-01-26 07:44:00 +08:00
|
|
|
|
2019-07-19 06:53:53 +08:00
|
|
|
err = st_sensors_i2c_configure(indio_dev, client);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2013-01-26 07:44:00 +08:00
|
|
|
|
2021-04-15 03:54:51 +08:00
|
|
|
err = st_sensors_power_enable(indio_dev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2021-08-23 19:22:02 +08:00
|
|
|
return st_magn_common_probe(indio_dev);
|
2013-01-26 07:44:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id st_magn_id_table[] = {
|
2015-04-30 21:15:50 +08:00
|
|
|
{ LSM303DLH_MAGN_DEV_NAME },
|
2013-01-26 07:44:00 +08:00
|
|
|
{ LSM303DLHC_MAGN_DEV_NAME },
|
|
|
|
{ LSM303DLM_MAGN_DEV_NAME },
|
|
|
|
{ LIS3MDL_MAGN_DEV_NAME },
|
2015-07-21 16:35:45 +08:00
|
|
|
{ LSM303AGR_MAGN_DEV_NAME },
|
2017-08-17 01:02:52 +08:00
|
|
|
{ LIS2MDL_MAGN_DEV_NAME },
|
2018-10-26 10:38:10 +08:00
|
|
|
{ LSM9DS1_MAGN_DEV_NAME },
|
2021-03-17 14:39:02 +08:00
|
|
|
{ IIS2MDC_MAGN_DEV_NAME },
|
2023-01-06 18:22:39 +08:00
|
|
|
{ LSM303C_MAGN_DEV_NAME },
|
2013-01-26 07:44:00 +08:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, st_magn_id_table);
|
|
|
|
|
|
|
|
static struct i2c_driver st_magn_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "st-magn-i2c",
|
2019-12-17 01:38:53 +08:00
|
|
|
.of_match_table = st_magn_of_match,
|
2013-01-26 07:44:00 +08:00
|
|
|
},
|
2023-05-16 04:50:48 +08:00
|
|
|
.probe = st_magn_i2c_probe,
|
2013-01-26 07:44:00 +08:00
|
|
|
.id_table = st_magn_id_table,
|
|
|
|
};
|
|
|
|
module_i2c_driver(st_magn_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
|
|
|
|
MODULE_DESCRIPTION("STMicroelectronics magnetometers i2c driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
2022-01-17 02:05:35 +08:00
|
|
|
MODULE_IMPORT_NS(IIO_ST_SENSORS);
|