From patchwork Sat Sep 17 13:44:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9337097 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 68DA160839 for ; Sat, 17 Sep 2016 13:44:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 594912968F for ; Sat, 17 Sep 2016 13:44:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E26129693; Sat, 17 Sep 2016 13:44:51 +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,FREEMAIL_FROM, 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 2313E2968F for ; Sat, 17 Sep 2016 13:44:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751944AbcIQNot (ORCPT ); Sat, 17 Sep 2016 09:44:49 -0400 Received: from mout.web.de ([212.227.15.14]:63120 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751852AbcIQNot (ORCPT ); Sat, 17 Sep 2016 09:44:49 -0400 Received: from [192.168.178.152] ([91.50.213.247]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0MV4hR-1bUSfP2afF-00YVFF; Sat, 17 Sep 2016 15:44:42 +0200 From: Heiner Kallweit Subject: [PATCH 4/4] spi: fsl-espi: replace of_get_property with of_property_read_u32 To: Mark Brown References: <1d67ce99-42ea-c816-da35-e64575cca8ff@web.de> Cc: "linux-spi@vger.kernel.org" Message-ID: Date: Sat, 17 Sep 2016 15:44:20 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <1d67ce99-42ea-c816-da35-e64575cca8ff@web.de> X-Provags-ID: V03:K0:8pNnTW9x7/yeGWA9Q14flcLwH+icaFYkQ0yFQMIeTgc4rPvQhij cH8DAVonu6CLAURHqVULVYaVfNUUb5r2uUzSBNxUzeli3lc6cEDEHn/5P5Tw7WrKc8YbJ5u lBXhB75O0/G8AHlVmn6YteFJ0VosH+13P1gJWKdgwcKCCKDm+uSlGKYL2GdFW7uSP8Aj11H d2Z9mkciQ6vUMdneuwMxQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:d8ATHQJGLIg=:2OB4wLHdSvGUuI091on18n RyJ3XiGVGdKgvjBk0hgaogvaPygQ/lxNmyLjQKiwbIsnOmWCNUuc2CYv5Ivrz/orePwH5shJp kyoWOIuJEGG4IS0tFgUaIETxknGbg4epDTmnPk6xYvg8HGbViE5W4kNU0A9ZAY/lnc378Lbm/ a9rTt/IRUEtMzgt+g/3dlGJCVHcUO+0h70LF10FpyxUwYTK5PUVlZVSUyA79NbsaG/F6hyt36 2d6VFXTXsWDhjS60Wddcc4gbzdEjnyT4sz4KCGnmAP0cw/DnUbNx7Rw3NVjzvkCiregspeNUe YedSh0iU3p/SPsEnR+WmH7/4urdm/l9Z9VMOZ8PsbDHCH2jChFHwKfFGefiFWIbtyQtqjRZJ0 LLdzt+V5RVpMengFprq5G5sJVddftJKXzd6ZhKejbRURzX5ZbhFs6hGjRCgmm7pGJ81OakYvK G8Kjd1JapOa7N9t/WvXSRBMZ8vU3GnY6fSzqSi0iae2qKXU1xtrx1/TMM51cg4HBOBwlPRgsn r43lEJm3u+YSt0qU5Q+QHNocxLwNIzM3W9B8CDg+biYjPRiLvs0YCSyV5ap69OyIr0/6ljkNZ BdZ6XaOsnIc87mAOuTGWGv9QxqSSkDod+gJxk+lHmz0PIIKniDwYZ2/GeOzFgOZwPZJqYX4Ah ZYk3v0RqtUtuEudBhtVDtmkiCBQhQGrv3wFAkVXU7lfwptb+MqKDbXFBrOPUxVgmvEgZGUD7t wkV5Xs9Tr+bO62vuakn7kQTtztQeKcDbM2n113fsWx4sWDBh4HpFPQkaEW8jigVZf8q3i38Mh VKLTRWg Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace of_get_property with of_property_read_u32, thus simplifying the code and improving readability. Signed-off-by: Heiner Kallweit --- drivers/spi/spi-fsl-espi.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c index 7451585..1f97cce 100644 --- a/drivers/spi/spi-fsl-espi.c +++ b/drivers/spi/spi-fsl-espi.c @@ -545,9 +545,8 @@ static int fsl_espi_probe(struct device *dev, struct resource *mem, struct spi_master *master; struct mpc8xxx_spi *mpc8xxx_spi; struct device_node *nc; - const __be32 *prop; - u32 regval, csmode; - int i, len, ret; + u32 regval, csmode, cs, prop; + int ret; master = spi_alloc_master(dev, sizeof(struct mpc8xxx_spi)); if (!master) @@ -599,29 +598,29 @@ static int fsl_espi_probe(struct device *dev, struct resource *mem, /* Init eSPI CS mode register */ for_each_available_child_of_node(master->dev.of_node, nc) { /* get chip select */ - prop = of_get_property(nc, "reg", &len); - if (!prop || len < sizeof(*prop)) - continue; - i = be32_to_cpup(prop); - if (i < 0 || i >= pdata->max_chipselect) + ret = of_property_read_u32(nc, "reg", &cs); + if (ret || cs >= pdata->max_chipselect) continue; csmode = CSMODE_INIT_VAL; + /* check if CSBEF is set in device tree */ - prop = of_get_property(nc, "fsl,csbef", &len); - if (prop && len >= sizeof(*prop)) { + ret = of_property_read_u32(nc, "fsl,csbef", &prop); + if (!ret) { csmode &= ~(CSMODE_BEF(0xf)); - csmode |= CSMODE_BEF(be32_to_cpup(prop)); + csmode |= CSMODE_BEF(prop); } + /* check if CSAFT is set in device tree */ - prop = of_get_property(nc, "fsl,csaft", &len); - if (prop && len >= sizeof(*prop)) { + ret = of_property_read_u32(nc, "fsl,csaft", &prop); + if (!ret) { csmode &= ~(CSMODE_AFT(0xf)); - csmode |= CSMODE_AFT(be32_to_cpup(prop)); + csmode |= CSMODE_AFT(prop); } - fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPMODEx(i), csmode); - dev_info(dev, "cs=%d, init_csmode=0x%x\n", i, csmode); + fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPMODEx(cs), csmode); + + dev_info(dev, "cs=%u, init_csmode=0x%x\n", cs, csmode); } /* Enable SPI interface */ @@ -660,16 +659,16 @@ static int of_fsl_espi_get_chipselects(struct device *dev) { struct device_node *np = dev->of_node; struct fsl_spi_platform_data *pdata = dev_get_platdata(dev); - const u32 *prop; - int len; + u32 num_cs; + int ret; - prop = of_get_property(np, "fsl,espi-num-chipselects", &len); - if (!prop || len < sizeof(*prop)) { + ret = of_property_read_u32(np, "fsl,espi-num-chipselects", &num_cs); + if (ret) { dev_err(dev, "No 'fsl,espi-num-chipselects' property\n"); return -EINVAL; } - pdata->max_chipselect = *prop; + pdata->max_chipselect = num_cs; pdata->cs_control = NULL; return 0;