linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sebastian Reichel <sebastian.reichel@collabora.com>
To: Mithil Bavishi <bavishimithil@gmail.com>
Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
	linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	dmitry.torokhov@gmail.com, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, lee@kernel.org,
	tony@atomide.com, linux@armlinux.org.uk, contact@paulk.fr
Subject: Re: [PATCH 03/10] power: reset: Add TWL6030 power driver, with minimal support for power off
Date: Sun, 11 Sep 2022 14:55:45 +0200	[thread overview]
Message-ID: <20220911125545.73afzbirtnsdbmgo@mercury.elektranox.org> (raw)
In-Reply-To: <20220820071659.1215-4-bavishimithil@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 5193 bytes --]

Hi,

On Sat, Aug 20, 2022 at 12:46:53PM +0530, Mithil Bavishi wrote:
> From: Paul Kocialkowski <contact@paulk.fr>
> 
> This adds a TWL6030 power driver, that currently only supports powering
> off the device when the TWL is used as system power controller.
> 
> This driver might be extended to support more power-related features of the
> TWL6030.
> 
> Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
> Signed-off-by: Mithil Bavishi <bavishimithil@gmail.com>
> ---
>  drivers/power/reset/Kconfig         | 10 ++++
>  drivers/power/reset/Makefile        |  1 +
>  drivers/power/reset/twl6030-power.c | 93 +++++++++++++++++++++++++++++
>  3 files changed, 104 insertions(+)
>  create mode 100644 drivers/power/reset/twl6030-power.c
> 
> diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
> index 39117b697..5156b1613 100644
> --- a/drivers/power/reset/Kconfig
> +++ b/drivers/power/reset/Kconfig
> @@ -316,3 +316,13 @@ config TWL4030_POWER
>            and load scripts controlling which resources are switched off/on
>            or reset when a sleep, wakeup or warm reset event occurs.
>  endif
> +
> +config TWL6030_POWER
> +	bool "TI TWL6030 power resources"
> +	depends on TWL4030_CORE && ARM
> +	help
> +	  Say yes here if you want to use the power resources on the
> +	  TWL6030 family chips.
> +
> +	  When used as system power controller, this driver allows turning off
> +	  the main power supply.
> diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
> index e9db25b09..692d51cef 100644
> --- a/drivers/power/reset/Makefile
> +++ b/drivers/power/reset/Makefile
> @@ -37,3 +37,4 @@ obj-$(CONFIG_POWER_RESET_SC27XX) += sc27xx-poweroff.o
>  obj-$(CONFIG_NVMEM_REBOOT_MODE) += nvmem-reboot-mode.o
>  obj-$(CONFIG_POWER_MLXBF) += pwr-mlxbf.o
>  obj-$(CONFIG_TWL4030_POWER) += twl4030-power.o
> +obj-$(CONFIG_TWL6030_POWER) += twl6030-power.o
> diff --git a/drivers/power/reset/twl6030-power.c b/drivers/power/reset/twl6030-power.c
> new file mode 100644
> index 000000000..78c8a02a3
> --- /dev/null
> +++ b/drivers/power/reset/twl6030-power.c
> @@ -0,0 +1,93 @@
> +/*
> + * TWL6030 power
> + *
> + * Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
> + *
> + * This file is subject to the terms and conditions of the GNU General
> + * Public License. See the file "COPYING" in the main directory of this
> + * archive for more details.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */

Please use SPDX format for license.

