drivers/gpu/drm/panel/panel-novatek-nt39016.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/panel/panel-novatek-nt39016.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/panel/panel-novatek-nt39016.c
Extension
.c
Size
9158 bytes
Lines
359
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 nt39016_panel_info {
	const struct drm_display_mode *display_modes;
	unsigned int num_modes;
	u16 width_mm, height_mm;
	u32 bus_format, bus_flags;
};

struct nt39016 {
	struct drm_panel drm_panel;
	struct regmap *map;
	struct regulator *supply;
	const struct nt39016_panel_info *panel_info;

	struct gpio_desc *reset_gpio;
};

static inline struct nt39016 *to_nt39016(struct drm_panel *panel)
{
	return container_of(panel, struct nt39016, drm_panel);
}

#define RV(REG, VAL) { .reg = (REG), .def = (VAL), .delay_us = 2 }
static const struct reg_sequence nt39016_panel_regs[] = {
	RV(NT39016_REG_SYSTEM, 0x00),
	RV(NT39016_REG_TIMING, 0x00),
	RV(NT39016_REG_OP, 0x03),
	RV(NT39016_REG_DATA_IN, 0xCC),
	RV(NT39016_REG_SRC_TIMING_DELAY, 0x46),
	RV(NT39016_REG_GATE_TIMING_DELAY, 0x05),
	RV(NT39016_REG_RESERVED, 0x00),
	RV(NT39016_REG_INITIAL_FUNC, 0x00),
	RV(NT39016_REG_CONTRAST, 0x08),
	RV(NT39016_REG_BRIGHTNESS, 0x40),
	RV(NT39016_REG_HUE_SATURATION, 0x88),
	RV(NT39016_REG_RB_SUBCONTRAST, 0x88),
	RV(NT39016_REG_R_SUBBRIGHTNESS, 0x20),
	RV(NT39016_REG_B_SUBBRIGHTNESS, 0x20),
	RV(NT39016_REG_VCOMDC, 0x67),
	RV(NT39016_REG_VCOMAC, 0xA4),
	RV(NT39016_REG_VGAM2, 0x04),
	RV(NT39016_REG_VGAM34, 0x24),
	RV(NT39016_REG_VGAM56, 0x24),
	RV(NT39016_REG_DISPLAY_MODE, 0x00),
};

#undef RV

static const struct regmap_range nt39016_regmap_no_ranges[] = {
	regmap_reg_range(0x13, 0x1D),
	regmap_reg_range(0x1F, 0x1F),
};

static const struct regmap_access_table nt39016_regmap_access_table = {
	.no_ranges = nt39016_regmap_no_ranges,
	.n_no_ranges = ARRAY_SIZE(nt39016_regmap_no_ranges),
};

static const struct regmap_config nt39016_regmap_config = {
	.reg_bits = 6,
	.pad_bits = 2,
	.val_bits = 8,

	.max_register = NT39016_REG_DISPLAY_MODE,
	.wr_table = &nt39016_regmap_access_table,
	.write_flag_mask = 0x02,

	.cache_type = REGCACHE_FLAT,
};

static int nt39016_prepare(struct drm_panel *drm_panel)
{
	struct nt39016 *panel = to_nt39016(drm_panel);
	int err;

	err = regulator_enable(panel->supply);
	if (err) {
		dev_err(drm_panel->dev, "Failed to enable power supply: %d\n", err);
		return err;
	}

	/*
	 * Reset the NT39016.
	 * The documentation says the reset pulse should be at least 40 us to
	 * pass the glitch filter, but when testing I see some resets fail and
	 * some succeed when using a 70 us delay, so we use 100 us instead.
	 */
	gpiod_set_value_cansleep(panel->reset_gpio, 1);
	usleep_range(100, 1000);
	gpiod_set_value_cansleep(panel->reset_gpio, 0);
	udelay(2);

Annotation

Implementation Notes