Denis Ciocca | d625116 | 2013-01-25 23:44:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * STMicroelectronics accelerometers driver |
| 3 | * |
| 4 | * Copyright 2012-2013 STMicroelectronics Inc. |
| 5 | * |
| 6 | * Denis Ciocca <denis.ciocca@st.com> |
| 7 | * |
| 8 | * Licensed under the GPL-2. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/slab.h> |
| 14 | #include <linux/i2c.h> |
| 15 | #include <linux/iio/iio.h> |
Denis Ciocca | d625116 | 2013-01-25 23:44:00 +0000 | [diff] [blame] | 16 | |
| 17 | #include <linux/iio/common/st_sensors.h> |
| 18 | #include <linux/iio/common/st_sensors_i2c.h> |
| 19 | #include "st_accel.h" |
| 20 | |
Linus Walleij | 2d7768a | 2014-08-07 08:16:00 +0100 | [diff] [blame] | 21 | #ifdef CONFIG_OF |
| 22 | static const struct of_device_id st_accel_of_match[] = { |
| 23 | { |
Linus Walleij | 3acddf7 | 2015-03-18 10:52:06 +0100 | [diff] [blame] | 24 | .compatible = "st,lis3lv02dl-accel", |
| 25 | .data = LIS3LV02DL_ACCEL_DEV_NAME, |
| 26 | }, |
| 27 | { |
Linus Walleij | 2d7768a | 2014-08-07 08:16:00 +0100 | [diff] [blame] | 28 | .compatible = "st,lsm303dlh-accel", |
| 29 | .data = LSM303DLH_ACCEL_DEV_NAME, |
| 30 | }, |
| 31 | { |
| 32 | .compatible = "st,lsm303dlhc-accel", |
| 33 | .data = LSM303DLHC_ACCEL_DEV_NAME, |
| 34 | }, |
| 35 | { |
| 36 | .compatible = "st,lis3dh-accel", |
| 37 | .data = LIS3DH_ACCEL_DEV_NAME, |
| 38 | }, |
| 39 | { |
| 40 | .compatible = "st,lsm330d-accel", |
| 41 | .data = LSM330D_ACCEL_DEV_NAME, |
| 42 | }, |
| 43 | { |
| 44 | .compatible = "st,lsm330dl-accel", |
| 45 | .data = LSM330DL_ACCEL_DEV_NAME, |
| 46 | }, |
| 47 | { |
| 48 | .compatible = "st,lsm330dlc-accel", |
| 49 | .data = LSM330DLC_ACCEL_DEV_NAME, |
| 50 | }, |
| 51 | { |
Linus Walleij | bbf5f03 | 2015-05-19 15:37:18 +0200 | [diff] [blame] | 52 | .compatible = "st,lis331dl-accel", |
| 53 | .data = LIS331DL_ACCEL_DEV_NAME, |
| 54 | }, |
| 55 | { |
Linus Walleij | 2d7768a | 2014-08-07 08:16:00 +0100 | [diff] [blame] | 56 | .compatible = "st,lis331dlh-accel", |
| 57 | .data = LIS331DLH_ACCEL_DEV_NAME, |
| 58 | }, |
| 59 | { |
| 60 | .compatible = "st,lsm303dl-accel", |
| 61 | .data = LSM303DL_ACCEL_DEV_NAME, |
| 62 | }, |
| 63 | { |
| 64 | .compatible = "st,lsm303dlm-accel", |
| 65 | .data = LSM303DLM_ACCEL_DEV_NAME, |
| 66 | }, |
| 67 | { |
| 68 | .compatible = "st,lsm330-accel", |
| 69 | .data = LSM330_ACCEL_DEV_NAME, |
| 70 | }, |
Giuseppe Barba | ddc05fa | 2015-07-21 10:35:44 +0200 | [diff] [blame] | 71 | { |
| 72 | .compatible = "st,lsm303agr-accel", |
| 73 | .data = LSM303AGR_ACCEL_DEV_NAME, |
| 74 | }, |
Giuseppe Barba | 34dc578 | 2015-11-12 08:36:49 +0100 | [diff] [blame] | 75 | { |
| 76 | .compatible = "st,lis2dh12-accel", |
| 77 | .data = LIS2DH12_ACCEL_DEV_NAME, |
| 78 | }, |
Linus Walleij | 2d7768a | 2014-08-07 08:16:00 +0100 | [diff] [blame] | 79 | {}, |
| 80 | }; |
| 81 | MODULE_DEVICE_TABLE(of, st_accel_of_match); |
| 82 | #else |
| 83 | #define st_accel_of_match NULL |
| 84 | #endif |
| 85 | |
Denis Ciocca | d625116 | 2013-01-25 23:44:00 +0000 | [diff] [blame] | 86 | static int st_accel_i2c_probe(struct i2c_client *client, |
| 87 | const struct i2c_device_id *id) |
| 88 | { |
| 89 | struct iio_dev *indio_dev; |
| 90 | struct st_sensor_data *adata; |
| 91 | int err; |
| 92 | |
Sachin Kamat | 6b7e0a9 | 2013-07-23 07:47:00 +0100 | [diff] [blame] | 93 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata)); |
| 94 | if (!indio_dev) |
| 95 | return -ENOMEM; |
Denis Ciocca | d625116 | 2013-01-25 23:44:00 +0000 | [diff] [blame] | 96 | |
| 97 | adata = iio_priv(indio_dev); |
Linus Walleij | 2d7768a | 2014-08-07 08:16:00 +0100 | [diff] [blame] | 98 | st_sensors_of_i2c_probe(client, st_accel_of_match); |
Denis Ciocca | d625116 | 2013-01-25 23:44:00 +0000 | [diff] [blame] | 99 | |
| 100 | st_sensors_i2c_configure(indio_dev, client, adata); |
| 101 | |
Denis CIOCCA | b6e6bda6 | 2014-10-03 17:35:36 +0200 | [diff] [blame] | 102 | err = st_accel_common_probe(indio_dev); |
Denis Ciocca | d625116 | 2013-01-25 23:44:00 +0000 | [diff] [blame] | 103 | if (err < 0) |
Sachin Kamat | 6b7e0a9 | 2013-07-23 07:47:00 +0100 | [diff] [blame] | 104 | return err; |
Denis Ciocca | d625116 | 2013-01-25 23:44:00 +0000 | [diff] [blame] | 105 | |
| 106 | return 0; |
Denis Ciocca | d625116 | 2013-01-25 23:44:00 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static int st_accel_i2c_remove(struct i2c_client *client) |
| 110 | { |
| 111 | st_accel_common_remove(i2c_get_clientdata(client)); |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | static const struct i2c_device_id st_accel_id_table[] = { |
| 117 | { LSM303DLH_ACCEL_DEV_NAME }, |
| 118 | { LSM303DLHC_ACCEL_DEV_NAME }, |
| 119 | { LIS3DH_ACCEL_DEV_NAME }, |
| 120 | { LSM330D_ACCEL_DEV_NAME }, |
| 121 | { LSM330DL_ACCEL_DEV_NAME }, |
| 122 | { LSM330DLC_ACCEL_DEV_NAME }, |
| 123 | { LIS331DLH_ACCEL_DEV_NAME }, |
| 124 | { LSM303DL_ACCEL_DEV_NAME }, |
| 125 | { LSM303DLM_ACCEL_DEV_NAME }, |
| 126 | { LSM330_ACCEL_DEV_NAME }, |
Giuseppe Barba | ddc05fa | 2015-07-21 10:35:44 +0200 | [diff] [blame] | 127 | { LSM303AGR_ACCEL_DEV_NAME }, |
Giuseppe Barba | 34dc578 | 2015-11-12 08:36:49 +0100 | [diff] [blame] | 128 | { LIS2DH12_ACCEL_DEV_NAME }, |
Denis Ciocca | d625116 | 2013-01-25 23:44:00 +0000 | [diff] [blame] | 129 | {}, |
| 130 | }; |
| 131 | MODULE_DEVICE_TABLE(i2c, st_accel_id_table); |
| 132 | |
| 133 | static struct i2c_driver st_accel_driver = { |
| 134 | .driver = { |
Denis Ciocca | d625116 | 2013-01-25 23:44:00 +0000 | [diff] [blame] | 135 | .name = "st-accel-i2c", |
Linus Walleij | 2d7768a | 2014-08-07 08:16:00 +0100 | [diff] [blame] | 136 | .of_match_table = of_match_ptr(st_accel_of_match), |
Denis Ciocca | d625116 | 2013-01-25 23:44:00 +0000 | [diff] [blame] | 137 | }, |
| 138 | .probe = st_accel_i2c_probe, |
| 139 | .remove = st_accel_i2c_remove, |
| 140 | .id_table = st_accel_id_table, |
| 141 | }; |
| 142 | module_i2c_driver(st_accel_driver); |
| 143 | |
| 144 | MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); |
| 145 | MODULE_DESCRIPTION("STMicroelectronics accelerometers i2c driver"); |
| 146 | MODULE_LICENSE("GPL v2"); |