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

Configure Feed

Select the types of activity you want to include in your feed.

misc: ds1682: Add NVMEM support

Add NVMEM support for the internal EEPROM.

Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
Link: https://lore.kernel.org/r/20240315213540.1682964-1-sean.anderson@linux.dev
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Sean Anderson and committed by
Greg Kroah-Hartman
115ee553 ad76f3e8

+37
+37
drivers/misc/ds1682.c
··· 32 32 #include <linux/i2c.h> 33 33 #include <linux/string.h> 34 34 #include <linux/list.h> 35 + #include <linux/nvmem-provider.h> 35 36 #include <linux/sysfs.h> 36 37 #include <linux/ctype.h> 37 38 #include <linux/hwmon-sysfs.h> ··· 198 197 .write = ds1682_eeprom_write, 199 198 }; 200 199 200 + static int ds1682_nvmem_read(void *priv, unsigned int offset, void *val, 201 + size_t bytes) 202 + { 203 + struct i2c_client *client = priv; 204 + int ret; 205 + 206 + ret = i2c_smbus_read_i2c_block_data(client, DS1682_REG_EEPROM + offset, 207 + bytes, val); 208 + return ret < 0 ? ret : 0; 209 + } 210 + 211 + static int ds1682_nvmem_write(void *priv, unsigned int offset, void *val, 212 + size_t bytes) 213 + { 214 + struct i2c_client *client = priv; 215 + int ret; 216 + 217 + ret = i2c_smbus_write_i2c_block_data(client, DS1682_REG_EEPROM + offset, 218 + bytes, val); 219 + return ret < 0 ? ret : 0; 220 + } 221 + 201 222 /* 202 223 * Called when a ds1682 device is matched with this driver 203 224 */ 204 225 static int ds1682_probe(struct i2c_client *client) 205 226 { 227 + struct nvmem_config config = { 228 + .dev = &client->dev, 229 + .owner = THIS_MODULE, 230 + .type = NVMEM_TYPE_EEPROM, 231 + .reg_read = ds1682_nvmem_read, 232 + .reg_write = ds1682_nvmem_write, 233 + .size = DS1682_EEPROM_SIZE, 234 + .priv = client, 235 + }; 236 + struct nvmem_device *nvmem; 206 237 int rc; 207 238 208 239 if (!i2c_check_functionality(client->adapter, ··· 243 210 rc = -ENODEV; 244 211 goto exit; 245 212 } 213 + 214 + nvmem = devm_nvmem_register(&client->dev, &config); 215 + if (IS_ENABLED(CONFIG_NVMEM) && IS_ERR(nvmem)) 216 + return PTR_ERR(nvmem); 246 217 247 218 rc = sysfs_create_group(&client->dev.kobj, &ds1682_group); 248 219 if (rc)