2015-01-06 17:13:28 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Traphandler
|
|
|
|
* Copyright (C) 2014 Free Electrons
|
|
|
|
* Copyright (C) 2014 Atmel
|
|
|
|
*
|
|
|
|
* Author: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
|
|
|
|
* Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 as published by
|
|
|
|
* the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/of_graph.h>
|
|
|
|
|
|
|
|
#include <drm/drmP.h>
|
2017-03-30 01:55:46 +07:00
|
|
|
#include <drm/drm_of.h>
|
2017-05-12 01:31:28 +07:00
|
|
|
#include <drm/drm_bridge.h>
|
2015-01-06 17:13:28 +07:00
|
|
|
|
|
|
|
#include "atmel_hlcdc_dc.h"
|
|
|
|
|
2018-08-25 15:56:20 +07:00
|
|
|
struct atmel_hlcdc_rgb_output {
|
|
|
|
struct drm_encoder encoder;
|
|
|
|
int bus_fmt;
|
|
|
|
};
|
|
|
|
|
2015-01-06 17:13:28 +07:00
|
|
|
static const struct drm_encoder_funcs atmel_hlcdc_panel_encoder_funcs = {
|
2017-05-12 01:31:27 +07:00
|
|
|
.destroy = drm_encoder_cleanup,
|
2015-01-06 17:13:28 +07:00
|
|
|
};
|
|
|
|
|
2018-08-25 15:56:20 +07:00
|
|
|
static struct atmel_hlcdc_rgb_output *
|
|
|
|
atmel_hlcdc_encoder_to_rgb_output(struct drm_encoder *encoder)
|
|
|
|
{
|
|
|
|
return container_of(encoder, struct atmel_hlcdc_rgb_output, encoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
int atmel_hlcdc_encoder_get_bus_fmt(struct drm_encoder *encoder)
|
|
|
|
{
|
|
|
|
struct atmel_hlcdc_rgb_output *output;
|
|
|
|
|
|
|
|
output = atmel_hlcdc_encoder_to_rgb_output(encoder);
|
|
|
|
|
|
|
|
return output->bus_fmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int atmel_hlcdc_of_bus_fmt(const struct device_node *ep)
|
|
|
|
{
|
|
|
|
u32 bus_width;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = of_property_read_u32(ep, "bus-width", &bus_width);
|
|
|
|
if (ret == -EINVAL)
|
|
|
|
return 0;
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
switch (bus_width) {
|
|
|
|
case 12:
|
|
|
|
return MEDIA_BUS_FMT_RGB444_1X12;
|
|
|
|
case 16:
|
|
|
|
return MEDIA_BUS_FMT_RGB565_1X16;
|
|
|
|
case 18:
|
|
|
|
return MEDIA_BUS_FMT_RGB666_1X18;
|
|
|
|
case 24:
|
|
|
|
return MEDIA_BUS_FMT_RGB888_1X24;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 19:35:21 +07:00
|
|
|
static int atmel_hlcdc_attach_endpoint(struct drm_device *dev, int endpoint)
|
2016-01-06 16:16:32 +07:00
|
|
|
{
|
2018-08-25 15:56:20 +07:00
|
|
|
struct atmel_hlcdc_rgb_output *output;
|
|
|
|
struct device_node *ep;
|
2016-01-06 16:16:32 +07:00
|
|
|
struct drm_panel *panel;
|
|
|
|
struct drm_bridge *bridge;
|
|
|
|
int ret;
|
2015-01-06 17:13:28 +07:00
|
|
|
|
2018-08-25 15:56:20 +07:00
|
|
|
ep = of_graph_get_endpoint_by_regs(dev->dev->of_node, 0, endpoint);
|
|
|
|
if (!ep)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2017-05-18 19:35:21 +07:00
|
|
|
ret = drm_of_find_panel_or_bridge(dev->dev->of_node, 0, endpoint,
|
|
|
|
&panel, &bridge);
|
2018-08-25 15:56:20 +07:00
|
|
|
if (ret) {
|
|
|
|
of_node_put(ep);
|
2017-05-18 19:35:21 +07:00
|
|
|
return ret;
|
2018-08-25 15:56:20 +07:00
|
|
|
}
|
2017-05-18 19:35:21 +07:00
|
|
|
|
2018-08-25 15:56:20 +07:00
|
|
|
output = devm_kzalloc(dev->dev, sizeof(*output), GFP_KERNEL);
|
|
|
|
if (!output) {
|
|
|
|
of_node_put(ep);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
output->bus_fmt = atmel_hlcdc_of_bus_fmt(ep);
|
|
|
|
of_node_put(ep);
|
|
|
|
if (output->bus_fmt < 0) {
|
|
|
|
dev_err(dev->dev, "endpoint %d: invalid bus width\n", endpoint);
|
2016-01-06 16:16:32 +07:00
|
|
|
return -EINVAL;
|
2018-08-25 15:56:20 +07:00
|
|
|
}
|
2015-01-06 17:13:28 +07:00
|
|
|
|
2018-08-25 15:56:20 +07:00
|
|
|
ret = drm_encoder_init(dev, &output->encoder,
|
2015-01-06 17:13:28 +07:00
|
|
|
&atmel_hlcdc_panel_encoder_funcs,
|
2016-01-01 00:24:09 +07:00
|
|
|
DRM_MODE_ENCODER_NONE, NULL);
|
2015-01-06 17:13:28 +07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2018-08-25 15:56:20 +07:00
|
|
|
output->encoder.possible_crtcs = 0x1;
|
2016-01-06 16:16:32 +07:00
|
|
|
|
|
|
|
if (panel) {
|
2017-05-12 01:31:28 +07:00
|
|
|
bridge = drm_panel_bridge_add(panel, DRM_MODE_CONNECTOR_Unknown);
|
|
|
|
if (IS_ERR(bridge))
|
|
|
|
return PTR_ERR(bridge);
|
2016-01-06 16:16:32 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bridge) {
|
2018-08-25 15:56:20 +07:00
|
|
|
ret = drm_bridge_attach(&output->encoder, bridge, NULL);
|
2016-01-06 16:16:32 +07:00
|
|
|
if (!ret)
|
|
|
|
return 0;
|
2017-05-12 01:31:28 +07:00
|
|
|
|
|
|
|
if (panel)
|
|
|
|
drm_panel_bridge_remove(bridge);
|
2016-01-06 16:16:32 +07:00
|
|
|
}
|
2015-01-06 17:13:28 +07:00
|
|
|
|
2018-08-25 15:56:20 +07:00
|
|
|
drm_encoder_cleanup(&output->encoder);
|
2015-01-06 17:13:28 +07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int atmel_hlcdc_create_outputs(struct drm_device *dev)
|
|
|
|
{
|
2017-05-18 19:35:21 +07:00
|
|
|
int endpoint, ret = 0;
|
2018-08-25 15:56:19 +07:00
|
|
|
int attached = 0;
|
2017-05-18 19:35:21 +07:00
|
|
|
|
2018-08-25 15:56:19 +07:00
|
|
|
/*
|
|
|
|
* Always scan the first few endpoints even if we get -ENODEV,
|
|
|
|
* but keep going after that as long as we keep getting hits.
|
|
|
|
*/
|
|
|
|
for (endpoint = 0; !ret || endpoint < 4; endpoint++) {
|
2017-05-18 19:35:21 +07:00
|
|
|
ret = atmel_hlcdc_attach_endpoint(dev, endpoint);
|
2018-08-25 15:56:19 +07:00
|
|
|
if (ret == -ENODEV)
|
|
|
|
continue;
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
attached++;
|
|
|
|
}
|
2017-05-18 19:35:21 +07:00
|
|
|
|
|
|
|
/* At least one device was successfully attached.*/
|
2018-08-25 15:56:19 +07:00
|
|
|
if (ret == -ENODEV && attached)
|
2017-05-18 19:35:21 +07:00
|
|
|
return 0;
|
2015-01-06 17:13:28 +07:00
|
|
|
|
2017-03-30 01:55:46 +07:00
|
|
|
return ret;
|
2015-01-06 17:13:28 +07:00
|
|
|
}
|