ti-cpufreq.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * TI CPUFreq/OPP hw-supported driver
  4. *
  5. * Copyright (C) 2016-2017 Texas Instruments, Inc.
  6. * Dave Gerlach <d-gerlach@ti.com>
  7. */
  8. #include <linux/cpu.h>
  9. #include <linux/io.h>
  10. #include <linux/mfd/syscon.h>
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/of.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/pm_opp.h>
  16. #include <linux/regmap.h>
  17. #include <linux/slab.h>
  18. #include <linux/sys_soc.h>
  19. #define REVISION_MASK 0xF
  20. #define REVISION_SHIFT 28
  21. #define AM33XX_800M_ARM_MPU_MAX_FREQ 0x1E2F
  22. #define AM43XX_600M_ARM_MPU_MAX_FREQ 0xFFA
  23. #define DRA7_EFUSE_HAS_OD_MPU_OPP 11
  24. #define DRA7_EFUSE_HAS_HIGH_MPU_OPP 15
  25. #define DRA76_EFUSE_HAS_PLUS_MPU_OPP 18
  26. #define DRA7_EFUSE_HAS_ALL_MPU_OPP 23
  27. #define DRA76_EFUSE_HAS_ALL_MPU_OPP 24
  28. #define DRA7_EFUSE_NOM_MPU_OPP BIT(0)
  29. #define DRA7_EFUSE_OD_MPU_OPP BIT(1)
  30. #define DRA7_EFUSE_HIGH_MPU_OPP BIT(2)
  31. #define DRA76_EFUSE_PLUS_MPU_OPP BIT(3)
  32. #define OMAP3_CONTROL_DEVICE_STATUS 0x4800244C
  33. #define OMAP3_CONTROL_IDCODE 0x4830A204
  34. #define OMAP34xx_ProdID_SKUID 0x4830A20C
  35. #define OMAP3_SYSCON_BASE (0x48000000 + 0x2000 + 0x270)
  36. #define AM625_EFUSE_K_MPU_OPP 11
  37. #define AM625_EFUSE_S_MPU_OPP 19
  38. #define AM625_EFUSE_T_MPU_OPP 20
  39. #define AM625_SUPPORT_K_MPU_OPP BIT(0)
  40. #define AM625_SUPPORT_S_MPU_OPP BIT(1)
  41. #define AM625_SUPPORT_T_MPU_OPP BIT(2)
  42. enum {
  43. AM62A7_EFUSE_M_MPU_OPP = 13,
  44. AM62A7_EFUSE_N_MPU_OPP,
  45. AM62A7_EFUSE_O_MPU_OPP,
  46. AM62A7_EFUSE_P_MPU_OPP,
  47. AM62A7_EFUSE_Q_MPU_OPP,
  48. AM62A7_EFUSE_R_MPU_OPP,
  49. AM62A7_EFUSE_S_MPU_OPP,
  50. /*
  51. * The V, U, and T speed grade numbering is out of order
  52. * to align with the AM625 more uniformly. I promise I know
  53. * my ABCs ;)
  54. */
  55. AM62A7_EFUSE_V_MPU_OPP,
  56. AM62A7_EFUSE_U_MPU_OPP,
  57. AM62A7_EFUSE_T_MPU_OPP,
  58. };
  59. #define AM62A7_SUPPORT_N_MPU_OPP BIT(0)
  60. #define AM62A7_SUPPORT_R_MPU_OPP BIT(1)
  61. #define AM62A7_SUPPORT_V_MPU_OPP BIT(2)
  62. #define AM62L3_EFUSE_E_MPU_OPP 5
  63. #define AM62L3_EFUSE_O_MPU_OPP 15
  64. #define AM62L3_SUPPORT_E_MPU_OPP BIT(0)
  65. #define AM62L3_SUPPORT_O_MPU_OPP BIT(1)
  66. #define AM62P5_EFUSE_O_MPU_OPP 15
  67. #define AM62P5_EFUSE_S_MPU_OPP 19
  68. #define AM62P5_EFUSE_T_MPU_OPP 20
  69. #define AM62P5_EFUSE_U_MPU_OPP 21
  70. #define AM62P5_EFUSE_V_MPU_OPP 22
  71. #define AM62P5_SUPPORT_O_MPU_OPP BIT(0)
  72. #define AM62P5_SUPPORT_U_MPU_OPP BIT(2)
  73. #define VERSION_COUNT 2
  74. struct ti_cpufreq_data;
  75. struct ti_cpufreq_soc_data {
  76. const char * const *reg_names;
  77. unsigned long (*efuse_xlate)(struct ti_cpufreq_data *opp_data,
  78. unsigned long efuse);
  79. unsigned long efuse_fallback;
  80. unsigned long efuse_offset;
  81. unsigned long efuse_mask;
  82. unsigned long efuse_shift;
  83. unsigned long rev_offset;
  84. bool multi_regulator;
  85. /* Backward compatibility hack: Might have missing syscon */
  86. #define TI_QUIRK_SYSCON_MAY_BE_MISSING 0x1
  87. /* Backward compatibility hack: new syscon size is 1 register wide */
  88. #define TI_QUIRK_SYSCON_IS_SINGLE_REG 0x2
  89. u8 quirks;
  90. };
  91. struct ti_cpufreq_data {
  92. struct device *cpu_dev;
  93. struct device_node *opp_node;
  94. struct regmap *syscon;
  95. const struct ti_cpufreq_soc_data *soc_data;
  96. };
  97. static unsigned long amx3_efuse_xlate(struct ti_cpufreq_data *opp_data,
  98. unsigned long efuse)
  99. {
  100. if (!efuse)
  101. efuse = opp_data->soc_data->efuse_fallback;
  102. /* AM335x and AM437x use "OPP disable" bits, so invert */
  103. return ~efuse;
  104. }
  105. static unsigned long dra7_efuse_xlate(struct ti_cpufreq_data *opp_data,
  106. unsigned long efuse)
  107. {
  108. unsigned long calculated_efuse = DRA7_EFUSE_NOM_MPU_OPP;
  109. /*
  110. * The efuse on dra7 and am57 parts contains a specific
  111. * value indicating the highest available OPP.
  112. */
  113. switch (efuse) {
  114. case DRA76_EFUSE_HAS_PLUS_MPU_OPP:
  115. case DRA76_EFUSE_HAS_ALL_MPU_OPP:
  116. calculated_efuse |= DRA76_EFUSE_PLUS_MPU_OPP;
  117. fallthrough;
  118. case DRA7_EFUSE_HAS_ALL_MPU_OPP:
  119. case DRA7_EFUSE_HAS_HIGH_MPU_OPP:
  120. calculated_efuse |= DRA7_EFUSE_HIGH_MPU_OPP;
  121. fallthrough;
  122. case DRA7_EFUSE_HAS_OD_MPU_OPP:
  123. calculated_efuse |= DRA7_EFUSE_OD_MPU_OPP;
  124. }
  125. return calculated_efuse;
  126. }
  127. static unsigned long omap3_efuse_xlate(struct ti_cpufreq_data *opp_data,
  128. unsigned long efuse)
  129. {
  130. /* OPP enable bit ("Speed Binned") */
  131. return BIT(efuse);
  132. }
  133. static unsigned long am62p5_efuse_xlate(struct ti_cpufreq_data *opp_data,
  134. unsigned long efuse)
  135. {
  136. unsigned long calculated_efuse = AM62P5_SUPPORT_O_MPU_OPP;
  137. switch (efuse) {
  138. case AM62P5_EFUSE_V_MPU_OPP:
  139. case AM62P5_EFUSE_U_MPU_OPP:
  140. case AM62P5_EFUSE_T_MPU_OPP:
  141. case AM62P5_EFUSE_S_MPU_OPP:
  142. calculated_efuse |= AM62P5_SUPPORT_U_MPU_OPP;
  143. fallthrough;
  144. case AM62P5_EFUSE_O_MPU_OPP:
  145. calculated_efuse |= AM62P5_SUPPORT_O_MPU_OPP;
  146. }
  147. return calculated_efuse;
  148. }
  149. static unsigned long am62a7_efuse_xlate(struct ti_cpufreq_data *opp_data,
  150. unsigned long efuse)
  151. {
  152. unsigned long calculated_efuse = AM62A7_SUPPORT_N_MPU_OPP;
  153. switch (efuse) {
  154. case AM62A7_EFUSE_V_MPU_OPP:
  155. case AM62A7_EFUSE_U_MPU_OPP:
  156. case AM62A7_EFUSE_T_MPU_OPP:
  157. case AM62A7_EFUSE_S_MPU_OPP:
  158. calculated_efuse |= AM62A7_SUPPORT_V_MPU_OPP;
  159. fallthrough;
  160. case AM62A7_EFUSE_R_MPU_OPP:
  161. case AM62A7_EFUSE_Q_MPU_OPP:
  162. case AM62A7_EFUSE_P_MPU_OPP:
  163. case AM62A7_EFUSE_O_MPU_OPP:
  164. calculated_efuse |= AM62A7_SUPPORT_R_MPU_OPP;
  165. fallthrough;
  166. case AM62A7_EFUSE_N_MPU_OPP:
  167. case AM62A7_EFUSE_M_MPU_OPP:
  168. calculated_efuse |= AM62A7_SUPPORT_N_MPU_OPP;
  169. }
  170. return calculated_efuse;
  171. }
  172. static unsigned long am625_efuse_xlate(struct ti_cpufreq_data *opp_data,
  173. unsigned long efuse)
  174. {
  175. unsigned long calculated_efuse = AM625_SUPPORT_K_MPU_OPP;
  176. switch (efuse) {
  177. case AM625_EFUSE_T_MPU_OPP:
  178. calculated_efuse |= AM625_SUPPORT_T_MPU_OPP;
  179. fallthrough;
  180. case AM625_EFUSE_S_MPU_OPP:
  181. calculated_efuse |= AM625_SUPPORT_S_MPU_OPP;
  182. fallthrough;
  183. case AM625_EFUSE_K_MPU_OPP:
  184. calculated_efuse |= AM625_SUPPORT_K_MPU_OPP;
  185. }
  186. return calculated_efuse;
  187. }
  188. static unsigned long am62l3_efuse_xlate(struct ti_cpufreq_data *opp_data,
  189. unsigned long efuse)
  190. {
  191. unsigned long calculated_efuse = AM62L3_SUPPORT_E_MPU_OPP;
  192. switch (efuse) {
  193. case AM62L3_EFUSE_O_MPU_OPP:
  194. calculated_efuse |= AM62L3_SUPPORT_O_MPU_OPP;
  195. fallthrough;
  196. case AM62L3_EFUSE_E_MPU_OPP:
  197. calculated_efuse |= AM62L3_SUPPORT_E_MPU_OPP;
  198. }
  199. return calculated_efuse;
  200. }
  201. static struct ti_cpufreq_soc_data am3x_soc_data = {
  202. .efuse_xlate = amx3_efuse_xlate,
  203. .efuse_fallback = AM33XX_800M_ARM_MPU_MAX_FREQ,
  204. .efuse_offset = 0x07fc,
  205. .efuse_mask = 0x1fff,
  206. .rev_offset = 0x600,
  207. .multi_regulator = false,
  208. };
  209. static struct ti_cpufreq_soc_data am4x_soc_data = {
  210. .efuse_xlate = amx3_efuse_xlate,
  211. .efuse_fallback = AM43XX_600M_ARM_MPU_MAX_FREQ,
  212. .efuse_offset = 0x0610,
  213. .efuse_mask = 0x3f,
  214. .rev_offset = 0x600,
  215. .multi_regulator = false,
  216. };
  217. static struct ti_cpufreq_soc_data dra7_soc_data = {
  218. .efuse_xlate = dra7_efuse_xlate,
  219. .efuse_offset = 0x020c,
  220. .efuse_mask = 0xf80000,
  221. .efuse_shift = 19,
  222. .rev_offset = 0x204,
  223. .multi_regulator = true,
  224. };
  225. /*
  226. * OMAP35x TRM (SPRUF98K):
  227. * CONTROL_IDCODE (0x4830 A204) describes Silicon revisions.
  228. * Control OMAP Status Register 15:0 (Address 0x4800 244C)
  229. * to separate between omap3503, omap3515, omap3525, omap3530
  230. * and feature presence.
  231. * There are encodings for versions limited to 400/266MHz
  232. * but we ignore.
  233. * Not clear if this also holds for omap34xx.
  234. * some eFuse values e.g. CONTROL_FUSE_OPP1_VDD1
  235. * are stored in the SYSCON register range
  236. * Register 0x4830A20C [ProdID.SKUID] [0:3]
  237. * 0x0 for normal 600/430MHz device.
  238. * 0x8 for 720/520MHz device.
  239. * Not clear what omap34xx value is.
  240. */
  241. static struct ti_cpufreq_soc_data omap34xx_soc_data = {
  242. .efuse_xlate = omap3_efuse_xlate,
  243. .efuse_offset = OMAP34xx_ProdID_SKUID - OMAP3_SYSCON_BASE,
  244. .efuse_shift = 3,
  245. .efuse_mask = BIT(3),
  246. .rev_offset = OMAP3_CONTROL_IDCODE - OMAP3_SYSCON_BASE,
  247. .multi_regulator = false,
  248. .quirks = TI_QUIRK_SYSCON_MAY_BE_MISSING,
  249. };
  250. /*
  251. * AM/DM37x TRM (SPRUGN4M)
  252. * CONTROL_IDCODE (0x4830 A204) describes Silicon revisions.
  253. * Control Device Status Register 15:0 (Address 0x4800 244C)
  254. * to separate between am3703, am3715, dm3725, dm3730
  255. * and feature presence.
  256. * Speed Binned = Bit 9
  257. * 0 800/600 MHz
  258. * 1 1000/800 MHz
  259. * some eFuse values e.g. CONTROL_FUSE_OPP 1G_VDD1
  260. * are stored in the SYSCON register range.
  261. * There is no 0x4830A20C [ProdID.SKUID] register (exists but
  262. * seems to always read as 0).
  263. */
  264. static const char * const omap3_reg_names[] = {"cpu0", "vbb", NULL};
  265. static struct ti_cpufreq_soc_data omap36xx_soc_data = {
  266. .reg_names = omap3_reg_names,
  267. .efuse_xlate = omap3_efuse_xlate,
  268. .efuse_offset = OMAP3_CONTROL_DEVICE_STATUS - OMAP3_SYSCON_BASE,
  269. .efuse_shift = 9,
  270. .efuse_mask = BIT(9),
  271. .rev_offset = OMAP3_CONTROL_IDCODE - OMAP3_SYSCON_BASE,
  272. .multi_regulator = true,
  273. .quirks = TI_QUIRK_SYSCON_MAY_BE_MISSING,
  274. };
  275. /*
  276. * AM3517 is quite similar to AM/DM37x except that it has no
  277. * high speed grade eFuse and no abb ldo
  278. */
  279. static struct ti_cpufreq_soc_data am3517_soc_data = {
  280. .efuse_xlate = omap3_efuse_xlate,
  281. .efuse_offset = OMAP3_CONTROL_DEVICE_STATUS - OMAP3_SYSCON_BASE,
  282. .efuse_shift = 0,
  283. .efuse_mask = 0,
  284. .rev_offset = OMAP3_CONTROL_IDCODE - OMAP3_SYSCON_BASE,
  285. .multi_regulator = false,
  286. .quirks = TI_QUIRK_SYSCON_MAY_BE_MISSING,
  287. };
  288. static const struct soc_device_attribute k3_cpufreq_soc[] = {
  289. { .family = "AM62X", },
  290. { .family = "AM62AX", },
  291. { .family = "AM62DX", },
  292. { .family = "AM62LX", },
  293. { .family = "AM62PX", },
  294. { /* sentinel */ }
  295. };
  296. static struct ti_cpufreq_soc_data am625_soc_data = {
  297. .efuse_xlate = am625_efuse_xlate,
  298. .efuse_offset = 0x0018,
  299. .efuse_mask = 0x07c0,
  300. .efuse_shift = 0x6,
  301. .multi_regulator = false,
  302. .quirks = TI_QUIRK_SYSCON_IS_SINGLE_REG,
  303. };
  304. static struct ti_cpufreq_soc_data am62a7_soc_data = {
  305. .efuse_xlate = am62a7_efuse_xlate,
  306. .efuse_offset = 0x0,
  307. .efuse_mask = 0x07c0,
  308. .efuse_shift = 0x6,
  309. .multi_regulator = false,
  310. };
  311. static struct ti_cpufreq_soc_data am62l3_soc_data = {
  312. .efuse_xlate = am62l3_efuse_xlate,
  313. .efuse_offset = 0x0,
  314. .efuse_mask = 0x07c0,
  315. .efuse_shift = 0x6,
  316. .multi_regulator = false,
  317. };
  318. static struct ti_cpufreq_soc_data am62p5_soc_data = {
  319. .efuse_xlate = am62p5_efuse_xlate,
  320. .efuse_offset = 0x0,
  321. .efuse_mask = 0x07c0,
  322. .efuse_shift = 0x6,
  323. .multi_regulator = false,
  324. };
  325. /**
  326. * ti_cpufreq_get_efuse() - Parse and return efuse value present on SoC
  327. * @opp_data: pointer to ti_cpufreq_data context
  328. * @efuse_value: Set to the value parsed from efuse
  329. *
  330. * Returns error code if efuse not read properly.
  331. */
  332. static int ti_cpufreq_get_efuse(struct ti_cpufreq_data *opp_data,
  333. u32 *efuse_value)
  334. {
  335. struct device *dev = opp_data->cpu_dev;
  336. u32 efuse;
  337. int ret;
  338. ret = regmap_read(opp_data->syscon, opp_data->soc_data->efuse_offset,
  339. &efuse);
  340. if (opp_data->soc_data->quirks & TI_QUIRK_SYSCON_IS_SINGLE_REG && ret == -EIO)
  341. ret = regmap_read(opp_data->syscon, 0x0, &efuse);
  342. if (opp_data->soc_data->quirks & TI_QUIRK_SYSCON_MAY_BE_MISSING && ret == -EIO) {
  343. /* not a syscon register! */
  344. void __iomem *regs = ioremap(OMAP3_SYSCON_BASE +
  345. opp_data->soc_data->efuse_offset, 4);
  346. if (!regs)
  347. return -ENOMEM;
  348. efuse = readl(regs);
  349. iounmap(regs);
  350. }
  351. else if (ret) {
  352. dev_err(dev,
  353. "Failed to read the efuse value from syscon: %d\n",
  354. ret);
  355. return ret;
  356. }
  357. efuse = (efuse & opp_data->soc_data->efuse_mask);
  358. efuse >>= opp_data->soc_data->efuse_shift;
  359. *efuse_value = opp_data->soc_data->efuse_xlate(opp_data, efuse);
  360. return 0;
  361. }
  362. /**
  363. * ti_cpufreq_get_rev() - Parse and return rev value present on SoC
  364. * @opp_data: pointer to ti_cpufreq_data context
  365. * @revision_value: Set to the value parsed from revision register
  366. *
  367. * Returns error code if revision not read properly.
  368. */
  369. static int ti_cpufreq_get_rev(struct ti_cpufreq_data *opp_data,
  370. u32 *revision_value)
  371. {
  372. struct device *dev = opp_data->cpu_dev;
  373. u32 revision;
  374. int ret;
  375. if (soc_device_match(k3_cpufreq_soc)) {
  376. /*
  377. * Since the SR is 1.0, hard code the revision_value as
  378. * 0x1 here. This way we avoid re using the same register
  379. * that is giving us required information inside socinfo
  380. * anyway.
  381. */
  382. *revision_value = 0x1;
  383. goto done;
  384. }
  385. ret = regmap_read(opp_data->syscon, opp_data->soc_data->rev_offset,
  386. &revision);
  387. if (opp_data->soc_data->quirks & TI_QUIRK_SYSCON_MAY_BE_MISSING && ret == -EIO) {
  388. /* not a syscon register! */
  389. void __iomem *regs = ioremap(OMAP3_SYSCON_BASE +
  390. opp_data->soc_data->rev_offset, 4);
  391. if (!regs)
  392. return -ENOMEM;
  393. revision = readl(regs);
  394. iounmap(regs);
  395. }
  396. else if (ret) {
  397. dev_err(dev,
  398. "Failed to read the revision number from syscon: %d\n",
  399. ret);
  400. return ret;
  401. }
  402. *revision_value = BIT((revision >> REVISION_SHIFT) & REVISION_MASK);
  403. done:
  404. return 0;
  405. }
  406. static int ti_cpufreq_setup_syscon_register(struct ti_cpufreq_data *opp_data)
  407. {
  408. struct device *dev = opp_data->cpu_dev;
  409. struct device_node *np = opp_data->opp_node;
  410. opp_data->syscon = syscon_regmap_lookup_by_phandle(np,
  411. "syscon");
  412. if (IS_ERR(opp_data->syscon)) {
  413. dev_err(dev,
  414. "\"syscon\" is missing, cannot use OPPv2 table.\n");
  415. return PTR_ERR(opp_data->syscon);
  416. }
  417. return 0;
  418. }
  419. static const struct of_device_id ti_cpufreq_of_match[] __maybe_unused = {
  420. { .compatible = "ti,am33xx", .data = &am3x_soc_data, },
  421. { .compatible = "ti,am3517", .data = &am3517_soc_data, },
  422. { .compatible = "ti,am43", .data = &am4x_soc_data, },
  423. { .compatible = "ti,dra7", .data = &dra7_soc_data },
  424. { .compatible = "ti,omap34xx", .data = &omap34xx_soc_data, },
  425. { .compatible = "ti,omap36xx", .data = &omap36xx_soc_data, },
  426. { .compatible = "ti,am625", .data = &am625_soc_data, },
  427. { .compatible = "ti,am62a7", .data = &am62a7_soc_data, },
  428. { .compatible = "ti,am62d2", .data = &am62a7_soc_data, },
  429. { .compatible = "ti,am62l3", .data = &am62l3_soc_data, },
  430. { .compatible = "ti,am62p5", .data = &am62p5_soc_data, },
  431. /* legacy */
  432. { .compatible = "ti,omap3430", .data = &omap34xx_soc_data, },
  433. { .compatible = "ti,omap3630", .data = &omap36xx_soc_data, },
  434. {},
  435. };
  436. static const struct of_device_id *ti_cpufreq_match_node(void)
  437. {
  438. struct device_node *np __free(device_node) = of_find_node_by_path("/");
  439. const struct of_device_id *match;
  440. match = of_match_node(ti_cpufreq_of_match, np);
  441. return match;
  442. }
  443. static int ti_cpufreq_probe(struct platform_device *pdev)
  444. {
  445. u32 version[VERSION_COUNT];
  446. const struct of_device_id *match;
  447. struct ti_cpufreq_data *opp_data;
  448. const char * const default_reg_names[] = {"vdd", "vbb", NULL};
  449. int ret;
  450. struct dev_pm_opp_config config = {
  451. .supported_hw = version,
  452. .supported_hw_count = ARRAY_SIZE(version),
  453. };
  454. match = dev_get_platdata(&pdev->dev);
  455. if (!match)
  456. return -ENODEV;
  457. opp_data = devm_kzalloc(&pdev->dev, sizeof(*opp_data), GFP_KERNEL);
  458. if (!opp_data)
  459. return -ENOMEM;
  460. opp_data->soc_data = match->data;
  461. opp_data->cpu_dev = get_cpu_device(0);
  462. if (!opp_data->cpu_dev) {
  463. pr_err("%s: Failed to get device for CPU0\n", __func__);
  464. return -ENODEV;
  465. }
  466. opp_data->opp_node = dev_pm_opp_of_get_opp_desc_node(opp_data->cpu_dev);
  467. if (!opp_data->opp_node) {
  468. dev_info(opp_data->cpu_dev,
  469. "OPP-v2 not supported, cpufreq-dt will attempt to use legacy tables.\n");
  470. goto register_cpufreq_dt;
  471. }
  472. ret = ti_cpufreq_setup_syscon_register(opp_data);
  473. if (ret)
  474. goto fail_put_node;
  475. /*
  476. * OPPs determine whether or not they are supported based on
  477. * two metrics:
  478. * 0 - SoC Revision
  479. * 1 - eFuse value
  480. */
  481. ret = ti_cpufreq_get_rev(opp_data, &version[0]);
  482. if (ret)
  483. goto fail_put_node;
  484. ret = ti_cpufreq_get_efuse(opp_data, &version[1]);
  485. if (ret)
  486. goto fail_put_node;
  487. if (opp_data->soc_data->multi_regulator) {
  488. if (opp_data->soc_data->reg_names)
  489. config.regulator_names = opp_data->soc_data->reg_names;
  490. else
  491. config.regulator_names = default_reg_names;
  492. }
  493. ret = dev_pm_opp_set_config(opp_data->cpu_dev, &config);
  494. if (ret < 0) {
  495. dev_err_probe(opp_data->cpu_dev, ret, "Failed to set OPP config\n");
  496. goto fail_put_node;
  497. }
  498. of_node_put(opp_data->opp_node);
  499. register_cpufreq_dt:
  500. platform_device_register_simple("cpufreq-dt", -1, NULL, 0);
  501. return 0;
  502. fail_put_node:
  503. of_node_put(opp_data->opp_node);
  504. return ret;
  505. }
  506. static int __init ti_cpufreq_init(void)
  507. {
  508. const struct of_device_id *match;
  509. /* Check to ensure we are on a compatible platform */
  510. match = ti_cpufreq_match_node();
  511. if (match)
  512. platform_device_register_data(NULL, "ti-cpufreq", -1, match,
  513. sizeof(*match));
  514. return 0;
  515. }
  516. module_init(ti_cpufreq_init);
  517. static struct platform_driver ti_cpufreq_driver = {
  518. .probe = ti_cpufreq_probe,
  519. .driver = {
  520. .name = "ti-cpufreq",
  521. },
  522. };
  523. builtin_platform_driver(ti_cpufreq_driver);
  524. MODULE_DESCRIPTION("TI CPUFreq/OPP hw-supported driver");
  525. MODULE_AUTHOR("Dave Gerlach <d-gerlach@ti.com>");
  526. MODULE_LICENSE("GPL v2");