2 * Copyright (C) 2009-2011, 2014 Freescale Semiconductor, Inc. All Rights Reserved.
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:
10 * http://www.opensource.org/licenses/gpl-license.html
11 * http://www.gnu.org/copyleft/gpl.html
15 #include <linux/init.h>
16 #include <linux/platform_device.h>
17 #include <linux/err.h>
19 #include <linux/miscdevice.h>
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;
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.
32 * @param file struct file *
33 * @param vma structure vm_area_struct *
35 * @return Return 0 on success or negative error code on error
37 static int mxs_viim_mmap(struct file *file, struct vm_area_struct *vma)
39 size_t size = vma->vm_end - vma->vm_start;
41 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
43 /* Remap-pfn-range will mark the range VM_IO and VM_RESERVED */
44 if (remap_pfn_range(vma,
46 iim_reg_base0 >> PAGE_SHIFT,
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,
64 * MXS Virtual IIM interface - open function
66 * @param inode struct inode *
67 * @param filp struct file *
69 * @return Return 0 on success or negative error code on error
71 static int mxs_viim_open(struct inode *inode, struct file *filp)
77 * MXS Virtual IIM interface - release function
79 * @param inode struct inode *
80 * @param filp struct file *
82 * @return Return 0 on success or negative error code on error
84 static int mxs_viim_release(struct inode *inode, struct file *filp)
89 static const struct file_operations mxs_viim_fops = {
90 .mmap = mxs_viim_mmap,
91 .open = mxs_viim_open,
92 .release = mxs_viim_release,
95 static struct miscdevice mxs_viim_miscdev = {
96 .minor = MISC_DYNAMIC_MINOR,
98 .fops = &mxs_viim_fops,
102 * This function is called by the driver framework to get virtual iim base/end
103 * address and register iim misc device.
105 * @param dev The device structure for Virtual IIM passed in by the
108 * @return Returns 0 on success or negative error code on error
110 static int mxs_viim_probe(struct platform_device *pdev)
112 struct resource *res;
115 iim_dev = &pdev->dev;
117 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
119 dev_err(iim_dev, "Unable to get Virtual IIM resource 0\n");
123 iim_reg_base0 = res->start;
124 iim_reg_end0 = res->end;
125 iim_reg_size0 = iim_reg_end0 - iim_reg_base0 + 1;
127 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
129 dev_err(iim_dev, "Unable to get Virtual IIM resource 1\n");
133 iim_reg_base1 = res->start;
134 iim_reg_end1 = res->end;
135 iim_reg_size1 = iim_reg_end1 - iim_reg_base1 + 1;
137 ret = misc_register(&mxs_viim_miscdev);
144 static int mxs_viim_remove(struct platform_device *pdev)
146 misc_deregister(&mxs_viim_miscdev);
150 static struct platform_driver mxs_viim_driver = {
152 .owner = THIS_MODULE,
155 .probe = mxs_viim_probe,
156 .remove = mxs_viim_remove,
159 static int __init mxs_viim_dev_init(void)
161 return platform_driver_register(&mxs_viim_driver);
164 static void __exit mxs_viim_dev_cleanup(void)
166 platform_driver_unregister(&mxs_viim_driver);
169 module_init(mxs_viim_dev_init);
170 module_exit(mxs_viim_dev_cleanup);
172 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
173 MODULE_DESCRIPTION("IMX Virtual IIM driver");
174 MODULE_LICENSE("GPL");
175 MODULE_ALIAS_MISCDEV(MISC_DYNAMIC_MINOR);