Lines Matching +full:i2c +full:- +full:bus

1 // SPDX-License-Identifier: GPL-2.0
3 // Register map access API - I2C support
10 #include <linux/i2c.h>
19 struct i2c_client *i2c = to_i2c_client(dev); in regmap_smbus_byte_reg_read() local
23 return -EINVAL; in regmap_smbus_byte_reg_read()
25 ret = i2c_smbus_read_byte_data(i2c, reg); in regmap_smbus_byte_reg_read()
38 struct i2c_client *i2c = to_i2c_client(dev); in regmap_smbus_byte_reg_write() local
41 return -EINVAL; in regmap_smbus_byte_reg_write()
43 return i2c_smbus_write_byte_data(i2c, reg, val); in regmap_smbus_byte_reg_write()
55 struct i2c_client *i2c = to_i2c_client(dev); in regmap_smbus_word_reg_read() local
59 return -EINVAL; in regmap_smbus_word_reg_read()
61 ret = i2c_smbus_read_word_data(i2c, reg); in regmap_smbus_word_reg_read()
74 struct i2c_client *i2c = to_i2c_client(dev); in regmap_smbus_word_reg_write() local
77 return -EINVAL; in regmap_smbus_word_reg_write()
79 return i2c_smbus_write_word_data(i2c, reg, val); in regmap_smbus_word_reg_write()
91 struct i2c_client *i2c = to_i2c_client(dev); in regmap_smbus_word_read_swapped() local
95 return -EINVAL; in regmap_smbus_word_read_swapped()
97 ret = i2c_smbus_read_word_swapped(i2c, reg); in regmap_smbus_word_read_swapped()
110 struct i2c_client *i2c = to_i2c_client(dev); in regmap_smbus_word_write_swapped() local
113 return -EINVAL; in regmap_smbus_word_write_swapped()
115 return i2c_smbus_write_word_swapped(i2c, reg, val); in regmap_smbus_word_write_swapped()
126 struct i2c_client *i2c = to_i2c_client(dev); in regmap_i2c_write() local
129 ret = i2c_master_send(i2c, data, count); in regmap_i2c_write()
135 return -EIO; in regmap_i2c_write()
143 struct i2c_client *i2c = to_i2c_client(dev); in regmap_i2c_gather_write() local
147 /* If the I2C controller can't do a gather tell the core, it in regmap_i2c_gather_write()
150 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_NOSTART)) in regmap_i2c_gather_write()
151 return -ENOTSUPP; in regmap_i2c_gather_write()
153 xfer[0].addr = i2c->addr; in regmap_i2c_gather_write()
158 xfer[1].addr = i2c->addr; in regmap_i2c_gather_write()
163 ret = i2c_transfer(i2c->adapter, xfer, 2); in regmap_i2c_gather_write()
169 return -EIO; in regmap_i2c_gather_write()
177 struct i2c_client *i2c = to_i2c_client(dev); in regmap_i2c_read() local
181 xfer[0].addr = i2c->addr; in regmap_i2c_read()
186 xfer[1].addr = i2c->addr; in regmap_i2c_read()
191 ret = i2c_transfer(i2c->adapter, xfer, 2); in regmap_i2c_read()
197 return -EIO; in regmap_i2c_read()
212 struct i2c_client *i2c = to_i2c_client(dev); in regmap_i2c_smbus_i2c_write() local
215 return -EINVAL; in regmap_i2c_smbus_i2c_write()
217 --count; in regmap_i2c_smbus_i2c_write()
218 return i2c_smbus_write_i2c_block_data(i2c, ((u8 *)data)[0], count, in regmap_i2c_smbus_i2c_write()
227 struct i2c_client *i2c = to_i2c_client(dev); in regmap_i2c_smbus_i2c_read() local
231 return -EINVAL; in regmap_i2c_smbus_i2c_read()
233 ret = i2c_smbus_read_i2c_block_data(i2c, ((u8 *)reg)[0], val_size, val); in regmap_i2c_smbus_i2c_read()
239 return -EIO; in regmap_i2c_smbus_i2c_read()
245 .max_raw_read = I2C_SMBUS_BLOCK_MAX - 1,
246 .max_raw_write = I2C_SMBUS_BLOCK_MAX - 1,
253 struct i2c_client *i2c = to_i2c_client(dev); in regmap_i2c_smbus_i2c_write_reg16() local
256 return -EINVAL; in regmap_i2c_smbus_i2c_write_reg16()
258 count--; in regmap_i2c_smbus_i2c_write_reg16()
259 return i2c_smbus_write_i2c_block_data(i2c, ((u8 *)data)[0], count, in regmap_i2c_smbus_i2c_write_reg16()
268 struct i2c_client *i2c = to_i2c_client(dev); in regmap_i2c_smbus_i2c_read_reg16() local
272 return -EINVAL; in regmap_i2c_smbus_i2c_read_reg16()
274 ret = i2c_smbus_write_byte_data(i2c, ((u16 *)reg)[0] & 0xff, in regmap_i2c_smbus_i2c_read_reg16()
282 ret = i2c_smbus_read_byte(i2c); in regmap_i2c_smbus_i2c_read_reg16()
288 len--; in regmap_i2c_smbus_i2c_read_reg16()
296 return -EIO; in regmap_i2c_smbus_i2c_read_reg16()
302 .max_raw_read = I2C_SMBUS_BLOCK_MAX - 2,
303 .max_raw_write = I2C_SMBUS_BLOCK_MAX - 2,
306 static const struct regmap_bus *regmap_get_i2c_bus(struct i2c_client *i2c, in regmap_get_i2c_bus() argument
310 const struct regmap_bus *bus = NULL; in regmap_get_i2c_bus() local
314 if (i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) in regmap_get_i2c_bus()
315 bus = &regmap_i2c; in regmap_get_i2c_bus()
316 else if (config->val_bits == 8 && config->reg_bits == 8 && in regmap_get_i2c_bus()
317 i2c_check_functionality(i2c->adapter, in regmap_get_i2c_bus()
319 bus = &regmap_i2c_smbus_i2c_block; in regmap_get_i2c_bus()
320 else if (config->val_bits == 8 && config->reg_bits == 16 && in regmap_get_i2c_bus()
321 i2c_check_functionality(i2c->adapter, in regmap_get_i2c_bus()
323 bus = &regmap_i2c_smbus_i2c_block_reg16; in regmap_get_i2c_bus()
324 else if (config->val_bits == 16 && config->reg_bits == 8 && in regmap_get_i2c_bus()
325 i2c_check_functionality(i2c->adapter, in regmap_get_i2c_bus()
327 switch (regmap_get_val_endian(&i2c->dev, NULL, config)) { in regmap_get_i2c_bus()
329 bus = &regmap_smbus_word; in regmap_get_i2c_bus()
332 bus = &regmap_smbus_word_swapped; in regmap_get_i2c_bus()
337 else if (config->val_bits == 8 && config->reg_bits == 8 && in regmap_get_i2c_bus()
338 i2c_check_functionality(i2c->adapter, in regmap_get_i2c_bus()
340 bus = &regmap_smbus_byte; in regmap_get_i2c_bus()
342 if (!bus) in regmap_get_i2c_bus()
343 return ERR_PTR(-ENOTSUPP); in regmap_get_i2c_bus()
345 quirks = i2c->adapter->quirks; in regmap_get_i2c_bus()
347 if (quirks->max_read_len && in regmap_get_i2c_bus()
348 (bus->max_raw_read == 0 || bus->max_raw_read > quirks->max_read_len)) in regmap_get_i2c_bus()
349 max_read = quirks->max_read_len; in regmap_get_i2c_bus()
351 if (quirks->max_write_len && in regmap_get_i2c_bus()
352 (bus->max_raw_write == 0 || bus->max_raw_write > quirks->max_write_len)) in regmap_get_i2c_bus()
353 max_write = quirks->max_write_len - in regmap_get_i2c_bus()
354 (config->reg_bits + config->pad_bits) / BITS_PER_BYTE; in regmap_get_i2c_bus()
357 ret_bus = kmemdup(bus, sizeof(*bus), GFP_KERNEL); in regmap_get_i2c_bus()
359 return ERR_PTR(-ENOMEM); in regmap_get_i2c_bus()
360 ret_bus->free_on_exit = true; in regmap_get_i2c_bus()
361 ret_bus->max_raw_read = max_read; in regmap_get_i2c_bus()
362 ret_bus->max_raw_write = max_write; in regmap_get_i2c_bus()
363 bus = ret_bus; in regmap_get_i2c_bus()
367 return bus; in regmap_get_i2c_bus()
370 struct regmap *__regmap_init_i2c(struct i2c_client *i2c, in __regmap_init_i2c() argument
375 const struct regmap_bus *bus = regmap_get_i2c_bus(i2c, config); in __regmap_init_i2c() local
377 if (IS_ERR(bus)) in __regmap_init_i2c()
378 return ERR_CAST(bus); in __regmap_init_i2c()
380 return __regmap_init(&i2c->dev, bus, &i2c->dev, config, in __regmap_init_i2c()
385 struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c, in __devm_regmap_init_i2c() argument
390 const struct regmap_bus *bus = regmap_get_i2c_bus(i2c, config); in __devm_regmap_init_i2c() local
392 if (IS_ERR(bus)) in __devm_regmap_init_i2c()
393 return ERR_CAST(bus); in __devm_regmap_init_i2c()
395 return __devm_regmap_init(&i2c->dev, bus, &i2c->dev, config, in __devm_regmap_init_i2c()
400 MODULE_DESCRIPTION("Register map access API - I2C support");