blob: 4be378b43d03540342cf1e0342b18ecac5abc7e5 [file] [log] [blame]
Maxime Ripard0749f642018-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
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
18static 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
30static int ds24xxx_probe(struct udevice *dev)
31{
32 struct w1_device *w1;
33
Simon Glasscaa4daa2020-12-03 16:55:18 -070034 w1 = dev_get_parent_plat(dev);
Maxime Ripard0749f642018-09-18 10:35:29 +030035 w1->id = 0;
36 return 0;
37}
38
39static const struct w1_eeprom_ops ds24xxx_ops = {
40 .read_buf = ds24xxx_read_buf,
41};
42
43static 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
49U_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 Maincentc9dffc92021-05-04 19:31:26 +020056
57u8 family_supported[] = {
58 W1_FAMILY_DS24B33,
59 W1_FAMILY_DS2431,
60};
61
62U_BOOT_W1_DEVICE(ds24xxx, family_supported);