Skip to content

Commit b051b34

Browse files
committed
drm/tinydrm: Use struct drm_rect
This prepares for the switch to drm_atomic_helper_dirtyfb() in the next patch. The damage helper returns a drm_rect so switch to that everywhere including using a pointer in the dirty functions. This is a non-functional change except for the debug print which looks a bit different. Signed-off-by: Noralf Trønnes <noralf@tronnes.org> Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch> Reviewed-by: Sam Ravnborg <sam@ravnborg.org> Link: https://patchwork.freedesktop.org/patch/msgid/20190115043643.2364-4-noralf@tronnes.org
1 parent 255f6fe commit b051b34

7 files changed

Lines changed: 67 additions & 60 deletions

File tree

‎drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <drm/drm_drv.h>
1919
#include <drm/drm_fourcc.h>
2020
#include <drm/drm_print.h>
21+
#include <drm/drm_rect.h>
2122
#include <drm/tinydrm/tinydrm.h>
2223
#include <drm/tinydrm/tinydrm-helpers.h>
2324
#include <uapi/drm/drm.h>
@@ -41,7 +42,7 @@ MODULE_PARM_DESC(spi_max, "Set a lower SPI max transfer size");
4142
* Returns:
4243
* true if it's a full clip, false otherwise
4344
*/
44-
bool tinydrm_merge_clips(struct drm_clip_rect *dst,
45+
bool tinydrm_merge_clips(struct drm_rect *dst,
4546
struct drm_clip_rect *src, unsigned int num_clips,
4647
unsigned int flags, u32 max_width, u32 max_height)
4748
{
@@ -63,10 +64,10 @@ bool tinydrm_merge_clips(struct drm_clip_rect *dst,
6364
for (i = 0; i < num_clips; i++) {
6465
if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY)
6566
i++;
66-
dst->x1 = min(dst->x1, src[i].x1);
67-
dst->x2 = max(dst->x2, src[i].x2);
68-
dst->y1 = min(dst->y1, src[i].y1);
69-
dst->y2 = max(dst->y2, src[i].y2);
67+
dst->x1 = min_t(int, dst->x1, src[i].x1);
68+
dst->x2 = max_t(int, dst->x2, src[i].x2);
69+
dst->y1 = min_t(int, dst->y1, src[i].y1);
70+
dst->y2 = max_t(int, dst->y2, src[i].y2);
7071
}
7172

7273
if (dst->x2 > max_width || dst->y2 > max_height ||
@@ -122,7 +123,7 @@ EXPORT_SYMBOL(tinydrm_fb_dirty);
122123
* @clip: Clip rectangle area to copy
123124
*/
124125
void tinydrm_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
125-
struct drm_clip_rect *clip)
126+
struct drm_rect *clip)
126127
{
127128
unsigned int cpp = drm_format_plane_cpp(fb->format->format, 0);
128129
unsigned int pitch = fb->pitches[0];
@@ -146,7 +147,7 @@ EXPORT_SYMBOL(tinydrm_memcpy);
146147
* @clip: Clip rectangle area to copy
147148
*/
148149
void tinydrm_swab16(u16 *dst, void *vaddr, struct drm_framebuffer *fb,
149-
struct drm_clip_rect *clip)
150+
struct drm_rect *clip)
150151
{
151152
size_t len = (clip->x2 - clip->x1) * sizeof(u16);
152153
unsigned int x, y;
@@ -186,7 +187,7 @@ EXPORT_SYMBOL(tinydrm_swab16);
186187
*/
187188
void tinydrm_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
188189
struct drm_framebuffer *fb,
189-
struct drm_clip_rect *clip, bool swap)
190+
struct drm_rect *clip, bool swap)
190191
{
191192
size_t len = (clip->x2 - clip->x1) * sizeof(u32);
192193
unsigned int x, y;
@@ -235,7 +236,7 @@ EXPORT_SYMBOL(tinydrm_xrgb8888_to_rgb565);
235236
* ITU BT.601 is used for the RGB -> luma (brightness) conversion.
236237
*/
237238
void tinydrm_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
238-
struct drm_clip_rect *clip)
239+
struct drm_rect *clip)
239240
{
240241
unsigned int len = (clip->x2 - clip->x1) * sizeof(u32);
241242
unsigned int x, y;

‎drivers/gpu/drm/tinydrm/ili9225.c‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <drm/drm_fourcc.h>
2626
#include <drm/drm_gem_cma_helper.h>
2727
#include <drm/drm_gem_framebuffer_helper.h>
28+
#include <drm/drm_rect.h>
2829
#include <drm/tinydrm/mipi-dbi.h>
2930
#include <drm/tinydrm/tinydrm-helpers.h>
3031

@@ -84,7 +85,8 @@ static int ili9225_fb_dirty(struct drm_framebuffer *fb,
8485
struct tinydrm_device *tdev = fb->dev->dev_private;
8586
struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev);
8687
bool swap = mipi->swap_bytes;
87-
struct drm_clip_rect clip;
88+
struct drm_rect clip;
89+
struct drm_rect *rect = &clip;
8890
u16 x_start, y_start;
8991
u16 x1, x2, y1, y2;
9092
int ret = 0;
@@ -97,13 +99,12 @@ static int ili9225_fb_dirty(struct drm_framebuffer *fb,
9799
full = tinydrm_merge_clips(&clip, clips, num_clips, flags,
98100
fb->width, fb->height);
99101

100-
DRM_DEBUG("Flushing [FB:%d] x1=%u, x2=%u, y1=%u, y2=%u\n", fb->base.id,
101-
clip.x1, clip.x2, clip.y1, clip.y2);
102+
DRM_DEBUG_KMS("Flushing [FB:%d] " DRM_RECT_FMT "\n", fb->base.id, DRM_RECT_ARG(rect));
102103

103104
if (!mipi->dc || !full || swap ||
104105
fb->format->format == DRM_FORMAT_XRGB8888) {
105106
tr = mipi->tx_buf;
106-
ret = mipi_dbi_buf_copy(mipi->tx_buf, fb, &clip, swap);
107+
ret = mipi_dbi_buf_copy(mipi->tx_buf, fb, rect, swap);
107108
if (ret)
108109
return ret;
109110
} else {
@@ -112,34 +113,34 @@ static int ili9225_fb_dirty(struct drm_framebuffer *fb,
112113

113114
switch (mipi->rotation) {
114115
default:
115-
x1 = clip.x1;
116-
x2 = clip.x2 - 1;
117-
y1 = clip.y1;
118-
y2 = clip.y2 - 1;
116+
x1 = rect->x1;
117+
x2 = rect->x2 - 1;
118+
y1 = rect->y1;
119+
y2 = rect->y2 - 1;
119120
x_start = x1;
120121
y_start = y1;
121122
break;
122123
case 90:
123-
x1 = clip.y1;
124-
x2 = clip.y2 - 1;
125-
y1 = fb->width - clip.x2;
126-
y2 = fb->width - clip.x1 - 1;
124+
x1 = rect->y1;
125+
x2 = rect->y2 - 1;
126+
y1 = fb->width - rect->x2;
127+
y2 = fb->width - rect->x1 - 1;
127128
x_start = x1;
128129
y_start = y2;
129130
break;
130131
case 180:
131-
x1 = fb->width - clip.x2;
132-
x2 = fb->width - clip.x1 - 1;
133-
y1 = fb->height - clip.y2;
134-
y2 = fb->height - clip.y1 - 1;
132+
x1 = fb->width - rect->x2;
133+
x2 = fb->width - rect->x1 - 1;
134+
y1 = fb->height - rect->y2;
135+
y2 = fb->height - rect->y1 - 1;
135136
x_start = x2;
136137
y_start = y2;
137138
break;
138139
case 270:
139-
x1 = fb->height - clip.y2;
140-
x2 = fb->height - clip.y1 - 1;
141-
y1 = clip.x1;
142-
y2 = clip.x2 - 1;
140+
x1 = fb->height - rect->y2;
141+
x2 = fb->height - rect->y1 - 1;
142+
y1 = rect->x1;
143+
y2 = rect->x2 - 1;
143144
x_start = x2;
144145
y_start = y1;
145146
break;
@@ -154,7 +155,7 @@ static int ili9225_fb_dirty(struct drm_framebuffer *fb,
154155
ili9225_command(mipi, ILI9225_RAM_ADDRESS_SET_2, y_start);
155156

156157
ret = mipi_dbi_command_buf(mipi, ILI9225_WRITE_DATA_TO_GRAM, tr,
157-
(clip.x2 - clip.x1) * (clip.y2 - clip.y1) * 2);
158+
(rect->x2 - rect->x1) * (rect->y2 - rect->y1) * 2);
158159

159160
return ret;
160161
}

‎drivers/gpu/drm/tinydrm/mipi-dbi.c‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <drm/drm_gem_cma_helper.h>
2323
#include <drm/drm_fourcc.h>
2424
#include <drm/drm_gem_framebuffer_helper.h>
25+
#include <drm/drm_rect.h>
2526
#include <drm/tinydrm/mipi-dbi.h>
2627
#include <drm/tinydrm/tinydrm-helpers.h>
2728
#include <uapi/drm/drm.h>
@@ -172,7 +173,7 @@ EXPORT_SYMBOL(mipi_dbi_command_buf);
172173
* Zero on success, negative error code on failure.
173174
*/
174175
int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
175-
struct drm_clip_rect *clip, bool swap)
176+
struct drm_rect *clip, bool swap)
176177
{
177178
struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
178179
struct dma_buf_attachment *import_attach = cma_obj->base.import_attach;
@@ -221,7 +222,8 @@ static int mipi_dbi_fb_dirty(struct drm_framebuffer *fb,
221222
struct tinydrm_device *tdev = fb->dev->dev_private;
222223
struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev);
223224
bool swap = mipi->swap_bytes;
224-
struct drm_clip_rect clip;
225+
struct drm_rect clip;
226+
struct drm_rect *rect = &clip;
225227
int ret = 0;
226228
bool full;
227229
void *tr;
@@ -232,28 +234,27 @@ static int mipi_dbi_fb_dirty(struct drm_framebuffer *fb,
232234
full = tinydrm_merge_clips(&clip, clips, num_clips, flags,
233235
fb->width, fb->height);
234236

235-
DRM_DEBUG("Flushing [FB:%d] x1=%u, x2=%u, y1=%u, y2=%u\n", fb->base.id,
236-
clip.x1, clip.x2, clip.y1, clip.y2);
237+
DRM_DEBUG_KMS("Flushing [FB:%d] " DRM_RECT_FMT "\n", fb->base.id, DRM_RECT_ARG(rect));
237238

238239
if (!mipi->dc || !full || swap ||
239240
fb->format->format == DRM_FORMAT_XRGB8888) {
240241
tr = mipi->tx_buf;
241-
ret = mipi_dbi_buf_copy(mipi->tx_buf, fb, &clip, swap);
242+
ret = mipi_dbi_buf_copy(mipi->tx_buf, fb, rect, swap);
242243
if (ret)
243244
return ret;
244245
} else {
245246
tr = cma_obj->vaddr;
246247
}
247248

248249
mipi_dbi_command(mipi, MIPI_DCS_SET_COLUMN_ADDRESS,
249-
(clip.x1 >> 8) & 0xFF, clip.x1 & 0xFF,
250-
((clip.x2 - 1) >> 8) & 0xFF, (clip.x2 - 1) & 0xFF);
250+
(rect->x1 >> 8) & 0xff, rect->x1 & 0xff,
251+
((rect->x2 - 1) >> 8) & 0xff, (rect->x2 - 1) & 0xff);
251252
mipi_dbi_command(mipi, MIPI_DCS_SET_PAGE_ADDRESS,
252-
(clip.y1 >> 8) & 0xFF, clip.y1 & 0xFF,
253-
((clip.y2 - 1) >> 8) & 0xFF, (clip.y2 - 1) & 0xFF);
253+
(rect->y1 >> 8) & 0xff, rect->y1 & 0xff,
254+
((rect->y2 - 1) >> 8) & 0xff, (rect->y2 - 1) & 0xff);
254255

255256
ret = mipi_dbi_command_buf(mipi, MIPI_DCS_WRITE_MEMORY_START, tr,
256-
(clip.x2 - clip.x1) * (clip.y2 - clip.y1) * 2);
257+
(rect->x2 - rect->x1) * (rect->y2 - rect->y1) * 2);
257258

258259
return ret;
259260
}

