/*
 *	ds_w1_bridge.c
 *
 * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
 *
 *
 * 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"

static struct ds_device *ds_dev;
static struct w1_bus_master *ds_bus_master;

static u8 ds9490r_touch_bit(void *data, u8 bit)
{
	u8 ret;
	struct ds_device *dev = data;

	if (ds_touch_bit(dev, bit, &ret))
		return 0;

	return ret;
}

static void ds9490r_write_bit(void *data, u8 bit)
{
	struct ds_device *dev = data;

	ds_write_bit(dev, bit);
}

static void ds9490r_write_byte(void *data, u8 byte)
{
	struct ds_device *dev = data;

	ds_write_byte(dev, byte);
}

static u8 ds9490r_read_bit(void *data)
{
	struct ds_device *dev = data;
	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;
}

static u8 ds9490r_read_byte(void *data)
{
	struct ds_device *dev = data;
	int err;
	u8 byte = 0;

	err = ds_read_byte(dev, &byte);
	if (err)
		return 0;

	return byte;
}

static void ds9490r_write_block(void *data, const u8 *buf, int len)
{
	struct ds_device *dev = data;

	ds_write_block(dev, (u8 *)buf, len);
}

static u8 ds9490r_read_block(void *data, u8 *buf, int len)
{
	struct ds_device *dev = data;
	int err;

	err = ds_read_block(dev, buf, len);
	if (err < 0)
		return 0;

	return len;
}

static u8 ds9490r_reset(void *data)
{
	struct ds_device *dev = data;
	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;

	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));

	ds_bus_master->data		= ds_dev;
	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;
	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>");
