These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / iio / accel / bmc150-accel-i2c.c
1 /*
2  * 3-axis accelerometer driver supporting following I2C Bosch-Sensortec chips:
3  *  - BMC150
4  *  - BMI055
5  *  - BMA255
6  *  - BMA250E
7  *  - BMA222E
8  *  - BMA280
9  *
10  * Copyright (c) 2014, Intel Corporation.
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms and conditions of the GNU General Public License,
14  * version 2, as published by the Free Software Foundation.
15  *
16  * This program is distributed in the hope it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19  * more details.
20  */
21
22 #include <linux/device.h>
23 #include <linux/mod_devicetable.h>
24 #include <linux/i2c.h>
25 #include <linux/module.h>
26 #include <linux/acpi.h>
27 #include <linux/regmap.h>
28
29 #include "bmc150-accel.h"
30
31 static const struct regmap_config bmc150_i2c_regmap_conf = {
32         .reg_bits = 8,
33         .val_bits = 8,
34 };
35
36 static int bmc150_accel_probe(struct i2c_client *client,
37                               const struct i2c_device_id *id)
38 {
39         struct regmap *regmap;
40         const char *name = NULL;
41         bool block_supported =
42                 i2c_check_functionality(client->adapter, I2C_FUNC_I2C) ||
43                 i2c_check_functionality(client->adapter,
44                                         I2C_FUNC_SMBUS_READ_I2C_BLOCK);
45
46         regmap = devm_regmap_init_i2c(client, &bmc150_i2c_regmap_conf);
47         if (IS_ERR(regmap)) {
48                 dev_err(&client->dev, "Failed to initialize i2c regmap\n");
49                 return PTR_ERR(regmap);
50         }
51
52         if (id)
53                 name = id->name;
54
55         return bmc150_accel_core_probe(&client->dev, regmap, client->irq, name,
56                                        block_supported);
57 }
58
59 static int bmc150_accel_remove(struct i2c_client *client)
60 {
61         return bmc150_accel_core_remove(&client->dev);
62 }
63
64 static const struct acpi_device_id bmc150_accel_acpi_match[] = {
65         {"BSBA0150",    bmc150},
66         {"BMC150A",     bmc150},
67         {"BMI055A",     bmi055},
68         {"BMA0255",     bma255},
69         {"BMA250E",     bma250e},
70         {"BMA222E",     bma222e},
71         {"BMA0280",     bma280},
72         { },
73 };
74 MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match);
75
76 static const struct i2c_device_id bmc150_accel_id[] = {
77         {"bmc150_accel",        bmc150},
78         {"bmi055_accel",        bmi055},
79         {"bma255",              bma255},
80         {"bma250e",             bma250e},
81         {"bma222e",             bma222e},
82         {"bma280",              bma280},
83         {}
84 };
85
86 MODULE_DEVICE_TABLE(i2c, bmc150_accel_id);
87
88 static struct i2c_driver bmc150_accel_driver = {
89         .driver = {
90                 .name   = "bmc150_accel_i2c",
91                 .acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match),
92                 .pm     = &bmc150_accel_pm_ops,
93         },
94         .probe          = bmc150_accel_probe,
95         .remove         = bmc150_accel_remove,
96         .id_table       = bmc150_accel_id,
97 };
98 module_i2c_driver(bmc150_accel_driver);
99
100 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
101 MODULE_LICENSE("GPL v2");
102 MODULE_DESCRIPTION("BMC150 I2C accelerometer driver");