1 From b279b2516d9fc40cc491b142fbf453f9533f6e4f Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.com>
3 Date: Fri, 19 Feb 2021 10:25:01 +0000
4 Subject: [PATCH] staging: fbtft: Add minipitft13 variant
6 The Adafruit Mini-PiTFT13 display needs offsets applying when rotated,
7 so use the "variant" mechanism to select a custom set_addr_win method
8 using a dedicated compatible string of "fbtft,minipitft13".
10 See: https://github.com/raspberrypi/firmware/issues/1524
12 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
14 drivers/staging/fbtft/fb_st7789v.c | 45 +++++++++++++++++++++++++++++-
15 1 file changed, 44 insertions(+), 1 deletion(-)
17 --- a/drivers/staging/fbtft/fb_st7789v.c
18 +++ b/drivers/staging/fbtft/fb_st7789v.c
19 @@ -66,6 +66,12 @@ enum st7789v_command {
20 #define MADCTL_MX BIT(6) /* bitmask for column address order */
21 #define MADCTL_MY BIT(7) /* bitmask for page address order */
23 +static u32 col_offset = 0;
24 +static u32 row_offset = 0;
25 +static u8 col_hack_fix_offset = 0;
26 +static short x_offset = 0;
27 +static short y_offset = 0;
30 * init_display() - initialize the display controller
32 @@ -145,6 +151,22 @@ static int init_display(struct fbtft_par
36 +static void minipitft13_set_addr_win(struct fbtft_par *par, int xs, int ys,
43 + write_reg(par, MIPI_DCS_SET_COLUMN_ADDRESS,
44 + xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
46 + write_reg(par, MIPI_DCS_SET_PAGE_ADDRESS,
47 + ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
49 + write_reg(par, MIPI_DCS_WRITE_MEMORY_START);
53 * set_var() - apply LCD properties like rotation and BGR mode
55 @@ -155,20 +177,32 @@ static int init_display(struct fbtft_par
56 static int set_var(struct fbtft_par *par)
59 + struct fbtft_display *display = &par->pdata->display;
60 + u32 width = display->width;
61 + u32 height = display->height;
64 madctl_par |= MADCTL_BGR;
65 switch (par->info->var.rotate) {
71 madctl_par |= (MADCTL_MV | MADCTL_MY);
72 + x_offset = (320 - height) - row_offset;
73 + y_offset = (240 - width) - col_offset;
76 madctl_par |= (MADCTL_MX | MADCTL_MY);
77 + x_offset = (240 - width) - col_offset + col_hack_fix_offset;
78 + // hack tweak to account for extra pixel width to make even
79 + y_offset = (320 - height) - row_offset;
82 madctl_par |= (MADCTL_MV | MADCTL_MX);
83 + x_offset = row_offset;
84 + y_offset = col_offset;
88 @@ -265,7 +299,16 @@ static struct fbtft_display display = {
92 -FBTFT_REGISTER_DRIVER(DRVNAME, "sitronix,st7789v", &display);
93 +int variant_minipitft13(struct fbtft_display *display)
95 + display->fbtftops.set_addr_win = minipitft13_set_addr_win;
99 +FBTFT_REGISTER_DRIVER_START(&display)
100 +FBTFT_COMPATIBLE("sitronix,st7789v")
101 +FBTFT_VARIANT_COMPATIBLE("fbtft,minipitft13", variant_minipitft13)
102 +FBTFT_REGISTER_DRIVER_END(DRVNAME, &display);
104 MODULE_ALIAS("spi:" DRVNAME);
105 MODULE_ALIAS("platform:" DRVNAME);