upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / samsung_boot_mode / samsung_boot_mode.c
1 #include <linux/init.h>
2 #include <linux/module.h>
3 #include <linux/kernel.h>
4 #include <linux/fs.h>
5 #include <linux/errno.h>
6 #include <linux/fcntl.h>
7 #include <linux/slab.h>
8 #include <linux/platform_device.h>
9 #include <linux/miscdevice.h>
10 #include <linux/device.h>
11 #include <linux/cdev.h>
12 #include <linux/sched.h>
13 #include <linux/spinlock.h>
14
15 unsigned int samsung_fota_config=0;
16 unsigned int samsung_fus_config=0;
17 unsigned int samsung_rtl_config=0;
18
19 static struct samsung_boot_mode_context {
20         int ready;
21 } samsung_boot_mode_cxt;
22
23 // FOTA Boot
24 static ssize_t 
25 samsung_fota_config_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
26 {
27         if(NULL == buf || count == 0 || count > PAGE_SIZE)
28                 return -1;
29
30         if (strstr(buf, "fota_disable") != NULL) {
31                 samsung_fota_config=0;
32         }
33         else if(strstr(buf, "fota_enable") != NULL) {
34                 samsung_fota_config=1;
35         }
36
37         return 1;
38 }
39
40 static ssize_t 
41 samsung_fota_config_show(struct device *dev, struct device_attribute *attr, char *buf)
42 {
43         return sprintf(buf, "%d\n", samsung_fota_config);
44 }
45
46 // Firmware update service
47 static ssize_t 
48 samsung_fus_config_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
49 {
50        if(NULL == buf || count == 0 || count > PAGE_SIZE)
51                return -1;
52
53        if (strstr(buf, "fus_disable")!= NULL) {
54                samsung_fus_config=0;
55        }
56        else if(strstr(buf, "fus_enable") != NULL) {
57                samsung_fus_config=1;
58        }
59
60        return 1;
61 }
62
63 static ssize_t 
64 samsung_fus_config_show(struct device *dev, struct device_attribute *attr, char *buf)
65 {
66        return sprintf(buf, "%d\n", samsung_fus_config);
67 }
68
69 // Update mode
70 static ssize_t 
71 samsung_rtl_config_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
72 {
73        if(NULL == buf || count == 0 || count > PAGE_SIZE)
74                return -1;
75
76         if (strstr(buf, "rtl_disable")!= NULL) {
77                samsung_rtl_config=0;
78        }
79        else if(strstr(buf, "rtl_enable") != NULL) {
80                samsung_rtl_config=1;
81        }
82
83        return 1;
84 }
85
86 static ssize_t 
87 samsung_rtl_config_show(struct device *dev, struct device_attribute *attr, char *buf)
88 {
89         return sprintf(buf, "%d\n", samsung_rtl_config);
90 }
91
92
93 static DEVICE_ATTR(samsung_fota_config, S_IRUGO | S_IWUSR, samsung_fota_config_show, samsung_fota_config_store);
94 static DEVICE_ATTR(samsung_fus_config, S_IRUGO | S_IWUSR, samsung_fus_config_show, samsung_fus_config_store);
95 static DEVICE_ATTR(samsung_rtl_config, S_IRUGO | S_IWUSR, samsung_rtl_config_show, samsung_rtl_config_store);
96
97 static struct attribute *samsung_boot_mode_attrs[] = {
98         &dev_attr_samsung_fota_config.attr,
99         &dev_attr_samsung_fus_config.attr,
100         &dev_attr_samsung_rtl_config.attr,
101         NULL
102 };
103
104 static const struct attribute_group samsung_boot_mode_attr_group = {
105         .attrs = samsung_boot_mode_attrs,
106 };
107
108
109 static struct file_operations samsung_boot_mode_fops =
110 {
111         .owner          = THIS_MODULE,
112 };
113
114 static struct miscdevice samsung_boot_mode_device = {
115         .minor = MISC_DYNAMIC_MINOR,
116         .name = "samsung_boot_mode",
117         .fops = &samsung_boot_mode_fops,
118 };
119
120 /*
121  * The functions for inserting/removing us as a module.
122  */
123
124 static int __devinit samsung_boot_mode_probe(struct platform_device *pdev)
125 {
126         struct samsung_boot_mode_context *cxt = &samsung_boot_mode_cxt;
127         int ret = 0;
128         ret = misc_register(&samsung_boot_mode_device);
129         if (ret) {
130                 printk("samsung_boot_mode_device register failed\n");
131                 goto err_reg;
132         }
133                 
134         ret = sysfs_create_group(&pdev->dev.kobj, &samsung_boot_mode_attr_group);
135         if (ret) {
136                 printk("samsung_boot_mode sysfs_create_group failed\n");
137                 goto err_grp;
138         }
139
140         printk("samsung_boot_mode init done \n");
141         return 0;
142
143 err_grp:
144         misc_deregister(&samsung_boot_mode_device);
145 err_reg:
146         return ret;
147 }
148
149 static int __devexit samsung_boot_mode_remove(struct platform_device *pdev)
150 {
151         sysfs_remove_group(&pdev->dev.kobj, &samsung_boot_mode_attr_group);
152         misc_deregister(&samsung_boot_mode_device);
153         printk("samsung_boot_mode_exit done\n");
154         return 0;
155 }
156
157
158 static struct platform_driver samsung_boot_mode_driver = {
159        .probe          = samsung_boot_mode_probe,
160        .remove         = __devexit_p(samsung_boot_mode_remove),
161        .driver          = {
162                 .owner  = THIS_MODULE,
163                 .name   = "s3c_samsung_boot_mode",
164         },
165 };
166
167 int __init samsung_boot_mode_init(void)
168 {
169         printk("Samsung Boot Mode Setting Driver\n");
170         return platform_driver_register(&samsung_boot_mode_driver);
171 }
172
173 void __exit samsung_boot_mode_exit(void)
174 {
175         platform_driver_unregister(&samsung_boot_mode_driver);
176 }
177
178 module_init(samsung_boot_mode_init);
179 module_exit(samsung_boot_mode_exit);
180
181 MODULE_AUTHOR("Yeongil Jang <yg0577.jang@samsung.com>");
182 MODULE_DESCRIPTION("Virtual driver for changing booting mode");
183 MODULE_LICENSE("GPL");