diff mbox series

[2/2] Input: pm8941-pwrkey: Introduce reboot mode support

Message ID 20170527065130.3456-2-bjorn.andersson@linaro.org
State New
Headers show
Series None | expand

Commit Message

Bjorn Andersson May 27, 2017, 6:51 a.m. UTC
In some Qualcomm platforms the magic for informing LK which mode to
reboot into is stored in the PON_SOFT_RB_SPARE register. Register with
the reboot mode helpers to expose this to the user.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>

---
 drivers/input/misc/Kconfig         |  1 +
 drivers/input/misc/pm8941-pwrkey.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

-- 
2.12.0

--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Bjorn Andersson May 30, 2017, 4:47 a.m. UTC | #1
On Mon 29 May 19:53 PDT 2017, Dmitry Torokhov wrote:

> On Fri, May 26, 2017 at 11:51:30PM -0700, Bjorn Andersson wrote:

> > In some Qualcomm platforms the magic for informing LK which mode to

> > reboot into is stored in the PON_SOFT_RB_SPARE register. Register with

> > the reboot mode helpers to expose this to the user.

> 

> Hmm, is the power key driver the best place to have this? WHy isn't this

> a driver in its own right?

> 


The functionality is part of the "PON" block in the Qualcomm PMICs,
other functionality from this block relates to configuration and
handling related to power-key and reset-key.

Several of these properties are intermingled, so I do believe it's best
to handle them in a single driver; that said, it might no longer be
correct to name the driver "pwrkey" or that it is a "misc input" driver.

Regards,
Bjorn
--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bjorn Andersson June 15, 2017, 6:33 p.m. UTC | #2
On Thu 15 Jun 09:26 PDT 2017, Sebastian Reichel wrote:

> Hi,

> 

> On Mon, Jun 12, 2017 at 04:32:03PM -0700, Bjorn Andersson wrote:

[..]
> > As such if we split the non-input related handling into another driver

> > we would need to make the input driver create a subdevice during probe -

> > or create a new pon-driver with a new compatible that internally spawns

> > the pwrkey driver. Neither seems desirable to me...

> 

> The pon-driver would have been the proper solution, but with the

> binding already being defined that's no longer a nice option :(

> 


We have a binding for the "qcom,pm8941-pwrkey", but as long as we
maintain the compatibility in the input driver with this we could come
up with a new binding for the "pon" block.

> > The features of the PON block not yet shown on LKML are status registers

> > to indicate the reason for powering up the PMIC and a watchdog (which I

> > don't believe is used or exposed today).

> 

> So we have a block, which has watchdog, powerdown, reboot, boot-reason,

> reboot-mode and power key. To me that does not look like it should be

> one driver.

> 


Unfortunately I do agree with this.

It would make sense to describe the pon in a single DT-node and have a
pon-driver spawning off individual driver for each functionality. That
way we get a clean representation in DT and we get clean implementation
of each component...

Regards,
Bjorn
--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox series

Patch

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 3872488c3fd7..56552e16fab1 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -132,6 +132,7 @@  config INPUT_PCSPKR
 config INPUT_PM8941_PWRKEY
 	tristate "Qualcomm PM8941 power key support"
 	depends on MFD_SPMI_PMIC
+	select REBOOT_MODE
 	help
 	  Say Y here if you want support for the power key usually found
 	  on boards using a Qualcomm PM8941 compatible PMIC.
diff --git a/drivers/input/misc/pm8941-pwrkey.c b/drivers/input/misc/pm8941-pwrkey.c
index 18ad956454f1..c48be6dbaa78 100644
--- a/drivers/input/misc/pm8941-pwrkey.c
+++ b/drivers/input/misc/pm8941-pwrkey.c
@@ -22,6 +22,7 @@ 
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/reboot.h>
+#include <linux/reboot-mode.h>
 #include <linux/regmap.h>
 
 #define PON_REV2			0x01
@@ -42,6 +43,7 @@ 
 #define PON_DBC_CTL			0x71
 #define  PON_DBC_DELAY_MASK		0x7
 
+#define PON_SOFT_RB_SPARE		0x8f
 
 struct pm8941_pwrkey {
 	struct device *dev;
@@ -52,8 +54,26 @@  struct pm8941_pwrkey {
 
 	unsigned int revision;
 	struct notifier_block reboot_notifier;
+
+	struct reboot_mode_driver reboot_mode;
 };
 
+static int pm8941_reboot_mode_write(struct reboot_mode_driver *reboot,
+				    unsigned int magic)
+{
+	struct pm8941_pwrkey *pwrkey = container_of(reboot, struct pm8941_pwrkey,
+						    reboot_mode);
+	int ret;
+
+	ret = regmap_update_bits(pwrkey->regmap,
+				 pwrkey->baseaddr + PON_SOFT_RB_SPARE,
+				 0xfc, magic << 2);
+	if (ret < 0)
+		dev_err(pwrkey->dev, "update reboot mode bits failed\n");
+
+	return ret;
+}
+
 static int pm8941_reboot_notify(struct notifier_block *nb,
 				unsigned long code, void *unused)
 {
@@ -256,6 +276,14 @@  static int pm8941_pwrkey_probe(struct platform_device *pdev)
 		return error;
 	}
 
+	pwrkey->reboot_mode.dev = &pdev->dev;
+	pwrkey->reboot_mode.write = pm8941_reboot_mode_write;
+	error = devm_reboot_mode_register(&pdev->dev, &pwrkey->reboot_mode);
+	if (error) {
+		dev_err(&pdev->dev, "can't register reboot mode\n");
+		return error;
+	}
+
 	platform_set_drvdata(pdev, pwrkey);
 	device_init_wakeup(&pdev->dev, 1);