From patchwork Sat Jun 8 18:06:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10983315 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2900F14E5 for ; Sat, 8 Jun 2019 18:09:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13CD428B12 for ; Sat, 8 Jun 2019 18:09:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0767828B6A; Sat, 8 Jun 2019 18:09:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 99F6128B12 for ; Sat, 8 Jun 2019 18:09:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kPAIjhCy9UHUWhlpVTZQ1FgYlv9kAHZ72JLdAr2B3ow=; b=kXyCpBwaOnMO3T 2Cmec0DrcAp0iXF3nWUO3P757646bk15IhK/cwKPrZHOzWUzUj65GW8NZuGZHU5a0D63Cl/QLPLAO mAHJzrjPey6EHjAfcAKUEAxiFtfvvtwBB246mrimjDteWH8+SnwGx/zhg1xjOZ0OY+1kdjA6AfHW/ /BxrSUcLA6llVXJLsg9mibEf5OA8wQGf875ptdJHtS0igS1PJHfHnEjQUg8T7C1hRvm69vYL7vdcX YVTrcGrbllRh2OnfNqIY73o2tpnr1xldcn8ylomMB3IP18IP7tU5BHcq3Lshrzts10tUIMngEH1yg 22rph9wsVOtZGsLq1e7w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hZfmF-00035A-Hy; Sat, 08 Jun 2019 18:09:15 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hZfjo-0000pe-5U; Sat, 08 Jun 2019 18:06:45 +0000 Received: by mail-wm1-x342.google.com with SMTP id w9so6231854wmd.1; Sat, 08 Jun 2019 11:06:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kOkFbu7Keyup8NSOgjduYXjsH/7xYfvaup38HVdoTI8=; b=t8KaWkhwgi43KZmS0c+ekfNGTUipDxJRBGfizchn4hnyD2OJ1PHMCmPPlZVvHqq1BA epuDC8ersvwklntb3JmERtfZCIFWJVDDcTKa2jlsi9Y2F8PeSWiNbproVIUqvPPZ0j4z XnDU+QUZYEoN4HJKkThGB5ztCA3INuN8bn3MylF/0mNHn5mK3si0uM3Knt0NrJcZedsA JuSPOLAMdoYmlYnp1enR9Awk2ycWofVoPYP6cM1hmZkRk2qaP7HWDanZNXdgc0Ws+T6t qtbUZnLk5J5L9qeOWn/ZsGJ2Dw/JelNbe4RBoDcQHZZbRFF2y9/zj8W/uDcTE+jBdDyJ C7YA== 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=kOkFbu7Keyup8NSOgjduYXjsH/7xYfvaup38HVdoTI8=; b=YirqJCvkHSuhTT9n6nYVVHRAEikUcoykQ1bqUG57Y27iqNqIBEOAl1YdQs0JPt9yUo MVO1689Q6sFPHONhQmipyrPoTW4AWOb53N8fFGl4meyNxY/qYZkHOZb3ZsEtCZVbJgKs bHgGwxO7NUCNxQ9igisMoKUwfiVNYzelUqMVDWf5u1TVijtWzs6TC52agpvodzDCBpt2 aiOvNfFPQLEHmn456i9/cT2ilL7P+6v76cPpKPed5EL1kqDgPUUqACHj6aA8LvjCst84 FTQu6TqKlWs4/CtmbBiGd28AZxV9SdFmJga39Z5BotRDLGK4NERFvccTvsQZ4O2P9eoq i6Vw== X-Gm-Message-State: APjAAAWMpghPdhMFdPKU8eHhLc/4EWkUgBj0E1ZQQuzCntl5QzcS2Ty3 gQNKmtpUhKGI8mLj8PzijvI5p/oh X-Google-Smtp-Source: APXvYqy/omBZ6sRYBAoPHP6FTJXnGXl4Kq2DSI3n1+vPxlevi/KhkeeRZcvOHtq/ny8G5WkhnfgsnA== X-Received: by 2002:a7b:cd15:: with SMTP id f21mr7153695wmj.99.1560017202312; Sat, 08 Jun 2019 11:06:42 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133DDA400D12EFF43FED1E981.dip0.t-ipconnect.de. [2003:f1:33dd:a400:d12e:ff43:fed1:e981]) by smtp.googlemail.com with ESMTPSA id c7sm5143345wrp.57.2019.06.08.11.06.41 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 08 Jun 2019 11:06:41 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-pwm@vger.kernel.org, thierry.reding@gmail.com Subject: [PATCH v2 08/14] pwm: meson: add the per-channel register offsets and bits in a struct Date: Sat, 8 Jun 2019 20:06:20 +0200 Message-Id: <20190608180626.30589-9-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190608180626.30589-1-martin.blumenstingl@googlemail.com> References: <20190608180626.30589-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190608_110644_242043_885A8239 X-CRM114-Status: GOOD ( 13.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , Neil Armstrong , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, u.kleine-koenig@pengutronix.de Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce struct meson_pwm_channel_data which contains the per-channel offsets for the PWM register and REG_MISC_AB bits. Replace the existing switch (pwm->hwpwm) statements with an access to the new struct. This simplifies the code and will make it easier to implement pwm_ops.get_state() because the switch-case which all per-channel registers and offsets (as previously implemented in meson_pwm_enable()) doesn't have to be duplicated. No functional changes intended. Signed-off-by: Martin Blumenstingl Reviewed-by: Neil Armstrong --- drivers/pwm/pwm-meson.c | 90 ++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 56 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index a4ae3587a3ce..ac7e188155fd 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -39,9 +39,27 @@ #define MESON_NUM_PWMS 2 -static const unsigned int mux_reg_shifts[] = { - MISC_A_CLK_SEL_SHIFT, - MISC_B_CLK_SEL_SHIFT +static struct meson_pwm_channel_data { + u8 reg_offset; + u8 clk_sel_shift; + u8 clk_div_shift; + u32 clk_en_mask; + u32 pwm_en_mask; +} meson_pwm_per_channel_data[MESON_NUM_PWMS] = { + { + .reg_offset = REG_PWM_A, + .clk_sel_shift = MISC_A_CLK_SEL_SHIFT, + .clk_div_shift = MISC_A_CLK_DIV_SHIFT, + .clk_en_mask = MISC_A_CLK_EN, + .pwm_en_mask = MISC_A_EN, + }, + { + .reg_offset = REG_PWM_B, + .clk_sel_shift = MISC_B_CLK_SEL_SHIFT, + .clk_div_shift = MISC_B_CLK_DIV_SHIFT, + .clk_en_mask = MISC_B_CLK_EN, + .pwm_en_mask = MISC_B_EN, + } }; struct meson_pwm_channel { @@ -194,43 +212,26 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm) { struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); - u32 value, clk_shift, clk_enable, enable; - unsigned int offset; + struct meson_pwm_channel_data *channel_data; unsigned long flags; + u32 value; - switch (pwm->hwpwm) { - case 0: - clk_shift = MISC_A_CLK_DIV_SHIFT; - clk_enable = MISC_A_CLK_EN; - enable = MISC_A_EN; - offset = REG_PWM_A; - break; - - case 1: - clk_shift = MISC_B_CLK_DIV_SHIFT; - clk_enable = MISC_B_CLK_EN; - enable = MISC_B_EN; - offset = REG_PWM_B; - break; - - default: - return; - } + channel_data = &meson_pwm_per_channel_data[pwm->hwpwm]; spin_lock_irqsave(&meson->lock, flags); value = readl(meson->base + REG_MISC_AB); - value &= ~(MISC_CLK_DIV_MASK << clk_shift); - value |= channel->pre_div << clk_shift; - value |= clk_enable; + value &= ~(MISC_CLK_DIV_MASK << channel_data->clk_div_shift); + value |= channel->pre_div << channel_data->clk_div_shift; + value |= channel_data->clk_en_mask; writel(value, meson->base + REG_MISC_AB); value = FIELD_PREP(PWM_HIGH_MASK, channel->hi) | FIELD_PREP(PWM_LOW_MASK, channel->lo); - writel(value, meson->base + offset); + writel(value, meson->base + channel_data->reg_offset); value = readl(meson->base + REG_MISC_AB); - value |= enable; + value |= channel_data->pwm_en_mask; writel(value, meson->base + REG_MISC_AB); spin_unlock_irqrestore(&meson->lock, flags); @@ -238,26 +239,13 @@ static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm) static void meson_pwm_disable(struct meson_pwm *meson, struct pwm_device *pwm) { - u32 value, enable; unsigned long flags; - - switch (pwm->hwpwm) { - case 0: - enable = MISC_A_EN; - break; - - case 1: - enable = MISC_B_EN; - break; - - default: - return; - } + u32 value; spin_lock_irqsave(&meson->lock, flags); value = readl(meson->base + REG_MISC_AB); - value &= ~enable; + value &= ~meson_pwm_per_channel_data[pwm->hwpwm].pwm_en_mask; writel(value, meson->base + REG_MISC_AB); spin_unlock_irqrestore(&meson->lock, flags); @@ -309,18 +297,7 @@ static void meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, if (!state) return; - switch (pwm->hwpwm) { - case 0: - mask = MISC_A_EN; - break; - - case 1: - mask = MISC_B_EN; - break; - - default: - return; - } + mask = meson_pwm_per_channel_data[pwm->hwpwm].pwm_en_mask; value = readl(meson->base + REG_MISC_AB); state->enabled = (value & mask) != 0; @@ -458,7 +435,8 @@ static int meson_pwm_init_channels(struct meson_pwm *meson) init.num_parents = meson->data->num_parents; channel->mux.reg = meson->base + REG_MISC_AB; - channel->mux.shift = mux_reg_shifts[i]; + channel->mux.shift = + meson_pwm_per_channel_data[i].clk_sel_shift; channel->mux.mask = MISC_CLK_SEL_MASK; channel->mux.flags = 0; channel->mux.lock = &meson->lock;