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