diff options
author | Markus Pargmann <mpa@pengutronix.de> | 2015-08-19 08:12:45 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2015-08-31 12:04:23 -0400 |
commit | 13426454b6493a847cebe276fb1ec3a7f1d48d0e (patch) | |
tree | 44e0323857282192fc582d197e5b2581b50c300a | |
parent | cb119d5350839297bbe8a382dbb2feff545742b5 (diff) |
iio: bmg160: Separate i2c and core driver
This patch separates the core driver using regmap and the i2c driver
which creates the i2c regmap. Also in the Kconfig file BMG160 and
BMG160_I2C are separate now.
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
Reviewed-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r-- | drivers/iio/gyro/Kconfig | 15 | ||||
-rw-r--r-- | drivers/iio/gyro/Makefile | 3 | ||||
-rw-r--r-- | drivers/iio/gyro/bmg160.h | 10 | ||||
-rw-r--r-- | drivers/iio/gyro/bmg160_core.c (renamed from drivers/iio/gyro/bmg160.c) | 76 | ||||
-rw-r--r-- | drivers/iio/gyro/bmg160_i2c.c | 71 |
5 files changed, 108 insertions, 67 deletions
diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig index cf82d74139a2..94526b13d49f 100644 --- a/drivers/iio/gyro/Kconfig +++ b/drivers/iio/gyro/Kconfig | |||
@@ -52,16 +52,21 @@ config ADXRS450 | |||
52 | 52 | ||
53 | config BMG160 | 53 | config BMG160 |
54 | tristate "BOSCH BMG160 Gyro Sensor" | 54 | tristate "BOSCH BMG160 Gyro Sensor" |
55 | depends on I2C | 55 | depends on (I2C || SPI_MASTER) |
56 | select IIO_BUFFER | 56 | select IIO_BUFFER |
57 | select IIO_TRIGGERED_BUFFER | 57 | select IIO_TRIGGERED_BUFFER |
58 | select REGMAP_I2C | 58 | select BMG160_I2C if (I2C) |
59 | help | 59 | help |
60 | Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor | 60 | Say yes here to build support for BOSCH BMG160 Tri-axis Gyro Sensor |
61 | driver. This driver also supports BMI055 gyroscope. | 61 | driver connected via I2C or SPI. This driver also supports BMI055 |
62 | gyroscope. | ||
62 | 63 | ||
63 | This driver can also be built as a module. If so, the module | 64 | This driver can also be built as a module. If so, the module |
64 | will be called bmg160. | 65 | will be called bmg160_i2c. |
66 | |||
67 | config BMG160_I2C | ||
68 | tristate | ||
69 | select REGMAP_I2C | ||
65 | 70 | ||
66 | config HID_SENSOR_GYRO_3D | 71 | config HID_SENSOR_GYRO_3D |
67 | depends on HID_SENSOR_HUB | 72 | depends on HID_SENSOR_HUB |
diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile index f46341b39139..608401041550 100644 --- a/drivers/iio/gyro/Makefile +++ b/drivers/iio/gyro/Makefile | |||
@@ -8,7 +8,8 @@ obj-$(CONFIG_ADIS16130) += adis16130.o | |||
8 | obj-$(CONFIG_ADIS16136) += adis16136.o | 8 | obj-$(CONFIG_ADIS16136) += adis16136.o |
9 | obj-$(CONFIG_ADIS16260) += adis16260.o | 9 | obj-$(CONFIG_ADIS16260) += adis16260.o |
10 | obj-$(CONFIG_ADXRS450) += adxrs450.o | 10 | obj-$(CONFIG_ADXRS450) += adxrs450.o |
11 | obj-$(CONFIG_BMG160) += bmg160.o | 11 | obj-$(CONFIG_BMG160) += bmg160_core.o |
12 | obj-$(CONFIG_BMG160_I2C) += bmg160_i2c.o | ||
12 | 13 | ||
13 | obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o | 14 | obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o |
14 | 15 | ||
diff --git a/drivers/iio/gyro/bmg160.h b/drivers/iio/gyro/bmg160.h new file mode 100644 index 000000000000..72db723c8fb6 --- /dev/null +++ b/drivers/iio/gyro/bmg160.h | |||
@@ -0,0 +1,10 @@ | |||
1 | #ifndef BMG160_H_ | ||
2 | #define BMG160_H_ | ||
3 | |||
4 | extern const struct dev_pm_ops bmg160_pm_ops; | ||
5 | |||
6 | int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq, | ||
7 | const char *name); | ||
8 | void bmg160_core_remove(struct device *dev); | ||
9 | |||
10 | #endif /* BMG160_H_ */ | ||
diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160_core.c index ca12402ffd93..02ff789852a0 100644 --- a/drivers/iio/gyro/bmg160.c +++ b/drivers/iio/gyro/bmg160_core.c | |||
@@ -13,7 +13,6 @@ | |||
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/i2c.h> | ||
17 | #include <linux/interrupt.h> | 16 | #include <linux/interrupt.h> |
18 | #include <linux/delay.h> | 17 | #include <linux/delay.h> |
19 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
@@ -29,8 +28,8 @@ | |||
29 | #include <linux/iio/trigger_consumer.h> | 28 | #include <linux/iio/trigger_consumer.h> |
30 | #include <linux/iio/triggered_buffer.h> | 29 | #include <linux/iio/triggered_buffer.h> |
31 | #include <linux/regmap.h> | 30 | #include <linux/regmap.h> |
31 | #include "bmg160.h" | ||
32 | 32 | ||
33 | #define BMG160_DRV_NAME "bmg160" | ||
34 | #define BMG160_IRQ_NAME "bmg160_event" | 33 | #define BMG160_IRQ_NAME "bmg160_event" |
35 | #define BMG160_GPIO_NAME "gpio_int" | 34 | #define BMG160_GPIO_NAME "gpio_int" |
36 | 35 | ||
@@ -137,12 +136,6 @@ static const struct { | |||
137 | { 133, BMG160_RANGE_250DPS}, | 136 | { 133, BMG160_RANGE_250DPS}, |
138 | { 66, BMG160_RANGE_125DPS} }; | 137 | { 66, BMG160_RANGE_125DPS} }; |
139 | 138 | ||
140 | static struct regmap_config bmg160_regmap_i2c_conf = { | ||
141 | .reg_bits = 8, | ||
142 | .val_bits = 8, | ||
143 | .max_register = 0x3f | ||
144 | }; | ||
145 | |||
146 | static int bmg160_set_mode(struct bmg160_data *data, u8 mode) | 139 | static int bmg160_set_mode(struct bmg160_data *data, u8 mode) |
147 | { | 140 | { |
148 | int ret; | 141 | int ret; |
@@ -996,31 +989,22 @@ static const char *bmg160_match_acpi_device(struct device *dev) | |||
996 | return dev_name(dev); | 989 | return dev_name(dev); |
997 | } | 990 | } |
998 | 991 | ||
999 | static int bmg160_probe(struct i2c_client *client, | 992 | int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq, |
1000 | const struct i2c_device_id *id) | 993 | const char *name) |
1001 | { | 994 | { |
1002 | struct bmg160_data *data; | 995 | struct bmg160_data *data; |
1003 | struct iio_dev *indio_dev; | 996 | struct iio_dev *indio_dev; |
1004 | int ret; | 997 | int ret; |
1005 | const char *name = NULL; | ||
1006 | struct regmap *regmap; | ||
1007 | struct device *dev = &client->dev; | ||
1008 | |||
1009 | regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf); | ||
1010 | if (IS_ERR(regmap)) { | ||
1011 | dev_err(&client->dev, "Failed to register i2c regmap %d\n", | ||
1012 | (int)PTR_ERR(regmap)); | ||
1013 | return PTR_ERR(regmap); | ||
1014 | } | ||
1015 | 998 | ||
1016 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); | 999 | indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); |
1017 | if (!indio_dev) | 1000 | if (!indio_dev) |
1018 | return -ENOMEM; | 1001 | return -ENOMEM; |
1019 | 1002 | ||
1020 | data = iio_priv(indio_dev); | 1003 | data = iio_priv(indio_dev); |
1021 | dev_set_drvdata(dev, indio_dev); | 1004 | dev_set_drvdata(dev, indio_dev); |
1022 | data->dev = dev; | 1005 | data->dev = dev; |
1023 | data->irq = client->irq; | 1006 | data->irq = irq; |
1007 | data->regmap = regmap; | ||
1024 | 1008 | ||
1025 | ret = bmg160_chip_init(data); | 1009 | ret = bmg160_chip_init(data); |
1026 | if (ret < 0) | 1010 | if (ret < 0) |
@@ -1028,9 +1012,6 @@ static int bmg160_probe(struct i2c_client *client, | |||
1028 | 1012 | ||
1029 | mutex_init(&data->mutex); | 1013 | mutex_init(&data->mutex); |
1030 | 1014 | ||
1031 | if (id) | ||
1032 | name = id->name; | ||
1033 | |||
1034 | if (ACPI_HANDLE(dev)) | 1015 | if (ACPI_HANDLE(dev)) |
1035 | name = bmg160_match_acpi_device(dev); | 1016 | name = bmg160_match_acpi_device(dev); |
1036 | 1017 | ||
@@ -1125,15 +1106,16 @@ err_trigger_unregister: | |||
1125 | 1106 | ||
1126 | return ret; | 1107 | return ret; |
1127 | } | 1108 | } |
1109 | EXPORT_SYMBOL_GPL(bmg160_core_probe); | ||
1128 | 1110 | ||
1129 | static int bmg160_remove(struct i2c_client *client) | 1111 | void bmg160_core_remove(struct device *dev) |
1130 | { | 1112 | { |
1131 | struct iio_dev *indio_dev = i2c_get_clientdata(client); | 1113 | struct iio_dev *indio_dev = dev_get_drvdata(dev); |
1132 | struct bmg160_data *data = iio_priv(indio_dev); | 1114 | struct bmg160_data *data = iio_priv(indio_dev); |
1133 | 1115 | ||
1134 | pm_runtime_disable(&client->dev); | 1116 | pm_runtime_disable(dev); |
1135 | pm_runtime_set_suspended(&client->dev); | 1117 | pm_runtime_set_suspended(dev); |
1136 | pm_runtime_put_noidle(&client->dev); | 1118 | pm_runtime_put_noidle(dev); |
1137 | 1119 | ||
1138 | iio_device_unregister(indio_dev); | 1120 | iio_device_unregister(indio_dev); |
1139 | iio_triggered_buffer_cleanup(indio_dev); | 1121 | iio_triggered_buffer_cleanup(indio_dev); |
@@ -1146,9 +1128,8 @@ static int bmg160_remove(struct i2c_client *client) | |||
1146 | mutex_lock(&data->mutex); | 1128 | mutex_lock(&data->mutex); |
1147 | bmg160_set_mode(data, BMG160_MODE_DEEP_SUSPEND); | 1129 | bmg160_set_mode(data, BMG160_MODE_DEEP_SUSPEND); |
1148 | mutex_unlock(&data->mutex); | 1130 | mutex_unlock(&data->mutex); |
1149 | |||
1150 | return 0; | ||
1151 | } | 1131 | } |
1132 | EXPORT_SYMBOL_GPL(bmg160_core_remove); | ||
1152 | 1133 | ||
1153 | #ifdef CONFIG_PM_SLEEP | 1134 | #ifdef CONFIG_PM_SLEEP |
1154 | static int bmg160_suspend(struct device *dev) | 1135 | static int bmg160_suspend(struct device *dev) |
@@ -1210,39 +1191,12 @@ static int bmg160_runtime_resume(struct device *dev) | |||
1210 | } | 1191 | } |
1211 | #endif | 1192 | #endif |
1212 | 1193 | ||
1213 | static const struct dev_pm_ops bmg160_pm_ops = { | 1194 | const struct dev_pm_ops bmg160_pm_ops = { |
1214 | SET_SYSTEM_SLEEP_PM_OPS(bmg160_suspend, bmg160_resume) | 1195 | SET_SYSTEM_SLEEP_PM_OPS(bmg160_suspend, bmg160_resume) |
1215 | SET_RUNTIME_PM_OPS(bmg160_runtime_suspend, | 1196 | SET_RUNTIME_PM_OPS(bmg160_runtime_suspend, |
1216 | bmg160_runtime_resume, NULL) | 1197 | bmg160_runtime_resume, NULL) |
1217 | }; | 1198 | }; |
1218 | 1199 | EXPORT_SYMBOL_GPL(bmg160_pm_ops); | |
1219 | static const struct acpi_device_id bmg160_acpi_match[] = { | ||
1220 | {"BMG0160", 0}, | ||
1221 | {"BMI055B", 0}, | ||
1222 | {}, | ||
1223 | }; | ||
1224 | |||
1225 | MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match); | ||
1226 | |||
1227 | static const struct i2c_device_id bmg160_id[] = { | ||
1228 | {"bmg160", 0}, | ||
1229 | {"bmi055_gyro", 0}, | ||
1230 | {} | ||
1231 | }; | ||
1232 | |||
1233 | MODULE_DEVICE_TABLE(i2c, bmg160_id); | ||
1234 | |||
1235 | static struct i2c_driver bmg160_driver = { | ||
1236 | .driver = { | ||
1237 | .name = BMG160_DRV_NAME, | ||
1238 | .acpi_match_table = ACPI_PTR(bmg160_acpi_match), | ||
1239 | .pm = &bmg160_pm_ops, | ||
1240 | }, | ||
1241 | .probe = bmg160_probe, | ||
1242 | .remove = bmg160_remove, | ||
1243 | .id_table = bmg160_id, | ||
1244 | }; | ||
1245 | module_i2c_driver(bmg160_driver); | ||
1246 | 1200 | ||
1247 | MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>"); | 1201 | MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>"); |
1248 | MODULE_LICENSE("GPL v2"); | 1202 | MODULE_LICENSE("GPL v2"); |
diff --git a/drivers/iio/gyro/bmg160_i2c.c b/drivers/iio/gyro/bmg160_i2c.c new file mode 100644 index 000000000000..90126a5a7663 --- /dev/null +++ b/drivers/iio/gyro/bmg160_i2c.c | |||
@@ -0,0 +1,71 @@ | |||
1 | #include <linux/i2c.h> | ||
2 | #include <linux/regmap.h> | ||
3 | #include <linux/iio/iio.h> | ||
4 | #include <linux/module.h> | ||
5 | #include <linux/acpi.h> | ||
6 | |||
7 | #include "bmg160.h" | ||
8 | |||
9 | static const struct regmap_config bmg160_regmap_i2c_conf = { | ||
10 | .reg_bits = 8, | ||
11 | .val_bits = 8, | ||
12 | .max_register = 0x3f | ||
13 | }; | ||
14 | |||
15 | static int bmg160_i2c_probe(struct i2c_client *client, | ||
16 | const struct i2c_device_id *id) | ||
17 | { | ||
18 | struct regmap *regmap; | ||
19 | const char *name = NULL; | ||
20 | |||
21 | regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf); | ||
22 | if (IS_ERR(regmap)) { | ||
23 | dev_err(&client->dev, "Failed to register i2c regmap %d\n", | ||
24 | (int)PTR_ERR(regmap)); | ||
25 | return PTR_ERR(regmap); | ||
26 | } | ||
27 | |||
28 | if (id) | ||
29 | name = id->name; | ||
30 | |||
31 | return bmg160_core_probe(&client->dev, regmap, client->irq, name); | ||
32 | } | ||
33 | |||
34 | static int bmg160_i2c_remove(struct i2c_client *client) | ||
35 | { | ||
36 | bmg160_core_remove(&client->dev); | ||
37 | |||
38 | return 0; | ||
39 | } | ||
40 | |||
41 | static const struct acpi_device_id bmg160_acpi_match[] = { | ||
42 | {"BMG0160", 0}, | ||
43 | {"BMI055B", 0}, | ||
44 | {}, | ||
45 | }; | ||
46 | |||
47 | MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match); | ||
48 | |||
49 | static const struct i2c_device_id bmg160_i2c_id[] = { | ||
50 | {"bmg160", 0}, | ||
51 | {"bmi055_gyro", 0}, | ||
52 | {} | ||
53 | }; | ||
54 | |||
55 | MODULE_DEVICE_TABLE(i2c, bmg160_i2c_id); | ||
56 | |||
57 | static struct i2c_driver bmg160_i2c_driver = { | ||
58 | .driver = { | ||
59 | .name = "bmg160_i2c", | ||
60 | .acpi_match_table = ACPI_PTR(bmg160_acpi_match), | ||
61 | .pm = &bmg160_pm_ops, | ||
62 | }, | ||
63 | .probe = bmg160_i2c_probe, | ||
64 | .remove = bmg160_i2c_remove, | ||
65 | .id_table = bmg160_i2c_id, | ||
66 | }; | ||
67 | module_i2c_driver(bmg160_i2c_driver); | ||
68 | |||
69 | MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>"); | ||
70 | MODULE_LICENSE("GPL v2"); | ||
71 | MODULE_DESCRIPTION("BMG160 I2C Gyro driver"); | ||