Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 6ca4ba0 | 2014-12-10 08:55:54 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014 Google, Inc |
Simon Glass | 6ca4ba0 | 2014-12-10 08:55:54 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Masahiro Yamada | f9d52cc | 2014-12-18 20:00:26 +0900 | [diff] [blame] | 7 | #include <linux/err.h> |
Simon Glass | 6ca4ba0 | 2014-12-10 08:55:54 -0700 | [diff] [blame] | 8 | #include <dm.h> |
| 9 | #include <i2c.h> |
| 10 | #include <i2c_eeprom.h> |
| 11 | |
Jonas Karlman | 8427a24 | 2017-04-22 08:57:41 +0000 | [diff] [blame] | 12 | int 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 | |
| 22 | int 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 | |
| 32 | static int i2c_eeprom_std_read(struct udevice *dev, int offset, uint8_t *buf, |
| 33 | int size) |
Simon Glass | 6ca4ba0 | 2014-12-10 08:55:54 -0700 | [diff] [blame] | 34 | { |
mario.six@gdsys.cc | 7559ac4 | 2016-06-22 15:14:16 +0200 | [diff] [blame] | 35 | return dm_i2c_read(dev, offset, buf, size); |
Simon Glass | 6ca4ba0 | 2014-12-10 08:55:54 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Jonas Karlman | 8427a24 | 2017-04-22 08:57:41 +0000 | [diff] [blame] | 38 | static int i2c_eeprom_std_write(struct udevice *dev, int offset, |
| 39 | const uint8_t *buf, int size) |
Simon Glass | 6ca4ba0 | 2014-12-10 08:55:54 -0700 | [diff] [blame] | 40 | { |
| 41 | return -ENODEV; |
| 42 | } |
| 43 | |
Masahiro Yamada | a7cc93e8 | 2017-06-22 16:51:22 +0900 | [diff] [blame] | 44 | static const struct i2c_eeprom_ops i2c_eeprom_std_ops = { |
Jonas Karlman | 8427a24 | 2017-04-22 08:57:41 +0000 | [diff] [blame] | 45 | .read = i2c_eeprom_std_read, |
| 46 | .write = i2c_eeprom_std_write, |
Simon Glass | 6ca4ba0 | 2014-12-10 08:55:54 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
mario.six@gdsys.cc | 7559ac4 | 2016-06-22 15:14:16 +0200 | [diff] [blame] | 49 | static 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); |
Baruch Siach | 263b5b0 | 2019-04-07 12:38:48 +0300 | [diff] [blame^] | 53 | u32 pagesize; |
| 54 | |
| 55 | if (dev_read_u32(dev, "pagesize", &pagesize) == 0) { |
| 56 | priv->pagesize = pagesize; |
| 57 | return 0; |
| 58 | } |
mario.six@gdsys.cc | 7559ac4 | 2016-06-22 15:14:16 +0200 | [diff] [blame] | 59 | |
| 60 | /* 6 bit -> page size of up to 2^63 (should be sufficient) */ |
| 61 | priv->pagewidth = data & 0x3F; |
| 62 | priv->pagesize = (1 << priv->pagewidth); |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
Masahiro Yamada | a7cc93e8 | 2017-06-22 16:51:22 +0900 | [diff] [blame] | 67 | static int i2c_eeprom_std_probe(struct udevice *dev) |
Simon Glass | 6ca4ba0 | 2014-12-10 08:55:54 -0700 | [diff] [blame] | 68 | { |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | static const struct udevice_id i2c_eeprom_std_ids[] = { |
mario.six@gdsys.cc | 7559ac4 | 2016-06-22 15:14:16 +0200 | [diff] [blame] | 73 | { .compatible = "i2c-eeprom", .data = 0 }, |
Wenyou Yang | 6db5042 | 2017-07-31 11:25:30 +0800 | [diff] [blame] | 74 | { .compatible = "microchip,24aa02e48", .data = 3 }, |
mario.six@gdsys.cc | 7559ac4 | 2016-06-22 15:14:16 +0200 | [diff] [blame] | 75 | { .compatible = "atmel,24c01a", .data = 3 }, |
| 76 | { .compatible = "atmel,24c02", .data = 3 }, |
| 77 | { .compatible = "atmel,24c04", .data = 4 }, |
Michal Simek | 191d02e | 2019-01-21 13:54:57 +0100 | [diff] [blame] | 78 | { .compatible = "atmel,24c08", .data = 4 }, |
mario.six@gdsys.cc | 7559ac4 | 2016-06-22 15:14:16 +0200 | [diff] [blame] | 79 | { .compatible = "atmel,24c08a", .data = 4 }, |
| 80 | { .compatible = "atmel,24c16a", .data = 4 }, |
Wenyou Yang | 911a610 | 2017-07-31 11:25:31 +0800 | [diff] [blame] | 81 | { .compatible = "atmel,24mac402", .data = 4 }, |
mario.six@gdsys.cc | 7559ac4 | 2016-06-22 15:14:16 +0200 | [diff] [blame] | 82 | { .compatible = "atmel,24c32", .data = 5 }, |
| 83 | { .compatible = "atmel,24c64", .data = 5 }, |
| 84 | { .compatible = "atmel,24c128", .data = 6 }, |
| 85 | { .compatible = "atmel,24c256", .data = 6 }, |
| 86 | { .compatible = "atmel,24c512", .data = 6 }, |
Simon Glass | 6ca4ba0 | 2014-12-10 08:55:54 -0700 | [diff] [blame] | 87 | { } |
| 88 | }; |
| 89 | |
| 90 | U_BOOT_DRIVER(i2c_eeprom_std) = { |
mario.six@gdsys.cc | 7559ac4 | 2016-06-22 15:14:16 +0200 | [diff] [blame] | 91 | .name = "i2c_eeprom", |
| 92 | .id = UCLASS_I2C_EEPROM, |
| 93 | .of_match = i2c_eeprom_std_ids, |
| 94 | .probe = i2c_eeprom_std_probe, |
| 95 | .ofdata_to_platdata = i2c_eeprom_std_ofdata_to_platdata, |
| 96 | .priv_auto_alloc_size = sizeof(struct i2c_eeprom), |
| 97 | .ops = &i2c_eeprom_std_ops, |
Simon Glass | 6ca4ba0 | 2014-12-10 08:55:54 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | UCLASS_DRIVER(i2c_eeprom) = { |
| 101 | .id = UCLASS_I2C_EEPROM, |
| 102 | .name = "i2c_eeprom", |
| 103 | }; |