4 * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
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.
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.
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
22 #include <linux/module.h>
23 #include <linux/types.h>
26 #include "../w1/w1_int.h"
29 static struct ds_device *ds_dev;
30 static struct w1_bus_master *ds_bus_master;
32 static u8 ds9490r_touch_bit(unsigned long data, u8 bit)
35 struct ds_device *dev = (struct ds_device *)data;
37 if (ds_touch_bit(dev, bit, &ret))
43 static void ds9490r_write_bit(unsigned long data, u8 bit)
45 struct ds_device *dev = (struct ds_device *)data;
47 ds_write_bit(dev, bit);
50 static void ds9490r_write_byte(unsigned long data, u8 byte)
52 struct ds_device *dev = (struct ds_device *)data;
54 ds_write_byte(dev, byte);
57 static u8 ds9490r_read_bit(unsigned long data)
59 struct ds_device *dev = (struct ds_device *)data;
63 err = ds_touch_bit(dev, 1, &bit);
66 //err = ds_read_bit(dev, &bit);
73 static u8 ds9490r_read_byte(unsigned long data)
75 struct ds_device *dev = (struct ds_device *)data;
79 err = ds_read_byte(dev, &byte);
86 static void ds9490r_write_block(unsigned long data, u8 *buf, int len)
88 struct ds_device *dev = (struct ds_device *)data;
90 ds_write_block(dev, buf, len);
93 static u8 ds9490r_read_block(unsigned long data, u8 *buf, int len)
95 struct ds_device *dev = (struct ds_device *)data;
98 err = ds_read_block(dev, buf, len);
105 static u8 ds9490r_reset(unsigned long data)
107 struct ds_device *dev = (struct ds_device *)data;
111 memset(&st, 0, sizeof(st));
113 err = ds_reset(dev, &st);
120 static int __devinit ds_w1_init(void)
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");
130 ds_dev = ds_get_device();
132 printk(KERN_ERR "DS9490R is not registered.\n");
134 goto err_out_free_bus_master;
137 memset(ds_bus_master, 0, sizeof(*ds_bus_master));
139 ds_bus_master->data = (unsigned long)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;
149 err = w1_add_master_device(ds_bus_master);
151 goto err_out_put_device;
156 ds_put_device(ds_dev);
157 err_out_free_bus_master:
158 kfree(ds_bus_master);
163 static void __devexit ds_w1_fini(void)
165 w1_remove_master_device(ds_bus_master);
166 ds_put_device(ds_dev);
167 kfree(ds_bus_master);
170 module_init(ds_w1_init);
171 module_exit(ds_w1_fini);
173 MODULE_LICENSE("GPL");
174 MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");