xref: /linux/drivers/gpu/drm/mgag200/mgag200_vga.c (revision 4b132aacb0768ac1e652cf517097ea6f237214b9)
1 // SPDX-License-Identifier: GPL-2.0-only
2 
3 #include <drm/drm_atomic_helper.h>
4 #include <drm/drm_modeset_helper_vtables.h>
5 #include <drm/drm_probe_helper.h>
6 
7 #include "mgag200_ddc.h"
8 #include "mgag200_drv.h"
9 
10 static const struct drm_encoder_funcs mgag200_dac_encoder_funcs = {
11 	.destroy = drm_encoder_cleanup
12 };
13 
14 static const struct drm_connector_helper_funcs mgag200_vga_connector_helper_funcs = {
15 	.get_modes = drm_connector_helper_get_modes,
16 	.detect_ctx = drm_connector_helper_detect_from_ddc
17 };
18 
19 static const struct drm_connector_funcs mgag200_vga_connector_funcs = {
20 	.reset                  = drm_atomic_helper_connector_reset,
21 	.fill_modes             = drm_helper_probe_single_connector_modes,
22 	.destroy                = drm_connector_cleanup,
23 	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
24 	.atomic_destroy_state   = drm_atomic_helper_connector_destroy_state
25 };
26 
27 int mgag200_vga_output_init(struct mga_device *mdev)
28 {
29 	struct drm_device *dev = &mdev->base;
30 	struct drm_crtc *crtc = &mdev->crtc;
31 	struct drm_encoder *encoder;
32 	struct drm_connector *connector;
33 	struct i2c_adapter *ddc;
34 	int ret;
35 
36 	encoder = &mdev->output.vga.encoder;
37 	ret = drm_encoder_init(dev, encoder, &mgag200_dac_encoder_funcs,
38 			       DRM_MODE_ENCODER_DAC, NULL);
39 	if (ret) {
40 		drm_err(dev, "drm_encoder_init() failed: %d\n", ret);
41 		return ret;
42 	}
43 	encoder->possible_crtcs = drm_crtc_mask(crtc);
44 
45 	ddc = mgag200_ddc_create(mdev);
46 	if (IS_ERR(ddc)) {
47 		ret = PTR_ERR(ddc);
48 		drm_err(dev, "failed to add DDC bus: %d\n", ret);
49 		return ret;
50 	}
51 
52 	connector = &mdev->output.vga.connector;
53 	ret = drm_connector_init_with_ddc(dev, connector,
54 					  &mgag200_vga_connector_funcs,
55 					  DRM_MODE_CONNECTOR_VGA, ddc);
56 	if (ret) {
57 		drm_err(dev, "drm_connector_init_with_ddc() failed: %d\n", ret);
58 		return ret;
59 	}
60 	drm_connector_helper_add(connector, &mgag200_vga_connector_helper_funcs);
61 
62 	connector->polled = DRM_CONNECTOR_POLL_CONNECT |
63 			    DRM_CONNECTOR_POLL_DISCONNECT;
64 
65 	ret = drm_connector_attach_encoder(connector, encoder);
66 	if (ret) {
67 		drm_err(dev, "drm_connector_attach_encoder() failed: %d\n", ret);
68 		return ret;
69 	}
70 
71 	return 0;
72 }
73