mt_boot.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #define pr_fmt(fmt) "["KBUILD_MODNAME"] " fmt
  2. #include <linux/io.h>
  3. #include <linux/module.h>
  4. #include <linux/device.h>
  5. #include <linux/fs.h>
  6. #include <linux/cdev.h>
  7. #include <linux/interrupt.h>
  8. #include <linux/spinlock.h>
  9. #include <linux/uaccess.h>
  10. #include <linux/mm.h>
  11. #include <linux/kfifo.h>
  12. #include <linux/firmware.h>
  13. #include <linux/syscalls.h>
  14. #include <linux/uaccess.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/proc_fs.h>
  17. #include <linux/of.h>
  18. #include <mt-plat/mt_boot.h>
  19. unsigned int g_meta_com_type = META_UNKNOWN_COM;
  20. unsigned int g_meta_com_id = 0;
  21. unsigned int g_meta_uart_port = 0;
  22. static struct platform_driver meta_com_type_info = {
  23. .driver = {
  24. .name = "meta_com_type_info",
  25. .bus = &platform_bus_type,
  26. .owner = THIS_MODULE,
  27. },
  28. .id_table = NULL,
  29. };
  30. static struct platform_driver meta_com_id_info = {
  31. .driver = {
  32. .name = "meta_com_id_info",
  33. .bus = &platform_bus_type,
  34. .owner = THIS_MODULE,
  35. },
  36. .id_table = NULL,
  37. };
  38. static struct platform_driver meta_uart_port_info = {
  39. .driver = {
  40. .name = "meta_uart_port_info",
  41. .bus = &platform_bus_type,
  42. .owner = THIS_MODULE,
  43. },
  44. .id_table = NULL,
  45. };
  46. #ifdef CONFIG_OF
  47. struct boot_tag_meta_com {
  48. u32 size;
  49. u32 tag;
  50. u32 meta_com_type; /* identify meta via uart or usb */
  51. u32 meta_com_id; /* multiple meta need to know com port id */
  52. u32 meta_uart_port; /* identify meta uart port number */
  53. };
  54. #endif
  55. /* usb android will check whether is com port enabled default.
  56. in normal boot it is default enabled. */
  57. bool com_is_enable(void)
  58. {
  59. if (get_boot_mode() == NORMAL_BOOT)
  60. return false;
  61. else
  62. return true;
  63. }
  64. unsigned int get_meta_com_type(void)
  65. {
  66. return g_meta_com_type;
  67. }
  68. unsigned int get_meta_com_id(void)
  69. {
  70. return g_meta_com_id;
  71. }
  72. unsigned int get_meta_uart_port(void)
  73. {
  74. return g_meta_uart_port;
  75. }
  76. static ssize_t meta_com_type_show(struct device_driver *driver, char *buf)
  77. {
  78. return sprintf(buf, "%d\n", g_meta_com_type);
  79. }
  80. static ssize_t meta_com_type_store(struct device_driver *driver, const char *buf, size_t count)
  81. {
  82. /*Do nothing */
  83. return count;
  84. }
  85. DRIVER_ATTR(meta_com_type_info, 0644, meta_com_type_show, meta_com_type_store);
  86. static ssize_t meta_com_id_show(struct device_driver *driver, char *buf)
  87. {
  88. return sprintf(buf, "%d\n", g_meta_com_id);
  89. }
  90. static ssize_t meta_com_id_store(struct device_driver *driver, const char *buf, size_t count)
  91. {
  92. /*Do nothing */
  93. return count;
  94. }
  95. DRIVER_ATTR(meta_com_id_info, 0644, meta_com_id_show, meta_com_id_store);
  96. static ssize_t meta_uart_port_show(struct device_driver *driver, char *buf)
  97. {
  98. return sprintf(buf, "%d\n", g_meta_uart_port);
  99. }
  100. static ssize_t meta_uart_port_store(struct device_driver *driver, const char *buf, size_t count)
  101. {
  102. /*Do nothing */
  103. return count;
  104. }
  105. DRIVER_ATTR(meta_uart_port_info, 0644, meta_uart_port_show, meta_uart_port_store);
  106. static int __init create_sysfs(void)
  107. {
  108. int ret;
  109. enum boot_mode_t bm = get_boot_mode();
  110. #ifdef CONFIG_OF
  111. if (of_chosen) {
  112. struct boot_tag_meta_com *tags;
  113. tags = (struct boot_tag_meta_com *)of_get_property(of_chosen, "atag,meta", NULL);
  114. if (tags) {
  115. g_meta_com_type = tags->meta_com_type;
  116. g_meta_com_id = tags->meta_com_id;
  117. g_meta_uart_port = tags->meta_uart_port;
  118. pr_debug
  119. ("[%s] g_meta_com_type = %d, g_meta_com_id = %d, g_meta_uart_port=%d.\n",
  120. __func__, g_meta_com_type, g_meta_com_id, g_meta_uart_port);
  121. } else
  122. pr_warn("[%s] No atag,meta found !\n", __func__);
  123. } else
  124. pr_warn("[%s] of_chosen is NULL !\n", __func__);
  125. #endif
  126. if (bm == META_BOOT || bm == ADVMETA_BOOT || bm == ATE_FACTORY_BOOT || bm == FACTORY_BOOT) {
  127. /* register driver and create sysfs files */
  128. ret = driver_register(&meta_com_type_info.driver);
  129. if (ret)
  130. pr_warn("fail to register META COM TYPE driver\n");
  131. ret =
  132. driver_create_file(&meta_com_type_info.driver, &driver_attr_meta_com_type_info);
  133. if (ret)
  134. pr_warn("fail to create META COM TPYE sysfs file\n");
  135. ret = driver_register(&meta_com_id_info.driver);
  136. if (ret)
  137. pr_warn("fail to register META COM ID driver\n");
  138. ret = driver_create_file(&meta_com_id_info.driver, &driver_attr_meta_com_id_info);
  139. if (ret)
  140. pr_warn("fail to create META COM ID sysfs file\n");
  141. ret = driver_register(&meta_uart_port_info.driver);
  142. if (ret)
  143. pr_warn("fail to register META UART PORT driver\n");
  144. ret =
  145. driver_create_file(&meta_uart_port_info.driver,
  146. &driver_attr_meta_uart_port_info);
  147. if (ret)
  148. pr_warn("fail to create META UART PORT sysfs file\n");
  149. }
  150. return 0;
  151. }
  152. static int __init boot_mod_init(void)
  153. {
  154. create_sysfs();
  155. return 0;
  156. }
  157. static void __exit boot_mod_exit(void)
  158. {
  159. }
  160. module_init(boot_mod_init);
  161. module_exit(boot_mod_exit);
  162. MODULE_DESCRIPTION("MTK Boot Information Querying Driver");
  163. MODULE_LICENSE("GPL");