treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / soc / rockchip / grf.c
blob494cf2b5bf7b6c813f7e4cbf5ba79112ade65aff
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Rockchip Generic Register Files setup
5 * Copyright (c) 2016 Heiko Stuebner <heiko@sntech.de>
6 */
8 #include <linux/err.h>
9 #include <linux/mfd/syscon.h>
10 #include <linux/of_device.h>
11 #include <linux/platform_device.h>
12 #include <linux/regmap.h>
14 #define HIWORD_UPDATE(val, mask, shift) \
15 ((val) << (shift) | (mask) << ((shift) + 16))
17 struct rockchip_grf_value {
18 const char *desc;
19 u32 reg;
20 u32 val;
23 struct rockchip_grf_info {
24 const struct rockchip_grf_value *values;
25 int num_values;
28 #define RK3036_GRF_SOC_CON0 0x140
30 static const struct rockchip_grf_value rk3036_defaults[] __initconst = {
32 * Disable auto jtag/sdmmc switching that causes issues with the
33 * clock-framework and the mmc controllers making them unreliable.
35 { "jtag switching", RK3036_GRF_SOC_CON0, HIWORD_UPDATE(0, 1, 11) },
38 static const struct rockchip_grf_info rk3036_grf __initconst = {
39 .values = rk3036_defaults,
40 .num_values = ARRAY_SIZE(rk3036_defaults),
43 #define RK3128_GRF_SOC_CON0 0x140
45 static const struct rockchip_grf_value rk3128_defaults[] __initconst = {
46 { "jtag switching", RK3128_GRF_SOC_CON0, HIWORD_UPDATE(0, 1, 8) },
49 static const struct rockchip_grf_info rk3128_grf __initconst = {
50 .values = rk3128_defaults,
51 .num_values = ARRAY_SIZE(rk3128_defaults),
54 #define RK3228_GRF_SOC_CON6 0x418
56 static const struct rockchip_grf_value rk3228_defaults[] __initconst = {
57 { "jtag switching", RK3228_GRF_SOC_CON6, HIWORD_UPDATE(0, 1, 8) },
60 static const struct rockchip_grf_info rk3228_grf __initconst = {
61 .values = rk3228_defaults,
62 .num_values = ARRAY_SIZE(rk3228_defaults),
65 #define RK3288_GRF_SOC_CON0 0x244
66 #define RK3288_GRF_SOC_CON2 0x24c
68 static const struct rockchip_grf_value rk3288_defaults[] __initconst = {
69 { "jtag switching", RK3288_GRF_SOC_CON0, HIWORD_UPDATE(0, 1, 12) },
70 { "pwm select", RK3288_GRF_SOC_CON2, HIWORD_UPDATE(1, 1, 0) },
73 static const struct rockchip_grf_info rk3288_grf __initconst = {
74 .values = rk3288_defaults,
75 .num_values = ARRAY_SIZE(rk3288_defaults),
78 #define RK3328_GRF_SOC_CON4 0x410
80 static const struct rockchip_grf_value rk3328_defaults[] __initconst = {
81 { "jtag switching", RK3328_GRF_SOC_CON4, HIWORD_UPDATE(0, 1, 12) },
84 static const struct rockchip_grf_info rk3328_grf __initconst = {
85 .values = rk3328_defaults,
86 .num_values = ARRAY_SIZE(rk3328_defaults),
89 #define RK3368_GRF_SOC_CON15 0x43c
91 static const struct rockchip_grf_value rk3368_defaults[] __initconst = {
92 { "jtag switching", RK3368_GRF_SOC_CON15, HIWORD_UPDATE(0, 1, 13) },
95 static const struct rockchip_grf_info rk3368_grf __initconst = {
96 .values = rk3368_defaults,
97 .num_values = ARRAY_SIZE(rk3368_defaults),
100 #define RK3399_GRF_SOC_CON7 0xe21c
102 static const struct rockchip_grf_value rk3399_defaults[] __initconst = {
103 { "jtag switching", RK3399_GRF_SOC_CON7, HIWORD_UPDATE(0, 1, 12) },
106 static const struct rockchip_grf_info rk3399_grf __initconst = {
107 .values = rk3399_defaults,
108 .num_values = ARRAY_SIZE(rk3399_defaults),
111 static const struct of_device_id rockchip_grf_dt_match[] __initconst = {
113 .compatible = "rockchip,rk3036-grf",
114 .data = (void *)&rk3036_grf,
115 }, {
116 .compatible = "rockchip,rk3128-grf",
117 .data = (void *)&rk3128_grf,
118 }, {
119 .compatible = "rockchip,rk3228-grf",
120 .data = (void *)&rk3228_grf,
121 }, {
122 .compatible = "rockchip,rk3288-grf",
123 .data = (void *)&rk3288_grf,
124 }, {
125 .compatible = "rockchip,rk3328-grf",
126 .data = (void *)&rk3328_grf,
127 }, {
128 .compatible = "rockchip,rk3368-grf",
129 .data = (void *)&rk3368_grf,
130 }, {
131 .compatible = "rockchip,rk3399-grf",
132 .data = (void *)&rk3399_grf,
134 { /* sentinel */ },
137 static int __init rockchip_grf_init(void)
139 const struct rockchip_grf_info *grf_info;
140 const struct of_device_id *match;
141 struct device_node *np;
142 struct regmap *grf;
143 int ret, i;
145 np = of_find_matching_node_and_match(NULL, rockchip_grf_dt_match,
146 &match);
147 if (!np)
148 return -ENODEV;
149 if (!match || !match->data) {
150 pr_err("%s: missing grf data\n", __func__);
151 return -EINVAL;
154 grf_info = match->data;
156 grf = syscon_node_to_regmap(np);
157 if (IS_ERR(grf)) {
158 pr_err("%s: could not get grf syscon\n", __func__);
159 return PTR_ERR(grf);
162 for (i = 0; i < grf_info->num_values; i++) {
163 const struct rockchip_grf_value *val = &grf_info->values[i];
165 pr_debug("%s: adjusting %s in %#6x to %#10x\n", __func__,
166 val->desc, val->reg, val->val);
167 ret = regmap_write(grf, val->reg, val->val);
168 if (ret < 0)
169 pr_err("%s: write to %#6x failed with %d\n",
170 __func__, val->reg, ret);
173 return 0;
175 postcore_initcall(rockchip_grf_init);