Blame view
drivers/video/lg4573.c
5.74 KB
83d290c56
|
1 |
// SPDX-License-Identifier: GPL-2.0 |
fc1a79d95
|
2 3 4 5 |
/* * LCD: LG4573, TFT 4.3", 480x800, RGB24 * LCD initialization via SPI * |
fc1a79d95
|
6 7 |
*/ #include <common.h> |
79db1b466
|
8 9 10 11 12 |
#include <backlight.h> #include <display.h> #include <dm.h> #include <dm/read.h> #include <dm/uclass-internal.h> |
fc1a79d95
|
13 14 |
#include <errno.h> #include <spi.h> |
79db1b466
|
15 |
#include <asm/gpio.h> |
fc1a79d95
|
16 17 |
#define PWR_ON_DELAY_MSECS 120 |
79db1b466
|
18 |
static int lb043wv_spi_write_u16(struct spi_slave *slave, u16 val) |
fc1a79d95
|
19 |
{ |
fc1a79d95
|
20 21 |
unsigned short buf16 = htons(val); int ret = 0; |
79db1b466
|
22 23 |
ret = spi_xfer(slave, 16, &buf16, NULL, SPI_XFER_BEGIN | SPI_XFER_END); |
fc1a79d95
|
24 25 26 27 28 29 |
if (ret) debug("%s: Failed to send: %d ", __func__, ret); return ret; } |
79db1b466
|
30 |
static void lb043wv_spi_write_u16_array(struct spi_slave *slave, u16 *buff, |
fc1a79d95
|
31 32 33 34 35 |
int size) { int i; for (i = 0; i < size; i++) |
79db1b466
|
36 |
lb043wv_spi_write_u16(slave, buff[i]); |
fc1a79d95
|
37 |
} |
79db1b466
|
38 |
static void lb043wv_display_mode_settings(struct spi_slave *slave) |
fc1a79d95
|
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 |
{ static u16 display_mode_settings[] = { 0x703A, 0x7270, 0x70B1, 0x7208, 0x723B, 0x720F, 0x70B2, 0x7200, 0x72C8, 0x70B3, 0x7200, 0x70B4, 0x7200, 0x70B5, 0x7242, 0x7210, 0x7210, 0x7200, 0x7220, 0x70B6, 0x720B, 0x720F, 0x723C, 0x7213, 0x7213, 0x72E8, 0x70B7, 0x7246, 0x7206, 0x720C, 0x7200, 0x7200, }; debug("transfer display mode settings "); |
79db1b466
|
77 |
lb043wv_spi_write_u16_array(slave, display_mode_settings, |
fc1a79d95
|
78 79 |
ARRAY_SIZE(display_mode_settings)); } |
79db1b466
|
80 |
static void lb043wv_power_settings(struct spi_slave *slave) |
fc1a79d95
|
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 |
{ static u16 power_settings[] = { 0x70C0, 0x7201, 0x7211, 0x70C3, 0x7207, 0x7203, 0x7204, 0x7204, 0x7204, 0x70C4, 0x7212, 0x7224, 0x7218, 0x7218, 0x7202, 0x7249, 0x70C5, 0x726F, 0x70C6, 0x7241, 0x7263, }; debug("transfer power settings "); |
79db1b466
|
108 |
lb043wv_spi_write_u16_array(slave, power_settings, |
fc1a79d95
|
109 110 |
ARRAY_SIZE(power_settings)); } |
79db1b466
|
111 |
static void lb043wv_gamma_settings(struct spi_slave *slave) |
fc1a79d95
|
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 166 167 168 169 170 171 172 173 174 175 176 177 |
{ static u16 gamma_settings[] = { 0x70D0, 0x7203, 0x7207, 0x7273, 0x7235, 0x7200, 0x7201, 0x7220, 0x7200, 0x7203, 0x70D1, 0x7203, 0x7207, 0x7273, 0x7235, 0x7200, 0x7201, 0x7220, 0x7200, 0x7203, 0x70D2, 0x7203, 0x7207, 0x7273, 0x7235, 0x7200, 0x7201, 0x7220, 0x7200, 0x7203, 0x70D3, 0x7203, 0x7207, 0x7273, 0x7235, 0x7200, 0x7201, 0x7220, 0x7200, 0x7203, 0x70D4, 0x7203, 0x7207, 0x7273, 0x7235, 0x7200, 0x7201, 0x7220, 0x7200, 0x7203, 0x70D5, 0x7203, 0x7207, 0x7273, 0x7235, 0x7200, 0x7201, 0x7220, 0x7200, 0x7203, }; debug("transfer gamma settings "); |
79db1b466
|
178 |
lb043wv_spi_write_u16_array(slave, gamma_settings, |
fc1a79d95
|
179 180 |
ARRAY_SIZE(gamma_settings)); } |
79db1b466
|
181 |
static void lb043wv_display_on(struct spi_slave *slave) |
fc1a79d95
|
182 183 184 |
{ static u16 sleep_out = 0x7011; static u16 display_on = 0x7029; |
79db1b466
|
185 |
lb043wv_spi_write_u16(slave, sleep_out); |
fc1a79d95
|
186 |
mdelay(PWR_ON_DELAY_MSECS); |
79db1b466
|
187 |
lb043wv_spi_write_u16(slave, display_on); |
fc1a79d95
|
188 |
} |
79db1b466
|
189 |
static int lg4573_spi_startup(struct spi_slave *slave) |
fc1a79d95
|
190 |
{ |
fc1a79d95
|
191 |
int ret; |
79db1b466
|
192 193 194 |
ret = spi_claim_bus(slave); if (ret) return ret; |
fc1a79d95
|
195 |
|
79db1b466
|
196 197 198 199 |
lb043wv_display_mode_settings(slave); lb043wv_power_settings(slave); lb043wv_gamma_settings(slave); lb043wv_display_on(slave); |
fc1a79d95
|
200 |
|
79db1b466
|
201 |
spi_release_bus(slave); |
fc1a79d95
|
202 |
return 0; |
fc1a79d95
|
203 204 205 206 207 |
} static int do_lgset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { |
79db1b466
|
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
struct spi_slave *slave; struct udevice *dev; int ret; ret = uclass_get_device_by_driver(UCLASS_DISPLAY, DM_GET_DRIVER(lg4573_lcd), &dev); if (ret) { printf("%s: Could not get lg4573 device ", __func__); return ret; } slave = dev_get_parent_priv(dev); if (!slave) { printf("%s: No slave data ", __func__); return -ENODEV; } lg4573_spi_startup(slave); |
fc1a79d95
|
226 227 228 229 230 231 232 233 |
return 0; } U_BOOT_CMD( lgset, 2, 1, do_lgset, "set lgdisplay", "" ); |
79db1b466
|
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
static int lg4573_bind(struct udevice *dev) { return 0; } static int lg4573_probe(struct udevice *dev) { return 0; } static const struct udevice_id lg4573_ids[] = { { .compatible = "lg,lg4573" }, { } }; struct lg4573_lcd_priv { struct display_timing timing; struct udevice *backlight; struct gpio_desc enable; int panel_bpp; u32 power_on_delay; }; static int lg4573_lcd_read_timing(struct udevice *dev, struct display_timing *timing) { struct lg4573_lcd_priv *priv = dev_get_priv(dev); memcpy(timing, &priv->timing, sizeof(struct display_timing)); return 0; } static int lg4573_lcd_enable(struct udevice *dev, int bpp, const struct display_timing *edid) { struct spi_slave *slave = dev_get_parent_priv(dev); struct lg4573_lcd_priv *priv = dev_get_priv(dev); int ret = 0; dm_gpio_set_value(&priv->enable, 1); ret = backlight_enable(priv->backlight); mdelay(priv->power_on_delay); lg4573_spi_startup(slave); return ret; }; static const struct dm_display_ops lg4573_lcd_ops = { .read_timing = lg4573_lcd_read_timing, .enable = lg4573_lcd_enable, }; static int lg4573_ofdata_to_platdata(struct udevice *dev) { struct lg4573_lcd_priv *priv = dev_get_priv(dev); int ret; ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev, "backlight", &priv->backlight); if (ret) { debug("%s: Cannot get backlight: ret=%d ", __func__, ret); return log_ret(ret); } ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable, GPIOD_IS_OUT); if (ret) { debug("%s: Warning: cannot get enable GPIO: ret=%d ", __func__, ret); if (ret != -ENOENT) return log_ret(ret); } priv->power_on_delay = dev_read_u32_default(dev, "power-on-delay", 10); return 0; } U_BOOT_DRIVER(lg4573_lcd) = { .name = "lg4573", .id = UCLASS_DISPLAY, .ops = &lg4573_lcd_ops, .ofdata_to_platdata = lg4573_ofdata_to_platdata, .of_match = lg4573_ids, .bind = lg4573_bind, .probe = lg4573_probe, .priv_auto_alloc_size = sizeof(struct lg4573_lcd_priv), }; |