1 /* SPDX-License-Identifier: MIT */ 2 3 #ifndef __LINUX_GUD_INTERNAL_H 4 #define __LINUX_GUD_INTERNAL_H 5 6 #include <linux/list.h> 7 #include <linux/mutex.h> 8 #include <linux/usb.h> 9 #include <linux/workqueue.h> 10 #include <uapi/drm/drm_fourcc.h> 11 12 #include <drm/drm_modes.h> 13 #include <drm/drm_simple_kms_helper.h> 14 15 struct gud_device { 16 struct drm_device drm; 17 struct drm_simple_display_pipe pipe; 18 struct device *dmadev; 19 struct work_struct work; 20 u32 flags; 21 const struct drm_format_info *xrgb8888_emulation_format; 22 23 u16 *properties; 24 unsigned int num_properties; 25 26 unsigned int bulk_pipe; 27 void *bulk_buf; 28 size_t bulk_len; 29 30 u8 compression; 31 void *lz4_comp_mem; 32 void *compress_buf; 33 34 u64 stats_length; 35 u64 stats_actual_length; 36 unsigned int stats_num_errors; 37 38 struct mutex ctrl_lock; /* Serialize get/set and status transfers */ 39 40 struct mutex damage_lock; /* Protects the following members: */ 41 struct drm_framebuffer *fb; 42 struct drm_rect damage; 43 bool prev_flush_failed; 44 }; 45 46 static inline struct gud_device *to_gud_device(struct drm_device *drm) 47 { 48 return container_of(drm, struct gud_device, drm); 49 } 50 51 static inline struct usb_device *gud_to_usb_device(struct gud_device *gdrm) 52 { 53 return interface_to_usbdev(to_usb_interface(gdrm->drm.dev)); 54 } 55 56 int gud_usb_get(struct gud_device *gdrm, u8 request, u16 index, void *buf, size_t len); 57 int gud_usb_set(struct gud_device *gdrm, u8 request, u16 index, void *buf, size_t len); 58 int gud_usb_get_u8(struct gud_device *gdrm, u8 request, u16 index, u8 *val); 59 int gud_usb_set_u8(struct gud_device *gdrm, u8 request, u8 val); 60 61 void gud_clear_damage(struct gud_device *gdrm); 62 void gud_flush_work(struct work_struct *work); 63 int gud_pipe_check(struct drm_simple_display_pipe *pipe, 64 struct drm_plane_state *new_plane_state, 65 struct drm_crtc_state *new_crtc_state); 66 void gud_pipe_update(struct drm_simple_display_pipe *pipe, 67 struct drm_plane_state *old_state); 68 int gud_connector_fill_properties(struct drm_connector_state *connector_state, 69 struct gud_property_req *properties); 70 int gud_get_connectors(struct gud_device *gdrm); 71 72 /* Driver internal fourcc transfer formats */ 73 #define GUD_DRM_FORMAT_R1 0x00000122 74 #define GUD_DRM_FORMAT_XRGB1111 0x03121722 75 76 static inline u8 gud_from_fourcc(u32 fourcc) 77 { 78 switch (fourcc) { 79 case GUD_DRM_FORMAT_R1: 80 return GUD_PIXEL_FORMAT_R1; 81 case GUD_DRM_FORMAT_XRGB1111: 82 return GUD_PIXEL_FORMAT_XRGB1111; 83 case DRM_FORMAT_RGB565: 84 return GUD_PIXEL_FORMAT_RGB565; 85 case DRM_FORMAT_XRGB8888: 86 return GUD_PIXEL_FORMAT_XRGB8888; 87 case DRM_FORMAT_ARGB8888: 88 return GUD_PIXEL_FORMAT_ARGB8888; 89 } 90 91 return 0; 92 } 93 94 static inline u32 gud_to_fourcc(u8 format) 95 { 96 switch (format) { 97 case GUD_PIXEL_FORMAT_R1: 98 return GUD_DRM_FORMAT_R1; 99 case GUD_PIXEL_FORMAT_XRGB1111: 100 return GUD_DRM_FORMAT_XRGB1111; 101 case GUD_PIXEL_FORMAT_RGB565: 102 return DRM_FORMAT_RGB565; 103 case GUD_PIXEL_FORMAT_XRGB8888: 104 return DRM_FORMAT_XRGB8888; 105 case GUD_PIXEL_FORMAT_ARGB8888: 106 return DRM_FORMAT_ARGB8888; 107 } 108 109 return 0; 110 } 111 112 static inline void gud_from_display_mode(struct gud_display_mode_req *dst, 113 const struct drm_display_mode *src) 114 { 115 u32 flags = src->flags & GUD_DISPLAY_MODE_FLAG_USER_MASK; 116 117 if (src->type & DRM_MODE_TYPE_PREFERRED) 118 flags |= GUD_DISPLAY_MODE_FLAG_PREFERRED; 119 120 dst->clock = cpu_to_le32(src->clock); 121 dst->hdisplay = cpu_to_le16(src->hdisplay); 122 dst->hsync_start = cpu_to_le16(src->hsync_start); 123 dst->hsync_end = cpu_to_le16(src->hsync_end); 124 dst->htotal = cpu_to_le16(src->htotal); 125 dst->vdisplay = cpu_to_le16(src->vdisplay); 126 dst->vsync_start = cpu_to_le16(src->vsync_start); 127 dst->vsync_end = cpu_to_le16(src->vsync_end); 128 dst->vtotal = cpu_to_le16(src->vtotal); 129 dst->flags = cpu_to_le32(flags); 130 } 131 132 static inline void gud_to_display_mode(struct drm_display_mode *dst, 133 const struct gud_display_mode_req *src) 134 { 135 u32 flags = le32_to_cpu(src->flags); 136 137 memset(dst, 0, sizeof(*dst)); 138 dst->clock = le32_to_cpu(src->clock); 139 dst->hdisplay = le16_to_cpu(src->hdisplay); 140 dst->hsync_start = le16_to_cpu(src->hsync_start); 141 dst->hsync_end = le16_to_cpu(src->hsync_end); 142 dst->htotal = le16_to_cpu(src->htotal); 143 dst->vdisplay = le16_to_cpu(src->vdisplay); 144 dst->vsync_start = le16_to_cpu(src->vsync_start); 145 dst->vsync_end = le16_to_cpu(src->vsync_end); 146 dst->vtotal = le16_to_cpu(src->vtotal); 147 dst->flags = flags & GUD_DISPLAY_MODE_FLAG_USER_MASK; 148 dst->type = DRM_MODE_TYPE_DRIVER; 149 if (flags & GUD_DISPLAY_MODE_FLAG_PREFERRED) 150 dst->type |= DRM_MODE_TYPE_PREFERRED; 151 drm_mode_set_name(dst); 152 } 153 154 #endif 155