From patchwork Wed Oct 16 07:38:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1177648 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lV01Pewh"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46tPLL05qkz9sP7 for ; Wed, 16 Oct 2019 18:38:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726354AbfJPHit (ORCPT ); Wed, 16 Oct 2019 03:38:49 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52823 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729325AbfJPHis (ORCPT ); Wed, 16 Oct 2019 03:38:48 -0400 Received: by mail-wm1-f65.google.com with SMTP id r19so1683967wmh.2 for ; Wed, 16 Oct 2019 00:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8uddH2lljej5bAW7SiuL/aXQPJTgUCIZOjKs3w73ZX4=; b=lV01Pewhmw84HAtrAzdEQiNJTDunw9jVS/+jc63APUpqu13ihpxrQn2xBCiUvXWV/p anMcfv/7Uz8o7P7otBw/FHM2zn6KdmjDnl8rqC/K9mrjqjZcoX9QS9HZWyqjXKx2OqIZ st/DPrpCdV5hE2m+FLAppwcNkjyy611ZfCrE8WLl7tqwem69Rlw0b7LC43L3BW9f1xIz aLGL4JroKJynEfN91ndJkTHNSjT7qLptg667Jh/nauPiXbS6NDyIUdOZKUT5ngpsI8oA YYKEzmBVZOYuZETF62rjRhuCtHLtie3uaEDjtdqX/q35dRxAATdcRlxeiVleZoDfgGxL J5nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8uddH2lljej5bAW7SiuL/aXQPJTgUCIZOjKs3w73ZX4=; b=ZsqsqZeeXfpAmXMZ0Ze3V4b0j3hWWv8Aiw5hnHdm2pVIooRFsl8DdM2Y3o2jJXLsPS juY9Qb+0vs32mWOrpcA3CA1kXsdPLnEaURBPUdObKLrr7XjfbmmM0mJk98EmvBtQVKPB u540Kf6fbNR4zbRn9xNIpbTwCdkmexermU9X9wk3AxZz+fNWixSCJvDYf0eeL1pnHTEl NO2QLZ7gnVhPoGT4Chv60VkFWxZSoeqrmfqgT3Nvmd99T8g9cR+ahqKvXQfS+yS7d1fB svwvSTIcp/bh+/6v7K7/DD1M8YR0vNyrsqfyW4qV+S6lrY9BHDzILzzX49k3d3ayIDeN i9QQ== X-Gm-Message-State: APjAAAXXpTGvqAFPOst2XjovJYOtIRLFiFmq79jFu3C0rO2X0C587ZJ8 a1pIJnUs0fNo+lXzzLGZW4E= X-Google-Smtp-Source: APXvYqxF26fdyeTdezi8eodlzFYf3me4vKpqMmBmaeO70mB4UM0qKK6WV9mMOXTKl0pRk3q9Y7KVUw== X-Received: by 2002:a7b:c7c1:: with SMTP id z1mr1937014wmk.61.1571211526924; Wed, 16 Oct 2019 00:38:46 -0700 (PDT) Received: from localhost (p2E5BE2CE.dip0.t-ipconnect.de. [46.91.226.206]) by smtp.gmail.com with ESMTPSA id n17sm23615263wrp.37.2019.10.16.00.38.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2019 00:38:45 -0700 (PDT) From: Thierry Reding To: Thierry Reding Cc: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Fabrice Gasnier , linux-pwm@vger.kernel.org Subject: [PATCH 1/3] pwm: stm32: Remove clutter from ternary operator Date: Wed, 16 Oct 2019 09:38:40 +0200 Message-Id: <20191016073842.1300297-2-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016073842.1300297-1-thierry.reding@gmail.com> References: <20191016073842.1300297-1-thierry.reding@gmail.com> MIME-Version: 1.0 Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org Remove usage of the ternary operator to assign values for register fields. This removes clutter and improves readability. Signed-off-by: Thierry Reding Reviewed-by: Uwe Kleine-König --- drivers/pwm/pwm-stm32.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c index 9430b4cd383f..b12fb11b7a55 100644 --- a/drivers/pwm/pwm-stm32.c +++ b/drivers/pwm/pwm-stm32.c @@ -493,11 +493,19 @@ static const struct pwm_ops stm32pwm_ops = { static int stm32_pwm_set_breakinput(struct stm32_pwm *priv, int index, int level, int filter) { - u32 bke = (index == 0) ? TIM_BDTR_BKE : TIM_BDTR_BK2E; - int shift = (index == 0) ? TIM_BDTR_BKF_SHIFT : TIM_BDTR_BK2F_SHIFT; - u32 mask = (index == 0) ? TIM_BDTR_BKE | TIM_BDTR_BKP | TIM_BDTR_BKF - : TIM_BDTR_BK2E | TIM_BDTR_BK2P | TIM_BDTR_BK2F; - u32 bdtr = bke; + u32 bke, shift, mask, bdtr; + + if (index == 0) { + bke = TIM_BDTR_BKE; + shift = TIM_BDTR_BKF_SHIFT; + mask = TIM_BDTR_BKE | TIM_BDTR_BKP | TIM_BDTR_BKF; + } else { + bke = TIM_BDTR_BK2E; + shift = TIM_BDTR_BK2F_SHIFT; + mask = TIM_BDTR_BK2E | TIM_BDTR_BK2P | TIM_BDTR_BK2F; + } + + bdtr = bke; /* * The both bits could be set since only one will be wrote From patchwork Wed Oct 16 07:38:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1177649 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FO2Bdpbr"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46tPLN4bR6z9sP7 for ; Wed, 16 Oct 2019 18:38:52 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733256AbfJPHiw (ORCPT ); Wed, 16 Oct 2019 03:38:52 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:54684 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729325AbfJPHiw (ORCPT ); Wed, 16 Oct 2019 03:38:52 -0400 Received: by mail-wm1-f68.google.com with SMTP id p7so1664852wmp.4 for ; Wed, 16 Oct 2019 00:38:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qhc0gHKOvdAh16HP2S+6KVMIuLQLQw2vk1l+n24RLFY=; b=FO2Bdpbr498r/+iBvA2fcNKBWaZbAgzADsEjuLL63RvLxVdHYhZOQZn+r/5yN3B+lw q1mIhoR7CsJ1McKpyu4/N+3Mw95i9lPYG01vB3NAM31mccHCkDkd58ChJ++14zyCfdgZ PSneLmUX5E5nB/pi6rqmGkc0gNtTiWWg41LloBnok/dbW4VYnfk5b+SAPbwYCJGwlRZ8 1NKv3jzobaQkRLRsJASdw7h3nx1hy54oJYk9Igq67kxPmgRTvH1tS3ywt381Ur92dwD5 1+7+cXRwmnLIUXLR1/fpGAneB2BuMis8w3+f42LswPf5hL6tUVbYJ43Xire2Z08Hnt7k Ohfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qhc0gHKOvdAh16HP2S+6KVMIuLQLQw2vk1l+n24RLFY=; b=H4igLg2T+I3yXRR8LkV5cRNQow4cMI+OgFv9KRzYS2m+wWeEJcfXyUtJk6UTgwLzIx k1IjfSxITH2FoX1M5otmCrZgpeCgSqLx6NIvNP420OdVf7KC/4Qryr7salyqE7Rd3qWT XBUpgXvkKUtr0rtKggilUE/5KgS5/0zXm7uWmAwOxcgDNQswUANPoDmz+qB/beUnsyU3 jSfgeBTQ2LJE784EyEcHAVRTcqkdl7kjYppLKHx9rsdnahP/F42Lrt8Wa0ZyvTd00GmM l0AwDuM7C18KFnKbiG1c8PoOhdzZ9ZA6YmQTRQyMKnw6H7pda+dkN5tMDKl4dKXY6soB Ocjg== X-Gm-Message-State: APjAAAUVE4TlZgGNWavz57SobScHvLg3nZ4xsqAnjWNsgDSseiXJJed0 3T8/ajSziznjKyL+Y0DqjLQ= X-Google-Smtp-Source: APXvYqyfV+joCmyfoqYK0Nr0uM7bRqfLO5DnuSQktYXhBjk1ZffcLKfLxHn5QihrJGuY1+h8CMR1og== X-Received: by 2002:a1c:7305:: with SMTP id d5mr2032462wmb.84.1571211529033; Wed, 16 Oct 2019 00:38:49 -0700 (PDT) Received: from localhost (p2E5BE2CE.dip0.t-ipconnect.de. [46.91.226.206]) by smtp.gmail.com with ESMTPSA id s10sm16419715wrr.5.2019.10.16.00.38.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2019 00:38:47 -0700 (PDT) From: Thierry Reding To: Thierry Reding Cc: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Fabrice Gasnier , linux-pwm@vger.kernel.org Subject: [PATCH 2/3] pwm: stm32: Remove confusing bitmask Date: Wed, 16 Oct 2019 09:38:41 +0200 Message-Id: <20191016073842.1300297-3-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016073842.1300297-1-thierry.reding@gmail.com> References: <20191016073842.1300297-1-thierry.reding@gmail.com> MIME-Version: 1.0 Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org Both BKP bits are set in the BDTR register and the code relies on the mask used during write to make sure only one of them is written. Since this isn't immediately obvious, a comment is needed to explain it. The same can be achieved by making explicit what happens, so add another temporary variable that contains only the one bit that is actually ORed into the register and get rid of the comment. Signed-off-by: Thierry Reding --- drivers/pwm/pwm-stm32.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c index b12fb11b7a55..8f1f3371e1dd 100644 --- a/drivers/pwm/pwm-stm32.c +++ b/drivers/pwm/pwm-stm32.c @@ -493,26 +493,24 @@ static const struct pwm_ops stm32pwm_ops = { static int stm32_pwm_set_breakinput(struct stm32_pwm *priv, int index, int level, int filter) { - u32 bke, shift, mask, bdtr; + u32 bke, bkp, shift, mask, bdtr; if (index == 0) { bke = TIM_BDTR_BKE; + bkp = TIM_BDTR_BKP; shift = TIM_BDTR_BKF_SHIFT; mask = TIM_BDTR_BKE | TIM_BDTR_BKP | TIM_BDTR_BKF; } else { bke = TIM_BDTR_BK2E; + bkp = TIM_BDTR_BK2P; shift = TIM_BDTR_BK2F_SHIFT; mask = TIM_BDTR_BK2E | TIM_BDTR_BK2P | TIM_BDTR_BK2F; } bdtr = bke; - /* - * The both bits could be set since only one will be wrote - * due to mask value. - */ if (level) - bdtr |= TIM_BDTR_BKP | TIM_BDTR_BK2P; + bdtr |= bkp; bdtr |= (filter & TIM_BDTR_BKF_MASK) << shift; From patchwork Wed Oct 16 07:38:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1177650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="J/H+JNJF"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46tPLR3G0Sz9sP7 for ; Wed, 16 Oct 2019 18:38:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387949AbfJPHiy (ORCPT ); Wed, 16 Oct 2019 03:38:54 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:37427 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729325AbfJPHix (ORCPT ); Wed, 16 Oct 2019 03:38:53 -0400 Received: by mail-wr1-f66.google.com with SMTP id p14so26745987wro.4 for ; Wed, 16 Oct 2019 00:38:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Vs2VhOLNsT887JCPUVtKi4tfgehtvhFhfAihWgRySOA=; b=J/H+JNJFGZ86uZXXPJhBXa1I71ICkk2UUVHbvTjx49l+WfrPGmkxPZRxXLl3Y56o2n VJiMkjD+CdapiMOiHw+9X2YdUNEkaZt2rK48ir86Djdy2fYjhYc3XTISAzk7FbP+Budi 6kh+IiClSlo7uY2dOy1ndN3SbRZE+T80DVO5+IWKCVx7U9BrvzMPwPAZbiUumvi7WK9c 9Vqm10d695eMxQllQ7xAIXNB0AZn9BDVouf3kb/z+4I1ohe1gsJ2bhvijPUeChxiJgra vefjdoiaCQS/MNHTCnXNF76XWZeu0Xz5Nj9W/G35AV+FohzNCxhIEkiGa6DIz6SB+E8x 2lUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vs2VhOLNsT887JCPUVtKi4tfgehtvhFhfAihWgRySOA=; b=n/Emg4bfSjwRH+9K07ya0c4PkR0IW3DkcmVtvWrHV4Sgglo6FHmlgd3mWTnLlWCjup xTgq9fOTFhoi+XJXv/A2s2/8BzhoC+n60A/hU8ZyykH2arxYn/5Lo6NGerbYvRsEFpY4 aQk6kcOXGHFYgpXaRDW9Z86XX3qdKQluucZCJV+taz6m8F+LCG6DmGbHK2Fqd1xlRPl3 bfsF5gTMlTaitxzkh5GCc82wlBhhuR8Ffa/iJ1FyIw/mMQK2aWeho3/FDwtrCgKMcAIZ POIWy9ReBxDDs2ySeMIcx0oyKpi2f8+vbenNlt6rapyCtxMX77beonNDMn2MSK5bSG8v iDgw== X-Gm-Message-State: APjAAAV4G23Gh+zTp0nBreU8WJoyea/RUmhobi32CtkFuxhAbRZ2i1bO 4NNLKEE8/MAlqWufhRr/neo= X-Google-Smtp-Source: APXvYqyH6JAqFqSn0uCIuyUWDa0wzD3/iNtWnLk3e6jF+Vq/O7F6I8z9+hvNIocnpq2t2XtRYKgjRg== X-Received: by 2002:adf:a141:: with SMTP id r1mr1409362wrr.122.1571211531605; Wed, 16 Oct 2019 00:38:51 -0700 (PDT) Received: from localhost (p2E5BE2CE.dip0.t-ipconnect.de. [46.91.226.206]) by smtp.gmail.com with ESMTPSA id a7sm33787504wra.43.2019.10.16.00.38.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2019 00:38:50 -0700 (PDT) From: Thierry Reding To: Thierry Reding Cc: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Fabrice Gasnier , linux-pwm@vger.kernel.org Subject: [PATCH 3/3] pwm: stm32: Pass breakinput instead of its values Date: Wed, 16 Oct 2019 09:38:42 +0200 Message-Id: <20191016073842.1300297-4-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016073842.1300297-1-thierry.reding@gmail.com> References: <20191016073842.1300297-1-thierry.reding@gmail.com> MIME-Version: 1.0 Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org Instead of passing the individual values of the breakpoint, pass a pointer to the breakpoint. Signed-off-by: Thierry Reding --- drivers/pwm/pwm-stm32.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c index 8f1f3371e1dd..9e500928c37d 100644 --- a/drivers/pwm/pwm-stm32.c +++ b/drivers/pwm/pwm-stm32.c @@ -491,11 +491,11 @@ static const struct pwm_ops stm32pwm_ops = { }; static int stm32_pwm_set_breakinput(struct stm32_pwm *priv, - int index, int level, int filter) + const struct stm32_breakinput *bi) { u32 bke, bkp, shift, mask, bdtr; - if (index == 0) { + if (bi->index == 0) { bke = TIM_BDTR_BKE; bkp = TIM_BDTR_BKP; shift = TIM_BDTR_BKF_SHIFT; @@ -509,10 +509,10 @@ static int stm32_pwm_set_breakinput(struct stm32_pwm *priv, bdtr = bke; - if (level) + if (bi->level) bdtr |= bkp; - bdtr |= (filter & TIM_BDTR_BKF_MASK) << shift; + bdtr |= (bi->filter & TIM_BDTR_BKF_MASK) << shift; regmap_update_bits(priv->regmap, TIM_BDTR, mask, bdtr); @@ -527,10 +527,7 @@ static int stm32_pwm_apply_breakinputs(struct stm32_pwm *priv) int ret; for (i = 0; i < priv->num_breakinputs; i++) { - ret = stm32_pwm_set_breakinput(priv, - priv->breakinputs[i].index, - priv->breakinputs[i].level, - priv->breakinputs[i].filter); + ret = stm32_pwm_set_breakinput(priv, &priv->breakinputs[i]); if (ret < 0) return ret; }