From patchwork Fri Feb 23 03:32: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: 129325 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp135212lja; Thu, 22 Feb 2018 19:33:14 -0800 (PST) X-Google-Smtp-Source: AH8x224r9flFddD1dK7sccLB+xNOLMl8Hpl/PZNPJdnbNZ552Nvl6sjbUGb+spw+gg3Ok9i++aQn X-Received: by 2002:a17:902:47:: with SMTP id 65-v6mr315658pla.194.1519356794291; Thu, 22 Feb 2018 19:33:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519356794; cv=none; d=google.com; s=arc-20160816; b=AENiC1bTBd5Yql2tMQSgH3FIAWFbAAPxs4yvBoguZoQLNXVf0XqpZxGrT3bDAoPHgt U1TWyvWWRhbe4K2enASAcD8WUFH3OF30G1BwHX8zv9tbY+LkGUSkA+0BsRNmob3e6rdA SbQAjtZaG0At+aGuUEuW5cFW0u+1cMvO2BsMWM50Md8/gpBYW/6Ks2Zf0PbklqCGkovq meqfxY62C5wyFnvlkP7mgn8QGXju1u5OY0kL/k+XmSafJYYUUnreO1ov2YvuDSV5OoYo hCmNQPO/EXPXQtL4ql6HHhAIJ3ISBAwMkdx4a3stKLhPJO0cyLseyvBx6Q4gcKhBGWcH KvJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=p5UP8tKsJlyow/olRuKb+wVuvfERDlKmrWa9xZbSlsk=; b=UcC4h9z55S0UGZS3OZ5bMqaryMt3i53XD4wKNUmFKrXMVCH8y37sTwwxAVg/5M0qoW udhUcBHT3Ye+DiizNKT60Y8nfB/c1nB2qgD0mjt1W54FcGCH7zHpQjQAwxlFxHQb8Wd9 r/Dmapw93H20qIibH/VJB06A3WOgGDCVbSJKKBu46QRRtWuNt0Hp1T7EmkxFyE+iOq6W sATL4N4wOc33n6zWZsS/nzPn/Hs9NVK+f2vgtklbWs5r1bAr5b3Bz4btqDxDrW28gtX6 liij2OEY+byY+18N/HV/ALtRmatf/7XiXviC9CUWzCrOAAnX+lGanjMiMyrJK153bpSc uzLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RarUVOA6; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o81si1095150pfk.67.2018.02.22.19.33.13; Thu, 22 Feb 2018 19:33:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RarUVOA6; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751314AbeBWDdJ (ORCPT + 11 others); Thu, 22 Feb 2018 22:33:09 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:41067 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751274AbeBWDdI (ORCPT ); Thu, 22 Feb 2018 22:33:08 -0500 Received: by mail-pg0-f67.google.com with SMTP id q27so1261288pgn.8 for ; Thu, 22 Feb 2018 19:33:08 -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=p5UP8tKsJlyow/olRuKb+wVuvfERDlKmrWa9xZbSlsk=; b=RarUVOA6SwMYRlCutIM1tWq5PlxKbVFN4cmxRf+YeZngpgOJT6FgEnadSGoy+WL5TJ 984UcUdEmJjAol+H1YX9iJTjdYOMue3ySa8PT4R+5MeDF2wLbEsD4oMUTCfuSz2KUAIu v6RY4VRfjmX47QsdyFgCUa0mIASJUhZI5uicg= 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=p5UP8tKsJlyow/olRuKb+wVuvfERDlKmrWa9xZbSlsk=; b=doPzoyyZkolAyvRTe3U+ZijBQxzgRH2STZdOo01AMFEYD6ee7uf7Fm5my6dHUH2Hl1 EvUS40/o5NKvU/mzoY3LzswTSIACCX8P9Xkoq3AQYGU/5UzCsExzzN+Ql3Aqm9vzWhPO y4xbPQBaP7F0JpgnKGuEUfCQp6Zd6JXbknira66xiKRLhp0IFrfRphgQ7gnw0HwgodCH s9t8yL5ve6S1kijrsLDrFuCvGgz4cWS4kJ47Ux1bNQ/wbzA6mSipPqDBh92oStDX9YFY 73TeVLCQklCxa8xP9dnck43jQJzE3YAqBhSWSbzmPqwjFu7kq3R1FukqZ520ak/9pfbr aQsA== X-Gm-Message-State: APf1xPC7EeE4ADZtn6M6ryW+S7wm5YW97TcuaszyV7rJvWCVmrK+kVvf DwU9k0KeCeZSrQsB+v/R2Scb6Q== X-Received: by 10.99.97.86 with SMTP id v83mr260856pgb.138.1519356787921; Thu, 22 Feb 2018 19:33:07 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id o18sm1661621pgd.26.2018.02.22.19.33.05 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Feb 2018 19:33:06 -0800 (PST) From: Baolin Wang To: sre@kernel.org Cc: broonie@kernel.org, baolin.wang@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v3] power: reset: Add Spreadtrum SC27xx PMIC power off support Date: Fri, 23 Feb 2018 11:32:38 +0800 Message-Id: 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 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 v2: - Change to build-in this driver. 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 | 64 +++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 drivers/power/reset/sc27xx-poweroff.c -- 1.7.9.5 diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index ca0de1a..01543f5 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 + bool "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..e3925a9 --- /dev/null +++ b/drivers/power/reset/sc27xx-poweroff.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018 Spreadtrum Communications Inc. + * Copyright (C) 2018 Linaro Ltd. + */ + +#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 struct platform_driver sc27xx_poweroff_driver = { + .probe = sc27xx_poweroff_probe, + .driver = { + .name = "sc27xx-poweroff", + }, +}; +builtin_platform_driver(sc27xx_poweroff_driver);