summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/i2c-coldfire.c (renamed from firmware/drivers/i2c-h100.c)34
1 files changed, 17 insertions, 17 deletions
diff --git a/firmware/drivers/i2c-h100.c b/firmware/drivers/i2c-coldfire.c
index c50cd7ed0a..5b4f4a1830 100644
--- a/firmware/drivers/i2c-h100.c
+++ b/firmware/drivers/i2c-coldfire.c
@@ -21,7 +21,7 @@
21#include "kernel.h" 21#include "kernel.h"
22#include "debug.h" 22#include "debug.h"
23#include "system.h" 23#include "system.h"
24#include "i2c-h100.h" 24#include "i2c-coldfire.h"
25 25
26#define I2C_DEVICE_1 ((volatile unsigned char *)&MADR) 26#define I2C_DEVICE_1 ((volatile unsigned char *)&MADR)
27#define I2C_DEVICE_2 ((volatile unsigned char *)&MADR2) 27#define I2C_DEVICE_2 ((volatile unsigned char *)&MADR2)
@@ -37,6 +37,7 @@ static volatile unsigned char *i2c_get_addr(int device);
37 37
38void i2c_init(void) 38void i2c_init(void)
39{ 39{
40#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
40 /* Audio Codec */ 41 /* Audio Codec */
41 MADR = 0x6c; /* iRiver firmware uses this addr */ 42 MADR = 0x6c; /* iRiver firmware uses this addr */
42 MBDR = 0; /* iRiver firmware does this */ 43 MBDR = 0; /* iRiver firmware does this */
@@ -48,22 +49,21 @@ void i2c_init(void)
48 MBDR2 = 0; 49 MBDR2 = 0;
49 MBCR2 = IEN; 50 MBCR2 = IEN;
50#endif 51#endif
52
53#endif
51} 54}
52 55
53void i2c_close(void) 56void i2c_close(void)
54{ 57{
55 MBCR = 0; 58 MBCR = 0;
56
57#if 0
58 MBCR2 = 0; 59 MBCR2 = 0;
59#endif
60} 60}
61 61
62/** 62/**
63 * Writes bytes to the selected device. 63 * Writes bytes to the selected device.
64 * 64 *
65 * Use device=1 for bus 1 at 0x40000280 (Audio Codec) 65 * Use device=1 for bus 1 at 0x40000280
66 * Use device=2 for bus 2 at 0x80000440 (Tuner ?) 66 * Use device=2 for bus 2 at 0x80000440
67 * 67 *
68 * Returns number of bytes successfully send or -1 if START failed 68 * Returns number of bytes successfully send or -1 if START failed
69 */ 69 */
@@ -106,33 +106,33 @@ int i2c_write_byte(int device, unsigned char data)
106 /* Wait for bus busy */ 106 /* Wait for bus busy */
107 while (!(regs[O_MBSR] & IBB) && count < MAX_LOOP) 107 while (!(regs[O_MBSR] & IBB) && count < MAX_LOOP)
108 { 108 {
109 yield(); 109 yield();
110 count++; 110 count++;
111 } 111 }
112 112
113 if (count >= MAX_LOOP) 113 if (count >= MAX_LOOP)
114 return -1; 114 return -1;
115 115
116 count = 0; 116 count = 0;
117 117
118 /* Wait for interrupt flag */ 118 /* Wait for interrupt flag */
119 while (!(regs[O_MBSR] & IFF) && count < MAX_LOOP) 119 while (!(regs[O_MBSR] & IFF) && count < MAX_LOOP)
120 { 120 {
121 yield(); 121 yield();
122 count++; 122 count++;
123 } 123 }
124 124
125 if (count >= MAX_LOOP) 125 if (count >= MAX_LOOP)
126 return -2; 126 return -2;
127 127
128 regs[O_MBSR] &= ~IFF; /* Clear interrupt flag */ 128 regs[O_MBSR] &= ~IFF; /* Clear interrupt flag */
129 129
130 if (!(regs[O_MBSR] & ICF)) /* Check that transfer is complete */ 130 if (!(regs[O_MBSR] & ICF)) /* Check that transfer is complete */
131 return -3; 131 return -3;
132 132
133 if (regs[O_MBSR] & RXAK) /* Check that the byte has been ACKed */ 133 if (regs[O_MBSR] & RXAK) /* Check that the byte has been ACKed */
134 return -4; 134 return -4;
135 135
136 return 0; 136 return 0;
137} 137}
138 138
@@ -142,14 +142,14 @@ int i2c_gen_start(int device)
142{ 142{
143 volatile unsigned char *regs = i2c_get_addr(device); 143 volatile unsigned char *regs = i2c_get_addr(device);
144 long count = 0; 144 long count = 0;
145 145
146 /* Wait for bus to become free */ 146 /* Wait for bus to become free */
147 while ((regs[O_MBSR] & IBB) && (count < MAX_LOOP)) 147 while ((regs[O_MBSR] & IBB) && (count < MAX_LOOP))
148 { 148 {
149 yield(); 149 yield();
150 count++; 150 count++;
151 } 151 }
152 152
153 if (count >= MAX_LOOP) 153 if (count >= MAX_LOOP)
154 return -1; 154 return -1;
155 155
@@ -169,6 +169,6 @@ volatile unsigned char *i2c_get_addr(int device)
169{ 169{
170 if (device == 1) 170 if (device == 1)
171 return I2C_DEVICE_1; 171 return I2C_DEVICE_1;
172 172
173 return I2C_DEVICE_2; 173 return I2C_DEVICE_2;
174} 174}