// SPDX-License-Identifier: GPL-2.0 /* * Panel driver for the TPO TPG110 400CH LTPS TFT LCD Single Chip * Digital Driver. * * This chip drives a TFT LCD, so it does not know what kind of * display is actually connected to it, so the width and height of that * display needs to be supplied from the machine configuration. * * Author: * Linus Walleij <linus.walleij@linaro.org>
*/ #include <drm/drm_modes.h> #include <drm/drm_panel.h>
/** * struct tpg110_panel_mode - lookup struct for the supported modes
*/ struct tpg110_panel_mode { /** * @name: the name of this panel
*/ constchar *name; /** * @magic: the magic value from the detection register
*/
u32 magic; /** * @mode: the DRM display mode for this panel
*/ struct drm_display_mode mode; /** * @bus_flags: the DRM bus flags for this panel e.g. inverted clock
*/
u32 bus_flags;
};
/** * struct tpg110 - state container for the TPG110 panel
*/ struct tpg110 { /** * @dev: the container device
*/ struct device *dev; /** * @spi: the corresponding SPI device
*/ struct spi_device *spi; /** * @panel: the DRM panel instance for this device
*/ struct drm_panel panel; /** * @panel_mode: the panel mode as detected
*/ conststruct tpg110_panel_mode *panel_mode; /** * @width: the width of this panel in mm
*/
u32 width; /** * @height: the height of this panel in mm
*/
u32 height; /** * @grestb: reset GPIO line
*/ struct gpio_desc *grestb;
};
if (write) { /* * Clear address bit 0, 1 when writing, just to be sure * The actual bit indicating a write here is bit 1, bit * 0 is just surplus to pad it up to 8 bits.
*/
buf[0] = address << 2;
buf[0] &= ~0x03;
buf[1] = outval;
t[1].tx_buf = &buf[1];
t[1].len = 1;
t[1].bits_per_word = 8;
} else { /* Set address bit 0 to 1 to read */
buf[0] = address << 1;
buf[0] |= 0x01;
/* * The last bit/clock is Hi-Z turnaround cycle, so we need * to send only 7 bits here. The 8th bit is the high impedance * turn-around cycle.
*/
t[0].bits_per_word = 7;
t[0].tx_buf = &buf[0];
t[0].len = 1;
staticint tpg110_startup(struct tpg110 *tpg)
{
u8 val; int i;
/* De-assert the reset signal */
gpiod_set_value_cansleep(tpg->grestb, 0);
usleep_range(1000, 2000);
dev_dbg(tpg->dev, "de-asserted GRESTB\n");
/* Test display communication */
tpg110_write_reg(tpg, TPG110_TEST, 0x55);
val = tpg110_read_reg(tpg, TPG110_TEST); if (val != 0x55) {
dev_err(tpg->dev, "failed communication test\n"); return -ENODEV;
}
val = tpg110_read_reg(tpg, TPG110_CHIPID);
dev_info(tpg->dev, "TPG110 chip ID: %d version: %d\n",
val >> 4, val & 0x0f);
/* Show display resolution */
val = tpg110_read_reg(tpg, TPG110_CTRL1);
val &= TPG110_RES_MASK; switch (val) { case TPG110_RES_400X240_D:
dev_info(tpg->dev, "IN 400x240 RGB -> OUT 800x480 RGB (dual scan)\n"); break; case TPG110_RES_480X272_D:
dev_info(tpg->dev, "IN 480x272 RGB -> OUT 800x480 RGB (dual scan)\n"); break; case TPG110_RES_480X640:
dev_info(tpg->dev, "480x640 RGB\n"); break; case TPG110_RES_480X272:
dev_info(tpg->dev, "480x272 RGB\n"); break; case TPG110_RES_640X480:
dev_info(tpg->dev, "640x480 RGB\n"); break; case TPG110_RES_800X480:
dev_info(tpg->dev, "800x480 RGB\n"); break; default:
dev_err(tpg->dev, "ILLEGAL RESOLUTION 0x%02x\n", val); break;
}
/* From the producer side, this is the same resolution */ if (val == TPG110_RES_480X272_D)
val = TPG110_RES_480X272;
for (i = 0; i < ARRAY_SIZE(tpg110_modes); i++) { conststruct tpg110_panel_mode *pm;
pm = &tpg110_modes[i]; if (pm->magic == val) {
tpg->panel_mode = pm; break;
}
} if (i == ARRAY_SIZE(tpg110_modes)) {
dev_err(tpg->dev, "unsupported mode (%02x) detected\n", val); return -ENODEV;
}
val = tpg110_read_reg(tpg, TPG110_CTRL2);
dev_info(tpg->dev, "resolution and standby is controlled by %s\n",
(val & TPG110_CTRL2_RES_PM_CTRL) ? "software" : "hardware"); /* Take control over resolution and standby */
val |= TPG110_CTRL2_RES_PM_CTRL;
tpg110_write_reg(tpg, TPG110_CTRL2, val);
/* Take chip out of standby */
val = tpg110_read_reg(tpg, TPG110_CTRL2_PM);
val |= TPG110_CTRL2_PM;
tpg110_write_reg(tpg, TPG110_CTRL2_PM, val);
return 0;
}
/** * tpg110_get_modes() - return the appropriate mode * @panel: the panel to get the mode for * @connector: reference to the central DRM connector control structure * * This currently does not present a forest of modes, instead it * presents the mode that is configured for the system under use, * and which is detected by reading the registers of the display.
*/ staticint tpg110_get_modes(struct drm_panel *panel, struct drm_connector *connector)
{ struct tpg110 *tpg = to_tpg110(panel); struct drm_display_mode *mode;
/* We get the physical display dimensions from the DT */
ret = of_property_read_u32(np, "width-mm", &tpg->width); if (ret)
dev_err(dev, "no panel width specified\n");
ret = of_property_read_u32(np, "height-mm", &tpg->height); if (ret)
dev_err(dev, "no panel height specified\n");
/* This asserts the GRESTB signal, putting the display into reset */
tpg->grestb = devm_gpiod_get(dev, "grestb", GPIOD_OUT_HIGH); if (IS_ERR(tpg->grestb)) {
dev_err(dev, "no GRESTB GPIO\n"); return -ENODEV;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.