mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-01 10:45:49 +00:00
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>
This commit is contained in:
parent
ad76f3e8f5
commit
115ee55351
@ -32,6 +32,7 @@
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/nvmem-provider.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <linux/ctype.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
@ -197,11 +198,43 @@ static const struct bin_attribute ds1682_eeprom_attr = {
|
||||
.write = ds1682_eeprom_write,
|
||||
};
|
||||
|
||||
static int ds1682_nvmem_read(void *priv, unsigned int offset, void *val,
|
||||
size_t bytes)
|
||||
{
|
||||
struct i2c_client *client = priv;
|
||||
int ret;
|
||||
|
||||
ret = i2c_smbus_read_i2c_block_data(client, DS1682_REG_EEPROM + offset,
|
||||
bytes, val);
|
||||
return ret < 0 ? ret : 0;
|
||||
}
|
||||
|
||||
static int ds1682_nvmem_write(void *priv, unsigned int offset, void *val,
|
||||
size_t bytes)
|
||||
{
|
||||
struct i2c_client *client = priv;
|
||||
int ret;
|
||||
|
||||
ret = i2c_smbus_write_i2c_block_data(client, DS1682_REG_EEPROM + offset,
|
||||
bytes, val);
|
||||
return ret < 0 ? ret : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a ds1682 device is matched with this driver
|
||||
*/
|
||||
static int ds1682_probe(struct i2c_client *client)
|
||||
{
|
||||
struct nvmem_config config = {
|
||||
.dev = &client->dev,
|
||||
.owner = THIS_MODULE,
|
||||
.type = NVMEM_TYPE_EEPROM,
|
||||
.reg_read = ds1682_nvmem_read,
|
||||
.reg_write = ds1682_nvmem_write,
|
||||
.size = DS1682_EEPROM_SIZE,
|
||||
.priv = client,
|
||||
};
|
||||
struct nvmem_device *nvmem;
|
||||
int rc;
|
||||
|
||||
if (!i2c_check_functionality(client->adapter,
|
||||
@ -211,6 +244,10 @@ static int ds1682_probe(struct i2c_client *client)
|
||||
goto exit;
|
||||
}
|
||||
|
||||
nvmem = devm_nvmem_register(&client->dev, &config);
|
||||
if (IS_ENABLED(CONFIG_NVMEM) && IS_ERR(nvmem))
|
||||
return PTR_ERR(nvmem);
|
||||
|
||||
rc = sysfs_create_group(&client->dev.kobj, &ds1682_group);
|
||||
if (rc)
|
||||
goto exit;
|
||||
|
Loading…
Reference in New Issue
Block a user