Maxime Ripard | d3e19cf | 2018-09-18 10:35:24 +0300 | [diff] [blame] | 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 | |
Simon Glass | 411e9eb | 2020-07-19 10:15:42 -0600 | [diff] [blame] | 11 | struct udevice; |
Maxime Ripard | d3e19cf | 2018-09-18 10:35:24 +0300 | [diff] [blame] | 12 | |
| 13 | #define W1_FAMILY_DS24B33 0x23 |
| 14 | #define W1_FAMILY_DS2431 0x2d |
Martin Fuzzey | f9c87ad | 2018-10-24 10:21:19 +0200 | [diff] [blame] | 15 | #define W1_FAMILY_DS2502 0x09 |
Eugen Hristev | 84e55bd | 2018-09-18 10:35:31 +0300 | [diff] [blame] | 16 | #define W1_FAMILY_EEP_SANDBOX 0xfe |
Maxime Ripard | d3e19cf | 2018-09-18 10:35:24 +0300 | [diff] [blame] | 17 | |
Kory Maincent | c9dffc9 | 2021-05-04 19:31:26 +0200 | [diff] [blame] | 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 | |
Maxime Ripard | d3e19cf | 2018-09-18 10:35:24 +0300 | [diff] [blame] | 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 |