2 * Copyright (C) 2011 MediaTek, Inc.
4 * Author: Holmes Chiou <holmes.chiou@mediatek.com>
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/sched.h>
19 #include <linux/kthread.h>
20 #include <linux/delay.h>
21 #include <linux/uaccess.h>
23 #include <linux/platform_device.h>
24 #include <linux/miscdevice.h>
25 //#include <asm/sched_clock.h>
26 #include <linux/vmalloc.h>
27 #include <linux/dma-mapping.h>
28 #include <board-custom.h>
29 #include <linux/seq_file.h>
31 #include "mach/mt_fhreg.h"
33 #include <linux/xlog.h> //ccyeh: for 6572
35 #if 0 //ccyeh: we don't need these header files here.
36 #include "mach/mt_clkmgr.h"
37 #include "mach/mt_typedefs.h"
38 #include "mach/mt_gpio.h"
39 #include "mach/mt_gpufreq.h"
40 #include "mach/mt_cpufreq.h"
41 #include "mach/emi_bwl.h"
42 #include "mach/sync_write.h"
43 #include "mach/mt_sleep.h"
46 #include <mach/mt_freqhopping_drv.h>
49 #define FREQ_HOPPING_DEVICE "mt-freqhopping"
51 #define FH_PLL_COUNT (g_p_fh_hal_drv->pll_cnt)
53 //static unsigned int g_resume_mempll_ssc=false;
54 static struct mt_fh_hal_driver
*g_p_fh_hal_drv
;
56 static fh_pll_t
*g_fh_drv_pll
;
57 static struct freqhopping_ssc
*g_fh_drv_usr_def
;
58 static unsigned int g_drv_pll_count
;
60 static struct miscdevice mt_fh_device
= {
61 .minor
= MISC_DYNAMIC_MINOR
,
62 .name
= "mtfreqhopping",
63 //.fops = &mt_fh_fops, //TODO: Interface for UI maybe in the future...
67 static int mt_freqhopping_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
);
69 static int mt_fh_drv_probe(struct platform_device
*dev
)
73 FH_MSG("EN: mt_fh_probe()");
75 if ((err
= misc_register(&mt_fh_device
)))
76 FH_MSG("register fh driver error!");
81 static int mt_fh_drv_remove(struct platform_device
*dev
)
85 if ((err
= misc_deregister(&mt_fh_device
)))
86 FH_MSG("deregister fh driver error!");
91 static void mt_fh_drv_shutdown(struct platform_device
*dev
)
93 FH_MSG("mt_fh_shutdown");
96 static int mt_fh_drv_suspend(struct platform_device
*dev
, pm_message_t state
)
98 // struct freqhopping_ioctl fh_ctl;
105 static int mt_fh_drv_resume(struct platform_device
*dev
)
107 // struct freqhopping_ioctl fh_ctl;
114 static struct platform_driver freqhopping_driver
= {
115 .probe
= mt_fh_drv_probe
,
116 .remove
= mt_fh_drv_remove
,
117 .shutdown
= mt_fh_drv_shutdown
,
118 .suspend
= mt_fh_drv_suspend
,
119 .resume
= mt_fh_drv_resume
,
121 .name
= FREQ_HOPPING_DEVICE
,
122 .owner
= THIS_MODULE
,
126 static int mt_fh_enable_usrdef(struct freqhopping_ioctl
* fh_ctl
)
128 unsigned long flags
= 0;
129 const unsigned int pll_id
= fh_ctl
->pll_id
;
131 FH_MSG("EN: %s",__func__
);
132 FH_MSG("pll_id: %d",fh_ctl
->pll_id
);
134 if (fh_ctl
->pll_id
< FH_PLL_COUNT
){
135 //we don't care the PLL status , we just change the flag & update the table
136 //the setting will be applied during the following FH enable
138 g_p_fh_hal_drv
->mt_fh_lock(&flags
);
139 memcpy(&g_fh_drv_usr_def
[pll_id
],&(fh_ctl
->ssc_setting
),sizeof(g_fh_drv_usr_def
[pll_id
]));
140 g_fh_drv_pll
[pll_id
].user_defined
= true;
141 g_p_fh_hal_drv
->mt_fh_unlock(&flags
);
150 static int mt_fh_disable_usrdef(struct freqhopping_ioctl
* fh_ctl
)
152 unsigned long flags
= 0;
153 const unsigned int pll_id
= fh_ctl
->pll_id
;
155 FH_MSG("EN: %s",__func__
);
156 FH_MSG("id: %d",fh_ctl
->pll_id
);
158 if (fh_ctl
->pll_id
< FH_PLL_COUNT
){
159 g_p_fh_hal_drv
->mt_fh_lock(&flags
);
160 memset(&g_fh_drv_usr_def
[pll_id
], 0,sizeof(g_fh_drv_usr_def
[pll_id
]));
161 g_fh_drv_pll
[pll_id
].user_defined
= false;
162 g_p_fh_hal_drv
->mt_fh_unlock(&flags
);
170 static int mt_fh_hal_ctrl_lock(struct freqhopping_ioctl
* fh_ctl
,bool enable
)
173 unsigned long flags
= 0;
175 FH_MSG("EN: _fctr_lck %d:%d",fh_ctl
->pll_id
,enable
);
177 g_p_fh_hal_drv
->mt_fh_lock(&flags
);
178 retVal
= g_p_fh_hal_drv
->mt_fh_hal_ctrl(fh_ctl
, enable
);
179 g_p_fh_hal_drv
->mt_fh_unlock(&flags
);
185 static int mt_freqhopping_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
187 //Get the structure of ioctl
190 struct freqhopping_ioctl
*freqhopping_ctl
= (struct freqhopping_ioctl
*)arg
;
192 FH_MSG("EN:CMD:%d pll id:%d",cmd
,freqhopping_ctl
->pll_id
);
194 if(FH_CMD_ENABLE
== cmd
) {
195 ret
= mt_fh_hal_ctrl_lock(freqhopping_ctl
,true);
196 }else if(FH_CMD_DISABLE
== cmd
) {
197 ret
= mt_fh_hal_ctrl_lock(freqhopping_ctl
,false);
199 else if(FH_CMD_ENABLE_USR_DEFINED
== cmd
) {
200 ret
= mt_fh_enable_usrdef(freqhopping_ctl
);
202 else if(FH_CMD_DISABLE_USR_DEFINED
== cmd
) {
203 ret
= mt_fh_disable_usrdef(freqhopping_ctl
);
205 //Invalid command is not acceptable!!
214 //static int freqhopping_userdefine_proc_read(char *page, char **start, off_t off, int count, int *eof, void *data)
215 static int freqhopping_userdefine_proc_read(struct seq_file
* m
, void* v
)
219 FH_MSG("EN: %s",__func__
);
221 seq_printf(m
, "user defined settings:\n");
223 seq_printf(m
, "===============================================\r\n" );
224 seq_printf(m
, " freq == delta t == delta f == up bond == low bond == dds ==\r\n" );
226 for(i
= 0;i
< g_drv_pll_count
; ++i
) {
227 seq_printf(m
, "%10d 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\r\n"
228 ,g_fh_drv_usr_def
[i
].freq
229 ,g_fh_drv_usr_def
[i
].dt
230 ,g_fh_drv_usr_def
[i
].df
231 ,g_fh_drv_usr_def
[i
].upbnd
232 ,g_fh_drv_usr_def
[i
].lowbnd
233 ,g_fh_drv_usr_def
[i
].dds
);
243 FH_MSG("EN: %s",__func__
);
245 p
+= sprintf(p
, "user defined settings:\n");
247 p
+= sprintf(p
, "===============================================\r\n" );
248 p
+= sprintf(p
, " freq == delta t == delta f == up bond == low bond == dds ==\r\n" );
250 for(i
=0;i
<g_drv_pll_count
;i
++) {
251 p
+= sprintf(p
, "%10d 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\r\n"
252 ,g_fh_drv_usr_def
[i
].freq
253 ,g_fh_drv_usr_def
[i
].dt
254 ,g_fh_drv_usr_def
[i
].df
255 ,g_fh_drv_usr_def
[i
].upbnd
256 ,g_fh_drv_usr_def
[i
].lowbnd
257 ,g_fh_drv_usr_def
[i
].dds
);
269 return len
< count
? len
: count
;
273 static ssize_t
freqhopping_userdefine_proc_write(struct file
*file
, const char *buffer
, size_t count
, loff_t
*data
)
278 unsigned int p1
,p2
,p3
,p4
,p5
,p6
,p7
;
279 struct freqhopping_ioctl fh_ctl
;
281 p1
= p2
= p3
= p4
= p5
= p6
= p7
= 0;
283 FH_MSG("EN: %s",__func__
);
285 len
= min(count
, (sizeof(kbuf
)-1));
287 if (count
== 0)return -1;
288 if(count
> 255)count
= 255;
290 ret
= copy_from_user(kbuf
, buffer
, count
);
291 if (ret
< 0)return -1;
295 sscanf(kbuf
, "%x %x %x %x %x %x %x", &p1
, &p2
, &p3
, &p4
, &p5
, &p6
, &p7
);
298 fh_ctl
.ssc_setting
.df
= p3
;
299 fh_ctl
.ssc_setting
.dt
= p4
;
300 fh_ctl
.ssc_setting
.upbnd
= p5
;
301 fh_ctl
.ssc_setting
.lowbnd
= p6
;
302 fh_ctl
.ssc_setting
.dds
= p7
;
303 fh_ctl
.ssc_setting
.freq
= 0;
305 /* Check validity of PLL ID */
306 if (fh_ctl
.pll_id
>= FH_PLL_COUNT
)
310 if( p1
== FH_CMD_ENABLE
){
311 ret
= mt_fh_enable_usrdef(&fh_ctl
);
313 FH_MSG("__EnableUsrSetting() fail!");
317 ret
= mt_fh_disable_usrdef(&fh_ctl
);
319 FH_MSG("__DisableUsrSetting() fail!");
323 FH_MSG("Exit: %s",__func__
);
327 //static int freqhopping_status_proc_read(char *page, char **start, off_t off, int count, int *eof, void *data)
328 static int freqhopping_status_proc_read(struct seq_file
* m
, void* v
)
332 FH_MSG("EN: %s",__func__
);
334 seq_printf(m
, "FH status:\r\n");
336 seq_printf(m
, "===============================================\r\n" );
337 seq_printf(m
, "id == fh_status == pll_status == setting_id == curr_freq == user_defined ==\r\n" );
340 for(i
= 0;i
< g_drv_pll_count
; ++i
) {
341 seq_printf(m
, "%2d %8d %8d",
343 g_fh_drv_pll
[i
].fh_status
,
344 g_fh_drv_pll
[i
].pll_status
);
345 seq_printf(m
, " %8d %8d ",
346 g_fh_drv_pll
[i
].setting_id
,
347 g_fh_drv_pll
[i
].curr_freq
);
349 seq_printf(m
, " %d\r\n",
350 g_fh_drv_pll
[i
].user_defined
);
352 seq_printf(m
, "\r\n");
361 FH_MSG("EN: %s",__func__
);
363 p
+= sprintf(p
, "FH status:\r\n");
365 p
+= sprintf(p
, "===============================================\r\n" );
366 p
+= sprintf(p
, "id == fh_status == pll_status == setting_id == curr_freq == user_defined ==\r\n" );
369 for(i
=0;i
<g_drv_pll_count
;i
++) {
370 p
+= sprintf(p
, "%2d %8d %8d",
372 g_fh_drv_pll
[i
].fh_status
,
373 g_fh_drv_pll
[i
].pll_status
);
374 p
+= sprintf(p
, " %8d %8d ",
375 g_fh_drv_pll
[i
].setting_id
,
376 g_fh_drv_pll
[i
].curr_freq
);
378 p
+= sprintf(p
, " %d\r\n",
379 g_fh_drv_pll
[i
].user_defined
);
382 p
+= sprintf(p
, "\r\nPLL status:\r\n");
383 for(i
=0;i
<g_drv_pll_count
;i
++) {
384 p
+= sprintf(p
, "%d ",pll_is_on(i
));
387 p
+= sprintf(p
, "\r\n");
389 //TODO: unsigned int mt_get_cpu_freq(void)
401 return len
< count
? len
: count
;
405 static ssize_t
freqhopping_status_proc_write(struct file
*file
, const char *buffer
, size_t count
, loff_t
*data
)
410 unsigned int p1
,p2
,p3
,p4
,p5
,p6
;
411 struct freqhopping_ioctl fh_ctl
;
413 p1
= p2
= p3
= p4
= p5
= p6
= 0;
415 FH_MSG("EN: %s",__func__
);
417 len
= min(count
, (sizeof(kbuf
)-1));
419 if (count
== 0)return -1;
420 if(count
> 255)count
= 255;
422 ret
= copy_from_user(kbuf
, buffer
, count
);
423 if (ret
< 0)return -1;
427 sscanf(kbuf
, "%x %x", &p1
, &p2
);
430 fh_ctl
.ssc_setting
.df
= 0;
431 fh_ctl
.ssc_setting
.dt
= 0;
432 fh_ctl
.ssc_setting
.upbnd
= 0;
433 fh_ctl
.ssc_setting
.lowbnd
= 0;
435 /* Check validity of PLL ID */
436 if (fh_ctl
.pll_id
>= FH_PLL_COUNT
)
440 mt_freqhopping_ioctl(NULL
,FH_CMD_DISABLE
,(unsigned long)(&fh_ctl
));
443 mt_freqhopping_ioctl(NULL
,FH_CMD_ENABLE
,(unsigned long)(&fh_ctl
));
449 //static int freqhopping_debug_proc_read(char *page, char **start, off_t off, int count, int *eof, void *data)
450 static int freqhopping_debug_proc_read(struct seq_file
* m
, void* v
)
452 #if defined(PLATFORM_DEP_DEBUG_PROC_READ)
453 FH_IO_PROC_READ_T arg
;
456 arg
.pll
= g_fh_drv_pll
;
457 //g_p_fh_hal_drv->ioctl(FH_IO_PROC_READ, &arg);
460 FH_MSG("EN: %s",__func__
);
462 seq_printf(m
, "\r\n[freqhopping debug flag]\r\n");
463 seq_printf(m
, "===============================================\r\n" );
464 seq_printf(m
, "id==ARMPLL==MAINPLL==MEMPLL==MSDCPLL==MMPLL==VENCPLL\r\n" );
465 seq_printf(m
, " == %04d====%04d====%04d====%04d====%04d====%04d=\r\n" ,
466 g_fh_drv_pll
[MT658X_FH_ARM_PLL
].fh_status
, g_fh_drv_pll
[MT658X_FH_MAIN_PLL
].fh_status
,
467 g_fh_drv_pll
[MT658X_FH_MEM_PLL
].fh_status
, g_fh_drv_pll
[MT658X_FH_MSDC_PLL
].fh_status
,
468 g_fh_drv_pll
[MT658X_FH_MM_PLL
].fh_status
, g_fh_drv_pll
[MT658X_FH_VENC_PLL
].fh_status
);
469 seq_printf(m
, " == %04d====%04d====%04d====%04d====%04d====%04d=\r\n" ,
470 g_fh_drv_pll
[MT658X_FH_ARM_PLL
].setting_id
, g_fh_drv_pll
[MT658X_FH_MAIN_PLL
].setting_id
,
471 g_fh_drv_pll
[MT658X_FH_MEM_PLL
].setting_id
, g_fh_drv_pll
[MT658X_FH_MSDC_PLL
].setting_id
,
472 g_fh_drv_pll
[MT658X_FH_MM_PLL
].setting_id
, g_fh_drv_pll
[MT658X_FH_VENC_PLL
].setting_id
);
478 FH_MSG("EN: %s",__func__
);
480 p
+= sprintf(p
, "\r\n[freqhopping debug flag]\r\n");
481 p
+= sprintf(p
, "===============================================\r\n" );
482 p
+= sprintf(p
, "id==ARMPLL==MAINPLL==MEMPLL==MSDCPLL==MMPLL==VENCPLL\r\n" );
483 p
+= sprintf(p
, " == %04d====%04d====%04d====%04d====%04d====%04d=\r\n" ,
484 g_fh_drv_pll
[MT658X_FH_ARM_PLL
].fh_status
, g_fh_drv_pll
[MT658X_FH_MAIN_PLL
].fh_status
,
485 g_fh_drv_pll
[MT658X_FH_MEM_PLL
].fh_status
, g_fh_drv_pll
[MT658X_FH_MSDC_PLL
].fh_status
,
486 g_fh_drv_pll
[MT658X_FH_MM_PLL
].fh_status
, g_fh_drv_pll
[MT658X_FH_VENC_PLL
].fh_status
);
487 p
+= sprintf(p
, " == %04d====%04d====%04d====%04d====%04d====%04d=\r\n" ,
488 g_fh_drv_pll
[MT658X_FH_ARM_PLL
].setting_id
, g_fh_drv_pll
[MT658X_FH_MAIN_PLL
].setting_id
,
489 g_fh_drv_pll
[MT658X_FH_MEM_PLL
].setting_id
, g_fh_drv_pll
[MT658X_FH_MSDC_PLL
].setting_id
,
490 g_fh_drv_pll
[MT658X_FH_MM_PLL
].setting_id
, g_fh_drv_pll
[MT658X_FH_VENC_PLL
].setting_id
);
501 return len
< count
? len
: count
;
506 static ssize_t
freqhopping_debug_proc_write(struct file
*file
, const char *buffer
, size_t count
, loff_t
*data
)
511 unsigned int cmd
,p1
,p2
,p3
,p4
,p5
,p6
,p7
;
512 struct freqhopping_ioctl fh_ctl
;
514 p1
= p2
= p3
= p4
= p5
= p6
= p7
= 0;
516 FH_MSG("EN: %s",__func__
);
518 len
= min(count
, (sizeof(kbuf
)-1));
520 if (count
== 0)return -1;
521 if(count
> 255)count
= 255;
523 ret
= copy_from_user(kbuf
, buffer
, count
);
524 if (ret
< 0)return -1;
528 sscanf(kbuf
, "%x %x %x %x %x %x %x %x", &cmd
, &p1
, &p2
, &p3
, &p4
, &p5
, &p6
, &p7
);
530 //ccyeh fh_ctl.opcode = p1;
532 //ccyeh removed fh_ctl.ssc_setting_id = p3;
533 fh_ctl
.ssc_setting
.dds
= p3
;
534 fh_ctl
.ssc_setting
.df
= p4
;
535 fh_ctl
.ssc_setting
.dt
= p5
;
536 fh_ctl
.ssc_setting
.upbnd
= p6
;
537 fh_ctl
.ssc_setting
.lowbnd
= p7
;
538 fh_ctl
.ssc_setting
.freq
= 0;
540 /* Check validity of PLL ID */
541 if (fh_ctl
.pll_id
>= FH_PLL_COUNT
)
545 if (cmd
< FH_CMD_INTERNAL_MAX_CMD
) {
546 mt_freqhopping_ioctl(NULL
,cmd
,(unsigned long)(&fh_ctl
));
548 else if((cmd
> FH_DCTL_CMD_ID
) && (cmd
< FH_DCTL_CMD_MAX
))
550 mt_freqhopping_devctl(cmd
, &fh_ctl
);
553 FH_MSG("CMD error!");
559 static int freqhopping_debug_proc_open(struct inode
*inode
, struct file
*file
)
561 return single_open(file
, freqhopping_debug_proc_read
, NULL
);
564 static int freqhopping_dramc_proc_open(struct inode
*inode
, struct file
*file
)
566 return single_open(file
, g_p_fh_hal_drv
->proc
.dramc_read
, NULL
);
568 static ssize_t
freqhopping_dramc_proc_write(struct file
*file
, const char *buffer
, size_t count
, loff_t
*data
)
570 return (ssize_t
)(g_p_fh_hal_drv
->proc
.dramc_write(file
, buffer
, count
, data
));
573 static int freqhopping_dvfs_proc_open(struct inode
*inode
, struct file
*file
)
575 return single_open(file
, g_p_fh_hal_drv
->proc
.dvfs_read
, NULL
);
577 static ssize_t
freqhopping_dvfs_proc_write(struct file
*file
, const char *buffer
, size_t count
, loff_t
*data
)
579 return (ssize_t
)(g_p_fh_hal_drv
->proc
.dvfs_write(file
, buffer
, count
, data
));
582 static int freqhopping_dumpregs_proc_open(struct inode
*inode
, struct file
*file
)
584 return single_open(file
, g_p_fh_hal_drv
->proc
.dumpregs_read
, NULL
);
587 static int freqhopping_status_proc_open(struct inode
*inode
, struct file
*file
)
589 return single_open(file
, freqhopping_status_proc_read
, NULL
);
591 static int freqhopping_userdefine_proc_open(struct inode
*inode
, struct file
*file
)
593 return single_open(file
, freqhopping_userdefine_proc_read
, NULL
);
596 static const struct file_operations freqhopping_debug_fops
= {
597 .owner
= THIS_MODULE
,
598 .open
= freqhopping_debug_proc_open
,
600 .write
= freqhopping_debug_proc_write
,
602 static const struct file_operations dramc_fops
= {
603 .owner
= THIS_MODULE
,
604 .open
= freqhopping_dramc_proc_open
,
606 .write
= freqhopping_dramc_proc_write
,
608 static const struct file_operations dvfs_fops
= {
609 .owner
= THIS_MODULE
,
610 .open
= freqhopping_dvfs_proc_open
,
612 .write
= freqhopping_dvfs_proc_write
,
614 static const struct file_operations dumpregs_fops
= {
615 .owner
= THIS_MODULE
,
616 .open
= freqhopping_dumpregs_proc_open
,
619 static const struct file_operations status_fops
= {
620 .owner
= THIS_MODULE
,
621 .open
= freqhopping_status_proc_open
,
623 .write
= freqhopping_status_proc_write
,
625 static const struct file_operations userdef_fops
= {
626 .owner
= THIS_MODULE
,
627 .open
= freqhopping_userdefine_proc_open
,
629 .write
= freqhopping_userdefine_proc_write
,
632 static int freqhopping_debug_proc_init(void)
634 struct proc_dir_entry
*prDebugEntry
;
635 struct proc_dir_entry
*prDramcEntry
;
636 struct proc_dir_entry
*prDumpregEntry
;
637 struct proc_dir_entry
*prStatusEntry
;
638 struct proc_dir_entry
*prUserdefEntry
;
639 struct proc_dir_entry
*fh_proc_dir
= NULL
;
641 //TODO: check the permission!!
643 FH_MSG("EN: %s",__func__
);
645 fh_proc_dir
= proc_mkdir("freqhopping", NULL
);
647 FH_MSG("proc_mkdir fail!");
653 /* /proc/freqhopping/freqhopping_debug */
654 //prDebugEntry = create_proc_entry("freqhopping_debug", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir);
655 prDebugEntry
= proc_create("freqhopping_debug", S_IRUGO
| S_IWUSR
| S_IWGRP
, fh_proc_dir
, &freqhopping_debug_fops
);
658 //prDebugEntry->read_proc = freqhopping_debug_proc_read;
659 //prDebugEntry->write_proc = freqhopping_debug_proc_write;
660 FH_MSG("[%s]: successfully create /proc/freqhopping_debug", __func__
);
662 FH_MSG("[%s]: failed to create /proc/freqhopping/freqhopping_debug", __func__
);
667 /* /proc/freqhopping/dramc */
668 //prDramcEntry = create_proc_entry("dramc", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir);
669 prDramcEntry
= proc_create("dramc", S_IRUGO
| S_IWUSR
| S_IWGRP
, fh_proc_dir
, &dramc_fops
);
672 //prDramcEntry->read_proc = g_p_fh_hal_drv->proc.dramc_read;
673 //prDramcEntry->write_proc = g_p_fh_hal_drv->proc.dramc_write;
674 FH_MSG("[%s]: successfully create /proc/freqhopping/prDramcEntry", __func__
);
676 FH_MSG("[%s]: failed to create /proc/freqhopping/prDramcEntry", __func__
);
679 /* /proc/freqhopping/dvfs */
680 //prDramcEntry = create_proc_entry("dvfs", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir);
681 prDramcEntry
= proc_create("dvfs", S_IRUGO
| S_IWUSR
| S_IWGRP
, fh_proc_dir
, &dvfs_fops
);
684 //prDramcEntry->read_proc = g_p_fh_hal_drv->proc.dvfs_read;
685 //prDramcEntry->write_proc = g_p_fh_hal_drv->proc.dvfs_write;
686 FH_MSG("[%s]: successfully create /proc/freqhopping/dvfs", __func__
);
688 FH_MSG("[%s]: failed to create /proc/freqhopping/dvfs", __func__
);
693 /* /proc/freqhopping/dumpregs */
694 //prDumpregEntry = create_proc_entry("dumpregs", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir);
695 prDumpregEntry
= proc_create("dumpregs", S_IRUGO
| S_IWUSR
| S_IWGRP
, fh_proc_dir
, &dumpregs_fops
);
698 //prDumpregEntry->read_proc = g_p_fh_hal_drv->proc.dumpregs_read;
699 //prDumpregEntry->write_proc = NULL;
700 FH_MSG("[%s]: successfully create /proc/freqhopping/dumpregs", __func__
);
702 FH_MSG("[%s]: failed to create /proc/freqhopping/dumpregs", __func__
);
707 /* /proc/freqhopping/status */
708 //prStatusEntry = create_proc_entry("status", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir);
709 prStatusEntry
= proc_create("status", S_IRUGO
| S_IWUSR
| S_IWGRP
, fh_proc_dir
, &status_fops
);
712 //prStatusEntry->read_proc = freqhopping_status_proc_read;
713 //prStatusEntry->write_proc = freqhopping_status_proc_write;
714 FH_MSG("[%s]: successfully create /proc/freqhopping/status", __func__
);
716 FH_MSG("[%s]: failed to create /proc/freqhopping/status", __func__
);
721 /* /proc/freqhopping/userdefine */
722 //prUserdefEntry = create_proc_entry("userdef", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir);
723 prUserdefEntry
= proc_create("userdef", S_IRUGO
| S_IWUSR
| S_IWGRP
, fh_proc_dir
, &userdef_fops
);
726 //prUserdefEntry->read_proc = freqhopping_userdefine_proc_read;
727 //prUserdefEntry->write_proc = freqhopping_userdefine_proc_write;
728 FH_MSG("[%s]: successfully create /proc/freqhopping/userdef", __func__
);
730 FH_MSG("[%s]: failed to create /proc/freqhopping/userdef", __func__
);
734 #if 0// MT_FH_CLK_GEN
735 /* /proc/freqhopping/clkgen */
736 prUserdefEntry
= create_proc_entry("clkgen", S_IRUGO
| S_IWUSR
| S_IWGRP
, fh_proc_dir
);
739 prUserdefEntry
->read_proc
= g_p_fh_hal_drv
->proc
.clk_gen_read
;
740 prUserdefEntry
->write_proc
= g_p_fh_hal_drv
->proc
.clk_gen_write
;
741 FH_MSG("[%s]: successfully create /proc/freqhopping/clkgen", __func__
);
743 FH_MSG("[%s]: failed to create /proc/freqhopping/clkgen", __func__
);
746 #endif //MT_FH_CLK_GEN
752 #if defined(DISABLE_FREQ_HOPPING)
753 void mt_fh_popod_save(void){}
754 EXPORT_SYMBOL(mt_fh_popod_save
);
756 void mt_fh_popod_restore(void){}
757 EXPORT_SYMBOL(mt_fh_popod_restore
);
759 int freqhopping_config(unsigned int pll_id
, unsigned long vco_freq
, unsigned int enable
){return 0;}
760 EXPORT_SYMBOL(freqhopping_config
);
762 int mt_l2h_mempll(void){return 0;}
763 EXPORT_SYMBOL(mt_l2h_mempll
);
765 int mt_h2l_mempll(void){return 0;}
766 EXPORT_SYMBOL(mt_h2l_mempll
);
768 int mt_dfs_armpll(unsigned int current_freq
, unsigned int target_dds
){return 0;}
769 EXPORT_SYMBOL(mt_dfs_armpll
);
771 int mt_dfs_mmpll(unsigned int target_dds
){ return 0;}
772 EXPORT_SYMBOL(mt_dfs_mmpll
);
774 int mt_dfs_vencpll(unsigned int target_dds
){return 0;}
775 EXPORT_SYMBOL(mt_dfs_vencpll
);
777 int mt_dfs_mpll(unsigned int target_dds
){return 0;}
778 EXPORT_SYMBOL(mt_dfs_mpll
);
780 int mt_is_support_DFS_mode(void){return 0;}
781 EXPORT_SYMBOL(mt_is_support_DFS_mode
);
783 int mt_l2h_dvfs_mempll(void){return 0;}
784 EXPORT_SYMBOL(mt_l2h_dvfs_mempll
);
786 int mt_h2l_dvfs_mempll(void){return 0;}
787 EXPORT_SYMBOL(mt_h2l_dvfs_mempll
);
789 int mt_fh_dram_overclock(int clk
){return 0;}
790 EXPORT_SYMBOL(mt_fh_dram_overclock
);
792 int mt_fh_get_dramc(void){return 0;}
793 EXPORT_SYMBOL(mt_fh_get_dramc
);
795 void mt_freqhopping_init(void){}
796 EXPORT_SYMBOL(mt_freqhopping_init
);
798 void mt_freqhopping_pll_init(void){}
799 EXPORT_SYMBOL(mt_freqhopping_pll_init
);
801 int mt_freqhopping_devctl(unsigned int cmd
, void* args
){return 0;}
802 EXPORT_SYMBOL(mt_freqhopping_devctl
);
805 void mt_fh_popod_save(void)
809 FH_MSG("[%s]: g_p_fh_hal_drv is uninitialized.", __func__
);
812 FH_MSG("EN: %s",__func__
);
814 g_p_fh_hal_drv
->mt_fh_popod_save();
816 EXPORT_SYMBOL(mt_fh_popod_save
);
818 void mt_fh_popod_restore(void)
822 FH_MSG("[%s]: g_p_fh_hal_drv is uninitialized.", __func__
);
826 FH_MSG("EN: %s",__func__
);
828 g_p_fh_hal_drv
->mt_fh_popod_restore();
830 EXPORT_SYMBOL(mt_fh_popod_restore
);
832 int freqhopping_config(unsigned int pll_id
, unsigned long vco_freq
, unsigned int enable
)
834 struct freqhopping_ioctl fh_ctl
;
835 unsigned int fh_status
;
836 unsigned long flags
=0;
837 unsigned int skip_flag
=0;
839 FH_MSG("conf() id: %d f: %d, e: %d",(int)pll_id
, (int)vco_freq
, (int)enable
);
841 if( (g_p_fh_hal_drv
->mt_fh_get_init()) == 0){
842 FH_MSG("Not init yet, init first.");
846 g_p_fh_hal_drv
->mt_fh_lock(&flags
);
849 fh_status
= g_fh_drv_pll
[pll_id
].fh_status
;
851 g_fh_drv_pll
[pll_id
].curr_freq
= vco_freq
;
852 g_fh_drv_pll
[pll_id
].pll_status
= (enable
> 0) ? FH_PLL_ENABLE
:FH_PLL_DISABLE
;
855 //prepare freqhopping_ioctl
856 fh_ctl
.pll_id
= pll_id
;
858 if(g_fh_drv_pll
[pll_id
].fh_status
!= FH_FH_DISABLE
){
860 g_p_fh_hal_drv
->mt_fh_hal_ctrl(&fh_ctl
,enable
);
865 //FH_MSG("-fh,skip");
869 g_fh_drv_pll
[pll_id
].fh_status
= fh_status
;
871 g_p_fh_hal_drv
->mt_fh_unlock(&flags
);
878 EXPORT_SYMBOL(freqhopping_config
);
881 int mt_l2h_mempll(void)
883 return(g_p_fh_hal_drv
->mt_l2h_mempll());
885 EXPORT_SYMBOL(mt_l2h_mempll
);
887 int mt_h2l_mempll(void)
889 return(g_p_fh_hal_drv
->mt_h2l_mempll());
891 EXPORT_SYMBOL(mt_h2l_mempll
);
893 int mt_dfs_armpll(unsigned int current_freq
, unsigned int target_dds
)
897 FH_MSG("[%s]: g_p_fh_hal_drv is uninitialized.", __func__
);
901 return(g_p_fh_hal_drv
->mt_dfs_armpll(current_freq
, target_dds
));
903 EXPORT_SYMBOL(mt_dfs_armpll
);
904 int mt_dfs_mmpll(unsigned int target_dds
)
908 FH_MSG("[%s]: g_p_fh_hal_drv is uninitialized.", __func__
);
911 return(g_p_fh_hal_drv
->mt_dfs_mmpll(target_dds
));
913 EXPORT_SYMBOL(mt_dfs_mmpll
);
914 int mt_dfs_vencpll(unsigned int target_dds
)
918 FH_MSG("[%s]: g_p_fh_hal_drv is uninitialized.", __func__
);
922 return(g_p_fh_hal_drv
->mt_dfs_vencpll(target_dds
));
924 EXPORT_SYMBOL(mt_dfs_vencpll
);
926 int mt_dfs_mpll(unsigned int target_dds
)
928 if((!g_p_fh_hal_drv
) || (!g_p_fh_hal_drv
->mt_dfs_mpll
))
930 FH_MSG("[%s]: g_p_fh_hal_drv is uninitialized.", __func__
);
934 return(g_p_fh_hal_drv
->mt_dfs_mpll(target_dds
));
937 EXPORT_SYMBOL(mt_dfs_mpll
);
940 int mt_is_support_DFS_mode(void)
942 return(g_p_fh_hal_drv
->mt_is_support_DFS_mode());
944 EXPORT_SYMBOL(mt_is_support_DFS_mode
);
945 int mt_l2h_dvfs_mempll(void)
949 FH_MSG("[%s]: g_p_fh_hal_drv is uninitialized.", __func__
);
952 return(g_p_fh_hal_drv
->mt_l2h_dvfs_mempll());
954 EXPORT_SYMBOL(mt_l2h_dvfs_mempll
);
956 int mt_h2l_dvfs_mempll(void)
960 FH_MSG("[%s]: g_p_fh_hal_drv is uninitialized.", __func__
);
964 return(g_p_fh_hal_drv
->mt_h2l_dvfs_mempll());
966 EXPORT_SYMBOL(mt_h2l_dvfs_mempll
);
967 int mt_fh_dram_overclock(int clk
)
969 return (g_p_fh_hal_drv
->mt_dram_overclock(clk
));
971 EXPORT_SYMBOL(mt_fh_dram_overclock
);
973 int mt_fh_get_dramc(void)
975 return (g_p_fh_hal_drv
->mt_get_dramc());
977 EXPORT_SYMBOL(mt_fh_get_dramc
);
979 void mt_freqhopping_init(void)
981 g_p_fh_hal_drv
= mt_get_fh_hal_drv();
983 g_p_fh_hal_drv
->mt_fh_hal_init();
985 g_fh_drv_pll
= g_p_fh_hal_drv
->fh_pll
;
986 g_fh_drv_usr_def
= g_p_fh_hal_drv
->fh_usrdef
;
987 g_drv_pll_count
= g_p_fh_hal_drv
->pll_cnt
;
989 freqhopping_debug_proc_init();
990 platform_driver_register(&freqhopping_driver
);
992 mt_freqhopping_pll_init(); //TODO_HAL: wait for clkmgr to invoke this function
994 EXPORT_SYMBOL(mt_freqhopping_init
);
996 void mt_freqhopping_pll_init(void)
998 g_p_fh_hal_drv
->mt_fh_default_conf();
1000 EXPORT_SYMBOL(mt_freqhopping_pll_init
);
1002 int mt_freqhopping_devctl(unsigned int cmd
, void* args
)
1009 //g_p_fh_hal_drv->ioctl(cmd, args);
1013 EXPORT_SYMBOL(mt_freqhopping_devctl
);