Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * STMicroelectronics gyroscopes driver
0004  *
0005  * Copyright 2012-2013 STMicroelectronics Inc.
0006  *
0007  * Denis Ciocca <denis.ciocca@st.com>
0008  */
0009 
0010 #include <linux/kernel.h>
0011 #include <linux/module.h>
0012 #include <linux/mod_devicetable.h>
0013 #include <linux/i2c.h>
0014 #include <linux/iio/iio.h>
0015 
0016 #include <linux/iio/common/st_sensors.h>
0017 #include <linux/iio/common/st_sensors_i2c.h>
0018 #include "st_gyro.h"
0019 
0020 static const struct of_device_id st_gyro_of_match[] = {
0021     {
0022         .compatible = "st,l3g4200d-gyro",
0023         .data = L3G4200D_GYRO_DEV_NAME,
0024     },
0025     {
0026         .compatible = "st,lsm330d-gyro",
0027         .data = LSM330D_GYRO_DEV_NAME,
0028     },
0029     {
0030         .compatible = "st,lsm330dl-gyro",
0031         .data = LSM330DL_GYRO_DEV_NAME,
0032     },
0033     {
0034         .compatible = "st,lsm330dlc-gyro",
0035         .data = LSM330DLC_GYRO_DEV_NAME,
0036     },
0037     {
0038         .compatible = "st,l3gd20-gyro",
0039         .data = L3GD20_GYRO_DEV_NAME,
0040     },
0041     {
0042         .compatible = "st,l3gd20h-gyro",
0043         .data = L3GD20H_GYRO_DEV_NAME,
0044     },
0045     {
0046         .compatible = "st,l3g4is-gyro",
0047         .data = L3G4IS_GYRO_DEV_NAME,
0048     },
0049     {
0050         .compatible = "st,lsm330-gyro",
0051         .data = LSM330_GYRO_DEV_NAME,
0052     },
0053     {
0054         .compatible = "st,lsm9ds0-gyro",
0055         .data = LSM9DS0_GYRO_DEV_NAME,
0056     },
0057     {},
0058 };
0059 MODULE_DEVICE_TABLE(of, st_gyro_of_match);
0060 
0061 static int st_gyro_i2c_probe(struct i2c_client *client,
0062                  const struct i2c_device_id *id)
0063 {
0064     const struct st_sensor_settings *settings;
0065     struct st_sensor_data *gdata;
0066     struct iio_dev *indio_dev;
0067     int err;
0068 
0069     st_sensors_dev_name_probe(&client->dev, client->name, sizeof(client->name));
0070 
0071     settings = st_gyro_get_settings(client->name);
0072     if (!settings) {
0073         dev_err(&client->dev, "device name %s not recognized.\n",
0074             client->name);
0075         return -ENODEV;
0076     }
0077 
0078     indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*gdata));
0079     if (!indio_dev)
0080         return -ENOMEM;
0081 
0082     gdata = iio_priv(indio_dev);
0083     gdata->sensor_settings = (struct st_sensor_settings *)settings;
0084 
0085     err = st_sensors_i2c_configure(indio_dev, client);
0086     if (err < 0)
0087         return err;
0088 
0089     err = st_sensors_power_enable(indio_dev);
0090     if (err)
0091         return err;
0092 
0093     return st_gyro_common_probe(indio_dev);
0094 }
0095 
0096 static const struct i2c_device_id st_gyro_id_table[] = {
0097     { L3G4200D_GYRO_DEV_NAME },
0098     { LSM330D_GYRO_DEV_NAME },
0099     { LSM330DL_GYRO_DEV_NAME },
0100     { LSM330DLC_GYRO_DEV_NAME },
0101     { L3GD20_GYRO_DEV_NAME },
0102     { L3GD20H_GYRO_DEV_NAME },
0103     { L3G4IS_GYRO_DEV_NAME },
0104     { LSM330_GYRO_DEV_NAME },
0105     { LSM9DS0_GYRO_DEV_NAME },
0106     {},
0107 };
0108 MODULE_DEVICE_TABLE(i2c, st_gyro_id_table);
0109 
0110 static struct i2c_driver st_gyro_driver = {
0111     .driver = {
0112         .name = "st-gyro-i2c",
0113         .of_match_table = st_gyro_of_match,
0114     },
0115     .probe = st_gyro_i2c_probe,
0116     .id_table = st_gyro_id_table,
0117 };
0118 module_i2c_driver(st_gyro_driver);
0119 
0120 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
0121 MODULE_DESCRIPTION("STMicroelectronics gyroscopes i2c driver");
0122 MODULE_LICENSE("GPL v2");
0123 MODULE_IMPORT_NS(IIO_ST_SENSORS);