Lines Matching +full:logicvc +full:- +full:3

1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2019-2022 Bootlin
42 * This allows us to stay compatible with the LogiCVC bistream definitions.
86 struct drm_device *drm_dev = drm_plane->dev; in logicvc_plane_atomic_check()
88 struct logicvc_drm *logicvc = logicvc_drm(drm_dev); in logicvc_plane_atomic_check() local
96 if (!new_state->crtc) in logicvc_plane_atomic_check()
99 crtc_state = drm_atomic_get_existing_crtc_state(new_state->state, in logicvc_plane_atomic_check()
100 new_state->crtc); in logicvc_plane_atomic_check()
102 return -EINVAL; in logicvc_plane_atomic_check()
104 if (new_state->crtc_x < 0 || new_state->crtc_y < 0) { in logicvc_plane_atomic_check()
106 "Negative on-CRTC positions are not supported.\n"); in logicvc_plane_atomic_check()
107 return -EINVAL; in logicvc_plane_atomic_check()
110 if (!logicvc->caps->layer_address) { in logicvc_plane_atomic_check()
111 ret = logicvc_layer_buffer_find_setup(logicvc, layer, new_state, in logicvc_plane_atomic_check()
122 can_position = (drm_plane->type == DRM_PLANE_TYPE_OVERLAY && in logicvc_plane_atomic_check()
123 layer->index != (logicvc->config.layers_count - 1) && in logicvc_plane_atomic_check()
124 logicvc->config.layers_configurable); in logicvc_plane_atomic_check()
141 struct logicvc_drm *logicvc = logicvc_drm(drm_plane->dev); in logicvc_plane_atomic_update() local
142 struct drm_device *drm_dev = &logicvc->drm_dev; in logicvc_plane_atomic_update()
145 struct drm_crtc *drm_crtc = &logicvc->crtc->drm_crtc; in logicvc_plane_atomic_update()
146 struct drm_display_mode *mode = &drm_crtc->state->adjusted_mode; in logicvc_plane_atomic_update()
147 struct drm_framebuffer *fb = new_state->fb; in logicvc_plane_atomic_update()
149 u32 index = layer->index; in logicvc_plane_atomic_update()
154 regmap_write(logicvc->regmap, LOGICVC_LAYER_WIDTH_REG(index), in logicvc_plane_atomic_update()
155 new_state->crtc_w - 1); in logicvc_plane_atomic_update()
156 regmap_write(logicvc->regmap, LOGICVC_LAYER_HEIGHT_REG(index), in logicvc_plane_atomic_update()
157 new_state->crtc_h - 1); in logicvc_plane_atomic_update()
159 if (logicvc->caps->layer_address) { in logicvc_plane_atomic_update()
162 regmap_write(logicvc->regmap, LOGICVC_LAYER_ADDRESS_REG(index), in logicvc_plane_atomic_update()
167 logicvc_layer_buffer_find_setup(logicvc, layer, new_state, in logicvc_plane_atomic_update()
172 regmap_write(logicvc->regmap, LOGICVC_BUFFER_SEL_REG, in logicvc_plane_atomic_update()
174 regmap_write(logicvc->regmap, LOGICVC_LAYER_HOFFSET_REG(index), in logicvc_plane_atomic_update()
176 regmap_write(logicvc->regmap, LOGICVC_LAYER_VOFFSET_REG(index), in logicvc_plane_atomic_update()
182 regmap_write(logicvc->regmap, LOGICVC_LAYER_HPOSITION_REG(index), in logicvc_plane_atomic_update()
183 mode->hdisplay - 1 - new_state->crtc_x); in logicvc_plane_atomic_update()
186 regmap_write(logicvc->regmap, LOGICVC_LAYER_VPOSITION_REG(index), in logicvc_plane_atomic_update()
187 mode->vdisplay - 1 - new_state->crtc_y); in logicvc_plane_atomic_update()
191 if (layer->config.alpha_mode == LOGICVC_LAYER_ALPHA_LAYER) { in logicvc_plane_atomic_update()
196 switch (layer->config.depth) { in logicvc_plane_atomic_update()
198 alpha_bits = 3; in logicvc_plane_atomic_update()
201 if (layer->config.colorspace == in logicvc_plane_atomic_update()
212 alpha_max = BIT(alpha_bits) - 1; in logicvc_plane_atomic_update()
213 alpha = new_state->alpha * alpha_max / DRM_BLEND_ALPHA_OPAQUE; in logicvc_plane_atomic_update()
218 regmap_write(logicvc->regmap, LOGICVC_LAYER_ALPHA_REG(index), in logicvc_plane_atomic_update()
226 if (logicvc_layer_format_inverted(fb->format->format)) in logicvc_plane_atomic_update()
231 regmap_write(logicvc->regmap, LOGICVC_LAYER_CTRL_REG(index), reg); in logicvc_plane_atomic_update()
238 struct logicvc_drm *logicvc = logicvc_drm(drm_plane->dev); in logicvc_plane_atomic_disable() local
239 u32 index = layer->index; in logicvc_plane_atomic_disable()
241 regmap_write(logicvc->regmap, LOGICVC_LAYER_CTRL_REG(index), 0); in logicvc_plane_atomic_disable()
259 int logicvc_layer_buffer_find_setup(struct logicvc_drm *logicvc, in logicvc_layer_buffer_find_setup() argument
264 struct drm_device *drm_dev = &logicvc->drm_dev; in logicvc_layer_buffer_find_setup()
265 struct drm_framebuffer *fb = state->fb; in logicvc_layer_buffer_find_setup()
267 u32 layer_bytespp = fb->format->cpp[0]; in logicvc_layer_buffer_find_setup()
268 u32 layer_stride = layer_bytespp * logicvc->config.row_stride; in logicvc_layer_buffer_find_setup()
269 u32 base_offset = layer->config.base_offset * layer_stride; in logicvc_layer_buffer_find_setup()
270 u32 buffer_offset = layer->config.buffer_offset * layer_stride; in logicvc_layer_buffer_find_setup()
278 if (!logicvc->reserved_mem_base) { in logicvc_layer_buffer_find_setup()
280 return -ENOMEM; in logicvc_layer_buffer_find_setup()
284 if (fb_addr < logicvc->reserved_mem_base) { in logicvc_layer_buffer_find_setup()
287 return -EINVAL; in logicvc_layer_buffer_find_setup()
290 fb_offset = (u32) (fb_addr - logicvc->reserved_mem_base); in logicvc_layer_buffer_find_setup()
295 return -EINVAL; in logicvc_layer_buffer_find_setup()
298 gap = fb_offset - base_offset; in logicvc_layer_buffer_find_setup()
306 gap -= buffer_sel * buffer_offset; in logicvc_layer_buffer_find_setup()
310 if (gap && layer_stride && logicvc->config.layers_configurable) { in logicvc_layer_buffer_find_setup()
315 gap -= voffset * layer_stride; in logicvc_layer_buffer_find_setup()
319 if (gap && layer_bytespp && logicvc->config.layers_configurable) { in logicvc_layer_buffer_find_setup()
324 gap -= hoffset * layer_bytespp; in logicvc_layer_buffer_find_setup()
330 layer->index, fb_offset - base_offset); in logicvc_layer_buffer_find_setup()
331 return -EINVAL; in logicvc_layer_buffer_find_setup()
335 layer->index, fb_offset - base_offset); in logicvc_layer_buffer_find_setup()
337 drm_dbg_kms(drm_dev, "- buffer_sel = 0x%x chunks of 0x%x bytes\n", in logicvc_layer_buffer_find_setup()
339 drm_dbg_kms(drm_dev, "- voffset = 0x%x chunks of 0x%x bytes\n", voffset, in logicvc_layer_buffer_find_setup()
341 drm_dbg_kms(drm_dev, "- hoffset = 0x%x chunks of 0x%x bytes\n", hoffset, in logicvc_layer_buffer_find_setup()
345 setup->buffer_sel = buffer_sel; in logicvc_layer_buffer_find_setup()
346 setup->voffset = voffset; in logicvc_layer_buffer_find_setup()
347 setup->hoffset = hoffset; in logicvc_layer_buffer_find_setup()
358 alpha = (layer->config.alpha_mode == LOGICVC_LAYER_ALPHA_PIXEL); in logicvc_layer_formats_lookup()
361 if (logicvc_layer_formats[i].colorspace == layer->config.colorspace && in logicvc_layer_formats_lookup()
362 logicvc_layer_formats[i].depth == layer->config.depth && in logicvc_layer_formats_lookup()
376 while (formats->formats[count] != DRM_FORMAT_INVALID) in logicvc_layer_formats_count()
382 static int logicvc_layer_config_parse(struct logicvc_drm *logicvc, in logicvc_layer_config_parse() argument
385 struct device_node *of_node = layer->of_node; in logicvc_layer_config_parse()
386 struct logicvc_layer_config *config = &layer->config; in logicvc_layer_config_parse()
391 &config->primary); in logicvc_layer_config_parse()
395 &config->colorspace); in logicvc_layer_config_parse()
401 &config->depth); in logicvc_layer_config_parse()
407 &config->alpha_mode); in logicvc_layer_config_parse()
414 if (logicvc->caps->layer_address) in logicvc_layer_config_parse()
419 &config->base_offset); in logicvc_layer_config_parse()
425 &config->buffer_offset); in logicvc_layer_config_parse()
432 struct logicvc_layer *logicvc_layer_get_from_index(struct logicvc_drm *logicvc, in logicvc_layer_get_from_index() argument
437 list_for_each_entry(layer, &logicvc->layers_list, list) in logicvc_layer_get_from_index()
438 if (layer->index == index) in logicvc_layer_get_from_index()
444 struct logicvc_layer *logicvc_layer_get_from_type(struct logicvc_drm *logicvc, in logicvc_layer_get_from_type() argument
449 list_for_each_entry(layer, &logicvc->layers_list, list) in logicvc_layer_get_from_type()
450 if (layer->drm_plane.type == type) in logicvc_layer_get_from_type()
456 struct logicvc_layer *logicvc_layer_get_primary(struct logicvc_drm *logicvc) in logicvc_layer_get_primary() argument
458 return logicvc_layer_get_from_type(logicvc, DRM_PLANE_TYPE_PRIMARY); in logicvc_layer_get_primary()
461 static int logicvc_layer_init(struct logicvc_drm *logicvc, in logicvc_layer_init() argument
464 struct drm_device *drm_dev = &logicvc->drm_dev; in logicvc_layer_init()
465 struct device *dev = drm_dev->dev; in logicvc_layer_init()
475 ret = -ENOMEM; in logicvc_layer_init()
479 layer->of_node = of_node; in logicvc_layer_init()
480 layer->index = index; in logicvc_layer_init()
482 ret = logicvc_layer_config_parse(logicvc, layer); in logicvc_layer_init()
493 ret = -EINVAL; in logicvc_layer_init()
500 if (logicvc->config.background_layer && in logicvc_layer_init()
501 index == (logicvc->config.layers_count - 1)) { in logicvc_layer_init()
511 regmap_write(logicvc->regmap, LOGICVC_BACKGROUND_COLOR_REG, in logicvc_layer_init()
519 if (layer->config.primary) in logicvc_layer_init()
524 ret = drm_universal_plane_init(drm_dev, &layer->drm_plane, 0, in logicvc_layer_init()
525 &logicvc_plane_funcs, formats->formats, in logicvc_layer_init()
532 drm_plane_helper_add(&layer->drm_plane, &logicvc_plane_helper_funcs); in logicvc_layer_init()
534 zpos = logicvc->config.layers_count - index - 1; in logicvc_layer_init()
537 if (layer->config.alpha_mode == LOGICVC_LAYER_ALPHA_LAYER) in logicvc_layer_init()
538 drm_plane_create_alpha_property(&layer->drm_plane); in logicvc_layer_init()
540 drm_plane_create_zpos_immutable_property(&layer->drm_plane, zpos); in logicvc_layer_init()
544 layer->formats = formats; in logicvc_layer_init()
546 list_add_tail(&layer->list, &logicvc->layers_list); in logicvc_layer_init()
557 static void logicvc_layer_fini(struct logicvc_drm *logicvc, in logicvc_layer_fini() argument
560 struct device *dev = logicvc->drm_dev.dev; in logicvc_layer_fini()
562 list_del(&layer->list); in logicvc_layer_fini()
566 void logicvc_layers_attach_crtc(struct logicvc_drm *logicvc) in logicvc_layers_attach_crtc() argument
568 uint32_t possible_crtcs = drm_crtc_mask(&logicvc->crtc->drm_crtc); in logicvc_layers_attach_crtc()
571 list_for_each_entry(layer, &logicvc->layers_list, list) { in logicvc_layers_attach_crtc()
572 if (layer->drm_plane.type != DRM_PLANE_TYPE_OVERLAY) in logicvc_layers_attach_crtc()
575 layer->drm_plane.possible_crtcs = possible_crtcs; in logicvc_layers_attach_crtc()
579 int logicvc_layers_init(struct logicvc_drm *logicvc) in logicvc_layers_init() argument
581 struct drm_device *drm_dev = &logicvc->drm_dev; in logicvc_layers_init()
582 struct device *dev = drm_dev->dev; in logicvc_layers_init()
583 struct device_node *of_node = dev->of_node; in logicvc_layers_init()
593 ret = -ENODEV; in logicvc_layers_init()
607 layer = logicvc_layer_get_from_index(logicvc, index); in logicvc_layers_init()
614 ret = logicvc_layer_init(logicvc, layer_node, index); in logicvc_layers_init()
626 list_for_each_entry_safe(layer, next, &logicvc->layers_list, list) in logicvc_layers_init()
627 logicvc_layer_fini(logicvc, layer); in logicvc_layers_init()