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.
This commit is contained in:
sov1178
2017-07-28 13:23:54 +03:00
committed by GitHub
parent e0a8ecfd40
commit 5961400922

View File

@@ -2,7 +2,7 @@
* w1.c
*
* Copyright (c) 2004 Evgeniy Polyakov <zbr@ioremap.net>
*
* Modified by Oleg Skydan <sov1178@gmail.com>
*
* 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 <zbr@ioremap.net>");
MODULE_AUTHOR("Evgeniy Polyakov <zbr@ioremap.net>, Oleg Skydan <sov1178@gmail.com>");
MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol.");
/* Added new feature ( by Oleg Skydan <sov1178@gmail.com> ):
/* 20.01.2017
* Added new feature ( by Oleg Skydan <sov1178@gmail.com> ):
* 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 <sov1178@gmail.com> ):
* 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. */