From patchwork Fri Feb 4 18:01:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 12735422 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A541AC433EF for ; Fri, 4 Feb 2022 18:03:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=q906Scrl22an8icXe3sbloMj0nMcYdE6vz4LZuBeKRg=; b=nSYuTpOoXM3XZa yU7mzlsk74UAfglTNugFw5v1UKMjzlYBRdKLqJylu4zVGyQkmtFblhBwbgMVpbXwSkEfQZCYlsn2H Dhs/g3frVjECUwbZ9UkWyuWa5v4hYkCY52EzkTTOXmgyOwfHrmmQ0wQjwriNp/3Jo/diLeKJ1U5AN feVFH62vW0J8rHWzwMXjWixxjzMSTu/tzWie5KLeoQ2EZ5ebSZEVKEy+fMS9MBCO/jjPwIo8+om2v /pzEoVK2EPbvvno4/ENHrTgpBxbOF9JUFdYd0NveGYyqoWSJ8Q/f/Run/ARNSdSoU4Qph55na+xYU Z2bh5FXK0h+FEAuqTctw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG2tz-0056ML-2l; Fri, 04 Feb 2022 18:01:43 +0000 Received: from mail-am6eur05on2040.outbound.protection.outlook.com ([40.107.22.40] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG2tu-0056L6-W3 for linux-arm-kernel@lists.infradead.org; Fri, 04 Feb 2022 18:01:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MiIEYgB2auWSCQ3WV4fqWmPDfp0kfWCh8nKuub8SykuMZzl5vjo7QOQ+8QJX0J6HoUfpmiBu6qbcunG5XkT1d0ccekimRXWZ1w1BWilAlLhXvggw3hi0Uwn6Bxb8XRr+4bhN0mSWFgbVGNtaqHHgNqpFAUmREKjz0BxQGjMtMGXz3UKf7uOEuMyT/Bby8s1xhGeQOwakd1M8jzcvELcHVC2J1CvrjNaNaNPlW6xbThE4VzI8j6lbpY5SrmTVL7zfAQAPoK2suYY6Z8DYnaDQqz7FVCpNJquUuAwP/KzUnkvX/BvFjCU+bZgdiSCvpPfroZIUOToo2JCYxK9YoJ7DNQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5K6zQeSq3sQcrKCaApSUoICBfsJi/RsiIe4H2tEgccw=; b=VWM1gKLSVGkJU/oAkXyiSozt9xpnndYf40ztTCKvToezYrH+0obDrMLztYxL0H2ePIALsnkJU6WxewtpQSPm3g6JYJkGH2Jww+dliRaq1cvL+OZQQOSCBAmv7qJb6kptksJmLr5GTCZTqCWQyx4/Y15oIPbu/BiPHPw88fIo25RZ0+2KjiAMDSPkMJMewX+sEJ12SmwCESx8Nuk1iJIVqRvaIyLJDADDI8HNZtEcHYN2FH0qA3Azr3Qxjf97unnraqOIoghoQ/N1wSDC64eMc6SDEvd6u7s/wp3OpeLLcFBp1NL9vYkO6Ntns1Fas/uunTRn9uBu9G0LJanTiDwxhA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5K6zQeSq3sQcrKCaApSUoICBfsJi/RsiIe4H2tEgccw=; b=cPTz0mdwsc3GHmhWPyjYwIBJt9ZAyfWVxCR+RqivJnX2hNrDxDY3IpcaIZWnfeavG8x8cx1kZmu74MccxZoAOL+eH+PmJaWHH7PfcHYF3qc7TXLmiyEyKWsgm5EqDEvQLV/HBrF6E0JbDNn0pkViDRRTY1F/XGx4kccbBzBSYf5F9zAfCK7Pc3YY/aNe5mZmB09gqTGFUX5Teo/tFZhnDrjlsU5un5j0Ng+M0vEdH17Ihq0f0uqqqIkAplGbeM4BzCY6dJRw5+vSQIjCRjWNUS3EFtI/TeybAA9sDFv6owKq8KKx9ZRDeAdeJj5phB+3gcdgu3Sun6ZbgRsVVynQaQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) by AM0PR03MB5764.eurprd03.prod.outlook.com (2603:10a6:208:173::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.14; Fri, 4 Feb 2022 18:01:36 +0000 Received: from DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::ed45:f086:5e82:fccd]) by DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::ed45:f086:5e82:fccd%4]) with mapi id 15.20.4951.016; Fri, 4 Feb 2022 18:01:35 +0000 From: Sean Anderson To: linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, Thierry Reding Cc: linux-arm-kernel@lists.infradead.org, Alvaro Gamez , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Mubin Usman Sayyed , linux-kernel@vger.kernel.org, michal.simek@xilinx.com, Lee Jones , Sean Anderson , Rob Herring Subject: [PATCH v13 1/2] dt-bindings: pwm: Add Xilinx AXI Timer Date: Fri, 4 Feb 2022 13:01:05 -0500 Message-Id: <20220204180106.154000-1-sean.anderson@seco.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: BL1PR13CA0433.namprd13.prod.outlook.com (2603:10b6:208:2c3::18) To DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 204f03f5-401d-45c2-bb28-08d9e808626a X-MS-TrafficTypeDiagnostic: AM0PR03MB5764:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QVaKYXqNF8BlhuoxhelPRVNeOhmBCJAuWeYFEiFdwY9O9idLWZ99+WYcXMcTnE08vHYkMdSSjLJ8D487qUJRBw3Xi6vJ0iSMvQNUERI70imGZX1V6fLkLVGjEpkRgikSfGOI5ZqOePeznZ5qHQ0CGGGqibOe8jDBZXGj4hY3jEV7vbS9V/i/YaRK8Pb6rDinupshaJ+9oxC5uYWThxKxpAituu7WK6HrEt5RDVniS++D75c9tm6Xz2iW5TUZOiWnwNfQfJEjz5mecAthd63O/C6sOIdAf3UQ0syQVtFXA5eOcj10UsY79DFfUxsTP0zRG9AQyXj51OPzKQBoU7fOQxPPbesX03XHO4Oni6Yq+AarQZUr5a+Rgd9RGJVl3SmK6dblKSxAhG+o0+c3/nGMi+/QrWZKT88ePukubWZO+STRVvz8eBg/nkBmcvIZ9TLsIoeQcorqHCMj63t5TzPDc3stCE0pbqFLoNnbXMmLIsm7lZ6XqW91mjVllWlTdVLukkDyuNuKJYrB211tu8N5VSluHYwjNkAWc83Z8FJgIAOJXR2pKtPj4aRHnLd98FebHI11lY2xu3i7viW4DqWiK5eNJU3XCkFl1aMMGLl7YWX/SwvA87+jTmxEsjRoBTFUiM+BKRv2whnbb8yXWOjHMA0dpm0QYKskjPaP6U37Y4+TXKeATP1YAGdVhYf1WiK/ExbnCuS+K3M1bdC0wfOSCmaXS3mh0yPF1KZhbn61Ky2P+j6wqRrCj7aJe0wtUa4Qzn0yqaS0GNm5zJkHnH8dctpGRiwIq0wGNwJ+LNo7c48= 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:(13230001)(366004)(6512007)(83380400001)(52116002)(66556008)(6506007)(38100700002)(66476007)(86362001)(36756003)(8936002)(4326008)(6666004)(316002)(38350700002)(8676002)(66946007)(7416002)(5660300002)(2616005)(2906002)(26005)(1076003)(186003)(54906003)(6486002)(44832011)(6916009)(966005)(508600001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bvGgz7csUoYVBKYsg9ZFprzfwHetVmclmF/Gj+YXXXnLhTr49t0QCprZKhL18P5VLb3bA7MHvB1KwEueI4WX5TrZtTHwySJYT7X2m8LOvSrzBygNcwVxNvaCCy9noTo/Lb6uuIzFKn12oRz9Db4kl8QnhKsf5wxZknq2cRHbJOijvTwBLPZow1biRZk4yk9uvjiunopxHchI7WyDWLPjiX5TuXtiHT+LyuGdCYr7pSbLfjWLTHBSi5ZvZCW8NpZ7oZl2jWZbrL7ZPxse9qdZa3Ehf1aIfVc+eIS852DKoAFrCpOwztlRw/cXh98HG2+MQQ8iyLnHB/bsEWzsaZKsm8LC8L+dK1nb1YJHELJLJJJHlWsDgVVuvNogq+8Kxy5rMzWRFUeQbhUCYFDOXRMVTINHuQlpNeD8aDr9+DZDEoTDyUT7xMdRnQpRoaCZoEN+tuECowVb7viU/4u6xhiO8JD23i1yRCoSqYyr3jaW9kcjNdEw3z9HtBEH/i7kI9kMjDEOFjIC5o6SuJ4B1JU0mnOeZ9V0C5Ih0FvNTj6/tTK0wXD/FVkp0Qaml32HEhF+yh9RnY+Tti6v9FS7UZdcHgxc+hkri0xArIfbEA09v/9wKJxtsy+4PFGAJiug3CkDLczaQukuoXNJ/FFDmM5Zf7wglKvo9wgCAPCxQgF7R6uFMeB/8p+HXQnVxaCv6dsE4JgecaXm0iyXHyl+g07+arjQqcHGHBf8RADl0IJq1RrazJbOcG6T/FRezr5hAt8LxFeJ6MT4btQ+iQxOkF9bZTHaIAfcssGyzU/PU9X42CLteWl0Lp6EdJmpGcZE1j0134MgGsKJzERcCCUFEgPra/nB5rvO21gKx0beRtEM+lOgcVRdcczGynUpbXnihqnN8b/WW5nF79ExLDUG+nTE3elB/ZjNhMOUwZgy+XISN6JisNuTmmy8Fs2kmSdMd2Xs3lEzYHy661EwawKyHfFqtOFzINFcqzfBLgy/T47LSeG6lmPyS9++iLOuR3fYKqwRO0Tp70DMHlWdTpX8imT0hoEjudrvMQpSTJbmOzzEdj86QhLOED/con3YZm+ywsGkcg9E3xyyXwIfDe09gNuI40zL/3Er6QVPV4pzuwk/GpPmgPnSJ35g4rdGxp09R9i68T4qTmSfFEYd6mI4yAGXXB2hJ1eTS7nyMGUU4trxi4NRDOQrG84oB82Ni4/8iUuhcPMJUpZlQbWS2HPOivh5MCKCsCEKD2Daizlaqy1WHHrM72kz5u+GaCIxYK7puL5JlqpmgkSfYML0qGsjICDJ99Fd0uAtLqi0N7DvHKRIvtK9gtWgywZjo0JO+O16n3JaxrkwgobKule5Hx/H8VOyMYptxXh4Z+/4jUivKuv8Ivp0rqDoKKyR+fkpBX3yUDbpeUYu4ifJMOhQWvr+i8qhWvioJ0RhAsSZ/uzGesFQxm0ikbaUNivwGajW9sDhDg9GCUOu3ZhzT6X7xdOJBXQv8whafP6QQM2rNIqCB2aXyxMEtJmFikjXbuDL1kNgfqeUy/whI0k0t8+ENOONCjkVnr/ZSQGAGjznTQvU8ho40CvlDeePf8lp21BvjcTi7ApEavlggyrzbGbJMz5u4in+fkJpE+Zd30IxDkvTeH4k17Y= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 204f03f5-401d-45c2-bb28-08d9e808626a X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4523.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2022 18:01:35.9117 (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: Z5VBL5wduK4IkP+SCvDTXizBOhJI9xQw0sXjCvIlHyp136fHdBGkQz0YLGtGyIBMMcy1Khk5tkMRmFR4Wmywqw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR03MB5764 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220204_100139_059376_11E4B553 X-CRM114-Status: GOOD ( 19.37 ) 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 some 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 some properties should be kept as they are, if possible. In addition, this binding is already in the kernel at arch/microblaze/boot/dts/system.dts, and in user software such as QEMU. The existing driver uses the clock-frequency property, or alternatively the /cpus/timebase-frequency property as its frequency input. Because these properties are deprecated, they have not been included with this schema. All new bindings should use the clocks/clock-names properties to specify the parent clock. Because we need to init timer devices so early in boot, we determine if we should use the PWM driver or the clocksource/clockevent driver by the presence/absence, respectively, of #pwm-cells. Because both counters are used by the PWM, there is no need for a separate property specifying which counters are to be used for the PWM. Signed-off-by: Sean Anderson Reviewed-by: Rob Herring --- (no changes since v8) Changes in v8: - Set additionalProperties: false Changes in v7: - Add #pwm-cells to properties - Document why additionalProperties is true Changes in v6: - Enumerate possible counter widths - Fix incorrect schema id Changes in v5: - Add example for timer binding - Fix indentation lint - Move schema into the timer directory - Remove xlnx,axi-timer-2.0 compatible string - Update commit message to reflect revisions Changes in v4: - Make some properties optional for clocksource drivers - Predicate PWM driver on the presence of #pwm-cells - Remove references to generate polarity so this can get merged Changes in v3: - Add an example with non-deprecated properties only. - Add xlnx,pwm and xlnx,gen?-active-low properties. - Make newer replacement properties mutually-exclusive with what they replace - Mark all boolean-as-int properties as deprecated Changes in v2: - Use 32-bit addresses for example binding .../bindings/timer/xlnx,xps-timer.yaml | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 Documentation/devicetree/bindings/timer/xlnx,xps-timer.yaml diff --git a/Documentation/devicetree/bindings/timer/xlnx,xps-timer.yaml b/Documentation/devicetree/bindings/timer/xlnx,xps-timer.yaml new file mode 100644 index 000000000000..dd168d41d2e0 --- /dev/null +++ b/Documentation/devicetree/bindings/timer/xlnx,xps-timer.yaml @@ -0,0 +1,92 @@ +# SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/timer/xlnx,xps-timer.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Xilinx LogiCORE IP AXI Timer Device Tree Binding + +maintainers: + - Sean Anderson + +properties: + compatible: + contains: + const: xlnx,xps-timer-1.00.a + + clocks: + maxItems: 1 + + clock-names: + const: s_axi_aclk + + interrupts: + maxItems: 1 + + reg: + maxItems: 1 + + '#pwm-cells': true + + xlnx,count-width: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [8, 16, 32] + default: 32 + description: + The width of the counter(s), in bits. + + xlnx,one-timer-only: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 0, 1 ] + description: + Whether only one timer is present in this block. + +required: + - compatible + - reg + - xlnx,one-timer-only + +allOf: + - if: + required: + - '#pwm-cells' + then: + allOf: + - required: + - clocks + - properties: + xlnx,one-timer-only: + const: 0 + else: + required: + - interrupts + - if: + required: + - clocks + then: + required: + - clock-names + +additionalProperties: false + +examples: + - | + timer@800e0000 { + clock-names = "s_axi_aclk"; + clocks = <&zynqmp_clk 71>; + compatible = "xlnx,xps-timer-1.00.a"; + reg = <0x800e0000 0x10000>; + interrupts = <0 39 2>; + xlnx,count-width = <16>; + xlnx,one-timer-only = <0x0>; + }; + + timer@800f0000 { + #pwm-cells = <0>; + clock-names = "s_axi_aclk"; + clocks = <&zynqmp_clk 71>; + compatible = "xlnx,xps-timer-1.00.a"; + reg = <0x800e0000 0x10000>; + xlnx,count-width = <32>; + xlnx,one-timer-only = <0x0>; + }; From patchwork Fri Feb 4 18:01:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 12735423 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4E1CDC433FE for ; Fri, 4 Feb 2022 18:03:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=3zmQ3E2vIo2JoQqsSsc9qkFmFwS9+hGFHRudn4AzIG4=; b=nECyFmQ0cQc+bO f+RCXgUwBSYAA5NA0trB2cgnP0DAGAFWtWWVJ2S+v5G9PRBuodnn0vw7O6MilWChx62YL7pl1u/Cf 6C3m9REfcFaYKktRKsxdfuZV3NjX4CTEO/PLcLL7yknz3LO5kh8cBwUmikcu5rawRR5sbeWLpYgmD tDxLKnnR2kWh4ls6VDlfDYumeXNNYFejVKNhxU+lOFu3GHNwQPd0PDtg/CK7VMYyS5WpglI+rqrzC txdUSvpUd7GuGZvzPQ6dhG3M03Cx3162w/biqyI4PSdBrXGI4iiM+JPHytz0rYPiHRfwtI87DyiTF oAsh8CAAC+CbUqM0GXxA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG2u9-0056OX-4b; Fri, 04 Feb 2022 18:01:53 +0000 Received: from mail-am6eur05on2040.outbound.protection.outlook.com ([40.107.22.40] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG2tx-0056L6-3T for linux-arm-kernel@lists.infradead.org; Fri, 04 Feb 2022 18:01:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mGrioQDjs41Lg03mQaIDHYuumOMO3fLQ5BUqyTvlI7j/G99t2JYcYzJc0xEkN/SjP0f0eADF4wVvCccLpvIrvDImlpwyW7kRctrtZXF6f9ZWeiK63lpRyj8aGYYIJAsReaBQGwF2HjvB4jCIh2w4p2i2HaUhXdJTfCEq+uvCUZHvc0yF7xIqkoMFRtMSIJT1x+WK8ZYPV0MK34/x+fPFRHDEzghO41mSNX5+TbvwUWA5vFq91GxH7F1DXnO+J48Y93LxEOPGBJMK2G5+RgRTD38VjGdSf2MK3XTg71/QoNGLUGbrJ6pryQCSwS3Ffc+cqEv9sfXoEBVeFTDeKVVqiQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pPn8NMRCrymMl2mfyEHPNie/WnoOhkfDSDzvS1ZQLaE=; b=BCX7xZndK3Qaj8cwCdoC33+Z73/6JDmvlKGP5JDjzAKNMY1P69tv3QpUvpHaN6JCOQn/KesdGEYUFQpi5fxc94XAbMv/iCetVPf1pOpWXzhQOJwWsRrxHp9qJxMqJy2juRsN1U0MALswKnTI6Xt6N4pvmq9wPp9qOKys4UvbKATrleEnXRQzG495H1G2sjxbg5ZRdD0/9gE/e/2Id+iSVdK+8au6NIM6yF1tQrvYWq2fItJsVdTIwRnJLV7z9+8VToZmP6xf0sGzU1NLnoUscvFAvfeHRefhyG1UZSI3nLzJcBBrUmoanFk5bCGeTNzbOOeA6ISaePJBosfUUUjcSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pPn8NMRCrymMl2mfyEHPNie/WnoOhkfDSDzvS1ZQLaE=; b=X6cZRVykkq9jDvrtO781wnaJUKzsNWsbTblt7b+XMvd76NlOdbK8iclvw6t2xaooTh+NZV++vzZz2FPQk8/l6KEVoC+CaJhNZt0upp3fVs1D+dRryWlYd4C30ddas+L+9Ce/jIp9JJLs3LpgE6owr6Gp4BeFsgr2TH/CDJolO86ZOKjAsxvODkTbedgQZkg4qf1p7UyAL0nh6TogZzKzXARzOt7SPadpO8aH4hmpuTcYL22ElBmlmD4b9bKV2yIi/n+aqCZ48TbC6W3ZUaDpSStAERUVHQaIEeYTPcHS3M376rU3u9uZuJWH/uomp/py/oe5QHkFu+LJskO0u/bRKA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) by AM0PR03MB5764.eurprd03.prod.outlook.com (2603:10a6:208:173::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.14; Fri, 4 Feb 2022 18:01:37 +0000 Received: from DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::ed45:f086:5e82:fccd]) by DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::ed45:f086:5e82:fccd%4]) with mapi id 15.20.4951.016; Fri, 4 Feb 2022 18:01:37 +0000 From: Sean Anderson To: linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, Thierry Reding Cc: linux-arm-kernel@lists.infradead.org, Alvaro Gamez , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Mubin Usman Sayyed , linux-kernel@vger.kernel.org, michal.simek@xilinx.com, Lee Jones , Sean Anderson Subject: [PATCH v13 2/2] pwm: Add support for Xilinx AXI Timer Date: Fri, 4 Feb 2022 13:01:06 -0500 Message-Id: <20220204180106.154000-2-sean.anderson@seco.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204180106.154000-1-sean.anderson@seco.com> References: <20220204180106.154000-1-sean.anderson@seco.com> X-ClientProxiedBy: BL1PR13CA0433.namprd13.prod.outlook.com (2603:10b6:208:2c3::18) To DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a1da5ca7-ad87-4641-d0a6-08d9e8086388 X-MS-TrafficTypeDiagnostic: AM0PR03MB5764:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2733; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KNGsMAMxDUPKBgTPsyaXXRpU8zpKq583uUKXVjTMub0jNzVwwOBQI8iiwS247s6nnrLmplqWiNQV3jKxNHZ+HesU2fwo30gF9ZTZeqaaGNfmd5wZnz8NJttAgTLWVo8KGw/bS2xld6i6hJCjeuhFunVe0zf2/ZtEzErJx2pN/ZeVfgiklcXXN5OPjD3nT8SmR74uyD+xDUeqfG5jj9WmW8FZLjiU58rremnSDl1nMZZ4rTAWVbMviWUdE/+Fqf7ZtB56n9r9HZcHU+BaTanmGOVAQt4a+fV1cibPVWUM6biRCKVotFe4NOtD6WqFY149Lcg3HxRMimy0zJ94nogAvnmQ9yfzEGXiWIaAjSK0kb7pG29Vxfx6mmy9TInH12vFkOjQM60bx1ErGs1VDcyZvE+EUQB0e9F1w0tC2Xx0AXk5mt2zM8hkC8FlLBtGs5dVOwuhNwlKmrb+GW/jDXQSZYz5wGUpNIEUlKSdzUaWuRqA60XTFWFVV8do1KlP085l7IlXHct+lvGy0GLfzJG3iKOaNREq2pD9p3POibzvRE8T4cUF0G6JVXytHBB+W40No3H5ed74o3b01g/IjGec0uR1s/Jt2dkzzXSvmvrRgx/cmqGhMKvXgePo6j0EoRjPzOM4lNkqK7/gnqyMVkJG9EycB5UFGl2SEyjMoz61taO2w06ws0EkG8LgAjXrxP6QHEB06+m+0NCNziGGbIlYJuq4XQ96qdF/j2MIJInGUcJSxLWgqTZ82F680hcTcVgUXOY2+jo05+jNp5qNdMfxCS/eZNhlPfKVhAW4wu6Kkso= 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:(13230001)(366004)(6512007)(83380400001)(52116002)(66556008)(6506007)(38100700002)(66476007)(86362001)(36756003)(8936002)(4326008)(6666004)(316002)(38350700002)(8676002)(66946007)(7416002)(5660300002)(107886003)(2616005)(2906002)(26005)(1076003)(186003)(54906003)(6486002)(44832011)(6916009)(966005)(30864003)(508600001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Bd0q8YMbi9idUDw3wHjXg8dXwcWD?= =?utf-8?q?GkwjkNB/ISdjPKpywCU6AG7IRgWZGwutsVmw9vX6vbrnph/HVgaDngFiX+uDu3HQ1?= =?utf-8?q?ShhhTi/mwlgJLF796G8L/AQLKRlBZAN1mjbo4BYsTbrhhhU8VYSwz6XVFuMCCysNn?= =?utf-8?q?ANqyQ3w7lb9SmJ0YtUWuxRwuWDqR2zM+KlxgANp+0qwAG3xpLLCOrlpo/v+eAf9tV?= =?utf-8?q?76anTZWbCCCalXQWstvgO69LCa9GrCXRGurV2hTohSLbFedNTBEn5K31gGi6Zt992?= =?utf-8?q?gJM3+9O4PsQG4cKZTrlk0v27QXrXuiguxY1MhXaTGgIME17/JVeRLHMF3IGSmT4iG?= =?utf-8?q?2bXePAB/trbBX/2rpfpkkbmyjRzSr970sygwQ05SU42jxjiE7HQaeTQAR9ereQrQG?= =?utf-8?q?904lJas/Su6nIqJQllP8VWIoVAlJ+aOX1NhF6KqUlTZTbcdCeBovRyHHx9VRUHQzI?= =?utf-8?q?54ISGIQuI+Etz2BSQJaktkkUgFL2rx8GYb0nKK5sV2o0r1Biq6+YAht/MxBw1IUsd?= =?utf-8?q?BrjyJSdw+HVOV3UbFnxFo31yYEDgoWEl6ACV0TP2bq2qm3QT+Ff6xLwZKmNkTp8ZS?= =?utf-8?q?cyYhJoREVhn5uz7LKfuqfLYLBssU9oufWQvMcWtGEMcDAGduz34ujFAsBfXOesGAL?= =?utf-8?q?XGRBVrXJ0OXHo0sP7eNWwk9RHzSBmE5PH5UjeQPNkUU86SO4ElhtZcXSqVtbi67MD?= =?utf-8?q?Q97Y98xpJCGzeAfb30ph71uTUl+TZpPryHqT9D0J23yxJZyAx+2TkUJg8ijp4W5c0?= =?utf-8?q?6ZOZZgarQRmTbbzPe1ctR+isaTXRNkv5wQhzX9IyRxV7dI85B/Y40FDx1iuOIlEie?= =?utf-8?q?/0rvc4ao8h+20Xo9OUJs4Zz+x2yOKVK2RMRpSzFX3CYroNefr13w/P99n90MAvIOR?= =?utf-8?q?VJPoLtBGnbzSakAm+O1VCuSL7eNeS7NG+SiG30q0KC7ZmiQGsaw73cxs+HKl8fSng?= =?utf-8?q?JFy6AGu0H/28rZdIgrmk9VwQURaCgEalqO/+KKvf0tvCCepgAnO3E73JMM0pKQ0BB?= =?utf-8?q?ep4w+h3HKXFnDOrBc72xmOSnuotTAAIONvKNdygocx5RHMxsmC/+8m1wqGcK19QNd?= =?utf-8?q?ASkgmQ9Bf1v2bEv6STvsy8rnDpBDGdNRPILZq825agetql3iQoNYRYx/e2bDp0jPV?= =?utf-8?q?JVP/3awwqkE7ReJJejmsbH0EirO3iHLjiz8i2tNuXrik5AdT7q7JttGCzv2c1hipp?= =?utf-8?q?+Fyn9DoR64+Gul8Nh5rMVxIJXudpCKXLEdl1GFeTYn1oMHq5cAY2XkN3Rs4wBK8AD?= =?utf-8?q?dHyMwBQcIuKxNHTZh/4s+PrzzFVeZu6Y5/q0A5WFe1cgw1J0SvLIB7xdY9rm4Wwiw?= =?utf-8?q?tRDO7lRZG/z1gg6A+7anS9rkryLVn8NlGyp0sPNIxYBEZdgJ8ojYmtkCxnyFgOcpm?= =?utf-8?q?9xGFTXRmXAyOHBHeiKBEwuT0E+QCZRD1GzAPWTxJA/VrUsiuoyw4iogQpNDcTuIdL?= =?utf-8?q?my8LOX2H42GuaiYhJJS8Cbk07BDKvvyXOEBkSkKPW4lWhlNRez5enPFZ+nqRGY24Y?= =?utf-8?q?eeZgIeKb1dQYZZCb+W8bAgDxNOmE8clQwbFCChg7GP+wasgd8JNBKrM=3D?= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: a1da5ca7-ad87-4641-d0a6-08d9e8086388 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4523.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2022 18:01:37.8803 (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: Yn48CtCeH5W8VbvvgsPotRCS5qxjJnainZJIDgjMPCey3qhANxYdU2R5AKJn9SBSuOTmmj6NS5UGbXs+3wbACQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR03MB5764 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220204_100141_333338_A034DA24 X-CRM114-Status: GOOD ( 37.57 ) 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. At the moment clock control is very basic: we just enable the clock during probe and pin the frequency. In the future, someone could add support for disabling the clock when not in use. Some common code has been specially demarcated. While currently only used by the PWM driver, it is anticipated that it may be split off in the future to be used by the timer driver as well. 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 Acked-by: Michal Simek --- Changes in v13: - Clamp period/duty_cycle by assuming rate is at most U32_MAX - Expand comment in xilinx_timer_get_period - Note that the 100% duty cycle calculations may be wrong for very high clock rates Changes in v12: - Add a comment to the timer driver about #pwm-cells - Combine/expand comments on rounding in xilinx_pwm_apply Changes in v11: - Add comment about why we test for #pwm-cells - Clarify comment on generate out signal - Rename pwm variables to xilinx_pwm - Round like Uwe wants... - s/xilinx_timer/xilinx_pwm/ for non-common functions Changes in v10: - Fix compilation error in timer driver Changes in v9: - Refactor "if { return } else if { }" to "if { return } if { }" - Remove drivers/clocksource/timer-xilinx-common.c from MAINTAINERS - Remove xilinx_timer_common_init and integrate it into xilinx_timer_probe Changes in v8: - Drop new timer driver; it has been deferred for future series Changes in v7: - Add dependency on OF_ADDRESS - Fix period_cycles calculation - Fix typo in limitations Changes in v6: - Capitalize error messages - Don't disable regmap locking to allow inspection of registers via debugfs - Prevent overflow when calculating period_cycles - Remove enabled variable from xilinx_pwm_apply - Swap order of period_cycle range comparisons Changes in v5: - Allow non-zero #pwm-cells - Correctly set duty_cycle in get_state when TLR0=TLR1 - Elaborate on limitation section - Perform some additional checks/rounding in apply_state - Remove xlnx,axi-timer-2.0 compatible string - Rework duty-cycle and period calculations with feedback from Uwe - Switch to regmap to abstract endianness issues - Use more verbose error messages Changes in v4: - Don't use volatile in read/write replacements. Some arches have it and some don't. - Put common timer properties into their own struct to better reuse code. - Remove references to properties which are not good enough for Linux. Changes in v3: - Add clockevent and clocksource support - Remove old microblaze driver - Rewrite probe to only use a device_node, since timers may need to be initialized before we have proper devices. This does bloat the code a bit since we can no longer rely on helpers such as dev_err_probe. We also cannot rely on device resources being free'd on failure, so we must free them manually. - We now access registers through xilinx_timer_(read|write). This allows us to deal with endianness issues, as originally seen in the microblaze driver. CAVEAT EMPTOR: I have not tested this on big-endian! Changes in v2: - Add comment describing device - Add comment explaining why we depend on !MICROBLAZE - Add dependencies on COMMON_CLK and HAS_IOMEM - Cast dividends to u64 to avoid overflow - Check for over- and underflow when calculating TLR - Check range of xlnx,count-width - Don't compile this module by default for arm64 - Don't set pwmchip.base to -1 - Ensure the clock is always running when the pwm is registered - Remove debugfs file :l - Rename TCSR_(SET|CLEAR) to TCSR_RUN_(SET|CLEAR) - Report errors with dev_error_probe - Set xilinx_pwm_ops.owner - Use NSEC_TO_SEC instead of defining our own - Use TCSR_RUN_MASK to check if the PWM is enabled, as suggested by Uwe MAINTAINERS | 6 + arch/microblaze/kernel/timer.c | 4 + drivers/pwm/Kconfig | 14 ++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-xilinx.c | 322 +++++++++++++++++++++++++++++ include/clocksource/timer-xilinx.h | 91 ++++++++ 6 files changed, 438 insertions(+) create mode 100644 drivers/pwm/pwm-xilinx.c create mode 100644 include/clocksource/timer-xilinx.h diff --git a/MAINTAINERS b/MAINTAINERS index f41088418aae..54709e3f09a8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21201,6 +21201,12 @@ F: drivers/misc/Makefile F: drivers/misc/xilinx_sdfec.c F: include/uapi/misc/xilinx_sdfec.h +XILINX PWM DRIVER +M: Sean Anderson +S: Maintained +F: drivers/pwm/pwm-xilinx.c +F: include/clocksource/timer-xilinx.h + XILINX UARTLITE SERIAL DRIVER M: Peter Korsgaard L: linux-serial@vger.kernel.org diff --git a/arch/microblaze/kernel/timer.c b/arch/microblaze/kernel/timer.c index f8832cf49384..26c385582c3b 100644 --- a/arch/microblaze/kernel/timer.c +++ b/arch/microblaze/kernel/timer.c @@ -251,6 +251,10 @@ static int __init xilinx_timer_init(struct device_node *timer) u32 timer_num = 1; int ret; + /* If this property is present, the device is a PWM and not a timer */ + if (of_property_read_bool(timer, "#pwm-cells")) + return 0; + if (initialized) return -EINVAL; diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig index 21e3b05a5153..cefbf00b4c7e 100644 --- a/drivers/pwm/Kconfig +++ b/drivers/pwm/Kconfig @@ -640,4 +640,18 @@ 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 OF_ADDRESS + depends on COMMON_CLK + select REGMAP_MMIO + help + PWM driver for Xilinx LogiCORE IP AXI timers. This timer is + typically a soft core which may be present in Xilinx FPGAs. + This device may also be present in Microblaze soft processors. + 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 708840b7fba8..ea785480359b 100644 --- a/drivers/pwm/Makefile +++ b/drivers/pwm/Makefile @@ -60,3 +60,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..1e7a38bd9b34 --- /dev/null +++ b/drivers/pwm/pwm-xilinx.c @@ -0,0 +1,322 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2021 Sean Anderson + * + * Limitations: + * - When changing both duty cycle and period, we may end up with one cycle + * with the old duty cycle and the new period. This is because the counters + * may only be reloaded by first stopping them, or by letting them be + * automatically reloaded at the end of a cycle. If this automatic reload + * happens after we set TLR0 but before we set TLR1 then we will have a + * bad cycle. This could probably be fixed by reading TCR0 just before + * reprogramming, but I think it would add complexity for little gain. + * - Cannot produce 100% duty cycle by configuring the TLRs. This might be + * possible by stopping the counters at an appropriate point in the cycle, + * but this is not (yet) implemented. + * - Only produces "normal" output. + * - Always produces low output if disabled. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * The following functions are "common" to drivers for this device, and may be + * exported at a future date. + */ +u32 xilinx_timer_tlr_cycles(struct xilinx_timer_priv *priv, u32 tcsr, + u64 cycles) +{ + WARN_ON(cycles < 2 || cycles - 2 > priv->max); + + if (tcsr & TCSR_UDT) + return cycles - 2; + return priv->max - cycles + 2; +} + +unsigned int xilinx_timer_get_period(struct xilinx_timer_priv *priv, + u32 tlr, u32 tcsr) +{ + u64 cycles; + + if (tcsr & TCSR_UDT) + cycles = tlr + 2; + else + cycles = (u64)priv->max - tlr + 2; + + /* cycles has a max of 2^32 + 2, so we can't overflow */ + return DIV64_U64_ROUND_UP(cycles * NSEC_PER_SEC, + clk_get_rate(priv->clk)); +} + +/* + * 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 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_PWM_SET (TCSR_GENT | TCSR_ARHT | TCSR_ENT | TCSR_PWMA) +#define TCSR_PWM_CLEAR (TCSR_MDT | TCSR_LOAD) +#define TCSR_PWM_MASK (TCSR_PWM_SET | TCSR_PWM_CLEAR) + +struct xilinx_pwm_device { + struct pwm_chip chip; + struct xilinx_timer_priv priv; +}; + +static inline struct xilinx_timer_priv +*xilinx_pwm_chip_to_priv(struct pwm_chip *chip) +{ + return &container_of(chip, struct xilinx_pwm_device, chip)->priv; +} + +static bool xilinx_timer_pwm_enabled(u32 tcsr0, u32 tcsr1) +{ + return ((TCSR_PWM_MASK | TCSR_CASC) & tcsr0) == TCSR_PWM_SET && + (TCSR_PWM_MASK & tcsr1) == TCSR_PWM_SET; +} + +static int xilinx_pwm_apply(struct pwm_chip *chip, struct pwm_device *unused, + const struct pwm_state *state) +{ + struct xilinx_timer_priv *priv = xilinx_pwm_chip_to_priv(chip); + u32 tlr0, tlr1, tcsr0, tcsr1; + u64 period_cycles, duty_cycles; + unsigned long rate; + + if (state->polarity != PWM_POLARITY_NORMAL) + return -EINVAL; + + /* + * To be representable by TLR, cycles must be between 2 and + * priv->max + 2. To enforce this we can reduce the cycles, but we may + * not increase them. Caveat emptor: while this does result in more + * predictable rounding, it may also result in a completely different + * duty cycle (% high time) than what was requested. + */ + rate = clk_get_rate(priv->clk); + /* Avoid overflow */ + period_cycles = min_t(u64, state->period, U32_MAX * NSEC_PER_SEC); + period_cycles = mul_u64_u32_div(period_cycles, rate, NSEC_PER_SEC); + period_cycles = min_t(u64, period_cycles, priv->max + 2); + if (period_cycles < 2) + return -ERANGE; + + /* Same thing for duty cycles */ + duty_cycles = min_t(u64, state->duty_cycle, U32_MAX * NSEC_PER_SEC); + duty_cycles = mul_u64_u32_div(duty_cycles, rate, NSEC_PER_SEC); + duty_cycles = min_t(u64, duty_cycles, priv->max + 2); + + /* + * If we specify 100% duty cycle, we will get 0% instead, so decrease + * the duty cycle count by one. + */ + if (duty_cycles >= period_cycles) + duty_cycles = period_cycles - 1; + + /* Round down to 0% duty cycle for unrepresentable duty cycles */ + if (duty_cycles < 2) + duty_cycles = period_cycles; + + regmap_read(priv->map, TCSR0, &tcsr0); + regmap_read(priv->map, TCSR1, &tcsr1); + tlr0 = xilinx_timer_tlr_cycles(priv, tcsr0, period_cycles); + tlr1 = xilinx_timer_tlr_cycles(priv, tcsr1, duty_cycles); + regmap_write(priv->map, TLR0, tlr0); + regmap_write(priv->map, TLR1, tlr1); + + if (state->enabled) { + /* + * If the PWM is already running, then the counters will be + * reloaded at the end of the current cycle. + */ + if (!xilinx_timer_pwm_enabled(tcsr0, tcsr1)) { + /* Load TLR into TCR */ + regmap_write(priv->map, TCSR0, tcsr0 | TCSR_LOAD); + regmap_write(priv->map, TCSR1, tcsr1 | TCSR_LOAD); + /* Enable timers all at once with ENALL */ + tcsr0 = (TCSR_PWM_SET & ~TCSR_ENT) | (tcsr0 & TCSR_UDT); + tcsr1 = TCSR_PWM_SET | TCSR_ENALL | (tcsr1 & TCSR_UDT); + regmap_write(priv->map, TCSR0, tcsr0); + regmap_write(priv->map, TCSR1, tcsr1); + } + } else { + regmap_write(priv->map, TCSR0, 0); + regmap_write(priv->map, TCSR1, 0); + } + + return 0; +} + +static void xilinx_pwm_get_state(struct pwm_chip *chip, + struct pwm_device *unused, + struct pwm_state *state) +{ + struct xilinx_timer_priv *priv = xilinx_pwm_chip_to_priv(chip); + u32 tlr0, tlr1, tcsr0, tcsr1; + + regmap_read(priv->map, TLR0, &tlr0); + regmap_read(priv->map, TLR1, &tlr1); + regmap_read(priv->map, TCSR0, &tcsr0); + regmap_read(priv->map, TCSR1, &tcsr1); + state->period = xilinx_timer_get_period(priv, tlr0, tcsr0); + state->duty_cycle = xilinx_timer_get_period(priv, tlr1, tcsr1); + state->enabled = xilinx_timer_pwm_enabled(tcsr0, tcsr1); + state->polarity = PWM_POLARITY_NORMAL; + + /* + * 100% duty cycle results in constant low output. This may be slightly + * wrong if rate >= 1GHz, so fix this if you have such hardware :) + */ + if (state->period == state->duty_cycle) + state->duty_cycle = 0; +} + +static const struct pwm_ops xilinx_pwm_ops = { + .apply = xilinx_pwm_apply, + .get_state = xilinx_pwm_get_state, + .owner = THIS_MODULE, +}; + +static const struct regmap_config xilinx_pwm_regmap_config = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, + .val_format_endian = REGMAP_ENDIAN_LITTLE, + .max_register = TCR1, +}; + +static int xilinx_pwm_probe(struct platform_device *pdev) +{ + int ret; + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct xilinx_timer_priv *priv; + struct xilinx_pwm_device *xilinx_pwm; + u32 pwm_cells, one_timer, width; + void __iomem *regs; + + /* If there are no PWM cells, this binding is for a timer */ + ret = of_property_read_u32(np, "#pwm-cells", &pwm_cells); + if (ret == -EINVAL) + return -ENODEV; + if (ret) + return dev_err_probe(dev, ret, "could not read #pwm-cells\n"); + + xilinx_pwm = devm_kzalloc(dev, sizeof(*xilinx_pwm), GFP_KERNEL); + if (!xilinx_pwm) + return -ENOMEM; + platform_set_drvdata(pdev, xilinx_pwm); + priv = &xilinx_pwm->priv; + + regs = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(regs)) + return PTR_ERR(regs); + + priv->map = devm_regmap_init_mmio(dev, regs, + &xilinx_pwm_regmap_config); + if (IS_ERR(priv->map)) + return dev_err_probe(dev, PTR_ERR(priv->map), + "Could not create regmap\n"); + + ret = of_property_read_u32(np, "xlnx,one-timer-only", &one_timer); + if (ret) + return dev_err_probe(dev, ret, + "Could not read xlnx,one-timer-only\n"); + + if (one_timer) + return dev_err_probe(dev, -EINVAL, + "Two timers required for PWM mode\n"); + + + ret = of_property_read_u32(np, "xlnx,count-width", &width); + if (ret == -EINVAL) + width = 32; + else if (ret) + return dev_err_probe(dev, ret, + "Could not read xlnx,count-width\n"); + + if (width != 8 && width != 16 && width != 32) + return dev_err_probe(dev, -EINVAL, + "Invalid counter width %d\n", width); + priv->max = BIT_ULL(width) - 1; + + /* + * The polarity of the Generate Out signals must be active high for PWM + * mode to work. We could determine this from the device tree, but + * alas, such properties are not allowed to be used. + */ + + priv->clk = devm_clk_get(dev, "s_axi_aclk"); + if (IS_ERR(priv->clk)) + return dev_err_probe(dev, PTR_ERR(priv->clk), + "Could not get clock\n"); + + ret = clk_prepare_enable(priv->clk); + if (ret) + return dev_err_probe(dev, ret, "Clock enable failed\n"); + clk_rate_exclusive_get(priv->clk); + + xilinx_pwm->chip.dev = dev; + xilinx_pwm->chip.ops = &xilinx_pwm_ops; + xilinx_pwm->chip.npwm = 1; + ret = pwmchip_add(&xilinx_pwm->chip); + if (ret) { + clk_rate_exclusive_put(priv->clk); + clk_disable_unprepare(priv->clk); + return dev_err_probe(dev, ret, "Could not register PWM chip\n"); + } + + return 0; +} + +static int xilinx_pwm_remove(struct platform_device *pdev) +{ + struct xilinx_pwm_device *xilinx_pwm = platform_get_drvdata(pdev); + + pwmchip_remove(&xilinx_pwm->chip); + clk_rate_exclusive_put(xilinx_pwm->priv.clk); + clk_disable_unprepare(xilinx_pwm->priv.clk); + return 0; +} + +static const struct of_device_id xilinx_pwm_of_match[] = { + { .compatible = "xlnx,xps-timer-1.00.a", }, + {}, +}; +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("PWM driver for Xilinx LogiCORE IP AXI Timer"); +MODULE_LICENSE("GPL v2"); diff --git a/include/clocksource/timer-xilinx.h b/include/clocksource/timer-xilinx.h new file mode 100644 index 000000000000..1f7757b84a5e --- /dev/null +++ b/include/clocksource/timer-xilinx.h @@ -0,0 +1,91 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2021 Sean Anderson + */ + +#ifndef XILINX_TIMER_H +#define XILINX_TIMER_H + +#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) + +struct clk; +struct device_node; +struct regmap; + +/** + * struct xilinx_timer_priv - Private data for Xilinx AXI timer drivers + * @map: Regmap of the device, possibly with an offset + * @clk: Parent clock + * @max: Maximum value of the counters + */ +struct xilinx_timer_priv { + struct regmap *map; + struct clk *clk; + u32 max; +}; + +/** + * xilinx_timer_tlr_cycles() - Calculate the TLR for a period specified + * in clock cycles + * @priv: The timer's private data + * @tcsr: The value of the TCSR register for this counter + * @cycles: The number of cycles in this period + * + * Callers of this function MUST ensure that @cycles is representable as + * a TLR. + * + * Return: The calculated value for TLR + */ +u32 xilinx_timer_tlr_cycles(struct xilinx_timer_priv *priv, u32 tcsr, + u64 cycles); + +/** + * xilinx_timer_get_period() - Get the current period of a counter + * @priv: The timer's private data + * @tlr: The value of TLR for this counter + * @tcsr: The value of TCSR for this counter + * + * Return: The period, in ns + */ +unsigned int xilinx_timer_get_period(struct xilinx_timer_priv *priv, + u32 tlr, u32 tcsr); + +/** + * xilinx_timer_common_init() - Perform common initialization for Xilinx + * AXI timer drivers. + * @priv: The timer's private data + * @np: The devicetree node for the timer + * @one_timer: Set to %1 if there is only one timer + * + * This performs common initialization, such as detecting endianness, + * and parsing devicetree properties. @priv->regs must be initialized + * before calling this function. This function initializes @priv->read, + * @priv->write, and @priv->width. + * + * Return: 0, or negative errno + */ +int xilinx_timer_common_init(struct device_node *np, + struct xilinx_timer_priv *priv, + u32 *one_timer); + +#endif /* XILINX_TIMER_H */