blob: 413d8bc58814514178b53a29541a53562ad8bbbd [file] [log] [blame]
Maxime Ripard62fbdb52018-09-18 10:35:29 +03001// 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 Ripard62fbdb52018-09-18 10:35:29 +030010#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
17static 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
29static int ds24xxx_probe(struct udevice *dev)
30{
31 struct w1_device *w1;
32
Simon Glass71fa5b42020-12-03 16:55:18 -070033 w1 = dev_get_parent_plat(dev);
Maxime Ripard62fbdb52018-09-18 10:35:29 +030034 w1->id = 0;
35 return 0;
36}
37
38static const struct w1_eeprom_ops ds24xxx_ops = {
39 .read_buf = ds24xxx_read_buf,
40};
41
42static 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
48U_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 Maincenta0670e52021-05-04 19:31:26 +020055
56u8 family_supported[] = {
57 W1_FAMILY_DS24B33,
58 W1_FAMILY_DS2431,
59};
60
61U_BOOT_W1_DEVICE(ds24xxx, family_supported);