mt_freqhopping_drv.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. /*
  2. * Copyright (C) 2011 MediaTek, Inc.
  3. *
  4. * Author: Holmes Chiou <holmes.chiou@mediatek.com>
  5. *
  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.
  9. *
  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.
  14. *
  15. */
  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>
  22. #include <linux/io.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/miscdevice.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/seq_file.h>
  28. #include "mach/mt_fhreg.h"
  29. #include "mt_freqhopping_drv.h"
  30. #define FREQ_HOPPING_DEVICE "mt-freqhopping"
  31. #define FH_PLL_COUNT (g_p_fh_hal_drv->pll_cnt)
  32. static struct mt_fh_hal_driver *g_p_fh_hal_drv;
  33. static fh_pll_t *g_fh_drv_pll;
  34. static struct freqhopping_ssc *g_fh_drv_usr_def;
  35. static unsigned int g_drv_pll_count;
  36. static int mt_freqhopping_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  37. #if !defined(DISABLE_FREQ_HOPPING)
  38. static struct miscdevice mt_fh_device = {
  39. .minor = MISC_DYNAMIC_MINOR,
  40. .name = "mtfreqhopping",
  41. /* .fops = &mt_fh_fops, //TODO: Interface for UI maybe in the future... */
  42. };
  43. static int mt_fh_drv_probe(struct platform_device *dev)
  44. {
  45. int err = 0;
  46. FH_MSG("EN: mt_fh_probe()");
  47. err = misc_register(&mt_fh_device);
  48. if (err)
  49. FH_MSG("register fh driver error!");
  50. return err;
  51. }
  52. static int mt_fh_drv_remove(struct platform_device *dev)
  53. {
  54. int err = 0;
  55. err = misc_deregister(&mt_fh_device);
  56. if (err)
  57. FH_MSG("deregister fh driver error!");
  58. return err;
  59. }
  60. static void mt_fh_drv_shutdown(struct platform_device *dev)
  61. {
  62. FH_MSG("mt_fh_shutdown");
  63. }
  64. static int mt_fh_drv_suspend(struct platform_device *dev, pm_message_t state)
  65. {
  66. /* struct freqhopping_ioctl fh_ctl; */
  67. FH_MSG("-supd-");
  68. return 0;
  69. }
  70. static int mt_fh_drv_resume(struct platform_device *dev)
  71. {
  72. /* struct freqhopping_ioctl fh_ctl; */
  73. FH_MSG("+resm+");
  74. return 0;
  75. }
  76. static struct platform_driver freqhopping_driver = {
  77. .probe = mt_fh_drv_probe,
  78. .remove = mt_fh_drv_remove,
  79. .shutdown = mt_fh_drv_shutdown,
  80. .suspend = mt_fh_drv_suspend,
  81. .resume = mt_fh_drv_resume,
  82. .driver = {
  83. .name = FREQ_HOPPING_DEVICE,
  84. .owner = THIS_MODULE,
  85. },
  86. };
  87. #endif
  88. static int mt_fh_enable_usrdef(struct freqhopping_ioctl *fh_ctl)
  89. {
  90. unsigned long flags = 0;
  91. const unsigned int pll_id = fh_ctl->pll_id;
  92. FH_MSG("EN: %s", __func__);
  93. FH_MSG("pll_id: %d", fh_ctl->pll_id);
  94. if (fh_ctl->pll_id < FH_PLL_COUNT) {
  95. /* we don't care the PLL status , we just change the flag & update the table */
  96. /* the setting will be applied during the following FH enable */
  97. g_p_fh_hal_drv->mt_fh_lock(&flags);
  98. memcpy(&g_fh_drv_usr_def[pll_id], &(fh_ctl->ssc_setting),
  99. sizeof(g_fh_drv_usr_def[pll_id]));
  100. g_fh_drv_pll[pll_id].user_defined = true;
  101. g_p_fh_hal_drv->mt_fh_unlock(&flags);
  102. }
  103. /* FH_MSG("Exit"); */
  104. return 0;
  105. }
  106. static int mt_fh_disable_usrdef(struct freqhopping_ioctl *fh_ctl)
  107. {
  108. unsigned long flags = 0;
  109. const unsigned int pll_id = fh_ctl->pll_id;
  110. FH_MSG("EN: %s", __func__);
  111. FH_MSG("id: %d", fh_ctl->pll_id);
  112. if (fh_ctl->pll_id < FH_PLL_COUNT) {
  113. g_p_fh_hal_drv->mt_fh_lock(&flags);
  114. memset(&g_fh_drv_usr_def[pll_id], 0, sizeof(g_fh_drv_usr_def[pll_id]));
  115. g_fh_drv_pll[pll_id].user_defined = false;
  116. g_p_fh_hal_drv->mt_fh_unlock(&flags);
  117. }
  118. /* FH_MSG("Exit"); */
  119. return 0;
  120. }
  121. static int mt_fh_hal_ctrl_lock(struct freqhopping_ioctl *fh_ctl, bool enable)
  122. {
  123. int retVal = 1;
  124. unsigned long flags = 0;
  125. FH_MSG("EN: _fctr_lck %d:%d", fh_ctl->pll_id, enable);
  126. g_p_fh_hal_drv->mt_fh_lock(&flags);
  127. retVal = g_p_fh_hal_drv->mt_fh_hal_ctrl(fh_ctl, enable);
  128. g_p_fh_hal_drv->mt_fh_unlock(&flags);
  129. return retVal;
  130. }
  131. static int mt_freqhopping_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  132. {
  133. /* Get the structure of ioctl */
  134. int ret = 0;
  135. struct freqhopping_ioctl *freqhopping_ctl = (struct freqhopping_ioctl *)arg;
  136. FH_MSG("EN:CMD:%d pll id:%d", cmd, freqhopping_ctl->pll_id);
  137. if (FH_CMD_ENABLE == cmd) {
  138. ret = mt_fh_hal_ctrl_lock(freqhopping_ctl, true);
  139. } else if (FH_CMD_DISABLE == cmd) {
  140. ret = mt_fh_hal_ctrl_lock(freqhopping_ctl, false);
  141. } else if (FH_CMD_ENABLE_USR_DEFINED == cmd) {
  142. ret = mt_fh_enable_usrdef(freqhopping_ctl);
  143. } else if (FH_CMD_DISABLE_USR_DEFINED == cmd) {
  144. ret = mt_fh_disable_usrdef(freqhopping_ctl);
  145. } else {
  146. /* Invalid command is not acceptable!! */
  147. WARN_ON(1);
  148. }
  149. /* FH_MSG("Exit"); */
  150. return ret;
  151. }
  152. /* static int freqhopping_userdefine_proc_read(char *page, char **start, off_t off, int count, int *eof, void *data) */
  153. static int freqhopping_userdefine_proc_read(struct seq_file *m, void *v)
  154. {
  155. int i = 0;
  156. FH_MSG("EN: %s", __func__);
  157. seq_puts(m, "user defined settings:\n");
  158. seq_puts(m, "===============================================\r\n");
  159. seq_printf(m,
  160. " freq == delta t == delta f == up bond == low bond == dds ==\r\n");
  161. for (i = 0; i < g_drv_pll_count; ++i) {
  162. seq_printf(m, "%10d 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\r\n",
  163. 0, g_fh_drv_usr_def[i].dt, g_fh_drv_usr_def[i].df,
  164. g_fh_drv_usr_def[i].upbnd, g_fh_drv_usr_def[i].lowbnd,
  165. g_fh_drv_usr_def[i].dds);
  166. }
  167. return 0;
  168. }
  169. static ssize_t freqhopping_userdefine_proc_write(struct file *file, const char *buffer,
  170. size_t count, loff_t *data)
  171. {
  172. int ret, n;
  173. char kbuf[256];
  174. size_t len = 0;
  175. unsigned int p1, p2, p3, p4, p5, p6, p7;
  176. struct freqhopping_ioctl fh_ctl;
  177. p1 = p2 = p3 = p4 = p5 = p6 = p7 = 0;
  178. FH_MSG("EN: %s", __func__);
  179. len = min(count, (sizeof(kbuf) - 1));
  180. if (count == 0)
  181. return -1;
  182. if (count > 255)
  183. count = 255;
  184. ret = copy_from_user(kbuf, buffer, count);
  185. if (ret < 0)
  186. return -1;
  187. kbuf[count] = '\0';
  188. n = sscanf(kbuf, "%x %x %x %x %x %x %x", &p1, &p2, &p3, &p4, &p5, &p6, &p7);
  189. fh_ctl.pll_id = p2;
  190. fh_ctl.ssc_setting.df = p3;
  191. fh_ctl.ssc_setting.dt = p4;
  192. fh_ctl.ssc_setting.upbnd = p5;
  193. fh_ctl.ssc_setting.lowbnd = p6;
  194. fh_ctl.ssc_setting.dds = p7;
  195. /* fh_ctl.ssc_setting.freq = 0; */
  196. if (p1 == FH_CMD_ENABLE) {
  197. ret = mt_fh_enable_usrdef(&fh_ctl);
  198. if (ret)
  199. FH_MSG("__EnableUsrSetting() fail!");
  200. } else {
  201. ret = mt_fh_disable_usrdef(&fh_ctl);
  202. if (ret)
  203. FH_MSG("__DisableUsrSetting() fail!");
  204. }
  205. FH_MSG("Exit: %s", __func__);
  206. return count;
  207. }
  208. /* static int freqhopping_status_proc_read(char *page, char **start, off_t off, int count, int *eof, void *data) */
  209. static int freqhopping_status_proc_read(struct seq_file *m, void *v)
  210. {
  211. int i = 0;
  212. FH_MSG("EN: %s", __func__);
  213. seq_puts(m, "FH status:\r\n");
  214. seq_puts(m, "===============================================\r\n");
  215. seq_printf(m,
  216. "id == fh_status == pll_status == setting_id == curr_freq == user_defined ==\r\n");
  217. for (i = 0; i < g_drv_pll_count; ++i) {
  218. seq_printf(m, "%2d %8d %8d",
  219. i, g_fh_drv_pll[i].fh_status, g_fh_drv_pll[i].pll_status);
  220. seq_printf(m, " %8d %8d ",
  221. g_fh_drv_pll[i].setting_id, g_fh_drv_pll[i].curr_freq);
  222. seq_printf(m, " %d\r\n", g_fh_drv_pll[i].user_defined);
  223. }
  224. seq_puts(m, "\r\n");
  225. return 0;
  226. }
  227. static ssize_t freqhopping_status_proc_write(struct file *file, const char *buffer, size_t count,
  228. loff_t *data)
  229. {
  230. int ret, n;
  231. char kbuf[256];
  232. size_t len = 0;
  233. unsigned int p1, p2, p3, p4, p5, p6;
  234. struct freqhopping_ioctl fh_ctl;
  235. p1 = p2 = p3 = p4 = p5 = p6 = 0;
  236. FH_MSG("EN: %s", __func__);
  237. len = min(count, (sizeof(kbuf) - 1));
  238. if (count == 0)
  239. return -1;
  240. if (count > 255)
  241. count = 255;
  242. ret = copy_from_user(kbuf, buffer, count);
  243. if (ret < 0)
  244. return -1;
  245. kbuf[count] = '\0';
  246. n = sscanf(kbuf, "%x %x", &p1, &p2);
  247. fh_ctl.pll_id = p2;
  248. fh_ctl.ssc_setting.df = 0;
  249. fh_ctl.ssc_setting.dt = 0;
  250. fh_ctl.ssc_setting.upbnd = 0;
  251. fh_ctl.ssc_setting.lowbnd = 0;
  252. if (p1 == 0)
  253. mt_freqhopping_ioctl(NULL, FH_CMD_DISABLE, (unsigned long)(&fh_ctl));
  254. else
  255. mt_freqhopping_ioctl(NULL, FH_CMD_ENABLE, (unsigned long)(&fh_ctl));
  256. return count;
  257. }
  258. /* static int freqhopping_debug_proc_read(char *page, char **start, off_t off, int count, int *eof, void *data) */
  259. static int freqhopping_debug_proc_read(struct seq_file *m, void *v)
  260. {
  261. FH_IO_PROC_READ_T arg;
  262. arg.m = m;
  263. arg.v = v;
  264. arg.pll = g_fh_drv_pll;
  265. g_p_fh_hal_drv->ioctl(FH_IO_PROC_READ, &arg);
  266. return 0;
  267. }
  268. static ssize_t freqhopping_debug_proc_write(struct file *file, const char *buffer, size_t count,
  269. loff_t *data)
  270. {
  271. int ret, n;
  272. char kbuf[256];
  273. size_t len = 0;
  274. unsigned int cmd, p1, p2, p3, p4, p5, p6, p7;
  275. struct freqhopping_ioctl fh_ctl;
  276. p1 = p2 = p3 = p4 = p5 = p6 = p7 = 0;
  277. FH_MSG("EN: %s", __func__);
  278. len = min(count, (sizeof(kbuf) - 1));
  279. if (count == 0)
  280. return -1;
  281. if (count > 255)
  282. count = 255;
  283. ret = copy_from_user(kbuf, buffer, count);
  284. if (ret < 0)
  285. return -1;
  286. kbuf[count] = '\0';
  287. n = sscanf(kbuf, "%x %x %x %x %x %x %x %x", &cmd, &p1, &p2, &p3, &p4, &p5, &p6, &p7);
  288. fh_ctl.pll_id = p2;
  289. fh_ctl.ssc_setting.dds = p3;
  290. fh_ctl.ssc_setting.df = p4;
  291. fh_ctl.ssc_setting.dt = p5;
  292. fh_ctl.ssc_setting.upbnd = p6;
  293. fh_ctl.ssc_setting.lowbnd = p7;
  294. /* fh_ctl.ssc_setting.freq = 0; */
  295. if (cmd < FH_CMD_INTERNAL_MAX_CMD)
  296. mt_freqhopping_ioctl(NULL, cmd, (unsigned long)(&fh_ctl));
  297. else if ((cmd > FH_DCTL_CMD_ID) && (cmd < FH_DCTL_CMD_MAX))
  298. mt_freqhopping_devctl(cmd, &fh_ctl);
  299. else
  300. FH_MSG("CMD error!");
  301. return count;
  302. }
  303. static int freqhopping_debug_proc_open(struct inode *inode, struct file *file)
  304. {
  305. return single_open(file, freqhopping_debug_proc_read, NULL);
  306. }
  307. static int freqhopping_dramc_proc_open(struct inode *inode, struct file *file)
  308. {
  309. return single_open(file, g_p_fh_hal_drv->proc.dramc_read, NULL);
  310. }
  311. static ssize_t freqhopping_dramc_proc_write(struct file *file, const char *buffer, size_t count,
  312. loff_t *data)
  313. {
  314. return (ssize_t) (g_p_fh_hal_drv->proc.dramc_write(file, buffer, count, data));
  315. }
  316. static int freqhopping_dvfs_proc_open(struct inode *inode, struct file *file)
  317. {
  318. return single_open(file, g_p_fh_hal_drv->proc.dvfs_read, NULL);
  319. }
  320. static ssize_t freqhopping_dvfs_proc_write(struct file *file, const char *buffer, size_t count,
  321. loff_t *data)
  322. {
  323. return (ssize_t) (g_p_fh_hal_drv->proc.dvfs_write(file, buffer, count, data));
  324. }
  325. static int freqhopping_dumpregs_proc_open(struct inode *inode, struct file *file)
  326. {
  327. return single_open(file, g_p_fh_hal_drv->proc.dumpregs_read, NULL);
  328. }
  329. static int freqhopping_status_proc_open(struct inode *inode, struct file *file)
  330. {
  331. return single_open(file, freqhopping_status_proc_read, NULL);
  332. }
  333. static int freqhopping_userdefine_proc_open(struct inode *inode, struct file *file)
  334. {
  335. return single_open(file, freqhopping_userdefine_proc_read, NULL);
  336. }
  337. static const struct file_operations freqhopping_debug_fops = {
  338. .owner = THIS_MODULE,
  339. .open = freqhopping_debug_proc_open,
  340. .read = seq_read,
  341. .write = freqhopping_debug_proc_write,
  342. .release = single_release,
  343. };
  344. static const struct file_operations dramc_fops = {
  345. .owner = THIS_MODULE,
  346. .open = freqhopping_dramc_proc_open,
  347. .read = seq_read,
  348. .write = freqhopping_dramc_proc_write,
  349. .release = single_release,
  350. };
  351. static const struct file_operations dvfs_fops = {
  352. .owner = THIS_MODULE,
  353. .open = freqhopping_dvfs_proc_open,
  354. .read = seq_read,
  355. .write = freqhopping_dvfs_proc_write,
  356. .release = single_release,
  357. };
  358. static const struct file_operations dumpregs_fops = {
  359. .owner = THIS_MODULE,
  360. .open = freqhopping_dumpregs_proc_open,
  361. .read = seq_read,
  362. .release = single_release,
  363. };
  364. static const struct file_operations status_fops = {
  365. .owner = THIS_MODULE,
  366. .open = freqhopping_status_proc_open,
  367. .read = seq_read,
  368. .write = freqhopping_status_proc_write,
  369. .release = single_release,
  370. };
  371. static const struct file_operations userdef_fops = {
  372. .owner = THIS_MODULE,
  373. .open = freqhopping_userdefine_proc_open,
  374. .read = seq_read,
  375. .write = freqhopping_userdefine_proc_write,
  376. .release = single_release,
  377. };
  378. #if !defined(DISABLE_FREQ_HOPPING)
  379. static int freqhopping_debug_proc_init(void)
  380. {
  381. struct proc_dir_entry *prDebugEntry;
  382. struct proc_dir_entry *prDramcEntry;
  383. struct proc_dir_entry *prDumpregEntry;
  384. struct proc_dir_entry *prStatusEntry;
  385. struct proc_dir_entry *prUserdefEntry;
  386. struct proc_dir_entry *fh_proc_dir = NULL;
  387. /* TODO: check the permission!! */
  388. FH_MSG("EN: %s", __func__);
  389. fh_proc_dir = proc_mkdir("freqhopping", NULL);
  390. if (!fh_proc_dir) {
  391. FH_MSG("proc_mkdir fail!");
  392. return 1;
  393. }
  394. /* /proc/freqhopping/freqhopping_debug */
  395. /* prDebugEntry = create_proc_entry("freqhopping_debug", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir); */
  396. prDebugEntry =
  397. proc_create("freqhopping_debug", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir,
  398. &freqhopping_debug_fops);
  399. if (prDebugEntry) {
  400. /* prDebugEntry->read_proc = freqhopping_debug_proc_read; */
  401. /* prDebugEntry->write_proc = freqhopping_debug_proc_write; */
  402. FH_MSG("[%s]: successfully create /proc/freqhopping_debug", __func__);
  403. } else {
  404. FH_MSG("[%s]: failed to create /proc/freqhopping/freqhopping_debug", __func__);
  405. return 1;
  406. }
  407. /* /proc/freqhopping/dramc */
  408. /* prDramcEntry = create_proc_entry("dramc", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir); */
  409. /* prDramcEntry = proc_create("dramc", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir, &dramc_fops); */
  410. /* if(prDramcEntry) */
  411. /* { */
  412. /* prDramcEntry->read_proc = g_p_fh_hal_drv->proc.dramc_read; */
  413. /* prDramcEntry->write_proc = g_p_fh_hal_drv->proc.dramc_write; */
  414. /* FH_MSG("[%s]: successfully create /proc/freqhopping/prDramcEntry", __func__); */
  415. /* }else{ */
  416. /* FH_MSG("[%s]: failed to create /proc/freqhopping/prDramcEntry", __func__); */
  417. /* return 1; */
  418. /* } */
  419. /* /proc/freqhopping/dvfs */
  420. /* prDramcEntry = create_proc_entry("dvfs", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir); */
  421. prDramcEntry = proc_create("dvfs", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir, &dvfs_fops);
  422. if (prDramcEntry) {
  423. /* prDramcEntry->read_proc = g_p_fh_hal_drv->proc.dvfs_read; */
  424. /* prDramcEntry->write_proc = g_p_fh_hal_drv->proc.dvfs_write; */
  425. FH_MSG("[%s]: successfully create /proc/freqhopping/dvfs", __func__);
  426. } else {
  427. FH_MSG("[%s]: failed to create /proc/freqhopping/dvfs", __func__);
  428. return 1;
  429. }
  430. /* /proc/freqhopping/dumpregs */
  431. /* prDumpregEntry = create_proc_entry("dumpregs", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir); */
  432. prDumpregEntry =
  433. proc_create("dumpregs", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir, &dumpregs_fops);
  434. if (prDumpregEntry) {
  435. /* prDumpregEntry->read_proc = g_p_fh_hal_drv->proc.dumpregs_read; */
  436. /* prDumpregEntry->write_proc = NULL; */
  437. FH_MSG("[%s]: successfully create /proc/freqhopping/dumpregs", __func__);
  438. } else {
  439. FH_MSG("[%s]: failed to create /proc/freqhopping/dumpregs", __func__);
  440. return 1;
  441. }
  442. /* /proc/freqhopping/status */
  443. /* prStatusEntry = create_proc_entry("status", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir); */
  444. prStatusEntry =
  445. proc_create("status", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir, &status_fops);
  446. if (prStatusEntry) {
  447. /* prStatusEntry->read_proc = freqhopping_status_proc_read; */
  448. /* prStatusEntry->write_proc = freqhopping_status_proc_write; */
  449. FH_MSG("[%s]: successfully create /proc/freqhopping/status", __func__);
  450. } else {
  451. FH_MSG("[%s]: failed to create /proc/freqhopping/status", __func__);
  452. return 1;
  453. }
  454. /* /proc/freqhopping/userdefine */
  455. /* prUserdefEntry = create_proc_entry("userdef", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir); */
  456. prUserdefEntry =
  457. proc_create("userdef", S_IRUGO | S_IWUSR | S_IWGRP, fh_proc_dir, &userdef_fops);
  458. if (prUserdefEntry) {
  459. /* prUserdefEntry->read_proc = freqhopping_userdefine_proc_read; */
  460. /* prUserdefEntry->write_proc = freqhopping_userdefine_proc_write; */
  461. FH_MSG("[%s]: successfully create /proc/freqhopping/userdef", __func__);
  462. } else {
  463. FH_MSG("[%s]: failed to create /proc/freqhopping/userdef", __func__);
  464. return 1;
  465. }
  466. return 0;
  467. }
  468. #endif
  469. #if defined(DISABLE_FREQ_HOPPING)
  470. void mt_fh_popod_save(void)
  471. {
  472. }
  473. EXPORT_SYMBOL(mt_fh_popod_save);
  474. void mt_fh_popod_restore(void)
  475. {
  476. }
  477. EXPORT_SYMBOL(mt_fh_popod_restore);
  478. int freqhopping_config(unsigned int pll_id, unsigned long vco_freq, unsigned int enable)
  479. {
  480. return 0;
  481. }
  482. EXPORT_SYMBOL(freqhopping_config);
  483. int mt_l2h_mempll(void)
  484. {
  485. return 0;
  486. }
  487. EXPORT_SYMBOL(mt_l2h_mempll);
  488. int mt_h2l_mempll(void)
  489. {
  490. return 0;
  491. }
  492. EXPORT_SYMBOL(mt_h2l_mempll);
  493. int mt_dfs_armpll(unsigned int current_freq, unsigned int target_dds)
  494. {
  495. return 0;
  496. }
  497. EXPORT_SYMBOL(mt_dfs_armpll);
  498. int mt_dfs_mmpll(unsigned int target_dds)
  499. {
  500. return 0;
  501. }
  502. EXPORT_SYMBOL(mt_dfs_mmpll);
  503. int mt_dfs_vencpll(unsigned int target_dds)
  504. {
  505. return 0;
  506. }
  507. EXPORT_SYMBOL(mt_dfs_vencpll);
  508. int mt_dfs_mpll(unsigned int target_dds)
  509. {
  510. return 0;
  511. }
  512. EXPORT_SYMBOL(mt_dfs_mpll);
  513. int mt_is_support_DFS_mode(void)
  514. {
  515. return 0;
  516. }
  517. EXPORT_SYMBOL(mt_is_support_DFS_mode);
  518. int mt_l2h_dvfs_mempll(void)
  519. {
  520. return 0;
  521. }
  522. EXPORT_SYMBOL(mt_l2h_dvfs_mempll);
  523. int mt_h2l_dvfs_mempll(void)
  524. {
  525. return 0;
  526. }
  527. EXPORT_SYMBOL(mt_h2l_dvfs_mempll);
  528. int mt_fh_dram_overclock(int clk)
  529. {
  530. return 0;
  531. }
  532. EXPORT_SYMBOL(mt_fh_dram_overclock);
  533. int mt_fh_get_dramc(void)
  534. {
  535. return 0;
  536. }
  537. EXPORT_SYMBOL(mt_fh_get_dramc);
  538. void mt_freqhopping_init(void)
  539. {
  540. }
  541. EXPORT_SYMBOL(mt_freqhopping_init);
  542. void mt_freqhopping_pll_init(void)
  543. {
  544. }
  545. EXPORT_SYMBOL(mt_freqhopping_pll_init);
  546. int mt_freqhopping_devctl(unsigned int cmd, void *args)
  547. {
  548. return 0;
  549. }
  550. EXPORT_SYMBOL(mt_freqhopping_devctl);
  551. #else
  552. void mt_fh_popod_save(void)
  553. {
  554. if (!g_p_fh_hal_drv) {
  555. FH_MSG("[%s]: g_p_fh_hal_drv is uninitialized.", __func__);
  556. return;
  557. }
  558. FH_MSG("EN: %s", __func__);
  559. g_p_fh_hal_drv->mt_fh_popod_save();
  560. }
  561. EXPORT_SYMBOL(mt_fh_popod_save);
  562. void mt_fh_popod_restore(void)
  563. {
  564. if (!g_p_fh_hal_drv) {
  565. FH_MSG("[%s]: g_p_fh_hal_drv is uninitialized.", __func__);
  566. return;
  567. }
  568. FH_MSG("EN: %s", __func__);
  569. g_p_fh_hal_drv->mt_fh_popod_restore();
  570. }
  571. EXPORT_SYMBOL(mt_fh_popod_restore);
  572. int freqhopping_config(unsigned int pll_id, unsigned long vco_freq, unsigned int enable)
  573. {
  574. struct freqhopping_ioctl fh_ctl;
  575. unsigned int fh_status;
  576. unsigned long flags = 0;
  577. unsigned int skip_flag = 0;
  578. /* FH_MSG("conf() id: %d f: %d, e: %d",(int)pll_id, (int)vco_freq, (int)enable); */
  579. if ((g_p_fh_hal_drv->mt_fh_get_init()) == 0) {
  580. FH_MSG("Not init yet, init first.");
  581. return 1;
  582. }
  583. g_p_fh_hal_drv->mt_fh_lock(&flags);
  584. /* backup */
  585. fh_status = g_fh_drv_pll[pll_id].fh_status;
  586. g_fh_drv_pll[pll_id].curr_freq = vco_freq;
  587. g_fh_drv_pll[pll_id].pll_status = (enable > 0) ? FH_PLL_ENABLE : FH_PLL_DISABLE;
  588. /* prepare freqhopping_ioctl */
  589. fh_ctl.pll_id = pll_id;
  590. if (g_fh_drv_pll[pll_id].fh_status != FH_FH_DISABLE) {
  591. /* FH_MSG("+fh"); */
  592. g_p_fh_hal_drv->mt_fh_hal_ctrl(&fh_ctl, enable);
  593. } else {
  594. skip_flag = 1;
  595. /* FH_MSG("-fh,skip"); */
  596. }
  597. /* restore */
  598. g_fh_drv_pll[pll_id].fh_status = fh_status;
  599. g_p_fh_hal_drv->mt_fh_unlock(&flags);
  600. /* if(skip_flag) */
  601. /* FH_MSG("-fh,skip"); */
  602. return 0;
  603. }
  604. EXPORT_SYMBOL(freqhopping_config);
  605. int mt_l2h_mempll(void)
  606. {
  607. return g_p_fh_hal_drv->mt_l2h_mempll();
  608. }
  609. EXPORT_SYMBOL(mt_l2h_mempll);
  610. int mt_h2l_mempll(void)
  611. {
  612. return g_p_fh_hal_drv->mt_h2l_mempll();
  613. }
  614. EXPORT_SYMBOL(mt_h2l_mempll);
  615. int mt_dfs_armpll(unsigned int current_freq, unsigned int target_dds)
  616. {
  617. if (!g_p_fh_hal_drv) {
  618. FH_MSG("[%s]: g_p_fh_hal_drv is uninitialized.", __func__);
  619. return 1;
  620. }
  621. return g_p_fh_hal_drv->mt_dfs_armpll(current_freq, target_dds);
  622. }
  623. EXPORT_SYMBOL(mt_dfs_armpll);
  624. int mt_dfs_mmpll(unsigned int target_dds)
  625. {
  626. if (!g_p_fh_hal_drv) {
  627. FH_MSG("[%s]: g_p_fh_hal_drv is uninitialized.", __func__);
  628. return 1;
  629. }
  630. return g_p_fh_hal_drv->mt_dfs_mmpll(target_dds);
  631. }
  632. EXPORT_SYMBOL(mt_dfs_mmpll);
  633. int mt_dfs_vencpll(unsigned int target_dds)
  634. {
  635. if (!g_p_fh_hal_drv) {
  636. FH_MSG("[%s]: g_p_fh_hal_drv is uninitialized.", __func__);
  637. return 1;
  638. }
  639. return g_p_fh_hal_drv->mt_dfs_vencpll(target_dds);
  640. }
  641. EXPORT_SYMBOL(mt_dfs_vencpll);
  642. int mt_dfs_mpll(unsigned int target_dds)
  643. {
  644. if ((!g_p_fh_hal_drv) || (!g_p_fh_hal_drv->mt_dfs_mpll)) {
  645. FH_MSG("[%s]: g_p_fh_hal_drv is uninitialized.", __func__);
  646. return 1;
  647. }
  648. return g_p_fh_hal_drv->mt_dfs_mpll(target_dds);
  649. }
  650. EXPORT_SYMBOL(mt_dfs_mpll);
  651. int mt_dfs_mempll(unsigned int target_dds)
  652. {
  653. if ((!g_p_fh_hal_drv) || (!g_p_fh_hal_drv->mt_dfs_mempll)) {
  654. FH_MSG("[%s]: g_p_fh_hal_drv or g_p_fh_hal_drv->mt_dfs_mempll is uninitialized.",
  655. __func__);
  656. return 1;
  657. }
  658. return g_p_fh_hal_drv->mt_dfs_mempll(target_dds);
  659. }
  660. EXPORT_SYMBOL(mt_dfs_mempll);
  661. int mt_is_support_DFS_mode(void)
  662. {
  663. return g_p_fh_hal_drv->mt_is_support_DFS_mode();
  664. }
  665. EXPORT_SYMBOL(mt_is_support_DFS_mode);
  666. int mt_l2h_dvfs_mempll(void)
  667. {
  668. if (!g_p_fh_hal_drv) {
  669. FH_MSG("[%s]: g_p_fh_hal_drv is uninitialized.", __func__);
  670. return 1;
  671. }
  672. return g_p_fh_hal_drv->mt_l2h_dvfs_mempll();
  673. }
  674. EXPORT_SYMBOL(mt_l2h_dvfs_mempll);
  675. int mt_h2l_dvfs_mempll(void)
  676. {
  677. if (!g_p_fh_hal_drv) {
  678. FH_MSG("[%s]: g_p_fh_hal_drv is uninitialized.", __func__);
  679. return 1;
  680. }
  681. return g_p_fh_hal_drv->mt_h2l_dvfs_mempll();
  682. }
  683. EXPORT_SYMBOL(mt_h2l_dvfs_mempll);
  684. int mt_fh_dram_overclock(int clk)
  685. {
  686. return g_p_fh_hal_drv->mt_dram_overclock(clk);
  687. }
  688. EXPORT_SYMBOL(mt_fh_dram_overclock);
  689. int mt_fh_get_dramc(void)
  690. {
  691. return g_p_fh_hal_drv->mt_get_dramc();
  692. }
  693. EXPORT_SYMBOL(mt_fh_get_dramc);
  694. void mt_freqhopping_init(void)
  695. {
  696. g_p_fh_hal_drv = mt_get_fh_hal_drv();
  697. g_p_fh_hal_drv->mt_fh_hal_init();
  698. g_fh_drv_pll = g_p_fh_hal_drv->fh_pll;
  699. g_fh_drv_usr_def = g_p_fh_hal_drv->fh_usrdef;
  700. g_drv_pll_count = g_p_fh_hal_drv->pll_cnt;
  701. freqhopping_debug_proc_init();
  702. platform_driver_register(&freqhopping_driver);
  703. mt_freqhopping_pll_init(); /* TODO_HAL: wait for clkmgr to invoke this function */
  704. }
  705. EXPORT_SYMBOL(mt_freqhopping_init);
  706. void mt_freqhopping_pll_init(void)
  707. {
  708. g_p_fh_hal_drv->mt_fh_default_conf();
  709. }
  710. EXPORT_SYMBOL(mt_freqhopping_pll_init);
  711. int mt_freqhopping_devctl(unsigned int cmd, void *args)
  712. {
  713. if (!g_p_fh_hal_drv)
  714. return 1;
  715. g_p_fh_hal_drv->ioctl(cmd, args);
  716. return 0;
  717. }
  718. EXPORT_SYMBOL(mt_freqhopping_devctl);
  719. #endif