gpio: sprd: Modification of UNISOC Platform EIC Driver
Subsystems (2)
v4 cover gpio: sprd: Modification of UNISOC Platform EIC Driver
Recently, some bugs have been discovered during use, and patch1 are bug fixes. Also, this patchset add optimization:
patch2 optimization the calculation method of eic number.
Change in V4:
-Add Fixes tag in PATCH 1/2.
-Change commit message in PATCH 1/2.
-Add clearing interrupt to debounce and latch mode in PATCH 1/2.
-Change commit message in PATCH 2/2.
-Delete SPRD_EIC_VAR_DATA macro in PATCH 2/2.
Wenhua Lin (2):
gpio: eic-sprd: Clear interrupt after set the interrupt type
gpio: eic-sprd: Optimize the calculation method of eic number
drivers/gpio/gpio-eic-sprd.c | 42 +++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
PATCH v4 1/2 gpio: eic-sprd: Clear interrupt after set the interrupt type
The raw interrupt status of eic maybe set before the interrupt is enabled, since the eic interrupt has a latch function, which would trigger the interrupt event once enabled it from user side. To solve this problem, interrupts generated before setting the interrupt trigger type are ignored.
--- drivers/gpio/gpio-eic-sprd.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-)
drivers/gpio/gpio-eic-sprd.c +28 -4
@@ -330,20 +330,27 @@ static int sprd_eic_irq_set_type(struct irq_data *data, unsigned int flow_type)switch (flow_type) {case IRQ_TYPE_LEVEL_HIGH :sprd_eic_update (chip, offset,SPRD_EIC_DBNC_IEV ,1 ); +sprd_eic_update (chip, offset,SPRD_EIC_DBNC_IC ,1 );break ;case IRQ_TYPE_LEVEL_LOW :sprd_eic_update (chip, offset,SPRD_EIC_DBNC_IEV ,0 ); +sprd_eic_update (chip, offset,SPRD_EIC_DBNC_IC ,1 );break ;case IRQ_TYPE_EDGE_RISING :case IRQ_TYPE_EDGE_FALLING :case IRQ_TYPE_EDGE_BOTH : state =sprd_eic_get (chip, offset); -if (state) +if (state) {sprd_eic_update (chip, offset,SPRD_EIC_DBNC_IEV ,0 ); -else +sprd_eic_update (chip, offset, +SPRD_EIC_DBNC_IC ,1 ); + }else {sprd_eic_update (chip, offset,SPRD_EIC_DBNC_IEV ,1 ); +sprd_eic_update (chip, offset, +SPRD_EIC_DBNC_IC ,1 ); + }break ;default :return -ENOTSUPP ;
@@ -355,20 +362,27 @@ static int sprd_eic_irq_set_type(struct irq_data *data, unsigned int flow_type)switch (flow_type) {case IRQ_TYPE_LEVEL_HIGH :sprd_eic_update (chip, offset,SPRD_EIC_LATCH_INTPOL ,0 ); +sprd_eic_update (chip, offset,SPRD_EIC_LATCH_INTCLR ,1 );break ;case IRQ_TYPE_LEVEL_LOW :sprd_eic_update (chip, offset,SPRD_EIC_LATCH_INTPOL ,1 ); +sprd_eic_update (chip, offset,SPRD_EIC_LATCH_INTCLR ,1 );break ;case IRQ_TYPE_EDGE_RISING :case IRQ_TYPE_EDGE_FALLING :case IRQ_TYPE_EDGE_BOTH : state =sprd_eic_get (chip, offset); -if (state) +if (state) {sprd_eic_update (chip, offset,SPRD_EIC_LATCH_INTPOL ,0 ); -else +sprd_eic_update (chip, offset, +SPRD_EIC_LATCH_INTCLR ,1 ); + }else {sprd_eic_update (chip, offset,SPRD_EIC_LATCH_INTPOL ,1 ); +sprd_eic_update (chip, offset, +SPRD_EIC_LATCH_INTCLR ,1 ); + }break ;default :return -ENOTSUPP ;
@@ -382,29 +396,34 @@ static int sprd_eic_irq_set_type(struct irq_data *data, unsigned int flow_type)sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTBOTH ,0 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTMODE ,0 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTPOL ,1 ); +sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_edge_irq);break ;case IRQ_TYPE_EDGE_FALLING :sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTBOTH ,0 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTMODE ,0 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTPOL ,0 ); +sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_edge_irq);break ;case IRQ_TYPE_EDGE_BOTH :sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTMODE ,0 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTBOTH ,1 ); +sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_edge_irq);break ;case IRQ_TYPE_LEVEL_HIGH :sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTBOTH ,0 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTMODE ,1 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTPOL ,1 ); +sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_level_irq);break ;case IRQ_TYPE_LEVEL_LOW :sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTBOTH ,0 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTMODE ,1 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTPOL ,0 ); +sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_level_irq);break ;default :
@@ -417,29 +436,34 @@ static int sprd_eic_irq_set_type(struct irq_data *data, unsigned int flow_type)sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTBOTH ,0 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTMODE ,0 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTPOL ,1 ); +sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_edge_irq);break ;case IRQ_TYPE_EDGE_FALLING :sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTBOTH ,0 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTMODE ,0 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTPOL ,0 ); +sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_edge_irq);break ;case IRQ_TYPE_EDGE_BOTH :sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTMODE ,0 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTBOTH ,1 ); +sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_edge_irq);break ;case IRQ_TYPE_LEVEL_HIGH :sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTBOTH ,0 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTMODE ,1 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTPOL ,1 ); +sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_level_irq);break ;case IRQ_TYPE_LEVEL_LOW :sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTBOTH ,0 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTMODE ,1 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTPOL ,0 ); +sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_level_irq);break ;default :
Signature · 1 line
2.17.1
Re: [PATCH V4 1/2] gpio: eic-sprd: Clear interrupt after set the interrupt type
Quoted 8 lines · Wenhua Lin
The raw interrupt status of eic maybe set before the interrupt is enabled, since the eic interrupt has a latch function, which would trigger the interrupt event once enabled it from user side. To solve this problem, interrupts generated before setting the interrupt trigger type are ignored.
Fixes 25518e024e3a ("gpio: Add Spreadtrum EIC driver support")Signed-off-by Wenhua Lin <[email protected]>
Quoted 141 lines
--- drivers/gpio/gpio-eic-sprd.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-)drivers/gpio/gpio-eic-sprd.c +28
-5@@ -330,20 +330,27 @@ static int sprd_eic_irq_set_type(struct irq_data *data, unsigned int flow_type)switch (flow_type) {case IRQ_TYPE_LEVEL_HIGH :sprd_eic_update (chip, offset,SPRD_EIC_DBNC_IEV ,1 ); +sprd_eic_update (chip, offset,SPRD_EIC_DBNC_IC ,1 );break ;case IRQ_TYPE_LEVEL_LOW :sprd_eic_update (chip, offset,SPRD_EIC_DBNC_IEV ,0 ); +sprd_eic_update (chip, offset,SPRD_EIC_DBNC_IC ,1 );break ;case IRQ_TYPE_EDGE_RISING :case IRQ_TYPE_EDGE_FALLING :case IRQ_TYPE_EDGE_BOTH : state =sprd_eic_get (chip, offset); -if (state) +if (state) {sprd_eic_update (chip, offset,SPRD_EIC_DBNC_IEV ,0 ); -else +sprd_eic_update (chip, offset, +SPRD_EIC_DBNC_IC ,1 ); + }else {sprd_eic_update (chip, offset,SPRD_EIC_DBNC_IEV ,1 ); +sprd_eic_update (chip, offset, +SPRD_EIC_DBNC_IC ,1 ); + }break ;default :return -ENOTSUPP ;@@ -355,20 +362,27 @@ static int sprd_eic_irq_set_type(struct irq_data *data, unsigned int flow_type)switch (flow_type) {case IRQ_TYPE_LEVEL_HIGH :sprd_eic_update (chip, offset,SPRD_EIC_LATCH_INTPOL ,0 ); +sprd_eic_update (chip, offset,SPRD_EIC_LATCH_INTCLR ,1 );break ;case IRQ_TYPE_LEVEL_LOW :sprd_eic_update (chip, offset,SPRD_EIC_LATCH_INTPOL ,1 ); +sprd_eic_update (chip, offset,SPRD_EIC_LATCH_INTCLR ,1 );break ;case IRQ_TYPE_EDGE_RISING :case IRQ_TYPE_EDGE_FALLING :case IRQ_TYPE_EDGE_BOTH : state =sprd_eic_get (chip, offset); -if (state) +if (state) {sprd_eic_update (chip, offset,SPRD_EIC_LATCH_INTPOL ,0 ); -else +sprd_eic_update (chip, offset, +SPRD_EIC_LATCH_INTCLR ,1 ); + }else {sprd_eic_update (chip, offset,SPRD_EIC_LATCH_INTPOL ,1 ); +sprd_eic_update (chip, offset, +SPRD_EIC_LATCH_INTCLR ,1 ); + }break ;default :return -ENOTSUPP ;@@ -382,29 +396,34 @@ static int sprd_eic_irq_set_type(struct irq_data *data, unsigned int flow_type)sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTBOTH ,0 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTMODE ,0 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTPOL ,1 ); +sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_edge_irq);break ;case IRQ_TYPE_EDGE_FALLING :sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTBOTH ,0 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTMODE ,0 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTPOL ,0 ); +sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_edge_irq);break ;case IRQ_TYPE_EDGE_BOTH :sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTMODE ,0 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTBOTH ,1 ); +sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_edge_irq);break ;case IRQ_TYPE_LEVEL_HIGH :sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTBOTH ,0 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTMODE ,1 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTPOL ,1 ); +sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_level_irq);break ;case IRQ_TYPE_LEVEL_LOW :sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTBOTH ,0 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTMODE ,1 );sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTPOL ,0 ); +sprd_eic_update (chip, offset,SPRD_EIC_ASYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_level_irq);break ;default :@@ -417,29 +436,34 @@ static int sprd_eic_irq_set_type(struct irq_data *data, unsigned int flow_type)sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTBOTH ,0 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTMODE ,0 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTPOL ,1 ); +sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_edge_irq);break ;case IRQ_TYPE_EDGE_FALLING :sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTBOTH ,0 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTMODE ,0 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTPOL ,0 ); +sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_edge_irq);break ;case IRQ_TYPE_EDGE_BOTH :sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTMODE ,0 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTBOTH ,1 ); +sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_edge_irq);break ;case IRQ_TYPE_LEVEL_HIGH :sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTBOTH ,0 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTMODE ,1 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTPOL ,1 ); +sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_level_irq);break ;case IRQ_TYPE_LEVEL_LOW :sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTBOTH ,0 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTMODE ,1 );sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTPOL ,0 ); +sprd_eic_update (chip, offset,SPRD_EIC_SYNC_INTCLR ,1 );irq_set_handler_locked (data, handle_level_irq);break ;default : --2.17.1
PATCH v4 2/2 gpio: eic-sprd: Optimize the calculation method of eic number
In reply to Wenhua LinThe num_eics is a default value, but some SoCs support more than 8. In order to adapt to all projects, the total number of eics is automatically calculated through dts.
--- drivers/gpio/gpio-eic-sprd.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpio/gpio-eic-sprd.c +4 -6
@@ -108,7 +108,6 @@ static struct sprd_eic *to_sprd_eic(struct notifier_block *nb)struct sprd_eic_variant_data {enum sprd_eic_type type; -u32 num_eics; };static const char *sprd_eic_label_name[SPRD_EIC_MAX ] = {
@@ -118,22 +117,18 @@ static const char *sprd_eic_label_name[SPRD_EIC_MAX] = {static const struct sprd_eic_variant_data sc9860_eic_dbnc_data = { .type =SPRD_EIC_DEBOUNCE , - .num_eics =8 , };static const struct sprd_eic_variant_data sc9860_eic_latch_data = { .type =SPRD_EIC_LATCH , - .num_eics =8 , };static const struct sprd_eic_variant_data sc9860_eic_async_data = { .type =SPRD_EIC_ASYNC , - .num_eics =8 , };static const struct sprd_eic_variant_data sc9860_eic_sync_data = { .type =SPRD_EIC_SYNC , - .num_eics =8 , }; static inline void __iomem *sprd_eic_offset_base(struct sprd_eic *sprd_eic,
@@ -619,6 +614,7 @@ static int sprd_eic_probe(struct platform_device *pdev)struct gpio_irq_chip *irq;struct sprd_eic *sprd_eic;struct resource *res; +u16 num_banks =0 ;int ret, i; pdata =of_device_get_match_data (dev);
@@ -652,10 +648,12 @@ static int sprd_eic_probe(struct platform_device *pdev) sprd_eic->base[i] =devm_ioremap_resource (dev, res);if (IS_ERR (sprd_eic->base[i]))return PTR_ERR (sprd_eic->base[i]); + + num_banks++; } sprd_eic->chip.label = sprd_eic_label_name[sprd_eic->type]; - sprd_eic->chip.ngpio = pdata->num_eics; + sprd_eic->chip.ngpio = num_banks *SPRD_EIC_PER_BANK_NR ; sprd_eic->chip.base =-1 ; sprd_eic->chip.parent = dev; sprd_eic->chip.direction_input = sprd_eic_direction_input;
Signature · 1 line
2.17.1
Re: [PATCH V4 2/2] gpio: eic-sprd: Optimize the calculation method of eic number
Quoted 6 lines · Wenhua Lin
The
num_eicsis a default value, but some SoCs support more than 8. In order to adapt to all projects, the total number of eics is automatically calculated through dts.Signed-off-by Wenhua Lin <[email protected]>
Thanks,
Chunyan
Quoted 64 lines
--- drivers/gpio/gpio-eic-sprd.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/gpio/gpio-eic-sprd.c +4
-7@@ -108,7 +108,6 @@ static struct sprd_eic *to_sprd_eic(struct notifier_block *nb)struct sprd_eic_variant_data {enum sprd_eic_type type; -u32 num_eics; };static const char *sprd_eic_label_name[SPRD_EIC_MAX ] = {@@ -118,22 +117,18 @@ static const char *sprd_eic_label_name[SPRD_EIC_MAX] = {static const struct sprd_eic_variant_data sc9860_eic_dbnc_data = { .type =SPRD_EIC_DEBOUNCE , - .num_eics =8 , };static const struct sprd_eic_variant_data sc9860_eic_latch_data = { .type =SPRD_EIC_LATCH , - .num_eics =8 , };static const struct sprd_eic_variant_data sc9860_eic_async_data = { .type =SPRD_EIC_ASYNC , - .num_eics =8 , };static const struct sprd_eic_variant_data sc9860_eic_sync_data = { .type =SPRD_EIC_SYNC , - .num_eics =8 , }; static inline void __iomem *sprd_eic_offset_base(struct sprd_eic *sprd_eic,@@ -619,6 +614,7 @@ static int sprd_eic_probe(struct platform_device *pdev)struct gpio_irq_chip *irq;struct sprd_eic *sprd_eic;struct resource *res; +u16 num_banks =0 ;int ret, i; pdata =of_device_get_match_data (dev);@@ -652,10 +648,12 @@ static int sprd_eic_probe(struct platform_device *pdev) sprd_eic->base[i] =devm_ioremap_resource (dev, res);if (IS_ERR (sprd_eic->base[i]))return PTR_ERR (sprd_eic->base[i]); + + num_banks++; } sprd_eic->chip.label = sprd_eic_label_name[sprd_eic->type]; - sprd_eic->chip.ngpio = pdata->num_eics; + sprd_eic->chip.ngpio = num_banks *SPRD_EIC_PER_BANK_NR ; sprd_eic->chip.base =-1 ; sprd_eic->chip.parent = dev; sprd_eic->chip.direction_input = sprd_eic_direction_input; --2.17.1
Quoted 18 lines · Wenhua Lin
Recently, some bugs have been discovered during use, and patch1 are bug fixes. Also, this patchset add optimization:
patch2 optimization the calculation method of eic number.Change in V4:
(quoted diff) +0
-5-Add Fixes tag in PATCH 1/2. -Change commit message in PATCH 1/2. -Add clearing interrupt to debounce and latch mode in PATCH 1/2. -Change commit message in PATCH 2/2. -Delete SPRD_EIC_VAR_DATA macro in PATCH 2/2.Wenhua Lin (2):
gpio: eic-sprd: Clear interrupt after set the interrupt type
gpio: eic-sprd: Optimize the calculation method of eic number
Quoted 7 lines
drivers/gpio/gpio-eic-sprd.c | 42 +++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-)--
2.17.1
Hey,
Can we get an Ack and (preferably) a Tested-by from the SPRD maintainers, please?
Bart
Quoted 18 lines · Wenhua Lin
Recently, some bugs have been discovered during use, and patch1 are bug fixes. Also, this patchset add optimization:
patch2 optimization the calculation method of eic number.Change in V4:
(quoted diff) +0
-5-Add Fixes tag in PATCH 1/2. -Change commit message in PATCH 1/2. -Add clearing interrupt to debounce and latch mode in PATCH 1/2. -Change commit message in PATCH 2/2. -Delete SPRD_EIC_VAR_DATA macro in PATCH 2/2.Wenhua Lin (2):
gpio: eic-sprd: Clear interrupt after set the interrupt type
gpio: eic-sprd: Optimize the calculation method of eic number
Quoted 7 lines
drivers/gpio/gpio-eic-sprd.c | 42 +++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-)--
2.17.1
Applied with Acks from Chunyan.
Bartosz