2 * Copyright (C) 2013, NVIDIA Corporation. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 #include <linux/backlight.h>
25 #include <linux/gpio.h>
26 #include <linux/module.h>
27 #include <linux/of_gpio.h>
28 #include <linux/of_platform.h>
29 #include <linux/platform_device.h>
30 #include <linux/regulator/consumer.h>
32 #include <drm/drm_crtc.h>
33 #include <drm/drm_panel.h>
36 const struct drm_display_mode *modes;
37 unsigned int num_modes;
45 /* TODO: convert to gpiod_*() API once it's been merged */
46 #define GPIO_ACTIVE_LOW (1 << 0)
49 struct drm_panel base;
52 const struct panel_desc *desc;
54 struct backlight_device *backlight;
55 struct regulator *supply;
57 unsigned long enable_gpio_flags;
61 static inline struct panel_simple *to_panel_simple(struct drm_panel *panel)
63 return container_of(panel, struct panel_simple, base);
66 static void panel_simple_disable(struct drm_panel *panel)
68 struct panel_simple *p = to_panel_simple(panel);
74 p->backlight->props.power = FB_BLANK_POWERDOWN;
75 backlight_update_status(p->backlight);
78 if (gpio_is_valid(p->enable_gpio)) {
79 if (p->enable_gpio_flags & GPIO_ACTIVE_LOW)
80 gpio_set_value(p->enable_gpio, 1);
82 gpio_set_value(p->enable_gpio, 0);
85 regulator_disable(p->supply);
89 static void panel_simple_enable(struct drm_panel *panel)
91 struct panel_simple *p = to_panel_simple(panel);
97 err = regulator_enable(p->supply);
99 dev_err(panel->dev, "failed to enable supply: %d\n", err);
101 if (gpio_is_valid(p->enable_gpio)) {
102 if (p->enable_gpio_flags & GPIO_ACTIVE_LOW)
103 gpio_set_value(p->enable_gpio, 0);
105 gpio_set_value(p->enable_gpio, 1);
109 p->backlight->props.power = FB_BLANK_UNBLANK;
110 backlight_update_status(p->backlight);
116 static int panel_simple_get_modes(struct drm_panel *panel)
118 struct panel_simple *p = to_panel_simple(panel);
119 struct drm_display_mode *mode;
122 for (i = 0; i < p->desc->num_modes; i++) {
123 mode = drm_mode_duplicate(panel->drm, &p->desc->modes[i]);
127 drm_mode_set_name(mode);
129 drm_mode_probed_add(panel->connector, mode);
132 return p->desc->num_modes;
135 static const struct drm_panel_funcs panel_simple_funcs = {
136 .disable = panel_simple_disable,
137 .enable = panel_simple_enable,
138 .get_modes = panel_simple_get_modes,
141 static const struct drm_display_mode auo_b101aw03_mode = {
144 .hsync_start = 1024 + 156,
145 .hsync_end = 1024 + 156 + 8,
146 .htotal = 1024 + 156 + 8 + 156,
148 .vsync_start = 600 + 16,
149 .vsync_end = 600 + 16 + 6,
150 .vtotal = 600 + 16 + 6 + 16,
154 static const struct panel_desc auo_b101aw03 = {
155 .modes = &auo_b101aw03_mode,
163 static const struct drm_display_mode chunghwa_claa101wb01_mode = {
166 .hsync_start = 1366 + 48,
167 .hsync_end = 1366 + 48 + 32,
168 .htotal = 1366 + 48 + 32 + 20,
170 .vsync_start = 768 + 16,
171 .vsync_end = 768 + 16 + 8,
172 .vtotal = 768 + 16 + 8 + 16,
176 static const struct panel_desc chunghwa_claa101wb01 = {
177 .modes = &chunghwa_claa101wb01_mode,
185 static const struct drm_display_mode panasonic_vvx10f004b00_mode = {
188 .hsync_start = 1920 + 154,
189 .hsync_end = 1920 + 154 + 16,
190 .htotal = 1920 + 154 + 16 + 32,
192 .vsync_start = 1200 + 17,
193 .vsync_end = 1200 + 17 + 2,
194 .vtotal = 1200 + 17 + 2 + 16,
198 static const struct panel_desc panasonic_vvx10f004b00 = {
199 .modes = &panasonic_vvx10f004b00_mode,
207 static const struct of_device_id panel_simple_of_match[] = {
209 .compatible = "auo,b101aw03",
210 .data = &auo_b101aw03,
212 .compatible = "chunghwa,claa101wb01",
213 .data = &chunghwa_claa101wb01
215 .compatible = "panasonic,vvx10f004b00",
216 .data = &panasonic_vvx10f004b00
221 MODULE_DEVICE_TABLE(of, panel_simple_of_match);
223 static int panel_simple_probe(struct platform_device *pdev)
225 const struct of_device_id *id;
226 struct device_node *backlight;
227 struct panel_simple *panel;
228 enum of_gpio_flags flags;
231 panel = devm_kzalloc(&pdev->dev, sizeof(*panel), GFP_KERNEL);
235 id = of_match_node(panel_simple_of_match, pdev->dev.of_node);
239 panel->desc = id->data;
240 panel->enabled = false;
242 panel->supply = devm_regulator_get(&pdev->dev, "power");
243 if (IS_ERR(panel->supply))
244 return PTR_ERR(panel->supply);
246 panel->enable_gpio = of_get_named_gpio_flags(pdev->dev.of_node,
249 if (gpio_is_valid(panel->enable_gpio)) {
252 if (flags & OF_GPIO_ACTIVE_LOW)
253 panel->enable_gpio_flags |= GPIO_ACTIVE_LOW;
255 err = gpio_request(panel->enable_gpio, "enable");
257 dev_err(&pdev->dev, "failed to request GPIO#%u: %d\n",
258 panel->enable_gpio, err);
262 value = (panel->enable_gpio_flags & GPIO_ACTIVE_LOW) != 0;
264 err = gpio_direction_output(panel->enable_gpio, value);
266 dev_err(&pdev->dev, "failed to setup GPIO%u: %d\n",
267 panel->enable_gpio, err);
272 backlight = of_parse_phandle(pdev->dev.of_node, "backlight", 0);
274 panel->backlight = of_find_backlight_by_node(backlight);
275 if (!panel->backlight) {
280 of_node_put(backlight);
283 drm_panel_init(&panel->base);
284 panel->base.dev = &pdev->dev;
285 panel->base.funcs = &panel_simple_funcs;
287 err = drm_panel_add(&panel->base);
291 platform_set_drvdata(pdev, panel);
296 if (gpio_is_valid(panel->enable_gpio))
297 gpio_free(panel->enable_gpio);
302 static int panel_simple_remove(struct platform_device *pdev)
304 struct panel_simple *panel = platform_get_drvdata(pdev);
306 drm_panel_detach(&panel->base);
307 drm_panel_remove(&panel->base);
309 panel_simple_disable(&panel->base);
311 if (panel->backlight)
312 put_device(&panel->backlight->dev);
314 if (gpio_is_valid(panel->enable_gpio))
315 gpio_free(panel->enable_gpio);
317 regulator_disable(panel->supply);
322 static struct platform_driver panel_simple_driver = {
324 .name = "panel-simple",
325 .owner = THIS_MODULE,
326 .of_match_table = panel_simple_of_match,
328 .probe = panel_simple_probe,
329 .remove = panel_simple_remove,
331 module_platform_driver(panel_simple_driver);
333 MODULE_DESCRIPTION("DRM Driver for Simple Panels");
334 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
335 MODULE_LICENSE("GPL v2");