Boris Brezillon | 1a39678 | 2015-01-06 11:13:28 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 Traphandler |
| 3 | * Copyright (C) 2014 Free Electrons |
| 4 | * Copyright (C) 2014 Atmel |
| 5 | * |
| 6 | * Author: Jean-Jacques Hiblot <jjhiblot@traphandler.com> |
| 7 | * Author: Boris BREZILLON <boris.brezillon@free-electrons.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License version 2 as published by |
| 11 | * the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 16 | * more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/of_graph.h> |
| 23 | |
| 24 | #include <drm/drmP.h> |
Rob Herring | ebc9446 | 2017-03-29 13:55:46 -0500 | [diff] [blame] | 25 | #include <drm/drm_of.h> |
Eric Anholt | 96160a8 | 2017-05-11 11:31:28 -0700 | [diff] [blame] | 26 | #include <drm/drm_bridge.h> |
Boris Brezillon | 1a39678 | 2015-01-06 11:13:28 +0100 | [diff] [blame] | 27 | |
| 28 | #include "atmel_hlcdc_dc.h" |
| 29 | |
Boris Brezillon | 1a39678 | 2015-01-06 11:13:28 +0100 | [diff] [blame] | 30 | static const struct drm_encoder_funcs atmel_hlcdc_panel_encoder_funcs = { |
Eric Anholt | 510fc3c | 2017-05-11 11:31:27 -0700 | [diff] [blame] | 31 | .destroy = drm_encoder_cleanup, |
Boris Brezillon | 1a39678 | 2015-01-06 11:13:28 +0100 | [diff] [blame] | 32 | }; |
| 33 | |
Boris Brezillon | 6bee9b7 | 2017-05-18 14:35:21 +0200 | [diff] [blame] | 34 | static int atmel_hlcdc_attach_endpoint(struct drm_device *dev, int endpoint) |
Boris Brezillon | 17a8e03 | 2016-01-06 10:16:32 +0100 | [diff] [blame] | 35 | { |
Eric Anholt | 96160a8 | 2017-05-11 11:31:28 -0700 | [diff] [blame] | 36 | struct drm_encoder *encoder; |
Boris Brezillon | 17a8e03 | 2016-01-06 10:16:32 +0100 | [diff] [blame] | 37 | struct drm_panel *panel; |
| 38 | struct drm_bridge *bridge; |
| 39 | int ret; |
| 40 | |
Boris Brezillon | 6bee9b7 | 2017-05-18 14:35:21 +0200 | [diff] [blame] | 41 | ret = drm_of_find_panel_or_bridge(dev->dev->of_node, 0, endpoint, |
| 42 | &panel, &bridge); |
| 43 | if (ret) |
| 44 | return ret; |
| 45 | |
Eric Anholt | 96160a8 | 2017-05-11 11:31:28 -0700 | [diff] [blame] | 46 | encoder = devm_kzalloc(dev->dev, sizeof(*encoder), GFP_KERNEL); |
| 47 | if (!encoder) |
Boris Brezillon | 1a39678 | 2015-01-06 11:13:28 +0100 | [diff] [blame] | 48 | return -EINVAL; |
| 49 | |
Eric Anholt | 96160a8 | 2017-05-11 11:31:28 -0700 | [diff] [blame] | 50 | ret = drm_encoder_init(dev, encoder, |
Boris Brezillon | 1a39678 | 2015-01-06 11:13:28 +0100 | [diff] [blame] | 51 | &atmel_hlcdc_panel_encoder_funcs, |
Boris Brezillon | abfc936 | 2015-12-31 18:24:09 +0100 | [diff] [blame] | 52 | DRM_MODE_ENCODER_NONE, NULL); |
Boris Brezillon | 1a39678 | 2015-01-06 11:13:28 +0100 | [diff] [blame] | 53 | if (ret) |
| 54 | return ret; |
| 55 | |
Eric Anholt | 96160a8 | 2017-05-11 11:31:28 -0700 | [diff] [blame] | 56 | encoder->possible_crtcs = 0x1; |
Boris Brezillon | 1a39678 | 2015-01-06 11:13:28 +0100 | [diff] [blame] | 57 | |
Boris Brezillon | 17a8e03 | 2016-01-06 10:16:32 +0100 | [diff] [blame] | 58 | if (panel) { |
Eric Anholt | 96160a8 | 2017-05-11 11:31:28 -0700 | [diff] [blame] | 59 | bridge = drm_panel_bridge_add(panel, DRM_MODE_CONNECTOR_Unknown); |
| 60 | if (IS_ERR(bridge)) |
| 61 | return PTR_ERR(bridge); |
Boris Brezillon | 17a8e03 | 2016-01-06 10:16:32 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Boris Brezillon | 17a8e03 | 2016-01-06 10:16:32 +0100 | [diff] [blame] | 64 | if (bridge) { |
Eric Anholt | 96160a8 | 2017-05-11 11:31:28 -0700 | [diff] [blame] | 65 | ret = drm_bridge_attach(encoder, bridge, NULL); |
Boris Brezillon | 17a8e03 | 2016-01-06 10:16:32 +0100 | [diff] [blame] | 66 | if (!ret) |
| 67 | return 0; |
Eric Anholt | 96160a8 | 2017-05-11 11:31:28 -0700 | [diff] [blame] | 68 | |
| 69 | if (panel) |
| 70 | drm_panel_bridge_remove(bridge); |
Boris Brezillon | 17a8e03 | 2016-01-06 10:16:32 +0100 | [diff] [blame] | 71 | } |
Boris Brezillon | 1a39678 | 2015-01-06 11:13:28 +0100 | [diff] [blame] | 72 | |
Eric Anholt | 96160a8 | 2017-05-11 11:31:28 -0700 | [diff] [blame] | 73 | drm_encoder_cleanup(encoder); |
Boris Brezillon | 1a39678 | 2015-01-06 11:13:28 +0100 | [diff] [blame] | 74 | |
| 75 | return ret; |
| 76 | } |
| 77 | |
| 78 | int atmel_hlcdc_create_outputs(struct drm_device *dev) |
| 79 | { |
Boris Brezillon | 6bee9b7 | 2017-05-18 14:35:21 +0200 | [diff] [blame] | 80 | int endpoint, ret = 0; |
Boris Brezillon | 1a39678 | 2015-01-06 11:13:28 +0100 | [diff] [blame] | 81 | |
Boris Brezillon | 6bee9b7 | 2017-05-18 14:35:21 +0200 | [diff] [blame] | 82 | for (endpoint = 0; !ret; endpoint++) |
| 83 | ret = atmel_hlcdc_attach_endpoint(dev, endpoint); |
Boris Brezillon | 1a39678 | 2015-01-06 11:13:28 +0100 | [diff] [blame] | 84 | |
Boris Brezillon | 6bee9b7 | 2017-05-18 14:35:21 +0200 | [diff] [blame] | 85 | /* At least one device was successfully attached.*/ |
| 86 | if (ret == -ENODEV && endpoint) |
| 87 | return 0; |
Boris Brezillon | 1a39678 | 2015-01-06 11:13:28 +0100 | [diff] [blame] | 88 | |
Rob Herring | ebc9446 | 2017-03-29 13:55:46 -0500 | [diff] [blame] | 89 | return ret; |
Boris Brezillon | 1a39678 | 2015-01-06 11:13:28 +0100 | [diff] [blame] | 90 | } |