Lines Matching +full:auto +full:- +full:i2c
1 // SPDX-License-Identifier: GPL-2.0
3 * I2C access driver for the following TI PMICs:
4 * - LP8764
5 * - TPS65224
6 * - TPS652G1
7 * - TPS6593
8 * - TPS6594
10 * Copyright (C) 2023 BayLibre Incorporated - https://www.baylibre.com/
14 #include <linux/i2c.h>
24 MODULE_PARM_DESC(enable_crc, "Enable CRC feature for I2C interface");
37 return -EIO; in tps6594_i2c_transfer()
44 /* I2C address = I2C base address + Page index */ in tps6594_i2c_reg_read_with_crc()
45 const u8 addr = client->addr + page; in tps6594_i2c_reg_read_with_crc()
49 * - B0: (I2C_addr_7bits << 1) | WR_bit, with WR_bit = 0 in tps6594_i2c_reg_read_with_crc()
50 * - B1: reg in tps6594_i2c_reg_read_with_crc()
51 * - B2: (I2C_addr_7bits << 1) | RD_bit, with RD_bit = 1 in tps6594_i2c_reg_read_with_crc()
52 * - B3: val in tps6594_i2c_reg_read_with_crc()
53 * - B4: CRC from B0-B1-B2-B3 in tps6594_i2c_reg_read_with_crc()
70 ret = tps6594_i2c_transfer(client->adapter, msgs, 2); in tps6594_i2c_reg_read_with_crc()
74 crc_data[sizeof(crc_data) - 1] = *val = buf_rx[0]; in tps6594_i2c_reg_read_with_crc()
76 return -EIO; in tps6594_i2c_reg_read_with_crc()
85 /* I2C address = I2C base address + Page index */ in tps6594_i2c_reg_write_with_crc()
86 const u8 addr = client->addr + page; in tps6594_i2c_reg_write_with_crc()
90 * - B0: (I2C_addr_7bits << 1) | WR_bit, with WR_bit = 0 in tps6594_i2c_reg_write_with_crc()
91 * - B1: reg in tps6594_i2c_reg_write_with_crc()
92 * - B2: val in tps6594_i2c_reg_write_with_crc()
93 * - B3: CRC from B0-B1-B2 in tps6594_i2c_reg_write_with_crc()
99 msg.flags = client->flags & I2C_M_TEN; in tps6594_i2c_reg_write_with_crc()
103 buf[msg.len - 1] = crc8(tps6594_i2c_crc_table, crc_data, sizeof(crc_data), CRC8_INIT_VALUE); in tps6594_i2c_reg_write_with_crc()
105 return tps6594_i2c_transfer(client->adapter, &msg, 1); in tps6594_i2c_reg_write_with_crc()
121 if (tps->use_crc) { in tps6594_i2c_read()
123 * Auto-increment feature does not support CRC protocol. in tps6594_i2c_read()
132 /* Write register: I2C address = I2C base address + Page index */ in tps6594_i2c_read()
133 msgs[0].addr = client->addr + page; in tps6594_i2c_read()
144 return tps6594_i2c_transfer(client->adapter, msgs, 2); in tps6594_i2c_read()
159 if (tps->use_crc) { in tps6594_i2c_write()
161 * Auto-increment feature does not support CRC protocol. in tps6594_i2c_write()
164 for (i = 0 ; ret == 0 && i < count - 2 ; i++) in tps6594_i2c_write()
171 buf = kzalloc(--count, GFP_KERNEL); in tps6594_i2c_write()
173 return -ENOMEM; in tps6594_i2c_write()
176 for (i = 0 ; i < count - 1 ; i++) in tps6594_i2c_write()
179 /* Write register and data: I2C address = I2C base address + Page index */ in tps6594_i2c_write()
180 msg.addr = client->addr + page; in tps6594_i2c_write()
181 msg.flags = client->flags & I2C_M_TEN; in tps6594_i2c_write()
185 ret = tps6594_i2c_transfer(client->adapter, &msg, 1); in tps6594_i2c_write()
201 { .compatible = "ti,tps6594-q1", .data = (void *)TPS6594, },
202 { .compatible = "ti,tps6593-q1", .data = (void *)TPS6593, },
203 { .compatible = "ti,lp8764-q1", .data = (void *)LP8764, },
204 { .compatible = "ti,tps65224-q1", .data = (void *)TPS65224, },
212 struct device *dev = &client->dev; in tps6594_i2c_probe()
218 return -ENOMEM; in tps6594_i2c_probe()
222 tps->dev = dev; in tps6594_i2c_probe()
223 tps->reg = client->addr; in tps6594_i2c_probe()
224 tps->irq = client->irq; in tps6594_i2c_probe()
228 return dev_err_probe(dev, -EINVAL, "Failed to find matching chip ID\n"); in tps6594_i2c_probe()
229 tps->chip_id = (unsigned long)match->data; in tps6594_i2c_probe()
231 if (tps->chip_id == TPS65224 || tps->chip_id == TPS652G1) in tps6594_i2c_probe()
234 tps->regmap = devm_regmap_init(dev, NULL, client, &tps6594_i2c_regmap_config); in tps6594_i2c_probe()
235 if (IS_ERR(tps->regmap)) in tps6594_i2c_probe()
236 return dev_err_probe(dev, PTR_ERR(tps->regmap), "Failed to init regmap\n"); in tps6594_i2c_probe()
253 MODULE_DESCRIPTION("I2C Interface Driver for TPS65224, TPS6594/3, and LP8764");