blob: 0c43032fc69318b294d3cf2baa29862bedb77d14 [file] [log] [blame]
Laurent Pinchart56c5dd02013-06-15 14:21:51 +02001/*
2 * rcar_du_lvdscon.c -- R-Car Display Unit LVDS Connector
3 *
Laurent Pinchart36d50462014-02-06 18:13:52 +01004 * Copyright (C) 2013-2014 Renesas Electronics Corporation
Laurent Pinchart56c5dd02013-06-15 14:21:51 +02005 *
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>
Laurent Pinchart3e8da872015-02-20 11:30:59 +020015#include <drm/drm_atomic_helper.h>
Laurent Pinchart56c5dd02013-06-15 14:21:51 +020016#include <drm/drm_crtc.h>
17#include <drm/drm_crtc_helper.h>
18
Laurent Pinchart96c02692014-01-21 15:57:26 +010019#include <video/display_timing.h>
20#include <video/of_display_timing.h>
21#include <video/videomode.h>
22
Laurent Pinchart56c5dd02013-06-15 14:21:51 +020023#include "rcar_du_drv.h"
Laurent Pinchart6978f122013-06-15 15:02:12 +020024#include "rcar_du_encoder.h"
Laurent Pinchart56c5dd02013-06-15 14:21:51 +020025#include "rcar_du_kms.h"
26#include "rcar_du_lvdscon.h"
27
28struct rcar_du_lvds_connector {
29 struct rcar_du_connector connector;
30
Laurent Pinchart2378ad12014-09-17 02:07:52 +030031 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;
Laurent Pinchart56c5dd02013-06-15 14:21:51 +020036};
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;
Laurent Pinchart56c5dd02013-06-15 14:21:51 +020052
Laurent Pinchart96c02692014-01-21 15:57:26 +010053 drm_display_mode_from_videomode(&lvdscon->panel.mode, mode);
Laurent Pinchart1d46fea2014-08-27 00:42:56 +020054
Laurent Pinchart56c5dd02013-06-15 14:21:51 +020055 drm_mode_probed_add(connector, mode);
56
57 return 1;
58}
59
Laurent Pinchart56c5dd02013-06-15 14:21:51 +020060static const struct drm_connector_helper_funcs connector_helper_funcs = {
61 .get_modes = rcar_du_lvds_connector_get_modes,
Laurent Pinchart56c5dd02013-06-15 14:21:51 +020062 .best_encoder = rcar_du_connector_best_encoder,
63};
64
65static void rcar_du_lvds_connector_destroy(struct drm_connector *connector)
66{
Thomas Wood34ea3d32014-05-29 16:57:41 +010067 drm_connector_unregister(connector);
Laurent Pinchart56c5dd02013-06-15 14:21:51 +020068 drm_connector_cleanup(connector);
69}
70
71static enum drm_connector_status
72rcar_du_lvds_connector_detect(struct drm_connector *connector, bool force)
73{
74 return connector_status_connected;
75}
76
77static const struct drm_connector_funcs connector_funcs = {
Laurent Pinchartf3483232015-02-22 01:49:11 +020078 .dpms = drm_atomic_helper_connector_dpms,
Laurent Pinchart3e8da872015-02-20 11:30:59 +020079 .reset = drm_atomic_helper_connector_reset,
Laurent Pinchart56c5dd02013-06-15 14:21:51 +020080 .detect = rcar_du_lvds_connector_detect,
81 .fill_modes = drm_helper_probe_single_connector_modes,
82 .destroy = rcar_du_lvds_connector_destroy,
Laurent Pinchart3e8da872015-02-20 11:30:59 +020083 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
84 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Laurent Pinchart56c5dd02013-06-15 14:21:51 +020085};
86
87int rcar_du_lvds_connector_init(struct rcar_du_device *rcdu,
88 struct rcar_du_encoder *renc,
Laurent Pinchart96c02692014-01-21 15:57:26 +010089 /* TODO const */ struct device_node *np)
Laurent Pinchart56c5dd02013-06-15 14:21:51 +020090{
Laurent Pinchart4b96b702014-03-31 01:50:16 +020091 struct drm_encoder *encoder = rcar_encoder_to_drm_encoder(renc);
Laurent Pinchart56c5dd02013-06-15 14:21:51 +020092 struct rcar_du_lvds_connector *lvdscon;
93 struct drm_connector *connector;
Laurent Pinchart2378ad12014-09-17 02:07:52 +030094 struct display_timing timing;
Laurent Pinchart56c5dd02013-06-15 14:21:51 +020095 int ret;
96
97 lvdscon = devm_kzalloc(rcdu->dev, sizeof(*lvdscon), GFP_KERNEL);
98 if (lvdscon == NULL)
99 return -ENOMEM;
100
Laurent Pinchart2378ad12014-09-17 02:07:52 +0300101 ret = of_get_display_timing(np, "panel-timing", &timing);
102 if (ret < 0)
103 return ret;
Laurent Pinchart96c02692014-01-21 15:57:26 +0100104
Laurent Pinchart2378ad12014-09-17 02:07:52 +0300105 videomode_from_timing(&timing, &lvdscon->panel.mode);
Laurent Pinchart96c02692014-01-21 15:57:26 +0100106
Laurent Pinchart2378ad12014-09-17 02:07:52 +0300107 of_property_read_u32(np, "width-mm", &lvdscon->panel.width_mm);
108 of_property_read_u32(np, "height-mm", &lvdscon->panel.height_mm);
Laurent Pinchart56c5dd02013-06-15 14:21:51 +0200109
110 connector = &lvdscon->connector.connector;
Laurent Pinchart96c02692014-01-21 15:57:26 +0100111 connector->display_info.width_mm = lvdscon->panel.width_mm;
112 connector->display_info.height_mm = lvdscon->panel.height_mm;
Laurent Pinchart56c5dd02013-06-15 14:21:51 +0200113
114 ret = drm_connector_init(rcdu->ddev, connector, &connector_funcs,
115 DRM_MODE_CONNECTOR_LVDS);
116 if (ret < 0)
117 return ret;
118
119 drm_connector_helper_add(connector, &connector_helper_funcs);
Thomas Wood34ea3d32014-05-29 16:57:41 +0100120 ret = drm_connector_register(connector);
Laurent Pinchart56c5dd02013-06-15 14:21:51 +0200121 if (ret < 0)
122 return ret;
123
Laurent Pinchartf3483232015-02-22 01:49:11 +0200124 connector->dpms = DRM_MODE_DPMS_OFF;
Laurent Pinchart56c5dd02013-06-15 14:21:51 +0200125 drm_object_property_set_value(&connector->base,
126 rcdu->ddev->mode_config.dpms_property, DRM_MODE_DPMS_OFF);
127
Laurent Pinchart4b96b702014-03-31 01:50:16 +0200128 ret = drm_mode_connector_attach_encoder(connector, encoder);
Laurent Pinchart56c5dd02013-06-15 14:21:51 +0200129 if (ret < 0)
130 return ret;
131
Laurent Pinchart56c5dd02013-06-15 14:21:51 +0200132 lvdscon->connector.encoder = renc;
133
134 return 0;
135}