drivers/gpu/drm/panel/panel-widechips-ws2401.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/panel/panel-widechips-ws2401.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/panel/panel-widechips-ws2401.c
Extension
.c
Size
13123 bytes
Lines
447
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 ws2401 {
	/** @dev: the container device */
	struct device *dev;
	/** @dbi: the DBI bus abstraction handle */
	struct mipi_dbi dbi;
	/** @panel: the DRM panel instance for this device */
	struct drm_panel panel;
	/** @width: the width of this panel in mm */
	u32 width;
	/** @height: the height of this panel in mm */
	u32 height;
	/** @reset: reset GPIO line */
	struct gpio_desc *reset;
	/** @regulators: VCCIO and VIO supply regulators */
	struct regulator_bulk_data regulators[2];
	/** @internal_bl: If using internal backlight */
	bool internal_bl;
};

static const struct drm_display_mode lms380kf01_480_800_mode = {
	/*
	 * The vendor driver states that the "SMD panel" has a clock
	 * frequency of 49920000 Hz / 2 = 24960000 Hz.
	 */
	.clock = 24960,
	.hdisplay = 480,
	.hsync_start = 480 + 8,
	.hsync_end = 480 + 8 + 10,
	.htotal = 480 + 8 + 10 + 8,
	.vdisplay = 800,
	.vsync_start = 800 + 8,
	.vsync_end = 800 + 8 + 2,
	.vtotal = 800 + 8 + 2 + 18,
	.width_mm = 50,
	.height_mm = 84,
	.flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
};

static inline struct ws2401 *to_ws2401(struct drm_panel *panel)
{
	return container_of(panel, struct ws2401, panel);
}

static void ws2401_read_mtp_id(struct ws2401 *ws)
{
	struct mipi_dbi *dbi = &ws->dbi;
	u8 id1, id2, id3;
	int ret;

	ret = mipi_dbi_command_read(dbi, WS2401_READ_ID1, &id1);
	if (ret) {
		dev_err(ws->dev, "unable to read MTP ID 1\n");
		return;
	}
	ret = mipi_dbi_command_read(dbi, WS2401_READ_ID2, &id2);
	if (ret) {
		dev_err(ws->dev, "unable to read MTP ID 2\n");
		return;
	}
	ret = mipi_dbi_command_read(dbi, WS2401_READ_ID3, &id3);
	if (ret) {
		dev_err(ws->dev, "unable to read MTP ID 3\n");
		return;
	}
	dev_info(ws->dev, "MTP ID: %02x %02x %02x\n", id1, id2, id3);
}

static int ws2401_power_on(struct ws2401 *ws)
{
	struct mipi_dbi *dbi = &ws->dbi;
	int ret;

	/* Power up */
	ret = regulator_bulk_enable(ARRAY_SIZE(ws->regulators),
				    ws->regulators);
	if (ret) {
		dev_err(ws->dev, "failed to enable regulators: %d\n", ret);
		return ret;
	}
	msleep(10);

	/* Assert reset >=1 ms */
	gpiod_set_value_cansleep(ws->reset, 1);
	usleep_range(1000, 5000);
	/* De-assert reset */
	gpiod_set_value_cansleep(ws->reset, 0);
	/* Wait >= 10 ms */
	msleep(10);
	dev_dbg(ws->dev, "de-asserted RESET\n");

Annotation

Implementation Notes