Commit 9eec31f3 authored by Han Nandor's avatar Han Nandor Committed by Alexandre Belloni

rtc: ds3232: get SRAM access using NVMEM Framework

DS3232 RTC has 236 bytes of persistent memory.

Add RTC SRAM read and write access using
the NVMEM Framework.
Signed-off-by: default avatarHan Nandor <nandor.han@vaisala.com>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 9fc0fd50
...@@ -48,6 +48,10 @@ ...@@ -48,6 +48,10 @@
# define DS3232_REG_SR_A1F 0x01 # define DS3232_REG_SR_A1F 0x01
#define DS3232_REG_TEMPERATURE 0x11 #define DS3232_REG_TEMPERATURE 0x11
#define DS3232_REG_SRAM_START 0x14
#define DS3232_REG_SRAM_END 0xFF
#define DS3232_REG_SRAM_SIZE 236
struct ds3232 { struct ds3232 {
struct device *dev; struct device *dev;
...@@ -461,11 +465,39 @@ static const struct rtc_class_ops ds3232_rtc_ops = { ...@@ -461,11 +465,39 @@ static const struct rtc_class_ops ds3232_rtc_ops = {
.alarm_irq_enable = ds3232_alarm_irq_enable, .alarm_irq_enable = ds3232_alarm_irq_enable,
}; };
static int ds3232_nvmem_read(void *priv, unsigned int offset, void *val,
size_t bytes)
{
struct regmap *ds3232_regmap = (struct regmap *)priv;
return regmap_bulk_read(ds3232_regmap, DS3232_REG_SRAM_START + offset,
val, bytes);
}
static int ds3232_nvmem_write(void *priv, unsigned int offset, void *val,
size_t bytes)
{
struct regmap *ds3232_regmap = (struct regmap *)priv;
return regmap_bulk_write(ds3232_regmap, DS3232_REG_SRAM_START + offset,
val, bytes);
}
static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq, static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq,
const char *name) const char *name)
{ {
struct ds3232 *ds3232; struct ds3232 *ds3232;
int ret; int ret;
struct nvmem_config nvmem_cfg = {
.name = "ds3232_sram",
.stride = 1,
.size = DS3232_REG_SRAM_SIZE,
.word_size = 1,
.reg_read = ds3232_nvmem_read,
.reg_write = ds3232_nvmem_write,
.priv = regmap,
.type = NVMEM_TYPE_BATTERY_BACKED
};
ds3232 = devm_kzalloc(dev, sizeof(*ds3232), GFP_KERNEL); ds3232 = devm_kzalloc(dev, sizeof(*ds3232), GFP_KERNEL);
if (!ds3232) if (!ds3232)
...@@ -490,6 +522,10 @@ static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq, ...@@ -490,6 +522,10 @@ static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq,
if (IS_ERR(ds3232->rtc)) if (IS_ERR(ds3232->rtc))
return PTR_ERR(ds3232->rtc); return PTR_ERR(ds3232->rtc);
ret = rtc_nvmem_register(ds3232->rtc, &nvmem_cfg);
if(ret)
return ret;
if (ds3232->irq > 0) { if (ds3232->irq > 0) {
ret = devm_request_threaded_irq(dev, ds3232->irq, NULL, ret = devm_request_threaded_irq(dev, ds3232->irq, NULL,
ds3232_irq, ds3232_irq,
...@@ -542,7 +578,7 @@ static int ds3232_i2c_probe(struct i2c_client *client, ...@@ -542,7 +578,7 @@ static int ds3232_i2c_probe(struct i2c_client *client,
static const struct regmap_config config = { static const struct regmap_config config = {
.reg_bits = 8, .reg_bits = 8,
.val_bits = 8, .val_bits = 8,
.max_register = 0x13, .max_register = DS3232_REG_SRAM_END,
}; };
regmap = devm_regmap_init_i2c(client, &config); regmap = devm_regmap_init_i2c(client, &config);
...@@ -609,7 +645,7 @@ static int ds3234_probe(struct spi_device *spi) ...@@ -609,7 +645,7 @@ static int ds3234_probe(struct spi_device *spi)
static const struct regmap_config config = { static const struct regmap_config config = {
.reg_bits = 8, .reg_bits = 8,
.val_bits = 8, .val_bits = 8,
.max_register = 0x13, .max_register = DS3232_REG_SRAM_END,
.write_flag_mask = 0x80, .write_flag_mask = 0x80,
}; };
struct regmap *regmap; struct regmap *regmap;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment