1*de0d6dbdSAndrew F. Davis /* 2*de0d6dbdSAndrew F. Davis * Copyright (c) 2004 Evgeniy Polyakov <zbr@ioremap.net> 3*de0d6dbdSAndrew F. Davis * 4*de0d6dbdSAndrew F. Davis * This program is free software; you can redistribute it and/or modify 5*de0d6dbdSAndrew F. Davis * it under the terms of the GNU General Public License as published by 6*de0d6dbdSAndrew F. Davis * the Free Software Foundation; either version 2 of the License, or 7*de0d6dbdSAndrew F. Davis * (at your option) any later version. 8*de0d6dbdSAndrew F. Davis * 9*de0d6dbdSAndrew F. Davis * This program is distributed in the hope that it will be useful, 10*de0d6dbdSAndrew F. Davis * but WITHOUT ANY WARRANTY; without even the implied warranty of 11*de0d6dbdSAndrew F. Davis * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*de0d6dbdSAndrew F. Davis * GNU General Public License for more details. 13*de0d6dbdSAndrew F. Davis */ 14*de0d6dbdSAndrew F. Davis 15*de0d6dbdSAndrew F. Davis #ifndef __W1_H 16*de0d6dbdSAndrew F. Davis #define __W1_H 17*de0d6dbdSAndrew F. Davis 18*de0d6dbdSAndrew F. Davis #include <linux/w1.h> 19*de0d6dbdSAndrew F. Davis 20*de0d6dbdSAndrew F. Davis #include <linux/completion.h> 21*de0d6dbdSAndrew F. Davis #include <linux/mutex.h> 22*de0d6dbdSAndrew F. Davis 23*de0d6dbdSAndrew F. Davis #define W1_SLAVE_ACTIVE 0 24*de0d6dbdSAndrew F. Davis #define W1_SLAVE_DETACH 1 25*de0d6dbdSAndrew F. Davis 26*de0d6dbdSAndrew F. Davis /** 27*de0d6dbdSAndrew F. Davis * struct w1_async_cmd - execute callback from the w1_process kthread 28*de0d6dbdSAndrew F. Davis * @async_entry: link entry 29*de0d6dbdSAndrew F. Davis * @cb: callback function, must list_del and destroy this list before 30*de0d6dbdSAndrew F. Davis * returning 31*de0d6dbdSAndrew F. Davis * 32*de0d6dbdSAndrew F. Davis * When inserted into the w1_master async_list, w1_process will execute 33*de0d6dbdSAndrew F. Davis * the callback. Embed this into the structure with the command details. 34*de0d6dbdSAndrew F. Davis */ 35*de0d6dbdSAndrew F. Davis struct w1_async_cmd { 36*de0d6dbdSAndrew F. Davis struct list_head async_entry; 37*de0d6dbdSAndrew F. Davis void (*cb)(struct w1_master *dev, struct w1_async_cmd *async_cmd); 38*de0d6dbdSAndrew F. Davis }; 39*de0d6dbdSAndrew F. Davis 40*de0d6dbdSAndrew F. Davis int w1_create_master_attributes(struct w1_master *master); 41*de0d6dbdSAndrew F. Davis void w1_destroy_master_attributes(struct w1_master *master); 42*de0d6dbdSAndrew F. Davis void w1_search(struct w1_master *dev, u8 search_type, 43*de0d6dbdSAndrew F. Davis w1_slave_found_callback cb); 44*de0d6dbdSAndrew F. Davis void w1_search_devices(struct w1_master *dev, u8 search_type, 45*de0d6dbdSAndrew F. Davis w1_slave_found_callback cb); 46*de0d6dbdSAndrew F. Davis /* call w1_unref_slave to release the reference counts w1_search_slave added */ 47*de0d6dbdSAndrew F. Davis struct w1_slave *w1_search_slave(struct w1_reg_num *id); 48*de0d6dbdSAndrew F. Davis /* 49*de0d6dbdSAndrew F. Davis * decrements the reference on sl->master and sl, and cleans up if zero 50*de0d6dbdSAndrew F. Davis * returns the reference count after it has been decremented 51*de0d6dbdSAndrew F. Davis */ 52*de0d6dbdSAndrew F. Davis int w1_unref_slave(struct w1_slave *sl); 53*de0d6dbdSAndrew F. Davis void w1_slave_found(struct w1_master *dev, u64 rn); 54*de0d6dbdSAndrew F. Davis void w1_search_process_cb(struct w1_master *dev, u8 search_type, 55*de0d6dbdSAndrew F. Davis w1_slave_found_callback cb); 56*de0d6dbdSAndrew F. Davis struct w1_slave *w1_slave_search_device(struct w1_master *dev, 57*de0d6dbdSAndrew F. Davis struct w1_reg_num *rn); 58*de0d6dbdSAndrew F. Davis struct w1_master *w1_search_master_id(u32 id); 59*de0d6dbdSAndrew F. Davis 60*de0d6dbdSAndrew F. Davis /* Disconnect and reconnect devices in the given family. Used for finding 61*de0d6dbdSAndrew F. Davis * unclaimed devices after a family has been registered or releasing devices 62*de0d6dbdSAndrew F. Davis * after a family has been unregistered. Set attach to 1 when a new family 63*de0d6dbdSAndrew F. Davis * has just been registered, to 0 when it has been unregistered. 64*de0d6dbdSAndrew F. Davis */ 65*de0d6dbdSAndrew F. Davis void w1_reconnect_slaves(struct w1_family *f, int attach); 66*de0d6dbdSAndrew F. Davis int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn); 67*de0d6dbdSAndrew F. Davis /* 0 success, otherwise EBUSY */ 68*de0d6dbdSAndrew F. Davis int w1_slave_detach(struct w1_slave *sl); 69*de0d6dbdSAndrew F. Davis 70*de0d6dbdSAndrew F. Davis void __w1_remove_master_device(struct w1_master *dev); 71*de0d6dbdSAndrew F. Davis 72*de0d6dbdSAndrew F. Davis void w1_family_put(struct w1_family *f); 73*de0d6dbdSAndrew F. Davis void __w1_family_get(struct w1_family *f); 74*de0d6dbdSAndrew F. Davis struct w1_family *w1_family_registered(u8 fid); 75*de0d6dbdSAndrew F. Davis 76*de0d6dbdSAndrew F. Davis extern struct device_driver w1_master_driver; 77*de0d6dbdSAndrew F. Davis extern struct device w1_master_device; 78*de0d6dbdSAndrew F. Davis extern int w1_max_slave_count; 79*de0d6dbdSAndrew F. Davis extern int w1_max_slave_ttl; 80*de0d6dbdSAndrew F. Davis extern struct list_head w1_masters; 81*de0d6dbdSAndrew F. Davis extern struct mutex w1_mlock; 82*de0d6dbdSAndrew F. Davis extern spinlock_t w1_flock; 83*de0d6dbdSAndrew F. Davis 84*de0d6dbdSAndrew F. Davis int w1_process_callbacks(struct w1_master *dev); 85*de0d6dbdSAndrew F. Davis int w1_process(void *data); 86*de0d6dbdSAndrew F. Davis 87*de0d6dbdSAndrew F. Davis #endif /* __W1_H */ 88