Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1640047ybe; Tue, 3 Sep 2019 01:05:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqxm6hv4DRyg0uABoapO0JM3QDOX+HAnqr6r7gP8dZso+vmrrj7LvuYasufd+K8mDvQ9+RNc X-Received: by 2002:a63:c009:: with SMTP id h9mr28902746pgg.166.1567497900215; Tue, 03 Sep 2019 01:05:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1567497900; cv=pass; d=google.com; s=arc-20160816; b=vSI108tS12GIWiNX3CGQzOY6eaoCdGAsDVNqm4dEi7KMp/KEEPRIt+T4M2VDwZygvG ZvCcpPVp1AQptiEVEo7oZfONMLNx3gLHW148hE9sMhO5OjMdNKilPw4MXyhIYBnwB+sD dcdzSMGBSHvGRcFCL5jkW07/iJobjyw/k/0YaoDlgHNqWNuPwcDXvbJHAo6mdMsgOoYS f8hnHqXUl5FaHelVJvWFOfG9EDPge9e3U9hLzBFdvKL55nsXINKtl2lxfMhzTCJhok6t FBToyu5cKfHQxBBWM5MPfvkVzjy/CnLyLU2bMqFLH5k+FpnWuvA7Gf+DlZdrotO9kwI4 g8Nw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=11shAEnm54iYqWnxs1WQewo/2M+laZAnVa3TTLn3/cs=; b=00AEgsREW4V9NakBVsHkl9xmaUYceE5iW3iGPpZGgWhqBlkJfoLT8CpV1FN+6nQkxI LMHTl4FXoRs+MYWBHgNs/3Zrqc9In5ODZ9whQXVY+Gga9pbn6N0nNFWKPGs2yF12Ml3z 9JWyWpRpBnnGwmes0Y1uYZ1ugCgoTom9k5KmqJur+modwILbzbgSa7f77A7o7Gn3HNwL t7BLB2rr0McGYPgWUg8lvTyIlTFPckgll/0bvVhvy5IXhEzbfA6eSq9zM0uXYUzKQfwZ gXPBten1jIZdW8d948OJ8hlbgnZtoz/eBuY6wWcLsG7QVHp1YRiW1TvDTazsfLMPHWyA znhw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@toradex.com header.s=selector2 header.b="m3BbNl/W"; arc=pass (i=1 spf=pass spfdomain=toradex.com dkim=pass dkdomain=toradex.com dmarc=pass fromdomain=toradex.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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=toradex.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 126si17292741pff.111.2019.09.03.01.04.44; Tue, 03 Sep 2019 01:05:00 -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; dkim=pass header.i=@toradex.com header.s=selector2 header.b="m3BbNl/W"; arc=pass (i=1 spf=pass spfdomain=toradex.com dkim=pass dkdomain=toradex.com dmarc=pass fromdomain=toradex.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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=toradex.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728094AbfICIDw (ORCPT + 99 others); Tue, 3 Sep 2019 04:03:52 -0400 Received: from mail-eopbgr80139.outbound.protection.outlook.com ([40.107.8.139]:43751 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725878AbfICIDv (ORCPT ); Tue, 3 Sep 2019 04:03:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HATWzs65G1a5j8/WyS93znngx3GxOFUYQsP1F96/rtsXlyKT4xVG1eu7XwlG7Sa3dkjJCPGFJJgVvs5hnHGVCqe2JD+pFPI+ZRQ3wdHWbDk9kIeB+4f524dcq78v/gSVRYWPVNFQRNwtnYfevTuaecuVDt9306KZ1yjh34n9wmGc+WyqnvGQGzoIGZsXm7mrrDl3ruQKcAxYfB4ShfdVOPkkI9kOjxHFjqlrjVhAMMzeIBJ7b7w3DvXvWhqJVpM9SgS4lexMNHN0BGOlx3a8ILz35/H39hZ6yedJGtI6bcLzyeks9c5MDR39u0X6bjNr+CkjIZASHg+e0fUJIFgLBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=11shAEnm54iYqWnxs1WQewo/2M+laZAnVa3TTLn3/cs=; b=iRKAfLKLw1o+Mt/5sac+H8iJfrnQqaq44Nu5jRX/C/urmahr8qyZdl4vPMCeeGKCWWL86znlHz4m+CvPl8EhcgtIvorbhwaP9s6ZFJkmc2NDGnBMYcLZtEHzFTXdGsrW2r7Wqrc8wtpnDCp+sUDu6wKvhtErJjEvHxmzWXSATesYY1fhqOM/tNVX4eVhffQqX0DEos+hBqcoY5ZrJgohYbFRwgqRATTHAC55Nw/NpFahDgVvSAi2acbURn8TNvl9w/qGdRucHDzz+FoaL6boJFG6DonRWJg7dg/DP5ZkaXT4OpZJ7Tp2rwO6yooQk6C1b91zS+UX6Zib9xvaX8oiig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=toradex.com; dmarc=pass action=none header.from=toradex.com; dkim=pass header.d=toradex.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toradex.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=11shAEnm54iYqWnxs1WQewo/2M+laZAnVa3TTLn3/cs=; b=m3BbNl/W9xGPPF41pe4pfo+WM6fqCeWATnyQG+NTQHPnrUGgryn9ZqD0H5MEm3ar6PzUz+rqSCQ8QQ5XpC+L9Q+gTRpppiYtHY9g7OIIXmZSPDVVZUTu/eJovq/gkafiCP8PYrXpxwqyUKnVuaMytnJFETSuUV1vjCXl23s3GAw= Received: from VI1PR0502MB3965.eurprd05.prod.outlook.com (52.134.17.157) by VI1PR0502MB4014.eurprd05.prod.outlook.com (52.134.18.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.19; Tue, 3 Sep 2019 08:03:47 +0000 Received: from VI1PR0502MB3965.eurprd05.prod.outlook.com ([fe80::f59f:a307:9c53:63b9]) by VI1PR0502MB3965.eurprd05.prod.outlook.com ([fe80::f59f:a307:9c53:63b9%6]) with mapi id 15.20.2220.022; Tue, 3 Sep 2019 08:03:47 +0000 From: Philippe Schenker To: "linux-kernel@vger.kernel.org" , Mark Brown , Shawn Guo , Sascha Hauer , Liam Girdwood CC: "devicetree@vger.kernel.org" , Max Krummenacher , Rob Herring , Stefan Agner , Marcel Ziswiler , Mark Rutland , Luka Pivk , Philippe Schenker Subject: [PATCH 1/3] regulator: fixed: add possibility to enable by clock Thread-Topic: [PATCH 1/3] regulator: fixed: add possibility to enable by clock Thread-Index: AQHVYi4cgyK53mdiuEKJwWlDc8lstw== Date: Tue, 3 Sep 2019 08:03:46 +0000 Message-ID: <20190903080336.32288-2-philippe.schenker@toradex.com> References: <20190903080336.32288-1-philippe.schenker@toradex.com> In-Reply-To: <20190903080336.32288-1-philippe.schenker@toradex.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR0802CA0015.eurprd08.prod.outlook.com (2603:10a6:800:aa::25) To VI1PR0502MB3965.eurprd05.prod.outlook.com (2603:10a6:803:23::29) authentication-results: spf=none (sender IP is ) smtp.mailfrom=philippe.schenker@toradex.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [46.140.72.82] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d877e1cb-927d-4b96-94d8-08d730453f33 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:VI1PR0502MB4014; x-ms-traffictypediagnostic: VI1PR0502MB4014: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:478; x-forefront-prvs: 01494FA7F7 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(4636009)(39840400004)(376002)(346002)(136003)(396003)(366004)(199004)(189003)(6436002)(66066001)(81166006)(110136005)(54906003)(5660300002)(71200400001)(305945005)(2501003)(25786009)(476003)(81156014)(2616005)(44832011)(107886003)(6512007)(66446008)(99286004)(66946007)(66556008)(186003)(64756008)(66476007)(26005)(6486002)(71190400001)(4326008)(53936002)(446003)(52116002)(486006)(102836004)(11346002)(1076003)(6116002)(478600001)(86362001)(50226002)(14454004)(2906002)(36756003)(8936002)(76176011)(3846002)(6506007)(386003)(316002)(256004)(8676002)(7736002);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0502MB4014;H:VI1PR0502MB3965.eurprd05.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: toradex.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: mmJ8sopXh3iWVuvyJJzxjaNL1FjIVqc3hLJ7nkWOPvxQPJT7S0Zok+JGxpRZSEGKneGQiHs0PsWEqO1NqnFJW5m2pKfWengoVeQDLn13vCY1QDO+OujCmGRnD+oTH/aj4UnCxcR7pdBQFNjmBDQL+Wue546J/NoE8U9jEsbLHNJkAfgZQ1TDGmANG9wM6VWHDiPtI3JV/kPoDRuI1HB66ryBvYpM1Bk4BewI4fuiPZHyjxEMo16w7dEJt6yBj7026DjJZkcJ7aVN2EWBNhhlDjedRAAIKL2nl8ycm4CjopPFXJtbl9ysD5ySZ1euWyc9y5E3e4Gm3MgS7wubVVc/qKf8IOKAKQabJGG7fufLpYleszeRvjFYymppSjgvH5SBIg9GsBb/YFYjr/Eulczx1sUPZaLonXHVQefsJB/rujE= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: toradex.com X-MS-Exchange-CrossTenant-Network-Message-Id: d877e1cb-927d-4b96-94d8-08d730453f33 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Sep 2019 08:03:46.9644 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d9995866-0d9b-4251-8315-093f062abab4 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: to/U//IDPULCOxneSCX3lq2LH0vrLBKhmPjZJ4R3mfewjb9O+YF4bVcr+3PpwcIc42WYmq22JdMYJZbC6HoGrCw73CtMxWjf8SkxG7P52Rk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0502MB4014 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit adds the possibility to choose the compatible "regulator-fixed-clock" in devicetree. This is a special regulator-fixed that has to have a clock, from which the regulator gets switched on and off. Signed-off-by: Philippe Schenker --- drivers/regulator/fixed.c | 86 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index 999547dde99d..eadeca9a1a6c 100644 --- a/drivers/regulator/fixed.c +++ b/drivers/regulator/fixed.c @@ -23,14 +23,66 @@ #include #include #include +#include #include #include +#include + =20 struct fixed_voltage_data { struct regulator_desc desc; struct regulator_dev *dev; + + struct clk *enable_clock; + unsigned int clk_enable_counter; +}; + +struct fixed_dev_type { + bool has_enable_clock; +}; + +static const struct fixed_dev_type fixed_voltage_data =3D { + .has_enable_clock =3D false, }; =20 +static const struct fixed_dev_type fixed_clkenable_data =3D { + .has_enable_clock =3D true, +}; + +static int reg_clock_enable(struct regulator_dev *rdev) +{ + struct fixed_voltage_data *priv =3D rdev_get_drvdata(rdev); + int ret =3D 0; + + ret =3D clk_prepare_enable(priv->enable_clock); + if (ret) + return ret; + + priv->clk_enable_counter++; + + return ret; +} + +static int reg_clock_disable(struct regulator_dev *rdev) +{ + struct fixed_voltage_data *priv =3D rdev_get_drvdata(rdev); + + clk_disable_unprepare(priv->enable_clock); + priv->clk_enable_counter--; + + return 0; +} + +static int reg_clock_is_enabled(struct regulator_dev *rdev) +{ + struct fixed_voltage_data *priv =3D rdev_get_drvdata(rdev); + + if (priv->clk_enable_counter > 0) + return 1; + + return 0; +} + =20 /** * of_get_fixed_voltage_config - extract fixed_voltage_config structure in= fo @@ -84,10 +136,19 @@ of_get_fixed_voltage_config(struct device *dev, static struct regulator_ops fixed_voltage_ops =3D { }; =20 +static struct regulator_ops fixed_voltage_clkenabled_ops =3D { + .enable =3D reg_clock_enable, + .disable =3D reg_clock_disable, + .is_enabled =3D reg_clock_is_enabled, +}; + static int reg_fixed_voltage_probe(struct platform_device *pdev) { + struct device *dev =3D &pdev->dev; struct fixed_voltage_config *config; struct fixed_voltage_data *drvdata; + const struct fixed_dev_type *drvtype =3D + of_match_device(dev->driver->of_match_table, dev)->data; struct regulator_config cfg =3D { }; enum gpiod_flags gflags; int ret; @@ -118,7 +179,18 @@ static int reg_fixed_voltage_probe(struct platform_dev= ice *pdev) } drvdata->desc.type =3D REGULATOR_VOLTAGE; drvdata->desc.owner =3D THIS_MODULE; - drvdata->desc.ops =3D &fixed_voltage_ops; + + if (drvtype->has_enable_clock) { + drvdata->desc.ops =3D &fixed_voltage_clkenabled_ops; + + drvdata->enable_clock =3D devm_clk_get(dev, NULL); + if (IS_ERR(drvdata->enable_clock)) { + dev_err(dev, "Cant get enable-clock from devicetree\n"); + return -ENOENT; + } + } else { + drvdata->desc.ops =3D &fixed_voltage_ops; + } =20 drvdata->desc.enable_time =3D config->startup_delay; =20 @@ -191,8 +263,16 @@ static int reg_fixed_voltage_probe(struct platform_dev= ice *pdev) =20 #if defined(CONFIG_OF) static const struct of_device_id fixed_of_match[] =3D { - { .compatible =3D "regulator-fixed", }, - {}, + { + .compatible =3D "regulator-fixed", + .data =3D &fixed_voltage_data, + }, + { + .compatible =3D "regulator-fixed-clock", + .data =3D &fixed_clkenable_data, + }, + { + }, }; MODULE_DEVICE_TABLE(of, fixed_of_match); #endif --=20 2.23.0