From patchwork Tue May 4 18:49:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 12238469 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=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 38AFDC433B4 for ; Tue, 4 May 2021 18:51:50 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B519E610E9 for ; Tue, 4 May 2021 18:51:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B519E610E9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=seco.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=bE6nb41J5ydy4NLhGOcYwsaW0iXQW+ZO1uSFP4tyMjg=; b=dz/7QNkmkVModymCn1PA3P6aR3 mgCYVJEKcGaxIogI3hKDHdQsS/3fihkFpicCzz+us6i6LB6iL4oHcVT/aXnQ88+v2/eu6k9l+aobJ iFCnWKLWTw3KOo7uktojceBMLmFQt/eOkSrFs0tue0x7Z7NcCboIqBfs4UHfqCfuQWS0HoiTX6ZsI +y9yk6GXWfMt/2UsM6EITlR1/Ei0xpQi7sZ5AfUjWTyOeAteH9Ad6gRQ1qI5PhwioGe5F9iWaBt+S akOP4msi4x7ZKdiwUgtOO+ejCIflYOU2AQj/iIf+KVdrzCiHqZ9HOjRpq1/Gi7aFho1G5AgvPzB68 SppyCoDQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1le07C-00Gp3p-Uh; Tue, 04 May 2021 18:49:51 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1le079-00Gp3M-Oq for linux-arm-kernel@desiato.infradead.org; Tue, 04 May 2021 18:49:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:In-Reply-To:References; bh=7OuNDm/M8pFW5GR8Cd1cF1ndTH7+81ik8rRZxwO2a4o=; b=bhGVNaY4iwyF9ShF80bgeoBF/Q L5TBiu6Q+ofwYiqjZG9fs5qb+r1tleb3xMiNIrD8tgr/Oii/eaKx3NjOILvLE4AIb9va5gmMzHKLp StLrj96Ia/4ScZ6+Qu9D+y2JkzwCluRdUxvA9EcpZPts0kEA2BMJ2vf87Ad7nCllsggaUd3ApywA7 V3Dy72rS1iVx6S+tSPXRmiou71POIsj7pqtJ/fDeLkRuKXbjBIww8EiqFrlnWWA45C765Hj4bbYzE 4wf9IGn3D5+1Hyf3EIhiwH4/6NywsMH/RqtTv6LP6tJg+/yu3PEd2/2Qzip9bYh0Z85qchBA6QeMj lRR2hQiA==; Received: from mail-db8eur05on2076.outbound.protection.outlook.com ([40.107.20.76] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1le076-004BqJ-Ge for linux-arm-kernel@lists.infradead.org; Tue, 04 May 2021 18:49:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jf5RZw31Vm6M9Ani+28XUP5AaqWn4Pl/p/lX0Xx0iamCwsxn1cxRijxQwQT/zxxKdpqviukl77bBd1Su0Am30WNG9em2/vSG1pQlK3cNoFvh17zTJs5yLWfn3gm+ccciAqSYkCmqR2EeGpt9TOVvcAgQCNQp+YYxi0WK356+98joXhbhE6lfeQGGGdayfS2c6TaGEXzgFe9cCKA1jFeZce/Y/uet/OmIM9tnor1kVb50p6nGKH4pQ1EwuQK9JccfmOFIh5OgrJZ0rF781Dmgmte39z5kD2rD5AzNiUK77N7LU+0oAr+O97KLCBXCdGJYZ6Ffu2QlsNW2UWlgy4uzjQ== 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=7OuNDm/M8pFW5GR8Cd1cF1ndTH7+81ik8rRZxwO2a4o=; b=n7catU4JNoIUBNbMJVdMleTnE4GFlGkvcicy0yKBMM4mtPujv6UKRjaL6CWa1MTUUWPB483TL/BDBup7LbQOtgvV8ExabY6ADU1DrWmzznGT3Pu+uuc8My6dZniNVprpK/Kil6A75juPo0Feq3EqxM2gO8ItbJXeSXFJOIE+IQsKxq8m0C5ZUdyvHUy3GfcuErhO6+YEDmetgDoZzHftFWf5HEYBFZCmRSQvVULTQXVGxNAr4nrgdPpkJGuiEP2+JhcI2Mtb8xs+vF4YS/xKKWi1zNiBwAjPGh7IVP5kJ+NtvhBMkeQqQX7kbX7jvIRjLQ/z9C70dkBbozAEaxuzFA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secospa.onmicrosoft.com; s=selector2-secospa-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7OuNDm/M8pFW5GR8Cd1cF1ndTH7+81ik8rRZxwO2a4o=; b=xkT3xl2iCkqo4zbi/1sV4WM6mRTbpe4XKALC/KohDbcJPLAOiMCZrMa29cCtrmBdpsoldKPYPDyhBI8v1GOzZJqr6Cy2Z+an0KiUw65RH2tFiwRddKTIiq0e99vg33mwv+TeKRKnF7eDMve8qe6nwMN9/nQmQNqItEkguMQ53n4= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) by DB9PR03MB7276.eurprd03.prod.outlook.com (2603:10a6:10:1fd::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24; Tue, 4 May 2021 18:49:39 +0000 Received: from DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::40d5:3554:c709:6b1b]) by DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::40d5:3554:c709:6b1b%5]) with mapi id 15.20.4087.044; Tue, 4 May 2021 18:49:39 +0000 From: Sean Anderson To: linux-pwm@vger.kernel.org, devicetree@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, michal.simek@xilinx.com, Alvaro Gamez , Sean Anderson , Rob Herring Subject: [PATCH v2 1/2] dt-bindings: pwm: Add Xilinx AXI Timer Date: Tue, 4 May 2021 14:49:24 -0400 Message-Id: <20210504184925.3399934-1-sean.anderson@seco.com> X-Mailer: git-send-email 2.25.1 X-Originating-IP: [50.195.82.171] X-ClientProxiedBy: MN2PR04CA0015.namprd04.prod.outlook.com (2603:10b6:208:d4::28) To DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from plantagenet.inhand.com (50.195.82.171) by MN2PR04CA0015.namprd04.prod.outlook.com (2603:10b6:208:d4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.27 via Frontend Transport; Tue, 4 May 2021 18:49:38 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 94f2edbc-e887-4983-e3c5-08d90f2d5f17 X-MS-TrafficTypeDiagnostic: DB9PR03MB7276: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1265; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QmWPNSLYBXbgR9Jao1RJcx5pQA/6IW+cm9qcqrF13KlP3e+W1NP6eQHIniG4xfR1w/77NsOwlVjexALBsTooZchmcPtNgsbgygDZ8ikmeOH0ovpjMkL0J5h38Xv9jKdqxFtoTRHpPb1xYCpspaodXfhWasvRV4qxEh5nK0YU/JvvR7kVSqqC+UbfBksnnEx7TornuBsRI19JVZ/JIwo6F7xDeBEYNXgK7NBK/iJF62Jyt9X0Gi/q1DOJKv6Lyh6qYcvx6p9X6B39R51j40Np9mY7DW/B/i5JmyBEQ+/YqIf32qZeSkkcwjVvxYIIYzgT5A+LGvr8PTW2os2M2+a/je0zAqu4LZcjZmh7tfR1z7HB3AKvM9eZa0UmUvkHKdDjkeriQ+F+HdRBDOTzF1x5YqZKBVYfP9WFqfyiTb59QDXYha4MK+Dc1UxTikCBOWVEdyNZpSV2GJMx81pOl8QlwBGOElPz05bc2ZHQ/UH//Mn71SgDV5QzWsVO997zdrYoepKau+4NPoGCHF7fgGOKtpZLwEdgsj3eJohtdQnOI+0cUxLQLB4bllxZ5ipRFWS4nKfi1Vyt2NYyKwct+NZAL1mLhc1LKEBkJ5wHX45YpqpRDET/ZWnX9PvvyORfhzcoeb3wE5+V0YvlcdFhnjN8JRydfeU2KFXOUgvTLrEX/jazmnC6pGCVgl3wOlTgKEK1idRsdZDAp+B6y63SpNETin6CzTLpjqYbleRuQ4/gjNs= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4523.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(136003)(366004)(346002)(396003)(39830400003)(376002)(38350700002)(38100700002)(66946007)(66556008)(2906002)(5660300002)(66476007)(44832011)(26005)(52116002)(478600001)(6486002)(6506007)(8936002)(16526019)(6666004)(966005)(186003)(2616005)(83380400001)(8676002)(86362001)(4326008)(956004)(36756003)(6512007)(1076003)(316002)(54906003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 9NlCeI1Sw5juLUeSzUwG7nGOXauWnoMErJYDnF9MbfRmOgiDCpBdw8oBkZgy1fBOotnVlmNqb1j8IG9lTnywHsSD4bltuu7n+97NhDgkbHDbjucm1IgKJuzB6VatuEVHVpgGEz/4I/YwBXa68TXeTA9+RxokHB+PSNlqImGcNMBuT5i9ZCHbkctmjpRXmEj3pdmNMxMoyEP+RD4CgqDIQCPwwiJx5D1fc+5D4zr3xCfU3HRiwfQC+Fedt1idiWH4kHWZ7J0DiayO2656q/IOxn4NqNrc3seT+PoU9B7/Vb7z2Sazl+2+hc7bzH3l4/KkxHbfWN35ALA+iBSY/AgsaXVlc2/wi2cmO4aQVQBgWiQQLLLMPBuauSI5LmFoFZIdUOCYpdEloMT6AlFrjyw+lP76TC3rdJ9fL4xYQpvAEmTeE9UNEx+pwiH6EGEPSP8Tv7uSmevWvknOrS92e9zDThQ847QMYhFUG7LoC1KtMHlDuq2XLH1sKWCaoSasDJc851U5Wl9r9qQVgJsTase///RCOVPrPl73+RIhvGuwkGXN7h0ovSTXsQ/L14gC5JESdfV79JAU0fOLAUiTRu6PK5Ugrry22i0j9aQdxZVAzU6gcO1TF6uDZJFgh88XAPvmIF1a+yPqQvTq7jMfjeARJ0EhkXADaWnj5oWEh9kG+SUplXn9WFvzErxIPlXyuJvXv/IUwpHLTLVWolmT2Hh0bxOXh31qc84iqg6v+DuvUGW2sdw4uFDwCPS6xt367grUJUTOu7dvVL7DRX6QFTSYWbW8Qt06zc0KEy3C4+H8uqdFs68wAApxkChkk4l1E7N3fU3u/roW1L4M+KU6h2a5IrSyct7BY+YPcZzSBwGwxM4i17rb4BByJfVIDbLCrGUWsQ9fVaxrqKl4hDRzdu8fe3tfXR3ZV39roc05KqWM/bBkp9i3KG/DBz3vuub4aec+q0QlI/qJeEQciukIjF3aNi2gcHqkfWxVPBNZQYp0HbsyEwlpsOmcc7Yza+1dLtVPEVXTA1givz2MzpPCWfd1HLNfEDLyhXwrydtT9WZ39gMUpysf4L+vK+RXjpEDDesFzInxmbOOI24ynvfjXz74ePki9nqIcfnZZFvWYpJI1TE5TYxKWHnXbZOek5gzR0ATjRrIK+QkfsvJThBb6xx7205ehHUA3nxOWUQHjKGtPO9r12yfkBilyaLaVsSW9mV6Cz7hwEw9/B8i8NTy8OmS3JDwPlTW/mFknqine3WFVtUER00VXF57pF5WgR2jgFJsY1/muQpU5iTO+tbZV/N3HoPltxbfdb5INxM5Ys/ahisHKnvBiB4sNKdyHsv9YglT X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 94f2edbc-e887-4983-e3c5-08d90f2d5f17 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4523.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 May 2021 18:49:39.4371 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UDXyyz/bTlImyu/a9qwwa2lyLn1PeMraZ6YRld5EAJloqHulvuTqYmiJObYT/LHBL3qY0sJ40n/q9C3+2QWj/A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR03MB7276 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210504_114944_658753_2A5201FB X-CRM114-Status: GOOD ( 14.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This adds a binding for the Xilinx LogiCORE IP AXI Timer. This device is a "soft" block, so it has many parameters which would not be configurable in most hardware. This binding is usually automatically generated by Xilinx's tools, so the names and values of properties must be kept as they are. Signed-off-by: Sean Anderson --- Changes in v2: - Use 32-bit addresses for example binding .../bindings/pwm/xlnx,axi-timer.yaml | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/xlnx,axi-timer.yaml diff --git a/Documentation/devicetree/bindings/pwm/xlnx,axi-timer.yaml b/Documentation/devicetree/bindings/pwm/xlnx,axi-timer.yaml new file mode 100644 index 000000000000..bd014134c322 --- /dev/null +++ b/Documentation/devicetree/bindings/pwm/xlnx,axi-timer.yaml @@ -0,0 +1,91 @@ +# SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pwm/xlnx,axi-timer.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Xilinx LogiCORE IP AXI Timer Device Tree Binding + +maintainers: + - Sean Anderson + +properties: + compatible: + items: + - const: xlnx,axi-timer-2.0 + - const: xlnx,xps-timer-1.00.a + + clocks: + maxItems: 1 + + clock-names: + const: s_axi_aclk + + reg: + maxItems: 1 + + xlnx,count-width: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 8 + maximum: 32 + description: + The width of the counters, in bits. + + xlnx,gen0-assert: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 0, 1 ] + description: + The polarity of the generateout0 signal. 0 for active-low, 1 for active-high. + + xlnx,gen1-assert: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 0, 1 ] + description: + The polarity of the generateout1 signal. 0 for active-low, 1 for active-high. + + xlnx,one-timer-only: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 0, 1 ] + description: + Whether only one timer is present in this block. + + xlnx,trig0-assert: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 0, 1 ] + description: + The polarity of the capturetrig0 signal. 0 for active-low, 1 for active-high. + + xlnx,trig1-assert: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 0, 1 ] + description: + The polarity of the capturetrig1 signal. 0 for active-low, 1 for active-high. + +required: + - compatible + - clocks + - reg + - xlnx,count-width + - xlnx,gen0-assert + - xlnx,gen1-assert + - xlnx,one-timer-only + - xlnx,trig0-assert + - xlnx,trig1-assert + +additionalProperties: true + +examples: + - | + axi_timer_0: timer@800e0000 { + clock-frequency = <99999001>; + clock-names = "s_axi_aclk"; + clocks = <&zynqmp_clk 71>; + compatible = "xlnx,axi-timer-2.0", "xlnx,xps-timer-1.00.a"; + reg = <0x800e0000 0x10000>; + xlnx,count-width = <0x20>; + xlnx,gen0-assert = <0x1>; + xlnx,gen1-assert = <0x1>; + xlnx,one-timer-only = <0x0>; + xlnx,trig0-assert = <0x1>; + xlnx,trig1-assert = <0x1>; + }; From patchwork Tue May 4 18:49:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 12238467 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=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 87EE7C433ED for ; Tue, 4 May 2021 18:51:49 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E0B68610FB for ; Tue, 4 May 2021 18:51:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E0B68610FB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=seco.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=j54Oyt+q0CBeGzAsmerwDbiVma1Jaf3eHNo887mD4BM=; b=qCx5T9RrBxD1UT1o0836XCRBs o3GimIRBprPhiypYtR0SwKepBsfQCFei8GrXBZ5UPz7n4Da9zpTE0LbBb4epbbhEkCXIMUdIV2Qld DFYxRZJy3aEE3VRfpm1y8PS4jaRTz6B32SrchwDj6ae2m0Fww6SIyhSf7UUIDpuetvoRQgSG6YZLr qnuB59iZSv1f7bk5xvQm/NvjFZcvobcBV06WFG/RlOjqt/1JtMmZE/SckVQ/UUmgP4m7Nao8y77Yq gm9FG3AbclvJm6RNvNuWOxMv4HbMJx5TZsZ/tpHmzU5Kmrr4zRGV3XaH5RSzyQQfLz+gi7xMXN3s6 xdxYIQnAw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1le07M-00Gp4T-7i; Tue, 04 May 2021 18:50:00 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1le07C-00Gp3n-6p for linux-arm-kernel@desiato.infradead.org; Tue, 04 May 2021 18:49:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=MIME-Version: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Message-Id:Date :Subject:Cc:To:From:Sender:Reply-To:Content-ID:Content-Description; bh=YzqEeHtP8TgIkjk+7URRd9LeXpi0bXmJH40p4j/CSZ4=; b=YTAcpi1UERQpgtQd6v8TAb3ING u4WRKOobUxPgLxvSe4l+SxSa1GXmrY2t3KAhzjCMGT/Yg9jVTDxoYXLklYU/1cP2Imj4eqj3ytlQW tlpgMHwT5eUJMYxg5WiNqHI06BVtruxMePGZ1N4T0t+1IvWVFa5oV0hr0VHgJOLOb+3fpvpkzO+gh zE4liWI771duySQwuS+/mdLPWQBXy81bAVBkI4KtQcCk7LKstbDYbfMiTa08ShBAViK2zFzIyXDAH 61HaU1Ot50GrJjPRwK5D7BOuNtVBD2KcwGZiBiS3nL3SElWCVZjj1z4peGx1QGUZlHPjJUghb4yg2 hqjooSuw==; Received: from mail-db8eur05on2076.outbound.protection.outlook.com ([40.107.20.76] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1le078-004BqJ-Pw for linux-arm-kernel@lists.infradead.org; Tue, 04 May 2021 18:49:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UhpHw6dwTK4xY6LoFDjnZHwDyl+wMpFSJ8acL90PEmLkQAadvm9xHpO7cwDUNRoDiLOaWzXSCff01Kz5SYBmjPMgEqg9NtLPHY9h76eaXuihaUecRVcc0QRqhLRbHuf4FGhMyOdxJ7+hzhV3/YuaIVugjiF8Iz6UeGSES2uEd+1W4nvY+s+bvVEzQaYFlnhj50h8b8SxoFk3UGjYqsSkWouL/n7tPocYN/dxR71Lm03qREusmYNRhnfEdSLqVfDTvRqeKVVI8zDwhkUw7z7kvEqzcclt/xQjGq/+s5/XQYhrYGr0XZ60EZHqqWrIT6jvguvDglmb0M5v4ia1Jh8Qew== 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=YzqEeHtP8TgIkjk+7URRd9LeXpi0bXmJH40p4j/CSZ4=; b=Odqc9A80UzNlyZV5lYkQAWXG9oBsyrIEe1Hw7jSMOUsatm+qgz01bGtFHQzmfW7V/yxLW0Zm7HTjtBF8Hj5BNDuUhOoAvaRUegB6VbPFL/XTmccKKSMkjW6OMcsXO2mBwxq/FZ0wlOXBwkJMeTqc8YlluRKjNEmNESiL5NkcVrI2+LEkW4l4hh1JQZQ9hnA6PCTHQh2Ad/SiP4ExxLvp6D0VswRtny59QlbNWXiV/E02DIl3nvYBN1lM21vl9Ioi61IwK1PZmz396Z13JNMRYV1vZ+Bm34dW8wEoEMEVHv6DeTC9npgrQKlFtlQsFrpU27pQJ2YL8GaA1kwVPa53Hg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secospa.onmicrosoft.com; s=selector2-secospa-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YzqEeHtP8TgIkjk+7URRd9LeXpi0bXmJH40p4j/CSZ4=; b=u/r5ROZhZZb88kXAM1h5yCFfA46ytsKsAmOj6pjCSZWCLuUJJjGOHp85c+eGpCl9jKsqZus/wN5lHd7cMq/g0V4aEPVrl33HCL5k8e3J867Ocls+yc3UlX2d+PtK5NV+vV25LANCVv5h70yudE/0iRZk7xD/iCrJBzEfw6qHRD4= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) by DB9PR03MB7276.eurprd03.prod.outlook.com (2603:10a6:10:1fd::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24; Tue, 4 May 2021 18:49:41 +0000 Received: from DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::40d5:3554:c709:6b1b]) by DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::40d5:3554:c709:6b1b%5]) with mapi id 15.20.4087.044; Tue, 4 May 2021 18:49:41 +0000 From: Sean Anderson To: linux-pwm@vger.kernel.org, devicetree@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, michal.simek@xilinx.com, Alvaro Gamez , Sean Anderson , Lee Jones , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Subject: [PATCH v2 2/2] pwm: Add support for Xilinx AXI Timer Date: Tue, 4 May 2021 14:49:25 -0400 Message-Id: <20210504184925.3399934-2-sean.anderson@seco.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210504184925.3399934-1-sean.anderson@seco.com> References: <20210504184925.3399934-1-sean.anderson@seco.com> X-Originating-IP: [50.195.82.171] X-ClientProxiedBy: MN2PR04CA0015.namprd04.prod.outlook.com (2603:10b6:208:d4::28) To DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from plantagenet.inhand.com (50.195.82.171) by MN2PR04CA0015.namprd04.prod.outlook.com (2603:10b6:208:d4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.27 via Frontend Transport; Tue, 4 May 2021 18:49:39 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 114618d6-6b73-414c-66cf-08d90f2d6006 X-MS-TrafficTypeDiagnostic: DB9PR03MB7276: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /IlBy/P2abS/z6UsoU0IZ7dOXo92BP1Nq60oL7t10Dw1kRAOiNVFItzlr93Gs+18hUwEhfRzlVuYNz8iXMCfAmGpCD5AZxsy3RPD2gWkkWOplekNDq6F24h0jGBhrZuglFzlIJkNkVbDZWZHQ9w3rIhMNo8k3dmQld8GgCKg55gKsPgCH/BTpozOeJA35TQgyx2cFVRgkbYGOo9iWuF1Oa6Net2QuwPRTV7GyhvPL1mu0IlGJHKsHXcSHC8DruGEUX7OYqElv73rlEuYkZBSB9WMskUVEQdj+gKlbbf4ybCdZE41oxRZkUwEOt4rCldIeAcogtW4TzY9Hi2QdisyYsZzGRBMICyopC2/8XgBxKQVa/vTkqQiFHbID8/lFqPJFAZt1Vv/hQ5IjO+YMuBGMTnspFpjmjgqi/ptLeo21b3qvAIjpswExItapc6dnQlnwDBypoH5qhX4qcMkQZd+m/XPT5ztyeT1Al3qKdokphvXwU33EbhIHslOXYV/3249GGcWHbE4faWXGTXAZ3/ezTjeIAU9IShnvgpcwwQ83m6ITO3y7256vvvNM6Xwxh1QhAX1SIUdan3Pb4ZR2ohv6yDenYJpz00GQyTjj1qovMzYyxkcqgi5sY7ao/W34kRzIKDySYgwSqXyaVrJJ+UvwJjbKjCLNR6R24HYGJeOfEsMr72eztNR/OcUX6HhRy9/xgV7hQO8WdCR0YGIHKCf0z32sXh141Xu6SlypMRX4f8= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4523.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(136003)(366004)(346002)(396003)(39830400003)(376002)(38350700002)(38100700002)(66946007)(66556008)(2906002)(5660300002)(66476007)(44832011)(26005)(52116002)(478600001)(6486002)(6506007)(8936002)(16526019)(6666004)(966005)(186003)(2616005)(83380400001)(8676002)(86362001)(4326008)(956004)(36756003)(6512007)(30864003)(1076003)(316002)(54906003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?76GYZyrU4Duiz4PAeZf3O3I291TGK1?= =?utf-8?q?XntTNKMQmZ9F/10831yBZwD75zvcWLYM+Z52Y33bFUiU1hfoTB7z8HvMufLmq+ej5?= =?utf-8?q?NNVKtP7F6gKKHc8fGMXe/OpIkFyCDto2Lhwnz/U5UlTwdXCXJEvky8Dpl6uE3CGQs?= =?utf-8?q?XQid/058r8CwMCwr4Iz2Iheb/XjhzFIZJ8+/ol/9LtJp6kyKx0yzOC3W/HchP+omj?= =?utf-8?q?yyXEDtT2p6IRdNo0Vnikyg4q7qc8qYoOt3Hb8et6a7eM9cfg3SuGGH9dr3+ozi7E2?= =?utf-8?q?ZVKqDJ1wH9ASzHwSWGPD/K0l4gD2CuQpf7zDYCgGqf3mcczctf7qIlcUXS6e4wtnV?= =?utf-8?q?JB5RJDkeoG2qRSDgJ1jXWzjqH9fNM7aBRsUwtcrZsOHXTfcRn0V9b5B5G7uJ199xe?= =?utf-8?q?gsSZ05pOWhwG7vsa4xrigPSYHutm4T/Ym6OpPFQleLiSgTuj+sxcFM+G58mbP/1FA?= =?utf-8?q?2u7vEf50AuADiIV3mvlt4kbaNyRZO83pW22WfXclVo2Kd5uSsxH3LUIEw+ROxGJaW?= =?utf-8?q?wGETCopDNe5RfR5vPGM4rFpiZx0beAWV6y/7u13k75XvOUd0uDhZOBu/1mHwqsW3R?= =?utf-8?q?m0pTaJ8znwNUeFhQItFtZlQuUJ1mjPZlO4GWqg8ObNPeLdJ2mOKvVQYg/k/tp+KyZ?= =?utf-8?q?D+M+7FVhP5hIm2L+BvHdzv6JNpDSr7XwZpDjfs+Qo0GglItdu77tIIpI1XwitqDty?= =?utf-8?q?qtp9oeroXX5bnWUPvibhkXLZg+fmzI9xS2E4PvQg5N60Tu1qFDSvqIR4coqmypHg8?= =?utf-8?q?h/dObQFPmYHA32QGpZ/DWWLK8XEpFDlG/gHGcF8HFKIYCP9PzkYhzguAsw9tMnK1/?= =?utf-8?q?epRqZ1nW/SC398pIv+HKjl2nci4SwoC01glfLAvVkpE6MHmyV3QxQ+DnJNfYxIlDi?= =?utf-8?q?HqYKN+qG6rh9/RDiwD5gV+DMWffcwy/TTX+vmLEIXEhfiFgEsOurDkFGSVrL9jJfY?= =?utf-8?q?yYi9D88ThD2dR4UX/y4JS+XUcX6q1lcCzhEANgADUbjkQYwBo3TP/ge5cGjh1LanA?= =?utf-8?q?crA4DU7o1mm+2Phbk8nGXkG8W96qEtnrzp5wiNk6Lca3YYLAPxOS78LS6dcNS3++E?= =?utf-8?q?GHnwDJySBuezdbG8xwV/vbn1v+9/nGvH40pjad6Y9jAbmn4VNBvPjm0z1dsNe7Eby?= =?utf-8?q?UBzPChNZMqhXdDKSxsRsjK13ge/177Z9BLZNMkod9Gfv59VwyGhdSS3xFOs5p/LPk?= =?utf-8?q?O4w40uvAI6zMrt/+mYby3R5bS60iUv8b2nJ0EKlRyGFVw8hP5x+t+n6JbYU4ZJ+0z?= =?utf-8?q?NeCSprVnpmbyTl?= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 114618d6-6b73-414c-66cf-08d90f2d6006 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4523.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 May 2021 18:49:41.0551 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: j77SXbp0kKzp3g2X9pd+xCv2XFPkHYpg+blCVm8hVqMqUOgADcbrTVOlFPYVFgXS3DokeLpMNiunvEUakf/t6Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR03MB7276 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210504_114946_882883_60C4F053 X-CRM114-Status: GOOD ( 33.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This adds PWM support for Xilinx LogiCORE IP AXI soft timers commonly found on Xilinx FPGAs. There is another driver for this device located at arch/microblaze/kernel/timer.c, but it is only used for timekeeping. This driver was written with reference to Xilinx DS764 for v1.03.a [1]. [1] https://www.xilinx.com/support/documentation/ip_documentation/axi_timer/v1_03_a/axi_timer_ds764.pdf Signed-off-by: Sean Anderson --- I tried adding a XILINX_PWM_ prefix to all the defines, but IMO it really hurt readability. That prefix almost doubles the size the defines, and is particularly excessive in something like XILINX_PWM_TCSR_RUN_MASK. Changes in v2: - Don't compile this module by default for arm64 - Add dependencies on COMMON_CLK and HAS_IOMEM - Add comment explaining why we depend on !MICROBLAZE - Add comment describing device - Rename TCSR_(SET|CLEAR) to TCSR_RUN_(SET|CLEAR) - Use NSEC_TO_SEC instead of defining our own - Use TCSR_RUN_MASK to check if the PWM is enabled, as suggested by Uwe - Cast dividends to u64 to avoid overflow - Check for over- and underflow when calculating TLR - Set xilinx_pwm_ops.owner - Don't set pwmchip.base to -1 - Check range of xlnx,count-width - Ensure the clock is always running when the pwm is registered - Remove debugfs file :l - Report errors with dev_error_probe drivers/pwm/Kconfig | 13 ++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-xilinx.c | 301 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 315 insertions(+) create mode 100644 drivers/pwm/pwm-xilinx.c diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig index 8ae68d6203fb..b1ad77ec81e3 100644 --- a/drivers/pwm/Kconfig +++ b/drivers/pwm/Kconfig @@ -620,4 +620,17 @@ config PWM_VT8500 To compile this driver as a module, choose M here: the module will be called pwm-vt8500. +config PWM_XILINX + tristate "Xilinx AXI Timer PWM support" + depends on HAS_IOMEM && COMMON_CLK + # This driver conflicts with arch/microblaze/kernel/timer.c + depends on !MICROBLAZE + help + PWM framework driver for Xilinx LogiCORE IP AXI Timers. This + timer is typically a soft core which may be present in Xilinx + FPGAs. If you don't have this IP in your design, choose N. + + To compile this driver as a module, choose M here: the module + will be called pwm-xilinx. + endif diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile index d43b1e17e8e1..655df169b895 100644 --- a/drivers/pwm/Makefile +++ b/drivers/pwm/Makefile @@ -58,3 +58,4 @@ obj-$(CONFIG_PWM_TWL) += pwm-twl.o obj-$(CONFIG_PWM_TWL_LED) += pwm-twl-led.o obj-$(CONFIG_PWM_VISCONTI) += pwm-visconti.o obj-$(CONFIG_PWM_VT8500) += pwm-vt8500.o +obj-$(CONFIG_PWM_XILINX) += pwm-xilinx.o diff --git a/drivers/pwm/pwm-xilinx.c b/drivers/pwm/pwm-xilinx.c new file mode 100644 index 000000000000..10483da1a942 --- /dev/null +++ b/drivers/pwm/pwm-xilinx.c @@ -0,0 +1,301 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2021 Sean Anderson + * + * For Xilinx LogiCORE IP AXI Timer documentation, refer to DS764: + * https://www.xilinx.com/support/documentation/ip_documentation/axi_timer/v1_03_a/axi_timer_ds764.pdf + * + * Hardware limitations: + * - When changing both duty cycle and period, we may end up with one cycle + * with the old duty cycle and the new period. + * - Cannot produce 100% duty cycle. + * - Only produces "normal" output. + */ +#include +#include +#include +#include +#include +#include + +#define TCSR0 0x00 +#define TLR0 0x04 +#define TCR0 0x08 +#define TCSR1 0x10 +#define TLR1 0x14 +#define TCR1 0x18 + +#define TCSR_MDT BIT(0) +#define TCSR_UDT BIT(1) +#define TCSR_GENT BIT(2) +#define TCSR_CAPT BIT(3) +#define TCSR_ARHT BIT(4) +#define TCSR_LOAD BIT(5) +#define TCSR_ENIT BIT(6) +#define TCSR_ENT BIT(7) +#define TCSR_TINT BIT(8) +#define TCSR_PWMA BIT(9) +#define TCSR_ENALL BIT(10) +#define TCSR_CASC BIT(11) + +/* + * The idea here is to capture whether the PWM is actually running (e.g. + * because we or the bootloader set it up) and we need to be careful to ensure + * we don't cause a glitch. According to the device data sheet, to enable the + * PWM we need to + * + * - Set both timers to generate mode (MDT=1) + * - Set both timers to PWM mode (PWMA=1) + * - Enable the generate out signals (GENT=1) + * + * In addition, + * + * - The timer must be running (ENT=1) + * - The timer must auto-reload TLR into TCR (ARHT=1) + * - We must not be in the process of loading TLR into TCR (LOAD=0) + * - Cascade mode must be disabled (CASC=0) + * + * If any of these differ from usual, then the PWM is either disabled, or is + * running in a mode that this driver does not support. + */ +#define TCSR_RUN_SET (TCSR_GENT | TCSR_ARHT | TCSR_ENT | TCSR_PWMA) +#define TCSR_RUN_CLEAR (TCSR_MDT | TCSR_LOAD) +#define TCSR_RUN_MASK (TCSR_RUN_SET | TCSR_RUN_CLEAR) + +/** + * struct xilinx_pwm_device - Driver data for Xilinx AXI timer PWM driver + * @chip: PWM controller chip + * @clk: Parent clock + * @regs: Base address of this device + * @width: Width of the counters, in bits + */ +struct xilinx_pwm_device { + struct pwm_chip chip; + struct clk *clk; + void __iomem *regs; + unsigned int width; +}; + +static inline struct xilinx_pwm_device *xilinx_pwm_chip_to_device(struct pwm_chip *chip) +{ + return container_of(chip, struct xilinx_pwm_device, chip); +} + +static bool xilinx_pwm_is_enabled(u32 tcsr0, u32 tcsr1) +{ + return ((TCSR_RUN_MASK | TCSR_CASC) & tcsr0) == TCSR_RUN_SET && + (TCSR_RUN_MASK & tcsr1) == TCSR_RUN_SET; +} + +static int xilinx_pwm_calc_tlr(struct xilinx_pwm_device *pwm, u32 *tlr, u32 tcsr, + unsigned int period) +{ + u64 max_count = BIT_ULL(pwm->width) - 1; + u64 cycles = DIV_ROUND_DOWN_ULL((u64)period * clk_get_rate(pwm->clk), + NSEC_PER_SEC); + + if (cycles < 2) + return -ERANGE; + + if (tcsr & TCSR_UDT) { + if (cycles - 2 > max_count) + return -ERANGE; + *tlr = cycles - 2; + } else { + if (cycles > max_count + 2) + return -ERANGE; + *tlr = max_count - cycles + 2; + } + + return 0; +} + +static unsigned int xilinx_pwm_get_period(struct xilinx_pwm_device *pwm, + u32 tlr, u32 tcsr) +{ + u64 cycles; + + if (tcsr & TCSR_UDT) + cycles = tlr + 2; + else + cycles = (BIT_ULL(pwm->width) - 1) - tlr + 2; + + return DIV_ROUND_UP_ULL(cycles * NSEC_PER_SEC, clk_get_rate(pwm->clk)); +} + +static int xilinx_pwm_apply(struct pwm_chip *chip, struct pwm_device *unused, + const struct pwm_state *state) +{ + int ret; + struct xilinx_pwm_device *pwm = xilinx_pwm_chip_to_device(chip); + u32 tlr0, tlr1; + u32 tcsr0 = readl(pwm->regs + TCSR0); + u32 tcsr1 = readl(pwm->regs + TCSR1); + bool enabled = xilinx_pwm_is_enabled(tcsr0, tcsr1); + + if (state->polarity != PWM_POLARITY_NORMAL) + return -EINVAL; + + ret = xilinx_pwm_calc_tlr(pwm, &tlr0, tcsr0, state->period); + if (ret) + return ret; + + ret = xilinx_pwm_calc_tlr(pwm, &tlr1, tcsr1, state->duty_cycle); + if (ret) + return ret; + + if (!enabled && state->enabled) + clk_rate_exclusive_get(pwm->clk); + + writel(tlr0, pwm->regs + TLR0); + writel(tlr1, pwm->regs + TLR1); + + if (state->enabled) { + /* Only touch the TCSRs if we aren't already running */ + if (!enabled) { + /* Load TLR into TCR */ + writel(tcsr0 | TCSR_LOAD, pwm->regs + TCSR0); + writel(tcsr1 | TCSR_LOAD, pwm->regs + TCSR1); + /* Enable timers all at once with ENALL */ + tcsr0 = (TCSR_RUN_SET & ~TCSR_ENT) | (tcsr0 & TCSR_UDT); + tcsr1 = TCSR_RUN_SET | TCSR_ENALL | (tcsr1 & TCSR_UDT); + writel(tcsr0, pwm->regs + TCSR0); + writel(tcsr1, pwm->regs + TCSR1); + } + } else { + writel(tcsr0 & ~TCSR_RUN_SET, pwm->regs + TCSR0); + writel(tcsr1 & ~TCSR_RUN_SET, pwm->regs + TCSR1); + } + + if (enabled && !state->enabled) + clk_rate_exclusive_put(pwm->clk); + + return 0; +} + +static void xilinx_pwm_get_state(struct pwm_chip *chip, + struct pwm_device *unused, + struct pwm_state *state) +{ + struct xilinx_pwm_device *pwm = xilinx_pwm_chip_to_device(chip); + u32 tlr0, tlr1, tcsr0, tcsr1; + + tlr0 = readl(pwm->regs + TLR0); + tlr1 = readl(pwm->regs + TLR1); + tcsr0 = readl(pwm->regs + TCSR0); + tcsr1 = readl(pwm->regs + TCSR1); + + state->period = xilinx_pwm_get_period(pwm, tlr0, tcsr0); + state->duty_cycle = xilinx_pwm_get_period(pwm, tlr1, tcsr1); + state->enabled = xilinx_pwm_is_enabled(tcsr0, tcsr1); + state->polarity = PWM_POLARITY_NORMAL; +} + +static const struct pwm_ops xilinx_pwm_ops = { + .apply = xilinx_pwm_apply, + .get_state = xilinx_pwm_get_state, + .owner = THIS_MODULE, +}; + +static int xilinx_pwm_probe(struct platform_device *pdev) +{ + bool enabled = false; + int i, ret; + struct device *dev = &pdev->dev; + struct xilinx_pwm_device *pwm; + u32 one_timer; + + ret = of_property_read_u32(dev->of_node, "xlnx,one-timer-only", + &one_timer); + if (ret || one_timer) + return dev_err_probe(dev, -EINVAL, + "two timers are needed for PWM mode\n"); + + for (i = 0; i < 2; i++) { + char fmt[] = "xlnx,gen%u-assert"; + char buf[sizeof(fmt)]; + u32 gen; + + snprintf(buf, sizeof(buf), fmt, i); + ret = of_property_read_u32(dev->of_node, buf, &gen); + if (ret || !gen) + return dev_err_probe(dev, -EINVAL, + "generateout%u must be active high\n", + i); + } + + pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL); + if (!pwm) + return -ENOMEM; + platform_set_drvdata(pdev, pwm); + + pwm->chip.dev = &pdev->dev; + pwm->chip.ops = &xilinx_pwm_ops; + pwm->chip.npwm = 1; + + pwm->regs = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(pwm->regs)) + return PTR_ERR(pwm->regs); + + ret = of_property_read_u32(dev->of_node, "xlnx,count-width", &pwm->width); + if (ret || pwm->width < 8 || pwm->width > 32) + return dev_err_probe(dev, -EINVAL, + "missing or invalid counter width\n"); + + pwm->clk = devm_clk_get(dev, NULL); + if (IS_ERR(pwm->clk)) + return dev_err_probe(dev, PTR_ERR(pwm->clk), "missing clock\n"); + + ret = clk_prepare_enable(pwm->clk); + if (ret) + return dev_err_probe(dev, ret, "clock enable failed\n"); + + enabled = xilinx_pwm_is_enabled(readl(pwm->regs + TCSR0), + readl(pwm->regs + TCSR1)); + if (enabled) + clk_rate_exclusive_get(pwm->clk); + + ret = pwmchip_add(&pwm->chip); + if (ret) { + dev_err_probe(dev, ret, "could not register pwm chip\n"); + if (enabled) + clk_rate_exclusive_put(pwm->clk); + clk_disable_unprepare(pwm->clk); + } + return ret; +} + +static int xilinx_pwm_remove(struct platform_device *pdev) +{ + struct xilinx_pwm_device *pwm = platform_get_drvdata(pdev); + bool enabled = xilinx_pwm_is_enabled(readl(pwm->regs + TCSR0), + readl(pwm->regs + TCSR1)); + + pwmchip_remove(&pwm->chip); + if (enabled) + clk_rate_exclusive_put(pwm->clk); + clk_disable_unprepare(pwm->clk); + + return 0; +} + +static const struct of_device_id xilinx_pwm_of_match[] = { + { .compatible = "xlnx,xps-timer-1.00.a" }, + { .compatible = "xlnx,axi-timer-2.0" }, + {}, +}; +MODULE_DEVICE_TABLE(of, xilinx_pwm_of_match); + +static struct platform_driver xilinx_pwm_driver = { + .probe = xilinx_pwm_probe, + .remove = xilinx_pwm_remove, + .driver = { + .name = "xilinx-pwm", + .of_match_table = of_match_ptr(xilinx_pwm_of_match), + }, +}; +module_platform_driver(xilinx_pwm_driver); + +MODULE_ALIAS("platform:xilinx-pwm"); +MODULE_DESCRIPTION("Xilinx LogiCORE IP AXI Timer PWM driver"); +MODULE_LICENSE("GPL v2");