Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Hans de Goede | a5464f2 | 2015-01-20 09:22:26 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Hitachi tx18d42vm LVDS LCD panel driver |
| 4 | * |
| 5 | * (C) Copyright 2015 Hans de Goede <hdegoede@redhat.com> |
Hans de Goede | a5464f2 | 2015-01-20 09:22:26 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 9 | #include <malloc.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 10 | #include <linux/delay.h> |
Hans de Goede | a5464f2 | 2015-01-20 09:22:26 +0100 | [diff] [blame] | 11 | |
| 12 | #include <asm/gpio.h> |
Andre Przywara | 207ed0a | 2022-09-06 10:36:38 +0100 | [diff] [blame^] | 13 | #include <sunxi_gpio.h> |
Hans de Goede | a5464f2 | 2015-01-20 09:22:26 +0100 | [diff] [blame] | 14 | #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 | */ |
| 21 | static 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 | |
| 39 | int 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 Holland | 4d9958b | 2021-09-11 16:50:48 -0500 | [diff] [blame] | 53 | 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 Goede | a5464f2 | 2015-01-20 09:22:26 +0100 | [diff] [blame] | 56 | |
| 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 | |
| 77 | out: |
| 78 | gpio_free(mosi); |
| 79 | gpio_free(clk); |
| 80 | gpio_free(cs); |
| 81 | |
| 82 | return ret; |
| 83 | } |