1 // SPDX-License-Identifier: GPL-2.0+
3 * eFuse driver for Rockchip devices
5 * Copyright 2017, Theobroma Systems Design und Consulting GmbH
6 * Written by Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
12 #include <display_options.h>
14 #include <linux/bitops.h>
15 #include <linux/delay.h>
18 #define RK3399_A_SHIFT 16
19 #define RK3399_A_MASK 0x3ff
20 #define RK3399_NFUSES 32
21 #define RK3399_BYTES_PER_FUSE 4
22 #define RK3399_STROBSFTSEL BIT(9)
23 #define RK3399_RSB BIT(7)
24 #define RK3399_PD BIT(5)
25 #define RK3399_PGENB BIT(3)
26 #define RK3399_LOAD BIT(2)
27 #define RK3399_STROBE BIT(1)
28 #define RK3399_CSB BIT(0)
30 struct rockchip_efuse_regs {
31 u32 ctrl; /* 0x00 efuse control register */
32 u32 dout; /* 0x04 efuse data out register */
33 u32 rf; /* 0x08 efuse redundancy bit used register */
35 u32 jtag_pass; /* 0x10 JTAG password */
36 u32 strobe_finish_ctrl;
37 /* 0x14 efuse strobe finish control register */
40 struct rockchip_efuse_plat {
46 static int dump_efuses(struct cmd_tbl *cmdtp, int flag,
47 int argc, char *const argv[])
50 * N.B.: This function is tailored towards the RK3399 and assumes that
51 * there's always 32 fuses x 32 bits (i.e. 128 bytes of data) to
59 /* retrieve the device */
60 ret = uclass_get_device_by_driver(UCLASS_MISC,
61 DM_DRIVER_GET(rockchip_efuse), &dev);
63 printf("%s: no misc-device found\n", __func__);
67 ret = misc_read(dev, 0, &fuses, sizeof(fuses));
69 printf("%s: misc_read failed\n", __func__);
73 printf("efuse-contents:\n");
74 print_buffer(0, fuses, 1, 128, 16);
80 rk3399_dump_efuses, 1, 1, dump_efuses,
81 "Dump the content of the efuses",
86 static int rockchip_rk3399_efuse_read(struct udevice *dev, int offset,
89 struct rockchip_efuse_plat *plat = dev_get_plat(dev);
90 struct rockchip_efuse_regs *efuse =
91 (struct rockchip_efuse_regs *)plat->base;
93 unsigned int addr_start, addr_end, addr_offset;
95 u8 bytes[RK3399_NFUSES * RK3399_BYTES_PER_FUSE];
99 addr_start = offset / RK3399_BYTES_PER_FUSE;
100 addr_offset = offset % RK3399_BYTES_PER_FUSE;
101 addr_end = DIV_ROUND_UP(offset + size, RK3399_BYTES_PER_FUSE);
103 /* cap to the size of the efuse block */
104 if (addr_end > RK3399_NFUSES)
105 addr_end = RK3399_NFUSES;
107 writel(RK3399_LOAD | RK3399_PGENB | RK3399_STROBSFTSEL | RK3399_RSB,
110 for (addr = addr_start; addr < addr_end; addr++) {
111 setbits_le32(&efuse->ctrl,
112 RK3399_STROBE | (addr << RK3399_A_SHIFT));
114 out_value = readl(&efuse->dout);
115 clrbits_le32(&efuse->ctrl, RK3399_STROBE);
118 memcpy(&bytes[i], &out_value, RK3399_BYTES_PER_FUSE);
119 i += RK3399_BYTES_PER_FUSE;
122 /* Switch to standby mode */
123 writel(RK3399_PD | RK3399_CSB, &efuse->ctrl);
125 memcpy(buf, bytes + addr_offset, size);
130 static int rockchip_efuse_read(struct udevice *dev, int offset,
133 return rockchip_rk3399_efuse_read(dev, offset, buf, size);
136 static const struct misc_ops rockchip_efuse_ops = {
137 .read = rockchip_efuse_read,
140 static int rockchip_efuse_of_to_plat(struct udevice *dev)
142 struct rockchip_efuse_plat *plat = dev_get_plat(dev);
144 plat->base = dev_read_addr_ptr(dev);
148 static const struct udevice_id rockchip_efuse_ids[] = {
149 { .compatible = "rockchip,rk3399-efuse" },
153 U_BOOT_DRIVER(rockchip_efuse) = {
154 .name = "rockchip_efuse",
156 .of_match = rockchip_efuse_ids,
157 .of_to_plat = rockchip_efuse_of_to_plat,
158 .plat_auto = sizeof(struct rockchip_efuse_plat),
159 .ops = &rockchip_efuse_ops,