From 59614009223ea48a0089b21cb0658d0c02b82706 Mon Sep 17 00:00:00 2001 From: sov1178 Date: Fri, 28 Jul 2017 13:23:54 +0300 Subject: [PATCH] Added per master temp conversion trigger Now each master has 'w1_master_therm_convert_all' file. Its functionality is the same as the 'w1_therm_convert_all' (located in '/sys/bus/w1'), but reading will start temperature conversion on sensors connected to this master only. --- drivers/w1/w1.c | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index 6a028eb8ce1a..7d7f62c0b615 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c @@ -2,7 +2,7 @@ * w1.c * * Copyright (c) 2004 Evgeniy Polyakov - * + * Modified by Oleg Skydan * * 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 @@ -42,15 +42,22 @@ #include "w1_netlink.h" MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Evgeniy Polyakov "); +MODULE_AUTHOR("Evgeniy Polyakov , Oleg Skydan "); MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol."); -/* Added new feature ( by Oleg Skydan ): +/* 20.01.2017 + * Added new feature ( by Oleg Skydan ): * Reading the 'w1_therm_convert_all' file (located in '/sys/bus/w1') will start * temperature conversion on all sensors in the w1 net and wait 750ms to finish * conversion. * * Then you can use the 'w1_read' (see modified w1_therm module) to read converted * temperatures. So you will not need to wait 750ms reading each sensor (using 'w1_slave'). + * + * 28.01.2017 + * Added new feature ( by Oleg Skydan ): + * Now each master has 'w1_master_therm_convert_all' file its functionality is the + * same as the 'w1_therm_convert_all' (located in '/sys/bus/w1'), but reading will start + * temperature conversion on sensors connected to this master only. */ static int w1_timeout = 10; int w1_max_slave_count = 10; @@ -506,6 +513,31 @@ static ssize_t w1_master_attribute_store_remove(struct device *dev, return result; } +static ssize_t w1_master_attribute_show_therm_convert_all(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct w1_master *md = dev_to_w1_master(dev); + ssize_t c; + unsigned int tm = 750; + + mutex_lock(&md->mutex); + + w1_reset_bus(md); + w1_write_8(md, W1_SKIP_ROM); + + w1_write_8(md, W1_CONVERT_TEMP); + + mutex_unlock(&md->mutex); + + /*wait 750ms while conversion in progress*/ + msleep(tm); + + c = snprintf(buf, PAGE_SIZE, "OK"); + + return c; +} + #define W1_MASTER_ATTR_RO(_name, _mode) \ struct device_attribute w1_master_attribute_##_name = \ __ATTR(w1_master_##_name, _mode, \ @@ -524,6 +556,7 @@ static W1_MASTER_ATTR_RO(max_slave_count, S_IRUGO); static W1_MASTER_ATTR_RO(attempts, S_IRUGO); static W1_MASTER_ATTR_RO(timeout, S_IRUGO); static W1_MASTER_ATTR_RO(pointer, S_IRUGO); +static W1_MASTER_ATTR_RO(therm_convert_all, S_IRUGO); static W1_MASTER_ATTR_RW(search, S_IRUGO | S_IWUSR | S_IWGRP); static W1_MASTER_ATTR_RW(pullup, S_IRUGO | S_IWUSR | S_IWGRP); static W1_MASTER_ATTR_RW(add, S_IRUGO | S_IWUSR | S_IWGRP); @@ -537,6 +570,7 @@ static struct attribute *w1_master_default_attrs[] = { &w1_master_attribute_attempts.attr, &w1_master_attribute_timeout.attr, &w1_master_attribute_pointer.attr, + &w1_master_attribute_therm_convert_all.attr, &w1_master_attribute_search.attr, &w1_master_attribute_pullup.attr, &w1_master_attribute_add.attr, @@ -1080,7 +1114,7 @@ static int __init w1_init(void) goto err_out_slave_unregister; } - return 0; + return 0; #if 1 /* For undoing the slave register if there was a step after it. */