blob: 95984fe3d3d1bab04d26a6165ef0415ed4bfc150 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Hans de Goedec0482032015-01-20 09:22:26 +01002/*
3 * Hitachi tx18d42vm LVDS LCD panel driver
4 *
5 * (C) Copyright 2015 Hans de Goede <hdegoede@redhat.com>
Hans de Goedec0482032015-01-20 09:22:26 +01006 */
7
8#include <common.h>
Simon Glass9bc15642020-02-03 07:36:16 -07009#include <malloc.h>
Simon Glassdbd79542020-05-10 11:40:11 -060010#include <linux/delay.h>
Hans de Goedec0482032015-01-20 09:22:26 +010011
12#include <asm/gpio.h>
Andre Przywaraf944a612022-09-06 10:36:38 +010013#include <sunxi_gpio.h>
Hans de Goedec0482032015-01-20 09:22:26 +010014#include <errno.h>
15
16/*
17 * Very simple write only SPI support, this does not use the generic SPI infra
18 * because that assumes R/W SPI, requiring a MISO pin. Also the necessary glue
19 * code alone would be larger then this minimal version.
20 */
21static void lcd_panel_spi_write(int cs, int clk, int mosi,
22 unsigned int data, int bits)
23{
24 int i, offset;
25
26 gpio_direction_output(cs, 0);
27 for (i = 0; i < bits; i++) {
28 gpio_direction_output(clk, 0);
29 offset = (bits - 1) - i;
30 gpio_direction_output(mosi, (data >> offset) & 1);
31 udelay(2);
32 gpio_direction_output(clk, 1);
33 udelay(2);
34 }
35 gpio_direction_output(cs, 1);
36 udelay(2);
37}
38
39int hitachi_tx18d42vm_init(void)
40{
41 const u16 init_data[] = {
42 0x0029, /* reset */
43 0x0025, /* standby */
44 0x0840, /* enable normally black */
45 0x0430, /* enable FRC/dither */
46 0x385f, /* enter test mode(1) */
47 0x3ca4, /* enter test mode(2) */
48 0x3409, /* enable SDRRS, enlarge OE width */
49 0x4041, /* adopt 2 line / 1 dot */
50 };
51 int i, cs, clk, mosi, ret = 0;
52
Samuel Hollandc7ab95d2021-09-11 16:50:48 -050053 cs = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_SPI_CS);
54 clk = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_SPI_SCLK);
55 mosi = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_SPI_MOSI);
Hans de Goedec0482032015-01-20 09:22:26 +010056
57 if (cs == -1 || clk == -1 || mosi == 1) {
58 printf("Error tx18d42vm spi gpio config is invalid\n");
59 return -EINVAL;
60 }
61
62 if (gpio_request(cs, "tx18d42vm-spi-cs") != 0 ||
63 gpio_request(clk, "tx18d42vm-spi-clk") != 0 ||
64 gpio_request(mosi, "tx18d42vm-spi-mosi") != 0) {
65 printf("Error cannot request tx18d42vm spi gpios\n");
66 ret = -EBUSY;
67 goto out;
68 }
69
70 for (i = 0; i < ARRAY_SIZE(init_data); i++)
71 lcd_panel_spi_write(cs, clk, mosi, init_data[i], 16);
72
73 mdelay(50); /* All the tx18d42vm drivers have a delay here ? */
74
75 lcd_panel_spi_write(cs, clk, mosi, 0x00ad, 16); /* display on */
76
77out:
78 gpio_free(mosi);
79 gpio_free(clk);
80 gpio_free(cs);
81
82 return ret;
83}