diff options
Diffstat (limited to 'drivers/w1/w1_io.c')
-rw-r--r-- | drivers/w1/w1_io.c | 70 |
1 files changed, 61 insertions, 9 deletions
diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c index 298ee8b72541..2173336b60a7 100644 --- a/drivers/w1/w1_io.c +++ b/drivers/w1/w1_io.c | |||
@@ -55,15 +55,29 @@ void w1_delay(unsigned long tm) | |||
55 | udelay(tm * w1_delay_parm); | 55 | udelay(tm * w1_delay_parm); |
56 | } | 56 | } |
57 | 57 | ||
58 | static void w1_write_bit(struct w1_master *dev, int bit); | ||
59 | static u8 w1_read_bit(struct w1_master *dev); | ||
60 | |||
61 | /** | ||
62 | * Generates a write-0 or write-1 cycle and samples the level. | ||
63 | */ | ||
58 | u8 w1_touch_bit(struct w1_master *dev, int bit) | 64 | u8 w1_touch_bit(struct w1_master *dev, int bit) |
59 | { | 65 | { |
60 | if (dev->bus_master->touch_bit) | 66 | if (dev->bus_master->touch_bit) |
61 | return dev->bus_master->touch_bit(dev->bus_master->data, bit); | 67 | return dev->bus_master->touch_bit(dev->bus_master->data, bit); |
62 | else | 68 | else if (bit) |
63 | return w1_read_bit(dev); | 69 | return w1_read_bit(dev); |
70 | else { | ||
71 | w1_write_bit(dev, 0); | ||
72 | return(0); | ||
73 | } | ||
64 | } | 74 | } |
65 | 75 | ||
66 | void w1_write_bit(struct w1_master *dev, int bit) | 76 | /** |
77 | * Generates a write-0 or write-1 cycle. | ||
78 | * Only call if dev->bus_master->touch_bit is NULL | ||
79 | */ | ||
80 | static void w1_write_bit(struct w1_master *dev, int bit) | ||
67 | { | 81 | { |
68 | if (bit) { | 82 | if (bit) { |
69 | dev->bus_master->write_bit(dev->bus_master->data, 0); | 83 | dev->bus_master->write_bit(dev->bus_master->data, 0); |
@@ -78,6 +92,12 @@ void w1_write_bit(struct w1_master *dev, int bit) | |||
78 | } | 92 | } |
79 | } | 93 | } |
80 | 94 | ||
95 | /** | ||
96 | * Writes 8 bits. | ||
97 | * | ||
98 | * @param dev the master device | ||
99 | * @param byte the byte to write | ||
100 | */ | ||
81 | void w1_write_8(struct w1_master *dev, u8 byte) | 101 | void w1_write_8(struct w1_master *dev, u8 byte) |
82 | { | 102 | { |
83 | int i; | 103 | int i; |
@@ -86,10 +106,15 @@ void w1_write_8(struct w1_master *dev, u8 byte) | |||
86 | dev->bus_master->write_byte(dev->bus_master->data, byte); | 106 | dev->bus_master->write_byte(dev->bus_master->data, byte); |
87 | else | 107 | else |
88 | for (i = 0; i < 8; ++i) | 108 | for (i = 0; i < 8; ++i) |
89 | w1_write_bit(dev, (byte >> i) & 0x1); | 109 | w1_touch_bit(dev, (byte >> i) & 0x1); |
90 | } | 110 | } |
91 | 111 | ||
92 | u8 w1_read_bit(struct w1_master *dev) | 112 | |
113 | /** | ||
114 | * Generates a write-1 cycle and samples the level. | ||
115 | * Only call if dev->bus_master->touch_bit is NULL | ||
116 | */ | ||
117 | static u8 w1_read_bit(struct w1_master *dev) | ||
93 | { | 118 | { |
94 | int result; | 119 | int result; |
95 | 120 | ||
@@ -104,6 +129,12 @@ u8 w1_read_bit(struct w1_master *dev) | |||
104 | return result & 0x1; | 129 | return result & 0x1; |
105 | } | 130 | } |
106 | 131 | ||
132 | /** | ||
133 | * Reads 8 bits. | ||
134 | * | ||
135 | * @param dev the master device | ||
136 | * @return the byte read | ||
137 | */ | ||
107 | u8 w1_read_8(struct w1_master * dev) | 138 | u8 w1_read_8(struct w1_master * dev) |
108 | { | 139 | { |
109 | int i; | 140 | int i; |
@@ -113,12 +144,20 @@ u8 w1_read_8(struct w1_master * dev) | |||
113 | res = dev->bus_master->read_byte(dev->bus_master->data); | 144 | res = dev->bus_master->read_byte(dev->bus_master->data); |
114 | else | 145 | else |
115 | for (i = 0; i < 8; ++i) | 146 | for (i = 0; i < 8; ++i) |
116 | res |= (w1_read_bit(dev) << i); | 147 | res |= (w1_touch_bit(dev,1) << i); |
117 | 148 | ||
118 | return res; | 149 | return res; |
119 | } | 150 | } |
120 | 151 | ||
121 | void w1_write_block(struct w1_master *dev, u8 *buf, int len) | 152 | /** |
153 | * Writes a series of bytes. | ||
154 | * | ||
155 | * @param dev the master device | ||
156 | * @param buf pointer to the data to write | ||
157 | * @param len the number of bytes to write | ||
158 | * @return the byte read | ||
159 | */ | ||
160 | void w1_write_block(struct w1_master *dev, const u8 *buf, int len) | ||
122 | { | 161 | { |
123 | int i; | 162 | int i; |
124 | 163 | ||
@@ -129,6 +168,14 @@ void w1_write_block(struct w1_master *dev, u8 *buf, int len) | |||
129 | w1_write_8(dev, buf[i]); | 168 | w1_write_8(dev, buf[i]); |
130 | } | 169 | } |
131 | 170 | ||
171 | /** | ||
172 | * Reads a series of bytes. | ||
173 | * | ||
174 | * @param dev the master device | ||
175 | * @param buf pointer to the buffer to fill | ||
176 | * @param len the number of bytes to read | ||
177 | * @return the number of bytes read | ||
178 | */ | ||
132 | u8 w1_read_block(struct w1_master *dev, u8 *buf, int len) | 179 | u8 w1_read_block(struct w1_master *dev, u8 *buf, int len) |
133 | { | 180 | { |
134 | int i; | 181 | int i; |
@@ -145,9 +192,15 @@ u8 w1_read_block(struct w1_master *dev, u8 *buf, int len) | |||
145 | return ret; | 192 | return ret; |
146 | } | 193 | } |
147 | 194 | ||
195 | /** | ||
196 | * Issues a reset bus sequence. | ||
197 | * | ||
198 | * @param dev The bus master pointer | ||
199 | * @return 0=Device present, 1=No device present or error | ||
200 | */ | ||
148 | int w1_reset_bus(struct w1_master *dev) | 201 | int w1_reset_bus(struct w1_master *dev) |
149 | { | 202 | { |
150 | int result = 0; | 203 | int result; |
151 | 204 | ||
152 | if (dev->bus_master->reset_bus) | 205 | if (dev->bus_master->reset_bus) |
153 | result = dev->bus_master->reset_bus(dev->bus_master->data) & 0x1; | 206 | result = dev->bus_master->reset_bus(dev->bus_master->data) & 0x1; |
@@ -183,9 +236,8 @@ void w1_search_devices(struct w1_master *dev, w1_slave_found_callback cb) | |||
183 | w1_search(dev); | 236 | w1_search(dev); |
184 | } | 237 | } |
185 | 238 | ||
186 | EXPORT_SYMBOL(w1_write_bit); | 239 | EXPORT_SYMBOL(w1_touch_bit); |
187 | EXPORT_SYMBOL(w1_write_8); | 240 | EXPORT_SYMBOL(w1_write_8); |
188 | EXPORT_SYMBOL(w1_read_bit); | ||
189 | EXPORT_SYMBOL(w1_read_8); | 241 | EXPORT_SYMBOL(w1_read_8); |
190 | EXPORT_SYMBOL(w1_reset_bus); | 242 | EXPORT_SYMBOL(w1_reset_bus); |
191 | EXPORT_SYMBOL(w1_calc_crc8); | 243 | EXPORT_SYMBOL(w1_calc_crc8); |