arm: vf610: add uart0 clock/iomux definitions
[u-boot/qq2440-u-boot.git] / drivers / bootcount / bootcount_i2c.c
blobe27b168c55cc556f5006894d63e284bcc08f654e
1 /*
2 * (C) Copyright 2013
3 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
6 */
8 #include <bootcount.h>
9 #include <linux/compiler.h>
10 #include <i2c.h>
12 #define BC_MAGIC 0xbc
14 void bootcount_store(ulong a)
16 unsigned char buf[3];
17 int ret;
19 buf[0] = BC_MAGIC;
20 buf[1] = (a & 0xff);
21 ret = i2c_write(CONFIG_SYS_I2C_RTC_ADDR, CONFIG_SYS_BOOTCOUNT_ADDR,
22 CONFIG_BOOTCOUNT_ALEN, buf, 2);
23 if (ret != 0)
24 puts("Error writing bootcount\n");
27 ulong bootcount_load(void)
29 unsigned char buf[3];
30 int ret;
32 ret = i2c_read(CONFIG_SYS_I2C_RTC_ADDR, CONFIG_SYS_BOOTCOUNT_ADDR,
33 CONFIG_BOOTCOUNT_ALEN, buf, 2);
34 if (ret != 0) {
35 puts("Error loading bootcount\n");
36 return 0;
38 if (buf[0] == BC_MAGIC)
39 return buf[1];
41 bootcount_store(0);
43 return 0;