Paweł Anikiel | 3515aed | 2022-06-17 12:47:19 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright 2022 Google LLC |
| 4 | */ |
| 5 | #include <net.h> |
| 6 | #include <dm/device.h> |
| 7 | #include <dm/uclass.h> |
| 8 | #include <atsha204a-i2c.h> |
| 9 | #include "mercury_aa1.h" |
| 10 | |
| 11 | #define MERCURY_AA1_ATSHA204A_OTP_MAC0 4 |
| 12 | #define MERCURY_AA1_ATSHA204A_OTP_MAC1 5 |
| 13 | |
| 14 | int mercury_aa1_read_mac(u8 *mac) |
| 15 | { |
| 16 | struct udevice *dev; |
| 17 | u8 buf[8]; |
| 18 | int ret; |
| 19 | |
| 20 | ret = uclass_get_device_by_name(UCLASS_MISC, "atsha204a@64", &dev); |
| 21 | if (ret) |
| 22 | return ret; |
| 23 | |
| 24 | ret = atsha204a_wakeup(dev); |
| 25 | if (ret) |
| 26 | return ret; |
| 27 | |
| 28 | ret = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false, |
| 29 | MERCURY_AA1_ATSHA204A_OTP_MAC0, buf); |
| 30 | if (ret) |
| 31 | goto sleep; |
| 32 | |
| 33 | ret = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false, |
| 34 | MERCURY_AA1_ATSHA204A_OTP_MAC1, buf + 4); |
| 35 | if (ret) |
| 36 | goto sleep; |
| 37 | |
| 38 | memcpy(mac, buf, ARP_HLEN); |
| 39 | |
| 40 | sleep: |
| 41 | atsha204a_sleep(dev); |
| 42 | return ret; |
| 43 | } |