tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / misc / sprd_srt / sprd_srt.c
1 #include <linux/module.h>
2 #include <linux/types.h>
3 #include <linux/fs.h>
4 #include <linux/errno.h>
5 #include <linux/mm.h>
6 #include <linux/sched.h>
7 #include <linux/init.h>
8 #include <linux/cdev.h>
9 #include <asm/io.h>
10 #include <asm/system.h>
11 #include <asm/uaccess.h>
12 #include <asm/processor.h>
13 #include <linux/slab.h>
14 #include <linux/workqueue.h>
15 #include <linux/delay.h>
16 #include <linux/device.h>
17 #include <linux/file.h>
18 #include <linux/kernel.h>
19 #include <linux/kmod.h>
20 #include <linux/ioctl.h>
21
22
23 /**********************************************************************************/
24 #define SRT_IOCTL_MAGIC 'e'
25 #define SRT_OPEN                        _IO(SRT_IOCTL_MAGIC, 1)
26 #define SRT_RELEASE                     _IO(SRT_IOCTL_MAGIC, 2)
27 #define SRT_ENABLE                      _IO(SRT_IOCTL_MAGIC, 3)
28 #define SRT_READ1                               _IOR(SRT_IOCTL_MAGIC, 4, struct srtinfo_struct)
29 #define SRT_READ2                               _IOR(SRT_IOCTL_MAGIC, 5, struct srtinfo_struct)
30 #define SRT_WRITE1                              _IOW(SRT_IOCTL_MAGIC, 6, struct srtinfo_struct)
31 #define SRT_WRITE2                              _IOW(SRT_IOCTL_MAGIC, 7, struct srtinfo_struct)
32
33 #include "sprd_srt.h"
34
35 /**********************************************************************************/
36 static struct srt_dev *g_srt_dev=0;
37 static int srt_open(struct inode *inode, struct file *filp)
38 {
39         return 0;
40 }
41 static int srt_release(struct inode *inode, struct file *filp)
42 {
43         return 0;
44 }
45 static ssize_t srt_read(struct file *filp, char __user *buf, size_t size, loff_t *ppos)
46 {
47         return 0;
48 }
49 static ssize_t srt_write(struct file *filp, const char __user *buf, size_t size, loff_t *ppos)
50 {
51         return 0;
52 }
53 static loff_t srt_llseek(struct file *filp, loff_t offset, int orig)
54 {
55         return 0;
56 }
57
58
59 static long srt_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
60 {
61         int i,ret=-1;
62         switch (cmd)
63         {
64         case SRT_READ1:
65                 break;
66         case SRT_READ2:
67                 break;
68         case SRT_WRITE1:
69                 break;
70         case SRT_WRITE2:
71                 break;
72         default:
73                 return  - EINVAL;
74         }
75
76         return 0;
77 }
78
79 static const struct file_operations srt_fops = {
80         .owner = THIS_MODULE,
81         .open = srt_open,
82         .release = srt_release,
83         .read = srt_read,
84         .write = srt_write,
85         .llseek = srt_llseek,
86         .unlocked_ioctl = srt_ioctl,
87 };
88 /**********************************************************************************/
89 int srt_init(void)
90 {
91         int err;
92         dev_t devno;
93
94         DEBUG_PRINT(LOG_TAG "%s Start\n", __func__);
95
96         g_srt_dev = kmalloc(sizeof(struct srt_dev), GFP_KERNEL);
97         if (!g_srt_dev)
98         {
99                 DEBUG_PRINT(LOG_TAG "mem alloc fail");
100                 return -1;
101         }
102         memset(g_srt_dev, 0, sizeof(struct srt_dev));
103         err = alloc_chrdev_region(&devno, 0, 1, "srt");
104         g_srt_dev->dev_major = MAJOR(devno);
105         if (err < 0)
106         {
107                 DEBUG_PRINT(LOG_TAG "alloc error=%d", err);
108                 return -1;
109         }
110         cdev_init(&g_srt_dev->cdev, &srt_fops);
111         g_srt_dev->cdev.owner = THIS_MODULE;
112         err = cdev_add(&g_srt_dev->cdev, devno, 1);
113         if (err)
114         {
115                 DEBUG_PRINT(LOG_TAG "cdev add=%d, error=%d", devno, err);
116                 return -1;
117         }
118         g_srt_dev->pClass = class_create(THIS_MODULE, "srt_class");
119         if (IS_ERR(g_srt_dev->pClass))
120         {
121                 DEBUG_PRINT(LOG_TAG "create class error\n");
122                 return -1;
123         }
124         g_srt_dev->pClassDev = device_create(g_srt_dev->pClass, NULL, devno, NULL, "srt_dev");
125         if (IS_ERR(g_srt_dev->pClassDev))
126         {
127                 DEBUG_PRINT(LOG_TAG "create class dev error\n");
128                 return -1;
129   }
130         DEBUG_PRINT(LOG_TAG "%s End\n", __func__);
131         return 0;
132 }
133
134 void srt_exit(void)
135 {
136         DEBUG_PRINT(LOG_TAG "%s\n", __func__);
137
138         cdev_del(&g_srt_dev->cdev);
139   device_destroy(g_srt_dev->pClass,  MKDEV(g_srt_dev->dev_major, 0));
140   class_destroy(g_srt_dev->pClass);
141         unregister_chrdev_region(MKDEV(g_srt_dev->dev_major, 0), 1);
142         kfree(g_srt_dev);
143         g_srt_dev=0;
144 }
145
146 module_init(srt_init);
147 module_exit(srt_exit);
148
149 MODULE_AUTHOR("jie.yang <jie.yang@spreadtrum.com>");
150 MODULE_DESCRIPTION("SRT");
151 MODULE_LICENSE("GPL");