2 * Copyright (C) 2014 Traphandler
3 * Copyright (C) 2014 Free Electrons
4 * Copyright (C) 2014 Atmel
6 * Author: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
7 * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
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.
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
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/>.
22 #include <linux/of_graph.h>
25 #include <drm/drm_of.h>
26 #include <drm/drm_bridge.h>
28 #include "atmel_hlcdc_dc.h"
30 static const struct drm_encoder_funcs atmel_hlcdc_panel_encoder_funcs
= {
31 .destroy
= drm_encoder_cleanup
,
34 static int atmel_hlcdc_attach_endpoint(struct drm_device
*dev
, int endpoint
)
36 struct drm_encoder
*encoder
;
37 struct drm_panel
*panel
;
38 struct drm_bridge
*bridge
;
41 ret
= drm_of_find_panel_or_bridge(dev
->dev
->of_node
, 0, endpoint
,
46 encoder
= devm_kzalloc(dev
->dev
, sizeof(*encoder
), GFP_KERNEL
);
50 ret
= drm_encoder_init(dev
, encoder
,
51 &atmel_hlcdc_panel_encoder_funcs
,
52 DRM_MODE_ENCODER_NONE
, NULL
);
56 encoder
->possible_crtcs
= 0x1;
59 bridge
= drm_panel_bridge_add(panel
, DRM_MODE_CONNECTOR_Unknown
);
61 return PTR_ERR(bridge
);
65 ret
= drm_bridge_attach(encoder
, bridge
, NULL
);
70 drm_panel_bridge_remove(bridge
);
73 drm_encoder_cleanup(encoder
);
78 int atmel_hlcdc_create_outputs(struct drm_device
*dev
)
80 int endpoint
, ret
= 0;
82 for (endpoint
= 0; !ret
; endpoint
++)
83 ret
= atmel_hlcdc_attach_endpoint(dev
, endpoint
);
85 /* At least one device was successfully attached.*/
86 if (ret
== -ENODEV
&& endpoint
)