Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp104100imm; Mon, 1 Oct 2018 07:20:36 -0700 (PDT) X-Google-Smtp-Source: ACcGV613lBiPD71PSNhrTXxxWTEDCbDXZ75b44BNd6+e9sMv2jftu448cavlLDu0zbi1BHeGMY81 X-Received: by 2002:a62:6d02:: with SMTP id i2-v6mr11894527pfc.218.1538403636532; Mon, 01 Oct 2018 07:20:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538403636; cv=none; d=google.com; s=arc-20160816; b=lA2arBtPX9GTK0/rYbpTw6qokw5ogYYyD8ZzVv/wCNAJCh9OvjJnbIiHRUSr4Wx6gd yoS6lrG9Z5XFphpVhMXpNtk2QLj0h62OOXBzg/Ea8tDHNxaAV4tij25iR6/nIsxqV44/ quKqd3V8NjYm+OQB2jbmBFEK2Ak/3uUTwiSFoVuZTm0zhtLeV7uRyXIhuwo7KwZo1VmG vmnQmsAAoSW65kz/mxABjQU0g7X/kUn9Ry3Bt9q5U+A9IeMMREb11re26prOqUdz/NMP RVKyNjA09B80GHyK3bLtB71nh0hQJpinY/xlzGAgKf1txce67lrK2GwbRC1++xFHU3vq FSUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aCe8FG4/Mz4NvX5trCge4u7yH0hCkDIqhLumUMeuZYs=; b=qhUIgL5RNxJnUHyXum8CHYsBO4K/+4d7yW/fq+Vgj0iR2uarIvnSH/xK4lNdqHf/tD SkwKz9X6ov8UWWGPfnlPkuLNg3Br4sBE+Un8ndxk3JaTFXaLYnkLqCxwDHl5nUNWixln 4HhJrZsQYMiG2nZY++5vzJ2zbNZwUZcrjwH/3LtUqK9DcHeMt2n7/gwRN5SsEEclT0lb ppvAWEfeeUTiX5FCZYpfvrf6D6qE4pLAnfPWQI3JQgxFLFdlQbxMuZVZvqmlwgjjhJca 0JGZOYu2HcgNKKqZCiGjl3v0bIQ5YnHeoD3xfusb4bmGUwqdXZbjVLuDXLU/lMF6LQLB em/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ysoft.com header.s=selector1 header.b=FXCd5Bct; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ysoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ba6-v6si12472286plb.364.2018.10.01.07.20.21; Mon, 01 Oct 2018 07:20:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ysoft.com header.s=selector1 header.b=FXCd5Bct; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ysoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729517AbeJAU6L (ORCPT + 99 others); Mon, 1 Oct 2018 16:58:11 -0400 Received: from mail-eopbgr00050.outbound.protection.outlook.com ([40.107.0.50]:42264 "EHLO EUR02-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729272AbeJAU6J (ORCPT ); Mon, 1 Oct 2018 16:58:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ysoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aCe8FG4/Mz4NvX5trCge4u7yH0hCkDIqhLumUMeuZYs=; b=FXCd5Bct/5D51uivs8LossmEx6W9l1mA9Scc6Ovqc6BVBsPIzEbMhGNIKa2pXalmLyROQ/Ed2UAxoQAULzy5p+S/jnImjfYRnoMb+3315wchYEemUuYeqDMNVUKAzatcHal+7Iujh6DJZ2C7kyzytsTNeAXNHmr08f+wIVzrRXA= Received: from iota-build.ysoft.local (89.24.100.190) by AM0PR04MB4659.eurprd04.prod.outlook.com (2603:10a6:208:75::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.25; Mon, 1 Oct 2018 14:20:00 +0000 From: =?UTF-8?q?Michal=20Vok=C3=A1=C4=8D?= To: Thierry Reding Cc: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Michal=20Vok=C3=A1=C4=8D?= Subject: [PATCH 2/3] pwm: imx: Use bitops and bitfield macros to define register values Date: Mon, 1 Oct 2018 16:19:47 +0200 Message-Id: <1538403588-68850-2-git-send-email-michal.vokac@ysoft.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1538403588-68850-1-git-send-email-michal.vokac@ysoft.com> References: <1538403588-68850-1-git-send-email-michal.vokac@ysoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Originating-IP: [89.24.100.190] X-ClientProxiedBy: VI1PR03CA0048.eurprd03.prod.outlook.com (2603:10a6:803:50::19) To AM0PR04MB4659.eurprd04.prod.outlook.com (2603:10a6:208:75::13) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 87be7f75-4dde-40df-79b4-08d627a8f8e4 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:AM0PR04MB4659; X-Microsoft-Exchange-Diagnostics: 1;AM0PR04MB4659;3:SdhUADnb51ebN5HKfszolJcqSaRsDJK8irdr+uJ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jeqxNVGq+fk16V43pNdr42CkWQpsh3o7aIHsfJApNGLiaNMFC7kpFLUa;4:nj/wr69/6fuyyqYOwNsjkVigF/+si8LxuiP1Bjq5Mln5/SISXxgULCC9KoqVz5Bc4n2Dt7e5pq83DOflU7Utv8FQxP7nhRc8Hhht+lIZi+Ma4f+tw3E6w5GP8BBRRAe/iTEEPZPL9dt2E7q8qvv39MxXeaMa/Ca6rBJ5GCy+ggWfXW8lomjeMcBgFbiAJHRbX8H+Lgy4TrxU8aCBgWu5xdw+X06xVLgjPKd2zGHGsMAoYBrCdF2ME96F2/DOqdB8RZP8vkIHY2FXXiARoxrLuA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(3231355)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(149066)(150057)(6041310)(20161123562045)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(201708071742011)(7699051)(76991041);SRVR:AM0PR04MB4659;BCL:0;PCL:0;RULEID:;SRVR:AM0PR04MB4659; X-Forefront-PRVS: 0812095267 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(136003)(366004)(396003)(39850400004)(376002)(346002)(199004)(189003)(6506007)(386003)(6512007)(316002)(36756003)(3846002)(6116002)(53936002)(34290500001)(23676004)(575784001)(86362001)(52116002)(6486002)(76176011)(11346002)(6916009)(476003)(2616005)(956004)(6666003)(50226002)(68736007)(2906002)(8936002)(5660300001)(446003)(81166006)(8676002)(81156014)(486006)(97736004)(105586002)(106356001)(478600001)(72206003)(25786009)(4326008)(39060400002)(186003)(16526019)(6346003)(26005)(7736002)(305945005)(2870700001)(107886003)(50466002)(47776003)(66066001);DIR:OUT;SFP:1101;SCL:1;SRVR:AM0PR04MB4659;H:iota-build.ysoft.local;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: ysoft.com does not designate permitted sender hosts) Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Michal.Vokac@ysoft.com; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtBTTBQUjA0TUI0NjU5OzIzOmZZV0RFOTRoVWRNdmRTcXlRZ2FKM1JvUUh2?= =?utf-8?B?bDcreVAzN3FsZ1FkWlJOR055K2dvaktEeEJyYWVycFRCV0xXNmFjM2xrMHBF?= =?utf-8?B?VnRoNmRGcW1yODlTLzRlUkRXWmIxOHpJWjFaQTZWa2ZNRGIwbHhONWdXcHRt?= =?utf-8?B?K21RMDZ6T2JmY1BZSnhYd0FyUE8zN2hoaXJ6UXIwSEFtTStpdEJhSUt5Q0d1?= =?utf-8?B?NW5SSnZ6Q2tjSGhwcm80R3hIb2x4QVMzNzB3cEZ6UFlKNVo4UkJYeENUV1hP?= =?utf-8?B?YmtVOFlzbUYweDZlY1hTVlFaT2g2Q2hQWHlRcFAzaVowRkNRa3NmcEZ1Z2ty?= =?utf-8?B?U2VuQzhLY01wcmxvZWE5eWVKZkZ4NVlQYjVweExybHVaci8yZ3ZuSCsxejlU?= =?utf-8?B?RGNFWnBGdU5ZVms5K0hnM3YzRW41bXorYlhuaVZTbFdkSmJpYzZSZFBjNmUz?= =?utf-8?B?UjlBZWxVT05tTWtob1psdHhOSmlxckh5elBacmRodVZ0UVlGanlEd3dWTW1t?= =?utf-8?B?WmpSSHB4Rk1zSnpWc1psT1F2WUlUSkN3ditjUlFoU1RiazZNQlljQVhKTW1W?= =?utf-8?B?eEVJTTFRYi9qdE5SdkhwVlh2OHBtdk4yWlczdjF2YkNiTWhQelljZ3YxRzd1?= =?utf-8?B?TmNSeXFjdytYL1ZyZXBqcEFIZGh4c05QbWVvYmlDaHVybXpQaG5lc2t1aGtk?= =?utf-8?B?SU1zQ0ZiY3F4UEgyK0tKZzBsaWdkUVpqQmE0K1pRc0F0alVSRzl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zkNthTUk+3WSuHcMMbla2m9MdtWxooCNb7WLi2nO8o1wF5TQCst0o+WgF2W2q7IT/h9jdHgetAvvX0ghuUbNA2b4KUEBa2L9pN9RHYmeItR1N5V/3Y7+4BERrkKoK7wnDk8k+2d5/SsToLJc=;7:lWj40ecI3MP8D3WGdN/jEZlfkJARunigUlPODBDTpJgsJIi6sFbs9fZriNCQ6UcRmW1ZN1wW7bVn1g8+YnwaWm7U5YBxwxoE0AxDGvE5EMUyjI23j278OEm7L4bGnLYhR4Kt/jPZomxgWbPyFi5NdhspPPsj+z1CP0EbK3GcPVvlQZanFWdKBIGzlwq2guu9T4IfH1DqL26q3CYyTiNp53ysHO32a5GH/xAz9w8O8q4JYfF7VNV38XsGsoHCYB3h SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: ysoft.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2018 14:20:00.0715 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 87be7f75-4dde-40df-79b4-08d627a8f8e4 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b5839965-430f-4be2-b282-d7a3149f2b37 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4659 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use existing macros to define register fields instead of manually shifting the bit masks. Also define some more register bits. Signed-off-by: Michal Vokáč --- drivers/pwm/pwm-imx.c | 78 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 20 deletions(-) diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c index bcbcac4..7a4907b 100644 --- a/drivers/pwm/pwm-imx.c +++ b/drivers/pwm/pwm-imx.c @@ -5,6 +5,8 @@ * Derived from pxa PWM driver by eric miao */ +#include +#include #include #include #include @@ -23,7 +25,7 @@ #define MX1_PWMS 0x04 /* PWM Sample Register */ #define MX1_PWMP 0x08 /* PWM Period Register */ -#define MX1_PWMC_EN (1 << 4) +#define MX1_PWMC_EN BIT(4) /* i.MX27, i.MX31, i.MX35 share the same PWM function block: */ @@ -31,18 +33,53 @@ #define MX3_PWMSR 0x04 /* PWM Status Register */ #define MX3_PWMSAR 0x0C /* PWM Sample Register */ #define MX3_PWMPR 0x10 /* PWM Period Register */ -#define MX3_PWMCR_PRESCALER(x) ((((x) - 1) & 0xFFF) << 4) -#define MX3_PWMCR_STOPEN (1 << 25) -#define MX3_PWMCR_DOZEEN (1 << 24) -#define MX3_PWMCR_WAITEN (1 << 23) -#define MX3_PWMCR_DBGEN (1 << 22) -#define MX3_PWMCR_POUTC (1 << 18) -#define MX3_PWMCR_CLKSRC_IPG_HIGH (2 << 16) -#define MX3_PWMCR_CLKSRC_IPG (1 << 16) -#define MX3_PWMCR_SWR (1 << 3) -#define MX3_PWMCR_EN (1 << 0) -#define MX3_PWMSR_FIFOAV_4WORDS 0x4 -#define MX3_PWMSR_FIFOAV_MASK 0x7 + +#define MX3_PWMCR_FWM GENMASK(27, 26) +#define MX3_PWMCR_STOPEN BIT(25) +#define MX3_PWMCR_DOZEN BIT(24) +#define MX3_PWMCR_WAITEN BIT(23) +#define MX3_PWMCR_DBGEN BIT(22) +#define MX3_PWMCR_BCTR BIT(21) +#define MX3_PWMCR_HCTR BIT(20) + +#define MX3_PWMCR_POUTC GENMASK(19, 18) +#define MX3_PWMCR_POUTC_NORMAL 0 +#define MX3_PWMCR_POUTC_INVERTED 1 +#define MX3_PWMCR_POUTC_OFF 2 + +#define MX3_PWMCR_CLKSRC GENMASK(17, 16) +#define MX3_PWMCR_CLKSRC_OFF 0 +#define MX3_PWMCR_CLKSRC_IPG 1 +#define MX3_PWMCR_CLKSRC_IPG_HIGH 2 +#define MX3_PWMCR_CLKSRC_IPG_32K 3 + +#define MX3_PWMCR_PRESCALER GENMASK(15, 4) + +#define MX3_PWMCR_SWR BIT(3) + +#define MX3_PWMCR_REPEAT GENMASK(2, 1) +#define MX3_PWMCR_REPEAT_1X 0 +#define MX3_PWMCR_REPEAT_2X 1 +#define MX3_PWMCR_REPEAT_4X 2 +#define MX3_PWMCR_REPEAT_8X 3 + +#define MX3_PWMCR_EN BIT(0) + +#define MX3_PWMSR_FWE BIT(6) +#define MX3_PWMSR_CMP BIT(5) +#define MX3_PWMSR_ROV BIT(4) +#define MX3_PWMSR_FE BIT(3) + +#define MX3_PWMSR_FIFOAV GENMASK(2, 0) +#define MX3_PWMSR_FIFOAV_EMPTY 0 +#define MX3_PWMSR_FIFOAV_1WORD 1 +#define MX3_PWMSR_FIFOAV_2WORDS 2 +#define MX3_PWMSR_FIFOAV_3WORDS 3 +#define MX3_PWMSR_FIFOAV_4WORDS 4 + +#define MX3_PWMCR_PRESCALER_SET(x) FIELD_PREP(MX3_PWMCR_PRESCALER, (x) - 1) +#define MX3_PWMCR_PRESCALER_GET(x) (FIELD_GET(MX3_PWMCR_PRESCALER, \ + (x)) + 1) #define MX3_PWM_SWR_LOOP 5 @@ -142,14 +179,14 @@ static void imx_pwm_wait_fifo_slot(struct pwm_chip *chip, u32 sr; sr = readl(imx->mmio_base + MX3_PWMSR); - fifoav = sr & MX3_PWMSR_FIFOAV_MASK; + fifoav = FIELD_GET(MX3_PWMSR_FIFOAV, sr); if (fifoav == MX3_PWMSR_FIFOAV_4WORDS) { period_ms = DIV_ROUND_UP(pwm_get_period(pwm), NSEC_PER_MSEC); msleep(period_ms); sr = readl(imx->mmio_base + MX3_PWMSR); - if (fifoav == (sr & MX3_PWMSR_FIFOAV_MASK)) + if (fifoav == FIELD_GET(MX3_PWMSR_FIFOAV, sr)) dev_warn(dev, "there is no free FIFO slot\n"); } } @@ -207,13 +244,14 @@ static int imx_pwm_apply_v2(struct pwm_chip *chip, struct pwm_device *pwm, writel(duty_cycles, imx->mmio_base + MX3_PWMSAR); writel(period_cycles, imx->mmio_base + MX3_PWMPR); - cr = MX3_PWMCR_PRESCALER(prescale) | - MX3_PWMCR_STOPEN | MX3_PWMCR_DOZEEN | MX3_PWMCR_WAITEN | - MX3_PWMCR_DBGEN | MX3_PWMCR_CLKSRC_IPG_HIGH | - MX3_PWMCR_EN; + cr = MX3_PWMCR_PRESCALER_SET(prescale) | + MX3_PWMCR_STOPEN | MX3_PWMCR_DOZEN | MX3_PWMCR_WAITEN | + FIELD_PREP(MX3_PWMCR_CLKSRC, MX3_PWMCR_CLKSRC_IPG_HIGH) | + MX3_PWMCR_DBGEN | MX3_PWMCR_EN; if (state->polarity == PWM_POLARITY_INVERSED) - cr |= MX3_PWMCR_POUTC; + cr |= FIELD_PREP(MX3_PWMCR_POUTC, + MX3_PWMCR_POUTC_INVERTED); writel(cr, imx->mmio_base + MX3_PWMCR); } else if (cstate.enabled) { -- 2.1.4