From patchwork Fri Feb 9 09:43:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "(Exiting) Baolin Wang" X-Patchwork-Id: 10208663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7699160245 for ; Fri, 9 Feb 2018 09:44:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 573872981F for ; Fri, 9 Feb 2018 09:44:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B5A529822; Fri, 9 Feb 2018 09:44:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEBB72981D for ; Fri, 9 Feb 2018 09:44:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751031AbeBIJoG (ORCPT ); Fri, 9 Feb 2018 04:44:06 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36113 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750942AbeBIJoE (ORCPT ); Fri, 9 Feb 2018 04:44:04 -0500 Received: by mail-pg0-f67.google.com with SMTP id j9so2200344pgv.3 for ; Fri, 09 Feb 2018 01:44:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=BjG5xum631wTNCzVAcnwi7nb06Tld78UuW5Pc25CL0U=; b=ZqgNYuYIFoZ4ov2M8Wmcv3nRC+rx4UHTZQEv+kmMeP9CuMSMZ4TCGpNzFj5YV+1YoF 91wXSAzlUDvx0ZpvOE+8jwVVFOG6Qycvk4r+AYXCO2SWjJR0NRfs0LKZMWEcvOq8UUfV xz+VQMvjBjU+xLjYhYMxfy+FGxxUoPSH2ll9E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BjG5xum631wTNCzVAcnwi7nb06Tld78UuW5Pc25CL0U=; b=gmbTfPz4XrdqN41AboyB4H8chSaBdUDBE7gNEieU4hM73mFoHoVqaO6tb3kXgOUQQW uQ70b4TEO6/rpro8LmQV2pg670+KwstO+ok4s80ZJYdFNKrDR4yYTisfdriuvMIp3v+m US87ax1bsjsbdY9s0BvFDsIqzy5qWWN1btqklS25393yupCiylNGml85jSIVX4EstgxO PLPEDEQbs2FRV9PgpsIHhOlve+ooFN85JGXHbF+ybFDkLRVyEDfM3T/fycXV5cmrKkeO pmpcYlhcIcC8K/9yDOITX+8gHsxYhyKch9FZBLiDA16i4tEPfnJM+ytuucLvC8w4DMGl I9tA== X-Gm-Message-State: APf1xPCPGG4CZn7h5YSyR/8CeCRvMn0Zh4x08pz72EeXGlm+1LIcPa9H cbbhg4qDPyJVf0zkcGtomGI54A== X-Google-Smtp-Source: AH8x227MJJRMOFBCd2+dCt1vB7FfKK4zgCKGDLDZdWtQHS9aAYdJIb+4UhUte+vyW7XJSbHV7ypDEg== X-Received: by 10.101.80.69 with SMTP id k5mr1870152pgo.433.1518169443732; Fri, 09 Feb 2018 01:44:03 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id 87sm4319835pft.122.2018.02.09.01.44.01 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Feb 2018 01:44:03 -0800 (PST) From: Baolin Wang To: sre@kernel.org Cc: arnd@arndb.de, broonie@kernel.org, baolin.wang@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v2] power: reset: Add Spreadtrum SC27xx PMIC power off support Date: Fri, 9 Feb 2018 17:43:38 +0800 Message-Id: <7655f39d44e804c9ed3209db475567abc250f642.1518169282.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Spreadtrum platform, we need power off system through external SC27xx series PMICs including the SC2720, SC2721, SC2723, SC2730 and SC2731 chips. Thus this patch adds SC27xx series PMICs power-off support. Signed-off-by: Baolin Wang --- Changes since v1: - Add remove interface. - Add regmap checking when probing the driver. - Add MODULE_ALIAS() --- drivers/power/reset/Kconfig | 9 ++++ drivers/power/reset/Makefile | 1 + drivers/power/reset/sc27xx-poweroff.c | 79 +++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 drivers/power/reset/sc27xx-poweroff.c diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index ca0de1a..611ae56 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -227,5 +227,14 @@ config SYSCON_REBOOT_MODE register, then the bootloader can read it to take different action according to the mode. +config POWER_RESET_SC27XX + tristate "Spreadtrum SC27xx PMIC power-off driver" + depends on MFD_SC27XX_PMIC || COMPILE_TEST + help + This driver supports powering off a system through + Spreadtrum SC27xx series PMICs. The SC27xx series + PMICs includes the SC2720, SC2721, SC2723, SC2730 + and SC2731 chips. + endif diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index aeb65ed..225d645 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile @@ -27,3 +27,4 @@ obj-$(CONFIG_POWER_RESET_RMOBILE) += rmobile-reset.o obj-$(CONFIG_POWER_RESET_ZX) += zx-reboot.o obj-$(CONFIG_REBOOT_MODE) += reboot-mode.o obj-$(CONFIG_SYSCON_REBOOT_MODE) += syscon-reboot-mode.o +obj-$(CONFIG_POWER_RESET_SC27XX) += sc27xx-poweroff.o diff --git a/drivers/power/reset/sc27xx-poweroff.c b/drivers/power/reset/sc27xx-poweroff.c new file mode 100644 index 0000000..73d9816 --- /dev/null +++ b/drivers/power/reset/sc27xx-poweroff.c @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018 Spreadtrum Communications Inc. + * Copyright (C) 2018 Linaro Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define SC27XX_PWR_PD_HW 0xc2c +#define SC27XX_PWR_OFF_EN BIT(0) + +static struct regmap *regmap; + +/* + * On Spreadtrum platform, we need power off system through external SC27xx + * series PMICs, and it is one similar SPI bus mapped by regmap to access PMIC, + * which is not fast io access. + * + * So before stopping other cores, we need release other cores' resource by + * taking cpus down to avoid racing regmap or spi mutex lock when poweroff + * system through PMIC. + */ +void sc27xx_poweroff_shutdown(void) +{ + int cpu = smp_processor_id(); + + freeze_secondary_cpus(cpu); +} + +static struct syscore_ops poweroff_syscore_ops = { + .shutdown = sc27xx_poweroff_shutdown, +}; + +static void sc27xx_poweroff_do_poweroff(void) +{ + regmap_write(regmap, SC27XX_PWR_PD_HW, SC27XX_PWR_OFF_EN); +} + +static int sc27xx_poweroff_probe(struct platform_device *pdev) +{ + if (regmap) + return -EINVAL; + + regmap = dev_get_regmap(pdev->dev.parent, NULL); + if (!regmap) + return -ENODEV; + + pm_power_off = sc27xx_poweroff_do_poweroff; + register_syscore_ops(&poweroff_syscore_ops); + return 0; +} + +static int sc27xx_poweroff_remove(struct platform_device *pdev) +{ + if (pm_power_off == sc27xx_poweroff_do_poweroff) + pm_power_off = NULL; + + regmap = NULL; + return 0; +} + +static struct platform_driver sc27xx_poweroff_driver = { + .probe = sc27xx_poweroff_probe, + .remove = sc27xx_poweroff_remove, + .driver = { + .name = "sc27xx-poweroff", + }, +}; +module_platform_driver(sc27xx_poweroff_driver); + +MODULE_ALIAS("platform:sc27xx-poweroff"); +MODULE_DESCRIPTION("Spreadtrum SC27xx PMIC Poweroff Driver"); +MODULE_LICENSE("GPL v2");