2014-03-30 19:55:38 +00:00
|
|
|
/*
|
|
|
|
* R-Car Display Unit HDMI Encoder
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Renesas Electronics Corporation
|
|
|
|
*
|
|
|
|
* Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
|
|
#include <drm/drmP.h>
|
|
|
|
#include <drm/drm_crtc.h>
|
|
|
|
#include <drm/drm_crtc_helper.h>
|
|
|
|
#include <drm/drm_encoder_slave.h>
|
|
|
|
|
|
|
|
#include "rcar_du_drv.h"
|
|
|
|
#include "rcar_du_encoder.h"
|
|
|
|
#include "rcar_du_hdmienc.h"
|
2014-10-25 22:14:27 +00:00
|
|
|
#include "rcar_du_lvdsenc.h"
|
2014-03-30 19:55:38 +00:00
|
|
|
|
|
|
|
struct rcar_du_hdmienc {
|
|
|
|
struct rcar_du_encoder *renc;
|
|
|
|
struct device *dev;
|
2015-02-20 12:05:21 +00:00
|
|
|
bool enabled;
|
2014-03-30 19:55:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define to_rcar_hdmienc(e) (to_rcar_encoder(e)->hdmi)
|
|
|
|
#define to_slave_funcs(e) (to_rcar_encoder(e)->slave.slave_funcs)
|
|
|
|
|
2015-02-20 12:05:21 +00:00
|
|
|
static void rcar_du_hdmienc_disable(struct drm_encoder *encoder)
|
2014-03-30 19:55:38 +00:00
|
|
|
{
|
|
|
|
struct rcar_du_hdmienc *hdmienc = to_rcar_hdmienc(encoder);
|
|
|
|
struct drm_encoder_slave_funcs *sfuncs = to_slave_funcs(encoder);
|
|
|
|
|
2015-02-20 12:05:21 +00:00
|
|
|
if (sfuncs->dpms)
|
|
|
|
sfuncs->dpms(encoder, DRM_MODE_DPMS_OFF);
|
2014-12-09 11:19:10 +00:00
|
|
|
|
2015-02-20 12:05:21 +00:00
|
|
|
if (hdmienc->renc->lvds)
|
|
|
|
rcar_du_lvdsenc_enable(hdmienc->renc->lvds, encoder->crtc,
|
|
|
|
false);
|
|
|
|
|
|
|
|
hdmienc->enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rcar_du_hdmienc_enable(struct drm_encoder *encoder)
|
|
|
|
{
|
|
|
|
struct rcar_du_hdmienc *hdmienc = to_rcar_hdmienc(encoder);
|
|
|
|
struct drm_encoder_slave_funcs *sfuncs = to_slave_funcs(encoder);
|
2014-03-30 19:55:38 +00:00
|
|
|
|
2015-02-20 12:05:21 +00:00
|
|
|
if (hdmienc->renc->lvds)
|
2015-02-20 12:59:58 +00:00
|
|
|
rcar_du_lvdsenc_enable(hdmienc->renc->lvds, encoder->crtc,
|
|
|
|
true);
|
2014-10-25 22:14:27 +00:00
|
|
|
|
2014-03-30 19:55:38 +00:00
|
|
|
if (sfuncs->dpms)
|
2015-02-20 12:05:21 +00:00
|
|
|
sfuncs->dpms(encoder, DRM_MODE_DPMS_ON);
|
2014-03-30 19:55:38 +00:00
|
|
|
|
2015-02-20 12:05:21 +00:00
|
|
|
hdmienc->enabled = true;
|
|
|
|
}
|
2014-10-25 22:14:27 +00:00
|
|
|
|
2015-02-22 19:02:39 +00:00
|
|
|
static int rcar_du_hdmienc_atomic_check(struct drm_encoder *encoder,
|
|
|
|
struct drm_crtc_state *crtc_state,
|
|
|
|
struct drm_connector_state *conn_state)
|
2014-03-30 19:55:38 +00:00
|
|
|
{
|
2014-10-25 22:14:27 +00:00
|
|
|
struct rcar_du_hdmienc *hdmienc = to_rcar_hdmienc(encoder);
|
2014-03-30 19:55:38 +00:00
|
|
|
struct drm_encoder_slave_funcs *sfuncs = to_slave_funcs(encoder);
|
2015-02-22 19:02:39 +00:00
|
|
|
struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
|
|
|
|
const struct drm_display_mode *mode = &crtc_state->mode;
|
2014-03-30 19:55:38 +00:00
|
|
|
|
2014-10-25 22:14:27 +00:00
|
|
|
/* The internal LVDS encoder has a clock frequency operating range of
|
|
|
|
* 30MHz to 150MHz. Clamp the clock accordingly.
|
|
|
|
*/
|
|
|
|
if (hdmienc->renc->lvds)
|
|
|
|
adjusted_mode->clock = clamp(adjusted_mode->clock,
|
|
|
|
30000, 150000);
|
|
|
|
|
2014-03-30 19:55:38 +00:00
|
|
|
if (sfuncs->mode_fixup == NULL)
|
2015-02-22 19:02:39 +00:00
|
|
|
return 0;
|
2014-03-30 19:55:38 +00:00
|
|
|
|
2015-02-22 19:02:39 +00:00
|
|
|
return sfuncs->mode_fixup(encoder, mode, adjusted_mode) ? 0 : -EINVAL;
|
2014-03-30 19:55:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rcar_du_hdmienc_mode_set(struct drm_encoder *encoder,
|
|
|
|
struct drm_display_mode *mode,
|
|
|
|
struct drm_display_mode *adjusted_mode)
|
|
|
|
{
|
|
|
|
struct rcar_du_hdmienc *hdmienc = to_rcar_hdmienc(encoder);
|
|
|
|
struct drm_encoder_slave_funcs *sfuncs = to_slave_funcs(encoder);
|
|
|
|
|
|
|
|
if (sfuncs->mode_set)
|
|
|
|
sfuncs->mode_set(encoder, mode, adjusted_mode);
|
|
|
|
|
|
|
|
rcar_du_crtc_route_output(encoder->crtc, hdmienc->renc->output);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_encoder_helper_funcs encoder_helper_funcs = {
|
|
|
|
.mode_set = rcar_du_hdmienc_mode_set,
|
2015-02-20 12:05:21 +00:00
|
|
|
.disable = rcar_du_hdmienc_disable,
|
|
|
|
.enable = rcar_du_hdmienc_enable,
|
2015-02-22 19:02:39 +00:00
|
|
|
.atomic_check = rcar_du_hdmienc_atomic_check,
|
2014-03-30 19:55:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void rcar_du_hdmienc_cleanup(struct drm_encoder *encoder)
|
|
|
|
{
|
|
|
|
struct rcar_du_hdmienc *hdmienc = to_rcar_hdmienc(encoder);
|
|
|
|
|
2015-02-20 12:05:21 +00:00
|
|
|
if (hdmienc->enabled)
|
|
|
|
rcar_du_hdmienc_disable(encoder);
|
2014-03-30 19:55:38 +00:00
|
|
|
|
|
|
|
drm_encoder_cleanup(encoder);
|
|
|
|
put_device(hdmienc->dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_encoder_funcs encoder_funcs = {
|
|
|
|
.destroy = rcar_du_hdmienc_cleanup,
|
|
|
|
};
|
|
|
|
|
|
|
|
int rcar_du_hdmienc_init(struct rcar_du_device *rcdu,
|
|
|
|
struct rcar_du_encoder *renc, struct device_node *np)
|
|
|
|
{
|
|
|
|
struct drm_encoder *encoder = rcar_encoder_to_drm_encoder(renc);
|
|
|
|
struct drm_i2c_encoder_driver *driver;
|
|
|
|
struct i2c_client *i2c_slave;
|
|
|
|
struct rcar_du_hdmienc *hdmienc;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
hdmienc = devm_kzalloc(rcdu->dev, sizeof(*hdmienc), GFP_KERNEL);
|
|
|
|
if (hdmienc == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* Locate the slave I2C device and driver. */
|
|
|
|
i2c_slave = of_find_i2c_device_by_node(np);
|
|
|
|
if (!i2c_slave || !i2c_get_clientdata(i2c_slave))
|
|
|
|
return -EPROBE_DEFER;
|
|
|
|
|
|
|
|
hdmienc->dev = &i2c_slave->dev;
|
|
|
|
|
|
|
|
if (hdmienc->dev->driver == NULL) {
|
|
|
|
ret = -EPROBE_DEFER;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the slave encoder. */
|
|
|
|
driver = to_drm_i2c_encoder_driver(to_i2c_driver(hdmienc->dev->driver));
|
|
|
|
ret = driver->encoder_init(i2c_slave, rcdu->ddev, &renc->slave);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
ret = drm_encoder_init(rcdu->ddev, encoder, &encoder_funcs,
|
|
|
|
DRM_MODE_ENCODER_TMDS);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
drm_encoder_helper_add(encoder, &encoder_helper_funcs);
|
|
|
|
|
|
|
|
renc->hdmi = hdmienc;
|
|
|
|
hdmienc->renc = renc;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
put_device(hdmienc->dev);
|
|
|
|
return ret;
|
|
|
|
}
|