0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 static inline u32
0049 bitbang_txrx_be_cpha0(struct spi_device *spi,
0050 unsigned nsecs, unsigned cpol, unsigned flags,
0051 u32 word, u8 bits)
0052 {
0053
0054
0055 u32 oldbit = (!(word & (1<<(bits-1)))) << 31;
0056
0057 for (word <<= (32 - bits); likely(bits); bits--) {
0058
0059
0060 if ((flags & SPI_MASTER_NO_TX) == 0) {
0061 if ((word & (1 << 31)) != oldbit) {
0062 setmosi(spi, word & (1 << 31));
0063 oldbit = word & (1 << 31);
0064 }
0065 }
0066 spidelay(nsecs);
0067
0068 setsck(spi, !cpol);
0069 spidelay(nsecs);
0070
0071
0072 word <<= 1;
0073 if ((flags & SPI_MASTER_NO_RX) == 0)
0074 word |= getmiso(spi);
0075 setsck(spi, cpol);
0076 }
0077 return word;
0078 }
0079
0080 static inline u32
0081 bitbang_txrx_be_cpha1(struct spi_device *spi,
0082 unsigned nsecs, unsigned cpol, unsigned flags,
0083 u32 word, u8 bits)
0084 {
0085
0086
0087 u32 oldbit = (!(word & (1<<(bits-1)))) << 31;
0088
0089 for (word <<= (32 - bits); likely(bits); bits--) {
0090
0091
0092 setsck(spi, !cpol);
0093 if ((flags & SPI_MASTER_NO_TX) == 0) {
0094 if ((word & (1 << 31)) != oldbit) {
0095 setmosi(spi, word & (1 << 31));
0096 oldbit = word & (1 << 31);
0097 }
0098 }
0099 spidelay(nsecs);
0100
0101 setsck(spi, cpol);
0102 spidelay(nsecs);
0103
0104
0105 word <<= 1;
0106 if ((flags & SPI_MASTER_NO_RX) == 0)
0107 word |= getmiso(spi);
0108 }
0109 return word;
0110 }
0111
0112 static inline u32
0113 bitbang_txrx_le_cpha0(struct spi_device *spi,
0114 unsigned int nsecs, unsigned int cpol, unsigned int flags,
0115 u32 word, u8 bits)
0116 {
0117
0118
0119 u8 rxbit = bits - 1;
0120 u32 oldbit = !(word & 1);
0121
0122 for (; likely(bits); bits--) {
0123
0124
0125 if ((flags & SPI_MASTER_NO_TX) == 0) {
0126 if ((word & 1) != oldbit) {
0127 setmosi(spi, word & 1);
0128 oldbit = word & 1;
0129 }
0130 }
0131 spidelay(nsecs);
0132
0133 setsck(spi, !cpol);
0134 spidelay(nsecs);
0135
0136
0137 word >>= 1;
0138 if ((flags & SPI_MASTER_NO_RX) == 0)
0139 word |= getmiso(spi) << rxbit;
0140 setsck(spi, cpol);
0141 }
0142 return word;
0143 }
0144
0145 static inline u32
0146 bitbang_txrx_le_cpha1(struct spi_device *spi,
0147 unsigned int nsecs, unsigned int cpol, unsigned int flags,
0148 u32 word, u8 bits)
0149 {
0150
0151
0152 u8 rxbit = bits - 1;
0153 u32 oldbit = !(word & 1);
0154
0155 for (; likely(bits); bits--) {
0156
0157
0158 setsck(spi, !cpol);
0159 if ((flags & SPI_MASTER_NO_TX) == 0) {
0160 if ((word & 1) != oldbit) {
0161 setmosi(spi, word & 1);
0162 oldbit = word & 1;
0163 }
0164 }
0165 spidelay(nsecs);
0166
0167 setsck(spi, cpol);
0168 spidelay(nsecs);
0169
0170
0171 word >>= 1;
0172 if ((flags & SPI_MASTER_NO_RX) == 0)
0173 word |= getmiso(spi) << rxbit;
0174 }
0175 return word;
0176 }