linux/drivers/w1/masters/ds2490.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 *	ds2490.c  USB to one wire bridge
 *
 * Copyright (c) 2004 Evgeniy Polyakov <[email protected]>
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/mod_devicetable.h>
#include <linux/usb.h>
#include <linux/slab.h>

#include <linux/w1.h>

/* USB Standard */
/* USB Control request vendor type */
#define VENDOR

/* COMMAND TYPE CODES */
#define CONTROL_CMD
#define COMM_CMD
#define MODE_CMD

/* CONTROL COMMAND CODES */
#define CTL_RESET_DEVICE
#define CTL_START_EXE
#define CTL_RESUME_EXE
#define CTL_HALT_EXE_IDLE
#define CTL_HALT_EXE_DONE
#define CTL_FLUSH_COMM_CMDS
#define CTL_FLUSH_RCV_BUFFER
#define CTL_FLUSH_XMT_BUFFER
#define CTL_GET_COMM_CMDS

/* MODE COMMAND CODES */
#define MOD_PULSE_EN
#define MOD_SPEED_CHANGE_EN
#define MOD_1WIRE_SPEED
#define MOD_STRONG_PU_DURATION
#define MOD_PULLDOWN_SLEWRATE
#define MOD_PROG_PULSE_DURATION
#define MOD_WRITE1_LOWTIME
#define MOD_DSOW0_TREC

/* COMMUNICATION COMMAND CODES */
#define COMM_ERROR_ESCAPE
#define COMM_SET_DURATION
#define COMM_BIT_IO
#define COMM_PULSE
#define COMM_1_WIRE_RESET
#define COMM_BYTE_IO
#define COMM_MATCH_ACCESS
#define COMM_BLOCK_IO
#define COMM_READ_STRAIGHT
#define COMM_DO_RELEASE
#define COMM_SET_PATH
#define COMM_WRITE_SRAM_PAGE
#define COMM_WRITE_EPROM
#define COMM_READ_CRC_PROT_PAGE
#define COMM_READ_REDIRECT_PAGE_CRC
#define COMM_SEARCH_ACCESS

/* Communication command bits */
#define COMM_TYPE
#define COMM_SE
#define COMM_D
#define COMM_Z
#define COMM_CH
#define COMM_SM
#define COMM_R
#define COMM_IM

#define COMM_PS
#define COMM_PST
#define COMM_CIB
#define COMM_RTS
#define COMM_DT
#define COMM_SPU
#define COMM_F
#define COMM_NTF
#define COMM_ICP
#define COMM_RST

#define PULSE_PROG
#define PULSE_SPUE

#define BRANCH_MAIN
#define BRANCH_AUX

/* Status flags */
#define ST_SPUA
#define ST_PRGA
#define ST_12VP
#define ST_PMOD
#define ST_HALT
#define ST_IDLE
#define ST_EPOF
/* Status transfer size, 16 bytes status, 16 byte result flags */
#define ST_SIZE
/* 1-wire data i/o fifo size, 128 bytes */
#define FIFO_SIZE

/* Result Register flags */
#define RR_DETECT
#define RR_NRS
#define RR_SH
#define RR_APP
#define RR_VPP
#define RR_CMP
#define RR_CRC
#define RR_RDP
#define RR_EOS

#define SPEED_NORMAL
#define SPEED_FLEXIBLE
#define SPEED_OVERDRIVE

#define NUM_EP
#define EP_CONTROL
#define EP_STATUS
#define EP_DATA_OUT
#define EP_DATA_IN

struct ds_device {};

struct ds_status {};

static LIST_HEAD(ds_devices);
static DEFINE_MUTEX(ds_mutex);

static int ds_send_control_cmd(struct ds_device *dev, u16 value, u16 index)
{}

static int ds_send_control_mode(struct ds_device *dev, u16 value, u16 index)
{}

static int ds_send_control(struct ds_device *dev, u16 value, u16 index)
{}

static void ds_dump_status(struct ds_device *ds_dev, unsigned char *buf, int count)
{}

static int ds_recv_status(struct ds_device *dev, struct ds_status *st)
{}

static void ds_reset_device(struct ds_device *dev)
{}

static int ds_recv_data(struct ds_device *dev, unsigned char *buf, int size)
{}

static int ds_send_data(struct ds_device *dev, unsigned char *buf, int len)
{}

#if 0

int ds_stop_pulse(struct ds_device *dev, int limit)
{
	struct ds_status st;
	int count = 0, err = 0;

	do {
		err = ds_send_control(dev, CTL_HALT_EXE_IDLE, 0);
		if (err)
			break;
		err = ds_send_control(dev, CTL_RESUME_EXE, 0);
		if (err)
			break;
		err = ds_recv_status(dev, &st);
		if (err)
			break;

		if ((st.status & ST_SPUA) == 0) {
			err = ds_send_control_mode(dev, MOD_PULSE_EN, 0);
			if (err)
				break;
		}
	} while (++count < limit);

	return err;
}

