blob: 57e40dd1222e8ad1bd058a52228dbc072b707ef2 [file] [log] [blame]
Daniel Baluta761b7912016-04-15 17:13:09 +03001/*
2 * 3-axis magnetometer driver supporting following I2C Bosch-Sensortec chips:
3 * - BMC150
4 * - BMC156
Daniel Baluta9d75db32016-04-26 15:39:58 +03005 * - BMM150
Daniel Baluta761b7912016-04-15 17:13:09 +03006 *
7 * Copyright (c) 2016, Intel Corporation.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms and conditions of the GNU General Public License,
11 * version 2, as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 */
18#include <linux/device.h>
19#include <linux/mod_devicetable.h>
20#include <linux/i2c.h>
21#include <linux/module.h>
22#include <linux/acpi.h>
23#include <linux/regmap.h>
24
25#include "bmc150_magn.h"
26
27static int bmc150_magn_i2c_probe(struct i2c_client *client,
28 const struct i2c_device_id *id)
29{
30 struct regmap *regmap;
31 const char *name = NULL;
32
33 regmap = devm_regmap_init_i2c(client, &bmc150_magn_regmap_config);
34 if (IS_ERR(regmap)) {
35 dev_err(&client->dev, "Failed to initialize i2c regmap\n");
36 return PTR_ERR(regmap);
37 }
38
39 if (id)
40 name = id->name;
41
42 return bmc150_magn_probe(&client->dev, regmap, client->irq, name);
43}
44
45static int bmc150_magn_i2c_remove(struct i2c_client *client)
46{
47 return bmc150_magn_remove(&client->dev);
48}
49
50static const struct acpi_device_id bmc150_magn_acpi_match[] = {
51 {"BMC150B", 0},
52 {"BMC156B", 0},
Daniel Baluta9d75db32016-04-26 15:39:58 +030053 {"BMM150B", 0},
Daniel Baluta761b7912016-04-15 17:13:09 +030054 {},
55};
56MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match);
57
58static const struct i2c_device_id bmc150_magn_i2c_id[] = {
59 {"bmc150_magn", 0},
60 {"bmc156_magn", 0},
Daniel Baluta9d75db32016-04-26 15:39:58 +030061 {"bmm150_magn", 0},
Daniel Baluta761b7912016-04-15 17:13:09 +030062 {}
63};
64MODULE_DEVICE_TABLE(i2c, bmc150_magn_i2c_id);
65
Javier Martinez Canillas49926b12017-03-15 01:44:51 -030066static const struct of_device_id bmc150_magn_of_match[] = {
67 { .compatible = "bosch,bmc150_magn" },
68 { .compatible = "bosch,bmc156_magn" },
69 { .compatible = "bosch,bmm150_magn" },
70 { }
71};
72MODULE_DEVICE_TABLE(of, bmc150_magn_of_match);
73
Daniel Baluta761b7912016-04-15 17:13:09 +030074static struct i2c_driver bmc150_magn_driver = {
75 .driver = {
76 .name = "bmc150_magn_i2c",
Javier Martinez Canillas49926b12017-03-15 01:44:51 -030077 .of_match_table = bmc150_magn_of_match,
Daniel Baluta761b7912016-04-15 17:13:09 +030078 .acpi_match_table = ACPI_PTR(bmc150_magn_acpi_match),
79 .pm = &bmc150_magn_pm_ops,
80 },
81 .probe = bmc150_magn_i2c_probe,
82 .remove = bmc150_magn_i2c_remove,
83 .id_table = bmc150_magn_i2c_id,
84};
85module_i2c_driver(bmc150_magn_driver);
86
87MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com");
88MODULE_LICENSE("GPL v2");
89MODULE_DESCRIPTION("BMC150 I2C magnetometer driver");