drivers/gpu/drm/sitronix/st7920.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/sitronix/st7920.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/sitronix/st7920.c
Extension
.c
Size
23407 bytes
Lines
868
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 spi7920_error {
	int errno;
};

struct st7920_device {
	struct drm_device drm;
	struct drm_display_mode mode;
	struct drm_plane primary_plane;
	struct drm_crtc crtc;
	struct drm_encoder encoder;
	struct drm_connector connector;
	struct spi_device *spi;

	struct regmap *regmap;

	struct gpio_desc *reset_gpio;

	u32 height;
	u32 width;
};

struct st7920_plane_state {
	struct drm_shadow_plane_state base;
	/* Intermediate buffer to convert pixels from XRGB8888 to HW format */
	u8 *buffer;
};

struct st7920_crtc_state {
	struct drm_crtc_state base;
	/* Buffer to store pixels in HW format and written to the panel */
	u8 *data_array;
};

static inline struct st7920_plane_state *to_st7920_plane_state(struct drm_plane_state *state)
{
	return container_of(state, struct st7920_plane_state, base.base);
}

static inline struct st7920_crtc_state *to_st7920_crtc_state(struct drm_crtc_state *state)
{
	return container_of(state, struct st7920_crtc_state, base);
}

static inline struct st7920_device *drm_to_st7920(struct drm_device *drm)
{
	return container_of(drm, struct st7920_device, drm);
}

static int st7920_store_gdram_address(const void *data, u8 *reg)
{
	const u8 y_addr = *(const u8 *)data;
	bool bottom_screen = (y_addr >= 32);
	int i = 0;

	reg[i++] = SYNC_BITS;
	/* Set vertical address */
	if (!bottom_screen)
		reg[i++] = TOP_VERTICAL_ADDRESS + (*(uint8_t *)data & HIGH_DATA_MASK);
	else
		reg[i++] = BOTTOM_VERTICAL_ADDRESS + (*(uint8_t *)data & HIGH_DATA_MASK);

	reg[i++] = *(uint8_t *)data << 4;
	/* Set horizontal address */
	reg[i++] = SET_GDRAM_ADDRESS;
	if (!bottom_screen)
		reg[i++] = TOP_HORIZONTAL_ADDRESS;
	else
		reg[i++] = BOTTOM_HORIZONTAL_ADDRESS;

	return i;
}

static int st7920_store_gdram_data(const void *data, u8 *reg)
{
	const u8 *line_data = data;
	int i = 0, j = 0;

	reg[i++] = SYNC_BITS | RS_HIGH;

	for (j = 0; j < 16; j++) {
		reg[i++] = line_data[j] & 0xF0;
		reg[i++] = (line_data[j] << 4) & 0xF0;
	}

	return i;
}

static int st7920_store_others(int cmd, const void *data, u8 *reg)
{
	int i = 0;

Annotation

Implementation Notes