Lorenzo Bianconi | e4a70e3 | 2016-10-13 22:06:04 +0200 | [diff] [blame] | 1 | /* |
| 2 | * STMicroelectronics hts221 i2c driver |
| 3 | * |
| 4 | * Copyright 2016 STMicroelectronics Inc. |
| 5 | * |
| 6 | * Lorenzo Bianconi <lorenzo.bianconi@st.com> |
| 7 | * |
| 8 | * Licensed under the GPL-2. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/module.h> |
Shrirang Bagul | 25fc503 | 2016-11-24 17:07:54 +0800 | [diff] [blame] | 13 | #include <linux/acpi.h> |
Lorenzo Bianconi | e4a70e3 | 2016-10-13 22:06:04 +0200 | [diff] [blame] | 14 | #include <linux/i2c.h> |
| 15 | #include <linux/slab.h> |
Lorenzo Bianconi | 6217792 | 2018-01-08 23:12:30 +0100 | [diff] [blame] | 16 | #include <linux/regmap.h> |
| 17 | |
Lorenzo Bianconi | e4a70e3 | 2016-10-13 22:06:04 +0200 | [diff] [blame] | 18 | #include "hts221.h" |
| 19 | |
Lorenzo Bianconi | 6217792 | 2018-01-08 23:12:30 +0100 | [diff] [blame] | 20 | #define HTS221_I2C_AUTO_INCREMENT BIT(7) |
Lorenzo Bianconi | e4a70e3 | 2016-10-13 22:06:04 +0200 | [diff] [blame] | 21 | |
Lorenzo Bianconi | 6217792 | 2018-01-08 23:12:30 +0100 | [diff] [blame] | 22 | static const struct regmap_config hts221_i2c_regmap_config = { |
| 23 | .reg_bits = 8, |
| 24 | .val_bits = 8, |
| 25 | .write_flag_mask = HTS221_I2C_AUTO_INCREMENT, |
| 26 | .read_flag_mask = HTS221_I2C_AUTO_INCREMENT, |
Lorenzo Bianconi | e4a70e3 | 2016-10-13 22:06:04 +0200 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | static int hts221_i2c_probe(struct i2c_client *client, |
| 30 | const struct i2c_device_id *id) |
| 31 | { |
Lorenzo Bianconi | 6217792 | 2018-01-08 23:12:30 +0100 | [diff] [blame] | 32 | struct regmap *regmap; |
| 33 | |
| 34 | regmap = devm_regmap_init_i2c(client, &hts221_i2c_regmap_config); |
| 35 | if (IS_ERR(regmap)) { |
| 36 | dev_err(&client->dev, "Failed to register i2c regmap %d\n", |
| 37 | (int)PTR_ERR(regmap)); |
| 38 | return PTR_ERR(regmap); |
| 39 | } |
| 40 | |
Lorenzo Bianconi | e1ca114 | 2017-12-30 00:33:04 +0100 | [diff] [blame] | 41 | return hts221_probe(&client->dev, client->irq, |
Lorenzo Bianconi | 6217792 | 2018-01-08 23:12:30 +0100 | [diff] [blame] | 42 | client->name, regmap); |
Lorenzo Bianconi | e4a70e3 | 2016-10-13 22:06:04 +0200 | [diff] [blame] | 43 | } |
| 44 | |
Shrirang Bagul | 25fc503 | 2016-11-24 17:07:54 +0800 | [diff] [blame] | 45 | static const struct acpi_device_id hts221_acpi_match[] = { |
| 46 | {"SMO9100", 0}, |
| 47 | { }, |
| 48 | }; |
| 49 | MODULE_DEVICE_TABLE(acpi, hts221_acpi_match); |
| 50 | |
Lorenzo Bianconi | e4a70e3 | 2016-10-13 22:06:04 +0200 | [diff] [blame] | 51 | static const struct of_device_id hts221_i2c_of_match[] = { |
| 52 | { .compatible = "st,hts221", }, |
| 53 | {}, |
| 54 | }; |
| 55 | MODULE_DEVICE_TABLE(of, hts221_i2c_of_match); |
| 56 | |
| 57 | static const struct i2c_device_id hts221_i2c_id_table[] = { |
| 58 | { HTS221_DEV_NAME }, |
| 59 | {}, |
| 60 | }; |
| 61 | MODULE_DEVICE_TABLE(i2c, hts221_i2c_id_table); |
| 62 | |
| 63 | static struct i2c_driver hts221_driver = { |
| 64 | .driver = { |
| 65 | .name = "hts221_i2c", |
Lorenzo Bianconi | b7079ee | 2017-05-14 17:45:44 +0200 | [diff] [blame] | 66 | .pm = &hts221_pm_ops, |
Lorenzo Bianconi | e4a70e3 | 2016-10-13 22:06:04 +0200 | [diff] [blame] | 67 | .of_match_table = of_match_ptr(hts221_i2c_of_match), |
Shrirang Bagul | 25fc503 | 2016-11-24 17:07:54 +0800 | [diff] [blame] | 68 | .acpi_match_table = ACPI_PTR(hts221_acpi_match), |
Lorenzo Bianconi | e4a70e3 | 2016-10-13 22:06:04 +0200 | [diff] [blame] | 69 | }, |
| 70 | .probe = hts221_i2c_probe, |
| 71 | .id_table = hts221_i2c_id_table, |
| 72 | }; |
| 73 | module_i2c_driver(hts221_driver); |
| 74 | |
| 75 | MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>"); |
| 76 | MODULE_DESCRIPTION("STMicroelectronics hts221 i2c driver"); |
| 77 | MODULE_LICENSE("GPL v2"); |