* updated kollision (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / architecture / powerpc64 / package / linux / 0060-ps3avmgr-char-device.patch
blob2f2775689ad26f8a39a775a13314e52becc87b22
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 #
4 # T2 SDE: architecture/powerpc64/package/.../0060-ps3avmgr-char-device.patch
5 # Copyright (C) 2019 The T2 SDE Project
6 #
7 # More information can be found in the files COPYING and README.
8 #
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 # --- T2-COPYRIGHT-NOTE-END ---
17 --- a/drivers/ps3/ps3av.c
18 +++ b/drivers/ps3/ps3av.c
19 @@ -13,6 +13,8 @@
20 #include <linux/ioctl.h>
21 #include <linux/fb.h>
22 #include <linux/slab.h>
23 +#include <linux/uaccess.h>
24 +#include <linux/miscdevice.h>
26 #include <asm/firmware.h>
27 #include <asm/ps3av.h>
28 @@ -23,6 +25,8 @@
29 #define BUFSIZE 4096 /* vuart buf size */
30 #define PS3AV_BUF_SIZE 512 /* max packet size */
32 +#define DEVICE_NAME "ps3avmngr"
34 static int safe_mode;
36 static int timeout = 5000; /* in msec ( 5 sec ) */
37 @@ -47,6 +51,8 @@ static struct ps3av {
38 struct ps3av_reply_hdr reply_hdr;
39 u8 raw[PS3AV_BUF_SIZE];
40 } recv_buf;
41 + struct miscdevice misc;
42 + int misc_ok;
43 } *ps3av;
45 /* color space */
46 @@ -919,6 +925,68 @@ int ps3av_audio_mute(int mute)
48 EXPORT_SYMBOL_GPL(ps3av_audio_mute);
50 +static ssize_t ps3av_misc_read(struct file *file, char __user *usrbuf,
51 + size_t count, loff_t *pos)
53 + char *buf;
54 + int result;
56 + buf = kmalloc(count, GFP_KERNEL);
57 + if (!buf)
58 + return -ENOMEM;
60 + result = ps3_vuart_read(ps3av->dev, buf, count);
61 + if (result)
62 + goto out;
64 + if (copy_to_user(usrbuf, buf, count)) {
65 + result = -EFAULT;
66 + goto out;
67 + }
69 + result = count;
71 +out:
73 + kfree(buf);
75 + return result;
78 +static ssize_t ps3av_misc_write(struct file *file, const char __user *usrbuf,
79 + size_t count, loff_t *pos)
81 + char *buf;
82 + int result;
84 + buf = kmalloc(count, GFP_KERNEL);
85 + if (!buf)
86 + return -ENOMEM;
88 + if (copy_from_user(buf, usrbuf, count)) {
89 + result = -EFAULT;
90 + goto out;
91 + }
93 + result = ps3_vuart_write(ps3av->dev, buf, count);
94 + if (result)
95 + goto out;
97 + result = count;
99 +out:
101 + kfree(buf);
103 + return result;
106 +static const struct file_operations ps3av_misc_fops = {
107 + .owner = THIS_MODULE,
108 + .read = ps3av_misc_read,
109 + .write = ps3av_misc_write,
112 static int ps3av_probe(struct ps3_system_bus_device *dev)
114 int res;
115 @@ -985,11 +1053,34 @@ static int ps3av_probe(struct ps3_system_bus_device *dev)
116 ps3av->ps3av_mode = id;
117 mutex_unlock(&ps3av->mutex);
119 + ps3av->misc.parent = &dev->core;
120 + ps3av->misc.minor = MISC_DYNAMIC_MINOR,
121 + ps3av->misc.name = DEVICE_NAME,
122 + ps3av->misc.fops = &ps3av_misc_fops,
124 + res = misc_register(&ps3av->misc);
125 + if (res) {
126 + dev_err(&dev->core, "%s:%u: misc_register failed %d\n",
127 + __func__, __LINE__, res);
128 + goto skip_misc;
131 + ps3av->misc_ok = 1;
133 + dev_info(&dev->core, "%s:%u: registered misc device %d\n",
134 + __func__, __LINE__, ps3av->misc.minor);
136 +skip_misc:
138 dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__);
140 return 0;
142 fail:
144 + if (ps3av->misc_ok)
145 + misc_deregister(&ps3av->misc);
147 kfree(ps3av);
148 ps3av = NULL;
149 return res;
150 @@ -999,6 +1090,9 @@ static int ps3av_remove(struct ps3_system_bus_device *dev)
152 dev_dbg(&dev->core, " -> %s:%d\n", __func__, __LINE__);
153 if (ps3av) {
154 + if (ps3av->misc_ok)
155 + misc_deregister(&ps3av->misc);
157 ps3av_cmd_fin();
158 flush_work(&ps3av->work);
159 kfree(ps3av);