From patchwork Mon Apr 24 13:13:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartlomiej Zolnierkiewicz X-Patchwork-Id: 9696125 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3DF2960113 for ; Mon, 24 Apr 2017 13:14:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DAF12074F for ; Mon, 24 Apr 2017 13:14:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2051226B41; Mon, 24 Apr 2017 13:14:01 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A9282074F for ; Mon, 24 Apr 2017 13:14:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1170717AbdDXNN7 (ORCPT ); Mon, 24 Apr 2017 09:13:59 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:47483 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1170784AbdDXNNt (ORCPT ); Mon, 24 Apr 2017 09:13:49 -0400 Received: from epcas1p3.samsung.com (unknown [182.195.41.47]) by mailout3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OOX02YHX0QY7H90@mailout3.samsung.com>; Mon, 24 Apr 2017 22:13:46 +0900 (KST) Received: from epsmges1p4.samsung.com (unknown [182.195.42.56]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20170424131346epcas1p41668e08d09d0dca880aa83959eba3acd~4V6EvxseZ3051130511epcas1p42; Mon, 24 Apr 2017 13:13:46 +0000 (GMT) Received: from epcas1p3.samsung.com ( [182.195.41.47]) by epsmges1p4.samsung.com (Symantec Messaging Gateway) with SMTP id D3.31.12779.A0AFDF85; Mon, 24 Apr 2017 22:13:46 +0900 (KST) Received: from epsmgms2p1 (unknown [182.195.42.79]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20170424131346epcas1p4584c5e78edfe5055beaba0ce0f5e5ae7~4V6EiwSYE3050730507epcas1p45; Mon, 24 Apr 2017 13:13:46 +0000 (GMT) X-AuditID: b6c32a38-f791a6d0000031eb-72-58fdfa0ae331 Received: from epmmp1.local.host ( [203.254.227.16]) by epsmgms2p1 (Symantec Messaging Gateway) with SMTP id 99.84.24926.90AFDF85; Mon, 24 Apr 2017 22:13:46 +0900 (KST) Received: from AMDC3058.DIGITAL.local ([106.120.53.102]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OOX006JS0QMW870@mmp1.samsung.com>; Mon, 24 Apr 2017 22:13:45 +0900 (KST) From: Bartlomiej Zolnierkiewicz To: Thierry Reding , Jean Delvare , Guenter Roeck , Kamil Debski Cc: Tomasz Figa , linux-pwm@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, b.zolnierkie@samsung.com Subject: [PATCH] pwm: pwm-samsung: switch to new atomic PWM API Date: Mon, 24 Apr 2017 15:13:18 +0200 Message-id: <1493039598-25881-2-git-send-email-b.zolnierkie@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1493039598-25881-1-git-send-email-b.zolnierkie@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrLIsWRmVeSWpSXmKPExsWy7bCmvi7Xr78RBs2P+Sw2zljPanF2QqDF zBPtrBbtr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8wpBfKMDNCAg3OAe7CSvl2CW0bHpMesBc/kKr4ebmNuYFwq2cXIySEhYCLR d+kGE4QtJnHh3nq2LkYuDiGBVYwSM17OYodwfjFKzLu7nw2kik3ASmJi+ypGkISIwHSgqpnb WUEcZoF9jBKru6Ywg1QJC9hL7N3TzwpiswioSqxcPA+sm1fAQ+LH0tOMEPvkJE4emwxWwyng KbG09ShLFyMH0DoPif3v/Ccw8i5gZFjFyJVaUJybnltsVGC4iREY4NsOa/nvYPxxNvoQowAH oxIPb4fi3wgh1sSy4srcQ4wSHMxKIrxvLwGFeFMSK6tSi/Lji0pzUosPMZoCXTKRWUo0OR8Y fXkl8YYmlkYmBmZmhkYGxmZK4rwTAr9ECAmkJ5akZqemFqQWwfQxcXBKNTC6OUy/c//OU2Nu qTbVd95bm/uPn278a8f1oj+uZ17B33fBbAom77pnzJrEp97kHJQmeFKzdLpHSJj2jeU7MwN2 qhfFsv40bN/9UUKNWfKaUFOF2elVWyZax4uX121bPefG07jYBu+GqG2p6+u/fzx/9spbeX4b 4did5/9qTJrUfnx6xscl+k+UWIozEg21mIuKEwF3Fbj2hgIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170424131346epcas1p4584c5e78edfe5055beaba0ce0f5e5ae7 X-Msg-Generator: CA X-Sender-IP: 182.195.42.79 X-Local-Sender: =?UTF-8?B?QmFydGxvbWllaiBab2xuaWVya2lld2ljehtTUlBPTC1LZXJu?= =?UTF-8?B?ZWwgKFRQKRvsgrzshLHsoITsnpAbU2VuaW9yIFNvZnR3YXJlIEVuZ2luZWVy?= X-Global-Sender: =?UTF-8?B?QmFydGxvbWllaiBab2xuaWVya2lld2ljehtTUlBPTC1LZXJu?= =?UTF-8?B?ZWwgKFRQKRtTYW1zdW5nIEVsZWN0cm9uaWNzG1NlbmlvciBTb2Z0d2FyZSBF?= =?UTF-8?B?bmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTI=?= CMS-TYPE: 101P X-HopCount: 7 X-CMS-RootMailID: 20170424131346epcas1p4584c5e78edfe5055beaba0ce0f5e5ae7 X-RootMTR: 20170424131346epcas1p4584c5e78edfe5055beaba0ce0f5e5ae7 References: <1493039598-25881-1-git-send-email-b.zolnierkie@samsung.com> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Switch pwm-samsung driver to new atomic PWM API. This is an initial conversion (based on the PWM core's pwm_apply_state() implementation) which can be improved later. There should be no functional changes caused by this patch. Signed-off-by: Bartlomiej Zolnierkiewicz --- Depends on "[PATCH v2 0/3] pwm: pwm-samsung: fix suspend/resume support" patchset (https://www.spinics.net/lists/kernel/msg2495209.html). drivers/pwm/pwm-samsung.c | 59 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/drivers/pwm/pwm-samsung.c b/drivers/pwm/pwm-samsung.c index 062f2cf..09868a9 100644 --- a/drivers/pwm/pwm-samsung.c +++ b/drivers/pwm/pwm-samsung.c @@ -241,7 +241,7 @@ static void pwm_samsung_free(struct pwm_chip *chip, struct pwm_device *pwm) pwm_set_chip_data(pwm, NULL); } -static int pwm_samsung_enable(struct pwm_chip *chip, struct pwm_device *pwm) +static void pwm_samsung_enable(struct pwm_chip *chip, struct pwm_device *pwm) { struct samsung_pwm_chip *our_chip = to_samsung_pwm_chip(chip); unsigned int tcon_chan = to_tcon_channel(pwm->hwpwm); @@ -263,8 +263,6 @@ static int pwm_samsung_enable(struct pwm_chip *chip, struct pwm_device *pwm) our_chip->disabled_mask &= ~BIT(pwm->hwpwm); spin_unlock_irqrestore(&samsung_pwm_lock, flags); - - return 0; } static void pwm_samsung_disable(struct pwm_chip *chip, struct pwm_device *pwm) @@ -385,12 +383,6 @@ static int __pwm_samsung_config(struct pwm_chip *chip, struct pwm_device *pwm, return 0; } -static int pwm_samsung_config(struct pwm_chip *chip, struct pwm_device *pwm, - int duty_ns, int period_ns) -{ - return __pwm_samsung_config(chip, pwm, duty_ns, period_ns, false); -} - static void pwm_samsung_set_invert(struct samsung_pwm_chip *chip, unsigned int channel, bool invert) { @@ -415,7 +407,7 @@ static void pwm_samsung_set_invert(struct samsung_pwm_chip *chip, spin_unlock_irqrestore(&samsung_pwm_lock, flags); } -static int pwm_samsung_set_polarity(struct pwm_chip *chip, +static void pwm_samsung_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm, enum pwm_polarity polarity) { @@ -424,6 +416,48 @@ static int pwm_samsung_set_polarity(struct pwm_chip *chip, /* Inverted means normal in the hardware. */ pwm_samsung_set_invert(our_chip, pwm->hwpwm, invert); +} + +static int pwm_samsung_apply(struct pwm_chip *chip, struct pwm_device *pwm, + struct pwm_state *state) +{ + int err; + + /* + * FIXME: restore the initial state in case of error. + */ + if (state->polarity != pwm->state.polarity) { + if (pwm->state.enabled) { + pwm_samsung_disable(pwm->chip, pwm); + pwm->state.enabled = false; + } + + pwm_samsung_set_polarity(pwm->chip, pwm, + state->polarity); + + pwm->state.polarity = state->polarity; + } + + if (state->period != pwm->state.period || + state->duty_cycle != pwm->state.duty_cycle) { + err = __pwm_samsung_config(pwm->chip, pwm, + state->duty_cycle, + state->period, false); + if (err) + return err; + + pwm->state.duty_cycle = state->duty_cycle; + pwm->state.period = state->period; + } + + if (state->enabled != pwm->state.enabled) { + if (state->enabled) + pwm_samsung_enable(pwm->chip, pwm); + else + pwm_samsung_disable(pwm->chip, pwm); + + pwm->state.enabled = state->enabled; + } return 0; } @@ -431,10 +465,7 @@ static int pwm_samsung_set_polarity(struct pwm_chip *chip, static const struct pwm_ops pwm_samsung_ops = { .request = pwm_samsung_request, .free = pwm_samsung_free, - .enable = pwm_samsung_enable, - .disable = pwm_samsung_disable, - .config = pwm_samsung_config, - .set_polarity = pwm_samsung_set_polarity, + .apply = pwm_samsung_apply, .owner = THIS_MODULE, };