| 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | /* |
| 3 | * Copyright (C) 2022 ROHM Semiconductors |
| 4 | * |
| 5 | * ROHM/KIONIX accelerometer driver |
| 6 | */ |
| 7 | |
| 8 | #include <linux/i2c.h> |
| 9 | #include <linux/interrupt.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/regmap.h> |
| 12 | |
| 13 | #include "kionix-kx022a.h" |
| 14 | |
| 15 | static int kx022a_i2c_probe(struct i2c_client *i2c) |
| 16 | { |
| 17 | struct device *dev = &i2c->dev; |
| 18 | const struct kx022a_chip_info *chip_info; |
| 19 | struct regmap *regmap; |
| 20 | |
| 21 | if (!i2c->irq) { |
| 22 | dev_err(dev, "No IRQ configured\n" ); |
| 23 | return -EINVAL; |
| 24 | } |
| 25 | |
| 26 | chip_info = i2c_get_match_data(client: i2c); |
| 27 | if (!chip_info) |
| 28 | return -EINVAL; |
| 29 | |
| 30 | regmap = devm_regmap_init_i2c(i2c, chip_info->regmap_config); |
| 31 | if (IS_ERR(ptr: regmap)) |
| 32 | return dev_err_probe(dev, err: PTR_ERR(ptr: regmap), |
| 33 | fmt: "Failed to initialize Regmap\n" ); |
| 34 | |
| 35 | return kx022a_probe_internal(dev, chip_info); |
| 36 | } |
| 37 | |
| 38 | static const struct i2c_device_id kx022a_i2c_id[] = { |
| 39 | { .name = "kx022a" , .driver_data = (kernel_ulong_t)&kx022a_chip_info }, |
| 40 | { .name = "kx132-1211" , .driver_data = (kernel_ulong_t)&kx132_chip_info }, |
| 41 | { .name = "kx134-1211" , .driver_data = (kernel_ulong_t)&kx134_chip_info }, |
| 42 | { .name = "kx132acr-lbz" , .driver_data = (kernel_ulong_t)&kx132acr_chip_info }, |
| 43 | { .name = "kx134acr-lbz" , .driver_data = (kernel_ulong_t)&kx134acr_chip_info }, |
| 44 | { } |
| 45 | }; |
| 46 | MODULE_DEVICE_TABLE(i2c, kx022a_i2c_id); |
| 47 | |
| 48 | static const struct of_device_id kx022a_of_match[] = { |
| 49 | { .compatible = "kionix,kx022a" , .data = &kx022a_chip_info }, |
| 50 | { .compatible = "kionix,kx132-1211" , .data = &kx132_chip_info }, |
| 51 | { .compatible = "kionix,kx134-1211" , .data = &kx134_chip_info }, |
| 52 | { .compatible = "rohm,kx132acr-lbz" , .data = &kx132acr_chip_info }, |
| 53 | { .compatible = "rohm,kx134acr-lbz" , .data = &kx134acr_chip_info }, |
| 54 | { } |
| 55 | }; |
| 56 | MODULE_DEVICE_TABLE(of, kx022a_of_match); |
| 57 | |
| 58 | static struct i2c_driver kx022a_i2c_driver = { |
| 59 | .driver = { |
| 60 | .name = "kx022a-i2c" , |
| 61 | .of_match_table = kx022a_of_match, |
| 62 | .probe_type = PROBE_PREFER_ASYNCHRONOUS, |
| 63 | }, |
| 64 | .probe = kx022a_i2c_probe, |
| 65 | .id_table = kx022a_i2c_id, |
| 66 | }; |
| 67 | module_i2c_driver(kx022a_i2c_driver); |
| 68 | |
| 69 | MODULE_DESCRIPTION("ROHM/Kionix KX022A accelerometer driver" ); |
| 70 | MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>" ); |
| 71 | MODULE_LICENSE("GPL" ); |
| 72 | MODULE_IMPORT_NS("IIO_KX022A" ); |
| 73 | |