gpio: dwapb: clarify usage of the register file version
Subsystems (2)
PATCH 1/1 gpio: dwapb: clarify usage of the register file version
First of all, it's obvious that different versions can't be provided simultaneously. Hence, versions can't be bit masks.
Second, due to above we have to mask out the version field in the flags and only that can be evaluated against the certain version.
Clarify all above by:
- introducing GPIO_REG_OFFSET_V1 and GPIO_REG_OFFSET_MASK
- replacing conditional to mask out bits and compare to a version
Luckily there is no functional change (at least intended), so no need to backport this.
--- drivers/gpio/gpio-dwapb.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpio/gpio-dwapb.c +6 -4
@@ -53,7 +53,9 @@#define GPIO_SWPORT_DR_STRIDE 0x0c/* register stride 3*32 bits */ #define GPIO_SWPORT_DDR_STRIDE 0x0c/* register stride 3*32 bits */ +#define GPIO_REG_OFFSET_V1 0#define GPIO_REG_OFFSET_V2 1 +#define GPIO_REG_OFFSET_MASK BIT(0)#define GPIO_INTMASK_V2 0x44#define GPIO_INTTYPE_LEVEL_V2 0x34
@@ -141,7 +143,7 @@ static inline u32 gpio_reg_v2_convert(unsigned int offset)static inline u32 gpio_reg_convert (struct dwapb_gpio *gpio,unsigned int offset) { -if (gpio->flags &GPIO_REG_OFFSET_V2 ) +if ((gpio->flags &GPIO_REG_OFFSET_MASK ) ==GPIO_REG_OFFSET_V2 )return gpio_reg_v2_convert (offset);return offset;
@@ -668,15 +670,15 @@ static int dwapb_get_clks(struct dwapb_gpio *gpio) }static const struct of_device_id dwapb_of_match[] = { - { .compatible ="snps,dw-apb-gpio" , .data = (void *)0 }, + { .compatible ="snps,dw-apb-gpio" , .data = (void *)GPIO_REG_OFFSET_V1 }, { .compatible ="apm,xgene-gpio-v2" , .data = (void *)GPIO_REG_OFFSET_V2 }, {/* Sentinel */ } };MODULE_DEVICE_TABLE (of, dwapb_of_match);static const struct acpi_device_id dwapb_acpi_match[] = { - {"HISI0181" ,0 }, - {"APMC0D07" ,0 }, + {"HISI0181" ,GPIO_REG_OFFSET_V1 }, + {"APMC0D07" ,GPIO_REG_OFFSET_V1 }, {"APMC0D81" ,GPIO_REG_OFFSET_V2 }, { } };
Signature · 1 line
2.33.0
Quoted 62 lines · Andy Shevchenko
First of all, it's obvious that different versions can't be provided simultaneously. Hence, versions can't be bit masks.
Second, due to above we have to mask out the version field in the flags and only that can be evaluated against the certain version.
Clarify all above by:
- introducingGPIO_REG_OFFSET_V1andGPIO_REG_OFFSET_MASK
- replacing conditional to mask out bits and compare to a versionLuckily there is no functional change (at least intended), so no need to backport this.
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/gpio/gpio-dwapb.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/gpio/gpio-dwapb.c +6
-5@@ -53,7 +53,9 @@#define GPIO_SWPORT_DR_STRIDE 0x0c/* register stride 3*32 bits */ #define GPIO_SWPORT_DDR_STRIDE 0x0c/* register stride 3*32 bits */ +#define GPIO_REG_OFFSET_V1 0#define GPIO_REG_OFFSET_V2 1 +#define GPIO_REG_OFFSET_MASK BIT(0)#define GPIO_INTMASK_V2 0x44#define GPIO_INTTYPE_LEVEL_V2 0x34@@ -141,7 +143,7 @@ static inline u32 gpio_reg_v2_convert(unsigned int offset)static inline u32 gpio_reg_convert (struct dwapb_gpio *gpio,unsigned int offset) { -if (gpio->flags &GPIO_REG_OFFSET_V2 ) +if ((gpio->flags &GPIO_REG_OFFSET_MASK ) ==GPIO_REG_OFFSET_V2 )return gpio_reg_v2_convert (offset);return offset;@@ -668,15 +670,15 @@ static int dwapb_get_clks(struct dwapb_gpio *gpio) }static const struct of_device_id dwapb_of_match[] = { - { .compatible ="snps,dw-apb-gpio" , .data = (void *)0 }, + { .compatible ="snps,dw-apb-gpio" , .data = (void *)GPIO_REG_OFFSET_V1 }, { .compatible ="apm,xgene-gpio-v2" , .data = (void *)GPIO_REG_OFFSET_V2 }, {/* Sentinel */ } };MODULE_DEVICE_TABLE (of, dwapb_of_match);static const struct acpi_device_id dwapb_acpi_match[] = { - {"HISI0181" ,0 }, - {"APMC0D07" ,0 }, + {"HISI0181" ,GPIO_REG_OFFSET_V1 }, + {"APMC0D07" ,GPIO_REG_OFFSET_V1 }, {"APMC0D81" ,GPIO_REG_OFFSET_V2 }, { } }; --
Quoted 2 lines
2.33.0
Please send it with your PR.
Bart
Quoted 4 lines · Bartosz Golaszewski
On Tue, Nov 30, 2021 at 5:50 PM Andy Shevchenko
<[email protected]> wrote:Reviewed-by Bartosz Golaszewski <[email protected]>
Thanks!
Quoted 1 line
Please send it with your PR.
Will do.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
First of all, it's obvious that different versions can't be provided simultaneously. Hence, versions can't be bit masks.
Second, due to above we have to mask out the version field in the flags and only that can be evaluated against the certain version.
Quoted 6 lines
Clarify all above by:
- introducingGPIO_REG_OFFSET_V1andGPIO_REG_OFFSET_MASK
- replacing conditional to mask out bits and compare to a versionLuckily there is no functional change (at least intended), so no need to backport this.
Seems reasonable. Thanks.
-Sergey
Quoted 51 lines
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/gpio/gpio-dwapb.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/gpio/gpio-dwapb.c +6
-4@@ -53,7 +53,9 @@#define GPIO_SWPORT_DR_STRIDE 0x0c/* register stride 3*32 bits */ #define GPIO_SWPORT_DDR_STRIDE 0x0c/* register stride 3*32 bits */ +#define GPIO_REG_OFFSET_V1 0#define GPIO_REG_OFFSET_V2 1 +#define GPIO_REG_OFFSET_MASK BIT(0)#define GPIO_INTMASK_V2 0x44#define GPIO_INTTYPE_LEVEL_V2 0x34@@ -141,7 +143,7 @@ static inline u32 gpio_reg_v2_convert(unsigned int offset)static inline u32 gpio_reg_convert (struct dwapb_gpio *gpio,unsigned int offset) { -if (gpio->flags &GPIO_REG_OFFSET_V2 ) +if ((gpio->flags &GPIO_REG_OFFSET_MASK ) ==GPIO_REG_OFFSET_V2 )return gpio_reg_v2_convert (offset);return offset;@@ -668,15 +670,15 @@ static int dwapb_get_clks(struct dwapb_gpio *gpio) }static const struct of_device_id dwapb_of_match[] = { - { .compatible ="snps,dw-apb-gpio" , .data = (void *)0 }, + { .compatible ="snps,dw-apb-gpio" , .data = (void *)GPIO_REG_OFFSET_V1 }, { .compatible ="apm,xgene-gpio-v2" , .data = (void *)GPIO_REG_OFFSET_V2 }, {/* Sentinel */ } };MODULE_DEVICE_TABLE (of, dwapb_of_match);static const struct acpi_device_id dwapb_acpi_match[] = { - {"HISI0181" ,0 }, - {"APMC0D07" ,0 }, + {"HISI0181" ,GPIO_REG_OFFSET_V1 }, + {"APMC0D07" ,GPIO_REG_OFFSET_V1 }, {"APMC0D81" ,GPIO_REG_OFFSET_V2 }, { } };Signature · 1 line
2.33.0
Quoted 11 lines · Serge Semin
Quoted 10 lines · Andy Shevchenko
First of all, it's obvious that different versions can't be provided simultaneously. Hence, versions can't be bit masks.
Second, due to above we have to mask out the version field in the flags and only that can be evaluated against the certain version.
Clarify all above by:
- introducingGPIO_REG_OFFSET_V1andGPIO_REG_OFFSET_MASK
- replacing conditional to mask out bits and compare to a version
Quoted 5 lines
Quoted 2 lines
Luckily there is no functional change (at least intended), so no need to backport this.
Seems reasonable. Thanks.
Acked-by Serge Semin <[email protected]>
Pushed to my review and testing queue, thanks!
Signature · 2 lines
With Best Regards, Andy Shevchenko