From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Rob Herring <robh@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Marcel Holtmann <marcel@holtmann.org>,
Jiri Slaby <jslaby@suse.com>, Sebastian Reichel <sre@kernel.org>,
Arnd Bergmann <arnd@arndb.de>,
"Dr . H . Nikolaus Schaller" <hns@goldelico.com>,
Peter Hurley <peter@hurleysoftware.com>,
Alan Cox <gnomes@lxorguk.ukuu.org.uk>
Cc: Loic Poulain <loic.poulain@intel.com>,
Pavel Machek <pavel@ucw.cz>, NeilBrown <neil@brown.name>,
Linus Walleij <linus.walleij@linaro.org>,
linux-bluetooth@vger.kernel.org, linux-serial@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 7/9] serdev: Introduce new bus for serial attached devices
Date: Sat, 07 Jan 2017 16:02:51 +0200 [thread overview]
Message-ID: <1483797771.26691.1.camel@linux.intel.com> (raw)
In-Reply-To: <20170106162635.19677-8-robh@kernel.org>
On Fri, 2017-01-06 at 10:26 -0600, Rob Herring wrote:
> The serdev bus is designed for devices such as Bluetooth, WiFi, GPS
> and NFC connected to UARTs on host processors. Tradionally these have
> been handled with tty line disciplines, rfkill, and userspace glue
> such
> as hciattach. This approach has many drawbacks since it doesn't fit
> into the Linux driver model. Handling of sideband signals, power
> control
> and firmware loading are the main issues.
>
> This creates a serdev bus with controllers (i.e. host serial ports)
> and
> attached devices. Typically, these are point to point connections, but
> some devices have muxing protocols or a h/w mux is conceivable. Any
> muxing is not yet supported with the serdev bus.
> --- /dev/null
> +++ b/drivers/tty/serdev/core.c
> @@ -0,0 +1,388 @@
>
> +
> +#include <linux/kernel.h>
> +#include <linux/errno.h>
> +#include <linux/idr.h>
> +#include <linux/slab.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/serdev.h>
Alphabetical order?
> +
> +static bool is_registered;
> +static DEFINE_IDA(ctrl_ida);
> +
> +static void serdev_device_release(struct device *dev)
> +{
> + struct serdev_device *serdev = to_serdev_device(dev);
> + kfree(serdev);
> +}
> +
> +static const struct device_type serdev_device_type = {
> + .release = serdev_device_release,
> +};
> +
> +static void serdev_ctrl_release(struct device *dev)
> +{
> + struct serdev_controller *ctrl = to_serdev_controller(dev);
> + ida_simple_remove(&ctrl_ida, ctrl->nr);
> + kfree(ctrl);
> +}
> +
> +static const struct device_type serdev_ctrl_type = {
> + .release = serdev_ctrl_release,
> +};
> +
> +static int serdev_device_match(struct device *dev, struct
> device_driver *drv)
> +{
> + return of_driver_match_device(dev, drv);
> +}
> +
>
> +int serdev_device_open(struct serdev_device *serdev)
> +{
> + struct serdev_controller *ctrl = serdev->ctrl;
> +
> + if (!ctrl || !ctrl->ops->open)
> + return 0;
> +
> + return serdev->ctrl->ops->open(ctrl);
Perhaps just ctrl->...();
> +}
> +EXPORT_SYMBOL_GPL(serdev_device_open);
> +
> +void serdev_device_close(struct serdev_device *serdev)
> +{
> + struct serdev_controller *ctrl = serdev->ctrl;
> +
> + if (ctrl && ctrl->ops->close)
Perhaps same pattern
if (!ctrl || !ctrl->ops->close)
return;
> + serdev->ctrl->ops->close(ctrl);
Just ctrl->... ?
> +}
> +EXPORT_SYMBOL_GPL(serdev_device_close);
> +
> +int serdev_device_write_buf(struct serdev_device *serdev,
> + const unsigned char *buf, size_t count)
> +{
> + struct serdev_controller *ctrl = serdev->ctrl;
> +
> + if (!ctrl || !ctrl->ops->write_buf)
> + return 0;
> +
> + return serdev->ctrl->ops->write_buf(ctrl, buf, count);
Just ctrl->... ?
> +}
> +EXPORT_SYMBOL_GPL(serdev_device_write_buf);
> +
> +void serdev_device_write_flush(struct serdev_device *serdev)
> +{
> + struct serdev_controller *ctrl = serdev->ctrl;
> +
> + if (ctrl && ctrl->ops->write_flush)
> + serdev->ctrl->ops->write_flush(ctrl);
Both comments.
> +}
> +EXPORT_SYMBOL_GPL(serdev_device_write_flush);
> +
> +int serdev_device_write_room(struct serdev_device *serdev)
> +{
> + struct serdev_controller *ctrl = serdev->ctrl;
> +
> + if (ctrl && ctrl->ops->write_room)
> + return serdev->ctrl->ops->write_room(ctrl);
> +
Ditto.
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(serdev_device_write_room);
> +
> +unsigned int serdev_device_set_baudrate(struct serdev_device *serdev,
> unsigned int speed)
> +{
> + struct serdev_controller *ctrl = serdev->ctrl;
> +
> + if (!ctrl || !ctrl->ops->set_baudrate)
> + return 0;
> +
> + return serdev->ctrl->ops->set_baudrate(ctrl, speed);
ctrl->...
> +
> +}
> +EXPORT_SYMBOL_GPL(serdev_device_set_baudrate);
> +
> +void serdev_device_set_flow_control(struct serdev_device *serdev,
> bool enable)
> +{
> + struct serdev_controller *ctrl = serdev->ctrl;
> +
> + if (ctrl && ctrl->ops->set_flow_control)
> + serdev->ctrl->ops->set_flow_control(ctrl, enable);
Both comments.
> +}
> +EXPORT_SYMBOL_GPL(serdev_device_set_flow_control);
> +
> +static int of_serdev_register_devices(struct serdev_controller *ctrl)
> +{
> + struct device_node *node;
> + struct serdev_device *serdev = NULL;
> + int err;
> + bool found = false;
> +
> + for_each_available_child_of_node(ctrl->dev.of_node, node) {
> + if (!of_get_property(node, "compatible", NULL))
> + continue;
> +
> + dev_dbg(&ctrl->dev, "adding child %s\n", node-
> >full_name);
> +
> + serdev = serdev_device_alloc(ctrl);
> + if (!serdev)
> + continue;
> +
> + serdev->dev.of_node = node;
> +
> + err = serdev_device_add(serdev);
> + if (err) {
> + dev_err(&serdev->dev,
> + "failure adding device. status %d\n",
> err);
> + serdev_device_put(serdev);
> + }
>
> + found = true;
Perhaps
} else if (!found)
found = true;
Otherwise if we end up with all devices not being added, called will not
know about it.
> + }
> + if (!found)
> + return -ENODEV;
> +
> + return 0;
> +}
>
+/**
> + * serdev_controller_remove(): remove an serdev controller
> + * @ctrl: controller to remove
> + *
> + * Remove a serdev controller. Caller is responsible for calling
> + * serdev_controller_put() to discard the allocated controller.
> + */
> +void serdev_controller_remove(struct serdev_controller *ctrl)
> +{
> + int dummy;
> +
>
> + if (!ctrl)
> + return;
By the way, should we take care or caller? What is the best practice
here?
> +#include <linux/types.h>
> +#include <linux/device.h>
>
> +static inline void serdev_controller_write_wakeup(struct
> serdev_controller *ctrl)
> +{
> + if (ctrl->serdev && ctrl->serdev->ops->write_wakeup)
> + ctrl->serdev->ops->write_wakeup(ctrl->serdev);
Same comment about pattern.
> +}
> +
> +static inline int serdev_controller_receive_buf(struct
> serdev_controller *ctrl,
> + const unsigned char
> *data,
> + size_t count)
> +{
> + if (ctrl->serdev && ctrl->serdev->ops->receive_buf)
> + return ctrl->serdev->ops->receive_buf(ctrl->serdev,
> data, count);
Ditto.
> +
> + return 0;
> +}
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
next prev parent reply other threads:[~2017-01-07 14:02 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-06 16:26 [PATCH 0/9] Serial slave device bus Rob Herring
[not found] ` <20170106162635.19677-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2017-01-06 16:26 ` [PATCH 1/9] tty: move the non-file related parts of tty_release to new tty_release_struct Rob Herring
2017-01-08 22:42 ` Sebastian Reichel
2017-01-06 16:26 ` [PATCH 2/9] tty_port: allow a port to be opened with a tty that has no file handle Rob Herring
2017-01-13 16:46 ` Rob Herring
2017-01-06 16:26 ` [PATCH 3/9] tty_port: make tty_port_register_device wrap tty_port_register_device_attr Rob Herring
2017-01-06 16:26 ` [PATCH 4/9] tty: constify tty_ldisc_receive_buf buffer pointer Rob Herring
2017-01-06 16:26 ` [PATCH 6/9] dt/bindings: Add a serial/UART attached device binding Rob Herring
2017-01-06 19:21 ` Arnd Bergmann
2017-01-06 20:41 ` Rob Herring
[not found] ` <20170106162635.19677-7-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2017-01-10 19:50 ` One Thousand Gnomes
2017-01-10 21:41 ` Pavel Machek
2017-01-06 16:26 ` [PATCH 8/9] serdev: add a tty port controller driver Rob Herring
[not found] ` <20170106162635.19677-9-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2017-01-07 14:11 ` Andy Shevchenko
2017-01-12 16:01 ` Rob Herring
2017-01-13 15:04 ` Andy Shevchenko
2017-01-13 15:28 ` Rob Herring
[not found] ` <CAL_JsqKjKz2=vWTBmzp9E3HrzJRszpq2hV4gsxcvnkTgRLH1QQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-13 15:55 ` Andy Shevchenko
2017-01-10 22:04 ` Pavel Machek
2017-01-14 2:54 ` Rob Herring
2017-01-06 16:26 ` [PATCH 9/9] tty_port: register tty ports with serdev bus Rob Herring
2017-01-06 19:25 ` [PATCH 0/9] Serial slave device bus Arnd Bergmann
2017-01-07 11:00 ` Andy Shevchenko
2017-01-10 17:24 ` Rob Herring
2017-01-10 18:32 ` Marcel Holtmann
2017-01-06 16:26 ` [PATCH 5/9] tty_port: Add port client functions Rob Herring
2017-01-06 16:26 ` [PATCH 7/9] serdev: Introduce new bus for serial attached devices Rob Herring
2017-01-07 14:02 ` Andy Shevchenko [this message]
2017-01-12 20:13 ` Rob Herring
2017-01-08 22:41 ` Sebastian Reichel
2017-01-10 21:46 ` Pavel Machek
2017-01-12 19:53 ` Rob Herring
2017-01-08 22:46 ` [PATCH 0/9] Serial slave device bus Sebastian Reichel
2017-01-10 11:44 ` H. Nikolaus Schaller
2017-01-10 12:02 ` Marcel Holtmann
2017-01-10 12:10 ` H. Nikolaus Schaller
2017-01-10 12:20 ` Andy Shevchenko
2017-01-10 12:40 ` H. Nikolaus Schaller
[not found] ` <CAL_JsqL-VMQ+zCTN+4+PPPCY+-askp=H908s8R=EjjytzuC8yw@mail.gmail.com>
[not found] ` <39C27218-E564-4C7D-A8CD-8D7F654EE2B3@goldelico.com>
2017-01-13 14:48 ` Rob Herring
2017-01-16 6:46 ` H. Nikolaus Schaller
2017-01-10 12:05 ` Marcel Holtmann
2017-01-10 22:05 ` Pavel Machek
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=1483797771.26691.1.camel@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=gnomes@lxorguk.ukuu.org.uk \
--cc=gregkh@linuxfoundation.org \
--cc=hns@goldelico.com \
--cc=jslaby@suse.com \
--cc=linus.walleij@linaro.org \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=loic.poulain@intel.com \
--cc=marcel@holtmann.org \
--cc=neil@brown.name \
--cc=pavel@ucw.cz \
--cc=peter@hurleysoftware.com \
--cc=robh@kernel.org \
--cc=sre@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).