aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/w1/w1_io.c
diff options
context:
space:
mode:
authorEvgeniy Polyakov <johnpol@2ka.mipt.ru>2005-06-03 17:21:46 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2005-06-22 00:43:10 -0400
commitbe57ce267fd558c52d2389530c15618681b7cfa7 (patch)
tree74b9d71873a9bd3152c955114b846c251f7216a9 /drivers/w1/w1_io.c
parent4e470aa9642d49230bcdfbb393cf5a81da333aba (diff)
[PATCH] w1: Cleans up usage of touch_bit/w1_read_bit/w1_write_bit.
Cleans up usage of touch_bit/w1_read_bit/w1_write_bit. Signed-off-by: Ben Gardner <bgardner@wabtec.com> Signed-off-by: Evgeniy Polyakov <johnpol@2ka.mipt.ru> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/w1/w1_io.c')
-rw-r--r--drivers/w1/w1_io.c70
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
58static void w1_write_bit(struct w1_master *dev, int bit);
59static u8 w1_read_bit(struct w1_master *dev);
60
61/**
62 * Generates a write-0 or write-1 cycle and samples the level.
63 */
58u8 w1_touch_bit(struct w1_master *dev, int bit) 64u8 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
66void 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 */
80static 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 */
81void w1_write_8(struct w1_master *dev, u8 byte) 101void 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
92u8 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 */
117static 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 */
107u8 w1_read_8(struct w1_master * dev) 138u8 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
121void 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 */
160void 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 */
132u8 w1_read_block(struct w1_master *dev, u8 *buf, int len) 179u8 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 */
148int w1_reset_bus(struct w1_master *dev) 201int 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
186EXPORT_SYMBOL(w1_write_bit); 239EXPORT_SYMBOL(w1_touch_bit);
187EXPORT_SYMBOL(w1_write_8); 240EXPORT_SYMBOL(w1_write_8);
188EXPORT_SYMBOL(w1_read_bit);
189EXPORT_SYMBOL(w1_read_8); 241EXPORT_SYMBOL(w1_read_8);
190EXPORT_SYMBOL(w1_reset_bus); 242EXPORT_SYMBOL(w1_reset_bus);
191EXPORT_SYMBOL(w1_calc_crc8); 243EXPORT_SYMBOL(w1_calc_crc8);