Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0-only
2
3#include <linux/backlight.h>
4#include <linux/mod_devicetable.h>
5#include <linux/property.h>
6#include <drm/drm_device.h>
7#include <drm/drm_mipi_dsi.h>
8#include <drm/drm_mode.h>
9#include <drm/drm_modes.h>
10#include <drm/drm_panel.h>
11#include <drm/drm_probe_helper.h>
12#include <video/mipi_display.h>
13
14struct summit_data {
15 struct mipi_dsi_device *dsi;
16 struct backlight_device *bl;
17 struct drm_panel panel;
18};
19
20static int summit_set_brightness(struct device *dev)
21{
22 struct summit_data *s_data = dev_get_drvdata(dev);
23 int level = backlight_get_brightness(s_data->bl);
24
25 return mipi_dsi_dcs_set_display_brightness(s_data->dsi, level);
26}
27
28static int summit_bl_update_status(struct backlight_device *dev)
29{
30 return summit_set_brightness(&dev->dev);
31}
32
33static const struct backlight_ops summit_bl_ops = {
34 .update_status = summit_bl_update_status,
35};
36
37static struct drm_display_mode summit_mode = {
38 .vdisplay = 2008,
39 .hdisplay = 60,
40 .hsync_start = 60 + 8,
41 .hsync_end = 60 + 8 + 80,
42 .htotal = 60 + 8 + 80 + 40,
43 .vsync_start = 2008 + 1,
44 .vsync_end = 2008 + 1 + 15,
45 .vtotal = 2008 + 1 + 15 + 6,
46 .clock = ((60 + 8 + 80 + 40) * (2008 + 1 + 15 + 6) * 60) / 1000,
47 .type = DRM_MODE_TYPE_DRIVER,
48 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC,
49};
50
51static int summit_get_modes(struct drm_panel *panel,
52 struct drm_connector *connector)
53{
54 connector->display_info.non_desktop = true;
55 drm_object_property_set_value(&connector->base,
56 connector->dev->mode_config.non_desktop_property,
57 connector->display_info.non_desktop);
58
59 return drm_connector_helper_get_modes_fixed(connector, &summit_mode);
60}
61
62static const struct drm_panel_funcs summit_panel_funcs = {
63 .get_modes = summit_get_modes,
64};
65
66static int summit_probe(struct mipi_dsi_device *dsi)
67{
68 struct backlight_properties props = { 0 };
69 struct device *dev = &dsi->dev;
70 struct summit_data *s_data;
71 int ret;
72
73 s_data = devm_drm_panel_alloc(dev, struct summit_data, panel,
74 &summit_panel_funcs,
75 DRM_MODE_CONNECTOR_DSI);
76 if (IS_ERR(s_data))
77 return PTR_ERR(s_data);
78
79 mipi_dsi_set_drvdata(dsi, s_data);
80 s_data->dsi = dsi;
81
82 ret = device_property_read_u32(dev, "max-brightness", &props.max_brightness);
83 if (ret)
84 return ret;
85 props.type = BACKLIGHT_RAW;
86
87 s_data->bl = devm_backlight_device_register(dev, dev_name(dev),
88 dev, s_data, &summit_bl_ops, &props);
89 if (IS_ERR(s_data->bl))
90 return PTR_ERR(s_data->bl);
91
92 drm_panel_add(&s_data->panel);
93
94 return mipi_dsi_attach(dsi);
95}
96
97static void summit_remove(struct mipi_dsi_device *dsi)
98{
99 struct summit_data *s_data = mipi_dsi_get_drvdata(dsi);
100
101 mipi_dsi_detach(dsi);
102 drm_panel_remove(&s_data->panel);
103}
104
105static int summit_suspend(struct device *dev)
106{
107 struct summit_data *s_data = dev_get_drvdata(dev);
108
109 return mipi_dsi_dcs_set_display_brightness(s_data->dsi, 0);
110}
111
112static DEFINE_SIMPLE_DEV_PM_OPS(summit_pm_ops, summit_suspend,
113 summit_set_brightness);
114
115static const struct of_device_id summit_of_match[] = {
116 { .compatible = "apple,summit" },
117 {},
118};
119
120MODULE_DEVICE_TABLE(of, summit_of_match);
121
122static struct mipi_dsi_driver summit_driver = {
123 .probe = summit_probe,
124 .remove = summit_remove,
125 .driver = {
126 .name = "panel-summit",
127 .of_match_table = summit_of_match,
128 .pm = pm_sleep_ptr(&summit_pm_ops),
129 },
130};
131module_mipi_dsi_driver(summit_driver);
132
133MODULE_DESCRIPTION("Summit Display Panel Driver");
134MODULE_LICENSE("GPL");