1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
| #include <linux/clk.h> #include <linux/component.h> #include <linux/mfd/syscon.h> #include <linux/of_graph.h> #include <linux/phy/phy.h> #include <linux/pinctrl/devinfo.h> #include <linux/platform_device.h> #include <linux/pm_runtime.h> #include <linux/regmap.h> #include <linux/reset.h>
#include <drm/drm_atomic_helper.h> #include <drm/drm_bridge.h> #include <drm/drm_bridge_connector.h> #include <drm/drm_dp_helper.h> #include <drm/drm_of.h> #include <drm/drm_panel.h> #include <drm/drm_probe_helper.h> #include <drm/drm_simple_kms_helper.h>
#include "demo_drv.h"
struct demo_lvds { struct device *dev; struct drm_device *drm_dev; struct device_node *port;
struct drm_connector connector; struct drm_encoder encoder;
};
static const struct drm_encoder_helper_funcs demo_lvds_encoder_funcs;
static void demo_connector_destroy(struct drm_connector *connector) { drm_connector_cleanup(connector); }
static const struct drm_connector_funcs demo_connector_funcs = { .fill_modes = drm_helper_probe_single_connector_modes, .destroy = demo_connector_destroy, .reset = drm_atomic_helper_connector_reset, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, };
static int demo_conn_get_modes(struct drm_connector *connector) { int count;
count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX); drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
return count; }
static const struct drm_connector_helper_funcs demo_conn_helper_funcs = { .get_modes = demo_conn_get_modes, };
static const struct of_device_id demo_lvds_dt_ids[] = { { .compatible = "demo,drm-lvds", }, {} }; MODULE_DEVICE_TABLE(of, demo_lvds_dt_ids);
static int demo_lvds_bind(struct device *dev, struct device *master, void *data) { struct demo_lvds *lvds = dev_get_drvdata(dev); struct drm_device *drm_dev = data; struct drm_encoder *encoder; struct drm_connector *connector; struct device_node *np = dev->of_node; int ret;
lvds->drm_dev = drm_dev; encoder = &lvds->encoder; encoder->possible_crtcs = drm_of_find_possible_crtcs(drm_dev, np);
pr_info("possible_crtcs %d\n", encoder->possible_crtcs);
ret = drm_simple_encoder_init(drm_dev, encoder, DRM_MODE_ENCODER_LVDS); if (ret < 0) { DRM_DEV_ERROR(drm_dev->dev, "failed to initialize encoder: %d\n", ret); return -1; }
drm_encoder_helper_add(encoder, &demo_lvds_encoder_funcs);
connector = &lvds->connector; ret = drm_connector_init(drm_dev, connector, &demo_connector_funcs, DRM_MODE_CONNECTOR_LVDS); if (ret) { DRM_ERROR("Failed to init connector\n"); return -1; } drm_connector_helper_add(connector, &demo_conn_helper_funcs);
ret = drm_connector_attach_encoder(connector, encoder); if (ret) { DRM_ERROR("Failed to attach connector to encoder\n"); return -1; }
pr_info("%s, %d\n", __func__, __LINE__); return 0; }
static void demo_lvds_unbind(struct device *dev, struct device *master, void *data) { pr_info("%s, %d\n", __func__, __LINE__); }
static const struct component_ops demo_lvds_component_ops = { .bind = demo_lvds_bind, .unbind = demo_lvds_unbind, };
static int demo_lvds_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct demo_lvds *lvds; int ret = 0;
pr_info("%s, %d\n", __func__, __LINE__);
lvds = devm_kzalloc(&pdev->dev, sizeof(*lvds), GFP_KERNEL); if (!lvds) return -ENOMEM;
dev_set_drvdata(dev, lvds);
ret = component_add(&pdev->dev, &demo_lvds_component_ops); if (ret < 0) { pr_err("failed to add component\n"); }
return ret; }
static int demo_lvds_remove(struct platform_device *pdev) { component_del(&pdev->dev, &demo_lvds_component_ops); return 0; }
struct platform_driver demo_lvds_driver = { .probe = demo_lvds_probe, .remove = demo_lvds_remove, .driver = { .name = "demo-lvds", .of_match_table = of_match_ptr(demo_lvds_dt_ids), }, };
|