From cc431212710860143b13877a0aa9d11a42598f49 Mon Sep 17 00:00:00 2001 From: Noralf Trønnes Date: Fri, 19 Jul 2019 17:59:15 +0200 Subject: drm/tinydrm/mipi-dbi: Add mipi_dbi_init_with_formats() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The MIPI DBI standard support more pixel formats than what this helper supports. Add an init function that lets the driver use different format(s). This avoids open coding mipi_dbi_init() in st7586. st7586 sets preferred_depth but this is not necessary since it only supports one format. v2: Forgot to remove the mipi->rotation assignment in st7586, mipi_dbi_init_with_formats() handles it. Cc: David Lechner Acked-by: David Lechner Signed-off-by: Noralf Trønnes Tested-by: David Lechner Link: https://patchwork.freedesktop.org/patch/msgid/20190719155916.62465-11-noralf@tronnes.org --- drivers/gpu/drm/tinydrm/mipi-dbi.c | 61 ++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'drivers/gpu/drm/tinydrm/mipi-dbi.c') diff --git a/drivers/gpu/drm/tinydrm/mipi-dbi.c b/drivers/gpu/drm/tinydrm/mipi-dbi.c index 73db287e5c52..a264c0bb74b0 100644 --- a/drivers/gpu/drm/tinydrm/mipi-dbi.c +++ b/drivers/gpu/drm/tinydrm/mipi-dbi.c @@ -412,27 +412,34 @@ static const uint32_t mipi_dbi_formats[] = { }; /** - * mipi_dbi_init - MIPI DBI initialization + * mipi_dbi_init_with_formats - MIPI DBI initialization with custom formats * @mipi: &mipi_dbi structure to initialize * @funcs: Display pipe functions + * @formats: Array of supported formats (DRM_FORMAT\_\*). + * @format_count: Number of elements in @formats * @mode: Display mode * @rotation: Initial rotation in degrees Counter Clock Wise + * @tx_buf_size: Allocate a transmit buffer of this size. * * This function sets up a &drm_simple_display_pipe with a &drm_connector that * has one fixed &drm_display_mode which is rotated according to @rotation. * This mode is used to set the mode config min/max width/height properties. - * Additionally &mipi_dbi.tx_buf is allocated. * - * Supported formats: Native RGB565 and emulated XRGB8888. + * Use mipi_dbi_init() if you don't need custom formats. + * + * Note: + * Some of the helper functions expects RGB565 to be the default format and the + * transmit buffer sized to fit that. * * Returns: * Zero on success, negative error code on failure. */ -int mipi_dbi_init(struct mipi_dbi *mipi, - const struct drm_simple_display_pipe_funcs *funcs, - const struct drm_display_mode *mode, unsigned int rotation) +int mipi_dbi_init_with_formats(struct mipi_dbi *mipi, + const struct drm_simple_display_pipe_funcs *funcs, + const uint32_t *formats, unsigned int format_count, + const struct drm_display_mode *mode, + unsigned int rotation, size_t tx_buf_size) { - size_t bufsize = mode->vdisplay * mode->hdisplay * sizeof(u16); struct drm_device *drm = &mipi->drm; int ret; @@ -441,14 +448,13 @@ int mipi_dbi_init(struct mipi_dbi *mipi, mutex_init(&mipi->cmdlock); - mipi->tx_buf = devm_kmalloc(drm->dev, bufsize, GFP_KERNEL); + mipi->tx_buf = devm_kmalloc(drm->dev, tx_buf_size, GFP_KERNEL); if (!mipi->tx_buf) return -ENOMEM; ret = tinydrm_display_pipe_init(drm, &mipi->pipe, funcs, DRM_MODE_CONNECTOR_SPI, - mipi_dbi_formats, - ARRAY_SIZE(mipi_dbi_formats), mode, + formats, format_count, mode, rotation); if (ret) return ret; @@ -456,14 +462,43 @@ int mipi_dbi_init(struct mipi_dbi *mipi, drm_plane_enable_fb_damage_clips(&mipi->pipe.plane); drm->mode_config.funcs = &mipi_dbi_mode_config_funcs; - drm->mode_config.preferred_depth = 16; mipi->rotation = rotation; - DRM_DEBUG_KMS("preferred_depth=%u, rotation = %u\n", - drm->mode_config.preferred_depth, rotation); + DRM_DEBUG_KMS("rotation = %u\n", rotation); return 0; } +EXPORT_SYMBOL(mipi_dbi_init_with_formats); + +/** + * mipi_dbi_init - MIPI DBI initialization + * @mipi: &mipi_dbi structure to initialize + * @funcs: Display pipe functions + * @mode: Display mode + * @rotation: Initial rotation in degrees Counter Clock Wise + * + * This function sets up a &drm_simple_display_pipe with a &drm_connector that + * has one fixed &drm_display_mode which is rotated according to @rotation. + * This mode is used to set the mode config min/max width/height properties. + * Additionally &mipi_dbi.tx_buf is allocated. + * + * Supported formats: Native RGB565 and emulated XRGB8888. + * + * Returns: + * Zero on success, negative error code on failure. + */ +int mipi_dbi_init(struct mipi_dbi *mipi, + const struct drm_simple_display_pipe_funcs *funcs, + const struct drm_display_mode *mode, unsigned int rotation) +{ + size_t bufsize = mode->vdisplay * mode->hdisplay * sizeof(u16); + + mipi->drm.mode_config.preferred_depth = 16; + + return mipi_dbi_init_with_formats(mipi, funcs, mipi_dbi_formats, + ARRAY_SIZE(mipi_dbi_formats), mode, + rotation, bufsize); +} EXPORT_SYMBOL(mipi_dbi_init); /** -- cgit v1.2.3