From mboxrd@z Thu Jan 1 00:00:00 1970 From: Frank Wunderlich Subject: [PATCH v3 08/10] power: reset: add driver for mt6323 poweroff Date: Mon, 29 Jul 2019 19:41:52 +0200 Message-ID: <20190729174154.4335-9-frank-w@public-files.de> References: <20190729174154.4335-1-frank-w@public-files.de> Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <20190729174154.4335-1-frank-w@public-files.de> Sender: linux-kernel-owner@vger.kernel.org To: Alessandro Zummo , Alexandre Belloni , Allison Randal , "David S. Miller" , devicetree@vger.kernel.org, Eddie Huang , Greg Kroah-Hartman , Jonathan Cameron , Kate Stewart , Lee Jones , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-pm@vger.kernel.org, linux-rtc@vger.kernel.org, Mark Rutland , Matthias Brugger , Mauro Carvalho Chehab , Nicolas Ferre , Richard Fontana Cc: Josef Friedl , Frank Wunderlich List-Id: devicetree@vger.kernel.org From: Josef Friedl add poweroff driver for mt6323 and make Makefile and Kconfig-Entries changes since v2: none (=3Dv2 part 5) Suggested-by: Frank Wunderlich Signed-off-by: Josef Friedl Signed-off-by: Frank Wunderlich =2D-- drivers/power/reset/Kconfig | 10 +++ drivers/power/reset/Makefile | 1 + drivers/power/reset/mt6323-poweroff.c | 97 +++++++++++++++++++++++++++ include/linux/mfd/mt6397/core.h | 2 + 4 files changed, 110 insertions(+) create mode 100644 drivers/power/reset/mt6323-poweroff.c diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index a564237278ff..c721939767eb 100644 =2D-- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -140,6 +140,16 @@ config POWER_RESET_LTC2952 This driver supports an external powerdown trigger and board power down via the LTC2952. Bindings are made in the device tree. +config POWER_RESET_MT6323 + bool "MediaTek MT6323 power-off driver" + depends on MFD_MT6397 + help + The power-off driver is responsible for externally shutdown down + the power of a remote MediaTek SoC MT6323 is connected to throug= h + controlling a tiny circuit BBPU inside MT6323 RTC. + + Say Y if you have a board where MT6323 could be found. + config POWER_RESET_QNAP bool "QNAP power-off driver" depends on OF_GPIO && PLAT_ORION diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index 85da3198e4e0..da37f8b851dc 100644 =2D-- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_POWER_RESET_GPIO) +=3D gpio-poweroff.o obj-$(CONFIG_POWER_RESET_GPIO_RESTART) +=3D gpio-restart.o obj-$(CONFIG_POWER_RESET_HISI) +=3D hisi-reboot.o obj-$(CONFIG_POWER_RESET_MSM) +=3D msm-poweroff.o +obj-$(CONFIG_POWER_RESET_MT6323) +=3D mt6323-poweroff.o obj-$(CONFIG_POWER_RESET_QCOM_PON) +=3D qcom-pon.o obj-$(CONFIG_POWER_RESET_OCELOT_RESET) +=3D ocelot-reset.o obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) +=3D piix4-poweroff.o diff --git a/drivers/power/reset/mt6323-poweroff.c b/drivers/power/reset/m= t6323-poweroff.c new file mode 100644 index 000000000000..1caf43d9e46d =2D-- /dev/null +++ b/drivers/power/reset/mt6323-poweroff.c @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Power off through MediaTek PMIC + * + * Copyright (C) 2018 MediaTek Inc. + * + * Author: Sean Wang + * + */ + +#include +#include +#include +#include +#include +#include + +struct mt6323_pwrc { + struct device *dev; + struct regmap *regmap; + u32 base; +}; + +static struct mt6323_pwrc *mt_pwrc; + +static void mt6323_do_pwroff(void) +{ + struct mt6323_pwrc *pwrc =3D mt_pwrc; + unsigned int val; + int ret; + + regmap_write(pwrc->regmap, pwrc->base + RTC_BBPU, RTC_BBPU_KEY); + regmap_write(pwrc->regmap, pwrc->base + RTC_WRTGR, 1); + + ret =3D regmap_read_poll_timeout(pwrc->regmap, + pwrc->base + RTC_BBPU, val, + !(val & RTC_BBPU_CBUSY), + MTK_RTC_POLL_DELAY_US, + MTK_RTC_POLL_TIMEOUT); + if (ret) + dev_err(pwrc->dev, "failed to write BBPU: %d\n", ret); + + /* Wait some time until system down, otherwise, notice with a warn */ + mdelay(1000); + + WARN_ONCE(1, "Unable to power off system\n"); +} + +static int mt6323_pwrc_probe(struct platform_device *pdev) +{ + struct mt6397_chip *mt6397_chip =3D dev_get_drvdata(pdev->dev.parent); + struct mt6323_pwrc *pwrc; + struct resource *res; + + pwrc =3D devm_kzalloc(&pdev->dev, sizeof(*pwrc), GFP_KERNEL); + if (!pwrc) + return -ENOMEM; + + res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); + pwrc->base =3D res->start; + pwrc->regmap =3D mt6397_chip->regmap; + pwrc->dev =3D &pdev->dev; + mt_pwrc =3D pwrc; + + pm_power_off =3D &mt6323_do_pwroff; + + return 0; +} + +static int mt6323_pwrc_remove(struct platform_device *pdev) +{ + if (pm_power_off =3D=3D &mt6323_do_pwroff) + pm_power_off =3D NULL; + + return 0; +} + +static const struct of_device_id mt6323_pwrc_dt_match[] =3D { + { .compatible =3D "mediatek,mt6323-pwrc" }, + {}, +}; +MODULE_DEVICE_TABLE(of, mt6323_pwrc_dt_match); + +static struct platform_driver mt6323_pwrc_driver =3D { + .probe =3D mt6323_pwrc_probe, + .remove =3D mt6323_pwrc_remove, + .driver =3D { + .name =3D "mt6323-pwrc", + .of_match_table =3D mt6323_pwrc_dt_match, + }, +}; + +module_platform_driver(mt6323_pwrc_driver); + +MODULE_DESCRIPTION("Poweroff driver for MT6323 PMIC"); +MODULE_AUTHOR("Sean Wang "); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/mfd/mt6397/core.h b/include/linux/mfd/mt6397/co= re.h index 25a95e72179b..652da61e3711 100644 =2D-- a/include/linux/mfd/mt6397/core.h +++ b/include/linux/mfd/mt6397/core.h @@ -7,6 +7,8 @@ #ifndef __MFD_MT6397_CORE_H__ #define __MFD_MT6397_CORE_H__ +#include + enum mt6397_irq_numbers { MT6397_IRQ_SPKL_AB =3D 0, MT6397_IRQ_SPKR_AB, =2D- 2.17.1