Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpufreq: imx6: use regmap to read ocotp register

Reading the ocotp register directly is unsafe and will cause the system
to hang if its clock is not turned on in CCM. The regmap interface has
clk enabled, which can solve this problem.

Signed-off-by: tianyu2 <tianyu2@kernelsoft.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

authored by

tianyu2 and committed by
Viresh Kumar
f21401ca 6613476e

+14 -29
+14 -29
drivers/cpufreq/imx6q-cpufreq.c
··· 14 14 #include <linux/pm_opp.h> 15 15 #include <linux/platform_device.h> 16 16 #include <linux/regulator/consumer.h> 17 + #include <linux/mfd/syscon.h> 18 + #include <linux/regmap.h> 17 19 18 20 #define PU_SOC_VOLTAGE_NORMAL 1250000 19 21 #define PU_SOC_VOLTAGE_HIGH 1275000 ··· 227 225 228 226 static int imx6q_opp_check_speed_grading(struct device *dev) 229 227 { 230 - struct device_node *np; 231 - void __iomem *base; 232 228 u32 val; 233 229 int ret; 234 230 ··· 235 235 if (ret) 236 236 return ret; 237 237 } else { 238 - np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-ocotp"); 239 - if (!np) 240 - return -ENOENT; 238 + struct regmap *ocotp; 241 239 242 - base = of_iomap(np, 0); 243 - of_node_put(np); 244 - if (!base) { 245 - dev_err(dev, "failed to map ocotp\n"); 246 - return -EFAULT; 247 - } 240 + ocotp = syscon_regmap_lookup_by_compatible("fsl,imx6q-ocotp"); 241 + if (IS_ERR(ocotp)) 242 + return -ENOENT; 248 243 249 244 /* 250 245 * SPEED_GRADING[1:0] defines the max speed of ARM: ··· 249 254 * 2b'00: 792000000Hz; 250 255 * We need to set the max speed of ARM according to fuse map. 251 256 */ 252 - val = readl_relaxed(base + OCOTP_CFG3); 253 - iounmap(base); 257 + regmap_read(ocotp, OCOTP_CFG3, &val); 254 258 } 255 259 256 260 val >>= OCOTP_CFG3_SPEED_SHIFT; ··· 284 290 if (ret) 285 291 return ret; 286 292 } else { 287 - struct device_node *np; 288 - void __iomem *base; 293 + struct regmap *ocotp; 289 294 290 - np = of_find_compatible_node(NULL, NULL, "fsl,imx6ul-ocotp"); 291 - if (!np) 292 - np = of_find_compatible_node(NULL, NULL, 293 - "fsl,imx6ull-ocotp"); 294 - if (!np) 295 + ocotp = syscon_regmap_lookup_by_compatible("fsl,imx6ul-ocotp"); 296 + if (IS_ERR(ocotp)) 297 + ocotp = syscon_regmap_lookup_by_compatible("fsl,imx6ull-ocotp"); 298 + 299 + if (IS_ERR(ocotp)) 295 300 return -ENOENT; 296 301 297 - base = of_iomap(np, 0); 298 - of_node_put(np); 299 - if (!base) { 300 - dev_err(dev, "failed to map ocotp\n"); 301 - return -EFAULT; 302 - } 303 - 304 - val = readl_relaxed(base + OCOTP_CFG3); 305 - iounmap(base); 302 + regmap_read(ocotp, OCOTP_CFG3, &val); 306 303 } 307 304 308 305 /*