‎drivers/gpu/drm/tinydrm/repaper.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <drm/drm_fb_cma_helper.h>
3131
#include <drm/drm_gem_cma_helper.h>
3232
#include <drm/drm_gem_framebuffer_helper.h>
33+
#include <drm/drm_rect.h>
3334
#include <drm/tinydrm/tinydrm.h>
3435
#include <drm/tinydrm/tinydrm-helpers.h>
3536

@@ -532,7 +533,7 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,
532533
struct dma_buf_attachment *import_attach = cma_obj->base.import_attach;
533534
struct tinydrm_device *tdev = fb->dev->dev_private;
534535
struct repaper_epd *epd = epd_from_tinydrm(tdev);
535-
struct drm_clip_rect clip;
536+
struct drm_rect clip;
536537
u8 *buf = NULL;
537538
int ret = 0;
538539

‎drivers/gpu/drm/tinydrm/st7586.c‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <drm/drm_fb_cma_helper.h>
2222
#include <drm/drm_gem_cma_helper.h>
2323
#include <drm/drm_gem_framebuffer_helper.h>
24+
#include <drm/drm_rect.h>
2425
#include <drm/tinydrm/mipi-dbi.h>
2526
#include <drm/tinydrm/tinydrm-helpers.h>
2627

@@ -62,7 +63,7 @@ static const u8 st7586_lookup[] = { 0x7, 0x4, 0x2, 0x0 };
6263

