Received: by 10.223.185.116 with SMTP id b49csp1838846wrg; Thu, 22 Feb 2018 04:06:06 -0800 (PST) X-Google-Smtp-Source: AH8x226h5vTGamysf+qFpr2aA1/J+6ySYnRUoBVGnfiixs2VOEhD4xuMlVntNNmll27fd/NQiivk X-Received: by 2002:a17:902:e65:: with SMTP id 92-v6mr6378215plw.268.1519301166775; Thu, 22 Feb 2018 04:06:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519301166; cv=none; d=google.com; s=arc-20160816; b=J7nbkKNtAbHn21Z4s09MClAZb5d9QyKML0CoyIVaQTXddFJrjehXbSRPYnA/k+hAkn yO3HH/6JwhmjVc7nYNkUCLOLXqfUZ66+I/XCI4l313LjMJeWDkn2NvKJuZPrQguHkq8y 5T4BZUpkVsWLHSBgDFrosjiJpxT6vYyuZO/PkwAknlGDDiB+Zv9YOIFaDl+PV+O+JI9J iNGZln2L5Yr9K/RZLNXb/WSWw9uw3Dq4DBBxAQdn1pgBY5j+A4yOQ37Qkmh5E0Z1UbPw cVI4Fo6QhWjZu0lzgkAjSD4Rm0MQYsAYebPs1ifar2QoDXFqnKnnoxy3tvgXV8WdVbyq TIiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=vSBwxLeSTDGelN8LcEYh+WYZ1BZvPeTc9TEzmyhEkaE=; b=kmRlBS2cuOyfjgeSIlHH/cJwETfGqSG/Oo6n96BP6IrKDxP/buWTm+Zqw9yMnW/El8 a/t9m3zHa49WqC93TYXMwByk/zQYR/WWVMtBQxB9qMVM851UY6nmel0/zY/sT2TLVsX0 hbOJyen/neRItjrgc4a8xfMilh7nBuDlFfrWSeMv91Ut4DKIBnblbH6KE4GA1EMjLSSZ lDhu+Ybcbjh+D9Iwe/WHbXyz3MeJ9xlbZsIB6rPFgt9BrbHvBJ0lJXgLF5xFYIMAo18f OQZj+i91u3hg0loPCZnYk2JT4xZQ1k3+co1VmIazwftJBnrRwvsyUOau7im2jP7IcP3j ipbg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8si8088737pgt.383.2018.02.22.04.05.52; Thu, 22 Feb 2018 04:06:06 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932449AbeBVMET (ORCPT + 99 others); Thu, 22 Feb 2018 07:04:19 -0500 Received: from esa1.microchip.iphmx.com ([68.232.147.91]:62285 "EHLO esa1.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932103AbeBVMEM (ORCPT ); Thu, 22 Feb 2018 07:04:12 -0500 X-IronPort-AV: E=Sophos;i="5.47,377,1515481200"; d="scan'208";a="12246010" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 22 Feb 2018 05:04:10 -0700 Received: from m18063-ThinkPad-T460p.microchip.com (10.10.76.4) by chn-sv-exch05.mchp-main.com (10.10.76.106) with Microsoft SMTP Server id 14.3.352.0; Thu, 22 Feb 2018 05:04:10 -0700 From: Claudiu Beznea To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , Claudiu Beznea Subject: [PATCH v3 10/10] pwm: atmel: add push-pull mode support Date: Thu, 22 Feb 2018 14:01:21 +0200 Message-ID: <1519300881-8136-11-git-send-email-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519300881-8136-1-git-send-email-claudiu.beznea@microchip.com> References: <1519300881-8136-1-git-send-email-claudiu.beznea@microchip.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for PWM push-pull mode. This is only supported by SAMA5D2 SoCs. Signed-off-by: Claudiu Beznea --- drivers/pwm/pwm-atmel.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c index d2482fe28cfa..da4b58c1ecf2 100644 --- a/drivers/pwm/pwm-atmel.c +++ b/drivers/pwm/pwm-atmel.c @@ -33,8 +33,11 @@ #define PWM_CMR 0x0 /* Bit field in CMR */ -#define PWM_CMR_CPOL (1 << 9) -#define PWM_CMR_UPD_CDTY (1 << 10) +#define PWM_CMR_CPOL BIT(9) +#define PWM_CMR_UPD_CDTY BIT(10) +#define PWM_CMR_DTHI BIT(17) +#define PWM_CMR_DTLI BIT(18) +#define PWM_CMR_PPM BIT(19) #define PWM_CMR_CPRE_MSK 0xF /* The following registers for PWM v1 */ @@ -219,16 +222,19 @@ static int atmel_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, { struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); struct pwm_state cstate; + struct pwm_caps caps; unsigned long cprd, cdty; u32 pres, val; int ret; pwm_get_state(pwm, &cstate); + pwm_get_caps(chip, pwm, &caps); if (state->enabled) { if (cstate.enabled && cstate.polarity == state->polarity && - cstate.period == state->period) { + cstate.period == state->period && + cstate.mode == state->mode) { cprd = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, atmel_pwm->data->regs.period); atmel_pwm_calculate_cdty(state, cprd, &cdty); @@ -263,6 +269,18 @@ static int atmel_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, val &= ~PWM_CMR_CPOL; else val |= PWM_CMR_CPOL; + + /* PWM mode. */ + if (caps.modes & PWM_MODE(PUSH_PULL)) { + if (state->mode == PWM_MODE(PUSH_PULL)) { + val |= PWM_CMR_PPM | PWM_CMR_DTLI; + val &= ~PWM_CMR_DTHI; + } else { + val &= ~(PWM_CMR_PPM | PWM_CMR_DTLI | + PWM_CMR_DTHI); + } + } + atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWM_CMR, val); atmel_pwm_set_cprd_cdty(chip, pwm, cprd, cdty); mutex_lock(&atmel_pwm->isr_lock); @@ -315,6 +333,20 @@ static const struct atmel_pwm_data atmel_pwm_data_v2 = { }, }; +static const struct atmel_pwm_data atmel_pwm_data_v3 = { + .regs = { + .period = PWMV2_CPRD, + .period_upd = PWMV2_CPRDUPD, + .duty = PWMV2_CDTY, + .duty_upd = PWMV2_CDTYUPD, + }, + .caps = { + .modes = PWM_MODE(NORMAL) | + PWM_MODE(COMPLEMENTARY) | + PWM_MODE(PUSH_PULL), + }, +}; + static const struct platform_device_id atmel_pwm_devtypes[] = { { .name = "at91sam9rl-pwm", @@ -337,7 +369,7 @@ static const struct of_device_id atmel_pwm_dt_ids[] = { .data = &atmel_pwm_data_v2, }, { .compatible = "atmel,sama5d2-pwm", - .data = &atmel_pwm_data_v2, + .data = &atmel_pwm_data_v3, }, { /* sentinel */ }, -- 2.7.4