extcon: sm5502: Add support for SM5504
Subsystems (2)
v3 cover extcon: sm5502: Add support for SM5504
This patch series adds support for SM5504 to the existing extcon-sm5502 driver. SM5502 and SM5504 are fairly similar so support for SM5504 can be added with a few simple if statements in the code.
I also put a few cleanup patches in front and convert the device tree bindings to DT schema.
I tested this patch series on both SM5502 (Samsung Galaxy A5 2015) and SM5504 (Samsung Galaxy S4 Mini Value Edition) and it seems to work just fine for both.
---
Changes in v3:
- Drop patch 1-4 (already applied)
- Avoid if (type == TYPE_SM5504) everywhere in the code, instead introduce a struct sm5502_type that encodes chip-specific information.
v2: https://lore.kernel.org/lkml/[email protected]/
Changes in v2: Fix compile warning in last patch
v1: https://lore.kernel.org/lkml/[email protected]/
Stephan Gerhold (3):
dt-bindings: extcon: sm5502: Document siliconmitus,sm5504-muic
extcon: sm5502: Refactor driver to use chip-specific struct
extcon: sm5502: Add support for SM5504
.../extcon/siliconmitus,sm5502-muic.yaml | 6 +- drivers/extcon/Kconfig | 2 +- drivers/extcon/extcon-sm5502.c | 196 +++++++++++++++--- drivers/extcon/extcon-sm5502.h | 82 +++++++- 4 files changed, 248 insertions(+), 38 deletions(-)
Signature · 1 line
2.31.1
PATCH v3 1/3 dt-bindings: extcon: sm5502: Document siliconmitus,sm5504-muic
Document support for SM5504 with the new siliconmitus,sm5504-muic compatible.
--- .../bindings/extcon/siliconmitus,sm5502-muic.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/extcon/siliconmitus,sm5502-muic.yaml +4 -2
@@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/extcon/siliconmitus,sm5502-muic.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: SM5502 MUIC (Micro-USB Interface Controller) device +title: SM5502/SM5504 MUIC (Micro-USB Interface Controller) device maintainers: - Chanwoo Choi <[email protected]>
@@ -19,10 +19,12 @@ properties: compatible: enum: - siliconmitus,sm5502-muic + - siliconmitus,sm5504-muic reg: maxItems: 1 - description: I2C slave address of the device. Usually 0x25 for SM5502. + description: I2C slave address of the device. Usually 0x25 for SM5502, + 0x14 for SM5504. interrupts: maxItems: 1
Signature · 1 line
2.31.1
Re: [PATCH v3 1/3] dt-bindings: extcon: sm5502: Document siliconmitus,sm5504-muic
Quoted 8 lines · Stephan Gerhold
Document support for SM5504 with the new siliconmitus,sm5504-muic compatible.
Signed-off-by Stephan Gerhold <[email protected]>--- .../bindings/extcon/siliconmitus,sm5502-muic.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
PATCH v3 2/3 extcon: sm5502: Refactor driver to use chip-specific struct
In reply to Stephan GerholdPrepare for supporting SM5504 in the extcon-sm5502 driver by replacing enum sm5504_types with a struct sm5504_type that stores the chip-specific definitions. This struct can then be defined separately for SM5504 without having to add if (type == TYPE_SM5504) everywhere in the code.
---
Changes in v3: New patch to simplify diff on next patch
--- drivers/extcon/extcon-sm5502.c | 64 +++++++++++++++++++++------------- drivers/extcon/extcon-sm5502.h | 4 --- 2 files changed, 40 insertions(+), 28 deletions(-)
drivers/extcon/extcon-sm5502.c +40 -24
@@ -40,17 +40,13 @@ struct sm5502_muic_info {struct i2c_client *i2c;struct regmap *regmap; +const struct sm5502_type *type;struct regmap_irq_chip_data *irq_data; -struct muic_irq *muic_irqs; -unsigned int num_muic_irqs;int irq;bool irq_attach;bool irq_detach;struct work_struct irq_work; -struct reg_data *reg_data; -unsigned int num_reg_data; -struct mutex mutex;/*
@@ -62,6 +58,17 @@ struct sm5502_muic_info {struct delayed_work wq_detcable; }; +struct sm5502_type { +struct muic_irq *muic_irqs; +unsigned int num_muic_irqs; +const struct regmap_irq_chip *irq_chip; + +struct reg_data *reg_data; +unsigned int num_reg_data; + +int (*parse_irq)(struct sm5502_muic_info *info,int irq_type); +}; +/* Default value of SM5502 register to bring up MUIC device. */ static struct reg_data sm5502_reg_data[] = { {
@@ -502,11 +509,11 @@ static irqreturn_t sm5502_muic_irq_handler(int irq, void *data)struct sm5502_muic_info *info = data;int i, irq_type =-1 , ret; -for (i =0 ; i < info->num_muic_irqs; i++) -if (irq == info->muic_irqs[i].virq) - irq_type = info->muic_irqs[i].irq; +for (i =0 ; i < info->type->num_muic_irqs; i++) +if (irq == info->type->muic_irqs[i].virq) + irq_type = info->type->muic_irqs[i].irq; - ret =sm5502_parse_irq (info, irq_type); + ret = info->type->parse_irq (info, irq_type);if (ret <0 ) {dev_warn (info->dev,"cannot handle is interrupt:%d\n" , irq_type);
@@ -551,14 +558,14 @@ static void sm5502_init_dev_type(struct sm5502_muic_info *info) version_id, vendor_id);/* Initiazle the register of SM5502 device to bring-up */ -for (i =0 ; i < info->num_reg_data; i++) { +for (i =0 ; i < info->type->num_reg_data; i++) {unsigned int val =0 ; -if (!info->reg_data[i].invert) - val |= ~info->reg_data[i].val; +if (!info->type->reg_data[i].invert) + val |= ~info->type->reg_data[i].val;else - val = info->reg_data[i].val; -regmap_write (info->regmap, info->reg_data[i].reg, val); + val = info->type->reg_data[i].val; +regmap_write (info->regmap, info->type->reg_data[i].reg, val); } }
@@ -579,10 +586,9 @@ static int sm5022_muic_i2c_probe(struct i2c_client *i2c) info->dev = &i2c->dev; info->i2c = i2c; info->irq = i2c->irq; - info->muic_irqs = sm5502_muic_irqs; - info->num_muic_irqs =ARRAY_SIZE (sm5502_muic_irqs); - info->reg_data = sm5502_reg_data; - info->num_reg_data =ARRAY_SIZE (sm5502_reg_data); + info->type =device_get_match_data (info->dev); +if (!info->type) +return -EINVAL ;mutex_init (&info->mutex);
@@ -598,16 +604,17 @@ static int sm5022_muic_i2c_probe(struct i2c_client *i2c)/* Support irq domain for SM5502 MUIC device */ irq_flags =IRQF_TRIGGER_FALLING |IRQF_ONESHOT |IRQF_SHARED ; - ret =devm_regmap_add_irq_chip (info->dev, info->regmap, info->irq, irq_flags, -0 , &sm5502_muic_irq_chip, &info->irq_data); + ret =devm_regmap_add_irq_chip (info->dev, info->regmap, info->irq, + irq_flags,0 , info->type->irq_chip, + &info->irq_data);if (ret !=0 ) {dev_err (info->dev,"failed to request IRQ %d: %d\n" , info->irq, ret);return ret; } -for (i =0 ; i < info->num_muic_irqs; i++) { -struct muic_irq *muic_irq = &info->muic_irqs[i]; +for (i =0 ; i < info->type->num_muic_irqs; i++) { +struct muic_irq *muic_irq = &info->type->muic_irqs[i];int virq =0 ; virq =regmap_irq_get_virq (info->irq_data, muic_irq->irq);
@@ -659,8 +666,17 @@ static int sm5022_muic_i2c_probe(struct i2c_client *i2c)return 0 ; } +static const struct sm5502_type sm5502_data = { + .muic_irqs = sm5502_muic_irqs, + .num_muic_irqs =ARRAY_SIZE (sm5502_muic_irqs), + .irq_chip = &sm5502_muic_irq_chip, + .reg_data = sm5502_reg_data, + .num_reg_data =ARRAY_SIZE (sm5502_reg_data), + .parse_irq = sm5502_parse_irq, +}; +static const struct of_device_id sm5502_dt_match[] = { - { .compatible ="siliconmitus,sm5502-muic" }, + { .compatible ="siliconmitus,sm5502-muic" , .data = &sm5502_data }, { }, };MODULE_DEVICE_TABLE (of, sm5502_dt_match);
@@ -691,7 +707,7 @@ static SIMPLE_DEV_PM_OPS(sm5502_muic_pm_ops, sm5502_muic_suspend, sm5502_muic_resume);static const struct i2c_device_id sm5502_i2c_id[] = { - {"sm5502" ,TYPE_SM5502 }, + {"sm5502" , (kernel_ulong_t)&sm5502_data }, { } };MODULE_DEVICE_TABLE (i2c, sm5502_i2c_id);
drivers/extcon/extcon-sm5502.h +0 -4
@@ -8,10 +8,6 @@#ifndef __LINUX_EXTCON_SM5502_H#define __LINUX_EXTCON_SM5502_H -enum sm5502_types { -TYPE_SM5502 , -}; -/* SM5502 registers */ enum sm5502_reg { SM5502_REG_DEVICE_ID = 0x01,
Signature · 1 line
2.31.1
Re: [PATCH v3 2/3] extcon: sm5502: Refactor driver to use chip-specific struct
Quoted 57 lines · Stephan Gerhold
Prepare for supporting SM5504 in the extcon-sm5502 driver by replacing enum
sm5504_typeswith a structsm5504_typethat stores the chip-specific definitions. This struct can then be defined separately for SM5504 without having to add if (type ==TYPE_SM5504) everywhere in the code.Signed-off-by Stephan Gerhold <[email protected]>---
Changes in v3: New patch to simplify diff on next patch--- drivers/extcon/extcon-sm5502.c | 64 +++++++++++++++++++++------------- drivers/extcon/extcon-sm5502.h | 4 --- 2 files changed, 40 insertions(+), 28 deletions(-)drivers/extcon/extcon-sm5502.c +12
-5@@ -40,17 +40,13 @@ struct sm5502_muic_info {struct i2c_client *i2c;struct regmap *regmap; +const struct sm5502_type *type;struct regmap_irq_chip_data *irq_data; -struct muic_irq *muic_irqs; -unsigned int num_muic_irqs;int irq;bool irq_attach;bool irq_detach;struct work_struct irq_work; -struct reg_data *reg_data; -unsigned int num_reg_data; -struct mutex mutex;/* @@ -62,6 +58,17 @@ struct sm5502_muic_info {struct delayed_work wq_detcable; }; +struct sm5502_type { +struct muic_irq *muic_irqs; +unsigned int num_muic_irqs; +const struct regmap_irq_chip *irq_chip; + +struct reg_data *reg_data; +unsigned int num_reg_data; + +int (*parse_irq)(struct sm5502_muic_info *info,int irq_type); +}; +/* Default value of SM5502 register to bring up MUIC device. */ static struct reg_data sm5502_reg_data[] = { {@@ -502,11 +509,11 @@ static irqreturn_t sm5502_muic_irq_handler(int irq, void *data)struct sm5502_muic_info *info = data;int i, irq_type =-1 , ret;
drivers/extcon/extcon-sm5502.c static irqreturn_t sm5502_muic_irq_handler(int irq, void *data) · line 516
Quoted 10 lines
drivers/extcon/extcon-sm5502.c +4
-4-for (i =0 ; i < info->num_muic_irqs; i++) -if (irq == info->muic_irqs[i].virq) - irq_type = info->muic_irqs[i].irq; +for (i =0 ; i < info->type->num_muic_irqs; i++) +if (irq == info->type->muic_irqs[i].virq) + irq_type = info->type->muic_irqs[i].irq; - ret =sm5502_parse_irq (info, irq_type); + ret = info->type->parse_irq (info, irq_type);
Looks good to me. But there is only one comment.
Need to check the 'parse_irq' as following:
If you agree this suggestion, I'll apply with following changes by myself:
if (!info->type->parse_irq) {
dev_err(info->dev, "failed to handle irq due to parse_irq\n",
return IRQ_NONE;
}(snip)
Signature · 3 lines
Best Regards, Samsung Electronics Chanwoo Choi
Re: [PATCH v3 2/3] extcon: sm5502: Refactor driver to use chip-specific struct
Quoted 66 lines · Chanwoo Choi
Quoted 51 lines · Stephan Gerhold
Prepare for supporting SM5504 in the extcon-sm5502 driver by replacing enum
sm5504_typeswith a structsm5504_typethat stores the chip-specific definitions. This struct can then be defined separately for SM5504 without having to add if (type ==TYPE_SM5504) everywhere in the code.Signed-off-by Stephan Gerhold <[email protected]>---
Changes in v3: New patch to simplify diff on next patch--- drivers/extcon/extcon-sm5502.c | 64 +++++++++++++++++++++------------- drivers/extcon/extcon-sm5502.h | 4 --- 2 files changed, 40 insertions(+), 28 deletions(-)drivers/extcon/extcon-sm5502.c +12
-5@@ -40,17 +40,13 @@ struct sm5502_muic_info {struct i2c_client *i2c;struct regmap *regmap; +const struct sm5502_type *type;struct regmap_irq_chip_data *irq_data; -struct muic_irq *muic_irqs; -unsigned int num_muic_irqs;int irq;bool irq_attach;bool irq_detach;struct work_struct irq_work; -struct reg_data *reg_data; -unsigned int num_reg_data; -struct mutex mutex;/* @@ -62,6 +58,17 @@ struct sm5502_muic_info {struct delayed_work wq_detcable; }; +struct sm5502_type { +struct muic_irq *muic_irqs; +unsigned int num_muic_irqs; +const struct regmap_irq_chip *irq_chip; + +struct reg_data *reg_data; +unsigned int num_reg_data; + +int (*parse_irq)(struct sm5502_muic_info *info,int irq_type); +}; +/* Default value of SM5502 register to bring up MUIC device. */ static struct reg_data sm5502_reg_data[] = { {drivers/extcon/extcon-sm5502.c static irqreturn_t sm5502_muic_irq_handler(int irq, void *data) · line 514
Quoted 10 lines
drivers/extcon/extcon-sm5502.c +4
-4@@ -502,11 +509,11 @@ static irqreturn_t sm5502_muic_irq_handler(int irq, void *data)struct sm5502_muic_info *info = data;int i, irq_type =-1 , ret; -for (i =0 ; i < info->num_muic_irqs; i++) -if (irq == info->muic_irqs[i].virq) - irq_type = info->muic_irqs[i].irq; +for (i =0 ; i < info->type->num_muic_irqs; i++) +if (irq == info->type->muic_irqs[i].virq) + irq_type = info->type->muic_irqs[i].irq; - ret =sm5502_parse_irq (info, irq_type); + ret = info->type->parse_irq (info, irq_type);Looks good to me. But there is only one comment.
Need to check the 'parse_irq' as following:
Quoted 8 lines
If you agree this suggestion, I'll apply with following changes by myself:
if (!info->type->parse_irq) { dev_err(info->dev, "failed to handle irq due to parse_irq\n", return IRQ_NONE; }
This condition should be impossible, since .parse_irq is set for both SM5502 and SM5504:
static const struct sm5502_type sm5502_data = {
/* ... */
.parse_irq = sm5502_parse_irq,
};static const struct sm5502_type sm5504_data = {
/* ... */
.parse_irq = sm5504_parse_irq,
};Which failure case are you trying to handle with that if statement?
Thanks!
Stephan
Re: [PATCH v3 2/3] extcon: sm5502: Refactor driver to use chip-specific struct
Quoted 84 lines · Stephan Gerhold
Quoted 66 lines · Chanwoo Choi
Quoted 51 lines · Stephan Gerhold
Prepare for supporting SM5504 in the extcon-sm5502 driver by replacing enum
sm5504_typeswith a structsm5504_typethat stores the chip-specific definitions. This struct can then be defined separately for SM5504 without having to add if (type ==TYPE_SM5504) everywhere in the code.Signed-off-by Stephan Gerhold <[email protected]>---
Changes in v3: New patch to simplify diff on next patch--- drivers/extcon/extcon-sm5502.c | 64 +++++++++++++++++++++------------- drivers/extcon/extcon-sm5502.h | 4 --- 2 files changed, 40 insertions(+), 28 deletions(-)drivers/extcon/extcon-sm5502.c +12
-5@@ -40,17 +40,13 @@ struct sm5502_muic_info {struct i2c_client *i2c;struct regmap *regmap; +const struct sm5502_type *type;struct regmap_irq_chip_data *irq_data; -struct muic_irq *muic_irqs; -unsigned int num_muic_irqs;int irq;bool irq_attach;bool irq_detach;struct work_struct irq_work; -struct reg_data *reg_data; -unsigned int num_reg_data; -struct mutex mutex;/* @@ -62,6 +58,17 @@ struct sm5502_muic_info {struct delayed_work wq_detcable; }; +struct sm5502_type { +struct muic_irq *muic_irqs; +unsigned int num_muic_irqs; +const struct regmap_irq_chip *irq_chip; + +struct reg_data *reg_data; +unsigned int num_reg_data; + +int (*parse_irq)(struct sm5502_muic_info *info,int irq_type); +}; +/* Default value of SM5502 register to bring up MUIC device. */ static struct reg_data sm5502_reg_data[] = { {drivers/extcon/extcon-sm5502.c static irqreturn_t sm5502_muic_irq_handler(int irq, void *data) · line 514
Quoted 10 lines
drivers/extcon/extcon-sm5502.c +4
-4@@ -502,11 +509,11 @@ static irqreturn_t sm5502_muic_irq_handler(int irq, void *data)struct sm5502_muic_info *info = data;int i, irq_type =-1 , ret; -for (i =0 ; i < info->num_muic_irqs; i++) -if (irq == info->muic_irqs[i].virq) - irq_type = info->muic_irqs[i].irq; +for (i =0 ; i < info->type->num_muic_irqs; i++) +if (irq == info->type->muic_irqs[i].virq) + irq_type = info->type->muic_irqs[i].irq; - ret =sm5502_parse_irq (info, irq_type); + ret = info->type->parse_irq (info, irq_type);Looks good to me. But there is only one comment.
Need to check the 'parse_irq' as following:Quoted 8 lines
If you agree this suggestion, I'll apply with following changes by myself:
if (!info->type->parse_irq) { dev_err(info->dev, "failed to handle irq due to parse_irq\n", return IRQ_NONE; }This condition should be impossible, since .parse_irq is set for both SM5502 and SM5504:
static const struct sm5502_type sm5502_data = { /* ... */ .parse_irq = sm5502_parse_irq, };
Quoted 6 lines
static const struct sm5502_type sm5504_data = { /* ... */ .parse_irq = sm5504_parse_irq, };Which failure case are you trying to handle with that if statement?
There is not failure case of this patchset. But, this refactoring suggestion has the potential problem without checking whether mandatory function pointer is NULL or not. When adding new chip by using this driver, the author might have the human error without parse_irq initialization even if the mandatory.
Quoted 4 lines
Thanks!
Stephan
Signature · 3 lines
Best Regards, Samsung Electronics Chanwoo Choi
Re: [PATCH v3 2/3] extcon: sm5502: Refactor driver to use chip-specific struct
Quoted 87 lines · Chanwoo Choi
Quoted 86 lines · Stephan Gerhold
Quoted 68 lines · Chanwoo Choi
Quoted 53 lines · Stephan Gerhold
Prepare for supporting SM5504 in the extcon-sm5502 driver by replacing enum
sm5504_typeswith a structsm5504_typethat stores the chip-specific definitions. This struct can then be defined separately for SM5504 without having to add if (type ==TYPE_SM5504) everywhere in the code.Signed-off-by Stephan Gerhold <[email protected]>---
Changes in v3: New patch to simplify diff on next patch
---
drivers/extcon/extcon-sm5502.c| 64
+++++++++++++++++++++-------------
drivers/extcon/extcon-sm5502.h| 4 ---2 files changed, 40 insertions(+), 28 deletions(-)drivers/extcon/extcon-sm5502.c +12
-5@@ -40,17 +40,13 @@ struct sm5502_muic_info { struct i2c_client *i2c; struct regmap *regmap; + const struct sm5502_type *type; struct regmap_irq_chip_data *irq_data; - struct muic_irq *muic_irqs; - unsigned int num_muic_irqs; int irq; bool irq_attach; bool irq_detach; struct work_struct irq_work; - struct reg_data *reg_data; - unsigned int num_reg_data; - struct mutex mutex; /*@@ -62,6 +58,17 @@ struct sm5502_muic_info { struct delayed_work wq_detcable; }; +struct sm5502_type { + struct muic_irq *muic_irqs; + unsigned int num_muic_irqs; + const struct regmap_irq_chip *irq_chip; + + struct reg_data *reg_data; + unsigned int num_reg_data; + + int (*parse_irq)(struct sm5502_muic_info *info, int irq_type); +}; + /* Default value of SM5502 register to bring up MUIC device. */ static struct reg_data sm5502_reg_data[] = { {@@ -502,11 +509,11 @@ static irqreturn_t sm5502_muic_irq_handler(int irq, void *data)drivers/extcon/extcon-sm5502.c static irqreturn_t sm5502_muic_irq_handler(int · line 515
Quoted 10 lines
drivers/extcon/extcon-sm5502.c +4
-4struct sm5502_muic_info *info = data; int i, irq_type = -1, ret; - for (i = 0; i < info->num_muic_irqs; i++) - if (irq == info->muic_irqs[i].virq) - irq_type = info->muic_irqs[i].irq; + for (i = 0; i < info->type->num_muic_irqs; i++) + if (irq == info->type->muic_irqs[i].virq) + irq_type = info->type->muic_irqs[i].irq; - ret = sm5502_parse_irq(info, irq_type); + ret = info->type->parse_irq(info, irq_type);Looks good to me. But there is only one comment.
Need to check the 'parse_irq' as following:Quoted 8 lines
If you agree this suggestion, I'll apply with following changes by myself:
if (!info->type->parse_irq) {
dev_err(info->dev, "failed to handle irq due to parse_irq\n", returnIRQ_NONE;
}This condition should be impossible, since .parse_irq is set for both SM5502 and SM5504:
static const struct
sm5502_typesm5502_data= {
/* ... */
.parse_irq =sm5502_parse_irq,
};
Quoted 9 lines
Quoted 6 lines
static const struct
sm5502_typesm5504_data= {
/* ... */
.parse_irq =sm5504_parse_irq,
};Which failure case are you trying to handle with that if statement?
There is not failure case of this patchset. But, this refactoring suggestion has the potential problem without checking whether mandatory function pointer is NULL or not. When adding new chip by using this driver, the author might have the human error without
parse_irqinitialization even if the mandatory.
Instead, it is better to check whether parser_irq is NULL or not on probe function in order to reduce the unnecessary repetitive checking.
Quoted 6 lines
Quoted 4 lines
Thanks!
Stephan
Signature · 3 lines
Best Regards, Samsung Electronics Chanwoo Choi
Re: [PATCH v3 2/3] extcon: sm5502: Refactor driver to use chip-specific struct
Quoted 105 lines · Chanwoo Choi
Quoted 95 lines · Chanwoo Choi
Quoted 94 lines · Stephan Gerhold
Quoted 70 lines · Chanwoo Choi
Quoted 55 lines · Stephan Gerhold
Prepare for supporting SM5504 in the extcon-sm5502 driver by replacing enum
sm5504_typeswith a structsm5504_typethat stores the chip-specific
definitions. This struct can then be defined separately for SM5504 without having to add if (type ==TYPE_SM5504) everywhere in the code.Signed-off-by Stephan Gerhold <[email protected]>---
Changes in v3: New patch to simplify diff on next patch
---
drivers/extcon/extcon-sm5502.c| 64
+++++++++++++++++++++-------------
drivers/extcon/extcon-sm5502.h| 4 ---2 files changed, 40 insertions(+), 28 deletions(-)drivers/extcon/extcon-sm5502.c +12
-5@@ -40,17 +40,13 @@ struct sm5502_muic_info { struct i2c_client *i2c; struct regmap *regmap; + const struct sm5502_type *type; struct regmap_irq_chip_data *irq_data; - struct muic_irq *muic_irqs; - unsigned int num_muic_irqs; int irq; bool irq_attach; bool irq_detach; struct work_struct irq_work; - struct reg_data *reg_data; - unsigned int num_reg_data; - struct mutex mutex; /*@@ -62,6 +58,17 @@ struct sm5502_muic_info { struct delayed_work wq_detcable; }; +struct sm5502_type { + struct muic_irq *muic_irqs; + unsigned int num_muic_irqs; + const struct regmap_irq_chip *irq_chip; + + struct reg_data *reg_data; + unsigned int num_reg_data; + + int (*parse_irq)(struct sm5502_muic_info *info, int irq_type); +}; + /* Default value of SM5502 register to bring up MUIC device. */ static struct reg_data sm5502_reg_data[] = { {@@ -502,11 +509,11 @@ static irqreturn_t sm5502_muic_irq_handler(int irq, void *data)drivers/extcon/extcon-sm5502.c static irqreturn_t · line 515
Quoted 10 lines
drivers/extcon/extcon-sm5502.c +4
-4struct sm5502_muic_info *info = data; int i, irq_type = -1, ret; - for (i = 0; i < info->num_muic_irqs; i++) - if (irq == info->muic_irqs[i].virq) - irq_type = info->muic_irqs[i].irq; + for (i = 0; i < info->type->num_muic_irqs; i++) + if (irq == info->type->muic_irqs[i].virq) + irq_type = info->type->muic_irqs[i].irq; - ret = sm5502_parse_irq(info, irq_type); + ret = info->type->parse_irq(info, irq_type);Looks good to me. But there is only one comment.
Need to check the 'parse_irq' as following:Quoted 9 lines
If you agree this suggestion, I'll apply with following changes by myself:
if (!info->type->parse_irq) {
dev_err(info->dev, "failed to handle irq due to parse_irq\n", returnIRQ_NONE;
}This condition should be impossible, since .parse_irq is set for both SM5502 and SM5504:
static const struct
sm5502_typesm5502_data= {
/* ... */
.parse_irq =sm5502_parse_irq,
};static const struct
sm5502_typesm5504_data= {
/* ... */
.parse_irq =sm5504_parse_irq,
};Quoted 8 lines
Quoted 1 line
Which failure case are you trying to handle with that if statement?
There is not failure case of this patchset. But, this refactoring suggestion has the potential problem without checking whether mandatory function pointer is NULL or not. When adding new chip by using this driver, the author might have the human error without
parse_irqinitialization even if the mandatory.
Quoted 3 lines
Instead, it is better to check whether
parser_irqis NULL or not on probe function in order to reduce the unnecessary repetitive checking.
Thanks for the explanation. This suggestion sounds better to me. (Although I consider it unlikely that someone would forget to define
.parse_irq when adding a new chip...)
Feel free to add something like the below when applying. Or let me know if I should re-send with this change:
drivers/extcon/extcon-sm5502.c +4 -0
@@ -694,6 +694,10 @@ static int sm5022_muic_i2c_probe(struct i2c_client *i2c) info->type =device_get_match_data (info->dev);if (!info->type)return -EINVAL ; +if (!info->type->parse_irq) { +dev_err (info->dev,"parse_irq missing in struct sm5502_type\n" ); +return -EINVAL ; + }mutex_init (&info->mutex);
Thanks for your review!
Stephan
Chanwoo Choi
maintainerRe: [PATCH v3 2/3] extcon: sm5502: Refactor driver to use chip-specific struct
Quoted 110 lines · Stephan Gerhold
Quoted 105 lines · Chanwoo Choi
Quoted 95 lines · Chanwoo Choi
Quoted 94 lines · Stephan Gerhold
Quoted 70 lines · Chanwoo Choi
Quoted 55 lines · Stephan Gerhold
Prepare for supporting SM5504 in the extcon-sm5502 driver by replacing enum
sm5504_typeswith a structsm5504_typethat stores the chip-specific
definitions. This struct can then be defined separately for SM5504 without having to add if (type ==TYPE_SM5504) everywhere in the code.Signed-off-by Stephan Gerhold <[email protected]>---
Changes in v3: New patch to simplify diff on next patch
---
drivers/extcon/extcon-sm5502.c| 64
+++++++++++++++++++++-------------
drivers/extcon/extcon-sm5502.h| 4 ---2 files changed, 40 insertions(+), 28 deletions(-)drivers/extcon/extcon-sm5502.c +12
-5@@ -40,17 +40,13 @@ struct sm5502_muic_info { struct i2c_client *i2c; struct regmap *regmap; + const struct sm5502_type *type; struct regmap_irq_chip_data *irq_data; - struct muic_irq *muic_irqs; - unsigned int num_muic_irqs; int irq; bool irq_attach; bool irq_detach; struct work_struct irq_work; - struct reg_data *reg_data; - unsigned int num_reg_data; - struct mutex mutex; /*@@ -62,6 +58,17 @@ struct sm5502_muic_info { struct delayed_work wq_detcable; }; +struct sm5502_type { + struct muic_irq *muic_irqs; + unsigned int num_muic_irqs; + const struct regmap_irq_chip *irq_chip; + + struct reg_data *reg_data; + unsigned int num_reg_data; + + int (*parse_irq)(struct sm5502_muic_info *info, int irq_type); +}; + /* Default value of SM5502 register to bring up MUIC device. */ static struct reg_data sm5502_reg_data[] = { {@@ -502,11 +509,11 @@ static irqreturn_t sm5502_muic_irq_handler(int irq, void *data)drivers/extcon/extcon-sm5502.c static irqreturn_t · line 515
Quoted 10 lines
drivers/extcon/extcon-sm5502.c +4
-4struct sm5502_muic_info *info = data; int i, irq_type = -1, ret; - for (i = 0; i < info->num_muic_irqs; i++) - if (irq == info->muic_irqs[i].virq) - irq_type = info->muic_irqs[i].irq; + for (i = 0; i < info->type->num_muic_irqs; i++) + if (irq == info->type->muic_irqs[i].virq) + irq_type = info->type->muic_irqs[i].irq; - ret = sm5502_parse_irq(info, irq_type); + ret = info->type->parse_irq(info, irq_type);Looks good to me. But there is only one comment.
Need to check the 'parse_irq' as following:Quoted 9 lines
If you agree this suggestion, I'll apply with following changes by myself:
if (!info->type->parse_irq) {
dev_err(info->dev, "failed to handle irq due to parse_irq\n", returnIRQ_NONE;
}This condition should be impossible, since .parse_irq is set for both SM5502 and SM5504:
static const struct
sm5502_typesm5502_data= {
/* ... */
.parse_irq =sm5502_parse_irq,
};static const struct
sm5502_typesm5504_data= {
/* ... */
.parse_irq =sm5504_parse_irq,
};Quoted 8 lines
Quoted 1 line
Which failure case are you trying to handle with that if statement?
There is not failure case of this patchset. But, this refactoring suggestion has the potential problem without checking whether mandatory function pointer is NULL or not. When adding new chip by using this driver, the author might have the human error without
parse_irqinitialization even if the mandatory.Quoted 3 lines
Instead, it is better to check whether
parser_irqis NULL or not on probe function in order to reduce the unnecessary repetitive checking.
Quoted 6 lines
Thanks for the explanation. This suggestion sounds better to me. (Although I consider it unlikely that someone would forget to define
.parse_irq when adding a new chip...)Feel free to add something like the below when applying. Or let me know if I should re-send with this change:
Please resend them. Thanks.
Quoted 21 lines
drivers/extcon/extcon-sm5502.c +4
-0@@ -694,6 +694,10 @@ static int sm5022_muic_i2c_probe(struct i2c_client *i2c) info->type =device_get_match_data (info->dev);if (!info->type)return -EINVAL ; +if (!info->type->parse_irq) { +dev_err (info->dev,"parse_irq missing in struct sm5502_type\n" ); +return -EINVAL ; + }mutex_init (&info->mutex);Thanks for your review!
Stephan
Signature · 3 lines
Best Regards, Chanwoo Choi Samsung Electronics
PATCH v3 3/3 extcon: sm5502: Add support for SM5504
In reply to Stephan GerholdSM5504 is another MUIC from Silicon Mitus that is fairly similar to SM5502. They seem to use the same register set, but:
- SM5504 has some additional bits in SM5502_REG_CONTROL
- SM5504 has a quite different set of interrupts
- SM5504 reports USB OTG as dev_type1 = BIT(0) instead of BIT(7)
Overall it's minor and we can support this by defining a separate struct sm5502_type for SM5504.
---
Changes in v3: Avoid if statements, use struct sm5502_type indirection
Changes in v2: Fix warning: cast to smaller integer type 'enum sm5502_types'
from 'const void *' [-Wvoid-pointer-to-enum-cast] reported by kernel test robot
v2: https://lore.kernel.org/lkml/[email protected]/
Interestingly enough the register set (and especially the interrupts) also look *very* similar to Richtek RT8973A (extcon-rt8973a) but I didn't investigate this further.
Note that the changes in this patch are mostly based on guesswork based on a SM5504 driver from Nitin Chaudhary [1] used in some Samsung vendor kernels, since I was not able to find a public datasheet for SM5504.
[1]: https://github.com/NitinChaudharyUSC/MSM8x16_8x26/blob/master/drivers/misc/sm5504.c
--- drivers/extcon/Kconfig | 2 +- drivers/extcon/extcon-sm5502.c | 132 +++++++++++++++++++++++++++++++-- drivers/extcon/extcon-sm5502.h | 78 +++++++++++++++++++ 3 files changed, 204 insertions(+), 8 deletions(-)
drivers/extcon/Kconfig +1 -1
@@ -154,7 +154,7 @@ config EXTCON_RT8973A from abnormal high input voltage (up to 28V). config EXTCON_SM5502 - tristate "Silicon Mitus SM5502 EXTCON support" + tristate "Silicon Mitus SM5502/SM5504 EXTCON support" depends on I2C select IRQ_DOMAIN select REGMAP_I2C
drivers/extcon/extcon-sm5502.c +125 -7
192 lines not on this page · raw message
drivers/extcon/extcon-sm5502.h +78 -0
100 lines not on this page · raw message
Signature · 1 line
2.31.1