From patchwork Mon Jul 20 20:35:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11674549 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AEFAA1667 for ; Mon, 20 Jul 2020 20:35:25 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E1F6206F2 for ; Mon, 20 Jul 2020 20:35:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="KhkPtvIs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E1F6206F2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 58F3089E03; Mon, 20 Jul 2020 20:35:22 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id ECA5989E03 for ; Mon, 20 Jul 2020 20:35:20 +0000 (UTC) Received: by mail-lj1-x242.google.com with SMTP id h22so21675151lji.9 for ; Mon, 20 Jul 2020 13:35:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=x2zJYpgDs4IU0fc9VR3TdzhXdQh+0MOJRer0pywnXKA=; b=KhkPtvIsDLUNIupaXYNs8UBWIwdZ5u3Ek5KzfJqFq/S0YjXqGAPiLmgJ8ef90Q0q9l zXaUKRTw8YvweSdBStgruLCIAPSNwXiiOKMzP+FUmVd7CdH8+m8yks4w7YQbA735nY1m Dhf9ftDAXtFClaNUWPGxg4atllIYzWU1vQzjQNFS68jYxjRmHMURVEL84OdGJXRjD8A3 i0FQSxlq89LbYuIqg68lCArt8ML/2QEDRwashMf9J5pQxQ5kx6s9bm+weCDzNzh4qu3X HhdCiEb6DWrcAlOQBt/OQjjqRBzPgposiQLdr7rFarZ4M8llrLhhmOkGZCMiM0ItgmBD zt2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=x2zJYpgDs4IU0fc9VR3TdzhXdQh+0MOJRer0pywnXKA=; b=j3aIcyCaD7FbIswHvigVRmOFZe/fRDpm5T0fYRgNLFSGeE7ZCO9kcSrWm50geL0vjM ZiflEnGRrt3zuBs6irXVMHn5JrQ1ti6ZmBrglpH8mlPFfYGQMrLfnaSCaCuuFaMlF8jH okyoq1E5x4g5O1NSMy9lLgEe+KpTZJ6B0cR1DulJeM/gUm/JdLbdLckSU/bSQnuTcgs/ /fsN+TnoiNIzDswRt59Acd9hbppJMT6FoQpWAj7srTDHrapL5TT4A8ow+vdcX2MPiCCg NDm9xuH6p6Q6LRl3YdsVz/poipze6kT0VZ/E/puQgqEFI4ZJGAY1wMHAYyuGGDAcjl0w ishg== X-Gm-Message-State: AOAM530xHWBtZE0ftkRIsS8r2BWLEIs9MZgXDPa0glNz98SM1YvB0V9n PRERLpHY4Q9L1PVWOrrT46iWhQ== X-Google-Smtp-Source: ABdhPJzvwrDIcDCCe4LB9xTwr68FXr5R+zlTi94XLknZf5DVBVuutopYN4TgqjOAlrk4Du5owjyogQ== X-Received: by 2002:a2e:8718:: with SMTP id m24mr11490351lji.253.1595277319177; Mon, 20 Jul 2020 13:35:19 -0700 (PDT) Received: from localhost.bredbandsbolaget (c-92d7225c.014-348-6c756e10.bbcust.telenor.se. [92.34.215.146]) by smtp.gmail.com with ESMTPSA id y24sm3435076ljy.91.2020.07.20.13.35.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2020 13:35:18 -0700 (PDT) From: Linus Walleij To: Lee Jones , Daniel Thompson , Jingoo Han , dri-devel@lists.freedesktop.org Subject: [PATCH 1/2 v1] dt-bindings: backlight: Add Kinetic KTD253 bindings Date: Mon, 20 Jul 2020 22:35:05 +0200 Message-Id: <20200720203506.3883129-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This adds device tree bindings for the Kinetic KTD253 white LED backlight driver. Cc: devicetree@vger.kernel.org Signed-off-by: Linus Walleij --- .../leds/backlight/kinetic,ktd253.yaml | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/backlight/kinetic,ktd253.yaml diff --git a/Documentation/devicetree/bindings/leds/backlight/kinetic,ktd253.yaml b/Documentation/devicetree/bindings/leds/backlight/kinetic,ktd253.yaml new file mode 100644 index 000000000000..610bf9a0e270 --- /dev/null +++ b/Documentation/devicetree/bindings/leds/backlight/kinetic,ktd253.yaml @@ -0,0 +1,48 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/backlight/kinetic,ktd253.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Kinetic Technologies KTD253 one-wire backlight + +maintainers: + - Linus Walleij + +description: | + The Kinetic Technologies KTD253 is a white LED backlight that is + controlled by a single GPIO line. If you just turn on the backlight + it goes to maximum backlight then you can set the level of backlight + using pulses on the enable wire. + +properties: + compatible: + const: kinetic,ktd253 + + gpios: + description: GPIO to use to enable/disable and dim the backlight. + maxItems: 1 + + default-brightness: + description: Default brightness level on boot. 0 is off. + minimum: 0 + maximum: 255 + + max-brightness: + description: Maximum brightness that is allowed during runtime. + minimum: 0 + maximum: 255 + +required: + - compatible + - gpios + +examples: + - | + #include + backlight { + compatible = "kinetic,ktd253"; + gpios = <&gpio2 5 GPIO_ACTIVE_HIGH>; + default-on; + default-brightness = <160>; + }; From patchwork Mon Jul 20 20:35:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11674551 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0BA9C13B6 for ; Mon, 20 Jul 2020 20:35:29 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DFC1C206F2 for ; Mon, 20 Jul 2020 20:35:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xoEgnIu5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DFC1C206F2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0551689E05; Mon, 20 Jul 2020 20:35:26 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 19FD489E08 for ; Mon, 20 Jul 2020 20:35:23 +0000 (UTC) Received: by mail-lj1-x242.google.com with SMTP id q7so21730073ljm.1 for ; Mon, 20 Jul 2020 13:35:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uRo9EdYadeSHfWc3w5HzcQwlKy6cTkikAo9K/0JHwHo=; b=xoEgnIu5VO5MY/m5ZXunTu4suP8heSTunV5TLZByQPwx/BhfkTxuaZlLnLeK8PhQ33 7ff8tXr7qCqRc4Lw1b+Q69MOHATFUtqNmyJDbWuG98r5c7TAAatyibWJqhK6BR6IeMjJ chrn73pykCae9chbKs6FJ4frDSY1Y+mQg8P02y+8wQp1X5JRnkdG127wluWOrMwWHF+8 S8Uvs+pZUAEADFciI1nYDoTzfeLAK4J+MMrxBuMp45V1BIqr28c5HgbEI5ikDKVpdr4F nkQTbhigF49LpcvkeO2As/7IEdAh6Zrgr6VgJKM4Hz1lBeop3s3nW81UAGP5GtSZY4o5 ZVWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uRo9EdYadeSHfWc3w5HzcQwlKy6cTkikAo9K/0JHwHo=; b=ms9bBjnB3HMVqqqRzXaZUQIYiAbPxgEoANi4k48uqc1I5v0yDxnXthcKQqZGV7xM8b NPI6shs/BcUun+7r29xPL9En+/pqNCL707FJH6J3jSrIdDMAjsPDH59j/bGSoG7FjCOz q7//IOaZixm7HtvpotzDm/BLKo6Y/0E/UP3vCZlvJQ4zDEBz44A7pWuFzLF3kYfmZhgB oNWgOX+OTbYgvZhfuMqiQpC3Asz1MFGmF/t42NSUzEGyg+In9waIae7uXStff10x49SS r9jNs14CjIxfxLU+zQiuMrD2vrp/5v84ntE4cTVo2ZIMXs6hEwHh9ToqMsZe0TMRo50B oTgw== X-Gm-Message-State: AOAM5339bIBI35/M3Lk/n6O/Yw36eTCX2R4R+IToufdsx0jxUSe0huNA M8BgP/mm+/rMU1403+mg7qiVyA== X-Google-Smtp-Source: ABdhPJwezis85ILHHrud26O/M6yjSAlvBotN1CpSZrbeceY8aHaFh0INwK56irstMSkEZOblGC6nDw== X-Received: by 2002:a2e:981a:: with SMTP id a26mr11433503ljj.337.1595277321404; Mon, 20 Jul 2020 13:35:21 -0700 (PDT) Received: from localhost.bredbandsbolaget (c-92d7225c.014-348-6c756e10.bbcust.telenor.se. [92.34.215.146]) by smtp.gmail.com with ESMTPSA id y24sm3435076ljy.91.2020.07.20.13.35.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2020 13:35:20 -0700 (PDT) From: Linus Walleij To: Lee Jones , Daniel Thompson , Jingoo Han , dri-devel@lists.freedesktop.org Subject: [PATCH 2/2 v1] backlight: Add Kinetic KTD253 backlight driver Date: Mon, 20 Jul 2020 22:35:06 +0200 Message-Id: <20200720203506.3883129-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200720203506.3883129-1-linus.walleij@linaro.org> References: <20200720203506.3883129-1-linus.walleij@linaro.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The Kinetic KTD253 backlight driver is controlled with a single GPIO line, but still supports a range of brightness settings by sending fast pulses on the line. This is based off the source code release for the Samsung GT-S7710 mobile phone. Signed-off-by: Linus Walleij --- MAINTAINERS | 6 + drivers/video/backlight/Kconfig | 8 + drivers/video/backlight/Makefile | 1 + drivers/video/backlight/ktd253-backlight.c | 254 +++++++++++++++++++++ 4 files changed, 269 insertions(+) create mode 100644 drivers/video/backlight/ktd253-backlight.c diff --git a/MAINTAINERS b/MAINTAINERS index b4a43a9e7fbc..ea6fcc5bb79e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9610,6 +9610,12 @@ F: Documentation/admin-guide/auxdisplay/ks0108.rst F: drivers/auxdisplay/ks0108.c F: include/linux/ks0108.h +KTD253 BACKLIGHT DRIVER +M: Linus Walleij +S: Maintained +F: Documentation/devicetree/bindings/leds/backlight/kinetic,ktd253.yaml +F: drivers/video/backlight/ktd253-backlight.c + L3MDEV M: David Ahern L: netdev@vger.kernel.org diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig index 7d22d7377606..6a74c60707b4 100644 --- a/drivers/video/backlight/Kconfig +++ b/drivers/video/backlight/Kconfig @@ -190,6 +190,14 @@ config BACKLIGHT_IPAQ_MICRO computers. Say yes if you have one of the h3100/h3600/h3700 machines. +config BACKLIGHT_KTD253 + tristate "Backlight Driver for Kinetic KTD253" + depends on GPIOLIB || COMPILE_TEST + help + Say y to enabled the backlight driver for the Kinetic KTD253 + which is a 1-wire GPIO-controlled backlight found in some mobile + phones. + config BACKLIGHT_LM3533 tristate "Backlight Driver for LM3533" depends on MFD_LM3533 diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile index 0c1a1524627a..d50cd12574ae 100644 --- a/drivers/video/backlight/Makefile +++ b/drivers/video/backlight/Makefile @@ -36,6 +36,7 @@ obj-$(CONFIG_BACKLIGHT_GPIO) += gpio_backlight.o obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o obj-$(CONFIG_BACKLIGHT_HP700) += jornada720_bl.o obj-$(CONFIG_BACKLIGHT_IPAQ_MICRO) += ipaq_micro_bl.o +obj-$(CONFIG_BACKLIGHT_KTD253) += ktd253-backlight.o obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_bl.o obj-$(CONFIG_BACKLIGHT_LM3630A) += lm3630a_bl.o obj-$(CONFIG_BACKLIGHT_LM3639) += lm3639_bl.o diff --git a/drivers/video/backlight/ktd253-backlight.c b/drivers/video/backlight/ktd253-backlight.c new file mode 100644 index 000000000000..d460d1fef329 --- /dev/null +++ b/drivers/video/backlight/ktd253-backlight.c @@ -0,0 +1,254 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Backlight driver for the Kinetic KTD253 + * Based on code and know-how from the Samsung GT-S7710 + * Gareth Phillips + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Current ratio is n/32 from 1/32 to 32/32 */ +#define KTD253_MIN_RATIO 1 +#define KTD253_MAX_RATIO 32 +#define KTD253_DEFAULT_RATIO 13 + +/* With the table we use this is 24/32 current ratio actually */ +#define KTD253_MAX_BRIGHTNESS 255 +#define KTD253_DEFAULT_BRIGHTNESS 160 + +#define KTD253_T_LOW_NS (200 + 10) /* Additional 10ns as safety factor */ +#define KTD253_T_HIGH_NS (200 + 10) /* Additional 10ns as safety factor */ +#define KTD253_T_OFF_MS 3 + +struct ktd253_backlight { + struct device *dev; + struct gpio_desc *gpiod; + u16 ratio; + unsigned int brightness; +}; + +/* + * The following table is used to convert brightness level to the LED + * Current Ratio expressed as (full current) /(n * 32). + * i.e. 1 = 1/32 full current. Zero indicates LED is powered off. + * The table is intended to allow the brightness level to be "tuned" + * to compensate for non-linearity of brightness relative to current. + */ +static const u16 ktd253_brightness_to_current_ratio[] = { + 0, /* (0/32) KTD253_BACKLIGHT_OFF */ + 39, /* (1/32) KTD253_MIN_RATIO */ + 58, /* (2/32) */ + 67, /* (3/32) */ + 76, /* (4/32) */ + 85, /* (5/32) */ + 94, /* (6/32) */ + 104, /* (7/32) */ + 113, /* (8/32) */ + 122, /* (9/32) */ + 131, /* (10/32) */ + 145, /* (11/32) */ + 159, /* (12/32) */ + 169, /* (13/32) */ + 179, /* (14/32) */ + 189, /* (15/32) */ + 196, /* (16/32) */ + 203, /* (17/32) */ + 210, /* (18/32) */ + 217, /* (19/32) */ + 224, /* (20/32) */ + 231, /* (21/32) */ + 238, /* (22/32) */ + 245, /* (23/32) */ + 255, /* (24/32) */ + 300, /* (25/32) */ + 300, /* (26/32) */ + 300, /* (27/32) */ + 300, /* (28/32) */ + 300, /* (29/32) */ + 300, /* (30/32) */ + 300, /* (31/32) */ + 300 /* (32/32) KTD253_MAX_RATIO */ + +}; + +/* Inspired by gpio_bl.c */ +static int ktd253_backlight_get_next_brightness(struct backlight_device *bl) +{ + int brightness = bl->props.brightness; + + if (bl->props.power != FB_BLANK_UNBLANK || + bl->props.fb_blank != FB_BLANK_UNBLANK || + bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK)) + brightness = 0; + + return brightness; +} + +static int ktd253_backlight_update_status(struct backlight_device *bl) +{ + struct ktd253_backlight *ktd253 = bl_get_data(bl); + int brightness = ktd253_backlight_get_next_brightness(bl); + u16 target_ratio; + u16 current_ratio = ktd253->ratio; + unsigned long flags; + + dev_dbg(ktd253->dev, "new brightness: %d\n", brightness); + + /* Look up the current ratio */ + for (target_ratio = KTD253_MAX_RATIO; target_ratio > 0; target_ratio--) { + if (brightness > ktd253_brightness_to_current_ratio[target_ratio - 1]) + break; + } + + dev_dbg(ktd253->dev, "new ratio: %d/32\n", target_ratio); + + if (target_ratio == current_ratio) + /* This is already right */ + return 0; + + if (target_ratio == 0) { + gpiod_set_value_cansleep(ktd253->gpiod, 0); + /* + * We need to keep the GPIO low for at least this long + * to actually switch the KTD253 off. + */ + msleep(KTD253_T_OFF_MS); + ktd253->ratio = 0; + return 0; + } + + if (current_ratio == 0) { + gpiod_set_value_cansleep(ktd253->gpiod, 1); + ndelay(KTD253_T_HIGH_NS); + /* We always fall back to this when we power on */ + current_ratio = KTD253_MAX_RATIO; + } + + /* + * WARNING: + * The loop to set the correct current level is performed + * with interrupts disabled as it is timing critical. + * The maximum number of cycles of the loop is 32 + * so the time taken will be (T_LOW_NS + T_HIGH_NS + loop_time) * 32, + */ + local_irq_save(flags); + while (current_ratio != target_ratio) { + /* + * These GPIO operations absolutely can NOT sleep so no + * _cansleep suffixes, and no using GPIO expanders on + * slow buses for this! + */ + gpiod_set_value(ktd253->gpiod, 0); + ndelay(KTD253_T_LOW_NS); + gpiod_set_value(ktd253->gpiod, 1); + ndelay(KTD253_T_HIGH_NS); + /* After 1/32 we loop back to 32/32 */ + if (current_ratio == KTD253_MIN_RATIO) + current_ratio = KTD253_MAX_RATIO; + else + current_ratio--; + } + local_irq_restore(flags); + ktd253->ratio = current_ratio; + + dev_dbg(ktd253->dev, "new ratio set to %d/32\n", target_ratio); + + return 0; +} + +static const struct backlight_ops ktd253_backlight_ops = { + .options = BL_CORE_SUSPENDRESUME, + .update_status = ktd253_backlight_update_status, +}; + +static int ktd253_backlight_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct backlight_device *bl; + struct ktd253_backlight *ktd253; + u32 max_brightness; + u32 brightness; + int ret; + + ktd253 = devm_kzalloc(dev, sizeof(*ktd253), GFP_KERNEL); + if (!ktd253) + return -ENOMEM; + ktd253->dev = dev; + + ret = device_property_read_u32(dev, "max-brightness", &max_brightness); + if (ret) + max_brightness = KTD253_MAX_BRIGHTNESS; + + ret = device_property_read_u32(dev, "default-brightness", &brightness); + if (ret) + brightness = KTD253_DEFAULT_BRIGHTNESS; + + if (brightness) + /* This will be the default ratio when the KTD253 is enabled */ + ktd253->ratio = KTD253_MAX_RATIO; + else + ktd253->ratio = 0; + + ktd253->gpiod = devm_gpiod_get(dev, NULL, + brightness ? GPIOD_OUT_HIGH : + GPIOD_OUT_LOW); + if (IS_ERR(ktd253->gpiod)) { + ret = PTR_ERR(ktd253->gpiod); + if (ret != -EPROBE_DEFER) + dev_err(dev, "gpio line missing or invalid.\n"); + return ret; + } + gpiod_set_consumer_name(ktd253->gpiod, dev_name(dev)); + + bl = devm_backlight_device_register(dev, dev_name(dev), dev, ktd253, + &ktd253_backlight_ops, NULL); + if (IS_ERR(bl)) { + dev_err(dev, "failed to register backlight\n"); + return PTR_ERR(bl); + } + bl->props.max_brightness = max_brightness; + /* When we just enable the GPIO line we set max brightness */ + if (brightness) { + bl->props.brightness = brightness; + bl->props.power = FB_BLANK_UNBLANK; + ktd253_backlight_update_status(bl); + } else { + bl->props.brightness = 0; + bl->props.power = FB_BLANK_POWERDOWN; + } + + platform_set_drvdata(pdev, bl); + + return 0; +} + +static const struct of_device_id ktd253_backlight_of_match[] = { + { .compatible = "kinetic,ktd253" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, ktd253_backlight_of_match); + +static struct platform_driver ktd253_backlight_driver = { + .driver = { + .name = "ktd253-backlight", + .of_match_table = ktd253_backlight_of_match, + }, + .probe = ktd253_backlight_probe, +}; +module_platform_driver(ktd253_backlight_driver); + +MODULE_AUTHOR("Linus Walleij "); +MODULE_DESCRIPTION("Kinetic KTD253 Backlight Driver"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:ktd253-backlight");