From patchwork Mon Jun 8 20:56:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 6568041 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4875EC0020 for ; Mon, 8 Jun 2015 21:02:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1D5BE20450 for ; Mon, 8 Jun 2015 21:02:12 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C96572044C for ; Mon, 8 Jun 2015 21:02:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z248v-00026j-5z; Mon, 08 Jun 2015 20:59:37 +0000 Received: from mail-lb0-x22a.google.com ([2a00:1450:4010:c04::22a]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z2470-0000d9-Ry for linux-arm-kernel@lists.infradead.org; Mon, 08 Jun 2015 20:57:45 +0000 Received: by lbcmx3 with SMTP id mx3so88423014lbc.1 for ; Mon, 08 Jun 2015 13:57:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ncCOnBPc8Y7ur6F3ClidB1v6H3tGGfI9TBA5iPQjogw=; b=CX3IL7aZFGwywMtBuULoLe2NooJwqdW7vEWn4KbOks55PcqBmUohbAg687x9+wtmOL arZoPQtHl/qvNzS5Y69SFwkIRQ+Cd6s2vtBV3MYp2cHjx/o2LOGPDSbvtEd8FLMP14h/ HHIcGzJJwJLxAq09yBQbVUMDkO78v14+PuM/TahsD5tcUghuD98iomV6hUKLLmbiQlxf cl060SCdYHSuMy5m8jXgRqk6zOMtjXoOqHxFLnn+xhVafviex066ogRJfCFoAEKTUZCE xOrvNolKBhbFkR2w3Y+6IUGqP9Loo1rahElXfP37Xhz4vbbvZBDofUEzssqaXUZ9pJZv Fiug== X-Received: by 10.152.205.102 with SMTP id lf6mr19123253lac.1.1433797035745; Mon, 08 Jun 2015 13:57:15 -0700 (PDT) Received: from anuminas.rup.mentorg.com (ppp89-110-20-81.pppoe.avangarddsl.ru. [89.110.20.81]) by mx.google.com with ESMTPSA id s8sm892556las.29.2015.06.08.13.57.14 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Jun 2015 13:57:14 -0700 (PDT) From: Dmitry Eremin-Solenikov To: Russell King , Lee Jones Subject: [PATCH v5 06/17] video: backlight: add new locomo backlight driver Date: Mon, 8 Jun 2015 23:56:37 +0300 Message-Id: <1433797008-6246-7-git-send-email-dbaryshkov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1433797008-6246-1-git-send-email-dbaryshkov@gmail.com> References: <1433797008-6246-1-git-send-email-dbaryshkov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150608_135739_336919_D25113D1 X-CRM114-Status: GOOD ( 19.10 ) X-Spam-Score: -0.8 (/) Cc: Andrea Adami , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add new simple backlight driver - it cares only about PWM/frontlight part of LoCoMo, it does not touch TFT settings and does not export TFT power control. Signed-off-by: Dmitry Eremin-Solenikov Acked-by: Jingoo Han --- drivers/video/backlight/Kconfig | 6 +- drivers/video/backlight/Makefile | 2 +- drivers/video/backlight/locomo_bl.c | 153 ++++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+), 4 deletions(-) create mode 100644 drivers/video/backlight/locomo_bl.c diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig index 2d9923a..6c093e2 100644 --- a/drivers/video/backlight/Kconfig +++ b/drivers/video/backlight/Kconfig @@ -217,12 +217,12 @@ config BACKLIGHT_LM3533 levels. config BACKLIGHT_LOCOMO - tristate "Sharp LOCOMO LCD/Backlight Driver" - depends on SHARP_LOCOMO + tristate "Sharp LOCOMO Backlight Driver" + depends on MFD_LOCOMO default y help If you have a Sharp Zaurus SL-5500 (Collie) or SL-5600 (Poodle) say y to - enable the LCD/backlight driver. + enable the backlight driver. config BACKLIGHT_OMAP1 tristate "OMAP1 PWL-based LCD Backlight" diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile index d67073f..2de73d2 100644 --- a/drivers/video/backlight/Makefile +++ b/drivers/video/backlight/Makefile @@ -39,7 +39,7 @@ obj-$(CONFIG_BACKLIGHT_IPAQ_MICRO) += ipaq_micro_bl.o obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_bl.o obj-$(CONFIG_BACKLIGHT_LM3630A) += lm3630a_bl.o obj-$(CONFIG_BACKLIGHT_LM3639) += lm3639_bl.o -obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o +obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomo_bl.o obj-$(CONFIG_BACKLIGHT_LP855X) += lp855x_bl.o obj-$(CONFIG_BACKLIGHT_LP8788) += lp8788_bl.o obj-$(CONFIG_BACKLIGHT_LV5207LP) += lv5207lp.o diff --git a/drivers/video/backlight/locomo_bl.c b/drivers/video/backlight/locomo_bl.c new file mode 100644 index 0000000..cc60022 --- /dev/null +++ b/drivers/video/backlight/locomo_bl.c @@ -0,0 +1,153 @@ +/* + * Backlight control code for Sharp Zaurus SL-5500 + * + * Copyright 2005 John Lenz + * Maintainer: Pavel Machek (unless John wants to :-) + * GPL v2 + * + * This driver assumes single CPU. That's okay, because collie is + * slightly old hardware, and no one is going to retrofit second CPU to + * old PDA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct locomo_bl { + struct regmap *regmap; + int current_intensity; + struct gpio_desc *fl_vr; +}; + +static const struct { + u16 duty, bpwf; + bool vr; +} locomo_bl_pwm[] = { + { 0, 161, false }, + { 117, 161, false }, + { 163, 148, false }, + { 194, 161, false }, + { 194, 161, true }, +}; + +static int locomo_bl_set_intensity(struct backlight_device *bd) +{ + int intensity = bd->props.brightness; + struct locomo_bl *bl = dev_get_drvdata(&bd->dev); + + if (bd->props.power != FB_BLANK_UNBLANK) + intensity = 0; + if (bd->props.fb_blank != FB_BLANK_UNBLANK) + intensity = 0; + if (bd->props.state & BL_CORE_SUSPENDED) + intensity = 0; + + gpiod_set_value(bl->fl_vr, locomo_bl_pwm[intensity].vr); + + regmap_write(bl->regmap, LOCOMO_ALS, locomo_bl_pwm[intensity].bpwf); + usleep_range(100, 200); + regmap_write(bl->regmap, LOCOMO_ALD, locomo_bl_pwm[intensity].duty); + usleep_range(100, 200); + regmap_write(bl->regmap, LOCOMO_ALS, locomo_bl_pwm[intensity].bpwf | + LOCOMO_ALS_EN); + + bl->current_intensity = intensity; + if (bd->props.state & BL_CORE_SUSPENDED) + regmap_write(bl->regmap, LOCOMO_ALS, 0x00); + + return 0; +} + +static int locomo_bl_get_intensity(struct backlight_device *bd) +{ + struct locomo_bl *bl = dev_get_drvdata(&bd->dev); + + return bl->current_intensity; +} + +static const struct backlight_ops locomo_bl_ops = { + .options = BL_CORE_SUSPENDRESUME, + .get_brightness = locomo_bl_get_intensity, + .update_status = locomo_bl_set_intensity, +}; + +static int locomo_bl_probe(struct platform_device *dev) +{ + struct backlight_properties props; + struct locomo_bl *bl; + struct backlight_device *locomo_bl_device; + + bl = devm_kmalloc(&dev->dev, sizeof(struct locomo_bl), GFP_KERNEL); + if (!bl) + return -ENOMEM; + + bl->regmap = dev_get_regmap(dev->dev.parent, NULL); + if (!bl->regmap) + return -ENODEV; + + bl->fl_vr = devm_gpiod_get(&dev->dev, "flvr", GPIOD_OUT_LOW); + if (IS_ERR(bl->fl_vr)) + return PTR_ERR(bl->fl_vr); + + regmap_write(bl->regmap, LOCOMO_ALS, 0); + regmap_write(bl->regmap, LOCOMO_ALD, 0); + + memset(&props, 0, sizeof(struct backlight_properties)); + props.type = BACKLIGHT_RAW; + props.max_brightness = ARRAY_SIZE(locomo_bl_pwm) - 1; + props.brightness = props.max_brightness / 2; + locomo_bl_device = devm_backlight_device_register(&dev->dev, + "locomo-bl", + &dev->dev, bl, + &locomo_bl_ops, &props); + + if (IS_ERR(locomo_bl_device)) + return PTR_ERR(locomo_bl_device); + + platform_set_drvdata(dev, locomo_bl_device); + + /* Set up frontlight so that screen is readable */ + backlight_update_status(locomo_bl_device); + + return 0; +} + +static void locomo_bl_shutdown(struct platform_device *dev) +{ + struct backlight_device *locomo_bl_device = platform_get_drvdata(dev); + + locomo_bl_device->props.brightness = 0; + locomo_bl_device->props.power = 0; + locomo_bl_set_intensity(locomo_bl_device); +} + +static int locomo_bl_remove(struct platform_device *dev) +{ + locomo_bl_shutdown(dev); + + return 0; +} + +static struct platform_driver locomo_bl_driver = { + .driver = { + .name = "locomo-backlight", + }, + .probe = locomo_bl_probe, + .remove = locomo_bl_remove, + /* Turn off bl on power off/reboot */ + .shutdown = locomo_bl_shutdown, +}; + +module_platform_driver(locomo_bl_driver); + +MODULE_AUTHOR("John Lenz "); +MODULE_AUTHOR("Pavel Machek "); +MODULE_DESCRIPTION("LoCoMo Backlight driver"); +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:locomo-backlight");