22 #include <linux/kernel.h>
23 #include <linux/list.h>
26 #include <linux/slab.h>
27 #include <linux/export.h>
35 static int w1_search_count = -1;
38 static int w1_enable_pullup = 1;
41 static struct w1_master * w1_alloc_dev(
u32 id,
int slave_count,
int slave_ttl,
45 struct w1_master *
dev;
51 dev = kzalloc(
sizeof(
struct w1_master) +
sizeof(
struct w1_bus_master),
GFP_KERNEL);
54 "Failed to allocate %zd bytes for new w1 device.\n",
55 sizeof(
struct w1_master));
60 dev->bus_master = (
struct w1_bus_master *)(dev + 1);
63 dev->max_slave_count = slave_count;
68 dev->slave_ttl = slave_ttl;
69 dev->search_count = w1_search_count;
70 dev->enable_pullup = w1_enable_pullup;
77 INIT_LIST_HEAD(&dev->slist);
81 memcpy(&dev->dev, device,
sizeof(
struct device));
83 snprintf(dev->name,
sizeof(dev->name),
"w1_bus_master%u", dev->id);
84 dev->dev.init_name = dev->name;
92 printk(
KERN_ERR "Failed to register master device. err=%d\n", err);
93 memset(dev, 0,
sizeof(
struct w1_master));
101 static void w1_free_dev(
struct w1_master *dev)
114 if (!(master->touch_bit && master->reset_bus) &&
115 !(master->write_bit && master->read_bit) &&
116 !(master->write_byte && master->read_byte && master->reset_bus)) {
127 if (!master->write_byte && !master->touch_bit && master->set_pullup) {
129 "write_byte or touch_bit, disabling\n");
130 master->set_pullup =
NULL;
141 if (entry->id ==
id) {
158 goto err_out_free_dev;
161 memcpy(dev->bus_master, master,
sizeof(
struct w1_bus_master));
163 dev->initialized = 1;
166 if (IS_ERR(dev->thread)) {
167 retval = PTR_ERR(dev->thread);
169 "Failed to create new kernel thread. err=%d\n",
172 goto err_out_rm_attr;
175 list_add(&dev->w1_master_entry, &w1_masters);
178 memset(&msg, 0,
sizeof(msg));
179 msg.
id.mst.id = dev->id;
200 struct w1_slave *
sl, *sln;
216 dev_info(&dev->dev,
"Waiting for %s to become free: refcnt=%d.\n",
223 memset(&msg, 0,
sizeof(msg));
224 msg.
id.mst.id = dev->id;
233 struct w1_master *
dev, *found =
NULL;
236 if (!dev->initialized)
239 if (dev->bus_master->data == bm->data) {