Resolve revision handling and add support for DA silicon
Subsystems (2)
v3 cover Resolve revision handling and add support for DA silicon
This patch set fixes the currently broken revision handling in the driver's i2c_probe() function and then adds DA support to existing permitted revisions.
v3:
- Replaced magic numbers around I2C paged access code with enums and defines
- Small style tidy ups as requested by Lee Jones
v2:
- Use raw I2C read access instead of a temporary regmap to interrogate chip and variant id registers
Adam Thomson (2):
mfd: da9063: Fix revision handling to correctly select reg tables
mfd: da9063: Add support for latest DA silicon revision
drivers/mfd/da9063-core.c | 31 ---- drivers/mfd/da9063-i2c.c | 271 +++++++++++++++++++++++++++++++---- include/linux/mfd/da9063/core.h | 1 + include/linux/mfd/da9063/registers.h | 15 +- 4 files changed, 257 insertions(+), 61 deletions(-)
Signature · 1 line
1.9.1
PATCH v3 1/2 mfd: da9063: Fix revision handling to correctly select reg tables
The current implementation performs checking in the i2c_probe() function of the variant_code but does this immediately after the containing struct has been initialised as all zero. This means the check for variant code will always default to using the BB tables and will never select AD. The variant code is subsequently set by device_init() and later used by the RTC so really it's a little fortunate this mismatch works.
This update adds raw I2C read access functionality to read the chip and variant/revision information (common to all revisions) so that it can subsequently correctly choose the proper regmap tables for real initialisation.
--- drivers/mfd/da9063-core.c | 31 ------ drivers/mfd/da9063-i2c.c | 184 +++++++++++++++++++++++++++++++---- include/linux/mfd/da9063/registers.h | 15 ++- 3 files changed, 177 insertions(+), 53 deletions(-)
drivers/mfd/da9063-core.c +0 -31
@@ -160,7 +160,6 @@ static int da9063_clear_fault_log(struct da9063 *da9063)int da9063_device_init (struct da9063 *da9063,unsigned int irq) { -int model, variant_id, variant_code;int ret; ret =da9063_clear_fault_log (da9063);
@@ -171,36 +170,6 @@ int da9063_device_init(struct da9063 *da9063, unsigned int irq) da9063->irq_base =-1 ; da9063->chip_irq = irq; - ret =regmap_read (da9063->regmap,DA9063_REG_CHIP_ID , &model); -if (ret <0 ) { -dev_err (da9063->dev,"Cannot read chip model id.\n" ); -return -EIO ; - } -if (model !=PMIC_CHIP_ID_DA9063 ) { -dev_err (da9063->dev,"Invalid chip model id: 0x%02x\n" , model); -return -ENODEV ; - } - - ret =regmap_read (da9063->regmap,DA9063_REG_CHIP_VARIANT , &variant_id); -if (ret <0 ) { -dev_err (da9063->dev,"Cannot read chip variant id.\n" ); -return -EIO ; - } - - variant_code = variant_id >>DA9063_CHIP_VARIANT_SHIFT ; - -dev_info (da9063->dev, -"Device detected (chip-ID: 0x%02X, var-ID: 0x%02X)\n" , - model, variant_id); - -if (variant_code <PMIC_DA9063_BB && variant_code !=PMIC_DA9063_AD ) { -dev_err (da9063->dev, -"Cannot support variant code: 0x%02X\n" , variant_code); -return -ENODEV ; - } - - da9063->variant_code = variant_code; - ret =da9063_irq_init (da9063);if (ret) {dev_err (da9063->dev,"Cannot initialize interrupts.\n" );
drivers/mfd/da9063-i2c.c +167 -17
225 lines not on this page · raw message
include/linux/mfd/da9063/registers.h +10 -5
@@ -292,8 +292,10 @@#define DA9063_BB_REG_GP_ID_19 0x134/* Chip ID and variant */ -#define DA9063_REG_CHIP_ID 0x181 -#define DA9063_REG_CHIP_VARIANT 0x182 +#define DA9063_REG_DEVICE_ID 0x181 +#define DA9063_REG_VARIANT_ID 0x182 +#define DA9063_REG_CUSTOMER_ID 0x183 +#define DA9063_REG_CONFIG_ID 0x184/* * PMIC registers bits
@@ -929,9 +931,6 @@#define DA9063_RTC_CLOCK 0x40#define DA9063_OUT_32K_EN 0x80 -/* DA9063_REG_CHIP_VARIANT */ -#define DA9063_CHIP_VARIANT_SHIFT 4 -/* DA9063_REG_BUCK_ILIM_A (addr=0x9A) */ #define DA9063_BIO_ILIM_MASK 0x0F#define DA9063_BMEM_ILIM_MASK 0xF0
@@ -1065,4 +1064,10 @@#define DA9063_MON_A10_IDX_LDO9 0x04#define DA9063_MON_A10_IDX_LDO10 0x05 +/* DA9063_REG_VARIANT_ID (addr=0x182) */ +#define DA9063_VARIANT_ID_VRC_SHIFT 0 +#define DA9063_VARIANT_ID_VRC_MASK 0x0F +#define DA9063_VARIANT_ID_MRC_SHIFT 4 +#define DA9063_VARIANT_ID_MRC_MASK 0xF0 +#endif /* _DA9063_REG_H */
Signature · 1 line
1.9.1
PATCH v3 2/2 mfd: da9063: Add support for latest DA silicon revision
In reply to Adam ThomsonThis update adds new regmap tables to support the latest DA silicon which will automatically be selected based on the chip and variant information read from the device.
--- drivers/mfd/da9063-i2c.c | 91 ++++++++++++++++++++++++++++++++++++----- include/linux/mfd/da9063/core.h | 1 + 2 files changed, 82 insertions(+), 10 deletions(-)
drivers/mfd/da9063-i2c.c +81 -10
@@ -197,7 +197,7 @@ static int da9063_get_device_type(struct i2c_client *i2c, struct da9063 *da9063) regmap_reg_range(DA9063_BB_REG_GP_ID_0, DA9063_BB_REG_GP_ID_19), }; -static const struct regmap_range da9063_bb_volatile_ranges[] = { +static const struct regmap_range da9063_bb_da_volatile_ranges[] = {regmap_reg_range (DA9063_REG_PAGE_CON ,DA9063_REG_EVENT_D ),regmap_reg_range (DA9063_REG_CONTROL_A ,DA9063_REG_CONTROL_B ),regmap_reg_range (DA9063_REG_CONTROL_E ,DA9063_REG_CONTROL_F ),
@@ -219,9 +219,9 @@ static int da9063_get_device_type(struct i2c_client *i2c, struct da9063 *da9063) .n_yes_ranges = ARRAY_SIZE(da9063_bb_writeable_ranges), }; -static const struct regmap_access_table da9063_bb_volatile_table = { - .yes_ranges = da9063_bb_volatile_ranges, - .n_yes_ranges =ARRAY_SIZE (da9063_bb_volatile_ranges), +static const struct regmap_access_table da9063_bb_da_volatile_table = { + .yes_ranges = da9063_bb_da_volatile_ranges, + .n_yes_ranges =ARRAY_SIZE (da9063_bb_da_volatile_ranges), };static const struct regmap_range da9063l_bb_readable_ranges[] = {
@@ -241,7 +241,7 @@ static int da9063_get_device_type(struct i2c_client *i2c, struct da9063 *da9063) regmap_reg_range(DA9063_BB_REG_GP_ID_0, DA9063_BB_REG_GP_ID_19), }; -static const struct regmap_range da9063l_bb_volatile_ranges[] = { +static const struct regmap_range da9063l_bb_da_volatile_ranges[] = {regmap_reg_range (DA9063_REG_PAGE_CON ,DA9063_REG_EVENT_D ),regmap_reg_range (DA9063_REG_CONTROL_A ,DA9063_REG_CONTROL_B ),regmap_reg_range (DA9063_REG_CONTROL_E ,DA9063_REG_CONTROL_F ),
@@ -263,9 +263,64 @@ static int da9063_get_device_type(struct i2c_client *i2c, struct da9063 *da9063) .n_yes_ranges = ARRAY_SIZE(da9063l_bb_writeable_ranges), }; -static const struct regmap_access_table da9063l_bb_volatile_table = { - .yes_ranges = da9063l_bb_volatile_ranges, - .n_yes_ranges =ARRAY_SIZE (da9063l_bb_volatile_ranges), +static const struct regmap_access_table da9063l_bb_da_volatile_table = { + .yes_ranges = da9063l_bb_da_volatile_ranges, + .n_yes_ranges =ARRAY_SIZE (da9063l_bb_da_volatile_ranges), +}; + +static const struct regmap_range da9063_da_readable_ranges[] = { +regmap_reg_range (DA9063_REG_PAGE_CON ,DA9063_BB_REG_SECOND_D ), +regmap_reg_range (DA9063_REG_SEQ ,DA9063_REG_ID_32_31 ), +regmap_reg_range (DA9063_REG_SEQ_A ,DA9063_REG_AUTO3_LOW ), +regmap_reg_range (DA9063_REG_T_OFFSET ,DA9063_BB_REG_GP_ID_11 ), +regmap_reg_range (DA9063_REG_DEVICE_ID ,DA9063_REG_VARIANT_ID ), +}; + +static const struct regmap_range da9063_da_writeable_ranges[] = { +regmap_reg_range (DA9063_REG_PAGE_CON ,DA9063_REG_PAGE_CON ), +regmap_reg_range (DA9063_REG_FAULT_LOG ,DA9063_REG_VSYS_MON ), +regmap_reg_range (DA9063_REG_COUNT_S ,DA9063_BB_REG_ALARM_Y ), +regmap_reg_range (DA9063_REG_SEQ ,DA9063_REG_ID_32_31 ), +regmap_reg_range (DA9063_REG_SEQ_A ,DA9063_REG_AUTO3_LOW ), +regmap_reg_range (DA9063_REG_CONFIG_I ,DA9063_BB_REG_MON_REG_4 ), +regmap_reg_range (DA9063_BB_REG_GP_ID_0 ,DA9063_BB_REG_GP_ID_11 ), +}; + +static const struct regmap_access_table da9063_da_readable_table = { + .yes_ranges = da9063_da_readable_ranges, + .n_yes_ranges =ARRAY_SIZE (da9063_da_readable_ranges), +}; + +static const struct regmap_access_table da9063_da_writeable_table = { + .yes_ranges = da9063_da_writeable_ranges, + .n_yes_ranges =ARRAY_SIZE (da9063_da_writeable_ranges), +}; + +static const struct regmap_range da9063l_da_readable_ranges[] = { +regmap_reg_range (DA9063_REG_PAGE_CON ,DA9063_REG_MON_A10_RES ), +regmap_reg_range (DA9063_REG_SEQ ,DA9063_REG_ID_32_31 ), +regmap_reg_range (DA9063_REG_SEQ_A ,DA9063_REG_AUTO3_LOW ), +regmap_reg_range (DA9063_REG_T_OFFSET ,DA9063_BB_REG_GP_ID_11 ), +regmap_reg_range (DA9063_REG_DEVICE_ID ,DA9063_REG_VARIANT_ID ), +}; + +static const struct regmap_range da9063l_da_writeable_ranges[] = { +regmap_reg_range (DA9063_REG_PAGE_CON ,DA9063_REG_PAGE_CON ), +regmap_reg_range (DA9063_REG_FAULT_LOG ,DA9063_REG_VSYS_MON ), +regmap_reg_range (DA9063_REG_SEQ ,DA9063_REG_ID_32_31 ), +regmap_reg_range (DA9063_REG_SEQ_A ,DA9063_REG_AUTO3_LOW ), +regmap_reg_range (DA9063_REG_CONFIG_I ,DA9063_BB_REG_MON_REG_4 ), +regmap_reg_range (DA9063_BB_REG_GP_ID_0 ,DA9063_BB_REG_GP_ID_11 ), +}; + +static const struct regmap_access_table da9063l_da_readable_table = { + .yes_ranges = da9063l_da_readable_ranges, + .n_yes_ranges =ARRAY_SIZE (da9063l_da_readable_ranges), +}; + +static const struct regmap_access_table da9063l_da_writeable_table = { + .yes_ranges = da9063l_da_writeable_ranges, + .n_yes_ranges =ARRAY_SIZE (da9063l_da_writeable_ranges), };static const struct regmap_range_cfg da9063_range_cfg[] = {
@@ -333,7 +388,15 @@ static int da9063_i2c_probe(struct i2c_client *i2c, da9063_regmap_config.wr_table = &da9063_bb_writeable_table; da9063_regmap_config.volatile_table = - &da9063_bb_volatile_table; + &da9063_bb_da_volatile_table; +break ; +case PMIC_DA9063_DA : + da9063_regmap_config.rd_table = + &da9063_da_readable_table; + da9063_regmap_config.wr_table = + &da9063_da_writeable_table; + da9063_regmap_config.volatile_table = + &da9063_bb_da_volatile_table;break ;default : dev_err(da9063->dev,
@@ -350,7 +413,15 @@ static int da9063_i2c_probe(struct i2c_client *i2c, da9063_regmap_config.wr_table = &da9063l_bb_writeable_table; da9063_regmap_config.volatile_table = - &da9063l_bb_volatile_table; + &da9063l_bb_da_volatile_table; +break ; +case PMIC_DA9063_DA : + da9063_regmap_config.rd_table = + &da9063l_da_readable_table; + da9063_regmap_config.wr_table = + &da9063l_da_writeable_table; + da9063_regmap_config.volatile_table = + &da9063l_bb_da_volatile_table;break ;default : dev_err(da9063->dev,
include/linux/mfd/da9063/core.h +1 -0
@@ -35,6 +35,7 @@ enum da9063_variant_codes {PMIC_DA9063_AD =0x3 ,PMIC_DA9063_BB =0x5 ,PMIC_DA9063_CA =0x6 , + PMIC_DA9063_DA = 0x7, };/* Interrupts */
Signature · 1 line
1.9.1
Quoted 2 lines · Adam Thomson
This patch set fixes the currently broken revision handling in the driver's
i2c_probe()function and then adds DA support to existing permitted revisions.
Do I need to resend this patch, or will you still pick up the original mail submission from April, Lee?
Quoted 23 lines
v3:
- Replaced magic numbers around I2C paged access code with enums and
defines
- Small style tidy ups as requested by Lee Jonesv2:
- Use raw I2C read access instead of a temporary regmap to interrogate chip and variant id registersAdam Thomson (2):
mfd: da9063: Fix revision handling to correctly select reg tables
mfd: da9063: Add support for latest DA silicon revisiondrivers/mfd/da9063-core.c | 31 ---- drivers/mfd/da9063-i2c.c | 271 +++++++++++++++++++++++++++++++--- - include/linux/mfd/da9063/core.h | 1 + include/linux/mfd/da9063/registers.h | 15 +- 4 files changed, 257 insertions(+), 61 deletions(-)--
1.9.1
Re: [PATCH v3 1/2] mfd: da9063: Fix revision handling to correctly select reg tables
In reply to Adam ThomsonQuoted 19 lines · Adam Thomson
The current implementation performs checking in the
i2c_probe()function of thevariant_codebut does this immediately after the containing struct has been initialised as all zero. This means the check for variant code will always default to using the BB tables and will never select AD. The variant code is subsequently set bydevice_init()and later used by the RTC so really it's a little fortunate this mismatch works.This update adds raw I2C read access functionality to read the chip and variant/revision information (common to all revisions) so that it can subsequently correctly choose the proper regmap tables for real initialisation.
Signed-off-by Adam Thomson <[email protected]>--- drivers/mfd/da9063-core.c | 31 ------ drivers/mfd/da9063-i2c.c | 184 +++++++++++++++++++++++++++++++---- include/linux/mfd/da9063/registers.h | 15 ++- 3 files changed, 177 insertions(+), 53 deletions(-)
[...]
Quoted 62 lines
+ * Raw I2C access required for just accessing chip and variant info before we
+ * know which device is present. The info read from the device using this
+ * approach is then used to select the correct regmap tables.
+ */drivers/mfd/da9063-i2c.c +58
-0+ +#define DA9063_REG_PAGE_SIZE 0x100 +#define DA9063_REG_PAGED_ADDR_MASK 0xFF + +enum da9063_page_sel_buf_fmt { +DA9063_PAGE_SEL_BUF_PAGE_REG =0 , +DA9063_PAGE_SEL_BUF_PAGE_VAL , +DA9063_PAGE_SEL_BUF_SIZE , +}; + +enum da9063_paged_read_msgs { +DA9063_PAGED_READ_MSG_PAGE_SEL =0 , +DA9063_PAGED_READ_MSG_REG_SEL , +DA9063_PAGED_READ_MSG_DATA , +DA9063_PAGED_READ_MSG_CNT , +}; + +static int da9063_i2c_blockreg_read (struct i2c_client *client,u16 addr, +u8 *buf,int count) +{ +struct i2c_msg xfer[DA9063_PAGED_READ_MSG_CNT ]; +u8 page_sel_buf[DA9063_PAGE_SEL_BUF_SIZE ]; +u8 page_num, paged_addr; +int ret; + +/* Determine page info based on register address */ + page_num = (addr /DA9063_REG_PAGE_SIZE ); +if (page_num >1 ) { +dev_err (&client->dev,"Invalid register address provided\n" ); +return -EINVAL ; + } + + paged_addr = (addr %DA9063_REG_PAGE_SIZE ) &DA9063_REG_PAGED_ADDR_MASK ; + page_sel_buf[DA9063_PAGE_SEL_BUF_PAGE_REG ] =DA9063_REG_PAGE_CON ; + page_sel_buf[DA9063_PAGE_SEL_BUF_PAGE_VAL ] = + (page_num <<DA9063_I2C_PAGE_SEL_SHIFT ) &DA9063_REG_PAGE_MASK ; + +/* Write reg address, page selection */ + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL ].addr = client->addr; + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL ].flags =0 ; + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL ].len =DA9063_PAGE_SEL_BUF_SIZE ; + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL ].buf = page_sel_buf; + +/* Select register address */ + xfer[DA9063_PAGED_READ_MSG_REG_SEL ].addr = client->addr; + xfer[DA9063_PAGED_READ_MSG_REG_SEL ].flags =0 ; + xfer[DA9063_PAGED_READ_MSG_REG_SEL ].len =sizeof (paged_addr); + xfer[DA9063_PAGED_READ_MSG_REG_SEL ].buf = &paged_addr; + +/* Read data */ + xfer[DA9063_PAGED_READ_MSG_DATA ].addr = client->addr; + xfer[DA9063_PAGED_READ_MSG_DATA ].flags =I2C_M_RD ; + xfer[DA9063_PAGED_READ_MSG_DATA ].len = count; + xfer[DA9063_PAGED_READ_MSG_DATA ].buf = buf; + + ret =i2c_transfer (client->adapter, xfer,DA9063_PAGED_READ_MSG_CNT ); +if (ret <0 ) { +dev_err (&client->dev,"Paged block read failed: %d\n" , ret);
drivers/mfd/da9063-i2c.c line 97
Quoted 10 lines
drivers/mfd/da9063-i2c.c +10
-0+return ret; + } + +if (ret !=DA9063_PAGED_READ_MSG_CNT ) { +dev_err (&client->dev,"Paged block read failed to complete\n" ); +return -EIO ; + } + +return 0 ; +}
Rather than open coding this, does it make sense to register a small (temporary?) Device ID Regmap to read from?
Signature · 4 lines
Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog
RE: [PATCH v3 1/2] mfd: da9063: Fix revision handling to correctly select reg tables
Quoted 88 lines · Lee Jones
Quoted 13 lines
The current implementation performs checking in the
i2c_probe()function of thevariant_codebut does this immediately after the containing struct has been initialised as all zero. This means the check for variant code will always default to using the BB tables and will never select AD. The variant code is subsequently set bydevice_init()and later used by the RTC so really it's a little fortunate this mismatch works.This update adds raw I2C read access functionality to read the chip and variant/revision information (common to all revisions) so that it can subsequently correctly choose the proper regmap tables for real initialisation.
Quoted 4 lines
Signed-off-by Adam Thomson <[email protected]>--- drivers/mfd/da9063-core.c | 31 ------ drivers/mfd/da9063-i2c.c | 184 +++++++++++++++++++++++++++++++----
Quoted 2 lines
include/linux/mfd/da9063/registers.h | 15 ++- 3 files changed, 177 insertions(+), 53 deletions(-)[...]
Quoted 27 lines
+ * Raw I2C access required for just accessing chip and variant info before we
+ * know which device is present. The info read from the device using this
+ * approach is then used to select the correct regmap tables.
+ */drivers/mfd/da9063-i2c.c +23
-0+ +#define DA9063_REG_PAGE_SIZE 0x100 +#define DA9063_REG_PAGED_ADDR_MASK 0xFF + +enum da9063_page_sel_buf_fmt { +DA9063_PAGE_SEL_BUF_PAGE_REG =0 , +DA9063_PAGE_SEL_BUF_PAGE_VAL , +DA9063_PAGE_SEL_BUF_SIZE , +}; + +enum da9063_paged_read_msgs { +DA9063_PAGED_READ_MSG_PAGE_SEL =0 , +DA9063_PAGED_READ_MSG_REG_SEL , +DA9063_PAGED_READ_MSG_DATA , +DA9063_PAGED_READ_MSG_CNT , +}; + +static int da9063_i2c_blockreg_read (struct i2c_client *client,u16 addr, +u8 *buf,int count) +{ +struct i2c_msg xfer[DA9063_PAGED_READ_MSG_CNT ]; +u8 page_sel_buf[DA9063_PAGE_SEL_BUF_SIZE ]; +u8 page_num, paged_addr;drivers/mfd/da9063-i2c.c
Quoted 10 lines
drivers/mfd/da9063-i2c.c +10
-0+int ret; + +/* Determine page info based on register address */ + page_num = (addr /DA9063_REG_PAGE_SIZE ); +if (page_num >1 ) { +dev_err (&client->dev,"Invalid register address provided\n" ); +return -EINVAL ; + } + + paged_addr = (addr % DA9063_REG_PAGE_SIZE) &
DA9063_REG_PAGED_ADDR_MASK;Review
Quoted 1 line
(quoted diff) +1
-0+ page_sel_buf[DA9063_PAGE_SEL_BUF_PAGE_REG] =
DA9063_REG_PAGE_CON;Review
Quoted 2 lines
(quoted diff) +2
-0+ page_sel_buf[DA9063_PAGE_SEL_BUF_PAGE_VAL] = + (page_num << DA9063_I2C_PAGE_SEL_SHIFT) &
DA9063_REG_PAGE_MASK;drivers/mfd/da9063-i2c.c
Quoted 5 lines
drivers/mfd/da9063-i2c.c +5
-0+ +/* Write reg address, page selection */ + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL ].addr = client->addr; + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL ].flags =0 ; + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL].len =
DA9063_PAGE_SEL_BUF_SIZE;Quoted 5 lines
drivers/mfd/da9063-i2c.c +5
-0+ xfer[DA9063_PAGED_READ_MSG_PAGE_SEL ].buf = page_sel_buf; + +/* Select register address */ + xfer[DA9063_PAGED_READ_MSG_REG_SEL ].addr = client->addr; + xfer[DA9063_PAGED_READ_MSG_REG_SEL ].flags =0 ;drivers/mfd/da9063-i2c.c
Quoted 10 lines
drivers/mfd/da9063-i2c.c +10
-0+ xfer[DA9063_PAGED_READ_MSG_REG_SEL ].len =sizeof (paged_addr); + xfer[DA9063_PAGED_READ_MSG_REG_SEL ].buf = &paged_addr; + +/* Read data */ + xfer[DA9063_PAGED_READ_MSG_DATA ].addr = client->addr; + xfer[DA9063_PAGED_READ_MSG_DATA ].flags =I2C_M_RD ; + xfer[DA9063_PAGED_READ_MSG_DATA ].len = count; + xfer[DA9063_PAGED_READ_MSG_DATA ].buf = buf; + + ret = i2c_transfer(client->adapter, xfer,
DA9063_PAGED_READ_MSG_CNT);
Quoted 15 lines
drivers/mfd/da9063-i2c.c line 97
Quoted 12 lines
drivers/mfd/da9063-i2c.c +12
-0+if (ret <0 ) { +dev_err (&client->dev,"Paged block read failed: %d\n" , ret); +return ret; + } + +if (ret !=DA9063_PAGED_READ_MSG_CNT ) { +dev_err (&client->dev,"Paged block read failed to complete\n" ); +return -EIO ; + } + +return 0 ; +}Rather than open coding this, does it make sense to register a small (temporary?) Device ID Regmap to read from?
The original patch submission did exactly that but you indicated you weren't keen due to overheads, hence the implementation above. Actually what we have here is a bit smaller than the regmap approach and I really I'd rather not have to respin again just to revert to something that was dismissed in the first place over 6 months ago.
Re: [PATCH v3 1/2] mfd: da9063: Fix revision handling to correctly select reg tables
Quoted 106 lines · Adam Thomson
Quoted 88 lines · Lee Jones
Quoted 13 lines
The current implementation performs checking in the
i2c_probe()function of thevariant_codebut does this immediately after the containing struct has been initialised as all zero. This means the check for variant code will always default to using the BB tables and will never select AD. The variant code is subsequently set bydevice_init()and later used by the RTC so really it's a little fortunate this mismatch works.This update adds raw I2C read access functionality to read the chip and variant/revision information (common to all revisions) so that it can subsequently correctly choose the proper regmap tables for real initialisation.
Quoted 4 lines
Signed-off-by Adam Thomson <[email protected]>--- drivers/mfd/da9063-core.c | 31 ------ drivers/mfd/da9063-i2c.c | 184 +++++++++++++++++++++++++++++++----
Quoted 2 lines
include/linux/mfd/da9063/registers.h | 15 ++- 3 files changed, 177 insertions(+), 53 deletions(-)[...]
Quoted 27 lines
+ * Raw I2C access required for just accessing chip and variant info before we
+ * know which device is present. The info read from the device using this
+ * approach is then used to select the correct regmap tables.
+ */drivers/mfd/da9063-i2c.c +23
-0+ +#define DA9063_REG_PAGE_SIZE 0x100 +#define DA9063_REG_PAGED_ADDR_MASK 0xFF + +enum da9063_page_sel_buf_fmt { +DA9063_PAGE_SEL_BUF_PAGE_REG =0 , +DA9063_PAGE_SEL_BUF_PAGE_VAL , +DA9063_PAGE_SEL_BUF_SIZE , +}; + +enum da9063_paged_read_msgs { +DA9063_PAGED_READ_MSG_PAGE_SEL =0 , +DA9063_PAGED_READ_MSG_REG_SEL , +DA9063_PAGED_READ_MSG_DATA , +DA9063_PAGED_READ_MSG_CNT , +}; + +static int da9063_i2c_blockreg_read (struct i2c_client *client,u16 addr, +u8 *buf,int count) +{ +struct i2c_msg xfer[DA9063_PAGED_READ_MSG_CNT ]; +u8 page_sel_buf[DA9063_PAGE_SEL_BUF_SIZE ]; +u8 page_num, paged_addr;drivers/mfd/da9063-i2c.c
Quoted 10 lines
drivers/mfd/da9063-i2c.c +10
-0+int ret; + +/* Determine page info based on register address */ + page_num = (addr /DA9063_REG_PAGE_SIZE ); +if (page_num >1 ) { +dev_err (&client->dev,"Invalid register address provided\n" ); +return -EINVAL ; + } + + paged_addr = (addr % DA9063_REG_PAGE_SIZE) &
DA9063_REG_PAGED_ADDR_MASK;Review
Quoted 1 line
(quoted diff) +1
-0+ page_sel_buf[DA9063_PAGE_SEL_BUF_PAGE_REG] =
DA9063_REG_PAGE_CON;Review
Quoted 2 lines
(quoted diff) +2
-0+ page_sel_buf[DA9063_PAGE_SEL_BUF_PAGE_VAL] = + (page_num << DA9063_I2C_PAGE_SEL_SHIFT) &
DA9063_REG_PAGE_MASK;drivers/mfd/da9063-i2c.c
Quoted 5 lines
drivers/mfd/da9063-i2c.c +5
-0+ +/* Write reg address, page selection */ + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL ].addr = client->addr; + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL ].flags =0 ; + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL].len =
DA9063_PAGE_SEL_BUF_SIZE;Quoted 5 lines
drivers/mfd/da9063-i2c.c +5
-0+ xfer[DA9063_PAGED_READ_MSG_PAGE_SEL ].buf = page_sel_buf; + +/* Select register address */ + xfer[DA9063_PAGED_READ_MSG_REG_SEL ].addr = client->addr; + xfer[DA9063_PAGED_READ_MSG_REG_SEL ].flags =0 ;drivers/mfd/da9063-i2c.c
Quoted 10 lines
drivers/mfd/da9063-i2c.c +10
-0+ xfer[DA9063_PAGED_READ_MSG_REG_SEL ].len =sizeof (paged_addr); + xfer[DA9063_PAGED_READ_MSG_REG_SEL ].buf = &paged_addr; + +/* Read data */ + xfer[DA9063_PAGED_READ_MSG_DATA ].addr = client->addr; + xfer[DA9063_PAGED_READ_MSG_DATA ].flags =I2C_M_RD ; + xfer[DA9063_PAGED_READ_MSG_DATA ].len = count; + xfer[DA9063_PAGED_READ_MSG_DATA ].buf = buf; + + ret = i2c_transfer(client->adapter, xfer,
DA9063_PAGED_READ_MSG_CNT);Quoted 15 lines
drivers/mfd/da9063-i2c.c line 97
Quoted 12 lines
drivers/mfd/da9063-i2c.c +12
-0+if (ret <0 ) { +dev_err (&client->dev,"Paged block read failed: %d\n" , ret); +return ret; + } + +if (ret !=DA9063_PAGED_READ_MSG_CNT ) { +dev_err (&client->dev,"Paged block read failed to complete\n" ); +return -EIO ; + } + +return 0 ; +}Rather than open coding this, does it make sense to register a small (temporary?) Device ID Regmap to read from?
Quoted 5 lines
The original patch submission did exactly that but you indicated you weren't keen due to overheads, hence the implementation above. Actually what we have here is a bit smaller than the regmap approach and I really I'd rather not have to respin again just to revert to something that was dismissed in the first place over 6 months ago.
Actually the conversation went like:
Lee:
IIUC, you have a dependency issue whereby the device type is required before you can select the correct Regmap configuration. Is that correct?
If so, using Regmap for the initial register reads sounds like over-kill. What's stopping you simply using raw reads before the Regmap is instantiated?
Adam:
Actually nothing and I did consider this at the start. Nice thing with regmap is it's all tidily contained and provides the page swapping mechanism to access higher page registers like the variant information. Given this is only once at probe time it felt like this was a reasonable solution. However if you're not keen I can update to use raw access instead.
Lee:
It would be nice to compare the 2 solutions side by side. I can't see the raw reads of a few device-ID registers being anywhere near 170 lines though.
Ah, they are I2C transactions? Not the nice readl()s I had in mind.
Adam:
I can knock something together though just to see what it looks like.
Lee:
Well, I'd appreciated that, thanks.
So now we can see them side-by-side we can take them on their own merits. When I initially requested raw reads, I had readl()s in mind, rather than the extensive code required to read the required registers via I2C.
However, it looks like there is very little difference between them, thus I do not see a benefit to reverting it back. The current version seems fine.
I'll conduct a full review shortly, when I have a little more spare time (looking at my current TODO list, this will probably be Monday now). Although everything does look fine at first glance.
Signature · 4 lines
Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog
RE: [PATCH v3 1/2] mfd: da9063: Fix revision handling to correctly select reg tables
Quoted 142 lines · Lee Jones
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
The current implementation performs checking in the
i2c_probe()function of thevariant_codebut does this immediately after the containing struct has been initialised as all zero. This means the check for variant code will always default to using the BB tables and will never select AD. The variant code is subsequently set bydevice_init()and later used by the RTC so really it's a little fortunate this mismatch works.Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
This update adds raw I2C read access functionality to read the chip and variant/revision information (common to all revisions) so that it can subsequently correctly choose the proper regmap tables for real initialisation.
Signed-off-by Adam ThomsonQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
--- drivers/mfd/da9063-core.c | 31 ------ drivers/mfd/da9063-i2c.c | 184+++++++++++++++++++++++++++++++-
Quoted 7 lines
Quoted 7 lines
---
Quoted 2 lines
include/linux/mfd/da9063/registers.h | 15 ++- 3 files changed, 177 insertions(+), 53 deletions(-)[...]
Quoted 1 line
+ * Raw I2C access required for just accessing chip and variant info before
we
Quoted 80 lines
Quoted 64 lines
Quoted 26 lines
+ * know which device is present. The info read from the device using this
+ * approach is then used to select the correct regmap tables.
+ */drivers/mfd/da9063-i2c.c +23
-0+ +#define DA9063_REG_PAGE_SIZE 0x100 +#define DA9063_REG_PAGED_ADDR_MASK 0xFF + +enum da9063_page_sel_buf_fmt { +DA9063_PAGE_SEL_BUF_PAGE_REG =0 , +DA9063_PAGE_SEL_BUF_PAGE_VAL , +DA9063_PAGE_SEL_BUF_SIZE , +}; + +enum da9063_paged_read_msgs { +DA9063_PAGED_READ_MSG_PAGE_SEL =0 , +DA9063_PAGED_READ_MSG_REG_SEL , +DA9063_PAGED_READ_MSG_DATA , +DA9063_PAGED_READ_MSG_CNT , +}; + +static int da9063_i2c_blockreg_read (struct i2c_client *client,u16 addr, +u8 *buf,int count) +{ +struct i2c_msg xfer[DA9063_PAGED_READ_MSG_CNT ]; +u8 page_sel_buf[DA9063_PAGE_SEL_BUF_SIZE ]; +u8 page_num, paged_addr;drivers/mfd/da9063-i2c.c
Quoted 10 lines
drivers/mfd/da9063-i2c.c +10
-0+int ret; + +/* Determine page info based on register address */ + page_num = (addr /DA9063_REG_PAGE_SIZE ); +if (page_num >1 ) { +dev_err (&client->dev,"Invalid register address provided\n" ); +return -EINVAL ; + } + + paged_addr = (addr % DA9063_REG_PAGE_SIZE) &
DA9063_REG_PAGED_ADDR_MASK;Review
Quoted 1 line
(quoted diff) +1
-0+ page_sel_buf[DA9063_PAGE_SEL_BUF_PAGE_REG] =
DA9063_REG_PAGE_CON;Review
Quoted 2 lines
(quoted diff) +2
-0+ page_sel_buf[DA9063_PAGE_SEL_BUF_PAGE_VAL] = + (page_num << DA9063_I2C_PAGE_SEL_SHIFT) &
DA9063_REG_PAGE_MASK;drivers/mfd/da9063-i2c.c
Quoted 5 lines
drivers/mfd/da9063-i2c.c +5
-0+ +/* Write reg address, page selection */ + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL ].addr = client->addr; + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL ].flags =0 ; + xfer[DA9063_PAGED_READ_MSG_PAGE_SEL].len =
DA9063_PAGE_SEL_BUF_SIZE;Quoted 5 lines
drivers/mfd/da9063-i2c.c +5
-0+ xfer[DA9063_PAGED_READ_MSG_PAGE_SEL ].buf = page_sel_buf; + +/* Select register address */ + xfer[DA9063_PAGED_READ_MSG_REG_SEL ].addr = client->addr; + xfer[DA9063_PAGED_READ_MSG_REG_SEL ].flags =0 ;drivers/mfd/da9063-i2c.c
Quoted 10 lines
drivers/mfd/da9063-i2c.c +10
-0+ xfer[DA9063_PAGED_READ_MSG_REG_SEL ].len =sizeof (paged_addr); + xfer[DA9063_PAGED_READ_MSG_REG_SEL ].buf = &paged_addr; + +/* Read data */ + xfer[DA9063_PAGED_READ_MSG_DATA ].addr = client->addr; + xfer[DA9063_PAGED_READ_MSG_DATA ].flags =I2C_M_RD ; + xfer[DA9063_PAGED_READ_MSG_DATA ].len = count; + xfer[DA9063_PAGED_READ_MSG_DATA ].buf = buf; + + ret = i2c_transfer(client->adapter, xfer,
DA9063_PAGED_READ_MSG_CNT);Quoted 15 lines
drivers/mfd/da9063-i2c.c line 97
Quoted 12 lines
drivers/mfd/da9063-i2c.c +12
-0+if (ret <0 ) { +dev_err (&client->dev,"Paged block read failed: %d\n" , ret); +return ret; + } + +if (ret !=DA9063_PAGED_READ_MSG_CNT ) { +dev_err (&client->dev,"Paged block read failed to complete\n" ); +return -EIO ; + } + +return 0 ; +}Rather than open coding this, does it make sense to register a small (temporary?) Device ID Regmap to read from?
Quoted 2 lines
The original patch submission did exactly that but you indicated you weren't keen due to overheads, hence the implementation above. Actually what we
have
Quoted 3 lines
here is a bit smaller than the regmap approach and I really I'd rather not have to respin again just to revert to something that was dismissed in the first place over 6 months ago.
Actually the conversation went like:
Lee:
IIUC, you have a dependency issue whereby the device type is required before you can select the correct Regmap configuration. Is that correct?If so, using Regmap for the initial register reads sounds like over-kill. What's stopping you simply using raw reads before the Regmap is instantiated?
Adam:
Actually nothing and I did consider this at the start. Nice thing with regmap is it's all tidily contained and provides the page swapping mechanism to access higher page registers like the variant information. Given this is only once at probe time it felt like this was a reasonable solution. However if you're not keen I can update to use raw access instead.Lee:
It would be nice to compare the 2 solutions side by side. I can't see the raw reads of a few device-ID registers being anywhere near 170 lines though.Ah, they are I2C transactions? Not the nice readl()s I had in mind.
Adam:
I can knock something together though just to see what it looks like.
Quoted 7 lines
Lee:
Well, I'd appreciated that, thanks.So now we can see them side-by-side we can take them on their own merits. When I initially requested raw reads, I had readl()s in mind, rather than the extensive code required to read the required registers via I2C.
To be fair those changes were in V2 of the patch set, which is why I was a quite surprised by your suggestion today as you hadn't made this comment against that version, given the previous discussion.
Quoted 9 lines
However, it looks like there is very little difference between them, thus I do not see a benefit to reverting it back. The current version seems fine.
I'll conduct a full review shortly, when I have a little more spare time (looking at my current TODO list, this will probably be Monday now). Although everything does look fine at first glance.
Thanks. That would be appreciated.
Quoted 5 lines
--
Lee Jones [李琼斯]
Senior Technical Lead - Developer ServicesLinaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH v3 1/2] mfd: da9063: Fix revision handling to correctly select reg tables
Quoted 24 lines · Adam Thomson
Quoted 22 lines · Lee Jones
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
The current implementation performs checking in the
i2c_probe()function of thevariant_codebut does this immediately after the containing struct has been initialised as all zero. This means the check for variant code will always default to using the BB tables and will never select AD. The variant code is subsequently set bydevice_init()and later used by the RTC so really it's a little fortunate this mismatch works.Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
This update adds raw I2C read access functionality to read the chip and variant/revision information (common to all revisions) so that it can subsequently correctly choose the proper regmap tables for real initialisation.
Signed-off-by Adam ThomsonQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
--- drivers/mfd/da9063-core.c | 31 ------ drivers/mfd/da9063-i2c.c | 184+++++++++++++++++++++++++++++++-
Quoted 3 lines
Quoted 3 lines
---
Quoted 2 lines
include/linux/mfd/da9063/registers.h | 15 ++- 3 files changed, 177 insertions(+), 53 deletions(-)
[...]
Quoted 41 lines
Quoted 41 lines
Quoted 5 lines
Quoted 2 lines
Rather than open coding this, does it make sense to register a small (temporary?) Device ID Regmap to read from?
The original patch submission did exactly that but you indicated you weren't keen due to overheads, hence the implementation above. Actually what we
have
Quoted 3 lines
here is a bit smaller than the regmap approach and I really I'd rather not have to respin again just to revert to something that was dismissed in the first place over 6 months ago.
Actually the conversation went like:
Lee:
IIUC, you have a dependency issue whereby the device type is required before you can select the correct Regmap configuration. Is that correct?If so, using Regmap for the initial register reads sounds like over-kill. What's stopping you simply using raw reads before the Regmap is instantiated?
Adam:
Actually nothing and I did consider this at the start. Nice thing with regmap is it's all tidily contained and provides the page swapping mechanism to access higher page registers like the variant information. Given this is only once at probe time it felt like this was a reasonable solution. However if you're not keen I can update to use raw access instead.Lee:
It would be nice to compare the 2 solutions side by side. I can't see the raw reads of a few device-ID registers being anywhere near 170 lines though.Ah, they are I2C transactions? Not the nice readl()s I had in mind.
Adam:
I can knock something together though just to see what it looks like.Lee:
Well, I'd appreciated that, thanks.
Quoted 8 lines
Quoted 4 lines
So now we can see them side-by-side we can take them on their own merits. When I initially requested raw reads, I had readl()s in mind, rather than the extensive code required to read the required registers via I2C.
To be fair those changes were in V2 of the patch set, which is why I was a quite surprised by your suggestion today as you hadn't made this comment against that version, given the previous discussion.
It would be very difficult to remember complete revision history for every patch received. Especially with the lack of a provided patch-level changelog. So I have to take each submission on its own merits. This is particularly true for patch-sets ranging over 6 months or more.
The Regmap vs raw accesses decision could easily have gone either way, so it's not surprising the other was considered during the review of each submission. Both times were phrased as an "I wonder if" enquiry, rather than a demand.
Quoted 9 lines
Quoted 7 lines
However, it looks like there is very little difference between them, thus I do not see a benefit to reverting it back. The current version seems fine.
I'll conduct a full review shortly, when I have a little more spare time (looking at my current TODO list, this will probably be Monday now). Although everything does look fine at first glance.
Thanks. That would be appreciated.
Signature · 4 lines
Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog