Thomas Gleixner | fda8d26 | 2019-05-28 09:57:06 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Lorenzo Bianconi | 3025c86 | 2017-11-23 23:59:05 +0100 | [diff] [blame] | 2 | /* |
| 3 | * STMicroelectronics uvis25 i2c driver |
| 4 | * |
| 5 | * Copyright 2017 STMicroelectronics Inc. |
| 6 | * |
| 7 | * Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> |
Lorenzo Bianconi | 3025c86 | 2017-11-23 23:59:05 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/module.h> |
Jonathan Cameron | 645aee5 | 2020-04-19 16:02:05 +0100 | [diff] [blame] | 12 | #include <linux/mod_devicetable.h> |
Lorenzo Bianconi | 3025c86 | 2017-11-23 23:59:05 +0100 | [diff] [blame] | 13 | #include <linux/i2c.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/regmap.h> |
| 16 | |
| 17 | #include "st_uvis25.h" |
| 18 | |
| 19 | #define UVIS25_I2C_AUTO_INCREMENT BIT(7) |
| 20 | |
Colin Ian King | debbbbe | 2017-12-04 12:04:06 +0000 | [diff] [blame] | 21 | static const struct regmap_config st_uvis25_i2c_regmap_config = { |
Lorenzo Bianconi | 3025c86 | 2017-11-23 23:59:05 +0100 | [diff] [blame] | 22 | .reg_bits = 8, |
| 23 | .val_bits = 8, |
| 24 | .write_flag_mask = UVIS25_I2C_AUTO_INCREMENT, |
| 25 | .read_flag_mask = UVIS25_I2C_AUTO_INCREMENT, |
| 26 | }; |
| 27 | |
| 28 | static int st_uvis25_i2c_probe(struct i2c_client *client, |
| 29 | const struct i2c_device_id *id) |
| 30 | { |
| 31 | struct regmap *regmap; |
| 32 | |
| 33 | regmap = devm_regmap_init_i2c(client, &st_uvis25_i2c_regmap_config); |
| 34 | if (IS_ERR(regmap)) { |
Andy Shevchenko | 3c50dee | 2020-03-13 12:49:48 +0200 | [diff] [blame] | 35 | dev_err(&client->dev, "Failed to register i2c regmap %ld\n", |
| 36 | PTR_ERR(regmap)); |
Lorenzo Bianconi | 3025c86 | 2017-11-23 23:59:05 +0100 | [diff] [blame] | 37 | return PTR_ERR(regmap); |
| 38 | } |
| 39 | |
| 40 | return st_uvis25_probe(&client->dev, client->irq, regmap); |
| 41 | } |
| 42 | |
| 43 | static const struct of_device_id st_uvis25_i2c_of_match[] = { |
| 44 | { .compatible = "st,uvis25", }, |
| 45 | {}, |
| 46 | }; |
| 47 | MODULE_DEVICE_TABLE(of, st_uvis25_i2c_of_match); |
| 48 | |
| 49 | static const struct i2c_device_id st_uvis25_i2c_id_table[] = { |
| 50 | { ST_UVIS25_DEV_NAME }, |
| 51 | {}, |
| 52 | }; |
| 53 | MODULE_DEVICE_TABLE(i2c, st_uvis25_i2c_id_table); |
| 54 | |
| 55 | static struct i2c_driver st_uvis25_driver = { |
| 56 | .driver = { |
| 57 | .name = "st_uvis25_i2c", |
| 58 | .pm = &st_uvis25_pm_ops, |
Jonathan Cameron | 645aee5 | 2020-04-19 16:02:05 +0100 | [diff] [blame] | 59 | .of_match_table = st_uvis25_i2c_of_match, |
Lorenzo Bianconi | 3025c86 | 2017-11-23 23:59:05 +0100 | [diff] [blame] | 60 | }, |
| 61 | .probe = st_uvis25_i2c_probe, |
| 62 | .id_table = st_uvis25_i2c_id_table, |
| 63 | }; |
| 64 | module_i2c_driver(st_uvis25_driver); |
| 65 | |
| 66 | MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>"); |
| 67 | MODULE_DESCRIPTION("STMicroelectronics uvis25 i2c driver"); |
| 68 | MODULE_LICENSE("GPL v2"); |