From 490463fcd58ebce2e06033c349e2b9eda569e07b Mon Sep 17 00:00:00 2001 From: Ivan Date: Mon, 13 Mar 2017 19:44:32 +0900 Subject: [PATCH] s5j/efuse: add s5j_efuse_get_mac_addr() To get WLAN driver work, we need to implement s5j_efuse_get_mac_addr() which reads MAC address from OTP area. This commit can be reverted after the WLAN driver can read it by itself. Change-Id: Ida4dcc32c57605f2df33fb68d6b2bf5223b2f83d Signed-off-by: Ivan Signed-off-by: Heesub Shin --- os/arch/arm/src/s5j/Make.defs | 2 + os/arch/arm/src/s5j/s5j_efuse.c | 87 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 os/arch/arm/src/s5j/s5j_efuse.c diff --git a/os/arch/arm/src/s5j/Make.defs b/os/arch/arm/src/s5j/Make.defs index 9d0d51e..3bca2dd 100644 --- a/os/arch/arm/src/s5j/Make.defs +++ b/os/arch/arm/src/s5j/Make.defs @@ -147,6 +147,8 @@ endif ifeq ($(CONFIG_S5J_EFUSE),y) CHIP_CSRCS += s5j_efuse.c +else +CHIP_CSRCS += s5j_efuse.c endif ifeq ($(CONFIG_S5J_LEDCTRLBLK),y) diff --git a/os/arch/arm/src/s5j/s5j_efuse.c b/os/arch/arm/src/s5j/s5j_efuse.c new file mode 100644 index 0000000..5318532 --- /dev/null +++ b/os/arch/arm/src/s5j/s5j_efuse.c @@ -0,0 +1,87 @@ +/**************************************************************************** + * + * Copyright 2017 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + * + ****************************************************************************/ +/**************************************************************************** + * arch/arm/src/s5j/s5j_efuse.c + * + * Copyright (C) 2009-2010, 2014-2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include "up_arch.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ +int s5j_efuse_get_mac_addr(char *macaddr) +{ + int i; + union { + unsigned long long raw; + struct { + unsigned int low; + unsigned int high; + }; + unsigned char bytes[8]; + } addr; + + putreg32(0x003c0180, 0x8000032c); + putreg32(0x00000001, 0x80000328); + + while ((getreg32(0x80000400) & 0x1) == 0); + + addr.low = getreg32(0x80000320); + addr.high = getreg32(0x80000324); + + addr.raw = addr.raw >> 6; + + for (i = 5; i >= 0; i--) + *macaddr++ = addr.bytes[i]; + + return 0; +} -- 2.7.4