bcm27xx: add support for linux v5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.15 / 950-0374-staging-fbtft-Add-minipitft13-variant.patch
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
5
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".
9
10 See: https://github.com/raspberrypi/firmware/issues/1524
11
12 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
13 ---
14 drivers/staging/fbtft/fb_st7789v.c | 44 +++++++++++++++++++++++++++++-
15 1 file changed, 43 insertions(+), 1 deletion(-)
16
17 --- a/drivers/staging/fbtft/fb_st7789v.c
18 +++ b/drivers/staging/fbtft/fb_st7789v.c
19 @@ -75,6 +75,11 @@ enum st7789v_command {
20
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;
28
29 static irqreturn_t panel_te_handler(int irq, void *data)
30 {
31 @@ -261,6 +266,22 @@ static int write_vmem(struct fbtft_par *
32 return ret;
33 }
34
35 +static void minipitft13_set_addr_win(struct fbtft_par *par, int xs, int ys,
36 + int xe, int ye)
37 +{
38 + xs += x_offset;
39 + xe += x_offset;
40 + ys += y_offset;
41 + ye += y_offset;
42 + write_reg(par, MIPI_DCS_SET_COLUMN_ADDRESS,
43 + xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
44 +
45 + write_reg(par, MIPI_DCS_SET_PAGE_ADDRESS,
46 + ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
47 +
48 + write_reg(par, MIPI_DCS_WRITE_MEMORY_START);
49 +}
50 +
51 /**
52 * set_var() - apply LCD properties like rotation and BGR mode
53 *
54 @@ -271,20 +292,32 @@ static int write_vmem(struct fbtft_par *
55 static int set_var(struct fbtft_par *par)
56 {
57 u8 madctl_par = 0;
58 + struct fbtft_display *display = &par->pdata->display;
59 + u32 width = display->width;
60 + u32 height = display->height;
61
62 if (par->bgr)
63 madctl_par |= MADCTL_BGR;
64 switch (par->info->var.rotate) {
65 case 0:
66 + x_offset = 0;
67 + y_offset = 0;
68 break;
69 case 90:
70 madctl_par |= (MADCTL_MV | MADCTL_MY);
71 + x_offset = (320 - height) - row_offset;
72 + y_offset = (240 - width) - col_offset;
73 break;
74 case 180:
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;
79 break;
80 case 270:
81 madctl_par |= (MADCTL_MV | MADCTL_MX);
82 + x_offset = row_offset;
83 + y_offset = col_offset;
84 break;
85 default:
86 return -EINVAL;
87 @@ -382,7 +415,16 @@ static struct fbtft_display display = {
88 },
89 };
90
91 -FBTFT_REGISTER_DRIVER(DRVNAME, "sitronix,st7789v", &display);
92 +int variant_minipitft13(struct fbtft_display *display)
93 +{
94 + display->fbtftops.set_addr_win = minipitft13_set_addr_win;
95 + return 0;
96 +}
97 +
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);
102
103 MODULE_ALIAS("spi:" DRVNAME);
104 MODULE_ALIAS("platform:" DRVNAME);