2 * rcar_du_lvdscon.c -- R-Car Display Unit LVDS Connector
4 * Copyright (C) 2013 Renesas Corporation
6 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
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.
15 #include <drm/drm_crtc.h>
16 #include <drm/drm_crtc_helper.h>
18 #include "rcar_du_drv.h"
19 #include "rcar_du_encoder.h"
20 #include "rcar_du_kms.h"
21 #include "rcar_du_lvdscon.h"
23 struct rcar_du_lvds_connector
{
24 struct rcar_du_connector connector
;
26 const struct rcar_du_panel_data
*panel
;
29 #define to_rcar_lvds_connector(c) \
30 container_of(c, struct rcar_du_lvds_connector, connector.connector)
32 static int rcar_du_lvds_connector_get_modes(struct drm_connector
*connector
)
34 struct rcar_du_lvds_connector
*lvdscon
=
35 to_rcar_lvds_connector(connector
);
36 struct drm_display_mode
*mode
;
38 mode
= drm_mode_create(connector
->dev
);
42 mode
->type
= DRM_MODE_TYPE_PREFERRED
| DRM_MODE_TYPE_DRIVER
;
43 mode
->clock
= lvdscon
->panel
->mode
.clock
;
44 mode
->hdisplay
= lvdscon
->panel
->mode
.hdisplay
;
45 mode
->hsync_start
= lvdscon
->panel
->mode
.hsync_start
;
46 mode
->hsync_end
= lvdscon
->panel
->mode
.hsync_end
;
47 mode
->htotal
= lvdscon
->panel
->mode
.htotal
;
48 mode
->vdisplay
= lvdscon
->panel
->mode
.vdisplay
;
49 mode
->vsync_start
= lvdscon
->panel
->mode
.vsync_start
;
50 mode
->vsync_end
= lvdscon
->panel
->mode
.vsync_end
;
51 mode
->vtotal
= lvdscon
->panel
->mode
.vtotal
;
52 mode
->flags
= lvdscon
->panel
->mode
.flags
;
54 drm_mode_set_name(mode
);
55 drm_mode_probed_add(connector
, mode
);
60 static int rcar_du_lvds_connector_mode_valid(struct drm_connector
*connector
,
61 struct drm_display_mode
*mode
)
66 static const struct drm_connector_helper_funcs connector_helper_funcs
= {
67 .get_modes
= rcar_du_lvds_connector_get_modes
,
68 .mode_valid
= rcar_du_lvds_connector_mode_valid
,
69 .best_encoder
= rcar_du_connector_best_encoder
,
72 static void rcar_du_lvds_connector_destroy(struct drm_connector
*connector
)
74 drm_sysfs_connector_remove(connector
);
75 drm_connector_cleanup(connector
);
78 static enum drm_connector_status
79 rcar_du_lvds_connector_detect(struct drm_connector
*connector
, bool force
)
81 return connector_status_connected
;
84 static const struct drm_connector_funcs connector_funcs
= {
85 .dpms
= drm_helper_connector_dpms
,
86 .detect
= rcar_du_lvds_connector_detect
,
87 .fill_modes
= drm_helper_probe_single_connector_modes
,
88 .destroy
= rcar_du_lvds_connector_destroy
,
91 int rcar_du_lvds_connector_init(struct rcar_du_device
*rcdu
,
92 struct rcar_du_encoder
*renc
,
93 const struct rcar_du_panel_data
*panel
)
95 struct rcar_du_lvds_connector
*lvdscon
;
96 struct drm_connector
*connector
;
99 lvdscon
= devm_kzalloc(rcdu
->dev
, sizeof(*lvdscon
), GFP_KERNEL
);
103 lvdscon
->panel
= panel
;
105 connector
= &lvdscon
->connector
.connector
;
106 connector
->display_info
.width_mm
= panel
->width_mm
;
107 connector
->display_info
.height_mm
= panel
->height_mm
;
109 ret
= drm_connector_init(rcdu
->ddev
, connector
, &connector_funcs
,
110 DRM_MODE_CONNECTOR_LVDS
);
114 drm_connector_helper_add(connector
, &connector_helper_funcs
);
115 ret
= drm_sysfs_connector_add(connector
);
119 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_OFF
);
120 drm_object_property_set_value(&connector
->base
,
121 rcdu
->ddev
->mode_config
.dpms_property
, DRM_MODE_DPMS_OFF
);
123 ret
= drm_mode_connector_attach_encoder(connector
, &renc
->encoder
);
127 connector
->encoder
= &renc
->encoder
;
128 lvdscon
->connector
.encoder
= renc
;