brcm63xx: enhance dt partitions support to match upstream more closely
[openwrt/openwrt.git] / target / linux / brcm63xx / patches-4.4 / 000-4.9-01-spi-introduce-max_message_size-hook-in-spi_master.patch
1 From 5090cc6ae2f79ee779e5faf7c8a28edf42b7d738 Mon Sep 17 00:00:00 2001
2 From: Heiner Kallweit <hkallweit1@gmail.com>
3 Date: Wed, 17 Aug 2016 21:08:01 +0200
4 Subject: [PATCH] spi: introduce max_message_size hook in spi_master
5
6 Recently a maximum transfer size was was introduced in struct spi_master.
7 However there are also spi controllers with a maximum message size, e.g.
8 fsl-espi has a max message size of 64KB.
9 Introduce a hook max_message_size to deal with such limitations.
10
11 Also make sure that spi_max_transfer_size doesn't return greater values
12 than spi_max_message_size, even if hook max_transfer_size is not set.
13
14 Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
15 Signed-off-by: Mark Brown <broonie@kernel.org>
16 ---
17 include/linux/spi/spi.h | 25 +++++++++++++++++++++----
18 1 file changed, 21 insertions(+), 4 deletions(-)
19
20 --- a/include/linux/spi/spi.h
21 +++ b/include/linux/spi/spi.h
22 @@ -304,6 +304,8 @@ static inline void spi_unregister_driver
23 * @min_speed_hz: Lowest supported transfer speed
24 * @max_speed_hz: Highest supported transfer speed
25 * @flags: other constraints relevant to this driver
26 + * @max_message_size: function that returns the max message size for
27 + * a &spi_device; may be %NULL, so the default %SIZE_MAX will be used.
28 * @bus_lock_spinlock: spinlock for SPI bus locking
29 * @bus_lock_mutex: mutex for SPI bus locking
30 * @bus_lock_flag: indicates that the SPI bus is locked for exclusive use
31 @@ -429,10 +431,11 @@ struct spi_master {
32 #define SPI_MASTER_MUST_TX BIT(4) /* requires tx */
33
34 /*
35 - * on some hardware transfer size may be constrained
36 + * on some hardware transfer / message size may be constrained
37 * the limit may depend on device transfer settings
38 */
39 size_t (*max_transfer_size)(struct spi_device *spi);
40 + size_t (*max_message_size)(struct spi_device *spi);
41
42 /* lock and mutex for SPI bus locking */
43 spinlock_t bus_lock_spinlock;
44 @@ -844,12 +847,26 @@ extern int spi_async_locked(struct spi_d
45 struct spi_message *message);
46
47 static inline size_t
48 -spi_max_transfer_size(struct spi_device *spi)
49 +spi_max_message_size(struct spi_device *spi)
50 {
51 struct spi_master *master = spi->master;
52 - if (!master->max_transfer_size)
53 + if (!master->max_message_size)
54 return SIZE_MAX;
55 - return master->max_transfer_size(spi);
56 + return master->max_message_size(spi);
57 +}
58 +
59 +static inline size_t
60 +spi_max_transfer_size(struct spi_device *spi)
61 +{
62 + struct spi_master *master = spi->master;
63 + size_t tr_max = SIZE_MAX;
64 + size_t msg_max = spi_max_message_size(spi);
65 +
66 + if (master->max_transfer_size)
67 + tr_max = master->max_transfer_size(spi);
68 +
69 + /* transfer size limit must not be greater than messsage size limit */
70 + return min(tr_max, msg_max);
71 }
72
73 /*---------------------------------------------------------------------------*/