linux/drivers/gpu/drm/rcar-du/rcar_du_lvdscon.c
<<
>>
Prefs
   1/*
   2 * rcar_du_lvdscon.c  --  R-Car Display Unit LVDS Connector
   3 *
   4 * Copyright (C) 2013-2014 Renesas Electronics Corporation
   5 *
   6 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
   7 *
   8 * This program is free software; you can redistribute it and/or modify
   9 * it under the terms of the GNU General Public License as published by
  10 * the Free Software Foundation; either version 2 of the License, or
  11 * (at your option) any later version.
  12 */
  13
  14#include <drm/drmP.h>
  15#include <drm/drm_atomic_helper.h>
  16#include <drm/drm_crtc.h>
  17#include <drm/drm_crtc_helper.h>
  18
  19#include <video/display_timing.h>
  20#include <video/of_display_timing.h>
  21#include <video/videomode.h>
  22
  23#include "rcar_du_drv.h"
  24#include "rcar_du_encoder.h"
  25#include "rcar_du_kms.h"
  26#include "rcar_du_lvdscon.h"
  27
  28struct rcar_du_lvds_connector {
  29        struct rcar_du_connector connector;
  30
  31        struct {
  32                unsigned int width_mm;          /* Panel width in mm */
  33                unsigned int height_mm;         /* Panel height in mm */
  34                struct videomode mode;
  35        } panel;
  36};
  37
  38#define to_rcar_lvds_connector(c) \
  39        container_of(c, struct rcar_du_lvds_connector, connector.connector)
  40
  41static int rcar_du_lvds_connector_get_modes(struct drm_connector *connector)
  42{
  43        struct rcar_du_lvds_connector *lvdscon =
  44                to_rcar_lvds_connector(connector);
  45        struct drm_display_mode *mode;
  46
  47        mode = drm_mode_create(connector->dev);
  48        if (mode == NULL)
  49                return 0;
  50
  51        mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
  52
  53        drm_display_mode_from_videomode(&lvdscon->panel.mode, mode);
  54
  55        drm_mode_probed_add(connector, mode);
  56
  57        return 1;
  58}
  59
  60static const struct drm_connector_helper_funcs connector_helper_funcs = {
  61        .get_modes = rcar_du_lvds_connector_get_modes,
  62        .best_encoder = rcar_du_connector_best_encoder,
  63};
  64
  65static enum drm_connector_status
  66rcar_du_lvds_connector_detect(struct drm_connector *connector, bool force)
  67{
  68        return connector_status_connected;
  69}
  70
  71static const struct drm_connector_funcs connector_funcs = {
  72        .dpms = drm_atomic_helper_connector_dpms,
  73        .reset = drm_atomic_helper_connector_reset,
  74        .detect = rcar_du_lvds_connector_detect,
  75        .fill_modes = drm_helper_probe_single_connector_modes,
  76        .destroy = drm_connector_cleanup,
  77        .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  78        .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  79};
  80
  81int rcar_du_lvds_connector_init(struct rcar_du_device *rcdu,
  82                                struct rcar_du_encoder *renc,
  83                                /* TODO const */ struct device_node *np)
  84{
  85        struct drm_encoder *encoder = rcar_encoder_to_drm_encoder(renc);
  86        struct rcar_du_lvds_connector *lvdscon;
  87        struct drm_connector *connector;
  88        struct display_timing timing;
  89        int ret;
  90
  91        lvdscon = devm_kzalloc(rcdu->dev, sizeof(*lvdscon), GFP_KERNEL);
  92        if (lvdscon == NULL)
  93                return -ENOMEM;
  94
  95        ret = of_get_display_timing(np, "panel-timing", &timing);
  96        if (ret < 0)
  97                return ret;
  98
  99        videomode_from_timing(&timing, &lvdscon->panel.mode);
 100
 101        of_property_read_u32(np, "width-mm", &lvdscon->panel.width_mm);
 102        of_property_read_u32(np, "height-mm", &lvdscon->panel.height_mm);
 103
 104        connector = &lvdscon->connector.connector;
 105        connector->display_info.width_mm = lvdscon->panel.width_mm;
 106        connector->display_info.height_mm = lvdscon->panel.height_mm;
 107
 108        ret = drm_connector_init(rcdu->ddev, connector, &connector_funcs,
 109                                 DRM_MODE_CONNECTOR_LVDS);
 110        if (ret < 0)
 111                return ret;
 112
 113        drm_connector_helper_add(connector, &connector_helper_funcs);
 114
 115        connector->dpms = DRM_MODE_DPMS_OFF;
 116        drm_object_property_set_value(&connector->base,
 117                rcdu->ddev->mode_config.dpms_property, DRM_MODE_DPMS_OFF);
 118
 119        ret = drm_mode_connector_attach_encoder(connector, encoder);
 120        if (ret < 0)
 121                return ret;
 122
 123        lvdscon->connector.encoder = renc;
 124
 125        return 0;
 126}
 127