Commit 89da4293 authored by Trent Piepho's avatar Trent Piepho Committed by Mark Brown

spi: Use of_property_read_u32

Instead of getting the raw property, checking the length, and doing
endian conversion each time, use the OF function
of_property_read_u32() that does all that.

Error messages are slightly improved with error codes from
of_property_read_u32() for different ways the property may be invalid
(missing, too short, etc.)
Signed-off-by: default avatarTrent Piepho <tpiepho@gmail.com>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent 70fac17c
...@@ -838,9 +838,8 @@ static void of_register_spi_devices(struct spi_master *master) ...@@ -838,9 +838,8 @@ static void of_register_spi_devices(struct spi_master *master)
{ {
struct spi_device *spi; struct spi_device *spi;
struct device_node *nc; struct device_node *nc;
const __be32 *prop;
int rc; int rc;
int len; u32 value;
if (!master->dev.of_node) if (!master->dev.of_node)
return; return;
...@@ -865,14 +864,14 @@ static void of_register_spi_devices(struct spi_master *master) ...@@ -865,14 +864,14 @@ static void of_register_spi_devices(struct spi_master *master)
} }
/* Device address */ /* Device address */
prop = of_get_property(nc, "reg", &len); rc = of_property_read_u32(nc, "reg", &value);
if (!prop || len < sizeof(*prop)) { if (rc) {
dev_err(&master->dev, "%s has no 'reg' property\n", dev_err(&master->dev, "%s has no valid 'reg' property (%d)\n",
nc->full_name); nc->full_name, rc);
spi_dev_put(spi); spi_dev_put(spi);
continue; continue;
} }
spi->chip_select = be32_to_cpup(prop); spi->chip_select = value;
/* Mode (clock phase/polarity/etc.) */ /* Mode (clock phase/polarity/etc.) */
if (of_find_property(nc, "spi-cpha", NULL)) if (of_find_property(nc, "spi-cpha", NULL))
...@@ -885,55 +884,53 @@ static void of_register_spi_devices(struct spi_master *master) ...@@ -885,55 +884,53 @@ static void of_register_spi_devices(struct spi_master *master)
spi->mode |= SPI_3WIRE; spi->mode |= SPI_3WIRE;
/* Device DUAL/QUAD mode */ /* Device DUAL/QUAD mode */
prop = of_get_property(nc, "spi-tx-bus-width", &len); if (!of_property_read_u32(nc, "spi-tx-bus-width", &value)) {
if (prop && len == sizeof(*prop)) { switch (value) {
switch (be32_to_cpup(prop)) { case 1:
case SPI_NBITS_SINGLE:
break; break;
case SPI_NBITS_DUAL: case 2:
spi->mode |= SPI_TX_DUAL; spi->mode |= SPI_TX_DUAL;
break; break;
case SPI_NBITS_QUAD: case 4:
spi->mode |= SPI_TX_QUAD; spi->mode |= SPI_TX_QUAD;
break; break;
default: default:
dev_err(&master->dev, dev_err(&master->dev,
"spi-tx-bus-width %d not supported\n", "spi-tx-bus-width %d not supported\n",
be32_to_cpup(prop)); value);
spi_dev_put(spi); spi_dev_put(spi);
continue; continue;
} }
} }
prop = of_get_property(nc, "spi-rx-bus-width", &len); if (!of_property_read_u32(nc, "spi-rx-bus-width", &value)) {
if (prop && len == sizeof(*prop)) { switch (value) {
switch (be32_to_cpup(prop)) { case 1:
case SPI_NBITS_SINGLE:
break; break;
case SPI_NBITS_DUAL: case 2:
spi->mode |= SPI_RX_DUAL; spi->mode |= SPI_RX_DUAL;
break; break;
case SPI_NBITS_QUAD: case 4:
spi->mode |= SPI_RX_QUAD; spi->mode |= SPI_RX_QUAD;
break; break;
default: default:
dev_err(&master->dev, dev_err(&master->dev,
"spi-rx-bus-width %d not supported\n", "spi-rx-bus-width %d not supported\n",
be32_to_cpup(prop)); value);
spi_dev_put(spi); spi_dev_put(spi);
continue; continue;
} }
} }
/* Device speed */ /* Device speed */
prop = of_get_property(nc, "spi-max-frequency", &len); rc = of_property_read_u32(nc, "spi-max-frequency", &value);
if (!prop || len < sizeof(*prop)) { if (rc) {
dev_err(&master->dev, "%s has no 'spi-max-frequency' property\n", dev_err(&master->dev, "%s has no valid 'spi-max-frequency' property (%d)\n",
nc->full_name); nc->full_name, rc);
spi_dev_put(spi); spi_dev_put(spi);
continue; continue;
} }
spi->max_speed_hz = be32_to_cpup(prop); spi->max_speed_hz = value;
/* IRQ */ /* IRQ */
spi->irq = irq_of_parse_and_map(nc, 0); spi->irq = irq_of_parse_and_map(nc, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment