All of lore.kernel.org
 help / color / mirror / Atom feed
From: Evgeniy Polyakov <zbr@ioremap.net>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, Evgeniy Polyakov <zbr@ioremap.net>
Subject: [W1] Added touch block command.
Date: Thu,  4 Dec 2008 17:50:07 +0300	[thread overview]
Message-ID: <12284022144105-git-send-email-zbr@ioremap.net> (raw)
In-Reply-To: <12284022143564-git-send-email-zbr@ioremap.net>


Signed-off-by: Evgeniy Polyakov <zbr@ioremap.net>
---
 drivers/w1/w1.h         |    1 +
 drivers/w1/w1_io.c      |   26 +++++++++++++++++++++++++-
 drivers/w1/w1_netlink.c |   13 +++++++++----
 drivers/w1/w1_netlink.h |    1 +
 4 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h
index 97304bd..d8a9709 100644
--- a/drivers/w1/w1.h
+++ b/drivers/w1/w1.h
@@ -210,6 +210,7 @@ u8 w1_read_8(struct w1_master *);
 int w1_reset_bus(struct w1_master *);
 u8 w1_calc_crc8(u8 *, int);
 void w1_write_block(struct w1_master *, const u8 *, int);
+void w1_touch_block(struct w1_master *, u8 *, int);
 u8 w1_read_block(struct w1_master *, u8 *, int);
 int w1_reset_select_slave(struct w1_slave *sl);
 void w1_next_pullup(struct w1_master *, int);
diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c
index 0d15b0e..3d781f8 100644
--- a/drivers/w1/w1_io.c
+++ b/drivers/w1/w1_io.c
@@ -238,7 +238,6 @@ EXPORT_SYMBOL_GPL(w1_read_8);
  * @param dev     the master device
  * @param buf     pointer to the data to write
  * @param len     the number of bytes to write
- * @return        the byte read
  */
 void w1_write_block(struct w1_master *dev, const u8 *buf, int len)
 {
@@ -256,6 +255,31 @@ void w1_write_block(struct w1_master *dev, const u8 *buf, int len)
 EXPORT_SYMBOL_GPL(w1_write_block);
 
 /**
+ * Touches a series of bytes.
+ *
+ * @param dev     the master device
+ * @param buf     pointer to the data to write
+ * @param len     the number of bytes to write
+ */
+void w1_touch_block(struct w1_master *dev, u8 *buf, int len)
+{
+	int i, j;
+	u8 tmp;
+
+	for (i = 0; i < len; ++i) {
+		tmp = 0;
+		for (j = 0; j < 8; ++j) {
+			if (j == 7)
+				w1_pre_write(dev);
+			tmp |= w1_touch_bit(dev, (buf[i] >> j) & 0x1) << j;
+		}
+
+		buf[i] = tmp;
+	}
+}
+EXPORT_SYMBOL_GPL(w1_touch_block);
+
+/**
  * Reads a series of bytes.
  *
  * @param dev     the master device
diff --git a/drivers/w1/w1_netlink.c b/drivers/w1/w1_netlink.c
index a3b2630..cae556c 100644
--- a/drivers/w1/w1_netlink.c
+++ b/drivers/w1/w1_netlink.c
@@ -108,6 +108,10 @@ static int w1_process_command_slave(struct w1_slave *sl, struct cn_msg *msg,
 		cmd->cmd, cmd->len);
 
 	switch (cmd->cmd) {
+		case W1_CMD_TOUCH:
+			w1_touch_block(sl->master, cmd->data, cmd->len);
+			w1_send_read_reply(sl, msg, hdr, cmd);
+			break;
 		case W1_CMD_READ:
 			w1_read_block(sl->master, cmd->data, cmd->len);
 			w1_send_read_reply(sl, msg, hdr, cmd);
@@ -162,7 +166,7 @@ static int w1_process_command_root(struct cn_msg *msg, struct w1_netlink_msg *mc
 	list_for_each_entry(m, &w1_masters, w1_master_entry) {
 		if (cn->len + sizeof(*id) > PAGE_SIZE - sizeof(struct cn_msg)) {
 			cn_netlink_send(cn, 0, GFP_KERNEL);
-			cn->ack++
+			cn->ack++;
 			cn->len = sizeof(struct w1_netlink_msg);
 			w->len = 0;
 			id = (u32 *)(w + 1);
@@ -208,9 +212,6 @@ static void w1_cn_callback(void *data)
 			break;
 		}
 
-		if (!mlen)
-			goto out_cont;
-
 		if (m->type == W1_MASTER_CMD) {
 			dev = w1_search_master_id(m->id.mst.id);
 		} else if (m->type == W1_SLAVE_CMD) {
@@ -227,6 +228,10 @@ static void w1_cn_callback(void *data)
 			goto out_cont;
 		}
 
+		err = 0;
+		if (!mlen)
+			goto out_cont;
+
 		mutex_lock(&dev->mutex);
 
 		if (sl && w1_reset_select_slave(sl)) {
diff --git a/drivers/w1/w1_netlink.h b/drivers/w1/w1_netlink.h
index 21913df..99dd21b 100644
--- a/drivers/w1/w1_netlink.h
+++ b/drivers/w1/w1_netlink.h
@@ -56,6 +56,7 @@ struct w1_netlink_msg
 #define W1_CMD_WRITE		0x1
 #define W1_CMD_SEARCH		0x2
 #define W1_CMD_ALARM_SEARCH	0x3
+#define W1_CMD_TOUCH		0x4
 
 struct w1_netlink_cmd
 {
-- 
1.5.2.5


  reply	other threads:[~2008-12-04 14:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-04 14:50 [W1] extend userspace commands Evgeniy Polyakov
2008-12-04 14:50 ` Evgeniy Polyakov
2008-12-04 14:50   ` [W1] Added list masters w1 command Evgeniy Polyakov
2008-12-04 14:50     ` Evgeniy Polyakov [this message]
2008-12-04 14:50       ` [W1] Updated documentation Evgeniy Polyakov
2008-12-04 14:50         ` [W1] List slaves commands Evgeniy Polyakov
2008-12-04 14:50           ` [W1] W1 search/alarm search documentation Evgeniy Polyakov
2008-12-04 23:53         ` [W1] Updated documentation Randy Dunlap
2008-12-05  6:28           ` Evgeniy Polyakov
2008-12-04 15:42       ` [W1] Added touch block command Frederik Deweerdt
2008-12-04 15:58         ` Evgeniy Polyakov
2008-12-04 15:41     ` [W1] Added list masters w1 command Frederik Deweerdt
  -- strict thread matches above, loose matches on Subject: below --
2008-12-05 12:41 [W1 take2]: extend userspace commands Evgeniy Polyakov
2008-12-05 12:41 ` [W1] Added list masters w1 command Evgeniy Polyakov
2008-12-05 12:41   ` [W1] Added touch block command Evgeniy Polyakov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=12284022144105-git-send-email-zbr@ioremap.net \
    --to=zbr@ioremap.net \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.