From: Linus Walleij <linus.walleij@linaro.org>
To: Danilo Krummrich <danilokrummrich@dk-develop.de>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Linux Input <linux-input@vger.kernel.org>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>
Subject: Re: [PATCH] serio: PS2 gpio bit banging driver for the serio bus
Date: Mon, 7 Aug 2017 11:03:53 +0200 [thread overview]
Message-ID: <CACRpkdYz_+soss4Rb9zMiP4eZZtXqjW_Xy7hH=wm1x2m_R9R3A@mail.gmail.com> (raw)
In-Reply-To: <20170731222452.22887-1-danilokrummrich@dk-develop.de>
On Tue, Aug 1, 2017 at 12:24 AM, Danilo Krummrich
<danilokrummrich@dk-develop.de> wrote:
> This driver provides PS2 serio bus support by implementing bit banging
> with the GPIO API. The GPIO pins, data and clock, can be configured with
> a node in the device tree or by static platform data.
>
> Writing to a device is supported as well, though it is not recommended as
> the timings to be halt given by libps2 are very tough and difficult to
> reach with bit banging. Therefore it can be configured (also in DT and
> pdata) whether the serio write function should be available for clients.
>
> This driver is for development purposes and not for productive use.
> However, this driver can be useful e.g. when no USB port is available or
> using old peripherals is desired as PS2 controllers getting rare.
>
> This driver was tested on a RPI1 and on Hikey960 and it worked well
> together with the atkbd driver.
>
> Signed-off-by: Danilo Krummrich <danilokrummrich@dk-develop.de>
> +++ b/Documentation/devicetree/bindings/serio/ps2-gpio.txt
When you add DT bindings you have to CC devicetree@vger.kernel.org
> @@ -0,0 +1,20 @@
> +Device-Tree bindings for ps2 gpio driver
> +
> +Required properties:
> + - compatible = "ps2-gpio";
> + - gpios: data and clock gpio
> +
> +Optional properties:
> + - ps2-gpio,write-enable: Indicates whether write function is provided
> + to serio device. Most probably providing the write fn will not work,
> + because of the tough timing libps2 requires.
> +
> +Example nodes:
> +
> +ps2@0 {
> + compatible = "ps2-gpio";
> + gpios = <&gpio 24 0 /* data */
> + &gpio 23 0 /* clock */
> + >;
> + i2c-gpio,write-enable = <0>;
> +};
These look fine to me though.
> diff --git a/Documentation/gpio/drivers-on-gpio.txt b/Documentation/gpio/drivers-on-gpio.txt
Thanks for patching this!
> +config SERIO_GPIO_PS2
> + tristate "GPIO PS/2 bit banging driver"
> + help
> + Say Y here if you want PS/2 bit banging support via GPIO.
> +
> + To compile this driver as a module, choose M here: the
> + module will be called gpio-ps2.
> +
> + If you are unsure, say N.
As mentioned
depends on GPIOLIB
depends on OF
> +#include <linux/gpio.h>
Use only:
#include <linux/gpio/consumer.h>
> +#include <linux/of_gpio.h>
Should not be needed.
> +struct ps2_gpio_data {
> + struct device *dev;
> + struct serio *serio;
> + unsigned char mode;
> + unsigned int gpio_clk;
> + unsigned int gpio_data;
> + unsigned int write_enable;
Do not use the global GPIO number space, use GPIO descriptors.
Example:
drivers/input/keyboard/gpio_keys.c
> +static int ps2_gpio_write(struct serio *serio, unsigned char val)
> +{
> + struct ps2_gpio_data *drvdata = serio->port_data;
> +
> + drvdata->mode = PS2_MODE_TX;
> + drvdata->tx_byte = val;
> + /* Make sure ISR running on other CPU notice changes. */
> + barrier();
This seems overengineered, is this really needed?
If we have races like this, the error is likely elsewhere, and should be
fixed in the GPIO driver MMIO access or so.
> + disable_irq_nosync(drvdata->irq);
> + gpio_direction_output(drvdata->gpio_clk, 0);
No use GPIO descriptors please.
> + // dev_info(drvdata->dev, "recv bit %u: %u\n", cnt, data);
Delete comments or convert to dev_dbg()
> +static int of_ps2_gpio_get_props(struct device *dev,
> + struct ps2_gpio_data *drvdata)
> +{
> + if (of_gpio_count(dev->of_node) < 2)
> + return -ENODEV;
> +
> + drvdata->gpio_data = of_get_gpio(dev->of_node, 0);
> + drvdata->gpio_clk = of_get_gpio(dev->of_node, 1);
> +
> + if (drvdata->gpio_data == -EPROBE_DEFER ||
> + drvdata->gpio_clk == -EPROBE_DEFER)
> + return -EPROBE_DEFER;
> +
> + if (!gpio_is_valid(drvdata->gpio_data) ||
> + !gpio_is_valid(drvdata->gpio_clk)) {
> + dev_err(dev, "invalid GPIOs, data=%d, clk=%d\n",
> + drvdata->gpio_data, drvdata->gpio_clk);
> + return -ENODEV;
> + }
With GPIO descriptors you should just gpiod_get(dev, "foo", FLAG);
No need to poke around in the device tree like this.
Error checks and deferrals apply as usual though.
> + error = devm_gpio_request(dev, drvdata->gpio_clk, "ps2 clk");
> + if (error) {
> + dev_err(dev, "failed to request gpio %u: %d",
> + drvdata->gpio_clk, error);
> + goto err_free_serio;
> + }
> +
> + error = devm_gpio_request(dev, drvdata->gpio_data, "ps2 data");
> + if (error) {
> + dev_err(dev, "failed to request gpio %u: %d",
> + drvdata->gpio_data, error);
> + goto err_free_serio;
> + }
So devm_gpiod_get(...)
> + gpio_direction_input(drvdata->gpio_clk);
> + gpio_direction_input(drvdata->gpio_data);
And incidentallt then you can just specify GPIOD_IN as flag and
it will be set up for you.
Yours,
Linus Walleij
next prev parent reply other threads:[~2017-08-07 9:03 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-31 22:24 [PATCH] serio: PS2 gpio bit banging driver for the serio bus Danilo Krummrich
2017-08-07 9:03 ` Linus Walleij [this message]
2017-08-07 16:21 ` Danilo Krummrich
2017-08-08 2:49 ` Dmitry Torokhov
[not found] ` <20170807182207.348762301bf3d7f8509b1bf7@dk-develop.de>
2017-08-10 14:38 ` Danilo Krummrich
2017-08-11 9:16 ` Linus Walleij
2017-08-11 11:05 ` Danilo Krummrich
2017-08-17 9:09 ` Russell King - ARM Linux
2017-08-17 10:51 ` Danilo Krummrich
2017-08-17 13:01 ` Russell King - ARM Linux
2017-08-17 14:14 ` Danilo Krummrich
2017-08-22 13:35 ` Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CACRpkdYz_+soss4Rb9zMiP4eZZtXqjW_Xy7hH=wm1x2m_R9R3A@mail.gmail.com' \
--to=linus.walleij@linaro.org \
--cc=danilokrummrich@dk-develop.de \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).