Commit eaa85689 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/w1-2.6

* master.kernel.org:/pub/scm/linux/kernel/git/gregkh/w1-2.6:
  [PATCH] w1: warning fix
  [PATCH] w1: clean up W1_CON dependency.
  [PATCH] drivers/w1/w1.c: fix a compile error
  [PATCH] W1: fix dependencies of W1_SLAVE_DS2433_CRC
  [PATCH] W1: possible cleanups
  [PATCH] W1: cleanups
  [PATCH] w1 exports
  [PATCH] w1: Use mutexes instead of semaphores.
  [PATCH] w1: Make w1 connector notifications depend on connector.
  [PATCH] w1: netlink: Mark netlink group 1 as unused.
  [PATCH] w1: Move w1-connector definitions into linux/include/connector.h
  [PATCH] w1: Userspace communication protocol over connector.
  [PATCH] w1: Replace dscore and ds_w1_bridge with ds2490 driver.
  [PATCH] w1: Added default generic read/write operations.
parents 6c763eb9 c6976a4e
Kernel driver ds2490
====================
Supported chips:
* Maxim DS2490 based
Author: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Description
-----------
The Maixm/Dallas Semiconductor DS2490 is a chip
which allows to build USB <-> W1 bridges.
DS9490(R) is a USB <-> W1 bus master device
which has 0x81 family ID integrated chip and DS2490
low-level operational chip.
......@@ -27,8 +27,19 @@ When a w1 master driver registers with the w1 subsystem, the following occurs:
When a device is found on the bus, w1 core checks if driver for it's family is
loaded. If so, the family driver is attached to the slave.
If there is no driver for the family, a simple sysfs entry is created
for the slave device.
If there is no driver for the family, default one is assigned, which allows to perform
almost any kind of operations. Each logical operation is a transaction
in nature, which can contain several (two or one) low-level operations.
Let's see how one can read EEPROM context:
1. one must write control buffer, i.e. buffer containing command byte
and two byte address. At this step bus is reset and appropriate device
is selected using either W1_SKIP_ROM or W1_MATCH_ROM command.
Then provided control buffer is being written to the wire.
2. reading. This will issue reading eeprom response.
It is possible that between 1. and 2. w1 master thread will reset bus for searching
and slave device will be even removed, but in this case 0xff will
be read, since no device was selected.
W1 device families
......@@ -89,4 +100,5 @@ driver - (standard) symlink to the w1 driver
name - the device name, usually the same as the directory name
w1_slave - (optional) a binary file whose meaning depends on the
family driver
rw - (optional) created for slave devices which do not have
appropriate family driver. Allows to read/write binary data.
Userspace communication protocol over connector [1].
Message types.
=============
There are three types of messages between w1 core and userspace:
1. Events. They are generated each time new master or slave device found
either due to automatic or requested search.
2. Userspace commands. Includes read/write and search/alarm search comamnds.
3. Replies to userspace commands.
Protocol.
========
[struct cn_msg] - connector header. It's length field is equal to size of the attached data.
[struct w1_netlink_msg] - w1 netlink header.
__u8 type - message type.
W1_SLAVE_ADD/W1_SLAVE_REMOVE - slave add/remove events.
W1_MASTER_ADD/W1_MASTER_REMOVE - master add/remove events.
W1_MASTER_CMD - userspace command for bus master device (search/alarm search).
W1_SLAVE_CMD - userspace command for slave device (read/write/ search/alarm search
for bus master device where given slave device found).
__u8 res - reserved
__u16 len - size of attached to this header data.
union {
__u8 id; - slave unique device id
struct w1_mst {
__u32 id; - master's id.
__u32 res; - reserved
} mst;
} id;
[strucrt w1_netlink_cmd] - command for gived master or slave device.
__u8 cmd - command opcode.
W1_CMD_READ - read command.
W1_CMD_WRITE - write command.
W1_CMD_SEARCH - search command.
W1_CMD_ALARM_SEARCH - alarm search command.
__u8 res - reserved
__u16 len - length of data for this command.
For read command data must be allocated like for write command.
__u8 data[0] - data for this command.
Each connector message can include one or more w1_netlink_msg with zero of more attached w1_netlink_cmd messages.
For event messages there are no w1_netlink_cmd embedded structures, only connector header
and w1_netlink_msg strucutre with "len" field being zero and filled type (one of event types)
and id - either 8 bytes of slave unique id in host order, or master's id, which is assigned
to bus master device when it is added to w1 core.
Currently replies to userspace commands are only generated for read command request.
One reply is generated exactly for one w1_netlink_cmd read request.
Replies are not combined when sent - i.e. typical reply messages looks like the following:
[cn_msg][w1_netlink_msg][w1_netlink_cmd]
cn_msg.len = sizeof(struct w1_netlink_msg) + sizeof(struct w1_netlink_cmd) + cmd->len;
w1_netlink_msg.len = sizeof(struct w1_netlink_cmd) + cmd->len;
w1_netlink_cmd.len = cmd->len;
Operation steps in w1 core when new command is received.
=======================================================
When new message (w1_netlink_msg) is received w1 core detects if it is master of slave request,
according to w1_netlink_msg.type field.
Then master or slave device is searched for.
When found, master device (requested or those one on where slave device is found) is locked.
If slave command is requested, then reset/select procedure is started to select given device.
Then all requested in w1_netlink_msg operations are performed one by one.
If command requires reply (like read command) it is sent on command completion.
When all commands (w1_netlink_cmd) are processed muster device is unlocked
and next w1_netlink_msg header processing started.
Connector [1] specific documentation.
====================================
Each connector message includes two u32 fields as "address".
w1 uses CN_W1_IDX and CN_W1_VAL defined in include/linux/connector.h header.
Each message also includes sequence and acknowledge numbers.
Sequence number for event messages is appropriate bus master sequence number increased with
each event message sent "through" this master.
Sequence number for userspace requests is set by userspace application.
Sequence number for reply is the same as was in request, and
acknowledge number is set to seq+1.
Additional documantion, source code examples.
============================================
1. Documentation/connector
2. http://tservice.net.ru/~s0mbre/archive/w1
This archive includes userspace application w1d.c which
uses read/write/search commands for all master/slave devices found on the bus.
......@@ -3,7 +3,7 @@ menu "Dallas's 1-wire bus"
config W1
tristate "Dallas's 1-wire support"
---help---
Dallas's 1-wire bus is useful to connect slow 1-pin devices
Dallas' 1-wire bus is useful to connect slow 1-pin devices
such as iButtons and thermal sensors.
If you want W1 support, you should say Y here.
......@@ -11,6 +11,18 @@ config W1
This W1 support can also be built as a module. If so, the module
will be called wire.ko.
config W1_CON
depends on CONNECTOR && W1
bool "Userspace communication over connector"
default y
--- help ---
This allows to communicate with userspace using connector [Documentation/connector].
There are three types of messages between w1 core and userspace:
1. Events. They are generated each time new master or slave device found
either due to automatic or requested search.
2. Userspace commands. Includes read/write and search/alarm search comamnds.
3. Replies to userspace commands.
source drivers/w1/masters/Kconfig
source drivers/w1/slaves/Kconfig
......
......@@ -2,10 +2,6 @@
# Makefile for the Dallas's 1-wire bus.
#
ifneq ($(CONFIG_NET), y)
EXTRA_CFLAGS += -DNETLINK_DISABLED
endif
ifeq ($(CONFIG_W1_DS2433_CRC), y)
EXTRA_CFLAGS += -DCONFIG_W1_F23_CRC
endif
......
......@@ -15,24 +15,15 @@ config W1_MASTER_MATROX
This support is also available as a module. If so, the module
will be called matrox_w1.ko.
config W1_MASTER_DS9490
tristate "DS9490R transport layer driver"
depends on W1 && USB
help
Say Y here if you want to have a driver for DS9490R UWB <-> W1 bridge.
This support is also available as a module. If so, the module
will be called ds9490r.ko.
config W1_MASTER_DS9490_BRIDGE
tristate "DS9490R USB <-> W1 transport layer for 1-wire"
depends on W1_MASTER_DS9490
help
Say Y here if you want to communicate with your 1-wire devices
using DS9490R USB bridge.
This support is also available as a module. If so, the module
will be called ds_w1_bridge.ko.
config W1_MASTER_DS2490
tristate "DS2490 USB <-> W1 transport layer for 1-wire"
depends on W1 && USB
help
Say Y here if you want to have a driver for DS2490 based USB <-> W1 bridges,
for example DS9490*.
This support is also available as a module. If so, the module
will be called ds2490.ko.
config W1_MASTER_DS2482
tristate "Maxim DS2482 I2C to 1-Wire bridge"
......
......@@ -3,11 +3,6 @@
#
obj-$(CONFIG_W1_MASTER_MATROX) += matrox_w1.o
obj-$(CONFIG_W1_MASTER_DS9490) += ds9490r.o
ds9490r-objs := dscore.o
obj-$(CONFIG_W1_MASTER_DS9490_BRIDGE) += ds_w1_bridge.o
obj-$(CONFIG_W1_MASTER_DS2490) += ds2490.o
obj-$(CONFIG_W1_MASTER_DS2482) += ds2482.o
......@@ -125,7 +125,7 @@ struct ds2482_w1_chan {
struct ds2482_data {
struct i2c_client client;
struct semaphore access_lock;
struct mutex access_lock;
/* 1-wire interface(s) */
int w1_count; /* 1 or 8 */
......@@ -265,7 +265,7 @@ static u8 ds2482_w1_touch_bit(void *data, u8 bit)
struct ds2482_data *pdev = pchan->pdev;
int status = -1;
down(&pdev->access_lock);
mutex_lock(&pdev->access_lock);
/* Select the channel */
ds2482_wait_1wire_idle(pdev);
......@@ -277,7 +277,7 @@ static u8 ds2482_w1_touch_bit(void *data, u8 bit)
bit ? 0xFF : 0))
status = ds2482_wait_1wire_idle(pdev);
up(&pdev->access_lock);
mutex_unlock(&pdev->access_lock);
return (status & DS2482_REG_STS_SBR) ? 1 : 0;
}
......@@ -297,7 +297,7 @@ static u8 ds2482_w1_triplet(void *data, u8 dbit)
struct ds2482_data *pdev = pchan->pdev;
int status = (3 << 5);
down(&pdev->access_lock);
mutex_lock(&pdev->access_lock);
/* Select the channel */
ds2482_wait_1wire_idle(pdev);
......@@ -309,7 +309,7 @@ static u8 ds2482_w1_triplet(void *data, u8 dbit)
dbit ? 0xFF : 0))
status = ds2482_wait_1wire_idle(pdev);
up(&pdev->access_lock);
mutex_unlock(&pdev->access_lock);
/* Decode the status */
return (status >> 5);
......@@ -326,7 +326,7 @@ static void ds2482_w1_write_byte(void *data, u8 byte)
struct ds2482_w1_chan *pchan = data;
struct ds2482_data *pdev = pchan->pdev;
down(&pdev->access_lock);
mutex_lock(&pdev->access_lock);
/* Select the channel */
ds2482_wait_1wire_idle(pdev);
......@@ -336,7 +336,7 @@ static void ds2482_w1_write_byte(void *data, u8 byte)
/* Send the write byte command */
ds2482_send_cmd_data(pdev, DS2482_CMD_1WIRE_WRITE_BYTE, byte);
up(&pdev->access_lock);
mutex_unlock(&pdev->access_lock);
}
/**
......@@ -351,7 +351,7 @@ static u8 ds2482_w1_read_byte(void *data)
struct ds2482_data *pdev = pchan->pdev;
int result;
down(&pdev->access_lock);
mutex_lock(&pdev->access_lock);
/* Select the channel */
ds2482_wait_1wire_idle(pdev);
......@@ -370,7 +370,7 @@ static u8 ds2482_w1_read_byte(void *data)
/* Read the data byte */
result = i2c_smbus_read_byte(&pdev->client);
up(&pdev->access_lock);
mutex_unlock(&pdev->access_lock);
return result;
}
......@@ -389,7 +389,7 @@ static u8 ds2482_w1_reset_bus(void *data)
int err;
u8 retval = 1;
down(&pdev->access_lock);
mutex_lock(&pdev->access_lock);
/* Select the channel */
ds2482_wait_1wire_idle(pdev);
......@@ -409,7 +409,7 @@ static u8 ds2482_w1_reset_bus(void *data)
0xF0);
}
up(&pdev->access_lock);
mutex_unlock(&pdev->access_lock);
return retval;
}
......@@ -482,7 +482,7 @@ static int ds2482_detect(struct i2c_adapter *adapter, int address, int kind)
snprintf(new_client->name, sizeof(new_client->name), "ds2482-%d00",
data->w1_count);
init_MUTEX(&data->access_lock);
mutex_init(&data->access_lock);
/* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client)))
......
......@@ -24,7 +24,136 @@
#include <linux/mod_devicetable.h>
#include <linux/usb.h>
#include "dscore.h"
#include "../w1_int.h"
#include "../w1.h"
/* COMMAND TYPE CODES */
#define CONTROL_CMD 0x00
#define COMM_CMD 0x01
#define MODE_CMD 0x02
/* CONTROL COMMAND CODES */
#define CTL_RESET_DEVICE 0x0000
#define CTL_START_EXE 0x0001
#define CTL_RESUME_EXE 0x0002
#define CTL_HALT_EXE_IDLE 0x0003
#define CTL_HALT_EXE_DONE 0x0004
#define CTL_FLUSH_COMM_CMDS 0x0007
#define CTL_FLUSH_RCV_BUFFER 0x0008
#define CTL_FLUSH_XMT_BUFFER 0x0009
#define CTL_GET_COMM_CMDS 0x000A
/* MODE COMMAND CODES */
#define MOD_PULSE_EN 0x0000
#define MOD_SPEED_CHANGE_EN 0x0001
#define MOD_1WIRE_SPEED 0x0002
#define MOD_STRONG_PU_DURATION 0x0003
#define MOD_PULLDOWN_SLEWRATE 0x0004
#define MOD_PROG_PULSE_DURATION 0x0005
#define MOD_WRITE1_LOWTIME 0x0006
#define MOD_DSOW0_TREC 0x0007
/* COMMUNICATION COMMAND CODES */
#define COMM_ERROR_ESCAPE 0x0601
#define COMM_SET_DURATION 0x0012
#define COMM_BIT_IO 0x0020
#define COMM_PULSE 0x0030
#define COMM_1_WIRE_RESET 0x0042
#define COMM_BYTE_IO 0x0052
#define COMM_MATCH_ACCESS 0x0064
#define COMM_BLOCK_IO 0x0074
#define COMM_READ_STRAIGHT 0x0080
#define COMM_DO_RELEASE 0x6092
#define COMM_SET_PATH 0x00A2
#define COMM_WRITE_SRAM_PAGE 0x00B2
#define COMM_WRITE_EPROM 0x00C4
#define COMM_READ_CRC_PROT_PAGE 0x00D4
#define COMM_READ_REDIRECT_PAGE_CRC 0x21E4
#define COMM_SEARCH_ACCESS 0x00F4
/* Communication command bits */
#define COMM_TYPE 0x0008
#define COMM_SE 0x0008
#define COMM_D 0x0008
#define COMM_Z 0x0008
#define COMM_CH 0x0008
#define COMM_SM 0x0008
#define COMM_R 0x0008
#define COMM_IM 0x0001
#define COMM_PS 0x4000
#define COMM_PST 0x4000
#define COMM_CIB 0x4000
#define COMM_RTS 0x4000
#define COMM_DT 0x2000
#define COMM_SPU 0x1000
#define COMM_F 0x0800
#define COMM_NTP 0x0400
#define COMM_ICP 0x0200
#define COMM_RST 0x0100
#define PULSE_PROG 0x01
#define PULSE_SPUE 0x02
#define BRANCH_MAIN 0xCC
#define BRANCH_AUX 0x33
/*
* Duration of the strong pull-up pulse in milliseconds.
*/
#define PULLUP_PULSE_DURATION 750
/* Status flags */
#define ST_SPUA 0x01 /* Strong Pull-up is active */
#define ST_PRGA 0x02 /* 12V programming pulse is being generated */
#define ST_12VP 0x04 /* external 12V programming voltage is present */
#define ST_PMOD 0x08 /* DS2490 powered from USB and external sources */
#define ST_HALT 0x10 /* DS2490 is currently halted */
#define ST_IDLE 0x20 /* DS2490 is currently idle */
#define ST_EPOF 0x80
#define SPEED_NORMAL 0x00
#define SPEED_FLEXIBLE 0x01
#define SPEED_OVERDRIVE 0x02
#define NUM_EP 4
#define EP_CONTROL 0
#define EP_STATUS 1
#define EP_DATA_OUT 2
#define EP_DATA_IN 3
struct ds_device
{
struct list_head ds_entry;
struct usb_device *udev;
struct usb_interface *intf;
int ep[NUM_EP];
struct w1_bus_master master;
};
struct ds_status
{
u8 enable;
u8 speed;
u8 pullup_dur;
u8 ppuls_dur;
u8 pulldown_slew;
u8 write1_time;
u8 write0_time;
u8 reserved0;
u8 status;
u8 command0;
u8 command1;
u8 command_buffer_status;
u8 data_out_buffer_status;
u8 data_in_buffer_status;
u8 reserved1;
u8 reserved2;
};
static struct usb_device_id ds_id_table [] = {
{ USB_DEVICE(0x04fa, 0x2490) },
......@@ -35,21 +164,12 @@ MODULE_DEVICE_TABLE(usb, ds_id_table);
static int ds_probe(struct usb_interface *, const struct usb_device_id *);
static void ds_disconnect(struct usb_interface *);
int ds_touch_bit(struct ds_device *, u8, u8 *);
int ds_read_byte(struct ds_device *, u8 *);
int ds_read_bit(struct ds_device *, u8 *);
int ds_write_byte(struct ds_device *, u8);
int ds_write_bit(struct ds_device *, u8);
static int ds_start_pulse(struct ds_device *, int);
int ds_reset(struct ds_device *, struct ds_status *);
struct ds_device * ds_get_device(void);
void ds_put_device(struct ds_device *);
static inline void ds_dump_status(unsigned char *, unsigned char *, int);
static int ds_send_control(struct ds_device *, u16, u16);
static int ds_send_control_mode(struct ds_device *, u16, u16);
static int ds_send_control_cmd(struct ds_device *, u16, u16);
static LIST_HEAD(ds_devices);
static DEFINE_MUTEX(ds_mutex);
static struct usb_driver ds_driver = {
.name = "DS9490R",
......@@ -58,20 +178,6 @@ static struct usb_driver ds_driver = {
.id_table = ds_id_table,
};
static struct ds_device *ds_dev;
struct ds_device * ds_get_device(void)
{
if (ds_dev)
atomic_inc(&ds_dev->refcnt);
return ds_dev;
}
void ds_put_device(struct ds_device *dev)
{
atomic_dec(&dev->refcnt);
}
static int ds_send_control_cmd(struct ds_device *dev, u16 value, u16 index)
{
int err;
......@@ -86,7 +192,7 @@ static int ds_send_control_cmd(struct ds_device *dev, u16 value, u16 index)
return err;
}
#if 0
static int ds_send_control_mode(struct ds_device *dev, u16 value, u16 index)
{
int err;
......@@ -101,7 +207,7 @@ static int ds_send_control_mode(struct ds_device *dev, u16 value, u16 index)
return err;
}
#endif
static int ds_send_control(struct ds_device *dev, u16 value, u16 index)
{
int err;
......@@ -324,7 +430,7 @@ static int ds_wait_status(struct ds_device *dev, struct ds_status *st)
return 0;
}
int ds_reset(struct ds_device *dev, struct ds_status *st)
static int ds_reset(struct ds_device *dev, struct ds_status *st)
{
int err;
......@@ -345,7 +451,7 @@ int ds_reset(struct ds_device *dev, struct ds_status *st)
}
#if 0
int ds_set_speed(struct ds_device *dev, int speed)
static int ds_set_speed(struct ds_device *dev, int speed)
{
int err;
......@@ -395,7 +501,7 @@ static int ds_start_pulse(struct ds_device *dev, int delay)
return err;
}
int ds_touch_bit(struct ds_device *dev, u8 bit, u8 *tbit)
static int ds_touch_bit(struct ds_device *dev, u8 bit, u8 *tbit)
{
int err, count;
struct ds_status st;
......@@ -427,7 +533,7 @@ int ds_touch_bit(struct ds_device *dev, u8 bit, u8 *tbit)
return 0;
}
int ds_write_bit(struct ds_device *dev, u8 bit)
static int ds_write_bit(struct ds_device *dev, u8 bit)
{
int err;
struct ds_status st;
......@@ -441,7 +547,7 @@ int ds_write_bit(struct ds_device *dev, u8 bit)
return 0;
}
int ds_write_byte(struct ds_device *dev, u8 byte)
static int ds_write_byte(struct ds_device *dev, u8 byte)
{
int err;
struct ds_status st;
......@@ -464,26 +570,7 @@ int ds_write_byte(struct ds_device *dev, u8 byte)
return !(byte == rbyte);
}
int ds_read_bit(struct ds_device *dev, u8 *bit)
{
int err;
err = ds_send_control_mode(dev, MOD_PULSE_EN, PULSE_SPUE);
if (err)
return err;
err = ds_send_control(dev, COMM_BIT_IO | COMM_IM | COMM_SPU | COMM_D, 0);
if (err)
return err;
err = ds_recv_data(dev, bit, sizeof(*bit));
if (err < 0)
return err;
return 0;
}
int ds_read_byte(struct ds_device *dev, u8 *byte)
static int ds_read_byte(struct ds_device *dev, u8 *byte)
{
int err;
struct ds_status st;
......@@ -501,7 +588,7 @@ int ds_read_byte(struct ds_device *dev, u8 *byte)
return 0;
}
int ds_read_block(struct ds_device *dev, u8 *buf, int len)
static int ds_read_block(struct ds_device *dev, u8 *buf, int len)
{
struct ds_status st;
int err;
......@@ -527,7 +614,7 @@ int ds_read_block(struct ds_device *dev, u8 *buf, int len)
return err;
}
int ds_write_block(struct ds_device *dev, u8 *buf, int len)
static int ds_write_block(struct ds_device *dev, u8 *buf, int len)
{
int err;
struct ds_status st;
......@@ -555,7 +642,7 @@ int ds_write_block(struct ds_device *dev, u8 *buf, int len)
#if 0
int ds_search(struct ds_device *dev, u64 init, u64 *buf, u8 id_number, int conditional_search)
static int ds_search(struct ds_device *dev, u64 init, u64 *buf, u8 id_number, int conditional_search)
{
int err;
u16 value, index;
......@@ -584,7 +671,7 @@ int ds_search(struct ds_device *dev, u64 init, u64 *buf, u8 id_number, int condi
return err/8;
}
int ds_match_access(struct ds_device *dev, u64 init)
static int ds_match_access(struct ds_device *dev, u64 init)
{
int err;
struct ds_status st;
......@@ -604,7 +691,7 @@ int ds_match_access(struct ds_device *dev, u64 init)