Maxime Ripard | 0749f64 | 2018-09-18 10:35:29 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * |
| 4 | * Copyright (c) 2015 Free Electrons |
| 5 | * Copyright (c) 2015 NextThing Co |
| 6 | * Copyright (c) 2018 Microchip Technology, Inc. |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <linux/err.h> |
| 12 | #include <dm.h> |
| 13 | #include <w1-eeprom.h> |
| 14 | #include <w1.h> |
| 15 | |
| 16 | #define W1_F2D_READ_EEPROM 0xf0 |
| 17 | |
| 18 | static int ds24xxx_read_buf(struct udevice *dev, unsigned int offset, |
| 19 | u8 *buf, unsigned int count) |
| 20 | { |
| 21 | w1_reset_select(dev); |
| 22 | |
| 23 | w1_write_byte(dev, W1_F2D_READ_EEPROM); |
| 24 | w1_write_byte(dev, offset & 0xff); |
| 25 | w1_write_byte(dev, offset >> 8); |
| 26 | |
| 27 | return w1_read_buf(dev, buf, count); |
| 28 | } |
| 29 | |
| 30 | static int ds24xxx_probe(struct udevice *dev) |
| 31 | { |
| 32 | struct w1_device *w1; |
| 33 | |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 34 | w1 = dev_get_parent_plat(dev); |
Maxime Ripard | 0749f64 | 2018-09-18 10:35:29 +0300 | [diff] [blame] | 35 | w1->id = 0; |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | static const struct w1_eeprom_ops ds24xxx_ops = { |
| 40 | .read_buf = ds24xxx_read_buf, |
| 41 | }; |
| 42 | |
| 43 | static const struct udevice_id ds24xxx_id[] = { |
| 44 | { .compatible = "maxim,ds24b33", .data = W1_FAMILY_DS24B33 }, |
| 45 | { .compatible = "maxim,ds2431", .data = W1_FAMILY_DS2431 }, |
| 46 | { }, |
| 47 | }; |
| 48 | |
| 49 | U_BOOT_DRIVER(ds24xxx) = { |
| 50 | .name = "ds24xxx", |
| 51 | .id = UCLASS_W1_EEPROM, |
| 52 | .of_match = ds24xxx_id, |
| 53 | .ops = &ds24xxx_ops, |
| 54 | .probe = ds24xxx_probe, |
| 55 | }; |
Kory Maincent | c9dffc9 | 2021-05-04 19:31:26 +0200 | [diff] [blame] | 56 | |
| 57 | u8 family_supported[] = { |
| 58 | W1_FAMILY_DS24B33, |
| 59 | W1_FAMILY_DS2431, |
| 60 | }; |
| 61 | |
| 62 | U_BOOT_W1_DEVICE(ds24xxx, family_supported); |