2019-05-28 09:57:06 -07:00
// SPDX-License-Identifier: GPL-2.0-only
2013-01-25 23:44:00 +00: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-08 18:51:49 +01:00
# include <linux/mod_devicetable.h>
2013-01-25 23:44:00 +00: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 08:16:00 +01:00
static const struct of_device_id st_magn_of_match [ ] = {
2015-04-30 15:15:50 +02:00
{
. compatible = " st,lsm303dlh-magn " ,
. data = LSM303DLH_MAGN_DEV_NAME ,
} ,
2014-08-07 08:16:00 +01: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 10:35:45 +02:00
{
. compatible = " st,lsm303agr-magn " ,
. data = LSM303AGR_MAGN_DEV_NAME ,
} ,
2017-08-16 19:02:52 +02:00
{
. compatible = " st,lis2mdl " ,
. data = LIS2MDL_MAGN_DEV_NAME ,
} ,
2018-10-25 19:38:10 -07:00
{
. compatible = " st,lsm9ds1-magn " ,
. data = LSM9DS1_MAGN_DEV_NAME ,
} ,
2021-03-17 06:39:02 +00:00
{
. compatible = " st,iis2mdc " ,
. data = IIS2MDC_MAGN_DEV_NAME ,
} ,
2023-01-06 11:22:39 +01:00
{
. compatible = " st,lsm303c-magn " ,
. data = LSM303C_MAGN_DEV_NAME ,
} ,
2014-08-07 08:16:00 +01:00
{ } ,
} ;
MODULE_DEVICE_TABLE ( of , st_magn_of_match ) ;
2022-10-23 15:23:01 +02:00
static int st_magn_i2c_probe ( struct i2c_client * client )
2013-01-25 23:44:00 +00:00
{
2019-07-18 15:53:50 -07:00
const struct st_sensor_settings * settings ;
2013-01-25 23:44:00 +00:00
struct st_sensor_data * mdata ;
2019-07-18 15:53:50 -07:00
struct iio_dev * indio_dev ;
2013-01-25 23:44:00 +00:00
int err ;
2019-12-16 19:38:52 +02:00
st_sensors_dev_name_probe ( & client - > dev , client - > name , sizeof ( client - > name ) ) ;
2019-07-18 15:53:50 -07: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 11:08:00 +01:00
indio_dev = devm_iio_device_alloc ( & client - > dev , sizeof ( * mdata ) ) ;
if ( ! indio_dev )
return - ENOMEM ;
2013-01-25 23:44:00 +00:00
mdata = iio_priv ( indio_dev ) ;
2019-07-18 15:53:50 -07:00
mdata - > sensor_settings = ( struct st_sensor_settings * ) settings ;
2013-01-25 23:44:00 +00:00
2019-07-18 15:53:53 -07:00
err = st_sensors_i2c_configure ( indio_dev , client ) ;
if ( err < 0 )
return err ;
2013-01-25 23:44:00 +00:00
2021-04-14 22:54:51 +03:00
err = st_sensors_power_enable ( indio_dev ) ;
if ( err )
return err ;
2021-08-23 14:22:02 +03:00
return st_magn_common_probe ( indio_dev ) ;
2013-01-25 23:44:00 +00:00
}
static const struct i2c_device_id st_magn_id_table [ ] = {
2015-04-30 15:15:50 +02:00
{ LSM303DLH_MAGN_DEV_NAME } ,
2013-01-25 23:44:00 +00:00
{ LSM303DLHC_MAGN_DEV_NAME } ,
{ LSM303DLM_MAGN_DEV_NAME } ,
{ LIS3MDL_MAGN_DEV_NAME } ,
2015-07-21 10:35:45 +02:00
{ LSM303AGR_MAGN_DEV_NAME } ,
2017-08-16 19:02:52 +02:00
{ LIS2MDL_MAGN_DEV_NAME } ,
2018-10-25 19:38:10 -07:00
{ LSM9DS1_MAGN_DEV_NAME } ,
2021-03-17 06:39:02 +00:00
{ IIS2MDC_MAGN_DEV_NAME } ,
2023-01-06 11:22:39 +01:00
{ LSM303C_MAGN_DEV_NAME } ,
2013-01-25 23:44:00 +00:00
{ } ,
} ;
MODULE_DEVICE_TABLE ( i2c , st_magn_id_table ) ;
static struct i2c_driver st_magn_driver = {
. driver = {
. name = " st-magn-i2c " ,
2019-12-16 19:38:53 +02:00
. of_match_table = st_magn_of_match ,
2013-01-25 23:44:00 +00:00
} ,
2023-05-15 22:50:48 +02:00
. probe = st_magn_i2c_probe ,
2013-01-25 23:44:00 +00: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-16 18:05:35 +00:00
MODULE_IMPORT_NS ( IIO_ST_SENSORS ) ;