Browse Source

[bitbash] Add optional open() and close() methods for bit-bashing interfaces

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
d1949f2737
3 changed files with 48 additions and 1 deletions
  1. 10
    1
      src/drivers/bitbash/i2c_bit.c
  2. 6
    0
      src/drivers/bitbash/spi_bit.c
  3. 32
    0
      src/include/ipxe/bitbash.h

+ 10
- 1
src/drivers/bitbash/i2c_bit.c View File

239
 	 * pull SDA low while SCL is high (which creates a start
239
 	 * pull SDA low while SCL is high (which creates a start
240
 	 * condition).
240
 	 * condition).
241
 	 */
241
 	 */
242
+	open_bit ( basher );
242
 	setscl ( basher, 0 );
243
 	setscl ( basher, 0 );
243
 	setsda ( basher, 1 );
244
 	setsda ( basher, 1 );
244
 	for ( i = 0 ; i < I2C_RESET_MAX_CYCLES ; i++ ) {
245
 	for ( i = 0 ; i < I2C_RESET_MAX_CYCLES ; i++ ) {
251
 			i2c_stop ( basher );
252
 			i2c_stop ( basher );
252
 			DBGC ( basher, "I2CBIT %p reset after %d attempts\n",
253
 			DBGC ( basher, "I2CBIT %p reset after %d attempts\n",
253
 			       basher, ( i + 1 ) );
254
 			       basher, ( i + 1 ) );
255
+			close_bit ( basher );
254
 			return 0;
256
 			return 0;
255
 		}
257
 		}
256
 		setscl ( basher, 0 );
258
 		setscl ( basher, 0 );
258
 
260
 
259
 	DBGC ( basher, "I2CBIT %p could not reset after %d attempts\n",
261
 	DBGC ( basher, "I2CBIT %p could not reset after %d attempts\n",
260
 	       basher, i );
262
 	       basher, i );
263
+	close_bit ( basher );
261
 	return -ETIMEDOUT;
264
 	return -ETIMEDOUT;
262
 }
265
 }
263
 
266
 
285
 	DBGC ( basher, "I2CBIT %p reading from device %x: ",
288
 	DBGC ( basher, "I2CBIT %p reading from device %x: ",
286
 	       basher, i2cdev->dev_addr );
289
 	       basher, i2cdev->dev_addr );
287
 
290
 
291
+	open_bit ( basher );
292
+
288
 	for ( ; ; data++, offset++ ) {
293
 	for ( ; ; data++, offset++ ) {
289
 
294
 
290
 		/* Select device for writing */
295
 		/* Select device for writing */
312
 	
317
 	
313
 	DBGC ( basher, "%s\n", ( rc ? "failed" : "" ) );
318
 	DBGC ( basher, "%s\n", ( rc ? "failed" : "" ) );
314
 	i2c_stop ( basher );
319
 	i2c_stop ( basher );
320
+	close_bit ( basher );
315
 	return rc;
321
 	return rc;
316
 }
322
 }
317
 
323
 
339
 	DBGC ( basher, "I2CBIT %p writing to device %x: ",
345
 	DBGC ( basher, "I2CBIT %p writing to device %x: ",
340
 	       basher, i2cdev->dev_addr );
346
 	       basher, i2cdev->dev_addr );
341
 
347
 
348
+	open_bit ( basher );
349
+
342
 	for ( ; ; data++, offset++ ) {
350
 	for ( ; ; data++, offset++ ) {
343
 
351
 
344
 		/* Select device for writing */
352
 		/* Select device for writing */
359
 		if ( ( rc = i2c_send_byte ( basher, *data ) ) != 0 )
367
 		if ( ( rc = i2c_send_byte ( basher, *data ) ) != 0 )
360
 			break;
368
 			break;
361
 	}
369
 	}
362
-	
370
+
363
 	DBGC ( basher, "%s\n", ( rc ? "failed" : "" ) );
371
 	DBGC ( basher, "%s\n", ( rc ? "failed" : "" ) );
364
 	i2c_stop ( basher );
372
 	i2c_stop ( basher );
373
+	close_bit ( basher );
365
 	return rc;
374
 	return rc;
366
 }
375
 }
367
 
376
 

+ 6
- 0
src/drivers/bitbash/spi_bit.c View File

163
 	uint32_t tmp_address;
163
 	uint32_t tmp_address;
164
 	uint32_t tmp_address_detect;
164
 	uint32_t tmp_address_detect;
165
 
165
 
166
+	/* Open bit-bashing interface */
167
+	open_bit ( &spibit->basher );
168
+
166
 	/* Deassert chip select to reset specified slave */
169
 	/* Deassert chip select to reset specified slave */
167
 	spi_bit_set_slave_select ( spibit, device->slave, DESELECT_SLAVE );
170
 	spi_bit_set_slave_select ( spibit, device->slave, DESELECT_SLAVE );
168
 
171
 
214
 	/* Deassert chip select on specified slave */
217
 	/* Deassert chip select on specified slave */
215
 	spi_bit_set_slave_select ( spibit, device->slave, DESELECT_SLAVE );
218
 	spi_bit_set_slave_select ( spibit, device->slave, DESELECT_SLAVE );
216
 
219
 
220
+	/* Close bit-bashing interface */
221
+	close_bit ( &spibit->basher );
222
+
217
 	return 0;
223
 	return 0;
218
 }
224
 }
219
 
225
 

+ 32
- 0
src/include/ipxe/bitbash.h View File

13
 
13
 
14
 /** Bit-bashing operations */
14
 /** Bit-bashing operations */
15
 struct bit_basher_operations {
15
 struct bit_basher_operations {
16
+	/**
17
+	 * Open bit-bashing interface (optional)
18
+	 *
19
+	 * @v basher		Bit-bashing interface
20
+	 */
21
+	void ( * open ) ( struct bit_basher *basher );
22
+	/**
23
+	 * Close bit-bashing interface (optional)
24
+	 *
25
+	 * @v basher		Bit-bashing interface
26
+	 */
27
+	void ( * close ) ( struct bit_basher *basher );
16
 	/**
28
 	/**
17
 	 * Set/clear output bit
29
 	 * Set/clear output bit
18
 	 *
30
 	 *
45
 	struct bit_basher_operations *op;
57
 	struct bit_basher_operations *op;
46
 };
58
 };
47
 
59
 
60
+/**
61
+ * Open bit-bashing interface
62
+ *
63
+ * @v basher		Bit-bashing interface
64
+ */
65
+static inline void open_bit ( struct bit_basher *basher ) {
66
+	if ( basher->op->open )
67
+		basher->op->open ( basher );
68
+}
69
+
70
+/**
71
+ * Close bit-bashing interface
72
+ *
73
+ * @v basher		Bit-bashing interface
74
+ */
75
+static inline void close_bit ( struct bit_basher *basher ) {
76
+	if ( basher->op->close )
77
+		basher->op->close ( basher );
78
+}
79
+
48
 extern void write_bit ( struct bit_basher *basher, unsigned int bit_id,
80
 extern void write_bit ( struct bit_basher *basher, unsigned int bit_id,
49
 			unsigned long data );
81
 			unsigned long data );
50
 extern int read_bit ( struct bit_basher *basher, unsigned int bit_id );
82
 extern int read_bit ( struct bit_basher *basher, unsigned int bit_id );

Loading…
Cancel
Save