1 From a033cf69a4592c8148bca72bef7c4c103316eb0a 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 | 44 +++++++++++++++++++++++++++++-
15 1 file changed, 43 insertions(+), 1 deletion(-)
17 --- a/drivers/staging/fbtft/fb_st7789v.c
18 +++ b/drivers/staging/fbtft/fb_st7789v.c
19 @@ -75,6 +75,11 @@ enum st7789v_command {
21 static struct completion panel_te; /* completion for panel TE line */
22 static int irq_te; /* Linux IRQ for LCD TE line */
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;
29 static irqreturn_t panel_te_handler(int irq, void *data)
31 @@ -261,6 +266,22 @@ static int write_vmem(struct fbtft_par *
35 +static void minipitft13_set_addr_win(struct fbtft_par *par, int xs, int ys,
42 + write_reg(par, MIPI_DCS_SET_COLUMN_ADDRESS,
43 + xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
45 + write_reg(par, MIPI_DCS_SET_PAGE_ADDRESS,
46 + ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
48 + write_reg(par, MIPI_DCS_WRITE_MEMORY_START);
52 * set_var() - apply LCD properties like rotation and BGR mode
54 @@ -271,20 +292,32 @@ static int write_vmem(struct fbtft_par *
55 static int set_var(struct fbtft_par *par)
58 + struct fbtft_display *display = &par->pdata->display;
59 + u32 width = display->width;
60 + u32 height = display->height;
63 madctl_par |= MADCTL_BGR;
64 switch (par->info->var.rotate) {
70 madctl_par |= (MADCTL_MV | MADCTL_MY);
71 + x_offset = (320 - height) - row_offset;
72 + y_offset = (240 - width) - col_offset;
75 madctl_par |= (MADCTL_MX | MADCTL_MY);
76 + x_offset = (240 - width) - col_offset + col_hack_fix_offset;
77 + // hack tweak to account for extra pixel width to make even
78 + y_offset = (320 - height) - row_offset;
81 madctl_par |= (MADCTL_MV | MADCTL_MX);
82 + x_offset = row_offset;
83 + y_offset = col_offset;
87 @@ -382,7 +415,16 @@ static struct fbtft_display display = {
91 -FBTFT_REGISTER_DRIVER(DRVNAME, "sitronix,st7789v", &display);
92 +int variant_minipitft13(struct fbtft_display *display)
94 + display->fbtftops.set_addr_win = minipitft13_set_addr_win;
98 +FBTFT_REGISTER_DRIVER_START(&display)
99 +FBTFT_COMPATIBLE("sitronix,st7789v")
100 +FBTFT_VARIANT_COMPATIBLE("fbtft,minipitft13", variant_minipitft13)
101 +FBTFT_REGISTER_DRIVER_END(DRVNAME, &display);
103 MODULE_ALIAS("spi:" DRVNAME);
104 MODULE_ALIAS("platform:" DRVNAME);