162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2004 Evgeniy Polyakov <zbr@ioremap.net>
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef __W1_H
762306a36Sopenharmony_ci#define __W1_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/w1.h>
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <linux/completion.h>
1262306a36Sopenharmony_ci#include <linux/mutex.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#define W1_SLAVE_ACTIVE		0
1562306a36Sopenharmony_ci#define W1_SLAVE_DETACH		1
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci/**
1862306a36Sopenharmony_ci * struct w1_async_cmd - execute callback from the w1_process kthread
1962306a36Sopenharmony_ci * @async_entry: link entry
2062306a36Sopenharmony_ci * @cb: callback function, must list_del and destroy this list before
2162306a36Sopenharmony_ci * returning
2262306a36Sopenharmony_ci *
2362306a36Sopenharmony_ci * When inserted into the w1_master async_list, w1_process will execute
2462306a36Sopenharmony_ci * the callback.  Embed this into the structure with the command details.
2562306a36Sopenharmony_ci */
2662306a36Sopenharmony_cistruct w1_async_cmd {
2762306a36Sopenharmony_ci	struct list_head	async_entry;
2862306a36Sopenharmony_ci	void (*cb)(struct w1_master *dev, struct w1_async_cmd *async_cmd);
2962306a36Sopenharmony_ci};
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ciint w1_create_master_attributes(struct w1_master *master);
3262306a36Sopenharmony_civoid w1_destroy_master_attributes(struct w1_master *master);
3362306a36Sopenharmony_civoid w1_search(struct w1_master *dev, u8 search_type,
3462306a36Sopenharmony_ci	       w1_slave_found_callback cb);
3562306a36Sopenharmony_civoid w1_search_devices(struct w1_master *dev, u8 search_type,
3662306a36Sopenharmony_ci		       w1_slave_found_callback cb);
3762306a36Sopenharmony_ci/* call w1_unref_slave to release the reference counts w1_search_slave added */
3862306a36Sopenharmony_cistruct w1_slave *w1_search_slave(struct w1_reg_num *id);
3962306a36Sopenharmony_ci/*
4062306a36Sopenharmony_ci * decrements the reference on sl->master and sl, and cleans up if zero
4162306a36Sopenharmony_ci * returns the reference count after it has been decremented
4262306a36Sopenharmony_ci */
4362306a36Sopenharmony_ciint w1_unref_slave(struct w1_slave *sl);
4462306a36Sopenharmony_civoid w1_slave_found(struct w1_master *dev, u64 rn);
4562306a36Sopenharmony_civoid w1_search_process_cb(struct w1_master *dev, u8 search_type,
4662306a36Sopenharmony_ci			  w1_slave_found_callback cb);
4762306a36Sopenharmony_cistruct w1_slave *w1_slave_search_device(struct w1_master *dev,
4862306a36Sopenharmony_ci					struct w1_reg_num *rn);
4962306a36Sopenharmony_cistruct w1_master *w1_search_master_id(u32 id);
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci/* Disconnect and reconnect devices in the given family.  Used for finding
5262306a36Sopenharmony_ci * unclaimed devices after a family has been registered or releasing devices
5362306a36Sopenharmony_ci * after a family has been unregistered.  Set attach to 1 when a new family
5462306a36Sopenharmony_ci * has just been registered, to 0 when it has been unregistered.
5562306a36Sopenharmony_ci */
5662306a36Sopenharmony_civoid w1_reconnect_slaves(struct w1_family *f, int attach);
5762306a36Sopenharmony_ciint w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn);
5862306a36Sopenharmony_ci/* 0 success, otherwise EBUSY */
5962306a36Sopenharmony_ciint w1_slave_detach(struct w1_slave *sl);
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_civoid __w1_remove_master_device(struct w1_master *dev);
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_civoid w1_family_put(struct w1_family *f);
6462306a36Sopenharmony_civoid __w1_family_get(struct w1_family *f);
6562306a36Sopenharmony_cistruct w1_family *w1_family_registered(u8 fid);
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ciextern struct device_driver w1_master_driver;
6862306a36Sopenharmony_ciextern struct device w1_master_device;
6962306a36Sopenharmony_ciextern int w1_max_slave_count;
7062306a36Sopenharmony_ciextern int w1_max_slave_ttl;
7162306a36Sopenharmony_ciextern struct list_head w1_masters;
7262306a36Sopenharmony_ciextern struct mutex w1_mlock;
7362306a36Sopenharmony_ciextern spinlock_t w1_flock;
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ciint w1_process_callbacks(struct w1_master *dev);
7662306a36Sopenharmony_ciint w1_process(void *data);
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci#endif /* __W1_H */
79