2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2005-08-03 13:14:50 +02:00
|
|
|
* ds_w1_bridge.c
|
2005-04-17 00:20:36 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
|
2005-08-03 13:14:50 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
|
|
|
|
#include "../w1/w1.h"
|
|
|
|
#include "../w1/w1_int.h"
|
|
|
|
#include "dscore.h"
|
2005-08-03 13:14:50 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
static struct ds_device *ds_dev;
|
|
|
|
static struct w1_bus_master *ds_bus_master;
|
|
|
|
|
2005-12-06 11:38:27 +01:00
|
|
|
static u8 ds9490r_touch_bit(void *data, u8 bit)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
u8 ret;
|
2005-12-06 11:38:27 +01:00
|
|
|
struct ds_device *dev = data;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (ds_touch_bit(dev, bit, &ret))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-06 11:38:27 +01:00
|
|
|
static void ds9490r_write_bit(void *data, u8 bit)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2005-12-06 11:38:27 +01:00
|
|
|
struct ds_device *dev = data;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
ds_write_bit(dev, bit);
|
|
|
|
}
|
|
|
|
|
2005-12-06 11:38:27 +01:00
|
|
|
static void ds9490r_write_byte(void *data, u8 byte)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2005-12-06 11:38:27 +01:00
|
|
|
struct ds_device *dev = data;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
ds_write_byte(dev, byte);
|
|
|
|
}
|
|
|
|
|
2005-12-06 11:38:27 +01:00
|
|
|
static u8 ds9490r_read_bit(void *data)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2005-12-06 11:38:27 +01:00
|
|
|
struct ds_device *dev = data;
|
2005-04-17 00:20:36 +02:00
|
|
|
int err;
|
|
|
|
u8 bit = 0;
|
|
|
|
|
|
|
|
err = ds_touch_bit(dev, 1, &bit);
|
|
|
|
if (err)
|
|
|
|
return 0;
|
|
|
|
//err = ds_read_bit(dev, &bit);
|
|
|
|
//if (err)
|
|
|
|
// return 0;
|
|
|
|
|
|
|
|
return bit & 1;
|
|
|
|
}
|
|
|
|
|
2005-12-06 11:38:27 +01:00
|
|
|
static u8 ds9490r_read_byte(void *data)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2005-12-06 11:38:27 +01:00
|
|
|
struct ds_device *dev = data;
|
2005-04-17 00:20:36 +02:00
|
|
|
int err;
|
|
|
|
u8 byte = 0;
|
|
|
|
|
|
|
|
err = ds_read_byte(dev, &byte);
|
|
|
|
if (err)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return byte;
|
|
|
|
}
|
|
|
|
|
2005-12-06 11:38:27 +01:00
|
|
|
static void ds9490r_write_block(void *data, const u8 *buf, int len)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2005-12-06 11:38:27 +01:00
|
|
|
struct ds_device *dev = data;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-06-03 23:29:25 +02:00
|
|
|
ds_write_block(dev, (u8 *)buf, len);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2005-12-06 11:38:27 +01:00
|
|
|
static u8 ds9490r_read_block(void *data, u8 *buf, int len)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2005-12-06 11:38:27 +01:00
|
|
|
struct ds_device *dev = data;
|
2005-04-17 00:20:36 +02:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = ds_read_block(dev, buf, len);
|
|
|
|
if (err < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2005-12-06 11:38:27 +01:00
|
|
|
static u8 ds9490r_reset(void *data)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2005-12-06 11:38:27 +01:00
|
|
|
struct ds_device *dev = data;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct ds_status st;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
memset(&st, 0, sizeof(st));
|
|
|
|
|
|
|
|
err = ds_reset(dev, &st);
|
|
|
|
if (err)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devinit ds_w1_init(void)
|
|
|
|
{
|
|
|
|
int err;
|
2005-08-03 13:14:50 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
ds_bus_master = kmalloc(sizeof(*ds_bus_master), GFP_KERNEL);
|
|
|
|
if (!ds_bus_master) {
|
|
|
|
printk(KERN_ERR "Failed to allocate DS9490R USB<->W1 bus_master structure.\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
ds_dev = ds_get_device();
|
|
|
|
if (!ds_dev) {
|
|
|
|
printk(KERN_ERR "DS9490R is not registered.\n");
|
|
|
|
err = -ENODEV;
|
|
|
|
goto err_out_free_bus_master;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(ds_bus_master, 0, sizeof(*ds_bus_master));
|
|
|
|
|
2005-12-06 11:38:27 +01:00
|
|
|
ds_bus_master->data = ds_dev;
|
2005-08-03 13:14:50 +02:00
|
|
|
ds_bus_master->touch_bit = &ds9490r_touch_bit;
|
|
|
|
ds_bus_master->read_bit = &ds9490r_read_bit;
|
|
|
|
ds_bus_master->write_bit = &ds9490r_write_bit;
|
|
|
|
ds_bus_master->read_byte = &ds9490r_read_byte;
|
|
|
|
ds_bus_master->write_byte = &ds9490r_write_byte;
|
|
|
|
ds_bus_master->read_block = &ds9490r_read_block;
|
|
|
|
ds_bus_master->write_block = &ds9490r_write_block;
|
2005-04-17 00:20:36 +02:00
|
|
|
ds_bus_master->reset_bus = &ds9490r_reset;
|
|
|
|
|
|
|
|
err = w1_add_master_device(ds_bus_master);
|
|
|
|
if (err)
|
|
|
|
goto err_out_put_device;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_out_put_device:
|
|
|
|
ds_put_device(ds_dev);
|
|
|
|
err_out_free_bus_master:
|
|
|
|
kfree(ds_bus_master);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __devexit ds_w1_fini(void)
|
|
|
|
{
|
|
|
|
w1_remove_master_device(ds_bus_master);
|
|
|
|
ds_put_device(ds_dev);
|
|
|
|
kfree(ds_bus_master);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(ds_w1_init);
|
|
|
|
module_exit(ds_w1_fini);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
|