linux/drivers/gpu/drm/armada/armada_output.c
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2012 Russell King
   3 *
   4 * This program is free software; you can redistribute it and/or modify
   5 * it under the terms of the GNU General Public License version 2 as
   6 * published by the Free Software Foundation.
   7 */
   8#include <drm/drmP.h>
   9#include <drm/drm_crtc_helper.h>
  10#include <drm/drm_edid.h>
  11#include <drm/drm_encoder_slave.h>
  12#include "armada_output.h"
  13#include "armada_drm.h"
  14
  15struct armada_connector {
  16        struct drm_connector conn;
  17        const struct armada_output_type *type;
  18};
  19
  20#define drm_to_armada_conn(c) container_of(c, struct armada_connector, conn)
  21
  22struct drm_encoder *armada_drm_connector_encoder(struct drm_connector *conn)
  23{
  24        struct drm_encoder *enc = conn->encoder;
  25
  26        return enc ? enc : drm_encoder_find(conn->dev, conn->encoder_ids[0]);
  27}
  28
  29static enum drm_connector_status armada_drm_connector_detect(
  30        struct drm_connector *conn, bool force)
  31{
  32        struct armada_connector *dconn = drm_to_armada_conn(conn);
  33        enum drm_connector_status status = connector_status_disconnected;
  34
  35        if (dconn->type->detect) {
  36                status = dconn->type->detect(conn, force);
  37        } else {
  38                struct drm_encoder *enc = armada_drm_connector_encoder(conn);
  39
  40                if (enc)
  41                        status = encoder_helper_funcs(enc)->detect(enc, conn);
  42        }
  43
  44        return status;
  45}
  46
  47static void armada_drm_connector_destroy(struct drm_connector *conn)
  48{
  49        struct armada_connector *dconn = drm_to_armada_conn(conn);
  50
  51        drm_connector_unregister(conn);
  52        drm_connector_cleanup(conn);
  53        kfree(dconn);
  54}
  55
  56static int armada_drm_connector_set_property(struct drm_connector *conn,
  57        struct drm_property *property, uint64_t value)
  58{
  59        struct armada_connector *dconn = drm_to_armada_conn(conn);
  60
  61        if (!dconn->type->set_property)
  62                return -EINVAL;
  63
  64        return dconn->type->set_property(conn, property, value);
  65}
  66
  67static const struct drm_connector_funcs armada_drm_conn_funcs = {
  68        .dpms           = drm_helper_connector_dpms,
  69        .fill_modes     = drm_helper_probe_single_connector_modes,
  70        .detect         = armada_drm_connector_detect,
  71        .destroy        = armada_drm_connector_destroy,
  72        .set_property   = armada_drm_connector_set_property,
  73};
  74
  75/* Shouldn't this be a generic helper function? */
  76int armada_drm_slave_encoder_mode_valid(struct drm_connector *conn,
  77        struct drm_display_mode *mode)
  78{
  79        struct drm_encoder *encoder = armada_drm_connector_encoder(conn);
  80        int valid = MODE_BAD;
  81
  82        if (encoder) {
  83                struct drm_encoder_slave *slave = to_encoder_slave(encoder);
  84
  85                valid = slave->slave_funcs->mode_valid(encoder, mode);
  86        }
  87        return valid;
  88}
  89
  90int armada_drm_slave_encoder_set_property(struct drm_connector *conn,
  91        struct drm_property *property, uint64_t value)
  92{
  93        struct drm_encoder *encoder = armada_drm_connector_encoder(conn);
  94        int rc = -EINVAL;
  95
  96        if (encoder) {
  97                struct drm_encoder_slave *slave = to_encoder_slave(encoder);
  98
  99                rc = slave->slave_funcs->set_property(encoder, conn, property,
 100                                                      value);
 101        }
 102        return rc;
 103}
 104
 105int armada_output_create(struct drm_device *dev,
 106        const struct armada_output_type *type, const void *data)
 107{
 108        struct armada_connector *dconn;
 109        int ret;
 110
 111        dconn = kzalloc(sizeof(*dconn), GFP_KERNEL);
 112        if (!dconn)
 113                return -ENOMEM;
 114
 115        dconn->type = type;
 116
 117        ret = drm_connector_init(dev, &dconn->conn, &armada_drm_conn_funcs,
 118                                 type->connector_type);
 119        if (ret) {
 120                DRM_ERROR("unable to init connector\n");
 121                goto err_destroy_dconn;
 122        }
 123
 124        ret = type->create(&dconn->conn, data);
 125        if (ret)
 126                goto err_conn;
 127
 128        ret = drm_connector_register(&dconn->conn);
 129        if (ret)
 130                goto err_sysfs;
 131
 132        return 0;
 133
 134 err_sysfs:
 135        if (dconn->conn.encoder)
 136                dconn->conn.encoder->funcs->destroy(dconn->conn.encoder);
 137 err_conn:
 138        drm_connector_cleanup(&dconn->conn);
 139 err_destroy_dconn:
 140        kfree(dconn);
 141        return ret;
 142}
 143