Lines Matching +full:master +full:- +full:kernel

1 // SPDX-License-Identifier: GPL-2.0-or-later
6 #include <linux/kernel.h>
18 static int w1_search_count = -1; /* Default is continual scan */
32 * We are in process context(kernel thread), so can sleep. in w1_alloc_dev()
38 dev->bus_master = (struct w1_bus_master *)(dev + 1); in w1_alloc_dev()
40 dev->owner = THIS_MODULE; in w1_alloc_dev()
41 dev->max_slave_count = slave_count; in w1_alloc_dev()
42 dev->slave_count = 0; in w1_alloc_dev()
43 dev->attempts = 0; in w1_alloc_dev()
44 dev->initialized = 0; in w1_alloc_dev()
45 dev->id = id; in w1_alloc_dev()
46 dev->slave_ttl = slave_ttl; in w1_alloc_dev()
47 dev->search_count = w1_search_count; in w1_alloc_dev()
48 dev->enable_pullup = w1_enable_pullup; in w1_alloc_dev()
52 atomic_set(&dev->refcnt, 1); in w1_alloc_dev()
54 INIT_LIST_HEAD(&dev->slist); in w1_alloc_dev()
55 INIT_LIST_HEAD(&dev->async_list); in w1_alloc_dev()
56 mutex_init(&dev->mutex); in w1_alloc_dev()
57 mutex_init(&dev->bus_mutex); in w1_alloc_dev()
58 mutex_init(&dev->list_mutex); in w1_alloc_dev()
60 memcpy(&dev->dev, device, sizeof(struct device)); in w1_alloc_dev()
61 dev_set_name(&dev->dev, "w1_bus_master%u", dev->id); in w1_alloc_dev()
62 snprintf(dev->name, sizeof(dev->name), "w1_bus_master%u", dev->id); in w1_alloc_dev()
63 dev->dev.init_name = dev->name; in w1_alloc_dev()
65 dev->driver = driver; in w1_alloc_dev()
67 dev->seq = 1; in w1_alloc_dev()
69 err = device_register(&dev->dev); in w1_alloc_dev()
71 pr_err("Failed to register master device. err=%d\n", err); in w1_alloc_dev()
72 put_device(&dev->dev); in w1_alloc_dev()
81 device_unregister(&dev->dev); in w1_free_dev()
85 * w1_add_master_device() - registers a new master device
86 * @master: master bus device to register
88 int w1_add_master_device(struct w1_bus_master *master) in w1_add_master_device() argument
96 if (!(master->touch_bit && master->reset_bus) && in w1_add_master_device()
97 !(master->write_bit && master->read_bit) && in w1_add_master_device()
98 !(master->write_byte && master->read_byte && master->reset_bus)) { in w1_add_master_device()
100 return(-EINVAL); in w1_add_master_device()
111 if (entry->id == id) { in w1_add_master_device()
122 return -ENOMEM; in w1_add_master_device()
131 memcpy(dev->bus_master, master, sizeof(struct w1_bus_master)); in w1_add_master_device()
133 dev->initialized = 1; in w1_add_master_device()
135 dev->thread = kthread_run(&w1_process, dev, "%s", dev->name); in w1_add_master_device()
136 if (IS_ERR(dev->thread)) { in w1_add_master_device()
137 retval = PTR_ERR(dev->thread); in w1_add_master_device()
138 dev_err(&dev->dev, in w1_add_master_device()
139 "Failed to create new kernel thread. err=%d\n", in w1_add_master_device()
145 list_add(&dev->w1_master_entry, &w1_masters); in w1_add_master_device()
149 msg.id.mst.id = dev->id; in w1_add_master_device()
157 set_bit(W1_ABORT_SEARCH, &dev->flags); in w1_add_master_device()
158 kthread_stop(dev->thread); in w1_add_master_device()
175 list_del(&dev->w1_master_entry); in __w1_remove_master_device()
178 set_bit(W1_ABORT_SEARCH, &dev->flags); in __w1_remove_master_device()
179 kthread_stop(dev->thread); in __w1_remove_master_device()
181 mutex_lock(&dev->mutex); in __w1_remove_master_device()
182 mutex_lock(&dev->list_mutex); in __w1_remove_master_device()
183 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { in __w1_remove_master_device()
184 mutex_unlock(&dev->list_mutex); in __w1_remove_master_device()
186 mutex_lock(&dev->list_mutex); in __w1_remove_master_device()
189 mutex_unlock(&dev->list_mutex); in __w1_remove_master_device()
190 mutex_unlock(&dev->mutex); in __w1_remove_master_device()
191 atomic_dec(&dev->refcnt); in __w1_remove_master_device()
193 while (atomic_read(&dev->refcnt)) { in __w1_remove_master_device()
194 dev_info(&dev->dev, "Waiting for %s to become free: refcnt=%d.\n", in __w1_remove_master_device()
195 dev->name, atomic_read(&dev->refcnt)); in __w1_remove_master_device()
199 mutex_lock(&dev->list_mutex); in __w1_remove_master_device()
201 mutex_unlock(&dev->list_mutex); in __w1_remove_master_device()
203 mutex_lock(&dev->list_mutex); in __w1_remove_master_device()
205 mutex_unlock(&dev->list_mutex); in __w1_remove_master_device()
208 msg.id.mst.id = dev->id; in __w1_remove_master_device()
216 * w1_remove_master_device() - unregister a master device
217 * @bm: master bus device to remove
224 if (!dev->initialized) in w1_remove_master_device()
227 if (dev->bus_master->data == bm->data) { in w1_remove_master_device()