There are 3 chip types already in the driver: * PCA953X_TYPE (standard register set, + pcal chips have extended set) * PCAL653X_TYPE (standard + extended register set, different spacing) * PCA957X_TYPE (standard + other registers, different addresses) A later patch in this series adds yet another type. This would take up all 4 bits allocated to chip type information in driver_data, leaving no space for new types in the future. Convert PCA_TYPE defines from bits to numbers. Replace if-else statements with cleaner switch statements. This makes it easier to add new types. Signed-off-by: Levente Révész <levente.revesz@xxxxxxxxxx> --- Changes in v2: This is a new patch. drivers/gpio/gpio-pca953x.c | 43 ++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index ebe1943b85dd..bee81101ba28 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -64,9 +64,9 @@ #define PCA_INT BIT(8) #define PCA_PCAL BIT(9) #define PCA_LATCH_INT (PCA_PCAL | PCA_INT) -#define PCA953X_TYPE BIT(12) -#define PCA957X_TYPE BIT(13) -#define PCAL653X_TYPE BIT(14) +#define PCA953X_TYPE (0x00 << 12) +#define PCAL653X_TYPE (0x02 << 12) +#define PCA957X_TYPE (0x03 << 12) #define PCA_TYPE_MASK GENMASK(15, 12) #define PCA_CHIP_TYPE(x) ((x) & PCA_TYPE_MASK) @@ -349,13 +349,17 @@ static bool pca953x_readable_register(struct device *dev, unsigned int reg) struct pca953x_chip *chip = dev_get_drvdata(dev); u32 bank; - if (PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE) { + switch (PCA_CHIP_TYPE(chip->driver_data)) { + case PCA953X_TYPE: + case PCAL653X_TYPE: + bank = PCA953x_BANK_INPUT | PCA953x_BANK_OUTPUT | + PCA953x_BANK_POLARITY | PCA953x_BANK_CONFIG; + break; + case PCA957X_TYPE: bank = PCA957x_BANK_INPUT | PCA957x_BANK_OUTPUT | PCA957x_BANK_POLARITY | PCA957x_BANK_CONFIG | PCA957x_BANK_BUSHOLD; - } else { - bank = PCA953x_BANK_INPUT | PCA953x_BANK_OUTPUT | - PCA953x_BANK_POLARITY | PCA953x_BANK_CONFIG; + break; } if (chip->driver_data & PCA_PCAL) { @@ -372,12 +376,16 @@ static bool pca953x_writeable_register(struct device *dev, unsigned int reg) struct pca953x_chip *chip = dev_get_drvdata(dev); u32 bank; - if (PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE) { - bank = PCA957x_BANK_OUTPUT | PCA957x_BANK_POLARITY | - PCA957x_BANK_CONFIG | PCA957x_BANK_BUSHOLD; - } else { + switch (PCA_CHIP_TYPE(chip->driver_data)) { + case PCA953X_TYPE: + case PCAL653X_TYPE: bank = PCA953x_BANK_OUTPUT | PCA953x_BANK_POLARITY | - PCA953x_BANK_CONFIG; + PCA953x_BANK_CONFIG; + break; + case PCA957X_TYPE: + bank = PCA957x_BANK_OUTPUT | PCA957x_BANK_POLARITY | + PCA957x_BANK_CONFIG | PCA957x_BANK_BUSHOLD; + break; } if (chip->driver_data & PCA_PCAL) @@ -392,10 +400,15 @@ static bool pca953x_volatile_register(struct device *dev, unsigned int reg) struct pca953x_chip *chip = dev_get_drvdata(dev); u32 bank; - if (PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE) - bank = PCA957x_BANK_INPUT; - else + switch (PCA_CHIP_TYPE(chip->driver_data)) { + case PCA953X_TYPE: + case PCAL653X_TYPE: bank = PCA953x_BANK_INPUT; + break; + case PCA957X_TYPE: + bank = PCA957x_BANK_INPUT; + break; + } if (chip->driver_data & PCA_PCAL) bank |= PCAL9xxx_BANK_IRQ_STAT; -- 2.37.3