| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- #define pr_fmt(fmt) "["KBUILD_MODNAME"] " fmt
- #include <linux/io.h>
- #include <linux/module.h>
- #include <linux/device.h>
- #include <linux/fs.h>
- #include <linux/cdev.h>
- #include <linux/interrupt.h>
- #include <linux/spinlock.h>
- #include <linux/uaccess.h>
- #include <linux/mm.h>
- #include <linux/kfifo.h>
- #include <linux/firmware.h>
- #include <linux/syscalls.h>
- #include <linux/uaccess.h>
- #include <linux/platform_device.h>
- #include <linux/proc_fs.h>
- #include <linux/of.h>
- #include <mt-plat/mt_boot.h>
- unsigned int g_meta_com_type = META_UNKNOWN_COM;
- unsigned int g_meta_com_id = 0;
- unsigned int g_meta_uart_port = 0;
- static struct platform_driver meta_com_type_info = {
- .driver = {
- .name = "meta_com_type_info",
- .bus = &platform_bus_type,
- .owner = THIS_MODULE,
- },
- .id_table = NULL,
- };
- static struct platform_driver meta_com_id_info = {
- .driver = {
- .name = "meta_com_id_info",
- .bus = &platform_bus_type,
- .owner = THIS_MODULE,
- },
- .id_table = NULL,
- };
- static struct platform_driver meta_uart_port_info = {
- .driver = {
- .name = "meta_uart_port_info",
- .bus = &platform_bus_type,
- .owner = THIS_MODULE,
- },
- .id_table = NULL,
- };
- #ifdef CONFIG_OF
- struct boot_tag_meta_com {
- u32 size;
- u32 tag;
- u32 meta_com_type; /* identify meta via uart or usb */
- u32 meta_com_id; /* multiple meta need to know com port id */
- u32 meta_uart_port; /* identify meta uart port number */
- };
- #endif
- /* usb android will check whether is com port enabled default.
- in normal boot it is default enabled. */
- bool com_is_enable(void)
- {
- if (get_boot_mode() == NORMAL_BOOT)
- return false;
- else
- return true;
- }
- unsigned int get_meta_com_type(void)
- {
- return g_meta_com_type;
- }
- unsigned int get_meta_com_id(void)
- {
- return g_meta_com_id;
- }
- unsigned int get_meta_uart_port(void)
- {
- return g_meta_uart_port;
- }
- static ssize_t meta_com_type_show(struct device_driver *driver, char *buf)
- {
- return sprintf(buf, "%d\n", g_meta_com_type);
- }
- static ssize_t meta_com_type_store(struct device_driver *driver, const char *buf, size_t count)
- {
- /*Do nothing */
- return count;
- }
- DRIVER_ATTR(meta_com_type_info, 0644, meta_com_type_show, meta_com_type_store);
- static ssize_t meta_com_id_show(struct device_driver *driver, char *buf)
- {
- return sprintf(buf, "%d\n", g_meta_com_id);
- }
- static ssize_t meta_com_id_store(struct device_driver *driver, const char *buf, size_t count)
- {
- /*Do nothing */
- return count;
- }
- DRIVER_ATTR(meta_com_id_info, 0644, meta_com_id_show, meta_com_id_store);
- static ssize_t meta_uart_port_show(struct device_driver *driver, char *buf)
- {
- return sprintf(buf, "%d\n", g_meta_uart_port);
- }
- static ssize_t meta_uart_port_store(struct device_driver *driver, const char *buf, size_t count)
- {
- /*Do nothing */
- return count;
- }
- DRIVER_ATTR(meta_uart_port_info, 0644, meta_uart_port_show, meta_uart_port_store);
- static int __init create_sysfs(void)
- {
- int ret;
- enum boot_mode_t bm = get_boot_mode();
- #ifdef CONFIG_OF
- if (of_chosen) {
- struct boot_tag_meta_com *tags;
- tags = (struct boot_tag_meta_com *)of_get_property(of_chosen, "atag,meta", NULL);
- if (tags) {
- g_meta_com_type = tags->meta_com_type;
- g_meta_com_id = tags->meta_com_id;
- g_meta_uart_port = tags->meta_uart_port;
- pr_debug
- ("[%s] g_meta_com_type = %d, g_meta_com_id = %d, g_meta_uart_port=%d.\n",
- __func__, g_meta_com_type, g_meta_com_id, g_meta_uart_port);
- } else
- pr_warn("[%s] No atag,meta found !\n", __func__);
- } else
- pr_warn("[%s] of_chosen is NULL !\n", __func__);
- #endif
- if (bm == META_BOOT || bm == ADVMETA_BOOT || bm == ATE_FACTORY_BOOT || bm == FACTORY_BOOT) {
- /* register driver and create sysfs files */
- ret = driver_register(&meta_com_type_info.driver);
- if (ret)
- pr_warn("fail to register META COM TYPE driver\n");
- ret =
- driver_create_file(&meta_com_type_info.driver, &driver_attr_meta_com_type_info);
- if (ret)
- pr_warn("fail to create META COM TPYE sysfs file\n");
- ret = driver_register(&meta_com_id_info.driver);
- if (ret)
- pr_warn("fail to register META COM ID driver\n");
- ret = driver_create_file(&meta_com_id_info.driver, &driver_attr_meta_com_id_info);
- if (ret)
- pr_warn("fail to create META COM ID sysfs file\n");
- ret = driver_register(&meta_uart_port_info.driver);
- if (ret)
- pr_warn("fail to register META UART PORT driver\n");
- ret =
- driver_create_file(&meta_uart_port_info.driver,
- &driver_attr_meta_uart_port_info);
- if (ret)
- pr_warn("fail to create META UART PORT sysfs file\n");
- }
- return 0;
- }
- static int __init boot_mod_init(void)
- {
- create_sysfs();
- return 0;
- }
- static void __exit boot_mod_exit(void)
- {
- }
- module_init(boot_mod_init);
- module_exit(boot_mod_exit);
- MODULE_DESCRIPTION("MTK Boot Information Querying Driver");
- MODULE_LICENSE("GPL");
|