diff options
Diffstat (limited to 'drivers/gpu/drm/exynos/exynos_drm_vidi.c')
| -rw-r--r-- | drivers/gpu/drm/exynos/exynos_drm_vidi.c | 712 |
1 files changed, 279 insertions, 433 deletions
diff --git a/drivers/gpu/drm/exynos/exynos_drm_vidi.c b/drivers/gpu/drm/exynos/exynos_drm_vidi.c index 41cc74d83e4e..64c69dd2966e 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_vidi.c +++ b/drivers/gpu/drm/exynos/exynos_drm_vidi.c @@ -1,65 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* exynos_drm_vidi.c * * Copyright (C) 2012 Samsung Electronics Co.Ltd * Authors: * Inki Dae <inki.dae@samsung.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * */ -#include <drm/drmP.h> +#include <linux/component.h> #include <linux/kernel.h> -#include <linux/module.h> #include <linux/platform_device.h> +#include <linux/timer.h> -#include <drm/exynos_drm.h> - +#include <drm/drm_atomic_helper.h> #include <drm/drm_edid.h> -#include <drm/drm_crtc_helper.h> +#include <drm/drm_framebuffer.h> +#include <drm/drm_print.h> +#include <drm/drm_probe_helper.h> +#include <drm/drm_simple_kms_helper.h> +#include <drm/drm_vblank.h> +#include <drm/exynos_drm.h> -#include "exynos_drm_drv.h" #include "exynos_drm_crtc.h" -#include "exynos_drm_encoder.h" +#include "exynos_drm_drv.h" +#include "exynos_drm_fb.h" +#include "exynos_drm_plane.h" +#include "exynos_drm_vidi.h" + +/* VIDI uses fixed refresh rate of 50Hz */ +#define VIDI_REFRESH_TIME (1000 / 50) /* vidi has totally three virtual windows. */ #define WINDOWS_NR 3 -#define get_vidi_context(dev) platform_get_drvdata(to_platform_device(dev)) - -struct vidi_win_data { - unsigned int offset_x; - unsigned int offset_y; - unsigned int ovl_width; - unsigned int ovl_height; - unsigned int fb_width; - unsigned int fb_height; - unsigned int bpp; - dma_addr_t dma_addr; - unsigned int buf_offsize; - unsigned int line_size; /* bytes */ - bool enabled; -}; +#define ctx_from_connector(c) container_of(c, struct vidi_context, \ + connector) struct vidi_context { - struct exynos_drm_subdrv subdrv; - struct drm_crtc *crtc; - struct vidi_win_data win_data[WINDOWS_NR]; - struct edid *raw_edid; + struct drm_encoder encoder; + struct drm_device *drm_dev; + struct device *dev; + struct exynos_drm_crtc *crtc; + struct drm_connector connector; + struct exynos_drm_plane planes[WINDOWS_NR]; + const struct drm_edid *raw_edid; unsigned int clkdiv; - unsigned int default_win; - unsigned long irq_flags; unsigned int connected; - bool vblank_on; bool suspended; - bool direct_vblank; - struct work_struct work; + struct timer_list timer; struct mutex lock; }; +static inline struct vidi_context *encoder_to_vidi(struct drm_encoder *e) +{ + return container_of(e, struct vidi_context, encoder); +} + static const char fake_edid_info[] = { 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x4c, 0x2d, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00, 0x30, 0x12, 0x01, 0x03, 0x80, 0x10, 0x09, 0x78, @@ -85,354 +80,98 @@ static const char fake_edid_info[] = { 0x00, 0x00, 0x00, 0x06 }; -static bool vidi_display_is_connected(struct device *dev) -{ - struct vidi_context *ctx = get_vidi_context(dev); - - /* - * connection request would come from user side - * to do hotplug through specific ioctl. - */ - return ctx->connected ? true : false; -} - -static struct edid *vidi_get_edid(struct device *dev, - struct drm_connector *connector) -{ - struct vidi_context *ctx = get_vidi_context(dev); - struct edid *edid; - int edid_len; - - /* - * the edid data comes from user side and it would be set - * to ctx->raw_edid through specific ioctl. - */ - if (!ctx->raw_edid) { - DRM_DEBUG_KMS("raw_edid is null.\n"); - return ERR_PTR(-EFAULT); - } - - edid_len = (1 + ctx->raw_edid->extensions) * EDID_LENGTH; - edid = kmemdup(ctx->raw_edid, edid_len, GFP_KERNEL); - if (!edid) { - DRM_DEBUG_KMS("failed to allocate edid\n"); - return ERR_PTR(-ENOMEM); - } - - return edid; -} - -static void *vidi_get_panel(struct device *dev) -{ - /* TODO. */ - - return NULL; -} - -static int vidi_check_mode(struct device *dev, struct drm_display_mode *mode) -{ - /* TODO. */ - - return 0; -} - -static int vidi_display_power_on(struct device *dev, int mode) -{ - /* TODO */ - - return 0; -} - -static struct exynos_drm_display_ops vidi_display_ops = { - .type = EXYNOS_DISPLAY_TYPE_VIDI, - .is_connected = vidi_display_is_connected, - .get_edid = vidi_get_edid, - .get_panel = vidi_get_panel, - .check_mode = vidi_check_mode, - .power_on = vidi_display_power_on, +static const uint32_t formats[] = { + DRM_FORMAT_XRGB8888, + DRM_FORMAT_ARGB8888, + DRM_FORMAT_NV12, }; -static void vidi_dpms(struct device *subdrv_dev, int mode) -{ - struct vidi_context *ctx = get_vidi_context(subdrv_dev); - - DRM_DEBUG_KMS("%d\n", mode); - - mutex_lock(&ctx->lock); - - switch (mode) { - case DRM_MODE_DPMS_ON: - /* TODO. */ - break; - case DRM_MODE_DPMS_STANDBY: - case DRM_MODE_DPMS_SUSPEND: - case DRM_MODE_DPMS_OFF: - /* TODO. */ - break; - default: - DRM_DEBUG_KMS("unspecified mode %d\n", mode); - break; - } - - mutex_unlock(&ctx->lock); -} - -static void vidi_apply(struct device *subdrv_dev) -{ - struct vidi_context *ctx = get_vidi_context(subdrv_dev); - struct exynos_drm_manager *mgr = ctx->subdrv.manager; - struct exynos_drm_manager_ops *mgr_ops = mgr->ops; - struct exynos_drm_overlay_ops *ovl_ops = mgr->overlay_ops; - struct vidi_win_data *win_data; - int i; - - for (i = 0; i < WINDOWS_NR; i++) { - win_data = &ctx->win_data[i]; - if (win_data->enabled && (ovl_ops && ovl_ops->commit)) - ovl_ops->commit(subdrv_dev, i); - } - - if (mgr_ops && mgr_ops->commit) - mgr_ops->commit(subdrv_dev); -} - -static void vidi_commit(struct device *dev) -{ - struct vidi_context *ctx = get_vidi_context(dev); - - if (ctx->suspended) - return; -} +static const enum drm_plane_type vidi_win_types[WINDOWS_NR] = { + DRM_PLANE_TYPE_PRIMARY, + DRM_PLANE_TYPE_OVERLAY, + DRM_PLANE_TYPE_CURSOR, +}; -static int vidi_enable_vblank(struct device *dev) +static int vidi_enable_vblank(struct exynos_drm_crtc *crtc) { - struct vidi_context *ctx = get_vidi_context(dev); + struct vidi_context *ctx = crtc->ctx; if (ctx->suspended) return -EPERM; - if (!test_and_set_bit(0, &ctx->irq_flags)) - ctx->vblank_on = true; - - ctx->direct_vblank = true; - - /* - * in case of page flip request, vidi_finish_pageflip function - * will not be called because direct_vblank is true and then - * that function will be called by overlay_ops->commit callback - */ - schedule_work(&ctx->work); + mod_timer(&ctx->timer, + jiffies + msecs_to_jiffies(VIDI_REFRESH_TIME) - 1); return 0; } -static void vidi_disable_vblank(struct device *dev) +static void vidi_disable_vblank(struct exynos_drm_crtc *crtc) { - struct vidi_context *ctx = get_vidi_context(dev); - - if (ctx->suspended) - return; - - if (test_and_clear_bit(0, &ctx->irq_flags)) - ctx->vblank_on = false; } -static struct exynos_drm_manager_ops vidi_manager_ops = { - .dpms = vidi_dpms, - .apply = vidi_apply, - .commit = vidi_commit, - .enable_vblank = vidi_enable_vblank, - .disable_vblank = vidi_disable_vblank, -}; - -static void vidi_win_mode_set(struct device *dev, - struct exynos_drm_overlay *overlay) +static void vidi_update_plane(struct exynos_drm_crtc *crtc, + struct exynos_drm_plane *plane) { - struct vidi_context *ctx = get_vidi_context(dev); - struct vidi_win_data *win_data; - int win; - unsigned long offset; - - if (!overlay) { - dev_err(dev, "overlay is NULL\n"); - return; - } - - win = overlay->zpos; - if (win == DEFAULT_ZPOS) - win = ctx->default_win; - - if (win < 0 || win >= WINDOWS_NR) - return; - - offset = overlay->fb_x * (overlay->bpp >> 3); - offset += overlay->fb_y * overlay->pitch; - - DRM_DEBUG_KMS("offset = 0x%lx, pitch = %x\n", offset, overlay->pitch); - - win_data = &ctx->win_data[win]; - - win_data->offset_x = overlay->crtc_x; - win_data->offset_y = overlay->crtc_y; - win_data->ovl_width = overlay->crtc_width; - win_data->ovl_height = overlay->crtc_height; - win_data->fb_width = overlay->fb_width; - win_data->fb_height = overlay->fb_height; - win_data->dma_addr = overlay->dma_addr[0] + offset; - win_data->bpp = overlay->bpp; - win_data->buf_offsize = (overlay->fb_width - overlay->crtc_width) * - (overlay->bpp >> 3); - win_data->line_size = overlay->crtc_width * (overlay->bpp >> 3); - - /* - * some parts of win_data should be transferred to user side - * through specific ioctl. - */ - - DRM_DEBUG_KMS("offset_x = %d, offset_y = %d\n", - win_data->offset_x, win_data->offset_y); - DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n", - win_data->ovl_width, win_data->ovl_height); - DRM_DEBUG_KMS("paddr = 0x%lx\n", (unsigned long)win_data->dma_addr); - DRM_DEBUG_KMS("fb_width = %d, crtc_width = %d\n", - overlay->fb_width, overlay->crtc_width); -} - -static void vidi_win_commit(struct device *dev, int zpos) -{ - struct vidi_context *ctx = get_vidi_context(dev); - struct vidi_win_data *win_data; - int win = zpos; + struct drm_plane_state *state = plane->base.state; + struct vidi_context *ctx = crtc->ctx; + dma_addr_t addr; if (ctx->suspended) return; - if (win == DEFAULT_ZPOS) - win = ctx->default_win; - - if (win < 0 || win >= WINDOWS_NR) - return; - - win_data = &ctx->win_data[win]; - - win_data->enabled = true; - - DRM_DEBUG_KMS("dma_addr = 0x%x\n", win_data->dma_addr); - - if (ctx->vblank_on) - schedule_work(&ctx->work); + addr = exynos_drm_fb_dma_addr(state->fb, 0); + DRM_DEV_DEBUG_KMS(ctx->dev, "dma_addr = %pad\n", &addr); } -static void vidi_win_disable(struct device *dev, int zpos) +static void vidi_atomic_enable(struct exynos_drm_crtc *crtc) { - struct vidi_context *ctx = get_vidi_context(dev); - struct vidi_win_data *win_data; - int win = zpos; + struct vidi_context *ctx = crtc->ctx; - if (win == DEFAULT_ZPOS) - win = ctx->default_win; + mutex_lock(&ctx->lock); - if (win < 0 || win >= WINDOWS_NR) - return; + ctx->suspended = false; - win_data = &ctx->win_data[win]; - win_data->enabled = false; + mutex_unlock(&ctx->lock); - /* TODO. */ + drm_crtc_vblank_on(&crtc->base); } -static struct exynos_drm_overlay_ops vidi_overlay_ops = { - .mode_set = vidi_win_mode_set, - .commit = vidi_win_commit, - .disable = vidi_win_disable, -}; - -static struct exynos_drm_manager vidi_manager = { - .pipe = -1, - .ops = &vidi_manager_ops, - .overlay_ops = &vidi_overlay_ops, - .display_ops = &vidi_display_ops, -}; - -static void vidi_fake_vblank_handler(struct work_struct *work) +static void vidi_atomic_disable(struct exynos_drm_crtc *crtc) { - struct vidi_context *ctx = container_of(work, struct vidi_context, - work); - struct exynos_drm_subdrv *subdrv = &ctx->subdrv; - struct exynos_drm_manager *manager = subdrv->manager; - - if (manager->pipe < 0) - return; + struct vidi_context *ctx = crtc->ctx; - /* refresh rate is about 50Hz. */ - usleep_range(16000, 20000); + drm_crtc_vblank_off(&crtc->base); mutex_lock(&ctx->lock); - if (ctx->direct_vblank) { - drm_handle_vblank(subdrv->drm_dev, manager->pipe); - ctx->direct_vblank = false; - mutex_unlock(&ctx->lock); - return; - } + ctx->suspended = true; mutex_unlock(&ctx->lock); - - exynos_drm_crtc_finish_pageflip(subdrv->drm_dev, manager->pipe); } -static int vidi_subdrv_probe(struct drm_device *drm_dev, struct device *dev) -{ - /* - * enable drm irq mode. - * - with irq_enabled = 1, we can use the vblank feature. - * - * P.S. note that we wouldn't use drm irq handler but - * just specific driver own one instead because - * drm framework supports only one irq handler. - */ - drm_dev->irq_enabled = 1; - - /* - * with vblank_disable_allowed = 1, vblank interrupt will be disabled - * by drm timer once a current process gives up ownership of - * vblank event.(after drm_vblank_put function is called) - */ - drm_dev->vblank_disable_allowed = 1; - - return 0; -} - -static void vidi_subdrv_remove(struct drm_device *drm_dev, struct device *dev) -{ - /* TODO. */ -} +static const struct exynos_drm_crtc_ops vidi_crtc_ops = { + .atomic_enable = vidi_atomic_enable, + .atomic_disable = vidi_atomic_disable, + .enable_vblank = vidi_enable_vblank, + .disable_vblank = vidi_disable_vblank, + .update_plane = vidi_update_plane, + .atomic_flush = exynos_crtc_handle_event, +}; -static int vidi_power_on(struct vidi_context *ctx, bool enable) +static void vidi_fake_vblank_timer(struct timer_list *t) { - struct exynos_drm_subdrv *subdrv = &ctx->subdrv; - struct device *dev = subdrv->dev; - - if (enable) { - ctx->suspended = false; - - /* if vblank was enabled status, enable it again. */ - if (test_and_clear_bit(0, &ctx->irq_flags)) - vidi_enable_vblank(dev); - - vidi_apply(dev); - } else { - ctx->suspended = true; - } + struct vidi_context *ctx = timer_container_of(ctx, t, timer); - return 0; + if (drm_crtc_handle_vblank(&ctx->crtc->base)) + mod_timer(&ctx->timer, + jiffies + msecs_to_jiffies(VIDI_REFRESH_TIME) - 1); } -static int vidi_show_connection(struct device *dev, +static ssize_t vidi_show_connection(struct device *dev, struct device_attribute *attr, char *buf) { + struct vidi_context *ctx = dev_get_drvdata(dev); int rc; - struct vidi_context *ctx = get_vidi_context(dev); mutex_lock(&ctx->lock); @@ -443,11 +182,11 @@ static int vidi_show_connection(struct device *dev, return rc; } -static int vidi_store_connection(struct device *dev, +static ssize_t vidi_store_connection(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { - struct vidi_context *ctx = get_vidi_context(dev); + struct vidi_context *ctx = dev_get_drvdata(dev); int ret; ret = kstrtoint(buf, 0, &ctx->connected); @@ -457,19 +196,18 @@ static int vidi_store_connection(struct device *dev, if (ctx->connected > 1) return -EINVAL; - /* use fake edid data for test. */ - if (!ctx->raw_edid) - ctx->raw_edid = (struct edid *)fake_edid_info; - - /* if raw_edid isn't same as fake data then it can't be tested. */ - if (ctx->raw_edid != (struct edid *)fake_edid_info) { - DRM_DEBUG_KMS("edid data is not fake data.\n"); + /* + * Use fake edid data for test. If raw_edid is set then it can't be + * tested. + */ + if (ctx->raw_edid) { + DRM_DEV_DEBUG_KMS(dev, "edid data is not fake data.\n"); return -EINVAL; } - DRM_DEBUG_KMS("requested connection.\n"); + DRM_DEV_DEBUG_KMS(dev, "requested connection.\n"); - drm_helper_hpd_irq_event(ctx->subdrv.drm_dev); + drm_helper_hpd_irq_event(ctx->drm_dev); return len; } @@ -477,151 +215,259 @@ static int vidi_store_connection(struct device *dev, static DEVICE_ATTR(connection, 0644, vidi_show_connection, vidi_store_connection); +static struct attribute *vidi_attrs[] = { + &dev_attr_connection.attr, + NULL, +}; +ATTRIBUTE_GROUPS(vidi); + int vidi_connection_ioctl(struct drm_device *drm_dev, void *data, struct drm_file *file_priv) { - struct vidi_context *ctx = NULL; - struct drm_encoder *encoder; - struct exynos_drm_manager *manager; - struct exynos_drm_display_ops *display_ops; + struct vidi_context *ctx = dev_get_drvdata(drm_dev->dev); struct drm_exynos_vidi_connection *vidi = data; - int edid_len; if (!vidi) { - DRM_DEBUG_KMS("user data for vidi is null.\n"); + DRM_DEV_DEBUG_KMS(ctx->dev, + "user data for vidi is null.\n"); return -EINVAL; } if (vidi->connection > 1) { - DRM_DEBUG_KMS("connection should be 0 or 1.\n"); - return -EINVAL; - } - - list_for_each_entry(encoder, &drm_dev->mode_config.encoder_list, - head) { - manager = exynos_drm_get_manager(encoder); - display_ops = manager->display_ops; - - if (display_ops->type == EXYNOS_DISPLAY_TYPE_VIDI) { - ctx = get_vidi_context(manager->dev); - break; - } - } - - if (!ctx) { - DRM_DEBUG_KMS("not found virtual device type encoder.\n"); + DRM_DEV_DEBUG_KMS(ctx->dev, + "connection should be 0 or 1.\n"); return -EINVAL; } if (ctx->connected == vidi->connection) { - DRM_DEBUG_KMS("same connection request.\n"); + DRM_DEV_DEBUG_KMS(ctx->dev, + "same connection request.\n"); return -EINVAL; } if (vidi->connection) { - struct edid *raw_edid = (struct edid *)(uint32_t)vidi->edid; - if (!drm_edid_is_valid(raw_edid)) { - DRM_DEBUG_KMS("edid data is invalid.\n"); - return -EINVAL; - } - edid_len = (1 + raw_edid->extensions) * EDID_LENGTH; - ctx->raw_edid = kmemdup(raw_edid, edid_len, GFP_KERNEL); - if (!ctx->raw_edid) { - DRM_DEBUG_KMS("failed to allocate raw_edid.\n"); + const struct drm_edid *drm_edid; + const struct edid *raw_edid; + size_t size; + + raw_edid = (const struct edid *)(unsigned long)vidi->edid; + size = (raw_edid->extensions + 1) * EDID_LENGTH; + + drm_edid = drm_edid_alloc(raw_edid, size); + if (!drm_edid) return -ENOMEM; + + if (!drm_edid_valid(drm_edid)) { + drm_edid_free(drm_edid); + DRM_DEV_DEBUG_KMS(ctx->dev, + "edid data is invalid.\n"); + return -EINVAL; } + ctx->raw_edid = drm_edid; } else { - /* - * with connection = 0, free raw_edid - * only if raw edid data isn't same as fake data. - */ - if (ctx->raw_edid && ctx->raw_edid != - (struct edid *)fake_edid_info) { - kfree(ctx->raw_edid); - ctx->raw_edid = NULL; - } + /* with connection = 0, free raw_edid */ + drm_edid_free(ctx->raw_edid); + ctx->raw_edid = NULL; } ctx->connected = vidi->connection; - drm_helper_hpd_irq_event(ctx->subdrv.drm_dev); + drm_helper_hpd_irq_event(ctx->drm_dev); return 0; } -static int vidi_probe(struct platform_device *pdev) +static enum drm_connector_status vidi_detect(struct drm_connector *connector, + bool force) { - struct device *dev = &pdev->dev; - struct vidi_context *ctx; - struct exynos_drm_subdrv *subdrv; - int ret; + struct vidi_context *ctx = ctx_from_connector(connector); - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); - if (!ctx) - return -ENOMEM; + /* + * connection request would come from user side + * to do hotplug through specific ioctl. + */ + return ctx->connected ? connector_status_connected : + connector_status_disconnected; +} - ctx->default_win = 0; +static void vidi_connector_destroy(struct drm_connector *connector) +{ +} - INIT_WORK(&ctx->work, vidi_fake_vblank_handler); +static const struct drm_connector_funcs vidi_connector_funcs = { + .fill_modes = drm_helper_probe_single_connector_modes, + .detect = vidi_detect, + .destroy = vidi_connector_destroy, + .reset = drm_atomic_helper_connector_reset, + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, +}; - subdrv = &ctx->subdrv; - subdrv->dev = dev; - subdrv->manager = &vidi_manager; - subdrv->probe = vidi_subdrv_probe; - subdrv->remove = vidi_subdrv_remove; +static int vidi_get_modes(struct drm_connector *connector) +{ + struct vidi_context *ctx = ctx_from_connector(connector); + const struct drm_edid *drm_edid; + int count; - mutex_init(&ctx->lock); + if (ctx->raw_edid) + drm_edid = drm_edid_dup(ctx->raw_edid); + else + drm_edid = drm_edid_alloc(fake_edid_info, sizeof(fake_edid_info)); - platform_set_drvdata(pdev, ctx); + drm_edid_connector_update(connector, drm_edid); - ret = device_create_file(dev, &dev_attr_connection); - if (ret < 0) - DRM_INFO("failed to create connection sysfs.\n"); + count = drm_edid_connector_add_modes(connector); - exynos_drm_subdrv_register(subdrv); + drm_edid_free(drm_edid); - return 0; + return count; } -static int vidi_remove(struct platform_device *pdev) +static const struct drm_connector_helper_funcs vidi_connector_helper_funcs = { + .get_modes = vidi_get_modes, +}; + +static int vidi_create_connector(struct drm_encoder *encoder) { - struct vidi_context *ctx = platform_get_drvdata(pdev); + struct vidi_context *ctx = encoder_to_vidi(encoder); + struct drm_connector *connector = &ctx->connector; + int ret; - exynos_drm_subdrv_unregister(&ctx->subdrv); + connector->polled = DRM_CONNECTOR_POLL_HPD; - if (ctx->raw_edid != (struct edid *)fake_edid_info) { - kfree(ctx->raw_edid); - ctx->raw_edid = NULL; + ret = drm_connector_init(ctx->drm_dev, connector, + &vidi_connector_funcs, DRM_MODE_CONNECTOR_VIRTUAL); + if (ret) { + DRM_DEV_ERROR(ctx->dev, + "Failed to initialize connector with drm\n"); + return ret; } + drm_connector_helper_add(connector, &vidi_connector_helper_funcs); + drm_connector_attach_encoder(connector, encoder); + return 0; } -#ifdef CONFIG_PM_SLEEP -static int vidi_suspend(struct device *dev) +static void exynos_vidi_mode_set(struct drm_encoder *encoder, + struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) +{ +} + +static void exynos_vidi_enable(struct drm_encoder *encoder) { - struct vidi_context *ctx = get_vidi_context(dev); +} + +static void exynos_vidi_disable(struct drm_encoder *encoder) +{ +} + +static const struct drm_encoder_helper_funcs exynos_vidi_encoder_helper_funcs = { + .mode_set = exynos_vidi_mode_set, + .enable = exynos_vidi_enable, + .disable = exynos_vidi_disable, +}; + +static int vidi_bind(struct device *dev, struct device *master, void *data) +{ + struct vidi_context *ctx = dev_get_drvdata(dev); + struct drm_device *drm_dev = data; + struct drm_encoder *encoder = &ctx->encoder; + struct exynos_drm_plane *exynos_plane; + struct exynos_drm_plane_config plane_config = { 0 }; + unsigned int i; + int ret; + + ctx->drm_dev = drm_dev; + + plane_config.pixel_formats = formats; + plane_config.num_pixel_formats = ARRAY_SIZE(formats); + + for (i = 0; i < WINDOWS_NR; i++) { + plane_config.zpos = i; + plane_config.type = vidi_win_types[i]; + + ret = exynos_plane_init(drm_dev, &ctx->planes[i], i, + &plane_config); + if (ret) + return ret; + } + + exynos_plane = &ctx->planes[DEFAULT_WIN]; + ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base, + EXYNOS_DISPLAY_TYPE_VIDI, &vidi_crtc_ops, ctx); + if (IS_ERR(ctx->crtc)) { + DRM_DEV_ERROR(dev, "failed to create crtc.\n"); + return PTR_ERR(ctx->crtc); + } + + drm_simple_encoder_init(drm_dev, encoder, DRM_MODE_ENCODER_TMDS); + + drm_encoder_helper_add(encoder, &exynos_vidi_encoder_helper_funcs); + + ret = exynos_drm_set_possible_crtcs(encoder, EXYNOS_DISPLAY_TYPE_VIDI); + if (ret < 0) + return ret; + + ret = vidi_create_connector(encoder); + if (ret) { + DRM_DEV_ERROR(dev, "failed to create connector ret = %d\n", + ret); + drm_encoder_cleanup(encoder); + return ret; + } - return vidi_power_on(ctx, false); + return 0; } -static int vidi_resume(struct device *dev) + +static void vidi_unbind(struct device *dev, struct device *master, void *data) { - struct vidi_context *ctx = get_vidi_context(dev); + struct vidi_context *ctx = dev_get_drvdata(dev); - return vidi_power_on(ctx, true); + timer_delete_sync(&ctx->timer); } -#endif -static const struct dev_pm_ops vidi_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(vidi_suspend, vidi_resume) +static const struct component_ops vidi_component_ops = { + .bind = vidi_bind, + .unbind = vidi_unbind, }; +static int vidi_probe(struct platform_device *pdev) +{ + struct vidi_context *ctx; + struct device *dev = &pdev->dev; + + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + ctx->dev = dev; + + timer_setup(&ctx->timer, vidi_fake_vblank_timer, 0); + + mutex_init(&ctx->lock); + + platform_set_drvdata(pdev, ctx); + + return component_add(dev, &vidi_component_ops); +} + +static void vidi_remove(struct platform_device *pdev) +{ + struct vidi_context *ctx = platform_get_drvdata(pdev); + + drm_edid_free(ctx->raw_edid); + ctx->raw_edid = NULL; + + component_del(&pdev->dev, &vidi_component_ops); +} + struct platform_driver vidi_driver = { .probe = vidi_probe, .remove = vidi_remove, .driver = { .name = "exynos-drm-vidi", - .owner = THIS_MODULE, - .pm = &vidi_pm_ops, + .dev_groups = vidi_groups, }, }; |