> +
> +#include <linux/module.h>
> +#include <linux/pm.h>
> +#include <linux/mfd/twl.h>
> +#include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +
> +#define TWL6030_PHOENIX_DEV_ON		0x25
> +
> +#define TWL6030_PHOENIX_APP_DEVOFF	BIT(0)
> +#define TWL6030_PHOENIX_CON_DEVOFF	BIT(1)
> +#define TWL6030_PHOENIX_MOD_DEVOFF	BIT(2)
> +
> +void twl6030_power_off(void)
> +{
> +	int err;
> +
> +	err = twl_i2c_write_u8(TWL6030_MODULE_ID0, TWL6030_PHOENIX_APP_DEVOFF |
> +		TWL6030_PHOENIX_CON_DEVOFF | TWL6030_PHOENIX_MOD_DEVOFF,
> +		TWL6030_PHOENIX_DEV_ON);
> +	if (err)
> +		pr_err("TWL6030 Unable to power off\n");
> +}
> +
> +static bool twl6030_power_use_poweroff(struct device_node *node)
> +{
> +	if (of_property_read_bool(node, "ti,system-power-controller"))
> +		return true;
> +
> +	return false;
> +}
> +
> +#ifdef CONFIG_OF
> +static const struct of_device_id twl6030_power_of_match[] = {
> +	{
> +		.compatible = "ti,twl6030-power",
> +	},
> +	{ },
> +};
> +
> +MODULE_DEVICE_TABLE(of, twl6030_power_of_match);
> +#endif	/* CONFIG_OF */
> +
> +static int twl6030_power_probe(struct platform_device *pdev)
> +{
> +	struct device_node *node = pdev->dev.of_node;
> +
> +	if (!node) {
> +		dev_err(&pdev->dev, "Platform data is missing\n");
> +		return -EINVAL;
> +	}
> +
> +	/* Board has to be wired properly to use this feature */
> +	if (twl6030_power_use_poweroff(node) && !pm_power_off)
> +		pm_power_off = twl6030_power_off;

Please devm_register_sys_off_handler or devm_register_power_off_handler().

> +
> +	return 0;
> +}
> +
> +static int twl6030_power_remove(struct platform_device *pdev)
> +{
> +	return 0;
> +}

Empty remove function can be removed.

> +
> +static struct platform_driver twl6030_power_driver = {
> +	.driver = {
> +		.name	= "twl6030_power",
> +		.of_match_table = of_match_ptr(twl6030_power_of_match),

The driver is not useful without CONFIG_OF, so you can just remove the
#ifdef around twl6030_power_of_match and drop of_match_ptr here.

-- Sebastian

> +	},
> +	.probe		= twl6030_power_probe,
> +	.remove		= twl6030_power_remove,
> +};
> +
> +module_platform_driver(twl6030_power_driver);
> +
> +MODULE_AUTHOR("Paul Kocialkowski <contact@paulk.fr>");
> +MODULE_DESCRIPTION("Power management for TWL6030");
> +MODULE_LICENSE("GPL");
> -- 
> 2.25.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2022-09-12 10:28 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-20  7:16 [PATCH 00/10] Add TWL6030 power off and powerbutton support Mithil Bavishi
2022-08-20  7:16 ` [PATCH 01/10] power: reset: Move TWL4030 power driver from mfd Mithil Bavishi
2022-09-06 15:13   ` Lee Jones
2022-08-20  7:16 ` [PATCH 02/10] dt-bindings: power: reset: Move twl4030-power from mfd to power/reset Mithil Bavishi
2022-08-22 19:23   ` Rob Herring
2022-09-06 15:13   ` Lee Jones
2022-08-20  7:16 ` [PATCH 03/10] power: reset: Add TWL6030 power driver, with minimal support for power off Mithil Bavishi
2022-09-11 12:55   ` Sebastian Reichel [this message]
2022-08-20  7:16 ` [PATCH 04/10] dt-bindings: input: twl-pwrbutton: Add support for twl6030-pwrbutton Mithil Bavishi
2022-08-22 19:25   ` Rob Herring
2022-08-20  7:16 ` [PATCH 05/10] dt-bindings: power: reset: Add bindings for twl6030-power Mithil Bavishi
2022-08-22 19:24   ` Rob Herring
2022-08-20  7:16 ` [PATCH 06/10] ARM: OMAP2+: Only select TWL4030_POWER for OMAP3 Mithil Bavishi
2022-08-20  7:16 ` [PATCH 07/10] ARM: OMAP2+: Select TWL6030_POWER for OMAP4 Mithil Bavishi
2022-08-20  7:16 ` [PATCH 08/10] input: misc: Rename twl4030_pwrbutton to twl_pwrbutton Mithil Bavishi
2022-08-20  7:16 ` [PATCH 09/10] dt-bindings: input: Rename twl4030-pwrbutton to twl-pwrbutton Mithil Bavishi
2022-08-22 19:26   ` Rob Herring

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=20220911125545.73afzbirtnsdbmgo@mercury.elektranox.org \
    --to=sebastian.reichel@collabora.com \
    --cc=bavishimithil@gmail.com \
    --cc=contact@paulk.fr \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=robh+dt@kernel.org \
    --cc=tony@atomide.com \
    /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).