Unverified Commit 8cdcd8ae authored by Linus Walleij's avatar Linus Walleij Committed by Mark Brown
Browse files

spi: imx/fsl-lpspi: Convert to GPIO descriptors



This converts the two Freescale i.MX SPI drivers
Freescale i.MX (CONFIG_SPI_IMX) and Freescale i.MX LPSPI
(CONFIG_SPI_FSL_LPSPI) to use GPIO descriptors handled in
the SPI core for GPIO chip selects whether defined in
the device tree or a board file.

The reason why both are converted at the same time is
that they were both using the same platform data and
platform device population helpers when using
board files intertwining the code so this gives a cleaner
cut.

The platform device creation was passing a platform data
container from each boardfile down to the driver using
struct spi_imx_master from <linux/platform_data/spi-imx.h>,
but this was only conveying the number of chipselects and
an int * array of the chipselect GPIO numbers.

The imx27 and imx31 platforms had code passing the
now-unused platform data when creating the platform devices,
this has been repurposed to pass around GPIO descriptor
tables. The platform data struct that was just passing an
array of integers and number of chip selects for the GPIO
lines has been removed.

The number of chipselects used to be passed from the board
file, because this number also limits the number of native
chipselects that the platform can use. To deal with this we
just augment the i.MX (CONFIG_SPI_IMX) driver to support 3
chipselects if the platform does not define "num-cs" as a
device property (such as from the device tree). This covers
all the legacy boards as these use <= 3 native chip selects
(or GPIO lines, and in that case the number of chip selects
is determined by the core from the number of available
GPIO lines). Any new boards should use device tree, so
this is a reasonable simplification to cover all old
boards.

The LPSPI driver never assigned the number of chipselects
and thus always fall back to the core default of 1 chip
select if no GPIOs are defined in the device tree.

The Freescale i.MX driver was already partly utilizing
the SPI core to obtain the GPIO numbers from the device tree,
so this completes the transtion to let the core handle all
of it.

All board files and the core i.MX boardfile registration
code is augmented to account for these changes.

This has been compile-tested with the imx_v4_v5_defconfig
and the imx_v6_v7_defconfig.

Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Acked-by: default avatarShawn Guo <shawnguo@kernel.org>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Robin Gong <yibin.gong@nxp.com>
Cc: Trent Piepho <tpiepho@impinj.com>
Cc: Clark Wang <xiaoning.wang@nxp.com>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: NXP Linux Team <linux-imx@nxp.com>
Link: https://lore.kernel.org/r/20200625200252.207614-1-linus.walleij@linaro.org


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent be8faebc
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -75,11 +75,11 @@ extern const struct imx_mxc_w1_data imx27_mxc_w1_data;
	imx_add_mxc_w1(&imx27_mxc_w1_data)

extern const struct imx_spi_imx_data imx27_cspi_data[];
#define imx27_add_cspi(id, pdata)	\
	imx_add_spi_imx(&imx27_cspi_data[id], pdata)
#define imx27_add_spi_imx0(pdata)	imx27_add_cspi(0, pdata)
#define imx27_add_spi_imx1(pdata)	imx27_add_cspi(1, pdata)
#define imx27_add_spi_imx2(pdata)	imx27_add_cspi(2, pdata)
#define imx27_add_cspi(id, gtable) \
	imx_add_spi_imx(&imx27_cspi_data[id], gtable)
#define imx27_add_spi_imx0(gtable)	imx27_add_cspi(0, gtable)
#define imx27_add_spi_imx1(gtable)	imx27_add_cspi(1, gtable)
#define imx27_add_spi_imx2(gtable)	imx27_add_cspi(2, gtable)

extern const struct imx_pata_imx_data imx27_pata_imx_data;
#define imx27_add_pata_imx() \
+5 −5
Original line number Diff line number Diff line
@@ -69,11 +69,11 @@ extern const struct imx_mxc_w1_data imx31_mxc_w1_data;
	imx_add_mxc_w1(&imx31_mxc_w1_data)

extern const struct imx_spi_imx_data imx31_cspi_data[];
#define imx31_add_cspi(id, pdata)	\
	imx_add_spi_imx(&imx31_cspi_data[id], pdata)
#define imx31_add_spi_imx0(pdata)	imx31_add_cspi(0, pdata)
#define imx31_add_spi_imx1(pdata)	imx31_add_cspi(1, pdata)
#define imx31_add_spi_imx2(pdata)	imx31_add_cspi(2, pdata)
#define imx31_add_cspi(id, gtable) \
	imx_add_spi_imx(&imx31_cspi_data[id], gtable)
#define imx31_add_spi_imx0(gtable)	imx31_add_cspi(0, gtable)
#define imx31_add_spi_imx1(gtable)	imx31_add_cspi(1, gtable)
#define imx31_add_spi_imx2(gtable)	imx31_add_cspi(2, gtable)

