| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2015 Linaro Ltd. |
|---|
| 3 | 4 | * Author: Pi-Cheng Chen <pi-cheng.chen@linaro.org> |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 7 | | - * published by the Free Software Foundation. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | | - * GNU General Public License for more details. |
|---|
| 13 | 5 | */ |
|---|
| 14 | 6 | |
|---|
| 15 | 7 | #include <linux/clk.h> |
|---|
| 16 | 8 | #include <linux/cpu.h> |
|---|
| 17 | | -#include <linux/cpu_cooling.h> |
|---|
| 18 | 9 | #include <linux/cpufreq.h> |
|---|
| 19 | 10 | #include <linux/cpumask.h> |
|---|
| 20 | 11 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 48 | 39 | struct regulator *sram_reg; |
|---|
| 49 | 40 | struct clk *cpu_clk; |
|---|
| 50 | 41 | struct clk *inter_clk; |
|---|
| 51 | | - struct thermal_cooling_device *cdev; |
|---|
| 52 | 42 | struct list_head list_head; |
|---|
| 53 | 43 | int intermediate_voltage; |
|---|
| 54 | 44 | bool need_voltage_tracking; |
|---|
| 55 | 45 | }; |
|---|
| 46 | + |
|---|
| 47 | +static struct platform_device *cpufreq_pdev; |
|---|
| 56 | 48 | |
|---|
| 57 | 49 | static LIST_HEAD(dvfs_info_list); |
|---|
| 58 | 50 | |
|---|
| .. | .. |
|---|
| 307 | 299 | |
|---|
| 308 | 300 | #define DYNAMIC_POWER "dynamic-power-coefficient" |
|---|
| 309 | 301 | |
|---|
| 310 | | -static void mtk_cpufreq_ready(struct cpufreq_policy *policy) |
|---|
| 311 | | -{ |
|---|
| 312 | | - struct mtk_cpu_dvfs_info *info = policy->driver_data; |
|---|
| 313 | | - |
|---|
| 314 | | - info->cdev = of_cpufreq_cooling_register(policy); |
|---|
| 315 | | -} |
|---|
| 316 | | - |
|---|
| 317 | 302 | static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu) |
|---|
| 318 | 303 | { |
|---|
| 319 | 304 | struct device *cpu_dev; |
|---|
| .. | .. |
|---|
| 355 | 340 | goto out_free_resources; |
|---|
| 356 | 341 | } |
|---|
| 357 | 342 | |
|---|
| 358 | | - proc_reg = regulator_get_exclusive(cpu_dev, "proc"); |
|---|
| 343 | + proc_reg = regulator_get_optional(cpu_dev, "proc"); |
|---|
| 359 | 344 | if (IS_ERR(proc_reg)) { |
|---|
| 360 | 345 | if (PTR_ERR(proc_reg) == -EPROBE_DEFER) |
|---|
| 361 | 346 | pr_warn("proc regulator for cpu%d not ready, retry.\n", |
|---|
| .. | .. |
|---|
| 465 | 450 | policy->driver_data = info; |
|---|
| 466 | 451 | policy->clk = info->cpu_clk; |
|---|
| 467 | 452 | |
|---|
| 453 | + dev_pm_opp_of_register_em(info->cpu_dev, policy->cpus); |
|---|
| 454 | + |
|---|
| 468 | 455 | return 0; |
|---|
| 469 | 456 | } |
|---|
| 470 | 457 | |
|---|
| .. | .. |
|---|
| 472 | 459 | { |
|---|
| 473 | 460 | struct mtk_cpu_dvfs_info *info = policy->driver_data; |
|---|
| 474 | 461 | |
|---|
| 475 | | - cpufreq_cooling_unregister(info->cdev); |
|---|
| 476 | 462 | dev_pm_opp_free_cpufreq_table(info->cpu_dev, &policy->freq_table); |
|---|
| 477 | 463 | |
|---|
| 478 | 464 | return 0; |
|---|
| .. | .. |
|---|
| 480 | 466 | |
|---|
| 481 | 467 | static struct cpufreq_driver mtk_cpufreq_driver = { |
|---|
| 482 | 468 | .flags = CPUFREQ_STICKY | CPUFREQ_NEED_INITIAL_FREQ_CHECK | |
|---|
| 483 | | - CPUFREQ_HAVE_GOVERNOR_PER_POLICY, |
|---|
| 469 | + CPUFREQ_HAVE_GOVERNOR_PER_POLICY | |
|---|
| 470 | + CPUFREQ_IS_COOLING_DEV, |
|---|
| 484 | 471 | .verify = cpufreq_generic_frequency_table_verify, |
|---|
| 485 | 472 | .target_index = mtk_cpufreq_set_target, |
|---|
| 486 | 473 | .get = cpufreq_generic_get, |
|---|
| 487 | 474 | .init = mtk_cpufreq_init, |
|---|
| 488 | 475 | .exit = mtk_cpufreq_exit, |
|---|
| 489 | | - .ready = mtk_cpufreq_ready, |
|---|
| 490 | 476 | .name = "mtk-cpufreq", |
|---|
| 491 | 477 | .attr = cpufreq_generic_attr, |
|---|
| 492 | 478 | }; |
|---|
| .. | .. |
|---|
| 551 | 537 | { .compatible = "mediatek,mt817x", }, |
|---|
| 552 | 538 | { .compatible = "mediatek,mt8173", }, |
|---|
| 553 | 539 | { .compatible = "mediatek,mt8176", }, |
|---|
| 540 | + { .compatible = "mediatek,mt8183", }, |
|---|
| 541 | + { .compatible = "mediatek,mt8516", }, |
|---|
| 554 | 542 | |
|---|
| 555 | 543 | { } |
|---|
| 556 | 544 | }; |
|---|
| .. | .. |
|---|
| 560 | 548 | { |
|---|
| 561 | 549 | struct device_node *np; |
|---|
| 562 | 550 | const struct of_device_id *match; |
|---|
| 563 | | - struct platform_device *pdev; |
|---|
| 564 | 551 | int err; |
|---|
| 565 | 552 | |
|---|
| 566 | 553 | np = of_find_node_by_path("/"); |
|---|
| .. | .. |
|---|
| 584 | 571 | * and the device registration codes are put here to handle defer |
|---|
| 585 | 572 | * probing. |
|---|
| 586 | 573 | */ |
|---|
| 587 | | - pdev = platform_device_register_simple("mtk-cpufreq", -1, NULL, 0); |
|---|
| 588 | | - if (IS_ERR(pdev)) { |
|---|
| 574 | + cpufreq_pdev = platform_device_register_simple("mtk-cpufreq", -1, NULL, 0); |
|---|
| 575 | + if (IS_ERR(cpufreq_pdev)) { |
|---|
| 589 | 576 | pr_err("failed to register mtk-cpufreq platform device\n"); |
|---|
| 590 | | - return PTR_ERR(pdev); |
|---|
| 577 | + platform_driver_unregister(&mtk_cpufreq_platdrv); |
|---|
| 578 | + return PTR_ERR(cpufreq_pdev); |
|---|
| 591 | 579 | } |
|---|
| 592 | 580 | |
|---|
| 593 | 581 | return 0; |
|---|
| 594 | 582 | } |
|---|
| 595 | | -device_initcall(mtk_cpufreq_driver_init); |
|---|
| 583 | +module_init(mtk_cpufreq_driver_init) |
|---|
| 584 | + |
|---|
| 585 | +static void __exit mtk_cpufreq_driver_exit(void) |
|---|
| 586 | +{ |
|---|
| 587 | + platform_device_unregister(cpufreq_pdev); |
|---|
| 588 | + platform_driver_unregister(&mtk_cpufreq_platdrv); |
|---|
| 589 | +} |
|---|
| 590 | +module_exit(mtk_cpufreq_driver_exit) |
|---|
| 596 | 591 | |
|---|
| 597 | 592 | MODULE_DESCRIPTION("MediaTek CPUFreq driver"); |
|---|
| 598 | 593 | MODULE_AUTHOR("Pi-Cheng Chen <pi-cheng.chen@linaro.org>"); |
|---|