Blame view

drivers/cpufreq/highbank-cpufreq.c 2.66 KB
d2912cb15   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-only
6754f5561   Mark Langsdorf   cpufreq / highban...
2
3
4
  /*
   * Copyright (C) 2012 Calxeda, Inc.
   *
6754f5561   Mark Langsdorf   cpufreq / highban...
5
   * This driver provides the clk notifier callbacks that are used when
bbcf07196   Viresh Kumar   cpufreq: cpu0: re...
6
   * the cpufreq-dt driver changes to frequency to alert the highbank
6754f5561   Mark Langsdorf   cpufreq / highban...
7
8
9
10
11
12
13
14
15
16
17
18
   * EnergyCore Management Engine (ECME) about the need to change
   * voltage. The ECME interfaces with the actual voltage regulators.
   */
  
  #define pr_fmt(fmt)	KBUILD_MODNAME ": " fmt
  
  #include <linux/kernel.h>
  #include <linux/module.h>
  #include <linux/clk.h>
  #include <linux/cpu.h>
  #include <linux/err.h>
  #include <linux/of.h>
f2fc42b6a   Suman Anna   mailbox: rename p...
19
  #include <linux/pl320-ipc.h>
5553f9e26   Shawn Guo   cpufreq: instanti...
20
  #include <linux/platform_device.h>
6754f5561   Mark Langsdorf   cpufreq / highban...
21
22
23
24
25
26
27
  
  #define HB_CPUFREQ_CHANGE_NOTE	0x80000001
  #define HB_CPUFREQ_IPC_LEN	7
  #define HB_CPUFREQ_VOLT_RETRIES	15
  
  static int hb_voltage_change(unsigned int freq)
  {
f5f43dcff   Emilio López   cpufreq: highbank...
28
  	u32 msg[HB_CPUFREQ_IPC_LEN] = {HB_CPUFREQ_CHANGE_NOTE, freq / 1000000};
6754f5561   Mark Langsdorf   cpufreq / highban...
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  
  	return pl320_ipc_transmit(msg);
  }
  
  static int hb_cpufreq_clk_notify(struct notifier_block *nb,
  				unsigned long action, void *hclk)
  {
  	struct clk_notifier_data *clk_data = hclk;
  	int i = 0;
  
  	if (action == PRE_RATE_CHANGE) {
  		if (clk_data->new_rate > clk_data->old_rate)
  			while (hb_voltage_change(clk_data->new_rate))
  				if (i++ > HB_CPUFREQ_VOLT_RETRIES)
  					return NOTIFY_BAD;
  	} else if (action == POST_RATE_CHANGE) {
  		if (clk_data->new_rate < clk_data->old_rate)
  			while (hb_voltage_change(clk_data->new_rate))
  				if (i++ > HB_CPUFREQ_VOLT_RETRIES)
  					return NOTIFY_BAD;
  	}
  
  	return NOTIFY_DONE;
  }
  
  static struct notifier_block hb_cpufreq_clk_nb = {
  	.notifier_call = hb_cpufreq_clk_notify,
  };
  
  static int hb_cpufreq_driver_init(void)
  {
bbcf07196   Viresh Kumar   cpufreq: cpu0: re...
60
  	struct platform_device_info devinfo = { .name = "cpufreq-dt", };
6754f5561   Mark Langsdorf   cpufreq / highban...
61
62
63
64
  	struct device *cpu_dev;
  	struct clk *cpu_clk;
  	struct device_node *np;
  	int ret;
fbbc5bfb4   Mark Langsdorf   cpufreq: highbank...
65
66
  	if ((!of_machine_is_compatible("calxeda,highbank")) &&
  		(!of_machine_is_compatible("calxeda,ecx-2000")))
6754f5561   Mark Langsdorf   cpufreq / highban...
67
  		return -ENODEV;
6754f5561   Mark Langsdorf   cpufreq / highban...
68
69
70
71
  	cpu_dev = get_cpu_device(0);
  	if (!cpu_dev) {
  		pr_err("failed to get highbank cpufreq device
  ");
5de6e94a2   Sudeep KarkadaNagesha   cpufreq: highbank...
72
  		return -ENODEV;
6754f5561   Mark Langsdorf   cpufreq / highban...
73
  	}
5de6e94a2   Sudeep KarkadaNagesha   cpufreq: highbank...
74
75
76
77
78
79
  	np = of_node_get(cpu_dev->of_node);
  	if (!np) {
  		pr_err("failed to find highbank cpufreq node
  ");
  		return -ENOENT;
  	}
6754f5561   Mark Langsdorf   cpufreq / highban...
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  
  	cpu_clk = clk_get(cpu_dev, NULL);
  	if (IS_ERR(cpu_clk)) {
  		ret = PTR_ERR(cpu_clk);
  		pr_err("failed to get cpu0 clock: %d
  ", ret);
  		goto out_put_node;
  	}
  
  	ret = clk_notifier_register(cpu_clk, &hb_cpufreq_clk_nb);
  	if (ret) {
  		pr_err("failed to register clk notifier: %d
  ", ret);
  		goto out_put_node;
  	}
bbcf07196   Viresh Kumar   cpufreq: cpu0: re...
95
  	/* Instantiate cpufreq-dt */
5553f9e26   Shawn Guo   cpufreq: instanti...
96
  	platform_device_register_full(&devinfo);
6754f5561   Mark Langsdorf   cpufreq / highban...
97
98
99
100
101
102
103
104
105
  out_put_node:
  	of_node_put(np);
  	return ret;
  }
  module_init(hb_cpufreq_driver_init);
  
  MODULE_AUTHOR("Mark Langsdorf <mark.langsdorf@calxeda.com>");
  MODULE_DESCRIPTION("Calxeda Highbank cpufreq driver");
  MODULE_LICENSE("GPL");