Commit | Line | Data |
---|---|---|
ab5b0107 HL |
1 | /* |
2 | * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License version 2 and | |
6 | * only version 2 as published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | */ | |
13 | ||
14 | #include "drm/drm_edid.h" | |
15 | #include "msm_kms.h" | |
16 | #include "edp.h" | |
17 | ||
18 | struct edp_connector { | |
19 | struct drm_connector base; | |
20 | struct msm_edp *edp; | |
21 | }; | |
22 | #define to_edp_connector(x) container_of(x, struct edp_connector, base) | |
23 | ||
24 | static enum drm_connector_status edp_connector_detect( | |
25 | struct drm_connector *connector, bool force) | |
26 | { | |
27 | struct edp_connector *edp_connector = to_edp_connector(connector); | |
28 | struct msm_edp *edp = edp_connector->edp; | |
29 | ||
30 | DBG(""); | |
31 | return msm_edp_ctrl_panel_connected(edp->ctrl) ? | |
32 | connector_status_connected : connector_status_disconnected; | |
33 | } | |
34 | ||
35 | static void edp_connector_destroy(struct drm_connector *connector) | |
36 | { | |
37 | struct edp_connector *edp_connector = to_edp_connector(connector); | |
38 | ||
39 | DBG(""); | |
8208ed93 | 40 | |
ab5b0107 HL |
41 | drm_connector_cleanup(connector); |
42 | ||
43 | kfree(edp_connector); | |
44 | } | |
45 | ||
46 | static int edp_connector_get_modes(struct drm_connector *connector) | |
47 | { | |
48 | struct edp_connector *edp_connector = to_edp_connector(connector); | |
49 | struct msm_edp *edp = edp_connector->edp; | |
50 | ||
51 | struct edid *drm_edid = NULL; | |
52 | int ret = 0; | |
53 | ||
54 | DBG(""); | |
55 | ret = msm_edp_ctrl_get_panel_info(edp->ctrl, connector, &drm_edid); | |
56 | if (ret) | |
57 | return ret; | |
58 | ||
59 | drm_mode_connector_update_edid_property(connector, drm_edid); | |
60 | if (drm_edid) | |
61 | ret = drm_add_edid_modes(connector, drm_edid); | |
62 | ||
63 | return ret; | |
64 | } | |
65 | ||
66 | static int edp_connector_mode_valid(struct drm_connector *connector, | |
67 | struct drm_display_mode *mode) | |
68 | { | |
69 | struct edp_connector *edp_connector = to_edp_connector(connector); | |
70 | struct msm_edp *edp = edp_connector->edp; | |
71 | struct msm_drm_private *priv = connector->dev->dev_private; | |
72 | struct msm_kms *kms = priv->kms; | |
73 | long actual, requested; | |
74 | ||
75 | requested = 1000 * mode->clock; | |
76 | actual = kms->funcs->round_pixclk(kms, | |
77 | requested, edp_connector->edp->encoder); | |
78 | ||
79 | DBG("requested=%ld, actual=%ld", requested, actual); | |
80 | if (actual != requested) | |
81 | return MODE_CLOCK_RANGE; | |
82 | ||
83 | if (!msm_edp_ctrl_pixel_clock_valid( | |
84 | edp->ctrl, mode->clock, NULL, NULL)) | |
85 | return MODE_CLOCK_RANGE; | |
86 | ||
87 | /* Invalidate all modes if color format is not supported */ | |
88 | if (connector->display_info.bpc > 8) | |
89 | return MODE_BAD; | |
90 | ||
91 | return MODE_OK; | |
92 | } | |
93 | ||
ab5b0107 HL |
94 | static const struct drm_connector_funcs edp_connector_funcs = { |
95 | .dpms = drm_atomic_helper_connector_dpms, | |
96 | .detect = edp_connector_detect, | |
97 | .fill_modes = drm_helper_probe_single_connector_modes, | |
98 | .destroy = edp_connector_destroy, | |
99 | .reset = drm_atomic_helper_connector_reset, | |
100 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, | |
101 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, | |
102 | }; | |
103 | ||
104 | static const struct drm_connector_helper_funcs edp_connector_helper_funcs = { | |
105 | .get_modes = edp_connector_get_modes, | |
106 | .mode_valid = edp_connector_mode_valid, | |
ab5b0107 HL |
107 | }; |
108 | ||
109 | /* initialize connector */ | |
110 | struct drm_connector *msm_edp_connector_init(struct msm_edp *edp) | |
111 | { | |
112 | struct drm_connector *connector = NULL; | |
113 | struct edp_connector *edp_connector; | |
114 | int ret; | |
115 | ||
116 | edp_connector = kzalloc(sizeof(*edp_connector), GFP_KERNEL); | |
8208ed93 AT |
117 | if (!edp_connector) |
118 | return ERR_PTR(-ENOMEM); | |
ab5b0107 HL |
119 | |
120 | edp_connector->edp = edp; | |
121 | ||
122 | connector = &edp_connector->base; | |
123 | ||
124 | ret = drm_connector_init(edp->dev, connector, &edp_connector_funcs, | |
125 | DRM_MODE_CONNECTOR_eDP); | |
126 | if (ret) | |
8208ed93 | 127 | return ERR_PTR(ret); |
ab5b0107 HL |
128 | |
129 | drm_connector_helper_add(connector, &edp_connector_helper_funcs); | |
130 | ||
131 | /* We don't support HPD, so only poll status until connected. */ | |
132 | connector->polled = DRM_CONNECTOR_POLL_CONNECT; | |
133 | ||
134 | /* Display driver doesn't support interlace now. */ | |
135 | connector->interlace_allowed = false; | |
136 | connector->doublescan_allowed = false; | |
137 | ||
6f6b2879 HL |
138 | drm_mode_connector_attach_encoder(connector, edp->encoder); |
139 | ||
ab5b0107 | 140 | return connector; |
ab5b0107 | 141 | } |