drm: Store USB device in struct drm_device
Subsystems (4)
Thomas Zimmermann
maintainerv3 cover drm: Store USB device in struct drm_device
The drivers gm12u320 and udl operate on USB devices. They leave the PCI device in struct drm_device empty and store the USB device in their own driver structure. It's expected that DRM core and helpers only touch the PCI-device field for actual PCI devices.
Fix this special case by upcasting struct drm_device.dev to the USB device. The drivers' udev variables are being removed.
v3:
* drop USB helper in favor of driver-internal helpers (Daniel)
v2:
* upcast USB device from struct drm_device.dev (Daniel)
Thomas Zimmermann (2):
drm/tiny/gm12u320: Retrieve USB device from struct drm_device.dev drm/udl: Retrieve USB device from struct drm_device.dev
drivers/gpu/drm/tiny/gm12u320.c | 56 ++++++++++++++--------------- drivers/gpu/drm/udl/udl_connector.c | 8 ++--- drivers/gpu/drm/udl/udl_drv.c | 3 -- drivers/gpu/drm/udl/udl_drv.h | 6 +++- drivers/gpu/drm/udl/udl_main.c | 23 ++++++------ 5 files changed, 49 insertions(+), 47 deletions(-)
--
2.29.0
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH v3 1/2 drm/tiny/gm12u320: Retrieve USB device from struct drm_device.dev
Drop the driver's udev field in favor of struct drm_device.dev. No functional changes made.
v3:
* upcast dev with gm12u320_to_usb_device()
v2:
* upcast dev with drm_dev_get_usb_device()
--- drivers/gpu/drm/tiny/gm12u320.c | 56 ++++++++++++++++----------------- 1 file changed, 28 insertions(+), 28 deletions(-)
drivers/gpu/drm/tiny/gm12u320.c +28 -28
@@ -45,7 +45,7 @@ MODULE_PARM_DESC(eco_mode, "Turn on Eco mode (less bright, more silent)");#define GM12U320_BLOCK_COUNT 20#define GM12U320_ERR (fmt, ...) \ - DRM_DEV_ERROR(&gm12u320->udev->dev, fmt, ##__VA_ARGS__) + DRM_DEV_ERROR(gm12u320->dev.dev, fmt, ##__VA_ARGS__)#define MISC_RCV_EPT 1#define DATA_RCV_EPT 2
@@ -85,7 +85,6 @@ struct gm12u320_device {struct drm_device dev;struct drm_simple_display_pipe pipe;struct drm_connector conn; -struct usb_device *udev;unsigned char *cmd_buf;unsigned char *data_buf[GM12U320_BLOCK_COUNT ];struct {
@@ -155,6 +154,11 @@ static const char data_block_footer[DATA_BLOCK_FOOTER_SIZE] = { 0x80, 0x00, 0x00, 0x4f }; +static inline struct usb_device *gm12u320_to_usb_device (struct gm12u320_device *gm12u320) +{ +return interface_to_usbdev (to_usb_interface (gm12u320->dev.dev)); +} +static int gm12u320_usb_alloc (struct gm12u320_device *gm12u320) {int i, block_size;
@@ -191,6 +195,7 @@ static int gm12u320_misc_request(struct gm12u320_device *gm12u320, u8 req_a, u8 req_b, u8 arg_a, u8 arg_b, u8 arg_c, u8 arg_d) { + struct usb_device *udev = gm12u320_to_usb_device(gm12u320);int ret, len;memcpy (gm12u320->cmd_buf, &cmd_misc,CMD_SIZE );
@@ -202,8 +207,7 @@ static int gm12u320_misc_request(struct gm12u320_device *gm12u320, gm12u320->cmd_buf[25 ] = arg_d;/* Send request */ - ret =usb_bulk_msg (gm12u320->udev, -usb_sndbulkpipe (gm12u320->udev,MISC_SND_EPT ), + ret =usb_bulk_msg (udev,usb_sndbulkpipe (udev,MISC_SND_EPT ), gm12u320->cmd_buf,CMD_SIZE , &len,CMD_TIMEOUT );if (ret || len !=CMD_SIZE ) {GM12U320_ERR ("Misc. req. error %d\n" , ret);
@@ -211,8 +215,7 @@ static int gm12u320_misc_request(struct gm12u320_device *gm12u320, }/* Read value */ - ret =usb_bulk_msg (gm12u320->udev, -usb_rcvbulkpipe (gm12u320->udev,MISC_RCV_EPT ), + ret =usb_bulk_msg (udev,usb_rcvbulkpipe (udev,MISC_RCV_EPT ), gm12u320->cmd_buf,MISC_VALUE_SIZE , &len,DATA_TIMEOUT );if (ret || len !=MISC_VALUE_SIZE ) {
@@ -222,8 +225,7 @@ static int gm12u320_misc_request(struct gm12u320_device *gm12u320,/* cmd_buf[0] now contains the read value, which we don't use */ /* Read status */ - ret =usb_bulk_msg (gm12u320->udev, -usb_rcvbulkpipe (gm12u320->udev,MISC_RCV_EPT ), + ret =usb_bulk_msg (udev,usb_rcvbulkpipe (udev,MISC_RCV_EPT ), gm12u320->cmd_buf,READ_STATUS_SIZE , &len,CMD_TIMEOUT );if (ret || len !=READ_STATUS_SIZE ) {
@@ -331,6 +333,7 @@ static void gm12u320_fb_update_work(struct work_struct *work)struct gm12u320_device *gm12u320 = container_of(to_delayed_work(work), struct gm12u320_device, fb_update.work); +struct usb_device *udev =gm12u320_to_usb_device (gm12u320);int block, block_size, len;int ret =0 ;
@@ -350,43 +353,41 @@ static void gm12u320_fb_update_work(struct work_struct *work) gm12u320->cmd_buf[21 ] = block | (gm12u320->fb_update.frame <<7 ); - ret =usb_bulk_msg (gm12u320->udev, -usb_sndbulkpipe (gm12u320->udev,DATA_SND_EPT ), - gm12u320->cmd_buf,CMD_SIZE , &len, -CMD_TIMEOUT ); + ret =usb_bulk_msg (udev, +usb_sndbulkpipe (udev,DATA_SND_EPT ), + gm12u320->cmd_buf,CMD_SIZE , &len, +CMD_TIMEOUT );if (ret || len !=CMD_SIZE ) goto err;/* Send data block to device */ - ret =usb_bulk_msg (gm12u320->udev, -usb_sndbulkpipe (gm12u320->udev,DATA_SND_EPT ), - gm12u320->data_buf[block], block_size, - &len,DATA_TIMEOUT ); + ret =usb_bulk_msg (udev, +usb_sndbulkpipe (udev,DATA_SND_EPT ), + gm12u320->data_buf[block], block_size, + &len,DATA_TIMEOUT );if (ret || len != block_size) goto err;/* Read status */ - ret =usb_bulk_msg (gm12u320->udev, -usb_rcvbulkpipe (gm12u320->udev,DATA_RCV_EPT ), - gm12u320->cmd_buf,READ_STATUS_SIZE , &len, -CMD_TIMEOUT ); + ret =usb_bulk_msg (udev, +usb_rcvbulkpipe (udev,DATA_RCV_EPT ), + gm12u320->cmd_buf,READ_STATUS_SIZE , &len, +CMD_TIMEOUT );if (ret || len !=READ_STATUS_SIZE ) goto err; }/* Send draw command to device */ memcpy (gm12u320->cmd_buf, cmd_draw,CMD_SIZE ); - ret =usb_bulk_msg (gm12u320->udev, -usb_sndbulkpipe (gm12u320->udev,DATA_SND_EPT ), - gm12u320->cmd_buf,CMD_SIZE , &len,CMD_TIMEOUT ); + ret =usb_bulk_msg (udev,usb_sndbulkpipe (udev,DATA_SND_EPT ), + gm12u320->cmd_buf,CMD_SIZE , &len,CMD_TIMEOUT );if (ret || len !=CMD_SIZE ) goto err;/* Read status */ - ret =usb_bulk_msg (gm12u320->udev, -usb_rcvbulkpipe (gm12u320->udev,DATA_RCV_EPT ), - gm12u320->cmd_buf,READ_STATUS_SIZE , &len, - gm12u320->fb_update.draw_status_timeout); + ret =usb_bulk_msg (udev,usb_rcvbulkpipe (udev,DATA_RCV_EPT ), + gm12u320->cmd_buf,READ_STATUS_SIZE , &len, + gm12u320->fb_update.draw_status_timeout);if (ret || len !=READ_STATUS_SIZE ) goto err;
@@ -638,7 +639,6 @@ static int gm12u320_usb_probe(struct usb_interface *interface,if (IS_ERR (gm12u320))return PTR_ERR (gm12u320); - gm12u320->udev =interface_to_usbdev (interface);INIT_DELAYED_WORK (&gm12u320->fb_update.work, gm12u320_fb_update_work);mutex_init (&gm12u320->fb_update.lock);
Signature · 6 lines
2.29.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH v3 2/2 drm/udl: Retrieve USB device from struct drm_device.dev
In reply to Thomas ZimmermannDrop the driver's udev field in favor of struct drm_device.dev. No functional changes made.
v3:
* upcast dev with udl_to_usb_device()
v2:
* upcast dev with drm_dev_get_usb_device()
--- drivers/gpu/drm/udl/udl_connector.c | 8 ++++---- drivers/gpu/drm/udl/udl_drv.c | 3 --- drivers/gpu/drm/udl/udl_drv.h | 6 +++++- drivers/gpu/drm/udl/udl_main.c | 23 ++++++++++++----------- 4 files changed, 21 insertions(+), 19 deletions(-)
drivers/gpu/drm/udl/udl_connector.c +4 -4
@@ -20,6 +20,7 @@ static int udl_get_edid_block(void *data, u8 *buf, unsigned int block,int ret, i;u8 *read_buff;struct udl_device *udl = data; +struct usb_device *udev =udl_to_usb_device (udl); read_buff =kmalloc (2 ,GFP_KERNEL );if (!read_buff)
@@ -27,10 +28,9 @@ static int udl_get_edid_block(void *data, u8 *buf, unsigned int block,for (i =0 ; i < len; i++) {int bval = (i + block *EDID_LENGTH ) <<8 ; - ret =usb_control_msg (udl->udev, -usb_rcvctrlpipe (udl->udev,0 ), - (0x02 ), (0x80 | (0x02 <<5 )), bval, -0xA1 , read_buff,2 ,HZ ); + ret =usb_control_msg (udev,usb_rcvctrlpipe (udev,0 ), +0x02 , (0x80 | (0x02 <<5 )), bval, +0xA1 , read_buff,2 ,HZ );if (ret <1 ) {DRM_ERROR ("Read EDID byte %d failed err %x\n" , i, ret);kfree (read_buff);
drivers/gpu/drm/udl/udl_drv.c +0 -3
@@ -53,7 +53,6 @@ static struct drm_driver driver = {static struct udl_device *udl_driver_create (struct usb_interface *interface) { -struct usb_device *udev =interface_to_usbdev (interface);struct udl_device *udl;int r;
@@ -62,8 +61,6 @@ static struct udl_device *udl_driver_create(struct usb_interface *interface)if (IS_ERR (udl))return udl; - udl->udev = udev; - r =udl_init (udl);if (r)return ERR_PTR (r);
drivers/gpu/drm/udl/udl_drv.h +5 -1
@@ -50,7 +50,6 @@ struct urb_list {struct udl_device {struct drm_device drm;struct device *dev; -struct usb_device *udev;struct drm_simple_display_pipe display_pipe;
@@ -66,6 +65,11 @@ struct udl_device {#define to_udl (x) container_of(x, struct udl_device, drm) +static inline struct usb_device *udl_to_usb_device (struct udl_device *udl) +{ +return interface_to_usbdev (to_usb_interface (udl->drm.dev)); +} +/* modeset */ int udl_modeset_init (struct drm_device *dev);struct drm_connector *udl_connector_init (struct drm_device *dev);
drivers/gpu/drm/udl/udl_main.c +12 -11
@@ -26,10 +26,9 @@#define GET_URB_TIMEOUT HZ#define FREE_URB_TIMEOUT (HZ*2) -static int udl_parse_vendor_descriptor (struct drm_device *dev, -struct usb_device *usbdev) +static int udl_parse_vendor_descriptor (struct udl_device *udl) { -struct udl_device *udl =to_udl (dev); +struct usb_device *udev =udl_to_usb_device (udl);char *desc;char *buf;char *desc_end;
@@ -41,7 +40,7 @@ static int udl_parse_vendor_descriptor(struct drm_device *dev,return false; desc = buf; - total_len =usb_get_descriptor (usbdev,0x5f ,/* vendor specific */ + total_len =usb_get_descriptor (udev,0x5f ,/* vendor specific */ 0 , desc,MAX_VENDOR_DESCRIPTOR_SIZE );if (total_len >5 ) { DRM_INFO("vendor descriptor length:%x data:%11ph\n",
@@ -98,19 +97,20 @@ static int udl_parse_vendor_descriptor(struct drm_device *dev,*/ static int udl_select_std_channel (struct udl_device *udl) { -int ret;static const u8 set_def_chn[] = {0x57 ,0xCD ,0xDC ,0xA7 ,0x1C ,0x88 ,0x5E ,0x15 ,0x60 ,0xFE ,0xC6 ,0x97 ,0x16 ,0x3D ,0x47 ,0xF2 }; +void *sendbuf; +int ret; +struct usb_device *udev =udl_to_usb_device (udl); sendbuf =kmemdup (set_def_chn,sizeof (set_def_chn),GFP_KERNEL );if (!sendbuf)return -ENOMEM ; - ret = usb_control_msg(udl->udev, - usb_sndctrlpipe(udl->udev, 0), + ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), NR_USB_REQUEST_CHANNEL, (USB_DIR_OUT | USB_TYPE_VENDOR), 0, 0, sendbuf, sizeof(set_def_chn),
@@ -202,6 +202,7 @@ static int udl_alloc_urb_list(struct drm_device *dev, int count, size_t size)struct urb_node *unode;char *buf;size_t wanted_size = count * size; +struct usb_device *udev =udl_to_usb_device (udl);spin_lock_init (&udl->urbs.lock);
@@ -229,7 +230,7 @@ static int udl_alloc_urb_list(struct drm_device *dev, int count, size_t size) } unode->urb = urb; - buf =usb_alloc_coherent (udl->udev, size,GFP_KERNEL , + buf =usb_alloc_coherent (udev, size,GFP_KERNEL , &urb->transfer_dma);if (!buf) {kfree (unode);
@@ -243,8 +244,8 @@ static int udl_alloc_urb_list(struct drm_device *dev, int count, size_t size) }/* urb->transfer_buffer_length set to actual before submit */ -usb_fill_bulk_urb (urb, udl->udev,usb_sndbulkpipe (udl->udev,1 ), - buf, size, udl_urb_completion, unode); +usb_fill_bulk_urb (urb, udev,usb_sndbulkpipe (udev,1 ), + buf, size, udl_urb_completion, unode); urb->transfer_flags |=URB_NO_TRANSFER_DMA_MAP ;list_add_tail (&unode->entry, &udl->urbs.list);
@@ -316,7 +317,7 @@ int udl_init(struct udl_device *udl)mutex_init (&udl->gem_lock); -if (!udl_parse_vendor_descriptor (dev, udl->udev)) { +if (!udl_parse_vendor_descriptor (udl)) { ret = -ENODEV ;DRM_ERROR ("firmware not recognized. Assume incompatible device\n" ); goto err;
Signature · 6 lines
2.29.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel