From a5fd9139f74c722a190b3bd69bbd611a8d91b388 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 7 Jan 2009 18:08:58 -0800 Subject: w1: add 1-wire master driver for i.MX27 / i.MX31 This patch adds support for the 1-wire master interface for i.MX27 and i.MX31. Signed-off-by: Luotao Fu Signed-off-by: Sascha Hauer Signed-off-by: Evgeniy Polyakov Cc: Russell King Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- Documentation/w1/masters/00-INDEX | 2 ++ Documentation/w1/masters/mxc-w1 | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 Documentation/w1/masters/mxc-w1 (limited to 'Documentation/w1') diff --git a/Documentation/w1/masters/00-INDEX b/Documentation/w1/masters/00-INDEX index 7b0ceaaad7af..d63fa024ac05 100644 --- a/Documentation/w1/masters/00-INDEX +++ b/Documentation/w1/masters/00-INDEX @@ -4,5 +4,7 @@ ds2482 - The Maxim/Dallas Semiconductor DS2482 provides 1-wire busses. ds2490 - The Maxim/Dallas Semiconductor DS2490 builds USB <-> W1 bridges. +mxc_w1 + - W1 master controller driver found on Freescale MX2/MX3 SoCs w1-gpio - GPIO 1-wire bus master driver. diff --git a/Documentation/w1/masters/mxc-w1 b/Documentation/w1/masters/mxc-w1 new file mode 100644 index 000000000000..97f6199a7f39 --- /dev/null +++ b/Documentation/w1/masters/mxc-w1 @@ -0,0 +1,11 @@ +Kernel driver mxc_w1 +==================== + +Supported chips: + * Freescale MX27, MX31 and probably other i.MX SoCs + Datasheets: + http://www.freescale.com/files/32bit/doc/data_sheet/MCIMX31.pdf?fpsp=1 + http://www.freescale.com/files/dsp/MCIMX27.pdf?fpsp=1 + +Author: Originally based on Freescale code, prepared for mainline by + Sascha Hauer -- cgit v1.2.3 From e4e056aa3518197830c884b85268799b1868e8e3 Mon Sep 17 00:00:00 2001 From: Evgeniy Polyakov Date: Wed, 7 Jan 2009 18:09:02 -0800 Subject: w1: documentation update Signed-off-by: Evgeniy Polyakov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- Documentation/w1/w1.netlink | 129 +++++++++++++++++++++++++++++++------------- 1 file changed, 91 insertions(+), 38 deletions(-) (limited to 'Documentation/w1') diff --git a/Documentation/w1/w1.netlink b/Documentation/w1/w1.netlink index 3640c7c87d45..d596d406e0a5 100644 --- a/Documentation/w1/w1.netlink +++ b/Documentation/w1/w1.netlink @@ -5,69 +5,122 @@ 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. +1. Events. They are generated each time new master or slave device + found either due to automatic or requested search. +2. Userspace commands. 3. Replies to userspace commands. Protocol. ======== -[struct cn_msg] - connector header. It's length field is equal to size of the attached data. +[struct cn_msg] - connector header. + Its 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). + W1_LIST_MASTERS + list current bus masters + 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/touch) __u8 res - reserved - __u16 len - size of attached to this header data. + __u16 len - size of data attached to this header data union { - __u8 id; - slave unique device id + __u8 id[8]; - slave unique device id struct w1_mst { - __u32 id; - master's id. + __u32 id; - master's id __u32 res; - reserved } mst; } id; -[strucrt w1_netlink_cmd] - command for gived master or slave device. +[struct w1_netlink_cmd] - command for given 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. + W1_CMD_READ - read command + W1_CMD_WRITE - write command + W1_CMD_TOUCH - touch command + (write and sample data back to userspace) + 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. + __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. +Each connector message can include one or more w1_netlink_msg with +zero or 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. +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: -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; +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; +Replies to W1_LIST_MASTERS should send a message back to the userspace +which will contain list of all registered master ids in the following +format: + + cn_msg (CN_W1_IDX.CN_W1_VAL as id, len is equal to sizeof(struct + w1_netlink_msg) plus number of masters multipled by 4) + w1_netlink_msg (type: W1_LIST_MASTERS, len is equal to + number of masters multiplied by 4 (u32 size)) + id0 ... idN + + Each message is at most 4k in size, so if number of master devices + exceeds this, it will be split into several messages, + cn.seq will be increased for each one. + +W1 search and alarm search commands. +request: +[cn_msg] + [w1_netlink_msg type = W1_MASTER_CMD + id is equal to the bus master id to use for searching] + [w1_netlink_cmd cmd = W1_CMD_SEARCH or W1_CMD_ALARM_SEARCH] + +reply: + [cn_msg, ack = 1 and increasing, 0 means the last message, + seq is equal to the request seq] + [w1_netlink_msg type = W1_MASTER_CMD] + [w1_netlink_cmd cmd = W1_CMD_SEARCH or W1_CMD_ALARM_SEARCH + len is equal to number of IDs multiplied by 8] + [64bit-id0 ... 64bit-idN] +Length in each header corresponds to the size of the data behind it, so +w1_netlink_cmd->len = N * 8; where N is number of IDs in this message. + Can be zero. +w1_netlink_msg->len = sizeof(struct w1_netlink_cmd) + N * 8; +cn_msg->len = sizeof(struct w1_netlink_msg) + + sizeof(struct w1_netlink_cmd) + + N*8; 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. +When new message (w1_netlink_msg) is received w1 core detects if it is +master or 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. +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. @@ -82,8 +135,8 @@ 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 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. @@ -93,6 +146,6 @@ 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. +2. http://www.ioremap.net/archive/w1 +This archive includes userspace application w1d.c which uses +read/write/search commands for all master/slave devices found on the bus. -- cgit v1.2.3 From f89735c4e281e8642907b38640c076ae5048f3a6 Mon Sep 17 00:00:00 2001 From: Evgeniy Polyakov Date: Wed, 7 Jan 2009 18:09:04 -0800 Subject: w1: added w1 reset command Command which allows to reset the bus. Signed-off-by: Evgeniy Polyakov Cc: Paul Alfille Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- Documentation/w1/w1.netlink | 6 ++++++ drivers/w1/w1_netlink.c | 3 +++ drivers/w1/w1_netlink.h | 1 + 3 files changed, 10 insertions(+) (limited to 'Documentation/w1') diff --git a/Documentation/w1/w1.netlink b/Documentation/w1/w1.netlink index d596d406e0a5..2756681b6ef5 100644 --- a/Documentation/w1/w1.netlink +++ b/Documentation/w1/w1.netlink @@ -112,6 +112,12 @@ cn_msg->len = sizeof(struct w1_netlink_msg) + sizeof(struct w1_netlink_cmd) + N*8; +W1 reset command. +[cn_msg] + [w1_netlink_msg type = W1_MASTER_CMD + id is equal to the bus master id to use for searching] + [w1_netlink_cmd cmd = W1_CMD_RESET] + Operation steps in w1 core when new command is received. ======================================================= diff --git a/drivers/w1/w1_netlink.c b/drivers/w1/w1_netlink.c index a94336be7654..f978c7504004 100644 --- a/drivers/w1/w1_netlink.c +++ b/drivers/w1/w1_netlink.c @@ -197,6 +197,9 @@ static int w1_process_command_master(struct w1_master *dev, struct cn_msg *req_m case W1_CMD_TOUCH: err = w1_process_command_io(dev, msg, hdr, cmd); break; + case W1_CMD_RESET: + err = w1_reset_bus(dev); + break; default: cmd->res = EINVAL; cn_netlink_send(msg, 0, GFP_KERNEL); diff --git a/drivers/w1/w1_netlink.h b/drivers/w1/w1_netlink.h index 01d86a71cf32..68a4ff46cb96 100644 --- a/drivers/w1/w1_netlink.h +++ b/drivers/w1/w1_netlink.h @@ -58,6 +58,7 @@ enum w1_commands { W1_CMD_SEARCH, W1_CMD_ALARM_SEARCH, W1_CMD_TOUCH, + W1_CMD_RESET, W1_CMD_MAX, }; -- cgit v1.2.3 From 4037014e3fb71e998189374e19ca141c59d15323 Mon Sep 17 00:00:00 2001 From: Evgeniy Polyakov Date: Wed, 7 Jan 2009 18:09:05 -0800 Subject: w1: send status messages after command processing Send completion status of the commands to the userspace. Message and protocol are described in the documentation. Signed-off-by: Evgeniy Polyakov Cc: Paul Alfille Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- Documentation/w1/w1.netlink | 29 +++++++++++++++++++++++++ drivers/w1/w1_netlink.c | 53 +++++++++++++++++++++++++++++++++++++++------ drivers/w1/w1_netlink.h | 2 +- 3 files changed, 76 insertions(+), 8 deletions(-) (limited to 'Documentation/w1') diff --git a/Documentation/w1/w1.netlink b/Documentation/w1/w1.netlink index 2756681b6ef5..804445f745ed 100644 --- a/Documentation/w1/w1.netlink +++ b/Documentation/w1/w1.netlink @@ -118,6 +118,35 @@ W1 reset command. id is equal to the bus master id to use for searching] [w1_netlink_cmd cmd = W1_CMD_RESET] + +Command status replies. +====================== + +Each command (either root, master or slave with or without w1_netlink_cmd +structure) will be 'acked' by the w1 core. Format of the reply is the same +as request message except that length parameters do not account for data +requested by the user, i.e. read/write/touch IO requests will not contain +data, so w1_netlink_cmd.len will be 0, w1_netlink_msg.len will be size +of the w1_netlink_cmd structure and cn_msg.len will be equal to the sum +of the sizeof(struct w1_netlink_msg) and sizeof(struct w1_netlink_cmd). +If reply is generated for master or root command (which do not have +w1_netlink_cmd attached), reply will contain only cn_msg and w1_netlink_msg +structires. + +w1_netlink_msg.status field will carry positive error value +(EINVAL for example) or zero in case of success. + +All other fields in every structure will mirror the same parameters in the +request message (except lengths as described above). + +Status reply is generated for every w1_netlink_cmd embedded in the +w1_netlink_msg, if there are no w1_netlink_cmd structures, +reply will be generated for the w1_netlink_msg. + +All w1_netlink_cmd command structures are handled in every w1_netlink_msg, +even if there were errors, only length mismatch interrupts message processing. + + Operation steps in w1 core when new command is received. ======================================================= diff --git a/drivers/w1/w1_netlink.c b/drivers/w1/w1_netlink.c index f978c7504004..fdf72851c574 100644 --- a/drivers/w1/w1_netlink.c +++ b/drivers/w1/w1_netlink.c @@ -152,7 +152,7 @@ static int w1_process_command_io(struct w1_master *dev, struct cn_msg *msg, w1_write_block(dev, cmd->data, cmd->len); break; default: - err = -1; + err = -EINVAL; break; } @@ -195,14 +195,13 @@ static int w1_process_command_master(struct w1_master *dev, struct cn_msg *req_m case W1_CMD_READ: case W1_CMD_WRITE: case W1_CMD_TOUCH: - err = w1_process_command_io(dev, msg, hdr, cmd); + err = w1_process_command_io(dev, req_msg, req_hdr, req_cmd); break; case W1_CMD_RESET: err = w1_reset_bus(dev); break; default: - cmd->res = EINVAL; - cn_netlink_send(msg, 0, GFP_KERNEL); + err = -EINVAL; break; } @@ -246,7 +245,7 @@ static int w1_process_command_root(struct cn_msg *msg, struct w1_netlink_msg *mc w = (struct w1_netlink_msg *)(cn + 1); w->type = W1_LIST_MASTERS; - w->reserved = 0; + w->status = 0; w->len = 0; id = (u32 *)(w + 1); @@ -273,6 +272,40 @@ static int w1_process_command_root(struct cn_msg *msg, struct w1_netlink_msg *mc return 0; } +static int w1_netlink_send_error(struct cn_msg *rcmsg, struct w1_netlink_msg *rmsg, + struct w1_netlink_cmd *rcmd, int error) +{ + struct cn_msg *cmsg; + struct w1_netlink_msg *msg; + struct w1_netlink_cmd *cmd; + + cmsg = kzalloc(sizeof(*msg) + sizeof(*cmd) + sizeof(*cmsg), GFP_KERNEL); + if (!cmsg) + return -ENOMEM; + + msg = (struct w1_netlink_msg *)(cmsg + 1); + cmd = (struct w1_netlink_cmd *)(msg + 1); + + memcpy(cmsg, rcmsg, sizeof(*cmsg)); + cmsg->len = sizeof(*msg); + + memcpy(msg, rmsg, sizeof(*msg)); + msg->len = 0; + msg->status = (short)-error; + + if (rcmd) { + memcpy(cmd, rcmd, sizeof(*cmd)); + cmd->len = 0; + msg->len += sizeof(*cmd); + cmsg->len += sizeof(*cmd); + } + + error = cn_netlink_send(cmsg, 0, GFP_KERNEL); + kfree(cmsg); + + return error; +} + static void w1_cn_callback(void *data) { struct cn_msg *msg = data; @@ -289,6 +322,7 @@ static void w1_cn_callback(void *data) dev = NULL; sl = NULL; + cmd = NULL; memcpy(&id, m->id.id, sizeof(id)); #if 0 @@ -336,9 +370,12 @@ static void w1_cn_callback(void *data) } if (sl) - w1_process_command_slave(sl, msg, m, cmd); + err = w1_process_command_slave(sl, msg, m, cmd); else - w1_process_command_master(dev, msg, m, cmd); + err = w1_process_command_master(dev, msg, m, cmd); + + w1_netlink_send_error(msg, m, cmd, err); + err = 0; cmd_data += cmd->len + sizeof(struct w1_netlink_cmd); mlen -= cmd->len + sizeof(struct w1_netlink_cmd); @@ -349,6 +386,8 @@ out_up: atomic_dec(&sl->refcnt); mutex_unlock(&dev->mutex); out_cont: + if (!cmd || err) + w1_netlink_send_error(msg, m, cmd, err); msg->len -= sizeof(struct w1_netlink_msg) + m->len; m = (struct w1_netlink_msg *)(((u8 *)m) + sizeof(struct w1_netlink_msg) + m->len); diff --git a/drivers/w1/w1_netlink.h b/drivers/w1/w1_netlink.h index 68a4ff46cb96..27e950f935b1 100644 --- a/drivers/w1/w1_netlink.h +++ b/drivers/w1/w1_netlink.h @@ -40,7 +40,7 @@ enum w1_netlink_message_types { struct w1_netlink_msg { __u8 type; - __u8 reserved; + __u8 status; __u16 len; union { __u8 id[8]; -- cgit v1.2.3