tegra194-cpufreq.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2020 - 2022, NVIDIA CORPORATION. All rights reserved
  4. */
  5. #include <linux/cpu.h>
  6. #include <linux/cpufreq.h>
  7. #include <linux/delay.h>
  8. #include <linux/dma-mapping.h>
  9. #include <linux/module.h>
  10. #include <linux/of.h>
  11. #include <linux/of_platform.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/slab.h>
  14. #include <asm/smp_plat.h>
  15. #include <soc/tegra/bpmp.h>
  16. #include <soc/tegra/bpmp-abi.h>
  17. #define KHZ 1000
  18. #define REF_CLK_MHZ 408 /* 408 MHz */
  19. #define US_DELAY 500
  20. #define CPUFREQ_TBL_STEP_HZ (50 * KHZ * KHZ)
  21. #define MAX_CNT ~0U
  22. #define NDIV_MASK 0x1FF
  23. #define CORE_OFFSET(cpu) (cpu * 8)
  24. #define CMU_CLKS_BASE 0x2000
  25. #define SCRATCH_FREQ_CORE_REG(data, cpu) (data->regs + CMU_CLKS_BASE + CORE_OFFSET(cpu))
  26. #define MMCRAB_CLUSTER_BASE(cl) (0x30000 + (cl * 0x10000))
  27. #define CLUSTER_ACTMON_BASE(data, cl) \
  28. (data->regs + (MMCRAB_CLUSTER_BASE(cl) + data->soc->actmon_cntr_base))
  29. #define CORE_ACTMON_CNTR_REG(data, cl, cpu) (CLUSTER_ACTMON_BASE(data, cl) + CORE_OFFSET(cpu))
  30. /* cpufreq transisition latency */
  31. #define TEGRA_CPUFREQ_TRANSITION_LATENCY (300 * 1000) /* unit in nanoseconds */
  32. struct tegra_cpu_ctr {
  33. u32 cpu;
  34. u32 coreclk_cnt, last_coreclk_cnt;
  35. u32 refclk_cnt, last_refclk_cnt;
  36. };
  37. struct read_counters_work {
  38. struct work_struct work;
  39. struct tegra_cpu_ctr c;
  40. };
  41. struct tegra_cpufreq_ops {
  42. void (*read_counters)(struct tegra_cpu_ctr *c);
  43. void (*set_cpu_ndiv)(struct cpufreq_policy *policy, u64 ndiv);
  44. void (*get_cpu_cluster_id)(u32 cpu, u32 *cpuid, u32 *clusterid);
  45. int (*get_cpu_ndiv)(u32 cpu, u32 cpuid, u32 clusterid, u64 *ndiv);
  46. };
  47. struct tegra_cpufreq_soc {
  48. struct tegra_cpufreq_ops *ops;
  49. int maxcpus_per_cluster;
  50. unsigned int num_clusters;
  51. phys_addr_t actmon_cntr_base;
  52. };
  53. struct tegra194_cpufreq_data {
  54. void __iomem *regs;
  55. struct cpufreq_frequency_table **tables;
  56. const struct tegra_cpufreq_soc *soc;
  57. };
  58. static struct workqueue_struct *read_counters_wq;
  59. static void tegra_get_cpu_mpidr(void *mpidr)
  60. {
  61. *((u64 *)mpidr) = read_cpuid_mpidr() & MPIDR_HWID_BITMASK;
  62. }
  63. static void tegra234_get_cpu_cluster_id(u32 cpu, u32 *cpuid, u32 *clusterid)
  64. {
  65. u64 mpidr;
  66. smp_call_function_single(cpu, tegra_get_cpu_mpidr, &mpidr, true);
  67. if (cpuid)
  68. *cpuid = MPIDR_AFFINITY_LEVEL(mpidr, 1);
  69. if (clusterid)
  70. *clusterid = MPIDR_AFFINITY_LEVEL(mpidr, 2);
  71. }
  72. static int tegra234_get_cpu_ndiv(u32 cpu, u32 cpuid, u32 clusterid, u64 *ndiv)
  73. {
  74. struct tegra194_cpufreq_data *data = cpufreq_get_driver_data();
  75. void __iomem *freq_core_reg;
  76. u64 mpidr_id;
  77. /* use physical id to get address of per core frequency register */
  78. mpidr_id = (clusterid * data->soc->maxcpus_per_cluster) + cpuid;
  79. freq_core_reg = SCRATCH_FREQ_CORE_REG(data, mpidr_id);
  80. *ndiv = readl(freq_core_reg) & NDIV_MASK;
  81. return 0;
  82. }
  83. static void tegra234_set_cpu_ndiv(struct cpufreq_policy *policy, u64 ndiv)
  84. {
  85. struct tegra194_cpufreq_data *data = cpufreq_get_driver_data();
  86. void __iomem *freq_core_reg;
  87. u32 cpu, cpuid, clusterid;
  88. u64 mpidr_id;
  89. for_each_cpu_and(cpu, policy->cpus, cpu_online_mask) {
  90. data->soc->ops->get_cpu_cluster_id(cpu, &cpuid, &clusterid);
  91. /* use physical id to get address of per core frequency register */
  92. mpidr_id = (clusterid * data->soc->maxcpus_per_cluster) + cpuid;
  93. freq_core_reg = SCRATCH_FREQ_CORE_REG(data, mpidr_id);
  94. writel(ndiv, freq_core_reg);
  95. }
  96. }
  97. /*
  98. * This register provides access to two counter values with a single
  99. * 64-bit read. The counter values are used to determine the average
  100. * actual frequency a core has run at over a period of time.
  101. * [63:32] PLLP counter: Counts at fixed frequency (408 MHz)
  102. * [31:0] Core clock counter: Counts on every core clock cycle
  103. */
  104. static void tegra234_read_counters(struct tegra_cpu_ctr *c)
  105. {
  106. struct tegra194_cpufreq_data *data = cpufreq_get_driver_data();
  107. void __iomem *actmon_reg;
  108. u32 cpuid, clusterid;
  109. u64 val;
  110. data->soc->ops->get_cpu_cluster_id(c->cpu, &cpuid, &clusterid);
  111. actmon_reg = CORE_ACTMON_CNTR_REG(data, clusterid, cpuid);
  112. val = readq(actmon_reg);
  113. c->last_refclk_cnt = upper_32_bits(val);
  114. c->last_coreclk_cnt = lower_32_bits(val);
  115. udelay(US_DELAY);
  116. val = readq(actmon_reg);
  117. c->refclk_cnt = upper_32_bits(val);
  118. c->coreclk_cnt = lower_32_bits(val);
  119. }
  120. static struct tegra_cpufreq_ops tegra234_cpufreq_ops = {
  121. .read_counters = tegra234_read_counters,
  122. .get_cpu_cluster_id = tegra234_get_cpu_cluster_id,
  123. .get_cpu_ndiv = tegra234_get_cpu_ndiv,
  124. .set_cpu_ndiv = tegra234_set_cpu_ndiv,
  125. };
  126. static const struct tegra_cpufreq_soc tegra234_cpufreq_soc = {
  127. .ops = &tegra234_cpufreq_ops,
  128. .actmon_cntr_base = 0x9000,
  129. .maxcpus_per_cluster = 4,
  130. .num_clusters = 3,
  131. };
  132. static const struct tegra_cpufreq_soc tegra239_cpufreq_soc = {
  133. .ops = &tegra234_cpufreq_ops,
  134. .actmon_cntr_base = 0x4000,
  135. .maxcpus_per_cluster = 8,
  136. .num_clusters = 1,
  137. };
  138. static void tegra194_get_cpu_cluster_id(u32 cpu, u32 *cpuid, u32 *clusterid)
  139. {
  140. u64 mpidr;
  141. smp_call_function_single(cpu, tegra_get_cpu_mpidr, &mpidr, true);
  142. if (cpuid)
  143. *cpuid = MPIDR_AFFINITY_LEVEL(mpidr, 0);
  144. if (clusterid)
  145. *clusterid = MPIDR_AFFINITY_LEVEL(mpidr, 1);
  146. }
  147. /*
  148. * Read per-core Read-only system register NVFREQ_FEEDBACK_EL1.
  149. * The register provides frequency feedback information to
  150. * determine the average actual frequency a core has run at over
  151. * a period of time.
  152. * [31:0] PLLP counter: Counts at fixed frequency (408 MHz)
  153. * [63:32] Core clock counter: counts on every core clock cycle
  154. * where the core is architecturally clocking
  155. */
  156. static u64 read_freq_feedback(void)
  157. {
  158. u64 val = 0;
  159. asm volatile("mrs %0, s3_0_c15_c0_5" : "=r" (val) : );
  160. return val;
  161. }
  162. static inline u32 map_ndiv_to_freq(struct mrq_cpu_ndiv_limits_response
  163. *nltbl, u16 ndiv)
  164. {
  165. return nltbl->ref_clk_hz / KHZ * ndiv / (nltbl->pdiv * nltbl->mdiv);
  166. }
  167. static void tegra194_read_counters(struct tegra_cpu_ctr *c)
  168. {
  169. u64 val;
  170. val = read_freq_feedback();
  171. c->last_refclk_cnt = lower_32_bits(val);
  172. c->last_coreclk_cnt = upper_32_bits(val);
  173. udelay(US_DELAY);
  174. val = read_freq_feedback();
  175. c->refclk_cnt = lower_32_bits(val);
  176. c->coreclk_cnt = upper_32_bits(val);
  177. }
  178. static void tegra_read_counters(struct work_struct *work)
  179. {
  180. struct tegra194_cpufreq_data *data = cpufreq_get_driver_data();
  181. struct read_counters_work *read_counters_work;
  182. struct tegra_cpu_ctr *c;
  183. /*
  184. * ref_clk_counter(32 bit counter) runs on constant clk,
  185. * pll_p(408MHz).
  186. * It will take = 2 ^ 32 / 408 MHz to overflow ref clk counter
  187. * = 10526880 usec = 10.527 sec to overflow
  188. *
  189. * Like wise core_clk_counter(32 bit counter) runs on core clock.
  190. * It's synchronized to crab_clk (cpu_crab_clk) which runs at
  191. * freq of cluster. Assuming max cluster clock ~2000MHz,
  192. * It will take = 2 ^ 32 / 2000 MHz to overflow core clk counter
  193. * = ~2.147 sec to overflow
  194. */
  195. read_counters_work = container_of(work, struct read_counters_work,
  196. work);
  197. c = &read_counters_work->c;
  198. data->soc->ops->read_counters(c);
  199. }
  200. /*
  201. * Return instantaneous cpu speed
  202. * Instantaneous freq is calculated as -
  203. * -Takes sample on every query of getting the freq.
  204. * - Read core and ref clock counters;
  205. * - Delay for X us
  206. * - Read above cycle counters again
  207. * - Calculates freq by subtracting current and previous counters
  208. * divided by the delay time or eqv. of ref_clk_counter in delta time
  209. * - Return Kcycles/second, freq in KHz
  210. *
  211. * delta time period = x sec
  212. * = delta ref_clk_counter / (408 * 10^6) sec
  213. * freq in Hz = cycles/sec
  214. * = (delta cycles / x sec
  215. * = (delta cycles * 408 * 10^6) / delta ref_clk_counter
  216. * in KHz = (delta cycles * 408 * 10^3) / delta ref_clk_counter
  217. *
  218. * @cpu - logical cpu whose freq to be updated
  219. * Returns freq in KHz on success, 0 if cpu is offline
  220. */
  221. static unsigned int tegra194_calculate_speed(u32 cpu)
  222. {
  223. struct read_counters_work read_counters_work;
  224. struct tegra_cpu_ctr c;
  225. u32 delta_refcnt;
  226. u32 delta_ccnt;
  227. u32 rate_mhz;
  228. /*
  229. * udelay() is required to reconstruct cpu frequency over an
  230. * observation window. Using workqueue to call udelay() with
  231. * interrupts enabled.
  232. */
  233. read_counters_work.c.cpu = cpu;
  234. INIT_WORK_ONSTACK(&read_counters_work.work, tegra_read_counters);
  235. queue_work_on(cpu, read_counters_wq, &read_counters_work.work);
  236. flush_work(&read_counters_work.work);
  237. c = read_counters_work.c;
  238. if (c.coreclk_cnt < c.last_coreclk_cnt)
  239. delta_ccnt = c.coreclk_cnt + (MAX_CNT - c.last_coreclk_cnt);
  240. else
  241. delta_ccnt = c.coreclk_cnt - c.last_coreclk_cnt;
  242. if (!delta_ccnt)
  243. return 0;
  244. /* ref clock is 32 bits */
  245. if (c.refclk_cnt < c.last_refclk_cnt)
  246. delta_refcnt = c.refclk_cnt + (MAX_CNT - c.last_refclk_cnt);
  247. else
  248. delta_refcnt = c.refclk_cnt - c.last_refclk_cnt;
  249. if (!delta_refcnt) {
  250. pr_debug("cpufreq: %d is idle, delta_refcnt: 0\n", cpu);
  251. return 0;
  252. }
  253. rate_mhz = ((unsigned long)(delta_ccnt * REF_CLK_MHZ)) / delta_refcnt;
  254. return (rate_mhz * KHZ); /* in KHz */
  255. }
  256. static void tegra194_get_cpu_ndiv_sysreg(void *ndiv)
  257. {
  258. u64 ndiv_val;
  259. asm volatile("mrs %0, s3_0_c15_c0_4" : "=r" (ndiv_val) : );
  260. *(u64 *)ndiv = ndiv_val;
  261. }
  262. static int tegra194_get_cpu_ndiv(u32 cpu, u32 cpuid, u32 clusterid, u64 *ndiv)
  263. {
  264. return smp_call_function_single(cpu, tegra194_get_cpu_ndiv_sysreg, &ndiv, true);
  265. }
  266. static void tegra194_set_cpu_ndiv_sysreg(void *data)
  267. {
  268. u64 ndiv_val = *(u64 *)data;
  269. asm volatile("msr s3_0_c15_c0_4, %0" : : "r" (ndiv_val));
  270. }
  271. static void tegra194_set_cpu_ndiv(struct cpufreq_policy *policy, u64 ndiv)
  272. {
  273. on_each_cpu_mask(policy->cpus, tegra194_set_cpu_ndiv_sysreg, &ndiv, true);
  274. }
  275. static unsigned int tegra194_get_speed(u32 cpu)
  276. {
  277. struct tegra194_cpufreq_data *data = cpufreq_get_driver_data();
  278. struct cpufreq_frequency_table *pos;
  279. u32 cpuid, clusterid;
  280. unsigned int rate;
  281. u64 ndiv;
  282. int ret;
  283. data->soc->ops->get_cpu_cluster_id(cpu, &cpuid, &clusterid);
  284. /* reconstruct actual cpu freq using counters */
  285. rate = tegra194_calculate_speed(cpu);
  286. /* get last written ndiv value */
  287. ret = data->soc->ops->get_cpu_ndiv(cpu, cpuid, clusterid, &ndiv);
  288. if (WARN_ON_ONCE(ret))
  289. return rate;
  290. /*
  291. * If the reconstructed frequency has acceptable delta from
  292. * the last written value, then return freq corresponding
  293. * to the last written ndiv value from freq_table. This is
  294. * done to return consistent value.
  295. */
  296. cpufreq_for_each_valid_entry(pos, data->tables[clusterid]) {
  297. if (pos->driver_data != ndiv)
  298. continue;
  299. if (abs(pos->frequency - rate) > 115200) {
  300. pr_warn("cpufreq: cpu%d,cur:%u,set:%u,set ndiv:%llu\n",
  301. cpu, rate, pos->frequency, ndiv);
  302. } else {
  303. rate = pos->frequency;
  304. }
  305. break;
  306. }
  307. return rate;
  308. }
  309. static int tegra194_cpufreq_init(struct cpufreq_policy *policy)
  310. {
  311. struct tegra194_cpufreq_data *data = cpufreq_get_driver_data();
  312. int maxcpus_per_cluster = data->soc->maxcpus_per_cluster;
  313. u32 start_cpu, cpu;
  314. u32 clusterid;
  315. data->soc->ops->get_cpu_cluster_id(policy->cpu, NULL, &clusterid);
  316. if (clusterid >= data->soc->num_clusters || !data->tables[clusterid])
  317. return -EINVAL;
  318. start_cpu = rounddown(policy->cpu, maxcpus_per_cluster);
  319. /* set same policy for all cpus in a cluster */
  320. for (cpu = start_cpu; cpu < (start_cpu + maxcpus_per_cluster); cpu++) {
  321. if (cpu_possible(cpu))
  322. cpumask_set_cpu(cpu, policy->cpus);
  323. }
  324. policy->freq_table = data->tables[clusterid];
  325. policy->cpuinfo.transition_latency = TEGRA_CPUFREQ_TRANSITION_LATENCY;
  326. return 0;
  327. }
  328. static int tegra194_cpufreq_set_target(struct cpufreq_policy *policy,
  329. unsigned int index)
  330. {
  331. struct cpufreq_frequency_table *tbl = policy->freq_table + index;
  332. struct tegra194_cpufreq_data *data = cpufreq_get_driver_data();
  333. /*
  334. * Each core writes frequency in per core register. Then both cores
  335. * in a cluster run at same frequency which is the maximum frequency
  336. * request out of the values requested by both cores in that cluster.
  337. */
  338. data->soc->ops->set_cpu_ndiv(policy, (u64)tbl->driver_data);
  339. return 0;
  340. }
  341. static struct cpufreq_driver tegra194_cpufreq_driver = {
  342. .name = "tegra194",
  343. .flags = CPUFREQ_CONST_LOOPS | CPUFREQ_NEED_INITIAL_FREQ_CHECK,
  344. .verify = cpufreq_generic_frequency_table_verify,
  345. .target_index = tegra194_cpufreq_set_target,
  346. .get = tegra194_get_speed,
  347. .init = tegra194_cpufreq_init,
  348. .attr = cpufreq_generic_attr,
  349. };
  350. static struct tegra_cpufreq_ops tegra194_cpufreq_ops = {
  351. .read_counters = tegra194_read_counters,
  352. .get_cpu_cluster_id = tegra194_get_cpu_cluster_id,
  353. .get_cpu_ndiv = tegra194_get_cpu_ndiv,
  354. .set_cpu_ndiv = tegra194_set_cpu_ndiv,
  355. };
  356. static const struct tegra_cpufreq_soc tegra194_cpufreq_soc = {
  357. .ops = &tegra194_cpufreq_ops,
  358. .maxcpus_per_cluster = 2,
  359. .num_clusters = 4,
  360. };
  361. static void tegra194_cpufreq_free_resources(void)
  362. {
  363. destroy_workqueue(read_counters_wq);
  364. }
  365. static struct cpufreq_frequency_table *
  366. init_freq_table(struct platform_device *pdev, struct tegra_bpmp *bpmp,
  367. unsigned int cluster_id)
  368. {
  369. struct cpufreq_frequency_table *freq_table;
  370. struct mrq_cpu_ndiv_limits_response resp;
  371. unsigned int num_freqs, ndiv, delta_ndiv;
  372. struct mrq_cpu_ndiv_limits_request req;
  373. struct tegra_bpmp_message msg;
  374. u16 freq_table_step_size;
  375. int err, index;
  376. memset(&req, 0, sizeof(req));
  377. req.cluster_id = cluster_id;
  378. memset(&msg, 0, sizeof(msg));
  379. msg.mrq = MRQ_CPU_NDIV_LIMITS;
  380. msg.tx.data = &req;
  381. msg.tx.size = sizeof(req);
  382. msg.rx.data = &resp;
  383. msg.rx.size = sizeof(resp);
  384. err = tegra_bpmp_transfer(bpmp, &msg);
  385. if (err)
  386. return ERR_PTR(err);
  387. if (msg.rx.ret == -BPMP_EINVAL) {
  388. /* Cluster not available */
  389. return NULL;
  390. }
  391. if (msg.rx.ret)
  392. return ERR_PTR(-EINVAL);
  393. /*
  394. * Make sure frequency table step is a multiple of mdiv to match
  395. * vhint table granularity.
  396. */
  397. freq_table_step_size = resp.mdiv *
  398. DIV_ROUND_UP(CPUFREQ_TBL_STEP_HZ, resp.ref_clk_hz);
  399. dev_dbg(&pdev->dev, "cluster %d: frequency table step size: %d\n",
  400. cluster_id, freq_table_step_size);
  401. delta_ndiv = resp.ndiv_max - resp.ndiv_min;
  402. if (unlikely(delta_ndiv == 0)) {
  403. num_freqs = 1;
  404. } else {
  405. /* We store both ndiv_min and ndiv_max hence the +1 */
  406. num_freqs = delta_ndiv / freq_table_step_size + 1;
  407. }
  408. num_freqs += (delta_ndiv % freq_table_step_size) ? 1 : 0;
  409. freq_table = devm_kcalloc(&pdev->dev, num_freqs + 1,
  410. sizeof(*freq_table), GFP_KERNEL);
  411. if (!freq_table)
  412. return ERR_PTR(-ENOMEM);
  413. for (index = 0, ndiv = resp.ndiv_min;
  414. ndiv < resp.ndiv_max;
  415. index++, ndiv += freq_table_step_size) {
  416. freq_table[index].driver_data = ndiv;
  417. freq_table[index].frequency = map_ndiv_to_freq(&resp, ndiv);
  418. }
  419. freq_table[index].driver_data = resp.ndiv_max;
  420. freq_table[index++].frequency = map_ndiv_to_freq(&resp, resp.ndiv_max);
  421. freq_table[index].frequency = CPUFREQ_TABLE_END;
  422. return freq_table;
  423. }
  424. static int tegra194_cpufreq_probe(struct platform_device *pdev)
  425. {
  426. const struct tegra_cpufreq_soc *soc;
  427. struct tegra194_cpufreq_data *data;
  428. struct tegra_bpmp *bpmp;
  429. int err, i;
  430. data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
  431. if (!data)
  432. return -ENOMEM;
  433. soc = of_device_get_match_data(&pdev->dev);
  434. if (soc->ops && soc->maxcpus_per_cluster && soc->num_clusters) {
  435. data->soc = soc;
  436. } else {
  437. dev_err(&pdev->dev, "soc data missing\n");
  438. return -EINVAL;
  439. }
  440. data->tables = devm_kcalloc(&pdev->dev, data->soc->num_clusters,
  441. sizeof(*data->tables), GFP_KERNEL);
  442. if (!data->tables)
  443. return -ENOMEM;
  444. if (soc->actmon_cntr_base) {
  445. /* mmio registers are used for frequency request and re-construction */
  446. data->regs = devm_platform_ioremap_resource(pdev, 0);
  447. if (IS_ERR(data->regs))
  448. return PTR_ERR(data->regs);
  449. }
  450. platform_set_drvdata(pdev, data);
  451. bpmp = tegra_bpmp_get(&pdev->dev);
  452. if (IS_ERR(bpmp))
  453. return PTR_ERR(bpmp);
  454. read_counters_wq = alloc_workqueue("read_counters_wq", __WQ_LEGACY, 1);
  455. if (!read_counters_wq) {
  456. dev_err(&pdev->dev, "fail to create_workqueue\n");
  457. err = -EINVAL;
  458. goto put_bpmp;
  459. }
  460. for (i = 0; i < data->soc->num_clusters; i++) {
  461. data->tables[i] = init_freq_table(pdev, bpmp, i);
  462. if (IS_ERR(data->tables[i])) {
  463. err = PTR_ERR(data->tables[i]);
  464. goto err_free_res;
  465. }
  466. }
  467. tegra194_cpufreq_driver.driver_data = data;
  468. err = cpufreq_register_driver(&tegra194_cpufreq_driver);
  469. if (!err)
  470. goto put_bpmp;
  471. err_free_res:
  472. tegra194_cpufreq_free_resources();
  473. put_bpmp:
  474. tegra_bpmp_put(bpmp);
  475. return err;
  476. }
  477. static int tegra194_cpufreq_remove(struct platform_device *pdev)
  478. {
  479. cpufreq_unregister_driver(&tegra194_cpufreq_driver);
  480. tegra194_cpufreq_free_resources();
  481. return 0;
  482. }
  483. static const struct of_device_id tegra194_cpufreq_of_match[] = {
  484. { .compatible = "nvidia,tegra194-ccplex", .data = &tegra194_cpufreq_soc },
  485. { .compatible = "nvidia,tegra234-ccplex-cluster", .data = &tegra234_cpufreq_soc },
  486. { .compatible = "nvidia,tegra239-ccplex-cluster", .data = &tegra239_cpufreq_soc },
  487. { /* sentinel */ }
  488. };
  489. MODULE_DEVICE_TABLE(of, tegra194_cpufreq_of_match);
  490. static struct platform_driver tegra194_ccplex_driver = {
  491. .driver = {
  492. .name = "tegra194-cpufreq",
  493. .of_match_table = tegra194_cpufreq_of_match,
  494. },
  495. .probe = tegra194_cpufreq_probe,
  496. .remove = tegra194_cpufreq_remove,
  497. };
  498. module_platform_driver(tegra194_ccplex_driver);
  499. MODULE_AUTHOR("Mikko Perttunen <[email protected]>");
  500. MODULE_AUTHOR("Sumit Gupta <[email protected]>");
  501. MODULE_DESCRIPTION("NVIDIA Tegra194 cpufreq driver");
  502. MODULE_LICENSE("GPL v2");