int ds_detect(struct ds_device *dev, struct ds_status *st)
{
	int err;

	err = ds_send_control_cmd(dev, CTL_RESET_DEVICE, 0);
	if (err)
		return err;

	err = ds_send_control(dev, COMM_SET_DURATION | COMM_IM, 0);
	if (err)
		return err;

	err = ds_send_control(dev, COMM_SET_DURATION | COMM_IM | COMM_TYPE, 0x40);
	if (err)
		return err;

	err = ds_send_control_mode(dev, MOD_PULSE_EN, PULSE_PROG);
	if (err)
		return err;

	err = ds_dump_status(dev, st);

	return err;
}

#endif  /*  0  */

static int ds_wait_status(struct ds_device *dev, struct ds_status *st)
{}

static int ds_reset(struct ds_device *dev)
{}

#if 0
static int ds_set_speed(struct ds_device *dev, int speed)
{
	int err;

	if (speed != SPEED_NORMAL && speed != SPEED_FLEXIBLE && speed != SPEED_OVERDRIVE)
		return -EINVAL;

	if (speed != SPEED_OVERDRIVE)
		speed = SPEED_FLEXIBLE;

	speed &= 0xff;

	err = ds_send_control_mode(dev, MOD_1WIRE_SPEED, speed);
	if (err)
		return err;

	return err;
}
#endif  /*  0  */

static int ds_set_pullup(struct ds_device *dev, int delay)
{}

static int ds_touch_bit(struct ds_device *dev, u8 bit, u8 *tbit)
{}

#if 0
static int ds_write_bit(struct ds_device *dev, u8 bit)
{
	int err;
	struct ds_status st;

	/* Set COMM_ICP to write without a readback.  Note, this will
	 * produce one time slot, a down followed by an up with COMM_D
	 * only determing the timing.
	 */
	err = ds_send_control(dev, COMM_BIT_IO | COMM_IM | COMM_ICP |
		(bit ? COMM_D : 0), 0);
	if (err)
		return err;

	ds_wait_status(dev, &st);

	return 0;
}
#endif

static int ds_write_byte(struct ds_device *dev, u8 byte)
{}

static int ds_read_byte(struct ds_device *dev, u8 *byte)
{}

static int read_block_chunk(struct ds_device *dev, u8 *buf, int len)
{}

static int ds_read_block(struct ds_device *dev, u8 *buf, int len)
{}

static int ds_write_block(struct ds_device *dev, u8 *buf, int len)
{}

static void ds9490r_search(void *data, struct w1_master *master,
	u8 search_type, w1_slave_found_callback callback)
{}

#if 0
/*
 * FIXME: if this disabled code is ever used in the future all ds_send_data()
 * calls must be changed to use a DMAable buffer.
 */
static int ds_match_access(struct ds_device *dev, u64 init)
{
	int err;
	struct ds_status st;

	err = ds_send_data(dev, (unsigned char *)&init, sizeof(init));
	if (err)
		return err;

	ds_wait_status(dev, &st);

	err = ds_send_control(dev, COMM_MATCH_ACCESS | COMM_IM | COMM_RST, 0x0055);
	if (err)
		return err;

	ds_wait_status(dev, &st);

	return 0;
}

static int ds_set_path(struct ds_device *dev, u64 init)
{
	int err;
	struct ds_status st;
	u8 buf[9];

	memcpy(buf, &init, 8);
	buf[8] = BRANCH_MAIN;

	err = ds_send_data(dev, buf, sizeof(buf));
	if (err)
		return err;

	ds_wait_status(dev, &st);

	err = ds_send_control(dev, COMM_SET_PATH | COMM_IM | COMM_RST, 0);
	if (err)
		return err;

	ds_wait_status(dev, &st);

	return 0;
}

#endif  /*  0  */

static u8 ds9490r_touch_bit(void *data, u8 bit)
{}

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

	ds_write_bit(dev, bit);
}

static u8 ds9490r_read_bit(void *data)
{
	struct ds_device *dev = data;
	int err;

	err = ds_touch_bit(dev, 1, &dev->byte_buf);
	if (err)
		return 0;

	return dev->byte_buf & 1;
}
#endif

static void ds9490r_write_byte(void *data, u8 byte)
{}

static u8 ds9490r_read_byte(void *data)
{}

static void ds9490r_write_block(void *data, const u8 *buf, int len)
{}

static u8 ds9490r_read_block(void *data, u8 *buf, int len)
{}

static u8 ds9490r_reset(void *data)
{}

static u8 ds9490r_set_pullup(void *data, int delay)
{}

static int ds_w1_init(struct ds_device *dev)
{}

static void ds_w1_fini(struct ds_device *dev)
{}

static int ds_probe(struct usb_interface *intf,
		    const struct usb_device_id *udev_id)
{}

static void ds_disconnect(struct usb_interface *intf)
{}

static const struct usb_device_id ds_id_table[] =;
MODULE_DEVICE_TABLE(usb, ds_id_table);

static struct usb_driver ds_driver =;
module_usb_driver();

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();