Markus Pargmann | 1342645 | 2015-08-19 14:12:45 +0200 | [diff] [blame] | 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"); |