Przeglądaj źródła

[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 lat temu
rodzic
commit
d1949f2737

+ 10
- 1
src/drivers/bitbash/i2c_bit.c Wyświetl plik

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

+ 6
- 0
src/drivers/bitbash/spi_bit.c Wyświetl plik

@@ -163,6 +163,9 @@ static int spi_bit_rw ( struct spi_bus *bus, struct spi_device *device,
163 163
 	uint32_t tmp_address;
164 164
 	uint32_t tmp_address_detect;
165 165
 
166
+	/* Open bit-bashing interface */
167
+	open_bit ( &spibit->basher );
168
+
166 169
 	/* Deassert chip select to reset specified slave */
167 170
 	spi_bit_set_slave_select ( spibit, device->slave, DESELECT_SLAVE );
168 171
 
@@ -214,6 +217,9 @@ static int spi_bit_rw ( struct spi_bus *bus, struct spi_device *device,
214 217
 	/* Deassert chip select on specified slave */
215 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 223
 	return 0;
218 224
 }
219 225
 

+ 32
- 0
src/include/ipxe/bitbash.h Wyświetl plik

@@ -13,6 +13,18 @@ struct bit_basher;
13 13
 
14 14
 /** Bit-bashing operations */
15 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 29
 	 * Set/clear output bit
18 30
 	 *
@@ -45,6 +57,26 @@ struct bit_basher {
45 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 80
 extern void write_bit ( struct bit_basher *basher, unsigned int bit_id,
49 81
 			unsigned long data );
50 82
 extern int read_bit ( struct bit_basher *basher, unsigned int bit_id );

Ładowanie…
Anuluj
Zapisz