extern const struct imx_pata_imx_data imx31_pata_imx_data;
#define imx31_add_pata_imx() \
+2 −3
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/init.h>
#include <linux/gpio/machine.h>
#include <linux/platform_data/dma-imx-sdma.h>

extern struct device mxc_aips_bus;
@@ -276,7 +277,6 @@ struct platform_device *__init imx_add_sdhci_esdhc_imx(
		const struct imx_sdhci_esdhc_imx_data *data,
		const struct esdhc_platform_data *pdata);

#include <linux/platform_data/spi-imx.h>
struct imx_spi_imx_data {
	const char *devid;
	int id;
@@ -285,8 +285,7 @@ struct imx_spi_imx_data {
	int irq;
};
struct platform_device *__init imx_add_spi_imx(
		const struct imx_spi_imx_data *data,
		const struct spi_imx_master *pdata);
	const struct imx_spi_imx_data *data, struct gpiod_lookup_table *gtable);

struct platform_device *imx_add_imx_dma(char *name, resource_size_t iobase,
					int irq, int irq_err);
+5 −4
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
 * Copyright (C) 2009-2010 Pengutronix
 * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
 */
#include <linux/gpio/machine.h>
#include "../hardware.h"
#include "devices-common.h"

@@ -57,8 +58,7 @@ const struct imx_spi_imx_data imx35_cspi_data[] __initconst = {
#endif /* ifdef CONFIG_SOC_IMX35 */

struct platform_device *__init imx_add_spi_imx(
		const struct imx_spi_imx_data *data,
		const struct spi_imx_master *pdata)
	const struct imx_spi_imx_data *data, struct gpiod_lookup_table *gtable)
{
	struct resource res[] = {
		{
@@ -71,7 +71,8 @@ struct platform_device *__init imx_add_spi_imx(
			.flags = IORESOURCE_IRQ,
		},
	};

	if (gtable)
		gpiod_add_lookup_table(gtable);
	return imx_add_platform_device(data->devid, data->id,
			res, ARRAY_SIZE(res), pdata, sizeof(*pdata));
			res, ARRAY_SIZE(res), NULL, 0);
}
+28 −12
Original line number Diff line number Diff line
@@ -303,18 +303,34 @@ static struct imx_ssi_platform_data mx27_3ds_ssi_pdata = {
};

/* SPI */
static int spi1_chipselect[] = {SPI1_SS0};

static const struct spi_imx_master spi1_pdata __initconst = {
	.chipselect	= spi1_chipselect,
	.num_chipselect	= ARRAY_SIZE(spi1_chipselect),
static struct gpiod_lookup_table mx27_spi1_gpiod_table = {
	.dev_id = "imx27-cspi.0", /* Actual device name for spi1 */
	.table = {
		/*
		 * The i.MX27 has the i.MX21 GPIO controller, the SPI1 CS GPIO
		 * SPI1_SS0 is numbered IMX_GPIO_NR(4, 28).
		 *
		 * This is in "bank 4" which is subtracted by one in the macro
		 * so this is actually bank 3 on "imx21-gpio.3".
		 */
		GPIO_LOOKUP_IDX("imx21-gpio.3", 28, "cs", 0, GPIO_ACTIVE_LOW),
		{ },
	},
};

static int spi2_chipselect[] = {SPI2_SS0};

static const struct spi_imx_master spi2_pdata __initconst = {
	.chipselect	= spi2_chipselect,
	.num_chipselect	= ARRAY_SIZE(spi2_chipselect),
static struct gpiod_lookup_table mx27_spi2_gpiod_table = {
	.dev_id = "imx27-cspi.1", /* Actual device name for spi2 */
	.table = {
		/*
		 * The i.MX27 has the i.MX21 GPIO controller, the SPI2 CS GPIO
		 * SPI2_SS0 is numbered IMX_GPIO_NR(4, 21).
		 *
		 * This is in "bank 4" which is subtracted by one in the macro
		 * so this is actually bank 3 on "imx21-gpio.3".
		 */
		GPIO_LOOKUP_IDX("imx21-gpio.3", 21, "cs", 0, GPIO_ACTIVE_LOW),
		{ },
	},
};

static struct imx_fb_videomode mx27_3ds_modes[] = {
@@ -397,8 +413,8 @@ static void __init mx27pdk_init(void)
	imx27_add_imx_keypad(&mx27_3ds_keymap_data);
	imx27_add_imx2_wdt();

	imx27_add_spi_imx1(&spi2_pdata);
	imx27_add_spi_imx0(&spi1_pdata);
	imx27_add_spi_imx1(&mx27_spi2_gpiod_table);
	imx27_add_spi_imx0(&mx27_spi1_gpiod_table);

	imx27_add_imx_i2c(0, &mx27_3ds_i2c0_data);
	imx27_add_imx_fb(&mx27_3ds_fb_data);
Loading