Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752818AbbF3GoU (ORCPT ); Tue, 30 Jun 2015 02:44:20 -0400 Received: from mail-wi0-f176.google.com ([209.85.212.176]:36517 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752508AbbF3Gn4 (ORCPT ); Tue, 30 Jun 2015 02:43:56 -0400 From: Fabio Falzoi To: thomas.petazzoni@free-electrons.com, noralf@tronnes.org Cc: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Fabio Falzoi Subject: [PATCH 05/10] Staging: fbtft: Set bus specific ops using separate functions Date: Tue, 30 Jun 2015 08:43:12 +0200 Message-Id: <1435646597-7612-6-git-send-email-fabio.falzoi84@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1435646597-7612-1-git-send-email-fabio.falzoi84@gmail.com> References: <1435646597-7612-1-git-send-email-fabio.falzoi84@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5608 Lines: 193 Use two separate functions for spi and platform bus (flexfb_set_spi_bus_func and flexfb_set_platform_bus_func, respectively) to set the appropriate write operations. This patch corrects the following checkpatch errors: WARNING:LONG_LiINE at lines 446, 450, 466, 476, 489 and 495. CHECK:PARENTHESIS_ALIGNMENT at line 459. Signed-off-by: Fabio Falzoi --- drivers/staging/fbtft/flexfb.c | 154 +++++++++++++++++++++++++---------------- 1 file changed, 94 insertions(+), 60 deletions(-) diff --git a/drivers/staging/fbtft/flexfb.c b/drivers/staging/fbtft/flexfb.c index dae092a..1b833f9 100644 --- a/drivers/staging/fbtft/flexfb.c +++ b/drivers/staging/fbtft/flexfb.c @@ -382,6 +382,94 @@ static int flexfb_set_regwrite_func(const struct device *dev, return 0; } +static int flexfb_emulate_spi_8(struct fbtft_par *par, struct spi_device *sdev) +{ + struct device *dev = &sdev->dev; + int ret; + + dev_warn(dev, "9-bit SPI not available, emulating using 8-bit.\n"); + sdev->bits_per_word = 8; + ret = sdev->master->setup(sdev); + if (ret) + return ret; + + /* allocate buffer with room for dc bits */ + par->extra = devm_kzalloc(par->info->device, + par->txbuf.len + (par->txbuf.len / 8) + 8, + GFP_KERNEL); + if (!par->extra) + return -ENOMEM; + par->fbtftops.write = fbtft_write_spi_emulate_9; + + return 0; +} + +static int flexfb_set_spi_bus_func(struct fbtft_par *par, + struct spi_device *sdev) +{ + struct device *dev = &sdev->dev; + int ret; + + par->fbtftops.write = fbtft_write_spi; + switch (buswidth) { + case 8: + par->fbtftops.write_vmem = fbtft_write_vmem16_bus8; + if (!par->startbyte) + par->fbtftops.verify_gpios = flexfb_verify_gpios_dc; + break; + case 9: + if (regwidth == 16) { + dev_err(dev, "argument 'regwidth': %d is not supported with buswidth=%d and SPI.\n", + regwidth, buswidth); + return -EINVAL; + } + par->fbtftops.write_register = fbtft_write_reg8_bus9; + par->fbtftops.write_vmem = fbtft_write_vmem16_bus9; + sdev->bits_per_word = 9; + ret = sdev->master->setup(sdev); + if (ret) { + ret = flexfb_emulate_spi_8(par, sdev); + if (ret) + return ret; + } + break; + default: + dev_err(dev, "argument 'buswidth': %d is not supported with SPI.\n", + buswidth); + return -EINVAL; + } + + return 0; +} + +static int flexfb_set_platform_bus_func(struct fbtft_par *par, + struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + + par->fbtftops.verify_gpios = flexfb_verify_gpios_db; + switch (buswidth) { + case 8: + par->fbtftops.write = fbtft_write_gpio8_wr; + par->fbtftops.write_vmem = fbtft_write_vmem16_bus8; + break; + case 16: + par->fbtftops.write_register = fbtft_write_reg16_bus16; + if (latched) + par->fbtftops.write = fbtft_write_gpio16_wr_latched; + else + par->fbtftops.write = fbtft_write_gpio16_wr; + par->fbtftops.write_vmem = fbtft_write_vmem16_bus16; + break; + default: + dev_err(dev, "argument 'buswidth': %d is not supported with parallel.\n", + buswidth); + return -EINVAL; + } + + return 0; +} + static int flexfb_probe_common(struct spi_device *sdev, struct platform_device *pdev) { @@ -436,66 +524,12 @@ static int flexfb_probe_common(struct spi_device *sdev, if (ret) goto out_release; - /* bus functions */ - if (sdev) { - par->fbtftops.write = fbtft_write_spi; - switch (buswidth) { - case 8: - par->fbtftops.write_vmem = fbtft_write_vmem16_bus8; - if (!par->startbyte) - par->fbtftops.verify_gpios = flexfb_verify_gpios_dc; - break; - case 9: - if (regwidth == 16) { - dev_err(dev, "argument 'regwidth': %d is not supported with buswidth=%d and SPI.\n", regwidth, buswidth); - return -EINVAL; - } - par->fbtftops.write_register = fbtft_write_reg8_bus9; - par->fbtftops.write_vmem = fbtft_write_vmem16_bus9; - sdev->bits_per_word = 9; - ret = sdev->master->setup(sdev); - if (ret) { - dev_warn(dev, - "9-bit SPI not available, emulating using 8-bit.\n"); - sdev->bits_per_word = 8; - ret = sdev->master->setup(sdev); - if (ret) - goto out_release; - /* allocate buffer with room for dc bits */ - par->extra = devm_kzalloc(par->info->device, - par->txbuf.len + (par->txbuf.len / 8) + 8, - GFP_KERNEL); - if (!par->extra) { - ret = -ENOMEM; - goto out_release; - } - par->fbtftops.write = fbtft_write_spi_emulate_9; - } - break; - default: - dev_err(dev, "argument 'buswidth': %d is not supported with SPI.\n", buswidth); - return -EINVAL; - } - } else { - par->fbtftops.verify_gpios = flexfb_verify_gpios_db; - switch (buswidth) { - case 8: - par->fbtftops.write = fbtft_write_gpio8_wr; - par->fbtftops.write_vmem = fbtft_write_vmem16_bus8; - break; - case 16: - par->fbtftops.write_register = fbtft_write_reg16_bus16; - if (latched) - par->fbtftops.write = fbtft_write_gpio16_wr_latched; - else - par->fbtftops.write = fbtft_write_gpio16_wr; - par->fbtftops.write_vmem = fbtft_write_vmem16_bus16; - break; - default: - dev_err(dev, "argument 'buswidth': %d is not supported with parallel.\n", buswidth); - return -EINVAL; - } - } + if (sdev) + ret = flexfb_set_spi_bus_func(par, sdev); + else + ret = flexfb_set_platform_bus_func(par, pdev); + if (ret) + goto out_release; /* set_addr_win function */ switch (setaddrwin) { -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/