1 /* SPDX-License-Identifier:	GPL-2.0+
2  *
3  * Copyright (c) 2015 Free Electrons
4  * Copyright (c) 2015 NextThing Co
5  *
6  */
7 
8 #ifndef __W1_H
9 #define __W1_H
10 
11 struct udevice;
12 
13 #define W1_FAMILY_DS24B33	0x23
14 #define W1_FAMILY_DS2431	0x2d
15 #define W1_FAMILY_DS2502	0x09
16 #define W1_FAMILY_EEP_SANDBOX	0xfe
17 
18 struct w1_driver_entry {
19 	struct driver	*driver;
20 	u8		*family;
21 };
22 
23 /* U_BOOT_W1_DEVICE() tells U-Boot to create a one-wire device.
24  *
25  * @__name: Device name (C identifier, not a string. E.g. gpio7_at_ff7e0000)
26  * @__driver: Driver name (C identifier, not a string. E.g. gpio7_at_ff7e0000)
27  * @__family: Family code number of the one-wire
28  */
29 #define U_BOOT_W1_DEVICE(__name, __family)				\
30 	ll_entry_declare(struct w1_driver_entry, __name, w1_driver_entry) = { \
31 		.driver = llsym(struct driver, __name, driver),		\
32 		.family = __family,					\
33 	}
34 
35 struct w1_device {
36 	u64	id;
37 };
38 
39 struct w1_ops {
40 	u8	(*read_byte)(struct udevice *dev);
41 	bool	(*reset)(struct udevice *dev);
42 	u8	(*triplet)(struct udevice *dev, bool bdir);
43 	void	(*write_byte)(struct udevice *dev, u8 byte);
44 };
45 
46 int w1_get_bus(int busnum, struct udevice **busp);
47 u8 w1_get_device_family(struct udevice *dev);
48 
49 int w1_read_buf(struct udevice *dev, u8 *buf, unsigned int count);
50 int w1_read_byte(struct udevice *dev);
51 int w1_reset_select(struct udevice *dev);
52 int w1_write_buf(struct udevice *dev, u8 *buf, unsigned int count);
53 int w1_write_byte(struct udevice *dev, u8 byte);
54 
55 #endif
56