aboutsummaryrefslogtreecommitdiff
path: root/drivers/misc/mediatek/boot/mt6735/mt_boot.c
blob: de65905b90bf1f2d7e94779523f981064eff7afc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#define pr_fmt(fmt) "["KBUILD_MODNAME"] " fmt
#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 <mach/mt_boot.h>
#include <mach/mt_reg_base.h>
#include <mach/mt_typedefs.h>
#include <asm/setup.h>

META_COM_TYPE g_meta_com_type = META_UNKNOWN_COM;
unsigned int g_meta_com_id = 0;
unsigned int g_meta_uart_port = 0;

struct meta_driver {
    struct device_driver driver;
    const struct platform_device_id *id_table;
};

static struct meta_driver meta_com_type_info = {
    .driver  = {
        .name = "meta_com_type_info",
        .bus = &platform_bus_type,
        .owner = THIS_MODULE,
    },
    .id_table = NULL,
};

static struct meta_driver meta_com_id_info = {
    .driver = {
        .name = "meta_com_id_info",
        .bus = &platform_bus_type,
        .owner = THIS_MODULE,
    },
    .id_table = NULL,
};

static struct meta_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

bool com_is_enable(void)  // usb android will check whether is com port enabled default. in normal boot it is default enabled.
{
    if (get_boot_mode() == NORMAL_BOOT) {
        return false;
	} else {
        return true;
	}
}

void set_meta_com(META_COM_TYPE type, unsigned int id)
{
    g_meta_com_type = type;
    g_meta_com_id = id;
}

META_COM_TYPE 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;
    BOOTMODE 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_notice("[%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_notice("[%s] No atag,meta found !\n", __func__);
    }
    else
        pr_notice("[%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");