6364
static void st7586_xrgb8888_to_gray332(u8 *dst, void *vaddr,
6465
struct drm_framebuffer *fb,
65-
struct drm_clip_rect *clip)
66+
struct drm_rect *clip)
6667
{
6768
size_t len = (clip->x2 - clip->x1) * (clip->y2 - clip->y1);
6869
unsigned int x, y;
@@ -88,7 +89,7 @@ static void st7586_xrgb8888_to_gray332(u8 *dst, void *vaddr,
8889
}
8990

9091
static int st7586_buf_copy(void *dst, struct drm_framebuffer *fb,
91-
struct drm_clip_rect *clip)
92+
struct drm_rect *clip)
9293
{
9394
struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
9495
struct dma_buf_attachment *import_attach = cma_obj->base.import_attach;
@@ -118,7 +119,8 @@ static int st7586_fb_dirty(struct drm_framebuffer *fb,
118119
{
119120
struct tinydrm_device *tdev = fb->dev->dev_private;
120121
struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev);
121-
struct drm_clip_rect clip;
122+
struct drm_rect clip;
123+
struct drm_rect *rect = &clip;
122124
int start, end;
123125
int ret = 0;
124126

@@ -129,30 +131,29 @@ static int st7586_fb_dirty(struct drm_framebuffer *fb,
129131
fb->height);
130132

131133
/* 3 pixels per byte, so grow clip to nearest multiple of 3 */
132-
clip.x1 = rounddown(clip.x1, 3);
133-
clip.x2 = roundup(clip.x2, 3);
134+
rect->x1 = rounddown(rect->x1, 3);
135+
rect->x2 = roundup(rect->x2, 3);
134136

135-
DRM_DEBUG("Flushing [FB:%d] x1=%u, x2=%u, y1=%u, y2=%u\n", fb->base.id,
136-
clip.x1, clip.x2, clip.y1, clip.y2);
137+
DRM_DEBUG_KMS("Flushing [FB:%d] " DRM_RECT_FMT "\n", fb->base.id, DRM_RECT_ARG(rect));
137138

138-
ret = st7586_buf_copy(mipi->tx_buf, fb, &clip);
139+
ret = st7586_buf_copy(mipi->tx_buf, fb, rect);
139140
if (ret)
140141
return ret;
141142

142143
/* Pixels are packed 3 per byte */
143-
start = clip.x1 / 3;
144-
end = clip.x2 / 3;
144+
start = rect->x1 / 3;
145+
end = rect->x2 / 3;
145146

146147
mipi_dbi_command(mipi, MIPI_DCS_SET_COLUMN_ADDRESS,
147148
(start >> 8) & 0xFF, start & 0xFF,
148149
(end >> 8) & 0xFF, (end - 1) & 0xFF);
149150
mipi_dbi_command(mipi, MIPI_DCS_SET_PAGE_ADDRESS,
150-
(clip.y1 >> 8) & 0xFF, clip.y1 & 0xFF,
151-
(clip.y2 >> 8) & 0xFF, (clip.y2 - 1) & 0xFF);
151+
(rect->y1 >> 8) & 0xFF, rect->y1 & 0xFF,
152+
(rect->y2 >> 8) & 0xFF, (rect->y2 - 1) & 0xFF);
152153

153154
ret = mipi_dbi_command_buf(mipi, MIPI_DCS_WRITE_MEMORY_START,
154155
(u8 *)mipi->tx_buf,
155-
(end - start) * (clip.y2 - clip.y1));
156+
(end - start) * (rect->y2 - rect->y1));
156157

