Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1548482
| From | Linus Walleij <linus.walleij@linaro.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 4/6] bus: add driver for the Technologic Systems NBUS |
| Date | 2016-12-30 09:00 +0100 |
| Message-ID | <sU0gx-1tm-3@gated-at.bofh.it> (permalink) |
| References | <sOr06-6CZ-13@gated-at.bofh.it> <sOr06-6CZ-45@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Thu, Dec 15, 2016 at 12:12 AM, Sebastien Bourdelin
<sebastien.bourdelin@savoirfairelinux.com> wrote:
> This driver implements a GPIOs bit-banged bus, called the NBUS by
> Technologic Systems. It is used to communicate with the peripherals in
> the FPGA on the TS-4600 SoM.
>
> Signed-off-by: Sebastien Bourdelin <sebastien.bourdelin@savoirfairelinux.com>
(...)
> +#include <linux/gpio.h>
Use:
#include <linux/gpio/consumer.h>
instead, and deal with the fallout.
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/of.h>
> +#include <linux/of_gpio.h>
Don't use this.
> +#include <linux/platform_device.h>
> +#include <linux/pwm.h>
> +
> +static DEFINE_MUTEX(ts_nbus_lock);
> +static bool ts_nbus_ready;
Why not move this to the struct ts_nbus state container?
It seems to be per-bus not per-system.
> +#define TS_NBUS_READ_MODE 0
> +#define TS_NBUS_WRITE_MODE 1
> +#define TS_NBUS_DIRECTION_IN 0
> +#define TS_NBUS_DIRECTION_OUT 1
> +#define TS_NBUS_WRITE_ADR 0
> +#define TS_NBUS_WRITE_VAL 1
> +
> +struct ts_nbus {
> + struct pwm_device *pwm;
> + int num_data;
> + int *data;
> + int csn;
> + int txrx;
> + int strobe;
> + int ale;
> + int rdy;
> +};
> +
> +static struct ts_nbus *ts_nbus;
Nopes. No singletons please.
Use the state container pattern:
Documentation/driver-model/design-patterns.txt
> +/*
> + * request all gpios required by the bus.
> + */
> +static int ts_nbus_init(struct platform_device *pdev)
> +{
> + int err;
> + int i;
> +
> + for (i = 0; i < ts_nbus->num_data; i++) {
> + err = devm_gpio_request_one(&pdev->dev, ts_nbus->data[i],
> + GPIOF_OUT_INIT_HIGH,
> + "TS NBUS data");
> + if (err)
> + return err;
> + }
DO not use the legacy GPIO API anywhere.
Reference the device and use gpiod_get() simple, fair and square.
Store struct gpio_desc * pointers in your state container instead.
> +static int ts_nbus_get_of_pdata(struct device *dev, struct device_node *np)
> +{
> + int num_data;
> + int *data;
> + int ret;
> + int i;
> +
> + ret = of_gpio_named_count(np, "data-gpios");
> + if (ret < 0) {
> + dev_err(dev,
> + "failed to count GPIOs in DT property data-gpios\n");
> + return ret;
> + }
Do not reinvent the wheel.
Use devm_gpiod_get_array().
> + ret = of_get_named_gpio(np, "csn-gpios", 0);
And again use devm_gpiod_get(), and gpiod_* accessors.
Applies everywhere.
Yours,
Linus Walleij
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH 0/6] Add board support for TS-4600 Sebastien Bourdelin <sebastien.bourdelin@savoirfairelinux.com> - 2016-12-15 00:20 +0100
[PATCH 3/6] dt-bindings: bus: Add documentation for the Technologic Systems NBUS Sebastien Bourdelin <sebastien.bourdelin@savoirfairelinux.com> - 2016-12-15 00:20 +0100
Re: [PATCH 3/6] dt-bindings: bus: Add documentation for the Technologic Systems NBUS Rob Herring <robh@kernel.org> - 2016-12-19 23:20 +0100
[PATCH 5/6] ARM: dts: TS-4600: add NBUS support Sebastien Bourdelin <sebastien.bourdelin@savoirfairelinux.com> - 2016-12-15 00:20 +0100
Re: [PATCH 5/6] ARM: dts: TS-4600: add NBUS support Linus Walleij <linus.walleij@linaro.org> - 2016-12-30 09:10 +0100
[PATCH 6/6] watchdog: ts4600: add driver for TS-4600 watchdog Sebastien Bourdelin <sebastien.bourdelin@savoirfairelinux.com> - 2016-12-15 00:20 +0100
Re: [PATCH 6/6] watchdog: ts4600: add driver for TS-4600 watchdog Rob Herring <robh@kernel.org> - 2016-12-19 23:20 +0100
Re: [PATCH 6/6] watchdog: ts4600: add driver for TS-4600 watchdog Guenter Roeck <linux@roeck-us.net> - 2016-12-23 03:00 +0100
[PATCH 2/6] ARM: dts: TS-4600: add basic device tree Sebastien Bourdelin <sebastien.bourdelin@savoirfairelinux.com> - 2016-12-15 00:20 +0100
[PATCH 2/6] ARM: dts: TS-4600: add basic device tree Sebastien Bourdelin <sebastien.bourdelin@savoirfairelinux.com> - 2016-12-15 00:20 +0100
[PATCH 1/6] of: documentation: add bindings documentation for TS-4600 Sebastien Bourdelin <sebastien.bourdelin@savoirfairelinux.com> - 2016-12-15 00:20 +0100
Re: [PATCH 1/6] of: documentation: add bindings documentation for TS-4600 Rob Herring <robh@kernel.org> - 2016-12-19 23:10 +0100
[PATCH 4/6] bus: add driver for the Technologic Systems NBUS Sebastien Bourdelin <sebastien.bourdelin@savoirfairelinux.com> - 2016-12-15 00:20 +0100
Re: [PATCH 4/6] bus: add driver for the Technologic Systems NBUS Linus Walleij <linus.walleij@linaro.org> - 2016-12-30 09:00 +0100
csiph-web