diff options
author | Evgeniy Polyakov <johnpol@2ka.mipt.ru> | 2005-12-06 05:38:28 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-03-23 20:28:11 -0500 |
commit | bd529cfb40c427d5b5aae0d315afb9f0a1da5e76 (patch) | |
tree | 54de1d9860defa3c4938fd96246caffe089b9f3a /drivers/w1/masters | |
parent | ccd6994000fb6d08ee1be8a7fa20c8d602a2267d (diff) |
[PATCH] W1: Move w1 bus master code into 'w1/masters' and move w1 slave code into 'w1/slaves'
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/masters')
-rw-r--r-- | drivers/w1/masters/Kconfig | 38 | ||||
-rw-r--r-- | drivers/w1/masters/Makefile | 11 | ||||
-rw-r--r-- | drivers/w1/masters/ds_w1_bridge.c | 174 | ||||
-rw-r--r-- | drivers/w1/masters/dscore.c | 795 | ||||
-rw-r--r-- | drivers/w1/masters/dscore.h | 166 | ||||
-rw-r--r-- | drivers/w1/masters/matrox_w1.c | 247 |
6 files changed, 1431 insertions, 0 deletions
diff --git a/drivers/w1/masters/Kconfig b/drivers/w1/masters/Kconfig new file mode 100644 index 00000000000..51bd64d0e54 --- /dev/null +++ b/drivers/w1/masters/Kconfig | |||
@@ -0,0 +1,38 @@ | |||
1 | # | ||
2 | # 1-wire bus master configuration | ||
3 | # | ||
4 | |||
5 | menu "1-wire Bus Masters" | ||
6 | depends on W1 | ||
7 | |||
8 | config W1_MASTER_MATROX | ||
9 | tristate "Matrox G400 transport layer for 1-wire" | ||
10 | depends on W1 && PCI | ||
11 | help | ||
12 | Say Y here if you want to communicate with your 1-wire devices | ||
13 | using Matrox's G400 GPIO pins. | ||
14 | |||
15 | This support is also available as a module. If so, the module | ||
16 | will be called matrox_w1.ko. | ||
17 | |||
18 | config W1_MASTER_DS9490 | ||
19 | tristate "DS9490R transport layer driver" | ||
20 | depends on W1 && USB | ||
21 | help | ||
22 | Say Y here if you want to have a driver for DS9490R UWB <-> W1 bridge. | ||
23 | |||
24 | This support is also available as a module. If so, the module | ||
25 | will be called ds9490r.ko. | ||
26 | |||
27 | config W1_MASTER_DS9490_BRIDGE | ||
28 | tristate "DS9490R USB <-> W1 transport layer for 1-wire" | ||
29 | depends on W1_DS9490 | ||
30 | help | ||
31 | Say Y here if you want to communicate with your 1-wire devices | ||
32 | using DS9490R USB bridge. | ||
33 | |||
34 | This support is also available as a module. If so, the module | ||
35 | will be called ds_w1_bridge.ko. | ||
36 | |||
37 | endmenu | ||
38 | |||
diff --git a/drivers/w1/masters/Makefile b/drivers/w1/masters/Makefile new file mode 100644 index 00000000000..d9b84e522d6 --- /dev/null +++ b/drivers/w1/masters/Makefile | |||
@@ -0,0 +1,11 @@ | |||
1 | # | ||
2 | # Makefile for 1-wire bus master drivers. | ||
3 | # | ||
4 | |||
5 | obj-$(CONFIG_W1_MASTER_MATROX) += matrox_w1.o | ||
6 | |||
7 | obj-$(CONFIG_W1_MASTER_DS9490) += ds9490r.o | ||
8 | ds9490r-objs := dscore.o | ||
9 | |||
10 | obj-$(CONFIG_W1_MASTER_DS9490_BRIDGE) += ds_w1_bridge.o | ||
11 | |||
diff --git a/drivers/w1/masters/ds_w1_bridge.c b/drivers/w1/masters/ds_w1_bridge.c new file mode 100644 index 00000000000..5d30783a3eb --- /dev/null +++ b/drivers/w1/masters/ds_w1_bridge.c | |||
@@ -0,0 +1,174 @@ | |||
1 | /* | ||
2 | * ds_w1_bridge.c | ||
3 | * | ||
4 | * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> | ||
5 | * | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/types.h> | ||
24 | |||
25 | #include "../w1.h" | ||
26 | #include "../w1_int.h" | ||
27 | #include "dscore.h" | ||
28 | |||
29 | static struct ds_device *ds_dev; | ||
30 | static struct w1_bus_master *ds_bus_master; | ||
31 | |||
32 | static u8 ds9490r_touch_bit(void *data, u8 bit) | ||
33 | { | ||
34 | u8 ret; | ||
35 | struct ds_device *dev = data; | ||
36 | |||
37 | if (ds_touch_bit(dev, bit, &ret)) | ||
38 | return 0; | ||
39 | |||
40 | return ret; | ||
41 | } | ||
42 | |||
43 | static void ds9490r_write_bit(void *data, u8 bit) | ||
44 | { | ||
45 | struct ds_device *dev = data; | ||
46 | |||
47 | ds_write_bit(dev, bit); | ||
48 | } | ||
49 | |||
50 | static void ds9490r_write_byte(void *data, u8 byte) | ||
51 | { | ||
52 | struct ds_device *dev = data; | ||
53 | |||
54 | ds_write_byte(dev, byte); | ||
55 | } | ||
56 | |||
57 | static u8 ds9490r_read_bit(void *data) | ||
58 | { | ||
59 | struct ds_device *dev = data; | ||
60 | int err; | ||
61 | u8 bit = 0; | ||
62 | |||
63 | err = ds_touch_bit(dev, 1, &bit); | ||
64 | if (err) | ||
65 | return 0; | ||
66 | //err = ds_read_bit(dev, &bit); | ||
67 | //if (err) | ||
68 | // return 0; | ||
69 | |||
70 | return bit & 1; | ||
71 | } | ||
72 | |||
73 | static u8 ds9490r_read_byte(void *data) | ||
74 | { | ||
75 | struct ds_device *dev = data; | ||
76 | int err; | ||
77 | u8 byte = 0; | ||
78 | |||
79 | err = ds_read_byte(dev, &byte); | ||
80 | if (err) | ||
81 | return 0; | ||
82 | |||
83 | return byte; | ||
84 | } | ||
85 | |||
86 | static void ds9490r_write_block(void *data, const u8 *buf, int len) | ||
87 | { | ||
88 | struct ds_device *dev = data; | ||
89 | |||
90 | ds_write_block(dev, (u8 *)buf, len); | ||
91 | } | ||
92 | |||
93 | static u8 ds9490r_read_block(void *data, u8 *buf, int len) | ||
94 | { | ||
95 | struct ds_device *dev = data; | ||
96 | int err; | ||
97 | |||
98 | err = ds_read_block(dev, buf, len); | ||
99 | if (err < 0) | ||
100 | return 0; | ||
101 | |||
102 | return len; | ||
103 | } | ||
104 | |||
105 | static u8 ds9490r_reset(void *data) | ||
106 | { | ||
107 | struct ds_device *dev = data; | ||
108 | struct ds_status st; | ||
109 | int err; | ||
110 | |||
111 | memset(&st, 0, sizeof(st)); | ||
112 | |||
113 | err = ds_reset(dev, &st); | ||
114 | if (err) | ||
115 | return 1; | ||
116 | |||
117 | return 0; | ||
118 | } | ||
119 | |||
120 | static int __devinit ds_w1_init(void) | ||
121 | { | ||
122 | int err; | ||
123 | |||
124 | ds_bus_master = kmalloc(sizeof(*ds_bus_master), GFP_KERNEL); | ||
125 | if (!ds_bus_master) { | ||
126 | printk(KERN_ERR "Failed to allocate DS9490R USB<->W1 bus_master structure.\n"); | ||
127 | return -ENOMEM; | ||
128 | } | ||
129 | |||
130 | ds_dev = ds_get_device(); | ||
131 | if (!ds_dev) { | ||
132 | printk(KERN_ERR "DS9490R is not registered.\n"); | ||
133 | err = -ENODEV; | ||
134 | goto err_out_free_bus_master; | ||
135 | } | ||
136 | |||
137 | memset(ds_bus_master, 0, sizeof(*ds_bus_master)); | ||
138 | |||
139 | ds_bus_master->data = ds_dev; | ||
140 | ds_bus_master->touch_bit = &ds9490r_touch_bit; | ||
141 | ds_bus_master->read_bit = &ds9490r_read_bit; | ||
142 | ds_bus_master->write_bit = &ds9490r_write_bit; | ||
143 | ds_bus_master->read_byte = &ds9490r_read_byte; | ||
144 | ds_bus_master->write_byte = &ds9490r_write_byte; | ||
145 | ds_bus_master->read_block = &ds9490r_read_block; | ||
146 | ds_bus_master->write_block = &ds9490r_write_block; | ||
147 | ds_bus_master->reset_bus = &ds9490r_reset; | ||
148 | |||
149 | err = w1_add_master_device(ds_bus_master); | ||
150 | if (err) | ||
151 | goto err_out_put_device; | ||
152 | |||
153 | return 0; | ||
154 | |||
155 | err_out_put_device: | ||
156 | ds_put_device(ds_dev); | ||
157 | err_out_free_bus_master: | ||
158 | kfree(ds_bus_master); | ||
159 | |||
160 | return err; | ||
161 | } | ||
162 | |||
163 | static void __devexit ds_w1_fini(void) | ||
164 | { | ||
165 | w1_remove_master_device(ds_bus_master); | ||
166 | ds_put_device(ds_dev); | ||
167 | kfree(ds_bus_master); | ||
168 | } | ||
169 | |||
170 | module_init(ds_w1_init); | ||
171 | module_exit(ds_w1_fini); | ||
172 | |||
173 | MODULE_LICENSE("GPL"); | ||
174 | MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>"); | ||
diff --git a/drivers/w1/masters/dscore.c b/drivers/w1/masters/dscore.c new file mode 100644 index 00000000000..2cf7776a708 --- /dev/null +++ b/drivers/w1/masters/dscore.c | |||
@@ -0,0 +1,795 @@ | |||
1 | /* | ||
2 | * dscore.c | ||
3 | * | ||
4 | * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> | ||
5 | * | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/kernel.h> | ||
24 | #include <linux/mod_devicetable.h> | ||
25 | #include <linux/usb.h> | ||
26 | |||
27 | #include "dscore.h" | ||
28 | |||
29 | static struct usb_device_id ds_id_table [] = { | ||
30 | { USB_DEVICE(0x04fa, 0x2490) }, | ||
31 | { }, | ||
32 | }; | ||
33 | MODULE_DEVICE_TABLE(usb, ds_id_table); | ||
34 | |||
35 | static int ds_probe(struct usb_interface *, const struct usb_device_id *); | ||
36 | static void ds_disconnect(struct usb_interface *); | ||
37 | |||
38 | int ds_touch_bit(struct ds_device *, u8, u8 *); | ||
39 | int ds_read_byte(struct ds_device *, u8 *); | ||
40 | int ds_read_bit(struct ds_device *, u8 *); | ||
41 | int ds_write_byte(struct ds_device *, u8); | ||
42 | int ds_write_bit(struct ds_device *, u8); | ||
43 | static int ds_start_pulse(struct ds_device *, int); | ||
44 | int ds_reset(struct ds_device *, struct ds_status *); | ||
45 | struct ds_device * ds_get_device(void); | ||
46 | void ds_put_device(struct ds_device *); | ||
47 | |||
48 | static inline void ds_dump_status(unsigned char *, unsigned char *, int); | ||
49 | static int ds_send_control(struct ds_device *, u16, u16); | ||
50 | static int ds_send_control_mode(struct ds_device *, u16, u16); | ||
51 | static int ds_send_control_cmd(struct ds_device *, u16, u16); | ||
52 | |||
53 | |||
54 | static struct usb_driver ds_driver = { | ||
55 | .name = "DS9490R", | ||
56 | .probe = ds_probe, | ||
57 | .disconnect = ds_disconnect, | ||
58 | .id_table = ds_id_table, | ||
59 | }; | ||
60 | |||
61 | static struct ds_device *ds_dev; | ||
62 | |||
63 | struct ds_device * ds_get_device(void) | ||
64 | { | ||
65 | if (ds_dev) | ||
66 | atomic_inc(&ds_dev->refcnt); | ||
67 | return ds_dev; | ||
68 | } | ||
69 | |||
70 | void ds_put_device(struct ds_device *dev) | ||
71 | { | ||
72 | atomic_dec(&dev->refcnt); | ||
73 | } | ||
74 | |||
75 | static int ds_send_control_cmd(struct ds_device *dev, u16 value, u16 index) | ||
76 | { | ||
77 | int err; | ||
78 | |||
79 | err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]), | ||
80 | CONTROL_CMD, 0x40, value, index, NULL, 0, 1000); | ||
81 | if (err < 0) { | ||
82 | printk(KERN_ERR "Failed to send command control message %x.%x: err=%d.\n", | ||
83 | value, index, err); | ||
84 | return err; | ||
85 | } | ||
86 | |||
87 | return err; | ||
88 | } | ||
89 | |||
90 | static int ds_send_control_mode(struct ds_device *dev, u16 value, u16 index) | ||
91 | { | ||
92 | int err; | ||
93 | |||
94 | err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]), | ||
95 | MODE_CMD, 0x40, value, index, NULL, 0, 1000); | ||
96 | if (err < 0) { | ||
97 | printk(KERN_ERR "Failed to send mode control message %x.%x: err=%d.\n", | ||
98 | value, index, err); | ||
99 | return err; | ||
100 | } | ||
101 | |||
102 | return err; | ||
103 | } | ||
104 | |||
105 | static int ds_send_control(struct ds_device *dev, u16 value, u16 index) | ||
106 | { | ||
107 | int err; | ||
108 | |||
109 | err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]), | ||
110 | COMM_CMD, 0x40, value, index, NULL, 0, 1000); | ||
111 | if (err < 0) { | ||
112 | printk(KERN_ERR "Failed to send control message %x.%x: err=%d.\n", | ||
113 | value, index, err); | ||
114 | return err; | ||
115 | } | ||
116 | |||
117 | return err; | ||
118 | } | ||
119 | |||
120 | static inline void ds_dump_status(unsigned char *buf, unsigned char *str, int off) | ||
121 | { | ||
122 | printk("%45s: %8x\n", str, buf[off]); | ||
123 | } | ||
124 | |||
125 | static int ds_recv_status_nodump(struct ds_device *dev, struct ds_status *st, | ||
126 | unsigned char *buf, int size) | ||
127 | { | ||
128 | int count, err; | ||
129 | |||
130 | memset(st, 0, sizeof(st)); | ||
131 | |||
132 | count = 0; | ||
133 | err = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_STATUS]), buf, size, &count, 100); | ||
134 | if (err < 0) { | ||
135 | printk(KERN_ERR "Failed to read 1-wire data from 0x%x: err=%d.\n", dev->ep[EP_STATUS], err); | ||
136 | return err; | ||
137 | } | ||
138 | |||
139 | if (count >= sizeof(*st)) | ||
140 | memcpy(st, buf, sizeof(*st)); | ||
141 | |||
142 | return count; | ||
143 | } | ||
144 | |||
145 | static int ds_recv_status(struct ds_device *dev, struct ds_status *st) | ||
146 | { | ||
147 | unsigned char buf[64]; | ||
148 | int count, err = 0, i; | ||
149 | |||
150 | memcpy(st, buf, sizeof(*st)); | ||
151 | |||
152 | count = ds_recv_status_nodump(dev, st, buf, sizeof(buf)); | ||
153 | if (count < 0) | ||
154 | return err; | ||
155 | |||
156 | printk("0x%x: count=%d, status: ", dev->ep[EP_STATUS], count); | ||
157 | for (i=0; i<count; ++i) | ||
158 | printk("%02x ", buf[i]); | ||
159 | printk("\n"); | ||
160 | |||
161 | if (count >= 16) { | ||
162 | ds_dump_status(buf, "enable flag", 0); | ||
163 | ds_dump_status(buf, "1-wire speed", 1); | ||
164 | ds_dump_status(buf, "strong pullup duration", 2); | ||
165 | ds_dump_status(buf, "programming pulse duration", 3); | ||
166 | ds_dump_status(buf, "pulldown slew rate control", 4); | ||
167 | ds_dump_status(buf, "write-1 low time", 5); | ||
168 | ds_dump_status(buf, "data sample offset/write-0 recovery time", 6); | ||
169 | ds_dump_status(buf, "reserved (test register)", 7); | ||
170 | ds_dump_status(buf, "device status flags", 8); | ||
171 | ds_dump_status(buf, "communication command byte 1", 9); | ||
172 | ds_dump_status(buf, "communication command byte 2", 10); | ||
173 | ds_dump_status(buf, "communication command buffer status", 11); | ||
174 | ds_dump_status(buf, "1-wire data output buffer status", 12); | ||
175 | ds_dump_status(buf, "1-wire data input buffer status", 13); | ||
176 | ds_dump_status(buf, "reserved", 14); | ||
177 | ds_dump_status(buf, "reserved", 15); | ||
178 | } | ||
179 | |||
180 | memcpy(st, buf, sizeof(*st)); | ||
181 | |||
182 | if (st->status & ST_EPOF) { | ||
183 | printk(KERN_INFO "Resetting device after ST_EPOF.\n"); | ||
184 | err = ds_send_control_cmd(dev, CTL_RESET_DEVICE, 0); | ||
185 | if (err) | ||
186 | return err; | ||
187 | count = ds_recv_status_nodump(dev, st, buf, sizeof(buf)); | ||
188 | if (count < 0) | ||
189 | return err; | ||
190 | } | ||
191 | #if 0 | ||
192 | if (st->status & ST_IDLE) { | ||
193 | printk(KERN_INFO "Resetting pulse after ST_IDLE.\n"); | ||
194 | err = ds_start_pulse(dev, PULLUP_PULSE_DURATION); | ||
195 | if (err) | ||
196 | return err; | ||
197 | } | ||
198 | #endif | ||
199 | |||
200 | return err; | ||
201 | } | ||
202 | |||
203 | static int ds_recv_data(struct ds_device *dev, unsigned char *buf, int size) | ||
204 | { | ||
205 | int count, err; | ||
206 | struct ds_status st; | ||
207 | |||
208 | count = 0; | ||
209 | err = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN]), | ||
210 | buf, size, &count, 1000); | ||
211 | if (err < 0) { | ||
212 | printk(KERN_INFO "Clearing ep0x%x.\n", dev->ep[EP_DATA_IN]); | ||
213 | usb_clear_halt(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN])); | ||
214 | ds_recv_status(dev, &st); | ||
215 | return err; | ||
216 | } | ||
217 | |||
218 | #if 0 | ||
219 | { | ||
220 | int i; | ||
221 | |||
222 | printk("%s: count=%d: ", __func__, count); | ||
223 | for (i=0; i<count; ++i) | ||
224 | printk("%02x ", buf[i]); | ||
225 | printk("\n"); | ||
226 | } | ||
227 | #endif | ||
228 | return count; | ||
229 | } | ||
230 | |||
231 | static int ds_send_data(struct ds_device *dev, unsigned char *buf, int len) | ||
232 | { | ||
233 | int count, err; | ||
234 | |||
235 | count = 0; | ||
236 | err = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, dev->ep[EP_DATA_OUT]), buf, len, &count, 1000); | ||
237 | if (err < 0) { | ||
238 | printk(KERN_ERR "Failed to read 1-wire data from 0x02: err=%d.\n", err); | ||
239 | return err; | ||
240 | } | ||
241 | |||
242 | return err; | ||
243 | } | ||
244 | |||
245 | #if 0 | ||
246 | |||
247 | int ds_stop_pulse(struct ds_device *dev, int limit) | ||
248 | { | ||
249 | struct ds_status st; | ||
250 | int count = 0, err = 0; | ||
251 | u8 buf[0x20]; | ||
252 | |||
253 | do { | ||
254 | err = ds_send_control(dev, CTL_HALT_EXE_IDLE, 0); | ||
255 | if (err) | ||
256 | break; | ||
257 | err = ds_send_control(dev, CTL_RESUME_EXE, 0); | ||
258 | if (err) | ||
259 | break; | ||
260 | err = ds_recv_status_nodump(dev, &st, buf, sizeof(buf)); | ||
261 | if (err) | ||
262 | break; | ||
263 | |||
264 | if ((st.status & ST_SPUA) == 0) { | ||
265 | err = ds_send_control_mode(dev, MOD_PULSE_EN, 0); | ||
266 | if (err) | ||
267 | break; | ||
268 | } | ||
269 | } while(++count < limit); | ||
270 | |||
271 | return err; | ||
272 | } | ||
273 | |||
274 | int ds_detect(struct ds_device *dev, struct ds_status *st) | ||
275 | { | ||
276 | int err; | ||
277 | |||
278 | err = ds_send_control_cmd(dev, CTL_RESET_DEVICE, 0); | ||
279 | if (err) | ||
280 | return err; | ||
281 | |||
282 | err = ds_send_control(dev, COMM_SET_DURATION | COMM_IM, 0); | ||
283 | if (err) | ||
284 | return err; | ||
285 | |||
286 | err = ds_send_control(dev, COMM_SET_DURATION | COMM_IM | COMM_TYPE, 0x40); | ||
287 | if (err) | ||
288 | return err; | ||
289 | |||
290 | err = ds_send_control_mode(dev, MOD_PULSE_EN, PULSE_PROG); | ||
291 | if (err) | ||
292 | return err; | ||
293 | |||
294 | err = ds_recv_status(dev, st); | ||
295 | |||
296 | return err; | ||
297 | } | ||
298 | |||
299 | #endif /* 0 */ | ||
300 | |||
301 | static int ds_wait_status(struct ds_device *dev, struct ds_status *st) | ||
302 | { | ||
303 | u8 buf[0x20]; | ||
304 | int err, count = 0; | ||
305 | |||
306 | do { | ||
307 | err = ds_recv_status_nodump(dev, st, buf, sizeof(buf)); | ||
308 | #if 0 | ||
309 | if (err >= 0) { | ||
310 | int i; | ||
311 | printk("0x%x: count=%d, status: ", dev->ep[EP_STATUS], err); | ||
312 | for (i=0; i<err; ++i) | ||
313 | printk("%02x ", buf[i]); | ||
314 | printk("\n"); | ||
315 | } | ||
316 | #endif | ||
317 | } while(!(buf[0x08] & 0x20) && !(err < 0) && ++count < 100); | ||
318 | |||
319 | |||
320 | if (((err > 16) && (buf[0x10] & 0x01)) || count >= 100 || err < 0) { | ||
321 | ds_recv_status(dev, st); | ||
322 | return -1; | ||
323 | } else | ||
324 | return 0; | ||
325 | } | ||
326 | |||
327 | int ds_reset(struct ds_device *dev, struct ds_status *st) | ||
328 | { | ||
329 | int err; | ||
330 | |||
331 | //err = ds_send_control(dev, COMM_1_WIRE_RESET | COMM_F | COMM_IM | COMM_SE, SPEED_FLEXIBLE); | ||
332 | err = ds_send_control(dev, 0x43, SPEED_NORMAL); | ||
333 | if (err) | ||
334 | return err; | ||
335 | |||
336 | ds_wait_status(dev, st); | ||
337 | #if 0 | ||
338 | if (st->command_buffer_status) { | ||
339 | printk(KERN_INFO "Short circuit.\n"); | ||
340 | return -EIO; | ||
341 | } | ||
342 | #endif | ||
343 | |||
344 | return 0; | ||
345 | } | ||
346 | |||
347 | #if 0 | ||
348 | int ds_set_speed(struct ds_device *dev, int speed) | ||
349 | { | ||
350 | int err; | ||
351 | |||
352 | if (speed != SPEED_NORMAL && speed != SPEED_FLEXIBLE && speed != SPEED_OVERDRIVE) | ||
353 | return -EINVAL; | ||
354 | |||
355 | if (speed != SPEED_OVERDRIVE) | ||
356 | speed = SPEED_FLEXIBLE; | ||
357 | |||
358 | speed &= 0xff; | ||
359 | |||
360 | err = ds_send_control_mode(dev, MOD_1WIRE_SPEED, speed); | ||
361 | if (err) | ||
362 | return err; | ||
363 | |||
364 | return err; | ||
365 | } | ||
366 | #endif /* 0 */ | ||
367 | |||
368 | static int ds_start_pulse(struct ds_device *dev, int delay) | ||
369 | { | ||
370 | int err; | ||
371 | u8 del = 1 + (u8)(delay >> 4); | ||
372 | struct ds_status st; | ||
373 | |||
374 | #if 0 | ||
375 | err = ds_stop_pulse(dev, 10); | ||
376 | if (err) | ||
377 | return err; | ||
378 | |||
379 | err = ds_send_control_mode(dev, MOD_PULSE_EN, PULSE_SPUE); | ||
380 | if (err) | ||
381 | return err; | ||
382 | #endif | ||
383 | err = ds_send_control(dev, COMM_SET_DURATION | COMM_IM, del); | ||
384 | if (err) | ||
385 | return err; | ||
386 | |||
387 | err = ds_send_control(dev, COMM_PULSE | COMM_IM | COMM_F, 0); | ||
388 | if (err) | ||
389 | return err; | ||
390 | |||
391 | mdelay(delay); | ||
392 | |||
393 | ds_wait_status(dev, &st); | ||
394 | |||
395 | return err; | ||
396 | } | ||
397 | |||
398 | int ds_touch_bit(struct ds_device *dev, u8 bit, u8 *tbit) | ||
399 | { | ||
400 | int err, count; | ||
401 | struct ds_status st; | ||
402 | u16 value = (COMM_BIT_IO | COMM_IM) | ((bit) ? COMM_D : 0); | ||
403 | u16 cmd; | ||
404 | |||
405 | err = ds_send_control(dev, value, 0); | ||
406 | if (err) | ||
407 | return err; | ||
408 | |||
409 | count = 0; | ||
410 | do { | ||
411 | err = ds_wait_status(dev, &st); | ||
412 | if (err) | ||
413 | return err; | ||
414 | |||
415 | cmd = st.command0 | (st.command1 << 8); | ||
416 | } while (cmd != value && ++count < 10); | ||
417 | |||
418 | if (err < 0 || count >= 10) { | ||
419 | printk(KERN_ERR "Failed to obtain status.\n"); | ||
420 | return -EINVAL; | ||
421 | } | ||
422 | |||
423 | err = ds_recv_data(dev, tbit, sizeof(*tbit)); | ||
424 | if (err < 0) | ||
425 | return err; | ||
426 | |||
427 | return 0; | ||
428 | } | ||
429 | |||
430 | int ds_write_bit(struct ds_device *dev, u8 bit) | ||
431 | { | ||
432 | int err; | ||
433 | struct ds_status st; | ||
434 | |||
435 | err = ds_send_control(dev, COMM_BIT_IO | COMM_IM | (bit) ? COMM_D : 0, 0); | ||
436 | if (err) | ||
437 | return err; | ||
438 | |||
439 | ds_wait_status(dev, &st); | ||
440 | |||
441 | return 0; | ||
442 | } | ||
443 | |||
444 | int ds_write_byte(struct ds_device *dev, u8 byte) | ||
445 | { | ||
446 | int err; | ||
447 | struct ds_status st; | ||
448 | u8 rbyte; | ||
449 | |||
450 | err = ds_send_control(dev, COMM_BYTE_IO | COMM_IM | COMM_SPU, byte); | ||
451 | if (err) | ||
452 | return err; | ||
453 | |||
454 | err = ds_wait_status(dev, &st); | ||
455 | if (err) | ||
456 | return err; | ||
457 | |||
458 | err = ds_recv_data(dev, &rbyte, sizeof(rbyte)); | ||
459 | if (err < 0) | ||
460 | return err; | ||
461 | |||
462 | ds_start_pulse(dev, PULLUP_PULSE_DURATION); | ||
463 | |||
464 | return !(byte == rbyte); | ||
465 | } | ||
466 | |||
467 | int ds_read_bit(struct ds_device *dev, u8 *bit) | ||
468 | { | ||
469 | int err; | ||
470 | |||
471 | err = ds_send_control_mode(dev, MOD_PULSE_EN, PULSE_SPUE); | ||
472 | if (err) | ||
473 | return err; | ||
474 | |||
475 | err = ds_send_control(dev, COMM_BIT_IO | COMM_IM | COMM_SPU | COMM_D, 0); | ||
476 | if (err) | ||
477 | return err; | ||
478 | |||
479 | err = ds_recv_data(dev, bit, sizeof(*bit)); | ||
480 | if (err < 0) | ||
481 | return err; | ||
482 | |||
483 | return 0; | ||
484 | } | ||
485 | |||
486 | int ds_read_byte(struct ds_device *dev, u8 *byte) | ||
487 | { | ||
488 | int err; | ||
489 | struct ds_status st; | ||
490 | |||
491 | err = ds_send_control(dev, COMM_BYTE_IO | COMM_IM , 0xff); | ||
492 | if (err) | ||
493 | return err; | ||
494 | |||
495 | ds_wait_status(dev, &st); | ||
496 | |||
497 | err = ds_recv_data(dev, byte, sizeof(*byte)); | ||
498 | if (err < 0) | ||
499 | return err; | ||
500 | |||
501 | return 0; | ||
502 | } | ||
503 | |||
504 | int ds_read_block(struct ds_device *dev, u8 *buf, int len) | ||
505 | { | ||
506 | struct ds_status st; | ||
507 | int err; | ||
508 | |||
509 | if (len > 64*1024) | ||
510 | return -E2BIG; | ||
511 | |||
512 | memset(buf, 0xFF, len); | ||
513 | |||
514 | err = ds_send_data(dev, buf, len); | ||
515 | if (err < 0) | ||
516 | return err; | ||
517 | |||
518 | err = ds_send_control(dev, COMM_BLOCK_IO | COMM_IM | COMM_SPU, len); | ||
519 | if (err) | ||
520 | return err; | ||
521 | |||
522 | ds_wait_status(dev, &st); | ||
523 | |||
524 | memset(buf, 0x00, len); | ||
525 | err = ds_recv_data(dev, buf, len); | ||
526 | |||
527 | return err; | ||
528 | } | ||
529 | |||
530 | int ds_write_block(struct ds_device *dev, u8 *buf, int len) | ||
531 | { | ||
532 | int err; | ||
533 | struct ds_status st; | ||
534 | |||
535 | err = ds_send_data(dev, buf, len); | ||
536 | if (err < 0) | ||
537 | return err; | ||
538 | |||
539 | ds_wait_status(dev, &st); | ||
540 | |||
541 | err = ds_send_control(dev, COMM_BLOCK_IO | COMM_IM | COMM_SPU, len); | ||
542 | if (err) | ||
543 | return err; | ||
544 | |||
545 | ds_wait_status(dev, &st); | ||
546 | |||
547 | err = ds_recv_data(dev, buf, len); | ||
548 | if (err < 0) | ||
549 | return err; | ||
550 | |||
551 | ds_start_pulse(dev, PULLUP_PULSE_DURATION); | ||
552 | |||
553 | return !(err == len); | ||
554 | } | ||
555 | |||
556 | #if 0 | ||
557 | |||
558 | int ds_search(struct ds_device *dev, u64 init, u64 *buf, u8 id_number, int conditional_search) | ||
559 | { | ||
560 | int err; | ||
561 | u16 value, index; | ||
562 | struct ds_status st; | ||
563 | |||
564 | memset(buf, 0, sizeof(buf)); | ||
565 | |||
566 | err = ds_send_data(ds_dev, (unsigned char *)&init, 8); | ||
567 | if (err) | ||
568 | return err; | ||
569 | |||
570 | ds_wait_status(ds_dev, &st); | ||
571 | |||
572 | value = COMM_SEARCH_ACCESS | COMM_IM | COMM_SM | COMM_F | COMM_RTS; | ||
573 | index = (conditional_search ? 0xEC : 0xF0) | (id_number << 8); | ||
574 | err = ds_send_control(ds_dev, value, index); | ||
575 | if (err) | ||
576 | return err; | ||
577 | |||
578 | ds_wait_status(ds_dev, &st); | ||
579 | |||
580 | err = ds_recv_data(ds_dev, (unsigned char *)buf, 8*id_number); | ||
581 | if (err < 0) | ||
582 | return err; | ||
583 | |||
584 | return err/8; | ||
585 | } | ||
586 | |||
587 | int ds_match_access(struct ds_device *dev, u64 init) | ||
588 | { | ||
589 | int err; | ||
590 | struct ds_status st; | ||
591 | |||
592 | err = ds_send_data(dev, (unsigned char *)&init, sizeof(init)); | ||
593 | if (err) | ||
594 | return err; | ||
595 | |||
596 | ds_wait_status(dev, &st); | ||
597 | |||
598 | err = ds_send_control(dev, COMM_MATCH_ACCESS | COMM_IM | COMM_RST, 0x0055); | ||
599 | if (err) | ||
600 | return err; | ||
601 | |||
602 | ds_wait_status(dev, &st); | ||
603 | |||
604 | return 0; | ||
605 | } | ||
606 | |||
607 | int ds_set_path(struct ds_device *dev, u64 init) | ||
608 | { | ||
609 | int err; | ||
610 | struct ds_status st; | ||
611 | u8 buf[9]; | ||
612 | |||
613 | memcpy(buf, &init, 8); | ||
614 | buf[8] = BRANCH_MAIN; | ||
615 | |||
616 | err = ds_send_data(dev, buf, sizeof(buf)); | ||
617 | if (err) | ||
618 | return err; | ||
619 | |||
620 | ds_wait_status(dev, &st); | ||
621 | |||
622 | err = ds_send_control(dev, COMM_SET_PATH | COMM_IM | COMM_RST, 0); | ||
623 | if (err) | ||
624 | return err; | ||
625 | |||
626 | ds_wait_status(dev, &st); | ||
627 | |||
628 | return 0; | ||
629 | } | ||
630 | |||
631 | #endif /* 0 */ | ||
632 | |||
633 | static int ds_probe(struct usb_interface *intf, | ||
634 | const struct usb_device_id *udev_id) | ||
635 | { | ||
636 | struct usb_device *udev = interface_to_usbdev(intf); | ||
637 | struct usb_endpoint_descriptor *endpoint; | ||
638 | struct usb_host_interface *iface_desc; | ||
639 | int i, err; | ||
640 | |||
641 | ds_dev = kmalloc(sizeof(struct ds_device), GFP_KERNEL); | ||
642 | if (!ds_dev) { | ||
643 | printk(KERN_INFO "Failed to allocate new DS9490R structure.\n"); | ||
644 | return -ENOMEM; | ||
645 | } | ||
646 | |||
647 | ds_dev->udev = usb_get_dev(udev); | ||
648 | usb_set_intfdata(intf, ds_dev); | ||
649 | |||
650 | err = usb_set_interface(ds_dev->udev, intf->altsetting[0].desc.bInterfaceNumber, 3); | ||
651 | if (err) { | ||
652 | printk(KERN_ERR "Failed to set alternative setting 3 for %d interface: err=%d.\n", | ||
653 | intf->altsetting[0].desc.bInterfaceNumber, err); | ||
654 | return err; | ||
655 | } | ||
656 | |||
657 | err = usb_reset_configuration(ds_dev->udev); | ||
658 | if (err) { | ||
659 | printk(KERN_ERR "Failed to reset configuration: err=%d.\n", err); | ||
660 | return err; | ||
661 | } | ||
662 | |||
663 | iface_desc = &intf->altsetting[0]; | ||
664 | if (iface_desc->desc.bNumEndpoints != NUM_EP-1) { | ||
665 | printk(KERN_INFO "Num endpoints=%d. It is not DS9490R.\n", iface_desc->desc.bNumEndpoints); | ||
666 | return -ENODEV; | ||
667 | } | ||
668 | |||
669 | atomic_set(&ds_dev->refcnt, 0); | ||
670 | memset(ds_dev->ep, 0, sizeof(ds_dev->ep)); | ||
671 | |||
672 | /* | ||
673 | * This loop doesn'd show control 0 endpoint, | ||
674 | * so we will fill only 1-3 endpoints entry. | ||
675 | */ | ||
676 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { | ||
677 | endpoint = &iface_desc->endpoint[i].desc; | ||
678 | |||
679 | ds_dev->ep[i+1] = endpoint->bEndpointAddress; | ||
680 | |||
681 | printk("%d: addr=%x, size=%d, dir=%s, type=%x\n", | ||
682 | i, endpoint->bEndpointAddress, le16_to_cpu(endpoint->wMaxPacketSize), | ||
683 | (endpoint->bEndpointAddress & USB_DIR_IN)?"IN":"OUT", | ||
684 | endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK); | ||
685 | } | ||
686 | |||
687 | #if 0 | ||
688 | { | ||
689 | int err, i; | ||
690 | u64 buf[3]; | ||
691 | u64 init=0xb30000002078ee81ull; | ||
692 | struct ds_status st; | ||
693 | |||
694 | ds_reset(ds_dev, &st); | ||
695 | err = ds_search(ds_dev, init, buf, 3, 0); | ||
696 | if (err < 0) | ||
697 | return err; | ||
698 | for (i=0; i<err; ++i) | ||
699 | printk("%d: %llx\n", i, buf[i]); | ||
700 | |||
701 | printk("Resetting...\n"); | ||
702 | ds_reset(ds_dev, &st); | ||
703 | printk("Setting path for %llx.\n", init); | ||
704 | err = ds_set_path(ds_dev, init); | ||
705 | if (err) | ||
706 | return err; | ||
707 | printk("Calling MATCH_ACCESS.\n"); | ||
708 | err = ds_match_access(ds_dev, init); | ||
709 | if (err) | ||
710 | return err; | ||
711 | |||
712 | printk("Searching the bus...\n"); | ||
713 | err = ds_search(ds_dev, init, buf, 3, 0); | ||
714 | |||
715 | printk("ds_search() returned %d\n", err); | ||
716 | |||
717 | if (err < 0) | ||
718 | return err; | ||
719 | for (i=0; i<err; ++i) | ||
720 | printk("%d: %llx\n", i, buf[i]); | ||
721 | |||
722 | return 0; | ||
723 | } | ||
724 | #endif | ||
725 | |||
726 | return 0; | ||
727 | } | ||
728 | |||
729 | static void ds_disconnect(struct usb_interface *intf) | ||
730 | { | ||
731 | struct ds_device *dev; | ||
732 | |||
733 | dev = usb_get_intfdata(intf); | ||
734 | usb_set_intfdata(intf, NULL); | ||
735 | |||
736 | while (atomic_read(&dev->refcnt)) { | ||
737 | printk(KERN_INFO "Waiting for DS to become free: refcnt=%d.\n", | ||
738 | atomic_read(&dev->refcnt)); | ||
739 | |||
740 | if (msleep_interruptible(1000)) | ||
741 | flush_signals(current); | ||
742 | } | ||
743 | |||
744 | usb_put_dev(dev->udev); | ||
745 | kfree(dev); | ||
746 | ds_dev = NULL; | ||
747 | } | ||
748 | |||
749 | static int ds_init(void) | ||
750 | { | ||
751 | int err; | ||
752 | |||
753 | err = usb_register(&ds_driver); | ||
754 | if (err) { | ||
755 | printk(KERN_INFO "Failed to register DS9490R USB device: err=%d.\n", err); | ||
756 | return err; | ||
757 | } | ||
758 | |||
759 | return 0; | ||
760 | } | ||
761 | |||
762 | static void ds_fini(void) | ||
763 | { | ||
764 | usb_deregister(&ds_driver); | ||
765 | } | ||
766 | |||
767 | module_init(ds_init); | ||
768 | module_exit(ds_fini); | ||
769 | |||
770 | MODULE_LICENSE("GPL"); | ||
771 | MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>"); | ||
772 | |||
773 | EXPORT_SYMBOL(ds_touch_bit); | ||
774 | EXPORT_SYMBOL(ds_read_byte); | ||
775 | EXPORT_SYMBOL(ds_read_bit); | ||
776 | EXPORT_SYMBOL(ds_read_block); | ||
777 | EXPORT_SYMBOL(ds_write_byte); | ||
778 | EXPORT_SYMBOL(ds_write_bit); | ||
779 | EXPORT_SYMBOL(ds_write_block); | ||
780 | EXPORT_SYMBOL(ds_reset); | ||
781 | EXPORT_SYMBOL(ds_get_device); | ||
782 | EXPORT_SYMBOL(ds_put_device); | ||
783 | |||
784 | /* | ||
785 | * This functions can be used for EEPROM programming, | ||
786 | * when driver will be included into mainline this will | ||
787 | * require uncommenting. | ||
788 | */ | ||
789 | #if 0 | ||
790 | EXPORT_SYMBOL(ds_start_pulse); | ||
791 | EXPORT_SYMBOL(ds_set_speed); | ||
792 | EXPORT_SYMBOL(ds_detect); | ||
793 | EXPORT_SYMBOL(ds_stop_pulse); | ||
794 | EXPORT_SYMBOL(ds_search); | ||
795 | #endif | ||
diff --git a/drivers/w1/masters/dscore.h b/drivers/w1/masters/dscore.h new file mode 100644 index 00000000000..6cf5671d6eb --- /dev/null +++ b/drivers/w1/masters/dscore.h | |||
@@ -0,0 +1,166 @@ | |||
1 | /* | ||
2 | * dscore.h | ||
3 | * | ||
4 | * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> | ||
5 | * | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | #ifndef __DSCORE_H | ||
23 | #define __DSCORE_H | ||
24 | |||
25 | #include <linux/usb.h> | ||
26 | #include <asm/atomic.h> | ||
27 | |||
28 | /* COMMAND TYPE CODES */ | ||
29 | #define CONTROL_CMD 0x00 | ||
30 | #define COMM_CMD 0x01 | ||
31 | #define MODE_CMD 0x02 | ||
32 | |||
33 | /* CONTROL COMMAND CODES */ | ||
34 | #define CTL_RESET_DEVICE 0x0000 | ||
35 | #define CTL_START_EXE 0x0001 | ||
36 | #define CTL_RESUME_EXE 0x0002 | ||
37 | #define CTL_HALT_EXE_IDLE 0x0003 | ||
38 | #define CTL_HALT_EXE_DONE 0x0004 | ||
39 | #define CTL_FLUSH_COMM_CMDS 0x0007 | ||
40 | #define CTL_FLUSH_RCV_BUFFER 0x0008 | ||
41 | #define CTL_FLUSH_XMT_BUFFER 0x0009 | ||
42 | #define CTL_GET_COMM_CMDS 0x000A | ||
43 | |||
44 | /* MODE COMMAND CODES */ | ||
45 | #define MOD_PULSE_EN 0x0000 | ||
46 | #define MOD_SPEED_CHANGE_EN 0x0001 | ||
47 | #define MOD_1WIRE_SPEED 0x0002 | ||
48 | #define MOD_STRONG_PU_DURATION 0x0003 | ||
49 | #define MOD_PULLDOWN_SLEWRATE 0x0004 | ||
50 | #define MOD_PROG_PULSE_DURATION 0x0005 | ||
51 | #define MOD_WRITE1_LOWTIME 0x0006 | ||
52 | #define MOD_DSOW0_TREC 0x0007 | ||
53 | |||
54 | /* COMMUNICATION COMMAND CODES */ | ||
55 | #define COMM_ERROR_ESCAPE 0x0601 | ||
56 | #define COMM_SET_DURATION 0x0012 | ||
57 | #define COMM_BIT_IO 0x0020 | ||
58 | #define COMM_PULSE 0x0030 | ||
59 | #define COMM_1_WIRE_RESET 0x0042 | ||
60 | #define COMM_BYTE_IO 0x0052 | ||
61 | #define COMM_MATCH_ACCESS 0x0064 | ||
62 | #define COMM_BLOCK_IO 0x0074 | ||
63 | #define COMM_READ_STRAIGHT 0x0080 | ||
64 | #define COMM_DO_RELEASE 0x6092 | ||
65 | #define COMM_SET_PATH 0x00A2 | ||
66 | #define COMM_WRITE_SRAM_PAGE 0x00B2 | ||
67 | #define COMM_WRITE_EPROM 0x00C4 | ||
68 | #define COMM_READ_CRC_PROT_PAGE 0x00D4 | ||
69 | #define COMM_READ_REDIRECT_PAGE_CRC 0x21E4 | ||
70 | #define COMM_SEARCH_ACCESS 0x00F4 | ||
71 | |||
72 | /* Communication command bits */ | ||
73 | #define COMM_TYPE 0x0008 | ||
74 | #define COMM_SE 0x0008 | ||
75 | #define COMM_D 0x0008 | ||
76 | #define COMM_Z 0x0008 | ||
77 | #define COMM_CH 0x0008 | ||
78 | #define COMM_SM 0x0008 | ||
79 | #define COMM_R 0x0008 | ||
80 | #define COMM_IM 0x0001 | ||
81 | |||
82 | #define COMM_PS 0x4000 | ||
83 | #define COMM_PST 0x4000 | ||
84 | #define COMM_CIB 0x4000 | ||
85 | #define COMM_RTS 0x4000 | ||
86 | #define COMM_DT 0x2000 | ||
87 | #define COMM_SPU 0x1000 | ||
88 | #define COMM_F 0x0800 | ||
89 | #define COMM_NTP 0x0400 | ||
90 | #define COMM_ICP 0x0200 | ||
91 | #define COMM_RST 0x0100 | ||
92 | |||
93 | #define PULSE_PROG 0x01 | ||
94 | #define PULSE_SPUE 0x02 | ||
95 | |||
96 | #define BRANCH_MAIN 0xCC | ||
97 | #define BRANCH_AUX 0x33 | ||
98 | |||
99 | /* | ||
100 | * Duration of the strong pull-up pulse in milliseconds. | ||
101 | */ | ||
102 | #define PULLUP_PULSE_DURATION 750 | ||
103 | |||
104 | /* Status flags */ | ||
105 | #define ST_SPUA 0x01 /* Strong Pull-up is active */ | ||
106 | #define ST_PRGA 0x02 /* 12V programming pulse is being generated */ | ||
107 | #define ST_12VP 0x04 /* external 12V programming voltage is present */ | ||
108 | #define ST_PMOD 0x08 /* DS2490 powered from USB and external sources */ | ||
109 | #define ST_HALT 0x10 /* DS2490 is currently halted */ | ||
110 | #define ST_IDLE 0x20 /* DS2490 is currently idle */ | ||
111 | #define ST_EPOF 0x80 | ||
112 | |||
113 | #define SPEED_NORMAL 0x00 | ||
114 | #define SPEED_FLEXIBLE 0x01 | ||
115 | #define SPEED_OVERDRIVE 0x02 | ||
116 | |||
117 | #define NUM_EP 4 | ||
118 | #define EP_CONTROL 0 | ||
119 | #define EP_STATUS 1 | ||
120 | #define EP_DATA_OUT 2 | ||
121 | #define EP_DATA_IN 3 | ||
122 | |||
123 | struct ds_device | ||
124 | { | ||
125 | struct usb_device *udev; | ||
126 | struct usb_interface *intf; | ||
127 | |||
128 | int ep[NUM_EP]; | ||
129 | |||
130 | atomic_t refcnt; | ||
131 | }; | ||
132 | |||
133 | struct ds_status | ||
134 | { | ||
135 | u8 enable; | ||
136 | u8 speed; | ||
137 | u8 pullup_dur; | ||
138 | u8 ppuls_dur; | ||
139 | u8 pulldown_slew; | ||
140 | u8 write1_time; | ||
141 | u8 write0_time; | ||
142 | u8 reserved0; | ||
143 | u8 status; | ||
144 | u8 command0; | ||
145 | u8 command1; | ||
146 | u8 command_buffer_status; | ||
147 | u8 data_out_buffer_status; | ||
148 | u8 data_in_buffer_status; | ||
149 | u8 reserved1; | ||
150 | u8 reserved2; | ||
151 | |||
152 | }; | ||
153 | |||
154 | int ds_touch_bit(struct ds_device *, u8, u8 *); | ||
155 | int ds_read_byte(struct ds_device *, u8 *); | ||
156 | int ds_read_bit(struct ds_device *, u8 *); | ||
157 | int ds_write_byte(struct ds_device *, u8); | ||
158 | int ds_write_bit(struct ds_device *, u8); | ||
159 | int ds_reset(struct ds_device *, struct ds_status *); | ||
160 | struct ds_device * ds_get_device(void); | ||
161 | void ds_put_device(struct ds_device *); | ||
162 | int ds_write_block(struct ds_device *, u8 *, int); | ||
163 | int ds_read_block(struct ds_device *, u8 *, int); | ||
164 | |||
165 | #endif /* __DSCORE_H */ | ||
166 | |||
diff --git a/drivers/w1/masters/matrox_w1.c b/drivers/w1/masters/matrox_w1.c new file mode 100644 index 00000000000..591809cbbb9 --- /dev/null +++ b/drivers/w1/masters/matrox_w1.c | |||
@@ -0,0 +1,247 @@ | |||
1 | /* | ||
2 | * matrox_w1.c | ||
3 | * | ||
4 | * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> | ||
5 | * | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | #include <asm/types.h> | ||
23 | #include <asm/atomic.h> | ||
24 | #include <asm/io.h> | ||
25 | |||
26 | #include <linux/delay.h> | ||
27 | #include <linux/kernel.h> | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/list.h> | ||
30 | #include <linux/interrupt.h> | ||
31 | #include <linux/spinlock.h> | ||
32 | #include <linux/timer.h> | ||
33 | #include <linux/slab.h> | ||
34 | #include <linux/pci_ids.h> | ||
35 | #include <linux/pci.h> | ||
36 | #include <linux/timer.h> | ||
37 | |||
38 | #include "../w1.h" | ||
39 | #include "../w1_int.h" | ||
40 | #include "../w1_log.h" | ||
41 | |||
42 | MODULE_LICENSE("GPL"); | ||
43 | MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>"); | ||
44 | MODULE_DESCRIPTION("Driver for transport(Dallas 1-wire prtocol) over VGA DDC(matrox gpio)."); | ||
45 | |||
46 | static struct pci_device_id matrox_w1_tbl[] = { | ||
47 | { PCI_DEVICE(PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400) }, | ||
48 | { }, | ||
49 | }; | ||
50 | MODULE_DEVICE_TABLE(pci, matrox_w1_tbl); | ||
51 | |||
52 | static int __devinit matrox_w1_probe(struct pci_dev *, const struct pci_device_id *); | ||
53 | static void __devexit matrox_w1_remove(struct pci_dev *); | ||
54 | |||
55 | static struct pci_driver matrox_w1_pci_driver = { | ||
56 | .name = "matrox_w1", | ||
57 | .id_table = matrox_w1_tbl, | ||
58 | .probe = matrox_w1_probe, | ||
59 | .remove = __devexit_p(matrox_w1_remove), | ||
60 | }; | ||
61 | |||
62 | /* | ||
63 | * Matrox G400 DDC registers. | ||
64 | */ | ||
65 | |||
66 | #define MATROX_G400_DDC_CLK (1<<4) | ||
67 | #define MATROX_G400_DDC_DATA (1<<1) | ||
68 | |||
69 | #define MATROX_BASE 0x3C00 | ||
70 | #define MATROX_STATUS 0x1e14 | ||
71 | |||
72 | #define MATROX_PORT_INDEX_OFFSET 0x00 | ||
73 | #define MATROX_PORT_DATA_OFFSET 0x0A | ||
74 | |||
75 | #define MATROX_GET_CONTROL 0x2A | ||
76 | #define MATROX_GET_DATA 0x2B | ||
77 | #define MATROX_CURSOR_CTL 0x06 | ||
78 | |||
79 | struct matrox_device | ||
80 | { | ||
81 | void __iomem *base_addr; | ||
82 | void __iomem *port_index; | ||
83 | void __iomem *port_data; | ||
84 | u8 data_mask; | ||
85 | |||
86 | unsigned long phys_addr; | ||
87 | void __iomem *virt_addr; | ||
88 | unsigned long found; | ||
89 | |||
90 | struct w1_bus_master *bus_master; | ||
91 | }; | ||
92 | |||
93 | static u8 matrox_w1_read_ddc_bit(void *); | ||
94 | static void matrox_w1_write_ddc_bit(void *, u8); | ||
95 | |||
96 | /* | ||
97 | * These functions read and write DDC Data bit. | ||
98 | * | ||
99 | * Using tristate pins, since i can't find any open-drain pin in whole motherboard. | ||
100 | * Unfortunately we can't connect to Intel's 82801xx IO controller | ||
101 | * since we don't know motherboard schema, wich has pretty unused(may be not) GPIO. | ||
102 | * | ||
103 | * I've heard that PIIX also has open drain pin. | ||
104 | * | ||
105 | * Port mapping. | ||
106 | */ | ||
107 | static __inline__ u8 matrox_w1_read_reg(struct matrox_device *dev, u8 reg) | ||
108 | { | ||
109 | u8 ret; | ||
110 | |||
111 | writeb(reg, dev->port_index); | ||
112 | ret = readb(dev->port_data); | ||
113 | barrier(); | ||
114 | |||
115 | return ret; | ||
116 | } | ||
117 | |||
118 | static __inline__ void matrox_w1_write_reg(struct matrox_device *dev, u8 reg, u8 val) | ||
119 | { | ||
120 | writeb(reg, dev->port_index); | ||
121 | writeb(val, dev->port_data); | ||
122 | wmb(); | ||
123 | } | ||
124 | |||
125 | static void matrox_w1_write_ddc_bit(void *data, u8 bit) | ||
126 | { | ||
127 | u8 ret; | ||
128 | struct matrox_device *dev = data; | ||
129 | |||
130 | if (bit) | ||
131 | bit = 0; | ||
132 | else | ||
133 | bit = dev->data_mask; | ||
134 | |||
135 | ret = matrox_w1_read_reg(dev, MATROX_GET_CONTROL); | ||
136 | matrox_w1_write_reg(dev, MATROX_GET_CONTROL, ((ret & ~dev->data_mask) | bit)); | ||
137 | matrox_w1_write_reg(dev, MATROX_GET_DATA, 0x00); | ||
138 | } | ||
139 | |||
140 | static u8 matrox_w1_read_ddc_bit(void *data) | ||
141 | { | ||
142 | u8 ret; | ||
143 | struct matrox_device *dev = data; | ||
144 | |||
145 | ret = matrox_w1_read_reg(dev, MATROX_GET_DATA); | ||
146 | |||
147 | return ret; | ||
148 | } | ||
149 | |||
150 | static void matrox_w1_hw_init(struct matrox_device *dev) | ||
151 | { | ||
152 | matrox_w1_write_reg(dev, MATROX_GET_DATA, 0xFF); | ||
153 | matrox_w1_write_reg(dev, MATROX_GET_CONTROL, 0x00); | ||
154 | } | ||
155 | |||
156 | static int __devinit matrox_w1_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | ||
157 | { | ||
158 | struct matrox_device *dev; | ||
159 | int err; | ||
160 | |||
161 | assert(pdev != NULL); | ||
162 | assert(ent != NULL); | ||
163 | |||
164 | if (pdev->vendor != PCI_VENDOR_ID_MATROX || pdev->device != PCI_DEVICE_ID_MATROX_G400) | ||
165 | return -ENODEV; | ||
166 | |||
167 | dev = kmalloc(sizeof(struct matrox_device) + | ||
168 | sizeof(struct w1_bus_master), GFP_KERNEL); | ||
169 | if (!dev) { | ||
170 | dev_err(&pdev->dev, | ||
171 | "%s: Failed to create new matrox_device object.\n", | ||
172 | __func__); | ||
173 | return -ENOMEM; | ||
174 | } | ||
175 | |||
176 | memset(dev, 0, sizeof(struct matrox_device) + sizeof(struct w1_bus_master)); | ||
177 | |||
178 | dev->bus_master = (struct w1_bus_master *)(dev + 1); | ||
179 | |||
180 | /* | ||
181 | * True for G400, for some other we need resource 0, see drivers/video/matrox/matroxfb_base.c | ||
182 | */ | ||
183 | |||
184 | dev->phys_addr = pci_resource_start(pdev, 1); | ||
185 | |||
186 | dev->virt_addr = ioremap_nocache(dev->phys_addr, 16384); | ||
187 | if (!dev->virt_addr) { | ||
188 | dev_err(&pdev->dev, "%s: failed to ioremap(0x%lx, %d).\n", | ||
189 | __func__, dev->phys_addr, 16384); | ||
190 | err = -EIO; | ||
191 | goto err_out_free_device; | ||
192 | } | ||
193 | |||
194 | dev->base_addr = dev->virt_addr + MATROX_BASE; | ||
195 | dev->port_index = dev->base_addr + MATROX_PORT_INDEX_OFFSET; | ||
196 | dev->port_data = dev->base_addr + MATROX_PORT_DATA_OFFSET; | ||
197 | dev->data_mask = (MATROX_G400_DDC_DATA); | ||
198 | |||
199 | matrox_w1_hw_init(dev); | ||
200 | |||
201 | dev->bus_master->data = dev; | ||
202 | dev->bus_master->read_bit = &matrox_w1_read_ddc_bit; | ||
203 | dev->bus_master->write_bit = &matrox_w1_write_ddc_bit; | ||
204 | |||
205 | err = w1_add_master_device(dev->bus_master); | ||
206 | if (err) | ||
207 | goto err_out_free_device; | ||
208 | |||
209 | pci_set_drvdata(pdev, dev); | ||
210 | |||
211 | dev->found = 1; | ||
212 | |||
213 | dev_info(&pdev->dev, "Matrox G400 GPIO transport layer for 1-wire.\n"); | ||
214 | |||
215 | return 0; | ||
216 | |||
217 | err_out_free_device: | ||
218 | kfree(dev); | ||
219 | |||
220 | return err; | ||
221 | } | ||
222 | |||
223 | static void __devexit matrox_w1_remove(struct pci_dev *pdev) | ||
224 | { | ||
225 | struct matrox_device *dev = pci_get_drvdata(pdev); | ||
226 | |||
227 | assert(dev != NULL); | ||
228 | |||
229 | if (dev->found) { | ||
230 | w1_remove_master_device(dev->bus_master); | ||
231 | iounmap(dev->virt_addr); | ||
232 | } | ||
233 | kfree(dev); | ||
234 | } | ||
235 | |||
236 | static int __init matrox_w1_init(void) | ||
237 | { | ||
238 | return pci_register_driver(&matrox_w1_pci_driver); | ||
239 | } | ||
240 | |||
241 | static void __exit matrox_w1_fini(void) | ||
242 | { | ||
243 | pci_unregister_driver(&matrox_w1_pci_driver); | ||
244 | } | ||
245 | |||
246 | module_init(matrox_w1_init); | ||
247 | module_exit(matrox_w1_fini); | ||