/*1* Copyright (c) 2018 naehrwert2*3* This program is free software; you can redistribute it and/or modify it4* under the terms and conditions of the GNU General Public License,5* version 2, as published by the Free Software Foundation.6*7* This program is distributed in the hope it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for10* more details.11*12* You should have received a copy of the GNU General Public License13* along with this program. If not, see <http://www.gnu.org/licenses/>.14*/1516#include <soc/kfuse.h>17#include <soc/clock.h>18#include <soc/t210.h>1920int kfuse_wait_ready()21{22// Wait for KFUSE to finish init and verification of data.23while (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_DONE))24;2526if (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_CRCPASS))27return 0;2829return 1;30}3132int kfuse_read(u32 *buf)33{34int res = 0;3536clock_enable_kfuse();3738if (!kfuse_wait_ready())39goto out;4041KFUSE(KFUSE_KEYADDR) = KFUSE_KEYADDR_AUTOINC;42for (int i = 0; i < KFUSE_NUM_WORDS; i++)43buf[i] = KFUSE(KFUSE_KEYS);4445res = 1;4647out:48clock_disable_kfuse();49return res;50}515253