Lines Matching +full:reg +full:- +full:addr
1 // SPDX-License-Identifier: GPL-2.0
4 * - LP8764
5 * - TPS65224
6 * - TPS652G1
7 * - TPS6593
8 * - TPS6594
10 * Copyright (C) 2023 BayLibre Incorporated - https://www.baylibre.com/
37 return -EIO; in tps6594_i2c_transfer()
40 static int tps6594_i2c_reg_read_with_crc(struct i2c_client *client, u8 page, u8 reg, u8 *val) in tps6594_i2c_reg_read_with_crc() argument
45 const u8 addr = client->addr + page; in tps6594_i2c_reg_read_with_crc() local
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()
55 u8 crc_data[] = { addr << 1, reg, addr << 1 | 1, 0 }; in tps6594_i2c_reg_read_with_crc()
59 msgs[0].addr = addr; in tps6594_i2c_reg_read_with_crc()
62 msgs[0].buf = ® in tps6594_i2c_reg_read_with_crc()
65 msgs[1].addr = msgs[0].addr; 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()
81 static int tps6594_i2c_reg_write_with_crc(struct i2c_client *client, u8 page, u8 reg, u8 val) in tps6594_i2c_reg_write_with_crc() argument
84 u8 buf[] = { reg, val, 0 }; in tps6594_i2c_reg_write_with_crc()
86 const u8 addr = client->addr + page; in tps6594_i2c_reg_write_with_crc() local
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()
95 const u8 crc_data[] = { addr << 1, reg, val }; in tps6594_i2c_reg_write_with_crc()
98 msg.addr = addr; 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()
117 u8 reg = reg_bytes[0]; in tps6594_i2c_read() local
121 if (tps->use_crc) { in tps6594_i2c_read()
123 * Auto-increment feature does not support CRC protocol. in tps6594_i2c_read()
127 ret = tps6594_i2c_reg_read_with_crc(client, page, reg + i, val_bytes + i); in tps6594_i2c_read()
133 msgs[0].addr = client->addr + page; in tps6594_i2c_read()
136 msgs[0].buf = ® in tps6594_i2c_read()
139 msgs[1].addr = msgs[0].addr; in tps6594_i2c_read()
144 return tps6594_i2c_transfer(client->adapter, msgs, 2); in tps6594_i2c_read()
155 const u8 reg = bytes[0]; in tps6594_i2c_write() local
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()
165 ret = tps6594_i2c_reg_write_with_crc(client, page, reg + i, bytes[i + 2]); in tps6594_i2c_write()
171 buf = kzalloc(--count, GFP_KERNEL); in tps6594_i2c_write()
173 return -ENOMEM; in tps6594_i2c_write()
175 buf[0] = reg; in tps6594_i2c_write()
176 for (i = 0 ; i < count - 1 ; i++) 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()