bcm27xx: switch to 5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.10 / 950-0517-staging-fbtft-Add-minipitft13-variant.patch
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
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 | 45 +++++++++++++++++++++++++++++-
15 1 file changed, 44 insertions(+), 1 deletion(-)
16
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 */
22
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 /**
30 * init_display() - initialize the display controller
31 *
32 @@ -147,6 +153,22 @@ static int init_display(struct fbtft_par
33 return 0;
34 }
35
36 +static void minipitft13_set_addr_win(struct fbtft_par *par, int xs, int ys,
37 + int xe, int ye)
38 +{
39 + xs += x_offset;
40 + xe += x_offset;
41 + ys += y_offset;
42 + ye += y_offset;
43 + write_reg(par, MIPI_DCS_SET_COLUMN_ADDRESS,
44 + xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
45 +
46 + write_reg(par, MIPI_DCS_SET_PAGE_ADDRESS,
47 + ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
48 +
49 + write_reg(par, MIPI_DCS_WRITE_MEMORY_START);
50 +}
51 +
52 /**
53 * set_var() - apply LCD properties like rotation and BGR mode
54 *
55 @@ -157,20 +179,32 @@ static int init_display(struct fbtft_par
56 static int set_var(struct fbtft_par *par)
57 {
58 u8 madctl_par = 0;
59 + struct fbtft_display *display = &par->pdata->display;
60 + u32 width = display->width;
61 + u32 height = display->height;
62
63 if (par->bgr)
64 madctl_par |= MADCTL_BGR;
65 switch (par->info->var.rotate) {
66 case 0:
67 + x_offset = 0;
68 + y_offset = 0;
69 break;
70 case 90:
71 madctl_par |= (MADCTL_MV | MADCTL_MY);
72 + x_offset = (320 - height) - row_offset;
73 + y_offset = (240 - width) - col_offset;
74 break;
75 case 180:
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;
80 break;
81 case 270:
82 madctl_par |= (MADCTL_MV | MADCTL_MX);
83 + x_offset = row_offset;
84 + y_offset = col_offset;
85 break;
86 default:
87 return -EINVAL;
88 @@ -267,7 +301,16 @@ static struct fbtft_display display = {
89 },
90 };
91
92 -FBTFT_REGISTER_DRIVER(DRVNAME, "sitronix,st7789v", &display);
93 +int variant_minipitft13(struct fbtft_display *display)
94 +{
95 + display->fbtftops.set_addr_win = minipitft13_set_addr_win;
96 + return 0;
97 +}
98 +
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);
103
104 MODULE_ALIAS("spi:" DRVNAME);
105 MODULE_ALIAS("platform:" DRVNAME);