]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/arm/mach-imx/busfreq-imx6.c
MLK-9961-4 arm:imx6x: Change PLL1 clock management.
[karo-tx-linux.git] / arch / arm / mach-imx / busfreq-imx6.c
1 /*
2  * Copyright (C) 2011-2015 Freescale Semiconductor, Inc. All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
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
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 /*!
20  * @file busfreq-imx6.c
21  *
22  * @brief A common API for the Freescale Semiconductor iMX6 Busfreq API
23  *
24  * The APIs are for setting bus frequency to different values based on the
25  * highest freqeuncy requested.
26  *
27  * @ingroup PM
28  */
29
30 #include <asm/cacheflush.h>
31 #include <asm/fncpy.h>
32 #include <asm/io.h>
33 #include <asm/mach/map.h>
34 #include <asm/mach-types.h>
35 #include <asm/tlb.h>
36 #include <linux/busfreq-imx6.h>
37 #include <linux/clk.h>
38 #include <linux/clk-provider.h>
39 #include <linux/delay.h>
40 #include <linux/module.h>
41 #include <linux/mutex.h>
42 #include <linux/of.h>
43 #include <linux/of_fdt.h>
44 #include <linux/platform_device.h>
45 #include <linux/proc_fs.h>
46 #include <linux/reboot.h>
47 #include <linux/regulator/consumer.h>
48 #include <linux/sched.h>
49 #include <linux/suspend.h>
50 #include "clk.h"
51 #include "hardware.h"
52 #include "common.h"
53
54 #define LPAPM_CLK               24000000
55 #define DDR3_AUDIO_CLK          50000000
56 #define LPDDR2_AUDIO_CLK        100000000
57
58 #define MMDC_MDMISC_DDR_TYPE_DDR3       0
59 #define MMDC_MDMISC_DDR_TYPE_LPDDR2     1
60
61 static int ddr_type;
62 int high_bus_freq_mode;
63 int med_bus_freq_mode;
64 int audio_bus_freq_mode;
65 int low_bus_freq_mode;
66 int ultra_low_bus_freq_mode;
67 unsigned int ddr_med_rate;
68 unsigned int ddr_normal_rate;
69 unsigned long ddr_freq_change_total_size;
70 unsigned long ddr_freq_change_iram_base;
71 unsigned long ddr_freq_change_iram_phys;
72
73 static int bus_freq_scaling_initialized;
74 static struct device *busfreq_dev;
75 static int busfreq_suspended;
76 static u32 org_arm_rate;
77 static int bus_freq_scaling_is_active;
78 static int high_bus_count, med_bus_count, audio_bus_count, low_bus_count;
79 static unsigned int ddr_low_rate;
80
81 extern unsigned long iram_tlb_phys_addr;
82 extern int unsigned long iram_tlb_base_addr;
83
84 extern int init_mmdc_lpddr2_settings(struct platform_device *dev);
85 extern int init_mmdc_ddr3_settings_imx6q(struct platform_device *dev);
86 extern int init_mmdc_ddr3_settings_imx6sx(struct platform_device *dev);
87 extern int update_ddr_freq_imx6q(int ddr_rate);
88 extern int update_ddr_freq_imx6sx(int ddr_rate);
89 extern int update_lpddr2_freq(int ddr_rate);
90
91 DEFINE_MUTEX(bus_freq_mutex);
92
93 static struct clk *mmdc_clk;
94 static struct clk *pll2_400;
95 static struct clk *periph_clk;
96 static struct clk *periph_pre_clk;
97 static struct clk *periph_clk2_sel;
98 static struct clk *periph_clk2;
99 static struct clk *osc_clk;
100 static struct clk *cpu_clk;
101 static struct clk *pll3;
102 static struct clk *pll2;
103 static struct clk *pll2_bus;
104 static struct clk *pll2_bypass_src;
105 static struct clk *pll2_bypass;
106 static struct clk *pll2_200;
107 static struct clk *pll1_sys;
108 static struct clk *periph2_clk;
109 static struct clk *ocram_clk;
110 static struct clk *ahb_clk;
111 static struct clk *pll1_sw_clk;
112 static struct clk *periph2_pre_clk;
113 static struct clk *periph2_clk2_sel;
114 static struct clk *periph2_clk2;
115 static struct clk *step_clk;
116 static struct clk *axi_alt_sel_clk;
117 static struct clk *axi_sel_clk;
118 static struct clk *pll3_pfd1_540m;
119 static struct clk *m4_clk;
120 static struct clk *pll1;
121 static struct clk *pll1_bypass;
122 static struct clk *pll1_bypass_src;
123
124 static u32 pll2_org_rate;
125 static struct delayed_work low_bus_freq_handler;
126 static struct delayed_work bus_freq_daemon;
127
128 static RAW_NOTIFIER_HEAD(busfreq_notifier_chain);
129
130 static int busfreq_notify(enum busfreq_event event)
131 {
132         int ret;
133
134         ret = raw_notifier_call_chain(&busfreq_notifier_chain, event, NULL);
135
136         return notifier_to_errno(ret);
137 }
138
139 int register_busfreq_notifier(struct notifier_block *nb)
140 {
141         return raw_notifier_chain_register(&busfreq_notifier_chain, nb);
142 }
143 EXPORT_SYMBOL(register_busfreq_notifier);
144
145 int unregister_busfreq_notifier(struct notifier_block *nb)
146 {
147         return raw_notifier_chain_unregister(&busfreq_notifier_chain, nb);
148 }
149 EXPORT_SYMBOL(unregister_busfreq_notifier);
150
151 static bool check_m4_sleep(void)
152 {
153         unsigned long timeout = jiffies + msecs_to_jiffies(500);
154
155         while (imx_gpc_is_m4_sleeping() == 0)
156                 if (time_after(jiffies, timeout))
157                         return false;
158         return  true;
159 }
160
161 static void enter_lpm_imx6sx(void)
162 {
163         if (imx_src_is_m4_enabled())
164                 if (!check_m4_sleep())
165                         pr_err("M4 is NOT in sleep!!!\n");
166
167         /* set periph_clk2 to source from OSC for periph */
168         imx_clk_set_parent(periph_clk2_sel, osc_clk);
169         imx_clk_set_parent(periph_clk, periph_clk2);
170         /* set ahb/ocram to 24MHz */
171         imx_clk_set_rate(ahb_clk, LPAPM_CLK);
172         imx_clk_set_rate(ocram_clk, LPAPM_CLK);
173
174         if (audio_bus_count) {
175                 /* Need to ensure that PLL2_PFD_400M is kept ON. */
176                 clk_prepare_enable(pll2_400);
177                 if (ddr_type == MMDC_MDMISC_DDR_TYPE_DDR3)
178                         update_ddr_freq_imx6sx(DDR3_AUDIO_CLK);
179                 else if (ddr_type == MMDC_MDMISC_DDR_TYPE_LPDDR2)
180                         update_lpddr2_freq(LPDDR2_AUDIO_CLK);
181                 imx_clk_set_parent(periph2_clk2_sel, pll3);
182                 imx_clk_set_parent(periph2_pre_clk, pll2_400);
183                 imx_clk_set_parent(periph2_clk, periph2_pre_clk);
184                 /*
185                  * As periph2_clk's parent is not changed from
186                  * high mode to audio mode, so clk framework
187                  * will not update its children's freq, but we
188                  * change the mmdc's podf in asm code, so here
189                  * need to update mmdc rate to make sure clk
190                  * tree is right, although it will not do any
191                  * change to hardware.
192                  */
193                 if (high_bus_freq_mode) {
194                         if (ddr_type == MMDC_MDMISC_DDR_TYPE_DDR3)
195                                 imx_clk_set_rate(mmdc_clk, DDR3_AUDIO_CLK);
196                         else if (ddr_type == MMDC_MDMISC_DDR_TYPE_LPDDR2)
197                                 imx_clk_set_rate(mmdc_clk, LPDDR2_AUDIO_CLK);
198                 }
199                 audio_bus_freq_mode = 1;
200                 low_bus_freq_mode = 0;
201         } else {
202                 if (ddr_type == MMDC_MDMISC_DDR_TYPE_DDR3)
203                         update_ddr_freq_imx6sx(LPAPM_CLK);
204                 else if (ddr_type == MMDC_MDMISC_DDR_TYPE_LPDDR2)
205                         update_lpddr2_freq(LPAPM_CLK);
206                 imx_clk_set_parent(periph2_clk2_sel, osc_clk);
207                 imx_clk_set_parent(periph2_clk, periph2_clk2);
208
209                 if (audio_bus_freq_mode)
210                         clk_disable_unprepare(pll2_400);
211                 low_bus_freq_mode = 1;
212                 audio_bus_freq_mode = 0;
213         }
214 }
215
216 static void exit_lpm_imx6sx(void)
217 {
218         clk_prepare_enable(pll2_400);
219
220         /*
221          * lower ahb/ocram's freq first to avoid too high
222          * freq during parent switch from OSC to pll3.
223          */
224         imx_clk_set_rate(ahb_clk, LPAPM_CLK / 3);
225         imx_clk_set_rate(ocram_clk, LPAPM_CLK / 2);
226         /* set periph_clk2 to pll3 */
227         imx_clk_set_parent(periph_clk2_sel, pll3);
228         /* set periph clk to from pll2_400 */
229         imx_clk_set_parent(periph_pre_clk, pll2_400);
230         imx_clk_set_parent(periph_clk, periph_pre_clk);
231
232         if (ddr_type == MMDC_MDMISC_DDR_TYPE_DDR3)
233                 update_ddr_freq_imx6sx(ddr_normal_rate);
234         else if (ddr_type == MMDC_MDMISC_DDR_TYPE_LPDDR2)
235                 update_lpddr2_freq(ddr_normal_rate);
236         /* correct parent info after ddr freq change in asm code */
237         imx_clk_set_parent(periph2_pre_clk, pll2_400);
238         imx_clk_set_parent(periph2_clk, periph2_pre_clk);
239         imx_clk_set_parent(periph2_clk2_sel, pll3);
240
241         /*
242          * As periph2_clk's parent is not changed from
243          * audio mode to high mode, so clk framework
244          * will not update its children's freq, but we
245          * change the mmdc's podf in asm code, so here
246          * need to update mmdc rate to make sure clk
247          * tree is right, although it will not do any
248          * change to hardware.
249          */
250         if (audio_bus_freq_mode)
251                 imx_clk_set_rate(mmdc_clk, ddr_normal_rate);
252
253         clk_disable_unprepare(pll2_400);
254
255         if (audio_bus_freq_mode)
256                 clk_disable_unprepare(pll2_400);
257 }
258
259 static void enter_lpm_imx6sl(void)
260 {
261         if (high_bus_freq_mode) {
262                 pll2_org_rate = clk_get_rate(pll2_bus);
263                 /* Set periph_clk to be sourced from OSC_CLK */
264                 imx_clk_set_parent(periph_clk2_sel, osc_clk);
265                 imx_clk_set_parent(periph_clk, periph_clk2);
266                 /* Ensure AHB/AXI clks are at 24MHz. */
267                 imx_clk_set_rate(ahb_clk, LPAPM_CLK);
268                 imx_clk_set_rate(ocram_clk, LPAPM_CLK);
269         }
270         if (audio_bus_count) {
271                 /* Set AHB to 8MHz to lower pwer.*/
272                 imx_clk_set_rate(ahb_clk, LPAPM_CLK / 3);
273
274                 /* Set up DDR to 100MHz. */
275                 update_lpddr2_freq(LPDDR2_AUDIO_CLK);
276
277                 /* Fix the clock tree in kernel */
278                 imx_clk_set_parent(periph2_pre_clk, pll2_200);
279                 imx_clk_set_parent(periph2_clk, periph2_pre_clk);
280
281                 if (low_bus_freq_mode || ultra_low_bus_freq_mode) {
282                         /*
283                          * Fix the clock tree in kernel, make sure
284                          * pll2_bypass is updated as it is
285                          * sourced from PLL2.
286                          */
287                         imx_clk_set_parent(pll2_bypass, pll2);
288                         /*
289                          * Swtich ARM to run off PLL2_PFD2_400MHz
290                          * since DDR is anyway at 100MHz.
291                          */
292                         imx_clk_set_parent(step_clk, pll2_400);
293                         imx_clk_set_parent(pll1_sw_clk, step_clk);
294                         /*
295                           * Need to ensure that PLL1 is bypassed and enabled
296                           * before ARM-PODF is set.
297                           */
298                         clk_set_parent(pll1_bypass, pll1_bypass_src);
299
300                         /*
301                          * Ensure that the clock will be
302                          * at original speed.
303                          */
304                         imx_clk_set_rate(cpu_clk, org_arm_rate);
305                 }
306                 low_bus_freq_mode = 0;
307                 ultra_low_bus_freq_mode = 0;
308                 audio_bus_freq_mode = 1;
309         } else {
310                 u32 arm_div, pll1_rate;
311                 org_arm_rate = clk_get_rate(cpu_clk);
312                 if (low_bus_freq_mode && low_bus_count == 0) {
313                         /*
314                          * We are already in DDR @ 24MHz state, but
315                          * no one but ARM needs the DDR. In this case,
316                          * we can lower the DDR freq to 1MHz when ARM
317                          * enters WFI in this state. Keep track of this state.
318                          */
319                         ultra_low_bus_freq_mode = 1;
320                         low_bus_freq_mode = 0;
321                         audio_bus_freq_mode = 0;
322                 } else {
323                         if (!ultra_low_bus_freq_mode && !low_bus_freq_mode) {
324                                 /*
325                                  * Anyway, make sure the AHB is running at 24MHz
326                                  * in low_bus_freq_mode.
327                                  */
328                                 if (audio_bus_freq_mode)
329                                         imx_clk_set_rate(ahb_clk, LPAPM_CLK);
330                                 /*
331                                  * Set DDR to 24MHz.
332                                  * Since we are going to bypass PLL2,
333                                  * we need to move ARM clk off PLL2_PFD2
334                                  * to PLL1. Make sure the PLL1 is running
335                                  * at the lowest possible freq.
336                                  * To work well with CPUFREQ we want to ensure that
337                                  * the CPU freq does not change, so attempt to
338                                  * get a freq as close to 396MHz as possible.
339                                  */
340                                 imx_clk_set_rate(pll1,
341                                         clk_round_rate(pll1, (org_arm_rate * 2)));
342                                 pll1_rate = clk_get_rate(pll1);
343                                 arm_div = pll1_rate / org_arm_rate;
344                                 if (pll1_rate / arm_div > org_arm_rate)
345                                         arm_div++;
346                                 /*
347                                   * Need to ensure that PLL1 is bypassed and enabled
348                                   * before ARM-PODF is set.
349                                   */
350                                 clk_set_parent(pll1_bypass, pll1);
351                                 /*
352                                  * Ensure ARM CLK is lower before
353                                  * changing the parent.
354                                  */
355                                 imx_clk_set_rate(cpu_clk, org_arm_rate / arm_div);
356                                 /* Now set the ARM clk parent to PLL1_SYS. */
357                                 imx_clk_set_parent(pll1_sw_clk, pll1_sys);
358
359                                 /*
360                                  * Set STEP_CLK back to OSC to save power and
361                                  * also to maintain the parent.The WFI iram code
362                                  * will switch step_clk to osc, but the clock API
363                                  * is not aware of the change and when a new request
364                                  * to change the step_clk parent to pll2_pfd2_400M
365                                  * is requested sometime later, the change is ignored.
366                                  */
367                                 imx_clk_set_parent(step_clk, osc_clk);
368                                 /* Now set DDR to 24MHz. */
369                                 update_lpddr2_freq(LPAPM_CLK);
370
371                                 /*
372                                  * Fix the clock tree in kernel.
373                                  * Make sure PLL2 rate is updated as it gets
374                                  * bypassed in the DDR freq change code.
375                                  */
376                                 imx_clk_set_parent(pll2_bypass, pll2_bypass_src);
377                                 imx_clk_set_parent(periph2_clk2_sel, pll2_bus);
378                                 imx_clk_set_parent(periph2_clk, periph2_clk2);
379
380                         }
381                         if (low_bus_count == 0) {
382                                 ultra_low_bus_freq_mode = 1;
383                                 low_bus_freq_mode = 0;
384                         } else {
385                                 ultra_low_bus_freq_mode = 0;
386                                 low_bus_freq_mode = 1;
387                         }
388                         audio_bus_freq_mode = 0;
389                 }
390         }
391 }
392
393 static void exit_lpm_imx6sl(void)
394 {
395         /* Change DDR freq in IRAM. */
396         update_lpddr2_freq(ddr_normal_rate);
397
398         /*
399          * Fix the clock tree in kernel.
400          * Make sure PLL2 rate is updated as it gets
401          * un-bypassed in the DDR freq change code.
402          */
403         imx_clk_set_parent(pll2_bypass, pll2);
404         imx_clk_set_parent(periph2_pre_clk, pll2_400);
405         imx_clk_set_parent(periph2_clk, periph2_pre_clk);
406
407         /* Ensure that periph_clk is sourced from PLL2_400. */
408         imx_clk_set_parent(periph_pre_clk, pll2_400);
409         /*
410          * Before switching the perhiph_clk, ensure that the
411          * AHB/AXI will not be too fast.
412          */
413         imx_clk_set_rate(ahb_clk, LPAPM_CLK / 3);
414         imx_clk_set_rate(ocram_clk, LPAPM_CLK / 2);
415         imx_clk_set_parent(periph_clk, periph_pre_clk);
416
417         if (low_bus_freq_mode || ultra_low_bus_freq_mode) {
418                 /* Move ARM from PLL1_SW_CLK to PLL2_400. */
419                 imx_clk_set_parent(step_clk, pll2_400);
420                 imx_clk_set_parent(pll1_sw_clk, step_clk);
421                 /*
422                   * Need to ensure that PLL1 is bypassed and enabled
423                   * before ARM-PODF is set.
424                   */
425                 clk_set_parent(pll1_bypass, pll1_bypass_src);
426                 imx_clk_set_rate(cpu_clk, org_arm_rate);
427                 ultra_low_bus_freq_mode = 0;
428         }
429 }
430
431 static void reduce_bus_freq(void)
432 {
433         clk_prepare_enable(pll3);
434         if (audio_bus_count && (low_bus_freq_mode || ultra_low_bus_freq_mode))
435                 busfreq_notify(LOW_BUSFREQ_EXIT);
436         else if (!audio_bus_count)
437                 busfreq_notify(LOW_BUSFREQ_ENTER);
438         if (cpu_is_imx6sl())
439                 enter_lpm_imx6sl();
440         else if (cpu_is_imx6sx())
441                 enter_lpm_imx6sx();
442         else {
443                 if (cpu_is_imx6dl())
444                         /* Set axi to periph_clk */
445                         imx_clk_set_parent(axi_sel_clk, periph_clk);
446
447                 if (audio_bus_count) {
448                         /* Need to ensure that PLL2_PFD_400M is kept ON. */
449                         clk_prepare_enable(pll2_400);
450                         update_ddr_freq_imx6q(DDR3_AUDIO_CLK);
451                         /* Make sure periph clk's parent also got updated */
452                         imx_clk_set_parent(periph_clk2_sel, pll3);
453                         imx_clk_set_parent(periph_pre_clk, pll2_200);
454                         imx_clk_set_parent(periph_clk, periph_pre_clk);
455                         audio_bus_freq_mode = 1;
456                         low_bus_freq_mode = 0;
457                 } else {
458                         update_ddr_freq_imx6q(LPAPM_CLK);
459                         /* Make sure periph clk's parent also got updated */
460                         imx_clk_set_parent(periph_clk2_sel, osc_clk);
461                         /* Set periph_clk parent to OSC via periph_clk2_sel */
462                         imx_clk_set_parent(periph_clk, periph_clk2);
463                         if (audio_bus_freq_mode)
464                                 clk_disable_unprepare(pll2_400);
465                         low_bus_freq_mode = 1;
466                         audio_bus_freq_mode = 0;
467                 }
468         }
469         clk_disable_unprepare(pll3);
470
471         med_bus_freq_mode = 0;
472         high_bus_freq_mode = 0;
473
474         if (audio_bus_freq_mode)
475                 dev_dbg(busfreq_dev, "Bus freq set to audio mode. Count:\
476                         high %d, med %d, audio %d\n",
477                         high_bus_count, med_bus_count, audio_bus_count);
478         if (low_bus_freq_mode)
479                 dev_dbg(busfreq_dev, "Bus freq set to low mode. Count:\
480                         high %d, med %d, audio %d\n",
481                         high_bus_count, med_bus_count, audio_bus_count);
482 }
483
484 static void reduce_bus_freq_handler(struct work_struct *work)
485 {
486         mutex_lock(&bus_freq_mutex);
487
488         reduce_bus_freq();
489
490         mutex_unlock(&bus_freq_mutex);
491 }
492
493 /*
494  * Set the DDR, AHB to 24MHz.
495  * This mode will be activated only when none of the modules that
496  * need a higher DDR or AHB frequency are active.
497  */
498 int set_low_bus_freq(void)
499 {
500         if (busfreq_suspended)
501                 return 0;
502
503         if (!bus_freq_scaling_initialized || !bus_freq_scaling_is_active)
504                 return 0;
505
506         /*
507          * Check to see if we need to got from
508          * low bus freq mode to audio bus freq mode.
509          * If so, the change needs to be done immediately.
510          */
511         if (audio_bus_count && (low_bus_freq_mode || ultra_low_bus_freq_mode))
512                 reduce_bus_freq();
513         else
514                 /*
515                  * Don't lower the frequency immediately. Instead
516                  * scheduled a delayed work and drop the freq if
517                  * the conditions still remain the same.
518                  */
519                 schedule_delayed_work(&low_bus_freq_handler,
520                                         usecs_to_jiffies(3000000));
521         return 0;
522 }
523
524 /*
525  * Set the DDR to either 528MHz or 400MHz for iMX6qd
526  * or 400MHz for iMX6dl.
527  */
528 static int set_high_bus_freq(int high_bus_freq)
529 {
530         struct clk *periph_clk_parent;
531
532         if (bus_freq_scaling_initialized && bus_freq_scaling_is_active)
533                 cancel_delayed_work_sync(&low_bus_freq_handler);
534
535         if (busfreq_suspended)
536                 return 0;
537
538         if (cpu_is_imx6q())
539                 periph_clk_parent = pll2_bus;
540         else
541                 periph_clk_parent = pll2_400;
542
543         if (!bus_freq_scaling_initialized || !bus_freq_scaling_is_active)
544                 return 0;
545
546         if (high_bus_freq_mode)
547                 return 0;
548
549         /* medium bus freq is only supported for MX6DQ */
550         if (med_bus_freq_mode && !high_bus_freq)
551                 return 0;
552
553         if (low_bus_freq_mode || ultra_low_bus_freq_mode)
554                 busfreq_notify(LOW_BUSFREQ_EXIT);
555
556         clk_prepare_enable(pll3);
557         if (cpu_is_imx6sl())
558                 exit_lpm_imx6sl();
559         else if (cpu_is_imx6sx())
560                 exit_lpm_imx6sx();
561         else {
562                 if (high_bus_freq) {
563                         clk_prepare_enable(pll2_400);
564                         update_ddr_freq_imx6q(ddr_normal_rate);
565                         /* Make sure periph clk's parent also got updated */
566                         imx_clk_set_parent(periph_clk2_sel, pll3);
567                         imx_clk_set_parent(periph_pre_clk, periph_clk_parent);
568                         imx_clk_set_parent(periph_clk, periph_pre_clk);
569                         if (cpu_is_imx6dl()) {
570                                 /* Set axi to pll3_pfd1_540m */
571                                 imx_clk_set_parent(axi_alt_sel_clk, pll3_pfd1_540m);
572                                 imx_clk_set_parent(axi_sel_clk, axi_alt_sel_clk);
573                         }
574                         clk_disable_unprepare(pll2_400);
575                 } else {
576                         update_ddr_freq_imx6q(ddr_med_rate);
577                         /* Make sure periph clk's parent also got updated */
578                         imx_clk_set_parent(periph_clk2_sel, pll3);
579                         imx_clk_set_parent(periph_pre_clk, pll2_400);
580                         imx_clk_set_parent(periph_clk, periph_pre_clk);
581                 }
582                 if (audio_bus_freq_mode)
583                         clk_disable_unprepare(pll2_400);
584         }
585
586         high_bus_freq_mode = 1;
587         med_bus_freq_mode = 0;
588         low_bus_freq_mode = 0;
589         audio_bus_freq_mode = 0;
590
591         clk_disable_unprepare(pll3);
592         if (high_bus_freq_mode)
593                 dev_dbg(busfreq_dev, "Bus freq set to high mode. Count:\
594                         high %d, med %d, audio %d\n",
595                         high_bus_count, med_bus_count, audio_bus_count);
596         if (med_bus_freq_mode)
597                 dev_dbg(busfreq_dev, "Bus freq set to med mode. Count:\
598                         high %d, med %d, audio %d\n",
599                         high_bus_count, med_bus_count, audio_bus_count);
600
601         return 0;
602 }
603
604 void request_bus_freq(enum bus_freq_mode mode)
605 {
606         mutex_lock(&bus_freq_mutex);
607
608         if (mode == BUS_FREQ_HIGH)
609                 high_bus_count++;
610         else if (mode == BUS_FREQ_MED)
611                 med_bus_count++;
612         else if (mode == BUS_FREQ_AUDIO)
613                 audio_bus_count++;
614         else if (mode == BUS_FREQ_LOW)
615                 low_bus_count++;
616
617         if (busfreq_suspended || !bus_freq_scaling_initialized ||
618                 !bus_freq_scaling_is_active) {
619                 mutex_unlock(&bus_freq_mutex);
620                 return;
621         }
622         cancel_delayed_work_sync(&low_bus_freq_handler);
623
624         if (cpu_is_imx6dl() || cpu_is_imx6sx()) {
625                 /* No support for medium setpoint on i.MX6DL and i.MX6SX. */
626                 if (mode == BUS_FREQ_MED) {
627                         high_bus_count++;
628                         mode = BUS_FREQ_HIGH;
629                 }
630         }
631
632         if ((mode == BUS_FREQ_HIGH) && (!high_bus_freq_mode)) {
633                 set_high_bus_freq(1);
634                 mutex_unlock(&bus_freq_mutex);
635                 return;
636         }
637
638         if ((mode == BUS_FREQ_MED) && (!high_bus_freq_mode) &&
639                 (!med_bus_freq_mode)) {
640                 set_high_bus_freq(0);
641                 mutex_unlock(&bus_freq_mutex);
642                 return;
643         }
644         if ((mode == BUS_FREQ_AUDIO) && (!high_bus_freq_mode) &&
645                 (!med_bus_freq_mode) && (!audio_bus_freq_mode)) {
646                 set_low_bus_freq();
647                 mutex_unlock(&bus_freq_mutex);
648                 return;
649         }
650         mutex_unlock(&bus_freq_mutex);
651         return;
652 }
653 EXPORT_SYMBOL(request_bus_freq);
654
655 void release_bus_freq(enum bus_freq_mode mode)
656 {
657         mutex_lock(&bus_freq_mutex);
658
659         if (mode == BUS_FREQ_HIGH) {
660                 if (high_bus_count == 0) {
661                         dev_err(busfreq_dev, "high bus count mismatch!\n");
662                         dump_stack();
663                         mutex_unlock(&bus_freq_mutex);
664                         return;
665                 }
666                 high_bus_count--;
667         } else if (mode == BUS_FREQ_MED) {
668                 if (med_bus_count == 0) {
669                         dev_err(busfreq_dev, "med bus count mismatch!\n");
670                         dump_stack();
671                         mutex_unlock(&bus_freq_mutex);
672                         return;
673                 }
674                 med_bus_count--;
675         } else if (mode == BUS_FREQ_AUDIO) {
676                 if (audio_bus_count == 0) {
677                         dev_err(busfreq_dev, "audio bus count mismatch!\n");
678                         dump_stack();
679                         mutex_unlock(&bus_freq_mutex);
680                         return;
681                 }
682                 audio_bus_count--;
683         } else if (mode == BUS_FREQ_LOW) {
684                 if (low_bus_count == 0) {
685                         dev_err(busfreq_dev, "low bus count mismatch!\n");
686                         dump_stack();
687                         mutex_unlock(&bus_freq_mutex);
688                         return;
689                 }
690                 low_bus_count--;
691         }
692
693         if (busfreq_suspended || !bus_freq_scaling_initialized ||
694                 !bus_freq_scaling_is_active) {
695                 mutex_unlock(&bus_freq_mutex);
696                 return;
697         }
698
699         if (cpu_is_imx6dl() || cpu_is_imx6sx()) {
700                 /* No support for medium setpoint on i.MX6DL and i.MX6SX. */
701                 if (mode == BUS_FREQ_MED) {
702                         high_bus_count--;
703                         mode = BUS_FREQ_HIGH;
704                 }
705         }
706
707         if ((!audio_bus_freq_mode) && (high_bus_count == 0) &&
708                 (med_bus_count == 0) && (audio_bus_count != 0)) {
709                 set_low_bus_freq();
710                 mutex_unlock(&bus_freq_mutex);
711                 return;
712         }
713         if ((!low_bus_freq_mode) && (high_bus_count == 0) &&
714                 (med_bus_count == 0) && (audio_bus_count == 0) &&
715                 (low_bus_count != 0)) {
716                 set_low_bus_freq();
717                 mutex_unlock(&bus_freq_mutex);
718                 return;
719         }
720         if ((!ultra_low_bus_freq_mode) && (high_bus_count == 0) &&
721                 (med_bus_count == 0) && (audio_bus_count == 0) &&
722                 (low_bus_count == 0)) {
723                 set_low_bus_freq();
724                 mutex_unlock(&bus_freq_mutex);
725                 return;
726         }
727
728         mutex_unlock(&bus_freq_mutex);
729         return;
730 }
731 EXPORT_SYMBOL(release_bus_freq);
732
733 static struct map_desc ddr_iram_io_desc __initdata = {
734         /* .virtual and .pfn are run-time assigned */
735         .length         = SZ_1M,
736         .type           = MT_MEMORY_RWX_NONCACHED,
737 };
738
739 const static char *ddr_freq_iram_match[] __initconst = {
740         "fsl,ddr-lpm-sram",
741         NULL
742 };
743
744 static int __init imx6_dt_find_ddr_sram(unsigned long node,
745                 const char *uname, int depth, void *data)
746 {
747         unsigned long ddr_iram_addr;
748         __be32 *prop;
749
750         if (of_flat_dt_match(node, ddr_freq_iram_match)) {
751                 unsigned long len;
752                 prop = of_get_flat_dt_prop(node, "reg", &len);
753                 if (prop == NULL || len != (sizeof(unsigned long) * 2))
754                         return EINVAL;
755                 ddr_iram_addr = be32_to_cpu(prop[0]);
756                 ddr_freq_change_total_size = be32_to_cpu(prop[1]);
757                 ddr_freq_change_iram_phys = ddr_iram_addr;
758
759                 /* Make sure ddr_freq_change_iram_phys is 8 byte aligned. */
760                 if ((uintptr_t)(ddr_freq_change_iram_phys) & (FNCPY_ALIGN - 1))
761                         ddr_freq_change_iram_phys += FNCPY_ALIGN - ((uintptr_t)ddr_freq_change_iram_phys % (FNCPY_ALIGN));
762         }
763         return 0;
764 }
765
766 void __init imx6_busfreq_map_io(void)
767 {
768         /*
769          * Get the address of IRAM to be used by the ddr frequency
770          * change code from the device tree.
771          */
772         WARN_ON(of_scan_flat_dt(imx6_dt_find_ddr_sram, NULL));
773
774         if (ddr_freq_change_iram_phys) {
775                 ddr_freq_change_iram_base = IMX_IO_P2V(ddr_freq_change_iram_phys);
776                 if ((iram_tlb_phys_addr & 0xFFF00000) != (ddr_freq_change_iram_phys & 0xFFF00000)) {
777                         /* We need to create a 1M page table entry. */
778                         ddr_iram_io_desc.virtual = IMX_IO_P2V(ddr_freq_change_iram_phys & 0xFFF00000);
779                         ddr_iram_io_desc.pfn = __phys_to_pfn(ddr_freq_change_iram_phys & 0xFFF00000);
780                         iotable_init(&ddr_iram_io_desc, 1);
781                 }
782                 memset((void *)ddr_freq_change_iram_base, 0, ddr_freq_change_total_size);
783         }
784 }
785
786 static void bus_freq_daemon_handler(struct work_struct *work)
787 {
788         mutex_lock(&bus_freq_mutex);
789         if ((!low_bus_freq_mode) && (high_bus_count == 0) &&
790                 (med_bus_count == 0) && (audio_bus_count == 0))
791                 set_low_bus_freq();
792         mutex_unlock(&bus_freq_mutex);
793 }
794
795 static ssize_t bus_freq_scaling_enable_show(struct device *dev,
796                                 struct device_attribute *attr, char *buf)
797 {
798         if (bus_freq_scaling_is_active)
799                 return sprintf(buf, "Bus frequency scaling is enabled\n");
800         else
801                 return sprintf(buf, "Bus frequency scaling is disabled\n");
802 }
803
804 static ssize_t bus_freq_scaling_enable_store(struct device *dev,
805                                  struct device_attribute *attr,
806                                  const char *buf, size_t size)
807 {
808         if (strncmp(buf, "1", 1) == 0) {
809                 bus_freq_scaling_is_active = 1;
810                 set_high_bus_freq(1);
811                 /*
812                  * We set bus freq to highest at the beginning,
813                  * so we use this daemon thread to make sure system
814                  * can enter low bus mode if
815                  * there is no high bus request pending
816                  */
817                 schedule_delayed_work(&bus_freq_daemon,
818                         usecs_to_jiffies(5000000));
819         } else if (strncmp(buf, "0", 1) == 0) {
820                 if (bus_freq_scaling_is_active)
821                         set_high_bus_freq(1);
822                 bus_freq_scaling_is_active = 0;
823         }
824         return size;
825 }
826
827 static int bus_freq_pm_notify(struct notifier_block *nb, unsigned long event,
828         void *dummy)
829 {
830         mutex_lock(&bus_freq_mutex);
831
832         if (event == PM_SUSPEND_PREPARE) {
833                 high_bus_count++;
834                 set_high_bus_freq(1);
835                 busfreq_suspended = 1;
836         } else if (event == PM_POST_SUSPEND) {
837                 busfreq_suspended = 0;
838                 high_bus_count--;
839                 schedule_delayed_work(&bus_freq_daemon,
840                         usecs_to_jiffies(5000000));
841         }
842
843         mutex_unlock(&bus_freq_mutex);
844
845         return NOTIFY_OK;
846 }
847
848 static int busfreq_reboot_notifier_event(struct notifier_block *this,
849                                                  unsigned long event, void *ptr)
850 {
851         /* System is rebooting. Set the system into high_bus_freq_mode. */
852         request_bus_freq(BUS_FREQ_HIGH);
853
854         return 0;
855 }
856
857 static struct notifier_block imx_bus_freq_pm_notifier = {
858         .notifier_call = bus_freq_pm_notify,
859 };
860
861 static struct notifier_block imx_busfreq_reboot_notifier = {
862         .notifier_call = busfreq_reboot_notifier_event,
863 };
864
865
866 static DEVICE_ATTR(enable, 0644, bus_freq_scaling_enable_show,
867                         bus_freq_scaling_enable_store);
868
869 /*!
870  * This is the probe routine for the bus frequency driver.
871  *
872  * @param   pdev   The platform device structure
873  *
874  * @return         The function returns 0 on success
875  *
876  */
877
878 static int busfreq_probe(struct platform_device *pdev)
879 {
880         u32 err;
881
882         busfreq_dev = &pdev->dev;
883
884         /* Return if no IRAM space is allocated for ddr freq change code. */
885         if (!ddr_freq_change_iram_base)
886                 return ENOMEM;
887
888         pll2_400 = devm_clk_get(&pdev->dev, "pll2_pfd2_396m");
889         if (IS_ERR(pll2_400)) {
890                 dev_err(busfreq_dev, "%s: failed to get pll2_pfd2_396m\n",
891                 __func__);
892                 return PTR_ERR(pll2_400);
893         }
894
895         pll2_200 = devm_clk_get(&pdev->dev, "pll2_198m");
896         if (IS_ERR(pll2_200)) {
897                 dev_err(busfreq_dev, "%s: failed to get pll2_198m\n",
898                         __func__);
899                 return PTR_ERR(pll2_200);
900         }
901
902         pll2_bus = devm_clk_get(&pdev->dev, "pll2_bus");
903         if (IS_ERR(pll2_bus)) {
904                 dev_err(busfreq_dev, "%s: failed to get pll2_bus\n",
905                         __func__);
906                 return PTR_ERR(pll2_bus);
907         }
908
909         cpu_clk = devm_clk_get(&pdev->dev, "arm");
910         if (IS_ERR(cpu_clk)) {
911                 dev_err(busfreq_dev, "%s: failed to get cpu_clk\n",
912                         __func__);
913                 return PTR_ERR(cpu_clk);
914         }
915
916         pll3 = devm_clk_get(&pdev->dev, "pll3_usb_otg");
917         if (IS_ERR(pll3)) {
918                 dev_err(busfreq_dev, "%s: failed to get pll3_usb_otg\n",
919                         __func__);
920                 return PTR_ERR(pll3);
921         }
922
923         periph_clk = devm_clk_get(&pdev->dev, "periph");
924         if (IS_ERR(periph_clk)) {
925                 dev_err(busfreq_dev, "%s: failed to get periph\n",
926                         __func__);
927                 return PTR_ERR(periph_clk);
928         }
929
930         periph_pre_clk = devm_clk_get(&pdev->dev, "periph_pre");
931         if (IS_ERR(periph_pre_clk)) {
932                 dev_err(busfreq_dev, "%s: failed to get periph_pre\n",
933                         __func__);
934                 return PTR_ERR(periph_pre_clk);
935         }
936
937         periph_clk2 = devm_clk_get(&pdev->dev, "periph_clk2");
938         if (IS_ERR(periph_clk2)) {
939                 dev_err(busfreq_dev, "%s: failed to get periph_clk2\n",
940                         __func__);
941                 return PTR_ERR(periph_clk2);
942         }
943
944         periph_clk2_sel = devm_clk_get(&pdev->dev, "periph_clk2_sel");
945         if (IS_ERR(periph_clk2_sel)) {
946                 dev_err(busfreq_dev, "%s: failed to get periph_clk2_sel\n",
947                         __func__);
948                 return PTR_ERR(periph_clk2_sel);
949         }
950
951         osc_clk = devm_clk_get(&pdev->dev, "osc");
952         if (IS_ERR(osc_clk)) {
953                 dev_err(busfreq_dev, "%s: failed to get osc_clk\n",
954                         __func__);
955                 return PTR_ERR(osc_clk);
956         }
957
958         if (cpu_is_imx6dl()) {
959                 axi_alt_sel_clk = devm_clk_get(&pdev->dev, "axi_alt_sel");
960                 if (IS_ERR(axi_alt_sel_clk)) {
961                         dev_err(busfreq_dev, "%s: failed to get axi_alt_sel_clk\n",
962                                 __func__);
963                         return PTR_ERR(axi_alt_sel_clk);
964                 }
965
966                 axi_sel_clk = devm_clk_get(&pdev->dev, "axi_sel");
967                 if (IS_ERR(axi_sel_clk)) {
968                         dev_err(busfreq_dev, "%s: failed to get axi_sel_clk\n",
969                                 __func__);
970                         return PTR_ERR(axi_sel_clk);
971                 }
972
973                 pll3_pfd1_540m = devm_clk_get(&pdev->dev, "pll3_pfd1_540m");
974                 if (IS_ERR(pll3_pfd1_540m)) {
975                         dev_err(busfreq_dev,
976                                 "%s: failed to get pll3_pfd1_540m\n", __func__);
977                         return PTR_ERR(pll3_pfd1_540m);
978                 }
979         }
980
981         if (cpu_is_imx6sl() || cpu_is_imx6sx()) {
982                 ahb_clk = devm_clk_get(&pdev->dev, "ahb");
983                 if (IS_ERR(ahb_clk)) {
984                         dev_err(busfreq_dev, "%s: failed to get ahb_clk\n",
985                                 __func__);
986                         return PTR_ERR(ahb_clk);
987                 }
988
989                 ocram_clk = devm_clk_get(&pdev->dev, "ocram");
990                 if (IS_ERR(ocram_clk)) {
991                         dev_err(busfreq_dev, "%s: failed to get ocram_clk\n",
992                                 __func__);
993                         return PTR_ERR(ocram_clk);
994                 }
995
996                 periph2_clk = devm_clk_get(&pdev->dev, "periph2");
997                 if (IS_ERR(periph2_clk)) {
998                         dev_err(busfreq_dev, "%s: failed to get periph2\n",
999                                 __func__);
1000                         return PTR_ERR(periph2_clk);
1001                 }
1002
1003                 periph2_pre_clk = devm_clk_get(&pdev->dev, "periph2_pre");
1004                 if (IS_ERR(periph2_pre_clk)) {
1005                         dev_err(busfreq_dev,
1006                                 "%s: failed to get periph2_pre_clk\n",
1007                                 __func__);
1008                         return PTR_ERR(periph2_pre_clk);
1009                 }
1010
1011                 periph2_clk2 = devm_clk_get(&pdev->dev, "periph2_clk2");
1012                 if (IS_ERR(periph2_clk2)) {
1013                         dev_err(busfreq_dev,
1014                                 "%s: failed to get periph2_clk2\n",
1015                                 __func__);
1016                         return PTR_ERR(periph2_clk2);
1017                 }
1018
1019                 periph2_clk2_sel = devm_clk_get(&pdev->dev, "periph2_clk2_sel");
1020                 if (IS_ERR(periph2_clk2_sel)) {
1021                         dev_err(busfreq_dev,
1022                                 "%s: failed to get periph2_clk2_sel\n",
1023                                 __func__);
1024                         return PTR_ERR(periph2_clk2_sel);
1025                 }
1026
1027                 step_clk = devm_clk_get(&pdev->dev, "step");
1028                 if (IS_ERR(step_clk)) {
1029                         dev_err(busfreq_dev,
1030                                 "%s: failed to get step_clk\n",
1031                                 __func__);
1032                         return PTR_ERR(step_clk);
1033                 }
1034         }
1035         if (cpu_is_imx6sl()) {
1036                 pll1 = devm_clk_get(&pdev->dev, "pll1");
1037                 if (IS_ERR(pll1)) {
1038                         dev_err(busfreq_dev, "%s: failed to get pll1\n",
1039                                 __func__);
1040                         return PTR_ERR(pll1);
1041                 }
1042
1043                 pll1_bypass = devm_clk_get(&pdev->dev, "pll1_bypass");
1044                 if (IS_ERR(pll1_bypass)) {
1045                         dev_err(busfreq_dev, "%s: failed to get pll1_bypass\n",
1046                                 __func__);
1047                         return PTR_ERR(pll1_bypass);
1048                 }
1049
1050                 pll1_bypass_src = devm_clk_get(&pdev->dev, "pll1_bypass_src");
1051                 if (IS_ERR(pll1_bypass_src)) {
1052                         dev_err(busfreq_dev, "%s: failed to get pll1_bypass_src\n",
1053                                 __func__);
1054                         return PTR_ERR(pll1_bypass_src);
1055                 }
1056
1057                 pll1_sys = devm_clk_get(&pdev->dev, "pll1_sys");
1058                 if (IS_ERR(pll1_sys)) {
1059                         dev_err(busfreq_dev, "%s: failed to get pll1_sys\n",
1060                                 __func__);
1061                         return PTR_ERR(pll1_sys);
1062                 }
1063
1064                 pll1_sw_clk = devm_clk_get(&pdev->dev, "pll1_sw");
1065                 if (IS_ERR(pll1_sw_clk)) {
1066                         dev_err(busfreq_dev, "%s: failed to get pll1_sw_clk\n",
1067                                 __func__);
1068                         return PTR_ERR(pll1_sw_clk);
1069                 }
1070
1071                 pll2_bypass_src = devm_clk_get(&pdev->dev, "pll2_bypass_src");
1072                 if (IS_ERR(pll2_bypass_src)) {
1073                         dev_err(busfreq_dev, "%s: failed to get pll2_bypass_src\n",
1074                                 __func__);
1075                         return PTR_ERR(pll2_bypass_src);
1076                 }
1077
1078                 pll2 = devm_clk_get(&pdev->dev, "pll2");
1079                 if (IS_ERR(pll2)) {
1080                         dev_err(busfreq_dev, "%s: failed to get pll2\n",
1081                                 __func__);
1082                         return PTR_ERR(pll2);
1083                 }
1084
1085                 pll2_bypass = devm_clk_get(&pdev->dev, "pll2_bypass");
1086                 if (IS_ERR(pll2_bypass)) {
1087                         dev_err(busfreq_dev, "%s: failed to get pll2_bypass\n",
1088                                 __func__);
1089                         return PTR_ERR(pll2_bypass);
1090                 }
1091         }
1092         if (cpu_is_imx6sx()) {
1093                 mmdc_clk = devm_clk_get(&pdev->dev, "mmdc");
1094                 if (IS_ERR(mmdc_clk)) {
1095                         dev_err(busfreq_dev,
1096                                 "%s: failed to get mmdc_clk\n",
1097                                 __func__);
1098                         return PTR_ERR(mmdc_clk);
1099                 }
1100                 m4_clk = devm_clk_get(&pdev->dev, "m4");
1101                 if (IS_ERR(m4_clk)) {
1102                         dev_err(busfreq_dev,
1103                                 "%s: failed to get m4_clk\n",
1104                                 __func__);
1105                         return PTR_ERR(m4_clk);
1106                 }
1107         }
1108
1109         err = sysfs_create_file(&busfreq_dev->kobj, &dev_attr_enable.attr);
1110         if (err) {
1111                 dev_err(busfreq_dev,
1112                        "Unable to register sysdev entry for BUSFREQ");
1113                 return err;
1114         }
1115
1116         if (of_property_read_u32(pdev->dev.of_node, "fsl,max_ddr_freq",
1117                         &ddr_normal_rate)) {
1118                 dev_err(busfreq_dev, "max_ddr_freq entry missing\n");
1119                 return -EINVAL;
1120         }
1121
1122         high_bus_freq_mode = 1;
1123         med_bus_freq_mode = 0;
1124         low_bus_freq_mode = 0;
1125         audio_bus_freq_mode = 0;
1126         ultra_low_bus_freq_mode = 0;
1127
1128         bus_freq_scaling_is_active = 1;
1129         bus_freq_scaling_initialized = 1;
1130
1131         ddr_low_rate = LPAPM_CLK;
1132         if (cpu_is_imx6q()) {
1133                 if (of_property_read_u32(pdev->dev.of_node, "fsl,med_ddr_freq",
1134                                 &ddr_med_rate)) {
1135                         dev_info(busfreq_dev,
1136                                         "DDR medium rate not supported.\n");
1137                         ddr_med_rate = ddr_normal_rate;
1138                 }
1139         }
1140
1141         INIT_DELAYED_WORK(&low_bus_freq_handler, reduce_bus_freq_handler);
1142         INIT_DELAYED_WORK(&bus_freq_daemon, bus_freq_daemon_handler);
1143         register_pm_notifier(&imx_bus_freq_pm_notifier);
1144         register_reboot_notifier(&imx_busfreq_reboot_notifier);
1145
1146         /*
1147          * Need to make sure to an entry for the ddr freq change code address in the IRAM page table.
1148          * This is only required if the DDR freq code and suspend/idle code are in different OCRAM spaces.
1149          */
1150         if ((iram_tlb_phys_addr & 0xFFF00000) != (ddr_freq_change_iram_phys & 0xFFF00000)) {
1151                 unsigned long i;
1152
1153                 /*
1154                  * Make sure the ddr_iram virtual address has a mapping
1155                  * in the IRAM page table.
1156                  */
1157                 i = ((IMX_IO_P2V(ddr_freq_change_iram_phys) >> 20) << 2) / 4;
1158                 *((unsigned long *)iram_tlb_base_addr + i) =
1159                         (ddr_freq_change_iram_phys  & 0xFFF00000) | TT_ATTRIB_NON_CACHEABLE_1M;
1160         }
1161
1162         if (cpu_is_imx6sl()) {
1163                 err = init_mmdc_lpddr2_settings(pdev);
1164         } else if (cpu_is_imx6sx()) {
1165                 ddr_type = imx_mmdc_get_ddr_type();
1166                 /* check whether it is a DDR3 or LPDDR2 board */
1167                 if (ddr_type == MMDC_MDMISC_DDR_TYPE_DDR3)
1168                         err = init_mmdc_ddr3_settings_imx6sx(pdev);
1169                 else if (ddr_type == MMDC_MDMISC_DDR_TYPE_LPDDR2)
1170                         err = init_mmdc_lpddr2_settings(pdev);
1171                 /* if M4 is enabled and rate > 24MHz, add high bus count */
1172                 if (imx_src_is_m4_enabled() &&
1173                         (clk_get_rate(m4_clk) > LPAPM_CLK))
1174                         high_bus_count++;
1175         } else {
1176                 err = init_mmdc_ddr3_settings_imx6q(pdev);
1177         }
1178
1179         if (err) {
1180                 dev_err(busfreq_dev, "Busfreq init of MMDC failed\n");
1181                 return err;
1182         }
1183         return 0;
1184 }
1185
1186 static const struct of_device_id imx6_busfreq_ids[] = {
1187         { .compatible = "fsl,imx6_busfreq", },
1188         { /* sentinel */ }
1189 };
1190
1191 static struct platform_driver busfreq_driver = {
1192         .driver = {
1193                 .name = "imx6_busfreq",
1194                 .owner  = THIS_MODULE,
1195                 .of_match_table = imx6_busfreq_ids,
1196                 },
1197         .probe = busfreq_probe,
1198 };
1199
1200 /*!
1201  * Initialise the busfreq_driver.
1202  *
1203  * @return  The function always returns 0.
1204  */
1205
1206 static int __init busfreq_init(void)
1207 {
1208 #ifndef CONFIG_MX6_VPU_352M
1209         if (platform_driver_register(&busfreq_driver) != 0)
1210                 return -ENODEV;
1211
1212         printk(KERN_INFO "Bus freq driver module loaded\n");
1213 #endif
1214         return 0;
1215 }
1216
1217 static void __exit busfreq_cleanup(void)
1218 {
1219         sysfs_remove_file(&busfreq_dev->kobj, &dev_attr_enable.attr);
1220
1221         /* Unregister the device structure */
1222         platform_driver_unregister(&busfreq_driver);
1223         bus_freq_scaling_initialized = 0;
1224 }
1225
1226 module_init(busfreq_init);
1227 module_exit(busfreq_cleanup);
1228
1229 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
1230 MODULE_DESCRIPTION("BusFreq driver");
1231 MODULE_LICENSE("GPL");