sec_misc.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. /*
  2. * driver/misc/sec_misc.c
  3. *
  4. * driver supporting miscellaneous functions for Samsung P-series device
  5. *
  6. * COPYRIGHT(C) Samsung Electronics Co., Ltd. 2006-2011 All Right Reserved.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. */
  22. #include <linux/module.h>
  23. #include <linux/device.h>
  24. #include <linux/miscdevice.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/fs.h>
  27. #include <linux/mm.h>
  28. #include <linux/slab.h>
  29. #include <linux/firmware.h>
  30. #include <linux/wakelock.h>
  31. #include <linux/blkdev.h>
  32. #include <mach/gpio.h>
  33. #include <linux/sec_param.h>
  34. #include <mach/sec_debug.h>
  35. #include <linux/sec_class.h>
  36. #define MOVINAND_CHECKSUM
  37. #define RORY_CONTROL
  38. static struct wake_lock sec_misc_wake_lock;
  39. #ifdef MOVINAND_CHECKSUM
  40. unsigned char emmc_checksum_done;
  41. unsigned char emmc_checksum_pass;
  42. #endif
  43. static const struct file_operations sec_misc_fops = {
  44. .owner = THIS_MODULE,
  45. /* .read = sec_misc_read,
  46. .ioctl = sec_misc_ioctl,
  47. .open = sec_misc_open,
  48. .release = sec_misc_release, */
  49. };
  50. static struct miscdevice sec_misc_device = {
  51. .minor = MISC_DYNAMIC_MINOR,
  52. .name = "sec_misc",
  53. .fops = &sec_misc_fops,
  54. };
  55. #ifdef MOVINAND_CHECKSUM
  56. static ssize_t emmc_checksum_done_show(struct device *dev,
  57. struct device_attribute *attr, char *buf)
  58. {
  59. return snprintf(buf, PAGE_SIZE, "%d\n", emmc_checksum_done);
  60. }
  61. static ssize_t emmc_checksum_done_store(struct device *dev,
  62. struct device_attribute *attr, const char *buf, size_t size)
  63. {
  64. int state;
  65. if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1))
  66. return -EINVAL;
  67. emmc_checksum_done = (unsigned char)state;
  68. return size;
  69. }
  70. static DEVICE_ATTR(emmc_checksum_done, S_IRUGO | S_IWUSR ,
  71. emmc_checksum_done_show, emmc_checksum_done_store);
  72. static ssize_t emmc_checksum_pass_show(struct device *dev,
  73. struct device_attribute *attr, char *buf)
  74. {
  75. return snprintf(buf, PAGE_SIZE, "%d\n", emmc_checksum_pass);
  76. }
  77. static ssize_t emmc_checksum_pass_store(struct device *dev,
  78. struct device_attribute *attr, const char *buf, size_t size)
  79. {
  80. int state;
  81. if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1))
  82. return -EINVAL;
  83. emmc_checksum_pass = (unsigned char)state;
  84. return size;
  85. }
  86. static DEVICE_ATTR(emmc_checksum_pass, S_IRUGO | S_IWUSR ,
  87. emmc_checksum_pass_show, emmc_checksum_pass_store);
  88. #endif /*MOVINAND_CHECKSUM*/
  89. #ifdef RORY_CONTROL
  90. static ssize_t rory_control_show(struct device *dev,
  91. struct device_attribute *attr, char *buf)
  92. {
  93. int rory_control;
  94. sec_get_param(param_rory_control, &rory_control);
  95. return snprintf(buf, PAGE_SIZE, "%d\n", rory_control);
  96. }
  97. static ssize_t rory_control_store(struct device *dev,
  98. struct device_attribute *attr, const char *buf, size_t size)
  99. {
  100. int rory_control;
  101. sscanf(buf, "%i", &rory_control);
  102. pr_info("rory control store ..... %d\n", rory_control);
  103. /* write to param */
  104. sec_set_param(param_rory_control, &rory_control);
  105. return size;
  106. }
  107. static DEVICE_ATTR(rory_control, S_IRUGO | S_IWUSR ,
  108. rory_control_show, rory_control_store);
  109. #endif /*RORY_CONTROL*/
  110. #ifdef CONFIG_SGLTE_QSC_MODEM
  111. static ssize_t qsc_control_show(struct device *dev,
  112. struct device_attribute *attr, char *buf)
  113. {
  114. int qsc_control;
  115. sec_get_param(param_update_cp_bin, &qsc_control);
  116. return snprintf(buf, PAGE_SIZE, "%d\n", qsc_control);
  117. }
  118. static ssize_t qsc_control_store(struct device *dev,
  119. struct device_attribute *attr, const char *buf, size_t size)
  120. {
  121. int qsc_control;
  122. sscanf(buf, "%i", &qsc_control);
  123. pr_info("qsc control store ..... %d\n", qsc_control);
  124. /* write to param */
  125. sec_set_param(param_update_cp_bin, &qsc_control);
  126. return size;
  127. }
  128. static DEVICE_ATTR(qsc_control, S_IRUGO | S_IWUSR ,
  129. qsc_control_show, qsc_control_store);
  130. #endif /*QSC_CONTROL*/
  131. #ifdef CONFIG_SEC_DEBUG
  132. static unsigned int convert_debug_level_str(const char *str)
  133. {
  134. if (strncasecmp(str, "0xA0A0", 6) == 0)
  135. return KERNEL_SEC_DEBUG_LEVEL_LOW;
  136. if (strncasecmp(str, "0xB0B0", 6) == 0)
  137. return KERNEL_SEC_DEBUG_LEVEL_MID;
  138. if (strncasecmp(str, "0xC0C0", 6) == 0)
  139. return KERNEL_SEC_DEBUG_LEVEL_HIGH;
  140. return 0;
  141. }
  142. static void convert_debug_level_int(unsigned int val, char *str)
  143. {
  144. if (val == KERNEL_SEC_DEBUG_LEVEL_LOW) {
  145. strlcpy(str, "0xA0A0", sizeof("0xA0A0") + 1);
  146. return;
  147. }
  148. if (val == KERNEL_SEC_DEBUG_LEVEL_MID) {
  149. strlcpy(str, "0xB0B0", sizeof("0xB0B0") + 1);
  150. return;
  151. }
  152. if (val == KERNEL_SEC_DEBUG_LEVEL_HIGH) {
  153. strlcpy(str, "0xC0C0", sizeof("0xC0C0") + 1);
  154. return;
  155. }
  156. }
  157. static ssize_t debug_level_show(struct device *dev,
  158. struct device_attribute *attr, char *buf)
  159. {
  160. char buffer[7];
  161. convert_debug_level_int(kernel_sec_get_debug_level(), buffer);
  162. return snprintf(buf, sizeof(buffer)+1, "%s\n", buffer);
  163. }
  164. static ssize_t debug_level_store(struct device *dev,
  165. struct device_attribute *attr, const char *buf, size_t size)
  166. {
  167. int sec_debug_level = convert_debug_level_str(buf);
  168. if (sec_debug_level == 0)
  169. return -EINVAL;
  170. kernel_sec_set_debug_level(sec_debug_level);
  171. return size;
  172. }
  173. static DEVICE_ATTR(debug_level, S_IRUGO | S_IWUSR ,
  174. debug_level_show, debug_level_store);
  175. #endif // CONFIG_SEC_DEBUG
  176. #if defined(CONFIG_MACH_APEXQ) || defined(CONFIG_MACH_AEGIS2)
  177. static ssize_t slideCount_show
  178. (struct device *dev, struct device_attribute *attr, char *buf)
  179. {
  180. int slideCount;
  181. sec_get_param(param_slideCount, &slideCount);
  182. return snprintf(buf, PAGE_SIZE, "%d\n", slideCount);
  183. }
  184. static ssize_t slideCount_store
  185. (struct device *dev, struct device_attribute *attr,\
  186. const char *buf, size_t size)
  187. {
  188. int slideCount;
  189. sscanf(buf, "%i", &slideCount);
  190. sec_set_param(param_slideCount, &slideCount);
  191. return size;
  192. }
  193. static DEVICE_ATTR(slideCount, S_IRUGO | S_IWUSR | S_IWGRP,\
  194. slideCount_show, slideCount_store);
  195. #endif
  196. /*
  197. * For Drop Caches
  198. */
  199. #include <linux/fs.h>
  200. #include <linux/vmstat.h>
  201. #include <linux/swap.h>
  202. #define K(x) ((x) << (PAGE_SHIFT - 10))
  203. extern void drop_pagecache_sb(struct super_block *sb, void *unused);
  204. extern void drop_slab(void);
  205. static ssize_t drop_caches_show
  206. (struct device *dev, struct device_attribute *attr, char *buf)
  207. {
  208. int ret = 0;
  209. return snprintf(buf, PAGE_SIZE, "%d\n", ret);
  210. }
  211. static ssize_t drop_caches_store
  212. (struct device *dev, struct device_attribute *attr,\
  213. const char *buf, size_t size)
  214. {
  215. struct sysinfo i;
  216. if (strlen(buf) > 2)
  217. goto out;
  218. if (buf[0] == '3') {
  219. si_meminfo(&i);
  220. printk("[Before]\nMemFree : %8lu kB\n", K(i.freeram));
  221. printk("Cached : %8lu kB\n\n", K(global_page_state(NR_FILE_PAGES) - \
  222. total_swapcache_pages() - i.bufferram));
  223. iterate_supers(drop_pagecache_sb, NULL);
  224. drop_slab();
  225. si_meminfo(&i);
  226. printk("[After]\nMemFree : %8lu kB\n", K(i.freeram));
  227. printk("Cached : %8lu kB\n\n", K(global_page_state(NR_FILE_PAGES) - \
  228. total_swapcache_pages() - i.bufferram));
  229. printk("Cached Drop done!\n");
  230. }
  231. out:
  232. return size;
  233. }
  234. static DEVICE_ATTR(drop_caches, S_IRUGO | S_IWUSR | S_IWGRP,\
  235. drop_caches_show, drop_caches_store);
  236. /*
  237. * End Drop Caches
  238. */
  239. /*
  240. * For external CP download
  241. */
  242. #ifdef CONFIG_GSM_MODEM_SPRD6500
  243. static ssize_t update_cp_bin_show
  244. (struct device *dev, struct device_attribute *attr, char *buf)
  245. {
  246. int update = 0;
  247. sec_get_param(param_update_cp_bin, (void *)&update);
  248. return snprintf(buf, PAGE_SIZE, "%d\n", update);
  249. }
  250. static ssize_t update_cp_bin_store
  251. (struct device *dev, struct device_attribute *attr,\
  252. const char *buf, size_t size)
  253. {
  254. int update = 0;
  255. sscanf(buf, "%i", &update);
  256. sec_set_param(param_update_cp_bin, &update);
  257. return size;
  258. }
  259. static DEVICE_ATTR(update_cp_bin, S_IRUGO | S_IWUSR | S_IWGRP,\
  260. update_cp_bin_show, update_cp_bin_store);
  261. #endif
  262. #if defined(CONFIG_SEC_SLOWPATH)
  263. extern unsigned int get_and_reset_timeup(void);
  264. extern unsigned int get_and_reset_slowtime(void);
  265. static ssize_t timeup_show
  266. (struct device *dev, struct device_attribute *attr, char *buf)
  267. {
  268. bool time_up;
  269. time_up = get_and_reset_timeup();
  270. return sprintf(buf, "%d\n", time_up);
  271. }
  272. static DEVICE_ATTR(timeup, S_IRUGO, timeup_show, NULL);
  273. static ssize_t slowpath_show
  274. (struct device *dev, struct device_attribute *attr, char *buf)
  275. {
  276. unsigned int slowtime;
  277. slowtime = get_and_reset_slowtime();
  278. return sprintf(buf, "%u\n", slowtime);
  279. }
  280. static DEVICE_ATTR(slowpath, S_IRUGO, slowpath_show, NULL);
  281. #endif
  282. struct device *sec_misc_dev;
  283. static struct device_attribute *sec_misc_attrs[] = {
  284. &dev_attr_emmc_checksum_done,
  285. &dev_attr_emmc_checksum_pass,
  286. &dev_attr_rory_control,
  287. #ifdef CONFIG_SEC_DEBUG
  288. &dev_attr_debug_level,
  289. #endif // CONFIG_SEC_DEBUG
  290. #if defined(CONFIG_MACH_APEXQ) || defined(CONFIG_MACH_AEGIS2)
  291. &dev_attr_slideCount,
  292. #endif
  293. &dev_attr_drop_caches,
  294. #ifdef CONFIG_GSM_MODEM_SPRD6500
  295. &dev_attr_update_cp_bin,
  296. #endif
  297. #if defined(CONFIG_SEC_SLOWPATH)
  298. &dev_attr_timeup,
  299. &dev_attr_slowpath,
  300. #endif
  301. #ifdef CONFIG_SGLTE_QSC_MODEM
  302. &dev_attr_qsc_control,
  303. #endif
  304. };
  305. static int __init sec_misc_init(void)
  306. {
  307. int ret = 0;
  308. int i;
  309. ret = misc_register(&sec_misc_device);
  310. if (ret < 0) {
  311. printk(KERN_ERR "misc_register failed!\n");
  312. goto failed_register_misc;
  313. }
  314. sec_misc_dev = device_create(sec_class, NULL, 0, NULL, "sec_misc");
  315. if (IS_ERR(sec_misc_dev)) {
  316. printk(KERN_ERR "failed to create device!\n");
  317. ret = -ENODEV;
  318. goto failed_create_device;
  319. }
  320. for (i = 0; i < ARRAY_SIZE(sec_misc_attrs) ; i++) {
  321. ret = device_create_file(sec_misc_dev, sec_misc_attrs[i]);
  322. if (ret < 0) {
  323. pr_err("failed to create device file - %s\n",
  324. dev_attr_emmc_checksum_done.attr.name);
  325. goto failed_create_device_file;
  326. }
  327. }
  328. wake_lock_init(&sec_misc_wake_lock, WAKE_LOCK_SUSPEND, "sec_misc");
  329. return 0;
  330. failed_create_device_file:
  331. if (i) {
  332. for (--i; i >= 0; i--)
  333. device_remove_file(sec_misc_dev, sec_misc_attrs[i]);
  334. }
  335. failed_create_device:
  336. misc_deregister(&sec_misc_device);
  337. failed_register_misc:
  338. return ret;
  339. }
  340. static void __exit sec_misc_exit(void)
  341. {
  342. wake_lock_destroy(&sec_misc_wake_lock);
  343. }
  344. module_init(sec_misc_init);
  345. module_exit(sec_misc_exit);
  346. /* Module information */
  347. MODULE_AUTHOR("Samsung");
  348. MODULE_DESCRIPTION("Samsung PX misc. driver");
  349. MODULE_LICENSE("GPL");