Skip to contentSkip to conversation

Resolve revision handling and add support for DA silicon

PATCH RESEND Superseded Adam Thomson 2 participants 11 messages Apr 6, 2020 – Apr 20, 2020

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 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.

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             | 249 +++++++++++++++++++++++++++++++----
 include/linux/mfd/da9063/core.h      |   1 +
 include/linux/mfd/da9063/registers.h |  15 ++-
 4 files changed, 235 insertions(+), 61 deletions(-)
Signature · 1 line
1.9.1
#8 lore raw

PATCH RESEND v2 2/2 mfd: da9063: Add support for latest DA silicon revision

This 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
index 2654b49..38452ae 100644
@@ -175,7 +175,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),
@@ -197,9 +197,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[] = {
@@ -219,7 +219,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),
@@ -241,9 +241,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[] = {
@@ -311,7 +366,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,
@@ -328,7 +391,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
index 5cd06ab..fa7a43f 100644
@@ -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
#1 lore raw

PATCH RESEND v2 1/2 mfd: da9063: Fix revision handling to correctly select reg tables

In reply to Adam Thomson

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             | 162 +++++++++++++++++++++++++++++++----
 include/linux/mfd/da9063/registers.h |  15 ++--
 3 files changed, 155 insertions(+), 53 deletions(-)
drivers/mfd/da9063-core.c +0 -31
index b125f90d..a353d52 100644
@@ -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 +145 -17

203 lines not on this page · raw message

include/linux/mfd/da9063/registers.h +10 -5
index ba706b0..1dbabf1 100644
@@ -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
#2 lore raw

Re: [RESEND PATCH v2 1/2] mfd: da9063: Fix revision handling to correctly select reg tables

Quoted 82 lines · Adam Thomson

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             | 162 +++++++++++++++++++++++++++++++----
 include/linux/mfd/da9063/registers.h |  15 ++--
 3 files changed, 155 insertions(+), 53 deletions(-)
drivers/mfd/da9063-core.c +0 -31
index b125f90d..a353d52 100644
@@ -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 +5 -0
index 455de74..2654b49 100644
@@ -22,12 +22,102 @@
 #include <linux/of.h>
 #include <linux/regulator/of_regulator.h>
 
+/*
+ * 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 line 39

Quoted 10 lines
drivers/mfd/da9063-i2c.c +10 -0
+static int da9063_i2c_blockreg_read(struct i2c_client *client, u16 addr,
+				    u8 *buf, int count)
+{
+	struct i2c_msg xfer[3];
+	u8 page_num, paged_addr;
+	u8 page_buf[2];
+	int ret;
+
+	/* Determine page info based on register address */
+	page_num = (addr / 0x100);

Please define magic numbers.

drivers/mfd/da9063-i2c.c line 40

Quoted 1 line
drivers/mfd/da9063-i2c.c +1 -0
+	if (page_num > 1)

Please define magic numbers.

drivers/mfd/da9063-i2c.c line 41

Quoted 1 line
drivers/mfd/da9063-i2c.c +1 -0
+		return -EINVAL;

Do you want to fail silently here?

Quoted 14 lines
drivers/mfd/da9063-i2c.c +14 -0
+	paged_addr = (addr % 0x100) & 0xFF;
+	page_buf[0] = DA9063_REG_PAGE_CON;
+	page_buf[1] = (page_num << DA9063_I2C_PAGE_SEL_SHIFT) &
+		      DA9063_REG_PAGE_MASK;
+
+	/* Write reg address, page selection */
+	xfer[0].addr = client->addr;
+	xfer[0].flags = 0;
+	xfer[0].len = 2;
+	xfer[0].buf = page_buf;
+
+	/* Select register address */
+	xfer[1].addr = client->addr;
+	xfer[1].flags = 0;

drivers/mfd/da9063-i2c.c line 66

Quoted 10 lines
drivers/mfd/da9063-i2c.c +10 -0
+	xfer[1].len = 1;
+	xfer[1].buf = &paged_addr;
+
+	/* Read data */
+	xfer[2].addr = client->addr;
+	xfer[2].flags = I2C_M_RD;
+	xfer[2].len = count;
+	xfer[2].buf = buf;
+
+	ret = i2c_transfer(client->adapter, xfer, 3);

Why is this 3? 'count' and a NULL char?

drivers/mfd/da9063-i2c.c line 72

Quoted 6 lines
drivers/mfd/da9063-i2c.c +6 -0
+	if (ret == 3)
+		return 0;
+	else if (ret < 0)
+		return ret;
+	else
+		return -EIO;

I think the following makes it slightly clearer.

	if (ret < 0)
		return ret;

	if (ret == 3)
		return 0;
	else
		return -EIO;

drivers/mfd/da9063-i2c.c line 84

Quoted 12 lines
drivers/mfd/da9063-i2c.c +12 -0
+}
+
+enum {
+	DA9063_DEV_ID_REG = 0,
+	DA9063_VAR_ID_REG,
+	DA9063_CHIP_ID_REGS,
+};
+
+static int da9063_get_device_type(struct i2c_client *i2c, struct da9063 *da9063)
+{
+	int ret;
+	u8 buf[DA9063_CHIP_ID_REGS];

Really small nit: Could you reverse these please.

drivers/mfd/da9063-i2c.c line 88

Quoted 3 lines
drivers/mfd/da9063-i2c.c +3 -0
+	ret = da9063_i2c_blockreg_read(i2c, DA9063_REG_DEVICE_ID, buf,
+				       DA9063_CHIP_ID_REGS);
+	if (ret < 0) {

if (ret)

Or better yet, as this is a read function, you could just return i2c_transfer() and do the appropriate error checking here *instead*.

drivers/mfd/da9063-i2c.c line 95

Quoted 7 lines
drivers/mfd/da9063-i2c.c +7 -0
+		dev_err(da9063->dev, "Cannot read chip id info.\n");
+		return ret;
+	}
+
+	if (buf[DA9063_DEV_ID_REG] != PMIC_CHIP_ID_DA9063) {
+		dev_err(da9063->dev,
+			"Invalid chip device id: 0x%02x\n",

s/id/ID/

Quoted 73 lines
drivers/mfd/da9063-i2c.c +24 -9
+			buf[DA9063_DEV_ID_REG]);
+		return -ENODEV;
+	}
+
+	dev_info(da9063->dev,
+		 "Device detected (chip-ID: 0x%02X, var-ID: 0x%02X)\n",
+		 buf[DA9063_DEV_ID_REG], buf[DA9063_VAR_ID_REG]);
+
+	da9063->variant_code =
+		(buf[DA9063_VAR_ID_REG] & DA9063_VARIANT_ID_MRC_MASK)
+		>> DA9063_VARIANT_ID_MRC_SHIFT;
+
+	return 0;
+}
+
+/*
+ * Variant specific regmap configs
+ */
+
 static const struct regmap_range da9063_ad_readable_ranges[] = {
 	regmap_reg_range(DA9063_REG_PAGE_CON, DA9063_AD_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_AD_REG_GP_ID_19),
-	regmap_reg_range(DA9063_REG_CHIP_ID, DA9063_REG_CHIP_VARIANT),
+	regmap_reg_range(DA9063_REG_DEVICE_ID, DA9063_REG_VARIANT_ID),
 };
 
 static const struct regmap_range da9063_ad_writeable_ranges[] = {
@@ -72,7 +162,7 @@
 	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_19),
