From: qianfanguijin@163.com To: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org Cc: preid@electromag.com.au, andriy.shevchenko@linux.intel.com, qianfan Zhao <qianfanguijin@163.com> Subject: [PATCH] drivers: fbtft: Refactor backlight logic Date: Sat, 12 Feb 2022 12:27:39 +0800 [thread overview] Message-ID: <20220212042739.21744-1-qianfanguijin@163.com> (raw) From: qianfan Zhao <qianfanguijin@163.com> Control led gpios by using GPIO_ACTIVE flags, don't detect the polarity by reading the gpio value when probe. Signed-off-by: qianfan Zhao <qianfanguijin@163.com> --- drivers/staging/fbtft/fbtft-core.c | 54 +++++++++++++++++------------- drivers/staging/fbtft/fbtft.h | 1 - 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c index ed992ca605eb..37548848af99 100644 --- a/drivers/staging/fbtft/fbtft-core.c +++ b/drivers/staging/fbtft/fbtft-core.c @@ -70,14 +70,14 @@ void fbtft_dbg_hex(const struct device *dev, int groupsize, } EXPORT_SYMBOL(fbtft_dbg_hex); -static int fbtft_request_one_gpio(struct fbtft_par *par, - const char *name, int index, - struct gpio_desc **gpiop) +static int fbtft_request_one_gpio_with_flags(struct fbtft_par *par, + const char *name, int index, + enum gpiod_flags flags, + struct gpio_desc **gpiop) { struct device *dev = par->info->device; - *gpiop = devm_gpiod_get_index_optional(dev, name, index, - GPIOD_OUT_LOW); + *gpiop = devm_gpiod_get_index_optional(dev, name, index, flags); if (IS_ERR(*gpiop)) return dev_err_probe(dev, PTR_ERR(*gpiop), "Failed to request %s GPIO\n", name); @@ -87,6 +87,25 @@ static int fbtft_request_one_gpio(struct fbtft_par *par, return 0; } +static int fbtft_request_one_gpio(struct fbtft_par *par, + const char *name, int index, + struct gpio_desc **gpiop) +{ + enum gpiod_flags flags = GPIOD_OUT_LOW; + + return fbtft_request_one_gpio_with_flags(par, name, index, flags, gpiop); +} + +static int fbtft_request_led_gpio(struct fbtft_par *par, + const char *name, int index, + struct gpio_desc **gpiop) +{ + enum gpiod_flags flags = GPIOD_OUT_HIGH; + + /* request and turn on backlight */ + return fbtft_request_one_gpio_with_flags(par, name, index, flags, gpiop); +} + static int fbtft_request_gpios(struct fbtft_par *par) { int i; @@ -115,7 +134,7 @@ static int fbtft_request_gpios(struct fbtft_par *par) &par->gpio.db[i]); if (ret) return ret; - ret = fbtft_request_one_gpio(par, "led", i, + ret = fbtft_request_led_gpio(par, "led", i, &par->gpio.led[i]); if (ret) return ret; @@ -132,17 +151,16 @@ static int fbtft_request_gpios(struct fbtft_par *par) static int fbtft_backlight_update_status(struct backlight_device *bd) { struct fbtft_par *par = bl_get_data(bd); - bool polarity = par->polarity; fbtft_par_dbg(DEBUG_BACKLIGHT, par, - "%s: polarity=%d, power=%d, fb_blank=%d\n", - __func__, polarity, bd->props.power, bd->props.fb_blank); + "%s: power=%d, fb_blank=%d\n", + __func__, bd->props.power, bd->props.fb_blank); if ((bd->props.power == FB_BLANK_UNBLANK) && (bd->props.fb_blank == FB_BLANK_UNBLANK)) - gpiod_set_value(par->gpio.led[0], polarity); + gpiod_set_value(par->gpio.led[0], 1); else - gpiod_set_value(par->gpio.led[0], !polarity); + gpiod_set_value(par->gpio.led[0], 0); return 0; } @@ -179,11 +197,7 @@ void fbtft_register_backlight(struct fbtft_par *par) } bl_props.type = BACKLIGHT_RAW; - /* Assume backlight is off, get polarity from current state of pin */ - bl_props.power = FB_BLANK_POWERDOWN; - if (!gpiod_get_value(par->gpio.led[0])) - par->polarity = true; - + bl_props.power = FB_BLANK_UNBLANK; bd = backlight_device_register(dev_driver_string(par->info->device), par->info->device, par, &fbtft_bl_ops, &bl_props); @@ -853,14 +867,6 @@ int fbtft_register_framebuffer(struct fb_info *fb_info) fb_info->fix.smem_len >> 10, text1, HZ / fb_info->fbdefio->delay, text2); -#ifdef CONFIG_FB_BACKLIGHT - /* Turn on backlight if available */ - if (fb_info->bl_dev) { - fb_info->bl_dev->props.power = FB_BLANK_UNBLANK; - fb_info->bl_dev->ops->update_status(fb_info->bl_dev); - } -#endif - return 0; reg_fail: diff --git a/drivers/staging/fbtft/fbtft.h b/drivers/staging/fbtft/fbtft.h index 76f8c090a837..6751c129df4d 100644 --- a/drivers/staging/fbtft/fbtft.h +++ b/drivers/staging/fbtft/fbtft.h @@ -228,7 +228,6 @@ struct fbtft_par { ktime_t update_time; bool bgr; void *extra; - bool polarity; }; #define NUMARGS(...) (sizeof((int[]){__VA_ARGS__}) / sizeof(int)) -- 2.17.1
WARNING: multiple messages have this Message-ID (diff)
From: qianfanguijin@163.com To: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org Cc: qianfan Zhao <qianfanguijin@163.com>, preid@electromag.com.au, andriy.shevchenko@linux.intel.com Subject: [PATCH] drivers: fbtft: Refactor backlight logic Date: Sat, 12 Feb 2022 12:27:39 +0800 [thread overview] Message-ID: <20220212042739.21744-1-qianfanguijin@163.com> (raw) From: qianfan Zhao <qianfanguijin@163.com> Control led gpios by using GPIO_ACTIVE flags, don't detect the polarity by reading the gpio value when probe. Signed-off-by: qianfan Zhao <qianfanguijin@163.com> --- drivers/staging/fbtft/fbtft-core.c | 54 +++++++++++++++++------------- drivers/staging/fbtft/fbtft.h | 1 - 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c index ed992ca605eb..37548848af99 100644 --- a/drivers/staging/fbtft/fbtft-core.c +++ b/drivers/staging/fbtft/fbtft-core.c @@ -70,14 +70,14 @@ void fbtft_dbg_hex(const struct device *dev, int groupsize, } EXPORT_SYMBOL(fbtft_dbg_hex); -static int fbtft_request_one_gpio(struct fbtft_par *par, - const char *name, int index, - struct gpio_desc **gpiop) +static int fbtft_request_one_gpio_with_flags(struct fbtft_par *par, + const char *name, int index, + enum gpiod_flags flags, + struct gpio_desc **gpiop) { struct device *dev = par->info->device; - *gpiop = devm_gpiod_get_index_optional(dev, name, index, - GPIOD_OUT_LOW); + *gpiop = devm_gpiod_get_index_optional(dev, name, index, flags); if (IS_ERR(*gpiop)) return dev_err_probe(dev, PTR_ERR(*gpiop), "Failed to request %s GPIO\n", name); @@ -87,6 +87,25 @@ static int fbtft_request_one_gpio(struct fbtft_par *par, return 0; } +static int fbtft_request_one_gpio(struct fbtft_par *par, + const char *name, int index, + struct gpio_desc **gpiop) +{ + enum gpiod_flags flags = GPIOD_OUT_LOW; + + return fbtft_request_one_gpio_with_flags(par, name, index, flags, gpiop); +} + +static int fbtft_request_led_gpio(struct fbtft_par *par, + const char *name, int index, + struct gpio_desc **gpiop) +{ + enum gpiod_flags flags = GPIOD_OUT_HIGH; + + /* request and turn on backlight */ + return fbtft_request_one_gpio_with_flags(par, name, index, flags, gpiop); +} + static int fbtft_request_gpios(struct fbtft_par *par) { int i; @@ -115,7 +134,7 @@ static int fbtft_request_gpios(struct fbtft_par *par) &par->gpio.db[i]); if (ret) return ret; - ret = fbtft_request_one_gpio(par, "led", i, + ret = fbtft_request_led_gpio(par, "led", i, &par->gpio.led[i]); if (ret) return ret; @@ -132,17 +151,16 @@ static int fbtft_request_gpios(struct fbtft_par *par) static int fbtft_backlight_update_status(struct backlight_device *bd) { struct fbtft_par *par = bl_get_data(bd); - bool polarity = par->polarity; fbtft_par_dbg(DEBUG_BACKLIGHT, par, - "%s: polarity=%d, power=%d, fb_blank=%d\n", - __func__, polarity, bd->props.power, bd->props.fb_blank); + "%s: power=%d, fb_blank=%d\n", + __func__, bd->props.power, bd->props.fb_blank); if ((bd->props.power == FB_BLANK_UNBLANK) && (bd->props.fb_blank == FB_BLANK_UNBLANK)) - gpiod_set_value(par->gpio.led[0], polarity); + gpiod_set_value(par->gpio.led[0], 1); else - gpiod_set_value(par->gpio.led[0], !polarity); + gpiod_set_value(par->gpio.led[0], 0); return 0; } @@ -179,11 +197,7 @@ void fbtft_register_backlight(struct fbtft_par *par) } bl_props.type = BACKLIGHT_RAW; - /* Assume backlight is off, get polarity from current state of pin */ - bl_props.power = FB_BLANK_POWERDOWN; - if (!gpiod_get_value(par->gpio.led[0])) - par->polarity = true; - + bl_props.power = FB_BLANK_UNBLANK; bd = backlight_device_register(dev_driver_string(par->info->device), par->info->device, par, &fbtft_bl_ops, &bl_props); @@ -853,14 +867,6 @@ int fbtft_register_framebuffer(struct fb_info *fb_info) fb_info->fix.smem_len >> 10, text1, HZ / fb_info->fbdefio->delay, text2); -#ifdef CONFIG_FB_BACKLIGHT - /* Turn on backlight if available */ - if (fb_info->bl_dev) { - fb_info->bl_dev->props.power = FB_BLANK_UNBLANK; - fb_info->bl_dev->ops->update_status(fb_info->bl_dev); - } -#endif - return 0; reg_fail: diff --git a/drivers/staging/fbtft/fbtft.h b/drivers/staging/fbtft/fbtft.h index 76f8c090a837..6751c129df4d 100644 --- a/drivers/staging/fbtft/fbtft.h +++ b/drivers/staging/fbtft/fbtft.h @@ -228,7 +228,6 @@ struct fbtft_par { ktime_t update_time; bool bgr; void *extra; - bool polarity; }; #define NUMARGS(...) (sizeof((int[]){__VA_ARGS__}) / sizeof(int)) -- 2.17.1
next reply other threads:[~2022-02-12 4:28 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-02-12 4:27 qianfanguijin [this message] 2022-02-12 4:27 ` [PATCH] drivers: fbtft: Refactor backlight logic qianfanguijin 2022-02-14 10:01 ` Andy Shevchenko 2022-02-14 10:01 ` Andy Shevchenko
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220212042739.21744-1-qianfanguijin@163.com \ --to=qianfanguijin@163.com \ --cc=andriy.shevchenko@linux.intel.com \ --cc=dri-devel@lists.freedesktop.org \ --cc=linux-fbdev@vger.kernel.org \ --cc=preid@electromag.com.au \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.