From patchwork Mon Oct 26 21:32:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olliver Schinagl X-Patchwork-Id: 7492291 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5FE0ABEEA4 for ; Mon, 26 Oct 2015 21:37:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 959AF206F6 for ; Mon, 26 Oct 2015 21:37:36 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B1AF020549 for ; Mon, 26 Oct 2015 21:37:35 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZqpQx-000524-JD; Mon, 26 Oct 2015 21:36:03 +0000 Received: from 7of9.schinagl.nl ([88.159.158.68]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZqpOg-0001c5-Lc for linux-arm-kernel@lists.infradead.org; Mon, 26 Oct 2015 21:33:45 +0000 Received: from um-mba-140.are-b.org. (unknown [10.2.0.189]) by 7of9.schinagl.nl (Postfix) with ESMTPA id 4E5314466A; Mon, 26 Oct 2015 22:32:54 +0100 (CET) From: Olliver Schinagl To: Olliver Schinagl , Thierry Reding , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Joachim Eastwood , Maxime Ripard , Alexandre Belloni Subject: [PATCH 09/10] pwm: pwm_gpio: add pulse option Date: Mon, 26 Oct 2015 22:32:40 +0100 Message-Id: <1445895161-2317-10-git-send-email-o.schinagl@ultimaker.com> X-Mailer: git-send-email 2.6.1 In-Reply-To: <1445895161-2317-1-git-send-email-o.schinagl@ultimaker.com> References: <1445895161-2317-1-git-send-email-o.schinagl@ultimaker.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151026_143343_220139_C4163EEA X-CRM114-Status: GOOD ( 14.70 ) X-Spam-Score: -1.2 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Olliver Schinagl , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Olliver Schinagl With the newly added pwm_pulse option added to the PWM framework, this patch adds the pulse functionality to the gpio_pwm driver. Signed-off-by: Olliver Schinagl --- drivers/pwm/pwm-gpio.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/pwm/pwm-gpio.c b/drivers/pwm/pwm-gpio.c index cf4b170..24c27b1 100644 --- a/drivers/pwm/pwm-gpio.c +++ b/drivers/pwm/pwm-gpio.c @@ -40,6 +40,8 @@ struct gpio_pwm_data { bool pin_on; int on_time; int off_time; + unsigned int count; + bool pulse; bool run; }; @@ -80,6 +82,16 @@ enum hrtimer_restart gpio_pwm_timer(struct hrtimer *timer) gpio_data->pin_on = false; } + if (gpio_data->count > 0) + gpio_data->count--; + if (!gpio_data->count && gpio_data->pulse) { + struct pwm_device *pwm = container_of((void *)gpio_data, + struct pwm_device, + chip_data); + pwm_pulse_done(pwm); + return HRTIMER_NORESTART; + } + return HRTIMER_RESTART; } @@ -88,6 +100,10 @@ static int gpio_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, { struct gpio_pwm_data *gpio_data = pwm_get_chip_data(pwm); + /* A full pulse is both the on and off time, and since counting each + * iteration of the timer is easy and clean, we need double the count. + */ + gpio_data->count = count * 2; gpio_data->on_time = duty_ns; gpio_data->off_time = period_ns - duty_ns; @@ -111,6 +127,9 @@ static int gpio_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) if (gpio_data->run) return -EBUSY; + if (pwm->pulse_count) + gpio_data->pulse = true; + gpio_data->count = pwm->pulse_count; gpio_data->run = true; if (gpio_data->off_time) { hrtimer_start(&gpio_data->timer, ktime_set(0, 0), @@ -130,6 +149,7 @@ static void gpio_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) struct gpio_pwm_data *gpio_data = pwm_get_chip_data(pwm); gpio_data->run = false; + gpio_data->pulse = false; if (!gpio_data->off_time) gpio_pwm_off(gpio_data); } @@ -196,6 +216,8 @@ static int gpio_pwm_probe(struct platform_device *pdev) gpio_data->timer.function = &gpio_pwm_timer; gpio_data->gpiod = gpiod; gpio_data->pin_on = false; + gpio_data->count = 0; + gpio_data->pulse = false; gpio_data->run = false; if (hrtimer_is_hres_active(&gpio_data->timer))