1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * elanfreq: cpufreq driver for the AMD ELAN family
5 * (c) Copyright 2002 Robert Schwebel <r.schwebel@pengutronix.de>
7 * Parts of this code are (c) Sven Geggus <sven@geggus.net>
11 * 2002-02-13: - initial revision for 2.4.18-pre9 by Robert Schwebel
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
20 #include <linux/delay.h>
21 #include <linux/cpufreq.h>
23 #include <asm/cpu_device_id.h>
25 #include <linux/timex.h>
28 #define REG_CSCIR 0x22 /* Chip Setup and Control Index Register */
29 #define REG_CSCDR 0x23 /* Chip Setup and Control Data Register */
31 /* Module parameter */
34 struct s_elan_multiplier
{
35 int clock
; /* frequency in kHz */
36 int val40h
; /* PMU Force Mode register */
37 int val80h
; /* CPU Clock Speed Register */
41 * It is important that the frequencies
42 * are listed in ascending order here!
44 static struct s_elan_multiplier elan_multiplier
[] = {
55 static struct cpufreq_frequency_table elanfreq_table
[] = {
64 {0, 0, CPUFREQ_TABLE_END
},
69 * elanfreq_get_cpu_frequency: determine current cpu speed
71 * Finds out at which frequency the CPU of the Elan SOC runs
72 * at the moment. Frequencies from 1 to 33 MHz are generated
73 * the normal way, 66 and 99 MHz are called "Hyperspeed Mode"
74 * and have the rest of the chip running with 33 MHz.
77 static unsigned int elanfreq_get_cpu_frequency(unsigned int cpu
)
79 u8 clockspeed_reg
; /* Clock Speed Register */
82 outb_p(0x80, REG_CSCIR
);
83 clockspeed_reg
= inb_p(REG_CSCDR
);
86 if ((clockspeed_reg
& 0xE0) == 0xE0)
89 /* Are we in CPU clock multiplied mode (66/99 MHz)? */
90 if ((clockspeed_reg
& 0xE0) == 0xC0) {
91 if ((clockspeed_reg
& 0x01) == 0)
97 /* 33 MHz is not 32 MHz... */
98 if ((clockspeed_reg
& 0xE0) == 0xA0)
101 return (1<<((clockspeed_reg
& 0xE0) >> 5)) * 1000;
105 static int elanfreq_target(struct cpufreq_policy
*policy
,
109 * Access to the Elan's internal registers is indexed via
110 * 0x22: Chip Setup & Control Register Index Register (CSCI)
111 * 0x23: Chip Setup & Control Register Data Register (CSCD)
116 * 0x40 is the Power Management Unit's Force Mode Register.
117 * Bit 6 enables Hyperspeed Mode (66/100 MHz core frequency)
121 outb_p(0x40, REG_CSCIR
); /* Disable hyperspeed mode */
122 outb_p(0x00, REG_CSCDR
);
123 local_irq_enable(); /* wait till internal pipelines and */
124 udelay(1000); /* buffers have cleaned up */
128 /* now, set the CPU clock speed register (0x80) */
129 outb_p(0x80, REG_CSCIR
);
130 outb_p(elan_multiplier
[state
].val80h
, REG_CSCDR
);
132 /* now, the hyperspeed bit in PMU Force Mode Register (0x40) */
133 outb_p(0x40, REG_CSCIR
);
134 outb_p(elan_multiplier
[state
].val40h
, REG_CSCDR
);
141 * Module init and exit code
144 static int elanfreq_cpu_init(struct cpufreq_policy
*policy
)
146 struct cpuinfo_x86
*c
= &cpu_data(0);
147 struct cpufreq_frequency_table
*pos
;
149 /* capability check */
150 if ((c
->x86_vendor
!= X86_VENDOR_AMD
) ||
151 (c
->x86
!= 4) || (c
->x86_model
!= 10))
156 max_freq
= elanfreq_get_cpu_frequency(0);
159 cpufreq_for_each_entry(pos
, elanfreq_table
)
160 if (pos
->frequency
> max_freq
)
161 pos
->frequency
= CPUFREQ_ENTRY_INVALID
;
163 policy
->freq_table
= elanfreq_table
;
170 * elanfreq_setup - elanfreq command line parameter parsing
172 * elanfreq command line parameter. Use:
174 * to set the maximum CPU frequency to 66 MHz. Note that in
175 * case you do not give this boot parameter, the maximum
176 * frequency will fall back to _current_ CPU frequency which
177 * might be lower. If you build this as a module, use the
178 * max_freq module parameter instead.
180 static int __init
elanfreq_setup(char *str
)
182 max_freq
= simple_strtoul(str
, &str
, 0);
183 pr_warn("You're using the deprecated elanfreq command line option. Use elanfreq.max_freq instead, please!\n");
186 __setup("elanfreq=", elanfreq_setup
);
190 static struct cpufreq_driver elanfreq_driver
= {
191 .get
= elanfreq_get_cpu_frequency
,
192 .flags
= CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING
,
193 .verify
= cpufreq_generic_frequency_table_verify
,
194 .target_index
= elanfreq_target
,
195 .init
= elanfreq_cpu_init
,
197 .attr
= cpufreq_generic_attr
,
200 static const struct x86_cpu_id elan_id
[] = {
201 X86_MATCH_VENDOR_FAM_MODEL(AMD
, 4, 10, NULL
),
204 MODULE_DEVICE_TABLE(x86cpu
, elan_id
);
206 static int __init
elanfreq_init(void)
208 if (!x86_match_cpu(elan_id
))
210 return cpufreq_register_driver(&elanfreq_driver
);
214 static void __exit
elanfreq_exit(void)
216 cpufreq_unregister_driver(&elanfreq_driver
);
220 module_param(max_freq
, int, 0444);
222 MODULE_LICENSE("GPL");
223 MODULE_AUTHOR("Robert Schwebel <r.schwebel@pengutronix.de>, "
224 "Sven Geggus <sven@geggus.net>");
225 MODULE_DESCRIPTION("cpufreq driver for AMD's Elan CPUs");
227 module_init(elanfreq_init
);
228 module_exit(elanfreq_exit
);