diff options
author | Marek Szyprowski <m.szyprowski@samsung.com> | 2010-06-30 16:27:32 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2010-07-04 00:45:44 -0400 |
commit | 04bb2a031cf95b34b7432dd47b318a932a895b4c (patch) | |
tree | d5c831a56c01b4a357450abae47f1afe8d61de34 /drivers/spi | |
parent | 5c2818cdfad1973ede3dcd2a8709620a192f8385 (diff) |
spi/bitbang: add support for SPI_MASTER_NO_{TX, RX} modes
This patch adds a new flags argument to bitbang_txrx_be_cpha0 and
bitbang_txrx_be_cpha1 transfer functions. This enables support for
SPI_MASTER_NO_{TX,RX} transfer modes. The change should have no impact
on speed of the existing drivers. bitbank_txrx_* functions are usually
inlined into the drivers. When the argument is equal to constant zero,
the optimizer would be able to eliminate the dead code (flags checks)
easily. Tested on ARM and GCC 4.4.x and in all cases the checks were
eliminated in the inlined function.
Reviewed-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/spi')
-rw-r--r-- | drivers/spi/spi_bitbang_txrx.h | 16 | ||||
-rw-r--r-- | drivers/spi/spi_butterfly.c | 2 | ||||
-rw-r--r-- | drivers/spi/spi_gpio.c | 8 | ||||
-rw-r--r-- | drivers/spi/spi_lm70llp.c | 2 | ||||
-rw-r--r-- | drivers/spi/spi_s3c24xx_gpio.c | 8 | ||||
-rw-r--r-- | drivers/spi/spi_sh_sci.c | 8 |
6 files changed, 24 insertions, 20 deletions
diff --git a/drivers/spi/spi_bitbang_txrx.h b/drivers/spi/spi_bitbang_txrx.h index fc033bbf9180..c16bf853c3eb 100644 --- a/drivers/spi/spi_bitbang_txrx.h +++ b/drivers/spi/spi_bitbang_txrx.h | |||
@@ -44,7 +44,7 @@ | |||
44 | 44 | ||
45 | static inline u32 | 45 | static inline u32 |
46 | bitbang_txrx_be_cpha0(struct spi_device *spi, | 46 | bitbang_txrx_be_cpha0(struct spi_device *spi, |
47 | unsigned nsecs, unsigned cpol, | 47 | unsigned nsecs, unsigned cpol, unsigned flags, |
48 | u32 word, u8 bits) | 48 | u32 word, u8 bits) |
49 | { | 49 | { |
50 | /* if (cpol == 0) this is SPI_MODE_0; else this is SPI_MODE_2 */ | 50 | /* if (cpol == 0) this is SPI_MODE_0; else this is SPI_MODE_2 */ |
@@ -53,7 +53,8 @@ bitbang_txrx_be_cpha0(struct spi_device *spi, | |||
53 | for (word <<= (32 - bits); likely(bits); bits--) { | 53 | for (word <<= (32 - bits); likely(bits); bits--) { |
54 | 54 | ||
55 | /* setup MSB (to slave) on trailing edge */ | 55 | /* setup MSB (to slave) on trailing edge */ |
56 | setmosi(spi, word & (1 << 31)); | 56 | if ((flags & SPI_MASTER_NO_TX) == 0) |
57 | setmosi(spi, word & (1 << 31)); | ||
57 | spidelay(nsecs); /* T(setup) */ | 58 | spidelay(nsecs); /* T(setup) */ |
58 | 59 | ||
59 | setsck(spi, !cpol); | 60 | setsck(spi, !cpol); |
@@ -61,7 +62,8 @@ bitbang_txrx_be_cpha0(struct spi_device *spi, | |||
61 | 62 | ||
62 | /* sample MSB (from slave) on leading edge */ | 63 | /* sample MSB (from slave) on leading edge */ |
63 | word <<= 1; | 64 | word <<= 1; |
64 | word |= getmiso(spi); | 65 | if ((flags & SPI_MASTER_NO_RX) == 0) |
66 | word |= getmiso(spi); | ||
65 | setsck(spi, cpol); | 67 | setsck(spi, cpol); |
66 | } | 68 | } |
67 | return word; | 69 | return word; |
@@ -69,7 +71,7 @@ bitbang_txrx_be_cpha0(struct spi_device *spi, | |||
69 | 71 | ||
70 | static inline u32 | 72 | static inline u32 |
71 | bitbang_txrx_be_cpha1(struct spi_device *spi, | 73 | bitbang_txrx_be_cpha1(struct spi_device *spi, |
72 | unsigned nsecs, unsigned cpol, | 74 | unsigned nsecs, unsigned cpol, unsigned flags, |
73 | u32 word, u8 bits) | 75 | u32 word, u8 bits) |
74 | { | 76 | { |
75 | /* if (cpol == 0) this is SPI_MODE_1; else this is SPI_MODE_3 */ | 77 | /* if (cpol == 0) this is SPI_MODE_1; else this is SPI_MODE_3 */ |
@@ -79,7 +81,8 @@ bitbang_txrx_be_cpha1(struct spi_device *spi, | |||
79 | 81 | ||
80 | /* setup MSB (to slave) on leading edge */ | 82 | /* setup MSB (to slave) on leading edge */ |
81 | setsck(spi, !cpol); | 83 | setsck(spi, !cpol); |
82 | setmosi(spi, word & (1 << 31)); | 84 | if ((flags & SPI_MASTER_NO_TX) == 0) |
85 | setmosi(spi, word & (1 << 31)); | ||
83 | spidelay(nsecs); /* T(setup) */ | 86 | spidelay(nsecs); /* T(setup) */ |
84 | 87 | ||
85 | setsck(spi, cpol); | 88 | setsck(spi, cpol); |
@@ -87,7 +90,8 @@ bitbang_txrx_be_cpha1(struct spi_device *spi, | |||
87 | 90 | ||
88 | /* sample MSB (from slave) on trailing edge */ | 91 | /* sample MSB (from slave) on trailing edge */ |
89 | word <<= 1; | 92 | word <<= 1; |
90 | word |= getmiso(spi); | 93 | if ((flags & SPI_MASTER_NO_RX) == 0) |
94 | word |= getmiso(spi); | ||
91 | } | 95 | } |
92 | return word; | 96 | return word; |
93 | } | 97 | } |
diff --git a/drivers/spi/spi_butterfly.c b/drivers/spi/spi_butterfly.c index 8b5281281111..0d4ceba3b590 100644 --- a/drivers/spi/spi_butterfly.c +++ b/drivers/spi/spi_butterfly.c | |||
@@ -156,7 +156,7 @@ butterfly_txrx_word_mode0(struct spi_device *spi, | |||
156 | unsigned nsecs, | 156 | unsigned nsecs, |
157 | u32 word, u8 bits) | 157 | u32 word, u8 bits) |
158 | { | 158 | { |
159 | return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits); | 159 | return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits); |
160 | } | 160 | } |
161 | 161 | ||
162 | /*----------------------------------------------------------------------*/ | 162 | /*----------------------------------------------------------------------*/ |
diff --git a/drivers/spi/spi_gpio.c b/drivers/spi/spi_gpio.c index 7edbd5807e0e..82b480cc9637 100644 --- a/drivers/spi/spi_gpio.c +++ b/drivers/spi/spi_gpio.c | |||
@@ -146,25 +146,25 @@ static inline int getmiso(const struct spi_device *spi) | |||
146 | static u32 spi_gpio_txrx_word_mode0(struct spi_device *spi, | 146 | static u32 spi_gpio_txrx_word_mode0(struct spi_device *spi, |
147 | unsigned nsecs, u32 word, u8 bits) | 147 | unsigned nsecs, u32 word, u8 bits) |
148 | { | 148 | { |
149 | return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits); | 149 | return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits); |
150 | } | 150 | } |
151 | 151 | ||
152 | static u32 spi_gpio_txrx_word_mode1(struct spi_device *spi, | 152 | static u32 spi_gpio_txrx_word_mode1(struct spi_device *spi, |
153 | unsigned nsecs, u32 word, u8 bits) | 153 | unsigned nsecs, u32 word, u8 bits) |
154 | { | 154 | { |
155 | return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits); | 155 | return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits); |
156 | } | 156 | } |
157 | 157 | ||
158 | static u32 spi_gpio_txrx_word_mode2(struct spi_device *spi, | 158 | static u32 spi_gpio_txrx_word_mode2(struct spi_device *spi, |
159 | unsigned nsecs, u32 word, u8 bits) | 159 | unsigned nsecs, u32 word, u8 bits) |
160 | { | 160 | { |
161 | return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits); | 161 | return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits); |
162 | } | 162 | } |
163 | 163 | ||
164 | static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi, | 164 | static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi, |
165 | unsigned nsecs, u32 word, u8 bits) | 165 | unsigned nsecs, u32 word, u8 bits) |
166 | { | 166 | { |
167 | return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits); | 167 | return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits); |
168 | } | 168 | } |
169 | 169 | ||
170 | /*----------------------------------------------------------------------*/ | 170 | /*----------------------------------------------------------------------*/ |
diff --git a/drivers/spi/spi_lm70llp.c b/drivers/spi/spi_lm70llp.c index 86fb7b5993db..7746a41ab6d6 100644 --- a/drivers/spi/spi_lm70llp.c +++ b/drivers/spi/spi_lm70llp.c | |||
@@ -191,7 +191,7 @@ static void lm70_chipselect(struct spi_device *spi, int value) | |||
191 | */ | 191 | */ |
192 | static u32 lm70_txrx(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits) | 192 | static u32 lm70_txrx(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits) |
193 | { | 193 | { |
194 | return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits); | 194 | return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits); |
195 | } | 195 | } |
196 | 196 | ||
197 | static void spi_lm70llp_attach(struct parport *p) | 197 | static void spi_lm70llp_attach(struct parport *p) |
diff --git a/drivers/spi/spi_s3c24xx_gpio.c b/drivers/spi/spi_s3c24xx_gpio.c index 8979a75dbd7b..be991359bf92 100644 --- a/drivers/spi/spi_s3c24xx_gpio.c +++ b/drivers/spi/spi_s3c24xx_gpio.c | |||
@@ -64,25 +64,25 @@ static inline u32 getmiso(struct spi_device *dev) | |||
64 | static u32 s3c2410_spigpio_txrx_mode0(struct spi_device *spi, | 64 | static u32 s3c2410_spigpio_txrx_mode0(struct spi_device *spi, |
65 | unsigned nsecs, u32 word, u8 bits) | 65 | unsigned nsecs, u32 word, u8 bits) |
66 | { | 66 | { |
67 | return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits); | 67 | return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits); |
68 | } | 68 | } |
69 | 69 | ||
70 | static u32 s3c2410_spigpio_txrx_mode1(struct spi_device *spi, | 70 | static u32 s3c2410_spigpio_txrx_mode1(struct spi_device *spi, |
71 | unsigned nsecs, u32 word, u8 bits) | 71 | unsigned nsecs, u32 word, u8 bits) |
72 | { | 72 | { |
73 | return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits); | 73 | return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits); |
74 | } | 74 | } |
75 | 75 | ||
76 | static u32 s3c2410_spigpio_txrx_mode2(struct spi_device *spi, | 76 | static u32 s3c2410_spigpio_txrx_mode2(struct spi_device *spi, |
77 | unsigned nsecs, u32 word, u8 bits) | 77 | unsigned nsecs, u32 word, u8 bits) |
78 | { | 78 | { |
79 | return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits); | 79 | return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits); |
80 | } | 80 | } |
81 | 81 | ||
82 | static u32 s3c2410_spigpio_txrx_mode3(struct spi_device *spi, | 82 | static u32 s3c2410_spigpio_txrx_mode3(struct spi_device *spi, |
83 | unsigned nsecs, u32 word, u8 bits) | 83 | unsigned nsecs, u32 word, u8 bits) |
84 | { | 84 | { |
85 | return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits); | 85 | return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits); |
86 | } | 86 | } |
87 | 87 | ||
88 | 88 | ||
diff --git a/drivers/spi/spi_sh_sci.c b/drivers/spi/spi_sh_sci.c index a511be7961a0..5c6439161199 100644 --- a/drivers/spi/spi_sh_sci.c +++ b/drivers/spi/spi_sh_sci.c | |||
@@ -83,25 +83,25 @@ static inline u32 getmiso(struct spi_device *dev) | |||
83 | static u32 sh_sci_spi_txrx_mode0(struct spi_device *spi, | 83 | static u32 sh_sci_spi_txrx_mode0(struct spi_device *spi, |
84 | unsigned nsecs, u32 word, u8 bits) | 84 | unsigned nsecs, u32 word, u8 bits) |
85 | { | 85 | { |
86 | return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits); | 86 | return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits); |
87 | } | 87 | } |
88 | 88 | ||
89 | static u32 sh_sci_spi_txrx_mode1(struct spi_device *spi, | 89 | static u32 sh_sci_spi_txrx_mode1(struct spi_device *spi, |
90 | unsigned nsecs, u32 word, u8 bits) | 90 | unsigned nsecs, u32 word, u8 bits) |
91 | { | 91 | { |
92 | return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits); | 92 | return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits); |
93 | } | 93 | } |
94 | 94 | ||
95 | static u32 sh_sci_spi_txrx_mode2(struct spi_device *spi, | 95 | static u32 sh_sci_spi_txrx_mode2(struct spi_device *spi, |
96 | unsigned nsecs, u32 word, u8 bits) | 96 | unsigned nsecs, u32 word, u8 bits) |
97 | { | 97 | { |
98 | return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits); | 98 | return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits); |
99 | } | 99 | } |
100 | 100 | ||
101 | static u32 sh_sci_spi_txrx_mode3(struct spi_device *spi, | 101 | static u32 sh_sci_spi_txrx_mode3(struct spi_device *spi, |
102 | unsigned nsecs, u32 word, u8 bits) | 102 | unsigned nsecs, u32 word, u8 bits) |
103 | { | 103 | { |
104 | return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits); | 104 | return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits); |
105 | } | 105 | } |
106 | 106 | ||
107 | static void sh_sci_spi_chipselect(struct spi_device *dev, int value) | 107 | static void sh_sci_spi_chipselect(struct spi_device *dev, int value) |