Received: by 10.192.165.148 with SMTP id m20csp473431imm; Wed, 25 Apr 2018 02:38:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/8dt+qeyVjUuBZoCUNdLpbJd4jxRFQSuNoM22QlFVaWrmSbgv9zdxOpAtTZ5CNy6Q39rXn X-Received: by 2002:a17:902:6181:: with SMTP id u1-v6mr28238028plj.272.1524649135126; Wed, 25 Apr 2018 02:38:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524649135; cv=none; d=google.com; s=arc-20160816; b=GbMXrfeJpQ0TFU56KrEYiRcvQjMzbcNbOB7u1iDaUHz5Nr/efbo6MEhpq10bMwcjJ0 UTOw0Xn/giYS1BVxAkmd7TQ+c+754W1yXR1Ckb3k5c04DQjk3FtZa5TDrnjOzsLI37Jn F7/zSt05j6aMxM+fsM67fjbD1FOtQCVMclk2JCOW03EID/XtMPphW0fenCllSRpQ2Koo jvBux3loTK/cLI4V+GLqmdzakkhyFDrcVOUlrzOPsXwTHlUSxePeDJTDVQQOKNHLEzwG KcqbHOWaGaV3czpkNx6irAChWAr7Ao8Fw0Mabdor5UrRjczDtBWP3bGINX7OD/XG2H5k IUQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=RE0X9DnyjcyqvAjpnpLricOZE65GU1vlq0t/sLJRijM=; b=HE972JAmHefQ9mOxfKdLD8qSMG2YEMBgJfLR70sHMqXhYHrkp6Bz057Yp3gUpYOQdw fbxEbh0zyVXPxrSNZiD2MPhT0tfT+0ioFDcBOtYft5TFCqzKXBj8hZCV/14wtvW8IFd0 R/TZsJmfQz3Hf/FwAWxqRINuLuh7cjvN42N/yRYe/R0aWjP+OPPJFccmER5Ejmkw02ek du6YPqnN6CMpI4D4/u1Pvmf6G98wgPiXg5Bov1hsi2vfsh64oW/gV135um2tutzA8RMk wZSm3KpiE/bKeb1SxOPWWzFwVNovj/pfMm8P+P5xeDF6fQwqS8AMEQx8BqmP67YLij1R xtzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p3-v6si15663579pld.408.2018.04.25.02.38.40; Wed, 25 Apr 2018 02:38:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752261AbeDYJhQ (ORCPT + 99 others); Wed, 25 Apr 2018 05:37:16 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:62845 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751064AbeDYJcy (ORCPT ); Wed, 25 Apr 2018 05:32:54 -0400 X-UUID: e61d2da81a3a4c4da80291b263650eba-20180425 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1709865228; Wed, 25 Apr 2018 17:32:51 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Wed, 25 Apr 2018 17:32:50 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Wed, 25 Apr 2018 17:32:50 +0800 From: To: , , , , , , , CC: , , , , , , Sean Wang Subject: [PATCH v2 15/17] power: reset: mt6323: add a driver for MT6323 power controller Date: Wed, 25 Apr 2018 17:32:41 +0800 Message-ID: <51d4fbe0d6a22986ddd2df66c9db39aa1eaab74a.1524646231.git.sean.wang@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Wang The power device is responsible for externally down or up the power of the remote MediaTek SoC through the tiny circuit BBPU inside PMIC RTC. Though it's a part of RTC device, it would be better to be a standalone driver than to be a part of existent RTC driver so as to let us make concentration on works about power-controlling topic and to obtain improvements while the subsystem power/reset constantly growing. Currently, the most basic functionality supported is to just power off the system by writing to a special bit field in BBPU register after the system has reached pm_poweroff. Signed-off-by: Sean Wang --- drivers/power/reset/Kconfig | 10 ++++ drivers/power/reset/Makefile | 1 + drivers/power/reset/mt6323-poweroff.c | 97 +++++++++++++++++++++++++++++++++++ include/linux/mfd/mt6397/rtc.h | 1 + 4 files changed, 109 insertions(+) create mode 100644 drivers/power/reset/mt6323-poweroff.c diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index df58fc8..7b49d71 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -128,6 +128,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 through + 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 7778c74..8836172 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o +obj-$(CONFIG_POWER_RESET_MT6323) += mt6323-poweroff.o obj-$(CONFIG_POWER_RESET_OCELOT_RESET) += ocelot-reset.o obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o diff --git a/drivers/power/reset/mt6323-poweroff.c b/drivers/power/reset/mt6323-poweroff.c new file mode 100644 index 0000000..c195766 --- /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 = 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 = 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 = dev_get_drvdata(pdev->dev.parent); + struct mt6323_pwrc *pwrc; + struct resource *res; + + pwrc = devm_kzalloc(&pdev->dev, sizeof(*pwrc), GFP_KERNEL); + if (!pwrc) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + pwrc->base = res->start; + pwrc->regmap = mt6397_chip->regmap; + pwrc->dev = &pdev->dev; + mt_pwrc = pwrc; + + pm_power_off = &mt6323_do_pwroff; + + return 0; +} + +static int mt6323_pwrc_remove(struct platform_device *pdev) +{ + if (pm_power_off == &mt6323_do_pwroff) + pm_power_off = NULL; + + return 0; +} + +static const struct of_device_id mt6323_pwrc_dt_match[] = { + { .compatible = "mediatek,mt6323-pwrc" }, + {}, +}; +MODULE_DEVICE_TABLE(of, mt6323_pwrc_dt_match); + +static struct platform_driver mt6323_pwrc_driver = { + .probe = mt6323_pwrc_probe, + .remove = mt6323_pwrc_remove, + .driver = { + .name = "mt6323-pwrc", + .of_match_table = 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/rtc.h b/include/linux/mfd/mt6397/rtc.h index 480977c..ac932c9 100644 --- a/include/linux/mfd/mt6397/rtc.h +++ b/include/linux/mfd/mt6397/rtc.h @@ -16,6 +16,7 @@ #define RTC_BBPU 0x0000 #define RTC_BBPU_CBUSY BIT(6) +#define RTC_BBPU_KEY (0x43 << 8) #define RTC_WRTGR 0x003c -- 2.7.4