157158
return ret;
158159
}

‎include/drm/tinydrm/mipi-dbi.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <drm/tinydrm/tinydrm.h>
1616

17+
struct drm_rect;
1718
struct spi_device;
1819
struct gpio_desc;
1920
struct regulator;
@@ -80,7 +81,7 @@ u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len);
8081
int mipi_dbi_command_read(struct mipi_dbi *mipi, u8 cmd, u8 *val);
8182
int mipi_dbi_command_buf(struct mipi_dbi *mipi, u8 cmd, u8 *data, size_t len);
8283
int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
83-
struct drm_clip_rect *clip, bool swap);
84+
struct drm_rect *clip, bool swap);
8485
/**
8586
* mipi_dbi_command - MIPI DCS command with optional parameter(s)
8687
* @mipi: MIPI structure

‎include/drm/tinydrm/tinydrm-helpers.h‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
struct backlight_device;
1414
struct tinydrm_device;
1515
struct drm_clip_rect;
16+
struct drm_rect;
1617
struct spi_transfer;
1718
struct spi_message;
1819
struct spi_device;
@@ -33,7 +34,7 @@ static inline bool tinydrm_machine_little_endian(void)
3334
#endif
3435
}
3536

36-
bool tinydrm_merge_clips(struct drm_clip_rect *dst,
37+
bool tinydrm_merge_clips(struct drm_rect *dst,
3738
struct drm_clip_rect *src, unsigned int num_clips,
3839
unsigned int flags, u32 max_width, u32 max_height);
3940
int tinydrm_fb_dirty(struct drm_framebuffer *fb,
@@ -42,14 +43,14 @@ int tinydrm_fb_dirty(struct drm_framebuffer *fb,
4243
struct drm_clip_rect *clips,
4344
unsigned int num_clips);
4445
void tinydrm_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
45-
struct drm_clip_rect *clip);
46+
struct drm_rect *clip);
4647
void tinydrm_swab16(u16 *dst, void *vaddr, struct drm_framebuffer *fb,
47-
struct drm_clip_rect *clip);
48+
struct drm_rect *clip);
4849
void tinydrm_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
4950
struct drm_framebuffer *fb,
50-
struct drm_clip_rect *clip, bool swap);
51+
struct drm_rect *clip, bool swap);
5152
void tinydrm_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
52-
struct drm_clip_rect *clip);
53+
struct drm_rect *clip);
5354

5455
size_t tinydrm_spi_max_transfer_size(struct spi_device *spi, size_t max_len);
5556
bool tinydrm_spi_bpw_supported(struct spi_device *spi, u8 bpw);

0 commit comments

Comments
 (0)