Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1478385
| From | Joe Perches <joe@perches.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v4 1/5] gpio: pca953x: code shrink |
| Date | 2016-09-07 17:10 +0200 |
| Message-ID | <seMEa-1mo-13@gated-at.bofh.it> (permalink) |
| References | <seMkN-109-5@gated-at.bofh.it> <seMuu-13P-59@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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.
>
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v4 0/5] gpio: pca953x: code refactoring Bartosz Golaszewski <bgolaszewski@baylibre.com> - 2016-09-07 16:50 +0200
[PATCH v4 3/5] gpio: pca953x: refactor pca953x_read_regs() Bartosz Golaszewski <bgolaszewski@baylibre.com> - 2016-09-07 17:00 +0200
[PATCH v4 4/5] gpio: pca953x: remove an unused variable Bartosz Golaszewski <bgolaszewski@baylibre.com> - 2016-09-07 17:00 +0200
[PATCH v4 2/5] gpio: pca953x: refactor pca953x_write_regs() Bartosz Golaszewski <bgolaszewski@baylibre.com> - 2016-09-07 17:00 +0200
[PATCH v4 1/5] gpio: pca953x: code shrink Bartosz Golaszewski <bgolaszewski@baylibre.com> - 2016-09-07 17:00 +0200
Re: [PATCH v4 1/5] gpio: pca953x: code shrink Joe Perches <joe@perches.com> - 2016-09-07 17:10 +0200
[PATCH v4 5/5] gpio: pca953x: coding style fixes Bartosz Golaszewski <bgolaszewski@baylibre.com> - 2016-09-07 17:00 +0200
Re: [PATCH v4 5/5] gpio: pca953x: coding style fixes Bartosz Golaszewski <bgolaszewski@baylibre.com> - 2016-09-07 17:20 +0200
Re: [PATCH v4 5/5] gpio: pca953x: coding style fixes Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-09-07 17:20 +0200
csiph-web