From patchwork Thu Jan 23 11:52:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Russell King - ARM Linux X-Patchwork-Id: 3528201 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AFED6C02DC for ; Thu, 23 Jan 2014 11:52:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B8491201C0 for ; Thu, 23 Jan 2014 11:52:58 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8F3A0201BC for ; Thu, 23 Jan 2014 11:52:57 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W6Iq4-0004LN-L2; Thu, 23 Jan 2014 11:52:52 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1W6Iq2-0006W4-3i; Thu, 23 Jan 2014 11:52:50 +0000 Received: from pandora.arm.linux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:1be6]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W6Ipy-0006UW-4c for linux-arm-kernel@lists.infradead.org; Thu, 23 Jan 2014 11:52:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=pandora; h=Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=+5p0h4wer5FZByjKHjq9Ooja3VROhclt9K4fKnWZ4cg=; b=UV2KaUKTTAZoV7eipRPrtUwB/ubQ6cbSFFwkkO/aAGDZM5KFDfIKlaAxvR8rZauUJHIQfcCRRTVfmWa45nqN/6beddpEbMp/Twv3lYHjRSRR0+adRUwSCI+oE3NyplE6a/sIaTpLA2TTViYAZMch1tjCRuwQlyOG7jZUvmNQWQU=; Received: from n2100.arm.linux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:4f86]:49401) by pandora.arm.linux.org.uk with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1W6IpJ-0003B3-6P; Thu, 23 Jan 2014 11:52:05 +0000 Received: from linux by n2100.arm.linux.org.uk with local (Exim 4.76) (envelope-from ) id 1W6IpH-0005c7-QS; Thu, 23 Jan 2014 11:52:03 +0000 Date: Thu, 23 Jan 2014 11:52:03 +0000 From: Russell King - ARM Linux To: Lothar =?iso-8859-1?Q?Wa=DFmann?= Subject: Re: [PATCHv2 2/2] pwm: imx: support polarity inversion Message-ID: <20140123115203.GV15937@n2100.arm.linux.org.uk> References: <1389859585-14006-1-git-send-email-LW@KARO-electronics.de> <1389859585-14006-3-git-send-email-LW@KARO-electronics.de> <20140116160356.GY16215@pengutronix.de> <20140123083714.3c6e86ae@ipc1.ka-ro> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140123083714.3c6e86ae@ipc1.ka-ro> User-Agent: Mutt/1.5.19 (2009-01-05) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140123_065246_612210_12E502C8 X-CRM114-Status: GOOD ( 24.05 ) X-Spam-Score: -2.6 (--) Cc: Mark Rutland , linux-pwm@vger.kernel.org, Sascha Hauer , Pawel Moll , Ian Campbell , Sascha Hauer , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Rob Herring , Thierry Reding , Rob Landley , Kumar Gala , Shawn Guo , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,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 On Thu, Jan 23, 2014 at 08:37:14AM +0100, Lothar Waßmann wrote: > This wouldn't buy much without a material change to of_pwm_get(). > The function of_parse_phandle_with_args() called by of_pwm_get() > requires the number of args in the pwms property be greater or equal to > the #pwm-cells property in the pwm node. Thus, the interesting case of > having #pwm-cells = <3> without changing the existing users is > prohibited by of_parse_phandle_with_args(). I really don't think that's a problem we need to be concerned with at the moment. What we need is for the kernel to be able to parse files with #pwm-cells = <2> with the pwms property containing two arguments, and when they're updated to #pwm-cells = <3> with the pwms property containing three arguments. Yes, that means all the board dt files need to be updated at the same time to include the additional argument, but I don't see that as a big problem. What we do need to do is to adjust the PWM parsing code such that it's possible to use either specification without causing any side effects. I would test this, but as u-boot is rather fscked at the moment and the networking has broken on my cubox-i as a result... and it seems that the u-boot developers have pissed off cubox-i u-boot hackers soo much that they've dropped u-boot in favour of barebox... drivers/pwm/core.c | 59 +++++++++++++++++++++++++++++------------------------ include/linux/pwm.h | 2 ++ 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 2ca95042a0b9..40adbce8ef0c 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -132,14 +132,11 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label) } struct pwm_device * -of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args) +of_pwm_xlate(struct pwm_chip *pc, const struct of_phandle_args *args) { struct pwm_device *pwm; - if (pc->of_pwm_n_cells < 3) - return ERR_PTR(-EINVAL); - - if (args->args[0] >= pc->npwm) + if (args->args_count < 2) return ERR_PTR(-EINVAL); pwm = pwm_request_from_chip(pc, args->args[0], NULL); @@ -148,33 +145,45 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args) pwm_set_period(pwm, args->args[1]); - if (args->args[2] & PWM_POLARITY_INVERTED) - pwm_set_polarity(pwm, PWM_POLARITY_INVERSED); - else - pwm_set_polarity(pwm, PWM_POLARITY_NORMAL); + if (args->args_count > 2) { + int err; + + if (args->args[2] & PWM_POLARITY_INVERTED) + err = pwm_set_polarity(pwm, PWM_POLARITY_INVERSED); + else + err = pwm_set_polarity(pwm, PWM_POLARITY_NORMAL); + + pwm_put(pwm); + return ERR_PTR(err); + } return pwm; } +EXPORT_SYMBOL(of_pwm_xlate); + +struct pwm_device * +of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args) +{ + if (pc->of_pwm_n_cells < 3) + return ERR_PTR(-EINVAL); + + if (args->args_count != pc->of_pwm_n_cells) + return ERR_PTR(-EINVAL); + + return of_pwm_xlate(pc, args); +} EXPORT_SYMBOL_GPL(of_pwm_xlate_with_flags); static struct pwm_device * of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args) { - struct pwm_device *pwm; - if (pc->of_pwm_n_cells < 2) return ERR_PTR(-EINVAL); - if (args->args[0] >= pc->npwm) + if (args->args_count != pc->of_pwm_n_cells) return ERR_PTR(-EINVAL); - pwm = pwm_request_from_chip(pc, args->args[0], NULL); - if (IS_ERR(pwm)) - return pwm; - - pwm_set_period(pwm, args->args[1]); - - return pwm; + return of_pwm_xlate(pc, args); } static void of_pwmchip_add(struct pwm_chip *chip) @@ -536,16 +545,12 @@ struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id) goto put; } - if (args.args_count != pc->of_pwm_n_cells) { - pr_debug("%s: wrong #pwm-cells for %s\n", np->full_name, - args.np->full_name); - pwm = ERR_PTR(-EINVAL); - goto put; - } - pwm = pc->of_xlate(pc, &args); - if (IS_ERR(pwm)) + if (IS_ERR(pwm)) { + pr_debug("%s: of_xlate failed for %s: %d\n", np->full_name, + args.np->full_name, (int)PTR_ERR(pwm)); goto put; + } /* * If a consumer name was not given, try to look it up from the diff --git a/include/linux/pwm.h b/include/linux/pwm.h index f0feafd184a0..14a823f77c31 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -188,6 +188,8 @@ struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip, unsigned int index, const char *label); +struct pwm_device *of_pwm_xlate(struct pwm_chip *pc, + const struct of_phandle_args *args); struct pwm_device *of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args);