xref: /openbmc/u-boot/drivers/w1-eeprom/ds24xxx.c (revision e11ef3d2)
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 
34 	w1 = dev_get_parent_platdata(dev);
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 };
56