-	regmap_reg_range(DA9063_REG_CHIP_ID, DA9063_REG_CHIP_VARIANT),
+	regmap_reg_range(DA9063_REG_DEVICE_ID, DA9063_REG_VARIANT_ID),
 };
 
 static const struct regmap_range da9063_bb_writeable_ranges[] = {
@@ -117,7 +207,7 @@
 	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_19),
-	regmap_reg_range(DA9063_REG_CHIP_ID, DA9063_REG_CHIP_VARIANT),
+	regmap_reg_range(DA9063_REG_DEVICE_ID, DA9063_REG_VARIANT_ID),
 };
 
 static const struct regmap_range da9063l_bb_writeable_ranges[] = {
@@ -159,7 +249,7 @@
 static const struct regmap_range_cfg da9063_range_cfg[] = {
 	{
 		.range_min = DA9063_REG_PAGE_CON,
-		.range_max = DA9063_REG_CHIP_VARIANT,
+		.range_max = DA9063_REG_CONFIG_ID,
 		.selector_reg = DA9063_REG_PAGE_CON,
 		.selector_mask = 1 << DA9063_I2C_PAGE_SEL_SHIFT,
 		.selector_shift = DA9063_I2C_PAGE_SEL_SHIFT,
@@ -173,7 +263,7 @@
 	.val_bits = 8,
 	.ranges = da9063_range_cfg,
 	.num_ranges = ARRAY_SIZE(da9063_range_cfg),
-	.max_register = DA9063_REG_CHIP_VARIANT,
+	.max_register = DA9063_REG_CONFIG_ID,
 
 	.cache_type = REGCACHE_RBTREE,
 };
@@ -199,18 +289,56 @@ static int da9063_i2c_probe(struct i2c_client *i2c,
 	da9063->chip_irq = i2c->irq;
 	da9063->type = id->driver_data;
 
-	if (da9063->variant_code == PMIC_DA9063_AD) {
-		da9063_regmap_config.rd_table = &da9063_ad_readable_table;
-		da9063_regmap_config.wr_table = &da9063_ad_writeable_table;
-		da9063_regmap_config.volatile_table = &da9063_ad_volatile_table;

drivers/mfd/da9063-i2c.c static int da9063_i2c_probe(struct i2c_client *i2c, · line 293

Quoted 10 lines
drivers/mfd/da9063-i2c.c +2 -8
-	} else if (da9063->type == PMIC_TYPE_DA9063L) {
-		da9063_regmap_config.rd_table = &da9063l_bb_readable_table;
-		da9063_regmap_config.wr_table = &da9063l_bb_writeable_table;
-		da9063_regmap_config.volatile_table = &da9063l_bb_volatile_table;
-	} else {
-		da9063_regmap_config.rd_table = &da9063_bb_readable_table;
-		da9063_regmap_config.wr_table = &da9063_bb_writeable_table;
-		da9063_regmap_config.volatile_table = &da9063_bb_volatile_table;
+	ret = da9063_get_device_type(i2c, da9063);
+	if (ret < 0)

Is a positive return value valid?

If not: if (ret)

Quoted 89 lines
drivers/mfd/da9063-i2c.c +48 -0
+		return ret;
+
+	switch (da9063->type) {
+	case PMIC_TYPE_DA9063:
+		switch (da9063->variant_code) {
+		case PMIC_DA9063_AD:
+			da9063_regmap_config.rd_table =
+				&da9063_ad_readable_table;
+			da9063_regmap_config.wr_table =
+				&da9063_ad_writeable_table;
+			da9063_regmap_config.volatile_table =
+				&da9063_ad_volatile_table;
+			break;
+		case PMIC_DA9063_BB:
+		case PMIC_DA9063_CA:
+			da9063_regmap_config.rd_table =
+				&da9063_bb_readable_table;
+			da9063_regmap_config.wr_table =
+				&da9063_bb_writeable_table;
+			da9063_regmap_config.volatile_table =
+				&da9063_bb_volatile_table;
+			break;
+		default:
+			dev_err(da9063->dev,
+				"Chip variant not supported for DA9063\n");
+			return -ENODEV;
+		}
+		break;
+	case PMIC_TYPE_DA9063L:
+		switch (da9063->variant_code) {
+		case PMIC_DA9063_BB:
+		case PMIC_DA9063_CA:
+			da9063_regmap_config.rd_table =
+				&da9063l_bb_readable_table;
+			da9063_regmap_config.wr_table =
+				&da9063l_bb_writeable_table;
+			da9063_regmap_config.volatile_table =
+				&da9063l_bb_volatile_table;
+			break;
+		default:
+			dev_err(da9063->dev,
+				"Chip variant not supported for DA9063L\n");
+			return -ENODEV;
+		}
+		break;
+	default:
+		dev_err(da9063->dev, "Chip type not supported\n");
+		return -ENODEV;
 	}
 
 	da9063->regmap = devm_regmap_init_i2c(i2c, &da9063_regmap_config);
include/linux/mfd/da9063/registers.h +10 -5
index ba706b0..1dbabf1 100644
@@ -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 · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#9 lore raw

Re: [RESEND v2 PATCH 2/2] mfd: da9063: Add support for latest DA silicon revision

In reply to Adam Thomson
Quoted 10 lines · Adam Thomson

This 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(-)

Can this patch be applied on its own?

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#3 lore raw

RE: [RESEND PATCH v2 1/2] mfd: da9063: Fix revision handling to correctly select reg tables

In reply to Lee Jones
Quoted 18 lines · Lee Jones
Quoted 5 lines
drivers/mfd/da9063-i2c.c +5 -0
+/*
+ * 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 line 39

Quoted 10 lines
drivers/mfd/da9063-i2c.c +10 -0
+static int da9063_i2c_blockreg_read(struct i2c_client *client, u16 addr,
+				    u8 *buf, int count)
+{
+	struct i2c_msg xfer[3];
+	u8 page_num, paged_addr;
+	u8 page_buf[2];
+	int ret;
+
+	/* Determine page info based on register address */
+	page_num = (addr / 0x100);

Please define magic numbers.

Quoted 3 lines

drivers/mfd/da9063-i2c.c line 40

Quoted 1 line
drivers/mfd/da9063-i2c.c +1 -0
+	if (page_num > 1)

Please define magic numbers.

I was going to but decided against it given the minimal use. Easy enough to change though.

Quoted 4 lines

drivers/mfd/da9063-i2c.c line 41

Quoted 2 lines
drivers/mfd/da9063-i2c.c +1 -0
+		return -EINVAL;

Do you want to fail silently here?

Well an error message is printed in the calling code, so didn't feel like it was necessary to have additional debug here. Felt like bloat.

Quoted 19 lines
Quoted 19 lines
drivers/mfd/da9063-i2c.c +18 -0
+	paged_addr = (addr % 0x100) & 0xFF;
+	page_buf[0] = DA9063_REG_PAGE_CON;
+	page_buf[1] = (page_num << DA9063_I2C_PAGE_SEL_SHIFT) &
+		      DA9063_REG_PAGE_MASK;
+
+	/* Write reg address, page selection */
+	xfer[0].addr = client->addr;
+	xfer[0].flags = 0;
+	xfer[0].len = 2;
+	xfer[0].buf = page_buf;
+
+	/* Select register address */
+	xfer[1].addr = client->addr;
+	xfer[1].flags = 0;
+	xfer[1].len = 1;
+	xfer[1].buf = &paged_addr;
+
+	/* Read data */
Quoted 8 lines

drivers/mfd/da9063-i2c.c line 66

Quoted 6 lines
drivers/mfd/da9063-i2c.c +6 -0
+	xfer[2].addr = client->addr;
+	xfer[2].flags = I2C_M_RD;
+	xfer[2].len = count;
+	xfer[2].buf = buf;
+
+	ret = i2c_transfer(client->adapter, xfer, 3);

Why is this 3? 'count' and a NULL char?

Well there are 3 messages defined above so I want to process all of them. One to set the page register to the page we want to read from, one to select the register we want to read from in that page and then finally the read back of the chip id and revision/variant info.

Quoted 10 lines

drivers/mfd/da9063-i2c.c line 72

Quoted 7 lines
drivers/mfd/da9063-i2c.c +6 -0
+	if (ret == 3)
+		return 0;
+	else if (ret < 0)
+		return ret;
+	else
+		return -EIO;

I think the following makes it slightly clearer.

Quoted 8 lines
	if (ret < 0)
		return ret;

	if (ret == 3)
		return 0;
	else
		return -EIO;

Ok. Don't think it makes much of a difference but don't mind really. I can add a #define for the number of messages to be sent which will clarify this slightly anyway.

Quoted 10 lines

drivers/mfd/da9063-i2c.c

Quoted 9 lines
drivers/mfd/da9063-i2c.c +9 -0
+}
+
+enum {
+	DA9063_DEV_ID_REG = 0,
+	DA9063_VAR_ID_REG,
+	DA9063_CHIP_ID_REGS,
+};
+
+static int da9063_get_device_type(struct i2c_client *i2c, struct da9063

*da9063)

Quoted 5 lines

drivers/mfd/da9063-i2c.c line 84

Quoted 3 lines
drivers/mfd/da9063-i2c.c +3 -0
+{
+	int ret;
+	u8 buf[DA9063_CHIP_ID_REGS];

Really small nit: Could you reverse these please.

Yep, agreed.

Quoted 9 lines

drivers/mfd/da9063-i2c.c line 88

Quoted 4 lines
drivers/mfd/da9063-i2c.c +3 -0
+	ret = da9063_i2c_blockreg_read(i2c, DA9063_REG_DEVICE_ID, buf,
+				       DA9063_CHIP_ID_REGS);
+	if (ret < 0) {

if (ret)

Or better yet, as this is a read function, you could just return i2c_transfer() and do the appropriate error checking here *instead*.

I think given that the function handles all of the I2C specific stuff I'd prefer it be kept there. Logically that to me makes more sense. Can change this to 'if (ret)'

Quoted 10 lines

drivers/mfd/da9063-i2c.c line 95

Quoted 8 lines
drivers/mfd/da9063-i2c.c +7 -0
+		dev_err(da9063->dev, "Cannot read chip id info.\n");
+		return ret;
+	}
+
+	if (buf[DA9063_DEV_ID_REG] != PMIC_CHIP_ID_DA9063) {
+		dev_err(da9063->dev,
+			"Invalid chip device id: 0x%02x\n",

s/id/ID/

yep, will update.

Quoted 20 lines

drivers/mfd/da9063-i2c.c static int da9063_i2c_probe(struct i2c_client *i2c, · line 204

Quoted 7 lines
drivers/mfd/da9063-i2c.c +0 -3
@@ -199,18 +289,56 @@ static int da9063_i2c_probe(struct i2c_client *i2c,
 	da9063->chip_irq = i2c->irq;
 	da9063->type = id->driver_data;
 
-	if (da9063->variant_code == PMIC_DA9063_AD) {
-		da9063_regmap_config.rd_table = &da9063_ad_readable_table;
-		da9063_regmap_config.wr_table =

&da9063_ad_writeable_table;

Review static int da9063_i2c_probe(struct i2c_client *i2c, · line 205

Quoted 1 line
(quoted diff) +0 -1
-		da9063_regmap_config.volatile_table =

&da9063_ad_volatile_table;

drivers/mfd/da9063-i2c.c static int da9063_i2c_probe(struct i2c_client *i2c,

Quoted 3 lines
drivers/mfd/da9063-i2c.c +0 -3
-	} else if (da9063->type == PMIC_TYPE_DA9063L) {
-		da9063_regmap_config.rd_table = &da9063l_bb_readable_table;
-		da9063_regmap_config.wr_table =

&da9063l_bb_writeable_table;

Review static int da9063_i2c_probe(struct i2c_client *i2c, · line 209

Quoted 1 line
(quoted diff) +0 -1
-		da9063_regmap_config.volatile_table =

&da9063l_bb_volatile_table;

drivers/mfd/da9063-i2c.c static int da9063_i2c_probe(struct i2c_client *i2c,

Quoted 3 lines
drivers/mfd/da9063-i2c.c +0 -3
-	} else {
-		da9063_regmap_config.rd_table = &da9063_bb_readable_table;
-		da9063_regmap_config.wr_table =

&da9063_bb_writeable_table;

Quoted 9 lines

Review static int da9063_i2c_probe(struct i2c_client *i2c, · line 213

Quoted 1 line
(quoted diff) +0 -1
-		da9063_regmap_config.volatile_table =

&da9063_bb_volatile_table;

drivers/mfd/da9063-i2c.c static int da9063_i2c_probe(struct i2c_client *i2c, · line 293

Quoted 2 lines
drivers/mfd/da9063-i2c.c +2 -0
+	ret = da9063_get_device_type(i2c, da9063);
+	if (ret < 0)

Is a positive return value valid?

If not: if (ret)

Yep, think this can be just 'if (ret)'

#10 lore raw

RE: [RESEND v2 PATCH 2/2] mfd: da9063: Add support for latest DA silicon revision

In reply to Lee Jones
Quoted 10 lines · Lee Jones
Quoted 8 lines · Adam Thomson

This 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
Quoted 5 lines

++++++++++++++++++++++++++++++++++++-----

Quoted 2 lines
 include/linux/mfd/da9063/core.h |  1 +
 2 files changed, 82 insertions(+), 10 deletions(-)

Can this patch be applied on its own?

Sadly not. Relies on a new switch statement added by the first patch.

#4 lore raw

Re: [RESEND PATCH v2 1/2] mfd: da9063: Fix revision handling to correctly select reg tables

In reply to Adam Thomson
Quoted 20 lines · Adam Thomson
Quoted 18 lines · Lee Jones
Quoted 5 lines
drivers/mfd/da9063-i2c.c +5 -0
+/*
+ * 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 line 39

Quoted 10 lines
drivers/mfd/da9063-i2c.c +10 -0
+static int da9063_i2c_blockreg_read(struct i2c_client *client, u16 addr,
+				    u8 *buf, int count)
+{
+	struct i2c_msg xfer[3];
+	u8 page_num, paged_addr;
+	u8 page_buf[2];
+	int ret;
+
+	/* Determine page info based on register address */
+	page_num = (addr / 0x100);

Please define magic numbers.

Quoted 6 lines
Quoted 3 lines

drivers/mfd/da9063-i2c.c line 40

Quoted 1 line
drivers/mfd/da9063-i2c.c +1 -0
+	if (page_num > 1)

Please define magic numbers.

I was going to but decided against it given the minimal use. Easy enough to change though.

It's purely for readability purposes.

Quoted 6 lines
Quoted 3 lines

drivers/mfd/da9063-i2c.c line 41

Quoted 1 line
drivers/mfd/da9063-i2c.c +1 -0
+		return -EINVAL;

Do you want to fail silently here?

Well an error message is printed in the calling code, so didn't feel like it was necessary to have additional debug here. Felt like bloat.

As a user, I would prefer a more specific reason.

Thus, I would provide an error message here and omit the generic one.

Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
drivers/mfd/da9063-i2c.c +18 -0
+	paged_addr = (addr % 0x100) & 0xFF;
+	page_buf[0] = DA9063_REG_PAGE_CON;
+	page_buf[1] = (page_num << DA9063_I2C_PAGE_SEL_SHIFT) &
+		      DA9063_REG_PAGE_MASK;
+
+	/* Write reg address, page selection */
+	xfer[0].addr = client->addr;
+	xfer[0].flags = 0;
+	xfer[0].len = 2;
+	xfer[0].buf = page_buf;
+
+	/* Select register address */
+	xfer[1].addr = client->addr;
+	xfer[1].flags = 0;
+	xfer[1].len = 1;
+	xfer[1].buf = &paged_addr;
+
+	/* Read data */
Quoted 8 lines

drivers/mfd/da9063-i2c.c line 66

Quoted 6 lines
drivers/mfd/da9063-i2c.c +6 -0
+	xfer[2].addr = client->addr;
+	xfer[2].flags = I2C_M_RD;
+	xfer[2].len = count;
+	xfer[2].buf = buf;
+
+	ret = i2c_transfer(client->adapter, xfer, 3);

Why is this 3? 'count' and a NULL char?

Quoted 4 lines

Well there are 3 messages defined above so I want to process all of them. One to set the page register to the page we want to read from, one to select the register we want to read from in that page and then finally the read back of the chip id and revision/variant info.

I see. Thank you for the explanation.

Quoted 18 lines
Quoted 9 lines

drivers/mfd/da9063-i2c.c line 72

Quoted 6 lines
drivers/mfd/da9063-i2c.c +6 -0
+	if (ret == 3)
+		return 0;
+	else if (ret < 0)
+		return ret;
+	else
+		return -EIO;

I think the following makes it slightly clearer.

Quoted 8 lines
	if (ret < 0)
		return ret;

	if (ret == 3)
		return 0;
	else
		return -EIO;
Quoted 3 lines

Ok. Don't think it makes much of a difference but don't mind really. I can add a #define for the number of messages to be sent which will clarify this slightly anyway.

Yes, I think that would be good.

Quoted 25 lines
Quoted 10 lines

drivers/mfd/da9063-i2c.c

Quoted 9 lines
drivers/mfd/da9063-i2c.c +9 -0
+}
+
+enum {
+	DA9063_DEV_ID_REG = 0,
+	DA9063_VAR_ID_REG,
+	DA9063_CHIP_ID_REGS,
+};
+
+static int da9063_get_device_type(struct i2c_client *i2c, struct da9063

*da9063)

Quoted 5 lines

drivers/mfd/da9063-i2c.c line 84

Quoted 3 lines
drivers/mfd/da9063-i2c.c +3 -0
+{
+	int ret;
+	u8 buf[DA9063_CHIP_ID_REGS];

Really small nit: Could you reverse these please.

Yep, agreed.

Quoted 7 lines

drivers/mfd/da9063-i2c.c line 88

Quoted 4 lines
drivers/mfd/da9063-i2c.c +3 -0
+	ret = da9063_i2c_blockreg_read(i2c, DA9063_REG_DEVICE_ID, buf,
+				       DA9063_CHIP_ID_REGS);
+	if (ret < 0) {

if (ret)

Quoted 6 lines
Quoted 2 lines

Or better yet, as this is a read function, you could just return i2c_transfer() and do the appropriate error checking here *instead*.

I think given that the function handles all of the I2C specific stuff I'd prefer it be kept there. Logically that to me makes more sense. Can change this to 'if (ret)'

Yes, not that I understand the message length (3) has more do to with the I2C interactions (rather than a derisive of 'count'), it makes sense to handle that inside the function.

However, it does seem odd to handle the return value of a *_read() function in this way. They usually return the number of bytes read, which in this case would be DA9063_CHIP_ID_REGS (count), right?

[...]

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#5 lore raw

RE: [RESEND PATCH v2 1/2] mfd: da9063: Fix revision handling to correctly select reg tables

Quoted 10 lines · Lee Jones
Quoted 6 lines
Quoted 3 lines

drivers/mfd/da9063-i2c.c line 41

Quoted 1 line
drivers/mfd/da9063-i2c.c +1 -0
+		return -EINVAL;

Do you want to fail silently here?

Well an error message is printed in the calling code, so didn't feel like it was necessary to have additional debug here. Felt like bloat.

As a user, I would prefer a more specific reason.

Thus, I would provide an error message here and omit the generic one.

I can update although I'll of course then need to do similar messages for the other error legs of this function. FWIW, as this is only being called once in the same file this error leg of code currently can never occur.

Quoted 32 lines
Quoted 25 lines
Quoted 10 lines

drivers/mfd/da9063-i2c.c

Quoted 9 lines
drivers/mfd/da9063-i2c.c +9 -0
+}
+
+enum {
+	DA9063_DEV_ID_REG = 0,
+	DA9063_VAR_ID_REG,
+	DA9063_CHIP_ID_REGS,
+};
+
+static int da9063_get_device_type(struct i2c_client *i2c, struct da9063

*da9063)

Quoted 5 lines

drivers/mfd/da9063-i2c.c line 84

Quoted 3 lines
drivers/mfd/da9063-i2c.c +3 -0
+{
+	int ret;
+	u8 buf[DA9063_CHIP_ID_REGS];

Really small nit: Could you reverse these please.

Yep, agreed.

Quoted 7 lines

drivers/mfd/da9063-i2c.c line 88

Quoted 4 lines
drivers/mfd/da9063-i2c.c +3 -0
+	ret = da9063_i2c_blockreg_read(i2c, DA9063_REG_DEVICE_ID, buf,
+				       DA9063_CHIP_ID_REGS);
+	if (ret < 0) {

if (ret)

Quoted 6 lines
Quoted 2 lines

Or better yet, as this is a read function, you could just return i2c_transfer() and do the appropriate error checking here *instead*.

I think given that the function handles all of the I2C specific stuff I'd prefer it be kept there. Logically that to me makes more sense. Can change this to 'if (ret)'

Quoted 7 lines

Yes, not that I understand the message length (3) has more do to with the I2C interactions (rather than a derisive of 'count'), it makes sense to handle that inside the function.

However, it does seem odd to handle the return value of a *_read() function in this way. They usually return the number of bytes read, which in this case would be DA9063_CHIP_ID_REGS (count), right?

Well regmap_bulk_read and regmap_read return 0 for success and negative for failure so I'd disagree on this part.

#6 lore raw

Re: [RESEND PATCH v2 1/2] mfd: da9063: Fix revision handling to correctly select reg tables

Quoted 9 lines · Adam Thomson
Quoted 7 lines · Lee Jones
Quoted 6 lines
Quoted 3 lines

drivers/mfd/da9063-i2c.c line 41

Quoted 1 line
drivers/mfd/da9063-i2c.c +1 -0
+		return -EINVAL;

Do you want to fail silently here?

Well an error message is printed in the calling code, so didn't feel like it was necessary to have additional debug here. Felt like bloat.

Quoted 7 lines
Quoted 3 lines

As a user, I would prefer a more specific reason.

Thus, I would provide an error message here and omit the generic one.

I can update although I'll of course then need to do similar messages for the other error legs of this function. FWIW, as this is only being called once in the same file this error leg of code currently can never occur.

As a tiny improvement, it's not a deal breaker. If it's too much work, you can either submit a subsequent patch or omit it completely.

Quoted 36 lines
Quoted 36 lines
Quoted 25 lines
Quoted 10 lines

drivers/mfd/da9063-i2c.c

Quoted 9 lines
drivers/mfd/da9063-i2c.c +9 -0
+}
+
+enum {
+	DA9063_DEV_ID_REG = 0,
+	DA9063_VAR_ID_REG,
+	DA9063_CHIP_ID_REGS,
+};
+
+static int da9063_get_device_type(struct i2c_client *i2c, struct da9063

*da9063)

Quoted 5 lines

drivers/mfd/da9063-i2c.c line 84

Quoted 3 lines
drivers/mfd/da9063-i2c.c +3 -0
+{
+	int ret;
+	u8 buf[DA9063_CHIP_ID_REGS];

Really small nit: Could you reverse these please.

Yep, agreed.

Quoted 7 lines

drivers/mfd/da9063-i2c.c line 88

Quoted 4 lines
drivers/mfd/da9063-i2c.c +3 -0
+	ret = da9063_i2c_blockreg_read(i2c, DA9063_REG_DEVICE_ID, buf,
+				       DA9063_CHIP_ID_REGS);
+	if (ret < 0) {

if (ret)

Quoted 6 lines
Quoted 2 lines

Or better yet, as this is a read function, you could just return i2c_transfer() and do the appropriate error checking here *instead*.

I think given that the function handles all of the I2C specific stuff I'd prefer it be kept there. Logically that to me makes more sense. Can change this to 'if (ret)'

Yes, not that I understand the message length (3) has more do to with the I2C interactions (rather than a derisive of 'count'), it makes sense to handle that inside the function.

Quoted 6 lines
Quoted 3 lines

However, it does seem odd to handle the return value of a *_read() function in this way. They usually return the number of bytes read, which in this case would be DA9063_CHIP_ID_REGS (count), right?

Well regmap_bulk_read and regmap_read return 0 for success and negative for failure so I'd disagree on this part.

Fair enough. :)

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#7 lore raw

RE: [RESEND PATCH v2 1/2] mfd: da9063: Fix revision handling to correctly select reg tables

Quoted 10 lines · Lee Jones
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

drivers/mfd/da9063-i2c.c line 41

Quoted 2 lines
drivers/mfd/da9063-i2c.c +1 -0
+		return -EINVAL;

Do you want to fail silently here?

Well an error message is printed in the calling code, so didn't feel like it was necessary to have additional debug here. Felt like bloat.

As a user, I would prefer a more specific reason.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Thus, I would provide an error message here and omit the generic one.

I can update although I'll of course then need to do similar messages for the other error legs of this function. FWIW, as this is only being called once in the same file this error leg of code currently can never occur.

As a tiny improvement, it's not a deal breaker. If it's too much work, you can either submit a subsequent patch or omit it completely.

Taken care of in the v3 patch set I submitted Friday. Hopefully that covers everything. :)