197fb5e8dSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2d1de6d6cSBjorn Andersson /*
3d1de6d6cSBjorn Andersson * Copyright (c) 2017 Linaro Ltd.
4d1de6d6cSBjorn Andersson */
5d1de6d6cSBjorn Andersson
6d1de6d6cSBjorn Andersson #include <linux/kernel.h>
7d1de6d6cSBjorn Andersson #include <linux/cdev.h>
8d1de6d6cSBjorn Andersson #include <linux/err.h>
9d1de6d6cSBjorn Andersson #include <linux/module.h>
10d1de6d6cSBjorn Andersson #include <linux/platform_device.h>
11d1de6d6cSBjorn Andersson #include <linux/of.h>
12d1de6d6cSBjorn Andersson #include <linux/of_reserved_mem.h>
13d1de6d6cSBjorn Andersson #include <linux/dma-mapping.h>
14d1de6d6cSBjorn Andersson #include <linux/slab.h>
15d1de6d6cSBjorn Andersson #include <linux/uaccess.h>
16d1de6d6cSBjorn Andersson #include <linux/io.h>
173bf90ecaSElliot Berman #include <linux/firmware/qcom/qcom_scm.h>
18d1de6d6cSBjorn Andersson
19d1de6d6cSBjorn Andersson #define QCOM_RMTFS_MEM_DEV_MAX (MINORMASK + 1)
20e656cd0bSLoic Poulain #define NUM_MAX_VMIDS 2
21d1de6d6cSBjorn Andersson
22d1de6d6cSBjorn Andersson static dev_t qcom_rmtfs_mem_major;
23d1de6d6cSBjorn Andersson
24d1de6d6cSBjorn Andersson struct qcom_rmtfs_mem {
25d1de6d6cSBjorn Andersson struct device dev;
26d1de6d6cSBjorn Andersson struct cdev cdev;
27d1de6d6cSBjorn Andersson
28d1de6d6cSBjorn Andersson void *base;
29d1de6d6cSBjorn Andersson phys_addr_t addr;
30d1de6d6cSBjorn Andersson phys_addr_t size;
31d1de6d6cSBjorn Andersson
32d1de6d6cSBjorn Andersson unsigned int client_id;
33fa65f804SBjorn Andersson
34968a26a0SElliot Berman u64 perms;
35d1de6d6cSBjorn Andersson };
36d1de6d6cSBjorn Andersson
37d1de6d6cSBjorn Andersson static ssize_t qcom_rmtfs_mem_show(struct device *dev,
38d1de6d6cSBjorn Andersson struct device_attribute *attr,
39d1de6d6cSBjorn Andersson char *buf);
40d1de6d6cSBjorn Andersson
41f58b0f9dSEvan Green static DEVICE_ATTR(phys_addr, 0444, qcom_rmtfs_mem_show, NULL);
42f58b0f9dSEvan Green static DEVICE_ATTR(size, 0444, qcom_rmtfs_mem_show, NULL);
43f58b0f9dSEvan Green static DEVICE_ATTR(client_id, 0444, qcom_rmtfs_mem_show, NULL);
44d1de6d6cSBjorn Andersson
qcom_rmtfs_mem_show(struct device * dev,struct device_attribute * attr,char * buf)45d1de6d6cSBjorn Andersson static ssize_t qcom_rmtfs_mem_show(struct device *dev,
46d1de6d6cSBjorn Andersson struct device_attribute *attr,
47d1de6d6cSBjorn Andersson char *buf)
48d1de6d6cSBjorn Andersson {
49d1de6d6cSBjorn Andersson struct qcom_rmtfs_mem *rmtfs_mem = container_of(dev,
50d1de6d6cSBjorn Andersson struct qcom_rmtfs_mem,
51d1de6d6cSBjorn Andersson dev);
52d1de6d6cSBjorn Andersson
53d1de6d6cSBjorn Andersson if (attr == &dev_attr_phys_addr)
54d1de6d6cSBjorn Andersson return sprintf(buf, "%pa\n", &rmtfs_mem->addr);
55d1de6d6cSBjorn Andersson if (attr == &dev_attr_size)
56d1de6d6cSBjorn Andersson return sprintf(buf, "%pa\n", &rmtfs_mem->size);
57d1de6d6cSBjorn Andersson if (attr == &dev_attr_client_id)
58d1de6d6cSBjorn Andersson return sprintf(buf, "%d\n", rmtfs_mem->client_id);
59d1de6d6cSBjorn Andersson
60d1de6d6cSBjorn Andersson return -EINVAL;
61d1de6d6cSBjorn Andersson }
62d1de6d6cSBjorn Andersson
63d1de6d6cSBjorn Andersson static struct attribute *qcom_rmtfs_mem_attrs[] = {
64d1de6d6cSBjorn Andersson &dev_attr_phys_addr.attr,
65d1de6d6cSBjorn Andersson &dev_attr_size.attr,
66d1de6d6cSBjorn Andersson &dev_attr_client_id.attr,
67d1de6d6cSBjorn Andersson NULL
68d1de6d6cSBjorn Andersson };
69d1de6d6cSBjorn Andersson ATTRIBUTE_GROUPS(qcom_rmtfs_mem);
70d1de6d6cSBjorn Andersson
qcom_rmtfs_mem_open(struct inode * inode,struct file * filp)71d1de6d6cSBjorn Andersson static int qcom_rmtfs_mem_open(struct inode *inode, struct file *filp)
72d1de6d6cSBjorn Andersson {
73d1de6d6cSBjorn Andersson struct qcom_rmtfs_mem *rmtfs_mem = container_of(inode->i_cdev,
74d1de6d6cSBjorn Andersson struct qcom_rmtfs_mem,
75d1de6d6cSBjorn Andersson cdev);
76d1de6d6cSBjorn Andersson
77d1de6d6cSBjorn Andersson get_device(&rmtfs_mem->dev);
78d1de6d6cSBjorn Andersson filp->private_data = rmtfs_mem;
79d1de6d6cSBjorn Andersson
80d1de6d6cSBjorn Andersson return 0;
81d1de6d6cSBjorn Andersson }
qcom_rmtfs_mem_read(struct file * filp,char __user * buf,size_t count,loff_t * f_pos)82d1de6d6cSBjorn Andersson static ssize_t qcom_rmtfs_mem_read(struct file *filp,
83d1de6d6cSBjorn Andersson char __user *buf, size_t count, loff_t *f_pos)
84d1de6d6cSBjorn Andersson {
85d1de6d6cSBjorn Andersson struct qcom_rmtfs_mem *rmtfs_mem = filp->private_data;
86d1de6d6cSBjorn Andersson
87d1de6d6cSBjorn Andersson if (*f_pos >= rmtfs_mem->size)
88d1de6d6cSBjorn Andersson return 0;
89d1de6d6cSBjorn Andersson
90d1de6d6cSBjorn Andersson if (*f_pos + count >= rmtfs_mem->size)
91d1de6d6cSBjorn Andersson count = rmtfs_mem->size - *f_pos;
92d1de6d6cSBjorn Andersson
93d1de6d6cSBjorn Andersson if (copy_to_user(buf, rmtfs_mem->base + *f_pos, count))
94d1de6d6cSBjorn Andersson return -EFAULT;
95d1de6d6cSBjorn Andersson
96d1de6d6cSBjorn Andersson *f_pos += count;
97d1de6d6cSBjorn Andersson return count;
98d1de6d6cSBjorn Andersson }
99d1de6d6cSBjorn Andersson
qcom_rmtfs_mem_write(struct file * filp,const char __user * buf,size_t count,loff_t * f_pos)100d1de6d6cSBjorn Andersson static ssize_t qcom_rmtfs_mem_write(struct file *filp,
101d1de6d6cSBjorn Andersson const char __user *buf, size_t count,
102d1de6d6cSBjorn Andersson loff_t *f_pos)
103d1de6d6cSBjorn Andersson {
104d1de6d6cSBjorn Andersson struct qcom_rmtfs_mem *rmtfs_mem = filp->private_data;
105d1de6d6cSBjorn Andersson
106d1de6d6cSBjorn Andersson if (*f_pos >= rmtfs_mem->size)
107d1de6d6cSBjorn Andersson return 0;
108d1de6d6cSBjorn Andersson
109d1de6d6cSBjorn Andersson if (*f_pos + count >= rmtfs_mem->size)
110d1de6d6cSBjorn Andersson count = rmtfs_mem->size - *f_pos;
111d1de6d6cSBjorn Andersson
112d1de6d6cSBjorn Andersson if (copy_from_user(rmtfs_mem->base + *f_pos, buf, count))
113d1de6d6cSBjorn Andersson return -EFAULT;
114d1de6d6cSBjorn Andersson
115d1de6d6cSBjorn Andersson *f_pos += count;
116d1de6d6cSBjorn Andersson return count;
117d1de6d6cSBjorn Andersson }
118d1de6d6cSBjorn Andersson
qcom_rmtfs_mem_release(struct inode * inode,struct file * filp)119d1de6d6cSBjorn Andersson static int qcom_rmtfs_mem_release(struct inode *inode, struct file *filp)
120d1de6d6cSBjorn Andersson {
121d1de6d6cSBjorn Andersson struct qcom_rmtfs_mem *rmtfs_mem = filp->private_data;
122d1de6d6cSBjorn Andersson
123d1de6d6cSBjorn Andersson put_device(&rmtfs_mem->dev);
124d1de6d6cSBjorn Andersson
125d1de6d6cSBjorn Andersson return 0;
126d1de6d6cSBjorn Andersson }
127d1de6d6cSBjorn Andersson
128b4aa93bcSEvan Green static struct class rmtfs_class = {
129b4aa93bcSEvan Green .name = "rmtfs",
130b4aa93bcSEvan Green };
131b4aa93bcSEvan Green
qcom_rmtfs_mem_mmap(struct file * filep,struct vm_area_struct * vma)1328da3daaaSAnkit Jain static int qcom_rmtfs_mem_mmap(struct file *filep, struct vm_area_struct *vma)
1338da3daaaSAnkit Jain {
1348da3daaaSAnkit Jain struct qcom_rmtfs_mem *rmtfs_mem = filep->private_data;
1358da3daaaSAnkit Jain
1368da3daaaSAnkit Jain if (vma->vm_end - vma->vm_start > rmtfs_mem->size) {
1378da3daaaSAnkit Jain dev_dbg(&rmtfs_mem->dev,
1388da3daaaSAnkit Jain "vm_end[%lu] - vm_start[%lu] [%lu] > mem->size[%pa]\n",
1398da3daaaSAnkit Jain vma->vm_end, vma->vm_start,
1408da3daaaSAnkit Jain (vma->vm_end - vma->vm_start), &rmtfs_mem->size);
1418da3daaaSAnkit Jain return -EINVAL;
1428da3daaaSAnkit Jain }
1438da3daaaSAnkit Jain
1448da3daaaSAnkit Jain vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
1458da3daaaSAnkit Jain return remap_pfn_range(vma,
1468da3daaaSAnkit Jain vma->vm_start,
1478da3daaaSAnkit Jain rmtfs_mem->addr >> PAGE_SHIFT,
1488da3daaaSAnkit Jain vma->vm_end - vma->vm_start,
1498da3daaaSAnkit Jain vma->vm_page_prot);
1508da3daaaSAnkit Jain }
1518da3daaaSAnkit Jain
152d1de6d6cSBjorn Andersson static const struct file_operations qcom_rmtfs_mem_fops = {
153d1de6d6cSBjorn Andersson .owner = THIS_MODULE,
154d1de6d6cSBjorn Andersson .open = qcom_rmtfs_mem_open,
155d1de6d6cSBjorn Andersson .read = qcom_rmtfs_mem_read,
156d1de6d6cSBjorn Andersson .write = qcom_rmtfs_mem_write,
157d1de6d6cSBjorn Andersson .release = qcom_rmtfs_mem_release,
158d1de6d6cSBjorn Andersson .llseek = default_llseek,
1598da3daaaSAnkit Jain .mmap = qcom_rmtfs_mem_mmap,
160d1de6d6cSBjorn Andersson };
161d1de6d6cSBjorn Andersson
qcom_rmtfs_mem_release_device(struct device * dev)162d1de6d6cSBjorn Andersson static void qcom_rmtfs_mem_release_device(struct device *dev)
163d1de6d6cSBjorn Andersson {
164d1de6d6cSBjorn Andersson struct qcom_rmtfs_mem *rmtfs_mem = container_of(dev,
165d1de6d6cSBjorn Andersson struct qcom_rmtfs_mem,
166d1de6d6cSBjorn Andersson dev);
167d1de6d6cSBjorn Andersson
168d1de6d6cSBjorn Andersson kfree(rmtfs_mem);
169d1de6d6cSBjorn Andersson }
170d1de6d6cSBjorn Andersson
qcom_rmtfs_mem_probe(struct platform_device * pdev)171d1de6d6cSBjorn Andersson static int qcom_rmtfs_mem_probe(struct platform_device *pdev)
172d1de6d6cSBjorn Andersson {
173d1de6d6cSBjorn Andersson struct device_node *node = pdev->dev.of_node;
174e656cd0bSLoic Poulain struct qcom_scm_vmperm perms[NUM_MAX_VMIDS + 1];
175d1de6d6cSBjorn Andersson struct reserved_mem *rmem;
176d1de6d6cSBjorn Andersson struct qcom_rmtfs_mem *rmtfs_mem;
177d1de6d6cSBjorn Andersson u32 client_id;
17894700741SLuca Weiss u32 vmid[NUM_MAX_VMIDS];
17994700741SLuca Weiss int num_vmids;
180e656cd0bSLoic Poulain int ret, i;
181d1de6d6cSBjorn Andersson
182d1de6d6cSBjorn Andersson rmem = of_reserved_mem_lookup(node);
183d1de6d6cSBjorn Andersson if (!rmem) {
184d1de6d6cSBjorn Andersson dev_err(&pdev->dev, "failed to acquire memory region\n");
185d1de6d6cSBjorn Andersson return -EINVAL;
186d1de6d6cSBjorn Andersson }
187d1de6d6cSBjorn Andersson
188d1de6d6cSBjorn Andersson ret = of_property_read_u32(node, "qcom,client-id", &client_id);
189d1de6d6cSBjorn Andersson if (ret) {
190d1de6d6cSBjorn Andersson dev_err(&pdev->dev, "failed to parse \"qcom,client-id\"\n");
191d1de6d6cSBjorn Andersson return ret;
192d1de6d6cSBjorn Andersson
193d1de6d6cSBjorn Andersson }
194d1de6d6cSBjorn Andersson
195d1de6d6cSBjorn Andersson rmtfs_mem = kzalloc(sizeof(*rmtfs_mem), GFP_KERNEL);
196d1de6d6cSBjorn Andersson if (!rmtfs_mem)
197d1de6d6cSBjorn Andersson return -ENOMEM;
198d1de6d6cSBjorn Andersson
199d1de6d6cSBjorn Andersson rmtfs_mem->addr = rmem->base;
200d1de6d6cSBjorn Andersson rmtfs_mem->client_id = client_id;
201d1de6d6cSBjorn Andersson rmtfs_mem->size = rmem->size;
202d1de6d6cSBjorn Andersson
203d1de6d6cSBjorn Andersson device_initialize(&rmtfs_mem->dev);
204d1de6d6cSBjorn Andersson rmtfs_mem->dev.parent = &pdev->dev;
205d1de6d6cSBjorn Andersson rmtfs_mem->dev.groups = qcom_rmtfs_mem_groups;
20678ee559dSJohan Hovold rmtfs_mem->dev.release = qcom_rmtfs_mem_release_device;
207d1de6d6cSBjorn Andersson
208d1de6d6cSBjorn Andersson rmtfs_mem->base = devm_memremap(&rmtfs_mem->dev, rmtfs_mem->addr,
209d1de6d6cSBjorn Andersson rmtfs_mem->size, MEMREMAP_WC);
210d1de6d6cSBjorn Andersson if (IS_ERR(rmtfs_mem->base)) {
211d1de6d6cSBjorn Andersson dev_err(&pdev->dev, "failed to remap rmtfs_mem region\n");
212d1de6d6cSBjorn Andersson ret = PTR_ERR(rmtfs_mem->base);
213d1de6d6cSBjorn Andersson goto put_device;
214d1de6d6cSBjorn Andersson }
215d1de6d6cSBjorn Andersson
216d1de6d6cSBjorn Andersson cdev_init(&rmtfs_mem->cdev, &qcom_rmtfs_mem_fops);
217d1de6d6cSBjorn Andersson rmtfs_mem->cdev.owner = THIS_MODULE;
218d1de6d6cSBjorn Andersson
219d1de6d6cSBjorn Andersson dev_set_name(&rmtfs_mem->dev, "qcom_rmtfs_mem%d", client_id);
220d1de6d6cSBjorn Andersson rmtfs_mem->dev.id = client_id;
221b4aa93bcSEvan Green rmtfs_mem->dev.class = &rmtfs_class;
222d1de6d6cSBjorn Andersson rmtfs_mem->dev.devt = MKDEV(MAJOR(qcom_rmtfs_mem_major), client_id);
223d1de6d6cSBjorn Andersson
224d1de6d6cSBjorn Andersson ret = cdev_device_add(&rmtfs_mem->cdev, &rmtfs_mem->dev);
225d1de6d6cSBjorn Andersson if (ret) {
226d1de6d6cSBjorn Andersson dev_err(&pdev->dev, "failed to add cdev: %d\n", ret);
227d1de6d6cSBjorn Andersson goto put_device;
228d1de6d6cSBjorn Andersson }
229d1de6d6cSBjorn Andersson
230e656cd0bSLoic Poulain num_vmids = of_property_count_u32_elems(node, "qcom,vmid");
231749d56bdSLuca Weiss if (num_vmids == -EINVAL) {
232749d56bdSLuca Weiss /* qcom,vmid is optional */
233749d56bdSLuca Weiss num_vmids = 0;
234749d56bdSLuca Weiss } else if (num_vmids < 0) {
23594700741SLuca Weiss dev_err(&pdev->dev, "failed to count qcom,vmid elements: %d\n", num_vmids);
236*7b374a2fSDan Carpenter ret = num_vmids;
237e656cd0bSLoic Poulain goto remove_cdev;
238e656cd0bSLoic Poulain } else if (num_vmids > NUM_MAX_VMIDS) {
239e656cd0bSLoic Poulain dev_warn(&pdev->dev,
240e656cd0bSLoic Poulain "too many VMIDs (%d) specified! Only mapping first %d entries\n",
241e656cd0bSLoic Poulain num_vmids, NUM_MAX_VMIDS);
242e656cd0bSLoic Poulain num_vmids = NUM_MAX_VMIDS;
243e656cd0bSLoic Poulain }
244e656cd0bSLoic Poulain
245e656cd0bSLoic Poulain ret = of_property_read_u32_array(node, "qcom,vmid", vmid, num_vmids);
246fa65f804SBjorn Andersson if (ret < 0 && ret != -EINVAL) {
247fa65f804SBjorn Andersson dev_err(&pdev->dev, "failed to parse qcom,vmid\n");
248fa65f804SBjorn Andersson goto remove_cdev;
249fa65f804SBjorn Andersson } else if (!ret) {
250137dc584SBjorn Andersson if (!qcom_scm_is_available()) {
251137dc584SBjorn Andersson ret = -EPROBE_DEFER;
252137dc584SBjorn Andersson goto remove_cdev;
253137dc584SBjorn Andersson }
254137dc584SBjorn Andersson
255fa65f804SBjorn Andersson perms[0].vmid = QCOM_SCM_VMID_HLOS;
256fa65f804SBjorn Andersson perms[0].perm = QCOM_SCM_PERM_RW;
257e656cd0bSLoic Poulain
258e656cd0bSLoic Poulain for (i = 0; i < num_vmids; i++) {
259e656cd0bSLoic Poulain perms[i + 1].vmid = vmid[i];
260e656cd0bSLoic Poulain perms[i + 1].perm = QCOM_SCM_PERM_RW;
261e656cd0bSLoic Poulain }
262fa65f804SBjorn Andersson
263fa65f804SBjorn Andersson rmtfs_mem->perms = BIT(QCOM_SCM_VMID_HLOS);
264fa65f804SBjorn Andersson ret = qcom_scm_assign_mem(rmtfs_mem->addr, rmtfs_mem->size,
265e656cd0bSLoic Poulain &rmtfs_mem->perms, perms, num_vmids + 1);
266fa65f804SBjorn Andersson if (ret < 0) {
267fa65f804SBjorn Andersson dev_err(&pdev->dev, "assign memory failed\n");
268fa65f804SBjorn Andersson goto remove_cdev;
269fa65f804SBjorn Andersson }
270fa65f804SBjorn Andersson }
271fa65f804SBjorn Andersson
272d1de6d6cSBjorn Andersson dev_set_drvdata(&pdev->dev, rmtfs_mem);
273d1de6d6cSBjorn Andersson
274d1de6d6cSBjorn Andersson return 0;
275d1de6d6cSBjorn Andersson
276fa65f804SBjorn Andersson remove_cdev:
277fa65f804SBjorn Andersson cdev_device_del(&rmtfs_mem->cdev, &rmtfs_mem->dev);
278d1de6d6cSBjorn Andersson put_device:
279d1de6d6cSBjorn Andersson put_device(&rmtfs_mem->dev);
280d1de6d6cSBjorn Andersson
281d1de6d6cSBjorn Andersson return ret;
282d1de6d6cSBjorn Andersson }
283d1de6d6cSBjorn Andersson
qcom_rmtfs_mem_remove(struct platform_device * pdev)284d1de6d6cSBjorn Andersson static int qcom_rmtfs_mem_remove(struct platform_device *pdev)
285d1de6d6cSBjorn Andersson {
286d1de6d6cSBjorn Andersson struct qcom_rmtfs_mem *rmtfs_mem = dev_get_drvdata(&pdev->dev);
287fa65f804SBjorn Andersson struct qcom_scm_vmperm perm;
288fa65f804SBjorn Andersson
289fa65f804SBjorn Andersson if (rmtfs_mem->perms) {
290fa65f804SBjorn Andersson perm.vmid = QCOM_SCM_VMID_HLOS;
291fa65f804SBjorn Andersson perm.perm = QCOM_SCM_PERM_RW;
292fa65f804SBjorn Andersson
293fa65f804SBjorn Andersson qcom_scm_assign_mem(rmtfs_mem->addr, rmtfs_mem->size,
294fa65f804SBjorn Andersson &rmtfs_mem->perms, &perm, 1);
295fa65f804SBjorn Andersson }
296d1de6d6cSBjorn Andersson
297d1de6d6cSBjorn Andersson cdev_device_del(&rmtfs_mem->cdev, &rmtfs_mem->dev);
298d1de6d6cSBjorn Andersson put_device(&rmtfs_mem->dev);
299d1de6d6cSBjorn Andersson
300d1de6d6cSBjorn Andersson return 0;
301d1de6d6cSBjorn Andersson }
302d1de6d6cSBjorn Andersson
303d1de6d6cSBjorn Andersson static const struct of_device_id qcom_rmtfs_mem_of_match[] = {
304d1de6d6cSBjorn Andersson { .compatible = "qcom,rmtfs-mem" },
305d1de6d6cSBjorn Andersson {}
306d1de6d6cSBjorn Andersson };
307d1de6d6cSBjorn Andersson MODULE_DEVICE_TABLE(of, qcom_rmtfs_mem_of_match);
308d1de6d6cSBjorn Andersson
309d1de6d6cSBjorn Andersson static struct platform_driver qcom_rmtfs_mem_driver = {
310d1de6d6cSBjorn Andersson .probe = qcom_rmtfs_mem_probe,
311d1de6d6cSBjorn Andersson .remove = qcom_rmtfs_mem_remove,
312d1de6d6cSBjorn Andersson .driver = {
313d1de6d6cSBjorn Andersson .name = "qcom_rmtfs_mem",
314d1de6d6cSBjorn Andersson .of_match_table = qcom_rmtfs_mem_of_match,
315d1de6d6cSBjorn Andersson },
316d1de6d6cSBjorn Andersson };
317d1de6d6cSBjorn Andersson
qcom_rmtfs_mem_init(void)318b4aa93bcSEvan Green static int __init qcom_rmtfs_mem_init(void)
319d1de6d6cSBjorn Andersson {
320d1de6d6cSBjorn Andersson int ret;
321d1de6d6cSBjorn Andersson
322b4aa93bcSEvan Green ret = class_register(&rmtfs_class);
323b4aa93bcSEvan Green if (ret)
324b4aa93bcSEvan Green return ret;
325b4aa93bcSEvan Green
326d1de6d6cSBjorn Andersson ret = alloc_chrdev_region(&qcom_rmtfs_mem_major, 0,
327d1de6d6cSBjorn Andersson QCOM_RMTFS_MEM_DEV_MAX, "qcom_rmtfs_mem");
328d1de6d6cSBjorn Andersson if (ret < 0) {
329d1de6d6cSBjorn Andersson pr_err("qcom_rmtfs_mem: failed to allocate char dev region\n");
330b4aa93bcSEvan Green goto unregister_class;
331d1de6d6cSBjorn Andersson }
332d1de6d6cSBjorn Andersson
333d1de6d6cSBjorn Andersson ret = platform_driver_register(&qcom_rmtfs_mem_driver);
334d1de6d6cSBjorn Andersson if (ret < 0) {
335d1de6d6cSBjorn Andersson pr_err("qcom_rmtfs_mem: failed to register rmtfs_mem driver\n");
336b4aa93bcSEvan Green goto unregister_chrdev;
337d1de6d6cSBjorn Andersson }
338d1de6d6cSBjorn Andersson
339b4aa93bcSEvan Green return 0;
340b4aa93bcSEvan Green
341b4aa93bcSEvan Green unregister_chrdev:
342b4aa93bcSEvan Green unregister_chrdev_region(qcom_rmtfs_mem_major, QCOM_RMTFS_MEM_DEV_MAX);
343b4aa93bcSEvan Green unregister_class:
344b4aa93bcSEvan Green class_unregister(&rmtfs_class);
345d1de6d6cSBjorn Andersson return ret;
346d1de6d6cSBjorn Andersson }
347d1de6d6cSBjorn Andersson module_init(qcom_rmtfs_mem_init);
348d1de6d6cSBjorn Andersson
qcom_rmtfs_mem_exit(void)349b4aa93bcSEvan Green static void __exit qcom_rmtfs_mem_exit(void)
350d1de6d6cSBjorn Andersson {
351d1de6d6cSBjorn Andersson platform_driver_unregister(&qcom_rmtfs_mem_driver);
352d1de6d6cSBjorn Andersson unregister_chrdev_region(qcom_rmtfs_mem_major, QCOM_RMTFS_MEM_DEV_MAX);
353b4aa93bcSEvan Green class_unregister(&rmtfs_class);
354d1de6d6cSBjorn Andersson }
355d1de6d6cSBjorn Andersson module_exit(qcom_rmtfs_mem_exit);
3563b229bdbSJesse Chan
3573b229bdbSJesse Chan MODULE_AUTHOR("Linaro Ltd");
3583b229bdbSJesse Chan MODULE_DESCRIPTION("Qualcomm Remote Filesystem memory driver");
3593b229bdbSJesse Chan MODULE_LICENSE("GPL v2");
360