forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/video/fbdev/udlfb.c
....@@ -1,13 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * udlfb.c -- Framebuffer driver for DisplayLink USB controller
34 *
45 * Copyright (C) 2009 Roberto De Ioris <roberto@unbit.it>
56 * Copyright (C) 2009 Jaya Kumar <jayakumar.lkml@gmail.com>
67 * Copyright (C) 2009 Bernie Thompson <bernie@plugable.com>
7
- *
8
- * This file is subject to the terms and conditions of the GNU General Public
9
- * License v2. See the file COPYING in the main directory of this archive for
10
- * more details.
118 *
129 * Layout is based on skeletonfb by James Simmons and Geert Uytterhoeven,
1310 * usb-skeleton by GregKH.
....@@ -29,6 +26,8 @@
2926 #include <asm/unaligned.h>
3027 #include <video/udlfb.h>
3128 #include "edid.h"
29
+
30
+#define OUT_EP_NUM 1 /* The endpoint number we will use */
3231
3332 static const struct fb_fix_screeninfo dlfb_fix = {
3433 .id = "udlfb",
....@@ -67,9 +66,9 @@
6766 MODULE_DEVICE_TABLE(usb, id_table);
6867
6968 /* module options */
70
-static bool console = 1; /* Allow fbcon to open framebuffer */
71
-static bool fb_defio = 1; /* Detect mmap writes using page faults */
72
-static bool shadow = 1; /* Optionally disable shadow framebuffer */
69
+static bool console = true; /* Allow fbcon to open framebuffer */
70
+static bool fb_defio = true; /* Detect mmap writes using page faults */
71
+static bool shadow = true; /* Optionally disable shadow framebuffer */
7372 static int pixel_limit; /* Optionally force a pixel resolution limit */
7473
7574 struct dlfb_deferred_free {
....@@ -1041,7 +1040,6 @@
10411040 fb_deferred_io_cleanup(info);
10421041 kfree(info->fbdefio);
10431042 info->fbdefio = NULL;
1044
- info->fbops->fb_mmap = dlfb_ops_mmap;
10451043 }
10461044
10471045 dev_dbg(info->dev, "release, user=%d count=%d\n", user, dlfb->fb_count);
....@@ -1187,7 +1185,7 @@
11871185 return 0;
11881186 }
11891187
1190
-static struct fb_ops dlfb_ops = {
1188
+static const struct fb_ops dlfb_ops = {
11911189 .owner = THIS_MODULE,
11921190 .fb_read = fb_sys_read,
11931191 .fb_write = dlfb_ops_write,
....@@ -1430,7 +1428,7 @@
14301428 struct device_attribute *a, char *buf) {
14311429 struct fb_info *fb_info = dev_get_drvdata(fbdev);
14321430 struct dlfb_data *dlfb = fb_info->par;
1433
- return snprintf(buf, PAGE_SIZE, "%u\n",
1431
+ return sysfs_emit(buf, "%u\n",
14341432 atomic_read(&dlfb->bytes_rendered));
14351433 }
14361434
....@@ -1438,7 +1436,7 @@
14381436 struct device_attribute *a, char *buf) {
14391437 struct fb_info *fb_info = dev_get_drvdata(fbdev);
14401438 struct dlfb_data *dlfb = fb_info->par;
1441
- return snprintf(buf, PAGE_SIZE, "%u\n",
1439
+ return sysfs_emit(buf, "%u\n",
14421440 atomic_read(&dlfb->bytes_identical));
14431441 }
14441442
....@@ -1446,7 +1444,7 @@
14461444 struct device_attribute *a, char *buf) {
14471445 struct fb_info *fb_info = dev_get_drvdata(fbdev);
14481446 struct dlfb_data *dlfb = fb_info->par;
1449
- return snprintf(buf, PAGE_SIZE, "%u\n",
1447
+ return sysfs_emit(buf, "%u\n",
14501448 atomic_read(&dlfb->bytes_sent));
14511449 }
14521450
....@@ -1454,7 +1452,7 @@
14541452 struct device_attribute *a, char *buf) {
14551453 struct fb_info *fb_info = dev_get_drvdata(fbdev);
14561454 struct dlfb_data *dlfb = fb_info->par;
1457
- return snprintf(buf, PAGE_SIZE, "%u\n",
1455
+ return sysfs_emit(buf, "%u\n",
14581456 atomic_read(&dlfb->cpu_kcycles_used));
14591457 }
14601458
....@@ -1462,7 +1460,7 @@
14621460 struct file *filp,
14631461 struct kobject *kobj, struct bin_attribute *a,
14641462 char *buf, loff_t off, size_t count) {
1465
- struct device *fbdev = container_of(kobj, struct device, kobj);
1463
+ struct device *fbdev = kobj_to_dev(kobj);
14661464 struct fb_info *fb_info = dev_get_drvdata(fbdev);
14671465 struct dlfb_data *dlfb = fb_info->par;
14681466
....@@ -1484,7 +1482,7 @@
14841482 struct file *filp,
14851483 struct kobject *kobj, struct bin_attribute *a,
14861484 char *src, loff_t src_off, size_t src_size) {
1487
- struct device *fbdev = container_of(kobj, struct device, kobj);
1485
+ struct device *fbdev = kobj_to_dev(kobj);
14881486 struct fb_info *fb_info = dev_get_drvdata(fbdev);
14891487 struct dlfb_data *dlfb = fb_info->par;
14901488 int ret;
....@@ -1653,8 +1651,9 @@
16531651 const struct device_attribute *attr;
16541652 struct dlfb_data *dlfb;
16551653 struct fb_info *info;
1656
- int retval = -ENOMEM;
1654
+ int retval;
16571655 struct usb_device *usbdev = interface_to_usbdev(intf);
1656
+ static u8 out_ep[] = {OUT_EP_NUM + USB_DIR_OUT, 0};
16581657
16591658 /* usb initialization */
16601659 dlfb = kzalloc(sizeof(*dlfb), GFP_KERNEL);
....@@ -1668,6 +1667,12 @@
16681667 dlfb->udev = usb_get_dev(usbdev);
16691668 usb_set_intfdata(intf, dlfb);
16701669
1670
+ if (!usb_check_bulk_endpoints(intf, out_ep)) {
1671
+ dev_err(&intf->dev, "Invalid DisplayLink device!\n");
1672
+ retval = -EINVAL;
1673
+ goto error;
1674
+ }
1675
+
16711676 dev_dbg(&intf->dev, "console enable=%d\n", console);
16721677 dev_dbg(&intf->dev, "fb_defio enable=%d\n", fb_defio);
16731678 dev_dbg(&intf->dev, "shadow enable=%d\n", shadow);
....@@ -1677,6 +1682,7 @@
16771682 if (!dlfb_parse_vendor_descriptor(dlfb, intf)) {
16781683 dev_err(&intf->dev,
16791684 "firmware not recognized, incompatible device?\n");
1685
+ retval = -ENODEV;
16801686 goto error;
16811687 }
16821688
....@@ -1691,7 +1697,7 @@
16911697 /* allocates framebuffer driver structure, not framebuffer memory */
16921698 info = framebuffer_alloc(0, &dlfb->udev->dev);
16931699 if (!info) {
1694
- dev_err(&dlfb->udev->dev, "framebuffer_alloc failed\n");
1700
+ retval = -ENOMEM;
16951701 goto error;
16961702 }
16971703
....@@ -1922,7 +1928,8 @@
19221928 }
19231929
19241930 /* urb->transfer_buffer_length set to actual before submit */
1925
- usb_fill_bulk_urb(urb, dlfb->udev, usb_sndbulkpipe(dlfb->udev, 1),
1931
+ usb_fill_bulk_urb(urb, dlfb->udev,
1932
+ usb_sndbulkpipe(dlfb->udev, OUT_EP_NUM),
19261933 buf, size, dlfb_urb_completion, unode);
19271934 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
19281935