Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752223AbcJALsV (ORCPT ); Sat, 1 Oct 2016 07:48:21 -0400 Received: from mail-db5eur01on0099.outbound.protection.outlook.com ([104.47.2.99]:7254 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751797AbcJALsJ (ORCPT ); Sat, 1 Oct 2016 07:48:09 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=bhuvanchandra.dv@toradex.com; From: Bhuvanchandra DV To: , CC: , , , , , , , , , , Lothar Wassmann , Bhuvanchandra DV Subject: [PATCH v2 2/6] pwm: core: make the PWM_POLARITY flag in DTB optional Date: Sat, 1 Oct 2016 15:42:31 +0530 Message-ID: <20161001101235.24598-3-bhuvanchandra.dv@toradex.com> X-Mailer: git-send-email 2.9.2 In-Reply-To: <20161001101235.24598-1-bhuvanchandra.dv@toradex.com> References: <20161001101235.24598-1-bhuvanchandra.dv@toradex.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [115.115.243.34] X-ClientProxiedBy: PN1PR01CA0050.INDPRD01.PROD.OUTLOOK.COM (2a01:111:e400:5a3d::22) To AM3PR05MB1396.eurprd05.prod.outlook.com (2a01:111:e400:5871::11) X-MS-Office365-Filtering-Correlation-Id: 9fdafc52-9efd-43ec-2337-08d3e9e3cb27 X-Microsoft-Exchange-Diagnostics: 1;AM3PR05MB1396;2:31IT/3VVfcqBLgGhWs0tSb9XGAi+hcY39W+8QNI1QdTCrJe4nENRccqWgAYqdMVuxcgOcD+VwPmYK/ZgvC2jx85SNgQlVDn9+RVDRzXRZ71IuIasOlv9W22+Wmf7hq5XNtA6cykbp32Siy9KIzL3UJW64Bu8p1JHNKMqRzuxFIUbPOZPmFfuqEV3yCuEpZOS;3:oUAF8sJNi1iqf9hRPeUWWVmmYduDZ32oa4H4KCpg8svRc507Z7qJgWgi3NzTsz8zZZR6wE2LW2FoSH30iu/k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PwjBkiHQpSgZC7xEdKjWbzz9S2G3HKx8bo66te+Of+oVnvA+4RjTibOgucyzrHSnfTYuyWbPKXLd6f+b9wLcljwTDE=;20:bevFA2sSi6KSueQKMU5PqJv0nxRP8M+8UR7lKtF2MGJPtpXEdkc2AOymAktPBhR8xhrQpPReKPwl8QzBctONnRfmf2iIW2+8eDP40cjVDNpCNaSfZcql8OjuNzwohAM9ciz8IBTXPGxbNIWaln15TyTD8U33UYFvgAE4dx8+s1pYuXqSDHTGrSRwQEuJ4UUpH29lSjL9DffBBUUsPhTYNhnF2iFQNom6l/EO8H51/CRLXnGlG8OZ1r4iF16cYtmkrOp5KSAnLetHoEsP26BucZFWNjXtd1DEO09GwglXbo3f4upDgCP3rxBDJRJQy8L+Ikq5Pjoj3kfaqlwmPkgcLg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001);SRVR:AM3PR05MB1396;BCL:0;PCL:0;RULEID:;SRVR:AM3PR05MB1396; X-Microsoft-Exchange-Diagnostics: 1;AM3PR05MB1396;4:v2pW9ow92RKX3ZyQErEndi4cdXEZdua0tIvbxaGZ5nBsU0IVefryXCaFMLS/8bm5UJDLlM4dxAUlLidPOe7N0HywY/vfomw9C1CH97ZXS2Jcbw+PMo7kJBt0jmdDMNb3b5jZSCv0PKyvLDxohBMWizA3xNBuwUGdSDU+s+0u0xfPQNe0YWIuKsYYh1Hpwip9lmtSsaPyZrVRh3R4HLm+L41yFL12n3VoHnXVlR+ARf6wLh7FL6aFMlcoLV3WFV1hF/3176pUpD9iorFd8FG6B7VVfQ5lUXMoDhvTqaUMgvr8iIMYF8fpe6ApV8Nho2sQOss0xLBuN4IIMmBdEcdtfLDUeMjDXfuEGX9oD/afe8PksQqPUyldPp2ltArty6mpEZNnlGujGmgpWh5J1jpOUQ== X-Forefront-PRVS: 00826B6158 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(979002)(6009001)(7916002)(199003)(189002)(7416002)(92566002)(36756003)(47776003)(189998001)(6666003)(305945005)(68736007)(229853001)(5001770100001)(97736004)(66066001)(4326007)(33646002)(105586002)(5660300001)(50226002)(106356001)(8666005)(2906002)(586003)(2950100002)(107886002)(50466002)(1076002)(76176999)(81156014)(50986999)(81166006)(7736002)(6116002)(3846002)(5003940100001)(42186005)(7846002)(8676002)(53416004)(101416001)(69596002)(86362001)(19580395003)(4001430100002)(48376002)(19580405001)(7059030)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1102;SCL:1;SRVR:AM3PR05MB1396;H:tdx-in-nb-0014.toradex.int;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;AM3PR05MB1396;23:ADeJ506kdUSkG7MBORFbGcGVC1hP3GQoZTGVo98Zs?= =?us-ascii?Q?bijVUts8+vuDcp6XRc5oQSSt8HvdiN+LeX+4xyLTTctft7mtqmWzdQqTwgyA?= =?us-ascii?Q?5DPFquvDiDwStZGu4Y5+lU8NNMyFornFh+8o/WcjR5DnWaA8coX8j97hZbCA?= =?us-ascii?Q?XVzVHCG1d3JiMhoyj/X5d/HAaaWX9ifkPw/bxhG5RilTK8CtqNucQSeU4WyZ?= =?us-ascii?Q?8QWYtq7gXDxtpN7WlHF8151EPOlynLWO6gVdbxzxpN+thFDEJnJxP2Vt4vQZ?= =?us-ascii?Q?meTjmAZPNztI8MUnAKJcRBoY1dQk//nZ2FxVtrrxJFoN6LUIJZLWJaqIseaX?= =?us-ascii?Q?iqFdt6cV4SVb6aLTXkR9Xupq93C47TJqpRSuUYzsqcq+WfVcHaeXYPfr1ohV?= =?us-ascii?Q?gEs/fjlhua9Jr9pPLJkz7usC8E657+ymi4WQXayx0fcA2xBC1qMkreKw3Z2V?= =?us-ascii?Q?Sxbx+x4hn1olMgQxAAoPqM7G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nm4A=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;AM3PR05MB1396;6:2a+ip7BhYrJ8Do+N69kokRJhsuY/NGrq+1Chhjy6fdttcGp09YBVtC733Odovz0xQ8OqL4+qB36UpvguWCttWXurtH2nlx4KwiTICuYPRHB6M98XvHd+CgF/qCRRcMvvXCvWaofITA1z7jee5ql+mPg3K3kfKXGmZCOZlj7Mi4G875PBub5VIpHvGJCzWM5BG5G8WauhwJ3LwZXVyj7Ok3sF66kfmfOVTpCZQilWzHZT0lZPej9KmOFpOymlxi/ZOyL+rnSIwKYo9WN8DHXGwy9UuKfBsqF54dvPovJAeIo=;5:NkWET+lkOht5kWJNZYeaveR5kjzfS6LHKJqFa3J9bIyQjOAd0q2SmVFFLsVabKOIwWyNuvK8CyMQJl7jo/bwCpKYICi9yTfijdZK6rADTHiZ6jgv86ux2wHh1WdukEKS1+kNjyqm8PJGqU/ZZ4TgKA==;24:VO8MuccAGKAxW2/bAnYzibcuv4Pj2mDXxn/abm8rGFfvAhsjze5DklVLPOuiiVN5gQo0kU9RxVH7fAR9Kpl94cK5AEsgV+5UKtyptecLBFk=;7:Ar1djjNBSxtQnMUeAj9q9J2G2XvEmqIVy11fhCUfylcfRGi66wda85BTmKEWJFJBkoYRcJjzzRmWGn5l+x7PzpW3a/Fr8VAiVPDpwkO/+EN4jBoRJspUqLOMRpG14xDiBrOJEZrdSDpAzx/8ErbWGN5qqC1pmW3aCpVv1SRnsSAJdEKHY35tnOuKij/cSMuHIi3ou3uav+9Q/5vDZRokrPZN4OAe7a/6sc4uW9P0zNiMavRu5txgM435y/jePO3Du7+fUkvA3gGHMr4To77QbBazdLwPDmTStfiYk2/hFfXxiQA7fN0Gd/ikT2kzHtoM SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: toradex.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2016 10:14:54.0628 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR05MB1396 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2438 Lines: 83 From: Lothar Wassmann Change the pwm chip driver registration, so that a chip driver that supports polarity inversion can still be used with DTBs that don't provide the 'PWM_POLARITY' flag. This is done to provide polarity inversion support for the pwm-imx driver without having to modify all existing DTS files. Signed-off-by: Lothar Wassmann Signed-off-by: Bhuvanchandra DV Suggested-by: Thierry Reding --- drivers/pwm/core.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 195373e..aae8db3 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -137,9 +137,14 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args) { struct pwm_device *pwm; + /* check, whether the driver supports a third cell for flags */ if (pc->of_pwm_n_cells < 3) return ERR_PTR(-EINVAL); + /* flags in the third cell are optional */ + if (args->args_count < 2) + return ERR_PTR(-EINVAL); + if (args->args[0] >= pc->npwm) return ERR_PTR(-EINVAL); @@ -149,10 +154,12 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args) pwm->args.period = args->args[1]; - if (args->args[2] & PWM_POLARITY_INVERTED) - pwm->args.polarity = PWM_POLARITY_INVERSED; - else - pwm->args.polarity = PWM_POLARITY_NORMAL; + if (args->args_count > 2) { + if (args->args[2] & PWM_POLARITY_INVERTED) + pwm_set_polarity(pwm, PWM_POLARITY_INVERSED); + else + pwm_set_polarity(pwm, PWM_POLARITY_NORMAL); + } return pwm; } @@ -163,9 +170,14 @@ of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args) { struct pwm_device *pwm; + /* sanity check driver support */ if (pc->of_pwm_n_cells < 2) return ERR_PTR(-EINVAL); + /* all cells are required */ + if (args->args_count != pc->of_pwm_n_cells) + return ERR_PTR(-EINVAL); + if (args->args[0] >= pc->npwm) return ERR_PTR(-EINVAL); @@ -672,13 +684,6 @@ 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)) goto put; -- 2.9.2