1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 # T2 SDE: architecture/powerpc64/package/.../0060-ps3avmgr-char-device.patch
5 # Copyright (C) 2019 The T2 SDE Project
7 # More information can be found in the files COPYING and README.
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
15 # --- T2-COPYRIGHT-NOTE-END ---
17 --- a/drivers/ps3/ps3av.c
18 +++ b/drivers/ps3/ps3av.c
20 #include <linux/ioctl.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>
29 #define BUFSIZE 4096 /* vuart buf size */
30 #define PS3AV_BUF_SIZE 512 /* max packet size */
32 +#define DEVICE_NAME "ps3avmngr"
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];
41 + struct miscdevice misc;
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)
56 + buf = kmalloc(count, GFP_KERNEL);
60 + result = ps3_vuart_read(ps3av->dev, buf, count);
64 + if (copy_to_user(usrbuf, buf, count)) {
78 +static ssize_t ps3av_misc_write(struct file *file, const char __user *usrbuf,
79 + size_t count, loff_t *pos)
84 + buf = kmalloc(count, GFP_KERNEL);
88 + if (copy_from_user(buf, usrbuf, count)) {
93 + result = ps3_vuart_write(ps3av->dev, buf, count);
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)
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);
126 + dev_err(&dev->core, "%s:%u: misc_register failed %d\n",
127 + __func__, __LINE__, res);
131 + ps3av->misc_ok = 1;
133 + dev_info(&dev->core, "%s:%u: registered misc device %d\n",
134 + __func__, __LINE__, ps3av->misc.minor);
138 dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__);
144 + if (ps3av->misc_ok)
145 + misc_deregister(&ps3av->misc);
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__);
154 + if (ps3av->misc_ok)
155 + misc_deregister(&ps3av->misc);
158 flush_work(&ps3av->work);