Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge remote-tracking branch 'regmap/topic/smbus' into regmap-next

+134 -2
+102 -2
drivers/base/regmap/regmap-i2c.c
··· 14 14 #include <linux/i2c.h> 15 15 #include <linux/module.h> 16 16 17 + 18 + static int regmap_smbus_byte_reg_read(void *context, unsigned int reg, 19 + unsigned int *val) 20 + { 21 + struct device *dev = context; 22 + struct i2c_client *i2c = to_i2c_client(dev); 23 + int ret; 24 + 25 + if (reg > 0xff) 26 + return -EINVAL; 27 + 28 + ret = i2c_smbus_read_byte_data(i2c, reg); 29 + if (ret < 0) 30 + return ret; 31 + 32 + *val = ret; 33 + 34 + return 0; 35 + } 36 + 37 + static int regmap_smbus_byte_reg_write(void *context, unsigned int reg, 38 + unsigned int val) 39 + { 40 + struct device *dev = context; 41 + struct i2c_client *i2c = to_i2c_client(dev); 42 + 43 + if (val > 0xff || reg > 0xff) 44 + return -EINVAL; 45 + 46 + return i2c_smbus_write_byte_data(i2c, reg, val); 47 + } 48 + 49 + static struct regmap_bus regmap_smbus_byte = { 50 + .reg_write = regmap_smbus_byte_reg_write, 51 + .reg_read = regmap_smbus_byte_reg_read, 52 + }; 53 + 54 + static int regmap_smbus_word_reg_read(void *context, unsigned int reg, 55 + unsigned int *val) 56 + { 57 + struct device *dev = context; 58 + struct i2c_client *i2c = to_i2c_client(dev); 59 + int ret; 60 + 61 + if (reg > 0xff) 62 + return -EINVAL; 63 + 64 + ret = i2c_smbus_read_word_data(i2c, reg); 65 + if (ret < 0) 66 + return ret; 67 + 68 + *val = ret; 69 + 70 + return 0; 71 + } 72 + 73 + static int regmap_smbus_word_reg_write(void *context, unsigned int reg, 74 + unsigned int val) 75 + { 76 + struct device *dev = context; 77 + struct i2c_client *i2c = to_i2c_client(dev); 78 + 79 + if (val > 0xffff || reg > 0xff) 80 + return -EINVAL; 81 + 82 + return i2c_smbus_write_word_data(i2c, reg, val); 83 + } 84 + 85 + static struct regmap_bus regmap_smbus_word = { 86 + .reg_write = regmap_smbus_word_reg_write, 87 + .reg_read = regmap_smbus_word_reg_read, 88 + }; 89 + 17 90 static int regmap_i2c_write(void *context, const void *data, size_t count) 18 91 { 19 92 struct device *dev = context; ··· 170 97 .read = regmap_i2c_read, 171 98 }; 172 99 100 + static const struct regmap_bus *regmap_get_i2c_bus(struct i2c_client *i2c, 101 + const struct regmap_config *config) 102 + { 103 + if (i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) 104 + return &regmap_i2c; 105 + else if (config->val_bits == 16 && config->reg_bits == 8 && 106 + i2c_check_functionality(i2c->adapter, 107 + I2C_FUNC_SMBUS_WORD_DATA)) 108 + return &regmap_smbus_word; 109 + else if (config->val_bits == 8 && config->reg_bits == 8 && 110 + i2c_check_functionality(i2c->adapter, 111 + I2C_FUNC_SMBUS_BYTE_DATA)) 112 + return &regmap_smbus_byte; 113 + 114 + return ERR_PTR(-ENOTSUPP); 115 + } 116 + 173 117 /** 174 118 * regmap_init_i2c(): Initialise register map 175 119 * ··· 199 109 struct regmap *regmap_init_i2c(struct i2c_client *i2c, 200 110 const struct regmap_config *config) 201 111 { 202 - return regmap_init(&i2c->dev, &regmap_i2c, &i2c->dev, config); 112 + const struct regmap_bus *bus = regmap_get_i2c_bus(i2c, config); 113 + 114 + if (IS_ERR(bus)) 115 + return ERR_CAST(bus); 116 + 117 + return regmap_init(&i2c->dev, bus, &i2c->dev, config); 203 118 } 204 119 EXPORT_SYMBOL_GPL(regmap_init_i2c); 205 120 ··· 221 126 struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c, 222 127 const struct regmap_config *config) 223 128 { 224 - return devm_regmap_init(&i2c->dev, &regmap_i2c, &i2c->dev, config); 129 + const struct regmap_bus *bus = regmap_get_i2c_bus(i2c, config); 130 + 131 + if (IS_ERR(bus)) 132 + return ERR_CAST(bus); 133 + 134 + return devm_regmap_init(&i2c->dev, bus, &i2c->dev, config); 225 135 } 226 136 EXPORT_SYMBOL_GPL(devm_regmap_init_i2c); 227 137
+26
drivers/base/regmap/regmap.c
··· 35 35 unsigned int mask, unsigned int val, 36 36 bool *change); 37 37 38 + static int _regmap_bus_reg_read(void *context, unsigned int reg, 39 + unsigned int *val); 38 40 static int _regmap_bus_read(void *context, unsigned int reg, 39 41 unsigned int *val); 40 42 static int _regmap_bus_formatted_write(void *context, unsigned int reg, 41 43 unsigned int val); 44 + static int _regmap_bus_reg_write(void *context, unsigned int reg, 45 + unsigned int val); 42 46 static int _regmap_bus_raw_write(void *context, unsigned int reg, 43 47 unsigned int val); 44 48 ··· 538 534 if (!bus) { 539 535 map->reg_read = config->reg_read; 540 536 map->reg_write = config->reg_write; 537 + 538 + map->defer_caching = false; 539 + goto skip_format_initialization; 540 + } else if (!bus->read || !bus->write) { 541 + map->reg_read = _regmap_bus_reg_read; 542 + map->reg_write = _regmap_bus_reg_write; 541 543 542 544 map->defer_caching = false; 543 545 goto skip_format_initialization; ··· 1346 1336 return ret; 1347 1337 } 1348 1338 1339 + static int _regmap_bus_reg_write(void *context, unsigned int reg, 1340 + unsigned int val) 1341 + { 1342 + struct regmap *map = context; 1343 + 1344 + return map->bus->reg_write(map->bus_context, reg, val); 1345 + } 1346 + 1349 1347 static int _regmap_bus_raw_write(void *context, unsigned int reg, 1350 1348 unsigned int val) 1351 1349 { ··· 1996 1978 val_len / map->format.val_bytes); 1997 1979 1998 1980 return ret; 1981 + } 1982 + 1983 + static int _regmap_bus_reg_read(void *context, unsigned int reg, 1984 + unsigned int *val) 1985 + { 1986 + struct regmap *map = context; 1987 + 1988 + return map->bus->reg_read(map->bus_context, reg, val); 1999 1989 } 2000 1990 2001 1991 static int _regmap_bus_read(void *context, unsigned int reg,
+6
include/linux/regmap.h
··· 276 276 typedef int (*regmap_hw_read)(void *context, 277 277 const void *reg_buf, size_t reg_size, 278 278 void *val_buf, size_t val_size); 279 + typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg, 280 + unsigned int *val); 281 + typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg, 282 + unsigned int val); 279 283 typedef struct regmap_async *(*regmap_hw_async_alloc)(void); 280 284 typedef void (*regmap_hw_free_context)(void *context); 281 285 ··· 313 309 regmap_hw_write write; 314 310 regmap_hw_gather_write gather_write; 315 311 regmap_hw_async_write async_write; 312 + regmap_hw_reg_write reg_write; 316 313 regmap_hw_read read; 314 + regmap_hw_reg_read reg_read; 317 315 regmap_hw_free_context free_context; 318 316 regmap_hw_async_alloc async_alloc; 319 317 u8 read_flag_mask;