Re: [PATCH v4 1/5] gpio: pca953x: code shrink

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2016-09-07 at 16:49 +0200, Bartosz Golaszewski wrote:
> There are multiple places in the driver code where a
> switch (chip->chip_type) is used to determine the proper register
> offset.
> 
> Unduplicate the code by adding a simple structure holding the possible
> offsets that differ between the pca953x and pca957x chip families and
> use it to avoid the checks.
[]
> diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
[]
> @@ -94,6 +94,24 @@ MODULE_DEVICE_TABLE(acpi, pca953x_acpi_ids);
>  
>  #define NBANK(chip) DIV_ROUND_UP(chip->gpio_chip.ngpio, BANK_SZ)
>  
> +struct pca953x_offset {
> > +	int direction;
> > +	int output;
> > +	int input;
> +};

The struct name seems suboptimal.
Maybe pca95xx_reg_io_config or some such.

> +static const struct pca953x_offset pca953x_offsets = {
> > +	.direction = PCA953X_DIRECTION,
> > +	.output = PCA953X_OUTPUT,
> > +	.input = PCA953X_INPUT,
> +};
> +
> +static const struct pca953x_offset pca957x_offsets = {
> > +	.direction = PCA957X_CFG,
> > +	.output = PCA957X_OUT,
> > +	.input = PCA957X_IN,
> +};

The more naming consistency for #defines would be nice too
at some point.

> 

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux