spi/pl022: add devicetree support
Subsystems (3)
PATCH v2 1/1 spi/pl022: add devicetree support
Add the chipselect array and cur_cs properties to pl022 main structure
Add a wrapper function to decide if the cs should be controlled by the cs_control callback or the chipselect gpio
Populate chipselect property from cs-gpios
Populate master->dev.of_node, so the spi bus can find child spi devices and register them
At pl022 setup, fill chip_data structure from dt nodes, if not provided by platform.
---
Applies to v3.5-rc4
Changes since v1:
return EPROBE_DEFFER if gpios are not initialized yet
.../devicetree/bindings/spi/spi_pl022.txt | 15 +++ drivers/spi/spi-pl022.c | 117 ++++++++++++++++---- 2 files changed, 112 insertions(+), 20 deletions(-)
Documentation/devicetree/bindings/spi/spi_pl022.txt +15 -0
@@ -6,7 +6,22 @@ Required properties: - interrupts : Should contain SPI controller interrupt Optional properties: +- pl022,num-chipselects : total number of chipselects - cs-gpios : should specify GPIOs used for chipselects. The gpios will be referred to as reg = <index> in the SPI child nodes. If unspecified, a single SPI device without a chip select can be used. +SPI slave nodes must be children of the SPI master node and can +contain the following properties. +See include/linux/amba/pl022.h for more details + +- pl022,hierarchy : master or slave interface +- pl022,interface : interface type +- pl022,slave-tx-disable : disconnect tx line in slave mode +- pl022,com-mode : polling, interrupt or dma +- pl022,rx-level-trig : Rx FIFO watermark level +- pl022,tx-level-trig : Tx FIFO watermark level +- pl022,ctrl-len : Microwire interface: Control length +- pl022,wait-state : Microwire interface: Wait state +- pl022,duplex : Microwire interface: Full/Half duplex +
drivers/spi/spi-pl022.c +97 -20
248 lines not on this page · raw message
Signature · 9 lines
1.7.10 ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
On Mon, Jun 25, 2012 at 06:06:28PM -0300, Alexandre Pereira da Silva wrote:
[...]
Quoted 1 line
drivers/spi/spi-pl022.c +0
-0
[...]
drivers/spi/spi-pl022.c static int calculate_effective_freq(struct pl022 *pl022, int freq, struct · line 1750
Quoted 9 lines
drivers/spi/spi-pl022.c +1
-1@@ -1733,7 +1744,7 @@ static int calculate_effective_freq(struct pl022 *pl022, int freq, struct* A piece of default chip info unless the platform * supplies it. */ -static const struct pl022_config_chip pl022_default_chip_info = { +static struct pl022_config_chip pl022_default_chip_info = { .com_mode =POLLING_TRANSFER , .iface =SSP_INTERFACE_MOTOROLA_SPI , .hierarchy =SSP_SLAVE ,
What's the reason for removing the const? You're only reading data from the structure.
[...]
drivers/spi/spi-pl022.c pl022_probe(struct amba_device *adev, const struct amba_id *id) · line 2045
Quoted 8 lines
drivers/spi/spi-pl022.c +4
-0@@ -1998,8 +2039,14 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id) goto err_no_pdata; } + num_cs = platform_info->num_chipselect; +#ifdef CONFIG_OF +of_property_read_u32 (np,"pl022,num-chipselects" , &num_cs); +#endif
This...
[...]
Quoted 29 lines
drivers/spi/spi-pl022.c +18
-1@@ -2017,13 +2064,40 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)* on this board */ master->bus_num = platform_info->bus_id; - master->num_chipselect = platform_info->num_chipselect; + master->num_chipselect = num_cs; master->cleanup = pl022_cleanup; master->setup = pl022_setup; master->prepare_transfer_hardware = pl022_prepare_transfer_hardware; master->transfer_one_message = pl022_transfer_one_message; master->unprepare_transfer_hardware = pl022_unprepare_transfer_hardware; master->rt = platform_info->rt; + master->dev.of_node = dev->of_node; + +#ifdef CONFIG_OF +for (i =0 ; i < num_cs; i++) { +int cs_gpio =of_get_named_gpio (np,"cs-gpios" , i); + +if (cs_gpio == -EPROBE_DEFER ) { + status = -EPROBE_DEFER ; + goto err_no_gpio; + } + + pl022->chipselect[i] = cs_gpio; + +if (gpio_is_valid (cs_gpio)) { +if (gpio_request (cs_gpio,"ssp-pl022" )) +dev_err (&adev->dev, +"could not request %d gpio\n" , cs_gpio);
drivers/spi/spi-pl022.c pl022_probe(struct amba_device *adev, const struct amba_id *id) · line 2100
Quoted 10 lines
drivers/spi/spi-pl022.c +10
-0+ else if (gpio_direction_output(cs_gpio, 1)) + dev_err(&adev->dev, +"could set gpio %d as output\n" , + cs_gpio); + } + } +#else +for (i =0 ; i < num_cs; i++) + pl022->chipselect[i] = -EINVAL ; +#endif
... and this would be good candidates for IS_ENABLED(CONFIG_OF).
drivers/spi/spi-pl022.c pl022_probe(struct amba_device *adev, const struct amba_id *id) · line 2209
Quoted 10 lines
drivers/spi/spi-pl022.c +3
-0/* * Supports mode 0-3, loopback, and active low CS. Transfers are @@ -2130,6 +2204,9 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id) err_no_ioremap:amba_release_regions (adev); err_no_ioregion: +#ifdef CONFIG_OF + err_no_gpio: +#endif
If you use the IS_ENABLED() macro, then you no longer need these either.
Thierry
Quoted 4 lines · Thierry Reding
On Mon, Jun 25, 2012 at 06:06:28PM -0300, Alexandre Pereira da Silva wrote:
[...]Quoted 1 line
drivers/spi/spi-pl022.c +0
-0[...]
Quoted 12 lines
drivers/spi/spi-pl022.c static int calculate_effective_freq(struct pl022 *pl022, int freq, struct · line 1750
Quoted 9 lines
drivers/spi/spi-pl022.c +1
-1@@ -1733,7 +1744,7 @@ static int calculate_effective_freq(struct pl022 *pl022, int freq, struct* A piece of default chip info unless the platform * supplies it. */ -static const struct pl022_config_chip pl022_default_chip_info = { +static struct pl022_config_chip pl022_default_chip_info = { .com_mode = POLLING_TRANSFER, .iface = SSP_INTERFACE_MOTOROLA_SPI, .hierarchy = SSP_SLAVE,What's the reason for removing the const? You're only reading data from the structure.
I are right. I will remove this change. It was a left-over from an older version.
Quoted 56 lines
[...]
drivers/spi/spi-pl022.c pl022_probe(struct amba_device *adev, const struct amba_id *id) · line 2045
Quoted 8 lines
drivers/spi/spi-pl022.c +4
-0@@ -1998,8 +2039,14 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id) goto err_no_pdata; } + num_cs = platform_info->num_chipselect; +#ifdef CONFIG_OF + of_property_read_u32(np, "pl022,num-chipselects", &num_cs); +#endif This...
[...]
Quoted 29 lines
drivers/spi/spi-pl022.c +18
-1@@ -2017,13 +2064,40 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)* on this board */ master->bus_num = platform_info->bus_id; - master->num_chipselect = platform_info->num_chipselect; + master->num_chipselect = num_cs; master->cleanup = pl022_cleanup; master->setup = pl022_setup; master->prepare_transfer_hardware = pl022_prepare_transfer_hardware; master->transfer_one_message = pl022_transfer_one_message; master->unprepare_transfer_hardware = pl022_unprepare_transfer_hardware; master->rt = platform_info->rt; + master->dev.of_node = dev->of_node; + +#ifdef CONFIG_OF + for (i = 0; i < num_cs; i++) { + int cs_gpio = of_get_named_gpio(np, "cs-gpios", i); + + if (cs_gpio == -EPROBE_DEFER) { + status = -EPROBE_DEFER; + goto err_no_gpio; + } + + pl022->chipselect[i] = cs_gpio; + + if (gpio_is_valid(cs_gpio)) { + if (gpio_request(cs_gpio, "ssp-pl022")) + dev_err(&adev->dev, + "could not request %d gpio\n", cs_gpio);drivers/spi/spi-pl022.c pl022_probe(struct amba_device *adev, const struct amba_id *id) · line 2100
Quoted 10 lines
drivers/spi/spi-pl022.c +10
-0+ else if (gpio_direction_output(cs_gpio, 1)) + dev_err(&adev->dev, + "could set gpio %d as output\n", + cs_gpio); + } + } +#else + for (i = 0; i < num_cs; i++) + pl022->chipselect[i] = -EINVAL; +#endif ... and this would be good candidates for
IS_ENABLED(CONFIG_OF).Quoted 1 line
Quoted 11 lines
Quoted 9 lines
/*
* Supports mode 0-3, loopback, and active low CS. Transfers aredrivers/spi/spi-pl022.c +0
-0@@ -2130,6 +2204,9 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
err_no_ioremap:
amba_release_regions(adev);
err_no_ioregion:
+ #ifdefCONFIG_OF
+err_no_gpio:
+ #endifIf you use the
IS_ENABLED()macro, then you no longer need these either.
Thanks for the suggestion, looks cleaner.