From: Peter Hurley <peter-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>
To: NeilBrown <neilb-l3A5Bk7waGM@public.gmane.org>,
Grant Likely
<grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
Greg Kroah-Hartman
<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
Jiri Slaby <jslaby-AlSwsSmVLrQ@public.gmane.org>
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 2/3] TTY: add slave driver to power-on device via a regulator.
Date: Thu, 11 Dec 2014 18:32:52 -0500 [thread overview]
Message-ID: <548A29A4.7060908@hurleysoftware.com> (raw)
In-Reply-To: <20141211215944.4127.4186.stgit-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
On 12/11/2014 04:59 PM, NeilBrown wrote:
> The regulator is identified in devicetree as 'vdd-supply'
>
> Signed-off-by: NeilBrown <neilb-l3A5Bk7waGM@public.gmane.org>
tty_* is only for tty core functions/data.
Regards,
Peter Hurley
> ---
> .../devicetree/bindings/serial/slave-reg.txt | 18 ++++
> drivers/tty/Kconfig | 2
> drivers/tty/Makefile | 1
> drivers/tty/slaves/Kconfig | 12 ++
> drivers/tty/slaves/Makefile | 2
> drivers/tty/slaves/tty-reg.c | 102 ++++++++++++++++++++
> 6 files changed, 137 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/serial/slave-reg.txt
> create mode 100644 drivers/tty/slaves/Kconfig
> create mode 100644 drivers/tty/slaves/Makefile
> create mode 100644 drivers/tty/slaves/tty-reg.c
>
> diff --git a/Documentation/devicetree/bindings/serial/slave-reg.txt b/Documentation/devicetree/bindings/serial/slave-reg.txt
> new file mode 100644
> index 000000000000..7896bce8dfe4
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/serial/slave-reg.txt
> @@ -0,0 +1,18 @@
> +Regulator powered UART-attached device
> +
> +Required properties:
> +- compatible: "tty,regulator"
> +- vdd-supply: regulator to power the device
> +
> +
> +This is listed as a child node of a UART. When the
> +UART is opened, the device is powered.
> +
> +Example:
> +
> +&uart1 {
> + bluetooth {
> + compatible = "tty,regulator";
> + vdd-supply = <&vaux4>;
> + };
> +};
> diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
> index b24aa010f68c..ea3383c71701 100644
> --- a/drivers/tty/Kconfig
> +++ b/drivers/tty/Kconfig
> @@ -419,4 +419,6 @@ config DA_CONSOLE
> help
> This enables a console on a Dash channel.
>
> +source drivers/tty/slaves/Kconfig
> +
> endif # TTY
> diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
> index 58ad1c05b7f8..45957d671e33 100644
> --- a/drivers/tty/Makefile
> +++ b/drivers/tty/Makefile
> @@ -13,6 +13,7 @@ obj-$(CONFIG_R3964) += n_r3964.o
> obj-y += vt/
> obj-$(CONFIG_HVC_DRIVER) += hvc/
> obj-y += serial/
> +obj-$(CONFIG_TTY_SLAVE) += slaves/
>
> # tty drivers
> obj-$(CONFIG_AMIGA_BUILTIN_SERIAL) += amiserial.o
> diff --git a/drivers/tty/slaves/Kconfig b/drivers/tty/slaves/Kconfig
> new file mode 100644
> index 000000000000..2dd1acf80f8c
> --- /dev/null
> +++ b/drivers/tty/slaves/Kconfig
> @@ -0,0 +1,12 @@
> +menuconfig TTY_SLAVE
> + bool "TTY slave devices"
> + help
> + Devices which attach via a uart, but need extra
> + driver support for power management etc.
> +
> +if TTY_SLAVE
> +
> +config TTY_SLAVE_REGULATOR
> + tristate "TTY slave device powered by regulator"
> +
> +endif
> diff --git a/drivers/tty/slaves/Makefile b/drivers/tty/slaves/Makefile
> new file mode 100644
> index 000000000000..e636bf49f1cc
> --- /dev/null
> +++ b/drivers/tty/slaves/Makefile
> @@ -0,0 +1,2 @@
> +
> +obj-$(CONFIG_TTY_SLAVE_REGULATOR) += tty-reg.o
> diff --git a/drivers/tty/slaves/tty-reg.c b/drivers/tty/slaves/tty-reg.c
> new file mode 100644
> index 000000000000..613f8b10967c
> --- /dev/null
> +++ b/drivers/tty/slaves/tty-reg.c
> @@ -0,0 +1,102 @@
> +/*
> + * tty-reg:
> + * Support for any device which needs a regulator turned on
> + * when a tty is opened.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/err.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/platform_device.h>
> +#include <linux/pm_runtime.h>
> +#include <linux/tty.h>
> +
> +struct tty_reg_data {
> + struct regulator *reg;
> + bool reg_enabled;
> +};
> +
> +static int tty_reg_runtime_resume(struct device *slave)
> +{
> + struct tty_reg_data *data = dev_get_drvdata(slave);
> + if (!data->reg_enabled &&
> + regulator_enable(data->reg) == 0) {
> + dev_dbg(slave, "power on\n");
> + data->reg_enabled = true;
> + }
> + return 0;
> +}
> +
> +static int tty_reg_runtime_suspend(struct device *slave)
> +{
> + struct tty_reg_data *data = dev_get_drvdata(slave);
> +
> + if (data->reg_enabled &&
> + regulator_disable(data->reg) == 0) {
> + dev_dbg(slave, "power off\n");
> + data->reg_enabled = false;
> + }
> + return 0;
> +}
> +
> +static int tty_reg_probe(struct platform_device *pdev)
> +{
> + struct tty_reg_data *data;
> + struct regulator *reg;
> + int err;
> +
> + err = -ENODEV;
> + if (pdev->dev.parent == NULL)
> + goto out;
> + reg = devm_regulator_get(&pdev->dev, "vdd");
> + err = PTR_ERR(reg);
> + if (IS_ERR(reg))
> + goto out;
> +
> + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> + err = -ENOMEM;
> + if (!data)
> + goto out;
> + data->reg = reg;
> + data->reg_enabled = false;
> + pm_runtime_enable(&pdev->dev);
> + platform_set_drvdata(pdev, data);
> + err = 0;
> +out:
> + return err;
> +}
> +
> +static struct of_device_id tty_reg_dt_ids[] = {
> + { .compatible = "tty,regulator", },
> + {}
> +};
> +
> +static const struct dev_pm_ops tty_reg_pm_ops = {
> + SET_RUNTIME_PM_OPS(tty_reg_runtime_suspend,
> + tty_reg_runtime_resume, NULL)
> +};
> +
> +static struct platform_driver tty_reg_driver = {
> + .driver.name = "tty-regulator",
> + .driver.owner = THIS_MODULE,
> + .driver.of_match_table = tty_reg_dt_ids,
> + .driver.pm = &tty_reg_pm_ops,
> + .probe = tty_reg_probe,
> +};
> +
> +static int __init tty_reg_init(void)
> +{
> + return platform_driver_register(&tty_reg_driver);
> +}
> +module_init(tty_reg_init);
> +
> +static void __exit tty_reg_exit(void)
> +{
> + platform_driver_unregister(&tty_reg_driver);
> +}
> +module_exit(tty_reg_exit);
> +
> +MODULE_AUTHOR("NeilBrown <neilb-l3A5Bk7waGM@public.gmane.org>");
> +MODULE_DESCRIPTION("Serial port device which requires a regulator when open.");
> +MODULE_LICENSE("GPL v2");
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2014-12-11 23:32 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-11 21:59 [PATCH 0/3] Add support for 'tty-slaves' described by devicetree NeilBrown
2014-12-11 21:59 ` [PATCH 3/3] TTY/slave: add driver for w2sg0004 GPS NeilBrown
[not found] ` <20141211215944.4127.57146.stgit-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2014-12-11 23:04 ` Sebastian Reichel
2014-12-11 23:11 ` One Thousand Gnomes
[not found] ` <20141211231100.05782a30-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2014-12-12 5:06 ` NeilBrown
[not found] ` <20141212160607.361d20db-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2014-12-15 11:39 ` One Thousand Gnomes
2014-12-12 12:11 ` Grant Likely
2014-12-11 21:59 ` [PATCH 2/3] TTY: add slave driver to power-on device via a regulator NeilBrown
[not found] ` <20141211215944.4127.4186.stgit-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2014-12-11 22:58 ` Sebastian Reichel
2014-12-12 0:46 ` Marcel Holtmann
2014-12-12 1:31 ` Sebastian Reichel
2014-12-12 5:01 ` NeilBrown
2014-12-11 23:32 ` Peter Hurley [this message]
2014-12-12 5:27 ` NeilBrown
[not found] ` <20141212162714.3a2378df-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2014-12-12 11:59 ` Peter Hurley
2014-12-12 12:05 ` Grant Likely
2014-12-11 21:59 ` [PATCH 1/3] TTY: add support for "tty slave" devices NeilBrown
[not found] ` <20141211215943.4127.24792.stgit-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2014-12-11 22:41 ` Sebastian Reichel
2014-12-11 23:18 ` Peter Hurley
[not found] ` <548A264D.8070103-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>
2014-12-12 5:23 ` NeilBrown
[not found] ` <20141212162352.66be5b5e-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2014-12-12 13:02 ` Peter Hurley
2014-12-13 14:23 ` One Thousand Gnomes
[not found] ` <20141213142344.61372b92-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2014-12-16 16:14 ` Peter Hurley
2014-12-13 14:12 ` One Thousand Gnomes
2014-12-12 11:59 ` Grant Likely
2014-12-13 17:46 ` Sebastian Reichel
2014-12-13 22:22 ` Grant Likely
2014-12-28 14:20 ` Pavel Machek
2015-01-02 21:33 ` NeilBrown
2015-01-04 10:18 ` Pavel Machek
2015-01-05 7:09 ` NeilBrown
[not found] ` <20150105200936.2ba8f596-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2015-01-05 13:43 ` Pavel Machek
2015-01-05 15:41 ` One Thousand Gnomes
2015-01-05 16:28 ` 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=548A29A4.7060908@hurleysoftware.com \
--to=peter-wagbzjegnqdsbiue7sb01tbpr1lh4cv8@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
--cc=jslaby-AlSwsSmVLrQ@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=neilb-l3A5Bk7waGM@public.gmane.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).