From 293bc21e4e1072895b2076905404da5e13ecdafc Mon Sep 17 00:00:00 2001 From: Wyon Bi Date: Fri, 3 Jun 2022 03:38:42 +0000 Subject: [PATCH] mfd: max96752f: mark 0x0050 & 0x0073 register as non-volatile Fixes: 4f64073a92d5 ("mfd: MAX96752F: add stream id for each link") Signed-off-by: Wyon Bi Change-Id: I8a7bbce97363120fadf3bc2d4f27be7d02cc50aa --- drivers/mfd/max96752f.c | 31 +++++++++++++++++++++---------- include/linux/mfd/max96752f.h | 1 - 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/mfd/max96752f.c b/drivers/mfd/max96752f.c index 21d82677f999..bedac0797606 100644 --- a/drivers/mfd/max96752f.c +++ b/drivers/mfd/max96752f.c @@ -36,6 +36,8 @@ static bool max96752f_volatile_reg(struct device *dev, unsigned int reg) { switch (reg) { case 0x0002: + case 0x0050: + case 0x0073: case 0x0140: case 0x01ce: case 0x0203 ... 0x022f: @@ -46,7 +48,7 @@ static bool max96752f_volatile_reg(struct device *dev, unsigned int reg) } static const struct reg_default max96752f_reg_defaults[] = { - { 0x0002, 0x47 }, + { 0x0002, 0x47 }, { 0x0050, 0x00 }, { 0x0073, 0x30 }, { 0x0140, 0x21 }, { 0x01ce, 0x06 }, { 0x0203, 0x84 }, { 0x0204, 0xa1 }, { 0x0205, 0x41 }, @@ -75,21 +77,21 @@ static const struct regmap_config max96752f_regmap_config = { .reg_defaults = max96752f_reg_defaults, .num_reg_defaults = ARRAY_SIZE(max96752f_reg_defaults), .cache_type = REGCACHE_RBTREE, - .use_single_write = true, }; static const unsigned short addr_list[] = { 0x48, 0x4a, 0x4c, 0x68, 0x6a, 0x6c, 0x28, 0x2a, I2C_CLIENT_END }; -void max96752f_regcache_sync(struct max96752f *max96752f) +static void max96752f_check_addr(struct max96752f *max96752f) { struct i2c_client *client = max96752f->client; u16 addr = client->addr; u32 id; int i, ret; - regcache_cache_only(max96752f->regmap, false); + if (!regmap_read(max96752f->regmap, 0x000d, &id)) + return; for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) { client->addr = addr_list[i]; @@ -104,11 +106,13 @@ void max96752f_regcache_sync(struct max96752f *max96752f) } client->addr = addr; +} - regmap_update_bits(max96752f->regmap, 0x0050, STR_SEL, - FIELD_PREP(STR_SEL, max96752f->stream_id)); - regmap_update_bits(max96752f->regmap, 0x0073, TX_SRC_ID, - FIELD_PREP(TX_SRC_ID, max96752f->stream_id)); +void max96752f_regcache_sync(struct max96752f *max96752f) +{ + regcache_cache_only(max96752f->regmap, false); + + max96752f_check_addr(max96752f); regcache_sync(max96752f->regmap); } @@ -120,6 +124,7 @@ static int max96752f_i2c_probe(struct i2c_client *client) struct device_node *child; struct max96752f *max96752f; unsigned int nr = 0; + u32 stream_id; int ret; for_each_available_child_of_node(dev->of_node, child) { @@ -141,7 +146,7 @@ static int max96752f_i2c_probe(struct i2c_client *client) max96752f->dev = dev; max96752f->client = client; - ret = device_property_read_u32(dev->parent, "reg", &max96752f->stream_id); + ret = device_property_read_u32(dev->parent, "reg", &stream_id); if (ret) return dev_err_probe(dev, ret, "failed to get gmsl id\n"); @@ -153,8 +158,14 @@ static int max96752f_i2c_probe(struct i2c_client *client) return dev_err_probe(dev, PTR_ERR(max96752f->regmap), "failed to initialize regmap\n"); + max96752f_check_addr(max96752f); + + regmap_update_bits(max96752f->regmap, 0x0050, STR_SEL, + FIELD_PREP(STR_SEL, stream_id)); + regmap_update_bits(max96752f->regmap, 0x0073, TX_SRC_ID, + FIELD_PREP(TX_SRC_ID, stream_id)); + regcache_mark_dirty(max96752f->regmap); - regcache_cache_only(max96752f->regmap, true); ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, max96752f_devs, ARRAY_SIZE(max96752f_devs), NULL, 0, NULL); diff --git a/include/linux/mfd/max96752f.h b/include/linux/mfd/max96752f.h index 01d9b059aa85..04885aa42b4e 100644 --- a/include/linux/mfd/max96752f.h +++ b/include/linux/mfd/max96752f.h @@ -105,7 +105,6 @@ struct max96752f { struct regmap *regmap; struct i2c_client *client; struct i2c_mux_core *muxc; - u32 stream_id; }; void max96752f_regcache_sync(struct max96752f *max96752f);