1d4921643SHugo Villeneuve // SPDX-License-Identifier: GPL-2.0+ 2d4921643SHugo Villeneuve /* SC16IS7xx I2C interface driver */ 3d4921643SHugo Villeneuve 4d4921643SHugo Villeneuve #include <linux/dev_printk.h> 5d4921643SHugo Villeneuve #include <linux/i2c.h> 6d4921643SHugo Villeneuve #include <linux/mod_devicetable.h> 7d4921643SHugo Villeneuve #include <linux/module.h> 8d4921643SHugo Villeneuve #include <linux/regmap.h> 9d4921643SHugo Villeneuve #include <linux/string.h> 10d4921643SHugo Villeneuve 11d4921643SHugo Villeneuve #include "sc16is7xx.h" 12d4921643SHugo Villeneuve 13d4921643SHugo Villeneuve static int sc16is7xx_i2c_probe(struct i2c_client *i2c) 14d4921643SHugo Villeneuve { 15d4921643SHugo Villeneuve const struct sc16is7xx_devtype *devtype; 16d4921643SHugo Villeneuve struct regmap *regmaps[SC16IS7XX_MAX_PORTS]; 17*48d4a801SHugo Villeneuve struct regmap_config regcfg; 18d4921643SHugo Villeneuve unsigned int i; 19d4921643SHugo Villeneuve 20d4921643SHugo Villeneuve devtype = i2c_get_match_data(i2c); 21d4921643SHugo Villeneuve if (!devtype) 22d4921643SHugo Villeneuve return dev_err_probe(&i2c->dev, -ENODEV, "Failed to match device\n"); 23d4921643SHugo Villeneuve 24*48d4a801SHugo Villeneuve memcpy(®cfg, &sc16is7xx_regcfg, sizeof(struct regmap_config)); 25*48d4a801SHugo Villeneuve 26d4921643SHugo Villeneuve for (i = 0; i < devtype->nr_uart; i++) { 27*48d4a801SHugo Villeneuve regcfg.name = sc16is7xx_regmap_name(i); 28*48d4a801SHugo Villeneuve regcfg.read_flag_mask = sc16is7xx_regmap_port_mask(i); 29*48d4a801SHugo Villeneuve regcfg.write_flag_mask = sc16is7xx_regmap_port_mask(i); 30*48d4a801SHugo Villeneuve regmaps[i] = devm_regmap_init_i2c(i2c, ®cfg); 31d4921643SHugo Villeneuve } 32d4921643SHugo Villeneuve 33d4921643SHugo Villeneuve return sc16is7xx_probe(&i2c->dev, devtype, regmaps, i2c->irq); 34d4921643SHugo Villeneuve } 35d4921643SHugo Villeneuve 36d4921643SHugo Villeneuve static void sc16is7xx_i2c_remove(struct i2c_client *client) 37d4921643SHugo Villeneuve { 38d4921643SHugo Villeneuve sc16is7xx_remove(&client->dev); 39d4921643SHugo Villeneuve } 40d4921643SHugo Villeneuve 41d4921643SHugo Villeneuve static const struct i2c_device_id sc16is7xx_i2c_id_table[] = { 42d4921643SHugo Villeneuve { "sc16is74x", (kernel_ulong_t)&sc16is74x_devtype, }, 43d4921643SHugo Villeneuve { "sc16is740", (kernel_ulong_t)&sc16is74x_devtype, }, 44d4921643SHugo Villeneuve { "sc16is741", (kernel_ulong_t)&sc16is74x_devtype, }, 45d4921643SHugo Villeneuve { "sc16is750", (kernel_ulong_t)&sc16is750_devtype, }, 46d4921643SHugo Villeneuve { "sc16is752", (kernel_ulong_t)&sc16is752_devtype, }, 47d4921643SHugo Villeneuve { "sc16is760", (kernel_ulong_t)&sc16is760_devtype, }, 48d4921643SHugo Villeneuve { "sc16is762", (kernel_ulong_t)&sc16is762_devtype, }, 49d4921643SHugo Villeneuve { } 50d4921643SHugo Villeneuve }; 51d4921643SHugo Villeneuve MODULE_DEVICE_TABLE(i2c, sc16is7xx_i2c_id_table); 52d4921643SHugo Villeneuve 53d4921643SHugo Villeneuve static struct i2c_driver sc16is7xx_i2c_driver = { 54d4921643SHugo Villeneuve .driver = { 55d4921643SHugo Villeneuve .name = SC16IS7XX_NAME, 56d4921643SHugo Villeneuve .of_match_table = sc16is7xx_dt_ids, 57d4921643SHugo Villeneuve }, 58d4921643SHugo Villeneuve .probe = sc16is7xx_i2c_probe, 59d4921643SHugo Villeneuve .remove = sc16is7xx_i2c_remove, 60d4921643SHugo Villeneuve .id_table = sc16is7xx_i2c_id_table, 61d4921643SHugo Villeneuve }; 62d4921643SHugo Villeneuve 63d4921643SHugo Villeneuve module_i2c_driver(sc16is7xx_i2c_driver); 64d4921643SHugo Villeneuve 65d4921643SHugo Villeneuve MODULE_LICENSE("GPL"); 66d4921643SHugo Villeneuve MODULE_DESCRIPTION("SC16IS7xx I2C interface driver"); 67d4921643SHugo Villeneuve MODULE_IMPORT_NS(SERIAL_NXP_SC16IS7XX); 68