Ruud Derwig | a189d28 | 2016-06-06 10:47:46 +0300 | [diff] [blame] | 1 | /* |
| 2 | * ARC PGU DRM driver. |
| 3 | * |
| 4 | * Copyright (C) 2016 Synopsys, Inc. (www.synopsys.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | */ |
| 16 | |
Ruud Derwig | a189d28 | 2016-06-06 10:47:46 +0300 | [diff] [blame] | 17 | #include <drm/drm_atomic_helper.h> |
Sam Ravnborg | 2f69deb | 2019-01-19 09:40:11 +0100 | [diff] [blame] | 18 | #include <drm/drm_device.h> |
Daniel Vetter | fcd70cd | 2019-01-17 22:03:34 +0100 | [diff] [blame] | 19 | #include <drm/drm_probe_helper.h> |
Ruud Derwig | a189d28 | 2016-06-06 10:47:46 +0300 | [diff] [blame] | 20 | |
| 21 | #include "arcpgu.h" |
| 22 | |
| 23 | #define XRES_DEF 640 |
| 24 | #define YRES_DEF 480 |
| 25 | |
| 26 | #define XRES_MAX 8192 |
| 27 | #define YRES_MAX 8192 |
| 28 | |
| 29 | |
| 30 | struct arcpgu_drm_connector { |
| 31 | struct drm_connector connector; |
Ruud Derwig | a189d28 | 2016-06-06 10:47:46 +0300 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | static int arcpgu_drm_connector_get_modes(struct drm_connector *connector) |
| 35 | { |
| 36 | int count; |
| 37 | |
| 38 | count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX); |
| 39 | drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF); |
| 40 | return count; |
| 41 | } |
| 42 | |
Ruud Derwig | a189d28 | 2016-06-06 10:47:46 +0300 | [diff] [blame] | 43 | static void arcpgu_drm_connector_destroy(struct drm_connector *connector) |
| 44 | { |
| 45 | drm_connector_unregister(connector); |
| 46 | drm_connector_cleanup(connector); |
| 47 | } |
| 48 | |
| 49 | static const struct drm_connector_helper_funcs |
| 50 | arcpgu_drm_connector_helper_funcs = { |
| 51 | .get_modes = arcpgu_drm_connector_get_modes, |
| 52 | }; |
| 53 | |
| 54 | static const struct drm_connector_funcs arcpgu_drm_connector_funcs = { |
Ruud Derwig | a189d28 | 2016-06-06 10:47:46 +0300 | [diff] [blame] | 55 | .reset = drm_atomic_helper_connector_reset, |
Ruud Derwig | a189d28 | 2016-06-06 10:47:46 +0300 | [diff] [blame] | 56 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 57 | .destroy = arcpgu_drm_connector_destroy, |
| 58 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
| 59 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
| 60 | }; |
| 61 | |
| 62 | static struct drm_encoder_funcs arcpgu_drm_encoder_funcs = { |
| 63 | .destroy = drm_encoder_cleanup, |
| 64 | }; |
| 65 | |
| 66 | int arcpgu_drm_sim_init(struct drm_device *drm, struct device_node *np) |
| 67 | { |
| 68 | struct arcpgu_drm_connector *arcpgu_connector; |
Daniel Vetter | b46310e | 2018-01-17 15:17:55 +0100 | [diff] [blame] | 69 | struct drm_encoder *encoder; |
Ruud Derwig | a189d28 | 2016-06-06 10:47:46 +0300 | [diff] [blame] | 70 | struct drm_connector *connector; |
| 71 | int ret; |
| 72 | |
| 73 | encoder = devm_kzalloc(drm->dev, sizeof(*encoder), GFP_KERNEL); |
| 74 | if (encoder == NULL) |
| 75 | return -ENOMEM; |
| 76 | |
Daniel Vetter | b46310e | 2018-01-17 15:17:55 +0100 | [diff] [blame] | 77 | encoder->possible_crtcs = 1; |
| 78 | encoder->possible_clones = 0; |
Ruud Derwig | a189d28 | 2016-06-06 10:47:46 +0300 | [diff] [blame] | 79 | |
Daniel Vetter | b46310e | 2018-01-17 15:17:55 +0100 | [diff] [blame] | 80 | ret = drm_encoder_init(drm, encoder, &arcpgu_drm_encoder_funcs, |
Ruud Derwig | a189d28 | 2016-06-06 10:47:46 +0300 | [diff] [blame] | 81 | DRM_MODE_ENCODER_VIRTUAL, NULL); |
| 82 | if (ret) |
| 83 | return ret; |
| 84 | |
| 85 | arcpgu_connector = devm_kzalloc(drm->dev, sizeof(*arcpgu_connector), |
| 86 | GFP_KERNEL); |
| 87 | if (!arcpgu_connector) { |
| 88 | ret = -ENOMEM; |
| 89 | goto error_encoder_cleanup; |
| 90 | } |
| 91 | |
| 92 | connector = &arcpgu_connector->connector; |
| 93 | drm_connector_helper_add(connector, &arcpgu_drm_connector_helper_funcs); |
| 94 | |
| 95 | ret = drm_connector_init(drm, connector, &arcpgu_drm_connector_funcs, |
| 96 | DRM_MODE_CONNECTOR_VIRTUAL); |
| 97 | if (ret < 0) { |
| 98 | dev_err(drm->dev, "failed to initialize drm connector\n"); |
| 99 | goto error_encoder_cleanup; |
| 100 | } |
| 101 | |
Daniel Vetter | cde4c44 | 2018-07-09 10:40:07 +0200 | [diff] [blame] | 102 | ret = drm_connector_attach_encoder(connector, encoder); |
Ruud Derwig | a189d28 | 2016-06-06 10:47:46 +0300 | [diff] [blame] | 103 | if (ret < 0) { |
| 104 | dev_err(drm->dev, "could not attach connector to encoder\n"); |
| 105 | drm_connector_unregister(connector); |
| 106 | goto error_connector_cleanup; |
| 107 | } |
| 108 | |
Ruud Derwig | a189d28 | 2016-06-06 10:47:46 +0300 | [diff] [blame] | 109 | return 0; |
| 110 | |
| 111 | error_connector_cleanup: |
| 112 | drm_connector_cleanup(connector); |
| 113 | |
| 114 | error_encoder_cleanup: |
Daniel Vetter | b46310e | 2018-01-17 15:17:55 +0100 | [diff] [blame] | 115 | drm_encoder_cleanup(encoder); |
Ruud Derwig | a189d28 | 2016-06-06 10:47:46 +0300 | [diff] [blame] | 116 | return ret; |
| 117 | } |