Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2191023ybz; Thu, 30 Apr 2020 12:29:58 -0700 (PDT) X-Google-Smtp-Source: APiQypJmnVwfEuIddOYdO7RadrBi01ESDkju/Ag6akYTDEUPB1OeydXjl0RYvjc8lO+SWTGzn+W7 X-Received: by 2002:a05:6402:1c07:: with SMTP id ck7mr572687edb.202.1588274998295; Thu, 30 Apr 2020 12:29:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588274998; cv=none; d=google.com; s=arc-20160816; b=x1U6O22cdPd5OD2k+UA2YkwgINqEeZqtOmz+T9p/vIV/kGXXMNjlyxerZiBpCSkTCw m47plkygHzOW7qLXVtqcPbBBeihGzG8K7/xpR5nwv7omo+V7g++6GvCSjARhf+y+bbNN 0NZ8Zu6zsuYVB+8WAlObw4cNoHWhn0RPZQrshkzwLeQuONGYJKY1ff21wlWUM0pngj4h vITEDcGYp6OWCUrMkGom7RhHPDJviaZurIKscqgcCNxxD7Zk8nUcJQl5tqNSO4gILaWm cW7Nh6yVMGj9S5+eeR+eEym8+GXLKxjEanOs8xtCk7b5xXTjoVq8xGZbEHue8H2ZhMAG S1nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ESQ+g+o6IIa77zk8w/+VnT6w3LIhaOBHZn17Q6WMW3k=; b=cYSBNL593aqUZ3oGF9Na/wAqOHAAQjOHFjVtbKD/5aHpe+3CAp2IAMiZQFvapJ8sXu JRVWde26yc6ymVaN+A15QPZFDuv80XeO1qpLSLEEN1g95Y33ZkI6Q7YSL8ryue6L35Cj YqC2g24CvOr0gWljK9tGwDoa4oJSscToJO4OHH0oDaji/SlwzpUWPniuzUkuFxKPe6rz CJnDTgALUVnbD9RBsMAshDzT7Glg0ycwC+MqNMqztyu7glU2aiPtzD4qX+BqOrsEA2qL wBDc2rFY+JUVwlO90eZbBQsEdSPU8kMZTABHnSgQJgl7U1jJTi+gVfVOlq+HL+sQO6tS Eiig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p4si307311eds.242.2020.04.30.12.29.34; Thu, 30 Apr 2020 12:29:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726870AbgD3T2I (ORCPT + 99 others); Thu, 30 Apr 2020 15:28:08 -0400 Received: from relay5-d.mail.gandi.net ([217.70.183.197]:37837 "EHLO relay5-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726685AbgD3T2H (ORCPT ); Thu, 30 Apr 2020 15:28:07 -0400 X-Originating-IP: 93.29.109.196 Received: from localhost.localdomain (196.109.29.93.rev.sfr.net [93.29.109.196]) (Authenticated sender: paul.kocialkowski@bootlin.com) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 60B821C000B; Thu, 30 Apr 2020 19:28:03 +0000 (UTC) From: Paul Kocialkowski To: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: David Airlie , Daniel Vetter , Rob Herring , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Paul Kocialkowski , Thomas Petazzoni Subject: [PATCH v6 3/3] NOTFORMERGE: drm/logicvc: Add plane colorkey support Date: Thu, 30 Apr 2020 21:27:46 +0200 Message-Id: <20200430192746.1866325-4-paul.kocialkowski@bootlin.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200430192746.1866325-1-paul.kocialkowski@bootlin.com> References: <20200430192746.1866325-1-paul.kocialkowski@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --- drivers/gpu/drm/logicvc/logicvc_drm.h | 3 + drivers/gpu/drm/logicvc/logicvc_layer.c | 143 +++++++++++++++++++++++- drivers/gpu/drm/logicvc/logicvc_layer.h | 7 ++ 3 files changed, 149 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/logicvc/logicvc_drm.h b/drivers/gpu/drm/logicvc/logicvc_drm.h index 68bbac6c4ab9..d69a686ab0f1 100644 --- a/drivers/gpu/drm/logicvc/logicvc_drm.h +++ b/drivers/gpu/drm/logicvc/logicvc_drm.h @@ -59,6 +59,9 @@ struct logicvc_drm { struct list_head layers_list; struct logicvc_crtc *crtc; struct logicvc_interface *interface; + + struct drm_property *colorkey_enabled_property; + struct drm_property *colorkey_value_property; }; #endif diff --git a/drivers/gpu/drm/logicvc/logicvc_layer.c b/drivers/gpu/drm/logicvc/logicvc_layer.c index 98c3c70b37b0..6a8254103145 100644 --- a/drivers/gpu/drm/logicvc/logicvc_layer.c +++ b/drivers/gpu/drm/logicvc/logicvc_layer.c @@ -23,6 +23,8 @@ #define logicvc_layer(p) \ container_of(p, struct logicvc_layer, drm_plane) +#define logicvc_layer_state(p) \ + container_of(p, struct logicvc_layer_state, drm_plane_state) static uint32_t logicvc_layer_formats_rgb16[] = { DRM_FORMAT_RGB565, @@ -135,6 +137,7 @@ static void logicvc_plane_atomic_update(struct drm_plane *drm_plane, struct logicvc_layer *layer = logicvc_layer(drm_plane); struct logicvc_drm *logicvc = logicvc_drm(drm_plane->dev); struct drm_plane_state *state = drm_plane->state; + struct logicvc_layer_state *layer_state = logicvc_layer_state(state); struct drm_crtc *drm_crtc = &logicvc->crtc->drm_crtc; struct drm_display_mode *mode = &drm_crtc->state->adjusted_mode; struct drm_framebuffer *fb = state->fb; @@ -210,6 +213,15 @@ static void logicvc_plane_atomic_update(struct drm_plane *drm_plane, alpha); } + /* Layer colorkey */ + + if (layer_state->colorkey_enabled) { + reg = layer_state->colorkey_value; + + regmap_write(logicvc->regmap, + LOGICVC_LAYER_COLOR_KEY_REG(index), reg); + } + /* Layer control */ reg = LOGICVC_LAYER_CTRL_ENABLE; @@ -217,7 +229,8 @@ static void logicvc_plane_atomic_update(struct drm_plane *drm_plane, if (logicvc_layer_format_inverted(fb->format->format)) reg |= LOGICVC_LAYER_CTRL_PIXEL_FORMAT_INVERT; - reg |= LOGICVC_LAYER_CTRL_COLOR_KEY_DISABLE; + if (!layer_state->colorkey_enabled) + reg |= LOGICVC_LAYER_CTRL_COLOR_KEY_DISABLE; regmap_write(logicvc->regmap, LOGICVC_LAYER_CTRL_REG(index), reg); } @@ -238,13 +251,108 @@ static struct drm_plane_helper_funcs logicvc_plane_helper_funcs = { .atomic_disable = logicvc_plane_atomic_disable, }; +static void logicvc_plane_reset(struct drm_plane *drm_plane) +{ + struct logicvc_drm *logicvc = logicvc_drm(drm_plane->dev); + struct device *dev = logicvc->drm_dev.dev; + struct logicvc_layer_state *layer_state; + + if (drm_plane->state) { + layer_state = logicvc_layer_state(drm_plane->state); + __drm_atomic_helper_plane_destroy_state(drm_plane->state); + devm_kfree(dev, layer_state); + drm_plane->state = NULL; + } + + layer_state = devm_kzalloc(dev, sizeof(*layer_state), GFP_KERNEL); + if (!layer_state) + return; + + __drm_atomic_helper_plane_reset(drm_plane, + &layer_state->drm_plane_state); +} + +static struct drm_plane_state *logicvc_plane_atomic_duplicate_state(struct drm_plane *drm_plane) +{ + struct logicvc_drm *logicvc = logicvc_drm(drm_plane->dev); + struct device *dev = logicvc->drm_dev.dev; + struct logicvc_layer_state *layer_state_current; + struct logicvc_layer_state *layer_state; + + if (WARN_ON(!drm_plane->state)) + return NULL; + + layer_state_current = logicvc_layer_state(drm_plane->state); + layer_state = devm_kzalloc(dev, sizeof(*layer_state), GFP_KERNEL); + if (!layer_state) + return NULL; + + layer_state->colorkey_enabled = layer_state_current->colorkey_enabled; + layer_state->colorkey_value = layer_state_current->colorkey_value; + + __drm_atomic_helper_plane_duplicate_state(drm_plane, + &layer_state->drm_plane_state); + + return &layer_state->drm_plane_state; +} + +static void logicvc_plane_destroy_state(struct drm_plane *drm_plane, + struct drm_plane_state *state) +{ + struct logicvc_drm *logicvc = logicvc_drm(drm_plane->dev); + struct device *dev = logicvc->drm_dev.dev; + struct logicvc_layer_state *layer_state = logicvc_layer_state(state); + + __drm_atomic_helper_plane_destroy_state(&layer_state->drm_plane_state); + + devm_kfree(dev, layer_state); +} + +static int logicvc_plane_atomic_set_property(struct drm_plane *drm_plane, + struct drm_plane_state *state, + struct drm_property *property, + uint64_t value) +{ + struct logicvc_drm *logicvc = logicvc_drm(drm_plane->dev); + struct logicvc_layer_state *layer_state = logicvc_layer_state(state); + + if (property == logicvc->colorkey_enabled_property) + layer_state->colorkey_enabled = !!value; + else if (property == logicvc->colorkey_value_property) + layer_state->colorkey_value = (uint32_t)value; + else + return -ENOENT; + + return 0; +} + +static int logicvc_plane_atomic_get_property(struct drm_plane *drm_plane, + const struct drm_plane_state *state, + struct drm_property *property, + uint64_t *value) +{ + struct logicvc_drm *logicvc = logicvc_drm(drm_plane->dev); + struct logicvc_layer_state *layer_state = logicvc_layer_state(state); + + if (property == logicvc->colorkey_enabled_property) + *value = layer_state->colorkey_enabled; + else if (property == logicvc->colorkey_value_property) + *value = layer_state->colorkey_value; + else + return -ENOENT; + + return 0; +} + static const struct drm_plane_funcs logicvc_plane_funcs = { .update_plane = drm_atomic_helper_update_plane, .disable_plane = drm_atomic_helper_disable_plane, .destroy = drm_plane_cleanup, - .reset = drm_atomic_helper_plane_reset, - .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, - .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, + .reset = logicvc_plane_reset, + .atomic_duplicate_state = logicvc_plane_atomic_duplicate_state, + .atomic_destroy_state = logicvc_plane_destroy_state, + .atomic_set_property = logicvc_plane_atomic_set_property, + .atomic_get_property = logicvc_plane_atomic_get_property, }; int logicvc_layer_buffer_find_setup(struct logicvc_drm *logicvc, @@ -519,6 +627,11 @@ static int logicvc_layer_init(struct logicvc_drm *logicvc, drm_plane_create_zpos_immutable_property(&layer->drm_plane, zpos); + drm_object_attach_property(&layer->drm_plane.base, + logicvc->colorkey_enabled_property, 0); + drm_object_attach_property(&layer->drm_plane.base, + logicvc->colorkey_value_property, 0); + DRM_DEBUG_DRIVER("Registering layer #%d\n", index); layer->formats = formats; @@ -567,6 +680,17 @@ int logicvc_layers_init(struct logicvc_drm *logicvc) struct logicvc_layer *next; int ret = 0; + logicvc->colorkey_enabled_property = + drm_property_create_bool(drm_dev, 0, "colorkey_enabled"); + if (!logicvc->colorkey_enabled_property) + goto error; + + logicvc->colorkey_value_property = + drm_property_create_range(drm_dev, 0, "colorkey_value", + 0, 0xffffffff); + if (!logicvc->colorkey_value_property) + goto error; + layers_node = of_get_child_by_name(of_node, "layers"); if (!layers_node) { DRM_ERROR("No layers node found in the description\n"); @@ -605,5 +729,16 @@ int logicvc_layers_init(struct logicvc_drm *logicvc) list_for_each_entry_safe(layer, next, &logicvc->layers_list, list) logicvc_layer_fini(logicvc, layer); + if (logicvc->colorkey_value_property) { + drm_property_destroy(drm_dev, logicvc->colorkey_value_property); + logicvc->colorkey_value_property = NULL; + } + + if (logicvc->colorkey_enabled_property) { + drm_property_destroy(drm_dev, + logicvc->colorkey_enabled_property); + logicvc->colorkey_enabled_property = NULL; + } + return ret; } diff --git a/drivers/gpu/drm/logicvc/logicvc_layer.h b/drivers/gpu/drm/logicvc/logicvc_layer.h index c5767c81f446..69bb208ad79c 100644 --- a/drivers/gpu/drm/logicvc/logicvc_layer.h +++ b/drivers/gpu/drm/logicvc/logicvc_layer.h @@ -39,6 +39,13 @@ struct logicvc_layer_formats { uint32_t *formats; }; +struct logicvc_layer_state { + struct drm_plane_state drm_plane_state; + + bool colorkey_enabled; + uint32_t colorkey_value; +}; + struct logicvc_layer { struct logicvc_layer_config config; struct logicvc_layer_formats *formats; -- 2.26.0