blob: c9f4174bad42f928e707e7a2570e24a827bca536 [file] [log] [blame]
Simon Glass20142012014-12-10 08:55:54 -07001/*
2 * Copyright (c) 2014 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Masahiro Yamadaee5ee872014-12-18 20:00:26 +09008#include <linux/err.h>
Simon Glass20142012014-12-10 08:55:54 -07009#include <dm.h>
10#include <i2c.h>
11#include <i2c_eeprom.h>
12
13static int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf,
14 int size)
15{
mario.six@gdsys.ccd7e28912016-06-22 15:14:16 +020016 return dm_i2c_read(dev, offset, buf, size);
Simon Glass20142012014-12-10 08:55:54 -070017}
18
19static int i2c_eeprom_write(struct udevice *dev, int offset,
20 const uint8_t *buf, int size)
21{
22 return -ENODEV;
23}
24
25struct i2c_eeprom_ops i2c_eeprom_std_ops = {
26 .read = i2c_eeprom_read,
27 .write = i2c_eeprom_write,
28};
29
mario.six@gdsys.ccd7e28912016-06-22 15:14:16 +020030static int i2c_eeprom_std_ofdata_to_platdata(struct udevice *dev)
31{
32 struct i2c_eeprom *priv = dev_get_priv(dev);
33 u64 data = dev_get_driver_data(dev);
34
35 /* 6 bit -> page size of up to 2^63 (should be sufficient) */
36 priv->pagewidth = data & 0x3F;
37 priv->pagesize = (1 << priv->pagewidth);
38
39 return 0;
40}
41
Simon Glass20142012014-12-10 08:55:54 -070042int i2c_eeprom_std_probe(struct udevice *dev)
43{
44 return 0;
45}
46
47static const struct udevice_id i2c_eeprom_std_ids[] = {
mario.six@gdsys.ccd7e28912016-06-22 15:14:16 +020048 { .compatible = "i2c-eeprom", .data = 0 },
49 { .compatible = "atmel,24c01a", .data = 3 },
50 { .compatible = "atmel,24c02", .data = 3 },
51 { .compatible = "atmel,24c04", .data = 4 },
52 { .compatible = "atmel,24c08a", .data = 4 },
53 { .compatible = "atmel,24c16a", .data = 4 },
54 { .compatible = "atmel,24c32", .data = 5 },
55 { .compatible = "atmel,24c64", .data = 5 },
56 { .compatible = "atmel,24c128", .data = 6 },
57 { .compatible = "atmel,24c256", .data = 6 },
58 { .compatible = "atmel,24c512", .data = 6 },
Simon Glass20142012014-12-10 08:55:54 -070059 { }
60};
61
62U_BOOT_DRIVER(i2c_eeprom_std) = {
mario.six@gdsys.ccd7e28912016-06-22 15:14:16 +020063 .name = "i2c_eeprom",
64 .id = UCLASS_I2C_EEPROM,
65 .of_match = i2c_eeprom_std_ids,
66 .probe = i2c_eeprom_std_probe,
67 .ofdata_to_platdata = i2c_eeprom_std_ofdata_to_platdata,
68 .priv_auto_alloc_size = sizeof(struct i2c_eeprom),
69 .ops = &i2c_eeprom_std_ops,
Simon Glass20142012014-12-10 08:55:54 -070070};
71
72UCLASS_DRIVER(i2c_eeprom) = {
73 .id = UCLASS_I2C_EEPROM,
74 .name = "i2c_eeprom",
75};