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