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()
42 dev->bus_master = (struct w1_bus_master *)(dev + 1); in w1_alloc_dev()
44 dev->owner = THIS_MODULE; in w1_alloc_dev()
45 dev->max_slave_count = slave_count; in w1_alloc_dev()
46 dev->slave_count = 0; in w1_alloc_dev()
47 dev->attempts = 0; in w1_alloc_dev()
48 dev->initialized = 0; in w1_alloc_dev()
49 dev->id = id; in w1_alloc_dev()
50 dev->slave_ttl = slave_ttl; in w1_alloc_dev()
51 dev->search_count = w1_search_count; in w1_alloc_dev()
52 dev->enable_pullup = w1_enable_pullup; in w1_alloc_dev()
57 atomic_set(&dev->refcnt, 2); in w1_alloc_dev()
59 INIT_LIST_HEAD(&dev->slist); in w1_alloc_dev()
60 INIT_LIST_HEAD(&dev->async_list); in w1_alloc_dev()
61 mutex_init(&dev->mutex); in w1_alloc_dev()
62 mutex_init(&dev->bus_mutex); in w1_alloc_dev()
63 mutex_init(&dev->list_mutex); in w1_alloc_dev()
65 memcpy(&dev->dev, device, sizeof(struct device)); in w1_alloc_dev()
66 dev_set_name(&dev->dev, "w1_bus_master%u", dev->id); in w1_alloc_dev()
67 snprintf(dev->name, sizeof(dev->name), "w1_bus_master%u", dev->id); in w1_alloc_dev()
68 dev->dev.init_name = dev->name; in w1_alloc_dev()
70 dev->driver = driver; in w1_alloc_dev()
72 dev->seq = 1; in w1_alloc_dev()
74 err = device_register(&dev->dev); in w1_alloc_dev()
76 pr_err("Failed to register master device. err=%d\n", err); in w1_alloc_dev()
77 put_device(&dev->dev); in w1_alloc_dev()
86 device_unregister(&dev->dev); in w1_free_dev()
90 * w1_add_master_device() - registers a new master device
91 * @master: master bus device to register
93 int w1_add_master_device(struct w1_bus_master *master) in w1_add_master_device() argument
101 if (!(master->touch_bit && master->reset_bus) && in w1_add_master_device()
102 !(master->write_bit && master->read_bit) && in w1_add_master_device()
103 !(master->write_byte && master->read_byte && master->reset_bus)) { in w1_add_master_device()
105 return(-EINVAL); in w1_add_master_device()
116 if (entry->id == id) { in w1_add_master_device()
127 return -ENOMEM; in w1_add_master_device()
136 memcpy(dev->bus_master, master, sizeof(struct w1_bus_master)); in w1_add_master_device()
138 dev->initialized = 1; in w1_add_master_device()
140 dev->thread = kthread_run(&w1_process, dev, "%s", dev->name); in w1_add_master_device()
141 if (IS_ERR(dev->thread)) { in w1_add_master_device()
142 retval = PTR_ERR(dev->thread); in w1_add_master_device()
143 dev_err(&dev->dev, in w1_add_master_device()
144 "Failed to create new kernel thread. err=%d\n", in w1_add_master_device()
150 list_add(&dev->w1_master_entry, &w1_masters); in w1_add_master_device()
154 msg.id.mst.id = dev->id; in w1_add_master_device()
162 set_bit(W1_ABORT_SEARCH, &dev->flags); in w1_add_master_device()
163 kthread_stop(dev->thread); in w1_add_master_device()
180 list_del(&dev->w1_master_entry); in __w1_remove_master_device()
183 set_bit(W1_ABORT_SEARCH, &dev->flags); in __w1_remove_master_device()
184 kthread_stop(dev->thread); in __w1_remove_master_device()
186 mutex_lock(&dev->mutex); in __w1_remove_master_device()
187 mutex_lock(&dev->list_mutex); in __w1_remove_master_device()
188 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { in __w1_remove_master_device()
189 mutex_unlock(&dev->list_mutex); in __w1_remove_master_device()
191 mutex_lock(&dev->list_mutex); in __w1_remove_master_device()
194 mutex_unlock(&dev->list_mutex); in __w1_remove_master_device()
195 mutex_unlock(&dev->mutex); in __w1_remove_master_device()
196 atomic_dec(&dev->refcnt); in __w1_remove_master_device()
198 while (atomic_read(&dev->refcnt)) { in __w1_remove_master_device()
199 dev_info(&dev->dev, "Waiting for %s to become free: refcnt=%d.\n", in __w1_remove_master_device()
200 dev->name, atomic_read(&dev->refcnt)); in __w1_remove_master_device()
204 mutex_lock(&dev->list_mutex); in __w1_remove_master_device()
206 mutex_unlock(&dev->list_mutex); in __w1_remove_master_device()
208 mutex_lock(&dev->list_mutex); in __w1_remove_master_device()
210 mutex_unlock(&dev->list_mutex); in __w1_remove_master_device()
213 msg.id.mst.id = dev->id; in __w1_remove_master_device()
221 * w1_remove_master_device() - unregister a master device
222 * @bm: master bus device to remove
229 if (!dev->initialized) in w1_remove_master_device()
232 if (dev->bus_master->data == bm->data) { in w1_remove_master_device()