diff options
author | Mark Brown <broonie@kernel.org> | 2015-08-31 09:45:27 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-08-31 09:45:27 -0400 |
commit | bc6450994976f26bbde656b1994f95b955bdabfc (patch) | |
tree | 464732f5478c63938973aea3afc1f3d632f1ef5e | |
parent | af211211e39f59575854d5976a4e301c8c21d4bc (diff) | |
parent | 63ab645f4d8b2dc1351c41751e7ebb1b3f1c99d3 (diff) |
Merge remote-tracking branch 'spi/topic/core' into spi-next
-rw-r--r-- | drivers/spi/spi.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index cf8b91b23a76..829323ce7cdf 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c | |||
@@ -1740,6 +1740,20 @@ EXPORT_SYMBOL_GPL(spi_busnum_to_master); | |||
1740 | * other core methods are currently defined as inline functions. | 1740 | * other core methods are currently defined as inline functions. |
1741 | */ | 1741 | */ |
1742 | 1742 | ||
1743 | static int __spi_validate_bits_per_word(struct spi_master *master, u8 bits_per_word) | ||
1744 | { | ||
1745 | if (master->bits_per_word_mask) { | ||
1746 | /* Only 32 bits fit in the mask */ | ||
1747 | if (bits_per_word > 32) | ||
1748 | return -EINVAL; | ||
1749 | if (!(master->bits_per_word_mask & | ||
1750 | SPI_BPW_MASK(bits_per_word))) | ||
1751 | return -EINVAL; | ||
1752 | } | ||
1753 | |||
1754 | return 0; | ||
1755 | } | ||
1756 | |||
1743 | /** | 1757 | /** |
1744 | * spi_setup - setup SPI mode and clock rate | 1758 | * spi_setup - setup SPI mode and clock rate |
1745 | * @spi: the device whose settings are being modified | 1759 | * @spi: the device whose settings are being modified |
@@ -1798,6 +1812,9 @@ int spi_setup(struct spi_device *spi) | |||
1798 | if (!spi->bits_per_word) | 1812 | if (!spi->bits_per_word) |
1799 | spi->bits_per_word = 8; | 1813 | spi->bits_per_word = 8; |
1800 | 1814 | ||
1815 | if (__spi_validate_bits_per_word(spi->master, spi->bits_per_word)) | ||
1816 | return -EINVAL; | ||
1817 | |||
1801 | if (!spi->max_speed_hz) | 1818 | if (!spi->max_speed_hz) |
1802 | spi->max_speed_hz = spi->master->max_speed_hz; | 1819 | spi->max_speed_hz = spi->master->max_speed_hz; |
1803 | 1820 | ||
@@ -1860,19 +1877,15 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) | |||
1860 | 1877 | ||
1861 | if (!xfer->speed_hz) | 1878 | if (!xfer->speed_hz) |
1862 | xfer->speed_hz = spi->max_speed_hz; | 1879 | xfer->speed_hz = spi->max_speed_hz; |
1880 | if (!xfer->speed_hz) | ||
1881 | xfer->speed_hz = master->max_speed_hz; | ||
1863 | 1882 | ||
1864 | if (master->max_speed_hz && | 1883 | if (master->max_speed_hz && |
1865 | xfer->speed_hz > master->max_speed_hz) | 1884 | xfer->speed_hz > master->max_speed_hz) |
1866 | xfer->speed_hz = master->max_speed_hz; | 1885 | xfer->speed_hz = master->max_speed_hz; |
1867 | 1886 | ||
1868 | if (master->bits_per_word_mask) { | 1887 | if (__spi_validate_bits_per_word(master, xfer->bits_per_word)) |
1869 | /* Only 32 bits fit in the mask */ | 1888 | return -EINVAL; |
1870 | if (xfer->bits_per_word > 32) | ||
1871 | return -EINVAL; | ||
1872 | if (!(master->bits_per_word_mask & | ||
1873 | BIT(xfer->bits_per_word - 1))) | ||
1874 | return -EINVAL; | ||
1875 | } | ||
1876 | 1889 | ||
1877 | /* | 1890 | /* |
1878 | * SPI transfer length should be multiple of SPI word size | 1891 | * SPI transfer length should be multiple of SPI word size |