18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2004 Evgeniy Polyakov <zbr@ioremap.net> 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef __W1_H 78c2ecf20Sopenharmony_ci#define __W1_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/w1.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/completion.h> 128c2ecf20Sopenharmony_ci#include <linux/mutex.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#define W1_SLAVE_ACTIVE 0 158c2ecf20Sopenharmony_ci#define W1_SLAVE_DETACH 1 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/** 188c2ecf20Sopenharmony_ci * struct w1_async_cmd - execute callback from the w1_process kthread 198c2ecf20Sopenharmony_ci * @async_entry: link entry 208c2ecf20Sopenharmony_ci * @cb: callback function, must list_del and destroy this list before 218c2ecf20Sopenharmony_ci * returning 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * When inserted into the w1_master async_list, w1_process will execute 248c2ecf20Sopenharmony_ci * the callback. Embed this into the structure with the command details. 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_cistruct w1_async_cmd { 278c2ecf20Sopenharmony_ci struct list_head async_entry; 288c2ecf20Sopenharmony_ci void (*cb)(struct w1_master *dev, struct w1_async_cmd *async_cmd); 298c2ecf20Sopenharmony_ci}; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciint w1_create_master_attributes(struct w1_master *master); 328c2ecf20Sopenharmony_civoid w1_destroy_master_attributes(struct w1_master *master); 338c2ecf20Sopenharmony_civoid w1_search(struct w1_master *dev, u8 search_type, 348c2ecf20Sopenharmony_ci w1_slave_found_callback cb); 358c2ecf20Sopenharmony_civoid w1_search_devices(struct w1_master *dev, u8 search_type, 368c2ecf20Sopenharmony_ci w1_slave_found_callback cb); 378c2ecf20Sopenharmony_ci/* call w1_unref_slave to release the reference counts w1_search_slave added */ 388c2ecf20Sopenharmony_cistruct w1_slave *w1_search_slave(struct w1_reg_num *id); 398c2ecf20Sopenharmony_ci/* 408c2ecf20Sopenharmony_ci * decrements the reference on sl->master and sl, and cleans up if zero 418c2ecf20Sopenharmony_ci * returns the reference count after it has been decremented 428c2ecf20Sopenharmony_ci */ 438c2ecf20Sopenharmony_ciint w1_unref_slave(struct w1_slave *sl); 448c2ecf20Sopenharmony_civoid w1_slave_found(struct w1_master *dev, u64 rn); 458c2ecf20Sopenharmony_civoid w1_search_process_cb(struct w1_master *dev, u8 search_type, 468c2ecf20Sopenharmony_ci w1_slave_found_callback cb); 478c2ecf20Sopenharmony_cistruct w1_slave *w1_slave_search_device(struct w1_master *dev, 488c2ecf20Sopenharmony_ci struct w1_reg_num *rn); 498c2ecf20Sopenharmony_cistruct w1_master *w1_search_master_id(u32 id); 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci/* Disconnect and reconnect devices in the given family. Used for finding 528c2ecf20Sopenharmony_ci * unclaimed devices after a family has been registered or releasing devices 538c2ecf20Sopenharmony_ci * after a family has been unregistered. Set attach to 1 when a new family 548c2ecf20Sopenharmony_ci * has just been registered, to 0 when it has been unregistered. 558c2ecf20Sopenharmony_ci */ 568c2ecf20Sopenharmony_civoid w1_reconnect_slaves(struct w1_family *f, int attach); 578c2ecf20Sopenharmony_ciint w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn); 588c2ecf20Sopenharmony_ci/* 0 success, otherwise EBUSY */ 598c2ecf20Sopenharmony_ciint w1_slave_detach(struct w1_slave *sl); 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_civoid __w1_remove_master_device(struct w1_master *dev); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_civoid w1_family_put(struct w1_family *f); 648c2ecf20Sopenharmony_civoid __w1_family_get(struct w1_family *f); 658c2ecf20Sopenharmony_cistruct w1_family *w1_family_registered(u8 fid); 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ciextern struct device_driver w1_master_driver; 688c2ecf20Sopenharmony_ciextern struct device w1_master_device; 698c2ecf20Sopenharmony_ciextern int w1_max_slave_count; 708c2ecf20Sopenharmony_ciextern int w1_max_slave_ttl; 718c2ecf20Sopenharmony_ciextern struct list_head w1_masters; 728c2ecf20Sopenharmony_ciextern struct mutex w1_mlock; 738c2ecf20Sopenharmony_ciextern spinlock_t w1_flock; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ciint w1_process_callbacks(struct w1_master *dev); 768c2ecf20Sopenharmony_ciint w1_process(void *data); 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci#endif /* __W1_H */ 79