Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a9d0c17 authored by Evgeniy Polyakov's avatar Evgeniy Polyakov Committed by Greg Kroah-Hartman
Browse files

[PATCH] w1: Adds a sysfs entry (w1_master_search) that allows you to...


[PATCH] w1: Adds a sysfs entry (w1_master_search) that allows you to disable/enable periodic searches.

Adds a sysfs entry (w1_master_search) that allows you to disable/enable
periodic searches.

Signed-off-by: default avatarBen Gardner <bgardner@wabtec.com>
Signed-off-by: default avatarEvgeniy Polyakov <johnpol@2ka.mipt.ru>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 6b729861
Loading
Loading
Loading
Loading
+49 −1
Original line number Original line Diff line number Diff line
@@ -148,6 +148,39 @@ static ssize_t w1_master_attribute_show_name(struct device *dev, struct device_a
	return count;
	return count;
}
}


static ssize_t w1_master_attribute_store_search(struct device * dev,
						struct device_attribute *attr,
						const char * buf, size_t count)
{
	struct w1_master *md = container_of(dev, struct w1_master, dev);

	if (down_interruptible (&md->mutex))
		return -EBUSY;

	md->search_count = simple_strtol(buf, NULL, 0);

	up(&md->mutex);

	return count;
}

static ssize_t w1_master_attribute_show_search(struct device *dev,
					       struct device_attribute *attr,
					       char *buf)
{
	struct w1_master *md = container_of(dev, struct w1_master, dev);
	ssize_t count;

	if (down_interruptible (&md->mutex))
		return -EBUSY;

	count = sprintf(buf, "%d\n", md->search_count);

	up(&md->mutex);

	return count;
}

static ssize_t w1_master_attribute_show_pointer(struct device *dev, struct device_attribute *attr, char *buf)
static ssize_t w1_master_attribute_show_pointer(struct device *dev, struct device_attribute *attr, char *buf)
{
{
	struct w1_master *md = container_of(dev, struct w1_master, dev);
	struct w1_master *md = container_of(dev, struct w1_master, dev);
@@ -242,6 +275,12 @@ static ssize_t w1_master_attribute_show_slaves(struct device *dev, struct device
		__ATTR(w1_master_##_name, _mode,		\
		__ATTR(w1_master_##_name, _mode,		\
		       w1_master_attribute_show_##_name, NULL)
		       w1_master_attribute_show_##_name, NULL)


#define W1_MASTER_ATTR_RW(_name, _mode)				\
	struct device_attribute w1_master_attribute_##_name =	\
		__ATTR(w1_master_##_name, _mode,		\
		       w1_master_attribute_show_##_name,	\
		       w1_master_attribute_store_##_name)

static W1_MASTER_ATTR_RO(name, S_IRUGO);
static W1_MASTER_ATTR_RO(name, S_IRUGO);
static W1_MASTER_ATTR_RO(slaves, S_IRUGO);
static W1_MASTER_ATTR_RO(slaves, S_IRUGO);
static W1_MASTER_ATTR_RO(slave_count, S_IRUGO);
static W1_MASTER_ATTR_RO(slave_count, S_IRUGO);
@@ -249,6 +288,7 @@ static W1_MASTER_ATTR_RO(max_slave_count, S_IRUGO);
static W1_MASTER_ATTR_RO(attempts, S_IRUGO);
static W1_MASTER_ATTR_RO(attempts, S_IRUGO);
static W1_MASTER_ATTR_RO(timeout, S_IRUGO);
static W1_MASTER_ATTR_RO(timeout, S_IRUGO);
static W1_MASTER_ATTR_RO(pointer, S_IRUGO);
static W1_MASTER_ATTR_RO(pointer, S_IRUGO);
static W1_MASTER_ATTR_RW(search, S_IRUGO | S_IWUGO);


static struct attribute *w1_master_default_attrs[] = {
static struct attribute *w1_master_default_attrs[] = {
	&w1_master_attribute_name.attr,
	&w1_master_attribute_name.attr,
@@ -258,6 +298,7 @@ static struct attribute *w1_master_default_attrs[] = {
	&w1_master_attribute_attempts.attr,
	&w1_master_attribute_attempts.attr,
	&w1_master_attribute_timeout.attr,
	&w1_master_attribute_timeout.attr,
	&w1_master_attribute_pointer.attr,
	&w1_master_attribute_pointer.attr,
	&w1_master_attribute_search.attr,
	NULL
	NULL
};
};


@@ -643,6 +684,9 @@ int w1_process(void *data)
		if (!dev->initialized)
		if (!dev->initialized)
			continue;
			continue;


		if (dev->search_count == 0)
			continue;

		if (down_interruptible(&dev->mutex))
		if (down_interruptible(&dev->mutex))
			continue;
			continue;


@@ -662,6 +706,10 @@ int w1_process(void *data)
			} else if (test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags))
			} else if (test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags))
				sl->ttl = dev->slave_ttl;
				sl->ttl = dev->slave_ttl;
		}
		}

		if (dev->search_count > 0)
			dev->search_count--;

		up(&dev->mutex);
		up(&dev->mutex);
	}
	}


+1 −0
Original line number Original line Diff line number Diff line
@@ -162,6 +162,7 @@ struct w1_master
	int			slave_ttl;
	int			slave_ttl;
	int			initialized;
	int			initialized;
	u32			id;
	u32			id;
	int			search_count;


	atomic_t		refcnt;
	atomic_t		refcnt;


+1 −0
Original line number Original line Diff line number Diff line
@@ -69,6 +69,7 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
	dev->initialized	= 0;
	dev->initialized	= 0;
	dev->id			= id;
	dev->id			= id;
	dev->slave_ttl		= slave_ttl;
	dev->slave_ttl		= slave_ttl;
        dev->search_count	= -1; /* continual scan */


	atomic_set(&dev->refcnt, 2);
	atomic_set(&dev->refcnt, 2);