Browse Source

Move per-transition delays from generic bit-bashing layer to i2c layer

(since SPI bit-bashing will require different delay semantics).
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
ab4f96e525
3 changed files with 15 additions and 10 deletions
  1. 0
    1
      src/drivers/bitbash/bitbash.c
  2. 15
    7
      src/drivers/bitbash/i2c_bit.c
  3. 0
    2
      src/include/gpxe/bitbash.h

+ 0
- 1
src/drivers/bitbash/bitbash.c View File

38
 void write_bit ( struct bit_basher *basher, unsigned int bit_id,
38
 void write_bit ( struct bit_basher *basher, unsigned int bit_id,
39
 		 unsigned long data ) {
39
 		 unsigned long data ) {
40
 	basher->write ( basher, bit_id, ( data ? -1UL : 0 ) );
40
 	basher->write ( basher, bit_id, ( data ? -1UL : 0 ) );
41
-	udelay ( basher->udelay );
42
 }
41
 }
43
 
42
 
44
 /**
43
 /**

+ 15
- 7
src/drivers/bitbash/i2c_bit.c View File

31
  * that provides two lines: SCL (clock) and SDA (data).
31
  * that provides two lines: SCL (clock) and SDA (data).
32
  */
32
  */
33
 
33
 
34
+/**
35
+ * Delay between output state changes
36
+ *
37
+ * Max rated i2c speed (for the basic i2c protocol) is 100kbps,
38
+ * i.e. 200k clock transitions per second.
39
+ */
40
+static void i2c_delay ( void ) {
41
+	udelay ( I2C_UDELAY );
42
+}
43
+
34
 /**
44
 /**
35
  * Set state of I2C SCL line
45
  * Set state of I2C SCL line
36
  *
46
  *
37
  * @v basher		Bit-bashing interface
47
  * @v basher		Bit-bashing interface
38
  * @v state		New state of SCL
48
  * @v state		New state of SCL
39
  */
49
  */
40
-static inline __attribute__ (( always_inline )) void
41
-setscl ( struct bit_basher *basher, int state ) {
50
+static void setscl ( struct bit_basher *basher, int state ) {
42
 	write_bit ( basher, I2C_BIT_SCL, state );
51
 	write_bit ( basher, I2C_BIT_SCL, state );
52
+	i2c_delay();
43
 }
53
 }
44
 
54
 
45
 /**
55
 /**
48
  * @v basher		Bit-bashing interface
58
  * @v basher		Bit-bashing interface
49
  * @v state		New state of SDA
59
  * @v state		New state of SDA
50
  */
60
  */
51
-static inline __attribute__ (( always_inline )) void
52
-setsda ( struct bit_basher *basher, int state ) {
61
+static void setsda ( struct bit_basher *basher, int state ) {
53
 	write_bit ( basher, I2C_BIT_SDA, state );
62
 	write_bit ( basher, I2C_BIT_SDA, state );
63
+	i2c_delay();
54
 }
64
 }
55
 
65
 
56
 /**
66
 /**
59
  * @v basher		Bit-bashing interface
69
  * @v basher		Bit-bashing interface
60
  * @ret state		State of SDA
70
  * @ret state		State of SDA
61
  */
71
  */
62
-static inline __attribute__ (( always_inline )) int
63
-getsda ( struct bit_basher *basher ) {
72
+static int getsda ( struct bit_basher *basher ) {
64
 	return read_bit ( basher, I2C_BIT_SDA );
73
 	return read_bit ( basher, I2C_BIT_SDA );
65
 }
74
 }
66
 
75
 
308
 	assert ( basher->write != NULL );
317
 	assert ( basher->write != NULL );
309
 	i2cbit->i2c.read = i2c_bit_read;
318
 	i2cbit->i2c.read = i2c_bit_read;
310
 	i2cbit->i2c.write = i2c_bit_write;
319
 	i2cbit->i2c.write = i2c_bit_write;
311
-	basher->udelay = I2C_UDELAY;
312
 	i2c_stop ( basher );
320
 	i2c_stop ( basher );
313
 }
321
 }

+ 0
- 2
src/include/gpxe/bitbash.h View File

33
 	 * @ret non-zero	Input is a logic 1
33
 	 * @ret non-zero	Input is a logic 1
34
 	 */
34
 	 */
35
 	int ( * read ) ( struct bit_basher *basher, unsigned int bit_id );
35
 	int ( * read ) ( struct bit_basher *basher, unsigned int bit_id );
36
-	/** Delay between subsequent calls to write(), in microseconds */
37
-	unsigned int udelay;
38
 };
36
 };
39
 
37
 
40
 extern void write_bit ( struct bit_basher *basher, unsigned int bit_id,
38
 extern void write_bit ( struct bit_basher *basher, unsigned int bit_id,

Loading…
Cancel
Save