Neil Armstrong | 4a4057a | 2020-09-29 11:53:53 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2020 BayLibre, SAS |
| 4 | * Author: Neil Armstrong <narmstrong@baylibre.com> |
| 5 | */ |
Neil Armstrong | 4a4057a | 2020-09-29 11:53:53 +0200 | [diff] [blame] | 6 | #include <backlight.h> |
| 7 | #include <dm.h> |
| 8 | #include <mipi_dsi.h> |
| 9 | #include <panel.h> |
| 10 | #include <asm/gpio.h> |
| 11 | #include <dm/device_compat.h> |
| 12 | #include <linux/delay.h> |
| 13 | #include <power/regulator.h> |
| 14 | |
| 15 | struct tl070wsh30_panel_priv { |
| 16 | struct udevice *reg; |
| 17 | struct udevice *backlight; |
| 18 | struct gpio_desc reset; |
| 19 | }; |
| 20 | |
| 21 | static const struct display_timing default_timing = { |
| 22 | .pixelclock.typ = 47250000, |
| 23 | .hactive.typ = 1024, |
| 24 | .hfront_porch.typ = 46, |
| 25 | .hback_porch.typ = 100, |
| 26 | .hsync_len.typ = 80, |
| 27 | .vactive.typ = 600, |
| 28 | .vfront_porch.typ = 5, |
| 29 | .vback_porch.typ = 20, |
| 30 | .vsync_len.typ = 5, |
| 31 | .flags = DISPLAY_FLAGS_HSYNC_HIGH | DISPLAY_FLAGS_VSYNC_HIGH, |
| 32 | }; |
| 33 | |
| 34 | static int tl070wsh30_panel_enable_backlight(struct udevice *dev) |
| 35 | { |
Dario Binacchi | f686e4d | 2021-01-15 09:10:26 +0100 | [diff] [blame] | 36 | struct mipi_dsi_panel_plat *plat = dev_get_plat(dev); |
Neil Armstrong | 4a4057a | 2020-09-29 11:53:53 +0200 | [diff] [blame] | 37 | struct mipi_dsi_device *device = plat->device; |
| 38 | struct tl070wsh30_panel_priv *priv = dev_get_priv(dev); |
| 39 | int ret; |
| 40 | |
| 41 | ret = mipi_dsi_attach(device); |
| 42 | if (ret < 0) |
| 43 | return ret; |
| 44 | |
| 45 | ret = mipi_dsi_dcs_exit_sleep_mode(device); |
| 46 | if (ret) |
| 47 | return ret; |
| 48 | |
| 49 | mdelay(200); |
| 50 | |
| 51 | ret = mipi_dsi_dcs_set_display_on(device); |
| 52 | if (ret) |
| 53 | return ret; |
| 54 | |
| 55 | mdelay(20); |
| 56 | |
| 57 | ret = backlight_enable(priv->backlight); |
| 58 | if (ret) |
| 59 | return ret; |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static int tl070wsh30_panel_get_display_timing(struct udevice *dev, |
| 65 | struct display_timing *timings) |
| 66 | { |
| 67 | memcpy(timings, &default_timing, sizeof(*timings)); |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
Dario Binacchi | f686e4d | 2021-01-15 09:10:26 +0100 | [diff] [blame] | 72 | static int tl070wsh30_panel_of_to_plat(struct udevice *dev) |
Neil Armstrong | 4a4057a | 2020-09-29 11:53:53 +0200 | [diff] [blame] | 73 | { |
| 74 | struct tl070wsh30_panel_priv *priv = dev_get_priv(dev); |
| 75 | int ret; |
| 76 | |
Marek Vasut | a951b43 | 2023-02-28 02:55:23 +0100 | [diff] [blame] | 77 | if (CONFIG_IS_ENABLED(DM_REGULATOR)) { |
Neil Armstrong | 4a4057a | 2020-09-29 11:53:53 +0200 | [diff] [blame] | 78 | ret = device_get_supply_regulator(dev, "power-supply", |
| 79 | &priv->reg); |
| 80 | if (ret && ret != -ENOENT) { |
| 81 | dev_err(dev, "Warning: cannot get power supply\n"); |
| 82 | return ret; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | ret = gpio_request_by_name(dev, "reset-gpios", 0, &priv->reset, |
| 87 | GPIOD_IS_OUT); |
| 88 | if (ret) { |
| 89 | dev_err(dev, "Warning: cannot get reset GPIO\n"); |
| 90 | if (ret != -ENOENT) |
| 91 | return ret; |
| 92 | } |
| 93 | |
| 94 | ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev, |
| 95 | "backlight", &priv->backlight); |
| 96 | if (ret) { |
| 97 | dev_err(dev, "Cannot get backlight: ret=%d\n", ret); |
| 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | static int tl070wsh30_panel_probe(struct udevice *dev) |
| 105 | { |
| 106 | struct tl070wsh30_panel_priv *priv = dev_get_priv(dev); |
Dario Binacchi | f686e4d | 2021-01-15 09:10:26 +0100 | [diff] [blame] | 107 | struct mipi_dsi_panel_plat *plat = dev_get_plat(dev); |
Neil Armstrong | 4a4057a | 2020-09-29 11:53:53 +0200 | [diff] [blame] | 108 | int ret; |
| 109 | |
Marek Vasut | a951b43 | 2023-02-28 02:55:23 +0100 | [diff] [blame] | 110 | if (CONFIG_IS_ENABLED(DM_REGULATOR) && priv->reg) { |
Neil Armstrong | 4a4057a | 2020-09-29 11:53:53 +0200 | [diff] [blame] | 111 | ret = regulator_set_enable(priv->reg, true); |
| 112 | if (ret) |
| 113 | return ret; |
| 114 | } |
| 115 | |
| 116 | mdelay(10); |
| 117 | |
| 118 | /* reset panel */ |
| 119 | dm_gpio_set_value(&priv->reset, true); |
Wolfgang Denk | 9d328a6 | 2021-09-27 17:42:38 +0200 | [diff] [blame] | 120 | |
Neil Armstrong | 4a4057a | 2020-09-29 11:53:53 +0200 | [diff] [blame] | 121 | mdelay(10); |
| 122 | |
| 123 | dm_gpio_set_value(&priv->reset, false); |
| 124 | |
| 125 | /* fill characteristics of DSI data link */ |
| 126 | plat->lanes = 4; |
| 127 | plat->format = MIPI_DSI_FMT_RGB888; |
| 128 | plat->mode_flags = MIPI_DSI_MODE_VIDEO | |
| 129 | MIPI_DSI_MODE_VIDEO_BURST | |
| 130 | MIPI_DSI_MODE_LPM; |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | static const struct panel_ops tl070wsh30_panel_ops = { |
| 136 | .enable_backlight = tl070wsh30_panel_enable_backlight, |
| 137 | .get_display_timing = tl070wsh30_panel_get_display_timing, |
| 138 | }; |
| 139 | |
| 140 | static const struct udevice_id tl070wsh30_panel_ids[] = { |
| 141 | { .compatible = "tdo,tl070wsh30" }, |
| 142 | { } |
| 143 | }; |
| 144 | |
| 145 | U_BOOT_DRIVER(tl070wsh30_panel) = { |
| 146 | .name = "tl070wsh30_panel", |
| 147 | .id = UCLASS_PANEL, |
| 148 | .of_match = tl070wsh30_panel_ids, |
| 149 | .ops = &tl070wsh30_panel_ops, |
Dario Binacchi | f686e4d | 2021-01-15 09:10:26 +0100 | [diff] [blame] | 150 | .of_to_plat = tl070wsh30_panel_of_to_plat, |
Neil Armstrong | 4a4057a | 2020-09-29 11:53:53 +0200 | [diff] [blame] | 151 | .probe = tl070wsh30_panel_probe, |
Dario Binacchi | f686e4d | 2021-01-15 09:10:26 +0100 | [diff] [blame] | 152 | .plat_auto = sizeof(struct mipi_dsi_panel_plat), |
| 153 | .priv_auto = sizeof(struct tl070wsh30_panel_priv), |
Neil Armstrong | 4a4057a | 2020-09-29 11:53:53 +0200 | [diff] [blame] | 154 | }; |