Messages in this thread | | | Subject | Re: [PATCH v3 2/3] extcon: sm5502: Refactor driver to use chip-specific struct | From | Chanwoo Choi <> | Date | Thu, 3 Jun 2021 00:13:18 +0900 |
| |
On 21. 6. 2. 오전 5:00, Stephan Gerhold wrote: > Prepare 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. > > Signed-off-by: Stephan Gerhold <stephan@gerhold.net> > --- > 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(-) > > diff --git a/drivers/extcon/extcon-sm5502.c b/drivers/extcon/extcon-sm5502.c > index 9f40bb9f1f81..951f6ca4c479 100644 > --- a/drivers/extcon/extcon-sm5502.c > +++ b/drivers/extcon/extcon-sm5502.c > @@ -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);
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)
-- Best Regards, Samsung Electronics Chanwoo Choi
| |