From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75CE7C43441 for ; Tue, 27 Nov 2018 11:57:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 23274208E7 for ; Tue, 27 Nov 2018 11:57:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="ez6lV4ys" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 23274208E7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=microchip.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731092AbeK0Wyy (ORCPT ); Tue, 27 Nov 2018 17:54:54 -0500 Received: from esa5.microchip.iphmx.com ([216.71.150.166]:22924 "EHLO esa5.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730122AbeK0Wyx (ORCPT ); Tue, 27 Nov 2018 17:54:53 -0500 X-IronPort-AV: E=Sophos;i="5.56,286,1539673200"; d="scan'208";a="21574163" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES128-SHA; 27 Nov 2018 04:57:13 -0700 Received: from NAM04-BN3-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.76.37) with Microsoft SMTP Server (TLS) id 14.3.352.0; Tue, 27 Nov 2018 04:57:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector1-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jMjS//5o5chhVNv5oD2mdk6g8h2JVhMs2bhRbOyql1Q=; b=ez6lV4ysv82yLxwHHbVOLKXQWRb+37wItcsFL+3cTbI3hlDQbu6bZNbeS52WqhPxuHUimcMyvEAMIQ8PoiQ1Z0p8aLsPylBjry3z6iuoSkdbgJCKcBFNTKu69kv03VewRhO6CqkqrTtW/TYNTovXepFl4WqG6YRFrD421U2ZJJM= Received: from BY2PR11MB0744.namprd11.prod.outlook.com (10.163.112.142) by BY2PR11MB0582.namprd11.prod.outlook.com (10.163.159.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1361.16; Tue, 27 Nov 2018 11:57:10 +0000 Received: from BY2PR11MB0744.namprd11.prod.outlook.com ([fe80::6c42:c3b0:5734:1681]) by BY2PR11MB0744.namprd11.prod.outlook.com ([fe80::6c42:c3b0:5734:1681%5]) with mapi id 15.20.1361.019; Tue, 27 Nov 2018 11:57:10 +0000 From: To: , , , , , , CC: , , , , Subject: [PATCH v2 1/5] regulator: act8945a-regulator: Implement PM functionalities Thread-Topic: [PATCH v2 1/5] regulator: act8945a-regulator: Implement PM functionalities Thread-Index: AQHUhkhTDeKLa/I6/0WndkFbPHNFbA== Date: Tue, 27 Nov 2018 11:57:10 +0000 Message-ID: <1543319801-19100-2-git-send-email-claudiu.beznea@microchip.com> References: <1543319801-19100-1-git-send-email-claudiu.beznea@microchip.com> In-Reply-To: <1543319801-19100-1-git-send-email-claudiu.beznea@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0173.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::17) To BY2PR11MB0744.namprd11.prod.outlook.com (2a01:111:e400:52de::14) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Claudiu.Beznea@microchip.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [94.177.32.154] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BY2PR11MB0582;6:y3mlOozDTebQpHM6lSyh1hxQeQXrTlHXLnY2eQaK4LqKPYuYpJYBKYVr+wqtO5BHVzmPDuaJfLDwQ9pTuF8IbBpV4xs8yRcpqWfcnLeucW+5Ve2R+cFopmyRTc83aS+LlWgSMjic1J9F1F+Hsnf3BMshcxd28nc7uQkMcBZG7xZIFett3Vk9AnqClEsnp5MsR7h88tgPpLIhFZaPxmwIa9Iyl3bsFdyUzdyuAVdug4Gt5iogDWA5ZkO2/zTKIhpUvEuZGoaAdrMAKuneHEgYxLoIhESrXfKzO7N9mZdWiNakaZmxXGInPpBeZi4O4MjeoVu+lLPhG1yxvMiudZqy37KPKN8a+t1NWSY/l3kxvBH+ylGTNmxPMnyzNqG+FNOCz+FjrtAhho+HZmm72DsaZQyjCuXQ4TvW+fmvFD+X5jEVeFpHEWn9xCZDrMLwD+/nwuoBvidV2lYquHmJjKYa3DV9JHV6aihp8sSkkECp95E=;5:lm+WE59/5Pr07DwYIfDEagx5RMFZLKmxMYzF4B9jigBYTYlvqgj5G5f2gMSzPTVb4rrsF2IflcdmAGOWkDi3Qj7oPHzV5ey+Uvx4QRjMdoynGoUEQMzbfsy8dKsRpksln3woTkMFmDMzYBwQaeCZeNM0Wk8CHkNtqDypk8jXDiY=;7:a6pcfJwVXtZPwVlDix5jYzMxkcMvBG5Wjq9HTCsr1vtfbhlxpfZiSF2hC+9Q7YBCAZJBkDE7QIlbSK5uNMO8+zHQ4izz8j20z3xqQQltVcmYVj77P7D5OxxYC49HA2pn+is7ku3zreWjaZlkwD1+/g== x-ms-office365-filtering-correlation-id: 30eec1ee-0725-471f-c01a-08d6545f75e5 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:BY2PR11MB0582; x-ms-traffictypediagnostic: BY2PR11MB0582: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231443)(944501410)(52105112)(3002001)(10201501046)(148016)(149066)(150057)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(201708071742011)(7699051)(76991095);SRVR:BY2PR11MB0582;BCL:0;PCL:0;RULEID:;SRVR:BY2PR11MB0582; x-forefront-prvs: 086943A159 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39860400002)(396003)(346002)(376002)(136003)(366004)(189003)(199004)(4326008)(66066001)(106356001)(575784001)(86362001)(5660300001)(97736004)(186003)(39060400002)(99286004)(6486002)(52116002)(26005)(105586002)(478600001)(36756003)(256004)(14444005)(2501003)(110136005)(54906003)(386003)(6506007)(107886003)(72206003)(7736002)(102836004)(305945005)(6116002)(3846002)(76176011)(71200400001)(68736007)(14454004)(71190400001)(6636002)(2906002)(476003)(2616005)(6436002)(25786009)(446003)(53936002)(316002)(8936002)(8676002)(11346002)(486006)(81156014)(6512007)(81166006);DIR:OUT;SFP:1101;SCL:1;SRVR:BY2PR11MB0582;H:BY2PR11MB0744.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: V1FNl5u32tQl9tabEUmpa+bbXW8dRVNxPHOQIRqjr3ARRpwJoa6ygMXELJgv6wZ+uagShZNFlaQah3sMpuoCS3+fxvRQ2hxUA0OfCgjzAVmEgwbFXuRIflnKXRODFQasrIYE6/Iql180lDGXb+V9H0oHFpUbKAYxVam5cMhBnboKyREE7Mih7ndUgz6efzGO5zoIf0ME+aAmM0ZjCzBXiyQVcWXwyXk3nJbN22jbQ7eLylVJOMVataH+k/aZXz+WgauZc/hoaYRHMmIlimip9g5iVc1QdGqpq2t1xw+8tOSImEdbfGA3XUSJI8YHubMaopISQ6G8UvlZtw2VkWTvRyUhOZukf2DOqEwyxOFJ218= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 30eec1ee-0725-471f-c01a-08d6545f75e5 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Nov 2018 11:57:10.0265 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR11MB0582 X-OriginatorOrg: microchip.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Boris Brezillon The regulator supports a dedicated suspend mode. Implement the appropriate ->set_suspend_xx() hooks, add support for ->set_mode(), and provide basic PM ops functionalities to setup the regulator in a suspend state when the system is entering suspend. Signed-off-by: Boris Brezillon [claudiu.beznea@microchip.com: remove shutdown function, use dev_pm_ops, fix checkpatch warning, adapt commit message, add LDO modes support, move modes constants to active-semi,8945a-regulator.h, remove rdevs from struct act8945a_pmic, add op_mode to act8945a_pmic] Signed-off-by: Claudiu Beznea --- drivers/regulator/act8945a-regulator.c | 186 +++++++++++++++++= +++- .../regulator/active-semi,8945a-regulator.h | 30 ++++ 2 files changed, 211 insertions(+), 5 deletions(-) create mode 100644 include/dt-bindings/regulator/active-semi,8945a-regulat= or.h diff --git a/drivers/regulator/act8945a-regulator.c b/drivers/regulator/act= 8945a-regulator.c index 8d71d9893d0d..f37d1a860407 100644 --- a/drivers/regulator/act8945a-regulator.c +++ b/drivers/regulator/act8945a-regulator.c @@ -18,6 +18,7 @@ #include #include #include +#include =20 /** * ACT8945A Global Register Map. @@ -28,20 +29,27 @@ #define ACT8945A_DCDC1_VSET1 0x20 #define ACT8945A_DCDC1_VSET2 0x21 #define ACT8945A_DCDC1_CTRL 0x22 +#define ACT8945A_DCDC1_SUS 0x24 #define ACT8945A_DCDC2_VSET1 0x30 #define ACT8945A_DCDC2_VSET2 0x31 #define ACT8945A_DCDC2_CTRL 0x32 +#define ACT8945A_DCDC2_SUS 0x34 #define ACT8945A_DCDC3_VSET1 0x40 #define ACT8945A_DCDC3_VSET2 0x41 #define ACT8945A_DCDC3_CTRL 0x42 +#define ACT8945A_DCDC3_SUS 0x44 #define ACT8945A_LDO1_VSET 0x50 #define ACT8945A_LDO1_CTRL 0x51 +#define ACT8945A_LDO1_SUS 0x52 #define ACT8945A_LDO2_VSET 0x54 #define ACT8945A_LDO2_CTRL 0x55 +#define ACT8945A_LDO2_SUS 0x56 #define ACT8945A_LDO3_VSET 0x60 #define ACT8945A_LDO3_CTRL 0x61 +#define ACT8945A_LDO3_SUS 0x62 #define ACT8945A_LDO4_VSET 0x64 #define ACT8945A_LDO4_CTRL 0x65 +#define ACT8945A_LDO4_SUS 0x66 =20 /** * Field Definitions. @@ -62,7 +70,12 @@ enum { ACT8945A_ID_LDO2, ACT8945A_ID_LDO3, ACT8945A_ID_LDO4, - ACT8945A_REG_NUM, + ACT8945A_ID_MAX, +}; + +struct act8945a_pmic { + struct regmap *regmap; + u32 op_mode[ACT8945A_ID_MAX]; }; =20 static const struct regulator_linear_range act8945a_voltage_ranges[] =3D { @@ -71,6 +84,143 @@ static const struct regulator_linear_range act8945a_vol= tage_ranges[] =3D { REGULATOR_LINEAR_RANGE(2400000, 48, 63, 100000), }; =20 +static int act8945a_set_suspend_state(struct regulator_dev *rdev, bool ena= ble) +{ + struct regmap *regmap =3D rdev->regmap; + int id =3D rdev->desc->id, reg, val; + + switch (id) { + case ACT8945A_ID_DCDC1: + reg =3D ACT8945A_DCDC1_SUS; + val =3D 0xa8; + break; + case ACT8945A_ID_DCDC2: + reg =3D ACT8945A_DCDC2_SUS; + val =3D 0xa8; + break; + case ACT8945A_ID_DCDC3: + reg =3D ACT8945A_DCDC3_SUS; + val =3D 0xa8; + break; + case ACT8945A_ID_LDO1: + reg =3D ACT8945A_LDO1_SUS; + val =3D 0xe8; + break; + case ACT8945A_ID_LDO2: + reg =3D ACT8945A_LDO2_SUS; + val =3D 0xe8; + break; + case ACT8945A_ID_LDO3: + reg =3D ACT8945A_LDO3_SUS; + val =3D 0xe8; + break; + case ACT8945A_ID_LDO4: + reg =3D ACT8945A_LDO4_SUS; + val =3D 0xe8; + break; + default: + return -EINVAL; + } + + if (enable) + val |=3D BIT(4); + + /* + * Ask the PMIC to enable/disable this output when entering hibernate + * mode. + */ + return regmap_write(regmap, reg, val); +} + +static int act8945a_set_suspend_enable(struct regulator_dev *rdev) +{ + return act8945a_set_suspend_state(rdev, true); +} + +static int act8945a_set_suspend_disable(struct regulator_dev *rdev) +{ + return act8945a_set_suspend_state(rdev, false); +} + +static unsigned int act8945a_of_map_mode(unsigned int mode) +{ + switch (mode) { + case ACT8945A_REGULATOR_MODE_FIXED: + case ACT8945A_REGULATOR_MODE_NORMAL: + return REGULATOR_MODE_NORMAL; + case ACT8945A_REGULATOR_MODE_LOWPOWER: + return REGULATOR_MODE_STANDBY; + default: + return REGULATOR_MODE_INVALID; + } +} + +static int act8945a_set_mode(struct regulator_dev *rdev, unsigned int mode= ) +{ + struct act8945a_pmic *act8945a =3D rdev_get_drvdata(rdev); + struct regmap *regmap =3D rdev->regmap; + int id =3D rdev->desc->id; + int reg, ret, val =3D 0; + + switch (id) { + case ACT8945A_ID_DCDC1: + reg =3D ACT8945A_DCDC1_CTRL; + break; + case ACT8945A_ID_DCDC2: + reg =3D ACT8945A_DCDC2_CTRL; + break; + case ACT8945A_ID_DCDC3: + reg =3D ACT8945A_DCDC3_CTRL; + break; + case ACT8945A_ID_LDO1: + reg =3D ACT8945A_LDO1_SUS; + break; + case ACT8945A_ID_LDO2: + reg =3D ACT8945A_LDO2_SUS; + break; + case ACT8945A_ID_LDO3: + reg =3D ACT8945A_LDO3_SUS; + break; + case ACT8945A_ID_LDO4: + reg =3D ACT8945A_LDO4_SUS; + break; + default: + return -EINVAL; + } + + switch (mode) { + case REGULATOR_MODE_STANDBY: + if (rdev->desc->id > ACT8945A_ID_DCDC3) + val =3D BIT(5); + break; + case REGULATOR_MODE_NORMAL: + if (rdev->desc->id <=3D ACT8945A_ID_DCDC3) + val =3D BIT(5); + break; + default: + return -EINVAL; + } + + ret =3D regmap_update_bits(regmap, reg, BIT(5), val); + if (ret) + return ret; + + act8945a->op_mode[id] =3D mode; + + return 0; +} + +static unsigned int act8945a_get_mode(struct regulator_dev *rdev) +{ + struct act8945a_pmic *act8945a =3D rdev_get_drvdata(rdev); + int id =3D rdev->desc->id; + + if (id < ACT8945A_ID_DCDC1 || id >=3D ACT8945A_ID_MAX) + return -EINVAL; + + return act8945a->op_mode[id]; +} + static const struct regulator_ops act8945a_ops =3D { .list_voltage =3D regulator_list_voltage_linear_range, .map_voltage =3D regulator_map_voltage_linear_range, @@ -78,7 +228,11 @@ static const struct regulator_ops act8945a_ops =3D { .set_voltage_sel =3D regulator_set_voltage_sel_regmap, .enable =3D regulator_enable_regmap, .disable =3D regulator_disable_regmap, + .set_mode =3D act8945a_set_mode, + .get_mode =3D act8945a_get_mode, .is_enabled =3D regulator_is_enabled_regmap, + .set_suspend_enable =3D act8945a_set_suspend_enable, + .set_suspend_disable =3D act8945a_set_suspend_disable, }; =20 #define ACT89xx_REG(_name, _family, _id, _vsel_reg, _supply) \ @@ -86,6 +240,7 @@ static const struct regulator_ops act8945a_ops =3D { .name =3D _name, \ .supply_name =3D _supply, \ .of_match =3D of_match_ptr("REG_"#_id), \ + .of_map_mode =3D act8945a_of_map_mode, \ .regulators_node =3D of_match_ptr("regulators"), \ .id =3D _family##_ID_##_id, \ .type =3D REGULATOR_VOLTAGE, \ @@ -124,13 +279,17 @@ static int act8945a_pmic_probe(struct platform_device= *pdev) { struct regulator_config config =3D { }; const struct regulator_desc *regulators; + struct act8945a_pmic *act8945a; struct regulator_dev *rdev; - struct regmap *regmap; int i, num_regulators; bool voltage_select; =20 - regmap =3D dev_get_regmap(pdev->dev.parent, NULL); - if (!regmap) { + act8945a =3D devm_kzalloc(&pdev->dev, sizeof(*act8945a), GFP_KERNEL); + if (!act8945a) + return -ENOMEM; + + act8945a->regmap =3D dev_get_regmap(pdev->dev.parent, NULL); + if (!act8945a->regmap) { dev_err(&pdev->dev, "could not retrieve regmap from parent device\n"); return -EINVAL; @@ -149,6 +308,7 @@ static int act8945a_pmic_probe(struct platform_device *= pdev) =20 config.dev =3D &pdev->dev; config.dev->of_node =3D pdev->dev.parent->of_node; + config.driver_data =3D act8945a; for (i =3D 0; i < num_regulators; i++) { rdev =3D devm_regulator_register(&pdev->dev, ®ulators[i], &config); if (IS_ERR(rdev)) { @@ -159,13 +319,29 @@ static int act8945a_pmic_probe(struct platform_device= *pdev) } } =20 + platform_set_drvdata(pdev, act8945a); + /* Unlock expert registers. */ - return regmap_write(regmap, ACT8945A_SYS_UNLK_REGS, 0xef); + return regmap_write(act8945a->regmap, ACT8945A_SYS_UNLK_REGS, 0xef); } =20 +static int act8945a_suspend(struct device *pdev) +{ + struct act8945a_pmic *act8945a =3D dev_get_drvdata(pdev); + + /* + * Ask the PMIC to enter the suspend mode on the next PWRHLD + * transition. + */ + return regmap_write(act8945a->regmap, ACT8945A_SYS_CTRL, 0x42); +} + +SIMPLE_DEV_PM_OPS(act8945a_pm, act8945a_suspend, NULL); + static struct platform_driver act8945a_pmic_driver =3D { .driver =3D { .name =3D "act8945a-regulator", + .pm =3D &act8945a_pm, }, .probe =3D act8945a_pmic_probe, }; diff --git a/include/dt-bindings/regulator/active-semi,8945a-regulator.h b/= include/dt-bindings/regulator/active-semi,8945a-regulator.h new file mode 100644 index 000000000000..9bdba5e3141a --- /dev/null +++ b/include/dt-bindings/regulator/active-semi,8945a-regulator.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2018 Microchip Technology, Inc. All rights reserved. + * + * Device Tree binding constants for the ACT8945A PMIC regulators + */ + +#ifndef _DT_BINDINGS_REGULATOR_ACT8945A_H +#define _DT_BINDINGS_REGULATOR_ACT8945A_H + +/* + * These constants should be used to specify regulator modes in device tre= e for + * ACT8945A regulators as follows: + * ACT8945A_REGULATOR_MODE_FIXED: It is specific to DCDC regulators and it + * specifies the usage of fixed-frequency + * PWM. + * + * ACT8945A_REGULATOR_MODE_NORMAL: It is specific to LDO regulators and it + * specifies the usage of normal mode. + * + * ACT8945A_REGULATOR_MODE_LOWPOWER: For DCDC and LDO regulators; it speci= fy + * the usage of proprietary power-saving + * mode. + */ + +#define ACT8945A_REGULATOR_MODE_FIXED 1 +#define ACT8945A_REGULATOR_MODE_NORMAL 2 +#define ACT8945A_REGULATOR_MODE_LOWPOWER 3 + +#endif --=20 2.7.4