secgpio_dvs.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. /*
  2. * Samsung Mobile VE Group.
  3. *
  4. * drivers/gpio/secgpio_dvs.c
  5. *
  6. * Drivers for samsung gpio debugging & verification.
  7. *
  8. * Copyright (C) 2013, Samsung Electronics.
  9. *
  10. * This program is free software. You can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation
  13. */
  14. #include <linux/module.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/workqueue.h>
  17. #include <linux/proc_fs.h>
  18. #include <linux/delay.h>
  19. #include <linux/types.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/timer.h>
  22. #include <linux/wakelock.h>
  23. #include <linux/power_supply.h>
  24. #include <linux/sched.h>
  25. #include <linux/init.h>
  26. #include <linux/fs.h>
  27. #include <linux/gpio.h>
  28. #include <linux/kernel.h>
  29. #include <linux/string.h>
  30. #include <linux/secgpio_dvs.h>
  31. /*sys fs*/
  32. struct class *secgpio_dvs_class;
  33. EXPORT_SYMBOL(secgpio_dvs_class);
  34. struct device *secgpio_dotest;
  35. EXPORT_SYMBOL(secgpio_dotest);
  36. /* extern GPIOMAP_RESULT GpioMap_result; */
  37. static struct gpio_dvs *gdvs_info;
  38. static ssize_t checked_secgpio_file_read(
  39. struct device *dev, struct device_attribute *attr, char *buf);
  40. static ssize_t checked_sleep_secgpio_file_read(
  41. struct device *dev, struct device_attribute *attr, char *buf);
  42. static ssize_t checked_secgpio_init_read_details(
  43. struct device *dev, struct device_attribute *attr, char *buf);
  44. static ssize_t checked_secgpio_sleep_read_details(
  45. struct device *dev, struct device_attribute *attr, char *buf);
  46. static ssize_t secgpio_ctrl_file_write(
  47. struct device *dev, struct device_attribute *attr,
  48. const char *buf, size_t size);
  49. static ssize_t secgpio_checked_sleepgpio_read(
  50. struct device *dev, struct device_attribute *attr, char *buf);
  51. static DEVICE_ATTR(gpioinit_check, 0664,
  52. checked_secgpio_file_read, NULL);
  53. static DEVICE_ATTR(gpiosleep_check, 0664,
  54. checked_sleep_secgpio_file_read, NULL);
  55. static DEVICE_ATTR(check_init_detail, 0664,
  56. checked_secgpio_init_read_details, NULL);
  57. static DEVICE_ATTR(check_sleep_detail, 0664,
  58. checked_secgpio_sleep_read_details, NULL);
  59. static DEVICE_ATTR(secgpio_ctrl, 0664 , NULL, secgpio_ctrl_file_write);
  60. static DEVICE_ATTR(checked_sleepGPIO, 0664,
  61. secgpio_checked_sleepgpio_read, NULL);
  62. static struct attribute *secgpio_dvs_attributes[] = {
  63. &dev_attr_gpioinit_check.attr,
  64. &dev_attr_gpiosleep_check.attr,
  65. &dev_attr_check_init_detail.attr,
  66. &dev_attr_check_sleep_detail.attr,
  67. &dev_attr_secgpio_ctrl.attr,
  68. &dev_attr_checked_sleepGPIO.attr,
  69. NULL,
  70. };
  71. static struct attribute_group secgpio_dvs_attr_group = {
  72. .attrs = secgpio_dvs_attributes,
  73. };
  74. static int atoi(const char *str)
  75. {
  76. int result = 0;
  77. int count = 0;
  78. if (str == NULL)
  79. return -EIO;
  80. while (str[count] != 0 /* NULL */
  81. && str[count] >= '0' && str[count] <= '9') {
  82. result = result * 10 + str[count] - '0';
  83. ++count;
  84. }
  85. return result;
  86. }
  87. static char *
  88. strtok_r(char *s, const char *delim, char **last)
  89. {
  90. char *spanp;
  91. int c, sc;
  92. char *tok;
  93. /* if (s == NULL && (s = *last) == NULL)
  94. return NULL; */
  95. if (s == NULL) {
  96. s = *last;
  97. if (s == NULL)
  98. return NULL;
  99. }
  100. /*
  101. * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
  102. */
  103. cont:
  104. c = *s++;
  105. for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
  106. if (c == sc)
  107. goto cont;
  108. }
  109. if (c == 0) { /* no non-delimiter characters */
  110. *last = NULL;
  111. return NULL;
  112. }
  113. tok = s - 1;
  114. /*
  115. * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
  116. * Note that delim must have one NUL; we stop if we see that, too.
  117. */
  118. for (;;) {
  119. c = *s++;
  120. spanp = (char *)delim;
  121. do {
  122. sc = *spanp++;
  123. if (sc == c) {
  124. if (c == 0)
  125. s = NULL;
  126. else
  127. s[-1] = 0;
  128. *last = s;
  129. return tok;
  130. }
  131. } while (sc != 0);
  132. }
  133. /* NOTREACHED */
  134. }
  135. static char *
  136. strtok(char *s, const char *delim)
  137. {
  138. static char *last;
  139. return strtok_r(s, delim, &last);
  140. }
  141. static ssize_t checked_secgpio_file_read(
  142. struct device *dev, struct device_attribute *attr, char *buf)
  143. {
  144. int i = 0;
  145. char temp_buf[20];
  146. struct gpio_dvs *gdvs = dev_get_drvdata(dev);
  147. for (i = 0; i < gdvs->count; i++) {
  148. memset(temp_buf, 0, sizeof(char)*20);
  149. snprintf(temp_buf, 20, "%x ", gdvs->result->init[i]);
  150. strlcat(buf, temp_buf, PAGE_SIZE);
  151. }
  152. return strlen(buf);
  153. }
  154. static ssize_t checked_sleep_secgpio_file_read(
  155. struct device *dev, struct device_attribute *attr, char *buf)
  156. {
  157. int i = 0;
  158. char temp_buf[20];
  159. struct gpio_dvs *gdvs = dev_get_drvdata(dev);
  160. for (i = 0; i < gdvs->count; i++) {
  161. memset(temp_buf, 0, sizeof(char)*20);
  162. snprintf(temp_buf, 20, "%x ", gdvs->result->sleep[i]);
  163. strlcat(buf, temp_buf, PAGE_SIZE);
  164. }
  165. return strlen(buf);
  166. }
  167. static ssize_t checked_secgpio_init_read_details(
  168. struct device *dev, struct device_attribute *attr, char *buf)
  169. {
  170. int i = 0;
  171. char temp_buf[20];
  172. struct gpio_dvs *gdvs = dev_get_drvdata(dev);
  173. for (i = 0; i < gdvs->count; i++) {
  174. memset(temp_buf, 0, sizeof(char)*20);
  175. snprintf(temp_buf, 20, "GI[%d] - %x\n ",
  176. i, gdvs->result->init[i]);
  177. strlcat(buf, temp_buf, PAGE_SIZE);
  178. }
  179. return strlen(buf);
  180. }
  181. static ssize_t checked_secgpio_sleep_read_details(
  182. struct device *dev, struct device_attribute *attr, char *buf)
  183. {
  184. int i = 0;
  185. char temp_buf[20];
  186. struct gpio_dvs *gdvs = dev_get_drvdata(dev);
  187. for (i = 0; i < gdvs->count; i++) {
  188. memset(temp_buf, 0, sizeof(char)*20);
  189. snprintf(temp_buf, 20, "GS[%d] - %x\n ",
  190. i, gdvs->result->sleep[i]);
  191. strlcat(buf, temp_buf, PAGE_SIZE);
  192. }
  193. return strlen(buf);
  194. }
  195. static ssize_t secgpio_ctrl_file_write(
  196. struct device *dev, struct device_attribute *attr,
  197. const char *buf, size_t size)
  198. {
  199. char *token = NULL;
  200. char comp[] = ",";
  201. int gpio_ctrl[3] = {0,}, num = 0;
  202. char temp_buf[50];
  203. pr_info("[secgpio_dvs] GPIO onoff buf = %s\n", buf);
  204. memset(temp_buf, 0, 50);
  205. strlcpy(temp_buf, buf, 50);
  206. token = strtok(temp_buf, comp);
  207. for (num = 0; num < 3; num++) {
  208. if (token != NULL) {
  209. pr_info("[secgpio_dvs] GPIO Control TOKEN = %s\n",
  210. token);
  211. gpio_ctrl[num] = atoi(token);
  212. token = strtok(NULL, comp);
  213. }
  214. pr_info("[secgpio_dvs] GPIO Control[%d] = %d\n",
  215. num, gpio_ctrl[num]);
  216. }
  217. /*
  218. gpio_ctrl[0] = IN/OUT, gpio_ctrl[1] = GPIO NUMBER,
  219. gpio_ctrl[2] = L/H
  220. */
  221. if (gpio_ctrl[0] == 1) {
  222. gpio_request(gpio_ctrl[1], "gpio_output_test_on");
  223. gpio_direction_input(gpio_ctrl[1]);
  224. gpio_free(gpio_ctrl[1]);
  225. } else {
  226. gpio_request(gpio_ctrl[1], "gpio_output_test_on");
  227. gpio_direction_output(gpio_ctrl[1], 1);
  228. gpio_free(gpio_ctrl[1]);
  229. if (gpio_ctrl[2] == 1) {
  230. gpio_request(gpio_ctrl[1], "gpio_output_test_on");
  231. gpio_set_value(gpio_ctrl[1], 1);
  232. gpio_free(gpio_ctrl[1]);
  233. } else if (gpio_ctrl[2] == 0) {
  234. gpio_request(gpio_ctrl[1], "gpio_output_test_off");
  235. gpio_set_value(gpio_ctrl[1], 0);
  236. gpio_free(gpio_ctrl[1]);
  237. }
  238. }
  239. return size;
  240. }
  241. static ssize_t secgpio_checked_sleepgpio_read(
  242. struct device *dev, struct device_attribute *attr, char *buf)
  243. {
  244. struct gpio_dvs *gdvs = dev_get_drvdata(dev);
  245. if (gdvs->check_sleep)
  246. return snprintf(buf, PAGE_SIZE, "1");
  247. else
  248. return snprintf(buf, PAGE_SIZE, "0");
  249. }
  250. void gpio_dvs_check_initgpio(void)
  251. {
  252. if (gdvs_info && gdvs_info->check_gpio_status)
  253. gdvs_info->check_gpio_status(PHONE_INIT);
  254. }
  255. void gpio_dvs_check_sleepgpio(void)
  256. {
  257. if (unlikely(!gdvs_info->check_sleep)) {
  258. gdvs_info->check_gpio_status(PHONE_SLEEP);
  259. gdvs_info->check_sleep = true;
  260. }
  261. }
  262. static int secgpio_dvs_probe(struct platform_device *pdev)
  263. {
  264. int ret = 0;
  265. struct class *secgpio_dvs_class;
  266. struct device *secgpio_dotest;
  267. struct gpio_dvs *gdvs = dev_get_platdata(&pdev->dev);
  268. pr_info("[secgpio_dvs] %s has been created!!!\n", __func__);
  269. secgpio_dvs_class = class_create(THIS_MODULE, "secgpio_check");
  270. if (IS_ERR(secgpio_dvs_class)) {
  271. ret = PTR_ERR(secgpio_dvs_class);
  272. pr_err("Failed to create class(secgpio_check_all)");
  273. goto fail_out;
  274. }
  275. secgpio_dotest = device_create(secgpio_dvs_class,
  276. NULL, 0, NULL, "secgpio_check_all");
  277. if (IS_ERR(secgpio_dotest)) {
  278. ret = PTR_ERR(secgpio_dotest);
  279. pr_err("Failed to create device(secgpio_check_all)");
  280. goto fail1;
  281. }
  282. dev_set_drvdata(secgpio_dotest, gdvs);
  283. gdvs_info = gdvs;
  284. ret = sysfs_create_group(&secgpio_dotest->kobj,
  285. &secgpio_dvs_attr_group);
  286. if (ret) {
  287. pr_err("Failed to create sysfs group");
  288. goto fail2;
  289. }
  290. return ret;
  291. fail2:
  292. device_destroy(secgpio_dvs_class,0);
  293. fail1:
  294. class_destroy(secgpio_dvs_class);
  295. fail_out:
  296. if (ret)
  297. pr_err(" (err = %d)!\n", ret);
  298. return ret;
  299. }
  300. static int secgpio_dvs_remove(struct platform_device *pdev)
  301. {
  302. return 0;
  303. }
  304. static struct platform_driver secgpio_dvs = {
  305. .probe = secgpio_dvs_probe,
  306. .remove = secgpio_dvs_remove,
  307. .driver = {
  308. .name = "secgpio_dvs",
  309. .owner = THIS_MODULE,
  310. },
  311. };
  312. static int __init secgpio_dvs_init(void)
  313. {
  314. int ret;
  315. ret = platform_driver_register(&secgpio_dvs);
  316. pr_info("[secgpio_dvs] secgpio_dvs_init has been initialized!!!\n");
  317. return ret;
  318. }
  319. static void __exit secgpio_dvs_exit(void)
  320. {
  321. platform_driver_unregister(&secgpio_dvs);
  322. }
  323. module_init(secgpio_dvs_init);
  324. module_exit(secgpio_dvs_exit);
  325. MODULE_AUTHOR("intae.jun@samsung.com");
  326. MODULE_DESCRIPTION("BCM2165x GPIO debugging and verification");
  327. MODULE_LICENSE("GPL");