@@ -77,9 +77,6 @@ struct cpufreq_frequency_table freq_table[] = {
7777 FV (2850 , 0 ),
7878 {0 , 0 , CPUFREQ_TABLE_END },
7979};
80- static void __init fill_freq_table (struct cpufreq_frequency_table * ft )
81- {
82- }
8380#endif
8481
8582#ifdef CONFIG_PLATFORM_XUELANG
@@ -135,60 +132,65 @@ static void __init fill_freq_table(struct cpufreq_frequency_table *ft)
135132
136133static unsigned int sunway_get_rate (struct cpufreq_policy * policy )
137134{
138- int i ;
135+ int i , node ;
139136 u64 val ;
140- void __iomem * spbu_base = misc_platform_get_spbu_base ( 0 ) ;
137+ void __iomem * spbu_base ;
141138 struct cpufreq_frequency_table * ft = policy -> freq_table ;
142139
140+ node = per_cpu (hard_node_id , policy -> cpu );
141+ spbu_base = misc_platform_get_spbu_base (node );
142+
143143 /* PLL2 provides working frequency for core */
144144 val = readq (spbu_base + OFFSET_CLK_CTL ) >> CORE_PLL2_CFG_SHIFT ;
145145 val &= CORE_PLL2_CFG_MASK ;
146146
147147 for (i = 0 ; ft [i ].frequency != CPUFREQ_TABLE_END ; i ++ ) {
148148 if (val == i ) {
149149 if (ft [i ].frequency == CPUFREQ_ENTRY_INVALID )
150- return cpuid ( GET_CPU_FREQ , 0 ) * 1000UL ;
150+ return sunway_max_cpu_freq () / KHZ ;
151151 return ft [i ].frequency ;
152152 }
153153 }
154154
155155 return 0 ;
156156}
157157
158- static int sunway_set_rate (unsigned int index )
158+ static int sunway_set_rate (struct cpufreq_policy * policy , unsigned int index )
159159{
160- int i , retry , cpu_num ;
160+ int retry , node ;
161161 void __iomem * spbu_base ;
162162
163- cpu_num = sw64_chip -> get_cpu_num ();
164- for (i = 0 ; i < cpu_num ; i ++ ) {
165- spbu_base = misc_platform_get_spbu_base (i );
166-
167- /* select PLL0/PLL1 */
168- writeq (CLK_LV1_SEL_PROTECT , spbu_base + OFFSET_CLU_LV1_SEL );
169- /* reset PLL2 */
170- writeq (CLK2_PROTECT | CORE_CLK2_RESET | CORE_CLK2_VALID , spbu_base + OFFSET_CLK_CTL );
171- /* configure PLL2_CFG */
172- writeq (CLK2_PROTECT | CORE_CLK2_VALID | (unsigned long )index << CORE_PLL2_CFG_SHIFT ,
173- spbu_base + OFFSET_CLK_CTL );
174- udelay (1 );
175- /* reset over */
176- writeq (CORE_CLK2_VALID , spbu_base + OFFSET_CLK_CTL );
177- retry = 0 ;
178- while (retry < MAX_RETRY ) {
179- if (readq (spbu_base + OFFSET_CLK_CTL ) & CORE_CLK2_LOCK )
180- break ;
181- retry ++ ;
182- udelay (100 );
183- }
184- if (retry == MAX_RETRY )
185- return - ETIME ;
186- /* configure over */
187- writeq (0 , spbu_base + OFFSET_CLK_CTL );
188- /* select PLL2/PLL2 */
189- writeq (CLK_LV1_SEL_MUXA | CLK_LV1_SEL_MUXB | CLK_LV1_SEL_PROTECT ,
190- spbu_base + OFFSET_CLU_LV1_SEL );
163+ node = per_cpu (hard_node_id , policy -> cpu );
164+ spbu_base = misc_platform_get_spbu_base (node );
165+
166+ /* select PLL0/PLL1 */
167+ writeq (CLK_LV1_SEL_PROTECT , spbu_base + OFFSET_CLU_LV1_SEL );
168+ /* reset PLL2 */
169+ writeq (CLK2_PROTECT | CORE_CLK2_RESET | CORE_CLK2_VALID , spbu_base + OFFSET_CLK_CTL );
170+ /* configure PLL2_CFG */
171+ writeq (CLK2_PROTECT | CORE_CLK2_VALID | (unsigned long )index << CORE_PLL2_CFG_SHIFT ,
172+ spbu_base + OFFSET_CLK_CTL );
173+
174+ udelay (1 );
175+ /* reset over */
176+ writeq (CORE_CLK2_VALID , spbu_base + OFFSET_CLK_CTL );
177+ retry = 0 ;
178+ while (retry < MAX_RETRY ) {
179+ if (readq (spbu_base + OFFSET_CLK_CTL ) & CORE_CLK2_LOCK )
180+ break ;
181+ retry ++ ;
182+ udelay (100 );
191183 }
184+
185+ if (retry == MAX_RETRY )
186+ return - ETIME ;
187+
188+ /* configure over */
189+ writeq (0 , spbu_base + OFFSET_CLK_CTL );
190+ /* select PLL2/PLL2 */
191+ writeq (CLK_LV1_SEL_MUXA | CLK_LV1_SEL_MUXB | CLK_LV1_SEL_PROTECT ,
192+ spbu_base + OFFSET_CLU_LV1_SEL );
193+
192194 return 0 ;
193195}
194196
@@ -205,9 +207,6 @@ static unsigned int sunway_cpufreq_get(unsigned int cpu)
205207 return sunway_get_rate (policy );
206208}
207209
208- /*
209- * Here we notify other drivers of the proposed change and the final change.
210- */
211210static int sunway_cpufreq_target (struct cpufreq_policy * policy ,
212211 unsigned int index )
213212{
@@ -218,24 +217,27 @@ static int sunway_cpufreq_target(struct cpufreq_policy *policy,
218217 return - ENODEV ;
219218
220219 /* setting the cpu frequency */
221- ret = sunway_set_rate (index );
220+ ret = sunway_set_rate (policy , index );
222221 if (ret )
223222 return ret ;
224- update_cpu_freq (freq_table [index ].frequency );
225223
226224 return 0 ;
227225}
228226
229227static int sunway_cpufreq_init (struct cpufreq_policy * policy )
230228{
231- cpufreq_generic_init ( policy , freq_table , 0 ) ;
229+ int cpu , node ;
232230
233- return 0 ;
234- }
231+ node = per_cpu (hard_node_id , policy -> cpu );
235232
236- static int sunway_cpufreq_verify (struct cpufreq_policy_data * policy )
237- {
238- return cpufreq_frequency_table_verify (policy , freq_table );
233+ for_each_possible_cpu (cpu ) {
234+ if (per_cpu (hard_node_id , cpu ) == node )
235+ cpumask_set_cpu (cpu , policy -> cpus );
236+ }
237+
238+ policy -> freq_table = freq_table ;
239+
240+ return 0 ;
239241}
240242
241243static int sunway_cpufreq_exit (struct cpufreq_policy * policy )
@@ -251,7 +253,7 @@ static struct cpufreq_driver sunway_cpufreq_driver = {
251253 .name = "sunway-cpufreq" ,
252254 .flags = CPUFREQ_NEED_INITIAL_FREQ_CHECK ,
253255 .init = sunway_cpufreq_init ,
254- .verify = sunway_cpufreq_verify ,
256+ .verify = cpufreq_generic_frequency_table_verify ,
255257 .target_index = sunway_cpufreq_target ,
256258 .get = sunway_cpufreq_get ,
257259 .exit = sunway_cpufreq_exit ,
@@ -261,14 +263,17 @@ static struct cpufreq_driver sunway_cpufreq_driver = {
261263static int __init cpufreq_init (void )
262264{
263265 int i , ret ;
264- unsigned long max_rate = get_cpu_freq () / 1000 ;
266+ unsigned long max_rate = sunway_max_cpu_freq () / KHZ ; /* KHz */
265267
266268 if (!is_in_host ()) {
267269 pr_warn ("cpufreq driver of Sunway platforms is only supported in host mode\n" );
268270 return - ENODEV ;
269271 }
270272
273+ #ifdef CONFIG_PLATFORM_XUELANG
271274 fill_freq_table (freq_table );
275+ #endif
276+
272277 for (i = 0 ; freq_table [i ].frequency != CPUFREQ_TABLE_END ; i ++ ) {
273278 if (max_rate == freq_table [i ].frequency )
274279 freq_table [i + 1 ].frequency = CPUFREQ_TABLE_END ;
0 commit comments