From patchwork Wed Jul 20 09:40:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 9239273 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 0D336602F0 for ; Wed, 20 Jul 2016 09:51:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F099C26C9B for ; Wed, 20 Jul 2016 09:51:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E511527A98; Wed, 20 Jul 2016 09:51: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=-4.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ECBEB26C9B for ; Wed, 20 Jul 2016 09:51:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bPo83-0004oH-Nv; Wed, 20 Jul 2016 09:49:23 +0000 Received: from mail-by2nam01on0063.outbound.protection.outlook.com ([104.47.34.63] helo=NAM01-BY2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bPo7z-0004jo-Ti for linux-arm-kernel@lists.infradead.org; Wed, 20 Jul 2016 09:49:21 +0000 Received: from BN3PR0301CA0082.namprd03.prod.outlook.com (10.160.152.178) by DM5PR03MB2473.namprd03.prod.outlook.com (10.168.233.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.544.10; Wed, 20 Jul 2016 09:48:56 +0000 Received: from BN1AFFO11FD029.protection.gbl (2a01:111:f400:7c10::180) by BN3PR0301CA0082.outlook.office365.com (2a01:111:e400:401e::50) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.544.10 via Frontend Transport; Wed, 20 Jul 2016 09:48:56 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none; nxp.com; dmarc=fail action=none header.from=nxp.com; nxp.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD029.mail.protection.outlook.com (10.58.52.184) with Microsoft SMTP Server (TLS) id 15.1.534.7 via Frontend Transport; Wed, 20 Jul 2016 09:48:56 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u6K9mT79026979; Wed, 20 Jul 2016 02:48:48 -0700 From: Peter Chen To: , , , , , , , , Subject: [PATCH v3 2/6] power: add power sequence library Date: Wed, 20 Jul 2016 17:40:25 +0800 Message-ID: <1469007629-31757-3-git-send-email-peter.chen@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1469007629-31757-1-git-send-email-peter.chen@nxp.com> References: <1469007629-31757-1-git-send-email-peter.chen@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131134817371325783; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(229853001)(85426001)(77096005)(47776003)(33646002)(189998001)(36756003)(68736007)(2906002)(356003)(8666005)(97736004)(5001770100001)(7846002)(305945005)(81156014)(81166006)(4326007)(86362001)(106466001)(15975445007)(8676002)(76176999)(50986999)(2201001)(92566002)(104016004)(8936002)(50466002)(2950100001)(2171001)(87936001)(48376002)(105606002)(6806005)(19580395003)(11100500001)(586003)(50226002)(19580405001)(5003940100001)(7059030)(2004002)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR03MB2473; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD029; 1:ysD7hkgtyWjz14wwbOWPzeEOKzOY73Jd1SQGwexT7hPrF5FS7+NrDPqH3seOJiWNrySk+hYTrPt+yfNbSXuR6k7IhuGl+T/PcrsNwuZURtlq16nrSxCg2Ur+bEnqWPc3wPNS8U7wvYoNUNuT4vG6lUwQqHryZduaIr8eI4IRsZWQU2xDh7O35BYQuwF9NQeo9Z2+QBV1UvQF1qSC4gR8mg1qgpc3xV+jGnNw5mTDvQSTHmXDkCDJX+oEc/oA2O6Gg83MTQDd3Sh6X4xnCoqTTnACZGcl098KQtp5B6z9phC8zPQ1Yakk6DZVLeeME3EkX5D3t1eruF2Yaxk7UxTPUFY/9VrTMzOYHmamdaY65g6u/CRftedlcmF+m2MzIS/fv9R3zDkhtiIm/NfAIKXu3KscC13Q7i8OXQXD+xw6hiFYNraFEaKdwQPs9g2VyFUJP/3bHkCquRj/t7G2hTrQfO3JOhz3zBSK9myJHqPFe6D3TJW5gdsQHu44wEqSGx0d8PF7hASW9c+4hJr4VeDyRnTw8C8bKesuE6QytrkFNafZNObEvBXChXzOV2eabkmBo8stNyLOOwe3DhZYJ9do/qQuMed3aQF2fx6F7B9iXn7/LKbT2BcPeNs7Hd99qAaF593d9CdFa1CaFGf0kPuvNgiTXR6bopIL/xvcVu/vP7I6+PA+8GHQjpqKZppn1TUZOgSs8fRWiP+QLFY8bymJL++nDvaw/ijwXnWGq3e/lHSv32JrAShC5tHOsqOnH7Da MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: f9f9e4d5-f37a-478b-23f6-08d3b083118f X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2473; 2:aNWZbE7+KG8IQq+xAMr3JX0AqWG/zXnQvy/r52LG85e968pjxsCoTsemes9ziWj6KqGk6z8Anx7EyNELsWOE85LnRcHXQ9fzFHeKetY98hgY1kN8TePtUyWANKBEZiZ6/QWoX2MvcsVQDVPC0W+OUKCWW+PLUmh5HMPl1TyboQyhoYCU2uzMb2n/SSFS+I8J; 3:wDie5FrvvDCd7CozMedE5Qna9VSovoXfyAJQ0HggsM37f4wA0ZjyCo9u1LKyePmty9rRwJXBZidaAlZaZu0wzVK0EoU+Pq8JYO+b2BuiUfSh1O4Js+cGHo6LEEBoHCyHF8rMWu/7ium1m9SpV8P8RQQc/jWvRepYZJwpESpkTtlSDEQ9gow08Uc5oL5tkQLdznLNI24aKJ7OujS2Ak/4D8Epu42P1bmLxefYfXK0H0g=; 25:BpX+rWgzuwzKXAuPUtDnyWXdQ+tHB9B8lbEQF+DljRNwxiiwvQuljtM2cZN+CwbBK1XWUZyYzEw3TodIsN+S/9JEGoY5b9j6XsmEmVbgYqQcfxfiaa83u8Fjd3n2q7i6ZyPuK7o/RNlkzUL3sIWtEgFt/hN1CpaCQRIYZ/r7nIfLRMZ5A54AT3hDsqsIp74eBrzwLZUE3J0wFt6lpsYLUbT0wQ0vuqQ8+Bz/yj5Adl8oDI7WhSdQS/9/zhtdwwW4VOvt1EcrOSZyewzQZrsXL9inrIc9Rsh2S2LQUo5L5+hxseZhDUMbavWcRKTBqu4YQlKC2Z1HsTO+nQwbIuNY3iqC12btsw6r7ZFoQlAJqxxDHLjUKr/vECCoByK0HlANH/0Z8fAq41Ltnt6FxbKWeObnj/cuK/07319eDEIcfV0= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM5PR03MB2473; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2473; 31:iI8Ksu8po6PYUTPT7cfkT61/adBmVq7e72CRCI5OVz4qnFFjlaIdZvkKDgts0S+GXzG+51hWbF5HX4s2lnZEEm7xgM7cgEncQfyV9p/Tr/cl0FuubPXaLoQCs6p04uSXqQyd6MNezx/UX/stnNkxbU/3P7rGg0UGgS1cmEp4OpU2ANCcpdrBY7idICV0tebLc5WKHU9a+NQPWiFyNBUvQA==; 4:fhXb4xYQKBEBuYtGwFxu9fiCO3ykyPMa0gGkFVlj3vzpGWyVA0jpsKjWJAD5NJBDTR2d9M/o1R48gMZN1z1/nKv8bB2n2XABr1BR00aNsWfAmxYCeI0KLx01OHdCfzaGTo6Jt7qtXJjeK66xS9gEDPnUu/f6V0aXjC+Cszs6t2mdNXaclTt+ZD7t3W6w73Hgpoawy73qQjwFs5+5WuC0+1aKAxh3gFhbAzmXrL5vSVHxkAApHFyiuCofRrjNoDDzN7vapzylmxXL/DH20o1lgQtSGy9dyPb+DemKBe0h+ryjQwnl8O42VHeAe3AsbmoFyvwBLUWrkAfovh4qnXoZ+MUhWsw5Z8hhBvu5vZF5ZQjrbOnMOeFXmYOTkS/09Sg58+e+wFX/dGiVQ2bPh15X4A3kwLoPJSWPALNRMbVDe9qyDTUMsMQqMw9ipkKvKrX7qpAYA7rtRxf3ha5Fv+7MWtkGgO4EB5vuvF/stCb4GOIHn091DgaB6URnUm6G36Lah7YC2jxR7V3rvTYjAeqz66Ihcn6hqlwy0J3DWxvyMOGFAPODaIfVlXYifHYmlHXt8WMtGOrIr/fhTAByNks4glX+6vIHPu3K8uuWFwG9Yc9qsrDk4bBaXqBI19SgFko/U1qTQAnU108cAuAy2R48gg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(250305191791016)(22074186197030)(9452136761055)(185117386973197)(84791874153150); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13018025)(8121501046)(13024025)(13023025)(13015025)(13017025)(5005006)(10201501046)(3002001)(6055026); SRVR:DM5PR03MB2473; BCL:0; PCL:0; RULEID:(400006); SRVR:DM5PR03MB2473; X-Forefront-PRVS: 000947967F X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR03MB2473; 23:5ZN7TT6GdpxhmzbzAI7iOGnmDu/GGGRDjgXUadFFw?= =?us-ascii?Q?Cw1ZrzNJZ++4C5BiOjIRe3Fv/9jcRgkpZ80dCXzjEGHsOe3IW5q3lFbKiKWV?= =?us-ascii?Q?1w8BNQap8uoVSQbWzD0AQ5eIRLuxqcku+R6g7UXfqeuUhiliJdYEnq0x23UH?= =?us-ascii?Q?Oj5ErK5BZr9QwUZrZ7lSAkV0kJbqlS5aVz4tk+ZlurVzlOMl7PMXr1dpgmuE?= =?us-ascii?Q?UFLNlSNxqpIJFrTUfqaajqIlqt8zRaLKC/p3wuRiVhS9hHaeyfvvi4c6FRLl?= =?us-ascii?Q?alEKW551+Ra8B3B+yE9AGh8ciDJlCxaRwzvTK7NY5lQOhGFP1/loGbKM4cI4?= =?us-ascii?Q?QkixxyB5JOCgZpx5lGZb3uus5T8zzrh+73BIhVbPrVUhsNU3z5okp2f0ZlAX?= =?us-ascii?Q?d0inbvA7awXFLDuo/E/Ay1qnW5vQSy8aEmRhA5Op9FT33OygKNmrluWHf81i?= =?us-ascii?Q?dw4dXwjWz9TWRAzPGt7QGvxl6VBiiO9Eh7ilV/ZWaHnaXHFawGafKmDnX4my?= =?us-ascii?Q?HGF94wMT3coDMqAZB0iJUUwn8JvAPPr+CZbVXKyyzYtGrLp7n2eGNw4566Da?= =?us-ascii?Q?GVtZTsSQ5hfucUiRyOfHTFAc7KNH/vr0BFJywHu6VJI1qvk32Vl/fdJGzHsP?= =?us-ascii?Q?sm9Xz+qKms0DM40W58F6DrSJiO3jzHnr178c2Wa9z+H2qSbMmhjivD4JsbP1?= =?us-ascii?Q?rj0W+JWsR6gh0ilUNtmKuXtJQvz5p3nNpEAIWIyNschXuV4bhPSkCYuPRXKG?= =?us-ascii?Q?jw4cPSxG/MwCUFm3wCEpn5h3a6f6Kf0nf/bj4r5cDfMgbNIGNCZZvziMAgJZ?= =?us-ascii?Q?YBhI2QYHfHEbkraiTqC2PNETbzSPzrF0ia119DV8P2wqACBL0gOPNDcH0smy?= =?us-ascii?Q?g+PZDTGciFw5Nhr6L6QZS9bmBSUDx8F9n59XB/gc10IYTNVycaRTLbDnDWzH?= =?us-ascii?Q?CjiNVX6y71mCHi+rDAqiYSX4tS906jZByrC55+L/iovAJVrNujh7O8YWJsvf?= =?us-ascii?Q?3Ijy3ISCrO1noQz6mhc29NgeYxUmAOTXhv/6CPYHsV4KAPwgHjabAnmss/o3?= =?us-ascii?Q?2ubeQCipc7jVqlTxKYqlUR+CppACffVMpCBV2TQNXwsFJXM9T6M4sG61rAe2?= =?us-ascii?Q?3UKM6PT1tsHNGD4w7cHmDVmVTLcyIbWEG+AOF1zseSKJYS555DgeJvXE89lk?= =?us-ascii?Q?Xabok09xrWleuenu6r1v+3IRw1yRF/NjH5bj/SZEolw2P1pioDY8YnbNOJl2?= =?us-ascii?Q?zf/odGLINcQRl6Zi6Y=3D?= X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2473; 6:81GQ9K85jkMCVFs9IomcfKqtodwores8fmIMuuH4eoyPsIdptV8qEUeIWMRejGRKXbsljAtsJ8trYDLImkWeaX6snEXTfIoSrVgggq6GpTNYFj09bFTz/ob0u0YL3t45V7SGrANFZhEt6heC+cCplrzAPxsWqMBpwwRl+v1WgnQK0oq29pIKiX5w/sb6RGOWv9bzweBvZLadvbfWpaRjAxcPZmCzghM79h0k3Xp7h/PgJdYFUeFpBqxtx/4ZDo1D/q06mdu+PSrLl3swP5YmMHot/jnLACOHxZqwSI6qJl4=; 5:0pI3dx1pY1s/DSLTkgqiTv68fEajtsIRh9wu553od5D5L9UkSMnRvMe59iXLGA2xIbsCfCZuR/uKYVfC6ALPdspIXvT1yBAnf4Ln0y8009mhsusMLfJurYPJ6Owb8794SgibG/bskACGOlsaSSzsrQcJR2hoNL+gjnVOAVtvYXM=; 24:Ct5naevO4UbfWBwc6OyCxH/r2tT7+1Frz4o36mz31MEng+A3Dr9S7NZh/UKVF3ad7HEzpV9rzO5AwdY75KoQDQWE2NNjsnwmlizEwzhKw7U=; 7:KXaNh3T154n0sfu4qSBE/5H6+ek0f9prfO7SC/PC6S6f138Fy/3nAZ/Cd/H6sP2qQ8Ieq7WzNdQOTEmxXsSgurCYzpu0si6EmC9e1VWLReAJ3NXRCvLcvsWZFrHJyt0d077PWsbvh3PHBwgvpg/ut6N7kFhWdMIBTllGvL2TyA4r7HpC148xdY9nK4ZtFae73LoWSz1bG0yYYmK2W4MB5zJ6H/Jgr2P67N3Dlipd96j17xmecB6cjkyYHniIHvd1 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2016 09:48:56.1029 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2473 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160720_024920_094678_EEAFD1B5 X-CRM114-Status: GOOD ( 22.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, k.kozlowski@samsung.com, stephen.boyd@linaro.org, oscar@naiandei.net, arnd@arndb.de, pawel.moll@arm.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, s.hauer@pengutronix.de, linux-usb@vger.kernel.org, mail@maciej.szmigiero.name, troy.kisky@boundarydevices.com, stillcompiling@gmail.com, Peter Chen , p.zabel@pengutronix.de, festevam@gmail.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We have an well-known problem that the device needs to do some power sequence before it can be recognized by related host, the typical example like hard-wired mmc devices and usb devices. This power sequence is hard to be described at device tree and handled by related host driver, so we have created a common power sequence library to cover this requirement. The core code has supplied some common helpers for host driver, and individual power sequence libraries handle kinds of power sequence for devices. pwrseq_generic is intended for general purpose of power sequence, which handles gpios and clocks currently, and can cover regulator and pinctrl in future. The host driver calls pwrseq_alloc_generic to create an generic pwrseq instance. Signed-off-by: Peter Chen --- MAINTAINERS | 9 ++ drivers/power/Kconfig | 1 + drivers/power/Makefile | 1 + drivers/power/pwrseq/Kconfig | 20 +++++ drivers/power/pwrseq/Makefile | 2 + drivers/power/pwrseq/core.c | 71 ++++++++++++++++ drivers/power/pwrseq/pwrseq_generic.c | 151 ++++++++++++++++++++++++++++++++++ include/linux/power/pwrseq.h | 50 +++++++++++ 8 files changed, 305 insertions(+) create mode 100644 drivers/power/pwrseq/Kconfig create mode 100644 drivers/power/pwrseq/Makefile create mode 100644 drivers/power/pwrseq/core.c create mode 100644 drivers/power/pwrseq/pwrseq_generic.c create mode 100644 include/linux/power/pwrseq.h diff --git a/MAINTAINERS b/MAINTAINERS index 68a90d0..6fd879f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9243,6 +9243,15 @@ F: include/linux/pm_* F: include/linux/powercap.h F: drivers/powercap/ +POWER SEQUENCE LIBRARY +M: Peter Chen +T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git +L: linux-pm@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/power/pwrseq/ +F: drivers/power/pwrseq/ +F: include/linux/power/pwrseq.h/ + POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS M: Sebastian Reichel M: Dmitry Eremin-Solenikov diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index acd4a15..f6aa4fd 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -515,3 +515,4 @@ endif # POWER_SUPPLY source "drivers/power/reset/Kconfig" source "drivers/power/avs/Kconfig" +source "drivers/power/pwrseq/Kconfig" diff --git a/drivers/power/Makefile b/drivers/power/Makefile index e46b75d..4ed2e12 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -74,3 +74,4 @@ obj-$(CONFIG_CHARGER_TPS65217) += tps65217_charger.o obj-$(CONFIG_POWER_RESET) += reset/ obj-$(CONFIG_AXP288_FUEL_GAUGE) += axp288_fuel_gauge.o obj-$(CONFIG_AXP288_CHARGER) += axp288_charger.o +obj-$(CONFIG_POWER_SEQUENCE) += pwrseq/ diff --git a/drivers/power/pwrseq/Kconfig b/drivers/power/pwrseq/Kconfig new file mode 100644 index 0000000..188729e --- /dev/null +++ b/drivers/power/pwrseq/Kconfig @@ -0,0 +1,20 @@ +# +# Power Sequence library +# + +config POWER_SEQUENCE + bool + +menu "Power Sequence Support" + +config PWRSEQ_GENERIC + bool "Generic power sequence control" + depends on OF + select POWER_SEQUENCE + help + It is used for drivers which needs to do power sequence + (eg, turn on clock, toggle reset gpio) before the related + devices can be found by hardware. This generic one can be + used for common power sequence control. + +endmenu diff --git a/drivers/power/pwrseq/Makefile b/drivers/power/pwrseq/Makefile new file mode 100644 index 0000000..ad82389 --- /dev/null +++ b/drivers/power/pwrseq/Makefile @@ -0,0 +1,2 @@ +obj-$(CONFIG_POWER_SEQUENCE) += core.o +obj-$(CONFIG_PWRSEQ_GENERIC) += pwrseq_generic.o diff --git a/drivers/power/pwrseq/core.c b/drivers/power/pwrseq/core.c new file mode 100644 index 0000000..60f1e4e --- /dev/null +++ b/drivers/power/pwrseq/core.c @@ -0,0 +1,71 @@ +/* + * core.c power sequence core file + * + * Copyright (C) 2016 Freescale Semiconductor, Inc. + * Author: Peter Chen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 of + * the License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +static DEFINE_MUTEX(pwrseq_list_mutex); +static LIST_HEAD(pwrseq_list); + +int pwrseq_get(struct device_node *np, struct pwrseq *p) +{ + if (p && p->get) + return p->get(np, p); + + return -ENOTSUPP; +} + +int pwrseq_on(struct device_node *np, struct pwrseq *p) +{ + if (p && p->on) + return p->on(np, p); + + return -ENOTSUPP; +} + +void pwrseq_off(struct pwrseq *p) +{ + if (p && p->off) + p->off(p); +} + +void pwrseq_put(struct pwrseq *p) +{ + if (p && p->put) + p->put(p); +} + +void pwrseq_free(struct pwrseq *p) +{ + if (p && p->free) + p->free(p); +} + +void pwrseq_register(struct pwrseq *pwrseq) +{ + mutex_lock(&pwrseq_list_mutex); + list_add(&pwrseq->node, &pwrseq_list); + mutex_unlock(&pwrseq_list_mutex); +} + +void pwrseq_unregister(struct pwrseq *pwrseq) +{ + mutex_lock(&pwrseq_list_mutex); + list_del(&pwrseq->node); + mutex_unlock(&pwrseq_list_mutex); +} diff --git a/drivers/power/pwrseq/pwrseq_generic.c b/drivers/power/pwrseq/pwrseq_generic.c new file mode 100644 index 0000000..b50cea6 --- /dev/null +++ b/drivers/power/pwrseq/pwrseq_generic.c @@ -0,0 +1,151 @@ +/* + * pwrseq_generic.c Generic power sequence handling + * + * Copyright (C) 2016 Freescale Semiconductor, Inc. + * Author: Peter Chen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 of + * the License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +struct pwrseq_generic { + struct pwrseq pwrseq; + struct gpio_desc *gpiod_reset; + struct clk *clk; +}; + +#define to_generic_pwrseq(p) container_of(p, struct pwrseq_generic, pwrseq) + +static void pwrseq_generic_free(struct pwrseq *pwrseq) +{ + struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq); + + pwrseq_unregister(pwrseq); + kfree(pwrseq_gen); +} + +static void pwrseq_generic_put(struct pwrseq *pwrseq) +{ + struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq); + + if (pwrseq_gen->gpiod_reset) + gpiod_put(pwrseq_gen->gpiod_reset); + + clk_put(pwrseq_gen->clk); +} + +static void pwrseq_generic_off(struct pwrseq *pwrseq) +{ + struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq); + + clk_disable_unprepare(pwrseq_gen->clk); +} + +static int pwrseq_generic_on(struct device_node *np, struct pwrseq *pwrseq) +{ + struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq); + int ret = 0; + struct gpio_desc *gpiod_reset = pwrseq_gen->gpiod_reset; + + if (pwrseq_gen->clk) { + ret = clk_prepare_enable(pwrseq_gen->clk); + if (ret) { + pr_err("Can't enable clock on %s: %d\n", + np->full_name, ret); + return ret; + } + } + + if (gpiod_reset) { + u32 duration_us = 50; + + of_property_read_u32(np, "reset-duration-us", + &duration_us); + usleep_range(duration_us, duration_us + 10); + gpiod_set_value(gpiod_reset, 0); + } + + return ret; +} + +static int pwrseq_generic_get(struct device_node *np, struct pwrseq *pwrseq) +{ + struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq); + enum of_gpio_flags flags; + int reset_gpio, ret = 0; + + pwrseq_gen->clk = of_clk_get_by_name(np, NULL); + if (IS_ERR(pwrseq_gen->clk)) { + pr_debug("Can't get clock on %s: %ld\n", + np->name, PTR_ERR(pwrseq_gen->clk)); + pwrseq_gen->clk = NULL; + } + + reset_gpio = of_get_named_gpio_flags(np, "reset-gpios", 0, &flags); + if (gpio_is_valid(reset_gpio)) { + unsigned long gpio_flags; + + if (flags & OF_GPIO_ACTIVE_LOW) + gpio_flags = GPIOF_ACTIVE_LOW | GPIOF_OUT_INIT_LOW; + else + gpio_flags = GPIOF_OUT_INIT_HIGH; + + ret = gpio_request_one(reset_gpio, gpio_flags, + "pwrseq-reset-gpios"); + if (ret) + goto err; + + pwrseq_gen->gpiod_reset = gpio_to_desc(reset_gpio); + } else { + if (reset_gpio == -ENOENT) + return 0; + + ret = reset_gpio; + pr_err("Failed to get reset gpio on %s, err = %d\n", + np->full_name, reset_gpio); + goto err; + } + + return ret; +err: + clk_put(pwrseq_gen->clk); + return ret; +} + +struct pwrseq *pwrseq_alloc_generic(void) +{ + struct pwrseq_generic *pwrseq_gen; + + pwrseq_gen = kzalloc(sizeof(*pwrseq_gen), GFP_KERNEL); + if (!pwrseq_gen) + return ERR_PTR(-ENOMEM); + + pwrseq_gen->pwrseq.get = pwrseq_generic_get; + pwrseq_gen->pwrseq.on = pwrseq_generic_on; + pwrseq_gen->pwrseq.off = pwrseq_generic_off; + pwrseq_gen->pwrseq.put = pwrseq_generic_put; + pwrseq_gen->pwrseq.free = pwrseq_generic_free; + + pwrseq_register(&pwrseq_gen->pwrseq); + return &pwrseq_gen->pwrseq; +} +EXPORT_SYMBOL_GPL(pwrseq_alloc_generic); diff --git a/include/linux/power/pwrseq.h b/include/linux/power/pwrseq.h new file mode 100644 index 0000000..6c4b9a0 --- /dev/null +++ b/include/linux/power/pwrseq.h @@ -0,0 +1,50 @@ +#ifndef __LINUX_PWRSEQ_H +#define __LINUX_PWRSEQ_H + +#include + +struct pwrseq { + char *name; + struct list_head node; + int (*get)(struct device_node *np, struct pwrseq *p); + int (*on)(struct device_node *np, struct pwrseq *p); + void (*off)(struct pwrseq *p); + void (*put)(struct pwrseq *p); + void (*free)(struct pwrseq *p); +}; + +#if IS_ENABLED(CONFIG_POWER_SEQUENCE) +int pwrseq_get(struct device_node *np, struct pwrseq *p); +int pwrseq_on(struct device_node *np, struct pwrseq *p); +void pwrseq_off(struct pwrseq *p); +void pwrseq_put(struct pwrseq *p); +void pwrseq_free(struct pwrseq *p); +void pwrseq_register(struct pwrseq *pwrseq); +void pwrseq_unregister(struct pwrseq *pwrseq); + +#else +static inline int pwrseq_get(struct device_node *np, struct pwrseq *p) +{ + return 0; +} +static inline int pwrseq_on(struct device_node *np, struct pwrseq *p) +{ + return 0; +} +static inline void pwrseq_off(struct pwrseq *p) {} +static inline void pwrseq_put(struct pwrseq *p) {} +static inline void pwrseq_free(struct pwrseq *p) {} +static inline void pwrseq_register(struct pwrseq *pwrseq) {} +static inline void pwrseq_unregister(struct pwrseq *pwrseq) {} +#endif /* CONFIG_POWER_SEQUENCE */ + +#if IS_ENABLED(CONFIG_PWRSEQ_GENERIC) +struct pwrseq *pwrseq_alloc_generic(void); +#else +static inline struct pwrseq *pwrseq_alloc_generic(void) +{ + return NULL; +} +#endif /* CONFIG_PWRSEQ_GENERIC */ + +#endif /* __LINUX_PWRSEQ_H */