Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932562AbcJGSrJ (ORCPT ); Fri, 7 Oct 2016 14:47:09 -0400 Received: from mail-db5eur01on0119.outbound.protection.outlook.com ([104.47.2.119]:20256 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932239AbcJGSrC (ORCPT ); Fri, 7 Oct 2016 14:47:02 -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 v3 2/6] pwm: core: make the PWM_POLARITY flag in DTB optional Date: Fri, 7 Oct 2016 20:41:25 +0530 Message-ID: <20161007151129.6043-3-bhuvanchandra.dv@toradex.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161007151129.6043-1-bhuvanchandra.dv@toradex.com> References: <20161007151129.6043-1-bhuvanchandra.dv@toradex.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [115.115.243.34] X-ClientProxiedBy: BM1PR01CA0062.INDPRD01.PROD.OUTLOOK.COM (10.163.199.34) To VI1PR05MB1407.eurprd05.prod.outlook.com (10.162.125.156) X-MS-Office365-Filtering-Correlation-Id: fa38e715-0d09-45fa-35e6-08d3eec498e6 X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1407;2:lBVeix9nzVP8vzonZyDlquDvIXFuUhJsmqXwGFdClwquBHq/nahB9ELPPS2qz1tgVVf+TY87VV6kl/eexJNOv4YhvtAZwd3RYRojxco+Rud2vLDz2CLKjLIBcrjWRDRWHhaRLdX9/miw53/JoIMXSlax0mIxjw5K7Ge9m3cVsBaidVHFisYyZggyVe+Je5asGfrmt3biewHNm56SSNxGQA==;3:IS5h8a+0iGoN2ua84tYpaJwDPQXFtT5iROorpXYPlrwvyFh5lBweVbWk/XJ+lEuEUUVbfKAU8io29ORz5pEVTeTD9QKoJfl4b3WqUNCgvIggU6+M1pSRXoBi/uqpYoW9XCERBarcls49j/m62Pk3hg== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR05MB1407; X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1407;25:z9eUnS24Ug5dG7wrfm1kWm7j8S/TIOd26doH++XgE6BnOZ3BGN5r6scAzDM6HcSm+s8QjnCvbEloFAuzfms1G0F17s1OeluE06UcMZMhCZtd5nfbet34xXJEjAWM659QkeuZZKej69Zzy8a/jkV5V43sEQPf/QW9Ef1fjaxlED2ZefcdVAvG3P5dIuEl2QlX7ZXVMZMkBgucMBcbXpSB5TXtNiKJp8cBywbU7dSaRMbmMxFiK+rBqaZeghFhAch3fVGcoiWU7XC+tFprStd7uohtGaznXM3ah5HaTwL2uESq21P3kb2drPDQsEphUgVgTjjPIJoJxIUdpRQDflW/uDX7RPcLpXO2PZxUFpDrifMpHTWUoZptvuVa6wnH72grznrJ0VyyPMDfb27epk4U7JyjWviimef/xXtjoP9fQFISm4w3R2+X4AwhTm8ulELMCRzEMzPhC0EtNw2wVSuTnHMuIf9V0VrByPft/Y0b8W0mvAlXWgveWQFO7m9clTD+4P8IMqF6G1kXAPAwdTydde3UOlA/Q7xHh+bP2slq/7LslnRL6hE7Z+BM21fGZ+JwI0JHT7/IlZVvIdWzpPSAs3VKaRyzwPXakgtnwK1D1chH4cDM9CkhXp7buE6skv2dMV2o4Mb42jDzTQWLky0xtvebOWjVcCvqKRZu5J1FtLN7HpTPrDkgV3K2TJKJJJ0W+gzYUg8R7XUzQDzr/BHM6841XjG1KLNOuQsB1SftBlQ= X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1407;31:O3JfrlETkzJdLFr3cgpqkzLFu179naPuPiOhU9jQq7DtncEhzMRa76SseosZhj/X/HEFemrth89Xqs/H5HQLBBcMg/2m4kZR2q03qD+sXWsurgG8xd3EOJyVIc6eqrLiipMe7ZhRRhGEq1Fqb9IkJrxGs99HaZWalZiKE21iDRG5q0At6rg4boxcOvYjQ5wxwy/30ZM/eA8RFzPrElBnx4OAJC3nfrs32NemDkFqXEfn7c6sEFaJP16dXTuFSBQnJ8wpGkielsbuQ6hUY+dDOw==;20:7RO+Ujrrsmg5omRofPhy53kINoKw64koHUKY5v4ags5N91EvxDekX3KsCznv+dxP1fno9kP5EczIR9oU/rNEjv88JDLoTRIKmB570gPb9giHV9w/fsOhHFyVehfeCjIWcfnPSftphL+VEc8FuigBQ9NpJlr2MiPpTyNiImh+XWsuxwVCQBtCgy5cI7LPTFggxzZ0iApkf9WKlYty4ho0Y52nVyeRY7X0/4Rs9jukjzpISD0fcfAkCVL5h6Hi4u5Zc9ULQwVQNZqrMhVMfKVaqrYYn3QevfnlOYevHHBwW0rlhbAhuC2+5cZU+dNyUETKk1FK2NXwlkHK4KatQOdaWA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(7411616537696); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001);SRVR:VI1PR05MB1407;BCL:0;PCL:0;RULEID:;SRVR:VI1PR05MB1407; X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1407;4:lOwtLIZJ4FMyN0+dGguDsKSeCgg5MCvw1vV/ss0VUVGOF51tySAKhtaDHpSD9Xg2ASyTw0KOp59YpntXKzVG86R94Jgc36Gnbo/NaCYLrmjmXDRQAkvjrTNOAc+bhMxULvUXO51AItujBa2QSwQLV4uU8EFXvEIHbx4YXdI8sOXLxROz7hmwKfq1/NsxXw6otq97K016OhQyNvUTyUonUJYa63M866nG79HP3mVk6CN7KofoE7UGTw9OdZ8cB5BskcoZUY/93XP1zyRfy8VfgOImVYB2f0gxIC16dHFmVcwc/P5DhtvTXBNsLKBRDjYZt4GS+Ac6/iWeSDPopAlfDIV5Gef6+qEAGqvB1ultG0H5+/ukKrCwuCy5cgR2gUJdy1fh145NuM6+wFgnCcwnSodPp41hMZkY6Hkl4jvsajU3ZBnMuma+DukMFRezQhQ+ X-Forefront-PRVS: 0088C92887 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(4001430100002)(5001770100001)(97736004)(77096005)(68736007)(107886002)(48376002)(86362001)(189998001)(4326007)(81166006)(81156014)(8676002)(36756003)(92566002)(2906002)(6116002)(50226002)(5003940100001)(50466002)(69596002)(586003)(1076002)(3846002)(33646002)(76176999)(50986999)(101416001)(6666003)(2950100002)(47776003)(42186005)(66066001)(7416002)(8666005)(7736002)(305945005)(5660300001)(19580405001)(19580395003)(7846002)(53416004)(105586002)(229853001)(106356001)(7059030);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR05MB1407;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;VI1PR05MB1407;23:7LD88nrsae2KOhHIJfMtZ2+IZqjIKAi7fzz4dq7k0?= =?us-ascii?Q?rxNSJvtiQAsIB9SjhvaKKI2CmhXpPfYn/P+No664ZfNUbCwXCIjzcGEr+E+1?= =?us-ascii?Q?ub/7NzeJcsytI/gvceTNZyrfu1SXGh5hGGTJzKDu4grDaaUwmpShdaf0J8tu?= =?us-ascii?Q?b4Lcmyr7PuJRcKzeX5GOasMtbsTG0H8xezkIwTYwUdYX2VA2sj6Gy1OVoKll?= =?us-ascii?Q?oCncp5bbAVOk9PR9jcZfLlp4I7P3u5iZT8j+3kdK8EMTyXpPYn/FoJS01TrK?= =?us-ascii?Q?MNYRyaGD652MfSLwewQi2CNcr4aqGImeosmM9mREvswd/Dsvi+goK/Rwrl3t?= =?us-ascii?Q?AYHov+bkJRXQy2x7Tlmb0qelOhpHWLDHwfsDkb8taH0LlRomrG2b/Y/3kxW0?= =?us-ascii?Q?rOS+6HVASoMQF5qGOlZNqUT5uX6xOZD6cOMmPmQZLYC+j148twjsGY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+H+ip0oTrwxYxpJe4YrBj5J1QiFZK9HrBrvXVCFlE6wIWi9YhJEOHGiYGIplmZ1AFfWifUfHG66yfazF3TEr+srzioY4cUX6b/Jy+ZoedkuSbvRWMDML9FaRPBsCwRDMT/HJpENwBCwlZzGsp8CzUraqCtkqBjIjs/m2sL5tjiRxKvrbCGPYt7tHIvuDeRP2v+tGTulo/fIB8aBK0PCPLs3z3MIa9JvuqGTy3m7lpiV2WYUz6UHOM6ieYaMZTZoDd2jWkx86PHuJtxrGFgsGU6yib1BmEAqVbFk6GvSIFqiLBB;5:ekW/kfAPU4vfDsNMMBU9ZzyT5Ey/IYh0CV3fZPvVVkSC1Z64Hl15JHFjrriv3FReUbW9q1WcTECnBVoVyi6S2Lz3fNK4ioWwCLNtULF/VF7VNeNtaIQx8m8x1GNHHjuLAtLiFKDixeYjjTTbXSCKiuWA/DPgN4I6ztzIbHO10G0=;24:vrD3kdv9b9eAa0CUUJrPOwA7ih34I4i/bBsn7SZyETA+F0fYAam9N9fhscaSNZPnd8ydkVOGhIvDY7q196s27+a3XkLVszu37fNCZ6BtsEk=;7:hui9Gy3vRR8CIirDe60m2LafcK4DjzbD32uX3BZ60/4w76A9e7G1Zw65Lbi7b31QcOtrNT0bdwTgUh4iQZOfZTklz7ybWM2DBRyXbBtHNm4CFcJCkSQot2ZxL954c9xuh6gtMk87CwUxjTQ2bqzYsuapz28wW5iV5gsg60UAlik/Ui4c3a1r6hJDC8KQ+JKyG1qhOrXkX+fzyPzddX0bWIwxEQXq4JiZNt2su6vm1UiuAo1IUyM/Hz9UsGBmROZ96CMPA16J3j0v88J6Pih/vWj07/OzzrBT4FdZTboMePF4IbCocgSMKBQbqW42IMcq2mDuB8K7cqHDPXQGsG0Ypw== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: toradex.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2016 15:14:11.2928 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB1407 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2431 Lines: 81 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: Lukasz Majewski Signed-off-by: Bhuvanchandra DV Suggested-by: Sascha Hauer --- drivers/pwm/core.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 195373e..85cdda6 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); @@ -148,11 +153,10 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args) return pwm; pwm->args.period = args->args[1]; + pwm->args.polarity = PWM_POLARITY_NORMAL; - if (args->args[2] & PWM_POLARITY_INVERTED) + if (args->args_count > 2 && args->args[2] & PWM_POLARITY_INVERTED) pwm->args.polarity = PWM_POLARITY_INVERSED; - else - pwm->args.polarity = PWM_POLARITY_NORMAL; return pwm; } @@ -163,9 +167,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 +681,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.10.0