blob: 243e7ae5abfbb5c7989f0c2f22da7b47a4fd9fee [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass20142012014-12-10 08:55:54 -07002/*
3 * Copyright (c) 2014 Google, Inc
Simon Glass20142012014-12-10 08:55:54 -07004 */
5
6#include <common.h>
Masahiro Yamadaee5ee872014-12-18 20:00:26 +09007#include <linux/err.h>
Simon Glass20142012014-12-10 08:55:54 -07008#include <dm.h>
9#include <i2c.h>
10#include <i2c_eeprom.h>
11
Jonas Karlman8880efb2017-04-22 08:57:41 +000012int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf, int size)
13{
14 const struct i2c_eeprom_ops *ops = device_get_ops(dev);
15
16 if (!ops->read)
17 return -ENOSYS;
18
19 return ops->read(dev, offset, buf, size);
20}
21
22int i2c_eeprom_write(struct udevice *dev, int offset, uint8_t *buf, int size)
23{
24 const struct i2c_eeprom_ops *ops = device_get_ops(dev);
25
26 if (!ops->write)
27 return -ENOSYS;
28
29 return ops->write(dev, offset, buf, size);
30}
31
32static int i2c_eeprom_std_read(struct udevice *dev, int offset, uint8_t *buf,
33 int size)
Simon Glass20142012014-12-10 08:55:54 -070034{
mario.six@gdsys.ccd7e28912016-06-22 15:14:16 +020035 return dm_i2c_read(dev, offset, buf, size);
Simon Glass20142012014-12-10 08:55:54 -070036}
37
Jonas Karlman8880efb2017-04-22 08:57:41 +000038static int i2c_eeprom_std_write(struct udevice *dev, int offset,
39 const uint8_t *buf, int size)
Simon Glass20142012014-12-10 08:55:54 -070040{
41 return -ENODEV;
42}
43
Masahiro Yamada5e75ea12017-06-22 16:51:22 +090044static const struct i2c_eeprom_ops i2c_eeprom_std_ops = {
Jonas Karlman8880efb2017-04-22 08:57:41 +000045 .read = i2c_eeprom_std_read,
46 .write = i2c_eeprom_std_write,
Simon Glass20142012014-12-10 08:55:54 -070047};
48
mario.six@gdsys.ccd7e28912016-06-22 15:14:16 +020049static int i2c_eeprom_std_ofdata_to_platdata(struct udevice *dev)
50{
51 struct i2c_eeprom *priv = dev_get_priv(dev);
52 u64 data = dev_get_driver_data(dev);
53
54 /* 6 bit -> page size of up to 2^63 (should be sufficient) */
55 priv->pagewidth = data & 0x3F;
56 priv->pagesize = (1 << priv->pagewidth);
57
58 return 0;
59}
60
Masahiro Yamada5e75ea12017-06-22 16:51:22 +090061static int i2c_eeprom_std_probe(struct udevice *dev)
Simon Glass20142012014-12-10 08:55:54 -070062{
63 return 0;
64}
65
66static const struct udevice_id i2c_eeprom_std_ids[] = {
mario.six@gdsys.ccd7e28912016-06-22 15:14:16 +020067 { .compatible = "i2c-eeprom", .data = 0 },
Wenyou Yang72640662017-07-31 11:25:30 +080068 { .compatible = "microchip,24aa02e48", .data = 3 },
mario.six@gdsys.ccd7e28912016-06-22 15:14:16 +020069 { .compatible = "atmel,24c01a", .data = 3 },
70 { .compatible = "atmel,24c02", .data = 3 },
71 { .compatible = "atmel,24c04", .data = 4 },
72 { .compatible = "atmel,24c08a", .data = 4 },
73 { .compatible = "atmel,24c16a", .data = 4 },
Wenyou Yangde656752017-07-31 11:25:31 +080074 { .compatible = "atmel,24mac402", .data = 4 },
mario.six@gdsys.ccd7e28912016-06-22 15:14:16 +020075 { .compatible = "atmel,24c32", .data = 5 },
76 { .compatible = "atmel,24c64", .data = 5 },
77 { .compatible = "atmel,24c128", .data = 6 },
78 { .compatible = "atmel,24c256", .data = 6 },
79 { .compatible = "atmel,24c512", .data = 6 },
Simon Glass20142012014-12-10 08:55:54 -070080 { }
81};
82
83U_BOOT_DRIVER(i2c_eeprom_std) = {
mario.six@gdsys.ccd7e28912016-06-22 15:14:16 +020084 .name = "i2c_eeprom",
85 .id = UCLASS_I2C_EEPROM,
86 .of_match = i2c_eeprom_std_ids,
87 .probe = i2c_eeprom_std_probe,
88 .ofdata_to_platdata = i2c_eeprom_std_ofdata_to_platdata,
89 .priv_auto_alloc_size = sizeof(struct i2c_eeprom),
90 .ops = &i2c_eeprom_std_ops,
Simon Glass20142012014-12-10 08:55:54 -070091};
92
93UCLASS_DRIVER(i2c_eeprom) = {
94 .id = UCLASS_I2C_EEPROM,
95 .name = "i2c_eeprom",
96};