Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/
0004  * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
0005  */
0006 
0007 #include <linux/export.h>
0008 
0009 #include <drm/drm_crtc.h>
0010 #include <drm/drm_crtc_helper.h>
0011 #include <drm/drm_panel.h>
0012 #include <drm/drm_of.h>
0013 
0014 #include "tidss_crtc.h"
0015 #include "tidss_drv.h"
0016 #include "tidss_encoder.h"
0017 
0018 static int tidss_encoder_atomic_check(struct drm_encoder *encoder,
0019                       struct drm_crtc_state *crtc_state,
0020                       struct drm_connector_state *conn_state)
0021 {
0022     struct drm_device *ddev = encoder->dev;
0023     struct tidss_crtc_state *tcrtc_state = to_tidss_crtc_state(crtc_state);
0024     struct drm_display_info *di = &conn_state->connector->display_info;
0025     struct drm_bridge *bridge;
0026     bool bus_flags_set = false;
0027 
0028     dev_dbg(ddev->dev, "%s\n", __func__);
0029 
0030     /*
0031      * Take the bus_flags from the first bridge that defines
0032      * bridge timings, or from the connector's display_info if no
0033      * bridge defines the timings.
0034      */
0035     drm_for_each_bridge_in_chain(encoder, bridge) {
0036         if (!bridge->timings)
0037             continue;
0038 
0039         tcrtc_state->bus_flags = bridge->timings->input_bus_flags;
0040         bus_flags_set = true;
0041         break;
0042     }
0043 
0044     if (!di->bus_formats || di->num_bus_formats == 0)  {
0045         dev_err(ddev->dev, "%s: No bus_formats in connected display\n",
0046             __func__);
0047         return -EINVAL;
0048     }
0049 
0050     // XXX any cleaner way to set bus format and flags?
0051     tcrtc_state->bus_format = di->bus_formats[0];
0052     if (!bus_flags_set)
0053         tcrtc_state->bus_flags = di->bus_flags;
0054 
0055     return 0;
0056 }
0057 
0058 static void tidss_encoder_destroy(struct drm_encoder *encoder)
0059 {
0060     drm_encoder_cleanup(encoder);
0061     kfree(encoder);
0062 }
0063 
0064 static const struct drm_encoder_helper_funcs encoder_helper_funcs = {
0065     .atomic_check = tidss_encoder_atomic_check,
0066 };
0067 
0068 static const struct drm_encoder_funcs encoder_funcs = {
0069     .destroy = tidss_encoder_destroy,
0070 };
0071 
0072 struct drm_encoder *tidss_encoder_create(struct tidss_device *tidss,
0073                      u32 encoder_type, u32 possible_crtcs)
0074 {
0075     struct drm_encoder *enc;
0076     int ret;
0077 
0078     enc = kzalloc(sizeof(*enc), GFP_KERNEL);
0079     if (!enc)
0080         return ERR_PTR(-ENOMEM);
0081 
0082     enc->possible_crtcs = possible_crtcs;
0083 
0084     ret = drm_encoder_init(&tidss->ddev, enc, &encoder_funcs,
0085                    encoder_type, NULL);
0086     if (ret < 0) {
0087         kfree(enc);
0088         return ERR_PTR(ret);
0089     }
0090 
0091     drm_encoder_helper_add(enc, &encoder_helper_funcs);
0092 
0093     dev_dbg(tidss->dev, "Encoder create done\n");
0094 
0095     return enc;
0096 }