Thread (5 messages) 5 messages, 3 authors, 2021-01-27

Re: [PATCH v9] staging: fbtft: add tearing signal detect

From: Geert Uytterhoeven <geert@linux-m68k.org>
Date: 2021-01-27 13:48:18
Also in: dri-devel, lkml

Hi Carlis,

On Wed, Jan 27, 2021 at 2:03 PM Carlis [off-list ref] wrote:
From: zhangxuezhi <redacted>

For st7789v ic,add tearing signal detect to avoid screen tearing

Signed-off-by: zhangxuezhi <redacted>
---
v9: change pr_* to dev_*
Thanks for the update!
quoted hunk ↗ jump to hunk
--- a/drivers/staging/fbtft/fb_st7789v.c
+++ b/drivers/staging/fbtft/fb_st7789v.c
@@ -9,9 +9,12 @@
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
+#include <linux/mutex.h>
+#include <linux/interrupt.h>
+#include <linux/completion.h>
 #include <linux/module.h>
 #include <video/mipi_display.h>
-
+#include <linux/gpio/consumer.h>
 #include "fbtft.h"

 #define DRVNAME "fb_st7789v"
@@ -66,6 +69,32 @@ enum st7789v_command {
 #define MADCTL_MX BIT(6) /* bitmask for column address order */
 #define MADCTL_MY BIT(7) /* bitmask for page address order */

+#define SPI_PANEL_TE_TIMEOUT   400
+static struct mutex te_mutex;/*mutex for tearing line*/
+static struct completion spi_panel_te;
+
+static irqreturn_t spi_panel_te_handler(int irq, void *data)
+{
+       complete(&spi_panel_te);
+       return IRQ_HANDLED;
+}
+
+static void set_spi_panel_te_irq_status(struct fbtft_par *par, bool enable)
+{
+       static int te_irq_count;
+
+       mutex_lock(&te_mutex);
+
+       if (enable) {
+               if (++te_irq_count == 1)
+                       enable_irq(gpiod_to_irq(par->gpio.te));
+       } else {
+               if (--te_irq_count == 0)
+                       disable_irq(gpiod_to_irq(par->gpio.te));
+       }
+       mutex_unlock(&te_mutex);
+}
+
 /**
  * init_display() - initialize the display controller
  *
@@ -82,6 +111,33 @@ enum st7789v_command {
  */
 static int init_display(struct fbtft_par *par)
 {
+       int rc;
+       struct device *dev = par->info->device;
+
+       par->gpio.te = devm_gpiod_get_index_optional(dev, "te", 0, GPIOD_IN);
+       if (IS_ERR(par->gpio.te)) {
+               rc = PTR_ERR(par->gpio.te);
+               dev_err(par->info->device, "Failed to request te gpio: %d\n", rc);
This also prints an error in case of -EPROBE_DEFER.
dev_err_probe()?
+               return rc;
+       }
+       if (par->gpio.te) {
+               init_completion(&spi_panel_te);
+               mutex_init(&te_mutex);
+               rc = devm_request_irq(dev,
+                                     gpiod_to_irq(par->gpio.te),
+                                    spi_panel_te_handler, IRQF_TRIGGER_RISING,
+                                    "TE_GPIO", par);
+               if (rc) {
+                       dev_err(par->info->device, "TE request_irq failed.\n");
+                       devm_gpiod_put(dev, par->gpio.te);
No need to call devm_gpiod_put() here, as it's managed automatically.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help