drivers/gpu/drm/panel/panel-tpo-td043mtea1.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
Extension
.c
Size
11734 bytes
Lines
505
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct td043mtea1_panel {
	struct drm_panel panel;

	struct spi_device *spi;
	struct regulator *vcc_reg;
	struct gpio_desc *reset_gpio;

	unsigned int mode;
	u16 gamma[12];
	bool vmirror;
	bool powered_on;
	bool spi_suspended;
	bool power_on_resume;
};

#define to_td043mtea1_device(p) container_of(p, struct td043mtea1_panel, panel)

/* -----------------------------------------------------------------------------
 * Hardware Access
 */

static int td043mtea1_write(struct td043mtea1_panel *lcd, u8 addr, u8 value)
{
	struct spi_message msg;
	struct spi_transfer xfer;
	u16 data;
	int ret;

	spi_message_init(&msg);

	memset(&xfer, 0, sizeof(xfer));

	data = ((u16)addr << 10) | (1 << 8) | value;
	xfer.tx_buf = &data;
	xfer.bits_per_word = 16;
	xfer.len = 2;
	spi_message_add_tail(&xfer, &msg);

	ret = spi_sync(lcd->spi, &msg);
	if (ret < 0)
		dev_warn(&lcd->spi->dev, "failed to write to LCD reg (%d)\n",
			 ret);

	return ret;
}

static void td043mtea1_write_gamma(struct td043mtea1_panel *lcd)
{
	const u16 *gamma = lcd->gamma;
	unsigned int i;
	u8 val;

	/* gamma bits [9:8] */
	for (val = i = 0; i < 4; i++)
		val |= (gamma[i] & 0x300) >> ((i + 1) * 2);
	td043mtea1_write(lcd, 0x11, val);

	for (val = i = 0; i < 4; i++)
		val |= (gamma[i + 4] & 0x300) >> ((i + 1) * 2);
	td043mtea1_write(lcd, 0x12, val);

	for (val = i = 0; i < 4; i++)
		val |= (gamma[i + 8] & 0x300) >> ((i + 1) * 2);
	td043mtea1_write(lcd, 0x13, val);

	/* gamma bits [7:0] */
	for (i = 0; i < 12; i++)
		td043mtea1_write(lcd, 0x14 + i, gamma[i] & 0xff);
}

static int td043mtea1_write_mirror(struct td043mtea1_panel *lcd)
{
	u8 reg4 = TPO_R04_NFLIP_H | TPO_R04_NFLIP_V |
		TPO_R04_CP_CLK_FREQ_1H | TPO_R04_VGL_FREQ_1H;
	if (lcd->vmirror)
		reg4 &= ~TPO_R04_NFLIP_V;

	return td043mtea1_write(lcd, 4, reg4);
}

static int td043mtea1_power_on(struct td043mtea1_panel *lcd)
{
	int ret;

	if (lcd->powered_on)
		return 0;

	ret = regulator_enable(lcd->vcc_reg);
	if (ret < 0)
		return ret;

Annotation

Implementation Notes