Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Wenyou Yang | d9b23e2 | 2017-09-01 16:26:16 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Microchip |
| 4 | * Wenyou Yang <wenyou.yang@microchip.com> |
Wenyou Yang | d9b23e2 | 2017-09-01 16:26:16 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
Simon Glass | 9fb625c | 2019-08-01 09:46:51 -0600 | [diff] [blame^] | 9 | #include <env.h> |
Alex Kiernan | 9925f1d | 2018-04-01 09:22:38 +0000 | [diff] [blame] | 10 | #include <environment.h> |
Wenyou Yang | d9b23e2 | 2017-09-01 16:26:16 +0800 | [diff] [blame] | 11 | #include <i2c_eeprom.h> |
| 12 | #include <netdev.h> |
| 13 | |
| 14 | int at91_set_ethaddr(int offset) |
| 15 | { |
| 16 | const int ETH_ADDR_LEN = 6; |
| 17 | unsigned char ethaddr[ETH_ADDR_LEN]; |
| 18 | const char *ETHADDR_NAME = "ethaddr"; |
| 19 | struct udevice *dev; |
| 20 | int ret; |
| 21 | |
| 22 | if (env_get(ETHADDR_NAME)) |
| 23 | return 0; |
| 24 | |
| 25 | ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev); |
| 26 | if (ret) |
| 27 | return ret; |
| 28 | |
| 29 | ret = i2c_eeprom_read(dev, offset, ethaddr, 6); |
| 30 | if (ret) |
| 31 | return ret; |
| 32 | |
| 33 | if (is_valid_ethaddr(ethaddr)) |
| 34 | eth_env_set_enetaddr(ETHADDR_NAME, ethaddr); |
| 35 | |
| 36 | return 0; |
| 37 | } |