]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/char/mxs_viim.c
ENGR00155179-2: Change imx_viim to mxs_viim.
[karo-tx-linux.git] / drivers / char / mxs_viim.c
1 /*
2  * Copyright (C) 2009-2011, 2014 Freescale Semiconductor, Inc. All Rights Reserved.
3  */
4
5 /*
6  * The code contained herein is licensed under the GNU General Public
7  * License. You may obtain a copy of the GNU General Public License
8  * Version 2 or later at the following locations:
9  *
10  * http://www.opensource.org/licenses/gpl-license.html
11  * http://www.gnu.org/copyleft/gpl.html
12  */
13
14 #include <linux/fs.h>
15 #include <linux/init.h>
16 #include <linux/platform_device.h>
17 #include <linux/err.h>
18 #include <linux/mm.h>
19 #include <linux/miscdevice.h>
20
21 static unsigned long iim_reg_base0, iim_reg_end0, iim_reg_size0;
22 static unsigned long iim_reg_base1, iim_reg_end1, iim_reg_size1;
23 static struct device *iim_dev;
24
25 /*!
26  * MXS Virtual IIM interface - memory map function
27  * This function maps one page size VIIM registers from VIIM base address0
28  * if the size of the required virtual memory space is less than or equal to
29  * one page size, otherwise this function will also map one page size VIIM
30  * registers from VIIM base address1.
31  *
32  * @param file       struct file *
33  * @param vma        structure vm_area_struct *
34  *
35  * @return           Return 0 on success or negative error code on error
36  */
37 static int mxs_viim_mmap(struct file *file, struct vm_area_struct *vma)
38 {
39         size_t size = vma->vm_end - vma->vm_start;
40
41         vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
42
43         /* Remap-pfn-range will mark the range VM_IO and VM_RESERVED */
44         if (remap_pfn_range(vma,
45                             vma->vm_start,
46                             iim_reg_base0 >> PAGE_SHIFT,
47                             iim_reg_size0,
48                             vma->vm_page_prot))
49                 return -EAGAIN;
50
51         if (size > iim_reg_size0) {
52                 if (remap_pfn_range(vma,
53                                     vma->vm_start + iim_reg_size0,
54                                     iim_reg_base1 >> PAGE_SHIFT,
55                                     iim_reg_size1,
56                                     vma->vm_page_prot))
57                         return -EAGAIN;
58         }
59
60         return 0;
61 }
62
63 /*!
64  * MXS Virtual IIM interface - open function
65  *
66  * @param inode      struct inode *
67  * @param filp       struct file *
68  *
69  * @return           Return 0 on success or negative error code on error
70  */
71 static int mxs_viim_open(struct inode *inode, struct file *filp)
72 {
73         return 0;
74 }
75
76 /*!
77  * MXS Virtual IIM interface - release function
78  *
79  * @param inode      struct inode *
80  * @param filp       struct file *
81  *
82  * @return           Return 0 on success or negative error code on error
83  */
84 static int mxs_viim_release(struct inode *inode, struct file *filp)
85 {
86         return 0;
87 }
88
89 static const struct file_operations mxs_viim_fops = {
90         .mmap = mxs_viim_mmap,
91         .open = mxs_viim_open,
92         .release = mxs_viim_release,
93 };
94
95 static struct miscdevice mxs_viim_miscdev = {
96         .minor = MISC_DYNAMIC_MINOR,
97         .name = "mxs_viim",
98         .fops = &mxs_viim_fops,
99 };
100
101 /*!
102  * This function is called by the driver framework to get virtual iim base/end
103  * address and register iim misc device.
104  *
105  * @param       dev     The device structure for Virtual IIM passed in by the
106  *                      driver framework.
107  *
108  * @return      Returns 0 on success or negative error code on error
109  */
110 static int mxs_viim_probe(struct platform_device *pdev)
111 {
112         struct resource *res;
113         int ret;
114
115         iim_dev = &pdev->dev;
116
117         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
118         if (IS_ERR(res)) {
119                 dev_err(iim_dev, "Unable to get Virtual IIM resource 0\n");
120                 return -ENODEV;
121         }
122
123         iim_reg_base0 = res->start;
124         iim_reg_end0 = res->end;
125         iim_reg_size0 = iim_reg_end0 - iim_reg_base0 + 1;
126
127         res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
128         if (IS_ERR(res)) {
129                 dev_err(iim_dev, "Unable to get Virtual IIM resource 1\n");
130                 return -ENODEV;
131         }
132
133         iim_reg_base1 = res->start;
134         iim_reg_end1 = res->end;
135         iim_reg_size1 = iim_reg_end1 - iim_reg_base1 + 1;
136
137         ret = misc_register(&mxs_viim_miscdev);
138         if (ret)
139                 return ret;
140
141         return 0;
142 }
143
144 static int mxs_viim_remove(struct platform_device *pdev)
145 {
146         misc_deregister(&mxs_viim_miscdev);
147         return 0;
148 }
149
150 static struct platform_driver mxs_viim_driver = {
151         .driver = {
152                    .owner = THIS_MODULE,
153                    .name = "mxs_viim",
154                    },
155         .probe = mxs_viim_probe,
156         .remove = mxs_viim_remove,
157 };
158
159 static int __init mxs_viim_dev_init(void)
160 {
161         return platform_driver_register(&mxs_viim_driver);
162 }
163
164 static void __exit mxs_viim_dev_cleanup(void)
165 {
166         platform_driver_unregister(&mxs_viim_driver);
167 }
168
169 module_init(mxs_viim_dev_init);
170 module_exit(mxs_viim_dev_cleanup);
171
172 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
173 MODULE_DESCRIPTION("IMX Virtual IIM driver");
174 MODULE_LICENSE("GPL");
175 MODULE_ALIAS_MISCDEV(MISC_DYNAMIC_MINOR);