diff options
| author | David Lechner <david@lechnology.com> | 2017-08-07 13:39:37 -0400 |
|---|---|---|
| committer | Noralf Trønnes <noralf@tronnes.org> | 2017-08-09 11:55:50 -0400 |
| commit | 8941a7cbcc5f06fb9e1d105911c928766d742861 (patch) | |
| tree | fa399310a397a5b9b0d47eb4df763b0cbbeef1f2 /drivers/gpu/drm/tinydrm | |
| parent | aadd41485bb227a16f964833a4fd55c091f4a729 (diff) | |
drm/tinydrm: Generalize tinydrm_xrgb8888_to_gray8()
This adds parameters for vaddr and clip to tinydrm_xrgb8888_to_gray8() to
make it more generic.
dma_buf_{begin,end}_cpu_access() are moved out to the repaper driver.
Return type is change to void to simplify error handling by callers.
Signed-off-by: David Lechner <david@lechnology.com>
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Link: https://patchwork.freedesktop.org/patch/msgid/1502127581-10517-2-git-send-email-david@lechnology.com
Diffstat (limited to 'drivers/gpu/drm/tinydrm')
| -rw-r--r-- | drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 42 | ||||
| -rw-r--r-- | drivers/gpu/drm/tinydrm/repaper.c | 28 |
2 files changed, 39 insertions, 31 deletions
diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c index 75808bb84c9a..bd6cce093a85 100644 --- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | |||
| @@ -185,7 +185,9 @@ EXPORT_SYMBOL(tinydrm_xrgb8888_to_rgb565); | |||
| 185 | /** | 185 | /** |
| 186 | * tinydrm_xrgb8888_to_gray8 - Convert XRGB8888 to grayscale | 186 | * tinydrm_xrgb8888_to_gray8 - Convert XRGB8888 to grayscale |
| 187 | * @dst: 8-bit grayscale destination buffer | 187 | * @dst: 8-bit grayscale destination buffer |
| 188 | * @vaddr: XRGB8888 source buffer | ||
| 188 | * @fb: DRM framebuffer | 189 | * @fb: DRM framebuffer |
| 190 | * @clip: Clip rectangle area to copy | ||
| 189 | * | 191 | * |
| 190 | * Drm doesn't have native monochrome or grayscale support. | 192 | * Drm doesn't have native monochrome or grayscale support. |
| 191 | * Such drivers can announce the commonly supported XR24 format to userspace | 193 | * Such drivers can announce the commonly supported XR24 format to userspace |
| @@ -195,41 +197,31 @@ EXPORT_SYMBOL(tinydrm_xrgb8888_to_rgb565); | |||
| 195 | * where 1 means foreground color and 0 background color. | 197 | * where 1 means foreground color and 0 background color. |
| 196 | * | 198 | * |
| 197 | * ITU BT.601 is used for the RGB -> luma (brightness) conversion. | 199 | * ITU BT.601 is used for the RGB -> luma (brightness) conversion. |
| 198 | * | ||
| 199 | * Returns: | ||
| 200 | * Zero on success, negative error code on failure. | ||
| 201 | */ | 200 | */ |
| 202 | int tinydrm_xrgb8888_to_gray8(u8 *dst, struct drm_framebuffer *fb) | 201 | void tinydrm_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb, |
| 202 | struct drm_clip_rect *clip) | ||
| 203 | { | 203 | { |
| 204 | struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); | 204 | unsigned int len = (clip->x2 - clip->x1) * sizeof(u32); |
| 205 | struct dma_buf_attachment *import_attach = cma_obj->base.import_attach; | 205 | unsigned int x, y; |
| 206 | unsigned int x, y, pitch = fb->pitches[0]; | ||
| 207 | int ret = 0; | ||
| 208 | void *buf; | 206 | void *buf; |
| 209 | u32 *src; | 207 | u32 *src; |
| 210 | 208 | ||
| 211 | if (WARN_ON(fb->format->format != DRM_FORMAT_XRGB8888)) | 209 | if (WARN_ON(fb->format->format != DRM_FORMAT_XRGB8888)) |
| 212 | return -EINVAL; | 210 | return; |
| 213 | /* | 211 | /* |
| 214 | * The cma memory is write-combined so reads are uncached. | 212 | * The cma memory is write-combined so reads are uncached. |
| 215 | * Speed up by fetching one line at a time. | 213 | * Speed up by fetching one line at a time. |
| 216 | */ | 214 | */ |
| 217 | buf = kmalloc(pitch, GFP_KERNEL); | 215 | buf = kmalloc(len, GFP_KERNEL); |
| 218 | if (!buf) | 216 | if (!buf) |
| 219 | return -ENOMEM; | 217 | return; |
| 220 | |||
| 221 | if (import_attach) { | ||
| 222 | ret = dma_buf_begin_cpu_access(import_attach->dmabuf, | ||
| 223 | DMA_FROM_DEVICE); | ||
| 224 | if (ret) | ||
| 225 | goto err_free; | ||
| 226 | } | ||
| 227 | 218 | ||
| 228 | for (y = 0; y < fb->height; y++) { | 219 | for (y = clip->y1; y < clip->y2; y++) { |
| 229 | src = cma_obj->vaddr + (y * pitch); | 220 | src = vaddr + (y * fb->pitches[0]); |
| 230 | memcpy(buf, src, pitch); | 221 | src += clip->x1; |
| 222 | memcpy(buf, src, len); | ||
| 231 | src = buf; | 223 | src = buf; |
| 232 | for (x = 0; x < fb->width; x++) { | 224 | for (x = clip->x1; x < clip->x2; x++) { |
| 233 | u8 r = (*src & 0x00ff0000) >> 16; | 225 | u8 r = (*src & 0x00ff0000) >> 16; |
| 234 | u8 g = (*src & 0x0000ff00) >> 8; | 226 | u8 g = (*src & 0x0000ff00) >> 8; |
| 235 | u8 b = *src & 0x000000ff; | 227 | u8 b = *src & 0x000000ff; |
| @@ -240,13 +232,7 @@ int tinydrm_xrgb8888_to_gray8(u8 *dst, struct drm_framebuffer *fb) | |||
| 240 | } | 232 | } |
| 241 | } | 233 | } |
| 242 | 234 | ||
| 243 | if (import_attach) | ||
| 244 | ret = dma_buf_end_cpu_access(import_attach->dmabuf, | ||
| 245 | DMA_FROM_DEVICE); | ||
| 246 | err_free: | ||
| 247 | kfree(buf); | 235 | kfree(buf); |
| 248 | |||
| 249 | return ret; | ||
| 250 | } | 236 | } |
| 251 | EXPORT_SYMBOL(tinydrm_xrgb8888_to_gray8); | 237 | EXPORT_SYMBOL(tinydrm_xrgb8888_to_gray8); |
| 252 | 238 | ||
diff --git a/drivers/gpu/drm/tinydrm/repaper.c b/drivers/gpu/drm/tinydrm/repaper.c index 3343d3f15a90..30dc97b3ff21 100644 --- a/drivers/gpu/drm/tinydrm/repaper.c +++ b/drivers/gpu/drm/tinydrm/repaper.c | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | */ | 18 | */ |
| 19 | 19 | ||
| 20 | #include <linux/delay.h> | 20 | #include <linux/delay.h> |
| 21 | #include <linux/dma-buf.h> | ||
| 21 | #include <linux/gpio/consumer.h> | 22 | #include <linux/gpio/consumer.h> |
| 22 | #include <linux/module.h> | 23 | #include <linux/module.h> |
| 23 | #include <linux/of_device.h> | 24 | #include <linux/of_device.h> |
| @@ -525,11 +526,20 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb, | |||
| 525 | struct drm_clip_rect *clips, | 526 | struct drm_clip_rect *clips, |
| 526 | unsigned int num_clips) | 527 | unsigned int num_clips) |
| 527 | { | 528 | { |
| 529 | struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); | ||
| 530 | struct dma_buf_attachment *import_attach = cma_obj->base.import_attach; | ||
| 528 | struct tinydrm_device *tdev = fb->dev->dev_private; | 531 | struct tinydrm_device *tdev = fb->dev->dev_private; |
| 529 | struct repaper_epd *epd = epd_from_tinydrm(tdev); | 532 | struct repaper_epd *epd = epd_from_tinydrm(tdev); |
| 533 | struct drm_clip_rect clip; | ||
| 530 | u8 *buf = NULL; | 534 | u8 *buf = NULL; |
| 531 | int ret = 0; | 535 | int ret = 0; |
| 532 | 536 | ||
| 537 | /* repaper can't do partial updates */ | ||
| 538 | clip.x1 = 0; | ||
| 539 | clip.x2 = fb->width; | ||
| 540 | clip.y1 = 0; | ||
| 541 | clip.y2 = fb->height; | ||
| 542 | |||
| 533 | mutex_lock(&tdev->dirty_lock); | 543 | mutex_lock(&tdev->dirty_lock); |
| 534 | 544 | ||
| 535 | if (!epd->enabled) | 545 | if (!epd->enabled) |
| @@ -550,9 +560,21 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb, | |||
| 550 | goto out_unlock; | 560 | goto out_unlock; |
| 551 | } | 561 | } |
| 552 | 562 | ||
| 553 | ret = tinydrm_xrgb8888_to_gray8(buf, fb); | 563 | if (import_attach) { |
| 554 | if (ret) | 564 | ret = dma_buf_begin_cpu_access(import_attach->dmabuf, |
| 555 | goto out_unlock; | 565 | DMA_FROM_DEVICE); |
| 566 | if (ret) | ||
| 567 | goto out_unlock; | ||
| 568 | } | ||
| 569 | |||
| 570 | tinydrm_xrgb8888_to_gray8(buf, cma_obj->vaddr, fb, &clip); | ||
| 571 | |||
| 572 | if (import_attach) { | ||
| 573 | ret = dma_buf_end_cpu_access(import_attach->dmabuf, | ||
| 574 | DMA_FROM_DEVICE); | ||
| 575 | if (ret) | ||
| 576 | goto out_unlock; | ||
| 577 | } | ||
| 556 | 578 | ||
| 557 | repaper_gray8_to_mono_reversed(buf, fb->width, fb->height); | 579 | repaper_gray8_to_mono_reversed(buf, fb->width, fb->height); |
| 558 | 580 | ||
