Source
x
// SPDX-License-Identifier: GPL-2.0
/*
* LCD: Formike, TFT 4.3", 480x800, RGB24, KWH043ST20-F01, DriverIC NT35510-16
* LCD initialization via SPI
* Based on:
*
*/
static int spi_write_tag_val(struct spi_slave *spi, unsigned char tag,
unsigned char val)
{
unsigned long flags = SPI_XFER_BEGIN;
u8 buf[2];
int ret;
buf[0] = tag;
ret = spi_xfer(spi, 8, buf, NULL, flags);
buf[0] = val;
flags = SPI_XFER_END;
ret = spi_xfer(spi, 8, buf, NULL, flags);
printf("spi_write_tag_val: tag=%02X, val=%02X ret: %d\n",
tag, val, ret);
/* KWH043ST20_F01_SPI_DEBUG */
if (ret)
debug("%s: Failed to send: %d\n", __func__, ret);
return ret;
}
static void spi_write_dat(struct spi_slave *spi, unsigned int val)
{
spi_write_tag_val(spi, TAG_WRITE|TAG_DATA, val);
}
static void spi_write_com(struct spi_slave *spi, unsigned int addr)
{
spi_write_tag_val(spi, TAG_WRITE|TAG_COMMAND|TAG_ADDR_H,
(addr & 0xff00) >> 8);
spi_write_tag_val(spi, TAG_WRITE|TAG_COMMAND|TAG_ADDR_L,
(addr & 0x00ff) >> 0);
}
int kwh043st20_f01_spi_startup(unsigned int bus, unsigned int cs,
unsigned int max_hz, unsigned int spi_mode)
{
struct spi_slave *spi;
int ret;
spi = spi_setup_slave(bus, cs, max_hz, spi_mode);
if (!spi) {
debug("%s: Failed to set up slave\n", __func__);
return -1;
}
ret = spi_claim_bus(spi);
if (ret) {
debug("%s: Failed to claim SPI bus: %d\n", __func__, ret);
goto err_claim_bus;
}
/* LV2 Page 1 enable */
spi_write_com(spi, 0xF000); spi_write_dat(spi, 0x55);
spi_write_com(spi, 0xF001); spi_write_dat(spi, 0xAA);
spi_write_com(spi, 0xF002); spi_write_dat(spi, 0x52);
spi_write_com(spi, 0xF003); spi_write_dat(spi, 0x08);
spi_write_com(spi, 0xF004); spi_write_dat(spi, 0x01);
/* AVDD Set AVDD 5.2V */
spi_write_com(spi, 0xB000); spi_write_dat(spi, 0x0D);
spi_write_com(spi, 0xB001); spi_write_dat(spi, 0x0D);
spi_write_com(spi, 0xB002); spi_write_dat(spi, 0x0D);
/* AVDD ratio */
spi_write_com(spi, 0xB600); spi_write_dat(spi, 0x34);
spi_write_com(spi, 0xB601); spi_write_dat(spi, 0x34);
spi_write_com(spi, 0xB602); spi_write_dat(spi, 0x34);