1*c942fddfSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 2de0d6dbdSAndrew F. Davis /* 3de0d6dbdSAndrew F. Davis * Copyright (c) 2004 Evgeniy Polyakov <zbr@ioremap.net> 4de0d6dbdSAndrew F. Davis */ 5de0d6dbdSAndrew F. Davis 6de0d6dbdSAndrew F. Davis #ifndef __W1_H 7de0d6dbdSAndrew F. Davis #define __W1_H 8de0d6dbdSAndrew F. Davis 9de0d6dbdSAndrew F. Davis #include <linux/w1.h> 10de0d6dbdSAndrew F. Davis 11de0d6dbdSAndrew F. Davis #include <linux/completion.h> 12de0d6dbdSAndrew F. Davis #include <linux/mutex.h> 13de0d6dbdSAndrew F. Davis 14de0d6dbdSAndrew F. Davis #define W1_SLAVE_ACTIVE 0 15de0d6dbdSAndrew F. Davis #define W1_SLAVE_DETACH 1 16de0d6dbdSAndrew F. Davis 17de0d6dbdSAndrew F. Davis /** 18de0d6dbdSAndrew F. Davis * struct w1_async_cmd - execute callback from the w1_process kthread 19de0d6dbdSAndrew F. Davis * @async_entry: link entry 20de0d6dbdSAndrew F. Davis * @cb: callback function, must list_del and destroy this list before 21de0d6dbdSAndrew F. Davis * returning 22de0d6dbdSAndrew F. Davis * 23de0d6dbdSAndrew F. Davis * When inserted into the w1_master async_list, w1_process will execute 24de0d6dbdSAndrew F. Davis * the callback. Embed this into the structure with the command details. 25de0d6dbdSAndrew F. Davis */ 26de0d6dbdSAndrew F. Davis struct w1_async_cmd { 27de0d6dbdSAndrew F. Davis struct list_head async_entry; 28de0d6dbdSAndrew F. Davis void (*cb)(struct w1_master *dev, struct w1_async_cmd *async_cmd); 29de0d6dbdSAndrew F. Davis }; 30de0d6dbdSAndrew F. Davis 31de0d6dbdSAndrew F. Davis int w1_create_master_attributes(struct w1_master *master); 32de0d6dbdSAndrew F. Davis void w1_destroy_master_attributes(struct w1_master *master); 33de0d6dbdSAndrew F. Davis void w1_search(struct w1_master *dev, u8 search_type, 34de0d6dbdSAndrew F. Davis w1_slave_found_callback cb); 35de0d6dbdSAndrew F. Davis void w1_search_devices(struct w1_master *dev, u8 search_type, 36de0d6dbdSAndrew F. Davis w1_slave_found_callback cb); 37de0d6dbdSAndrew F. Davis /* call w1_unref_slave to release the reference counts w1_search_slave added */ 38de0d6dbdSAndrew F. Davis struct w1_slave *w1_search_slave(struct w1_reg_num *id); 39de0d6dbdSAndrew F. Davis /* 40de0d6dbdSAndrew F. Davis * decrements the reference on sl->master and sl, and cleans up if zero 41de0d6dbdSAndrew F. Davis * returns the reference count after it has been decremented 42de0d6dbdSAndrew F. Davis */ 43de0d6dbdSAndrew F. Davis int w1_unref_slave(struct w1_slave *sl); 44de0d6dbdSAndrew F. Davis void w1_slave_found(struct w1_master *dev, u64 rn); 45de0d6dbdSAndrew F. Davis void w1_search_process_cb(struct w1_master *dev, u8 search_type, 46de0d6dbdSAndrew F. Davis w1_slave_found_callback cb); 47de0d6dbdSAndrew F. Davis struct w1_slave *w1_slave_search_device(struct w1_master *dev, 48de0d6dbdSAndrew F. Davis struct w1_reg_num *rn); 49de0d6dbdSAndrew F. Davis struct w1_master *w1_search_master_id(u32 id); 50de0d6dbdSAndrew F. Davis 51de0d6dbdSAndrew F. Davis /* Disconnect and reconnect devices in the given family. Used for finding 52de0d6dbdSAndrew F. Davis * unclaimed devices after a family has been registered or releasing devices 53de0d6dbdSAndrew F. Davis * after a family has been unregistered. Set attach to 1 when a new family 54de0d6dbdSAndrew F. Davis * has just been registered, to 0 when it has been unregistered. 55de0d6dbdSAndrew F. Davis */ 56de0d6dbdSAndrew F. Davis void w1_reconnect_slaves(struct w1_family *f, int attach); 57de0d6dbdSAndrew F. Davis int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn); 58de0d6dbdSAndrew F. Davis /* 0 success, otherwise EBUSY */ 59de0d6dbdSAndrew F. Davis int w1_slave_detach(struct w1_slave *sl); 60de0d6dbdSAndrew F. Davis 61de0d6dbdSAndrew F. Davis void __w1_remove_master_device(struct w1_master *dev); 62de0d6dbdSAndrew F. Davis 63de0d6dbdSAndrew F. Davis void w1_family_put(struct w1_family *f); 64de0d6dbdSAndrew F. Davis void __w1_family_get(struct w1_family *f); 65de0d6dbdSAndrew F. Davis struct w1_family *w1_family_registered(u8 fid); 66de0d6dbdSAndrew F. Davis 67de0d6dbdSAndrew F. Davis extern struct device_driver w1_master_driver; 68de0d6dbdSAndrew F. Davis extern struct device w1_master_device; 69de0d6dbdSAndrew F. Davis extern int w1_max_slave_count; 70de0d6dbdSAndrew F. Davis extern int w1_max_slave_ttl; 71de0d6dbdSAndrew F. Davis extern struct list_head w1_masters; 72de0d6dbdSAndrew F. Davis extern struct mutex w1_mlock; 73de0d6dbdSAndrew F. Davis extern spinlock_t w1_flock; 74de0d6dbdSAndrew F. Davis 75de0d6dbdSAndrew F. Davis int w1_process_callbacks(struct w1_master *dev); 76de0d6dbdSAndrew F. Davis int w1_process(void *data); 77de0d6dbdSAndrew F. Davis 78de0d6dbdSAndrew F. Davis #endif /* __W1_H */ 79