|
@@ -60,8 +60,8 @@ static void spi_bit_set_slave_select ( struct spi_bit_basher *spibit,
|
60
|
60
|
struct bit_basher *basher = &spibit->basher;
|
61
|
61
|
|
62
|
62
|
state ^= ( spibit->bus.mode & SPI_MODE_SSPOL );
|
63
|
|
- DBG ( "Setting slave %d select %s\n", slave,
|
64
|
|
- ( state ? "high" : "low" ) );
|
|
63
|
+ DBGC2 ( spibit, "SPIBIT %p setting slave %d select %s\n",
|
|
64
|
+ spibit, slave, ( state ? "high" : "low" ) );
|
65
|
65
|
|
66
|
66
|
spi_bit_delay();
|
67
|
67
|
write_bit ( basher, SPI_BIT_SS ( slave ), state );
|
|
@@ -96,7 +96,8 @@ static void spi_bit_transfer ( struct spi_bit_basher *spibit,
|
96
|
96
|
unsigned int bit;
|
97
|
97
|
unsigned int step;
|
98
|
98
|
|
99
|
|
- DBG ( "Transferring %d bits in mode %x\n", len, bus->mode );
|
|
99
|
+ DBGC2 ( spibit, "SPIBIT %p transferring %d bits in mode %#x\n",
|
|
100
|
+ spibit, len, bus->mode );
|
100
|
101
|
|
101
|
102
|
for ( step = 0 ; step < ( len * 2 ) ; step++ ) {
|
102
|
103
|
/* Calculate byte offset and byte mask */
|
|
@@ -113,6 +114,8 @@ static void spi_bit_transfer ( struct spi_bit_basher *spibit,
|
113
|
114
|
if ( data_out ) {
|
114
|
115
|
byte = ( data_out + byte_offset );
|
115
|
116
|
bit = ( *byte & byte_mask );
|
|
117
|
+ DBGCP ( spibit, "SPIBIT %p wrote bit %d\n",
|
|
118
|
+ spibit, ( bit ? 1 : 0 ) );
|
116
|
119
|
} else {
|
117
|
120
|
bit = 0;
|
118
|
121
|
}
|
|
@@ -123,6 +126,8 @@ static void spi_bit_transfer ( struct spi_bit_basher *spibit,
|
123
|
126
|
/* Shift data in */
|
124
|
127
|
bit = read_bit ( basher, SPI_BIT_MISO );
|
125
|
128
|
if ( data_in ) {
|
|
129
|
+ DBGCP ( spibit, "SPIBIT %p read bit %d\n",
|
|
130
|
+ spibit, ( bit ? 1 : 0 ) );
|
126
|
131
|
byte = ( data_in + byte_offset );
|
127
|
132
|
*byte &= ~byte_mask;
|
128
|
133
|
*byte |= ( bit & byte_mask );
|
|
@@ -131,7 +136,7 @@ static void spi_bit_transfer ( struct spi_bit_basher *spibit,
|
131
|
136
|
|
132
|
137
|
/* Toggle clock line */
|
133
|
138
|
spi_bit_delay();
|
134
|
|
- sclk = ~sclk;
|
|
139
|
+ sclk ^= 1;
|
135
|
140
|
write_bit ( basher, SPI_BIT_SCLK, sclk );
|
136
|
141
|
}
|
137
|
142
|
}
|
|
@@ -153,7 +158,9 @@ static int spi_bit_rw ( struct spi_bus *bus, struct spi_device *device,
|
153
|
158
|
const void *data_out, void *data_in, size_t len ) {
|
154
|
159
|
struct spi_bit_basher *spibit
|
155
|
160
|
= container_of ( bus, struct spi_bit_basher, bus );
|
156
|
|
- uint32_t tmp;
|
|
161
|
+ uint32_t tmp_command;
|
|
162
|
+ uint32_t tmp_address;
|
|
163
|
+ uint32_t tmp_address_detect;
|
157
|
164
|
|
158
|
165
|
/* Set clock line to idle state */
|
159
|
166
|
write_bit ( &spibit->basher, SPI_BIT_SCLK,
|
|
@@ -163,17 +170,37 @@ static int spi_bit_rw ( struct spi_bus *bus, struct spi_device *device,
|
163
|
170
|
spi_bit_set_slave_select ( spibit, device->slave, SELECT_SLAVE );
|
164
|
171
|
|
165
|
172
|
/* Transmit command */
|
166
|
|
- assert ( device->command_len <= ( 8 * sizeof ( tmp ) ) );
|
167
|
|
- tmp = cpu_to_le32 ( command );
|
168
|
|
- spi_bit_transfer ( spibit, &tmp, NULL, device->command_len,
|
|
173
|
+ assert ( device->command_len <= ( 8 * sizeof ( tmp_command ) ) );
|
|
174
|
+ tmp_command = cpu_to_le32 ( command );
|
|
175
|
+ spi_bit_transfer ( spibit, &tmp_command, NULL, device->command_len,
|
169
|
176
|
SPI_BIT_BIG_ENDIAN );
|
170
|
177
|
|
171
|
178
|
/* Transmit address, if present */
|
172
|
179
|
if ( address >= 0 ) {
|
173
|
|
- assert ( device->address_len <= ( 8 * sizeof ( tmp ) ) );
|
174
|
|
- tmp = cpu_to_le32 ( address );
|
175
|
|
- spi_bit_transfer ( spibit, &tmp, NULL, device->address_len,
|
176
|
|
- SPI_BIT_BIG_ENDIAN );
|
|
180
|
+ assert ( device->address_len <= ( 8 * sizeof ( tmp_address )));
|
|
181
|
+ tmp_address = cpu_to_le32 ( address );
|
|
182
|
+ if ( device->address_len == SPI_AUTODETECT_ADDRESS_LEN ) {
|
|
183
|
+ /* Autodetect address length. This relies on
|
|
184
|
+ * the device responding with a dummy zero
|
|
185
|
+ * data bit before the first real data bit.
|
|
186
|
+ */
|
|
187
|
+ DBGC ( spibit, "SPIBIT %p autodetecting device "
|
|
188
|
+ "address length\n", spibit );
|
|
189
|
+ assert ( address == 0 );
|
|
190
|
+ device->address_len = 0;
|
|
191
|
+ do {
|
|
192
|
+ spi_bit_transfer ( spibit, &tmp_address,
|
|
193
|
+ &tmp_address_detect, 1,
|
|
194
|
+ SPI_BIT_BIG_ENDIAN );
|
|
195
|
+ device->address_len++;
|
|
196
|
+ } while ( le32_to_cpu ( tmp_address_detect ) & 1 );
|
|
197
|
+ DBGC ( spibit, "SPIBIT %p autodetected device address "
|
|
198
|
+ "length %d\n", spibit, device->address_len );
|
|
199
|
+ } else {
|
|
200
|
+ spi_bit_transfer ( spibit, &tmp_address, NULL,
|
|
201
|
+ device->address_len,
|
|
202
|
+ SPI_BIT_BIG_ENDIAN );
|
|
203
|
+ }
|
177
|
204
|
}
|
178
|
205
|
|
179
|
206
|
/* Transmit/receive data */
|