blob: b18078ba152ddc1b479b17a6a7e186fa9b6c61d2 [file] [log] [blame]
Maxime Ripardd3e19cf2018-09-18 10:35:24 +03001/* 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
Simon Glass411e9eb2020-07-19 10:15:42 -060011struct udevice;
Maxime Ripardd3e19cf2018-09-18 10:35:24 +030012
13#define W1_FAMILY_DS24B33 0x23
14#define W1_FAMILY_DS2431 0x2d
Martin Fuzzeyf9c87ad2018-10-24 10:21:19 +020015#define W1_FAMILY_DS2502 0x09
Eugen Hristev84e55bd2018-09-18 10:35:31 +030016#define W1_FAMILY_EEP_SANDBOX 0xfe
Maxime Ripardd3e19cf2018-09-18 10:35:24 +030017
Kory Maincentc9dffc92021-05-04 19:31:26 +020018struct 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
Maxime Ripardd3e19cf2018-09-18 10:35:24 +030035struct w1_device {
36 u64 id;
37};
38
39struct 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
46int w1_get_bus(int busnum, struct udevice **busp);
47u8 w1_get_device_family(struct udevice *dev);
48
49int w1_read_buf(struct udevice *dev, u8 *buf, unsigned int count);
50int w1_read_byte(struct udevice *dev);
51int w1_reset_select(struct udevice *dev);
52int w1_write_buf(struct udevice *dev, u8 *buf, unsigned int count);
53int w1_write_byte(struct udevice *dev, u8 byte);
54
55#endif